/// <summary> /// Spawns a unit with the given parameters and adds it to battle. /// </summary> /// <param name="type">The type of unit to spawn</param> /// <param name="side">The Faction that the unit should 'fight for'</param> /// <param name="spawnPos">The GridPoint at which the created unit should spawn</param> public void SpawnCombatantOfType(UnitTypes type, Faction side, GridPoint spawnPos = null) { IMovementBehavior movement = null; IAttackBehavior attack = null; ITargetBehavior target = null; Unit testUnit = null; switch (type) { case UnitTypes.Caveman: // movement movement = MovementBehaviorFactory.SpawnBehavior(UnitMoverType.Walker, 1, spawnPos); // attack attack = AttackBehaviorFactory.SpawnBehavior(UnitAttackType.NeverAttacks, side); // target target = TargetBehaviorFactory.SpawnBehavior(UnitArmorType.Armored); break; case UnitTypes.Knight: // movement movement = MovementBehaviorFactory.SpawnBehavior(UnitMoverType.Walker, 1, spawnPos); // attack attack = AttackBehaviorFactory.SpawnBehavior(UnitAttackType.NeverAttacks, side); // target target = TargetBehaviorFactory.SpawnBehavior(UnitArmorType.Armored); break; case UnitTypes.Soldier: // movement movement = MovementBehaviorFactory.SpawnBehavior(UnitMoverType.Walker, 1, spawnPos); // attack attack = AttackBehaviorFactory.SpawnBehavior(UnitAttackType.NeverAttacks, side); // target target = TargetBehaviorFactory.SpawnBehavior(UnitArmorType.Armored); break; case UnitTypes.Swat: // movement movement = MovementBehaviorFactory.SpawnBehavior(UnitMoverType.Walker, 1, spawnPos); // attack attack = AttackBehaviorFactory.SpawnBehavior(UnitAttackType.NeverAttacks, side); // target target = TargetBehaviorFactory.SpawnBehavior(UnitArmorType.Armored); break; case UnitTypes.Tric: // movement movement = MovementBehaviorFactory.SpawnBehavior(UnitMoverType.Walker, 1, spawnPos); // attack attack = AttackBehaviorFactory.SpawnBehavior(UnitAttackType.NeverAttacks, side); // target target = TargetBehaviorFactory.SpawnBehavior(UnitArmorType.Armored); break; case UnitTypes.Boss: // movement movement = MovementBehaviorFactory.SpawnBehavior(UnitMoverType.Walker, 1, spawnPos); // attack attack = AttackBehaviorFactory.SpawnBehavior(UnitAttackType.NeverAttacks, side); // target target = TargetBehaviorFactory.SpawnBehavior(UnitArmorType.Armored); break; case UnitTypes.FlyingKappa: // movement movement = MovementBehaviorFactory.SpawnBehavior(UnitMoverType.Flyer, 1, spawnPos); // attack attack = AttackBehaviorFactory.SpawnBehavior(UnitAttackType.NeverAttacks, side); // target target = TargetBehaviorFactory.SpawnBehavior(UnitArmorType.Armored); break; case UnitTypes.WalkingKappa: // movement movement = MovementBehaviorFactory.SpawnBehavior(UnitMoverType.Walker, 2, spawnPos); // attack attack = AttackBehaviorFactory.SpawnBehavior(UnitAttackType.NeverAttacks, side); // target target = TargetBehaviorFactory.SpawnBehavior(UnitArmorType.Armored); break; case UnitTypes.DummyTower: // movement movement = MovementBehaviorFactory.SpawnBehavior(UnitMoverType.NoMovement, 5, spawnPos); // attack attack = AttackBehaviorFactory.SpawnBehavior(UnitAttackType.StopsToAttack, side, .5f, 10, 10); // target target = TargetBehaviorFactory.SpawnBehavior(UnitArmorType.Armored); break; default: Debug.LogError("Did you forget to add a unit type to SpawnCombatant?"); break; } if (movement == null || attack == null || target == null) Debug.LogError("Unit didn't instantiate correctly :("); _spawnedUnits[type]++; if (spawnPos == null) spawnPos = NavigationController.Instance.FirstTile; // TODO: this is here until units can decide where to go themselves movement.PathTo(NavigationController.Instance.LastTile); testUnit = new Unit(String.Format(type.ToString() + "-" + _spawnedUnits[type]), type, side, movement, attack, target); spawnPos.AddToTile(testUnit); AddCombatantToActiveBattle(testUnit); if (type == UnitTypes.DummyTower) SoundPlayer.getInstance ().Play (sounds.tower); else SoundPlayer.getInstance().Play (sounds.spawn); }