Example #1
0
        virtual protected void ReactOnDamage(IMySlimBlock Block, MyDamageInformation Damage, TimeSpan TruceDelay, out IMyPlayer Damager)
        {
            Damager = null;
            try
            {
                if (Damage.IsMeteor())
                {
                    Grid.DebugWrite("ReactOnDamage", "Grid was damaged by meteor. Ignoring.");
                    return;
                }

                if (Damage.IsThruster())
                {
                    if (Block != null && !Block.IsDestroyed)
                    {
                        Grid.DebugWrite("ReactOnDamage", "Grid was slighly damaged by thruster. Ignoring.");
                        return;
                    }
                }

                try
                {
                    if (Damage.IsDoneByPlayer(out Damager) && Damager != null)
                    {
                        try
                        {
                            Grid.DebugWrite("ReactOnDamage", $"Grid is damaged by player {Damager.DisplayName}. Trying to activate alert.");
                            RegisterHostileAction(Damager, TruceDelay);
                        }
                        catch (Exception Scrap)
                        {
                            Grid.LogError("ReactOnDamage.GetDamagerFaction", Scrap);
                        }
                    }
                    else
                    {
                        Grid.DebugWrite("ReactOnDamage", "Grid is damaged, but damage source is not recognized as player.");
                    }
                }
                catch (Exception Scrap)
                {
                    Grid.LogError("ReactOnDamage.IsDamageDoneByPlayer", Scrap);
                }
            }
            catch (Exception Scrap)
            {
                Grid.LogError("ReactOnDamage", Scrap);
            }
        }
        private void DamageHandler(IMySlimBlock block, MyDamageInformation damage)
        {
            if (block == null)
            {
                return;
            }
            if (!block.IsDestroyed && damage.IsThruster())
            {
                return;
            }
            IMyPlayer damager;

            ReactOnDamage(damage, out damager);
            if (damager != null)
            {
                OnAlert();
            }
        }
Example #3
0
        private void DamageHandler(IMySlimBlock Block, MyDamageInformation Damage)
        {
            if (Block == null)
            {
                return;
            }
            if (!Block.IsDestroyed && Damage.IsThruster())
            {
                return;
            }
            IMyPlayer Damager;

            ReactOnDamage(Block, Damage, CalmdownTime, out Damager);
            if (Damager != null)
            {
                OnAlert();
            }
        }
Example #4
0
        //public virtual void RecompilePBs()
        //{
        //	foreach (IMyProgrammableBlock pb in Term.GetBlocksOfType<IMyProgrammableBlock>())
        //	{
        //		MyAPIGateway.Utilities.InvokeOnGameThread(() => { pb.Recompile(); });
        //	}
        //}

        protected void ReactOnDamage(MyDamageInformation damage, out IMyPlayer damager)
        {
            damager = null;
            try
            {
                // Inconsequential damage sources, ignore them
                if (damage.IsDeformation || damage.IsMeteor() || damage.IsThruster())
                {
                    return;
                }
                if (damage.IsDoneByPlayer(out damager) && damager != null)
                {
                    if (damager.GetFaction() == null)
                    {
                        return;
                    }
                }
                DeclareWar(damager.GetFaction());
            }
            catch (Exception scrap)
            {
                Grid.LogError("ReactOnDamage", scrap);
            }
        }
Example #5
0
        //public virtual void RecompilePBs()
        //{
        //	foreach (IMyProgrammableBlock pb in Term.GetBlocksOfType<IMyProgrammableBlock>())
        //	{
        //		MyAPIGateway.Utilities.InvokeOnGameThread(() => { pb.Recompile(); });
        //	}
        //}

        protected void ReactOnDamage(MyDamageInformation damage, out IMyPlayer damager)
        {
            damager = null;
            try
            {
                AiSessionCore.DebugLog?.WriteToLog("ReactOnDamage", $"damage.AttackerId:\t{damage.AttackerId}");

                // Inconsequential damage sources, ignore them
                if (damage.IsDeformation || damage.IsMeteor() || damage.IsThruster())
                {
                    return;
                }

                //if (damage.IsDoneByPlayer(out damager) && damager != null)
                //	if (damager.GetFaction() == null) return;

                if (damage.IsDoneByPlayer(out damager))
                {
                    if (damager.GetFaction() == null)
                    {
                        return;
                    }
                    DeclareWar(damager.GetFaction());
                    return;
                }

                // Issue here is damager == null at this point.  Damager is IMyPlayer
                // Since damager == null, DeclareWar fails.
                // Need to check for damager == null here, if so, get pilot and declare war on them if they are in a faction

                List <IMyPlayer> possibleAttackingPlayers = new List <IMyPlayer>();
                MyAPIGateway.Players.GetPlayers(possibleAttackingPlayers,
                                                player =>
                                                player.Controller.ControlledEntity.Entity != null &&
                                                !player.IsBot &&
                                                player.Character != null &&
                                                player.Controller.ControlledEntity.Entity is IMyShipController);
                foreach (IMyPlayer possibleAttackingPlayer in possibleAttackingPlayers)
                {
                    if (((IMyShipController)possibleAttackingPlayer.Controller.ControlledEntity.Entity).SlimBlock.CubeGrid !=
                        MyAPIGateway.Entities.GetEntityById(damage.AttackerId))
                    {
                        continue;
                    }
                    damager = possibleAttackingPlayer;
                    IMyFaction attackingFaction = MyAPIGateway.Session.Factions.TryGetPlayerFaction(possibleAttackingPlayer.IdentityId);
                    if (attackingFaction == null)
                    {
                        continue;
                    }
                    DeclareWar(attackingFaction);
                }

                //HashSet<IMyEntity> possibleAttackingPlayers2 = new HashSet<IMyEntity>();
                //MyAPIGateway.Entities.GetEntities(possibleAttackingPlayers2, entity => entity is IMyShipController);
                //AiSessionCore.DebugLog?.WriteToLog("ReactOnDamage", $"EntListSize:\t{possibleAttackingPlayers2.Count}");

                //foreach (IMyPlayer possibleAttackingPlayer in possibleAttackingPlayers)
                //	AiSessionCore.DebugLog?.WriteToLog("ReactOnDamage", $"player:\t{possibleAttackingPlayer?.IdentityId}\t{possibleAttackingPlayer?.DisplayName}");

                //foreach (IMyEntity possibleAttackingPlayer in possibleAttackingPlayers2)
                //	AiSessionCore.DebugLog?.WriteToLog("ReactOnDamage", $"Entity:\t{possibleAttackingPlayer?.EntityId}\t{possibleAttackingPlayer?.DisplayName}");

                //AiSessionCore.DebugLog?.WriteToLog("ReactOnDamage", $"damage:\t{damage}");
                //AiSessionCore.DebugLog?.WriteToLog("ReactOnDamage", $"damage.Amount:\t{damage.Amount}");
                //AiSessionCore.DebugLog?.WriteToLog("ReactOnDamage", $"damage.AttackerId:\t{damage.AttackerId}");
                //AiSessionCore.DebugLog?.WriteToLog("ReactOnDamage", $"damage.Type:\t{damage.Type}");
                //AiSessionCore.DebugLog?.WriteToLog("ReactOnDamage", $"damager.IsNull:\t{damager == null}");
                //AiSessionCore.DebugLog?.WriteToLog("ReactOnDamage", $"damager.GetFaction()\t{damager?.GetFaction()}");
                //AiSessionCore.DebugLog?.WriteToLog("ReactOnDamage", $"damager.GetFactionIsNull()\t{damager?.GetFaction() == null}");
            }
            catch (Exception scrap)
            {
                Grid.LogError("ReactOnDamage", scrap);
            }
        }