Exemplo n.º 1
0
    public override void UpdateLogic(CharacterLogicController controller)
    {
        NavigationTargeter    targeter          = controller.GetComponent <NavigationTargeter>();
        WaypointChainFollower follower          = controller.GetComponent <WaypointChainFollower>();
        HealthTracker         tracker           = controller.GetComponent <HealthTracker>();
        ExcitementTracker     excitementTracker = controller.GetComponent <ExcitementTracker>();
        CharacterTeamAssigner teamAssigner      = controller.GetComponent <CharacterTeamAssigner>();
        WeaponController      weaponController  = controller.GetComponent <WeaponController>();

        bool canAttack  = !weaponController.isOnCooldown;
        bool isPanicked = tracker.currentHealth / tracker.maxHealth <= panicPercentage;

        List <CharacterTeamAssigner> enemiesInVision = new List <CharacterTeamAssigner>();
        List <Potion> potionsInVision = new List <Potion>();

        foreach (Collider2D collider in Physics2D.OverlapCircleAll(controller.transform.position, visionRange))
        {
            CharacterTeamAssigner otherTeamAssigner = collider.GetComponent <CharacterTeamAssigner>();
            Potion potion = collider.GetComponent <Potion>();

            if (otherTeamAssigner != null && otherTeamAssigner.team != teamAssigner.team)
            {
                enemiesInVision.Add(otherTeamAssigner);
            }

            if (potion != null)
            {
                potionsInVision.Add(potion);
            }
        }

        List <CharacterTeamAssigner> enemiesInAttackRange = ClosestUtility.ThresholdList(controller.transform, enemiesInVision, enemyAttackRange);

        bool inCombat = enemiesInAttackRange.Count > 0;

        if (inCombat)
        {
            excitementTracker.GainExcitement(excitementGainedWhenInCombatPerSecond * Time.deltaTime * (isPanicked ? panicExcitementMultiplier : 1.0f));
        }

        if (inCombat && !isPanicked && canAttack)
        {
            targeter.target = ClosestUtility.GetClosestInList(controller.transform, enemiesInAttackRange).transform;
            return;
        }

        bool canGetToPotion = potionsInVision.Count > 0;
        bool wantsPotion    = tracker.currentHealth < tracker.maxHealth;

        if (wantsPotion && canGetToPotion)
        {
            targeter.target = ClosestUtility.GetClosestInList(controller.transform, potionsInVision).transform;
            return;
        }

        targeter.target = follower.currentWaypoint;
    }
Exemplo n.º 2
0
        public override void UpdateLogic(CharacterLogicController controller)
        {
            WeaponController   weaponController = controller.GetComponent <WeaponController>();
            NavigationTargeter targeter         = controller.GetComponent <NavigationTargeter>();

            if (weaponController != null && targeter != null && weaponController.currentWeapon != null)
            {
                targeter.goalStoppingDistance = weaponController.currentWeapon.range - overlap;
            }
        }
Exemplo n.º 3
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            NavigationTargeter myScript = (NavigationTargeter)target;

            if (GUILayout.Button("Recompute Path To Target"))
            {
                myScript.RecomputeWaypoints();
            }
        }
        public override void DoBehavior(CharacterMovementController controller)
        {
            NavigationTargeter targeter = controller.GetComponent <NavigationTargeter>();

            if (targeter == null || targeter.waypoints == null)
            {
                return;
            }

            if (targeter.waypoints.Count > 0)
            {
                Vector2 destination   = targeter.waypoints.Peek();
                float   deltaDistance = ((Vector2)targeter.self.position - destination).magnitude;
                Vector2 nextPosition  = Vector2.MoveTowards(targeter.self.position, destination, Mathf.Min((controller.movementSpeed * Time.fixedDeltaTime), deltaDistance));
                Vector2 delta         = nextPosition - (Vector2)targeter.self.position;

                controller.MoveByDelta(delta);
            }
        }
Exemplo n.º 5
0
        public override void UpdateLogic(CharacterLogicController controller)
        {
            NavigationTargeter targeter = controller.GetComponent <NavigationTargeter>();

            if (targeter == null)
            {
                return;
            }

            if (targeter.target != null)
            {
                return;
            }

            Transform target          = null;
            float     closestDistance = Mathf.Infinity;

            foreach (Collider2D collider in Physics2D.OverlapCircleAll(controller.transform.position, seekRange))
            {
                CharacterTeamAssigner assigner = collider.GetComponent <CharacterTeamAssigner>();
                if (assigner != null)
                {
                    if (assigner.team == teamToSeek)
                    {
                        float distance = Vector2.Distance(controller.transform.position, assigner.transform.position);
                        if (distance < closestDistance)
                        {
                            target          = assigner.transform;
                            closestDistance = distance;
                        }
                    }
                }
            }
            targeter.target = target;
            targeter.RecomputeWaypoints();
        }
 private void Awake()
 {
     targeter = GetComponent <NavigationTargeter>();
     healthBar.gameObject.SetActive(targeter.target != null);
 }
Exemplo n.º 7
0
 private void Awake()
 {
     targeter = GetComponent <NavigationTargeter>();
 }