Esempio n. 1
0
    /// <summary>
    /// Returns an enemy of a certain faction that's in the encounter
    /// </summary>
    /// <param name="allyFaction">Faction of the enemy requesting the target</param>
    /// <returns>An enemy that can be set as the attack target</returns>
    public GameObject GetNewAttackTarget(Enemy.EnemyFaction allyFaction)
    {
        Debug.Log("Finding new ally attack target...");
        int rando   = Random.Range(0, encounterEnemies.Count);
        int ogRando = rando;

        while (encounterEnemies[rando].GetComponent <Enemy>().faction == allyFaction)
        {
            //Debug.Log("Forever allies?: " + Time.fixedTime);
            //Look for next enemy
            ++rando;
            //Make sure we're not out of bounds
            if (rando >= encounterEnemies.Count)
            {
                rando = 0;
            }
            //If we looped through all possible other enemies...
            if (rando == ogRando)
            {
                Debug.Log("No more enemies of opposing faction! Can't get new attack target");
                return(null);
            }
        }
        return(encounterEnemies[rando]);
    }
Esempio n. 2
0
    // N/A
    #endregion

    #region Encounter Methods
    /// <summary>
    /// Sets up an encounter
    /// CALLED BY ENEMIES
    /// </summary>
    public void StartEncounter(Encounter enc, Enemy.EnemyFaction hitEnemyFaction, Encounter.SpecialEncounters encounterType)
    {
        //change music to combat at encounter start
        SoundManager.PlayMusic(SoundManager.Music.Combat, this.gameObject);
        if (encounterActive)
        {
            MergeEncounters();
        }
        Helper.DebugLogDivider();
        //Reset aggression
        encounterAggressionCurrent = 0f;
        //Set flagged for being in an encounter
        encounterActive = true;
        //Set encounter type
        currentEncounterType = encounterType;
        //Update position of the encounter (which will simply be used as this object's location for debug purposes)
        this.transform.position = enc.transform.position;
        //Grab enemies within range and add them to the encounter
        for (int i = 0; i < zoneEnemies.Count; ++i)
        {
            //Try to add enemy to encounter
            if ((enc.transform.position - zoneEnemies[i].transform.position).sqrMagnitude <= Mathf.Pow(enc.Range, 2))
            {
                encounterEnemies.Add(zoneEnemies[i]);
                zoneEnemies[i].GetComponent <Enemy>().StartEncounter();
            }
            if (encounterEnemies.Count > 6)
            {
                Debug.Log("More than 6 enemies in encounter!");
                Debug.Break();
                throw new UnityException();//Don't allow more than 6 enemies in an encounter... if this line of code triggers then we need to fix something
            }
        }

        // spawn any extra enemies
        foreach (int key in enc.categoryXEnemies)
        {
            SpawnExtraEnemies(key);                                       // spawn any extra enemies
        }
        Debug.Log("Starting Encounter... Enemies = " + encounterEnemies.Count + ", now assigning attack targets... @ " + Time.fixedTime);
        //Now that we have all the encounter enemies setup, we can assign attack targets
        for (int i = 0; i < encounterEnemies.Count; ++i)
        {
            Enemy e = encounterEnemies[i].GetComponent <Enemy>();
            //Tell the enemies not to ally the player if they're of an opposing faction
            if (e.faction == hitEnemyFaction)
            {
                e.AlliedWithPlayer = false;
                //Try to add enemy to grid cell if they're not allied with the player
                e.MoveTarget = SendNewMoveTarget(e);
            }
            else
            {
                e.AlliedWithPlayer = true;
                e.gameObject.GetComponent <Entity>().SpeedModifier *= allySpeedMultiplier;//NOTE: This was changed to use multiplication to test the new speed system @ 11/8
                e.AttackTarget = GetNewAttackTarget(e.faction);
            }
        }
    }
Esempio n. 3
0
 /// <summary>
 /// Sets all enemies of a certain faction to be aggressive
 /// </summary>
 /// <param name="faction">Enemy faction to set as hostile</param>
 public void SetGlobalAggression(Enemy.EnemyFaction faction)
 {
     for (int i = 0; i < zoneEnemies.Count; ++i)
     {
         Enemy e = zoneEnemies[i].GetComponent <Enemy>();
         if (e.faction == faction)
         {
             e.AlliedWithPlayer = false;
         }
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Simply starts an encounter
 /// </summary>
 public void StartEncounter(Enemy.EnemyFaction hitEnemyFaction)
 {
     active = true;
     GameObject.Find("EnemyManagerGO").GetComponent <EnemyManager>().StartEncounter(this, hitEnemyFaction, specialEncounterType);
 }