Example #1
0
    public void GetRetreatPoints(RefactoredBarricade retreatTarget)
    {
        for (int i = 0; i < retreatTarget.backWaypoints.Count; i++)
        {
            retreatPoints.Add(retreatTarget.backWaypoints[i]);
        }

        for (int i = 0; i < retreatTarget.frontWaypoints.Count; i++)
        {
            retreatPoints.Add(retreatTarget.frontWaypoints[i]);
        }

        for (int i = 0; i < retreatTarget.retreatPoints.Count; i++)
        {
            retreatPoints.Add(retreatTarget.retreatPoints[i]);
        }
    }
Example #2
0
    /*  Function: Select targets, and perform the appropriate attack
        Parameters: None
        Returns: None
    */
    IEnumerator Combat()
    {
        while (true)
        {
            // If the current target has no HP, find a new one
            if ((targetHealthCache != null && targetHealthCache.currentHealth <= 0) || targetPlayerCache == null)
            {
                if (targetHealthCache != null && targetHealthCache.currentHealth <= 0)
                {
                    targetPlayerCache = null;
                }

                // If a player is found at the Barricade, cache it
                // Otherwise, cache the Barricade
                if (targetPlayerCache = FindPlayerTarget(targetBarricadeCache))
                {
                    targetHealthCache = targetPlayerCache.GetComponent<UnitStats>();
                    destinationCache = GetNewOffset(attackRange, targetPathNode.transform.position);
                }

                else
                {
                    targetPlayerCache = targetBarricadeCache.gameObject;
                    targetHealthCache = targetBarricadeCache.GetComponent<UnitStats>();
                    destinationCache = GetNewOffset(attackRange, targetPathNode.transform.position);

                    // If the Barricade has no HP, stop combat
                    if (targetHealthCache.currentHealth <= 0)
                    {
                        attacking = false;
                        targetPlayerCache = null;
                        targetLocation = null;
                        targetBarricadeCache = null;
                        targetPathNode = null;
                        beginPathing = true;

                        yield break;
                    }
                }
            }

            if (dir.magnitude < attackRange)
            {
                // Skips attack cooldown on first attack
                if (!beginAttacking)
                    yield return new WaitForSeconds(attackCooldown);

                else
                    beginAttacking = false;

                StopCoroutine("MoveToTarget");
                moving = false;

                switch (unitType)
                {
                    case EnemyTypes.Minion:
                        m_EnemyAttack.Punch(targetPlayerCache, attackDamage);
                        break;

                    case EnemyTypes.Brute:
                        m_EnemyAttack.Slam(targetPlayerCache, attackTargetLayer, attackDamage, attackEffectDuration, attackAreaOfEffect);
                        break;

                    case EnemyTypes.Evoker:
                        m_EnemyAttack.Shoot(targetPlayerCache, attackDamage);
                        break;

                    case EnemyTypes.Bob:
                        m_ParticleSystem.Play(true);
                        m_ParticleSystem.transform.parent = null;
                        AudioSource.PlayClipAtPoint(unitAudio[1], transform.position);
                        stats.KillUnit();
                        m_EnemyAttack.Explode(targetPlayerCache, attackTargetLayer, attackDamage, attackAreaOfEffect);
                        m_ParticleSystem.Play(true);
                        break;

                    default:
                        break;
                }
            }

            else if (!moving)
            {
                //StartCoroutine("MoveToTarget");
            }

            yield return null;
        }
    }
Example #3
0
    void Update()
    {
        /** MOVEMENT VALUES **/
        if (targetLocation != null)
        {
            dir = destinationCache - this.transform.position;                // The vector to move along to reach target location
        }

        distThisFrame = movespeed * Time.deltaTime;                                 // How far the unit moves in a frame

        /** STATE SWITCHING LOGIC **/
        if (targetPathNode != null && targetPathNode.barricade != null && !attacking)
        {
            attacking = true;
            beginAttacking = true;
            beginPathing = false;
            targetBarricadeCache = targetPathNode.barricade;                        // Cache the Barricade the unit is
            StartCoroutine("Combat");
        }

        else if (beginPathing)
        {
            if (!moving)
                StartCoroutine("MoveToTarget");

            Pathfinding();
        }
    }
Example #4
0
    /*  Function: Finds a random player located in front of a Barricade
        Parameters: 1) The Barricade to search
        Returns: The player found
    */
    GameObject FindPlayerTarget(RefactoredBarricade barricadeInput)
    {
        // Tracks how many players are in front of the Barricade
        // Starts at -1 to account for base 0 counting
        int frontPlayerCount = -1;

        // Count the number of players at the front waypoints
        for (int i = 0; i < barricadeInput.frontWaypoints.Count; i++)
        {
            // If a player is found, increment the playerCount
            if (barricadeInput.frontWaypoints[i].occupied)
            {
                frontPlayerCount++;
            }
        }

        if (frontPlayerCount >= 0)
            return barricadeInput.frontWaypoints[Random.Range(0, frontPlayerCount)].resident;

        else
            return null;
    }
Example #5
0
    IEnumerator RetreatFrom()
    {
        int i = 0;
        // As long as there are retreatpoints, check for occupied
        while (i < retreatFromBarricade.retreatPoints.Count)
        {
            if (!retreatFromBarricade.retreatPoints[i].occupied)
            {
                agent.SetDestination(retreatFromBarricade.retreatPoints[i].transform.position);
                currentBarricade = retreatFromBarricade.retreatPoints[i].belongsTo;
                currentBarricade.retreatPoints[i].resident = gameObject;
                break;
            }

            i++;
        }

        yield return null;
    }
Example #6
0
    float timer; // A timer between actions.

    #endregion Fields

    #region Methods

    public void BeginRetreat()
    {
        retreatFromBarricade = currentBarricade;
        StartCoroutine(RetreatFrom());
    }
Example #7
0
 // Use this for initialization
 void Awake()
 {
     belongsTo = GetComponentInParent<RefactoredBarricade>();
     occupied = false;
 }
Example #8
0
 /* Function: Spawns all units in the loadout into the scene
  * Parameters: None
  * Returns: None
  */
 public static void SpawnPlayerUnits(RefactoredBarricade evacShuttle)
 {
     for (int i = 0; i < playerLoadout.Length; i++)
     {
         if (playerLoadout[i] != null)
         {
             playerLoadout[i].transform.position = evacShuttle.frontWaypoints[i].transform.position;
             playerLoadout[i].SetActive(true);
         }
     }
 }
Example #9
0
    public void Move(BarricadeWaypoint target, RefactoredBarricade barricade)
    {
        if (setTargetOn.currentWaypoint != null)
        {
            setTargetOn.currentWaypoint.occupied = false;
            setTargetOn.currentBarricade.residentList.Remove(setTargetOn);

            if (setTargetOn.unitType == UnitTypes.Mechanic)
                StartCoroutine(setTargetOn.EndFortify());

            else if (setTargetOn.unitType == UnitTypes.Medic)
                StartCoroutine(setTargetOn.DeactivateHeal());
        }
        setTargetOn.healthRegenRate = 0;
        setTargetOn.currentWaypoint = target;
        setTargetOn.currentBarricade = barricade;
        target.occupied = true;
        target.resident = setTargetOn.gameObject;
        setTargetOn.currentWaypoint = target;
        barricade.residentList.Add(setTargetOn);

        if (setTargetOn.agent.enabled)
        {
            setTargetOn.agent.ResetPath();
            setTargetOn.agent.SetDestination(target.transform.position);
        }
    }
Example #10
0
    void SetWaypointButtons(RefactoredBarricade barricade)
    {
        for (int f = 0; f < barricade.frontWaypoints.Count; f++)
        {
            if (barricade.frontWaypoints[f].occupied == false)
            {
                EnableButton(frontWaypointButton);

                AddListeners(frontWaypointButton,barricade.frontWaypoints[f], barricade);
                break;
            }

            DisableButton(frontWaypointButton);
        }

        if (barricade.backWaypoints.Count > 1)
        {
            for (int b = 0; b < barricade.backWaypoints.Count; b++)
            {
                if (barricade.backWaypoints[b].occupied == false)
                {
                    EnableButton(rearWaypointButton);

                    AddListeners(rearWaypointButton, barricade.backWaypoints[b], barricade);
                    break;
                }

                DisableButton(rearWaypointButton);
            }
        }

        else
            DisableButton(rearWaypointButton);
    }
Example #11
0
 void AddListeners(Button b, BarricadeWaypoint parameter, RefactoredBarricade barricade)
 {
     b.onClick.RemoveAllListeners();
     b.onClick.AddListener(delegate { Move(parameter, barricade); });
 }