/// <summary> /// Verifies <paramref name="action"/> is executed after setting the position of /// <paramref name="positionable"/> to <paramref name="temporalPosition"/> and then /// gets restored to <paramref name="originalPosition"/>. /// </summary> /// /// <remarks> /// This should be called within a <see cref="Received.InOrder(Action)"/> block. /// </remarks> /// /// <param name="positionable">The posibionable to verify.</param> /// <param name="originalPosition">The expected original position.</param> /// <param name="temporalPosition">The expected temporal position.</param> /// <param name="action">The action to be executed.</param> public static void VerifyDoAtPosition(this IPositionable positionable, long originalPosition, long temporalPosition, Action action) { positionable.GetPosition(); positionable.SetPosition(temporalPosition); action.Invoke(); positionable.SetPosition(originalPosition); }
Activity FirstTick(Actor self) { triggered = true; // Place the actor and retrieve its visual position (CenterPosition) pos.SetPosition(self, dropPosition); currentPosition = self.CenterPosition; return(this); }
Activity FirstTick(Actor self) { triggered = true; foreach (var np in self.TraitsImplementing <INotifyParachute>()) { np.OnParachute(self); } // Place the actor and retrieve its visual position (CenterPosition) pos.SetPosition(self, dropPosition); currentPosition = self.CenterPosition; return(this); }
void SetNexusPosition(Actor self) { int x = 0, y = 0, cnt = 0; foreach (var se in slaveEntries) { if (!se.IsValid || !se.Actor.IsInWorld) { continue; } var pos = se.Actor.CenterPosition; x += pos.X; y += pos.Y; cnt++; } if (cnt == 0) { return; } var newPos = new WPos(x / cnt, y / cnt, aircraft != null ? aircraft.Info.CruiseAltitude.Length : 0); if (aircraft == null) { position.SetPosition(self, newPos); // breaks arrival detection of the aircraft if we set position. } position.SetVisualPosition(self, newPos); }
public override bool Tick(Actor self) { currentPosition -= fallVector; pos.SetCenterPosition(self, currentPosition); // If the unit has landed, this will be the last tick if (self.World.Map.DistanceAboveTerrain(currentPosition).Length <= 0) { var dat = self.World.Map.DistanceAboveTerrain(currentPosition); pos.SetPosition(self, currentPosition - new WVec(WDist.Zero, WDist.Zero, dat)); return(true); } return(false); }
public static CMap Create(IMapLoader loader) { Int32 width = loader.GetWidth(); Int32 height = loader.GetHeight(); var map = new CMap(width, height); for (var x = 0; x < map.Width; x++) { for (var y = 0; y < map.Height; y++) { var position = new SPoint(x, y); ICell cell = loader.GetCell(position); map.SetCell(cell); IPositionable unit = loader.GetUnit(position); if (unit != null) { unit.SetMap(map); unit.SetPosition(new SPoint(x, y)); //map.Spawn(unit, position.X, position.Y); } } } return(map); }
void Release() { var localOffset = carryall.CarryableOffset.Rotate(body.QuantizeOrientation(self, self.Orientation)); var targetPosition = self.CenterPosition + body.LocalToWorld(localOffset); var targetLocation = self.World.Map.CellContaining(targetPosition); positionable.SetPosition(carryall.Carryable, targetLocation, SubCell.FullCell); // HACK: directly manipulate the turret facings to match the new orientation // This can eventually go away, when we make turret facings relative to the body var facingDelta = carryallFacing.Facing - carryableFacing.Facing; foreach (var t in carryall.Carryable.TraitsImplementing <Turreted>()) { t.TurretFacing += facingDelta; } carryableFacing.Facing = carryallFacing.Facing; // Put back into world self.World.AddFrameEndTask(w => { var cargo = carryall.Carryable; w.Add(cargo); carryall.DetachCarryable(self); carryable.UnReserve(cargo); carryable.Detached(cargo); }); }
// CnP from Aircraft.cs + modified a little public void SetPosition(Actor self, WPos pos) { positionable.SetPosition(self, pos); if (!self.IsInWorld) { return; } self.World.UpdateMaps(self, ios); var altitude = self.World.Map.DistanceAboveTerrain(pos); var isAirborne = altitude.Length >= Info.MinAirborneAltitude; if (isAirborne && !airborne) { OnAirborneAltitudeReached(self); } else if (!isAirborne && airborne) { OnAirborneAltitudeLeft(self); } var isCruising = altitude == Info.CruiseAltitude; if (isCruising && !cruising) { OnCruisingAltitudeReached(self); } else if (!isCruising && cruising) { OnCruisingAltitudeLeft(self); } }
bool AttackTargets(Actor self, IEnumerable <Actor> targets) { var targetLocation = target.Actor.Location; foreach (var t in targets) { var targetClose = t; // loop variable in closure hazard self.World.AddFrameEndTask(_ => { // Don't use Kill() because we don't want any of its side-effects (husks, etc) targetClose.Dispose(); // Harvester insurance if (targetClose.Info.HasTraitInfo <HarvesterInfo>()) { var insurance = targetClose.Owner.PlayerActor.TraitOrDefault <HarvesterInsurance>(); if (insurance != null) { self.World.AddFrameEndTask(__ => insurance.TryActivate()); } } }); } positionable.SetPosition(self, targetLocation); var attackPosition = self.CenterPosition; var affectedPlayers = targets.Select(x => x.Owner).Distinct().ToList(); Game.Sound.Play(swallow.Info.WormAttackSound, self.CenterPosition); Game.RunAfterDelay(1000, () => { if (!Game.IsCurrentWorld(self.World)) { return; } foreach (var player in affectedPlayers) { Game.Sound.PlayNotification(player.World.Map.Rules, player, "Speech", swallow.Info.WormAttackNotification, player.Faction.InternalName); if (player == player.World.RenderPlayer) { radarPings.Add(() => true, attackPosition, Color.Red, 50); } } }); foreach (var notify in self.TraitsImplementing <INotifyAttack>()) { notify.PreparingAttack(self, target, null, null); notify.Attacking(self, target, null, null); } return(true); }
Activity FirstTick(Actor self) { triggered = true; if (um != null) { foreach (var u in para.ParachuteUpgrade) { um.GrantUpgrade(self, u, this); } } // Place the actor and retrieve its visual position (CenterPosition) pos.SetPosition(self, dropPosition); currentPosition = self.CenterPosition; return(this); }
bool WormAttack(Actor worm) { var targetLocation = target.Actor.Location; // The target has moved too far away if ((location - targetLocation).Length > NearEnough) { return(false); } var lunch = worm.World.ActorMap.GetUnitsAt(targetLocation) .Where(t => !t.Equals(worm) && weapon.IsValidAgainst(t, worm)); if (!lunch.Any()) { return(false); } stance = AttackState.EmergingAboveGround; sandworm.IsAttacking = true; foreach (var actor in lunch) { var actor1 = actor; // loop variable in closure hazard actor.World.AddFrameEndTask(_ => { actor1.Destroy(); // Harvester insurance if (!actor1.HasTrait <Harvester>()) { return; } var insurance = actor1.Owner.PlayerActor.TraitOrDefault <HarvesterInsurance>(); if (insurance != null) { actor1.World.AddFrameEndTask(__ => insurance.TryActivate()); } }); } positionable.SetPosition(worm, targetLocation); var attackPosition = worm.CenterPosition; var affectedPlayers = lunch.Select(x => x.Owner).Distinct().ToList(); PlayAttack(worm, attackPosition, affectedPlayers); foreach (var notify in worm.TraitsImplementing <INotifyAttack>()) { notify.Attacking(worm, target, null, null); } return(true); }
protected override void OnLastRun(Actor self) { var centerPosition = self.CenterPosition; pos.SetPosition(self, centerPosition - new WVec(0, 0, groundLevel - centerPosition.Z)); foreach (var np in self.TraitsImplementing <INotifyParachute>()) { np.OnLanded(self, ignore); } }
bool AttackTargets(Actor self, IEnumerable <Actor> targets) { var targetLocation = target.Actor.Location; foreach (var t in targets) { var targetClose = t; // loop variable in closure hazard self.World.AddFrameEndTask(_ => { // Don't use Kill() because we don't want any of its side-effects (husks, etc) targetClose.Dispose(); // Harvester insurance if (targetClose.Info.HasTraitInfo <HarvesterInfo>()) { var insurance = targetClose.Owner.PlayerActor.TraitOrDefault <HarvesterInsurance>(); if (insurance != null) { self.World.AddFrameEndTask(__ => insurance.TryActivate()); } } }); } positionable.SetPosition(self, targetLocation); var attackPosition = self.CenterPosition; var affectedPlayers = targets.Select(x => x.Owner).Distinct().ToList(); Game.Sound.Play(SoundType.World, swallow.Info.WormAttackSound, self.CenterPosition); foreach (var player in affectedPlayers) { self.World.AddFrameEndTask(w => w.Add(new MapNotificationEffect(player, "Speech", swallow.Info.WormAttackNotification, 25, true, attackPosition, Color.Red))); } var barrel = armament.CheckFire(self, facing, target); if (barrel == null) { return(false); } // armament.CheckFire already calls INotifyAttack.PreparingAttack foreach (var notify in self.TraitsImplementing <INotifyAttack>()) { notify.Attacking(self, target, armament, barrel); } return(true); }
void Release() { positionable.SetPosition(cargo, self.Location, SubCell.FullCell); cargoFacing.Facing = selfFacing.Facing; // Put back into world self.World.AddFrameEndTask(w => { cargo.World.Add(cargo); carryall.UnreserveCarryable(); }); // Unlock carryable carryall.CarryableReleased(); carryable.Dropped(); }
public Boolean Spawn(IPositionable unit, Int32 x, Int32 y) { if (unit is null) { throw new ArgumentNullException(nameof(unit)); } unit.SetMap(_map); var position = new SPoint(x, y); Boolean cellLocked = _lockContainer.TryLock(position); if (cellLocked) { try { unit.SetPosition(position); } finally { _lockContainer.Unlock(position); } } return(cellLocked); }
void SetPosition(IPositionable entityToPosition, int mode) { var MousePosition = World.Get <STACK.Components.Mouse>().Position; entityToPosition.SetPosition(MousePosition, mode); }