package model import ( "rocommon/util" "roserver/baseserver/model" "roserver/serverproto" ) const ( MAX_APPLY_COUNT = 5 Req_Gap_Time = 500 ) type RoleGuild struct { SaveObject roleGuild *serverproto.RoleGuild recommendID int32 //客户端请求次数 //公会战临时数据 guildBattlePosIdx int32 guildBattleFightUid uint64 lastReqTime uint64 challengePosIdxTime uint64 //以免端时间内发起多次挑战 } func newRoleGuild(r *Role) *RoleGuild { roleGuild := &RoleGuild{ SaveObject: SaveObject{ role: r, }, roleGuild: &serverproto.RoleGuild{ GuildActive: &serverproto.GuildActiveInfo{}, GuildApply: &serverproto.RoleApplyInfo{}, GuildBattle: &serverproto.GuildBattle{}, DemonInfo: &serverproto.DemonInfo{}, }, recommendID: 0, lastReqTime: 0, } return roleGuild } // func (this *RoleGuild) Load(msg interface{}) bool { proRole := msg.(*serverproto.Role) this.roleGuild = proRole.RoleGuild if this.roleGuild.GuildActive == nil { this.roleGuild.GuildActive = &serverproto.GuildActiveInfo{} } if this.roleGuild.GuildApply == nil { this.roleGuild.GuildApply = &serverproto.RoleApplyInfo{} } if this.roleGuild.GuildBattle == nil { this.roleGuild.GuildBattle = &serverproto.GuildBattle{} } if this.roleGuild.DemonInfo == nil { this.roleGuild.DemonInfo = &serverproto.DemonInfo{} } // this.GuildBattleOnline() return true } func (this *RoleGuild) GetGuildInfo() *serverproto.RoleGuild { return this.roleGuild } func (this *RoleGuild) Save() { this.SetDirty(false) util.DebugF("uid=%v RoleGuild save...", this.role.GetUUid()) saveMsg := &serverproto.SSGuildDataSaveReq{ Guild: &serverproto.RoleGuild{}, } saveMsg.Guild = this.roleGuild this.role.SendDb(saveMsg) } func (this *RoleGuild) DailyReset(notify bool) { globalData, ok := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Guild_Online_GuildActive)] if !ok { util.ErrorF("uid=%v RoleGuild DailyReset...", this.role.GetUUid()) return } if this.roleGuild.DemonInfo != nil { this.roleGuild.DemonInfo.UseFightCount = 0 this.roleGuild.DemonInfo.FreeFightCount = 0 this.roleGuild.DemonInfo.BuyFightCount = 0 this.SetDirty(true) } if this.roleGuild.GuildActive.DayActiveValue > 0 || this.roleGuild.QuitNum > 0 { //清除昨日公会活跃度获取值 this.roleGuild.GuildActive.DayActiveValue = 0 //每日重置退出公会次数 this.roleGuild.QuitNum = 0 this.SetDirty(true) } //每日活跃值 if this.AddGuildActivity(globalData.IVal) { this.SetDirty(true) } if this.ClearBossFightCount() { this.SetDirty(true) } //通知客户端 if notify == true { this.OnQuitGuildInfoChange() } } //普通boss单独清除 func (this *RoleGuild) ClearBossFightCount() bool { ret := false if this.roleGuild.BossFight == nil || len(this.roleGuild.BossFight) <= 0 { return ret } for _, data := range this.roleGuild.BossFight { bossType := this.GetBossType(data.BossId) if bossType == 1 { // data.BossId = 0 data.FightCount = 0 ret = true } } return ret } func (this *RoleGuild) GetRecommendCount() int32 { count := this.recommendID%3 + 1 this.recommendID++ return count } func (this *RoleGuild) GetNextJoin() int64 { return this.roleGuild.NextJoin } func (this *RoleGuild) OnQuitGuildInfoChange() { ntfMsg := &serverproto.SCQuitGuildCDNtf{} ntfMsg.QuitNum = this.roleGuild.QuitNum ntfMsg.NextJoin = this.roleGuild.NextJoin this.role.ReplayGate(ntfMsg, true) } func (this *RoleGuild) CheckGuildUnlock() serverproto.ErrorCode { globalData, ok := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Guild_System_Unlock)] if !ok { return serverproto.ErrorCode_ERROR_GUILD_CONFIG_NOT_FOUND } if this.role.GetRoleBattle().GetLevelId() < globalData.IVal { return serverproto.ErrorCode_ERROR_GUILD_SYSTEM_LOCKED } return serverproto.ErrorCode_ERROR_OK } //所有申请全部撤销 func (this *RoleGuild) CanBuildGuild(guildName string) serverproto.ErrorCode { if this.roleGuild.GuildId != 0 { return serverproto.ErrorCode_ERROR_GUILD_IN_GUILD } bSensitive := SensitiveUtil.IsMatch(guildName) if bSensitive == true { return serverproto.ErrorCode_ERROR_GUILD_NAME_SENSITIVE } bRet := this.CheckGuildUnlock() if bRet != serverproto.ErrorCode_ERROR_OK { return bRet } //检查道具是否足够 var costItemList = map[int32]int32{} globalData, ok := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Guild_Build_Cost)] if !ok { return serverproto.ErrorCode_ERROR_GUILD_BUILD_ITEM_NOT_ENOUGH } itemId, itemNum := model.Str2Res(globalData.SVal) costItemList[itemId] = itemNum if this.role.CheckResLitNum(costItemList) == false { util.DebugF("uid=%v build_guild error resource not enough!! costItemList=%v", this.role.GetUUid(), costItemList) return serverproto.ErrorCode_ERROR_GUILD_BUILD_ITEM_NOT_ENOUGH } return serverproto.ErrorCode_ERROR_OK } func (this *RoleGuild) DisbandGuild() { this.roleGuild.GuildId = 0 this.roleGuild.GuildName = "" this.SetDirty(true) } func (this *RoleGuild) CheckApply(guildId uint64) serverproto.ErrorCode { if guildId <= 0 { return serverproto.ErrorCode_ERROR_FAIL } bRet := this.CheckGuildUnlock() if bRet != serverproto.ErrorCode_ERROR_OK { return bRet } //判定加入公会冷却时间 if this.roleGuild.NextJoin > int64(util.GetCurrentTime()) { return serverproto.ErrorCode_ERROR_GUILD_LEAVE_GUILD_CD } return serverproto.ErrorCode_ERROR_OK } func (this *RoleGuild) CanQuitGuild() serverproto.ErrorCode { return serverproto.ErrorCode_ERROR_OK } //离开公会 func (this *RoleGuild) QuitGuild() { this.roleGuild.GuildId = 0 this.roleGuild.GuildName = "" this.roleGuild.QuitNum += 1 configCount := len(model.ConvertLeaveGuildTime) if this.roleGuild.QuitNum >= int32(configCount) { cdCount := model.ConvertLeaveGuildTime[int32(configCount)] this.roleGuild.NextJoin = int64(util.GetCurrentTime()) + int64(cdCount)*3600*1000 } else { cdCount := model.ConvertLeaveGuildTime[int32(this.roleGuild.QuitNum)] this.roleGuild.NextJoin = int64(util.GetCurrentTime()) + int64(cdCount)*3600*1000 } this.OnQuitGuildInfoChange() this.SetDirty(true) } func (this *RoleGuild) BuildGuildSuccess(guildBrief *serverproto.GuildBrief) { if guildBrief == nil { return } globalData, ok := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Guild_Build_Cost)] if !ok { return } var costItemList = map[int32]int32{} itemId, itemNum := model.Str2Res(globalData.SVal) costItemList[itemId] = itemNum if this.role.CheckResLitNum(costItemList) == false { util.DebugF("uid=%v build_guild error resource not enough!! costItemList=%v", this.role.GetUUid(), costItemList) return } this.role.DelItemList(costItemList, AddItemST{AddFrom: AddFrom_Guild}) //扣除道具 this.roleGuild.GuildId = guildBrief.GuildId this.roleGuild.GuildName = guildBrief.GuildName this.SetDirty(true) //Task TaskMagCheck(this.role, serverproto.TaskType_Guild_Join_Count, 1) } func (this *RoleGuild) SetOnlineGuildInfo(guildId uint64, name string) { //Task if guildId > 0 && this.roleGuild.GuildId != guildId { TaskMagCheck(this.role, serverproto.TaskType_Guild_Join_Count, 1) } if guildId != 0 && this.roleGuild.GuildId != guildId { globalData, ok := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Guild_Elite_Boss_FightCD)] if ok { this.roleGuild.EliteBossCd = util.GetCurrentTime() + uint64(globalData.IVal)*60*1000 } } if guildId != this.roleGuild.GuildId || (this.roleGuild.GuildId == guildId && this.roleGuild.GuildName != name) { this.roleGuild.GuildId = guildId this.roleGuild.GuildName = name this.SetDirty(true) } } func (this *RoleGuild) AddGuildActivity(activePoint int32) bool { if activePoint == 0 || this.roleGuild.GuildId == 0 { return false } globalData, ok := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Guild_Personal_Active)] if !ok { return false } if this.roleGuild.GuildActive == nil { this.roleGuild.GuildActive = &serverproto.GuildActiveInfo{} } if this.roleGuild.GuildActive.DayActiveValue >= globalData.IVal { return false } oldActive := this.roleGuild.GuildActive.DayActiveValue this.roleGuild.GuildActive.DayActiveValue += activePoint if this.roleGuild.GuildActive.DayActiveValue > globalData.IVal { this.roleGuild.GuildActive.DayActiveValue = globalData.IVal } addActive := this.roleGuild.GuildActive.DayActiveValue - oldActive this.roleGuild.GuildActive.ActiveValue += uint32(addActive) //判定活跃度上限 ntfMsg := &serverproto.SSGuildOnAddActivityNtf{} ntfMsg.Uid = this.role.GetUUid() ntfMsg.GuildId = this.role.GetRoleGuildId() ntfMsg.Activity = activePoint this.role.SendGuild(ntfMsg) this.SetDirty(true) return true } func (this *RoleGuild) GMAddGuildActivity(activePoint int32) { if activePoint == 0 { return } this.roleGuild.GuildActive.DayActiveValue += activePoint this.roleGuild.GuildActive.ActiveValue += uint32(activePoint) //判定活跃度上限 ntfMsg := &serverproto.SSGuildOnAddActivityNtf{} ntfMsg.Uid = this.role.GetUUid() ntfMsg.GuildId = this.role.GetRoleGuildId() ntfMsg.Activity = activePoint this.role.SendGuild(ntfMsg) } func (this *RoleGuild) ClearGuildApplyCD() { this.roleGuild.QuitNum = 0 this.roleGuild.NextJoin = 0 this.OnQuitGuildInfoChange() this.SetDirty(true) } func (this *RoleGuild) CheckBossFight(bossId uint32, damage uint32, fightTime uint32) serverproto.ErrorCode { //校验战斗时长 cfg, ok := serverproto.GuildBossCfgLoader[int32(bossId)] if !ok { return serverproto.ErrorCode_ERROR_GUILD_CONFIG_NOT_FOUND } if fightTime > uint32(cfg.BattleTime) { return serverproto.ErrorCode_ERROR_FAIL } for _, data := range this.roleGuild.BossFight { if data.BossId == bossId { bossType := this.GetBossType(data.BossId) bossChallenge := cfg.Challenge if bossType == 1 { vipGuildBoss := this.role.GetRoleBase().GetVipData(model.Vip_System_GuildHunt) if vipGuildBoss > 0 { bossChallenge += vipGuildBoss } } else if bossType == 2 { if this.roleGuild.EliteBossCd > util.GetCurrentTime() { return serverproto.ErrorCode_ERROR_GUILD_BOSS_FIGHT_CD } } if data.FightCount >= bossChallenge { return serverproto.ErrorCode_ERROR_GUILD_BOSS_CHALLENGE_MAX } break } } return serverproto.ErrorCode_ERROR_OK } func (this *RoleGuild) GetGuildBossReward(bossId uint32, damage int32) map[int32]int32 { rewardRank, ok := model.ConvertGuildBossRewardRank[int32(bossId)] if !ok { return nil } for _, data := range rewardRank.Reward { if data.MinDam <= damage && damage <= data.MaxDam { bossReward, ok2 := model.ConvertGuildBossReward[data.RewardID] if !ok2 { return nil } return bossReward.RewardList } } return nil } func (this *RoleGuild) GuildBossFightSuccess(msg *serverproto.SCGuildBossChallengeAck) { //校验战斗次数,合法则自增 var bFind = false for _, data := range this.roleGuild.BossFight { if data.BossId == msg.BossId { data.FightCount++ bFind = true break } } if bFind == false { this.roleGuild.BossFight = append(this.roleGuild.BossFight, &serverproto.GuildBossTickTime{ BossId: msg.BossId, FightCount: 1, }) } //给奖励 var addItemList = map[int32]int32{} addItemList = this.GetGuildBossReward(msg.BossId, int32(msg.Damage)) if addItemList != nil && len(addItemList) > 0 { this.role.AddItemList(addItemList, AddFrom_GuildBoss, true) for itemId, itemNum := range addItemList { msg.Reward = append(msg.Reward, &serverproto.KeyValueType{ Key: itemId, Value: itemNum, }) } } this.SetDirty(true) TaskMagCheck(this.role, serverproto.TaskType_Guild_Boss_Normal_Count, 1) } func (this *RoleGuild) SetFightCount(msg *serverproto.SCGuildBossInfoAck) { if len(this.roleGuild.BossFight) <= 0 { return } msg.EliteBossCd = this.roleGuild.EliteBossCd for _, data := range this.roleGuild.BossFight { msg.BossFight = append(msg.BossFight, &serverproto.KeyValueType{ Key: int32(data.BossId), Value: data.FightCount, }) } this.SetDirty(true) } func (this *RoleGuild) GetBossType(bossId uint32) int32 { cfg, ok := serverproto.GuildBossCfgLoader[int32(bossId)] if !ok { return -1 } return cfg.BossType } func (this *RoleGuild) BossRefreshData(ntfMsg *serverproto.SSGuildBossRefreshNtf) { if len(ntfMsg.RefTime) <= 0 || len(ntfMsg.RefTime) > 20 { return } var bChanged = true for _, ntfRef := range ntfMsg.RefTime { if this.GetBossType(ntfRef.BossId) != 2 { continue } var bFind = false for _, roleRef := range this.roleGuild.BossFight { if ntfRef.BossId == roleRef.BossId { bFind = true if ntfRef.RefreshTime != roleRef.RefreshTime { roleRef.RefreshTime = ntfRef.RefreshTime roleRef.FightCount = 0 bChanged = true } } } if bFind == false { this.roleGuild.BossFight = append(this.roleGuild.BossFight, &serverproto.GuildBossTickTime{ BossId: ntfRef.BossId, FightCount: 0, RefreshTime: ntfRef.RefreshTime, }) bChanged = true } } if bChanged == true { this.SetDirty(true) } } func (this *RoleGuild) GetBossFightCount(bossId uint32) int32 { for _, roleRef := range this.roleGuild.BossFight { if roleRef.BossId == bossId { return roleRef.FightCount } } return 0 } func (this *RoleGuild) GuildNameChange(guildId uint64, name string) { if guildId == this.roleGuild.GuildId { this.roleGuild.GuildName = name this.SetDirty(true) } } func (this *RoleGuild) HasBattleCount(msg *serverproto.SSOnlineGuildInfoAck) bool { if msg == nil || len(msg.Boss) <= 0 { return false } for _, bossId := range msg.Boss { bFind := false for _, data := range this.roleGuild.BossFight { if data.BossId == bossId { bFind = true cfg, ok := serverproto.GuildBossCfgLoader[int32(bossId)] if !ok { break } bossType := this.GetBossType(data.BossId) bossChallenge := cfg.Challenge if bossType == 1 { vipGuildBoss := this.role.GetRoleBase().GetVipData(model.Vip_System_GuildHunt) if vipGuildBoss > 0 { bossChallenge += vipGuildBoss } } if data.FightCount >= bossChallenge { break } //只要有1个可以挑战,就返回TRUE return true } } //有可以战斗的boss,但是没有战斗记录,则返回true if bFind == false { return true } } return false } func (this *RoleGuild) GuildBattleBuyChallengeNum(msg *serverproto.CSGuildBattleBuyChallengeReq) { ackMsg := &serverproto.SCGuildBattleBuyChallengeAck{} if msg.GuildBattleIdx > 7 || msg.GuildBattleIdx <= 0 { ackMsg.Error = int32(serverproto.ErrorCode_ERROR_FAIL) this.role.ReplayGate(ackMsg, true) return } var buyCost uint64 = 50 if this.role.GetResNum(int32(serverproto.ResType_Res_Rmb)) < buyCost { ackMsg.Error = int32(this.role.GetResNotice(int32(serverproto.ResType_Res_Rmb))) this.role.ReplayGate(ackMsg, true) return } this.role.DelItem(int32(serverproto.ResType_Res_Rmb), int32(buyCost), AddItemST{AddFrom: AddFrom_GuildBattle}) msg.SelfGuildId = uint64(this.roleGuild.GuildId) this.role.SendGuild(msg) } func (this *RoleGuild) GuildBattleResetReborn(msg *serverproto.CSGuildBattleRebornReq) { ackMsg := &serverproto.SCGuildBattleRebornAck{} if msg.GuildBattleIdx > 7 || msg.GuildBattleIdx <= 0 { ackMsg.Error = int32(serverproto.ErrorCode_ERROR_FAIL) this.role.ReplayGate(ackMsg, true) return } if this.role.GetResNum(int32(serverproto.ResType_Res_Rmb)) < model.GlobalGuildBattleRebornCost { ackMsg.Error = int32(serverproto.ErrorCode_ERROR_RMB_NOT_ENOUGH) this.role.ReplayGate(ackMsg, true) return } msg.SelfGuildId = uint64(this.roleGuild.GuildId) this.role.SendGuild(msg) } func (this *RoleGuild) OnGuildBattleResetReborn(ackMsg *serverproto.SCGuildBattleRebornAck) { if ackMsg.Error == int32(serverproto.ErrorCode_ERROR_OK) { //扣除资源 this.role.DelItem(int32(serverproto.ResType_Res_Rmb), int32(model.GlobalGuildBattleRebornCost), AddItemST{AddFrom: AddFrom_GuildBattle}) } this.role.ReplayGate(ackMsg, true) } func (this *RoleGuild) GuildBattleChallengePre(battleIdx, posIdx int32) serverproto.ErrorCode { if this.roleGuild.GuildId <= 0 { return serverproto.ErrorCode_ERROR_FAIL } nowTime := util.GetTimeMilliseconds() if this.challengePosIdxTime > 0 && (nowTime-this.challengePosIdxTime) < 1*60*1000 { return serverproto.ErrorCode_ERROR_GUILDBATTLE_FIGHTING } this.challengePosIdxTime = nowTime ssMsg := &serverproto.SSGuildBattleChallengeReq{ GuildBattleIdx: battleIdx, PosIdx: posIdx, SelfGuildId: uint64(this.roleGuild.GuildId), } if this.roleGuild.GuildBattle != nil { ssMsg.BuyChallengeNum = this.roleGuild.GuildBattle.ChallengeNum } ssMsg.BfInfo = &serverproto.CommonPlayerBriefInfo{} this.role.GetRoleBriefInfo(ssMsg.BfInfo) ssMsg.CurRmb = this.role.GetResNum(int32(serverproto.ResType_Res_Rmb)) this.role.SendGuild(ssMsg) return serverproto.ErrorCode_ERROR_OK } func (this *RoleGuild) OnGuildBattleChallengePre(ssAckMsg *serverproto.SSGuildBattleChallengeAck) { ackMsg := &serverproto.SCGuildBattleChallengeAck{ Error: ssAckMsg.Error, GuildBattleIdx: ssAckMsg.GuildBattleIdx, PosIdx: ssAckMsg.PosIdx, SelfData: ssAckMsg.SelfData, } if ssAckMsg.UseBuyNum == true { if this.roleGuild.GuildBattle != nil && this.roleGuild.GuildBattle.ChallengeNum > 0 { this.roleGuild.GuildBattle.ChallengeNum-- } else { //打印日志 } } //先购买虚弱,但是无法挑战 //扣除资源(花费金币方式来进行挑战/重置复活虚弱) if ssAckMsg.CostRmb > 0 { this.role.DelItem(int32(serverproto.ResType_Res_Rmb), int32(ssAckMsg.CostRmb), AddItemST{AddFrom: AddFrom_GuildBattle}) } if ackMsg.SelfData != nil { ntfMsg := &serverproto.SCGuildBattleChallengeNtf{ GuildBattleIdx: ssAckMsg.GuildBattleIdx, PosIdx: ssAckMsg.PosIdx, SelfData: ssAckMsg.SelfData, } if this.roleGuild.GuildBattle != nil { ntfMsg.BuyChallengeNum = this.roleGuild.GuildBattle.ChallengeNum } this.role.ReplayGate(ntfMsg, true) } if ssAckMsg.Error == int32(serverproto.ErrorCode_ERROR_OK) { ackMsg.FightInfo = ssAckMsg.FightInfo ackMsg.SelfBuffList = ssAckMsg.SelfBuffList ackMsg.FightBuffList = ssAckMsg.FightBuffList ackMsg.ChallengePosData = ssAckMsg.ChallengePosData this.guildBattlePosIdx = ssAckMsg.PosIdx if ssAckMsg.FightInfo != nil { this.guildBattleFightUid = ssAckMsg.FightInfo.BriefInfo.Uid } else { //重置挑战时间 this.challengePosIdxTime = 0 } } else { //重置挑战时间 this.challengePosIdxTime = 0 } if this.roleGuild.GuildBattle != nil { ackMsg.BuyChallengeNum = this.roleGuild.GuildBattle.ChallengeNum } this.role.ReplayGate(ackMsg, true) } func (this *RoleGuild) GuildBattleChallengeResult(msg *serverproto.CSGuildBattleChallengeResultReq) { msg.SelfGuildId = uint64(this.roleGuild.GuildId) msg.BfInfo = &serverproto.CommonPlayerBriefInfo{} this.role.GetRoleBriefInfo(msg.BfInfo) //reset challenge data this.guildBattlePosIdx = 0 this.guildBattleFightUid = 0 //重置挑战时间 this.challengePosIdxTime = 0 this.role.SendGuild(msg) } func (this *RoleGuild) GuildBattleChallengePint(msg *serverproto.CSGuildBattleChallengePingReq) { if msg.GuildBattleIdx <= 0 || msg.GuildBattleIdx > 7 || this.guildBattlePosIdx != msg.PosIdx { ackMsg := &serverproto.SCGuildBattleChallengePingAck{ Error: int32(serverproto.ErrorCode_ERROR_FAIL), } if this.guildBattlePosIdx != msg.PosIdx { ackMsg.Error = int32(serverproto.ErrorCode_ERROR_GUILDBATTLE_FIGHTING) } this.role.ReplayGate(ackMsg, true) return } this.role.SendGuild(msg) } func (this *RoleGuild) CheckReqTime() bool { curTime := util.GetCurrentTime() if this.lastReqTime != 0 && this.lastReqTime+Req_Gap_Time > curTime { ntfMsg := &serverproto.SCGuildBattleCPRankAck{ Error: int32(serverproto.ErrorCode_ERROR_GUILDBATTLE_OPERATOR_TO_FAST), } this.role.ReplayGate(ntfMsg, true) return false } this.lastReqTime = curTime return true } func (this *RoleGuild) GetGuildBattleRewardRound() int32 { if this.roleGuild != nil && this.roleGuild.GuildBattle != nil { return this.roleGuild.GuildBattle.RewardRound } return 0 } func (this *RoleGuild) SetGuildBattleRewardRound(round int32) { if this.roleGuild != nil && this.roleGuild.GuildBattle != nil { if this.roleGuild.GuildBattle.RewardRound >= round { return } this.roleGuild.GuildBattle.RewardRound = round this.SetDirty(true) } } func (this *RoleGuild) GetGuildBattleMvpRound() int32 { if this.roleGuild != nil && this.roleGuild.GuildBattle != nil { return this.roleGuild.GuildBattle.MvpRewardRound } return 0 } //MvpRewardRound只是用作,减少公会服务器遍历 func (this *RoleGuild) SetGuildBattleMvpRound(round int32) { if this.roleGuild != nil && this.roleGuild.GuildBattle != nil { if this.roleGuild.GuildBattle.MvpRewardRound >= round { return } this.roleGuild.GuildBattle.MvpRewardRound = round this.SetDirty(true) } } func (this *RoleGuild) AddBuyChallengeCount(add bool) { if this.roleGuild != nil && this.roleGuild.GuildBattle != nil { if add == true { this.roleGuild.GuildBattle.ChallengeNum++ } else { this.roleGuild.GuildBattle.ChallengeNum-- } this.SetDirty(true) } } func (this *RoleGuild) RemoveBuyBuffGold(needRes []*serverproto.KeyValueType) { if len(needRes) <= 0 { return } var costItemList = map[int32]int32{} for _, data := range needRes { costItemList[data.Key] = data.Value } if len(costItemList) > 0 { this.role.DelItemList(costItemList, AddItemST{AddFrom: AddFrom_GuildBattle}) } } func (this *RoleGuild) GuildBattleOnline() { if this.roleGuild == nil || this.roleGuild.GuildBattle == nil { return } reqMsg := &serverproto.SSGuildBattleOnlineGetRewardReq{ Uid: this.role.GetUUid(), CurRewardId: this.roleGuild.GuildBattle.RewardRound, MvpRewardId: this.roleGuild.GuildBattle.MvpRewardRound, } this.role.SendGuild(reqMsg) } func (this *RoleGuild) GetBuyChallengeNum() int32 { if this.roleGuild.GuildBattle != nil { return this.roleGuild.GuildBattle.ChallengeNum } return 0 } func (this *RoleGuild) GMSendReward() { reqMsg := &serverproto.SSGuildBattleRewardReq{} this.role.SendGuild(reqMsg) } func (this *RoleGuild) BuyDemonFightCount(buyCount int32) (serverproto.ErrorCode, int32, int32) { if this.roleGuild.DemonInfo == nil { this.roleGuild.DemonInfo = &serverproto.DemonInfo{} } bRet := this.IsInDemonFightTime() if bRet != serverproto.ErrorCode_ERROR_OK { return bRet, 0, 0 } //获取当前公会魔王ID nowTime := util.GetCurrentTimeNow() curWeekDay := nowTime.Weekday() if curWeekDay == 0 { curWeekDay = 7 } demonData, _ := model.GetDemonInfo(int32(curWeekDay), nowTime) if demonData == nil { return serverproto.ErrorCode_ERROR_FAIL, 0, 0 } //检查总购买次数 totalFightCount := this.roleGuild.DemonInfo.BuyFightCount + buyCount if totalFightCount > demonData.BuyChallengeCount { return serverproto.ErrorCode_ERROR_FAIL, 0, 0 } //计算金币消耗 var costItemList = map[int32]int32{} if this.roleGuild.DemonInfo.BuyFightCount >= int32(len(demonData.ChallengePrice))- 1 { data, ok := demonData.ChallengePrice[int32(len(demonData.ChallengePrice)-1)] if !ok { util.DebugF("uid=%v config not Found", this.role.GetUUid()) return serverproto.ErrorCode_ERROR_FAIL, 0, 0 } costItemList[data.Key] += data.Value * buyCount } else { payCount := int32(0) for i := int32(1); i <= buyCount; i++ { curCount := this.roleGuild.DemonInfo.BuyFightCount + i if curCount >= int32(len(demonData.ChallengePrice))-1 { break } payCount = i data, ok := demonData.ChallengePrice[curCount] if !ok { util.DebugF("uid=%v config not Found, buyCount %v", this.role.GetUUid(), curCount) return serverproto.ErrorCode_ERROR_FAIL, 0, 0 } costItemList[data.Key] += data.Value } if payCount < buyCount { leftCount := buyCount - payCount data, ok := demonData.ChallengePrice[int32(len(demonData.ChallengePrice)-1)] if !ok { util.DebugF("uid=%v config not Found", this.role.GetUUid()) return serverproto.ErrorCode_ERROR_FAIL, 0, 0 } costItemList[data.Key] += data.Value * leftCount } } if len(costItemList) <= 0 { return serverproto.ErrorCode_ERROR_FAIL, 0, 0 } if this.role.CheckResLitNum(costItemList) == false { util.DebugF("uid=%v build_guild error resource not enough!! costItemList=%v", this.role.GetUUid(), costItemList) return serverproto.ErrorCode_ERROR_FAIL, 0, 0 } this.role.DelItemList(costItemList, AddItemST{AddFrom: AddFrom_GuildDemon}) this.roleGuild.DemonInfo.BuyFightCount += buyCount this.SetDirty(true) leftUseCount := this.roleGuild.DemonInfo.BuyFightCount + demonData.ChallengeCount - this.roleGuild.DemonInfo.UseFightCount leftBuyCont := demonData.BuyChallengeCount - this.roleGuild.DemonInfo.BuyFightCount if leftBuyCont < 0 { leftBuyCont = 0 } if leftUseCount < 0 { leftUseCount = 0 } return serverproto.ErrorCode_ERROR_OK, leftUseCount, leftBuyCont } func (this *RoleGuild) GetGuildDemonInfo(ackMsg *serverproto.SCGuildDemonInfoAck) { if ackMsg == nil { return } nowTime := util.GetCurrentTimeNow() curWeekDay := nowTime.Weekday() if curWeekDay == 0 { curWeekDay = 7 } demonData, _ := model.GetDemonInfo(int32(curWeekDay), nowTime) if demonData == nil { return } ackMsg.LeftFightCount = demonData.ChallengeCount + this.roleGuild.DemonInfo.BuyFightCount - this.roleGuild.DemonInfo.UseFightCount ackMsg.LeftBuyCount = demonData.BuyChallengeCount - this.roleGuild.DemonInfo.BuyFightCount } func (this *RoleGuild) OnGuildDemonFight(refreshTime uint64, freeFightCount int32, ackMsg *serverproto.SCGuildDemonFightAck) { if ackMsg == nil || this.roleGuild.DemonInfo == nil { return } if ackMsg.Error != int32(serverproto.ErrorCode_ERROR_OK) { if this.roleGuild.DemonInfo.UseFightCount > 0 { this.roleGuild.DemonInfo.UseFightCount-- } return } this.roleGuild.DemonInfo.RefreshTime = refreshTime this.roleGuild.DemonInfo.LastFightTime =util.GetCurrentTime() this.SetDirty(true) demonData := model.GetDemonDataByConfigId(ackMsg.DemonId) if demonData == nil || len(demonData.BaseReward) <= 0 { util.ErrorF("get demon reward config not found uid:%v, demon:%v", this.role.GetUUid(), ackMsg.DemonId) return } //总共战斗次数 totalFightCount := this.roleGuild.DemonInfo.BuyFightCount + demonData.ChallengeCount ackMsg.FightCount = totalFightCount - this.roleGuild.DemonInfo.UseFightCount this.role.AddItemList(demonData.BaseReward, AddFrom_GuildDemon, true) for itemId, itemNum := range demonData.BaseReward { ackMsg.BaseReward = append(ackMsg.BaseReward, &serverproto.KeyValueType{ Key: itemId, Value: itemNum, }) } } func (this *RoleGuild) OnlineAddGuildDemonReward(ntfMsg *serverproto.SSGuildDemonOnlineGetRewardNtf) { if ntfMsg == nil || this.roleGuild.DemonInfo == nil{ return } if len(ntfMsg.RewardList) > 0 { this.role.AddMail1(model.GlobalMailGuildDemonReward, int32(serverproto.MailType_MailType_GuildDemon), ntfMsg.RewardList, []int32{ntfMsg.DemonId}, "", "") } this.roleGuild.DemonInfo = &serverproto.DemonInfo{} this.SetDirty(true) } func (this *RoleGuild) GetDemonFightTime () uint64 { if this.roleGuild.DemonInfo == nil { return 0 } if this.roleGuild.DemonInfo.LastFightTime != 0 { isReset := model.IsDailyResetHour5(this.roleGuild.DemonInfo.LastFightTime) if isReset == false { //表示同一天 demonData := model.GetDemonInfoByTimeStamp(this.roleGuild.DemonInfo.LastFightTime) if demonData == nil { return 0 } //同一天,ID不一样,说明做过更新 if demonData.DemonId == int32(this.roleGuild.DemonInfo.RefreshTime) { this.roleGuild.DemonInfo.RefreshTime = uint64(demonData.DemonId) } return 0 } } else { nowTime := util.GetCurrentTimeNow() curWeekDay := nowTime.Weekday() if curWeekDay == 0 { curWeekDay = 7 } demonData, _ := model.GetDemonInfo(int32(curWeekDay), nowTime) if demonData == nil { return 0 } if demonData.DemonId == int32(this.roleGuild.DemonInfo.RefreshTime) { return 0 } } return this.roleGuild.DemonInfo.RefreshTime } func (this *RoleGuild) CheckDemonChallenge() serverproto.ErrorCode{ if this.roleGuild.DemonInfo == nil { return serverproto.ErrorCode_ERROR_FAIL } bRet := this.IsInDemonFightTime() if bRet != serverproto.ErrorCode_ERROR_OK { return bRet } nowTime := util.GetCurrentTimeNow() curWeekDay := nowTime.Weekday() if curWeekDay == 0 { curWeekDay = 7 } demonData, _ := model.GetDemonInfo(int32(curWeekDay), nowTime) if demonData == nil { return serverproto.ErrorCode_ERROR_FAIL } //挑战次数不够 if this.roleGuild.DemonInfo.BuyFightCount + demonData.ChallengeCount <= this.roleGuild.DemonInfo.UseFightCount { return serverproto.ErrorCode_ERROR_FAIL } this.roleGuild.DemonInfo.UseFightCount += 1 this.SetDirty(true) return serverproto.ErrorCode_ERROR_OK } //是否在魔王战斗时间 func (this *RoleGuild) IsInDemonFightTime() serverproto.ErrorCode { nowTime := util.GetCurrentTimeNow() //凌晨4.30 到 5点前 nowMinut := nowTime.Minute() if nowTime.Hour() == 4 && 30 <= nowMinut && nowMinut<= 59 { return serverproto.ErrorCode_ERROR_GUILDDEMON_NOT_IN_CHANLLENGE_TIME } return serverproto.ErrorCode_ERROR_OK } func (this *RoleGuild) AddGuildDemonReward(rewardList []*serverproto.KeyValueType, msg *serverproto.SSGuildDemonRewardNtf) { if msg == nil || this.roleGuild == nil || this.roleGuild.DemonInfo == nil{ return } if this.roleGuild.DemonInfo.RefreshTime == 0 { util.ErrorF("[AddGuildDemonReward]guild demon reward error") return } this.role.AddMail1(model.GlobalMailGuildDemonReward, int32(serverproto.MailType_MailType_GuildDemon), rewardList, []int32{msg.DemonId}, "", "") this.roleGuild.DemonInfo.RefreshTime = 0 this.SetDirty(true) } func (this *RoleGuild) SendGuildDemonBroadCast(demonId int32, guildName string, rewardLevel int32) { this.role.AddSystemMessage(SystemmessageType_GuildDemon, AddSystemMsg{ParamId: demonId, ParaStr: guildName, ParamList: []int32{rewardLevel}}) }