package BaseObject import public Entity import public TerrainUtils import public ConfigValue import public SetupObject import public SerializeIds import public ChannelAbilityPreset import Assets /* ---Creating a new Baseobject--- Creating the baseobject will need 3 parameters the unit u: in whichs Userdata the struct is saved the radius: The Range of the InrangeDetection the code c: name of the static method that is being called upon inRangeEvent A Baseobject is usually a circle. A unit that doesn't move and has an onRange trigger. */ public constant KEY_RALLY_X = "r" public constant KEY_RALLY_Y = "s" public class StaticBaseObject extends UnitEntity effect noRally = null effect disFx = null var enabled = true private vec3 rallyPoint private unit rallyUnit = null private var rallyAngle = angle(0) protected trigger inRangeTrig construct(vec2 pos, unit actor, real radius, code action, code cond) super(actor) actor..addAbility(GHOST_VIS_ID)..addAbility(REMOVE_OBJECT_ID) this.setCurrentRegion() noRally = addEffect(Objects.questionMark1, pos) rallyPoint = this.pos // A few Objects like Spinner dont have inRange Events, so we only create it if the object has a radius if radius > 0. inRangeTrig = CreateTrigger() inRangeTrig.registerUnitInRangeSource(actor, radius) if cond == null inRangeTrig.addCondition(Condition((function isProper))) else inRangeTrig.addCondition(Condition(cond)) inRangeTrig.addAction(action) EventListener.add(actor, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER, () -> (GetOrderedUnit().getEntity() castTo StaticBaseObject).adjustRally()) EventListener.add(actor, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER, () -> (GetOrderedUnit().getEntity() castTo StaticBaseObject).adjustRally()) EventListener.add(actor, EVENT_PLAYER_UNIT_SPELL_CAST, () -> onCast()) function setEnabled(boolean flag) if flag and not enabled enabled = true activate() actor..removeAbility(TURN_ON_ID)..addAbility(TURN_OFF_ID) flashEffect(Abilities.ancestralSpiritCaster, pos) if disFx != null disFx.destr() else if enabled enabled = false deactivate() actor..removeAbility(TURN_OFF_ID)..addAbility(TURN_ON_ID) if disFx != null disFx.destr() var path = "" if localPlayer == owner path = Abilities.sleepTarget disFx = addEffect(path, pos) function onCast() let id = GetSpellAbilityId() switch id case TURN_ON_ID setEnabled(true) case TURN_OFF_ID setEnabled(false) function clearQuestionmark() if noRally != null noRally.destr() noRally = null function addQuestionmark() if noRally == null noRally = addEffect(Objects.questionMark1, pos) function isActive() returns boolean return active function adjustRally() let target = GetOrderTarget() let utarget = GetOrderTargetUnit() let itm = GetOrderTargetItem() let targetPoint = vec2(GetOrderPointX(), GetOrderPointY()) let orderid = GetIssuedOrderId() if orderid == 0xD000C or orderid == 851971 if target == null if itm == null setRallyPoint(targetPoint) else setRallyPoint(itm.getPos()) else if utarget != null let data = utarget.getEntity() if data != null and data instanceof SetupObject rallyUnit = (data castTo SetupObject).actor else rallyUnit = utarget clearQuestionmark() rallyPoint = target.getPos().toVec3() if noRally != null noRally.destr() noRally = null static function isProper() returns boolean return GetTriggerUnit().getFlyHeight() < 22 and (GetTriggeringTrigger().getSource().getEntity() castTo StaticBaseObject).enabled function setRallyPoint(vec2 tpos) rallyPoint = tpos.toVec3() rallyUnit = null rallyAngle = pos.angleTo2d(rallyPoint) clearQuestionmark() function getRallyPoint() returns vec3 if rallyUnit == null or not rallyUnit.isAliveTrick() return rallyPoint else if rallyUnit.getOwner() != DUMMY_PLAYER return rallyUnit.getPos3with(0) else return pos function getRallyUnit() returns unit return rallyUnit function getRallyAngle() returns angle if rallyUnit != null rallyAngle = pos.angleTo2d(rallyUnit.getPos()) return rallyAngle ondestroy actor.clearRegister() inRangeTrig.destr() clearQuestionmark() if disFx != null disFx.destr() disFx = null override function serialize() returns Json let json = super.serialize() if rallyUnit != null rallyPoint = rallyUnit.getPos3Zero() json ..addProperty(new Property(KEY_RALLY_X, (rallyPoint.x-serializeOrigin.x).toInt().toString())) ..addProperty(new Property(KEY_RALLY_Y, (rallyPoint.y-serializeOrigin.y).toInt().toString())) return json override function deserialize(Json json) super.deserialize(json) let rpos = vec2(serializeOrigin.x+json.getReal(KEY_RALLY_X), serializeOrigin.y+json.getReal(KEY_RALLY_Y)) setRallyPoint(rpos)