package data import ( "f1-game/internal/constant" "f1-game/internal/enum" "f1-game/internal/extend/math" "f1-game/internal/extend/rand" "f1-game/internal/extend/utils" "f1-game/internal/types" "unicode/utf8" ctime "github.com/cherry-game/cherry/extend/time" ) var ( mapRelocateCooldown int64 // 迁城冷却时间 mapCityBaseCooldown int64 // 建造主城地基冷却时间 mapResSnatchRatio float64 // 资源掠夺比例 ) func (p *constConfig) OnAfterLoad(_ bool) { mapRelocateCooldown = p.MapRelocateCooldown * ctime.MillisecondsPerMinute mapCityBaseCooldown = p.MapCityBaseCooldown * ctime.MillisecondsPerMinute mapResSnatchRatio = float64(p.MapResSnatchRatio) / constant.RatioBase } // CalEquipEnhanceAddProb 计算装备强化增加概率 // @Return 增加的概率, 消耗的MO币 func (p *constConfig) CalEquipEnhanceAddProb(curProb int32, curAssetNum int64) (int32, types.Assets) { if curProb >= constant.RatioBase || curAssetNum <= 0 { return 0, nil } var ( addProb int32 costMoCoin int64 ) // 最多使用MO币增加的次数 for range p.EquipEnhanceMOCoinTimes { // 到达最大概率 if addProb+curProb >= constant.RatioBase { break } // 没有足够的MO币 if costMoCoin+p.EquipEnhanceMOCoinCost > curAssetNum { break } addProb += p.EquipEnhanceMOCoinProb costMoCoin += p.EquipEnhanceAddProbCost.Num } if costMoCoin <= 0 { return 0, nil } costs := types.Assets{} costs.Add(p.EquipEnhanceAddProbCost.ID, costMoCoin) return addProb, costs } // IsSpecialSkillHit 是否命中特殊技能 func (p *constConfig) IsSpecialSkillHit() bool { return rand.RangeFloat(0.0, constant.RatioBase) <= p.EquipSpecailSkillProb } // 检测联盟名称长度是否符合 func (p *constConfig) CheckLeagueNameLen(leagueName string) bool { return utils.CheckStrLen(leagueName, p.LeagueNameLimit) } // 检测联盟简称长度是否符合 func (p *constConfig) CheckLeagueAbbNameLen(leagueAbbName string) bool { return utils.CheckStrLen(leagueAbbName, p.LeagueAbbNameLimit) } // 退出联盟CD检测 func (p *constConfig) CheckLeagueQuitCD(quitTime int64) bool { return quitTime+p.LeagueQuitCD > ctime.Now().ToSecond() } // 计算补兵消耗 func (p *constConfig) GetAddTroopsCost(addTroopsNum int32) types.Assets { if addTroopsNum < 0 { return nil } costs := types.Assets{} for _, asset := range p.TeamConscriptionCost { costs.Add(asset.ID, int64(addTroopsNum)*asset.Num) } return costs } // GetMapOccupyWaitTime 获取地图占领等待时间 func (p *constConfig) GetMapOccupyWaitTime() int64 { if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapOccupyWaitTime); ok { return value } return p.MapOccupyWaitTime * 1000 } // GetMapDiscardWaitTime 获取地图放弃等待时间 func (p *constConfig) GetMapDiscardWaitTime() int64 { if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapDiscardWaitTime); ok { return value } return p.MapDiscardWaitTime * 1000 } // GetMapSiegeWaitTime 获取攻城等待间隔 func (p *constConfig) GetMapSiegeWaitTime() int64 { if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapSiegeWaitTime); ok { return value } return p.MapSiegeWaitTime * 1000 } func (p *constConfig) GetMapSnatchWaitTime() int64 { if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapSnatchWaitTime); ok { return value } return p.MapSnatchWaitTime * 1000 } // 获取恢复一点体力所需的秒数 func (p *constConfig) GetRecoverOneEnergyNeedTime() int64 { return p.HeroEnergyAddInterval / int64(p.HeroEnergyAddValue) } func (p *constConfig) GetMapRelocateCooldown() int64 { if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapRelocateCooldown); ok { return value } return mapRelocateCooldown } func (p *constConfig) GetMapCityBaseCooldown() int64 { if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapCityBaseCooldown); ok { return value } return mapCityBaseCooldown } func (p *constConfig) GetMapResSnatchRatio() float64 { return mapResSnatchRatio } func (p *constConfig) GetMapComebackCoolDown() int64 { if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapComebackCooldown); ok { return value } return p.SelfStateComebackCoolDown * ctime.MillisecondsPerSecond } func (p *constConfig) GetMapRechooseComebackCoolDown() int64 { if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapRechooseComebackCooldown); ok { return value } return p.ChooseStateComebackCoolDown * ctime.MillisecondsPerSecond } // 通过联盟邮件类型获取邮件上限值 func (p *constConfig) GetLeagueMailLimit(mailType int32) int32 { switch mailType { case enum.MailType_Decree: return p.LeagueDecreeMailLimit case enum.MailType_Union: return p.LeagueUnionMailLimit case enum.MailType_Command: return p.LeagueCommandMailLimit default: return 0 } } // 检测玩家地图标记标题是否合法 标题可为空 func (p *constConfig) CheckMapMarkTitle(title string) bool { if len(title) <= 0 { return true } return utils.CheckStrLen(title, p.MapMarkTitleLimit) } // 检测联盟地图标记标题是否合法 不能为空 func (p *constConfig) CheckLeagueMapMarkTitle(title string) bool { return utils.CheckStrLen(title, p.LeagueMapMarkTitleLimit) } // 检测联盟地图标记描述是否合法 可以为空 func (p *constConfig) CheckLeagueMapMarkDesc(desc string) bool { if len(desc) <= 0 { return true } return utils.CheckStrLen(desc, p.LeagueMapMarkDescLimit) } func (p *constConfig) CheckPlayerNameLen(name string) bool { nameLen := int32(utf8.RuneCountInString(name)) if nameLen < p.PlayerNameMinLength || nameLen > p.PlayerNameMaxLength { return false } return true } func (p *constConfig) CheckPlayerDescLen(desc string) bool { descLen := utf8.RuneCountInString(desc) return descLen > p.PlayerDescLenLimit } func (p *constConfig) GetLeagueResidenceBackCost() types.Assets { costs := types.Assets{} costs.Add(p.LeagueResidenceBackCost.ID, p.LeagueResidenceBackCost.Num) return costs } func (p *constConfig) GetMapScoutMarchTime() int64 { return ctime.Now().ToMillisecond() + p.MapScoutMarchTime*ctime.MillisecondsPerSecond } func (p *constConfig) GetMapScoutTime(startTime int64) int64 { return startTime + p.MapScoutTime*ctime.MillisecondsPerSecond } func (p *constConfig) GetMapReinforcePrepareTime() int64 { if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapReinforcePrepareTime); ok { return value } return p.ReinforcePrepareTime * 1000 } func (p *constConfig) GetMapReinforceEffectTime() int64 { if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapReinforceEffectTime); ok { return value } return p.ReinforceTime * 1000 } func (p *constConfig) GetMapReinforceCooldown() int64 { if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapReinforceCooldown); ok { return value } return p.ReinforceCoolDown * 1000 } func (p *constConfig) GetEquipRandomCraftCost(craftNum int32) types.Assets { var ( num = int64(craftNum) costs = types.Assets{} ) for _, cost := range p.EquipRandomCraftCost { costs.Add(cost.ID, num*cost.Num) } return costs } func (p *constConfig) GetBeginerInvincibleTime() int64 { if value, ok := GameDebug.GetDebugValue(constant.GameDebug_BeginerInvincibleTime); ok { return value } return p.BeginerInvincibleTime * ctime.MillisecondsPerMinute } func (p *constConfig) GetComebackInvincibleTime() int64 { if value, ok := GameDebug.GetDebugValue(constant.GameDebug_ComebackInvincibleTime); ok { return value } return p.ComebackInvincibleTime * ctime.MillisecondsPerMinute } func (p *constConfig) GetResOccupyInvincibleTime() int64 { if value, ok := GameDebug.GetDebugValue(constant.GameDebug_ResOccupyInvincibleTime); ok { return value } return p.MapResProtectTime * ctime.MillisecondsPerSecond } func (p *constConfig) GetHeroInjureTime() int64 { if value, ok := GameDebug.GetDebugValue(constant.GameDebug_HeroInjureTime); ok { return value } return p.HeroInjureTime } // 获得帝国晶矿转联盟贡献 func (p *constConfig) CalCrystalMineToLeagueCon(addCrystalMine int64) int64 { return p.CalValueToNum(addCrystalMine, p.CrystalMineToConRatio) } // 攻城值转联盟贡献 func (p *constConfig) CalSiegeToLeagueCon(siegeValue int64) int64 { return p.CalValueToNum(siegeValue, p.TileSiegeToConRatio) } // 城建声望转联盟贡献 func (p *constConfig) CalFacilityToLeagueCon(diffPrestige int64) int64 { return p.CalValueToNum(diffPrestige, p.FacilityPrestigeToConRatio) } // 联盟贡献转联盟经验 func (p *constConfig) CalLeagueConToLeagueExp(leagueConValue int64) int64 { return p.CalValueToNum(leagueConValue, p.ConToLeagueExpRatio) } // 功勋转联盟经验 func (p *constConfig) CalFeatValueToLeagueExp(featValue int64) int64 { return p.CalValueToNum(featValue, p.FeatToLeagueExpRatio) } // 功勋转赛季积分 func (p *constConfig) CalFeatValueToSeasonScore(featValue int64) int64 { return p.CalValueToNum(featValue, p.FeatToSeasonScoreRatio) } // 联盟贡献转赛季积分 func (p *constConfig) CalConValueToSeasonScore(leagueConValue int64) int64 { return p.CalValueToNum(leagueConValue, p.ConToSeasonScoreRatio) } // value转化为num func (p *constConfig) CalValueToNum(value, ratio int64) int64 { if value <= 0 { return 0 } return math.Floor[float64, int64](float64(value*ratio) / constant.FRatioBase) } func (p *constConfig) GetMapCastleSiegeTime() int64 { value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapCastleSiegeTime) if !ok { value = constant.MapCastleSiegeTime } return max(value, constant.MapLeastCastleSiegeTime) }