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:
+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