/// <summary>
        /// Determines if damage was done by player.
        /// </summary>
        /// <param name="Damager">Provides player who did the damage. Null if damager object is not a player.</param>
        public static bool IsDoneByPlayer(this MyDamageInformation Damage, out IMyPlayer Damager)
        {
            Damager = null;
            try
            {
                IMyEntity AttackerEntity = MyAPIGateway.Entities.GetEntityById(Damage.AttackerId);
                if (AttackerEntity == null)
                {
                    AISessionCore.DebugWrite("Damage.IsDoneByPlayer", "Attacker entity was not found.", AntiSpam: false);
                    return(false);
                }

                if (AttackerEntity is IMyMeteor)
                {
                    return(false);
                }
                if (AttackerEntity is IMyWarhead)
                {
                    return(IsDamagedByPlayerWarhead(AttackerEntity as IMyWarhead, out Damager));
                }
                if (AttackerEntity is IMyGunBaseUser)
                {
                    return(IsDamagedByPlayer(AttackerEntity as IMyGunBaseUser, out Damager));
                }
                if (AttackerEntity is IMyEngineerToolBase)
                {
                    return(IsDamagedByPlayer(AttackerEntity as IMyEngineerToolBase, out Damager));
                }

                AttackerEntity = AttackerEntity.GetTopMostParent();

                if (AttackerEntity == null)
                {
                    AISessionCore.DebugWrite("Damage.IsDoneByPlayer", "Cannot acquire the attacker's topmost entity", AntiSpam: false);
                    return(false);
                }

                if (AttackerEntity is IMyCubeGrid)
                {
                    IMyCubeGrid Grid = AttackerEntity as IMyCubeGrid;
                    if (Grid.IsPirate())
                    {
                        return(false);
                    }
                    if (Grid.IsOwnedByNobody())
                    {
                        return(IsDamagedByPlayerInNeutralGrid(Grid, out Damager));
                    }

                    return(IsDamagedByPlayerGrid(Grid, out Damager));
                }

                return(false);
            }
            catch (Exception Scrap)
            {
                AISessionCore.LogError("Damage.IsDoneByPlayer", new Exception("General crash.", Scrap));
                return(false);
            }
        }
 public static void ProposePeace(this IMyFaction OurFaction, IMyFaction HostileFaction, bool Print = false)
 {
     MyAPIGateway.Session.Factions.SendPeaceRequest(OurFaction.FactionId, HostileFaction.FactionId);
     if (Print)
     {
         AISessionCore.DebugWrite($"{OurFaction.Tag}", $"Proposed peace to {HostileFaction.Tag}", AntiSpam: false);
     }
 }
 public static void DeclareWar(this IMyFaction OurFaction, IMyFaction HostileFaction, bool Print = false)
 {
     MyAPIGateway.Session.Factions.DeclareWar(OurFaction.FactionId, HostileFaction.FactionId);
     if (Print)
     {
         AISessionCore.DebugWrite($"{OurFaction.Tag}", $"Declared war on {HostileFaction.Tag}", AntiSpam: false);
     }
 }
 public static void AcceptPeace(this IMyFaction OurFaction, IMyFaction HostileFaction, bool Print = false)
 {
     MyAPIGateway.Session.Factions.AcceptPeace(HostileFaction.FactionId, OurFaction.FactionId);
     MyAPIGateway.Session.Factions.AcceptPeace(OurFaction.FactionId, HostileFaction.FactionId);
     if (Print)
     {
         AISessionCore.DebugWrite($"{OurFaction.Tag}", $"Accepted peace from {HostileFaction.Tag}", AntiSpam: false);
     }
 }
 static bool IsDamagedByPlayerWarhead(IMyWarhead Warhead, out IMyPlayer Damager)
 {
     Damager = null;
     try
     {
         if (Warhead.OwnerId == 0)
         {
             Damager = MyAPIGateway.Players.GetPlayerByID((Warhead as MyCubeBlock).BuiltBy);
             AISessionCore.DebugWrite("Damage.IsDoneByPlayer", "Attempting to find damager by neutral warhead.");
             return(Damager != null);
         }
         else
         {
             Damager = MyAPIGateway.Players.GetPlayerByID(Warhead.OwnerId);
             AISessionCore.DebugWrite("Damage.IsDoneByPlayer", "Attempting to find damager by warhead owner.");
             return(Damager != null);
         }
     }
     catch (Exception Scrap)
     {
         AISessionCore.LogError("Damage.IsDoneByPlayer", new Exception("Check for neutral warheads crashed", Scrap));
         return(false);
     }
 }