Example #1
0
 public override TurnArgs ChooseAttack(IList<Battler> allCharacters)
 {
     IList<Battler> liveCharacters = allCharacters.Where(b => b.BattleBehavior.Status.StatusEffect != StatusEffect.Defeated).ToList();
     int index = UnityEngine.Random.Range(0, liveCharacters.Count);
     Battler target = liveCharacters[index];
     float attackType = UnityEngine.Random.Range(0f, 1f);
     //Choose to use a normal attack or a special attack
     ActionType actionType = attackType < 0.5f ? ActionType.Attack : ActionType.Special;
     //ActionType actionType = ActionType.Special;
     int specialIndex = 0;
     ActionTarget actionTarget = ActionTarget.PartyMember;
     Action chosenAction = null;
     if (actionType == ActionType.Special)
     {
         //Check to see if you have enough SP
         IList<Action> usableAbilities = SpecialAbilities.Where(a => Stats.CurrentSP >= a.RequiredSP).ToList();
         if (usableAbilities.Count == 0)
         {
             actionType = ActionType.Attack;
         }
         //Pick a special attack to use out of all the usable attacks, then get its index in the SpecialAbilities list
         else
         {
             specialIndex = UnityEngine.Random.Range(0, usableAbilities.Count);
             chosenAction = usableAbilities[specialIndex];
             //Possibly check to see if an attack can be used on a particular character
             actionTarget = chosenAction.ActionTarget;
         }
     }
     TurnArgs args = new TurnArgs
     {
         User = Battler,
         Target = target,
         ActionTarget = actionTarget,
         ActionIndex = -1,
         ActionType = actionType,
         Action = chosenAction
     };
     return args;
 }
Example #2
0
    void Advance()
    {
        switch (CurrentMenu)
        {
            case BattleMenuItem.Main:
                switch (mainIndex)
                {
                    //Attack
                    case 0:
                        EnemyMenu();
                        //Select.Play();
                        break;

                    //Special
                    case 1:
                        SpecialMenu();
                        //Select.Play();
                        break;

                    //Item
                    case 2:
                        ItemsMenu();
                        //Select.Play();
                        break;

                    //Defend
                    case 3:
                        TurnArgs defendArgs = new TurnArgs
                        {
                            User = currentCharacter,
                            Target = null,
                            ActionTarget = ActionTarget.PartyMember,
                            ActionIndex = 0,
                            ActionType = ActionType.Defend
                        };
                        OnCharacterTurn(defendArgs);
                        Finish();
                        break;
                }
                break;

            //Attack an enemy with a normal or special attack
            case BattleMenuItem.Enemy:
                //Normal attack
                if (PrevMenu == BattleMenuItem.Main)
                {
                    TurnArgs args = new TurnArgs
                    {
                        User = currentCharacter,
                        Target = allEnemies[enemyIndex],
                        ActionTarget = ActionTarget.Enemy,
                        ActionIndex = 0,
                        ActionType = ActionType.Attack
                    };
                    OnCharacterTurn(args);
                    Finish();
                }
                //Special attack
                else if (PrevMenu == BattleMenuItem.Special)
                {
                    TurnArgs args = new TurnArgs
                    {
                        User = currentCharacter,
                        Target = allEnemies[enemyIndex],
                        ActionTarget = ActionTarget.Enemy,
                        ActionIndex = specialIndex,
                        ActionType = ActionType.Special,
                        Action = currentCharacter.BattleBehavior.SpecialAbilities[specialIndex]
                    };
                    OnCharacterTurn(args);
                    Finish();
                }
                cursorHover = false;
                CharacterCursor.SetActive(false);
                break;

            //Choose a special attack
            case BattleMenuItem.Special:
                Action specialAttack1 = currentCharacter.BattleBehavior.SpecialAbilities[specialIndex];
                //Choosing a single or multiple enemies handled in EnemyMenu()
                //Make sure the character has enough SP
                if (currentCharacter.BattleBehavior.Stats.CurrentSP >= specialAttack1.RequiredSP)
                {
                    if (specialAttack1.ActionTarget == ActionTarget.Enemy || specialAttack1.ActionTarget == ActionTarget.AllEnemies)
                    {
                        EnemyMenu();
                        //Select.Play();
                    }
                    else if (specialAttack1.ActionTarget == ActionTarget.PartyMember || specialAttack1.ActionTarget == ActionTarget.LivePartyMember || specialAttack1.ActionTarget == ActionTarget.Party)
                    {
                        CharacterMenu();
                        //Select.Play();
                    }
                }
                break;

            //Use an item
            case BattleMenuItem.Item:
                //TODO: Check if an item affects 1 or multiple party members
                if (currentCharacter.Inventory.Count > 0)
                    CharacterMenu();
                break;

            case BattleMenuItem.Player:
                if (currentCharacter.Inventory.Count == 0)
                {
                    break;
                }
                if (PrevMenu == BattleMenuItem.Item)
                {
                    Item item = currentCharacter.Inventory[itemIndex];
                    TurnArgs itemArgs = new TurnArgs
                    {
                        User = currentCharacter,
                        Target = allCharacters[charIndex],
                        ActionTarget = ActionTarget.PartyMember,
                        ActionIndex = itemIndex,
                        ActionType = ActionType.Item
                    };
                    OnCharacterTurn(itemArgs);
                }
                else if (PrevMenu == BattleMenuItem.Special)
                {
                    IList<Battler> characterList = allCharacters;
                    if (currentCharacter.BattleBehavior.SpecialAbilities[specialIndex].ActionTarget == ActionTarget.LivePartyMember)
                    {
                        characterList = allCharacters.Where(c => c.BattleBehavior.Status.StatusEffect != StatusEffect.Defeated).ToList();
                    }
                    TurnArgs args = new TurnArgs
                    {
                        User = currentCharacter,
                        Target = characterList[charIndex],
                        ActionTarget = ActionTarget.PartyMember,
                        ActionIndex = specialIndex,
                        ActionType = ActionType.Special,
                        Action = currentCharacter.BattleBehavior.SpecialAbilities[specialIndex]
                    };
                    OnCharacterTurn(args);
                }
                cursorHover = false;
                CharacterCursor.SetActive(false);
                Finish();
                break;

            case BattleMenuItem.AllPlayers:
                break;

            case BattleMenuItem.AllEnemies:
                //Normal attack
                if (PrevMenu == BattleMenuItem.Main)
                {
                    TurnArgs enemyArgs = new TurnArgs
                    {
                        User = currentCharacter,
                        Target = null,
                        ActionTarget = ActionTarget.AllEnemies,
                        ActionIndex = 0,
                        ActionType = ActionType.Attack
                    };
                    OnCharacterTurn(enemyArgs);
                    Finish();
                }

                //Special attack
                else if (PrevMenu == BattleMenuItem.Special)
                {
                    TurnArgs args = new TurnArgs
                    {
                        User = currentCharacter,
                        Target = null,
                        ActionTarget = ActionTarget.AllEnemies,
                        ActionIndex = specialIndex,
                        ActionType = ActionType.Special,
                        Action = currentCharacter.BattleBehavior.SpecialAbilities[specialIndex]
                    };
                    OnCharacterTurn(args);
                    Finish();
                }
                break;
        }
        UpdateMenu();
        UpdateCharacterName();
    }
Example #3
0
 void OnCharacterTurn(TurnArgs args)
 {
     if (StartCharacterTurn != null)
     {
         StartCharacterTurn(args);
     }
 }
Example #4
0
 void OnCharacterTurn(TurnArgs args)
 {
     wait = false;
     charTurnArgs = args;
 }