Ejemplo n.º 1
1
        public override void DoImpact(Target target, Actor firedBy, IEnumerable<int> damageModifiers)
        {
            if (!target.IsValidFor(firedBy))
                return;

            var pos = target.CenterPosition;
            var world = firedBy.World;
            var targetTile = world.Map.CellContaining(pos);
            var isValid = IsValidImpact(pos, firedBy);

            if ((!world.Map.Contains(targetTile)) || (!isValid))
                return;

            var palette = ExplosionPalette;
            if (UsePlayerPalette)
                palette += firedBy.Owner.InternalName;

            var explosion = Explosions.RandomOrDefault(Game.CosmeticRandom);
            if (Image != null && explosion != null)
                world.AddFrameEndTask(w => w.Add(new SpriteEffect(pos, w, Image, explosion, palette)));

            var impactSound = ImpactSounds.RandomOrDefault(Game.CosmeticRandom);
            if (impactSound != null)
                Game.Sound.Play(impactSound, pos);
        }
Ejemplo n.º 2
0
        public Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued )
        {
            if( order.OrderID == "Unload" )
                return new Order( order.OrderID, self, queued );

            return null;
        }
Ejemplo n.º 3
0
        public void GuardTarget(Actor self, Target target)
        {
            self.SetTargetLine(target, Color.Yellow);

            var range = WDist.FromCells(target.Actor.Info.Traits.Get<GuardableInfo>().Range);
            self.QueueActivity(false, new AttackMoveActivity(self, self.Trait<IMove>().MoveFollow(self, target, WDist.Zero, range)));
        }
Ejemplo n.º 4
0
 public override IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove)
 {
     var weapon = ChooseWeaponForTarget(newTarget);
     if( weapon == null )
         return null;
     return new Activities.Heal(newTarget, Math.Max(0, (int)weapon.Info.Range), allowMove);
 }
Ejemplo n.º 5
0
 public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove)
 {
     var weapon = ChooseArmamentForTarget(newTarget);
     if (weapon == null)
         return null;
     return new Activities.Attack(newTarget, Math.Max(0, (int)weapon.Weapon.Range), allowMove);
 }
Ejemplo n.º 6
0
		public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
		{
			if (order.OrderID == "SetRallyPoint")
				return new Order(order.OrderID, self, false) { TargetLocation = self.World.Map.CellContaining(target.CenterPosition), SuppressVisualFeedback = true };

			return null;
		}
Ejemplo n.º 7
0
 public IonCannon(Actor firedBy, World world, CPos location)
 {
     this.firedBy = firedBy;
     target = Target.FromCell(location);
     anim = new Animation("ionsfx");
     anim.PlayThen("idle", () => Finish(world));
 }
Ejemplo n.º 8
0
 public HeliAttack(Actor self, Target target)
 {
     this.target = target;
     helicopter = self.Trait<Helicopter>();
     attackHeli = self.Trait<AttackHeli>();
     ammoPools = self.TraitsImplementing<AmmoPool>().ToArray();
 }
Ejemplo n.º 9
0
        protected override bool CanAttack(Actor self, Target target)
        {
            if (!target.IsValidFor(self))
                return false;

            return base.CanAttack(self, target);
        }
Ejemplo n.º 10
0
 protected Enter(Actor self, Actor target, int maxTries = 1, bool targetCenter = false)
 {
     this.move = self.Trait<IMove>();
     this.target = Target.FromActor(target);
     this.maxTries = maxTries;
     this.targetCenter = targetCenter;
 }
Ejemplo n.º 11
0
        public Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued )
        {
            if( order.OrderID == "SetRallyPoint" )
                return new Order(order.OrderID, self, false) { TargetLocation = target.CenterPosition.ToCPos() };

            return null;
        }
Ejemplo n.º 12
0
		public FlyFollow(Actor self, Target target, WDist minRange, WDist maxRange)
		{
			this.target = target;
			plane = self.Trait<Aircraft>();
			this.minRange = minRange;
			this.maxRange = maxRange;
		}
Ejemplo n.º 13
0
		public override void DoImpact(Target target, Actor firedBy, IEnumerable<int> damageModifiers)
		{
			var actors = target.Type == TargetType.Actor ? new[] { target.Actor } :
				firedBy.World.FindActorsInCircle(target.CenterPosition, Range);

			foreach (var a in actors)
			{
				// Don't do anything on friendly fire
				if (a.Owner == firedBy.Owner)
					continue;

				if (Duration == 0)
					a.ChangeOwner(firedBy.Owner); // Permanent
				else
				{
					var tempOwnerManager = a.TraitOrDefault<TemporaryOwnerManager>();
					if (tempOwnerManager == null)
						continue;

					tempOwnerManager.ChangeOwner(a, firedBy.Owner, Duration);
				}

				// Stop shooting, you have new enemies
				a.CancelActivity();
			}
		}
Ejemplo n.º 14
0
		protected bool TryGetAlternateTargetInCircle(
			Actor self, WDist radius, Action<Target> update, Func<Actor, bool> primaryFilter, Func<Actor, bool>[] preferenceFilters = null)
		{
			var diff = new WVec(radius, radius, WDist.Zero);
			var candidates = self.World.ActorMap.ActorsInBox(self.CenterPosition - diff, self.CenterPosition + diff)
				.Where(primaryFilter).Select(a => new { Actor = a, Ls = (self.CenterPosition - a.CenterPosition).HorizontalLengthSquared })
				.Where(p => p.Ls <= radius.LengthSquared).OrderBy(p => p.Ls).Select(p => p.Actor);
			if (preferenceFilters != null)
				foreach (var filter in preferenceFilters)
				{
					var preferredCandidate = candidates.FirstOrDefault(filter);
					if (preferredCandidate == null)
						continue;
					target = Target.FromActor(preferredCandidate);
					update(target);
					return true;
				}

			var candidate = candidates.FirstOrDefault();
			if (candidate == null)
				return false;
			target = Target.FromActor(candidate);
			update(target);
			return true;
		}
Ejemplo n.º 15
0
 public ExternalCaptureActor(Actor self, Target target)
 {
     this.target = target;
     capturable = target.Actor.Trait<ExternalCapturable>();
     capturesInfo = self.Info.TraitInfo<ExternalCapturesInfo>();
     mobile = self.Trait<Mobile>();
 }
Ejemplo n.º 16
0
        public Order IssueOrder( Actor self, IOrderTargeter order, Target target )
        {
            if( order.OrderID == "Disguise" )
                return new Order( order.OrderID, self, target.Actor );

            return null;
        }
Ejemplo n.º 17
0
        protected override bool CanAttack(Actor self, Target target)
        {
            if (!IsReachableTarget(target, true))
                return false;

            return base.CanAttack(self, target);
        }
Ejemplo n.º 18
0
		public override void DoImpact(Target target, Actor firedBy, IEnumerable<int> damageModifiers)
		{
			var actors = target.Type == TargetType.Actor ? new[] { target.Actor } :
				firedBy.World.FindActorsInCircle(target.CenterPosition, Range);

			foreach (var a in actors)
			{
				if (!IsValidAgainst(a, firedBy))
					continue;

				var um = a.TraitOrDefault<UpgradeManager>();
				if (um == null)
					continue;

				foreach (var u in Upgrades)
				{
					if (Duration > 0)
					{
						if (um.AcknowledgesUpgrade(a, u))
							um.GrantTimedUpgrade(a, u, Duration, firedBy, Upgrades.Count(upg => upg == u));
					}
					else
					{
						if (um.AcceptsUpgrade(a, u))
							um.GrantUpgrade(a, u, this);
					}
				}
			}
		}
Ejemplo n.º 19
0
		// TODO: Allow maximum resource splatter to be defined. (Per tile, and in total).
		public override void DoImpact(Target target, Actor firedBy, IEnumerable<int> damageModifiers)
		{
			if (string.IsNullOrEmpty(AddsResourceType))
				return;

			var world = firedBy.World;
			var targetTile = world.Map.CellContaining(target.CenterPosition);
			var resLayer = world.WorldActor.Trait<ResourceLayer>();

			var minRange = (Size.Length > 1 && Size[1] > 0) ? Size[1] : 0;
			var allCells = world.Map.FindTilesInAnnulus(targetTile, minRange, Size[0]);

			var resourceType = world.WorldActor.TraitsImplementing<ResourceType>()
				.FirstOrDefault(t => t.Info.Name == AddsResourceType);

			if (resourceType == null)
				Log.Write("debug", "Warhead defines an invalid resource type '{0}'".F(AddsResourceType));
			else
			{
				foreach (var cell in allCells)
				{
					if (!resLayer.CanSpawnResourceAt(resourceType, cell))
						continue;

					var splash = world.SharedRandom.Next(1, resourceType.Info.MaxDensity - resLayer.GetResourceDensity(cell));
					resLayer.AddResource(resourceType, cell, splash);
				}
			}
		}
Ejemplo n.º 20
0
        public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
        {
            if (order.OrderID == "ChronoshiftJump" && chargeTick <= 0)
                self.World.OrderGenerator = new ChronoTankOrderGenerator(self);

            return new Order("ChronoshiftJump", self, false); // Hack until we can return null
        }
Ejemplo n.º 21
0
        public override void ResolveOrder(Actor self, Order order)
        {
            base.ResolveOrder(self, order);

            if (order.OrderString == "Stop")
                target = Target.None;
        }
Ejemplo n.º 22
0
        public override void DoImpact(Target target, Actor firedBy, IEnumerable<int> damageModifiers)
        {
            var world = firedBy.World;
            var targetTile = world.Map.CellContaining(target.CenterPosition);
            var smudgeLayers = world.WorldActor.TraitsImplementing<SmudgeLayer>().ToDictionary(x => x.Info.Type);

            var minRange = (Size.Length > 1 && Size[1] > 0) ? Size[1] : 0;
            var allCells = world.Map.FindTilesInAnnulus(targetTile, minRange, Size[0]);

            // Draw the smudges:
            foreach (var sc in allCells)
            {
                var smudgeType = world.Map.GetTerrainInfo(sc).AcceptsSmudgeType.FirstOrDefault(SmudgeType.Contains);
                if (smudgeType == null)
                    continue;

                var cellActors = world.ActorMap.GetActorsAt(sc);
                if (cellActors.Any(a => !IsValidAgainst(a, firedBy)))
                    continue;

                SmudgeLayer smudgeLayer;
                if (!smudgeLayers.TryGetValue(smudgeType, out smudgeLayer))
                    throw new NotImplementedException("Unknown smudge type `{0}`".F(smudgeType));

                smudgeLayer.AddSmudge(sc);
            }
        }
Ejemplo n.º 23
0
 public FlyAttack(Actor self, Target target)
 {
     this.target = target;
     attackPlane = self.TraitOrDefault<AttackPlane>();
     ammoPools = self.TraitsImplementing<AmmoPool>().ToArray();
     ticksUntilTurn = attackPlane.AttackPlaneInfo.AttackTurnDelay;
 }
Ejemplo n.º 24
0
        public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
        {
            if (order.OrderID == "DeliverSupplies")
                return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };

            return null;
        }
Ejemplo n.º 25
0
        public Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued )
        {
            if( order.OrderID == "EnterTransport" )
                return new Order( order.OrderID, self, target.Actor, queued );

            return null;
        }
Ejemplo n.º 26
0
 public Repair(Actor self, Actor host, WDist closeEnough)
 {
     this.host = Target.FromActor(host);
     this.closeEnough = closeEnough;
     repairsUnits = host.Info.TraitInfo<RepairsUnitsInfo>();
     health = self.TraitOrDefault<Health>();
 }
Ejemplo n.º 27
0
		public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
		{
			if (order.OrderID == "DeployTransform")
				return new Order(order.OrderID, self, queued);

			return null;
		}
Ejemplo n.º 28
0
		public bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
		{
			var type = target.Type;
			if (type != TargetType.Actor && type != TargetType.FrozenActor)
				return false;

			cursor = this.cursor;
			IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);

			if (ForceAttack != null && modifiers.HasModifier(TargetModifiers.ForceAttack) != ForceAttack)
				return false;

			var owner = type == TargetType.FrozenActor ? target.FrozenActor.Owner : target.Actor.Owner;
			var playerRelationship = self.Owner.Stances[owner];

			if (!modifiers.HasModifier(TargetModifiers.ForceAttack) && playerRelationship == Stance.Ally && !targetAllyUnits)
				return false;

			if (!modifiers.HasModifier(TargetModifiers.ForceAttack) && playerRelationship == Stance.Enemy && !targetEnemyUnits)
				return false;

			return type == TargetType.FrozenActor ?
				CanTargetFrozenActor(self, target.FrozenActor, modifiers, ref cursor) :
				CanTargetActor(self, target.Actor, modifiers, ref cursor);
		}
Ejemplo n.º 29
0
        public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
        {
            if (order.OrderID == "RepairBridge")
                return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };

            return null;
        }
Ejemplo n.º 30
0
		public FlyFollow(Actor self, Target target, WRange minRange, WRange maxRange)
		{
			this.target = target;
			plane = self.Trait<Plane>();
			this.minRange = minRange;
			this.maxRange = maxRange;
		}
Ejemplo n.º 31
0
 void INotifyAttack.PreparingAttack(Actor self, OpenRA.Traits.Target target, Armament a, Barrel barrel)
 {
 }