package Decoration import BaseObject import initlater InstantBuild public constant CHANGE_FACE_ID = compiletime(ABIL_ID_GEN.next()) public constant INC_SCALE = compiletime(ABIL_ID_GEN.next()) public constant DEC_SCALE = compiletime(ABIL_ID_GEN.next()) constant KEY_SCALE = "d" constant KEY_ANGLE = "e" public class Decoration extends StaticSetupObject private let scale = new ConfigValue(1.0, 0.1, "Scale") var tid = 0 var hasBeenChanged = false construct(vec2 pos, player owner, real a, int tid) super(CreateUnit(owner, buildorders[tid], pos.x, pos.y, a), CreateUnit(owner, buildorders[tid], pos.x, pos.y, a), 0., null) this.tid = tid setup..addAbility(CHANGE_FACE_ID)..addAbility(INC_SCALE)..addAbility(DEC_SCALE)..addAbility(GHOST_INVIS_ID) EventListener.add(setup, EVENT_PLAYER_UNIT_SPELL_CAST, () -> onCast()) function onCast() let id = GetSpellAbilityId() switch id case CHANGE_FACE_ID let tg = EventData.getSpellTargetPos() changeAngle(pos.angleTo2d(tg)) case INC_SCALE scale.increment(this, 3.0) case DEC_SCALE scale.decrement(this, 0.1) actor.setScale(scale.get()) setup.setScale(scale.get()) function changeAngle(angle a) let select = IsUnitSelected(setup, owner) setNewActor(createUnit(owner, actor.getTypeId(), pos, a)) setNewSetup(createUnit(owner, setup.getTypeId(), pos, a)) actor.addAbility(LOCUST_ID) setup..addAbility(GHOST_INVIS_ID)..addAbility(CHANGE_FACE_ID)..addAbility(INC_SCALE)..addAbility(DEC_SCALE) EventListener.add(setup, EVENT_PLAYER_UNIT_SPELL_CAST) -> onCast() if select owner.select(setup) hasBeenChanged = true ondestroy destroy scale override function deserialize(Json json) changeAngle((json.getInt(KEY_ANGLE).toReal().fromDeg())) let sc = json.getInt(KEY_SCALE) if sc > 0. scale.setVal(sc / 100.) actor.setScale(scale.get()) setup.setScale(scale.get()) override function serialize() returns Json let json = super.serialize() json..addProperty(new Property(KEY_TYPE, tid.toString())) if hasBeenChanged json..addProperty(new Property(KEY_ANGLE, actor.getFacingAngle().degrees().toInt().toString())) if scale.get() != 1.0 json..addProperty(new Property(KEY_SCALE, (scale.get() * 100.).toInt().toString())) return json @objectgen function genDeco() new ChannelAbilityPreset(CHANGE_FACE_ID, 1, true) ..setName("Set facing") ..presetTargetTypes(Targettype.POINT) ..presetCastRange(lvl -> 500) ..presetCooldown(lvl -> 0) ..presetManaCost(lvl -> 0) ..presetTooltipNormal(lvl -> "Set the facing of this decoration [Q]") ..presetTooltipNormalExtended(lvl -> "Makes this object point at the target direction") ..presetButtonPosNormal(0, 0) ..presetIcon(Icons.bTNLoad) ..presetHotkey("Q") new ChannelAbilityPreset(INC_SCALE, 1, true) ..setName("Increase Scale") ..presetTargetTypes(Targettype.NONE) ..makeUnitSpell(0, 0) ..presetTooltipNormal(lvl -> "Increase the scale of this decoration [W]") ..presetTooltipNormalExtended(lvl -> "+0.1") ..presetButtonPosNormal(1, 0) ..presetIcon(Icons.bTNReplay_SpeedUp) ..presetHotkey("W") new ChannelAbilityPreset(DEC_SCALE, 1, true) ..setName("Decrease Scale") ..presetTargetTypes(Targettype.NONE) ..makeUnitSpell(0, 0) ..presetTooltipNormal(lvl -> "Decrease the scale of this decoration [S]") ..presetTooltipNormalExtended(lvl -> "-0.1") ..presetButtonPosNormal(1, 1) ..presetIcon(Icons.bTNReplay_SpeedDown) ..presetHotkey("S")