package model import ( "rocommon/util" "roserver/baseserver/model" "roserver/serverproto" ) type RoleRush struct { SaveObject rushSkill *serverproto.RushSkill } func newRoleRush(r *Role) *RoleRush { roleCommon := &RoleRush{ SaveObject: SaveObject{ role: r, }, } return roleCommon } func (this *RoleRush) Load(msg interface{}) bool { proRole := msg.(*serverproto.Role) if proRole != nil && proRole.RoleRush != nil { this.rushSkill = proRole.RoleRush.RushSkill } bChanged := false if this.rushSkill == nil { this.rushSkill = &serverproto.RushSkill{} bChanged = true } if bChanged == true { this.SetDirty(true) } return true } func (this *RoleRush) Save() { this.SetDirty(false) util.DebugF("uid=%v RoleDraw save...", this.role.GetUUid()) saveMsg := &serverproto.SSRoleRushDataSaveReq{ RoleRush: &serverproto.RoleRush{}, } saveMsg.RoleRush.RushSkill = this.rushSkill this.role.SendDb(saveMsg) } func (this *RoleRush) CopyData(draw *serverproto.RoleDraw) { } func (this *RoleRush) OnlineGetRushReward(ackMsg *serverproto.SSGetRushRankRewardAck) { if ackMsg == nil { return } for _, reward := range ackMsg.RewardList { for _, data := range reward.RankReward { //没有奖励,返回 if len(data.RewardList) <= 0 { continue } bRet := serverproto.ErrorCode_ERROR_OK if reward.RushType == model.Rush_Type_Tower { bRet = this.role.GetRoleTower().CheckRankReward(reward.FinishRound) } else if reward.RushType == model.Rush_Type_Arena { bRet = this.role.GetRoleArena().CheckRankReward(reward.FinishRound) } else if reward.RushType == model.Rush_Type_Map { bRet = this.role.GetRoleBattle().CheckRankReward(reward.FinishRound) } else if reward.RushType == model.Rush_Type_Pet { bRet = this.role.GetRolePet().CheckRankReward(reward.FinishRound) } else { bRet = this.CheckRushRankReward(reward.RushType, reward.FinishRound) } if bRet != serverproto.ErrorCode_ERROR_OK { continue } mailCfgId := model.GlobalMailIdRushTower mailType := int32(serverproto.MailType_MailType_RushTower) if reward.RushType == model.Rush_Type_Arena { mailCfgId = model.GlobalMailIdRushArena mailType = int32(serverproto.MailType_MailType_RushArena) } else if reward.RushType == model.Rush_Type_Map { mailCfgId = model.GlobalMailIdRushMap mailType = int32(serverproto.MailType_MailType_RushMap) } else if reward.RushType == model.Rush_Type_Pet { mailCfgId = model.GlobalMailRushPetRankReward mailType = int32(serverproto.MailType_MailType_RushPet) } else if reward.RushType == model.Rush_Type_Skill { mailCfgId = model.GlobalMailRushSkillRankReward mailType = int32(serverproto.MailType_MailType_RushSkill) } this.role.AddMail1(mailCfgId, mailType, data.RewardList, data.MailParamList, "", "") if reward.RushType == model.Rush_Type_Tower { this.role.GetRoleTower().SetRankReward(reward.FinishRound) } else if reward.RushType == model.Rush_Type_Arena { this.role.GetRoleArena().SetRankReward(reward.FinishRound) } else if reward.RushType == model.Rush_Type_Map { this.role.GetRoleBattle().SetRankReward(reward.FinishRound) } else if reward.RushType == model.Rush_Type_Pet { this.role.GetRolePet().SetRankReward(reward.FinishRound) } else { this.SetRushRankReward(reward.RushType, reward.FinishRound) } } } } //===================================================== 技能冲榜功能 ===================================================== func (this *RoleRush) OnlineRush() { rewardReq := &serverproto.SSGetRushRankRewardReq{ Uid: this.role.GetUUid(), } if this.rushSkill != nil { rewardReq.RushData = append(rewardReq.RushData, &serverproto.KeyValueType{ Key: model.Rush_Type_Skill, Value: this.rushSkill.RankReward, }) } if this.role.GetRolePet() != nil && this.role.GetRolePet().rushPet != nil { rewardReq.RushData = append(rewardReq.RushData, &serverproto.KeyValueType{ Key: model.Rush_Type_Pet, Value: this.role.GetRolePet().rushPet.RankReward, }) } if this.role.GetRoleTower() != nil { rewardReq.RushData = append(rewardReq.RushData, &serverproto.KeyValueType{ Key: model.Rush_Type_Tower, Value: this.role.GetRoleTower().RankRewardRound, }) } if this.role.GetRoleBattle() != nil && this.role.GetRoleBattle().rushMap != nil { rewardReq.RushData = append(rewardReq.RushData, &serverproto.KeyValueType{ Key: model.Rush_Type_Map, Value: this.role.GetRoleBattle().rushMap.RankReward, }) } if this.role.GetRoleArena() != nil && this.role.GetRoleArena().arenaInfo.RushArena != nil && this.role.GetRoleArena().arenaInfo != nil { rewardReq.RushData = append(rewardReq.RushData, &serverproto.KeyValueType{ Key: model.Rush_Type_Arena, Value: this.role.GetRoleArena().arenaInfo.RushArena.RankReward, }) } this.role.SendRank(rewardReq) } func (this *RoleRush) OnlineGetRushBaseReward(rushType int32, rewardRound int32) { if rushType == model.Rush_Type_Skill { this.OnlineGetRushSkillBaseReward(rewardRound) } } func (this *RoleRush) OnlineGetRushSkillBaseReward(rewardRound int32) { if this.rushSkill == nil || rewardRound <= 0 { return } if this.rushSkill.ScoreRewardFlag < rewardRound { var addItemList = map[int32]int32{} model.GetRushActivityBaseReward(this.rushSkill.RushRound, model.Rush_Type_Skill, int32(this.rushSkill.TotalScore), addItemList) if len(addItemList) > 0 { this.role.AddMail(model.GlobalMailRushSkillBaseReward, serverproto.MailType_MailType_RushSkill, addItemList, []int32{int32(this.rushSkill.TotalScore)}, "", "") } this.rushSkill.ScoreRewardFlag = rewardRound this.rushSkill.TotalScore = 0 this.SetDirty(true) } else { this.rushSkill.TotalScore = 0 this.SetDirty(true) } } func (this *RoleRush) OnlineProcess() { if this.rushSkill == nil { return } //上线处理下,有可能这个人没有参加过。 this.OnRushSkillScoreChange() // 上线请求下冲榜是否有历史奖励可以领取 if this.rushSkill != nil { if this.rushSkill.RushRound != 0 && this.rushSkill.RushRound > this.rushSkill.ScoreRewardFlag { reqMsg := &serverproto.SSGetRushBaseRewardReq{} reqMsg.Uid = this.role.GetUUid() reqMsg.RushType = model.Rush_Type_Skill reqMsg.RushRound = this.rushSkill.RushRound this.role.SendRank(reqMsg) } } this.OnlineRush() } func (this *RoleRush) OnRushDataChange(rushType int32) { reqMsg := &serverproto.SSRushDataChangeReq{} reqMsg.Uid = this.role.GetUUid() reqMsg.RushType = rushType this.role.SendRank(reqMsg) } //发送到rank服务器验证 func (this *RoleRush) OnRushSkillScoreChange() { reqMsg := &serverproto.SSRushDataChangeReq{} reqMsg.Uid = this.role.GetUUid() reqMsg.RushType = model.Rush_Type_Skill this.role.SendRank(reqMsg) } func (this *RoleRush) AddRushScore(rushType int32, curRound int32) { if rushType == model.Rush_Type_Skill { this.AddRushSkillScore(curRound) return } } func (this *RoleRush) AddRushSkillScore(curRound int32) { if this.rushSkill == nil { this.rushSkill = &serverproto.RushSkill{} this.SetDirty(true) } if curRound == 0 { return } if curRound != this.rushSkill.RushRound { this.rushSkill.RushRound = curRound this.rushSkill.TotalScore = 0 } //发送到rank reqMsg := &serverproto.SSRushSkillInfoChangeNtf{} reqMsg.TotalScore = this.role.GetRoleBase().roleBase.RepressSkillPvpVal if reqMsg.TotalScore <= 0 { return } if uint32(reqMsg.TotalScore) >= this.rushSkill.TotalScore { this.rushSkill.TotalScore = uint32(reqMsg.TotalScore) reqMsg.Uid = this.role.GetUUid() this.role.SendRank(reqMsg) } this.SetDirty(true) } func (this *RoleRush) GetBaseReward(ackMsg *serverproto.SCRushActivityRewardAck, rushType int32, rushRound int32) serverproto.ErrorCode { if rushType == model.Rush_Type_Skill { return this.GetBaseScoreReward(ackMsg, rushRound) } return serverproto.ErrorCode_ERROR_FAIL } func (this *RoleRush) GetBaseScoreReward(ackMsg *serverproto.SCRushActivityRewardAck, rushRound int32) serverproto.ErrorCode { if ackMsg == nil { return serverproto.ErrorCode_ERROR_FAIL } if this.rushSkill == nil { this.rushSkill = &serverproto.RushSkill{} this.SetDirty(true) } if this.rushSkill.ScoreRewardFlag >= rushRound { return serverproto.ErrorCode_ERROR_RUSH_ACTIVITY_REWARD_FINISH } var addItemList = map[int32]int32{} model.GetRushActivityBaseReward(this.rushSkill.RushRound, model.Rush_Type_Skill, int32(this.rushSkill.TotalScore), addItemList) if len(addItemList) <= 0 { return serverproto.ErrorCode_ERROR_FAIL } for key, value := range addItemList { ackMsg.ItemList = append(ackMsg.ItemList, &serverproto.KeyValueType{ Key: key, Value: value, }) } this.role.AddItemList(addItemList, AddFrom_RushSkill, true) this.rushSkill.ScoreRewardFlag = rushRound this.SetDirty(true) return serverproto.ErrorCode_ERROR_OK } func (this *RoleRush) GetRushRankReward(ssAck *serverproto.SSGetRushRewardAck) serverproto.ErrorCode { if ssAck.RushType == model.Rush_Type_Skill { return this.GetRushSkillRankReward(ssAck) } return serverproto.ErrorCode_ERROR_FAIL } func (this *RoleRush) GetRushSkillRankReward(ssAck *serverproto.SSGetRushRewardAck) serverproto.ErrorCode { if ssAck == nil { return serverproto.ErrorCode_ERROR_FAIL } if this.rushSkill == nil { this.rushSkill = &serverproto.RushSkill{} this.SetDirty(true) } if this.rushSkill.RankReward >= ssAck.RushRound { return serverproto.ErrorCode_ERROR_RUSH_ACTIVITY_REWARD_FINISH } var addItemList = map[int32]int32{} for _, data := range ssAck.ItemList { addItemList[data.Key] += data.Value } this.role.AddItemList(addItemList, AddFrom_RushSkill, true) this.rushSkill.RankReward = ssAck.RushRound this.SetDirty(true) return serverproto.ErrorCode_ERROR_OK } func (this *RoleRush) GetRushInfo(ackMsg *serverproto.SCRushActivityAck, curRound int32) { if ackMsg.RushType == model.Rush_Type_Skill { this.GetRushSkillInfo(ackMsg, curRound) return } } func (this *RoleRush) GetRushSkillInfo(ackMsg *serverproto.SCRushActivityAck, curRound int32) { if ackMsg == nil { return } if this.rushSkill == nil { this.rushSkill = &serverproto.RushSkill{} this.SetDirty(true) } // ackMsg.SelfScore = this.rushSkill.TotalScore ackMsg.RankReward = false if this.rushSkill.RankReward == curRound { ackMsg.RankReward = true } ackMsg.ChallengReward = false if this.rushSkill.ScoreRewardFlag >= curRound { ackMsg.ChallengReward = true } } func (this *RoleRush) CheckRushRankReward(rushType int32, finishRound int32) serverproto.ErrorCode { if model.Rush_Type_Skill == rushType { return this.CheckSkillRankReward(finishRound) } return serverproto.ErrorCode_ERROR_FAIL } func (this *RoleRush) CheckSkillRankReward(finishRound int32) serverproto.ErrorCode { if this.rushSkill == nil { this.rushSkill = &serverproto.RushSkill{} this.SetDirty(true) } if this.rushSkill.RankReward >= finishRound { return serverproto.ErrorCode_ERROR_FAIL } return serverproto.ErrorCode_ERROR_OK } func (this *RoleRush) SetRushRankReward(rushType int32, finishRound int32) { if model.Rush_Type_Skill == rushType { this.SetRankReward(finishRound) } } func (this *RoleRush) SetRankReward(finishRound int32) { if this.rushSkill == nil { this.rushSkill = &serverproto.RushSkill{} this.SetDirty(true) } this.rushSkill.RankReward = finishRound this.SetDirty(true) } func (this *RoleRush) GetFightCountMailReward(rushRound int32) { if this.rushSkill == nil { this.rushSkill = &serverproto.RushSkill{} this.SetDirty(true) } if this.rushSkill.ScoreRewardFlag < rushRound { var addItemList = map[int32]int32{} model.GetRushActivityBaseReward(this.rushSkill.RushRound, model.Rush_Type_Skill, int32(this.rushSkill.TotalScore), addItemList) if len(addItemList) > 0 { this.role.AddMail(model.GlobalMailRushSkillBaseReward, serverproto.MailType_MailType_RushSkill, addItemList, []int32{int32(this.rushSkill.TotalScore)}, "", "") } this.rushSkill.ScoreRewardFlag = rushRound this.rushSkill.TotalScore = 0 this.SetDirty(true) } }