// ----------------------------------------------------------------------------- void SelectOrderOfActions() { m_isPlayerInPhase1 = false; // TODO - if a wild pokemon can flee the fight without attacking (Safari Park for example), add the condition here; // Running from a fight is resolve before any other action in the turn. // If a player plays an object, it will be done before any action from the AI if (m_playerAction.GetActionType() == ECombatActionType.Run || m_playerAction.GetActionType() == ECombatActionType.Object) { m_isPlayerInPhase1 = true; } // A switch from the player will also be done before any action from the AI, but can be done after some special attacks else if (m_AiAction.GetActionType() == ECombatActionType.Switch) { // For now true. Cannot always be true with some attack like "Pursuit" m_isPlayerInPhase1 = true; } else if (m_AiAction.GetActionType() == ECombatActionType.Attack) // if both pokemon attacks, select the fastest attack { CAttackAction playerAttackAction = (CAttackAction)m_playerAction; CAttackAction aiAttackAction = (CAttackAction)m_AiAction; int playerPriority = AttackDatabase.GetAttackById(playerAttackAction.attackId).m_priorite; int aiPriority = AttackDatabase.GetAttackById(aiAttackAction.attackId).m_priorite; // if higher attack priority for the player's pokemon if (playerPriority > aiPriority) { m_isPlayerInPhase1 = true; } else if (playerPriority == aiPriority) { int playerPokemonSpeed = GetPokemonSpeed(m_playerPokemon, true); int aiPokemonSpeed = GetPokemonSpeed(m_opponentPokemon, false); // If player's pokemon is faster if (playerPokemonSpeed > aiPokemonSpeed) { m_isPlayerInPhase1 = true; } else if (playerPokemonSpeed == aiPokemonSpeed) // if both pokemon goes to the same speed, then select one at random to attack first { if (Random.Range(0, 2) == 0) { m_isPlayerInPhase1 = true; } } } } }
// ----------------------------------------------------------------------------- void ResolveAttackPhase(EBattleStates state) { bool isPlayer = state == EBattleStates.eAtkPhase1 && m_isPlayerInPhase1 || state == EBattleStates.eAtkPhase2 && !m_isPlayerInPhase1; CCombatAction action; Pokemon attackingPokemon; Pokemon defendingPokemon; if (isPlayer) { m_playerAttacking = true; action = m_playerAction; attackingPokemon = m_playerPokemon; defendingPokemon = m_opponentPokemon; } else { m_playerAttacking = false; action = m_AiAction; attackingPokemon = m_opponentPokemon; defendingPokemon = m_playerPokemon; } switch (action.GetActionType()) { case ECombatActionType.Run: { // Only player can run away for now m_playerPokeValues.fleeAttempts++; if (CanRunAway()) { StopFight(false, true); } else // if the run attempt fails, the turn is lost { GoToState(m_battleState + 1); } } break; case ECombatActionType.Switch: { OnSwitch(isPlayer, (CSwitchAction)action); } break; case ECombatActionType.Object: { // TODO } break; case ECombatActionType.Attack: { CAttackAction attackAction = (CAttackAction)action; Attack attack = FindObjectOfType <Attack> (); if (attack) { attack.StartAttack(attackAction.attackId, attackingPokemon, defendingPokemon); } } break; default: break; } }