package UnitData import initlater PlayerData import public UnitIndex import initlater CreepExp import UnitTypeGen // Assure UnitBaseStatBuffers are valid before UnitData objects are created. import UnitTypeData import StatHandler import BuffHandler import DamageHandler import ThreatHandler import initlater CreepRespawn import initlater HeroRespawn import initlater CreepDrop import OOCRegen import TimerUtils // Unit API: public function unit.xGetUnitData() returns UnitData return this.getIndex() castTo UnitData public function unit.xIsHero() returns boolean return xGetPlayerHero(this.getOwner().getId()) == this public function unit.xIsAlive() returns boolean return not IsUnitType(this, UNIT_TYPE_DEAD) and GetUnitTypeId(this) != 0 public function unit.xIsBoss() returns boolean return IsUnitType(this, UNIT_TYPE_SAPPER) /** Returns false for all kinds of dummies, non-combat units, etc. */ public function unit.xIsCombatUnit() returns boolean return this.xGetUnitData() != null public function unit.xGetStat(Stat s) returns int return this.xGetUnitData().unitStatBuffer.get(s) public function unit.xGetStatReal(Stat s) returns real return this.xGetStat(s) / 100. public function xSpawnCreep(int raw, vec2 pos, real angle) returns unit let u = createUnit(Player(PLAYER_NEUTRAL_AGGRESSIVE), raw, pos, angle(angle)) new UnitData(u) return u // ---- public function unitDeath(unit u) let unitData = u.xGetUnitData() unitData.unitBuffList.destroyAllBuffs() if u.xIsHero() // Heroes: unitDisableOOCRegen(u) destroy unitData.threatHandlerPu unitData.threatHandlerPu = null respawnHero(u) // enables OOCRegen, creates new ThreadHandlerPu object else // Creeps, Bosses creepSpreadExp(u) creepDrop(u) if unitData.creepRespawn != null unitData.creepRespawn.respawn() destroy unitData.threatHandlerTu unitData.threatHandlerTu = null unitData.destroyTimed(3.) public class UnitData extends UnitIndex UnitStatBuffer unitStatBuffer UnitDamageHandler unitDamageHandler BuffList unitBuffList ThreatHandlerPU threatHandlerPu ThreatHandlerTU threatHandlerTu // Creep properties: CreepRespawn creepRespawn construct(unit u) super(u) unitStatBuffer = new UnitStatBuffer(u, u.getTypeId().xGetUnitTypeData().unitBaseStatBuffer) unitDamageHandler = new UnitDamageHandler(u) unitBuffList = new BuffList(u) threatHandlerPu = null threatHandlerTu = null creepRespawn = null if u.xIsHero() // Heroes: threatHandlerPu = new ThreatHandlerPU(u) unitEnableOOCRegen(u) else // Creeps, Bosses: threatHandlerTu = new ThreatHandlerTU(u) function destroyTimed(real timeout) getTimer() ..setData(this castTo int) ..start(timeout, () -> begin let t = GetExpiredTimer() destroy t.getData() castTo thistype t.release() end) ondestroy destroy unitStatBuffer destroy unitDamageHandler destroy unitBuffList if threatHandlerPu != null destroy threatHandlerPu if threatHandlerTu != null destroy threatHandlerTu if u.xIsHero() unitDisableOOCRegen(u)