package Tower import public Entity import initlater WaveTower import initlater TrooperTower import initlater HealbackTower import initlater FlamethrowerTower import initlater ArtilleryTower import Buff import ClosureTimers public constant BASIC_TOWER_ID = 'h003' public constant BASIC_WALL_ID = 'h000' public constant STOPPER_QUICKBUILD_ID = 'h028' public class Wall extends UnitEntity construct (unit wall) super(wall) public class Tower extends UnitEntity EventListener deathListener = null construct (unit tower) super(tower, tower.getPos3Real()) deathListener = EventListener.add(actor, EVENT_PLAYER_UNIT_DEATH) -> if not done terminate() construct(Tower oldTower) super(oldTower.actor) destroy oldTower.deathListener oldTower.actor.transferBuffs(actor) oldTower.terminate() deathListener = EventListener.add(actor, EVENT_PLAYER_UNIT_DEATH) -> if not done terminate() function onAttack(UnitEntity _target) /** Called on every upgrade of this tower. If this tower has been upgraded to another tier, the old tower is terminated and replaced through the new Tower */ function onUpgrade() switch actor.getTypeId() case FIRST_WAVE_ID this.actor.setEntity(null) new WaveTower(this) case TOWER_TROOPER_ID this.actor.setEntity(null) new TrooperTower(this) case FLAMETHROWER_ID this.actor.setEntity(null) new FlamethrowerTower(this) case ART_TOWER_ID this.actor.setEntity(null) new ArtilleryTower(this) case HEALBACK_TOWER_ID this.actor.setEntity(null) new HealbackTower(this) default printLog(Loglevel.TRACE, "upgrade not catched") actor.issueImmediateOrder("stop") function pause() actor.pause() function unpause() actor.unpause() /** Checks if the upgrade unlocks techtree */ function checkTech(unit u) if u.getTypeId() == 'h00S' or u.getTypeId() == 'h00T' SetPlayerTechMaxAllowed(u.getOwner(), 'h028', -1) init EventListener.add(EVENT_PLAYER_UNIT_CONSTRUCT_START) -> let u = GetConstructingStructure() let id = u.getTypeId() if id == BASIC_TOWER_ID new Tower(u) else if id == BASIC_WALL_ID or id == STOPPER_QUICKBUILD_ID new Wall(u) EventListener.add(EVENT_PLAYER_UNIT_UPGRADE_FINISH) -> let u = GetTriggerUnit() checkTech(u) let data = u.getEntity() if data != null and data instanceof Tower doAfter(0.01, () -> (data castTo Tower).onUpgrade()) DamageEvent.addListener() -> let damager = GetEventDamageSource() let damaged = GetTriggerUnit() if damager != damaged and damager.getEntity() != null and damaged.isAlive() let e = damager.getEntity() if e instanceof Tower let t = e castTo Tower if damaged.getEntity() != null t.onAttack(damaged.getEntity()) else t.actor.issueImmediateOrder("stop")