Ejemplo n.º 1
0
        public float Evaluate(Entity entity, AIBehaviourSetting behaviour, AbilityAIInput ai, List <Transform> targets)
        {
            _behaviour = behaviour;
            _transform = _behaviour.Actor.GameObject.transform;

            return(Random.value * _behaviour.basePriority);
        }
Ejemplo n.º 2
0
        public float Evaluate(Entity entity, AIBehaviourSetting behaviour, AbilityAIInput ai, List <Transform> targets)
        {
            _behaviour = behaviour;
            _transform = _behaviour.Actor.GameObject.transform;
            _player    = _behaviour.Actor.GameObject.GetComponent <AbilityActorPlayer>();

            if (_player == null)
            {
                return(0f);
            }

            var health      = _player.CurrentHealth;
            var sampleScale = behaviour.curveMaxSample - behaviour.curveMinSample;
            var curveSample = math.clamp(
                (health - behaviour.curveMinSample) / sampleScale, 0f, 1f);

            return(behaviour.priorityCurve.Evaluate(curveSample) * PRIORITY_MULTIPLIER);
        }
Ejemplo n.º 3
0
        public float Evaluate(Entity entity, AIBehaviourSetting behaviour, AbilityAIInput ai, List <Transform> targets)
        {
            if (this.GetType().ToString().Contains(ai.activeBehaviour.behaviourType))
            {
                return(0f);
            }

            _behaviour = behaviour;

            if (Time.timeSinceLevelLoad < ACTION_DELAY * Random.value)
            {
                return(0f);
            }

            if (World.DefaultGameObjectInjectionWorld.EntityManager.HasComponent <DeadActorData>(entity))
            {
                return(0f);
            }

            if (CustomInput == null)
            {
                //Debug.Log("[ATTACK BEHAVIOUR] No Input Ability!");
                return(0f);
            }

            if (CustomInput.bindingsDict.ContainsKey(_behaviour.executeCustomInput))
            {
                _abilities = CustomInput.bindingsDict[_behaviour.executeCustomInput];
            }
            else
            {
                //Debug.Log($"[ATTACK BEHAVIOUR] Custom Input {_behaviour.executeCustomInput} in Attack Behaviour not set in Input Ability!");
                return(0f);
            }

            if (!_abilities.ActionPossible())
            {
                //Debug.Log($"[ATTACK BEHAVIOUR] Custom Input {_behaviour.executeCustomInput} has no actions!");
                return(0f);
            }

            return(behaviour.basePriority * Random.value);
        }
Ejemplo n.º 4
0
        public float Evaluate(Entity entity, AIBehaviourSetting behaviour, AbilityAIInput ai, List <Transform> targets)
        {
            if (this.GetType().ToString().Contains(ai.activeBehaviour.behaviourType))
            {
                return(0f);
            }

            _target    = null;
            _behaviour = behaviour;
            _transform = behaviour.Actor.GameObject.transform;

            if (Time.timeSinceLevelLoad < ATTACK_DELAY * Random.value)
            {
                return(0f);
            }

            if (World.DefaultGameObjectInjectionWorld.EntityManager.HasComponent <DeadActorData>(entity))
            {
                return(0f);
            }

            if (CustomInput == null)
            {
                //Debug.Log("[ATTACK BEHAVIOUR] No Input Ability!");
                return(0f);
            }

            if (CustomInput.bindingsDict.ContainsKey(_behaviour.executeCustomInput))
            {
                _abilities = CustomInput.bindingsDict[_behaviour.executeCustomInput];
            }
            else
            {
                //Debug.Log($"[ATTACK BEHAVIOUR] Custom Input {_behaviour.executeCustomInput} in Attack Behaviour not set in Input Ability!");
                return(0f);
            }

            if (!_abilities.ActionPossible())
            {
                //Debug.Log($"[ATTACK BEHAVIOUR] Custom Input {_behaviour.executeCustomInput} has no actions!");
                return(0f);
            }

            List <Transform> orderedTargets = targets.Where(t => t.FilterTag(_behaviour) && t != _transform).OrderBy(t =>
                                                                                                                     math.distancesq(_transform.position, t.position)).ToList();

            if (orderedTargets.Count == 0)
            {
                return(0f);
            }

            foreach (var t in orderedTargets)
            {
                //Debug.DrawRay(_transform.position + VIEW_POINT_DELTA, t.position - _transform.position, Color.blue, 2f);

                if (Physics.Raycast(_transform.position + VIEW_POINT_DELTA, t.position - _transform.position, out var hit,
                                    AIM_MAX_DIST))
                {
                    if (hit.transform != t)
                    {
                        continue;
                    }
                    _target = t;

                    var dist        = math.distance(_transform.position, _target.position);
                    var sampleScale = _behaviour.curveMaxSample - _behaviour.curveMinSample;
                    var curveSample = math.clamp(
                        (dist - _behaviour.curveMinSample) / sampleScale, 0f, 1f);
                    var result = _behaviour.priorityCurve.Evaluate(curveSample) * _behaviour.basePriority;

                    return(result);
                }
            }

            return(0f);
        }
Ejemplo n.º 5
0
        public float Evaluate(Entity entity, AIBehaviourSetting behaviour, AbilityAIInput ai, List <Transform> targets)
        {
            _target    = null;
            _transform = behaviour.Actor?.GameObject.transform;

            if (_transform == null)
            {
                return(0f);
            }

            List <Transform> filteredTargets = targets.Where(t => t.FilterTag(behaviour) && t != _transform).ToList();

            if (filteredTargets.Count == 0)
            {
                return(0f);
            }
            if (filteredTargets.Count == 1)
            {
                _target = filteredTargets.First();
                return(math.distancesq(_transform.position, _target.position) < FINISH_CHASE_DISTSQ ? 0f :
                       behaviour.basePriority *PRIORITY_MULTIPLIER);
            }

            var sampleScale = behaviour.curveMaxSample - behaviour.curveMinSample;

            switch (behaviour.additionalMode)
            {
            case "Random mode: priority as probability":
                var priorities = new List <MinMaxTarget>();

                var priorityCache = 0f;

                foreach (var target in filteredTargets)
                {
                    var d           = math.distance(_transform.position, target.position);
                    var curveSample = math.clamp(
                        (d - behaviour.curveMinSample) / sampleScale, 0f, 1f);
                    var priority = behaviour.priorityCurve.Evaluate(curveSample);

                    priorities.Add(new MinMaxTarget
                    {
                        Min    = priorityCache,
                        Max    = priority + priorityCache,
                        Target = target
                    });

                    priorityCache += priority;
                }

                var randomNumber = Random.Range(0f, priorityCache);

                _target = priorities.Find(t => t.Min < randomNumber && t.Max >= randomNumber).Target;
                break;

            default:     // ReSharper disable once RedundantCaseLabel
            case "Strict mode: distance to priority":
                var orderedTargets = filteredTargets.OrderBy(t =>
                {
                    var d           = math.distance(_transform.position, t.position);
                    var curveSample = math.clamp(
                        (d - behaviour.curveMinSample) / sampleScale, 0f, 1f);
                    return(behaviour.priorityCurve.Evaluate(curveSample));
                }).ToList();

                _target = orderedTargets.Last();
                break;
            }

            return(math.distancesq(_transform.position, _target.position) < FINISH_CHASE_DISTSQ ? 0f :
                   behaviour.basePriority *PRIORITY_MULTIPLIER);
        }