player.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. package model
  2. import (
  3. "fmt"
  4. "sort"
  5. "strconv"
  6. "time"
  7. "leafstalk/otherutils/deepcopy"
  8. "xorm.io/xorm"
  9. )
  10. const (
  11. MapValueMainChapterRankReward = "ChapterFirstPassed" //主线排名奖励
  12. MapValueCooperationRankReward = "CoopFirstPassed" //合作排名奖励
  13. MapValueChangedNickNum = "NickChanged" // 改名次数
  14. MapValueCreditScore = "CreditScore" // 信用积分
  15. MapValueRenown = "renown" //军衔 声望
  16. MapValueLoginDays = "loginDays" // 登录天数
  17. )
  18. const (
  19. StatsTypeRecritHeroCount = "recruitHero" // 招募英雄次数
  20. StatsTypeRecritTreasureCount = "recruitTreasure" // 招募宝物次数
  21. StatsTypeRecritLegendCount = "recruitLegend" // 招募铭文次数
  22. )
  23. type EnterRoomData struct {
  24. SyncRoomId int64 `json:"syncRoomId,string"`
  25. Seed int64 `json:"seed"`
  26. LevelId int64 `json:"chapterId"`
  27. Players []*EnterChapterDataItem `json:"players"`
  28. ArenasWear int64 `json:"arenasWear"` //当前游戏装配场景id -> 0 表示未装配 -> 装配玩家id
  29. GameSyncAddr string `json:"gameSyncAddr"`
  30. }
  31. type EnterChapterDataItem struct {
  32. PlayerId int64 `json:"userId"`
  33. HeadId int64 `json:"headId"`
  34. FrameId int64 `json:"frameId"`
  35. Nick string `json:"nick"`
  36. Heros map[int64]*Hero `json:"heros"`
  37. Fort *EntryDataFort `json:"fort"`
  38. Runes map[string]*BagRune `json:"runes"`
  39. Treasures map[int64]*GrowableTreasure `json:"treasures"`
  40. Emojis map[int64]struct{} `json:"emojis"`
  41. Resonances []*GrowableResonance `json:"resonances"`
  42. Renown int64 `json:"renown"`
  43. Arenas ClientArena `json:"arenas"`
  44. ArenaSkins map[int64]int64 `json:"arenaSkins"`
  45. Legend *LegendCalc `json:"legend"`
  46. }
  47. type ClientArena struct {
  48. Arenas map[int64]int64 `json:"arenas"` //场景id:星级
  49. Wear int64 `json:"wear"` //装配场景id
  50. Skills [3]int64 `json:"skill"` //装配技能对应的场景id
  51. }
  52. type EntryDataFort struct {
  53. Level int64 `json:"level"` //等级
  54. Parts [6]*FortPart `json:"parts"` //部位
  55. TalentTree [2]int64 `json:"talents"` //天赋树
  56. Skin *FortSkin `json:"skin"` //皮肤
  57. SkillIds [3]int64 `json:"skill"` //技能
  58. }
  59. type Hero struct {
  60. ID int64 `json:"id"`
  61. Level int64 `json:"level"` // 当等级=0时,表示英雄未解锁,可以拥有皮肤
  62. Wear int64 `json:"wear"`
  63. Skins []int64 `json:"skins"`
  64. }
  65. type FortSkin struct {
  66. Wear int64 `json:"wear"`
  67. Skins map[int64]int64 `json:"skins"` //皮肤id:星级
  68. }
  69. type LoginToken struct {
  70. AccId int64
  71. OpenId string
  72. Token string
  73. NickName string
  74. ImgUrl string
  75. GdtVid string // 进入所点击广告ID
  76. AdId string
  77. AdSrc string
  78. Flag int //用户标志
  79. Plat string
  80. PlatSessionKey string
  81. }
  82. type PlayerSummary struct {
  83. LineId int `json:"serverId"`
  84. Level int `json:"level"`
  85. }
  86. // Player 玩家信息
  87. type Player struct {
  88. Id int64
  89. AccId int64 `xorm:"BIGINT index 'accId'"`
  90. OpenID string `xorm:"varchar(255) index 'openid'"`
  91. NickName string `xorm:"varchar(255) 'nickname'" json:"nickName"`
  92. AvatarURL string `xorm:"varchar(512) 'avatar'" json:"avatarUrl"` // 目前由world维护 login储存
  93. Account string `xorm:"varchar(255) 'account'"`
  94. Passwod string `xorm:"varchar(255) 'password'" json:"-"`
  95. Inviter int64 `xorm:"BIGINT 'inviter'"`
  96. InviteServer int64 `xorm:"BIGINT 'inviteServer'"`
  97. PlatOpenID string `xorm:"varchar(255) 'platopenid'"`
  98. Unionid string `xorm:"varchar(255) 'unionid'"`
  99. Plat int `xorm:"int 'plat'"`
  100. SessionKey string `xorm:"varchar(512) 'sessionkey'"`
  101. SelectServer int `xorm:"int 'server'"` // 选择登录线
  102. Summary []*PlayerSummary `xorm:"varchar(1024) json 'summary'"` // 玩家在各服的档案信息
  103. Ban int `xorm:"int 'ban'"`
  104. Flag int `xorm:"default 0 int 'flag'"` //用户标记,老用户为0,新用户根据openid计算,奇数为1,偶数为0
  105. IDCard string `xorm:"varchar(255) 'idcard'"`
  106. RealName string `xorm:"varchar(255) 'name'"`
  107. BornTime int64 `xorm:"BIGINT 'borntime'"`
  108. GameTime int64 `xorm:"BIGINT 'gametime'"`
  109. GameTimeLen int `xorm:"int 'gametimelen'"`
  110. ClickId string `xorm:"varchar(255) 'clickId'"` // 进入所点击广告ID
  111. AdId string `xorm:"varchar(128) 'aId'"` //广告ID
  112. AdSrc string `xorm:"varchar(128) 'adSrc'"` //广告来源
  113. UpdateTime int64 `xorm:"'updated' updated"`
  114. CreateTime int64 `xorm:"'createtime' created" json:"createtime"`
  115. ClientVersion string `xorm:"varchar(255) 'clientVersion'"` // 客户端储存的验证版本相关信息 服务器只做储存 客户端不会发 ;
  116. TableNo int `xorm:"-"`
  117. }
  118. // TableName 表名
  119. func (player *Player) TableName() string {
  120. if player.TableNo > 0 {
  121. return fmt.Sprintf("user_account_%v", player.TableNo)
  122. }
  123. return "user_account"
  124. }
  125. func (p *Player) GlobalId() int64 {
  126. return p.AccId
  127. }
  128. func (p *Player) Key() string {
  129. if len(p.OpenID) > 0 {
  130. return p.OpenID
  131. }
  132. if len(p.Account) > 0 {
  133. return fmt.Sprintf("%v@%v", p.Account, LoginPlatAccount)
  134. }
  135. return fmt.Sprintf("%v@%v", "test", LoginPlatAccount)
  136. }
  137. // 成长性英雄
  138. type GrowableHero struct {
  139. // ID int64 `json:"id"`
  140. Level int64 `json:"level"`
  141. Skin int64 `json:"wear"`
  142. }
  143. type HeroShow struct {
  144. ID int64 `json:"id"`
  145. Level int64 `json:"level"`
  146. Skin int64 `json:"wear"`
  147. }
  148. // // 要塞时装(皮肤)
  149. // type FortSkin struct {
  150. // Wear int64 `json:"wear"`
  151. // Skins map[int64]struct{} `json:"skins"` //皮肤星级id:
  152. // }
  153. // func (fs *GrowableFort) FindStarSkinByModeId(modelId int64) int64 {
  154. // for starId := range fs.Skins {
  155. // if starId/100 == modelId {
  156. // return starId
  157. // }
  158. // }
  159. // return 0
  160. // }
  161. // func (fs *GrowableFort) HasStarSkin(skinId int64) bool {
  162. // _, ok := fs.Skins[skinId]
  163. // return ok
  164. // }
  165. // func (fs *GrowableFort) GetSkinModeIds() []int64 {
  166. // var lst []int64
  167. // for starId, _ := range fs.Skins {
  168. // lst = append(lst, starId/100)
  169. // }
  170. // return lst
  171. // }
  172. func FortSkinStarIdToSkinId(skinStarId int64) int64 {
  173. return skinStarId / 100
  174. }
  175. func FortSkinIdToStarId(skinId int64, level int64) int64 {
  176. return (skinId*100 + level)
  177. }
  178. // 要塞部位
  179. type FortPart struct {
  180. Level int64 `json:"level"` //部位等级
  181. WearRune int64 `json:"wear,string"` //部位镶嵌的符文
  182. }
  183. // 部位展示
  184. type PartShow struct {
  185. Pos int64 `json:"pos"` // 部位
  186. Level int64 `json:"level"` // 部位等级
  187. Rune int64 `json:"rune"` // 符文模型ID
  188. }
  189. // 要塞
  190. type GrowableFort struct {
  191. Level int64 `json:"level"` //等级
  192. Parts [6]*FortPart `json:"parts"` //部位
  193. TalentTree [2]int64 `json:"talents"` //天赋树
  194. WearSkin int64 `json:"wear"`
  195. SkillIds [3]int64 `json:"skill"` //技能对应的皮肤ID 不时星级ID
  196. // Skins map[int64]int64 `json:"skins"` //皮肤id:星级
  197. // Skin *FortSkin `json:"skin"` //皮肤
  198. }
  199. // 场景
  200. type GrowableArena struct {
  201. // Arenas map[int64]int64 `json:"arenas"` //场景id:星级
  202. Wear int64 `json:"wear"` //装配场景id
  203. Skills [3]int64 `json:"skill"` //装配技能对应的场景id
  204. }
  205. func NewGrowableArena() *GrowableArena {
  206. it := new(GrowableArena)
  207. // it.FortArenas = make(map[int64]int64)
  208. return it
  209. }
  210. // type DropMaterial struct {
  211. // MaterialData map[int64]*MaterialData `json:"materialData"`
  212. // }
  213. type HeadFrame struct {
  214. HeadId int64 `json:"headId"` // 头像 -1 代表使用 AvatarURL 微信授权头像
  215. FrameId int64 `json:"frameId"` // 头像框
  216. HIdEndTs int64 `json:"hEndTs"` // 头像结束时间 -1 无限制
  217. FIdEndTs int64 `json:"fEndTs"` // 头像框结束时间
  218. }
  219. type RuneAffix struct {
  220. Type int64 `json:"typ"`
  221. Value float64 `json:"val"`
  222. }
  223. type RuneAffixAndPos struct {
  224. *RuneAffix //`json:"runeAffix"` //
  225. Pos int `json:"pos"` //
  226. }
  227. type RuneRecastAttr struct {
  228. Gid int64
  229. Ts int64
  230. Items []*RuneAffixAndPos
  231. }
  232. // 符文
  233. type BagRune struct {
  234. ModeId int64 `json:"id"`
  235. Attrs []*RuneAffix `json:"attrs,omitempty"` // 附加属性 [几条属性][属性类型,值]
  236. // WearPos int64 `json:"pos,omitempty"` // 穿戴位置
  237. }
  238. // type ClientBagRune struct {
  239. // ModeId int64 `json:"id"`
  240. // Attrs []*RuneAffix `json:"attrs,omitempty"` // 附加属性 [几条属性][属性类型,值]
  241. // // WearPos int64 `json:"pos,omitempty"` // 穿戴位置
  242. // }
  243. type DropedRune struct {
  244. *BagRune
  245. GId int64 `json:"gId"`
  246. }
  247. func NewChapterSummary() *ChapterSummary {
  248. it := new(ChapterSummary)
  249. it.Process = make([]*ChapterProcess, 0, 1)
  250. it.Levels = make(map[int64]*LevelSummary)
  251. return it
  252. }
  253. type ChapterSummary struct {
  254. Process []*ChapterProcess `json:"process"`
  255. Levels map[int64]*LevelSummary `json:"levels"`
  256. }
  257. func NewChapterProcess2(typ int64) *ChapterProcess {
  258. it := new(ChapterProcess)
  259. it.Type = typ
  260. return it
  261. }
  262. type ChapterProcess struct {
  263. Type int64 `json:"type"`
  264. Chapter int64 `json:"chapter"`
  265. Level int64 `json:"level"`
  266. Wave int64 `json:"wave"`
  267. Passed int64 `json:"passed"`
  268. }
  269. func NewLevelSummary() *LevelSummary {
  270. it := new(LevelSummary)
  271. return it
  272. }
  273. type LevelSummary struct {
  274. // Level int64 `json:"id"`
  275. Wave int64 `json:"wave"`
  276. Geted int64 `json:"geted"`
  277. SubWave int64 `json:"subWave"`
  278. SubGeted int64 `json:"subGeted"`
  279. JoinTs int64 `json:"joinTs"`
  280. }
  281. type ChapterProcess2 struct {
  282. ChapterLevels map[int64][2]int64 `json:"cl"` //已解锁的章节关卡 章节[小章节ID,是否已通关?1:0]
  283. LevelWaves map[int64]*LevelSummary `json:"levels"` //需要处理的关卡进度及奖励 关卡编号[大章节ID,关卡ID,首次通过波数,首通奖励领取到的波次,循环通过的波次,循环奖励领取到的波次,循环波次完成时间]
  284. // Chapter int64 `json:"id"` //大章节ID
  285. // Level int64 `json:"lv"` //关卡 1,2,3,。。
  286. // First [2]int `json:"fw"` //首次通过波数 [首次通过波数,首次奖励领取到的波次]
  287. // Cycle [2]int `json:"cw"` //循环通过的波次 [循环通过的波次,循环奖励领取到的波次]
  288. // FirstReward int64 `json:"fr"` //首通奖励领取到的波次
  289. // CycleWave int64 `json:"cw"` //循环通过的波次
  290. // CycleReward int64 `json:"cr"` //循环奖励领取到的波次
  291. // Chpater int64 `json:"id"` //关卡ID
  292. // Door int64 `json:"door"` //关卡门
  293. // FirstWave int64 `json:"fw"` //首次通过波数
  294. // FirstReward int64 `json:"fr"` //首通奖励领取到的波次
  295. // CycleWave int64 `json:"cw"` //循环通过的波次
  296. // CycleReward int64 `json:"cr"` //循环奖励领取到的波次
  297. // FirstPass int64 `json:"pass"` //是否通关
  298. }
  299. // type WaveAndReward struct {
  300. // Wave int64 `json:"w"` //首次通过波数
  301. // Reward int64 `json:"r"` //首通奖励领取到的波次
  302. // }
  303. type ChapterLevel2 struct {
  304. First [2]int64 `json:"fw"` //首次通过波数 [首次通过波数,首次奖励领取到的波次]
  305. Normal [2]int64 `json:"nw"` //循环通过的波次 [循环通过的波次,循环奖励领取到的波次]
  306. JoinTs int64 `json:"js"` //循环波次完成时间
  307. // Chapter int64 `json:"id"` //大章节ID
  308. // Level int64 `json:"lv"` //关卡 1,2,3,。。
  309. // Chapter int64 `json:"id"` //关卡ID
  310. // Level int64 `json:"lv"` //关卡
  311. // FirstWave int64 `json:"fw"` //首次通过波数
  312. // FirstReward int64 `json:"fr"` //首通奖励领取到的波次
  313. // CycleWave int64 `json:"cw"` //循环通过的波次
  314. // CycleReward int64 `json:"cr"` //循环奖励领取到的波次
  315. // CycleTs int64 `json:"ts"` //循环波次完成时间
  316. // // FirstPass int64 `json:"pass"` //是否通关
  317. }
  318. // 宝物
  319. type GrowableTreasure struct {
  320. Level int64 `json:"level"` // 等级
  321. Star int64 `json:"star"` // 星级
  322. }
  323. type TreasureShow struct {
  324. Id int64 `json:"id"` // 宝物id
  325. Level int64 `json:"level"` // 等级
  326. Star int64 `json:"star"` // 星级
  327. }
  328. type RecruitStatis struct {
  329. HeroNum int64 `json:"heroNum"` // 英雄招募次数(暗保底使用,触发暗保底后会清0)
  330. TreasureNum [2]int64 `json:"treasureNum"` // 宝物招募次数(暗保底使用,触发暗保底后会清0) 10次保底和500次保底
  331. LegendNum [2]int64 `json:"epigraphNum"` // 铭文招募次数(暗保底使用,触发暗保底后会清0) 10次保底和500次保底
  332. }
  333. type RecoverItem struct {
  334. ItemId int64 `json:"itemId"`
  335. LastRecoverTs int64 `json:"lastStamTick"` // 开始恢复的时间
  336. DayBuyTs int64 `json:"dayStamTick"` // 购买时间
  337. DayBuyCount int `json:"dayStamBuyCount"` // 今日购买次数
  338. DayAdCount int `json:"adStamCount"` // 今日使用免费次数
  339. // Stamina int `json:"stamina"` // 当前体力 放背包
  340. }
  341. func NewRecoverItem(recoverId int64) *RecoverItem {
  342. recoveritem := new(RecoverItem)
  343. recoveritem.ItemId = recoverId
  344. recoveritem.LastRecoverTs = time.Now().Unix()
  345. recoveritem.DayBuyTs = 0
  346. recoveritem.DayBuyCount = 0
  347. recoveritem.DayAdCount = 0
  348. return recoveritem
  349. }
  350. // type RecoverItem2 struct {
  351. // // Stamina int `json:"stamina"` // 当前体力 放背包
  352. // LastStamTick int64 `json:"lastStamTick"` // 生效时间
  353. // DayStamTick int64 `json:"dayStamTick"` // 购买时间
  354. // DayStamBuyCount int `json:"dayStamBuyCount"` // 今日购买次数
  355. // AdStamCount int `json:"adStamCount"` // 今日使用免费次数
  356. // LastEnergyTick int64 `json:"lastEnergyTick"` // 精力生效时间
  357. // DayEnergyTick int64 `json:"dayEnergyTick"` // 精力购买时间
  358. // DayEnergyBuyCount int `json:"dayEnergyBuyCount"` // 今日精力购买次数
  359. // AdEnergyCount int `json:"adEnergyCount"` // 今日精力使用免费次数
  360. // }
  361. type GrowableResonance struct {
  362. Faction int64 `json:"faction"` //阵营
  363. Level int64 `json:"level"` //等级
  364. Slots []*ResonanceSlot `json:"heros"` //英雄
  365. }
  366. func NewGrowableResonance(faction int64) *GrowableResonance {
  367. return &GrowableResonance{
  368. Faction: faction,
  369. Slots: make([]*ResonanceSlot, 0),
  370. }
  371. }
  372. type ResonanceSlot struct {
  373. Pos int `json:"pos"` //位置
  374. HeroId int64 `json:"heroId"` //英雄ID
  375. RemoveTs int64 `json:"removeTs"` //移除时间
  376. }
  377. //type BagLegendItem struct {
  378. // ModeId int64 `json:"id"`
  379. // SlotId int64 `json:"slotId"`
  380. //}
  381. type GrowableLegend struct {
  382. Level int64 `json:"level"` // 精通等级
  383. SlotWear map[int64]int64 `json:"slotWear"` // {slotId:modelId}
  384. // Legends map[int64]int64 `json:"legends"` // {modelId:num}
  385. }
  386. func NewGrowableLegend() *GrowableLegend {
  387. return &GrowableLegend{
  388. // Legends: make(map[int64]int64),
  389. SlotWear: make(map[int64]int64),
  390. }
  391. }
  392. type LegendCalc struct {
  393. Level int64 `json:"level"` // 精通等级
  394. SlotWear map[int64]int64 `json:"legends"` // {slotId:modelId}
  395. }
  396. const (
  397. // GameStatusLogin = int64(1)
  398. GameStatusChapterMatch = int64(2)
  399. // GameStatusLogout = int64(3)
  400. )
  401. // type GameSetting struct {
  402. // Bgm bool `json:"bgm"`
  403. // BgSound bool `json:"bgSound"`
  404. // DamageFloatText bool `json:"damageFloatText"`
  405. // }
  406. type GamePlayer struct {
  407. Id int64 //`xorm:"BIGINT pk autoincr 'id'"`
  408. PlayerId int64 `xorm:"BIGINT index 'playerid'"`
  409. AccId int64 `xorm:"BIGINT index(serveracc) 'accId'"`
  410. LineId int64 `xorm:"int index(serveracc) 'line'"`
  411. Level int64 `xorm:"int 'level'"`
  412. Exp int64 `xorm:"BIGINT 'exp'"`
  413. LastLoginTick int64 `xorm:"BIGINT 'lastlogintick'"`
  414. LastLogoutTick int64 `xorm:"BIGINT 'lastlogouttick'"`
  415. OpenId string `xorm:"VARCHAR(255) 'openId'"`
  416. NickName string `xorm:"VARCHAR(255) index 'nickName'"`
  417. ImgUrl string `xorm:"VARCHAR(512) 'imgUrl'"`
  418. HeadId int64 `xorm:"int 'headId'"` // 头像 -1 代表使用 AvatarURL 微信授权头像
  419. HeadFrameId int64 `xorm:"int 'frameId'"` // 头像框
  420. CreateTime time.Time `xorm:"created"`
  421. Ban int `xorm:"int 'ban'"`
  422. AdId string `xorm:"VARCHAR(128) 'adId'"`
  423. ClickId string `xorm:"VARCHAR(255) 'clickId'"`
  424. AdSrc string `xorm:"VARCHAR(128) 'adSrc'"`
  425. Plat string `xorm:"VARCHAR(20) 'plat'"` // wx tt
  426. SubPlat int `xorm:"int default 0 subPlat"` // 1 抖音; 2 抖音极速
  427. Flag int `xorm:"int 'flag'"` //标记
  428. SessionKey string `xorm:"-"` // 小游戏登录凭证
  429. GateId int64 `xorm:"-"` // 所在网关
  430. Online bool `xorm:"-"` // 在线状态 上线 下线
  431. GameState int64 `xorm:"-"` // 游戏状态 匹配状态
  432. GameSyncRoomId int64 `xorm:"BIGINT 'gameSyncRoomId'"` // 游戏同步房间id
  433. GameSyncData *EnterRoomData `xorm:"-"`
  434. Materials map[int64]int64 `xorm:"Text 'materials'"` // 道具
  435. Heros map[int64]*GrowableHero `xorm:"Text json 'heros'"` // 英雄
  436. HeroSkins map[int64]struct{} `xorm:"Text json 'heroSkins'"` // 英雄皮肤,玩家可以不拥有英雄却拥有皮肤。所以单独记录。
  437. Fort *GrowableFort `xorm:"Text json 'fort'"` //时装
  438. FortSkins map[int64]int64 `xorm:"Text 'fortSkins'"` //皮肤id:星级
  439. Runes map[int64]*BagRune `xorm:"MEDIUMTEXT 'runes'"` //符文
  440. Chapters *ChapterSummary `xorm:"Text json 'chapters'"` //章节进度
  441. Treasures map[int64]*GrowableTreasure `xorm:"Text json 'treasures'"` // 宝物
  442. Recruit *RecruitStatis `xorm:"Text json 'recruit'"` // 招募
  443. RuneRecast *RuneRecastAttr `xorm:"Text json 'recast'"` //符文重铸
  444. Crystals map[int64]int64 `xorm:"Text 'crystal'"` //水晶 [水晶id]领取过奖励
  445. Recovers []*RecoverItem `xorm:"Text json 'recovers'"` // 体力 精力信息
  446. CoopTickets map[int64]int64 `xorm:"Text json 'coopTickets'"` // 作战卷轴 【卷轴ID】开始恢复时间
  447. Arenas *GrowableArena `xorm:"Text json 'arena'"` //场景
  448. ArenaSkins map[int64]int64 `xorm:"Text 'arenaSkins'"` //场景id:星级
  449. Resonances []*GrowableResonance `xorm:"Text json 'resonance'"` //共鸣
  450. LegendFoster *GrowableLegend `xorm:"Text json 'legendFoster'"` // 铭文
  451. Legends map[int64]int64 `xorm:"Text legends"` // {modelId:num}
  452. Heads map[int64]struct{} `xorm:"Text heads"` //头像
  453. HeadFrames map[int64]struct{} `xorm:"Text headFrames"` //头像框
  454. Emojis map[int64]struct{} `xorm:"Text emojis"` //聊天表情
  455. MapValues map[string]int64 `xorm:"Text states"` // 各种游戏状态, 见MapValueXXX
  456. Statistics map[string]int64 `xorm:"Text stats"` // 玩家统计信息
  457. Cards *CardActivity `xorm:"Text json 'cards'"` // 精彩活动
  458. ShareReward *EnterShareReward `xorm:"Text json 'shareReward'"` // 分享奖励
  459. AdInvite *InviteSummary `xorm:"Text json 'inviteSummary'"` // 推广邀请奖励
  460. OffLineStat *OffLineSummary `xorm:"Text json 'offLineStat'"` // 离线时长统计
  461. // GameSetting *GameSetting `xorm:"Text json 'gameSetting'"` //游戏设置
  462. // WearRunes map[int64]struct{} `xorm:"-"` //穿戴的符文[符文类型]符文id
  463. // StaminaInfo *StaminaData `xorm:"Text json 'stamina'"` // 体力信息
  464. }
  465. type EnterShareReward struct {
  466. AddToDesk int `json:"addToDesk"` // 添加奖励
  467. LastLaunchTs int64 `json:"lastLaunchTs"` // 最后领取侧边栏进入奖励的时间
  468. LastShareTs int64 `json:"lastShareTs"` // 最后分享视频的时间
  469. ShareCount int64 `json:"shareCount"` // 当天分享次数
  470. }
  471. type InviteSummary struct {
  472. Num int64 `json:"num"` // 邀请次数
  473. Reward int64 `json:"reward"` // 邀请奖励
  474. }
  475. type OffLineSummary struct {
  476. CalcTs int64 `json:"calcTs"` // 计算今日离线时间
  477. OffLineTl int64 `json:"offLineTs"` //今日离线时长
  478. YesterdayOffLineTl int64 `json:"offLineTime"` //昨日离线时长
  479. }
  480. func NewCardActivity() *CardActivity {
  481. return &CardActivity{
  482. MonthCards: &MonthCards{
  483. DailyRewardTs: 0,
  484. Cards: make(map[int64]*MonthCardItem),
  485. },
  486. PrivilegeCards: make(map[int64]int64),
  487. }
  488. }
  489. // 精彩活动
  490. type CardActivity struct {
  491. MonthCards *MonthCards `json:"monthCards"` // 月卡
  492. PrivilegeCards map[int64]int64 `json:"privilegeCards"` // 特权卡[类型:购买时间]
  493. }
  494. type MonthCards struct {
  495. DailyRewardTs int64 `json:"dailyRewardTs"` // 每日福利领取时间
  496. Cards map[int64]*MonthCardItem `json:"cards"` // 月卡状态
  497. }
  498. type MonthCardItem struct {
  499. // 购买时间
  500. BuyTs int64 `json:"buyTs"`
  501. // 今日奖励领取时间
  502. TodayRewardTs int64 `json:"todayRewardTs"`
  503. }
  504. func (m GamePlayer) TableName() string {
  505. return "player_attr"
  506. }
  507. func (m *GamePlayer) QueryExist(eng *xorm.Engine) (bool, error) {
  508. player := new(GamePlayer)
  509. player.PlayerId = m.PlayerId
  510. return eng.Exist(player)
  511. }
  512. func (m *GamePlayer) UpdateDB(eng *xorm.Engine) (int64, error) {
  513. return eng.Where("playerid=?", m.PlayerId).MustCols("stamina", "lastStamTick").Update(m)
  514. }
  515. func (m *GamePlayer) GetUniqueKey() string {
  516. return strconv.FormatInt(m.PlayerId, 10)
  517. }
  518. func (t *GamePlayer) GetUniqueIntKey() int64 {
  519. return t.PlayerId
  520. }
  521. func (t *GamePlayer) GetRuneShow() []PartShow {
  522. its := make([]PartShow, 6)
  523. if t.Fort == nil {
  524. for i := range 6 {
  525. its[i].Pos = int64(i)
  526. }
  527. return its
  528. }
  529. for k, v := range t.Fort.Parts {
  530. its[k].Pos = int64(k)
  531. its[k].Level = v.Level
  532. if wr, ok := t.Runes[v.WearRune]; ok {
  533. its[k].Rune = wr.ModeId
  534. }
  535. }
  536. return its
  537. }
  538. func (t *GamePlayer) GetHeroShow() []*HeroShow {
  539. lst := make([]*HeroShow, 0)
  540. for k, v := range t.Heros {
  541. if !IsMythicHero(k) {
  542. continue
  543. }
  544. it := new(HeroShow)
  545. it.ID = k
  546. it.Level = v.Level
  547. it.Skin = v.Skin
  548. lst = append(lst, it)
  549. }
  550. sort.Sort(HeroShowList(lst))
  551. return lst
  552. }
  553. func (t *GamePlayer) GetTreasureShow() []*TreasureShow {
  554. lst := make([]*TreasureShow, 0)
  555. for k, v := range t.Treasures {
  556. if !IsMythicTreasure(k) {
  557. continue
  558. }
  559. it := new(TreasureShow)
  560. it.Id = k
  561. it.Level = v.Level
  562. it.Star = v.Star
  563. lst = append(lst, it)
  564. }
  565. sort.Sort(TreasureShowList(lst))
  566. return lst
  567. }
  568. // func (t *GamePlayer) GetRuneCalc() int64 {
  569. // return t.PlayerId
  570. // }
  571. // 实现DeepCopy接口
  572. func CopyGamePlayer(old *GamePlayer) *GamePlayer {
  573. new2, err := deepcopy.Copy(old) //
  574. if err != nil {
  575. return nil
  576. }
  577. return new2.(*GamePlayer)
  578. }
  579. func (t *GamePlayer) SetGameState(status int64) int64 {
  580. old := t.GameState
  581. t.GameState = status
  582. return old
  583. }
  584. // 上下线状态
  585. func (t *GamePlayer) SetOnlineState(online bool) {
  586. t.Online = online
  587. if !online {
  588. fmt.Println("玩家下线")
  589. }
  590. }
  591. func (t *GamePlayer) IsOnline() bool {
  592. return t.Online
  593. }
  594. // 需要保存的数据需确保在这里能复制到new1 中
  595. // func (m *GamePlayer) DeepCopy() interface{} {
  596. // new1 := new(GamePlayer)
  597. // *new1 = *m
  598. // return new1
  599. // }
  600. func GetRecoverItem(user *GamePlayer, recoverId int64) *RecoverItem {
  601. var recoveritem *RecoverItem
  602. for _, it := range user.Recovers {
  603. if it.ItemId == recoverId {
  604. recoveritem = it
  605. }
  606. }
  607. return recoveritem
  608. }
  609. // 获取关卡进度
  610. func FindChapterProcess(process []*ChapterProcess, typ int64) *ChapterProcess {
  611. for _, v := range process {
  612. if v.Type == typ {
  613. return v
  614. }
  615. }
  616. return nil
  617. }
  618. type HeroShowList []*HeroShow
  619. func (m HeroShowList) Len() int { return len(m) }
  620. func (m HeroShowList) Swap(i, j int) { m[i], m[j] = m[j], m[i] }
  621. func (m HeroShowList) Less(i, j int) bool {
  622. if m[i].Level < m[j].Level {
  623. return true
  624. } else if m[i].Level > m[j].Level {
  625. return false
  626. } else {
  627. return m[i].ID < m[j].ID
  628. }
  629. }
  630. type TreasureShowList []*TreasureShow
  631. func (m TreasureShowList) Len() int { return len(m) }
  632. func (m TreasureShowList) Swap(i, j int) { m[i], m[j] = m[j], m[i] }
  633. func (m TreasureShowList) Less(i, j int) bool {
  634. if m[i].Star < m[j].Star {
  635. return true
  636. } else if m[i].Star > m[j].Star {
  637. return false
  638. } else {
  639. return m[i].Id < m[j].Id
  640. }
  641. }