extend_const.go 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. package data
  2. import (
  3. "f1-game/internal/constant"
  4. "f1-game/internal/enum"
  5. "f1-game/internal/extend/math"
  6. "f1-game/internal/extend/rand"
  7. "f1-game/internal/extend/utils"
  8. "f1-game/internal/types"
  9. "unicode/utf8"
  10. ctime "github.com/cherry-game/cherry/extend/time"
  11. )
  12. var (
  13. mapRelocateCooldown int64 // 迁城冷却时间
  14. mapCityBaseCooldown int64 // 建造主城地基冷却时间
  15. mapResSnatchRatio float64 // 资源掠夺比例
  16. )
  17. func (p *constConfig) OnAfterLoad(_ bool) {
  18. mapRelocateCooldown = p.MapRelocateCooldown * ctime.MillisecondsPerMinute
  19. mapCityBaseCooldown = p.MapCityBaseCooldown * ctime.MillisecondsPerMinute
  20. mapResSnatchRatio = float64(p.MapResSnatchRatio) / constant.RatioBase
  21. }
  22. // CalEquipEnhanceAddProb 计算装备强化增加概率
  23. // @Return 增加的概率, 消耗的MO币
  24. func (p *constConfig) CalEquipEnhanceAddProb(curProb int32, curAssetNum int64) (int32, types.Assets) {
  25. if curProb >= constant.RatioBase || curAssetNum <= 0 {
  26. return 0, nil
  27. }
  28. var (
  29. addProb int32
  30. costMoCoin int64
  31. )
  32. // 最多使用MO币增加的次数
  33. for range p.EquipEnhanceMOCoinTimes {
  34. // 到达最大概率
  35. if addProb+curProb >= constant.RatioBase {
  36. break
  37. }
  38. // 没有足够的MO币
  39. if costMoCoin+p.EquipEnhanceMOCoinCost > curAssetNum {
  40. break
  41. }
  42. addProb += p.EquipEnhanceMOCoinProb
  43. costMoCoin += p.EquipEnhanceAddProbCost.Num
  44. }
  45. if costMoCoin <= 0 {
  46. return 0, nil
  47. }
  48. costs := types.Assets{}
  49. costs.Add(p.EquipEnhanceAddProbCost.ID, costMoCoin)
  50. return addProb, costs
  51. }
  52. // IsSpecialSkillHit 是否命中特殊技能
  53. func (p *constConfig) IsSpecialSkillHit() bool {
  54. return rand.RangeFloat(0.0, constant.RatioBase) <= p.EquipSpecailSkillProb
  55. }
  56. // 检测联盟名称长度是否符合
  57. func (p *constConfig) CheckLeagueNameLen(leagueName string) bool {
  58. return utils.CheckStrLen(leagueName, p.LeagueNameLimit)
  59. }
  60. // 检测联盟简称长度是否符合
  61. func (p *constConfig) CheckLeagueAbbNameLen(leagueAbbName string) bool {
  62. return utils.CheckStrLen(leagueAbbName, p.LeagueAbbNameLimit)
  63. }
  64. // 退出联盟CD检测
  65. func (p *constConfig) CheckLeagueQuitCD(quitTime int64) bool {
  66. return quitTime+p.LeagueQuitCD > ctime.Now().ToSecond()
  67. }
  68. // 计算补兵消耗
  69. func (p *constConfig) GetAddTroopsCost(addTroopsNum int32) types.Assets {
  70. if addTroopsNum < 0 {
  71. return nil
  72. }
  73. costs := types.Assets{}
  74. for _, asset := range p.TeamConscriptionCost {
  75. costs.Add(asset.ID, int64(addTroopsNum)*asset.Num)
  76. }
  77. return costs
  78. }
  79. // GetMapOccupyWaitTime 获取地图占领等待时间
  80. func (p *constConfig) GetMapOccupyWaitTime() int64 {
  81. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapOccupyWaitTime); ok {
  82. return value
  83. }
  84. return p.MapOccupyWaitTime * 1000
  85. }
  86. // GetMapDiscardWaitTime 获取地图放弃等待时间
  87. func (p *constConfig) GetMapDiscardWaitTime() int64 {
  88. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapDiscardWaitTime); ok {
  89. return value
  90. }
  91. return p.MapDiscardWaitTime * 1000
  92. }
  93. // GetMapSiegeWaitTime 获取攻城等待间隔
  94. func (p *constConfig) GetMapSiegeWaitTime() int64 {
  95. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapSiegeWaitTime); ok {
  96. return value
  97. }
  98. return p.MapSiegeWaitTime * 1000
  99. }
  100. func (p *constConfig) GetMapSnatchWaitTime() int64 {
  101. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapSnatchWaitTime); ok {
  102. return value
  103. }
  104. return p.MapSnatchWaitTime * 1000
  105. }
  106. // 获取恢复一点体力所需的秒数
  107. func (p *constConfig) GetRecoverOneEnergyNeedTime() int64 {
  108. return p.HeroEnergyAddInterval / int64(p.HeroEnergyAddValue)
  109. }
  110. func (p *constConfig) GetMapRelocateCooldown() int64 {
  111. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapRelocateCooldown); ok {
  112. return value
  113. }
  114. return mapRelocateCooldown
  115. }
  116. func (p *constConfig) GetMapCityBaseCooldown() int64 {
  117. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapCityBaseCooldown); ok {
  118. return value
  119. }
  120. return mapCityBaseCooldown
  121. }
  122. func (p *constConfig) GetMapResSnatchRatio() float64 {
  123. return mapResSnatchRatio
  124. }
  125. func (p *constConfig) GetMapComebackCoolDown() int64 {
  126. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapComebackCooldown); ok {
  127. return value
  128. }
  129. return p.SelfStateComebackCoolDown * ctime.MillisecondsPerSecond
  130. }
  131. func (p *constConfig) GetMapRechooseComebackCoolDown() int64 {
  132. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapRechooseComebackCooldown); ok {
  133. return value
  134. }
  135. return p.ChooseStateComebackCoolDown * ctime.MillisecondsPerSecond
  136. }
  137. // 通过联盟邮件类型获取邮件上限值
  138. func (p *constConfig) GetLeagueMailLimit(mailType int32) int32 {
  139. switch mailType {
  140. case enum.MailType_Decree:
  141. return p.LeagueDecreeMailLimit
  142. case enum.MailType_Union:
  143. return p.LeagueUnionMailLimit
  144. case enum.MailType_Command:
  145. return p.LeagueCommandMailLimit
  146. default:
  147. return 0
  148. }
  149. }
  150. // 检测玩家地图标记标题是否合法 标题可为空
  151. func (p *constConfig) CheckMapMarkTitle(title string) bool {
  152. if len(title) <= 0 {
  153. return true
  154. }
  155. return utils.CheckStrLen(title, p.MapMarkTitleLimit)
  156. }
  157. // 检测联盟地图标记标题是否合法 不能为空
  158. func (p *constConfig) CheckLeagueMapMarkTitle(title string) bool {
  159. return utils.CheckStrLen(title, p.LeagueMapMarkTitleLimit)
  160. }
  161. // 检测联盟地图标记描述是否合法 可以为空
  162. func (p *constConfig) CheckLeagueMapMarkDesc(desc string) bool {
  163. if len(desc) <= 0 {
  164. return true
  165. }
  166. return utils.CheckStrLen(desc, p.LeagueMapMarkDescLimit)
  167. }
  168. func (p *constConfig) CheckPlayerNameLen(name string) bool {
  169. nameLen := int32(utf8.RuneCountInString(name))
  170. if nameLen < p.PlayerNameMinLength || nameLen > p.PlayerNameMaxLength {
  171. return false
  172. }
  173. return true
  174. }
  175. func (p *constConfig) CheckPlayerDescLen(desc string) bool {
  176. descLen := utf8.RuneCountInString(desc)
  177. return descLen > p.PlayerDescLenLimit
  178. }
  179. func (p *constConfig) GetLeagueResidenceBackCost() types.Assets {
  180. costs := types.Assets{}
  181. costs.Add(p.LeagueResidenceBackCost.ID, p.LeagueResidenceBackCost.Num)
  182. return costs
  183. }
  184. func (p *constConfig) GetMapScoutMarchTime() int64 {
  185. return ctime.Now().ToMillisecond() + p.MapScoutMarchTime*ctime.MillisecondsPerSecond
  186. }
  187. func (p *constConfig) GetMapScoutTime(startTime int64) int64 {
  188. return startTime + p.MapScoutTime*ctime.MillisecondsPerSecond
  189. }
  190. func (p *constConfig) GetMapReinforcePrepareTime() int64 {
  191. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapReinforcePrepareTime); ok {
  192. return value
  193. }
  194. return p.ReinforcePrepareTime * 1000
  195. }
  196. func (p *constConfig) GetMapReinforceEffectTime() int64 {
  197. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapReinforceEffectTime); ok {
  198. return value
  199. }
  200. return p.ReinforceTime * 1000
  201. }
  202. func (p *constConfig) GetMapReinforceCooldown() int64 {
  203. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapReinforceCooldown); ok {
  204. return value
  205. }
  206. return p.ReinforceCoolDown * 1000
  207. }
  208. func (p *constConfig) GetEquipRandomCraftCost(craftNum int32) types.Assets {
  209. var (
  210. num = int64(craftNum)
  211. costs = types.Assets{}
  212. )
  213. for _, cost := range p.EquipRandomCraftCost {
  214. costs.Add(cost.ID, num*cost.Num)
  215. }
  216. return costs
  217. }
  218. func (p *constConfig) GetBeginerInvincibleTime() int64 {
  219. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_BeginerInvincibleTime); ok {
  220. return value
  221. }
  222. return p.BeginerInvincibleTime * ctime.MillisecondsPerMinute
  223. }
  224. func (p *constConfig) GetComebackInvincibleTime() int64 {
  225. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_ComebackInvincibleTime); ok {
  226. return value
  227. }
  228. return p.ComebackInvincibleTime * ctime.MillisecondsPerMinute
  229. }
  230. func (p *constConfig) GetResOccupyInvincibleTime() int64 {
  231. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_ResOccupyInvincibleTime); ok {
  232. return value
  233. }
  234. return p.MapResProtectTime * ctime.MillisecondsPerSecond
  235. }
  236. func (p *constConfig) GetHeroInjureTime() int64 {
  237. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_HeroInjureTime); ok {
  238. return value
  239. }
  240. return p.HeroInjureTime
  241. }
  242. // 获得帝国晶矿转联盟贡献
  243. func (p *constConfig) CalCrystalMineToLeagueCon(addCrystalMine int64) int64 {
  244. return p.CalValueToNum(addCrystalMine, p.CrystalMineToConRatio)
  245. }
  246. // 攻城值转联盟贡献
  247. func (p *constConfig) CalSiegeToLeagueCon(siegeValue int64) int64 {
  248. return p.CalValueToNum(siegeValue, p.TileSiegeToConRatio)
  249. }
  250. // 城建声望转联盟贡献
  251. func (p *constConfig) CalFacilityToLeagueCon(diffPrestige int64) int64 {
  252. return p.CalValueToNum(diffPrestige, p.FacilityPrestigeToConRatio)
  253. }
  254. // 联盟贡献转联盟经验
  255. func (p *constConfig) CalLeagueConToLeagueExp(leagueConValue int64) int64 {
  256. return p.CalValueToNum(leagueConValue, p.ConToLeagueExpRatio)
  257. }
  258. // 功勋转联盟经验
  259. func (p *constConfig) CalFeatValueToLeagueExp(featValue int64) int64 {
  260. return p.CalValueToNum(featValue, p.FeatToLeagueExpRatio)
  261. }
  262. // 功勋转赛季积分
  263. func (p *constConfig) CalFeatValueToSeasonScore(featValue int64) int64 {
  264. return p.CalValueToNum(featValue, p.FeatToSeasonScoreRatio)
  265. }
  266. // 联盟贡献转赛季积分
  267. func (p *constConfig) CalConValueToSeasonScore(leagueConValue int64) int64 {
  268. return p.CalValueToNum(leagueConValue, p.ConToSeasonScoreRatio)
  269. }
  270. // value转化为num
  271. func (p *constConfig) CalValueToNum(value, ratio int64) int64 {
  272. if value <= 0 {
  273. return 0
  274. }
  275. return math.Floor[float64, int64](float64(value*ratio) / constant.FRatioBase)
  276. }
  277. func (p *constConfig) GetMapCastleSiegeTime() int64 {
  278. value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapCastleSiegeTime)
  279. if !ok {
  280. value = constant.MapCastleSiegeTime
  281. }
  282. return max(value, constant.MapLeastCastleSiegeTime)
  283. }