| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042 |
- package model
- import (
- "math"
- "rocommon/service"
- "rocommon/util"
- "roserver/baseserver/model"
- "roserver/baseserver/set"
- "roserver/serverproto"
- "sync"
- )
- const (
- Max_Change_Count = 5
- Card_Operation = 2 //卡片一键操作间隔
- updateCrossFightPowerRankDurationTime = 10 * 60 * 1000
- )
- type RoleBase struct {
- SaveObject
- roleBase *serverproto.RoleBase
- fightChangeNum int32
- cardOperation int64
- headFrameTick uint64
- lastFightPowerChangeTimeStamp uint64
- }
- var roleBasePool = sync.Pool{
- New: func() interface{} {
- retBase := newRoleBase()
- return retBase
- },
- }
- func newRoleBase() *RoleBase {
- base := &RoleBase{
- roleBase: &serverproto.RoleBase{
- RoleData: &serverproto.RoleData{
- HeroData: &serverproto.HeroData{
- Slot: &serverproto.SlotData{},
- Skill: &serverproto.RoleSkill{},
- SkillEquipSlot: &serverproto.SkillEquipSlotData{},
- },
- },
- FashionData: &serverproto.FashionData{},
- Head_Info: &serverproto.HeadInfo{},
- },
- }
- base.cardOperation = 0
- return base
- }
- func (this *RoleBase) CopyData(base *serverproto.RoleBase) {
- *base = *this.roleBase
- }
- // 剧情//TODO wangzhaocan 后续放入RoleCommon
- func (this *RoleBase) CopyStoryData(msgNtf *serverproto.SCRoleStoryNtf) {
- for _, data := range this.roleBase.StoryId {
- msgNtf.Story = append(msgNtf.Story, data)
- }
- msgNtf.MapCart = this.roleBase.MapAnimation
- //util.DebugF("uid=%v SCRoleStoryNtf msg=%v", this.role.GetUUid(), msgNtf)
- }
- func (this *RoleBase) Load(msg interface{}) bool {
- proRole := msg.(*serverproto.Role)
- *this.roleBase = *proRole.RoleBase
- if this.roleBase.RoleData != nil {
- //if this.roleBase.RoleData.HeroData.SkillEquipSlot == nil {
- // this.roleBase.RoleData.HeroData.SkillEquipSlot = &serverproto.SkillEquipSlotData{}
- // for i := 0; i < SKILL_EQUIP_SLOT_TYPE_NUM; i++ {
- // this.roleBase.RoleData.HeroData.SkillEquipSlot.SlotList = append(this.roleBase.RoleData.HeroData.SkillEquipSlot.SlotList, &serverproto.SkillEquipSlotDetailData{SlotLevel:1})
- // }
- //}
- if this.roleBase.RoleData.JobLevel == 0 {
- this.roleBase.RoleData.JobLevel = 1
- //初始化主角可添加的属性点
- this.roleBase.RoleData.HeroData.AttrPoint = model.GlobalRoleOriginalAttrPoint
- //初始化最大巡游值
- this.roleBase.RoleData.MaxCruise = model.GlobalCruiseMax
- if this.roleBase.Head_Info == nil {
- this.roleBase.Head_Info = &serverproto.HeadInfo{}
- this.roleBase.Head_Info.HeadFrameList = append(this.roleBase.Head_Info.HeadFrameList, &serverproto.HeadFrameData{
- HeadFrameId: model.GlobalGuildHeadFrame,
- HeadFrameTime: -1,
- })
- }
- //初始化角色头像
- if this.roleBase.RoleData.HeadId == 0 {
- if this.roleBase.GetSex() == 1 {
- this.roleBase.RoleData.HeadId = int32(model.GlobalFemaleHead)
- } else {
- this.roleBase.RoleData.HeadId = int32(model.GlobalMaleHead)
- }
- }
- if this.roleBase.RoleData.HeadFrameId == 0 {
- this.roleBase.RoleData.HeadFrameId = model.GlobalGuildHeadFrame
- }
- this.SetDirty(true)
- }
- if this.role.roleTask != nil {
- this.role.roleTask.OnlineCheckNewHead()
- }
- }
- return true
- }
- func (this *RoleBase) OnlineProcess() {
- //创号时,设置主角可转目标职业的任务条件
- this.role.roleTask.GetChangeJobTask(this.roleBase.RoleData.HeroData.Id, 0, false)
- }
- func (this *RoleBase) RoleData() *serverproto.RoleData {
- return this.roleBase.RoleData
- }
- func (this *RoleBase) Save() {
- this.SetDirty(false)
- //util.DebugF("uid=%v RoleBase save...", this.role.GetUUid())
- saveMsg := &serverproto.SSRoleBaseSaveReq{
- Base: this.roleBase,
- }
- this.role.SendDb(saveMsg)
- }
- func (this *RoleBase) GetMoney() uint64 {
- return this.roleBase.Coin
- }
- func (this *RoleBase) GetRmb() uint32 {
- return this.roleBase.Rmb
- }
- func (this *RoleBase) GetRoleBaseExp() int32 {
- return this.RoleData().BaseExp
- }
- func (this *RoleBase) GetHeroBaseExp() int32 {
- return this.RoleData().HeroExp
- }
- func (this *RoleBase) GetRoleJobExp() int32 {
- return this.RoleData().JobExp
- }
- func (this *RoleBase) GetRoleLevel() int32 {
- return this.RoleData().HeroData.BaseLevel
- }
- func (this *RoleBase) GetRoleJobLevel() int32 {
- return this.RoleData().JobLevel
- }
- func (this *RoleBase) GetRoleName() string {
- return this.roleBase.NickName
- }
- func (this *RoleBase) GetRoleTotalRecharge() float32 {
- return this.roleBase.TotalRecharge
- }
- func (this *RoleBase) GetRoleSex() int32 {
- //1 female 2 male
- return this.roleBase.Sex
- }
- func (this *RoleBase) GetRoleJobType() int32 {
- return this.role.GetRoleHero().GetMainHeroJobType()
- }
- func (this *RoleBase) GetCruise() int32 {
- return this.RoleData().Cruise
- }
- func (this *RoleBase) Rename(name string) {
- this.roleBase.NickName = name
- this.SetDirty(true)
- }
- // 时效性头像刷新
- func (this *RoleBase) Update(ms uint64) {
- if this.roleBase.Head_Info == nil || len(this.roleBase.Head_Info.HeadFrameList) <= 0 {
- return
- }
- if this.headFrameTick != 0 && this.headFrameTick > ms+1000*60 {
- return
- }
- this.headFrameTick = ms
- var headFrame []*serverproto.HeadFrameData
- idx := 0
- nowTime := int64(ms / 1000)
- for idx < len(this.roleBase.Head_Info.HeadFrameList) {
- data := this.roleBase.Head_Info.HeadFrameList[idx]
- if data.HeadFrameTime != -1 && data.HeadFrameTime <= nowTime {
- headFrame = append(headFrame, &serverproto.HeadFrameData{
- HeadFrameId: data.HeadFrameId,
- HeadFrameTime: 0,
- })
- this.roleBase.Head_Info.HeadFrameList = append(this.roleBase.Head_Info.HeadFrameList[:idx], this.roleBase.Head_Info.HeadFrameList[idx+1:]...)
- this.SetDirty(true)
- //当前头像到期了的话。
- if this.roleBase.GetRoleData().HeadFrameId != 0 && data.HeadFrameId == this.roleBase.GetRoleData().HeadFrameId {
- this.roleBase.GetRoleData().HeadFrameId = model.GlobalGuildHeadFrame
- this.UpdatePlayerBriefInfo(false)
- this.BaseChangeNtf()
- }
- this.role.roleBattleAttr.AttrChange(AttrChangeST{
- ChangeType: Attr_Change_HeadFrame,
- ChangeHeroData: this.role.GetRoleHero().GetMainHero(),
- BHeadFrameDelete: true,
- HeadFrameId: data.HeadFrameId,
- })
- } else {
- idx++
- }
- }
- if len(headFrame) > 0 {
- this.HeadFrameChangeNtf(headFrame)
- //this.role.GetRoleFightPower().HeadFrameAttrChange(false)
- }
- }
- func (this *RoleBase) DailyReset(notify bool) uint64 {
- nowTime := util.GetTimeMilliseconds()
- oldDailyResetTimeStamp := this.roleBase.DailyResetTimeStamp
- this.roleBase.DailyResetTimeStamp = nowTime
- //每日累计重置重置
- this.roleBase.DayRecharge = 0
- this.roleBase.BtZhenDayRecharge = 0
- this.roleBase.BtJiaDayRecharge = 0
- //累计在线时间奖励数据重置
- this.onlineTImeRewardAll(nowTime)
- this.roleBase.OnlineStamp = nowTime
- this.roleBase.OnlineRewardId = 0
- this.roleBase.TotalOnlineTime = 0
- this.SetDirty(true)
- if notify {
- ntfMsg := &serverproto.SCPayInfoNtf{
- TotalRecharge: this.roleBase.TotalRecharge,
- DayRecharge: this.roleBase.DayRecharge,
- BtZhenDayRecharge: this.roleBase.BtZhenDayRecharge,
- BtJiaDayRecharge: int32(float32(this.roleBase.BtJiaDayRecharge) * BTJiaChangeDollar),
- BtJiaTotalRecharge: uint64(float32(this.roleBase.BtJiaTotalRecharge) * BTJiaChangeDollar),
- }
- this.role.ReplayGate(ntfMsg, true)
- ntfOnlineTimeRewardMsg := &serverproto.SCOnlineTimeRewardNtf{
- OnlineStamp: this.roleBase.OnlineStamp,
- OnlineRewardId: 0,
- TotalOnlineTime: 0,
- }
- this.role.ReplayGate(ntfOnlineTimeRewardMsg, true)
- }
- return oldDailyResetTimeStamp
- }
- func (this *RoleBase) AddRMB(st AddItemST, add bool) bool {
- rmb := st.ItemCount
- if rmb <= 0 || rmb >= math.MaxInt32 {
- return false
- }
- oldRMB := this.roleBase.Rmb
- if !add {
- if this.roleBase.Rmb >= uint32(rmb) {
- this.roleBase.Rmb -= uint32(rmb)
- TaskMagCheck(this.role, serverproto.TaskType_Gold_Consumption_Count, rmb)
- } else {
- //直接消耗剩余的金币
- this.roleBase.Rmb = 0
- TaskMagCheck(this.role, serverproto.TaskType_Gold_Consumption_Count, rmb)
- this.SetDirty(true)
- return false
- }
- } else {
- tmpExp := uint64(rmb) + uint64(this.roleBase.Rmb)
- if tmpExp >= math.MaxInt32 {
- // 金币获得达到上限无法再获得
- tmpExp = math.MaxInt32
- ntfMsg := &serverproto.SCErrorMessageNtf{
- Error: int32(serverproto.ErrorCode_ERROR_RMB_CANNOT_ADD_MORE),
- }
- this.role.ReplayGate(ntfMsg, true)
- }
- this.roleBase.Rmb = uint32(tmpExp)
- }
- this.SetDirty(true)
- //mysql
- this.role.MysqlLogNtf(serverproto.MysqlLogType_LType_RBM,
- []int32{int32(oldRMB), int32(this.roleBase.Rmb), int32(rmb), st.ReasonParam}, int32(st.AddFrom))
- util.InfoF("uid=%v AddRMB from=%v old=%v new=%v addvalue=%v add=%v", this.role.GetUUid(), st.AddFrom,
- oldRMB, this.roleBase.Rmb, rmb, add)
- return true
- }
- func (this *RoleBase) AddMoney(st AddItemST, add bool) bool {
- money := st.ItemCount
- if money <= 0 || money >= math.MaxInt32 {
- return false
- }
- oldMoney := this.roleBase.Coin
- if !add {
- if this.roleBase.Coin >= uint64(money) {
- this.roleBase.Coin -= uint64(money)
- TaskMagCheck(this.role, serverproto.TaskType_Silver_Consumption_Count, money)
- //超值礼包开启
- if this.role.GetRoleActivity() != nil {
- this.role.GetRoleActivity().SuperChargeUnlockCheck(
- serverproto.UnlockChargeType_UChargeType_ZenyOnceCost, &SuperChargeUnlockST{oldValue: money})
- }
- } else {
- //直接消耗剩余的Coin
- this.roleBase.Coin = 0
- TaskMagCheck(this.role, serverproto.TaskType_Silver_Consumption_Count, money)
- //超值礼包开启
- if this.role.GetRoleActivity() != nil {
- this.role.GetRoleActivity().SuperChargeUnlockCheck(
- serverproto.UnlockChargeType_UChargeType_ZenyOnceCost, &SuperChargeUnlockST{oldValue: money})
- }
- this.SetDirty(true)
- return false
- }
- } else {
- this.roleBase.Coin += uint64(money)
- if this.role.GetRoleTask() != nil {
- this.role.GetRoleTask().totalAddZeny += uint64(money)
- this.role.GetRoleTask().SetDirty(true)
- }
- TaskMagCheck(this.role, serverproto.TaskType_Get_Silver_Count, money)
- }
- this.SetDirty(true)
- util.InfoF("uid=%v AddMoney from=%v old=%v new=%v addvalue=%v add=%v", this.role.GetUUid(), st.AddFrom,
- oldMoney, this.GetMoney(), money, add)
- return true
- }
- func (this *RoleBase) AddHeroExp(st AddItemST, add bool) bool {
- exp := st.ItemCount
- if exp <= 0 || exp >= math.MaxInt32 {
- return false
- }
- oldHeroExp := this.RoleData().HeroExp
- if !add {
- if this.RoleData().HeroExp >= exp {
- this.RoleData().HeroExp -= exp
- } else {
- return false
- }
- } else {
- tmpExp := uint64(exp) + uint64(this.RoleData().HeroExp)
- if tmpExp >= math.MaxInt32 {
- tmpExp = math.MaxInt32
- }
- this.RoleData().HeroExp = int32(tmpExp)
- }
- this.SetDirty(true)
- util.InfoF("uid=%v AddHeroExp old=%v new=%v addvalue=%v add=%v", this.role.GetUUid(),
- oldHeroExp, this.RoleData().HeroExp, exp, add)
- return true
- }
- func (this *RoleBase) AddCruise(st AddItemST, add bool) bool {
- value := st.ItemCount
- if value <= 0 || value >= math.MaxInt32 {
- return false
- }
- oldCruise := this.RoleData().Cruise
- if !add {
- if this.RoleData().Cruise >= value {
- this.RoleData().Cruise -= value
- } else {
- return false
- }
- } else {
- if this.RoleData().Cruise >= this.RoleData().MaxCruise {
- return false
- }
- this.RoleData().Cruise += value
- if this.RoleData().Cruise > this.RoleData().MaxCruise {
- this.RoleData().Cruise = this.RoleData().MaxCruise
- }
- }
- this.SetDirty(true)
- util.InfoF("uid=%v AddCruise old=%v new=%v addvalue=%v add=%v", this.role.GetUUid(),
- oldCruise, this.RoleData().Cruise, value, add)
- return true
- }
- // 获取资源
- func (this *RoleBase) GetCommonRes(resType int32) int32 {
- for _, data := range this.roleBase.ResList {
- if data.Key == resType {
- return data.Value
- }
- }
- return 0
- }
- // default true
- func (this *RoleBase) ResetCommonRes(resType int32, notify bool) {
- for _, data := range this.roleBase.ResList {
- if data.Key == resType {
- if data.Value > 0 {
- oldValue := data.Value
- data.Value = 0
- util.InfoF("uid=%v ResetCommonRes restype=%v old=%v new=%", this.role.GetUUid(), resType, oldValue, data.Value)
- this.SetDirty(true)
- if notify {
- this.BaseChangeNtf()
- }
- }
- break
- }
- }
- }
- // 添加资源
- func (this *RoleBase) AddCommonRes(resType int32, st AddItemST, add bool) bool {
- resValue := st.ItemCount
- if resValue <= 0 || resValue >= math.MaxInt32 {
- return false
- }
- if !add {
- for _, data := range this.roleBase.ResList {
- if data.Key == resType {
- if data.Value < resValue {
- return false
- } else {
- oldValue := data.Value
- data.Value -= resValue
- util.InfoF("uid=%v AddCommonRes restype=%v old=%v new=%v addvalue=%v add=%v",
- this.role.GetUUid(), resType, oldValue, data.Value, resValue, add)
- //bt假每日累计充值
- if resType == int32(serverproto.ResType_Res_CreditRecharge) {
- this.AddBtJiaRecharge(resValue)
- // 根据消耗比例获取vip经验(充值钱包消耗获得vip经验)
- addVipExp := float32(resValue) * model.GlobalCreditRechargeFactor
- st.ItemCount = int32(addVipExp)
- this.AddCommonRes(int32(serverproto.ResType_Res_VipExp), st, true)
- }
- break
- }
- }
- }
- } else {
- bFind := false
- for _, data := range this.roleBase.ResList {
- if data.Key == resType {
- oldValue := data.Value
- //data.Value += resValue
- tmpVal := uint64(data.Value) + uint64(resValue)
- if tmpVal >= math.MaxInt32 {
- tmpVal = math.MaxInt32 - 1
- }
- data.Value = int32(tmpVal)
- //上限处理
- switch serverproto.ResType(resType) {
- case serverproto.ResType_Res_EvilExp:
- if model.GlobalEvilExpLimit > 0 && data.Value > model.GlobalEvilExpLimit {
- data.Value = model.GlobalEvilExpLimit
- }
- case serverproto.ResType_Res_VipExp:
- this.CheckVipLevelUp()
- case serverproto.ResType_Res_BoliShopExp:
- this.checkBTBoliLevelUp()
- }
- bFind = true
- util.InfoF("uid=%v AddCommonRes restype=%v old=%v new=%v addvalue=%v add=%v",
- this.role.GetUUid(), resType, oldValue, data.Value, resValue, add)
- break
- }
- }
- if !bFind {
- this.roleBase.ResList = append(this.roleBase.ResList, &serverproto.KeyValueType{
- Key: resType,
- Value: resValue,
- })
- //上限处理
- switch serverproto.ResType(resType) {
- case serverproto.ResType_Res_EvilExp:
- if model.GlobalEvilExpLimit > 0 && resValue > model.GlobalEvilExpLimit {
- resValue = model.GlobalEvilExpLimit
- }
- case serverproto.ResType_Res_BoliShopExp:
- this.checkBTBoliLevelUp()
- }
- if serverproto.ResType(resType) == serverproto.ResType_Res_VipExp {
- this.CheckVipLevelUp()
- }
- util.InfoF("uid=%v AddCommonRes restype=%v old=0 new=%v addvalue=%v add=%v",
- this.role.GetUUid(), resType, resValue, resValue, add)
- }
- }
- this.SetDirty(true)
- return true
- }
- func (this *RoleBase) AddBtJiaRecharge(val int32) {
- this.roleBase.BtJiaDayRecharge += val
- this.roleBase.BtJiaTotalRecharge += uint64(val)
- this.SetDirty(true)
- todayCharge := int32(math.Ceil(float64(float32(this.roleBase.BtJiaDayRecharge)*BTJiaChangeDollar))) +
- int32(math.Ceil(float64(this.roleBase.BtZhenDayRecharge)))
- ntfMsg := &serverproto.SCPayInfoNtf{
- TotalRecharge: this.roleBase.TotalRecharge,
- DayRecharge: this.roleBase.DayRecharge,
- BtZhenDayRecharge: this.roleBase.BtZhenDayRecharge,
- BtJiaDayRecharge: todayCharge,
- BtJiaTotalRecharge: uint64(float32(this.roleBase.BtJiaTotalRecharge) * BTJiaChangeDollar),
- }
- this.role.ReplayGate(ntfMsg, true)
- TaskMagCheck(this.role, serverproto.TaskType_BT_ZhenJiaRecharge, todayCharge)
- }
- // 增加累计充值
- func (this *RoleBase) AddPayRecharge(payRewardInfo *serverproto.PayOrderSaveInfo) {
- amount := payRewardInfo.Amount
- if amount <= 0.00001 {
- return
- }
- oldVal := this.roleBase.TotalRecharge
- this.roleBase.TotalRecharge += amount
- this.roleBase.DayRecharge += amount
- this.roleBase.LastRechargeTime = util.GetTimeMilliseconds()
- this.SetDirty(true)
- // bt服务器真假累计充值
- if payRewardInfo.GoodsType == int32(serverproto.PayGoodsType_EPayType_NormalBag) {
- goodCfg, ok := model.ConvertGiftBag[payRewardInfo.GoodsId]
- if ok && goodCfg.BagType == Rune_BagShop_Type_Gold {
- this.roleBase.BtZhenDayRecharge += amount
- todayCharge := int32(math.Ceil(float64(float32(this.roleBase.BtJiaDayRecharge)*BTJiaChangeDollar))) +
- int32(math.Ceil(float64(this.roleBase.BtZhenDayRecharge)))
- TaskMagCheck(this.role, serverproto.TaskType_BT_ZhenJiaRecharge, todayCharge)
- }
- }
- calCeilAmount := math.Ceil(float64(payRewardInfo.Amount))
- // bt 获得RO币
- tmpRoCoin := calCeilAmount * float64(model.GlobalRoCoinFactor)
- TaskMagCheck(this.role, serverproto.TaskType_BT_ROCoinRecharge, int32(tmpRoCoin))
- ntfMsg := &serverproto.SCPayInfoNtf{
- TotalRecharge: this.roleBase.TotalRecharge,
- DayRecharge: this.roleBase.DayRecharge,
- BtZhenDayRecharge: this.roleBase.BtZhenDayRecharge,
- BtJiaDayRecharge: int32(float32(this.roleBase.BtJiaDayRecharge) * BTJiaChangeDollar),
- BtJiaTotalRecharge: uint64(float32(this.roleBase.BtJiaTotalRecharge) * BTJiaChangeDollar),
- }
- this.role.ReplayGate(ntfMsg, true)
- util.InfoF("uid=%v AddPayRecharge old=%v new=%v add=%v", this.role.GetUUid(), oldVal, this.roleBase.TotalRecharge, amount)
- //给VIP经验
- if model.GlobalRMBToVipExpRMB > 0 {
- vipExp := float32(calCeilAmount) * float32(model.GlobalRMBToVipExpVip) / float32(model.GlobalRMBToVipExpRMB)
- this.role.AddRes(int32(serverproto.ResType_Res_VipExp), AddItemST{ItemCount: int32(vipExp)}, true)
- }
- //充值任务
- TaskMagCheck(this.role, serverproto.TaskType_Recharge_Num_Accu, int32(amount+0.5))
- TaskMagCheck(this.role, serverproto.TaskType_Recharge_Num, int32(amount+0.5))
- TaskMagCheck(this.role, serverproto.TaskType_Eve_Recharge_Value, int32(amount+0.5))
- //首充是否开启
- if this.role.GetRoleActivity() != nil {
- //开启时自动做任务检测
- this.role.GetRoleActivity().FirstChargeUnlockState()
- this.role.GetRoleActivity().TaskCheck(serverproto.TaskType_Recharge_Num_Accu, int32(amount+0.5))
- //超值礼包开启
- this.role.GetRoleActivity().SuperChargeUnlockCheck(serverproto.UnlockChargeType_UChargeType_PayAmount,
- &SuperChargeUnlockST{oldValue: int32(payRewardInfo.Amount)})
- }
- //BT根据关卡的功能解锁
- if this.role.GetRoleBT() != nil {
- this.role.GetRoleBT().UnlockBTSystem()
- }
- //gm方式充值 不写入数据库
- if payRewardInfo.GoodsType != int32(serverproto.PayGoodsType_EPayType_None) {
- //充值成功添加到mysql(订单信息)
- payLogData := &serverproto.SSRoleLogData{
- Uid: this.role.GetUUid(),
- Type: int32(serverproto.MysqlLogType_LType_Pay),
- ParamList: []int32{int32(oldVal), int32(this.roleBase.TotalRecharge), int32(amount)},
- }
- orderLogData := &serverproto.SSRoleLogData{
- Uid: this.role.GetUUid(),
- Type: int32(serverproto.MysqlLogType_LType_OrderList),
- ParamList: []int32{int32(amount), payRewardInfo.GoodsType, payRewardInfo.GoodsId},
- Param64List: []uint64{payRewardInfo.CpOrderId, payRewardInfo.OrderProcessTime},
- RewardList: payRewardInfo.RewardList,
- StrList: []string{payRewardInfo.SdkOrderId},
- }
- this.role.AddMysqlLog(payLogData)
- this.role.AddMysqlLog(orderLogData)
- //mysqlNtf := &serverproto.SSRoleLogNtf{}
- //mysqlNtf.LogList = append(mysqlNtf.LogList, payLogData)
- //mysqlNtf.LogList = append(mysqlNtf.LogList, orderLogData)
- //this.role.SendDb(mysqlNtf)
- //sdk log
- addGold := this.role.WriteChargeLog(payRewardInfo)
- if addGold != 0 {
- this.role.WriteChargeAddGoldLogJF(payRewardInfo, int32(addGold))
- }
- }
- }
- func (this *RoleBase) SetLastLoginTime() uint64 {
- var durationTime uint64 = 0
- nowTime := util.GetTimeMilliseconds()
- if this.RoleData().LastLoginTime > 0 && nowTime > this.RoleData().LastLoginTime {
- durationTime = nowTime - this.RoleData().LastLoginTime
- }
- this.RoleData().LastLoginTime = nowTime
- this.roleBase.OnlineStamp = nowTime
- this.SetDirty(true)
- return durationTime
- }
- func (this *RoleBase) GetLastLoginTime() uint64 {
- return this.RoleData().LastLoginTime
- }
- func (this *RoleBase) BaseChangeNtf() {
- ntfMsg := &serverproto.SCRoleBaseInfoNtf{
- Coin: this.roleBase.Coin,
- Rmb: this.roleBase.Rmb,
- ResList: this.roleBase.ResList,
- RoleData: this.RoleData(),
- RepressSkillPvpVal: this.roleBase.RepressSkillPvpVal,
- }
- this.role.ReplayGate(ntfMsg, true)
- }
- func (this *RoleBase) OnlineTimeReward() serverproto.ErrorCode {
- bChang := false
- nowTime := util.GetTimeMilliseconds()
- curDiffDay := util.GetDurationDay2(this.role.RegisterTime, nowTime)
- //计算当天累计在线时间
- tmpTotalOnlineTime := this.roleBase.TotalOnlineTime
- if this.roleBase.OnlineStamp <= 0 {
- this.roleBase.OnlineStamp = nowTime
- }
- if nowTime > this.roleBase.OnlineStamp {
- tmpTotalOnlineTime += int32((nowTime - this.roleBase.OnlineStamp) / 1000)
- }
- if curDiffDay >= model.ConvertOnlineRewardMaxDay {
- curDiffDay = model.ConvertOnlineRewardMaxDay
- }
- onlineRewardCfgData, ok := model.ConvertOnlineRewardList[curDiffDay]
- if !ok {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- ackMsg := &serverproto.SCOnlineTimeRewardAck{}
- rewardList := map[int32]int32{}
- for idx := 0; idx < len(onlineRewardCfgData); idx++ {
- if onlineRewardCfgData[idx].Id > this.roleBase.OnlineRewardId {
- if onlineRewardCfgData[idx].RewardToTalTime <= tmpTotalOnlineTime {
- this.roleBase.OnlineRewardId = onlineRewardCfgData[idx].Id
- this.roleBase.TotalOnlineTime = tmpTotalOnlineTime
- this.roleBase.OnlineStamp = nowTime
- this.SetDirty(true)
- bChang = true
- util.DebugF("uid=%v rewardid=%v onlinetime=%v", this.role.GetUUid(),
- this.roleBase.OnlineRewardId, this.roleBase.TotalOnlineTime)
- ackMsg.RewardItemList = onlineRewardCfgData[idx].RewardList
- for k := 0; k < len(onlineRewardCfgData[idx].RewardList); k++ {
- item := onlineRewardCfgData[idx].RewardList[k]
- rewardList[item.Key] += item.Value
- }
- }
- //else {
- // //花费金币进行领奖操作
- // if this.role.GetRmb() < uint32(onlineRewardCfgData[idx].RewardCostCoin) {
- // return serverproto.ErrorCode_ERROR_RMB_NOT_ENOUGH
- // }
- // this.role.DelItem(int32(serverproto.ResType_Res_Rmb),
- // onlineRewardCfgData[idx].RewardCostCoin, AddItemST{AddFrom: AddFrom_OnlineReward})
- //
- // this.roleBase.OnlineRewardId = onlineRewardCfgData[idx].Id
- // this.roleBase.TotalOnlineTime = onlineRewardCfgData[idx].RewardToTalTime
- // this.roleBase.OnlineStamp = nowTime
- // this.SetDirty(true)
- // bChang = true
- //
- // util.DebugF("uid=%v rewardid=%v onlinetime=%v costrmb", this.role.GetUUid(),
- // this.roleBase.OnlineRewardId, this.roleBase.TotalOnlineTime)
- //
- // ackMsg.RewardItemList = onlineRewardCfgData[idx].RewardList
- // for k := 0; k < len(onlineRewardCfgData[idx].RewardList); k++ {
- // item := onlineRewardCfgData[idx].RewardList[k]
- // rewardList[item.Key] += item.Value
- // }
- //}
- break
- }
- }
- if bChang {
- ntfMsg := &serverproto.SCOnlineTimeRewardNtf{
- TotalOnlineTime: this.roleBase.TotalOnlineTime,
- OnlineStamp: this.roleBase.OnlineStamp,
- OnlineRewardId: this.roleBase.OnlineRewardId,
- }
- this.role.ReplayGate(ntfMsg, true)
- }
- if len(rewardList) > 0 {
- this.role.GetRoleBag().AddItemList(rewardList, AddItemST{
- AddFrom: AddFrom_OnlineReward,
- Notify: true,
- })
- this.role.ReplayGate(ackMsg, true)
- } else {
- return serverproto.ErrorCode_ERROR_ONLINE_REWARD_NO
- }
- return serverproto.ErrorCode_ERROR_OK
- }
- // 离线时处理在线时间加成
- func (this *RoleBase) OfflineOnlineTimeProcess() {
- nowTime := util.GetTimeMilliseconds()
- //计算当天累计在线时间
- tmpTotalOnlineTime := this.roleBase.TotalOnlineTime
- if this.roleBase.OnlineStamp <= 0 {
- this.roleBase.OnlineStamp = nowTime
- }
- if nowTime > this.roleBase.OnlineStamp {
- tmpTotalOnlineTime += int32((nowTime - this.roleBase.OnlineStamp) / 1000)
- }
- if tmpTotalOnlineTime > this.roleBase.TotalOnlineTime {
- this.roleBase.OnlineStamp = nowTime
- this.roleBase.TotalOnlineTime = tmpTotalOnlineTime
- this.SetDirty(true)
- }
- }
- // 隔天领取之前天未领取的奖励
- func (this *RoleBase) onlineTImeRewardAll(nowTime uint64) {
- curDiffDay := util.GetDurationDay2(this.role.RegisterTime, nowTime) - 1
- if curDiffDay <= 0 {
- return
- }
- cfgData, ok := model.ConvertOnlineRewardList[curDiffDay]
- if !ok {
- return
- }
- tmpTotalOnlineTime := this.roleBase.TotalOnlineTime
- rewardList := map[int32]int32{}
- for idx := 0; idx < len(cfgData); idx++ {
- if cfgData[idx].Id > this.roleBase.OnlineRewardId {
- if cfgData[idx].RewardToTalTime <= tmpTotalOnlineTime {
- util.DebugF("uid=%v rewardid=%v onlinetime=%v rewardAll beffor", this.role.GetUUid(),
- this.roleBase.OnlineRewardId, this.roleBase.TotalOnlineTime)
- for k := 0; k < len(cfgData[idx].RewardList); k++ {
- item := cfgData[idx].RewardList[k]
- rewardList[item.Key] += item.Value
- }
- }
- }
- }
- if len(rewardList) > 0 {
- this.role.GetRoleMail().AddMail(23, serverproto.MailType_MailType_OnlineReward,
- rewardList, nil, "", "")
- }
- }
- func (this *RoleBase) SlotChangNtf(heroId int32, slotData *serverproto.SlotData) {
- //英雄槽位数据变更通知
- ntfMsg := &serverproto.SCSlotDataNtf{
- HeroId: heroId,
- Slot: &serverproto.SlotData{},
- }
- *ntfMsg.Slot = *slotData
- this.role.ReplayGate(ntfMsg, true)
- }
- func (this *RoleBase) SkillEquipSlotChangNtf(heroId int32, slotData *serverproto.SkillEquipSlotData) {
- //英雄槽位数据变更通知
- ntfMsg := &serverproto.SCSkillEquipSlotDataNtf{
- HeroId: heroId,
- Slot: &serverproto.SkillEquipSlotData{},
- }
- *ntfMsg.Slot = *slotData
- this.role.ReplayGate(ntfMsg, true)
- }
- func (this *RoleBase) FashionChangeNtf() {
- //时装数据变更通知
- //ntfMsg := &serverproto.SCFashionDataNtf{
- // FashionUpList: this.roleBase.FashionData.FashionUpList,
- //}
- //this.role.ReplayGate(ntfMsg, true)
- }
- // 更新玩家简介信息
- func (this *RoleBase) UpdatePlayerBriefInfo(bOffline bool) {
- ssMsg := &serverproto.SSRoleBriefInfoSaveReq{
- BriefInfo: &serverproto.CommonPlayerBriefInfo{
- Uid: this.roleBase.Id,
- NickName: this.roleBase.NickName,
- Gender: this.roleBase.Sex,
- Level: this.roleBase.RoleData.HeroData.BaseLevel,
- ConfigId: this.roleBase.RoleData.HeroData.ConfigId,
- FightPower: int32(this.role.roleBattleAttr.curTotalFightPower),
- //FightPower: int32(this.role.GetRoleFightPower().TotalFightPower), //(this.roleBase.RoleData.FightPower),
- ImgId: this.role.GetImageId(),
- TowerLevel: this.role.GetRoleTower().nowTowerLevel,
- TowerTime: uint64(this.role.GetRoleTower().nowTowerPassTime),
- MapLevelId: this.role.GetRoleBattle().GetLevelId(),
- HeadFrameId: this.roleBase.RoleData.HeadFrameId,
- VipLevel: this.roleBase.VipLevel,
- Rmb: uint64(this.GetRmb()),
- Zeny: this.GetMoney(),
- TotalRecharge: this.roleBase.TotalRecharge,
- LastRechargeTime: this.roleBase.LastRechargeTime,
- MaxFightPower: uint32(this.RoleData().FightPower),
- HeadId: this.role.GetHeadId(),
- },
- OpenId: this.role.GetOpenId(),
- ActiveCode: this.role.activeCode,
- SubPlatform: this.role.GetSubPlatform(),
- }
- if this.role.GetRoleDaoChang100() != nil {
- ssMsg.BriefInfo.Daochang100Tips = this.role.GetRoleDaoChang100().dataInfo.TipsDesc
- }
- ssMsg.BriefInfo.OnlineTime = this.RoleData().LastLoginTime
- this.role.SendDb(ssMsg)
- }
- // 是否是可重置的属性点类型
- func (this *RoleBase) isAttrPointType(attrKey int32) bool {
- key := serverproto.Attr(attrKey)
- if key == serverproto.Attr_Str || key == serverproto.Attr_Agi || key == serverproto.Attr_Int ||
- key == serverproto.Attr_Vit || key == serverproto.Attr_Dex || key == serverproto.Attr_Luk {
- return true
- }
- return false
- }
- // 主角经验 + 升级
- func (this *RoleBase) AddBaseExp(st AddItemST) int32 {
- exp := st.ItemCount
- if exp <= 0 || exp >= math.MaxInt32 {
- return 0
- }
- var changLevel int32 = 0
- var attrPoint int32 = 0
- oldLevel := this.RoleData().HeroData.BaseLevel
- newLevel := oldLevel
- //newExp := this.RoleData().BaseExp + exp
- tmpExp := uint64(this.RoleData().BaseExp) + uint64(exp)
- if tmpExp >= math.MaxInt32 {
- tmpExp = math.MaxInt32 - 1
- util.InfoF("uid=%v AddBaseExp exp max limit", this.role.GetUUid())
- }
- newExp := int32(tmpExp)
- for {
- cfgData, ok := serverproto.RoleAttributeCfgLoader[newLevel]
- _, ok1 := serverproto.RoleAttributeCfgLoader[newLevel+1]
- if !ok || !ok1 {
- util.InfoF("uid=%v AddBaseExp error", this.role.GetUUid())
- break
- }
- if newExp >= cfgData.Name && cfgData.Name > 0 {
- newLevel++
- newExp -= cfgData.Name
- attrPoint += cfgData.GetPoint
- } else {
- break
- }
- }
- this.RoleData().BaseExp = newExp
- if newLevel > oldLevel {
- ntfMsg := &serverproto.SCBaseLevelUpNtf{
- OldLevel: oldLevel,
- NewLevel: newLevel,
- }
- this.role.ReplayGate(ntfMsg, true)
- changLevel = newLevel - oldLevel
- this.RoleData().HeroData.BaseLevel = newLevel
- //获得属性点
- this.role.GetRoleHero().GetMainHero().AttrPoint += attrPoint
- //判断等级相关的解锁信息,属性变化
- this.processLevelState(oldLevel, newLevel)
- }
- this.SetDirty(true)
- util.InfoF("uid=%v AddBaseExp addExp=%v newBaseExp=%v oldLevel=%v newLevel=%v", this.role.GetUUid(),
- exp, this.RoleData().BaseExp, oldLevel, newLevel)
- return changLevel
- }
- func (this *RoleBase) processLevelState(oldLevel int32, newLevel int32) {
- util.DebugF("uid=%v processLevelState oldLevel=%v newLevel=%v", this.role.GetUUid(), oldLevel, newLevel)
- //判断解锁技能槽位
- if this.role.GetRoleSkill() != nil {
- this.role.GetRoleSkill().CheckSlotLockState()
- }
- //判断解锁卡槽
- if this.role.GetRoleCard() != nil {
- this.role.GetRoleCard().CheckUnLockState()
- }
- //任务条件处理
- TaskMagCheck(this.role, serverproto.TaskType_Base_Level, 0)
- //升级属性变化
- //this.role.roleFightPower.onFighterAttrChange(this.role.roleHero.GetMainHero().Id)
- this.role.roleBattleAttr.ResetLevelAttrList(this.RoleData().HeroData)
- //英灵殿匹配对象最低等级
- if oldLevel < model.GlobalDaoChangRankMinLevel && newLevel >= model.GlobalDaoChangRankMinLevel {
- this.role.GetRoleArena().SetArenaScoreRank(0)
- }
- //超值礼包开启
- if this.role.GetRoleActivity() != nil {
- this.role.GetRoleActivity().SuperChargeUnlockCheck(
- serverproto.UnlockChargeType_UChargeType_BaseLevel, &SuperChargeUnlockST{oldValue: oldLevel})
- this.role.GetRoleActivity().SuperChargeUnlockCheck(
- serverproto.UnlockChargeType_UChargeType_SkillLevelUp, &SuperChargeUnlockST{oldValue: oldLevel})
- }
- this.role.registerServerList(this.roleBase.RoleData.HeadFrameId, newLevel)
- this.UpdatePlayerBriefInfo(false)
- //添加到mysql log
- logData := &serverproto.SSRoleLogData{
- Uid: this.role.GetUUid(),
- Type: int32(serverproto.MysqlLogType_LType_Level),
- ParamList: []int32{int32(oldLevel), int32(newLevel), int32(newLevel - oldLevel)}, //oldLevel,newLevel
- }
- mysqlLevelNtf := &serverproto.SSRoleLogNtf{}
- mysqlLevelNtf.LogList = append(mysqlLevelNtf.LogList, logData)
- SendDb(mysqlLevelNtf)
- //邀请码导师处理
- if this.role.GetRoleInvitation() != nil {
- this.role.GetRoleInvitation().InvitationNoticeMaster(
- &serverproto.KeyValueType{
- Key: int32(serverproto.TaskType_Invitation_Base_Level_Num),
- Value: newLevel})
- }
- }
- // 返回改变的等级
- func (this *RoleBase) AddJobExp(st AddItemST) int32 {
- exp := st.ItemCount
- if exp <= 0 || exp >= math.MaxInt32 {
- return 0
- }
- jobCfgData, ok := serverproto.JobCfgLoader[this.RoleData().HeroData.ConfigId]
- if !ok || this.GetRoleJobLevel() >= jobCfgData.MaxJobLv {
- return 0
- }
- var changLevel int32
- var jobPoint int32
- oldLevel := this.RoleData().JobLevel
- newLevel := oldLevel
- //newExp := this.RoleData().JobExp + exp
- tmpExp := uint64(this.RoleData().JobExp) + uint64(exp)
- if tmpExp >= math.MaxInt32 {
- tmpExp = math.MaxInt32 - 1
- util.InfoF("uid=%v AddJobExp exp max limit", this.role.GetUUid())
- }
- newExp := int32(tmpExp)
- for {
- cfgData, ok := serverproto.JobExpCfgLoader[newLevel]
- _, ok1 := serverproto.JobExpCfgLoader[newLevel]
- if !ok || !ok1 {
- util.WarnF("uid=%v AddJobExp error not level data level=%v", this.role.GetUUid(), newLevel)
- break
- }
- var needExp int32 = -1
- var addPoint int32
- switch jobCfgData.JobStage {
- case 0:
- needExp = cfgData.ExpRequire1
- addPoint = cfgData.Point1
- case 1:
- needExp = cfgData.ExpRequire2
- addPoint = cfgData.Point2
- case 2:
- needExp = cfgData.ExpRequire3
- addPoint = cfgData.Point3
- }
- if newExp >= needExp && needExp >= 0 {
- newLevel++
- newExp -= needExp
- jobPoint += addPoint
- if newLevel >= jobCfgData.MaxJobLv { //到了当前职业最大等级,经验条设为0
- newExp = 0
- break
- }
- } else {
- break
- }
- }
- this.RoleData().JobExp = newExp
- if newLevel > oldLevel {
- ntfMsg := &serverproto.SCJobLevelUpNtf{
- OldLevel: oldLevel,
- NewLevel: newLevel,
- }
- this.role.ReplayGate(ntfMsg, true)
- changLevel = newLevel - oldLevel
- this.RoleData().JobLevel = newLevel
- //任务条件处理
- TaskMagCheck(this.role, serverproto.TaskType_Job_Level, 0)
- }
- this.SetDirty(true)
- util.InfoF("uid=%v AddJobExp addexp=%v newBaseExp=%v oldLevel=%v newLevel=%v", this.role.GetUUid(),
- exp, this.RoleData().JobExp, oldLevel, newLevel)
- return changLevel
- }
- // 根据类型获得具体部位索引
- func (this *RoleBase) GetSlotIndexByType(slotType int32) int32 {
- switch slotType {
- case Equip_Type_Head:
- return SLOT_TYPE_INDEX_Head
- case Equip_Type_Body:
- return SLOT_TYPE_INDEX_Body
- case Equip_Type_Weapon:
- return SLOT_TYPE_INDEX_Weapon
- case Equip_Type_Wrap:
- return SLOT_TYPE_INDEX_Wrap
- case Equip_Type_Shoes:
- return SLOT_TYPE_INDEX_Shoes
- case Equip_Type_Jew:
- return SLOT_TYPE_INDEX_Jew
- default:
- return SLOT_TYPE_INDEX
- }
- }
- func (this *RoleBase) GetSlotTypeByIndex(slotIndex int32) int32 {
- switch slotIndex {
- case SLOT_TYPE_INDEX_Head:
- return Equip_Type_Head
- case SLOT_TYPE_INDEX_Body:
- return Equip_Type_Body
- case SLOT_TYPE_INDEX_Weapon:
- return Equip_Type_Weapon
- case SLOT_TYPE_INDEX_Wrap:
- return Equip_Type_Wrap
- case SLOT_TYPE_INDEX_Shoes:
- return Equip_Type_Shoes
- case SLOT_TYPE_INDEX_Jew:
- return Equip_Type_Jew
- default:
- return Equip_Type_None
- }
- }
- func (this *RoleBase) getSlotData(heroId int32) *serverproto.SlotData {
- heroData := this.role.GetRoleHero().GetHero(heroId)
- if heroData == nil {
- return nil
- }
- return heroData.Slot
- }
- func (this *RoleBase) getSkillEquipSlotData(heroId int32) *serverproto.SkillEquipSlotData {
- heroData := this.role.GetRoleHero().GetHero(heroId)
- if heroData == nil {
- return nil
- }
- if heroData.SkillEquipSlot == nil {
- heroData.SkillEquipSlot = &serverproto.SkillEquipSlotData{}
- }
- typeLen := len(heroData.SkillEquipSlot.SlotList)
- if typeLen < SKILL_EQUIP_SLOT_TYPE_NUM {
- for i := 0; i < SKILL_EQUIP_SLOT_TYPE_NUM-typeLen; i++ {
- heroData.SkillEquipSlot.SlotList =
- append(heroData.SkillEquipSlot.SlotList,
- &serverproto.SkillEquipSlotDetailData{SlotLevel: 1})
- }
- }
- return heroData.SkillEquipSlot
- }
- func (this *RoleBase) EquipUp(heroId int32, slotIndex int32, equipId int32) serverproto.ErrorCode {
- heroData := this.role.GetRoleHero().GetHero(heroId)
- if heroData == nil {
- util.WarnF("uid=%v EquipUp hero data not found heroId=%v", this.role.GetUUid(), heroId)
- return serverproto.ErrorCode_ERROR_FAIL
- }
- //var slotData *serverproto.SlotData = nil
- slotData := heroData.Slot
- if slotData == nil {
- util.WarnF("uid=%v EquipUp slotData nil heroId=%v", this.role.GetUUid(), heroId)
- return serverproto.ErrorCode_ERROR_FAIL
- }
- typeLen := len(slotData.SlotList)
- if typeLen < SLOT_TYPE_NUM {
- for i := 0; i < SLOT_TYPE_NUM-typeLen; i++ {
- slotData.SlotList = append(slotData.SlotList, &serverproto.SlotDetailData{})
- }
- }
- //equip all
- if slotIndex != 0 {
- return this.role.GetRoleEquip().EquipUp(heroId, slotData, equipId, slotIndex)
- }
- this.role.GetRoleEquip().EquipUpAll(heroId, slotData)
- return serverproto.ErrorCode_ERROR_OK
- }
- // 任意N件装备精炼等级达到X级
- func (this *RoleBase) GetEquipSlotLevelNum(equipLevel int32) int32 {
- var retNum int32 = 0
- //game hero
- retNum += this.GetMainEquipSlotLevelNum(equipLevel)
- //fellow
- retNum += this.GetPartnerEquipSlotLevelNum(equipLevel)
- return retNum
- }
- // 任意N件装备精炼等级达到X级
- func (this *RoleBase) GetEquipSlotLevelRoleCnt(equipLevel int32) int32 {
- var retNum int32 = 0
- all := false
- slotData := this.role.GetRoleBase().RoleData().HeroData.Slot
- for _, detailData := range slotData.SlotList {
- if detailData.Level < equipLevel {
- all = false
- break
- }
- all = true
- }
- if all {
- retNum += 1
- }
- for _, heroData := range this.role.GetRoleHero().heroList {
- if heroData.Slot == nil {
- continue
- }
- find := false
- for _, detailData := range heroData.Slot.SlotList {
- if detailData.Level < equipLevel {
- find = false
- break
- }
- find = true
- }
- if find {
- retNum += 1
- }
- }
- return retNum
- }
- func (this *RoleBase) GetMainEquipSlotLevelNum(equipLevel int32) int32 {
- var retNum int32 = 0
- //game hero
- slotData := this.role.GetRoleBase().RoleData().HeroData.Slot
- for _, detailData := range slotData.SlotList {
- if detailData.Level >= equipLevel {
- retNum++
- }
- }
- return retNum
- }
- func (this *RoleBase) GetPartnerEquipSlotLevelNum(equipLevel int32) int32 {
- var retNum int32 = 0
- for _, heroData := range this.role.GetRoleHero().heroList {
- if heroData.Slot == nil {
- continue
- }
- for _, detailData := range heroData.Slot.SlotList {
- if detailData.Level >= equipLevel {
- retNum++
- }
- }
- }
- return retNum
- }
- func (this *RoleBase) EquipDown(heroId int32, subIndex int32) {
- slotData := this.getSlotData(heroId)
- if slotData == nil {
- util.WarnF("uid=%v EquipDown slotData nil heroId=%v", this.role.GetUUid(), heroId)
- return
- }
- this.role.GetRoleEquip().EquipDown(heroId, slotData, subIndex)
- }
- func (this *RoleBase) ChangeJobRefreshFashion(heroId int32) {
- slotData := this.getSlotData(heroId)
- if slotData == nil {
- util.WarnF("uid=%v EquipDown slotData nil heroId=%v", this.role.GetUUid(), heroId)
- return
- }
- this.role.GetRoleFashion().ChangeJobRefresh(heroId)
- }
- func (this *RoleBase) EquipLevelUpAll(heroId int32) {
- ackMsg := &serverproto.SCEquipLevelUpAllAck{
- Error: int32(serverproto.ErrorCode_ERROR_FAIL),
- }
- slotData := this.getSlotData(heroId)
- if slotData == nil {
- util.WarnF("uid=%v EquipLevelUpAll slotData nil heroId=%v", this.role.GetUUid(), heroId)
- this.role.ReplayGate(ackMsg, true)
- return
- }
- ret := this.role.GetRoleEquip().EquipLevelUpAll(heroId, slotData)
- if ret {
- ackMsg := &serverproto.SCEquipLevelUpAllAck{
- Error: int32(serverproto.ErrorCode_ERROR_OK),
- }
- this.role.ReplayGate(ackMsg, true)
- TaskMagCheck(this.role, serverproto.TaskType_Eve_Battle_Role_Quality, 0)
- }
- }
- func (this *RoleBase) EquipSlotLevelUp(heroId, subSlotIndex int32) serverproto.ErrorCode {
- slotData := this.getSlotData(heroId)
- if slotData == nil {
- util.WarnF("uid=%v EquipSlotLevelUp slotData nil heroId=%v", this.role.GetUUid(), heroId)
- return serverproto.ErrorCode_ERROR_FAIL
- }
- return this.role.GetRoleEquip().SlotLevelUp(slotData, heroId, subSlotIndex)
- }
- func (this *RoleBase) SlotCardMount(heroId, subSlotIndex, cardSlotIndex, cardCfgId int32) serverproto.ErrorCode {
- slotData := this.getSlotData(heroId)
- if slotData == nil {
- util.WarnF("uid=%v SlotCardMount slotData nil heroId=%v", this.role.GetUUid(), heroId)
- return serverproto.ErrorCode_ERROR_FAIL
- }
- if subSlotIndex > int32(len(slotData.SlotList)) || subSlotIndex < 0 {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- //当前槽位没有装备,无法进行卡片镶嵌
- if slotData.SlotList[subSlotIndex-1].EquipId == 0 {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- ret := this.role.GetRoleCard().Mount(slotData, heroId, subSlotIndex, cardSlotIndex, cardCfgId, true)
- if ret == serverproto.ErrorCode_ERROR_OK {
- this.SetDirty(true)
- this.role.GetRoleHero().addHeroChange(heroId)
- //槽位上的卡片数据变更
- this.SlotChangNtf(heroId, slotData)
- this.role.roleBattleAttr.AttrChange(
- AttrChangeST{
- ChangeType: Attr_Change_Card,
- ChangeHeroData: this.role.GetRoleHero().GetHero(heroId),
- })
- }
- return ret
- }
- func (this *RoleBase) SlotCardDown(heroId, subSlotIndex, cardSlotIndex int32) serverproto.ErrorCode {
- slotData := this.getSlotData(heroId)
- if slotData == nil {
- util.WarnF("uid=%v SlotCardDown slotData nil heroId=%v", this.role.GetUUid(), heroId)
- return serverproto.ErrorCode_ERROR_FAIL
- }
- ret := serverproto.ErrorCode_ERROR_OK
- if cardSlotIndex == 0 {
- //一键卸下
- ret = this.role.GetRoleCard().CardDownAll(slotData, subSlotIndex, heroId, true)
- } else {
- //单部位卸下
- ret = this.role.GetRoleCard().CardDown(slotData, subSlotIndex, cardSlotIndex, heroId)
- }
- if ret == serverproto.ErrorCode_ERROR_OK {
- //战斗力计算
- //this.role.roleFightPower.CardAttrChange(heroId, subSlotIndex)
- this.SetDirty(true)
- this.role.GetRoleHero().addHeroChange(heroId)
- this.SlotChangNtf(heroId, slotData)
- }
- return ret
- }
- func (this *RoleBase) CheckCardOp() serverproto.ErrorCode {
- if this.cardOperation != 0 && this.cardOperation+Card_Operation > util.GetTimeSeconds() {
- return serverproto.ErrorCode_ERROR_CARD_OP_SLOT_CARD_TOO_FAST
- }
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBase) SlotCardMountAll(msg *serverproto.CSCardEquipAllReq) serverproto.ErrorCode {
- vipCardMount := this.role.GetRoleBase().GetVipData(model.Vip_System_CardInsert)
- if vipCardMount <= 0 {
- return serverproto.ErrorCode_ERROR_VIP_LEVEL_LOW
- }
- ret := this.CheckCardOp()
- if ret != serverproto.ErrorCode_ERROR_OK {
- return ret
- }
- slotData := this.getSlotData(msg.HeroId)
- if slotData == nil {
- util.WarnF("uid=%v SlotCardDownAll slotData nil", this.role.GetUUid())
- return serverproto.ErrorCode_ERROR_FAIL
- }
- var bRet serverproto.ErrorCode
- for _, cardData := range msg.EqiupSlotData {
- for _, card := range cardData.CardSlotInfo {
- ret := this.role.GetRoleCard().Mount(slotData, msg.HeroId, cardData.SlotId, card.Key, card.Value, false)
- if ret == serverproto.ErrorCode_ERROR_OK { //有问题,也要计算后续的
- bRet = serverproto.ErrorCode_ERROR_OK
- }
- }
- }
- //如果有卡片装备成功
- if bRet == serverproto.ErrorCode_ERROR_OK {
- this.SetDirty(true)
- this.role.GetRoleHero().addHeroChange(msg.HeroId)
- //槽位上的卡片数据变更
- this.SlotChangNtf(msg.HeroId, slotData)
- //战斗力计算
- //this.role.roleFightPower.AllCardAttrChange(msg.HeroId)
- this.role.roleBattleAttr.AttrChange(
- AttrChangeST{
- ChangeType: Attr_Change_Card,
- ChangeHeroData: this.role.GetRoleHero().GetHero(msg.HeroId),
- })
- }
- this.cardOperation = util.GetTimeSeconds()
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBase) SlotCardDownAll(heroId int32) serverproto.ErrorCode {
- ret := this.CheckCardOp()
- if ret != serverproto.ErrorCode_ERROR_OK {
- return ret
- }
- slotData := this.getSlotData(heroId)
- if slotData == nil {
- util.WarnF("uid=%v SlotCardDownAll slotData nil heroId=%v", this.role.GetUUid(), heroId)
- return serverproto.ErrorCode_ERROR_FAIL
- }
- //检查是否装备卡片
- var bRet serverproto.ErrorCode
- for idx := range slotData.SlotList {
- if slotData.SlotList[idx].EquipId == 0 {
- continue
- }
- ret := this.role.GetRoleCard().CardDownAll(slotData, int32(idx+1), heroId, false)
- if ret == serverproto.ErrorCode_ERROR_OK {
- bRet = serverproto.ErrorCode_ERROR_OK
- }
- }
- if bRet == serverproto.ErrorCode_ERROR_OK {
- this.SetDirty(true)
- this.role.GetRoleHero().addHeroChange(heroId)
- this.SlotChangNtf(heroId, slotData)
- this.role.roleBattleAttr.AttrChange(
- AttrChangeST{
- ChangeType: Attr_Change_Card,
- ChangeHeroData: this.role.GetRoleHero().GetHero(heroId),
- })
- //战斗力计算
- //this.role.roleFightPower.AllCardAttrChange(heroId)
- this.cardOperation = util.GetTimeSeconds()
- return serverproto.ErrorCode_ERROR_OK
- }
- return serverproto.ErrorCode_ERROR_FAIL
- }
- func (this *RoleBase) SlotCardUpGradeAll(msg *serverproto.CSCardUpGradeAllReq) serverproto.ErrorCode {
- ret := this.CheckCardOp()
- if ret != serverproto.ErrorCode_ERROR_OK {
- return ret
- }
- slotData := this.getSlotData(msg.HeroId)
- if slotData == nil {
- util.WarnF("uid=%v SlotCardDownAll slotData nil heroId=%v", this.role.GetUUid(), msg.HeroId)
- return serverproto.ErrorCode_ERROR_FAIL
- }
- var bChanged = false
- var changIdList = set.New(set.NonThreadSafe)
- for _, data := range msg.Data {
- //check key 装备位序号,value 卡片位序号
- if data.Key < Equip_Type_Head || data.Key > Equip_Type_Jew || data.Value <= 0 || data.Value > Max_Card_Slot_Num {
- continue
- }
- //装备位没有装备不让操作。
- slotData := slotData.SlotList[data.Key-1]
- if slotData == nil || slotData.EquipId == 0 {
- continue
- }
- if int(data.Value) <= len(slotData.CardIdList) && data.Value > 0 {
- cardData := slotData.CardIdList[data.Value-1]
- if cardData == 0 {
- continue
- }
- //走合成卡片流程, toCardId合成的目标ID
- bRet, toCardId := this.role.GetRoleCard().SlotCardLevelUp(cardData, changIdList)
- if !bRet {
- continue
- }
- changIdList.Add(slotData.CardIdList[data.Value-1])
- slotData.CardIdList[data.Value-1] = toCardId
- bChanged = true
- }
- }
- if bChanged == true {
- //set dirty
- this.role.GetRoleHero().addHeroChange(msg.HeroId)
- this.role.GetRoleCard().cardChangNtf(changIdList, false)
- this.SlotChangNtf(msg.HeroId, slotData)
- //this.role.GetRoleFightPower().AllCardAttrChange(msg.HeroId)
- this.role.roleBattleAttr.AttrChange(AttrChangeST{
- ChangeType: Attr_Change_Card,
- ChangeHeroData: this.role.GetRoleHero().GetHero(msg.HeroId),
- })
- return serverproto.ErrorCode_ERROR_OK
- }
- this.cardOperation = util.GetTimeSeconds()
- return serverproto.ErrorCode_ERROR_FAIL
- }
- func (this *RoleBase) checkUnLockState(heroId int32, condition []*serverproto.KeyValueType) serverproto.ErrorCode {
- if len(condition) <= 0 {
- return serverproto.ErrorCode_ERROR_OK
- }
- for id := range condition {
- conType := condition[id].Key
- conValue := condition[id].Value
- switch (serverproto.TaskType)(conType) {
- //使用任务枚举字段
- case serverproto.TaskType_Base_Level: //角色等级
- heroData := this.role.roleHero.GetHero(heroId)
- if heroData == nil {
- return serverproto.ErrorCode_ERROR_HERO_NO_FOUND
- }
- if heroData.BaseLevel < int32(conValue) { //获取英雄的等级来判定
- return serverproto.ErrorCode_ERROR_SKILL_ROLE_LEVEL_NOT_ENOUGH
- }
- case serverproto.TaskType_Level_Battle_Count:
- if this.role.GetRoleBattle().getLevelId(this.role.GetRoleBattle().mapId, this.role.GetRoleBattle().mapLevel) < int32(conValue) {
- return serverproto.ErrorCode_ERROR_MAP_MAP_LEVEL_LOW
- }
- case serverproto.TaskType_Climbing_Tower_Level: //爬塔到达层数
- if this.role.GetRoleTower().GetCurTower() < int32(conValue) {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- case serverproto.TaskType_VIP_Level:
- if this.role.GetRoleVipLevel() < int32(conValue) {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- case serverproto.TaskType_Start_Server_Days:
- startUpTime := service.GetServiceStartupTime()
- if startUpTime < 0 {
- util.ErrorF("[convertRushListCfg] data error:%v")
- return serverproto.ErrorCode_ERROR_FAIL
- }
- durationDay := util.GetDurationDay2(startUpTime, util.GetCurrentTime())
- if durationDay < int32(conValue) {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- default:
- return serverproto.ErrorCode_ERROR_FAIL
- }
- }
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBase) SetFightPower(fightPower uint32) {
- nowTime := util.GetTimeMilliseconds()
- if this.RoleData().FightPower < uint64(fightPower) {
- this.RoleData().FightPower = uint64(fightPower)
- this.SetDirty(true)
- //设置历史战力排行榜
- ssReqMsg := &serverproto.SSMaxFightPowerRankNtf{
- Uid: this.role.GetUUid(),
- MaxFightPower: this.RoleData().FightPower,
- }
- this.role.SendRank(ssReqMsg)
- //cross rank
- //更新跨服最大战力排行榜
- if this.role.GetRoleBattle().GetLevelId() >= model.GlobalCrossMaxFightPowerRankVal {
- crossSSMsg := &serverproto.SSCrossRankUpdateNtf{
- SelfMaxFightPower: uint64(fightPower),
- FightInfo: &serverproto.FightRoleInfo{},
- }
- this.role.GetRoleFightInfo(crossSSMsg.FightInfo, false)
- crossSSMsg.FightInfo.BriefInfo.FightPower = int32(fightPower)
- this.role.SendSocial(crossSSMsg)
- this.lastFightPowerChangeTimeStamp = nowTime
- }
- }
- //当前版本,暂定实时同步
- if fightPower > 0 {
- this.UpdatePlayerBriefInfo(false)
- }
- //设置简介信息 //战力超过5K。立刻写入,战力低于5000,每5次变化写入
- /*
- if fightPower >= 2000 {
- this.UpdatePlayerBriefInfo(false)
- this.fightChangeNum = 0
- } else {
- if this.fightChangeNum >= Max_Change_Count {
- this.UpdatePlayerBriefInfo(false)
- this.fightChangeNum = 0
- } else {
- this.fightChangeNum++
- }
- }
- */
- //更新跨服最大战力排行榜玩家阵容信息
- if this.role.GetRoleBattle().GetLevelId() >= model.GlobalCrossMaxFightPowerRankVal {
- fightInfoUpdateTime := model.GlobalCrossMaxFightPowerFightInfoUpdateTime * 1000
- if nowTime-this.lastFightPowerChangeTimeStamp > uint64(fightInfoUpdateTime) {
- this.lastFightPowerChangeTimeStamp = nowTime
- crossSSMsg := &serverproto.SSCrossRankFightInfoUpdateNtf{
- FightInfo: &serverproto.FightRoleInfo{},
- CurSelfMaxFightPower: this.RoleData().FightPower,
- }
- this.role.GetRoleFightInfo(crossSSMsg.FightInfo, false)
- if fightPower > 0 {
- crossSSMsg.FightInfo.BriefInfo.FightPower = int32(fightPower)
- } else {
- if this.role.roleBattleAttr.curTotalFightPower > 0 {
- crossSSMsg.FightInfo.BriefInfo.FightPower = int32(this.role.roleBattleAttr.curTotalFightPower)
- } else {
- crossSSMsg.FightInfo.BriefInfo.FightPower = int32(this.RoleData().FightPower)
- }
- }
- this.role.SendSocial(crossSSMsg)
- }
- }
- }
- // 设置头像
- func (this *RoleBase) SetRoleHeadPic(headId int32) serverproto.ErrorCode {
- bRet := this.CheckHeadUnlock(headId)
- if bRet && this.roleBase.RoleData.HeadId != headId && headId != 0 {
- this.roleBase.RoleData.HeadId = headId
- this.SetDirty(true)
- return serverproto.ErrorCode_ERROR_OK
- }
- return serverproto.ErrorCode_ERROR_FAIL
- }
- // 请求头像信息
- func (this *RoleBase) HeadInfoReq() {
- ackMsg := &serverproto.SCHeadInfoAck{}
- for _, data := range this.roleBase.Head_Info.HeadList {
- ackMsg.HeadList = append(ackMsg.HeadList, data)
- }
- ackMsg.Head_Info = &this.role.roleTask.roleHeadCond
- this.role.ReplayGate(ackMsg, true)
- }
- // 请求激活头像
- func (this *RoleBase) ActiveHead(headId int32) serverproto.ErrorCode {
- //检查headId是否已经被激活
- if bRet := this.CheckHeadUnlock(headId); bRet {
- return serverproto.ErrorCode_ERROR_ACTIVE_HEAD_UNLOCKED
- }
- //检查headId被激活条件是否满足
- if !this.role.roleTask.CheckHeadUnlocked(headId) {
- return serverproto.ErrorCode_ERROR_ACTIVE_HEAD_CHECK_CONDITION_FAILED
- }
- //解锁头像加入到解锁列表中
- this.roleBase.Head_Info.HeadList = append(this.roleBase.Head_Info.HeadList, headId)
- //通知客户端激活成功
- this.SetDirty(true)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBase) AddHeadFrame(frameId, lastTime, count int32) serverproto.ErrorCode {
- var endTime int64 = -1
- var bFind = false
- if this.roleBase.Head_Info != nil {
- for _, data := range this.roleBase.Head_Info.HeadFrameList {
- if data.HeadFrameId == frameId {
- if data.HeadFrameTime == -1 { //已经是永久了
- return serverproto.ErrorCode_ERROR_HEAD_FRAME_EXCHANGE_ITEM
- }
- if lastTime == -1 {
- data.HeadFrameTime = -1
- endTime = -1
- } else {
- data.HeadFrameTime += int64(count * lastTime * 3600)
- endTime = data.HeadFrameTime
- }
- bFind = true
- break
- }
- }
- }
- if bFind == false {
- if lastTime != -1 {
- endTime = util.GetTimeSeconds() + int64(count*lastTime)*3600
- }
- this.roleBase.Head_Info.HeadFrameList = append(this.roleBase.Head_Info.HeadFrameList, &serverproto.HeadFrameData{
- HeadFrameId: frameId,
- HeadFrameTime: endTime,
- })
- }
- //通知头像框改变
- var headFrame []*serverproto.HeadFrameData
- headFrame = append(headFrame, &serverproto.HeadFrameData{
- HeadFrameId: frameId,
- HeadFrameTime: endTime,
- })
- this.HeadFrameChangeNtf(headFrame)
- //this.role.GetRoleFightPower().HeadFrameAttrChange(false)
- this.SetDirty(true)
- this.role.roleBattleAttr.AttrChange(AttrChangeST{
- ChangeType: Attr_Change_HeadFrame,
- ChangeHeroData: this.role.GetRoleHero().GetMainHero(),
- HeadFrameId: frameId,
- })
- TaskMagCheck(this.role, serverproto.TaskType_Eve_Head_Icon_Cont, 1)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBase) SetHeadFrameId(frameId int32) serverproto.ErrorCode {
- nowTime := util.GetTimeSeconds()
- if this.roleBase.Head_Info != nil && len(this.roleBase.Head_Info.HeadFrameList) > 0 {
- for _, data := range this.roleBase.Head_Info.HeadFrameList {
- if data.HeadFrameId == frameId {
- if data.HeadFrameTime == -1 || (data.HeadFrameTime != -1 && int64(data.HeadFrameTime) >= nowTime) {
- this.roleBase.GetRoleData().HeadFrameId = frameId
- this.SetDirty(true)
- this.UpdatePlayerBriefInfo(false)
- return serverproto.ErrorCode_ERROR_OK
- }
- }
- }
- }
- return serverproto.ErrorCode_ERROR_FAIL
- }
- func (this *RoleBase) GetHeadFrameCount() int32 {
- if this.roleBase.Head_Info == nil {
- return 0
- }
- return int32(len(this.roleBase.Head_Info.HeadFrameList))
- }
- func (this *RoleBase) PackHeadFrameInfo(ackMsg *serverproto.SCHeadFrameInfoAck) serverproto.ErrorCode {
- if this.roleBase.Head_Info == nil || len(this.roleBase.Head_Info.HeadFrameList) <= 0 {
- return serverproto.ErrorCode_ERROR_OK
- }
- for _, data := range this.roleBase.Head_Info.HeadFrameList {
- if data.HeadFrameId != 0 && data.HeadFrameTime != 0 {
- ackMsg.HeadFrame = append(ackMsg.HeadFrame, &serverproto.HeadFrameData{
- HeadFrameId: data.HeadFrameId,
- HeadFrameTime: data.HeadFrameTime,
- })
- }
- }
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBase) HeadFrameChangeNtf(headFrame []*serverproto.HeadFrameData) {
- ntfMsg := &serverproto.SCHeadFrameChangeNtf{}
- ntfMsg.HeadFrame = headFrame
- this.role.ReplayGate(ntfMsg, true)
- }
- // 检查头像任务是否激活
- func (this *RoleBase) CheckHeadUnlock(headId int32) bool {
- for _, data := range this.roleBase.Head_Info.HeadList {
- if data == headId {
- return true
- }
- }
- return false
- }
- func (this *RoleBase) ChangeNameItemEnough(name string, remove bool) serverproto.ErrorCode {
- consumeCfg, ok := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Rename_Consume)]
- if !ok {
- return serverproto.ErrorCode_ERROR_RENAME_CONSUME_CONFIG_ERROR
- }
- if len(consumeCfg.SVal) > 0 {
- var costItemList = map[int32]int32{}
- k, v := model.Str2Res(consumeCfg.SVal)
- if k > 0 && v > 0 {
- costItemList[k] = v
- if this.role.CheckResLitNum(costItemList) {
- if remove {
- this.role.DelItemList(costItemList, AddItemST{AddFrom: AddFrom_System})
- } else {
- return serverproto.ErrorCode_ERROR_OK
- }
- } else {
- util.DebugF("uid=%v ChangeName chang name item not enough", this.role.GetUUid())
- return serverproto.ErrorCode_ERROR_RENAME_ITEM_NOT_ENOUGH
- }
- }
- }
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBase) ChangeRoleName(name string) serverproto.ErrorCode {
- bRet := this.ChangeNameItemEnough(name, true)
- if bRet != serverproto.ErrorCode_ERROR_OK {
- return bRet
- }
- this.Rename(name)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBase) SetGuideId(guideId int32) {
- if this.roleBase.GuideId < guideId {
- this.roleBase.GuideId = guideId
- this.SetDirty(true)
- }
- }
- func (this *RoleBase) SetStoryId(story *serverproto.KeyValueType) serverproto.ErrorCode {
- tmpVal := story.Key*100 + story.Value
- for index, data := range this.roleBase.StoryId {
- //不是这个Key
- if data/100 != story.Key {
- continue
- }
- //重复发送
- if data == tmpVal {
- return serverproto.ErrorCode_ERROR_OK
- }
- //删除当前元素
- this.roleBase.StoryId = append(this.roleBase.StoryId[:index], this.roleBase.StoryId[index+1:]...)
- //记录新的元素
- this.roleBase.StoryId = append(this.roleBase.StoryId, tmpVal)
- this.SetDirty(true)
- return serverproto.ErrorCode_ERROR_OK
- }
- this.roleBase.StoryId = append(this.roleBase.StoryId, tmpVal)
- this.SetDirty(true)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBase) SetCompulsoryId(storyId, status int32) serverproto.ErrorCode {
- if this.roleBase.Cguide == nil {
- this.roleBase.Cguide = &serverproto.KeyValueType{
- Key: storyId,
- Value: status,
- }
- this.SetDirty(true)
- return serverproto.ErrorCode_ERROR_OK
- }
- if this.roleBase.Cguide.Key > storyId {
- return serverproto.ErrorCode_ERROR_FAIL
- } else if this.roleBase.Cguide.Key == storyId {
- if this.roleBase.Cguide.Value >= status {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- }
- this.roleBase.Cguide.Key = storyId
- this.roleBase.Cguide.Value = status
- this.SetDirty(true)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBase) SetNewMapCartoonId(id int32, status int32) serverproto.ErrorCode {
- if id == 0 || (status != NEW_MAP_CARTOON_START && status != NEW_MAP_CARTOON_END) {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- if this.roleBase.MapAnimation != nil {
- if this.roleBase.MapAnimation.Key > id {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- if this.roleBase.MapAnimation.Key == id && this.roleBase.MapAnimation.Value == status {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- this.roleBase.MapAnimation.Key = id
- this.roleBase.MapAnimation.Value = status
- } else {
- this.roleBase.MapAnimation = &serverproto.KeyValueType{
- Key: id,
- Value: NEW_MAP_CARTOON_START,
- }
- }
- this.SetDirty(true)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBase) AddBossReward(addItemList map[int32]int32) {
- for key, val := range addItemList {
- bRet := false
- for idx := 0; idx < len(this.roleBase.RoleData.BossRewardList); idx++ {
- if this.roleBase.RoleData.BossRewardList[idx].Key == key {
- bRet = true
- this.roleBase.RoleData.BossRewardList[idx].Value += val
- break
- }
- }
- if !bRet {
- this.roleBase.RoleData.BossRewardList = append(this.roleBase.RoleData.BossRewardList,
- &serverproto.KeyValueType{
- Key: key,
- Value: val,
- })
- }
- }
- this.SetDirty(true)
- }
- func (this *RoleBase) HasBossReward() bool {
- return len(this.roleBase.RoleData.BossRewardList) > 0
- }
- func (this *RoleBase) GetBossReward() []*serverproto.KeyValueType {
- return this.roleBase.RoleData.BossRewardList
- }
- func (this *RoleBase) ClearBossReward() {
- this.roleBase.RoleData.BossRewardList = this.roleBase.RoleData.BossRewardList[:0]
- this.SetDirty(true)
- }
- func (this *RoleBase) CheckVipLevelUp() {
- vipExp := this.role.getCommonResNum(int32(serverproto.ResType_Res_VipExp))
- bLevelUp := false
- nowLevel := this.role.GetRoleVipLevel()
- for i := nowLevel; i < int32(len(model.ConvertVipRight)); i++ {
- if model.ConvertVipRight[i].VipRight[model.Vip_System_Levelup] <= 0 {
- continue
- }
- if model.ConvertVipRight[i].VipRight[model.Vip_System_Levelup] <= vipExp {
- nextCfg, ok := model.ConvertVipRight[i+1]
- if !ok {
- break
- }
- this.role.GetRoleBase().roleBase.VipLevel = i + 1
- bLevelUp = true
- //给Vip升级奖励
- if len(nextCfg.VipReward) > 0 {
- this.role.GetRoleMail().AddMail(model.GlobalMailIdVipLevelUp, serverproto.MailType_MailType_VipLevelUp,
- nextCfg.VipReward, []int32{this.role.GetRoleBase().roleBase.VipLevel}, "", "")
- }
- this.SetDirty(true)
- }
- }
- ntfMsg := &serverproto.SCVipChangeNtf{
- VipLevel: this.role.GetRoleVipLevel(),
- VipExp: this.role.getCommonResNum(int32(serverproto.ResType_Res_VipExp)),
- }
- this.role.ReplayGate(ntfMsg, true)
- if bLevelUp == true {
- this.role.GetRoleBattle().CheckEvilBattleCount()
- this.UpdatePlayerBriefInfo(false)
- }
- }
- func (this *RoleBase) checkBTBoliLevelUp() {
- // boli商城等级提升检测
- bLevelUp := false
- newExp := this.role.getCommonResNum(int32(serverproto.ResType_Res_BoliShopExp))
- var oldLevel int32 = 0
- if this.role.roleBT.boliData != nil {
- oldLevel = this.role.roleBT.boliData.Level
- }
- newLevel := oldLevel
- for {
- // 1lv->2lv使用1的升级经验
- cfgData, ok := model.ConvertBoliVipData[newLevel]
- if !ok {
- break
- }
- if newExp >= cfgData.VipExp && cfgData.VipExp > 0 {
- if _, nextLevelOk := model.ConvertBoliVipData[newLevel+1]; !nextLevelOk {
- break
- }
- bLevelUp = true
- newLevel++
- } else {
- break
- }
- }
- if bLevelUp {
- this.role.roleBT.OnBoliLevelUp(newLevel)
- }
- }
- // 获取特权对应加成数值
- func (this *RoleBase) GetVipData(dataType int32) int32 {
- var retVal int32 = 0
- vipLevel := this.role.GetRoleVipLevel()
- data, ok := model.ConvertVipRight[vipLevel]
- if ok {
- right, ok1 := data.VipRight[dataType]
- if ok1 {
- if dataType == model.Vip_System_Evil && right == 0 {
- return right
- }
- if right < 0 {
- right = 0
- }
- retVal = right
- }
- }
- // RO通行证
- if dataType == model.Vip_System_QuickBattleBaseExp {
- if this.role.GetRoleRune() != nil && this.role.GetRoleRune().runeBase.IsPassCheck {
- if right, ok := model.ConvertPassCheckData.VipRight[dataType]; ok {
- if dataType == model.Vip_System_Evil && right == 0 {
- return right
- }
- if right < 0 {
- right = 0
- }
- retVal += right
- }
- }
- }
- // 波利商城
- if this.role.roleBT != nil {
- var boliLevel int32 = 0
- if this.role.roleBT.boliData != nil {
- boliLevel = this.role.roleBT.boliData.Level
- }
- cfgData, ok := model.ConvertBoliVipData[boliLevel]
- if ok {
- if right, ok1 := cfgData.VipRight[dataType]; ok1 {
- if dataType == model.Vip_System_Evil && right == 0 {
- return right
- }
- if right < 0 {
- right = 0
- }
- retVal += right
- }
- }
- }
- return retVal
- }
|