Ejemplo n.º 1
0
        /// <summary>
        /// Stops shooting at any current target and sets <paramref name="newTarget"/> as the target of this Shooter if the <paramref name="newTarget"/> is in range of this shooter.
        /// </summary>
        /// <param name="newTarget">New target to try shooting at.</param>
        /// <returns>True if <paramref name="newTarget"/> is in range, false otherwise.</returns>
        public bool ShootAt(IRangeTarget newTarget)
        {
            StopShooting();

            if (!CanShootAt(newTarget))
            {
                return(false);
            }

            Target = newTarget;
            newTarget.AddShooter(this);
            return(true);
        }
Ejemplo n.º 2
0
        IRangeTarget SetExplicitTarget(IEntity targetEntity)
        {
            IRangeTarget target = targetEntity.GetDefaultComponent <RangeTargetComponent>();

            if (target == null)
            {
                return(null);
            }

            ResetExplicitTarget();

            explicitTarget      = target;
            target.TargetMoved += ExplicitTargetMoved;
            target.AddShooter(this);

            return(target);
        }
Ejemplo n.º 3
0
        void SearchTarget(float timeStep)
        {
            if (!SearchForTarget)
            {
                return;
            }

            if (searchDelay >= 0)
            {
                searchDelay -= timeStep;
                return;
            }

            if (Target == null && searchDelay < 0)
            {
                searchDelay = TargetSearchDelay;

                //Check for target in range
                var possibleTargets = Player.GetEnemyPlayers()
                                      .SelectMany(enemy => enemy.GetAllUnits())
                                      //.AsParallel()
                                      .Where(unit => projectileType.IsInRange(Entity.Position, unit.GetDefaultComponent <RangeTargetComponent>()))
                                      .OrderBy(unit => Vector3.Distance(Entity.Position, unit.Position));


                foreach (var possibleTarget in possibleTargets)
                {
                    var newTarget = possibleTarget.GetDefaultComponent <RangeTargetComponent>();

                    Target = newTarget;
                    Target.AddShooter(this);
                    InvokeOnTargetAcquired();
                    break;
                }
            }
        }