| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035 |
- 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)
- 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)
- TaskMagCheck(this.role, serverproto.TaskType_BT_ZhenJiaRecharge, val)
- }
- // 增加累计充值
- 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
- TaskMagCheck(this.role, serverproto.TaskType_BT_ZhenJiaRecharge, int32(amount))
- }
- }
- // bt 获得RO币
- tmpRoCoin := payRewardInfo.Amount * 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 := amount * 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
- //main 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
- //main 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
- }
|