Pokemon Sword And Shield VS - Fight Manager

View on GitHub

The feature controls battle flow, animations, and skill damage between player and enemy Pokémon. It manages both turns, handles camera changes, and applies skill effects and status conditions.

This feature was made for a school project where we had to recreate certain features of Pokémon sword and shield in 8 weeks, thus some things are hardcoded and inefficient

Overview

The script links several managers and controls:

  • MenuManager for UI transitions
  • DialogueSystem for move text
  • Skillmanager for damage stats and effects
  • Player and enemy animators for attacks

The class uses multiple serialized references for direct scene access. The setup is functional but depends heavily on manual assignments and specific camera objects.

DoSkill Function

The DoSkill method calculates attack results. It handles accuracy, critical hits, random variation, and type effectiveness. Damage is based on power, level, and relevant stats.

public float DoSkill(int pp, float power, int accuracy, Skillmanager.moveType moveType,
  bool isSpecial, Skillmanager.StatusEffect statusType, Pokemon caster, Pokemon target)
  {
      float isMiss = UnityEngine.Random.Range(0, 100);
      float isCrit = UnityEngine.Random.Range(0, 100);
      float effectivenessMult = 1;
      float random = UnityEngine.Random.Range(85, 100);
      float damage = 0f;

      // Hardcoded effectiveness
      if (moveType == Skillmanager.moveType.Poison &&
          target.type[0] == Pokemon.PokemonType.Fairy && target.type[1] == Pokemon.PokemonType.Grass)
          effectivenessMult += 3;

      if (moveType == Skillmanager.moveType.Fairy &&
          target.type[0] == Pokemon.PokemonType.Poison || target.type[1] == Pokemon.PokemonType.Poison)
          effectivenessMult -= 0.5f;

      if (isMiss < accuracy)
      {
          if (isCrit <= 35.2)
              damage = (((((((2 * caster.level) / 5) * power *
              (caster.specialAttack / target.specialDefense)) / 50) + 2) *
              (random / 100)) * effectivenessMult) * 1.5f;
          else
              damage = ((((((2 * caster.level) / 5) * power *
              (caster.specialAttack / target.specialDefense)) / 50) + 2) *
              (random / 100)) * effectivenessMult;
      }

      if (statusType == Skillmanager.StatusEffect.poison)
          target.isPoisoned = true;

      return damage;
  }

This method is clear but inefficient. Type matchups and calculations are hardcoded, making changes slow and error-prone. Logic repetition increases code size and reduces clarity.

Battle Sequence Screenshot

Attack Sequence

The attack sequence coroutine runs camera transitions, plays animations, and applies visual effects in sync with attacks.

public IEnumerator PokemonAttackSequence(...)
  {
      menuManager.inBattleSequence = true;
      yield return new WaitForSeconds(1.9f);
      Camera3.SetActive(true);
      playerAnimator.Play("AttackAnimation");
      PlayerAttackParticle.SetActive(true);
      yield return new WaitForSeconds(1.5f);
      PlayerAttackParticle.SetActive(false);
      PlayerAttackHitParticle.SetActive(true);
      damage = DoSkill(...);
      yield return new WaitForSeconds(1);
      for (int i = 0; i < damage; i++)
      {
          enemy.healthPoints--;
          yield return new WaitForSeconds(0.01f);
      }
      menuManager.SwitchToBattleMenu();
  }

All camera switches, animation timings, and damage intervals are hardcoded. The logic is functional but fixed to a specific setup.

Enemy Move Selection

The enemy randomly selects from four fixed moves, each calling DoSkill with set parameters.

public float EnemyMove()
  {
      float random = UnityEngine.Random.Range(0, 3);
      random = Mathf.Round(random);

      if (random == 0)
          return DoSkill(... PoisonPowder ...);

      if (random == 1)
          return DoSkill(... DazzlingGleam ...);

      if (random == 2)
          return DoSkill(... StrengthSap ...);

      if (random == 3)
          return DoSkill(... GigaDrain ...);

      return 0f;
  }

The selection is entirely hardcoded. Each skill is manually referenced, which limits reuse and expandability. Random choice ignores Pokémon state or move logic.

Enemy Move Logic

Summary

The FightManager combines gameplay, UI, and animation control in one class. It performs all core functions of a battle but includes hardcoded behavior across damage, animations, and move selection. Despite inefficiencies, it effectively connects the battle flow and visual feedback in Unity.

Back to Projects