extend_const.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. package data
  2. import (
  3. "f1-game/internal/constant"
  4. "f1-game/internal/enum"
  5. "f1-game/internal/extend/rand"
  6. "f1-game/internal/extend/utils"
  7. "f1-game/internal/types"
  8. "unicode/utf8"
  9. ctime "github.com/cherry-game/cherry/extend/time"
  10. )
  11. var (
  12. mapRelocateCooldown int64 // 迁城冷却时间
  13. mapCityBaseCooldown int64 // 建造主城地基冷却时间
  14. mapResSnatchRatio float64 // 资源掠夺比例
  15. )
  16. func (p *constConfig) OnAfterLoad(_ bool) {
  17. mapRelocateCooldown = p.MapRelocateCooldown * ctime.MillisecondsPerMinute
  18. mapCityBaseCooldown = p.MapCityBaseCooldown * ctime.MillisecondsPerMinute
  19. mapResSnatchRatio = float64(p.MapResSnatchRatio) / constant.RatioBase
  20. }
  21. // CalEquipEnhanceAddProb 计算装备强化增加概率
  22. // @Return 增加的概率, 消耗的MO币
  23. func (p *constConfig) CalEquipEnhanceAddProb(curProb int32, curAssetNum int64) (int32, types.Assets) {
  24. if curProb >= constant.RatioBase || curAssetNum <= 0 {
  25. return 0, nil
  26. }
  27. var (
  28. addProb int32
  29. costMoCoin int64
  30. )
  31. // 最多使用MO币增加的次数
  32. for range p.EquipEnhanceMOCoinTimes {
  33. // 到达最大概率
  34. if addProb+curProb >= constant.RatioBase {
  35. break
  36. }
  37. // 没有足够的MO币
  38. if costMoCoin+p.EquipEnhanceMOCoinCost > curAssetNum {
  39. break
  40. }
  41. addProb += p.EquipEnhanceMOCoinProb
  42. costMoCoin += p.EquipEnhanceAddProbCost.Num
  43. }
  44. if costMoCoin <= 0 {
  45. return 0, nil
  46. }
  47. costs := types.Assets{}
  48. costs.Add(p.EquipEnhanceAddProbCost.ID, costMoCoin)
  49. return addProb, costs
  50. }
  51. // IsSpecialSkillHit 是否命中特殊技能
  52. func (p *constConfig) IsSpecialSkillHit() bool {
  53. return rand.RangeFloat(0.0, constant.RatioBase) <= p.EquipSpecailSkillProb
  54. }
  55. // 检测联盟名称长度是否符合
  56. func (p *constConfig) CheckLeagueNameLen(leagueName string) bool {
  57. return utils.CheckStrLen(leagueName, p.LeagueNameLimit)
  58. }
  59. // 检测联盟简称长度是否符合
  60. func (p *constConfig) CheckLeagueAbbNameLen(leagueAbbName string) bool {
  61. return utils.CheckStrLen(leagueAbbName, p.LeagueAbbNameLimit)
  62. }
  63. // 退出联盟CD检测
  64. func (p *constConfig) CheckLeagueQuitCD(quitTime int64) bool {
  65. return quitTime+p.LeagueQuitCD > ctime.Now().ToSecond()
  66. }
  67. // 计算补兵消耗
  68. func (p *constConfig) GetAddTroopsCost(addTroopsNum int32) types.Assets {
  69. if addTroopsNum < 0 {
  70. return nil
  71. }
  72. costs := types.Assets{}
  73. for _, asset := range p.TeamConscriptionCost {
  74. costs.Add(asset.ID, int64(addTroopsNum)*asset.Num)
  75. }
  76. return costs
  77. }
  78. // GetMapOccupyWaitTime 获取地图占领等待时间
  79. func (p *constConfig) GetMapOccupyWaitTime() int64 {
  80. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapOccupyWaitTime); ok {
  81. return value
  82. }
  83. return p.MapOccupyWaitTime * 1000
  84. }
  85. // GetMapDiscardWaitTime 获取地图放弃等待时间
  86. func (p *constConfig) GetMapDiscardWaitTime() int64 {
  87. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapDiscardWaitTime); ok {
  88. return value
  89. }
  90. return p.MapDiscardWaitTime * 1000
  91. }
  92. // GetMapSiegeWaitTime 获取攻城等待间隔
  93. func (p *constConfig) GetMapSiegeWaitTime() int64 {
  94. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapSiegeWaitTime); ok {
  95. return value
  96. }
  97. return p.MapSiegeWaitTime * 1000
  98. }
  99. func (p *constConfig) GetMapSnatchWaitTime() int64 {
  100. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapSnatchWaitTime); ok {
  101. return value
  102. }
  103. return p.MapSnatchWaitTime * 1000
  104. }
  105. // 获取恢复一点体力所需的秒数
  106. func (p *constConfig) GetRecoverOneEnergyNeedTime() int64 {
  107. return p.HeroEnergyAddInterval / int64(p.HeroEnergyAddValue)
  108. }
  109. func (p *constConfig) GetMapRelocateCooldown() int64 {
  110. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapRelocateCooldown); ok {
  111. return value
  112. }
  113. return mapRelocateCooldown
  114. }
  115. func (p *constConfig) GetMapCityBaseCooldown() int64 {
  116. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapCityBaseCooldown); ok {
  117. return value
  118. }
  119. return mapCityBaseCooldown
  120. }
  121. func (p *constConfig) GetMapResSnatchRatio() float64 {
  122. return mapResSnatchRatio
  123. }
  124. func (p *constConfig) GetMapComebackCoolDown() int64 {
  125. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapComebackCooldown); ok {
  126. return value
  127. }
  128. return p.SelfStateComebackCoolDown * ctime.MillisecondsPerSecond
  129. }
  130. func (p *constConfig) GetMapRechooseComebackCoolDown() int64 {
  131. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapRechooseComebackCooldown); ok {
  132. return value
  133. }
  134. return p.ChooseStateComebackCoolDown * ctime.MillisecondsPerSecond
  135. }
  136. // 通过联盟邮件类型获取邮件上限值
  137. func (p *constConfig) GetLeagueMailLimit(mailType int32) int32 {
  138. switch mailType {
  139. case enum.MailType_Decree:
  140. return p.LeagueDecreeMailLimit
  141. case enum.MailType_Union:
  142. return p.LeagueUnionMailLimit
  143. case enum.MailType_Command:
  144. return p.LeagueCommandMailLimit
  145. default:
  146. return 0
  147. }
  148. }
  149. // 检测玩家地图标记标题是否合法 标题可为空
  150. func (p *constConfig) CheckMapMarkTitle(title string) bool {
  151. if len(title) <= 0 {
  152. return true
  153. }
  154. return utils.CheckStrLen(title, p.MapMarkTitleLimit)
  155. }
  156. // 检测联盟地图标记标题是否合法 不能为空
  157. func (p *constConfig) CheckLeagueMapMarkTitle(title string) bool {
  158. return utils.CheckStrLen(title, p.LeagueMapMarkTitleLimit)
  159. }
  160. // 检测联盟地图标记描述是否合法 可以为空
  161. func (p *constConfig) CheckLeagueMapMarkDesc(desc string) bool {
  162. if len(desc) <= 0 {
  163. return true
  164. }
  165. return utils.CheckStrLen(desc, p.LeagueMapMarkDescLimit)
  166. }
  167. func (p *constConfig) CheckPlayerNameLen(name string) bool {
  168. nameLen := int32(utf8.RuneCountInString(name))
  169. if nameLen < p.PlayerNameMinLength || nameLen > p.PlayerNameMaxLength {
  170. return false
  171. }
  172. return true
  173. }
  174. func (p *constConfig) CheckPlayerDescLen(desc string) bool {
  175. descLen := utf8.RuneCountInString(desc)
  176. return descLen > p.PlayerDescLenLimit
  177. }
  178. func (p *constConfig) GetLeagueResidenceBackCost() types.Assets {
  179. costs := types.Assets{}
  180. costs.Add(p.LeagueResidenceBackCost.ID, p.LeagueResidenceBackCost.Num)
  181. return costs
  182. }
  183. func (p *constConfig) GetMapScoutMarchTime() int64 {
  184. return ctime.Now().ToMillisecond() + p.MapScoutMarchTime*ctime.MillisecondsPerSecond
  185. }
  186. func (p *constConfig) GetMapScoutTime() int64 {
  187. return ctime.Now().ToMillisecond() + p.MapScoutTime*ctime.MillisecondsPerSecond
  188. }
  189. func (p *constConfig) GetMapReinforcePrepareTime() int64 {
  190. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapReinforcePrepareTime); ok {
  191. return value
  192. }
  193. return p.ReinforcePrepareTime * 1000
  194. }
  195. func (p *constConfig) GetMapReinforceEffectTime() int64 {
  196. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapReinforceEffectTime); ok {
  197. return value
  198. }
  199. return p.ReinforceTime * 1000
  200. }
  201. func (p *constConfig) GetMapReinforceCooldown() int64 {
  202. if value, ok := GameDebug.GetDebugValue(constant.GameDebug_MapReinforceCooldown); ok {
  203. return value
  204. }
  205. return p.ReinforceCoolDown * 1000
  206. }