role_base.go 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079
  1. package model
  2. import (
  3. "math"
  4. "rocommon/service"
  5. "rocommon/util"
  6. "roserver/baseserver/model"
  7. "roserver/baseserver/set"
  8. "roserver/serverproto"
  9. "sync"
  10. )
  11. const (
  12. Max_Change_Count = 5
  13. Card_Operation = 2 //卡片一键操作间隔
  14. updateCrossFightPowerRankDurationTime = 10 * 60 * 1000
  15. )
  16. type RoleBase struct {
  17. SaveObject
  18. roleBase *serverproto.RoleBase
  19. fightChangeNum int32
  20. cardOperation int64
  21. headFrameTick uint64
  22. lastFightPowerChangeTimeStamp uint64
  23. }
  24. var roleBasePool = sync.Pool{
  25. New: func() interface{} {
  26. retBase := newRoleBase()
  27. return retBase
  28. },
  29. }
  30. func newRoleBase() *RoleBase {
  31. base := &RoleBase{
  32. roleBase: &serverproto.RoleBase{
  33. RoleData: &serverproto.RoleData{
  34. HeroData: &serverproto.HeroData{
  35. Slot: &serverproto.SlotData{},
  36. Skill: &serverproto.RoleSkill{},
  37. SkillEquipSlot: &serverproto.SkillEquipSlotData{},
  38. },
  39. },
  40. FashionData: &serverproto.FashionData{},
  41. Head_Info: &serverproto.HeadInfo{},
  42. },
  43. }
  44. base.cardOperation = 0
  45. return base
  46. }
  47. func (this *RoleBase) CopyData(base *serverproto.RoleBase) {
  48. *base = *this.roleBase
  49. }
  50. // 剧情//TODO wangzhaocan 后续放入RoleCommon
  51. func (this *RoleBase) CopyStoryData(msgNtf *serverproto.SCRoleStoryNtf) {
  52. for _, data := range this.roleBase.StoryId {
  53. msgNtf.Story = append(msgNtf.Story, data)
  54. }
  55. msgNtf.MapCart = this.roleBase.MapAnimation
  56. //util.DebugF("uid=%v SCRoleStoryNtf msg=%v", this.role.GetUUid(), msgNtf)
  57. }
  58. func (this *RoleBase) Load(msg interface{}) bool {
  59. proRole := msg.(*serverproto.Role)
  60. //m := map[int32]int{
  61. // 22100: 1, 22101: 1, 22102: 1, 22103: 1, 22104: 1, 22105: 1, 22106: 1, 22107: 1, 22108: 1, 22109: 1, 22110: 1, 22111: 1,
  62. // 22200: 1, 22201: 1, 22202: 1, 22203: 1, 22204: 1, 22205: 1, 22206: 1, 22207: 1, 22208: 1, 22209: 1, 22210: 1, 22211: 1,
  63. // 22300: 1, 22301: 1, 22302: 1, 22303: 1, 22304: 1, 22305: 1, 22306: 1, 22307: 1, 22308: 1, 22309: 1, 22310: 1, 22311: 1,
  64. // 22400: 1, 22401: 1, 22402: 1, 22403: 1, 22404: 1, 22405: 1, 22406: 1, 22407: 1, 22408: 1, 22409: 1, 22410: 1, 22411: 1,
  65. // 22500: 1, 22501: 1, 22502: 1, 22503: 1, 22504: 1, 22505: 1, 22506: 1, 22507: 1, 22508: 1, 22509: 1, 22510: 1, 22511: 1,
  66. //}
  67. *this.roleBase = *proRole.RoleBase
  68. if this.roleBase.RoleData != nil {
  69. //if this.roleBase.RoleData.HeroData != nil && !this.role.GetRoleBase().roleBase.RoleDelete4 {
  70. // if this.roleBase.RoleData.HeroData.Slot != nil {
  71. // for _, v := range this.roleBase.RoleData.HeroData.Slot.SlotList {
  72. // var newS []int32
  73. // for _, c := range v.CardIdList {
  74. // if _, ok := m[c]; !ok {
  75. // newS = append(newS, c)
  76. // }
  77. // }
  78. // v.CardIdList = newS
  79. // }
  80. // }
  81. // util.ErrorF("delete card uuid:%v,name:%v", this.role.GetUUid(), this.roleBase.NickName)
  82. // this.role.GetRoleBase().roleBase.RoleDelete4 = true
  83. // this.role.GetRoleBase().SetDirty(true)
  84. // this.SetDirty(true)
  85. //}
  86. //if !this.role.GetRoleBase().roleBase.RoleDelete3 {
  87. // //ro币扣除
  88. // for _, v := range this.roleBase.ResList {
  89. // if v.Key == 54 && v.Value > 30000 {
  90. // util.ErrorF("ro set ro 30000 uuid:%v,ro:%v,name:%v", this.role.GetUUid(), this.roleBase.Rmb, this.roleBase.NickName)
  91. // v.Value = 30000
  92. // }
  93. // }
  94. // if this.roleBase.Rmb > 10000000 {
  95. // util.ErrorF("ro set coin 10000000 uuid:%v,coin:%v,name:%v", this.role.GetUUid(), this.roleBase.Rmb, this.roleBase.NickName)
  96. // this.roleBase.Rmb = 10000000
  97. // }
  98. // this.role.GetRoleBase().roleBase.RoleDelete3 = true
  99. // this.role.GetRoleBase().SetDirty(true)
  100. //}
  101. //if this.roleBase.RoleData.HeroData.SkillEquipSlot == nil {
  102. // this.roleBase.RoleData.HeroData.SkillEquipSlot = &serverproto.SkillEquipSlotData{}
  103. // for i := 0; i < SKILL_EQUIP_SLOT_TYPE_NUM; i++ {
  104. // this.roleBase.RoleData.HeroData.SkillEquipSlot.SlotList = append(this.roleBase.RoleData.HeroData.SkillEquipSlot.SlotList, &serverproto.SkillEquipSlotDetailData{SlotLevel:1})
  105. // }
  106. //}
  107. if this.roleBase.RoleData.JobLevel == 0 {
  108. this.roleBase.RoleData.JobLevel = 1
  109. //初始化主角可添加的属性点
  110. this.roleBase.RoleData.HeroData.AttrPoint = model.GlobalRoleOriginalAttrPoint
  111. //初始化最大巡游值
  112. this.roleBase.RoleData.MaxCruise = model.GlobalCruiseMax
  113. if this.roleBase.Head_Info == nil {
  114. this.roleBase.Head_Info = &serverproto.HeadInfo{}
  115. this.roleBase.Head_Info.HeadFrameList = append(this.roleBase.Head_Info.HeadFrameList, &serverproto.HeadFrameData{
  116. HeadFrameId: model.GlobalGuildHeadFrame,
  117. HeadFrameTime: -1,
  118. })
  119. }
  120. //初始化角色头像
  121. if this.roleBase.RoleData.HeadId == 0 {
  122. if this.roleBase.GetSex() == 1 {
  123. this.roleBase.RoleData.HeadId = int32(model.GlobalFemaleHead)
  124. } else {
  125. this.roleBase.RoleData.HeadId = int32(model.GlobalMaleHead)
  126. }
  127. }
  128. if this.roleBase.RoleData.HeadFrameId == 0 {
  129. this.roleBase.RoleData.HeadFrameId = model.GlobalGuildHeadFrame
  130. }
  131. this.SetDirty(true)
  132. }
  133. if this.role.roleTask != nil {
  134. this.role.roleTask.OnlineCheckNewHead()
  135. }
  136. }
  137. return true
  138. }
  139. func (this *RoleBase) OnlineProcess() {
  140. //创号时,设置主角可转目标职业的任务条件
  141. this.role.roleTask.GetChangeJobTask(this.roleBase.RoleData.HeroData.Id, 0, false)
  142. }
  143. func (this *RoleBase) RoleData() *serverproto.RoleData {
  144. return this.roleBase.RoleData
  145. }
  146. func (this *RoleBase) Save() {
  147. this.SetDirty(false)
  148. //util.DebugF("uid=%v RoleBase save...", this.role.GetUUid())
  149. saveMsg := &serverproto.SSRoleBaseSaveReq{
  150. Base: this.roleBase,
  151. }
  152. this.role.SendDb(saveMsg)
  153. }
  154. func (this *RoleBase) GetMoney() uint64 {
  155. return this.roleBase.Coin
  156. }
  157. func (this *RoleBase) GetRmb() uint32 {
  158. return this.roleBase.Rmb
  159. }
  160. func (this *RoleBase) GetRoleBaseExp() int32 {
  161. return this.RoleData().BaseExp
  162. }
  163. func (this *RoleBase) GetHeroBaseExp() int32 {
  164. return this.RoleData().HeroExp
  165. }
  166. func (this *RoleBase) GetRoleJobExp() int32 {
  167. return this.RoleData().JobExp
  168. }
  169. func (this *RoleBase) GetRoleLevel() int32 {
  170. return this.RoleData().HeroData.BaseLevel
  171. }
  172. func (this *RoleBase) GetRoleJobLevel() int32 {
  173. return this.RoleData().JobLevel
  174. }
  175. func (this *RoleBase) GetRoleName() string {
  176. return this.roleBase.NickName
  177. }
  178. func (this *RoleBase) GetRoleTotalRecharge() float32 {
  179. return this.roleBase.TotalRecharge
  180. }
  181. func (this *RoleBase) GetRoleSex() int32 {
  182. //1 female 2 male
  183. return this.roleBase.Sex
  184. }
  185. func (this *RoleBase) GetRoleJobType() int32 {
  186. return this.role.GetRoleHero().GetMainHeroJobType()
  187. }
  188. func (this *RoleBase) GetCruise() int32 {
  189. return this.RoleData().Cruise
  190. }
  191. func (this *RoleBase) Rename(name string) {
  192. this.roleBase.NickName = name
  193. this.SetDirty(true)
  194. }
  195. // 时效性头像刷新
  196. func (this *RoleBase) Update(ms uint64) {
  197. if this.roleBase.Head_Info == nil || len(this.roleBase.Head_Info.HeadFrameList) <= 0 {
  198. return
  199. }
  200. if this.headFrameTick != 0 && this.headFrameTick > ms+1000*60 {
  201. return
  202. }
  203. this.headFrameTick = ms
  204. var headFrame []*serverproto.HeadFrameData
  205. idx := 0
  206. nowTime := int64(ms / 1000)
  207. for idx < len(this.roleBase.Head_Info.HeadFrameList) {
  208. data := this.roleBase.Head_Info.HeadFrameList[idx]
  209. if data.HeadFrameTime != -1 && data.HeadFrameTime <= nowTime {
  210. headFrame = append(headFrame, &serverproto.HeadFrameData{
  211. HeadFrameId: data.HeadFrameId,
  212. HeadFrameTime: 0,
  213. })
  214. this.roleBase.Head_Info.HeadFrameList = append(this.roleBase.Head_Info.HeadFrameList[:idx], this.roleBase.Head_Info.HeadFrameList[idx+1:]...)
  215. this.SetDirty(true)
  216. //当前头像到期了的话。
  217. if this.roleBase.GetRoleData().HeadFrameId != 0 && data.HeadFrameId == this.roleBase.GetRoleData().HeadFrameId {
  218. this.roleBase.GetRoleData().HeadFrameId = model.GlobalGuildHeadFrame
  219. this.UpdatePlayerBriefInfo(false)
  220. this.BaseChangeNtf()
  221. }
  222. this.role.roleBattleAttr.AttrChange(AttrChangeST{
  223. ChangeType: Attr_Change_HeadFrame,
  224. ChangeHeroData: this.role.GetRoleHero().GetMainHero(),
  225. BHeadFrameDelete: true,
  226. HeadFrameId: data.HeadFrameId,
  227. })
  228. } else {
  229. idx++
  230. }
  231. }
  232. if len(headFrame) > 0 {
  233. this.HeadFrameChangeNtf(headFrame)
  234. //this.role.GetRoleFightPower().HeadFrameAttrChange(false)
  235. }
  236. }
  237. func (this *RoleBase) DailyReset(notify bool) uint64 {
  238. nowTime := util.GetTimeMilliseconds()
  239. oldDailyResetTimeStamp := this.roleBase.DailyResetTimeStamp
  240. this.roleBase.DailyResetTimeStamp = nowTime
  241. //每日累计重置重置
  242. this.roleBase.DayRecharge = 0
  243. this.roleBase.BtZhenDayRecharge = 0
  244. this.roleBase.BtJiaDayRecharge = 0
  245. //累计在线时间奖励数据重置
  246. this.onlineTImeRewardAll(nowTime)
  247. this.roleBase.OnlineStamp = nowTime
  248. this.roleBase.OnlineRewardId = 0
  249. this.roleBase.TotalOnlineTime = 0
  250. this.SetDirty(true)
  251. if notify {
  252. ntfMsg := &serverproto.SCPayInfoNtf{
  253. TotalRecharge: this.roleBase.TotalRecharge,
  254. DayRecharge: this.roleBase.DayRecharge,
  255. BtZhenDayRecharge: this.roleBase.BtZhenDayRecharge,
  256. BtJiaDayRecharge: int32(float32(this.roleBase.BtJiaDayRecharge) * BTJiaChangeDollar),
  257. BtJiaTotalRecharge: uint64(float32(this.roleBase.BtJiaTotalRecharge) * BTJiaChangeDollar),
  258. }
  259. this.role.ReplayGate(ntfMsg, true)
  260. ntfOnlineTimeRewardMsg := &serverproto.SCOnlineTimeRewardNtf{
  261. OnlineStamp: this.roleBase.OnlineStamp,
  262. OnlineRewardId: 0,
  263. TotalOnlineTime: 0,
  264. }
  265. this.role.ReplayGate(ntfOnlineTimeRewardMsg, true)
  266. }
  267. return oldDailyResetTimeStamp
  268. }
  269. func (this *RoleBase) AddRMB(st AddItemST, add bool) bool {
  270. rmb := st.ItemCount
  271. if rmb <= 0 || rmb >= math.MaxInt32 {
  272. return false
  273. }
  274. oldRMB := this.roleBase.Rmb
  275. if !add {
  276. if this.roleBase.Rmb >= uint32(rmb) {
  277. this.roleBase.Rmb -= uint32(rmb)
  278. TaskMagCheck(this.role, serverproto.TaskType_Gold_Consumption_Count, rmb)
  279. } else {
  280. //直接消耗剩余的金币
  281. this.roleBase.Rmb = 0
  282. TaskMagCheck(this.role, serverproto.TaskType_Gold_Consumption_Count, rmb)
  283. this.SetDirty(true)
  284. return false
  285. }
  286. } else {
  287. tmpExp := uint64(rmb) + uint64(this.roleBase.Rmb)
  288. if tmpExp >= math.MaxInt32 {
  289. // 金币获得达到上限无法再获得
  290. tmpExp = math.MaxInt32
  291. ntfMsg := &serverproto.SCErrorMessageNtf{
  292. Error: int32(serverproto.ErrorCode_ERROR_RMB_CANNOT_ADD_MORE),
  293. }
  294. this.role.ReplayGate(ntfMsg, true)
  295. }
  296. this.roleBase.Rmb = uint32(tmpExp)
  297. }
  298. this.SetDirty(true)
  299. //mysql
  300. this.role.MysqlLogNtf(serverproto.MysqlLogType_LType_RBM,
  301. []int32{int32(oldRMB), int32(this.roleBase.Rmb), int32(rmb), st.ReasonParam}, int32(st.AddFrom))
  302. util.InfoF("uid=%v AddRMB from=%v old=%v new=%v addvalue=%v add=%v", this.role.GetUUid(), st.AddFrom,
  303. oldRMB, this.roleBase.Rmb, rmb, add)
  304. return true
  305. }
  306. func (this *RoleBase) AddMoney(st AddItemST, add bool) bool {
  307. money := st.ItemCount
  308. if money <= 0 || money >= math.MaxInt32 {
  309. return false
  310. }
  311. oldMoney := this.roleBase.Coin
  312. if !add {
  313. if this.roleBase.Coin >= uint64(money) {
  314. this.roleBase.Coin -= uint64(money)
  315. TaskMagCheck(this.role, serverproto.TaskType_Silver_Consumption_Count, money)
  316. //超值礼包开启
  317. if this.role.GetRoleActivity() != nil {
  318. this.role.GetRoleActivity().SuperChargeUnlockCheck(
  319. serverproto.UnlockChargeType_UChargeType_ZenyOnceCost, &SuperChargeUnlockST{oldValue: money})
  320. }
  321. } else {
  322. //直接消耗剩余的Coin
  323. this.roleBase.Coin = 0
  324. TaskMagCheck(this.role, serverproto.TaskType_Silver_Consumption_Count, money)
  325. //超值礼包开启
  326. if this.role.GetRoleActivity() != nil {
  327. this.role.GetRoleActivity().SuperChargeUnlockCheck(
  328. serverproto.UnlockChargeType_UChargeType_ZenyOnceCost, &SuperChargeUnlockST{oldValue: money})
  329. }
  330. this.SetDirty(true)
  331. return false
  332. }
  333. } else {
  334. this.roleBase.Coin += uint64(money)
  335. if this.role.GetRoleTask() != nil {
  336. this.role.GetRoleTask().totalAddZeny += uint64(money)
  337. this.role.GetRoleTask().SetDirty(true)
  338. }
  339. TaskMagCheck(this.role, serverproto.TaskType_Get_Silver_Count, money)
  340. }
  341. this.SetDirty(true)
  342. util.InfoF("uid=%v AddMoney from=%v old=%v new=%v addvalue=%v add=%v", this.role.GetUUid(), st.AddFrom,
  343. oldMoney, this.GetMoney(), money, add)
  344. return true
  345. }
  346. func (this *RoleBase) AddHeroExp(st AddItemST, add bool) bool {
  347. exp := st.ItemCount
  348. if exp <= 0 || exp >= math.MaxInt32 {
  349. return false
  350. }
  351. oldHeroExp := this.RoleData().HeroExp
  352. if !add {
  353. if this.RoleData().HeroExp >= exp {
  354. this.RoleData().HeroExp -= exp
  355. } else {
  356. return false
  357. }
  358. } else {
  359. tmpExp := uint64(exp) + uint64(this.RoleData().HeroExp)
  360. if tmpExp >= math.MaxInt32 {
  361. tmpExp = math.MaxInt32
  362. }
  363. this.RoleData().HeroExp = int32(tmpExp)
  364. }
  365. this.SetDirty(true)
  366. util.InfoF("uid=%v AddHeroExp old=%v new=%v addvalue=%v add=%v", this.role.GetUUid(),
  367. oldHeroExp, this.RoleData().HeroExp, exp, add)
  368. return true
  369. }
  370. func (this *RoleBase) AddCruise(st AddItemST, add bool) bool {
  371. value := st.ItemCount
  372. if value <= 0 || value >= math.MaxInt32 {
  373. return false
  374. }
  375. oldCruise := this.RoleData().Cruise
  376. if !add {
  377. if this.RoleData().Cruise >= value {
  378. this.RoleData().Cruise -= value
  379. } else {
  380. return false
  381. }
  382. } else {
  383. if this.RoleData().Cruise >= this.RoleData().MaxCruise {
  384. return false
  385. }
  386. this.RoleData().Cruise += value
  387. if this.RoleData().Cruise > this.RoleData().MaxCruise {
  388. this.RoleData().Cruise = this.RoleData().MaxCruise
  389. }
  390. }
  391. this.SetDirty(true)
  392. util.InfoF("uid=%v AddCruise old=%v new=%v addvalue=%v add=%v", this.role.GetUUid(),
  393. oldCruise, this.RoleData().Cruise, value, add)
  394. return true
  395. }
  396. // 获取资源
  397. func (this *RoleBase) GetCommonRes(resType int32) int32 {
  398. for _, data := range this.roleBase.ResList {
  399. if data.Key == resType {
  400. return data.Value
  401. }
  402. }
  403. return 0
  404. }
  405. // default true
  406. func (this *RoleBase) ResetCommonRes(resType int32, notify bool) {
  407. for _, data := range this.roleBase.ResList {
  408. if data.Key == resType {
  409. if data.Value > 0 {
  410. oldValue := data.Value
  411. data.Value = 0
  412. util.InfoF("uid=%v ResetCommonRes restype=%v old=%v new=%", this.role.GetUUid(), resType, oldValue, data.Value)
  413. this.SetDirty(true)
  414. if notify {
  415. this.BaseChangeNtf()
  416. }
  417. }
  418. break
  419. }
  420. }
  421. }
  422. // 添加资源
  423. func (this *RoleBase) AddCommonRes(resType int32, st AddItemST, add bool) bool {
  424. resValue := st.ItemCount
  425. if resValue <= 0 || resValue >= math.MaxInt32 {
  426. return false
  427. }
  428. if !add {
  429. for _, data := range this.roleBase.ResList {
  430. if data.Key == resType {
  431. if data.Value < resValue {
  432. return false
  433. } else {
  434. oldValue := data.Value
  435. data.Value -= resValue
  436. util.InfoF("uid=%v AddCommonRes restype=%v old=%v new=%v addvalue=%v add=%v",
  437. this.role.GetUUid(), resType, oldValue, data.Value, resValue, add)
  438. //bt假每日累计充值
  439. if resType == int32(serverproto.ResType_Res_CreditRecharge) {
  440. this.AddBtJiaRecharge(resValue)
  441. // 根据消耗比例获取vip经验(充值钱包消耗获得vip经验)
  442. addVipExp := float32(resValue) * model.GlobalCreditRechargeFactor
  443. st.ItemCount = int32(addVipExp)
  444. this.AddCommonRes(int32(serverproto.ResType_Res_VipExp), st, true)
  445. }
  446. break
  447. }
  448. }
  449. }
  450. } else {
  451. bFind := false
  452. for _, data := range this.roleBase.ResList {
  453. if data.Key == resType {
  454. oldValue := data.Value
  455. //data.Value += resValue
  456. tmpVal := uint64(data.Value) + uint64(resValue)
  457. if tmpVal >= math.MaxInt32 {
  458. tmpVal = math.MaxInt32 - 1
  459. }
  460. data.Value = int32(tmpVal)
  461. //上限处理
  462. switch serverproto.ResType(resType) {
  463. case serverproto.ResType_Res_EvilExp:
  464. if model.GlobalEvilExpLimit > 0 && data.Value > model.GlobalEvilExpLimit {
  465. data.Value = model.GlobalEvilExpLimit
  466. }
  467. case serverproto.ResType_Res_VipExp:
  468. this.CheckVipLevelUp()
  469. case serverproto.ResType_Res_BoliShopExp:
  470. this.checkBTBoliLevelUp()
  471. }
  472. bFind = true
  473. util.InfoF("uid=%v AddCommonRes restype=%v old=%v new=%v addvalue=%v add=%v",
  474. this.role.GetUUid(), resType, oldValue, data.Value, resValue, add)
  475. break
  476. }
  477. }
  478. if !bFind {
  479. this.roleBase.ResList = append(this.roleBase.ResList, &serverproto.KeyValueType{
  480. Key: resType,
  481. Value: resValue,
  482. })
  483. //上限处理
  484. switch serverproto.ResType(resType) {
  485. case serverproto.ResType_Res_EvilExp:
  486. if model.GlobalEvilExpLimit > 0 && resValue > model.GlobalEvilExpLimit {
  487. resValue = model.GlobalEvilExpLimit
  488. }
  489. case serverproto.ResType_Res_BoliShopExp:
  490. this.checkBTBoliLevelUp()
  491. }
  492. if serverproto.ResType(resType) == serverproto.ResType_Res_VipExp {
  493. this.CheckVipLevelUp()
  494. }
  495. util.InfoF("uid=%v AddCommonRes restype=%v old=0 new=%v addvalue=%v add=%v",
  496. this.role.GetUUid(), resType, resValue, resValue, add)
  497. }
  498. }
  499. this.SetDirty(true)
  500. return true
  501. }
  502. func (this *RoleBase) AddBtJiaRecharge(val int32) {
  503. this.roleBase.BtJiaDayRecharge += val
  504. this.roleBase.BtJiaTotalRecharge += uint64(val)
  505. this.SetDirty(true)
  506. todayCharge := int32(math.Ceil(float64(float32(this.roleBase.BtJiaDayRecharge)*BTJiaChangeDollar))) +
  507. int32(math.Ceil(float64(this.roleBase.BtZhenDayRecharge)))
  508. ntfMsg := &serverproto.SCPayInfoNtf{
  509. TotalRecharge: this.roleBase.TotalRecharge,
  510. DayRecharge: this.roleBase.DayRecharge,
  511. BtZhenDayRecharge: this.roleBase.BtZhenDayRecharge,
  512. BtJiaDayRecharge: todayCharge,
  513. BtJiaTotalRecharge: uint64(float32(this.roleBase.BtJiaTotalRecharge) * BTJiaChangeDollar),
  514. }
  515. this.role.ReplayGate(ntfMsg, true)
  516. TaskMagCheck(this.role, serverproto.TaskType_BT_ZhenJiaRecharge, todayCharge)
  517. }
  518. // 增加累计充值
  519. func (this *RoleBase) AddPayRecharge(payRewardInfo *serverproto.PayOrderSaveInfo) {
  520. amount := payRewardInfo.Amount
  521. if amount <= 0.00001 {
  522. return
  523. }
  524. oldVal := this.roleBase.TotalRecharge
  525. this.roleBase.TotalRecharge += amount
  526. this.roleBase.DayRecharge += amount
  527. this.roleBase.LastRechargeTime = util.GetTimeMilliseconds()
  528. this.SetDirty(true)
  529. // bt服务器真假累计充值
  530. if payRewardInfo.GoodsType == int32(serverproto.PayGoodsType_EPayType_NormalBag) {
  531. goodCfg, ok := model.ConvertGiftBag[payRewardInfo.GoodsId]
  532. if ok && goodCfg.BagType == Rune_BagShop_Type_Gold {
  533. this.roleBase.BtZhenDayRecharge += amount
  534. todayCharge := int32(math.Ceil(float64(float32(this.roleBase.BtJiaDayRecharge)*BTJiaChangeDollar))) +
  535. int32(math.Ceil(float64(this.roleBase.BtZhenDayRecharge)))
  536. TaskMagCheck(this.role, serverproto.TaskType_BT_ZhenJiaRecharge, todayCharge)
  537. }
  538. }
  539. calCeilAmount := math.Ceil(float64(payRewardInfo.Amount))
  540. // bt 获得RO币
  541. tmpRoCoin := calCeilAmount * float64(model.GlobalRoCoinFactor)
  542. TaskMagCheck(this.role, serverproto.TaskType_BT_ROCoinRecharge, int32(tmpRoCoin))
  543. ntfMsg := &serverproto.SCPayInfoNtf{
  544. TotalRecharge: this.roleBase.TotalRecharge,
  545. DayRecharge: this.roleBase.DayRecharge,
  546. BtZhenDayRecharge: this.roleBase.BtZhenDayRecharge,
  547. BtJiaDayRecharge: int32(float32(this.roleBase.BtJiaDayRecharge) * BTJiaChangeDollar),
  548. BtJiaTotalRecharge: uint64(float32(this.roleBase.BtJiaTotalRecharge) * BTJiaChangeDollar),
  549. }
  550. this.role.ReplayGate(ntfMsg, true)
  551. util.InfoF("uid=%v AddPayRecharge old=%v new=%v add=%v", this.role.GetUUid(), oldVal, this.roleBase.TotalRecharge, amount)
  552. //给VIP经验
  553. if model.GlobalRMBToVipExpRMB > 0 {
  554. vipExp := float32(calCeilAmount) * float32(model.GlobalRMBToVipExpVip) / float32(model.GlobalRMBToVipExpRMB)
  555. this.role.AddRes(int32(serverproto.ResType_Res_VipExp), AddItemST{ItemCount: int32(vipExp)}, true)
  556. }
  557. //充值任务
  558. TaskMagCheck(this.role, serverproto.TaskType_Recharge_Num_Accu, int32(amount+0.5))
  559. TaskMagCheck(this.role, serverproto.TaskType_Recharge_Num, int32(amount+0.5))
  560. TaskMagCheck(this.role, serverproto.TaskType_Eve_Recharge_Value, int32(amount+0.5))
  561. //首充是否开启
  562. if this.role.GetRoleActivity() != nil {
  563. //开启时自动做任务检测
  564. this.role.GetRoleActivity().FirstChargeUnlockState()
  565. this.role.GetRoleActivity().TaskCheck(serverproto.TaskType_Recharge_Num_Accu, int32(amount+0.5))
  566. //超值礼包开启
  567. this.role.GetRoleActivity().SuperChargeUnlockCheck(serverproto.UnlockChargeType_UChargeType_PayAmount,
  568. &SuperChargeUnlockST{oldValue: int32(payRewardInfo.Amount)})
  569. }
  570. //BT根据关卡的功能解锁
  571. if this.role.GetRoleBT() != nil {
  572. this.role.GetRoleBT().UnlockBTSystem()
  573. }
  574. //gm方式充值 不写入数据库
  575. if payRewardInfo.GoodsType != int32(serverproto.PayGoodsType_EPayType_None) {
  576. //充值成功添加到mysql(订单信息)
  577. payLogData := &serverproto.SSRoleLogData{
  578. Uid: this.role.GetUUid(),
  579. Type: int32(serverproto.MysqlLogType_LType_Pay),
  580. ParamList: []int32{int32(oldVal), int32(this.roleBase.TotalRecharge), int32(amount)},
  581. }
  582. orderLogData := &serverproto.SSRoleLogData{
  583. Uid: this.role.GetUUid(),
  584. Type: int32(serverproto.MysqlLogType_LType_OrderList),
  585. ParamList: []int32{int32(amount), payRewardInfo.GoodsType, payRewardInfo.GoodsId},
  586. Param64List: []uint64{payRewardInfo.CpOrderId, payRewardInfo.OrderProcessTime},
  587. RewardList: payRewardInfo.RewardList,
  588. StrList: []string{payRewardInfo.SdkOrderId},
  589. }
  590. this.role.AddMysqlLog(payLogData)
  591. this.role.AddMysqlLog(orderLogData)
  592. //mysqlNtf := &serverproto.SSRoleLogNtf{}
  593. //mysqlNtf.LogList = append(mysqlNtf.LogList, payLogData)
  594. //mysqlNtf.LogList = append(mysqlNtf.LogList, orderLogData)
  595. //this.role.SendDb(mysqlNtf)
  596. //sdk log
  597. addGold := this.role.WriteChargeLog(payRewardInfo)
  598. if addGold != 0 {
  599. this.role.WriteChargeAddGoldLogJF(payRewardInfo, int32(addGold))
  600. }
  601. }
  602. }
  603. func (this *RoleBase) SetLastLoginTime() uint64 {
  604. var durationTime uint64 = 0
  605. nowTime := util.GetTimeMilliseconds()
  606. if this.RoleData().LastLoginTime > 0 && nowTime > this.RoleData().LastLoginTime {
  607. durationTime = nowTime - this.RoleData().LastLoginTime
  608. }
  609. this.RoleData().LastLoginTime = nowTime
  610. this.roleBase.OnlineStamp = nowTime
  611. this.SetDirty(true)
  612. return durationTime
  613. }
  614. func (this *RoleBase) GetLastLoginTime() uint64 {
  615. return this.RoleData().LastLoginTime
  616. }
  617. func (this *RoleBase) BaseChangeNtf() {
  618. ntfMsg := &serverproto.SCRoleBaseInfoNtf{
  619. Coin: this.roleBase.Coin,
  620. Rmb: this.roleBase.Rmb,
  621. ResList: this.roleBase.ResList,
  622. RoleData: this.RoleData(),
  623. RepressSkillPvpVal: this.roleBase.RepressSkillPvpVal,
  624. }
  625. this.role.ReplayGate(ntfMsg, true)
  626. }
  627. func (this *RoleBase) OnlineTimeReward() serverproto.ErrorCode {
  628. bChang := false
  629. nowTime := util.GetTimeMilliseconds()
  630. curDiffDay := util.GetDurationDay2(this.role.RegisterTime, nowTime)
  631. //计算当天累计在线时间
  632. tmpTotalOnlineTime := this.roleBase.TotalOnlineTime
  633. if this.roleBase.OnlineStamp <= 0 {
  634. this.roleBase.OnlineStamp = nowTime
  635. }
  636. if nowTime > this.roleBase.OnlineStamp {
  637. tmpTotalOnlineTime += int32((nowTime - this.roleBase.OnlineStamp) / 1000)
  638. }
  639. if curDiffDay >= model.ConvertOnlineRewardMaxDay {
  640. curDiffDay = model.ConvertOnlineRewardMaxDay
  641. }
  642. onlineRewardCfgData, ok := model.ConvertOnlineRewardList[curDiffDay]
  643. if !ok {
  644. return serverproto.ErrorCode_ERROR_FAIL
  645. }
  646. ackMsg := &serverproto.SCOnlineTimeRewardAck{}
  647. rewardList := map[int32]int32{}
  648. for idx := 0; idx < len(onlineRewardCfgData); idx++ {
  649. if onlineRewardCfgData[idx].Id > this.roleBase.OnlineRewardId {
  650. if onlineRewardCfgData[idx].RewardToTalTime <= tmpTotalOnlineTime {
  651. this.roleBase.OnlineRewardId = onlineRewardCfgData[idx].Id
  652. this.roleBase.TotalOnlineTime = tmpTotalOnlineTime
  653. this.roleBase.OnlineStamp = nowTime
  654. this.SetDirty(true)
  655. bChang = true
  656. util.DebugF("uid=%v rewardid=%v onlinetime=%v", this.role.GetUUid(),
  657. this.roleBase.OnlineRewardId, this.roleBase.TotalOnlineTime)
  658. ackMsg.RewardItemList = onlineRewardCfgData[idx].RewardList
  659. for k := 0; k < len(onlineRewardCfgData[idx].RewardList); k++ {
  660. item := onlineRewardCfgData[idx].RewardList[k]
  661. rewardList[item.Key] += item.Value
  662. }
  663. } else {
  664. //花费金币进行领奖操作
  665. if this.role.GetRmb() < uint32(onlineRewardCfgData[idx].RewardCostCoin) {
  666. return serverproto.ErrorCode_ERROR_RMB_NOT_ENOUGH
  667. }
  668. this.role.DelItem(int32(serverproto.ResType_Res_Rmb),
  669. onlineRewardCfgData[idx].RewardCostCoin, AddItemST{AddFrom: AddFrom_OnlineReward})
  670. this.roleBase.OnlineRewardId = onlineRewardCfgData[idx].Id
  671. this.roleBase.TotalOnlineTime = onlineRewardCfgData[idx].RewardToTalTime
  672. this.roleBase.OnlineStamp = nowTime
  673. this.SetDirty(true)
  674. bChang = true
  675. util.DebugF("uid=%v rewardid=%v onlinetime=%v costrmb", this.role.GetUUid(),
  676. this.roleBase.OnlineRewardId, this.roleBase.TotalOnlineTime)
  677. ackMsg.RewardItemList = onlineRewardCfgData[idx].RewardList
  678. for k := 0; k < len(onlineRewardCfgData[idx].RewardList); k++ {
  679. item := onlineRewardCfgData[idx].RewardList[k]
  680. rewardList[item.Key] += item.Value
  681. }
  682. }
  683. break
  684. }
  685. }
  686. if bChang {
  687. ntfMsg := &serverproto.SCOnlineTimeRewardNtf{
  688. TotalOnlineTime: this.roleBase.TotalOnlineTime,
  689. OnlineStamp: this.roleBase.OnlineStamp,
  690. OnlineRewardId: this.roleBase.OnlineRewardId,
  691. }
  692. this.role.ReplayGate(ntfMsg, true)
  693. }
  694. if len(rewardList) > 0 {
  695. this.role.GetRoleBag().AddItemList(rewardList, AddItemST{
  696. AddFrom: AddFrom_OnlineReward,
  697. Notify: true,
  698. })
  699. this.role.ReplayGate(ackMsg, true)
  700. } else {
  701. return serverproto.ErrorCode_ERROR_ONLINE_REWARD_NO
  702. }
  703. return serverproto.ErrorCode_ERROR_OK
  704. }
  705. // 离线时处理在线时间加成
  706. func (this *RoleBase) OfflineOnlineTimeProcess() {
  707. nowTime := util.GetTimeMilliseconds()
  708. //计算当天累计在线时间
  709. tmpTotalOnlineTime := this.roleBase.TotalOnlineTime
  710. if this.roleBase.OnlineStamp <= 0 {
  711. this.roleBase.OnlineStamp = nowTime
  712. }
  713. if nowTime > this.roleBase.OnlineStamp {
  714. tmpTotalOnlineTime += int32((nowTime - this.roleBase.OnlineStamp) / 1000)
  715. }
  716. if tmpTotalOnlineTime > this.roleBase.TotalOnlineTime {
  717. this.roleBase.OnlineStamp = nowTime
  718. this.roleBase.TotalOnlineTime = tmpTotalOnlineTime
  719. this.SetDirty(true)
  720. }
  721. }
  722. // 隔天领取之前天未领取的奖励
  723. func (this *RoleBase) onlineTImeRewardAll(nowTime uint64) {
  724. curDiffDay := util.GetDurationDay2(this.role.RegisterTime, nowTime) - 1
  725. if curDiffDay <= 0 {
  726. return
  727. }
  728. cfgData, ok := model.ConvertOnlineRewardList[curDiffDay]
  729. if !ok {
  730. return
  731. }
  732. tmpTotalOnlineTime := this.roleBase.TotalOnlineTime
  733. rewardList := map[int32]int32{}
  734. for idx := 0; idx < len(cfgData); idx++ {
  735. if cfgData[idx].Id > this.roleBase.OnlineRewardId {
  736. if cfgData[idx].RewardToTalTime <= tmpTotalOnlineTime {
  737. util.DebugF("uid=%v rewardid=%v onlinetime=%v rewardAll beffor", this.role.GetUUid(),
  738. this.roleBase.OnlineRewardId, this.roleBase.TotalOnlineTime)
  739. for k := 0; k < len(cfgData[idx].RewardList); k++ {
  740. item := cfgData[idx].RewardList[k]
  741. rewardList[item.Key] += item.Value
  742. }
  743. }
  744. }
  745. }
  746. if len(rewardList) > 0 {
  747. this.role.GetRoleMail().AddMail(23, serverproto.MailType_MailType_OnlineReward,
  748. rewardList, nil, "", "")
  749. }
  750. }
  751. func (this *RoleBase) SlotChangNtf(heroId int32, slotData *serverproto.SlotData) {
  752. //英雄槽位数据变更通知
  753. ntfMsg := &serverproto.SCSlotDataNtf{
  754. HeroId: heroId,
  755. Slot: &serverproto.SlotData{},
  756. }
  757. *ntfMsg.Slot = *slotData
  758. this.role.ReplayGate(ntfMsg, true)
  759. }
  760. func (this *RoleBase) SkillEquipSlotChangNtf(heroId int32, slotData *serverproto.SkillEquipSlotData) {
  761. //英雄槽位数据变更通知
  762. ntfMsg := &serverproto.SCSkillEquipSlotDataNtf{
  763. HeroId: heroId,
  764. Slot: &serverproto.SkillEquipSlotData{},
  765. }
  766. *ntfMsg.Slot = *slotData
  767. this.role.ReplayGate(ntfMsg, true)
  768. }
  769. func (this *RoleBase) FashionChangeNtf() {
  770. //时装数据变更通知
  771. //ntfMsg := &serverproto.SCFashionDataNtf{
  772. // FashionUpList: this.roleBase.FashionData.FashionUpList,
  773. //}
  774. //this.role.ReplayGate(ntfMsg, true)
  775. }
  776. // 更新玩家简介信息
  777. func (this *RoleBase) UpdatePlayerBriefInfo(bOffline bool) {
  778. ssMsg := &serverproto.SSRoleBriefInfoSaveReq{
  779. BriefInfo: &serverproto.CommonPlayerBriefInfo{
  780. Uid: this.roleBase.Id,
  781. NickName: this.roleBase.NickName,
  782. Gender: this.roleBase.Sex,
  783. Level: this.roleBase.RoleData.HeroData.BaseLevel,
  784. ConfigId: this.roleBase.RoleData.HeroData.ConfigId,
  785. FightPower: int32(this.role.roleBattleAttr.curTotalFightPower),
  786. //FightPower: int32(this.role.GetRoleFightPower().TotalFightPower), //(this.roleBase.RoleData.FightPower),
  787. ImgId: this.role.GetImageId(),
  788. TowerLevel: this.role.GetRoleTower().nowTowerLevel,
  789. TowerTime: uint64(this.role.GetRoleTower().nowTowerPassTime),
  790. MapLevelId: this.role.GetRoleBattle().GetLevelId(),
  791. HeadFrameId: this.roleBase.RoleData.HeadFrameId,
  792. VipLevel: this.roleBase.VipLevel,
  793. Rmb: uint64(this.GetRmb()),
  794. Zeny: this.GetMoney(),
  795. TotalRecharge: this.roleBase.TotalRecharge,
  796. LastRechargeTime: this.roleBase.LastRechargeTime,
  797. MaxFightPower: uint32(this.RoleData().FightPower),
  798. HeadId: this.role.GetHeadId(),
  799. },
  800. OpenId: this.role.GetOpenId(),
  801. ActiveCode: this.role.activeCode,
  802. SubPlatform: this.role.GetSubPlatform(),
  803. }
  804. if this.role.GetRoleDaoChang100() != nil {
  805. ssMsg.BriefInfo.Daochang100Tips = this.role.GetRoleDaoChang100().dataInfo.TipsDesc
  806. }
  807. ssMsg.BriefInfo.OnlineTime = this.RoleData().LastLoginTime
  808. this.role.SendDb(ssMsg)
  809. }
  810. // 是否是可重置的属性点类型
  811. func (this *RoleBase) isAttrPointType(attrKey int32) bool {
  812. key := serverproto.Attr(attrKey)
  813. if key == serverproto.Attr_Str || key == serverproto.Attr_Agi || key == serverproto.Attr_Int ||
  814. key == serverproto.Attr_Vit || key == serverproto.Attr_Dex || key == serverproto.Attr_Luk {
  815. return true
  816. }
  817. return false
  818. }
  819. // 主角经验 + 升级
  820. func (this *RoleBase) AddBaseExp(st AddItemST) int32 {
  821. exp := st.ItemCount
  822. if exp <= 0 || exp >= math.MaxInt32 {
  823. return 0
  824. }
  825. var changLevel int32 = 0
  826. var attrPoint int32 = 0
  827. oldLevel := this.RoleData().HeroData.BaseLevel
  828. newLevel := oldLevel
  829. //newExp := this.RoleData().BaseExp + exp
  830. tmpExp := uint64(this.RoleData().BaseExp) + uint64(exp)
  831. if tmpExp >= math.MaxInt32 {
  832. tmpExp = math.MaxInt32 - 1
  833. util.InfoF("uid=%v AddBaseExp exp max limit", this.role.GetUUid())
  834. }
  835. newExp := int32(tmpExp)
  836. for {
  837. cfgData, ok := serverproto.RoleAttributeCfgLoader[newLevel]
  838. _, ok1 := serverproto.RoleAttributeCfgLoader[newLevel+1]
  839. if !ok || !ok1 {
  840. util.InfoF("uid=%v AddBaseExp error", this.role.GetUUid())
  841. break
  842. }
  843. if newExp >= cfgData.Name && cfgData.Name > 0 {
  844. newLevel++
  845. newExp -= cfgData.Name
  846. attrPoint += cfgData.GetPoint
  847. } else {
  848. break
  849. }
  850. }
  851. this.RoleData().BaseExp = newExp
  852. if newLevel > oldLevel {
  853. ntfMsg := &serverproto.SCBaseLevelUpNtf{
  854. OldLevel: oldLevel,
  855. NewLevel: newLevel,
  856. }
  857. this.role.ReplayGate(ntfMsg, true)
  858. changLevel = newLevel - oldLevel
  859. this.RoleData().HeroData.BaseLevel = newLevel
  860. //获得属性点
  861. this.role.GetRoleHero().GetMainHero().AttrPoint += attrPoint
  862. //判断等级相关的解锁信息,属性变化
  863. this.processLevelState(oldLevel, newLevel)
  864. }
  865. this.SetDirty(true)
  866. util.InfoF("uid=%v AddBaseExp addExp=%v newBaseExp=%v oldLevel=%v newLevel=%v", this.role.GetUUid(),
  867. exp, this.RoleData().BaseExp, oldLevel, newLevel)
  868. return changLevel
  869. }
  870. func (this *RoleBase) processLevelState(oldLevel int32, newLevel int32) {
  871. util.DebugF("uid=%v processLevelState oldLevel=%v newLevel=%v", this.role.GetUUid(), oldLevel, newLevel)
  872. //判断解锁技能槽位
  873. if this.role.GetRoleSkill() != nil {
  874. this.role.GetRoleSkill().CheckSlotLockState()
  875. }
  876. //判断解锁卡槽
  877. if this.role.GetRoleCard() != nil {
  878. this.role.GetRoleCard().CheckUnLockState()
  879. }
  880. //任务条件处理
  881. TaskMagCheck(this.role, serverproto.TaskType_Base_Level, 0)
  882. //升级属性变化
  883. //this.role.roleFightPower.onFighterAttrChange(this.role.roleHero.GetMainHero().Id)
  884. this.role.roleBattleAttr.ResetLevelAttrList(this.RoleData().HeroData)
  885. //英灵殿匹配对象最低等级
  886. if oldLevel < model.GlobalDaoChangRankMinLevel && newLevel >= model.GlobalDaoChangRankMinLevel {
  887. this.role.GetRoleArena().SetArenaScoreRank(0)
  888. }
  889. //超值礼包开启
  890. if this.role.GetRoleActivity() != nil {
  891. this.role.GetRoleActivity().SuperChargeUnlockCheck(
  892. serverproto.UnlockChargeType_UChargeType_BaseLevel, &SuperChargeUnlockST{oldValue: oldLevel})
  893. this.role.GetRoleActivity().SuperChargeUnlockCheck(
  894. serverproto.UnlockChargeType_UChargeType_SkillLevelUp, &SuperChargeUnlockST{oldValue: oldLevel})
  895. }
  896. this.role.registerServerList(this.roleBase.RoleData.HeadFrameId, newLevel)
  897. this.UpdatePlayerBriefInfo(false)
  898. //添加到mysql log
  899. logData := &serverproto.SSRoleLogData{
  900. Uid: this.role.GetUUid(),
  901. Type: int32(serverproto.MysqlLogType_LType_Level),
  902. ParamList: []int32{int32(oldLevel), int32(newLevel), int32(newLevel - oldLevel)}, //oldLevel,newLevel
  903. }
  904. mysqlLevelNtf := &serverproto.SSRoleLogNtf{}
  905. mysqlLevelNtf.LogList = append(mysqlLevelNtf.LogList, logData)
  906. SendDb(mysqlLevelNtf)
  907. //邀请码导师处理
  908. if this.role.GetRoleInvitation() != nil {
  909. this.role.GetRoleInvitation().InvitationNoticeMaster(
  910. &serverproto.KeyValueType{
  911. Key: int32(serverproto.TaskType_Invitation_Base_Level_Num),
  912. Value: newLevel})
  913. }
  914. }
  915. // 返回改变的等级
  916. func (this *RoleBase) AddJobExp(st AddItemST) int32 {
  917. exp := st.ItemCount
  918. if exp <= 0 || exp >= math.MaxInt32 {
  919. return 0
  920. }
  921. jobCfgData, ok := serverproto.JobCfgLoader[this.RoleData().HeroData.ConfigId]
  922. if !ok || this.GetRoleJobLevel() >= jobCfgData.MaxJobLv {
  923. return 0
  924. }
  925. var changLevel int32
  926. var jobPoint int32
  927. oldLevel := this.RoleData().JobLevel
  928. newLevel := oldLevel
  929. //newExp := this.RoleData().JobExp + exp
  930. tmpExp := uint64(this.RoleData().JobExp) + uint64(exp)
  931. if tmpExp >= math.MaxInt32 {
  932. tmpExp = math.MaxInt32 - 1
  933. util.InfoF("uid=%v AddJobExp exp max limit", this.role.GetUUid())
  934. }
  935. newExp := int32(tmpExp)
  936. for {
  937. cfgData, ok := serverproto.JobExpCfgLoader[newLevel]
  938. _, ok1 := serverproto.JobExpCfgLoader[newLevel]
  939. if !ok || !ok1 {
  940. util.WarnF("uid=%v AddJobExp error not level data level=%v", this.role.GetUUid(), newLevel)
  941. break
  942. }
  943. var needExp int32 = -1
  944. var addPoint int32
  945. switch jobCfgData.JobStage {
  946. case 0:
  947. needExp = cfgData.ExpRequire1
  948. addPoint = cfgData.Point1
  949. case 1:
  950. needExp = cfgData.ExpRequire2
  951. addPoint = cfgData.Point2
  952. case 2:
  953. needExp = cfgData.ExpRequire3
  954. addPoint = cfgData.Point3
  955. }
  956. if newExp >= needExp && needExp >= 0 {
  957. newLevel++
  958. newExp -= needExp
  959. jobPoint += addPoint
  960. if newLevel >= jobCfgData.MaxJobLv { //到了当前职业最大等级,经验条设为0
  961. newExp = 0
  962. break
  963. }
  964. } else {
  965. break
  966. }
  967. }
  968. this.RoleData().JobExp = newExp
  969. if newLevel > oldLevel {
  970. ntfMsg := &serverproto.SCJobLevelUpNtf{
  971. OldLevel: oldLevel,
  972. NewLevel: newLevel,
  973. }
  974. this.role.ReplayGate(ntfMsg, true)
  975. changLevel = newLevel - oldLevel
  976. this.RoleData().JobLevel = newLevel
  977. //任务条件处理
  978. TaskMagCheck(this.role, serverproto.TaskType_Job_Level, 0)
  979. }
  980. this.SetDirty(true)
  981. util.InfoF("uid=%v AddJobExp addexp=%v newBaseExp=%v oldLevel=%v newLevel=%v", this.role.GetUUid(),
  982. exp, this.RoleData().JobExp, oldLevel, newLevel)
  983. return changLevel
  984. }
  985. // 根据类型获得具体部位索引
  986. func (this *RoleBase) GetSlotIndexByType(slotType int32) int32 {
  987. switch slotType {
  988. case Equip_Type_Head:
  989. return SLOT_TYPE_INDEX_Head
  990. case Equip_Type_Body:
  991. return SLOT_TYPE_INDEX_Body
  992. case Equip_Type_Weapon:
  993. return SLOT_TYPE_INDEX_Weapon
  994. case Equip_Type_Wrap:
  995. return SLOT_TYPE_INDEX_Wrap
  996. case Equip_Type_Shoes:
  997. return SLOT_TYPE_INDEX_Shoes
  998. case Equip_Type_Jew:
  999. return SLOT_TYPE_INDEX_Jew
  1000. default:
  1001. return SLOT_TYPE_INDEX
  1002. }
  1003. }
  1004. func (this *RoleBase) GetSlotTypeByIndex(slotIndex int32) int32 {
  1005. switch slotIndex {
  1006. case SLOT_TYPE_INDEX_Head:
  1007. return Equip_Type_Head
  1008. case SLOT_TYPE_INDEX_Body:
  1009. return Equip_Type_Body
  1010. case SLOT_TYPE_INDEX_Weapon:
  1011. return Equip_Type_Weapon
  1012. case SLOT_TYPE_INDEX_Wrap:
  1013. return Equip_Type_Wrap
  1014. case SLOT_TYPE_INDEX_Shoes:
  1015. return Equip_Type_Shoes
  1016. case SLOT_TYPE_INDEX_Jew:
  1017. return Equip_Type_Jew
  1018. default:
  1019. return Equip_Type_None
  1020. }
  1021. }
  1022. func (this *RoleBase) getSlotData(heroId int32) *serverproto.SlotData {
  1023. heroData := this.role.GetRoleHero().GetHero(heroId)
  1024. if heroData == nil {
  1025. return nil
  1026. }
  1027. return heroData.Slot
  1028. }
  1029. func (this *RoleBase) getSkillEquipSlotData(heroId int32) *serverproto.SkillEquipSlotData {
  1030. heroData := this.role.GetRoleHero().GetHero(heroId)
  1031. if heroData == nil {
  1032. return nil
  1033. }
  1034. if heroData.SkillEquipSlot == nil {
  1035. heroData.SkillEquipSlot = &serverproto.SkillEquipSlotData{}
  1036. }
  1037. typeLen := len(heroData.SkillEquipSlot.SlotList)
  1038. if typeLen < SKILL_EQUIP_SLOT_TYPE_NUM {
  1039. for i := 0; i < SKILL_EQUIP_SLOT_TYPE_NUM-typeLen; i++ {
  1040. heroData.SkillEquipSlot.SlotList =
  1041. append(heroData.SkillEquipSlot.SlotList,
  1042. &serverproto.SkillEquipSlotDetailData{SlotLevel: 1})
  1043. }
  1044. }
  1045. return heroData.SkillEquipSlot
  1046. }
  1047. func (this *RoleBase) EquipUp(heroId int32, slotIndex int32, equipId int32) serverproto.ErrorCode {
  1048. heroData := this.role.GetRoleHero().GetHero(heroId)
  1049. if heroData == nil {
  1050. util.WarnF("uid=%v EquipUp hero data not found heroId=%v", this.role.GetUUid(), heroId)
  1051. return serverproto.ErrorCode_ERROR_FAIL
  1052. }
  1053. //var slotData *serverproto.SlotData = nil
  1054. slotData := heroData.Slot
  1055. if slotData == nil {
  1056. util.WarnF("uid=%v EquipUp slotData nil heroId=%v", this.role.GetUUid(), heroId)
  1057. return serverproto.ErrorCode_ERROR_FAIL
  1058. }
  1059. typeLen := len(slotData.SlotList)
  1060. if typeLen < SLOT_TYPE_NUM {
  1061. for i := 0; i < SLOT_TYPE_NUM-typeLen; i++ {
  1062. slotData.SlotList = append(slotData.SlotList, &serverproto.SlotDetailData{})
  1063. }
  1064. }
  1065. //equip all
  1066. if slotIndex != 0 {
  1067. return this.role.GetRoleEquip().EquipUp(heroId, slotData, equipId, slotIndex)
  1068. }
  1069. this.role.GetRoleEquip().EquipUpAll(heroId, slotData)
  1070. return serverproto.ErrorCode_ERROR_OK
  1071. }
  1072. // 任意N件装备精炼等级达到X级
  1073. func (this *RoleBase) GetEquipSlotLevelNum(equipLevel int32) int32 {
  1074. var retNum int32 = 0
  1075. //game hero
  1076. retNum += this.GetMainEquipSlotLevelNum(equipLevel)
  1077. //fellow
  1078. retNum += this.GetPartnerEquipSlotLevelNum(equipLevel)
  1079. return retNum
  1080. }
  1081. // 任意N件装备精炼等级达到X级
  1082. func (this *RoleBase) GetEquipSlotLevelRoleCnt(equipLevel int32) int32 {
  1083. var retNum int32 = 0
  1084. all := false
  1085. slotData := this.role.GetRoleBase().RoleData().HeroData.Slot
  1086. for _, detailData := range slotData.SlotList {
  1087. if detailData.Level < equipLevel {
  1088. all = false
  1089. break
  1090. }
  1091. all = true
  1092. }
  1093. if all {
  1094. retNum += 1
  1095. }
  1096. for _, heroData := range this.role.GetRoleHero().heroList {
  1097. if heroData.Slot == nil {
  1098. continue
  1099. }
  1100. find := false
  1101. for _, detailData := range heroData.Slot.SlotList {
  1102. if detailData.Level < equipLevel {
  1103. find = false
  1104. break
  1105. }
  1106. find = true
  1107. }
  1108. if find {
  1109. retNum += 1
  1110. }
  1111. }
  1112. return retNum
  1113. }
  1114. func (this *RoleBase) GetMainEquipSlotLevelNum(equipLevel int32) int32 {
  1115. var retNum int32 = 0
  1116. //game hero
  1117. slotData := this.role.GetRoleBase().RoleData().HeroData.Slot
  1118. for _, detailData := range slotData.SlotList {
  1119. if detailData.Level >= equipLevel {
  1120. retNum++
  1121. }
  1122. }
  1123. return retNum
  1124. }
  1125. func (this *RoleBase) GetPartnerEquipSlotLevelNum(equipLevel int32) int32 {
  1126. var retNum int32 = 0
  1127. for _, heroData := range this.role.GetRoleHero().heroList {
  1128. if heroData.Slot == nil {
  1129. continue
  1130. }
  1131. for _, detailData := range heroData.Slot.SlotList {
  1132. if detailData.Level >= equipLevel {
  1133. retNum++
  1134. }
  1135. }
  1136. }
  1137. return retNum
  1138. }
  1139. func (this *RoleBase) EquipDown(heroId int32, subIndex int32) {
  1140. slotData := this.getSlotData(heroId)
  1141. if slotData == nil {
  1142. util.WarnF("uid=%v EquipDown slotData nil heroId=%v", this.role.GetUUid(), heroId)
  1143. return
  1144. }
  1145. this.role.GetRoleEquip().EquipDown(heroId, slotData, subIndex)
  1146. }
  1147. func (this *RoleBase) ChangeJobRefreshFashion(heroId int32) {
  1148. slotData := this.getSlotData(heroId)
  1149. if slotData == nil {
  1150. util.WarnF("uid=%v EquipDown slotData nil heroId=%v", this.role.GetUUid(), heroId)
  1151. return
  1152. }
  1153. this.role.GetRoleFashion().ChangeJobRefresh(heroId)
  1154. }
  1155. func (this *RoleBase) EquipLevelUpAll(heroId int32) {
  1156. ackMsg := &serverproto.SCEquipLevelUpAllAck{
  1157. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  1158. }
  1159. slotData := this.getSlotData(heroId)
  1160. if slotData == nil {
  1161. util.WarnF("uid=%v EquipLevelUpAll slotData nil heroId=%v", this.role.GetUUid(), heroId)
  1162. this.role.ReplayGate(ackMsg, true)
  1163. return
  1164. }
  1165. ret := this.role.GetRoleEquip().EquipLevelUpAll(heroId, slotData)
  1166. if ret {
  1167. ackMsg := &serverproto.SCEquipLevelUpAllAck{
  1168. Error: int32(serverproto.ErrorCode_ERROR_OK),
  1169. }
  1170. this.role.ReplayGate(ackMsg, true)
  1171. TaskMagCheck(this.role, serverproto.TaskType_Eve_Battle_Role_Quality, 0)
  1172. }
  1173. }
  1174. func (this *RoleBase) EquipSlotLevelUp(heroId, subSlotIndex int32) serverproto.ErrorCode {
  1175. slotData := this.getSlotData(heroId)
  1176. if slotData == nil {
  1177. util.WarnF("uid=%v EquipSlotLevelUp slotData nil heroId=%v", this.role.GetUUid(), heroId)
  1178. return serverproto.ErrorCode_ERROR_FAIL
  1179. }
  1180. return this.role.GetRoleEquip().SlotLevelUp(slotData, heroId, subSlotIndex)
  1181. }
  1182. func (this *RoleBase) SlotCardMount(heroId, subSlotIndex, cardSlotIndex, cardCfgId int32) serverproto.ErrorCode {
  1183. slotData := this.getSlotData(heroId)
  1184. if slotData == nil {
  1185. util.WarnF("uid=%v SlotCardMount slotData nil heroId=%v", this.role.GetUUid(), heroId)
  1186. return serverproto.ErrorCode_ERROR_FAIL
  1187. }
  1188. if subSlotIndex > int32(len(slotData.SlotList)) || subSlotIndex < 0 {
  1189. return serverproto.ErrorCode_ERROR_FAIL
  1190. }
  1191. //当前槽位没有装备,无法进行卡片镶嵌
  1192. if slotData.SlotList[subSlotIndex-1].EquipId == 0 {
  1193. return serverproto.ErrorCode_ERROR_FAIL
  1194. }
  1195. ret := this.role.GetRoleCard().Mount(slotData, heroId, subSlotIndex, cardSlotIndex, cardCfgId, true)
  1196. if ret == serverproto.ErrorCode_ERROR_OK {
  1197. this.SetDirty(true)
  1198. this.role.GetRoleHero().addHeroChange(heroId)
  1199. //槽位上的卡片数据变更
  1200. this.SlotChangNtf(heroId, slotData)
  1201. this.role.roleBattleAttr.AttrChange(
  1202. AttrChangeST{
  1203. ChangeType: Attr_Change_Card,
  1204. ChangeHeroData: this.role.GetRoleHero().GetHero(heroId),
  1205. })
  1206. }
  1207. return ret
  1208. }
  1209. func (this *RoleBase) SlotCardDown(heroId, subSlotIndex, cardSlotIndex int32) serverproto.ErrorCode {
  1210. slotData := this.getSlotData(heroId)
  1211. if slotData == nil {
  1212. util.WarnF("uid=%v SlotCardDown slotData nil heroId=%v", this.role.GetUUid(), heroId)
  1213. return serverproto.ErrorCode_ERROR_FAIL
  1214. }
  1215. ret := serverproto.ErrorCode_ERROR_OK
  1216. if cardSlotIndex == 0 {
  1217. //一键卸下
  1218. ret = this.role.GetRoleCard().CardDownAll(slotData, subSlotIndex, heroId, true)
  1219. } else {
  1220. //单部位卸下
  1221. ret = this.role.GetRoleCard().CardDown(slotData, subSlotIndex, cardSlotIndex, heroId)
  1222. }
  1223. if ret == serverproto.ErrorCode_ERROR_OK {
  1224. //战斗力计算
  1225. //this.role.roleFightPower.CardAttrChange(heroId, subSlotIndex)
  1226. this.SetDirty(true)
  1227. this.role.GetRoleHero().addHeroChange(heroId)
  1228. this.SlotChangNtf(heroId, slotData)
  1229. }
  1230. return ret
  1231. }
  1232. func (this *RoleBase) CheckCardOp() serverproto.ErrorCode {
  1233. if this.cardOperation != 0 && this.cardOperation+Card_Operation > util.GetTimeSeconds() {
  1234. return serverproto.ErrorCode_ERROR_CARD_OP_SLOT_CARD_TOO_FAST
  1235. }
  1236. return serverproto.ErrorCode_ERROR_OK
  1237. }
  1238. func (this *RoleBase) SlotCardMountAll(msg *serverproto.CSCardEquipAllReq) serverproto.ErrorCode {
  1239. vipCardMount := this.role.GetRoleBase().GetVipData(model.Vip_System_CardInsert)
  1240. if vipCardMount <= 0 {
  1241. return serverproto.ErrorCode_ERROR_VIP_LEVEL_LOW
  1242. }
  1243. ret := this.CheckCardOp()
  1244. if ret != serverproto.ErrorCode_ERROR_OK {
  1245. return ret
  1246. }
  1247. slotData := this.getSlotData(msg.HeroId)
  1248. if slotData == nil {
  1249. util.WarnF("uid=%v SlotCardDownAll slotData nil", this.role.GetUUid())
  1250. return serverproto.ErrorCode_ERROR_FAIL
  1251. }
  1252. var bRet serverproto.ErrorCode
  1253. for _, cardData := range msg.EqiupSlotData {
  1254. for _, card := range cardData.CardSlotInfo {
  1255. ret := this.role.GetRoleCard().Mount(slotData, msg.HeroId, cardData.SlotId, card.Key, card.Value, false)
  1256. if ret == serverproto.ErrorCode_ERROR_OK { //有问题,也要计算后续的
  1257. bRet = serverproto.ErrorCode_ERROR_OK
  1258. }
  1259. }
  1260. }
  1261. //如果有卡片装备成功
  1262. if bRet == serverproto.ErrorCode_ERROR_OK {
  1263. this.SetDirty(true)
  1264. this.role.GetRoleHero().addHeroChange(msg.HeroId)
  1265. //槽位上的卡片数据变更
  1266. this.SlotChangNtf(msg.HeroId, slotData)
  1267. //战斗力计算
  1268. //this.role.roleFightPower.AllCardAttrChange(msg.HeroId)
  1269. this.role.roleBattleAttr.AttrChange(
  1270. AttrChangeST{
  1271. ChangeType: Attr_Change_Card,
  1272. ChangeHeroData: this.role.GetRoleHero().GetHero(msg.HeroId),
  1273. })
  1274. }
  1275. this.cardOperation = util.GetTimeSeconds()
  1276. return serverproto.ErrorCode_ERROR_OK
  1277. }
  1278. func (this *RoleBase) SlotCardDownAll(heroId int32) serverproto.ErrorCode {
  1279. ret := this.CheckCardOp()
  1280. if ret != serverproto.ErrorCode_ERROR_OK {
  1281. return ret
  1282. }
  1283. slotData := this.getSlotData(heroId)
  1284. if slotData == nil {
  1285. util.WarnF("uid=%v SlotCardDownAll slotData nil heroId=%v", this.role.GetUUid(), heroId)
  1286. return serverproto.ErrorCode_ERROR_FAIL
  1287. }
  1288. //检查是否装备卡片
  1289. var bRet serverproto.ErrorCode
  1290. for idx := range slotData.SlotList {
  1291. if slotData.SlotList[idx].EquipId == 0 {
  1292. continue
  1293. }
  1294. ret := this.role.GetRoleCard().CardDownAll(slotData, int32(idx+1), heroId, false)
  1295. if ret == serverproto.ErrorCode_ERROR_OK {
  1296. bRet = serverproto.ErrorCode_ERROR_OK
  1297. }
  1298. }
  1299. if bRet == serverproto.ErrorCode_ERROR_OK {
  1300. this.SetDirty(true)
  1301. this.role.GetRoleHero().addHeroChange(heroId)
  1302. this.SlotChangNtf(heroId, slotData)
  1303. this.role.roleBattleAttr.AttrChange(
  1304. AttrChangeST{
  1305. ChangeType: Attr_Change_Card,
  1306. ChangeHeroData: this.role.GetRoleHero().GetHero(heroId),
  1307. })
  1308. //战斗力计算
  1309. //this.role.roleFightPower.AllCardAttrChange(heroId)
  1310. this.cardOperation = util.GetTimeSeconds()
  1311. return serverproto.ErrorCode_ERROR_OK
  1312. }
  1313. return serverproto.ErrorCode_ERROR_FAIL
  1314. }
  1315. func (this *RoleBase) SlotCardUpGradeAll(msg *serverproto.CSCardUpGradeAllReq) serverproto.ErrorCode {
  1316. ret := this.CheckCardOp()
  1317. if ret != serverproto.ErrorCode_ERROR_OK {
  1318. return ret
  1319. }
  1320. slotData := this.getSlotData(msg.HeroId)
  1321. if slotData == nil {
  1322. util.WarnF("uid=%v SlotCardDownAll slotData nil heroId=%v", this.role.GetUUid(), msg.HeroId)
  1323. return serverproto.ErrorCode_ERROR_FAIL
  1324. }
  1325. var bChanged = false
  1326. var changIdList = set.New(set.NonThreadSafe)
  1327. for _, data := range msg.Data {
  1328. //check key 装备位序号,value 卡片位序号
  1329. if data.Key < Equip_Type_Head || data.Key > Equip_Type_Jew || data.Value <= 0 || data.Value > Max_Card_Slot_Num {
  1330. continue
  1331. }
  1332. //装备位没有装备不让操作。
  1333. slotData := slotData.SlotList[data.Key-1]
  1334. if slotData == nil || slotData.EquipId == 0 {
  1335. continue
  1336. }
  1337. if int(data.Value) <= len(slotData.CardIdList) && data.Value > 0 {
  1338. cardData := slotData.CardIdList[data.Value-1]
  1339. if cardData == 0 {
  1340. continue
  1341. }
  1342. //走合成卡片流程, toCardId合成的目标ID
  1343. bRet, toCardId := this.role.GetRoleCard().SlotCardLevelUp(cardData, changIdList)
  1344. if !bRet {
  1345. continue
  1346. }
  1347. changIdList.Add(slotData.CardIdList[data.Value-1])
  1348. slotData.CardIdList[data.Value-1] = toCardId
  1349. bChanged = true
  1350. }
  1351. }
  1352. if bChanged == true {
  1353. //set dirty
  1354. this.role.GetRoleHero().addHeroChange(msg.HeroId)
  1355. this.role.GetRoleCard().cardChangNtf(changIdList, false)
  1356. this.SlotChangNtf(msg.HeroId, slotData)
  1357. //this.role.GetRoleFightPower().AllCardAttrChange(msg.HeroId)
  1358. this.role.roleBattleAttr.AttrChange(AttrChangeST{
  1359. ChangeType: Attr_Change_Card,
  1360. ChangeHeroData: this.role.GetRoleHero().GetHero(msg.HeroId),
  1361. })
  1362. return serverproto.ErrorCode_ERROR_OK
  1363. }
  1364. this.cardOperation = util.GetTimeSeconds()
  1365. return serverproto.ErrorCode_ERROR_FAIL
  1366. }
  1367. func (this *RoleBase) checkUnLockState(heroId int32, condition []*serverproto.KeyValueType) serverproto.ErrorCode {
  1368. if len(condition) <= 0 {
  1369. return serverproto.ErrorCode_ERROR_OK
  1370. }
  1371. for id := range condition {
  1372. conType := condition[id].Key
  1373. conValue := condition[id].Value
  1374. switch (serverproto.TaskType)(conType) {
  1375. //使用任务枚举字段
  1376. case serverproto.TaskType_Base_Level: //角色等级
  1377. heroData := this.role.roleHero.GetHero(heroId)
  1378. if heroData == nil {
  1379. return serverproto.ErrorCode_ERROR_HERO_NO_FOUND
  1380. }
  1381. if heroData.BaseLevel < int32(conValue) { //获取英雄的等级来判定
  1382. return serverproto.ErrorCode_ERROR_SKILL_ROLE_LEVEL_NOT_ENOUGH
  1383. }
  1384. case serverproto.TaskType_Level_Battle_Count:
  1385. if this.role.GetRoleBattle().getLevelId(this.role.GetRoleBattle().mapId, this.role.GetRoleBattle().mapLevel) < int32(conValue) {
  1386. return serverproto.ErrorCode_ERROR_MAP_MAP_LEVEL_LOW
  1387. }
  1388. case serverproto.TaskType_Climbing_Tower_Level: //爬塔到达层数
  1389. if this.role.GetRoleTower().GetCurTower() < int32(conValue) {
  1390. return serverproto.ErrorCode_ERROR_FAIL
  1391. }
  1392. case serverproto.TaskType_VIP_Level:
  1393. if this.role.GetRoleVipLevel() < int32(conValue) {
  1394. return serverproto.ErrorCode_ERROR_FAIL
  1395. }
  1396. case serverproto.TaskType_Start_Server_Days:
  1397. startUpTime := service.GetServiceStartupTime()
  1398. if startUpTime < 0 {
  1399. util.ErrorF("[convertRushListCfg] data error:%v")
  1400. return serverproto.ErrorCode_ERROR_FAIL
  1401. }
  1402. durationDay := util.GetDurationDay2(startUpTime, util.GetCurrentTime())
  1403. if durationDay < int32(conValue) {
  1404. return serverproto.ErrorCode_ERROR_FAIL
  1405. }
  1406. default:
  1407. return serverproto.ErrorCode_ERROR_FAIL
  1408. }
  1409. }
  1410. return serverproto.ErrorCode_ERROR_OK
  1411. }
  1412. func (this *RoleBase) SetFightPower(fightPower uint32) {
  1413. nowTime := util.GetTimeMilliseconds()
  1414. if this.RoleData().FightPower < uint64(fightPower) {
  1415. this.RoleData().FightPower = uint64(fightPower)
  1416. this.SetDirty(true)
  1417. //设置历史战力排行榜
  1418. ssReqMsg := &serverproto.SSMaxFightPowerRankNtf{
  1419. Uid: this.role.GetUUid(),
  1420. MaxFightPower: this.RoleData().FightPower,
  1421. }
  1422. this.role.SendRank(ssReqMsg)
  1423. //cross rank
  1424. //更新跨服最大战力排行榜
  1425. if this.role.GetRoleBattle().GetLevelId() >= model.GlobalCrossMaxFightPowerRankVal {
  1426. crossSSMsg := &serverproto.SSCrossRankUpdateNtf{
  1427. SelfMaxFightPower: uint64(fightPower),
  1428. FightInfo: &serverproto.FightRoleInfo{},
  1429. }
  1430. this.role.GetRoleFightInfo(crossSSMsg.FightInfo, false)
  1431. crossSSMsg.FightInfo.BriefInfo.FightPower = int32(fightPower)
  1432. this.role.SendSocial(crossSSMsg)
  1433. this.lastFightPowerChangeTimeStamp = nowTime
  1434. }
  1435. }
  1436. //当前版本,暂定实时同步
  1437. if fightPower > 0 {
  1438. this.UpdatePlayerBriefInfo(false)
  1439. }
  1440. //设置简介信息 //战力超过5K。立刻写入,战力低于5000,每5次变化写入
  1441. /*
  1442. if fightPower >= 2000 {
  1443. this.UpdatePlayerBriefInfo(false)
  1444. this.fightChangeNum = 0
  1445. } else {
  1446. if this.fightChangeNum >= Max_Change_Count {
  1447. this.UpdatePlayerBriefInfo(false)
  1448. this.fightChangeNum = 0
  1449. } else {
  1450. this.fightChangeNum++
  1451. }
  1452. }
  1453. */
  1454. //更新跨服最大战力排行榜玩家阵容信息
  1455. if this.role.GetRoleBattle().GetLevelId() >= model.GlobalCrossMaxFightPowerRankVal {
  1456. fightInfoUpdateTime := model.GlobalCrossMaxFightPowerFightInfoUpdateTime * 1000
  1457. if nowTime-this.lastFightPowerChangeTimeStamp > uint64(fightInfoUpdateTime) {
  1458. this.lastFightPowerChangeTimeStamp = nowTime
  1459. crossSSMsg := &serverproto.SSCrossRankFightInfoUpdateNtf{
  1460. FightInfo: &serverproto.FightRoleInfo{},
  1461. CurSelfMaxFightPower: this.RoleData().FightPower,
  1462. }
  1463. this.role.GetRoleFightInfo(crossSSMsg.FightInfo, false)
  1464. if fightPower > 0 {
  1465. crossSSMsg.FightInfo.BriefInfo.FightPower = int32(fightPower)
  1466. } else {
  1467. if this.role.roleBattleAttr.curTotalFightPower > 0 {
  1468. crossSSMsg.FightInfo.BriefInfo.FightPower = int32(this.role.roleBattleAttr.curTotalFightPower)
  1469. } else {
  1470. crossSSMsg.FightInfo.BriefInfo.FightPower = int32(this.RoleData().FightPower)
  1471. }
  1472. }
  1473. this.role.SendSocial(crossSSMsg)
  1474. }
  1475. }
  1476. }
  1477. // 设置头像
  1478. func (this *RoleBase) SetRoleHeadPic(headId int32) serverproto.ErrorCode {
  1479. bRet := this.CheckHeadUnlock(headId)
  1480. if bRet && this.roleBase.RoleData.HeadId != headId && headId != 0 {
  1481. this.roleBase.RoleData.HeadId = headId
  1482. this.SetDirty(true)
  1483. return serverproto.ErrorCode_ERROR_OK
  1484. }
  1485. return serverproto.ErrorCode_ERROR_FAIL
  1486. }
  1487. // 请求头像信息
  1488. func (this *RoleBase) HeadInfoReq() {
  1489. ackMsg := &serverproto.SCHeadInfoAck{}
  1490. for _, data := range this.roleBase.Head_Info.HeadList {
  1491. ackMsg.HeadList = append(ackMsg.HeadList, data)
  1492. }
  1493. ackMsg.Head_Info = &this.role.roleTask.roleHeadCond
  1494. this.role.ReplayGate(ackMsg, true)
  1495. }
  1496. // 请求激活头像
  1497. func (this *RoleBase) ActiveHead(headId int32) serverproto.ErrorCode {
  1498. //检查headId是否已经被激活
  1499. if bRet := this.CheckHeadUnlock(headId); bRet {
  1500. return serverproto.ErrorCode_ERROR_ACTIVE_HEAD_UNLOCKED
  1501. }
  1502. //检查headId被激活条件是否满足
  1503. if !this.role.roleTask.CheckHeadUnlocked(headId) {
  1504. return serverproto.ErrorCode_ERROR_ACTIVE_HEAD_CHECK_CONDITION_FAILED
  1505. }
  1506. //解锁头像加入到解锁列表中
  1507. this.roleBase.Head_Info.HeadList = append(this.roleBase.Head_Info.HeadList, headId)
  1508. //通知客户端激活成功
  1509. this.SetDirty(true)
  1510. return serverproto.ErrorCode_ERROR_OK
  1511. }
  1512. func (this *RoleBase) AddHeadFrame(frameId, lastTime, count int32) serverproto.ErrorCode {
  1513. var endTime int64 = -1
  1514. var bFind = false
  1515. if this.roleBase.Head_Info != nil {
  1516. for _, data := range this.roleBase.Head_Info.HeadFrameList {
  1517. if data.HeadFrameId == frameId {
  1518. if data.HeadFrameTime == -1 { //已经是永久了
  1519. return serverproto.ErrorCode_ERROR_HEAD_FRAME_EXCHANGE_ITEM
  1520. }
  1521. if lastTime == -1 {
  1522. data.HeadFrameTime = -1
  1523. endTime = -1
  1524. } else {
  1525. data.HeadFrameTime += int64(count * lastTime * 3600)
  1526. endTime = data.HeadFrameTime
  1527. }
  1528. bFind = true
  1529. break
  1530. }
  1531. }
  1532. }
  1533. if bFind == false {
  1534. if lastTime != -1 {
  1535. endTime = util.GetTimeSeconds() + int64(count*lastTime)*3600
  1536. }
  1537. this.roleBase.Head_Info.HeadFrameList = append(this.roleBase.Head_Info.HeadFrameList, &serverproto.HeadFrameData{
  1538. HeadFrameId: frameId,
  1539. HeadFrameTime: endTime,
  1540. })
  1541. }
  1542. //通知头像框改变
  1543. var headFrame []*serverproto.HeadFrameData
  1544. headFrame = append(headFrame, &serverproto.HeadFrameData{
  1545. HeadFrameId: frameId,
  1546. HeadFrameTime: endTime,
  1547. })
  1548. this.HeadFrameChangeNtf(headFrame)
  1549. //this.role.GetRoleFightPower().HeadFrameAttrChange(false)
  1550. this.SetDirty(true)
  1551. this.role.roleBattleAttr.AttrChange(AttrChangeST{
  1552. ChangeType: Attr_Change_HeadFrame,
  1553. ChangeHeroData: this.role.GetRoleHero().GetMainHero(),
  1554. HeadFrameId: frameId,
  1555. })
  1556. TaskMagCheck(this.role, serverproto.TaskType_Eve_Head_Icon_Cont, 1)
  1557. return serverproto.ErrorCode_ERROR_OK
  1558. }
  1559. func (this *RoleBase) SetHeadFrameId(frameId int32) serverproto.ErrorCode {
  1560. nowTime := util.GetTimeSeconds()
  1561. if this.roleBase.Head_Info != nil && len(this.roleBase.Head_Info.HeadFrameList) > 0 {
  1562. for _, data := range this.roleBase.Head_Info.HeadFrameList {
  1563. if data.HeadFrameId == frameId {
  1564. if data.HeadFrameTime == -1 || (data.HeadFrameTime != -1 && int64(data.HeadFrameTime) >= nowTime) {
  1565. this.roleBase.GetRoleData().HeadFrameId = frameId
  1566. this.SetDirty(true)
  1567. this.UpdatePlayerBriefInfo(false)
  1568. return serverproto.ErrorCode_ERROR_OK
  1569. }
  1570. }
  1571. }
  1572. }
  1573. return serverproto.ErrorCode_ERROR_FAIL
  1574. }
  1575. func (this *RoleBase) GetHeadFrameCount() int32 {
  1576. if this.roleBase.Head_Info == nil {
  1577. return 0
  1578. }
  1579. return int32(len(this.roleBase.Head_Info.HeadFrameList))
  1580. }
  1581. func (this *RoleBase) PackHeadFrameInfo(ackMsg *serverproto.SCHeadFrameInfoAck) serverproto.ErrorCode {
  1582. if this.roleBase.Head_Info == nil || len(this.roleBase.Head_Info.HeadFrameList) <= 0 {
  1583. return serverproto.ErrorCode_ERROR_OK
  1584. }
  1585. for _, data := range this.roleBase.Head_Info.HeadFrameList {
  1586. if data.HeadFrameId != 0 && data.HeadFrameTime != 0 {
  1587. ackMsg.HeadFrame = append(ackMsg.HeadFrame, &serverproto.HeadFrameData{
  1588. HeadFrameId: data.HeadFrameId,
  1589. HeadFrameTime: data.HeadFrameTime,
  1590. })
  1591. }
  1592. }
  1593. return serverproto.ErrorCode_ERROR_OK
  1594. }
  1595. func (this *RoleBase) HeadFrameChangeNtf(headFrame []*serverproto.HeadFrameData) {
  1596. ntfMsg := &serverproto.SCHeadFrameChangeNtf{}
  1597. ntfMsg.HeadFrame = headFrame
  1598. this.role.ReplayGate(ntfMsg, true)
  1599. }
  1600. // 检查头像任务是否激活
  1601. func (this *RoleBase) CheckHeadUnlock(headId int32) bool {
  1602. for _, data := range this.roleBase.Head_Info.HeadList {
  1603. if data == headId {
  1604. return true
  1605. }
  1606. }
  1607. return false
  1608. }
  1609. func (this *RoleBase) ChangeNameItemEnough(name string, remove bool) serverproto.ErrorCode {
  1610. consumeCfg, ok := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Rename_Consume)]
  1611. if !ok {
  1612. return serverproto.ErrorCode_ERROR_RENAME_CONSUME_CONFIG_ERROR
  1613. }
  1614. if len(consumeCfg.SVal) > 0 {
  1615. var costItemList = map[int32]int32{}
  1616. k, v := model.Str2Res(consumeCfg.SVal)
  1617. if k > 0 && v > 0 {
  1618. costItemList[k] = v
  1619. if this.role.CheckResLitNum(costItemList) {
  1620. if remove {
  1621. this.role.DelItemList(costItemList, AddItemST{AddFrom: AddFrom_System})
  1622. } else {
  1623. return serverproto.ErrorCode_ERROR_OK
  1624. }
  1625. } else {
  1626. util.DebugF("uid=%v ChangeName chang name item not enough", this.role.GetUUid())
  1627. return serverproto.ErrorCode_ERROR_RENAME_ITEM_NOT_ENOUGH
  1628. }
  1629. }
  1630. }
  1631. return serverproto.ErrorCode_ERROR_OK
  1632. }
  1633. func (this *RoleBase) ChangeRoleName(name string) serverproto.ErrorCode {
  1634. bRet := this.ChangeNameItemEnough(name, true)
  1635. if bRet != serverproto.ErrorCode_ERROR_OK {
  1636. return bRet
  1637. }
  1638. this.Rename(name)
  1639. return serverproto.ErrorCode_ERROR_OK
  1640. }
  1641. func (this *RoleBase) SetGuideId(guideId int32) {
  1642. if this.roleBase.GuideId < guideId {
  1643. this.roleBase.GuideId = guideId
  1644. this.SetDirty(true)
  1645. }
  1646. }
  1647. func (this *RoleBase) SetStoryId(story *serverproto.KeyValueType) serverproto.ErrorCode {
  1648. tmpVal := story.Key*100 + story.Value
  1649. for index, data := range this.roleBase.StoryId {
  1650. //不是这个Key
  1651. if data/100 != story.Key {
  1652. continue
  1653. }
  1654. //重复发送
  1655. if data == tmpVal {
  1656. return serverproto.ErrorCode_ERROR_OK
  1657. }
  1658. //删除当前元素
  1659. this.roleBase.StoryId = append(this.roleBase.StoryId[:index], this.roleBase.StoryId[index+1:]...)
  1660. //记录新的元素
  1661. this.roleBase.StoryId = append(this.roleBase.StoryId, tmpVal)
  1662. this.SetDirty(true)
  1663. return serverproto.ErrorCode_ERROR_OK
  1664. }
  1665. this.roleBase.StoryId = append(this.roleBase.StoryId, tmpVal)
  1666. this.SetDirty(true)
  1667. return serverproto.ErrorCode_ERROR_OK
  1668. }
  1669. func (this *RoleBase) SetCompulsoryId(storyId, status int32) serverproto.ErrorCode {
  1670. if this.roleBase.Cguide == nil {
  1671. this.roleBase.Cguide = &serverproto.KeyValueType{
  1672. Key: storyId,
  1673. Value: status,
  1674. }
  1675. this.SetDirty(true)
  1676. return serverproto.ErrorCode_ERROR_OK
  1677. }
  1678. if this.roleBase.Cguide.Key > storyId {
  1679. return serverproto.ErrorCode_ERROR_FAIL
  1680. } else if this.roleBase.Cguide.Key == storyId {
  1681. if this.roleBase.Cguide.Value >= status {
  1682. return serverproto.ErrorCode_ERROR_FAIL
  1683. }
  1684. }
  1685. this.roleBase.Cguide.Key = storyId
  1686. this.roleBase.Cguide.Value = status
  1687. this.SetDirty(true)
  1688. return serverproto.ErrorCode_ERROR_OK
  1689. }
  1690. func (this *RoleBase) SetNewMapCartoonId(id int32, status int32) serverproto.ErrorCode {
  1691. if id == 0 || (status != NEW_MAP_CARTOON_START && status != NEW_MAP_CARTOON_END) {
  1692. return serverproto.ErrorCode_ERROR_FAIL
  1693. }
  1694. if this.roleBase.MapAnimation != nil {
  1695. if this.roleBase.MapAnimation.Key > id {
  1696. return serverproto.ErrorCode_ERROR_FAIL
  1697. }
  1698. if this.roleBase.MapAnimation.Key == id && this.roleBase.MapAnimation.Value == status {
  1699. return serverproto.ErrorCode_ERROR_FAIL
  1700. }
  1701. this.roleBase.MapAnimation.Key = id
  1702. this.roleBase.MapAnimation.Value = status
  1703. } else {
  1704. this.roleBase.MapAnimation = &serverproto.KeyValueType{
  1705. Key: id,
  1706. Value: NEW_MAP_CARTOON_START,
  1707. }
  1708. }
  1709. this.SetDirty(true)
  1710. return serverproto.ErrorCode_ERROR_OK
  1711. }
  1712. func (this *RoleBase) AddBossReward(addItemList map[int32]int32) {
  1713. for key, val := range addItemList {
  1714. bRet := false
  1715. for idx := 0; idx < len(this.roleBase.RoleData.BossRewardList); idx++ {
  1716. if this.roleBase.RoleData.BossRewardList[idx].Key == key {
  1717. bRet = true
  1718. this.roleBase.RoleData.BossRewardList[idx].Value += val
  1719. break
  1720. }
  1721. }
  1722. if !bRet {
  1723. this.roleBase.RoleData.BossRewardList = append(this.roleBase.RoleData.BossRewardList,
  1724. &serverproto.KeyValueType{
  1725. Key: key,
  1726. Value: val,
  1727. })
  1728. }
  1729. }
  1730. this.SetDirty(true)
  1731. }
  1732. func (this *RoleBase) HasBossReward() bool {
  1733. return len(this.roleBase.RoleData.BossRewardList) > 0
  1734. }
  1735. func (this *RoleBase) GetBossReward() []*serverproto.KeyValueType {
  1736. return this.roleBase.RoleData.BossRewardList
  1737. }
  1738. func (this *RoleBase) ClearBossReward() {
  1739. this.roleBase.RoleData.BossRewardList = this.roleBase.RoleData.BossRewardList[:0]
  1740. this.SetDirty(true)
  1741. }
  1742. func (this *RoleBase) CheckVipLevelUp() {
  1743. vipExp := this.role.getCommonResNum(int32(serverproto.ResType_Res_VipExp))
  1744. bLevelUp := false
  1745. nowLevel := this.role.GetRoleVipLevel()
  1746. for i := nowLevel; i < int32(len(model.ConvertVipRight)); i++ {
  1747. if model.ConvertVipRight[i].VipRight[model.Vip_System_Levelup] <= 0 {
  1748. continue
  1749. }
  1750. if model.ConvertVipRight[i].VipRight[model.Vip_System_Levelup] <= vipExp {
  1751. nextCfg, ok := model.ConvertVipRight[i+1]
  1752. if !ok {
  1753. break
  1754. }
  1755. this.role.GetRoleBase().roleBase.VipLevel = i + 1
  1756. bLevelUp = true
  1757. //给Vip升级奖励
  1758. if len(nextCfg.VipReward) > 0 {
  1759. this.role.GetRoleMail().AddMail(model.GlobalMailIdVipLevelUp, serverproto.MailType_MailType_VipLevelUp,
  1760. nextCfg.VipReward, []int32{this.role.GetRoleBase().roleBase.VipLevel}, "", "")
  1761. }
  1762. this.SetDirty(true)
  1763. }
  1764. }
  1765. ntfMsg := &serverproto.SCVipChangeNtf{
  1766. VipLevel: this.role.GetRoleVipLevel(),
  1767. VipExp: this.role.getCommonResNum(int32(serverproto.ResType_Res_VipExp)),
  1768. }
  1769. this.role.ReplayGate(ntfMsg, true)
  1770. if bLevelUp == true {
  1771. this.role.GetRoleBattle().CheckEvilBattleCount()
  1772. this.UpdatePlayerBriefInfo(false)
  1773. }
  1774. }
  1775. func (this *RoleBase) checkBTBoliLevelUp() {
  1776. // boli商城等级提升检测
  1777. bLevelUp := false
  1778. newExp := this.role.getCommonResNum(int32(serverproto.ResType_Res_BoliShopExp))
  1779. var oldLevel int32 = 0
  1780. if this.role.roleBT.boliData != nil {
  1781. oldLevel = this.role.roleBT.boliData.Level
  1782. }
  1783. newLevel := oldLevel
  1784. for {
  1785. // 1lv->2lv使用1的升级经验
  1786. cfgData, ok := model.ConvertBoliVipData[newLevel]
  1787. if !ok {
  1788. break
  1789. }
  1790. if newExp >= cfgData.VipExp && cfgData.VipExp > 0 {
  1791. if _, nextLevelOk := model.ConvertBoliVipData[newLevel+1]; !nextLevelOk {
  1792. break
  1793. }
  1794. bLevelUp = true
  1795. newLevel++
  1796. } else {
  1797. break
  1798. }
  1799. }
  1800. if bLevelUp {
  1801. this.role.roleBT.OnBoliLevelUp(newLevel)
  1802. }
  1803. }
  1804. // 获取特权对应加成数值
  1805. func (this *RoleBase) GetVipData(dataType int32) int32 {
  1806. var retVal int32 = 0
  1807. vipLevel := this.role.GetRoleVipLevel()
  1808. data, ok := model.ConvertVipRight[vipLevel]
  1809. if ok {
  1810. right, ok1 := data.VipRight[dataType]
  1811. if ok1 {
  1812. if dataType == model.Vip_System_Evil && right == 0 {
  1813. return right
  1814. }
  1815. if right < 0 {
  1816. right = 0
  1817. }
  1818. retVal = right
  1819. }
  1820. }
  1821. // RO通行证
  1822. if dataType == model.Vip_System_QuickBattleBaseExp {
  1823. if this.role.GetRoleRune() != nil && this.role.GetRoleRune().runeBase.IsPassCheck {
  1824. if right, ok := model.ConvertPassCheckData.VipRight[dataType]; ok {
  1825. if dataType == model.Vip_System_Evil && right == 0 {
  1826. return right
  1827. }
  1828. if right < 0 {
  1829. right = 0
  1830. }
  1831. retVal += right
  1832. }
  1833. }
  1834. }
  1835. // 波利商城
  1836. if this.role.roleBT != nil {
  1837. var boliLevel int32 = 0
  1838. if this.role.roleBT.boliData != nil {
  1839. boliLevel = this.role.roleBT.boliData.Level
  1840. }
  1841. cfgData, ok := model.ConvertBoliVipData[boliLevel]
  1842. if ok {
  1843. if right, ok1 := cfgData.VipRight[dataType]; ok1 {
  1844. if dataType == model.Vip_System_Evil && right == 0 {
  1845. return right
  1846. }
  1847. if right < 0 {
  1848. right = 0
  1849. }
  1850. retVal += right
  1851. }
  1852. }
  1853. }
  1854. return retVal
  1855. }