Пример #1
0
        public void AddFact_should_add_a_fact_to_the_Facts_collection()
        {
            // arrange
            var fact = new Fact();

            // act
            _workingMemory.AddFact(fact);

            // assert
            Assert.Contains(fact, _workingMemory.Facts);
        }
Пример #2
0
        public void AddFact(string assertion)
        {
            var fact = new Fact()
            {
                Assertion = assertion
            };

            _workingMemory.AddFact(fact);
        }
Пример #3
0
    /*
     * public bool GetTargetHittability(Character target)
     * {
     *      GameObject myEyes = _parentCharacter.MyReference.Eyes;
     *      RaycastHit hit;
     *      float colliderHeight = target.GetComponent<CapsuleCollider>().height;
     *      Vector3 rayTarget = target.transform.position + Vector3.up * colliderHeight * 0.75f;
     *      Ray ray = new Ray(myEyes.transform.position, rayTarget - myEyes.transform.position);
     *      if(Physics.Raycast(ray, out hit))
     *      {
     *              //Debug.Log("raycast hit in sensor: " + hit.collider.name);
     *              Character hitCharacter = hit.collider.GetComponent<Character>();
     *              if(hitCharacter == target)
     *              {
     *                      return true;
     *              }
     *      }
     *      else
     *      {
     *              return false;
     *      }
     *
     *      return false;
     * }
     */

    public void OnTakingDamage(Character attacker)
    {
        if (_parentCharacter.MyAI.ControlType == AIControlType.Player)
        {
            return;
        }

        CsDebug.Inst.CharLog(_parentCharacter, "Taking damage! " + _parentCharacter.name);
        //ignore friendly fire
        if (_parentCharacter.MyAI.IsCharacterFriendly(attacker))
        {
            return;
        }

        WorkingMemoryFact fact = _workingMemory.FindExistingFact(FactType.PersonalThreat, attacker);

        if (fact == null)
        {
            fact = _workingMemory.AddFact(FactType.PersonalThreat, attacker, attacker.transform.position, 1, 0.1f);

            fact.ThreatLevel = PersonalThreatHigh;

            fact.ThreatDropRate = 0.1f;
        }
        else
        {
            fact.Confidence = 1;
            if (fact.ThreatLevel < PersonalThreatHigh)
            {
                fact.ThreatLevel = PersonalThreatHigh;
            }
            fact.LastKnownPos = attacker.transform.position;
        }

        //raise threat to critical if health is low
        if (_parentCharacter.MyStatus.Health <= _parentCharacter.MyStatus.MaxHealth / 3 ||
            (_parentCharacter.MyAI.BlackBoard.TargetEnemy == null && _parentCharacter.MyAI.BlackBoard.InvisibleEnemy == null))
        {
            fact.ThreatLevel = PersonalThreatCritical;
        }

        if (attacker != null && attacker.MyAI.ControlType == AIControlType.Player)
        {
            if (_parentCharacter.MyAI.IsCharacterEnemy(attacker) > 0)
            {
                //reduce relationship
                float reduction = 0.25f;
                if (_parentCharacter.MyAI.BlackBoard.TargetEnemy != null)
                {
                    reduction = 0.07f;
                }
                GameManager.Inst.NPCManager.GetFactionData(Faction.Player).ReduceRelationshipByID(_parentCharacter.Faction, reduction);
                GameManager.Inst.NPCManager.GetFactionData(_parentCharacter.Faction).ReduceRelationshipByID(Faction.Player, reduction);
            }
        }

        //check if there's already a known enemy matching the shooter
        WorkingMemoryFact enemyFact = _workingMemory.FindExistingFact(FactType.KnownEnemy, attacker);

        if (enemyFact != null)
        {
            enemyFact.ThreatLevel = 1;
        }
        else
        {
            //if no existing known enemy fact from this attacker, add one
            fact                = _workingMemory.AddFact(FactType.KnownEnemy, attacker, attacker.transform.position, 0.5f, 0.01f);
            fact.ThreatLevel    = 1f;
            fact.ThreatDropRate = 0.01f;

            _parentCharacter.MyAI.BlackBoard.InvisibleEnemy         = attacker;
            _parentCharacter.MyAI.BlackBoard.LastKnownEnemyPosition = attacker.transform.position;

            _parentCharacter.MyAI.CallForHelp(attacker);
        }

        //check if there is currently invisible enemy; if not add it
        if (_parentCharacter.MyAI.BlackBoard.TargetEnemy == null && _parentCharacter.MyAI.BlackBoard.InvisibleEnemy == null)
        {
            _parentCharacter.MyAI.BlackBoard.InvisibleEnemy         = attacker;
            _parentCharacter.MyAI.BlackBoard.LastKnownEnemyPosition = attacker.transform.position;
        }

        //raise guard level
        _parentCharacter.MyAI.BlackBoard.GuardLevel        = 3;
        _parentCharacter.MyAI.BlackBoard.TargetEnemyThreat = 1;

        //only raise important event when the highest personal threat is lower than new threat, in order to damp the rate of replanning
        _parentCharacter.MyAI.BlackBoard.AvgPersonalThreatDir = (fact.LastKnownPos - _parentCharacter.transform.position).normalized;
        if (fact.ThreatLevel > _parentCharacter.MyAI.BlackBoard.HighestPersonalThreat)
        {
            //Debug.Log("VERY HIGH personal threat! new: " + fact.ThreatLevel + " old: " + _parentCharacter.MyAI.BlackBoard.HighestPersonalThreat + _parentCharacter.name);
            _parentCharacter.MyAI.BlackBoard.HighestPersonalThreat = fact.ThreatLevel;

            _parentCharacter.MyAI.OnImportantEvent(1);
        }
    }