role_base.go 60 KB

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