Implement more endpoints & overhaul [2/n]
Drop LevelDB and move all the things to SQLite. Implemented endpoints: /api <unit, accessoryMaterialAll> /api <unit, accessoryTab> /live/continue /live/partyList /unit/favoriteAccessory (WIP) /unit/sale Signed-off-by: Sean Du <do4suki@gmail.com>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package live
|
||||
|
||||
import (
|
||||
"honoka-chan/internal/middleware"
|
||||
"honoka-chan/internal/router"
|
||||
liveschema "honoka-chan/internal/schema/live"
|
||||
"honoka-chan/internal/session"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func continuee(ctx *gin.Context) {
|
||||
ss := session.Get(ctx)
|
||||
defer ss.Finalize()
|
||||
|
||||
ss.Respond(liveschema.ContinueResp{
|
||||
ResponseData: liveschema.ContinueData{
|
||||
BeforeSnsCoin: 100000,
|
||||
AfterSnsCoin: 100000,
|
||||
ServerTimestamp: time.Now().Unix(),
|
||||
},
|
||||
ReleaseInfo: []any{},
|
||||
StatusCode: 200,
|
||||
})
|
||||
}
|
||||
|
||||
func init() {
|
||||
router.AddHandler("main.php", "POST", "/live/continue", middleware.Common, continuee)
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package live
|
||||
import (
|
||||
"honoka-chan/internal/middleware"
|
||||
"honoka-chan/internal/router"
|
||||
"honoka-chan/internal/schema/live"
|
||||
liveschema "honoka-chan/internal/schema/live"
|
||||
"honoka-chan/internal/session"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -11,9 +11,12 @@ import (
|
||||
|
||||
func gameOver(ctx *gin.Context) {
|
||||
ss := session.Get(ctx)
|
||||
defer ss.Finalize()
|
||||
defer func() {
|
||||
ss.ClearLiveInProgress()
|
||||
ss.Finalize()
|
||||
}()
|
||||
|
||||
ss.Respond(live.GameOverResp{
|
||||
ss.Respond(liveschema.GameOverResp{
|
||||
ResponseData: []any{},
|
||||
ReleaseInfo: []any{},
|
||||
StatusCode: 200,
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package live
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"honoka-chan/internal/middleware"
|
||||
unitmodel "honoka-chan/internal/model/unit"
|
||||
usermodel "honoka-chan/internal/model/user"
|
||||
"honoka-chan/internal/router"
|
||||
liveschema "honoka-chan/internal/schema/live"
|
||||
"honoka-chan/internal/session"
|
||||
honokautils "honoka-chan/pkg/utils"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -14,14 +17,81 @@ func partyList(ctx *gin.Context) {
|
||||
ss := session.Get(ctx)
|
||||
defer ss.Finalize()
|
||||
|
||||
data := honokautils.ReadAllText("assets/serverdata/partylist.json")
|
||||
var partyResp map[string]any
|
||||
err := json.Unmarshal([]byte(data), &partyResp)
|
||||
pref := usermodel.UserPref{}
|
||||
_, err := ss.UserEng.Table("user_pref").Where("user_id = ?", ss.UserID).Get(&pref)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
ss.Respond(partyResp)
|
||||
// TODO: 好友功能实装前先使用自己的卡组助战
|
||||
var unitList []usermodel.UserDeckUnit
|
||||
err = ss.UserEng.Table("user_deck_unit").Where("user_id = ? AND position = 5", ss.UserID).Find(&unitList)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
var partyList []liveschema.PartyList
|
||||
for _, u := range unitList {
|
||||
var unitInfo unitmodel.UnitDataMap
|
||||
has, err := ss.GetBasicUnitInfo().
|
||||
Where("unit_owning_user_id = ?", u.UnitOwningUserID).Get(&unitInfo)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
if !has {
|
||||
ss.Abort(errors.New("卡片不存在!"))
|
||||
return
|
||||
}
|
||||
|
||||
partyList = append(partyList, liveschema.PartyList{
|
||||
UserInfo: ss.GetUserInfo(),
|
||||
CenterUnitInfo: liveschema.CenterUnitInfo{
|
||||
UnitOwningUserID: u.UnitOwningUserID,
|
||||
UnitID: u.UnitID,
|
||||
Exp: unitInfo.Exp,
|
||||
NextExp: 0,
|
||||
Level: u.Level,
|
||||
LevelLimitID: u.LevelLimitID,
|
||||
MaxLevel: unitInfo.MaxLevel,
|
||||
Rank: unitInfo.Rank,
|
||||
MaxRank: unitInfo.MaxRank,
|
||||
Love: u.Love,
|
||||
MaxLove: u.MaxLove,
|
||||
UnitSkillLevel: u.UnitSkillLevel,
|
||||
MaxHp: unitInfo.MaxHp,
|
||||
FavoriteFlag: unitInfo.FavoriteFlag,
|
||||
DisplayRank: u.DisplayRank,
|
||||
UnitSkillExp: unitInfo.UnitSkillExp,
|
||||
UnitRemovableSkillCapacity: unitInfo.UnitRemovableSkillCapacity,
|
||||
Attribute: unitInfo.Attribute,
|
||||
Smile: unitInfo.Smile,
|
||||
Cute: unitInfo.Cute,
|
||||
Cool: unitInfo.Cool,
|
||||
IsLoveMax: u.IsLoveMax,
|
||||
IsLevelMax: u.IsLevelMax,
|
||||
IsRankMax: u.IsRankMax,
|
||||
IsSigned: u.IsSigned,
|
||||
IsSkillLevelMax: unitInfo.IsSkillLevelMax,
|
||||
SettingAwardID: pref.AwardID,
|
||||
RemovableSkillIds: []int{},
|
||||
},
|
||||
SettingAwardID: pref.AwardID,
|
||||
AvailableSocialPoint: 10,
|
||||
FriendStatus: 1,
|
||||
})
|
||||
}
|
||||
|
||||
ss.Respond(liveschema.PartyListResp{
|
||||
ResponseData: liveschema.PartyListData{
|
||||
PartyList: partyList,
|
||||
TrainingEnergy: 10,
|
||||
TrainingEnergyMax: 10,
|
||||
ServerTimestamp: time.Now().Unix(),
|
||||
},
|
||||
ReleaseInfo: []any{},
|
||||
StatusCode: 200,
|
||||
})
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
+144
-155
@@ -2,183 +2,157 @@ package live
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"honoka-chan/internal/middleware"
|
||||
unitmodel "honoka-chan/internal/model/unit"
|
||||
"honoka-chan/internal/router"
|
||||
"honoka-chan/internal/schema/live"
|
||||
liveschema "honoka-chan/internal/schema/live"
|
||||
"honoka-chan/internal/session"
|
||||
"honoka-chan/pkg/db"
|
||||
honokautils "honoka-chan/pkg/utils"
|
||||
"math"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func play(ctx *gin.Context) {
|
||||
ss := session.Get(ctx)
|
||||
defer ss.Finalize()
|
||||
|
||||
playReq := live.PlayReq{}
|
||||
playReq := liveschema.PlayReq{}
|
||||
err := json.Unmarshal([]byte(ctx.MustGet("request_data").(string)), &playReq)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
// fmt.Println(ctx.MustGet("request_data").(string))
|
||||
|
||||
tDifficultyId := playReq.LiveDifficultyID
|
||||
difficultyId, err := strconv.Atoi(tDifficultyId)
|
||||
ss.RegisterLiveInProgress(playReq.UnitDeckID)
|
||||
|
||||
difficultyID, _ := strconv.Atoi(playReq.LiveDifficultyID)
|
||||
|
||||
// 歌曲类型: normal / special
|
||||
// sqlite3 不支持 FULL OUTER JOIN 所以这里使用 UNION ALL
|
||||
var liveSetting struct {
|
||||
NotesSettingAsset string `xorm:"notes_setting_asset"`
|
||||
ARankScore int `xorm:"a_rank_score"`
|
||||
BRankScore int `xorm:"b_rank_score"`
|
||||
CRankScore int `xorm:"c_rank_score"`
|
||||
SRankScore int `xorm:"s_rank_score"`
|
||||
AcFlag int `xorm:"ac_flag"`
|
||||
SwingFlag int `xorm:"swing_flag"`
|
||||
}
|
||||
sql := `
|
||||
SELECT notes_setting_asset,
|
||||
a_rank_score,
|
||||
b_rank_score,
|
||||
c_rank_score,
|
||||
s_rank_score,
|
||||
ac_flag,
|
||||
swing_flag
|
||||
FROM live_setting_m
|
||||
WHERE live_setting_id IN (
|
||||
SELECT live_setting_id
|
||||
FROM normal_live_m
|
||||
WHERE live_difficulty_id = ?
|
||||
UNION ALL
|
||||
SELECT live_setting_id
|
||||
FROM special_live_m
|
||||
WHERE live_difficulty_id = ?
|
||||
)
|
||||
`
|
||||
_, err = ss.MainEng.SQL(sql, difficultyID, difficultyID).Get(&liveSetting)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
deckId := playReq.UnitDeckID
|
||||
// fmt.Println("liveSetting", liveSetting)
|
||||
|
||||
// Save Deck Id for /live/reward
|
||||
key := "live_deck_" + strconv.Itoa(ss.UserID)
|
||||
err = db.Ldb.Set([]byte(key), []byte(strconv.Itoa(deckId)))
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
// Song type: normal / special
|
||||
// sqlite3 doesn't support FULL OUTER JOIN so use UNION ALL here.
|
||||
sql := `SELECT notes_setting_asset,c_rank_score,b_rank_score,a_rank_score,s_rank_score,ac_flag,swing_flag FROM live_setting_m WHERE live_setting_id IN (SELECT live_setting_id FROM normal_live_m WHERE live_difficulty_id = ? UNION ALL SELECT live_setting_id FROM special_live_m WHERE live_difficulty_id = ?)`
|
||||
var notes_setting_asset string
|
||||
var c_rank_score, b_rank_score, a_rank_score, s_rank_score, ac_flag, swing_flag int
|
||||
err = ss.MainEng.DB().QueryRow(sql, difficultyId, difficultyId).Scan(¬es_setting_asset, &c_rank_score, &b_rank_score, &a_rank_score, &s_rank_score, &ac_flag, &swing_flag)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
// fmt.Println(notes_setting_asset)
|
||||
// fmt.Println(c_rank_score, b_rank_score, a_rank_score, s_rank_score)
|
||||
|
||||
notes := []live.NotesList{}
|
||||
// fmt.Println("./assets/serverdata/beatmaps/" + notes_setting_asset)
|
||||
notes_list := honokautils.ReadAllText("./assets/serverdata/beatmaps/" + notes_setting_asset)
|
||||
notes := []liveschema.NotesList{}
|
||||
notes_list := honokautils.ReadAllText("./assets/serverdata/beatmaps/" + liveSetting.NotesSettingAsset)
|
||||
err = json.Unmarshal([]byte(notes_list), ¬es)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
ranks := []live.RankInfo{}
|
||||
ranks = append(ranks, live.RankInfo{
|
||||
ranks := []liveschema.RankInfo{}
|
||||
ranks = append(ranks, liveschema.RankInfo{
|
||||
Rank: 5,
|
||||
RankMin: 0,
|
||||
RankMax: c_rank_score,
|
||||
}, live.RankInfo{
|
||||
RankMax: liveSetting.CRankScore,
|
||||
}, liveschema.RankInfo{
|
||||
Rank: 4,
|
||||
RankMin: c_rank_score + 1,
|
||||
RankMax: b_rank_score,
|
||||
}, live.RankInfo{
|
||||
RankMin: liveSetting.CRankScore + 1,
|
||||
RankMax: liveSetting.BRankScore,
|
||||
}, liveschema.RankInfo{
|
||||
Rank: 3,
|
||||
RankMin: b_rank_score + 1,
|
||||
RankMax: a_rank_score,
|
||||
}, live.RankInfo{
|
||||
RankMin: liveSetting.BRankScore + 1,
|
||||
RankMax: liveSetting.ARankScore,
|
||||
}, liveschema.RankInfo{
|
||||
Rank: 2,
|
||||
RankMin: a_rank_score + 1,
|
||||
RankMax: s_rank_score,
|
||||
}, live.RankInfo{
|
||||
RankMin: liveSetting.ARankScore + 1,
|
||||
RankMax: liveSetting.SRankScore,
|
||||
}, liveschema.RankInfo{
|
||||
Rank: 1,
|
||||
RankMin: s_rank_score + 1,
|
||||
RankMin: liveSetting.SRankScore + 1,
|
||||
RankMax: 0,
|
||||
})
|
||||
|
||||
// ss.UserEng.ShowSQL(true)
|
||||
// ss.MainEng.ShowSQL(true)
|
||||
owningIdList := []int{}
|
||||
err = ss.UserEng.Table("user_deck_unit").Join("LEFT", "user_deck", "user_deck_unit.user_deck_id = user_deck.id").
|
||||
Where("user_id = ? AND deck_id = ?", ss.UserID, deckId).Cols("unit_owning_user_id").
|
||||
OrderBy("user_deck_unit.position ASC").Find(&owningIdList)
|
||||
err = ss.UserEng.Table("user_deck_unit").
|
||||
Join("LEFT", "user_deck", "user_deck_unit.user_deck_id = user_deck.id").
|
||||
Where("user_deck.user_id = ? AND user_deck.deck_id = ?", ss.UserID, playReq.UnitDeckID).
|
||||
Cols("unit_owning_user_id").OrderBy("user_deck_unit.position ASC").Find(&owningIdList)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
unitList := []live.UnitList{}
|
||||
var totalSmile, totalPure, totalCool, maxLove float64
|
||||
unitList := []liveschema.UnitList{}
|
||||
var totalSmile, totalPure, totalCool float64
|
||||
var totalHp int
|
||||
for _, owningId := range owningIdList {
|
||||
var uId int
|
||||
exists, err := ss.MainEng.Table("common_unit_m").Where("unit_owning_user_id = ?", owningId).Cols("unit_id").Get(&uId)
|
||||
// 卡片基础属性
|
||||
var baseSmile, basePure, baseCool, smileMax, pureMax, coolMax float64
|
||||
var unitData unitmodel.UnitDataMap
|
||||
_, err = ss.GetBasicUnitInfo().Where("unit_owning_user_id = ?", owningId).Get(&unitData)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
var maxHp, attrId, unitTypeId int
|
||||
var baseSmile, basePure, baseCool, smileMax, pureMax, coolMax float64
|
||||
if exists {
|
||||
// 公共卡片仅为100级属性
|
||||
_, err = ss.MainEng.Table("unit_m").Where("unit_id = ?", uId).
|
||||
Join("LEFT", "unit_rarity_m", "unit_m.rarity = unit_rarity_m.rarity").
|
||||
Cols("attribute_id,hp_max,smile_max,pure_max,cool_max,after_love_max,unit_type_id").
|
||||
Get(&attrId, &maxHp, &baseSmile, &basePure, &baseCool, &maxLove, &unitTypeId)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// 用户卡片暂时固定为满级350级
|
||||
exists, err := ss.UserEng.Table("user_unit").Where("unit_owning_user_id = ?", owningId).Cols("unit_id").Get(&uId)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
if exists {
|
||||
// 卡片100级基础属性
|
||||
_, err = ss.MainEng.Table("unit_m").Where("unit_id = ?", uId).
|
||||
Join("LEFT", "unit_rarity_m", "unit_m.rarity = unit_rarity_m.rarity").
|
||||
Cols("attribute_id,hp_max,smile_max,pure_max,cool_max,after_love_max,unit_type_id").
|
||||
Get(&attrId, &maxHp, &baseSmile, &basePure, &baseCool, &maxLove, &unitTypeId)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
// 增量属性
|
||||
var diffSmile, diffPure, diffCool float64
|
||||
_, err = ss.MainEng.Table("unit_level_limit_pattern_m").Where("unit_level_limit_id = 1 AND unit_level = 350").
|
||||
Cols("smile_diff,pure_diff,cool_diff").Get(&diffSmile, &diffPure, &diffCool)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
// 更新卡片属性(注意这里是负数,要用减号)
|
||||
baseSmile -= diffSmile
|
||||
basePure -= diffPure
|
||||
baseCool -= diffCool
|
||||
} else {
|
||||
err = fmt.Errorf("no such unit owning id: %d", owningId)
|
||||
}
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
}
|
||||
baseSmile = float64(unitData.Smile)
|
||||
basePure = float64(unitData.Cute)
|
||||
baseCool = float64(unitData.Cool)
|
||||
// fmt.Println("================================")
|
||||
// fmt.Println("基础属性:", baseSmile, basePure, baseCool)
|
||||
|
||||
// 饰品属性加成(满级)
|
||||
var accessoryOwningId int
|
||||
_, err = ss.UserEng.Table("user_accessory_wear").Where("unit_owning_user_id = ?", owningId).
|
||||
exists, err := ss.UserEng.Table("user_accessory_wear").
|
||||
Where("unit_owning_user_id = ?", owningId).
|
||||
Cols("accessory_owning_user_id").Get(&accessoryOwningId)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
var smileAccessory, pureAccessory, coolAccessory float64
|
||||
_, err = ss.MainEng.Table("common_accessory_m").Join("LEFT", "accessory_m", "common_accessory_m.accessory_id = accessory_m.accessory_id").
|
||||
Where("accessory_owning_user_id = ?", accessoryOwningId).Cols("smile_max,pure_max,cool_max").
|
||||
Get(&smileAccessory, &pureAccessory, &coolAccessory)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
// fmt.Println("基础属性:", baseSmile, basePure, baseCool)
|
||||
if exists {
|
||||
var smileAccessory, pureAccessory, coolAccessory float64
|
||||
_, err = ss.MainEng.Table("common_accessory_m").
|
||||
Join("LEFT", "accessory_m", "common_accessory_m.accessory_id = accessory_m.accessory_id").
|
||||
Where("accessory_owning_user_id = ?", accessoryOwningId).Cols("smile_max,pure_max,cool_max").
|
||||
Get(&smileAccessory, &pureAccessory, &coolAccessory)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
// 饰品属性加成(该加成会影响个宝等百分比宝石属性加成的计算,故先计算。)
|
||||
baseSmile += smileAccessory
|
||||
basePure += pureAccessory
|
||||
baseCool += coolAccessory
|
||||
// fmt.Println("饰品属性加成:", smileAccessory, pureAccessory, coolAccessory)
|
||||
// fmt.Println("饰品属性加成后的基础属性:", baseSmile, basePure, baseCool)
|
||||
// 饰品属性加成(该加成会影响个宝等百分比宝石属性加成的计算,故先计算。)
|
||||
baseSmile += smileAccessory
|
||||
basePure += pureAccessory
|
||||
baseCool += coolAccessory
|
||||
// fmt.Println("饰品属性加成:", smileAccessory, pureAccessory, coolAccessory)
|
||||
// fmt.Println("饰品属性加成后的基础属性:", baseSmile, basePure, baseCool)
|
||||
}
|
||||
|
||||
// 回忆画廊属性加成(该加成会影响个宝等百分比宝石属性加成的计算,故先计算。)
|
||||
var smileBuff, pureBuff, coolBuff float64
|
||||
_, err = ss.MainEng.Table("museum_contents_m").Select("SUM(smile_buff),SUM(pure_buff),SUM(cool_buff)").Get(&smileBuff, &pureBuff, &coolBuff)
|
||||
_, err = ss.MainEng.Table("museum_contents_m").
|
||||
Select("SUM(smile_buff),SUM(pure_buff),SUM(cool_buff)").
|
||||
Get(&smileBuff, &pureBuff, &coolBuff)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
@@ -189,26 +163,25 @@ func play(ctx *gin.Context) {
|
||||
// fmt.Println("回忆画廊属性加成后的基础属性:", baseSmile, basePure, baseCool)
|
||||
|
||||
// 绊属性加成(该加成会影响个宝等百分比宝石属性加成的计算,故先计算。)
|
||||
switch attrId {
|
||||
switch unitData.Attribute {
|
||||
case 1:
|
||||
baseSmile += maxLove
|
||||
baseSmile += float64(unitData.MaxLove)
|
||||
case 2:
|
||||
basePure += maxLove
|
||||
basePure += float64(unitData.MaxLove)
|
||||
case 3:
|
||||
baseCool += maxLove
|
||||
baseCool += float64(unitData.MaxLove)
|
||||
}
|
||||
// fmt.Println("绊属性加成:", maxLove)
|
||||
// fmt.Println("绊属性加成:", unitData.MaxLove)
|
||||
// fmt.Println("绊属性加成后的基础属性:", baseSmile, basePure, baseCool)
|
||||
|
||||
// 宝石属性加成
|
||||
var kissSmile, kissPure, kissCool float64
|
||||
var skillSmile, skillPure, skillCool float64
|
||||
// var mainCenterSmile, mainCenterPure, mainCenterCool float64
|
||||
// var secCenterSmile, secCenterPure, secCenterCool float64
|
||||
|
||||
// 宝石加成(满级)
|
||||
removableSkillIds := []int{}
|
||||
err = ss.UserEng.Table("user_unit_skill_equip").Where("unit_owning_user_id = ? AND user_id = ?", owningId, ss.UserID).
|
||||
err = ss.UserEng.Table("user_unit_skill_equip").
|
||||
Where("unit_owning_user_id = ?", owningId).
|
||||
Cols("unit_removable_skill_id").Find(&removableSkillIds)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
@@ -218,7 +191,8 @@ func play(ctx *gin.Context) {
|
||||
// 判断宝石效果类型(效果范围、效果类型、效果值、是否固定数值)
|
||||
var effectRange, effectType, fixedValueFlag, refType int
|
||||
var effectValue float64
|
||||
_, err = ss.MainEng.Table("unit_removable_skill_m").Where("unit_removable_skill_id = ?", sk).
|
||||
_, err = ss.MainEng.Table("unit_removable_skill_m").
|
||||
Where("unit_removable_skill_id = ?", sk).
|
||||
Cols("effect_range,effect_type,effect_value,fixed_value_flag,target_reference_type").
|
||||
Get(&effectRange, &effectType, &effectValue, &fixedValueFlag, &refType)
|
||||
if ss.CheckErr(err) {
|
||||
@@ -276,7 +250,8 @@ func play(ctx *gin.Context) {
|
||||
|
||||
// 主唱技能加成
|
||||
var myCenterUnitId int
|
||||
_, err = ss.UserEng.Table("user_deck_unit").Join("LEFT", "user_deck", "user_deck_unit.user_deck_id = user_deck.id").
|
||||
_, err = ss.UserEng.Table("user_deck_unit").
|
||||
Join("LEFT", "user_deck", "user_deck_unit.user_deck_id = user_deck.id").
|
||||
Where("user_deck.deck_id = ? AND user_deck.user_id = ? AND user_deck_unit.position = 5", playReq.UnitDeckID, ss.UserID).
|
||||
Cols("user_deck_unit.unit_id").Get(&myCenterUnitId)
|
||||
if ss.CheckErr(err) {
|
||||
@@ -310,16 +285,18 @@ func play(ctx *gin.Context) {
|
||||
_, err = ss.MainEng.Table("unit_m").
|
||||
Join("LEFT", "unit_leader_skill_extra_m", "unit_m.default_leader_skill_id = unit_leader_skill_extra_m.unit_leader_skill_id").
|
||||
Where("unit_m.unit_id = ?", myCenterUnitId).
|
||||
Cols("unit_leader_skill_extra_m.effect_value,unit_leader_skill_extra_m.member_tag_id").Get(&mySubEffectValue, &myMemberTagId)
|
||||
Cols("unit_leader_skill_extra_m.effect_value,unit_leader_skill_extra_m.member_tag_id").
|
||||
Get(&mySubEffectValue, &myMemberTagId)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
exists, err = ss.MainEng.Table("unit_type_member_tag_m").
|
||||
Where("unit_type_id = ? AND member_tag_id = ?", unitTypeId, myMemberTagId).Exist()
|
||||
Where("unit_type_id = ? AND member_tag_id = ?", unitData.UnitTypeID, myMemberTagId).Exist()
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
var mySubSmile, mySubPure, mySubCool float64
|
||||
if exists {
|
||||
switch myAttrId {
|
||||
@@ -335,24 +312,26 @@ func play(ctx *gin.Context) {
|
||||
|
||||
// 好友主唱技能加成
|
||||
// TODO 好友支援存入数据库
|
||||
var tomoUnitId int64
|
||||
partyList := gjson.Parse(honokautils.ReadAllText("assets/serverdata/partylist.json")).Get("response_data.party_list")
|
||||
partyList.ForEach(func(key, value gjson.Result) bool {
|
||||
if value.Get("user_info.user_id").Int() == playReq.PartyUserID {
|
||||
tomoUnitId = value.Get("center_unit_info.unit_id").Int()
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
// var tomoUnitId int64
|
||||
// partyList := gjson.Parse(honokautils.ReadAllText("assets/serverdata/partylist.json")).Get("response_data.party_list")
|
||||
// partyList.ForEach(func(key, value gjson.Result) bool {
|
||||
// if value.Get("user_info.user_id").Int() == playReq.PartyUserID {
|
||||
// tomoUnitId = value.Get("center_unit_info.unit_id").Int()
|
||||
// return false
|
||||
// }
|
||||
// return true
|
||||
// })
|
||||
// TODO: 好友功能实装前先使用自己的卡组助战
|
||||
tomoUnitId := myCenterUnitId
|
||||
// fmt.Println("好友UnitID:", tomoUnitId)
|
||||
|
||||
// 好友主唱技能加成:主C技能(这里不使用新C技能,即以某属性的百分比提升另一属性)
|
||||
var tomoAttrId int
|
||||
var tomoEffectValue float64
|
||||
_, err = ss.MainEng.Table("unit_m").
|
||||
Join("LEFT", "unit_leader_skill_m", "unit_m.default_leader_skill_id = unit_leader_skill_m.unit_leader_skill_id").
|
||||
Where("unit_m.unit_id = ?", tomoUnitId).
|
||||
Cols("unit_m.attribute_id,unit_leader_skill_m.effect_value").Get(&tomoAttrId, &tomoEffectValue)
|
||||
Cols("unit_leader_skill_m.effect_value").
|
||||
Get(&tomoEffectValue)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
@@ -373,13 +352,14 @@ func play(ctx *gin.Context) {
|
||||
_, err = ss.MainEng.Table("unit_m").
|
||||
Join("LEFT", "unit_leader_skill_extra_m", "unit_m.default_leader_skill_id = unit_leader_skill_extra_m.unit_leader_skill_id").
|
||||
Where("unit_m.unit_id = ?", tomoUnitId).
|
||||
Cols("unit_leader_skill_extra_m.effect_value,unit_leader_skill_extra_m.member_tag_id").Get(&tomoSubEffectValue, &tomoMemberTagId)
|
||||
Cols("unit_leader_skill_extra_m.effect_value,unit_leader_skill_extra_m.member_tag_id").
|
||||
Get(&tomoSubEffectValue, &tomoMemberTagId)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
exists, err = ss.MainEng.Table("unit_type_member_tag_m").
|
||||
Where("unit_type_id = ? AND member_tag_id = ?", unitTypeId, tomoMemberTagId).Exist()
|
||||
Where("unit_type_id = ? AND member_tag_id = ?", unitData.UnitTypeID, tomoMemberTagId).Exist()
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
@@ -400,7 +380,16 @@ func play(ctx *gin.Context) {
|
||||
totalSmile += smileMax + myCenterSmile + mySubSmile + tomoCenterSmile + tomoSubSmile
|
||||
totalPure += pureMax + myCenterPure + mySubPure + tomoCenterPure + tomoSubPure
|
||||
totalCool += coolMax + myCenterCool + mySubCool + tomoCenterCool + tomoSubCool
|
||||
totalHp += maxHp
|
||||
totalHp += unitData.MaxHp
|
||||
// fmt.Println("smileMax, myCenterSmile, mySubSmile, tomoCenterSmile, tomoSubSmile, totalSmile",
|
||||
// smileMax, myCenterSmile, mySubSmile, tomoCenterSmile, tomoSubSmile,
|
||||
// smileMax+myCenterSmile+mySubSmile+tomoCenterSmile+tomoSubSmile)
|
||||
// fmt.Println("pureMax, myCenterPure, mySubPure, tomoCenterPure, tomoSubPure, totalPure",
|
||||
// pureMax, myCenterPure, mySubPure, tomoCenterPure, tomoSubPure,
|
||||
// pureMax+myCenterPure+mySubPure+tomoCenterPure+tomoSubPure)
|
||||
// fmt.Println("coolMax, myCenterCool, mySubCool, tomoCenterCool, tomoSubCool, totalPure",
|
||||
// coolMax, myCenterCool, mySubCool, tomoCenterCool, tomoSubCool,
|
||||
// coolMax+myCenterCool+mySubCool+tomoCenterCool+tomoSubCool)
|
||||
|
||||
// 单卡属性计算结果取上取整
|
||||
fixedSmileMax := int(smileMax)
|
||||
@@ -408,7 +397,7 @@ func play(ctx *gin.Context) {
|
||||
fixedCoolMax := int(coolMax)
|
||||
// fmt.Println("单卡属性:", fixedSmileMax, fixedPureMax, fixedCoolMax)
|
||||
|
||||
unitList = append(unitList, live.UnitList{
|
||||
unitList = append(unitList, liveschema.UnitList{
|
||||
Smile: fixedSmileMax,
|
||||
Cute: fixedPureMax,
|
||||
Cool: fixedCoolMax,
|
||||
@@ -421,17 +410,17 @@ func play(ctx *gin.Context) {
|
||||
fixedTotalCool := int(math.Ceil(totalCool))
|
||||
// fmt.Println("全卡组属性:", fixedTotalSmile, fixedTotalPure, fixedTotalCool)
|
||||
|
||||
lives := []live.PlayLiveList{}
|
||||
lives = append(lives, live.PlayLiveList{
|
||||
LiveInfo: live.LiveInfo{
|
||||
LiveDifficultyID: difficultyId,
|
||||
lives := []liveschema.PlayLiveList{}
|
||||
lives = append(lives, liveschema.PlayLiveList{
|
||||
LiveInfo: liveschema.LiveInfo{
|
||||
LiveDifficultyID: difficultyID,
|
||||
IsRandom: false,
|
||||
AcFlag: ac_flag,
|
||||
SwingFlag: swing_flag,
|
||||
AcFlag: liveSetting.AcFlag,
|
||||
SwingFlag: liveSetting.SwingFlag,
|
||||
NotesList: notes,
|
||||
},
|
||||
DeckInfo: live.DeckInfo{
|
||||
UnitDeckID: deckId,
|
||||
DeckInfo: liveschema.DeckInfo{
|
||||
UnitDeckID: playReq.UnitDeckID,
|
||||
TotalSmile: fixedTotalSmile,
|
||||
TotalCute: fixedTotalPure,
|
||||
TotalCool: fixedTotalCool,
|
||||
@@ -441,8 +430,8 @@ func play(ctx *gin.Context) {
|
||||
},
|
||||
})
|
||||
|
||||
playResp := live.PlayResp{
|
||||
ResponseData: live.PlayData{
|
||||
playResp := liveschema.PlayResp{
|
||||
ResponseData: liveschema.PlayData{
|
||||
RankInfo: ranks,
|
||||
EnergyFullTime: "2023-03-20 01:28:55",
|
||||
OverMaxEnergy: 0,
|
||||
|
||||
@@ -2,11 +2,13 @@ package live
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"honoka-chan/internal/constant"
|
||||
"honoka-chan/internal/middleware"
|
||||
usermodel "honoka-chan/internal/model/user"
|
||||
"honoka-chan/internal/router"
|
||||
"honoka-chan/internal/schema/live"
|
||||
liveschema "honoka-chan/internal/schema/live"
|
||||
"honoka-chan/internal/session"
|
||||
honokautils "honoka-chan/pkg/utils"
|
||||
"honoka-chan/pkg/utils"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -17,90 +19,225 @@ func preciseScore(ctx *gin.Context) {
|
||||
ss := session.Get(ctx)
|
||||
defer ss.Finalize()
|
||||
|
||||
playScoreReq := live.PlayScoreReq{}
|
||||
playScoreReq := liveschema.PlayScoreReq{}
|
||||
err := json.Unmarshal([]byte(ctx.MustGet("request_data").(string)), &playScoreReq)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
// fmt.Println(ctx.MustGet("request_data").(string))
|
||||
|
||||
tDifficultyId := playScoreReq.LiveDifficultyID
|
||||
difficultyId, err := strconv.Atoi(tDifficultyId)
|
||||
difficultyID, _ := strconv.Atoi(playScoreReq.LiveDifficultyID)
|
||||
|
||||
// 歌曲类型: normal / special
|
||||
// sqlite3 不支持 FULL OUTER JOIN 所以这里使用 UNION ALL
|
||||
var liveSetting struct {
|
||||
NotesSettingAsset string `xorm:"notes_setting_asset"`
|
||||
ARankScore int `xorm:"a_rank_score"`
|
||||
BRankScore int `xorm:"b_rank_score"`
|
||||
CRankScore int `xorm:"c_rank_score"`
|
||||
SRankScore int `xorm:"s_rank_score"`
|
||||
AcFlag int `xorm:"ac_flag"`
|
||||
SwingFlag int `xorm:"swing_flag"`
|
||||
}
|
||||
sql := `
|
||||
SELECT notes_setting_asset,
|
||||
a_rank_score,
|
||||
b_rank_score,
|
||||
c_rank_score,
|
||||
s_rank_score,
|
||||
ac_flag,
|
||||
swing_flag
|
||||
FROM live_setting_m
|
||||
WHERE live_setting_id IN (
|
||||
SELECT live_setting_id
|
||||
FROM normal_live_m
|
||||
WHERE live_difficulty_id = ?
|
||||
UNION ALL
|
||||
SELECT live_setting_id
|
||||
FROM special_live_m
|
||||
WHERE live_difficulty_id = ?
|
||||
)
|
||||
`
|
||||
_, err = ss.MainEng.SQL(sql, difficultyID, difficultyID).Get(&liveSetting)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
// fmt.Println("liveSetting", liveSetting)
|
||||
|
||||
// Song type: normal / special
|
||||
// sqlite3 doesn't support FULL OUTER JOIN so use UNION ALL here.
|
||||
sql := `SELECT notes_setting_asset,c_rank_score,b_rank_score,a_rank_score,s_rank_score,ac_flag,swing_flag FROM live_setting_m WHERE live_setting_id IN (SELECT live_setting_id FROM normal_live_m WHERE live_difficulty_id = ? UNION ALL SELECT live_setting_id FROM special_live_m WHERE live_difficulty_id = ?)`
|
||||
var notes_setting_asset string
|
||||
var c_rank_score, b_rank_score, a_rank_score, s_rank_score, ac_flag, swing_flag int
|
||||
err = ss.MainEng.DB().QueryRow(sql, difficultyId, difficultyId).Scan(¬es_setting_asset, &c_rank_score, &b_rank_score, &a_rank_score, &s_rank_score, &ac_flag, &swing_flag)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
// fmt.Println(notes_setting_asset)
|
||||
// fmt.Println(c_rank_score, b_rank_score, a_rank_score, s_rank_score)
|
||||
|
||||
notes := []live.NotesList{}
|
||||
// fmt.Println("./assets/serverdata/beatmaps/" + notes_setting_asset)
|
||||
notes_list := honokautils.ReadAllText("./assets/serverdata/beatmaps/" + notes_setting_asset)
|
||||
notes := []liveschema.NotesList{}
|
||||
notes_list := utils.ReadAllText("./assets/serverdata/beatmaps/" + liveSetting.NotesSettingAsset)
|
||||
err = json.Unmarshal([]byte(notes_list), ¬es)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
ranks := []live.RankInfo{}
|
||||
ranks = append(ranks, live.RankInfo{
|
||||
ranks := []liveschema.RankInfo{}
|
||||
ranks = append(ranks, liveschema.RankInfo{
|
||||
Rank: 5,
|
||||
RankMin: 0,
|
||||
RankMax: c_rank_score,
|
||||
}, live.RankInfo{
|
||||
RankMax: liveSetting.CRankScore,
|
||||
}, liveschema.RankInfo{
|
||||
Rank: 4,
|
||||
RankMin: c_rank_score + 1,
|
||||
RankMax: b_rank_score,
|
||||
}, live.RankInfo{
|
||||
RankMin: liveSetting.CRankScore + 1,
|
||||
RankMax: liveSetting.BRankScore,
|
||||
}, liveschema.RankInfo{
|
||||
Rank: 3,
|
||||
RankMin: b_rank_score + 1,
|
||||
RankMax: a_rank_score,
|
||||
}, live.RankInfo{
|
||||
RankMin: liveSetting.BRankScore + 1,
|
||||
RankMax: liveSetting.ARankScore,
|
||||
}, liveschema.RankInfo{
|
||||
Rank: 2,
|
||||
RankMin: a_rank_score + 1,
|
||||
RankMax: s_rank_score,
|
||||
}, live.RankInfo{
|
||||
RankMin: liveSetting.ARankScore + 1,
|
||||
RankMax: liveSetting.SRankScore,
|
||||
}, liveschema.RankInfo{
|
||||
Rank: 1,
|
||||
RankMin: s_rank_score + 1,
|
||||
RankMin: liveSetting.SRankScore + 1,
|
||||
RankMax: 0,
|
||||
})
|
||||
|
||||
playResp := live.PreciseScoreResp{
|
||||
ResponseData: live.PreciseScoreData{
|
||||
On: live.On{
|
||||
HasRecord: false,
|
||||
LiveInfo: live.LiveInfo{
|
||||
LiveDifficultyID: difficultyId,
|
||||
IsRandom: false,
|
||||
AcFlag: ac_flag,
|
||||
SwingFlag: swing_flag,
|
||||
NotesList: notes,
|
||||
// 检查是否正在进行 Live
|
||||
progress, _ := ss.GetLiveInProgress()
|
||||
|
||||
// 检查是否有 Live 记录
|
||||
liveRecord := ss.GetUserLiveRecord(difficultyID)
|
||||
|
||||
var skillOn liveschema.Skill
|
||||
var skillOff liveschema.Skill
|
||||
var playResp liveschema.PreciseScoreResp
|
||||
|
||||
// 正在进行 Live
|
||||
if progress {
|
||||
// 返回默认
|
||||
playResp = liveschema.PreciseScoreResp{
|
||||
ResponseData: liveschema.PreciseScoreData{
|
||||
On: liveschema.Skill{
|
||||
HasRecord: false,
|
||||
LiveInfo: liveschema.LiveInfo{
|
||||
LiveDifficultyID: difficultyID,
|
||||
IsRandom: false,
|
||||
AcFlag: liveSetting.AcFlag,
|
||||
SwingFlag: liveSetting.SwingFlag,
|
||||
NotesList: notes,
|
||||
},
|
||||
},
|
||||
},
|
||||
Off: live.Off{
|
||||
HasRecord: false,
|
||||
LiveInfo: live.LiveInfo{
|
||||
LiveDifficultyID: difficultyId,
|
||||
IsRandom: false,
|
||||
AcFlag: ac_flag,
|
||||
SwingFlag: swing_flag,
|
||||
NotesList: notes,
|
||||
Off: liveschema.Skill{
|
||||
HasRecord: false,
|
||||
LiveInfo: liveschema.LiveInfo{
|
||||
LiveDifficultyID: difficultyID,
|
||||
IsRandom: false,
|
||||
AcFlag: liveSetting.AcFlag,
|
||||
SwingFlag: liveSetting.SwingFlag,
|
||||
NotesList: notes,
|
||||
},
|
||||
},
|
||||
RankInfo: ranks,
|
||||
CanActivateEffect: true,
|
||||
ServerTimestamp: time.Now().Unix(),
|
||||
},
|
||||
RankInfo: ranks,
|
||||
CanActivateEffect: true,
|
||||
ServerTimestamp: time.Now().Unix(),
|
||||
},
|
||||
ReleaseInfo: []any{},
|
||||
StatusCode: 200,
|
||||
ReleaseInfo: []any{},
|
||||
StatusCode: 200,
|
||||
}
|
||||
} else {
|
||||
// 如果有 Live 记录
|
||||
if len(liveRecord) > 0 {
|
||||
skillOn = liveschema.Skill{
|
||||
HasRecord: false,
|
||||
RandomSeed: nil,
|
||||
MaxCombo: nil,
|
||||
UpdateDate: nil,
|
||||
PreciseList: nil,
|
||||
DeckInfo: nil,
|
||||
TapAdjust: nil, // TODO: 不知道保存在哪里
|
||||
CanReplay: false, // TODO: 不知道保存在哪里
|
||||
}
|
||||
skillOff = skillOn
|
||||
|
||||
// 已完成的 Live 判断技能开关情况
|
||||
for _, record := range liveRecord {
|
||||
// LiveInfo
|
||||
var liveInfo liveschema.LiveInfo
|
||||
err = json.Unmarshal([]byte(record.LiveInfoJSON), &liveInfo)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
liveInfo.NotesList = notes
|
||||
|
||||
// PreciseList
|
||||
var preciseList []liveschema.PreciseList
|
||||
err = json.Unmarshal([]byte(record.PreciseListJSON), &preciseList)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
// DeckInfo
|
||||
var deckInfo usermodel.DeckInfo
|
||||
err = json.Unmarshal([]byte(record.DeckInfoJSON), &deckInfo)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
// LiveSetting
|
||||
var liveSetting liveschema.LiveSetting
|
||||
err = json.Unmarshal([]byte(record.LiveSettingJSON), &liveSetting)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
// TriggerLog
|
||||
var triggerLog []liveschema.TriggerLog
|
||||
err = json.Unmarshal([]byte(record.TriggerLogJSON), &triggerLog)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
if record.IsSkillOn {
|
||||
// 技能开
|
||||
skillOn.HasRecord = true
|
||||
skillOn.LiveInfo = liveInfo
|
||||
skillOn.RandomSeed = time.Now().Unix() // TODO: 从 /live/play 的 Timestamp 字段获取
|
||||
skillOn.MaxCombo = record.MaxCombo
|
||||
skillOn.UpdateDate = record.UpdateDate
|
||||
skillOn.PreciseList = preciseList
|
||||
skillOn.DeckInfo = deckInfo
|
||||
skillOn.LiveSetting = liveSetting
|
||||
skillOn.TriggerLog = triggerLog
|
||||
skillOn.TapAdjust = record.TapAdjust
|
||||
skillOn.CanReplay = record.CanReplay
|
||||
} else {
|
||||
// 技能关
|
||||
skillOff.HasRecord = true
|
||||
skillOff.LiveInfo = liveInfo
|
||||
skillOff.RandomSeed = time.Now().Unix() // TODO: 从 /live/play 的 Timestamp 字段获取
|
||||
skillOff.MaxCombo = record.MaxCombo
|
||||
skillOff.UpdateDate = record.UpdateDate
|
||||
skillOff.PreciseList = preciseList
|
||||
skillOff.DeckInfo = deckInfo
|
||||
skillOff.LiveSetting = liveSetting
|
||||
skillOff.TriggerLog = triggerLog
|
||||
skillOff.TapAdjust = record.TapAdjust
|
||||
skillOff.CanReplay = record.CanReplay
|
||||
}
|
||||
}
|
||||
|
||||
playResp = liveschema.PreciseScoreResp{
|
||||
ResponseData: liveschema.PreciseScoreData{
|
||||
On: skillOn,
|
||||
Off: skillOff,
|
||||
RankInfo: ranks,
|
||||
CanActivateEffect: true,
|
||||
ServerTimestamp: time.Now().Unix(),
|
||||
},
|
||||
ReleaseInfo: []any{},
|
||||
StatusCode: 200,
|
||||
}
|
||||
} else {
|
||||
playResp = liveschema.PreciseScoreResp{
|
||||
ResponseData: map[string]constant.ErrorCode{
|
||||
"error_code": constant.ErrorCodeLivePreciseListNotFound,
|
||||
},
|
||||
ReleaseInfo: []any{},
|
||||
StatusCode: 600,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ss.Respond(playResp)
|
||||
|
||||
+79
-102
@@ -3,12 +3,11 @@ package live
|
||||
import (
|
||||
"encoding/json"
|
||||
"honoka-chan/internal/middleware"
|
||||
"honoka-chan/internal/model/user"
|
||||
usermodel "honoka-chan/internal/model/user"
|
||||
"honoka-chan/internal/router"
|
||||
"honoka-chan/internal/schema/live"
|
||||
liveschema "honoka-chan/internal/schema/live"
|
||||
"honoka-chan/internal/session"
|
||||
"honoka-chan/pkg/db"
|
||||
"strconv"
|
||||
"honoka-chan/pkg/utils"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -16,68 +15,64 @@ import (
|
||||
|
||||
func reward(ctx *gin.Context) {
|
||||
ss := session.Get(ctx)
|
||||
defer ss.Finalize()
|
||||
defer func() {
|
||||
ss.ClearLiveInProgress()
|
||||
ss.Finalize()
|
||||
}()
|
||||
|
||||
playRewardReq := live.RewardReq{}
|
||||
playRewardReq := liveschema.RewardReq{}
|
||||
err := json.Unmarshal([]byte(ctx.MustGet("request_data").(string)), &playRewardReq)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
// fmt.Println(ctx.MustGet("request_data").(string))
|
||||
|
||||
difficultyId := playRewardReq.LiveDifficultyID
|
||||
difficultyID := playRewardReq.LiveDifficultyID
|
||||
_, liveInfo := ss.GetLiveInfo(difficultyID)
|
||||
_, progress := ss.GetLiveInProgress() // TODO: 添加返回指定状态码的方法
|
||||
_, deckInfo := ss.GetDeckInfo(progress.DeckID)
|
||||
deckInfo.LiveDifficultyID = difficultyID
|
||||
|
||||
// Song type: normal / special
|
||||
// sqlite3 doesn't support FULL OUTER JOIN so use UNION ALL here.
|
||||
sql := `SELECT c_rank_score,b_rank_score,a_rank_score,s_rank_score,c_rank_combo,b_rank_combo,a_rank_combo,s_rank_combo,ac_flag,swing_flag FROM live_setting_m WHERE live_setting_id IN (SELECT live_setting_id FROM normal_live_m WHERE live_difficulty_id = ? UNION ALL SELECT live_setting_id FROM special_live_m WHERE live_difficulty_id = ?)`
|
||||
var c_rank_score, b_rank_score, a_rank_score, s_rank_score, c_rank_combo, b_rank_combo, a_rank_combo, s_rank_combo, ac_flag, swing_flag int
|
||||
err = ss.MainEng.DB().QueryRow(sql, difficultyId, difficultyId).Scan(&c_rank_score, &b_rank_score, &a_rank_score, &s_rank_score, &c_rank_combo, &b_rank_combo, &a_rank_combo, &s_rank_combo, &ac_flag, &swing_flag)
|
||||
unitsList := []liveschema.PlayRewardUnitList{}
|
||||
err = ss.UserEng.Table("user_deck_unit").
|
||||
Join("LEFT", "user_deck", "user_deck_unit.user_deck_id = user_deck.id").
|
||||
Where("user_deck.user_id = ? AND user_deck.deck_id = ?", ss.UserID, progress.DeckID).
|
||||
Find(&unitsList)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
key := "live_deck_" + strconv.Itoa(ss.UserID)
|
||||
deckId, err := db.Ldb.Get([]byte(key))
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
unitsList := []live.PlayRewardUnitList{}
|
||||
err = ss.UserEng.Table("user_deck_unit").Join("LEFT", "user_deck", "user_deck_unit.user_deck_id = user_deck.id").
|
||||
Where("user_id = ? AND deck_id = ?", ss.UserID, string(deckId)).Find(&unitsList)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
pref := user.UserPref{}
|
||||
pref := usermodel.UserPref{}
|
||||
_, err = ss.UserEng.Table("user_pref").Where("user_id = ?", ss.UserID).Get(&pref)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
totalScore := playRewardReq.ScoreSmile + playRewardReq.ScoreCool + playRewardReq.ScoreCute
|
||||
playResp := live.RewardResp{
|
||||
ResponseData: live.RewardData{
|
||||
LiveInfo: []live.RewardLiveInfo{
|
||||
playResp := liveschema.RewardResp{
|
||||
ResponseData: liveschema.RewardData{
|
||||
LiveInfo: []liveschema.RewardLiveInfo{
|
||||
{
|
||||
LiveDifficultyID: difficultyId,
|
||||
LiveDifficultyID: difficultyID,
|
||||
IsRandom: false,
|
||||
AcFlag: ac_flag,
|
||||
SwingFlag: swing_flag,
|
||||
AcFlag: liveInfo.AcFlag,
|
||||
SwingFlag: liveInfo.SwingFlag,
|
||||
},
|
||||
},
|
||||
TotalLove: 0,
|
||||
IsHighScore: true,
|
||||
HiScore: totalScore,
|
||||
BaseRewardInfo: live.BaseRewardInfo{
|
||||
BaseRewardInfo: liveschema.BaseRewardInfo{
|
||||
PlayerExp: 0,
|
||||
PlayerExpUnitMax: live.PlayerExpUnitMax{
|
||||
PlayerExpUnitMax: liveschema.PlayerExpUnitMax{
|
||||
Before: 0,
|
||||
After: 0,
|
||||
},
|
||||
PlayerExpFriendMax: live.PlayerExpFriendMax{
|
||||
PlayerExpFriendMax: liveschema.PlayerExpFriendMax{
|
||||
Before: 99,
|
||||
After: 99,
|
||||
},
|
||||
PlayerExpLpMax: live.PlayerExpLpMax{
|
||||
PlayerExpLpMax: liveschema.PlayerExpLpMax{
|
||||
Before: 417,
|
||||
After: 417,
|
||||
},
|
||||
@@ -85,72 +80,26 @@ func reward(ctx *gin.Context) {
|
||||
GameCoinRewardBoxFlag: false,
|
||||
SocialPoint: 0,
|
||||
},
|
||||
RewardUnitList: live.RewardUnitList{
|
||||
LiveClear: []live.LiveClear{},
|
||||
LiveRank: []live.LiveRank{},
|
||||
RewardUnitList: liveschema.RewardUnitList{
|
||||
LiveClear: []liveschema.LiveClear{},
|
||||
LiveRank: []liveschema.LiveRank{},
|
||||
LiveCombo: []any{},
|
||||
},
|
||||
UnlockedSubscenarioIds: []any{},
|
||||
UnlockedMultiUnitScenarioIds: []any{},
|
||||
EffortPoint: []live.EffortPoint{},
|
||||
EffortPoint: []liveschema.EffortPoint{},
|
||||
IsEffortPointVisible: false,
|
||||
LimitedEffortBox: []any{},
|
||||
UnitList: unitsList,
|
||||
BeforeUserInfo: live.BeforeUserInfo{
|
||||
Level: pref.UserLevel,
|
||||
Exp: 1089696,
|
||||
PreviousExp: 0,
|
||||
NextExp: 1207185,
|
||||
GameCoin: 999999999,
|
||||
SnsCoin: 10000,
|
||||
FreeSnsCoin: 50000,
|
||||
PaidSnsCoin: 50000,
|
||||
SocialPoint: 1438165,
|
||||
UnitMax: 5000,
|
||||
WaitingUnitMax: 1000,
|
||||
CurrentEnergy: 417,
|
||||
EnergyMax: 417,
|
||||
TrainingEnergy: 9,
|
||||
TrainingEnergyMax: 10,
|
||||
EnergyFullTime: "2023-03-20 01:28:55",
|
||||
LicenseLiveEnergyRecoverlyTime: 60,
|
||||
FriendMax: 99,
|
||||
TutorialState: -1,
|
||||
OverMaxEnergy: 417,
|
||||
UnlockRandomLiveMuse: 1,
|
||||
UnlockRandomLiveAqours: 1,
|
||||
},
|
||||
AfterUserInfo: live.AfterUserInfo{
|
||||
Level: pref.UserLevel,
|
||||
Exp: 1089696,
|
||||
PreviousExp: 0,
|
||||
NextExp: 1207185,
|
||||
GameCoin: 999999999,
|
||||
SnsCoin: 100000,
|
||||
FreeSnsCoin: 50000,
|
||||
PaidSnsCoin: 50000,
|
||||
SocialPoint: 1438375,
|
||||
UnitMax: 5000,
|
||||
WaitingUnitMax: 1000,
|
||||
CurrentEnergy: 417,
|
||||
EnergyMax: 417,
|
||||
TrainingEnergy: 9,
|
||||
TrainingEnergyMax: 10,
|
||||
EnergyFullTime: "2023-03-20 01:28:55",
|
||||
LicenseLiveEnergyRecoverlyTime: 60,
|
||||
FriendMax: 99,
|
||||
TutorialState: -1,
|
||||
OverMaxEnergy: 417,
|
||||
UnlockRandomLiveMuse: 1,
|
||||
UnlockRandomLiveAqours: 1,
|
||||
},
|
||||
NextLevelInfo: []live.NextLevelInfo{
|
||||
BeforeUserInfo: ss.GetUserInfo(),
|
||||
AfterUserInfo: ss.GetUserInfo(),
|
||||
NextLevelInfo: []liveschema.NextLevelInfo{
|
||||
{
|
||||
Level: pref.UserLevel,
|
||||
FromExp: 1089696,
|
||||
},
|
||||
},
|
||||
GoalAccompInfo: live.GoalAccompInfo{
|
||||
GoalAccompInfo: liveschema.GoalAccompInfo{
|
||||
AchievedIds: []any{},
|
||||
Rewards: []any{},
|
||||
},
|
||||
@@ -159,8 +108,8 @@ func reward(ctx *gin.Context) {
|
||||
DailyRewardInfo: []any{},
|
||||
CanSendFriendRequest: false,
|
||||
UsingBuffInfo: []any{},
|
||||
ClassSystem: live.ClassSystem{
|
||||
RankInfo: live.RewardRankInfo{
|
||||
ClassSystem: liveschema.ClassSystem{
|
||||
RankInfo: liveschema.RewardRankInfo{
|
||||
BeforeClassRankID: 10,
|
||||
AfterClassRankID: 10,
|
||||
RankUpDate: "2020-02-12 11:57:15",
|
||||
@@ -169,11 +118,11 @@ func reward(ctx *gin.Context) {
|
||||
IsOpened: true,
|
||||
IsVisible: true,
|
||||
},
|
||||
AccomplishedAchievementList: []live.AccomplishedAchievementList{},
|
||||
AccomplishedAchievementList: []liveschema.AccomplishedAchievementList{},
|
||||
UnaccomplishedAchievementCnt: 0,
|
||||
AddedAchievementList: []any{},
|
||||
MuseumInfo: live.Museum{},
|
||||
UnitSupportList: []live.RewardUnitSupportList{},
|
||||
MuseumInfo: liveschema.Museum{},
|
||||
UnitSupportList: []liveschema.RewardUnitSupportList{},
|
||||
ServerTimestamp: time.Now().Unix(),
|
||||
PresentCnt: 0,
|
||||
},
|
||||
@@ -181,30 +130,58 @@ func reward(ctx *gin.Context) {
|
||||
StatusCode: 200,
|
||||
}
|
||||
|
||||
if playRewardReq.MaxCombo > s_rank_combo {
|
||||
if playRewardReq.MaxCombo > liveInfo.SRankCombo {
|
||||
playResp.ResponseData.ComboRank = 1
|
||||
} else if playRewardReq.MaxCombo > a_rank_combo {
|
||||
} else if playRewardReq.MaxCombo > liveInfo.ARankCombo {
|
||||
playResp.ResponseData.ComboRank = 2
|
||||
} else if playRewardReq.MaxCombo > b_rank_combo {
|
||||
} else if playRewardReq.MaxCombo > liveInfo.BRankCombo {
|
||||
playResp.ResponseData.ComboRank = 3
|
||||
} else if playRewardReq.MaxCombo > c_rank_combo {
|
||||
} else if playRewardReq.MaxCombo > liveInfo.CRankCombo {
|
||||
playResp.ResponseData.ComboRank = 4
|
||||
} else {
|
||||
playResp.ResponseData.ComboRank = 5
|
||||
}
|
||||
|
||||
if totalScore > s_rank_score {
|
||||
if totalScore > liveInfo.SRankScore {
|
||||
playResp.ResponseData.Rank = 1
|
||||
} else if totalScore > a_rank_score {
|
||||
} else if totalScore > liveInfo.ARankScore {
|
||||
playResp.ResponseData.Rank = 2
|
||||
} else if totalScore > b_rank_score {
|
||||
} else if totalScore > liveInfo.BRankScore {
|
||||
playResp.ResponseData.Rank = 3
|
||||
} else if totalScore > c_rank_score {
|
||||
} else if totalScore > liveInfo.CRankScore {
|
||||
playResp.ResponseData.Rank = 4
|
||||
} else {
|
||||
playResp.ResponseData.Rank = 5
|
||||
}
|
||||
|
||||
// 判断歌曲记录是否需要保存或者更新
|
||||
liveSetting := playRewardReq.PreciseScoreLog.LiveSetting
|
||||
liveSetting.BackgroundID = ss.UserPref.BackgroundID
|
||||
if playRewardReq.PreciseScoreLog.IsLogOn && liveSetting.PreciseScoreAutoUpdateFlag {
|
||||
newLiveRecord := usermodel.UserLiveRecord{
|
||||
LiveDifficultyID: difficultyID,
|
||||
DeckID: progress.DeckID,
|
||||
TotalScore: totalScore,
|
||||
PerfectCnt: playRewardReq.PerfectCnt,
|
||||
GreatCnt: playRewardReq.GreatCnt,
|
||||
GoodCnt: playRewardReq.GoodCnt,
|
||||
BadCnt: playRewardReq.BadCnt,
|
||||
MissCnt: playRewardReq.MissCnt,
|
||||
MaxCombo: playRewardReq.MaxCombo,
|
||||
IsSkillOn: playRewardReq.PreciseScoreLog.IsSkillOn,
|
||||
LiveInfoJSON: utils.ToJSON(liveInfo),
|
||||
PreciseListJSON: utils.ToJSON(playRewardReq.PreciseScoreLog.PreciseList),
|
||||
DeckInfoJSON: utils.ToJSON(deckInfo),
|
||||
TapAdjust: playRewardReq.PreciseScoreLog.TapAdjust,
|
||||
LiveSettingJSON: utils.ToJSON(liveSetting),
|
||||
CanReplay: true,
|
||||
TriggerLogJSON: utils.ToJSON(playRewardReq.PreciseScoreLog.TriggerLog),
|
||||
UserID: ss.UserID,
|
||||
UpdateDate: time.Now().Format("2006-01-02 15:04:05"),
|
||||
}
|
||||
ss.UpdateUserLiveRecord(&newLiveRecord, liveSetting.PreciseScoreUpdateType)
|
||||
}
|
||||
|
||||
ss.Respond(playResp)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user