Esempio n. 1
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);
        }
Esempio n. 2
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);
        }