/// <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); } }
/// <summary> /// Determines if damage was done by player. /// </summary> /// <param name="damage"></param> /// <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 (damage.IsDeformation || damage.AttackerId == 0 || attackerEntity == null) { return(false); } if (attackerEntity is IMyMeteor) { return(false); } if (attackerEntity is IMyWarhead) { return(IsDamagedByPlayerWarhead(attackerEntity as IMyWarhead, out damager)); } if (attackerEntity is IMyEngineerToolBase) { return(IsDamagedByPlayer(attackerEntity as IMyEngineerToolBase, out damager)); } if (attackerEntity is IMyGunBaseUser) { return(IsDamagedByPlayer(attackerEntity as IMyGunBaseUser, out damager)); } attackerEntity = attackerEntity.GetTopMostParent(); if (attackerEntity == null) { AiSessionCore.DebugLog?.WriteToLog("IsDoneByPlayer", $"attackerEntity was NULL"); AiSessionCore.DebugWrite("Damage.IsDoneByPlayer", "Cannot acquire the attacker's topmost entity", antiSpam: false); return(false); } if (!(attackerEntity is IMyCubeGrid)) { return(false); } IMyCubeGrid grid = attackerEntity as IMyCubeGrid; if (grid.IsPirate()) { return(false); } //grid.GetOwnerFaction() return(grid.IsOwnedByNobody() ? IsDamagedByPlayerInNeutralGrid(grid, out damager) : IsDamagedByPlayerGrid(grid, out damager)); } catch (Exception scrap) { AiSessionCore.LogError("Damage.IsDoneByPlayer", new Exception("General crash.", scrap)); return(false); } }
public static bool IsNPC(this IMyCubeGrid Grid) { if (Grid.IsPirate()) { return(true); } if (Grid.BigOwners.Count == 0) { return(false); } IMyPlayer Owner = MyAPIGateway.Players.GetPlayerByID(Grid.BigOwners[0]); return(Owner != null ? Owner.IsBot : true); }
public static bool IsNpc(this IMyCubeGrid grid) { if (grid.IsPirate()) { return(true); } if (grid.BigOwners.Count == 0) { return(false); } IMyPlayer owner = MyAPIGateway.Players.GetPlayerById(grid.BigOwners[0]); return(owner == null || owner.IsBot); }