player.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. package model
  2. import (
  3. "fmt"
  4. "strconv"
  5. "time"
  6. "leafstalk/otherutils/deepcopy"
  7. "xorm.io/xorm"
  8. )
  9. type LoginToken struct {
  10. AccId int64
  11. OpenId string
  12. Token string
  13. NickName string
  14. ImgUrl string
  15. GdtVid string // 进入所点击广告ID
  16. AdId string
  17. AdSrc string
  18. Flag int //用户标志
  19. Plat string
  20. }
  21. type PlayerSummary struct {
  22. LineId int `json:"serverId"`
  23. Level int `json:"level"`
  24. }
  25. // Player 玩家信息
  26. type Player struct {
  27. Id int64
  28. AccId int64 `xorm:"BIGINT index 'accId'"`
  29. OpenID string `xorm:"varchar(255) index 'openid'"`
  30. NickName string `xorm:"varchar(255) 'nickname'" json:"nickName"`
  31. AvatarURL string `xorm:"varchar(512) 'avatar'" json:"avatarUrl"` // 目前由world维护 login储存
  32. Account string `xorm:"varchar(255) 'account'"`
  33. Passwod string `xorm:"varchar(255) 'password'" json:"-"`
  34. Inviter int64 `xorm:"BIGINT 'inviter'"`
  35. PlatOpenID string `xorm:"varchar(255) 'platopenid'"`
  36. Unionid string `xorm:"varchar(255) 'unionid'"`
  37. Plat int `xorm:"int 'plat'"`
  38. SessionKey string `xorm:"varchar(512) 'sessionkey'"`
  39. SelectServer int `xorm:"int 'server'"` // 选择登录线
  40. Summary []*PlayerSummary `xorm:"varchar(1024) json 'summary'"` // 玩家在各服的档案信息
  41. Ban int `xorm:"int 'ban'"`
  42. Flag int `xorm:"default 0 int 'flag'"` //用户标记,老用户为0,新用户根据openid计算,奇数为1,偶数为0
  43. IDCard string `xorm:"varchar(255) 'idcard'"`
  44. RealName string `xorm:"varchar(255) 'name'"`
  45. BornTime int64 `xorm:"BIGINT 'borntime'"`
  46. GameTime int64 `xorm:"BIGINT 'gametime'"`
  47. GameTimeLen int `xorm:"int 'gametimelen'"`
  48. ClickId string `xorm:"varchar(255) 'clickId'"` // 进入所点击广告ID
  49. AdId string `xorm:"varchar(128) 'aId'"` //广告ID
  50. AdSrc string `xorm:"varchar(128) 'adSrc'"` //广告来源
  51. UpdateTime int64 `xorm:"'updated' updated"`
  52. CreateTime int64 `xorm:"'createtime' created" json:"createtime"`
  53. ClientVersion string `xorm:"varchar(255) 'clientVersion'"` // 客户端储存的验证版本相关信息 服务器只做储存 客户端不会发 ;
  54. TableNo int `xorm:"-"`
  55. }
  56. // TableName 表名
  57. func (player *Player) TableName() string {
  58. if player.TableNo > 0 {
  59. return fmt.Sprintf("user_account_%v", player.TableNo)
  60. }
  61. return "user_account"
  62. }
  63. func (p *Player) GlobalId() int64 {
  64. return p.AccId
  65. }
  66. func (p *Player) Key() string {
  67. if len(p.OpenID) > 0 {
  68. return p.OpenID
  69. }
  70. if len(p.Account) > 0 {
  71. return fmt.Sprintf("%v@%v", p.Account, LoginPlatAccount)
  72. }
  73. return fmt.Sprintf("%v@%v", "test", LoginPlatAccount)
  74. }
  75. // 成长性英雄
  76. type GrowableHero struct {
  77. // ID int64 `json:"id"`
  78. Level int64 `json:"level"`
  79. Skin int64 `json:"wear"`
  80. }
  81. // // 要塞时装(皮肤)
  82. // type FortSkin struct {
  83. // Wear int64 `json:"wear"`
  84. // Skins map[int64]struct{} `json:"skins"` //皮肤星级id:
  85. // }
  86. // func (fs *GrowableFort) FindStarSkinByModeId(modelId int64) int64 {
  87. // for starId := range fs.Skins {
  88. // if starId/100 == modelId {
  89. // return starId
  90. // }
  91. // }
  92. // return 0
  93. // }
  94. // func (fs *GrowableFort) HasStarSkin(skinId int64) bool {
  95. // _, ok := fs.Skins[skinId]
  96. // return ok
  97. // }
  98. // func (fs *GrowableFort) GetSkinModeIds() []int64 {
  99. // var lst []int64
  100. // for starId, _ := range fs.Skins {
  101. // lst = append(lst, starId/100)
  102. // }
  103. // return lst
  104. // }
  105. func FortSkinStarIdToSkinId(skinStarId int64) int64 {
  106. return skinStarId / 100
  107. }
  108. func FortSkinIdToStarId(skinId int64, level int64) int64 {
  109. return (skinId*100 + level)
  110. }
  111. // 要塞部位
  112. type FortPart struct {
  113. Level int64 `json:"level"` //部位等级
  114. WearRune int64 `json:"wear,string"` //部位镶嵌的符文
  115. }
  116. // 要塞
  117. type GrowableFort struct {
  118. Level int64 `json:"level"` //等级
  119. Parts [6]*FortPart `json:"parts"` //部位
  120. TalentTree [2]int64 `json:"talents"` //天赋树
  121. WearSkin int64 `json:"wear"`
  122. Skins map[int64]int64 `json:"skins"` //皮肤id:星级
  123. SkillIds [3]int64 `json:"skill"` //技能对应的皮肤ID 不时星级ID
  124. // Skin *FortSkin `json:"skin"` //皮肤
  125. }
  126. // type DropMaterial struct {
  127. // MaterialData map[int64]*MaterialData `json:"materialData"`
  128. // }
  129. type HeadFrame struct {
  130. HeadId int64 `json:"headId"` // 头像 -1 代表使用 AvatarURL 微信授权头像
  131. FrameId int64 `json:"frameId"` // 头像框
  132. HIdEndTs int64 `json:"hEndTs"` // 头像结束时间 -1 无限制
  133. FIdEndTs int64 `json:"fEndTs"` // 头像框结束时间
  134. }
  135. type RuneAffix struct {
  136. Type int64 `json:"typ"`
  137. Value float64 `json:"val"`
  138. }
  139. type RuneAffixAndPos struct {
  140. *RuneAffix //`json:"runeAffix"` //
  141. Pos int `json:"pos"` //
  142. }
  143. type RuneRecastAttr struct {
  144. Gid int64
  145. Ts int64
  146. Items []*RuneAffixAndPos
  147. }
  148. // 符文
  149. type BagRune struct {
  150. ModeId int64 `json:"id"`
  151. Attrs []*RuneAffix `json:"attrs,omitempty"` // 附加属性 [几条属性][属性类型,值]
  152. // WearPos int64 `json:"pos,omitempty"` // 穿戴位置
  153. }
  154. // type ClientBagRune struct {
  155. // ModeId int64 `json:"id"`
  156. // Attrs []*RuneAffix `json:"attrs,omitempty"` // 附加属性 [几条属性][属性类型,值]
  157. // // WearPos int64 `json:"pos,omitempty"` // 穿戴位置
  158. // }
  159. type DropedRune struct {
  160. *BagRune
  161. GId int64 `json:"gId"`
  162. }
  163. func NewChapterSummary() *ChapterSummary {
  164. it := new(ChapterSummary)
  165. it.Process = make([]*ChapterProcess, 0, 1)
  166. it.Levels = make(map[int64]*LevelSummary)
  167. return it
  168. }
  169. type ChapterSummary struct {
  170. Process []*ChapterProcess `json:"process"`
  171. Levels map[int64]*LevelSummary `json:"levels"`
  172. }
  173. func NewChapterProcess2(typ int64) *ChapterProcess {
  174. it := new(ChapterProcess)
  175. it.Type = typ
  176. return it
  177. // it.Chapter =
  178. // return &ChapterProcess{
  179. // ChapterLevels: make(map[int64][2]int64),
  180. // LevelWaves: make(map[int64]*ChapterLevel),
  181. // }
  182. }
  183. type ChapterProcess struct {
  184. Type int64 `json:"type"`
  185. Chapter int64 `json:"chapter"`
  186. Level int64 `json:"level"`
  187. Passed int64 `json:"passed"`
  188. }
  189. func NewLevelSummary() *LevelSummary {
  190. it := new(LevelSummary)
  191. return it
  192. }
  193. type LevelSummary struct {
  194. // Level int64 `json:"id"`
  195. Wave int64 `json:"wave"`
  196. Geted int64 `json:"geted"`
  197. SubWave int64 `json:"subWave"`
  198. SubGeted int64 `json:"subGeted"`
  199. JoinTs int64 `json:"joinTs"`
  200. }
  201. type ChapterProcess2 struct {
  202. ChapterLevels map[int64][2]int64 `json:"cl"` //已解锁的章节关卡 章节[小章节ID,是否已通关?1:0]
  203. LevelWaves map[int64]*LevelSummary `json:"levels"` //需要处理的关卡进度及奖励 关卡编号[大章节ID,关卡ID,首次通过波数,首通奖励领取到的波次,循环通过的波次,循环奖励领取到的波次,循环波次完成时间]
  204. // Chapter int64 `json:"id"` //大章节ID
  205. // Level int64 `json:"lv"` //关卡 1,2,3,。。
  206. // First [2]int `json:"fw"` //首次通过波数 [首次通过波数,首次奖励领取到的波次]
  207. // Cycle [2]int `json:"cw"` //循环通过的波次 [循环通过的波次,循环奖励领取到的波次]
  208. // FirstReward int64 `json:"fr"` //首通奖励领取到的波次
  209. // CycleWave int64 `json:"cw"` //循环通过的波次
  210. // CycleReward int64 `json:"cr"` //循环奖励领取到的波次
  211. // Chpater int64 `json:"id"` //关卡ID
  212. // Door int64 `json:"door"` //关卡门
  213. // FirstWave int64 `json:"fw"` //首次通过波数
  214. // FirstReward int64 `json:"fr"` //首通奖励领取到的波次
  215. // CycleWave int64 `json:"cw"` //循环通过的波次
  216. // CycleReward int64 `json:"cr"` //循环奖励领取到的波次
  217. // FirstPass int64 `json:"pass"` //是否通关
  218. }
  219. // type WaveAndReward struct {
  220. // Wave int64 `json:"w"` //首次通过波数
  221. // Reward int64 `json:"r"` //首通奖励领取到的波次
  222. // }
  223. type ChapterLevel2 struct {
  224. First [2]int64 `json:"fw"` //首次通过波数 [首次通过波数,首次奖励领取到的波次]
  225. Normal [2]int64 `json:"nw"` //循环通过的波次 [循环通过的波次,循环奖励领取到的波次]
  226. JoinTs int64 `json:"js"` //循环波次完成时间
  227. // Chapter int64 `json:"id"` //大章节ID
  228. // Level int64 `json:"lv"` //关卡 1,2,3,。。
  229. // Chapter int64 `json:"id"` //关卡ID
  230. // Level int64 `json:"lv"` //关卡
  231. // FirstWave int64 `json:"fw"` //首次通过波数
  232. // FirstReward int64 `json:"fr"` //首通奖励领取到的波次
  233. // CycleWave int64 `json:"cw"` //循环通过的波次
  234. // CycleReward int64 `json:"cr"` //循环奖励领取到的波次
  235. // CycleTs int64 `json:"ts"` //循环波次完成时间
  236. // // FirstPass int64 `json:"pass"` //是否通关
  237. }
  238. // 宝物
  239. type GrowableTreasure struct {
  240. Level int64 `json:"level"` // 等级
  241. Star int64 `json:"star"` // 星级
  242. }
  243. type RecruitStatis struct {
  244. HeroNum int64 `json:"heroNum"` // 英雄招募次数(暗保底使用,触发暗保底后会清0)
  245. TreasureNum [2]int64 `json:"treasureNum"` // 宝物招募次数(暗保底使用,触发暗保底后会清0) 10次保底和500次保底
  246. EpigraphNum int64 `json:"epigraphNum"` // 铭文招募次数(暗保底使用,触发暗保底后会清0)
  247. }
  248. type TicketData struct {
  249. // Stamina int `json:"stamina"` // 当前体力 放背包
  250. LastStamTick int64 `json:"lastStamTick"` // 生效时间
  251. DayStamTick int64 `json:"dayStamTick"` // 购买时间
  252. DayStamBuyCount int `json:"dayStamBuyCount"` // 今日购买次数
  253. AdStamCount int `json:"adStamCount"` // 今日使用免费次数
  254. LastEnergyTick int64 `json:"lastEnergyTick"` // 精力生效时间
  255. DayEnergyTick int64 `json:"dayEnergyTick"` // 精力购买时间
  256. DayEnergyBuyCount int `json:"dayEnergyBuyCount"` // 今日精力购买次数
  257. AdEnergyCount int `json:"adEnergyCount"` // 今日精力使用免费次数
  258. }
  259. type GamePlayer struct {
  260. Id int64 //`xorm:"BIGINT pk autoincr 'id'"`
  261. PlayerId int64 `xorm:"BIGINT index 'playerid'"`
  262. AccId int64 `xorm:"BIGINT index(serveracc) 'accId'"`
  263. LineId int64 `xorm:"int index(serveracc) 'line'"`
  264. Level int64 `xorm:"int 'level'"`
  265. Exp int64 `xorm:"BIGINT 'exp'"`
  266. LastLoginTick int64 `xorm:"BIGINT 'lastlogintick'"`
  267. LastLogoutTick int64 `xorm:"BIGINT 'lastlogouttick'"`
  268. OpenId string `xorm:"VARCHAR(255) 'openId'"`
  269. NickName string `xorm:"VARCHAR(255) index 'nickName'"`
  270. ImgUrl string `xorm:"VARCHAR(512) 'imgUrl'"`
  271. HeadImg HeadFrame `xorm:"Text json 'headImg'"`
  272. CreateTime time.Time `xorm:"created"`
  273. Ban int `xorm:"int 'ban'"`
  274. AdId string `xorm:"VARCHAR(128) 'adId'"`
  275. ClickId string `xorm:"VARCHAR(255) 'clickId'"`
  276. AdSrc string `xorm:"VARCHAR(128) 'adSrc'"`
  277. Plat string `xorm:"VARCHAR(20) 'plat'"` // wx tt
  278. SubPlat int `xorm:"int default 0 subPlat"` // 1 抖音; 2 抖音极速
  279. Flag int `xorm:"int 'flag'"` //标记
  280. GateId int64 `xorm:"-"` // 所在网关
  281. Online bool `xorm:"-"` // 在线状态
  282. Materials map[int64]int64 `xorm:"Text 'materials'"` // 道具
  283. Heros map[int64]*GrowableHero `xorm:"Text json 'heros'"` // 英雄
  284. HeroSkins map[int64]struct{} `xorm:"Text json 'heroSkins'"` // 英雄皮肤,玩家可以不拥有英雄却拥有皮肤。所以单独记录。
  285. Fort *GrowableFort `xorm:"Text json 'fort'"` //时装
  286. Runes map[int64]*BagRune `xorm:"Text 'runes'"` //符文
  287. Chapters *ChapterSummary `xorm:"Text json 'chapters'"` //章节进度
  288. Treasures map[int64]*GrowableTreasure `xorm:"Text json 'treasures'"` // 宝物
  289. Recruit *RecruitStatis `xorm:"Text json 'recruit'"` // 招募
  290. RuneRecast *RuneRecastAttr `xorm:"Text json 'recast'"` //符文重铸
  291. // StaminaInfo *StaminaData `xorm:"Text json 'stamina'"` // 体力信息
  292. Crystals map[int64]int64 `xorm:"Text 'crystal'"` //水晶 [水晶id]领取过奖励
  293. TicketInfo *TicketData `xorm:"Text json 'ticketdata'"` // 体力 精力信息
  294. // WearRunes map[int64]struct{} `xorm:"-"` //穿戴的符文[符文类型]符文id
  295. // Coin int64 `xorm:"BIGINT 'coin'"`
  296. // Diamond int `xorm:"int 'diamond'"`
  297. // Exterior *Exterior `xorm:"Text json 'exterior'"` // 外观
  298. // CombatEffe int64 `xorm:"BIGINT default 0 combatEffe"`
  299. // MaxCombatEffe int64 `xorm:"BIGINT default 0 maxCombatEffe"`
  300. // HeadFrames *DropedHeadFrame `xorm:"Text json 'headFrames'"` // 头像
  301. // Heros *DropedHero `xorm:"Text json 'heros'"` // 英雄
  302. // PassRoom *PassRoom `xorm:"Text json 'passRoom'"` // 关卡数据
  303. // Fortress *DropedFortress `xorm:"Text json 'fortress'"` // 要塞
  304. // Fashion *DropedFashion `xorm:"Text json 'fashion'"` // 时装
  305. // New bool `xorm:"-"` // 新注册玩家
  306. }
  307. func (m GamePlayer) TableName() string {
  308. return "player_attr"
  309. }
  310. // 需要保存的数据需确保在这里能复制到new1 中
  311. func (m *GamePlayer) DeepCopy() interface{} {
  312. new1 := new(GamePlayer)
  313. *new1 = *m
  314. return new1
  315. }
  316. func (m *GamePlayer) QueryExist(eng *xorm.Engine) (bool, error) {
  317. player := new(GamePlayer)
  318. player.PlayerId = m.PlayerId
  319. return eng.Exist(player)
  320. }
  321. func (m *GamePlayer) UpdateDB(eng *xorm.Engine) (int64, error) {
  322. return eng.Where("playerid=?", m.PlayerId).MustCols("stamina", "lastStamTick").Update(m)
  323. }
  324. func (m *GamePlayer) GetUniqueKey() string {
  325. //return m.UserId
  326. return strconv.FormatInt(m.PlayerId, 10)
  327. }
  328. // 实现DeepCopy接口
  329. func CopyGamePlayer(old *GamePlayer) *GamePlayer {
  330. new2, err := deepcopy.Copy(old) //
  331. if err != nil {
  332. return nil
  333. }
  334. return new2.(*GamePlayer)
  335. }