role_base.go 61 KB

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