Example #1
0
		void ITick.Tick(Actor self)
		{
			var wasInAttackRange = inAttackRange;
			inAttackRange = false;

			if (self.IsInWorld)
			{
				var dat = self.World.Map.DistanceAboveTerrain(target.CenterPosition);
				target = Target.FromPos(target.CenterPosition - new WVec(WDist.Zero, WDist.Zero, dat));

				var wasFacingTarget = facingTarget;
				facingTarget = TargetInFiringArc(self, target, 4 * info.FacingTolerance);

				foreach (var a in Armaments)
				{
					if (!target.IsInRange(self.CenterPosition, a.MaxRange()))
						continue;

					inAttackRange = true;
					a.CheckFire(self, facing, target);
				}

				// Actors without armaments may want to trigger an action when it passes the target
				if (!Armaments.Any())
					inAttackRange = !wasInAttackRange && !facingTarget && wasFacingTarget;
			}

			if (inAttackRange && !wasInAttackRange)
				OnEnteredAttackRange(self);

			if (!inAttackRange && wasInAttackRange)
				OnExitedAttackRange(self);
		}
Example #2
0
        public void Tick(Actor self)
        {
            var cp               = self.CenterPosition;
            var bombTarget       = Target.FromPos(cp - new WVec(0, 0, cp.Z));
            var wasInAttackRange = inAttackRange;
            var wasFacingTarget  = facingTarget;

            inAttackRange = false;

            var f              = facing.Value.Facing;
            var delta          = target.CenterPosition - self.CenterPosition;
            var facingToTarget = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : f;

            facingTarget = Math.Abs(facingToTarget - f) % 256 <= info.FacingTolerance;

            // Bombs drop anywhere in range
            foreach (var a in Armaments.Where(a => a.Info.Name == info.Bombs))
            {
                if (!target.IsInRange(self.CenterPosition, a.MaxRange()))
                {
                    continue;
                }

                inAttackRange = true;
                a.CheckFire(self, facing.Value, bombTarget);
            }

            // Guns only fire when approaching the target
            if (facingTarget)
            {
                foreach (var a in Armaments.Where(a => a.Info.Name == info.Guns))
                {
                    if (!target.IsInRange(self.CenterPosition, a.MaxRange()))
                    {
                        continue;
                    }

                    var t = Target.FromPos(cp - new WVec(0, a.MaxRange().Length / 2, cp.Z).Rotate(WRot.FromFacing(f)));
                    inAttackRange = true;
                    a.CheckFire(self, facing.Value, t);
                }
            }

            // Actors without armaments may want to trigger an action when it passes the target
            if (!Armaments.Any())
            {
                inAttackRange = !wasInAttackRange && !facingTarget && wasFacingTarget;
            }

            if (inAttackRange && !wasInAttackRange)
            {
                OnEnteredAttackRange(self);
            }

            if (!inAttackRange && wasInAttackRange)
            {
                OnExitedAttackRange(self);
            }
        }
Example #3
0
        public WRange GetMaximumRange()
        {
            if (!Armaments.Any())
            {
                return(WRange.Zero);
            }

            return(Armaments.Max(a => a.Weapon.Range));
        }
Example #4
0
        public bool HasAnyValidWeapons(Target t)
        {
            if (IsTraitDisabled)
            {
                return(false);
            }

            if (Info.AttackRequiresEnteringCell && !positionable.Value.CanEnterCell(t.Actor.Location, null, false))
            {
                return(false);
            }

            return(Armaments.Any(a => a.Weapon.IsValidAgainst(t, self.World, self)));
        }
Example #5
0
        void ITick.Tick(Actor self)
        {
            var dat = self.World.Map.DistanceAboveTerrain(target.CenterPosition);

            target = Target.FromPos(target.CenterPosition - new WVec(WDist.Zero, WDist.Zero, dat));
            var wasInAttackRange = inAttackRange;
            var wasFacingTarget  = facingTarget;

            inAttackRange = false;

            var f              = facing.Facing;
            var delta          = target.CenterPosition - self.CenterPosition;
            var facingToTarget = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : f;

            facingTarget = Math.Abs(facingToTarget - f) % 256 <= info.FacingTolerance;

            foreach (var a in Armaments)
            {
                if (!target.IsInRange(self.CenterPosition, a.MaxRange()))
                {
                    continue;
                }

                inAttackRange = true;
                a.CheckFire(self, facing, target);
            }

            // Actors without armaments may want to trigger an action when it passes the target
            if (!Armaments.Any())
            {
                inAttackRange = !wasInAttackRange && !facingTarget && wasFacingTarget;
            }

            if (inAttackRange && !wasInAttackRange)
            {
                OnEnteredAttackRange(self);
            }

            if (!inAttackRange && wasInAttackRange)
            {
                OnExitedAttackRange(self);
            }
        }
Example #6
0
 public bool HasAnyValidWeapons(Target t)
 {
     return(Armaments.Any(a => a.Weapon.IsValidAgainst(t, self.World)));
 }