| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079 |
- 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)
- //m := map[int32]int{
- // 22100: 1, 22101: 1, 22102: 1, 22103: 1, 22104: 1, 22105: 1, 22106: 1, 22107: 1, 22108: 1, 22109: 1, 22110: 1, 22111: 1,
- // 22200: 1, 22201: 1, 22202: 1, 22203: 1, 22204: 1, 22205: 1, 22206: 1, 22207: 1, 22208: 1, 22209: 1, 22210: 1, 22211: 1,
- // 22300: 1, 22301: 1, 22302: 1, 22303: 1, 22304: 1, 22305: 1, 22306: 1, 22307: 1, 22308: 1, 22309: 1, 22310: 1, 22311: 1,
- // 22400: 1, 22401: 1, 22402: 1, 22403: 1, 22404: 1, 22405: 1, 22406: 1, 22407: 1, 22408: 1, 22409: 1, 22410: 1, 22411: 1,
- // 22500: 1, 22501: 1, 22502: 1, 22503: 1, 22504: 1, 22505: 1, 22506: 1, 22507: 1, 22508: 1, 22509: 1, 22510: 1, 22511: 1,
- //}
- *this.roleBase = *proRole.RoleBase
- if this.roleBase.RoleData != nil {
- //if this.roleBase.RoleData.HeroData != nil && !this.role.GetRoleBase().roleBase.RoleDelete4 {
- // if this.roleBase.RoleData.HeroData.Slot != nil {
- // for _, v := range this.roleBase.RoleData.HeroData.Slot.SlotList {
- // var newS []int32
- // for _, c := range v.CardIdList {
- // if _, ok := m[c]; !ok {
- // newS = append(newS, c)
- // }
- // }
- // v.CardIdList = newS
- // }
- // }
- // util.ErrorF("delete card uuid:%v,name:%v", this.role.GetUUid(), this.roleBase.NickName)
- // this.role.GetRoleBase().roleBase.RoleDelete4 = true
- // this.role.GetRoleBase().SetDirty(true)
- // this.SetDirty(true)
- //}
- //if !this.role.GetRoleBase().roleBase.RoleDelete3 {
- // //ro币扣除
- // for _, v := range this.roleBase.ResList {
- // if v.Key == 54 && v.Value > 30000 {
- // util.ErrorF("ro set ro 30000 uuid:%v,ro:%v,name:%v", this.role.GetUUid(), this.roleBase.Rmb, this.roleBase.NickName)
- // v.Value = 30000
- // }
- // }
- // if this.roleBase.Rmb > 10000000 {
- // util.ErrorF("ro set coin 10000000 uuid:%v,coin:%v,name:%v", this.role.GetUUid(), this.roleBase.Rmb, this.roleBase.NickName)
- // this.roleBase.Rmb = 10000000
- // }
- // this.role.GetRoleBase().roleBase.RoleDelete3 = true
- // this.role.GetRoleBase().SetDirty(true)
- //}
- //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
- }
|