role_base.go 60 KB

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