Esempio n. 1
0
        public HumanAIController(Character c) : base(c)
        {
            steeringManager = new IndoorsSteeringManager(this, true);

            objectiveManager = new AIObjectiveManager(c);
            objectiveManager.AddObjective(new AIObjectiveFindSafety(c));
            objectiveManager.AddObjective(new AIObjectiveIdle(c));

            updateObjectiveTimer = Rand.Range(0.0f, UpdateObjectiveInterval);

            InitProjSpecific();
        }
        public override void OnAttacked(Character attacker, float amount)
        {
            if (amount <= 0.0f)
            {
                return;
            }

            var enemy = attacker as Character;

            if (enemy == null || enemy == Character ||
                (enemy.SelectedCharacter == base.Character && enemy.AnimController.Anim == AnimController.Animation.CPR))
            {
                return;
            }



            objectiveManager.AddObjective(new AIObjectiveCombat(Character, enemy));

            //the objective in the manager is not necessarily the same as the one we just instantiated,
            //because the objective isn't added if there's already an identical objective in the manager
            var combatObjective = objectiveManager.GetObjective <AIObjectiveCombat>();

            combatObjective.MaxEnemyDamage = Math.Max(amount, combatObjective.MaxEnemyDamage);
        }
Esempio n. 3
0
        public HumanAIController(Character c) : base(c)
        {
            steeringManager = new IndoorsSteeringManager(this, true);

            objectiveManager = new AIObjectiveManager(c);
            objectiveManager.AddObjective(new AIObjectiveFindSafety(c));
            objectiveManager.AddObjective(new AIObjectiveIdle(c));

            updateObjectiveTimer = Rand.Range(0.0f, UpdateObjectiveInterval);

            if (GameMain.GameSession != null && GameMain.GameSession.CrewManager != null)
            {
                CurrentOrder = Order.PrefabList.Find(o => o.Name.ToLowerInvariant() == "dismissed");
                objectiveManager.SetOrder(CurrentOrder, "");
                GameMain.GameSession.CrewManager.SetCharacterOrder(Character, CurrentOrder);
            }
        }
Esempio n. 4
0
        public override void OnAttacked(IDamageable attacker, float amount)
        {
            if (amount <= 0.0f)
            {
                return;
            }

            var enemy = attacker as Character;

            if (enemy == null || enemy == Character)
            {
                return;
            }

            objectiveManager.AddObjective(new AIObjectiveCombat(Character, enemy));
        }
Esempio n. 5
0
        public override void OnAttacked(Character attacker, AttackResult attackResult)
        {
            float damage = attackResult.Damage;

            if (damage <= 0)
            {
                return;
            }
            if (ObjectiveManager.CurrentObjective is AIObjectiveFightIntruders)
            {
                return;
            }
            if (attacker == null || attacker.IsDead || attacker.Removed)
            {
                // Ignore damage from falling etc that we shouldn't react to.
                if (Character.LastDamageSource == null)
                {
                    return;
                }
                AddCombatObjective(AIObjectiveCombat.CombatMode.Retreat, Rand.Range(0.5f, 1f, Rand.RandSync.Unsynced));
            }
            else if (IsFriendly(attacker))
            {
                if (attacker.AnimController.Anim == Barotrauma.AnimController.Animation.CPR && attacker.SelectedCharacter == Character)
                {
                    // Don't attack characters that damage you while doing cpr, because let's assume that they are helping you.
                    // Should not cancel any existing ai objectives (so that if the character attacked you and then helped, we still would want to retaliate).
                    return;
                }
                if (!attacker.IsRemotePlayer && Character.Controlled != attacker && attacker.AIController != null && attacker.AIController.Enabled)
                {
                    // Don't retaliate on damage done by friendly ai, because we know that it's accidental
                    AddCombatObjective(AIObjectiveCombat.CombatMode.Retreat, Rand.Range(0.5f, 1f, Rand.RandSync.Unsynced));
                }
                else
                {
                    float currentVitality = Character.CharacterHealth.Vitality;
                    float dmgPercentage   = damage / currentVitality * 100;
                    if (dmgPercentage < currentVitality / 10)
                    {
                        // Don't retaliate on minor (accidental) dmg done by friendly characters
                        AddCombatObjective(AIObjectiveCombat.CombatMode.Retreat, Rand.Range(0.5f, 1f, Rand.RandSync.Unsynced));
                    }
                    else
                    {
                        AddCombatObjective(AIObjectiveCombat.CombatMode.Defensive, Rand.Range(0.5f, 1f, Rand.RandSync.Unsynced));
                    }
                }
            }
            else
            {
                AddCombatObjective(AIObjectiveCombat.CombatMode.Defensive);
            }

            void AddCombatObjective(AIObjectiveCombat.CombatMode mode, float delay = 0)
            {
                if (ObjectiveManager.CurrentObjective is AIObjectiveCombat combatObjective)
                {
                    if (combatObjective.Enemy != attacker || (combatObjective.Enemy == null && attacker == null))
                    {
                        // Replace the old objective with the new.
                        ObjectiveManager.Objectives.Remove(combatObjective);
                        objectiveManager.AddObjective(new AIObjectiveCombat(Character, attacker, mode, objectiveManager));
                    }
                }
                else
                {
                    if (delay > 0)
                    {
                        objectiveManager.AddObjective(new AIObjectiveCombat(Character, attacker, mode, objectiveManager), delay);
                    }
                    else
                    {
                        objectiveManager.AddObjective(new AIObjectiveCombat(Character, attacker, mode, objectiveManager));
                    }
                }
            }
        }
Esempio n. 6
0
        public override void OnAttacked(Character attacker, AttackResult attackResult)
        {
            float damage = attackResult.Damage;

            if (damage <= 0)
            {
                return;
            }
            if (attacker == null || attacker.IsDead || attacker.Removed)
            {
                if (objectiveManager.CurrentOrder == null)
                {
                    objectiveManager.GetObjective <AIObjectiveFindSafety>().Priority = 100;
                }
                return;
            }
            if (IsFriendly(attacker))
            {
                if (attacker.AnimController.Anim == Barotrauma.AnimController.Animation.CPR && attacker.SelectedCharacter == Character)
                {
                    // Don't attack characters that damage you while doing cpr, because let's assume that they are helping you.
                    // Should not cancel any existing ai objectives (so that if the character attacked you and then helped, we still would want to retaliate).
                    return;
                }
                if (!attacker.IsRemotePlayer && Character.Controlled != attacker && attacker.AIController != null && attacker.AIController.Enabled)
                {
                    // Don't react to damage done by friendly ai, because we know that it's accidental
                    if (objectiveManager.CurrentOrder == null)
                    {
                        objectiveManager.GetObjective <AIObjectiveFindSafety>().Priority = 100;
                    }
                    return;
                }
                float currentVitality = Character.CharacterHealth.Vitality;
                float dmgPercentage   = damage / currentVitality * 100;
                if (dmgPercentage < currentVitality / 10)
                {
                    // Don't react to a minor amount of (accidental) dmg done by friendly characters
                    if (objectiveManager.CurrentOrder == null)
                    {
                        objectiveManager.GetObjective <AIObjectiveFindSafety>().Priority = 100;
                    }
                }
                if (ObjectiveManager.CurrentObjective is AIObjectiveCombat combatObjective)
                {
                    if (combatObjective.Enemy != attacker)
                    {
                        // Replace the old objective with the new.
                        ObjectiveManager.Objectives.Remove(combatObjective);
                        objectiveManager.AddObjective(new AIObjectiveCombat(Character, attacker));
                    }
                }
                else
                {
                    objectiveManager.AddObjective(new AIObjectiveCombat(Character, attacker), Rand.Range(0.5f, 1f, Rand.RandSync.Unsynced));
                }
            }
            else
            {
                if (ObjectiveManager.CurrentObjective is AIObjectiveCombat combatObjective)
                {
                    if (combatObjective.Enemy != attacker)
                    {
                        // Replace the old objective with the new.
                        ObjectiveManager.Objectives.Remove(combatObjective);
                        objectiveManager.AddObjective(new AIObjectiveCombat(Character, attacker));
                    }
                }
                else
                {
                    objectiveManager.AddObjective(new AIObjectiveCombat(Character, attacker));
                }
            }
        }