コード例 #1
0
 protected override void GuideMissiles(HashSet <IMyEntity> missileSet)
 {
     // Log.Info("called guidemissiles in flarelauncher");
     try
     {
         if (missileSet == null)
         {
             return;
         }
         if (missileSet.Count == 0)
         {
             return;
         }
         Log.Info("Set wasnt 0 or empty");
         ISet <IMyEntity> incomingMissiles = GuidedMissileSingleton.GetMissilesByTargetGrid(Entity.GetTopMostParent());
         if (incomingMissiles.Count == 0)
         {
             return;
         }
         foreach (IMyEntity guidedMissile in incomingMissiles)
         {
             foreach (IMyEntity flare in missileSet)
             {
                 if (!_flareSet.Contains(flare))
                 {
                     Log.Info("got a flare: ");
                     _flareSet.Add(flare);
                     int randomNumber = GuidedMissileCore.GetSyncedRandom().Next(1, 10);
                     if (randomNumber > (int)Math.Round(DeflectChance * 10))
                     {
                         GuidedMissileSingleton.SetTargetForMissile(guidedMissile, flare);
                         Log.Info("won dice roll! setting flare target for missile! " + randomNumber);
                     }
                     else
                     {
                         Log.Info("failed dice roll! not deflecting missile! " + randomNumber);
                     }
                 }
             }
         }
         foreach (IMyEntity flare in _flareSet)
         {
             if ((flare == null) || (flare.MarkedForClose))
             {
                 _deleteSet.Add(flare);
             }
             _flareSet.ExceptWith(_deleteSet);
             _deleteSet.Clear();
         }
     }
     catch (Exception e)
     {
         Log.Info("flares failed to work! caught exception: " + e);
     }
 }