From 15f41d9380137ec0c666ef4bbeb99b695464ca9c Mon Sep 17 00:00:00 2001 From: Yuan Si Date: Fri, 21 Apr 2023 01:28:59 +0800 Subject: [PATCH] Add a simple extension to load llhelper deck info Signed-off-by: Yuan Si --- .gitignore | 1 + assets/partylist.json | 40 +++++++------- llhelper/helper.go | 119 ++++++++++++++++++++++++++++++++++++++++++ llhelper/model.go | 26 +++++++++ main.go | 1 + 5 files changed, 167 insertions(+), 20 deletions(-) create mode 100644 llhelper/helper.go create mode 100644 llhelper/model.go diff --git a/.gitignore b/.gitignore index 74c1e5e..b407a8b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,6 @@ data logs assets/data.db +assets/unit.sd .vscode diff --git a/assets/partylist.json b/assets/partylist.json index 8e9a2ff..4a0ffa9 100644 --- a/assets/partylist.json +++ b/assets/partylist.json @@ -4,40 +4,40 @@ { "user_info": { "user_id": 5762285, - "name": "\u840c\u840c\u5ba1\u795e\u8005", + "name": "SDS Nico", "level": 21 }, "center_unit_info": { "unit_owning_user_id": 1000880096808, - "unit_id": 855, - "exp": 4394, - "next_exp": 4560, - "level": 11, - "level_limit_id": 2, + "unit_id": 4001, + "exp": 79700, + "next_exp": 0, + "level": 100, + "level_limit_id": 1, "max_level": 100, "rank": 2, "max_rank": 2, - "love": 20, + "love": 1000, "max_love": 1000, - "unit_skill_level": 1, + "unit_skill_level": 8, "max_hp": 4, "favorite_flag": false, "display_rank": 2, - "unit_skill_exp": 0, - "unit_removable_skill_capacity": 4, - "attribute": 1, - "smile": 3540, - "cute": 2410, - "cool": 2870, - "is_love_max": false, - "is_level_max": false, + "unit_skill_exp": 29900, + "unit_removable_skill_capacity": 8, + "attribute": 2, + "smile": 7210, + "cute": 7870, + "cool": 7430, + "is_love_max": true, + "is_level_max": true, "is_rank_max": true, - "is_signed": false, - "is_skill_level_max": false, - "setting_award_id": 17, + "is_signed": true, + "is_skill_level_max": true, + "setting_award_id": 121, "removable_skill_ids": [] }, - "setting_award_id": 17, + "setting_award_id": 121, "available_social_point": 10, "friend_status": 1 }, diff --git a/llhelper/helper.go b/llhelper/helper.go new file mode 100644 index 0000000..e87af2d --- /dev/null +++ b/llhelper/helper.go @@ -0,0 +1,119 @@ +package llhelper + +import ( + "encoding/json" + "fmt" + "honoka-chan/config" + "honoka-chan/tools" + "honoka-chan/utils" + "os" +) + +var ( + unitFile = "assets/unit.sd" +) + +func CheckErr(err error) { + if err != nil { + panic(err) + } +} + +func init() { + LoadData() +} + +func LoadData() { + _, err := os.Stat(unitFile) + if err != nil { + fmt.Println(err) + return + } + data := Data{} + err = json.Unmarshal([]byte(utils.ReadAllText(unitFile)), &data) + CheckErr(err) + + session := config.UserEng.NewSession() + defer session.Close() + if err = session.Begin(); err != nil { + session.Rollback() + panic(err) + } + + for _, team := range data.Team { + fmt.Println(team.Cardid) + if team.Cardid == 0 { + continue + } + var unitId, unitExp, unitRarity, unitHp, unitSigned int + exists, err := config.MainEng.Table("common_unit_m").Join("LEFT", "unit_m", "common_unit_m.unit_id = unit_m.unit_id"). + Where("unit_m.unit_number = ?", team.Cardid). + Cols("common_unit_m.unit_id,common_unit_m.exp,unit_m.rarity,common_unit_m.max_hp,common_unit_m.is_signed"). + Get(&unitId, &unitExp, &unitRarity, &unitHp, &unitSigned) + CheckErr(err) + + if !exists { + panic("no such unit") + } + + if unitRarity != 4 { + panic("only support UR") + } + + var diffExp, diffSmile, diffPure, diffCool int + _, err = config.MainEng.Table("unit_level_limit_pattern_m").Where("unit_level_limit_id = 1 AND unit_level = 350"). + Cols("next_exp,smile_diff,pure_diff,cool_diff").Get(&diffExp, &diffSmile, &diffPure, &diffCool) + CheckErr(err) + + isSigned := false + if unitSigned == 1 { + isSigned = true + } + + var skillExp int + if team.Skilllevel != 8 { + skillExp = 0 + } else { + skillExp = 29900 + } + + unitData := tools.UnitData{ + UserID: 1681205441, // Replace with your own + UnitID: unitId, + Exp: unitExp + diffExp, + NextExp: 0, + Level: 350, + MaxLevel: 350, + LevelLimitID: 1, + Rank: 2, + MaxRank: 2, + Love: 1000, + MaxLove: 1000, + UnitSkillExp: skillExp, + UnitSkillLevel: team.Skilllevel, + MaxHp: unitHp, + UnitRemovableSkillCapacity: 8, + FavoriteFlag: false, + DisplayRank: 2, + IsRankMax: true, + IsLoveMax: true, + IsLevelMax: true, + IsSigned: isSigned, + IsSkillLevelMax: true, + IsRemovableSkillCapacityMax: true, + InsertDate: "2023-04-20 10:00:00", + } + + _, err = session.Table("user_unit_m").Insert(&unitData) + if err != nil { + session.Rollback() + panic(err) + } + fmt.Println("Insert ID:", unitData.UnitOwningUserID) + + if err = session.Commit(); err != nil { + session.Rollback() + panic(err) + } + } +} diff --git a/llhelper/model.go b/llhelper/model.go new file mode 100644 index 0000000..4245ff3 --- /dev/null +++ b/llhelper/model.go @@ -0,0 +1,26 @@ +package llhelper + +type Data struct { + Version int `json:"version"` + Team []Team `json:"team"` + Gemstock interface{} `json:"gemstock"` + Submember []interface{} `json:"submember"` +} + +type Accessory struct { + ID string `json:"id"` + Level int `json:"level"` +} + +type Team struct { + Hp int `json:"hp"` + Smile int `json:"smile"` + Pure int `json:"pure"` + Cool int `json:"cool"` + Skilllevel int `json:"skilllevel"` + Gemlist []string `json:"gemlist"` + Cardid int `json:"cardid"` + Mezame int `json:"mezame"` + Maxcost int `json:"maxcost"` + Accessory Accessory `json:"accessory,omitempty"` +} diff --git a/main.go b/main.go index 68d5304..39f6f7f 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "honoka-chan/config" "honoka-chan/handler" + _ "honoka-chan/llhelper" "honoka-chan/middleware" _ "honoka-chan/tools" "honoka-chan/xclog"