2026-03-04 15:54:01 +08:00

2124 lines
62 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package model
import (
"math"
"rocommon/service"
"rocommon/util"
"roserver/baseserver/model"
"roserver/baseserver/set"
"roserver/serverproto"
"sync"
"time"
)
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) {
msgNtf.Story = make([]int64, 0)
for _, data := range this.roleBase.StoryId {
msgNtf.Story = append(msgNtf.Story, data)
}
msgNtf.StoryNpc = make([]int64, 0)
for _, data := range this.roleBase.StoryNpcId {
msgNtf.StoryNpc = append(msgNtf.StoryNpc, 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
}
/*todo wangzhaocan 看广告屏蔽
if len(this.roleBase.WatchAd) <= 0 {
this.refreshWatchAd(false)
}
*/
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) GetVipLevel() int32 {
return this.roleBase.VipLevel
}
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.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,
}
this.role.ReplayGate(ntfMsg, true)
ntfOnlineTimeRewardMsg := &serverproto.SCOnlineTimeRewardNtf{
OnlineStamp: this.roleBase.OnlineStamp,
OnlineRewardId: 0,
TotalOnlineTime: 0,
}
this.role.ReplayGate(ntfOnlineTimeRewardMsg, true)
}
//todo wangzhaocan 看广告屏蔽
//this.refreshWatchAd(notify)
return oldDailyResetTimeStamp
}
/*todo wangzhaocan 看广告屏蔽
func (this *RoleBase) refreshWatchAd(notify bool) {
this.roleBase.WatchAd = this.roleBase.WatchAd[0:0]
for key, value := range model.GlobalWatchAdDayCount {
this.roleBase.WatchAd = append(this.roleBase.WatchAd, &serverproto.KeyValueType{
Key: key,
Value: value,
})
}
this.SetDirty(true)
if notify {
this.WatchAddCountChangeNtf()
}
}
func (this *RoleBase) CheckWatchAdCount(adType int32) bool {
count, ok := model.GlobalWatchAdDayCount[adType]
if !ok { //没找到说明不限制
return true
}
if count <= 0 {
return false
}
for _, data := range this.roleBase.WatchAd {
if data.Key != adType {
continue
}
if data.Value <= 0 {
return false
}
break
}
return true
}
func (this *RoleBase) AddWatchAdCount(adType int32) {
count, ok := model.GlobalWatchAdDayCount[adType]
if !ok {
return
}
if count <= 0 {
return
}
for _, data := range this.roleBase.WatchAd {
if data.Key != adType {
continue
}
data.Value--
if data.Value < 0 {
data.Value = 0
}
}
this.WatchAddCountChangeNtf()
this.SetDirty(true)
}
func (this *RoleBase) WatchAddCountChangeNtf() {
ackMsg := &serverproto.SCWatchADInfoNtf{}
for _, data := range this.roleBase.WatchAd {
ackMsg.WatchAd = append(ackMsg.WatchAd, &serverproto.KeyValueType{
Key: data.Key,
Value: data.Value,
})
}
this.role.ReplayGate(ackMsg, true)
util.InfoF("uid=%v ackMsg := %v", this.role.GetUUid(), ackMsg)
}
*/
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
}
this.roleBase.Rmb = uint32(tmpExp)
}
this.SetDirty(true)
this.WriteMiaojuGoldLog()
//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) WriteMiaojuGoldLog() {
goldLog := &MiaojuLogGold{
Properties: Gold{
Coin: int(this.roleBase.Rmb),
},
}
goldLog.OpenId = this.role.GetLunaAccount()
goldLog.DistinctId = ""
goldLog.Type = "user_set"
goldLog.CurTime = time.Unix(int64(util.GetTimeSeconds()), 0).Format(util.DATE_FORMAT)
goldLog.Log(this.role)
}
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
}
// 添加资源
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)
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()
}
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 {
//上限处理
switch serverproto.ResType(resType) {
case serverproto.ResType_Res_EvilExp:
if model.GlobalEvilExpLimit > 0 && resValue > model.GlobalEvilExpLimit {
resValue = model.GlobalEvilExpLimit
}
}
this.roleBase.ResList = append(this.roleBase.ResList, &serverproto.KeyValueType{
Key: resType,
Value: resValue,
})
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) WriteMiaojuPayLog(amount, oldVal float32) {
if oldVal == 0 {
//首冲只写一次
firstPayLog := &MiaojuLogFirstPay{
Properties: FirstPay{
FirstPayTime: time.Unix(int64(util.GetTimeSeconds()), 0).Format(util.DATE_FORMAT),
},
}
firstPayLog.OpenId = this.role.GetLunaAccount()
firstPayLog.DistinctId = ""
firstPayLog.Type = "user_setOnce"
firstPayLog.CurTime = time.Unix(int64(util.GetTimeSeconds()), 0).Format(util.DATE_FORMAT)
firstPayLog.Log(this.role)
}
{
//累计充值日志
totalPayLog := &MiaojuLogTotalPay{
Properties: TotalPay{
TotalCharge: this.roleBase.TotalRecharge,
},
}
totalPayLog.OpenId = this.role.GetLunaAccount()
totalPayLog.DistinctId = ""
totalPayLog.Type = "user_add"
totalPayLog.CurTime = time.Unix(int64(util.GetTimeSeconds()), 0).Format(util.DATE_FORMAT)
totalPayLog.Log(this.role)
}
}
// 增加累计充值
func (this *RoleBase) AddPayRecharge(payRewardInfo *serverproto.PayOrderSaveInfo) {
amount := payRewardInfo.KrCur
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)
this.WriteMiaojuPayLog(amount, oldVal)
ntfMsg := &serverproto.SCPayInfoNtf{
TotalRecharge: this.roleBase.TotalRecharge,
DayRecharge: this.roleBase.DayRecharge,
}
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)
//欧美区域vip经验处理
if service.ServerRegion == "ea" {
vipExp = float32(math.Ceil(float64(vipExp)))
}
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.KrCur * 100)})
}
//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 * 100), int32(this.roleBase.TotalRecharge * 100), int32(amount * 100)},
}
orderLogData := &serverproto.SSRoleLogData{
Uid: this.role.GetUUid(),
Type: int32(serverproto.MysqlLogType_LType_OrderList),
ParamList: []int32{int32(amount * 100), 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() {
if !this.role.isCliLoad {
return
}
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(),
SelectZone: this.role.GetSelectZone(),
},
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)
}
if oldLevel < newLevel {
this.WriteMiaojuLevelUpLog(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) WriteMiaojuLevelUpLog(roleLevel int32) {
levelUpLog := &MiaojuLogLevelUp{
Properties: LevelUp{
RoleLevel: int(roleLevel),
},
}
levelUpLog.OpenId = this.role.GetLunaAccount()
levelUpLog.DistinctId = ""
levelUpLog.Type = "user_set"
levelUpLog.Type = "user_set"
levelUpLog.CurTime = time.Unix(int64(util.GetTimeSeconds()), 0).Format(util.DATE_FORMAT)
levelUpLog.Log(this.role)
}
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
return true
}
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) GetStoryVal(storyId int32) int32 {
for _, storyData := range this.roleBase.StoryId {
currStoryId := int32(storyData / 1000)
currStoryStoreData := int32(storyData % 1000)
if currStoryId == storyId {
return currStoryStoreData
}
}
return 0
}
func (this *RoleBase) SetStoryId(story *serverproto.KeyValueType) serverproto.ErrorCode {
tmpVal := story.Key*1000 + story.Value
for index, data := range this.roleBase.StoryId {
//不是这个Key
if data/1000 != int64(story.Key) {
continue
}
//重复发送
if data == int64(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, int64(tmpVal))
this.SetDirty(true)
return serverproto.ErrorCode_ERROR_OK
}
this.roleBase.StoryId = append(this.roleBase.StoryId, int64(tmpVal))
this.SetDirty(true)
return serverproto.ErrorCode_ERROR_OK
}
func (this *RoleBase) GetStoryNpcHeart(storyNpcId int32) int32 {
for _, storyNpcData := range this.roleBase.StoryNpcId {
currStoryNpcId := int32(storyNpcData / 1000)
currStoryNpcHeart := int32(storyNpcData % 1000)
if currStoryNpcId == storyNpcId {
return currStoryNpcHeart
}
}
return 0
}
func (this *RoleBase) SetStoryNpcId(storyNpc *serverproto.KeyValueType) serverproto.ErrorCode {
tmpVal := storyNpc.Key*1000 + storyNpc.Value
for index, data := range this.roleBase.StoryNpcId {
//不是这个Key
if data/1000 != int64(storyNpc.Key) {
continue
}
//重复发送
if data == int64(tmpVal) {
return serverproto.ErrorCode_ERROR_OK
}
//删除当前元素
this.roleBase.StoryNpcId = append(this.roleBase.StoryNpcId[:index], this.roleBase.StoryNpcId[index+1:]...)
//记录新的元素
this.roleBase.StoryNpcId = append(this.roleBase.StoryNpcId, int64(tmpVal))
this.SetDirty(true)
return serverproto.ErrorCode_ERROR_OK
}
this.roleBase.StoryNpcId = append(this.roleBase.StoryNpcId, int64(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)
}
if nowLevel < this.role.GetRoleVipLevel() {
this.WriteMiaojuVipLevelLog()
}
}
func (this *RoleBase) WriteMiaojuVipLevelLog() {
levelUpLog := &MiaojuLogVipLevel{
Properties: VipLevel{
VipLevel: int(this.role.GetRoleVipLevel()),
},
}
levelUpLog.OpenId = this.role.GetLunaAccount()
levelUpLog.DistinctId = ""
levelUpLog.Type = "user_set"
levelUpLog.CurTime = time.Unix(int64(util.GetTimeSeconds()), 0).Format(util.DATE_FORMAT)
levelUpLog.Log(this.role)
}
func (this *RoleBase) GetVipData(dataType int32) int32 {
vipLevel := this.role.GetRoleVipLevel()
data, ok := model.ConvertVipRight[vipLevel]
if !ok {
return -1
}
_, ok1 := data.VipRight[dataType]
if !ok1 {
return -1
}
return data.VipRight[dataType]
}
func (this *RoleBase) GetGoogleCommentReward() serverproto.ErrorCode {
if this.roleBase.GoogleComment {
return serverproto.ErrorCode_ERROR_FAIL
}
if len(model.GlobalGoogleCommentReward) > 0 {
this.role.GetRoleMail().AddMail(33, serverproto.MailType_MailType_GoogleComment,
model.GlobalGoogleCommentReward, nil, "", "")
} else {
util.InfoF("uid=%v model.GlobalGoogleCommentReward empty!! ", this.role.GetUUid())
}
this.roleBase.GoogleComment = true
this.SetDirty(true)
return serverproto.ErrorCode_ERROR_OK
}