| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038 |
- 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}})
- }
|