Esempio n. 1
0
 public void SetTarget(FighterAI value)
 {
     if (!currentEnemy || !currentEnemy.isLocked)
     {
         currentEnemy = value;
         target       = currentEnemy.gameObject;
     }
 }
Esempio n. 2
0
 // Use this for initialization
 void Start()
 {
     hp            = maxHp;
     wep           = GetComponent <Weapons> ();
     parent        = GetComponentInParent <LargeShipAI> ();
     fighterParent = GetComponentInParent <FighterAI> ();
     rb            = GetComponentInParent <Rigidbody> ();
     isPlayerSide  = GetComponentInParent <BaseShip> ().isPlayerSide;
     pc            = GetComponentInParent <PlayerControls> ();
 }
Esempio n. 3
0
    IEnumerator Spawn_async(FighterAI AI)
    {
        _penalty += 0.2f;
        yield return(new WaitForSeconds(_penalty));

        AI.transform.position = new Vector3(transform.position.x + Random.Range(100, 400), transform.position.y + Random.Range(100, 400), transform.position.z + Random.Range(100, 400));
        AI.gameObject.SetActive(true);
        AI.Initialize(_bc, this);

        //	_hitPoints -= 100;

        OnHit(1000);
    }
Esempio n. 4
0
    // function to spawn a new enemy and link the player to the enemy
    public void SpawnNewEnemy()
    {
        // instantiate the new enemy and update all of the enemies information
        GameObject newEnemy = Instantiate(enemyPrefab, Vector3.zero, Quaternion.identity);

        newEnemy.name  = "Enemy";
        enemy          = newEnemy.GetComponent <FighterAI>();
        enemy.nickname = enemyNames[Random.Range(0, enemyNames.Length)];

        // output that a new enemy has appeared
        textBox.fontSize = 44;
        textBox.text     = enemy.nickname + " has appeared!";
        timeSinceAction  = actionCooldown / 2f; // speed up delay between enemy appearing and being able to play

        // set an enemy sprite active for the new enemy
        spriteIndex = Random.Range(0, enemySprites.Length);
        enemySprites[spriteIndex].SetActive(true);
    }
Esempio n. 5
0
    public FighterAI Create()
    {
        GameObject go;

        if (_faction == Faction.ALLY)
        {
            go = ObjectFactory.instance.MakeObject(ObjectFactory.PrefabType.AllyFighter);
        }
        else
        {
            go = ObjectFactory.instance.MakeObject(ObjectFactory.PrefabType.Fighter);
        }

        go.transform.position = new Vector3(transform.position.x + Random.Range(-900, 900), transform.position.y + Random.Range(-900, 900), transform.position.z + Random.Range(-900, 900));
        FighterAI AI = go.GetComponent <FighterAI> ();

        AI.Initialize(_bc, this);

        return(AI);
    }
Esempio n. 6
0
 public MoveStateFighter(FighterAI owner)
 {
     this.owner = owner;
 }
Esempio n. 7
0
 public TargetCastleState(FighterAI fighter) : base(fighter.gameObject)
 {
     _fighter = fighter;
 }
    //Esta função checa de quem é o turno e remove um de HP do lutador respectivo
    public IEnumerator TakeDamage()
    {
        suspendMoveCalculation = true;
        //Audio de dano toca.
        if (ShiftManagementScript.state == BattleState.PLAYERTURN)
        {
            redAnimator.SetTrigger("hurt");
            playerFighter.hP--;
            TextPlayer.instance.addToEndOfSequence(listaSons.playerDamageSound,
                                                   listaSons.danoRecebido);
        }
        else if (ShiftManagementScript.state == BattleState.ENEMYTURN)
        {
            blueAnimator.SetTrigger("hurt");
            enemyFighter.hP--;
            TextPlayer.instance.addToEndOfSequence(listaSons.enemyDamageSound,
                                                   listaSons.voceAcertou);
        }
        UpdateUI();
        if (!TextPlayer.instance.ForcedToStop) // while(TextPlayer.instance.SourcesPlaying()) yield return null;
        {
            PlayHPCounter(playerFighter);
            // while(TextPlayer.instance.SourcesPlaying()) yield return null;
            PlayHPCounter(enemyFighter);
        }
        while (TextPlayer.instance.SourcesPlaying())
        {
            yield return(null);
        }

        //As listas são reinicializadas
        fightMoves = new List <Move>();
        tempMoves  = new List <Move>();

        FighterAI ai = GameObject.FindObjectOfType <FighterAI>();

        ai.RefreshEnemyHitChance();

        //Caso alguém chegue a 0 de vida, o jogo se encerra
        if (playerFighter.hP == 0 || enemyFighter.hP == 0)
        {
            StartCoroutine(EndRound());
            yield break;
        }

        if (ShiftManagementScript.state == BattleState.PLAYERTURN)
        {
            TextPlayer.instance.addToEndOfSequence(listaSons.facaUmMovimentoNovo);
            // while(TextPlayer.instance.SourcesPlaying()) yield return null;
        }
        else if (ShiftManagementScript.state == BattleState.ENEMYTURN)
        {
            TextPlayer.instance.addToEndOfSequence(listaSons.seuAdvNovaRodada);
            // while(TextPlayer.instance.SourcesPlaying()) yield return null;
        }
        while (TextPlayer.instance.SourcesPlaying())
        {
            yield return(null);
        }
        suspendMoveCalculation = false;
        yield break;
    }
Esempio n. 9
0
 public AttackState(FighterAI fighter) : base(fighter.gameObject)
 {
     _fighter = fighter;
 }
 public GatherStateFighter(FighterAI owner)
 {
     this.owner = owner;
 }
Esempio n. 11
0
    // function to handle the execution of actions between the player and the target
    public void ExecuteAction(FighterAI target, string action)
    {
        // get targets action and setup battleFeedback to give the information from the actions
        string targetsAction = target.Action();

        battleFeedback = "You used " + currentAction.ToLower() + " and " + target.nickname + " used " + targetsAction.ToLower() + ".\n";

        // check for repeat player actions
        if (previousAction == currentAction)
        {
            repeatActions++;
        }
        else
        {
            repeatActions = 0;
        }

        // check for repeat enemy actions
        if (enemyPreviousAction == targetsAction)
        {
            enemyRepeatActions++;
        }
        else
        {
            enemyRepeatActions = 0;
        }

        graphNodeIndex = 13; // for random conversation if it is not overwritten by a situation

        if (repeatActions >= 2)
        {
            graphNodeIndex = 19;
        }
        else if (targetsAction == "Heal" && enemyRepeatActions >= 2)
        {
            graphNodeIndex = 18;
        }
        else if ((targetsAction == "Defend" || targetsAction == "Counter") && (enemyRepeatActions >= 2))
        {
            graphNodeIndex = 20;
        }
        else if (turnCount >= 10)
        {
            graphNodeIndex = 9;
        }

        if (action == "Attack")   // check if player used attack
        {
            attackSFX.Play();
            if (enemy.GetHealth() > 7 && enemy.GetHealth() <= 10)
            {
                graphNodeIndex = 5;
            }

            // check for if target used rush or heal because they take priority over attack
            if (targetsAction == "Rush")
            {
                rushSFX.Play();
                battleFeedback += target.nickname + " dealt " + (int)(target.AttackAmount() / 1.5f) + " damage to you.\n";
                TakeDamage((int)(target.AttackAmount() / 1.5f));
            }
            else if (targetsAction == "Heal")
            {
                healSFX.Play();
                battleFeedback += target.nickname + " healed for 4 HP.\n";
                target.TakeDamage(-4); // take damage from target with a negative value to increase targets health
            }

            if (Alive())  // check that player is still alive
            {
                int damage = attackAmount;

                if (targetsAction == "Counter")
                {
                    graphNodeIndex  = 16;
                    battleFeedback += target.nickname + " was unsuccessful in countering. ";
                    damage         *= 2; // attack does twice as much if target counters
                }
                else if (targetsAction == "Defend")
                {
                    defendSFX.Play();
                    graphNodeIndex  = 15;
                    battleFeedback += target.nickname + " defended. ";
                    damage         -= target.DefenseAmount(); // attack does less if target defends
                }

                damage          = Mathf.Clamp(damage, 0, attackAmount * 2); // clamp the min to 0 in case targets defense is higher than your attack damage
                battleFeedback += "You dealt " + damage + " damage to " + target.nickname + ".\n";
                target.TakeDamage(damage);

                if (target.Alive() && targetsAction == "Attack")  // check if target is still alive and if they used the attack command
                {
                    battleFeedback += target.nickname + " dealt " + target.AttackAmount() + " damage to you.\n";
                    TakeDamage(target.AttackAmount());
                }
            }
        }
        else if (action == "Rush")    // check if player used rush
        {
            if (enemySuccussfulCounter)
            {
                graphNodeIndex = 8;
            }

            if (targetsAction == "Counter")
            {
                counterSFX.Play();
                graphNodeIndex  = 17;
                battleFeedback += target.nickname + " was successful in countering and dealt " + target.AttackAmount() * 2 + " damage to you.\n";
                TakeDamage(target.AttackAmount() * 2); // deal damage to the player since the oppenent successfully countered
            }
            else if (targetsAction == "Defend")
            {
                rushSFX.Play();
                defendSFX.Play();
                int damage = (int)((attackAmount / 1.5f) - target.DefenseAmount());
                damage = Mathf.Clamp(damage, 0, attackAmount * 2); // clamp the min to 0 in case targets defense is higher than your attack damage
                target.TakeDamage(damage);
                battleFeedback += target.nickname + " defended. You dealt " + damage + " damage to " + target.nickname + ".\n";
            }
            else
            {
                rushSFX.Play();
                battleFeedback += "You dealt " + (int)(attackAmount / 1.5f) + " damage to " + target.nickname + ".\n";
                target.TakeDamage((int)(attackAmount / 1.5f));

                if (target.Alive())  // check if target is still alive
                {
                    if (targetsAction == "Attack")
                    {
                        attackSFX.Play();
                        battleFeedback += target.nickname + " dealt " + target.AttackAmount() + " damage to you.\n";
                        TakeDamage(target.AttackAmount());
                    }
                    else if (targetsAction == "Rush")
                    {
                        battleFeedback += target.nickname + " dealt " + (int)(target.AttackAmount() / 1.5f) + " damage to you.\n";
                        TakeDamage((int)(target.AttackAmount() / 1.5f));
                    }
                    else if (targetsAction == "Heal")
                    {
                        healSFX.Play();
                        battleFeedback += target.nickname + " healed for 4 HP.\n";
                        target.TakeDamage(-4); // take damage from target with a negative value to increase targets health
                    }
                }
            }
        }
        else if (action == "Defend")    // check if player used defend
        {
            defendSFX.Play();
            graphNodeIndex = 7;

            if (targetsAction == "Defend" || targetsAction == "Counter")
            {
                battleFeedback += "Nothing happened.\n";
            }
            else if (targetsAction == "Heal")
            {
                healSFX.Play();
                battleFeedback += "You defended.\n" + target.nickname + " healed for 4 HP.\n";
                target.TakeDamage(-4); // take damage from target with a negative value to increase targets health
            }
            else
            {
                int targetDamage = target.AttackAmount();
                battleFeedback += "You defended. ";

                if (targetsAction == "Attack")
                {
                    attackSFX.Play();
                    targetDamage -= defenseAmount;
                }
                else if (targetsAction == "Rush")
                {
                    rushSFX.Play();
                    targetDamage = (int)((targetDamage / 1.5f) - defenseAmount);
                }

                targetDamage    = Mathf.Clamp(targetDamage, 0, target.AttackAmount());
                battleFeedback += target.nickname + " dealt " + targetDamage + " damage to you.\n";
                TakeDamage(targetDamage);
            }
        }
        else if (action == "Counter")    // check if player used counter
        {
            if (Health < (maxHealth / 2))
            {
                graphNodeIndex = 4;
            }

            if (targetsAction == "Defend" || targetsAction == "Counter")
            {
                graphNodeIndex = 6;
                if (targetsAction == "Defend")
                {
                    defendSFX.Play();
                }
                battleFeedback += "Nothing happened.\n";
            }
            else if (targetsAction == "Rush")
            {
                counterSFX.Play();
                //graphNodeIndex = ;
                battleFeedback += "You successfully countered and dealt " + attackAmount * 2 + " damage to " + target.nickname + ".\n";
                target.TakeDamage(attackAmount * 2); // deal damage to the target since player successfully countered
            }
            else
            {
                graphNodeIndex = 6;

                /*int pick = Random.Range(0, 2);
                 * if (pick == 0) { graphNodeIndex = 6; }
                 * else { graphNodeIndex = 14; }*/
                battleFeedback += "You were unsuccessful in countering. ";

                if (targetsAction == "Attack")
                {
                    attackSFX.Play();
                    battleFeedback += target.nickname + " dealt " + (target.AttackAmount() * 2) + " damage to you.\n";
                    TakeDamage(target.AttackAmount() * 2);
                }
                else if (targetsAction == "Heal")
                {
                    healSFX.Play();
                    battleFeedback += target.nickname + " healed for 7 HP.\n";
                    target.TakeDamage(-7); // take damage from target with a negative value to increase targets health
                }
            }
        }
        else if (action == "Heal")
        {
            // check rush first because it has priority over heal
            if (targetsAction == "Rush")
            {
                rushSFX.Play();
                battleFeedback += target.nickname + " dealt " + (int)(target.AttackAmount() / 2) + " damage to you.\n";
                TakeDamage((int)(target.AttackAmount() / 1.5f));

                if (Alive())  // check if player is still alive
                {
                    healSFX.Play();
                    battleFeedback += "You healed for 6 HP.\n";
                    Health         += 6;
                    Health          = Mathf.Clamp(Health, 0, maxHealth);
                }
            }
            else
            {
                healSFX.Play();
                battleFeedback += "You healed for 6 HP.\n";
                Health         += 6;
                Health          = Mathf.Clamp(Health, 0, maxHealth);

                if (targetsAction == "Attack")
                {
                    attackSFX.Play();
                    battleFeedback += target.nickname + " dealt " + target.AttackAmount() + " damage to you.\n";
                    TakeDamage(target.AttackAmount());
                }
                else if (targetsAction == "Defend")
                {
                    battleFeedback += target.nickname + " defended.\n";
                }
                else if (targetsAction == "Counter")
                {
                    battleFeedback += target.nickname + " was unsuccessful in countering.\n";
                }
                else if (targetsAction == "Heal")
                {
                    battleFeedback += target.nickname + " healed for 4 HP.\n";
                    target.TakeDamage(-4); // take damage from target with a negative value to increase targets health
                }
            }
        }


        if (!Alive())  // check if the player was defeated during the battle
        {
            deathSFX.Play();
            battleFeedback += "You have been defeated.\n";
        }

        if (!target.Alive())   // check if target was defeated during the battle
        {
            deathSFX.Play();
            battleFeedback += "You have defeated " + target.nickname + " and recieved " + target.ExpAmount() + " EXP!\n";
            ExpGain(target.ExpAmount());
            enemySprites[spriteIndex].SetActive(false);
            needsNewTarget = true; // update that the player needs a new target
        }

        if (action == "Rush" && targetsAction == "Counter")
        {
            enemySuccussfulCounter = true;
        }
        else
        {
            enemySuccussfulCounter = false;
        }

        textBox.text = battleFeedback; // update the textBox with the battle feedback
    }
Esempio n. 12
0
 public ChaseState(FighterAI fighter) : base(fighter.gameObject)
 {
     _fighter = fighter;
 }
 public SearchStateFighter(FighterAI owner)
 {
     this.owner = owner;
 }
Esempio n. 14
0
 public void Spawn(FighterAI AI)
 {
     StartCoroutine(Spawn_async(AI));
 }