role_base.go 60 KB

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