local ____lualib = require("lualib_bundle") local __TS__Number = ____lualib.__TS__Number local __TS__NumberIsFinite = ____lualib.__TS__NumberIsFinite local ____exports = {} local ____card_value_resolver = require("cards.card_value_resolver") local getCardValueByLevel = ____card_value_resolver.getCardValueByLevel ____exports.MODIFIER_CARD_2 = "modifier_card_2" ____exports.MODIFIER_CARD_43 = "modifier_card_43" local CARD_2_ID = 2 local MIN_BAT = 0.35 local DEFAULT_BAT = 1.7 --- BAT из KV юнита (AttackRate). GetBaseAttackTime() в рантайме — уже модифицированный интервал (~0.24), не подходит. function ____exports.readHeroKVBaseAttackTime(self, parent) if not parent or not IsValidEntity(parent) then return DEFAULT_BAT end local unitName = parent:GetUnitName() if unitName ~= nil then local kv = GetUnitKeyValuesByName(unitName) local rateRaw = kv and kv.AttackRate local rate = tonumber(rateRaw) or __TS__Number(rateRaw) if __TS__NumberIsFinite(rate) and rate > 0 then return rate end end return DEFAULT_BAT end function ____exports.getCard2BatReductionPercent(self, hero) if not hero or not IsValidEntity(hero) then return 0 end return math.max( 0, getCardValueByLevel( nil, CARD_2_ID, hero, "attacktime", 0 ) ) end --- Целевой BAT после карт 2 (%) и суммарного flat с копий карты 43. function ____exports.computeTargetBat(self, parent, card43FlatReduction) local baseBat = ____exports.readHeroKVBaseAttackTime(nil, parent) local card2Pct = ____exports.getCard2BatReductionPercent(nil, parent) local flat = math.max(0, card43FlatReduction) local targetBat = baseBat * (1 - card2Pct * 0.01) - flat return math.max(MIN_BAT, targetBat) end --- Прямое применение BAT на сервере (главный путь для карты 43). function ____exports.applyHeroTargetBat(self, parent, card43FlatReduction) if not IsServer() or not parent or not IsValidEntity(parent) then return end parent:SetBaseAttackTime(____exports.computeTargetBat(nil, parent, card43FlatReduction)) end --- Запасной IAS, если SetBaseAttackTime перезаписали. function ____exports.computeAttackSpeedBonusForTargetBat(self, parent, card43FlatReduction) local currentBat = parent:GetBaseAttackTime() local targetBat = ____exports.computeTargetBat(nil, parent, card43FlatReduction) if not __TS__NumberIsFinite(currentBat) or currentBat <= 0 or targetBat >= currentBat - 0.001 then return 0 end return 100 * (currentBat / targetBat - 1) end return ____exports