Пример #1
0
        protected virtual IMyEntity GetTarget(IMyEntity missile)
        {
            IMyEntity targetGrid = GuidedMissileTargetGridHook.GetMissileTargetForGrid(Entity.GetTopMostParent());
            IMyEntity target     = GuidedMissileTargetGridHook.GetRandomBlockInGrid(targetGrid);

            if (target == null)
            {
                target = targetGrid;
            }
            return(target);
        }
Пример #2
0
 public bool IsExpired()
 {
     if (Missile == null)
     {
         return(true);
     }
     if (Target == null)
     {
         return(true);
     }
     if (Missile.MarkedForClose)
     {
         _onExplode(Missile);
         return(true);
     }
     if (TrackedFrames > _deathTimer)
     {
         Missile.Close();
         return(true);
     }
     if (Target.MarkedForClose)
     {
         // Log.Info("Target is marked for close, searching new one");
         if (Target.GetTopMostParent().MarkedForClose)
         {
             return(true);
         }
         IMyEntity newTarget = GuidedMissileTargetGridHook.GetRandomBlockInGrid(Target);
         if (newTarget == null)
         {
             return(true);
         }
         Target                = newTarget;
         _isOvershooting       = false;
         _overshootDistance    = 0f;
         _finishedOvershooting = false;
         return(false);
         //  return true;
     }
     return(false);
 }
        protected override IMyEntity GetTarget(IMyEntity missile)
        {
            //IMyEntity targetGrid = GuidedMissileTargetGridHook.GetMissileTargetForGrid(Entity.GetTopMostParent());


            Ray       ray        = new Ray(missile.GetPosition(), Vector3.Normalize(missile.WorldMatrix.Forward));
            IMyEntity targetGrid = GuidedMissileCore.GetClosestTargetAlongRay(ray, 3000, 7, Entity.GetTopMostParent());
            IMyEntity target     = GuidedMissileTargetGridHook.GetRandomBlockInGrid(targetGrid);

            if (target == null)
            {
                //  Log.Info("target was null...");
                //   if (targetGrid == null) Log.Info("targetgrid was null as well!");
                target = targetGrid;
                Log.Info("target was null, now set to grid");
                //  IMyEntity grid = target;
            }

            //  Log.Info("got a target: " + target.ToString());

            if (target != null)
            {
                IMyPlayerCollection allPlayers = MyAPIGateway.Players;

                List <IMyPlayer> playerList = new List <IMyPlayer>();

                HashSet <IMyEntity> componentSet = new HashSet <IMyEntity>();

                Entity.GetTopMostParent().Hierarchy.GetChildrenRecursive(componentSet);
                List <IMyEntity> componentList = new List <IMyEntity>();
                componentList.AddRange(componentSet);

                allPlayers.GetPlayers(playerList);
                componentSet.Clear();


                foreach (IMyEntity component in componentList)
                {
                    if (component is IMyCockpit)
                    {
                        componentSet.Add(component);
                    }
                }

                foreach (IMyPlayer player in playerList)
                {
                    if (MyAPIGateway.Session.Player == player)
                    {
                        if ((player != null) && (player.Controller != null) && (player.Controller.ControlledEntity != null) && (player.Controller.ControlledEntity.Entity != null))
                        {
                            foreach (IMyEntity entity in componentSet)
                            {
                                if (player.Controller.ControlledEntity.Entity.EntityId == entity.EntityId)
                                {
                                    MyAPIGateway.Utilities.ShowNotification("" + target.GetTopMostParent().DisplayName + " was set as missile target!", 2000, MyFontEnum.Red);
                                }
                            }
                        }
                    }
                }
            }
            return(target);
        }