| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- package data
- import (
- "f1-game/internal/constant"
- "f1-game/internal/enum"
- "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() int64 {
- return ctime.Now().ToMillisecond() + 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
- }
|