diff --git a/internal/handler/api.go b/internal/handler/api.go index ba312a9..41fe7d2 100644 --- a/internal/handler/api.go +++ b/internal/handler/api.go @@ -54,7 +54,8 @@ func Api(ctx *gin.Context) { switch v.Module { case "login": - if v.Action == "topInfo" { + switch v.Action { + case "topInfo": // key = "login_topinfo_result" topInfoResp := model.TopInfoResp{ Result: model.TopInfoRes{ @@ -91,7 +92,7 @@ func Api(ctx *gin.Context) { } res, err = json.Marshal(topInfoResp) utils.CheckErr(err) - } else if v.Action == "topInfoOnce" { + case "topInfoOnce": // key = "login_topinfo_once_result" topInfoOnceResp := model.TopInfoOnceResp{ Result: model.TopInfoOnceRes{ @@ -125,7 +126,8 @@ func Api(ctx *gin.Context) { utils.CheckErr(err) } case "live": - if v.Action == "liveStatus" { + switch v.Action { + case "liveStatus": // key = "live_status_result" var liveDifficultyId []int normalLives := []model.NormalLiveStatusList{} @@ -173,7 +175,7 @@ func Api(ctx *gin.Context) { } res, err = json.Marshal(LiveStatusResp) utils.CheckErr(err) - } else if v.Action == "schedule" { + case "schedule": // key = "live_list_result" var liveDifficultyId []int specialLives := []model.SpecialLiveStatusList{} @@ -216,7 +218,7 @@ func Api(ctx *gin.Context) { } res, err = json.Marshal(liveListResp) utils.CheckErr(err) - } else { + default: fmt.Println("Invalid action: ", v.Module, v.Action) } case "unit": @@ -419,16 +421,17 @@ func Api(ctx *gin.Context) { albumList.UnitID = unit.UnitId if unit.Rarity != 4 { albumList.SignFlag = false - if unit.Rarity == 1 { + switch unit.Rarity { + case 1: albumList.HighestLovePerUnit = 50 albumList.TotalLove = 50 - } else if unit.Rarity == 2 { + case 2: albumList.HighestLovePerUnit = 200 albumList.TotalLove = 200 - } else if unit.Rarity == 3 { + case 3: albumList.HighestLovePerUnit = 500 albumList.TotalLove = 500 - } else if unit.Rarity == 5 { + case 5: albumList.HighestLovePerUnit = 750 albumList.TotalLove = 750 } @@ -541,11 +544,12 @@ func Api(ctx *gin.Context) { } // HACK event_scenario_btn_asset - if id == 10001 { + switch id { + case 10001: eventList.EventScenarioBtnAsset = "assets/image/ui/eventscenario/38_se_ba_t.png" - } else if id == 221 { + case 221: eventList.EventScenarioBtnAsset = "assets/image/ui/eventscenario/215_se_ba_t.png" - } else { + default: eventList.EventScenarioBtnAsset = fmt.Sprintf("assets/image/ui/eventscenario/%d_se_ba_t.png", id) } @@ -726,7 +730,8 @@ func Api(ctx *gin.Context) { fmt.Println("Invalid action: ", v.Module, v.Action) } case "user": - if v.Action == "getNavi" { + switch v.Action { + case "getNavi": // key = "user_intro_result" var uId, oId int _, err := UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Cols("user_id,unit_owning_user_id").Get(&uId, &oId) @@ -744,7 +749,7 @@ func Api(ctx *gin.Context) { } res, err = json.Marshal(userIntroResp) utils.CheckErr(err) - } else if v.Action == "userInfo" { + case "userInfo": userId, err := strconv.Atoi(ctx.GetString("userid")) utils.CheckErr(err) @@ -793,7 +798,7 @@ func Api(ctx *gin.Context) { } res, err = json.Marshal(userInfoResp) utils.CheckErr(err) - } else { + default: fmt.Println("Invalid action: ", v.Module, v.Action) } case "navigation": @@ -1030,7 +1035,8 @@ func Api(ctx *gin.Context) { fmt.Println("Invalid action: ", v.Module, v.Action) } case "profile": - if v.Action == "liveCnt" { + switch v.Action { + case "liveCnt": // key = "profile_livecnt_result" difficultyResp := model.DifficultyResp{ Result: []model.DifficultyRes{ @@ -1061,7 +1067,7 @@ func Api(ctx *gin.Context) { } res, err = json.Marshal(difficultyResp) utils.CheckErr(err) - } else if v.Action == "cardRanking" { + case "cardRanking": // key = "profile_card_ranking_result" var result []any love := honokautils.ReadAllText("assets/serverdata/love.json") @@ -1075,7 +1081,7 @@ func Api(ctx *gin.Context) { } res, err = json.Marshal(loveResp) utils.CheckErr(err) - } else if v.Action == "profileInfo" { + case "profileInfo": // key = "profile_info_result" pref := tools.UserPref{} exists, err := UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Get(&pref) @@ -1236,7 +1242,7 @@ func Api(ctx *gin.Context) { } res, err = json.Marshal(profileResp) utils.CheckErr(err) - } else { + default: fmt.Println("Invalid action: ", v.Module, v.Action) } case "secretbox": diff --git a/internal/handler/lbonus.go b/internal/handler/lbonus.go index 9f01b5c..0247fa9 100644 --- a/internal/handler/lbonus.go +++ b/internal/handler/lbonus.go @@ -53,7 +53,7 @@ func LBonusExecute(ctx *gin.Context) { Amount: 1, }, }) - if c == d2 { + if c.Equal(d2) { break } } @@ -86,7 +86,7 @@ func LBonusExecute(ctx *gin.Context) { Amount: 1, }, }) - if c == d2 { + if c.Equal(d2) { break } } diff --git a/internal/handler/live.go b/internal/handler/live.go index f72959e..2ace580 100644 --- a/internal/handler/live.go +++ b/internal/handler/live.go @@ -161,11 +161,12 @@ func PlayLive(ctx *gin.Context) { // fmt.Println("回忆画廊属性加成后的基础属性:", baseSmile, basePure, baseCool) // 绊属性加成(该加成会影响个宝等百分比宝石属性加成的计算,故先计算。) - if attrId == 1 { + switch attrId { + case 1: baseSmile += maxLove - } else if attrId == 2 { + case 2: basePure += maxLove - } else if attrId == 3 { + case 3: baseCool += maxLove } // fmt.Println("绊属性加成:", maxLove) @@ -194,11 +195,12 @@ func PlayLive(ctx *gin.Context) { if fixedValueFlag == 1 { // 吻、眼神属性加成(固定数值) - if effectType == 1 { + switch effectType { + case 1: kissSmile += effectValue - } else if effectType == 2 { + case 2: kissPure += effectValue - } else if effectType == 3 { + case 3: kissCool += effectValue } // fmt.Println("吻、眼神属性加成:", kissSmile, kissPure, kissCool) @@ -207,11 +209,12 @@ func PlayLive(ctx *gin.Context) { if effectType == 1 || effectType == 2 || effectType == 3 { // 加成范围:2:全员 1:非全员 if effectRange == 2 { - if effectType == 1 { + switch effectType { + case 1: skillSmile += math.Ceil(baseSmile * (effectValue / 100)) - } else if effectType == 2 { + case 2: skillPure += math.Ceil(basePure * (effectValue / 100)) - } else if effectType == 3 { + case 3: skillCool += math.Ceil(baseCool * (effectValue / 100)) } // fmt.Println("全员类宝石属性加成:", skillSmile, skillPure, skillCool) @@ -255,11 +258,12 @@ func PlayLive(ctx *gin.Context) { Cols("unit_m.attribute_id,unit_leader_skill_m.effect_value").Get(&myAttrId, &myEffectValue) utils.CheckErr(err) var myCenterSmile, myCenterPure, myCenterCool float64 - if myAttrId == 1 { + switch myAttrId { + case 1: myCenterSmile = math.Ceil(smileMax * (myEffectValue / 100)) - } else if myAttrId == 2 { + case 2: myCenterPure = math.Ceil(pureMax * (myEffectValue / 100)) - } else if myAttrId == 3 { + case 3: myCenterCool = math.Ceil(coolMax * (myEffectValue / 100)) } // fmt.Println("主C技能属性加成:", myCenterSmile, myCenterPure, myCenterCool) @@ -278,11 +282,12 @@ func PlayLive(ctx *gin.Context) { utils.CheckErr(err) var mySubSmile, mySubPure, mySubCool float64 if exists { - if myAttrId == 1 { + switch myAttrId { + case 1: mySubSmile = math.Ceil(smileMax * (mySubEffectValue / 100)) - } else if myAttrId == 2 { + case 2: mySubPure = math.Ceil(pureMax * (mySubEffectValue / 100)) - } else if myAttrId == 3 { + case 3: mySubCool = math.Ceil(coolMax * (mySubEffectValue / 100)) } // fmt.Println("副C技能属性加成:", mySubSmile, mySubPure, mySubCool) @@ -310,11 +315,12 @@ func PlayLive(ctx *gin.Context) { Cols("unit_m.attribute_id,unit_leader_skill_m.effect_value").Get(&tomoAttrId, &tomoEffectValue) utils.CheckErr(err) var tomoCenterSmile, tomoCenterPure, tomoCenterCool float64 - if myAttrId == 1 { + switch myAttrId { + case 1: tomoCenterSmile = math.Ceil(smileMax * (tomoEffectValue / 100)) - } else if myAttrId == 2 { + case 2: tomoCenterPure = math.Ceil(pureMax * (tomoEffectValue / 100)) - } else if myAttrId == 3 { + case 3: tomoCenterCool = math.Ceil(coolMax * (tomoEffectValue / 100)) } // fmt.Println("好友主C技能属性加成:", tomoCenterSmile, tomoCenterPure, tomoCenterCool) @@ -333,11 +339,12 @@ func PlayLive(ctx *gin.Context) { utils.CheckErr(err) var tomoSubSmile, tomoSubPure, tomoSubCool float64 if exists { - if myAttrId == 1 { + switch myAttrId { + case 1: tomoSubSmile = math.Ceil(smileMax * (tomoSubEffectValue / 100)) - } else if myAttrId == 2 { + case 2: tomoSubPure = math.Ceil(pureMax * (tomoSubEffectValue / 100)) - } else if myAttrId == 3 { + case 3: tomoSubCool = math.Ceil(coolMax * (tomoSubEffectValue / 100)) } // fmt.Println("好友副C技能属性加成:", tomoSubSmile, tomoSubPure, tomoSubCool)