Esempio n. 1
0
        public Projectile(Unit attacker, Unit target, float speed)
        {
            // how do we want to get projectile names?
            _attacker = attacker;
            _target = target;
            _currentLocation = attacker.CurrentLocation;
            _damage = attacker.AttackBehavior.AttackDamage;
            _speed = speed;
            _targetPosition = _target.CurrentLocation;
            _destroy = false;

            //Debug.Log("attacker @ " + attacker.CurrentLocation + ", target @ " + target.CurrentLocation);

            _projectileView = new ProjectileView(this, _currentLocation);
        }
Esempio n. 2
0
 public static Unit CreateUnitAtPos(Unit unit, GridPoint pos)
 {
     return null;
 }
Esempio n. 3
0
 /// <summary>
 /// Adds the provided to the CombatController pending unit list.
 /// </summary>
 /// <param name="u">The unit to be added to combat</param>
 private void AddCombatantToActiveBattle(Unit u)
 {
     _pendingUnits.Add(u);
 }
Esempio n. 4
0
        /// <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);
        }
Esempio n. 5
0
        /// <summary>
        /// Spawns a new projectile and adds it to the list of pending projectiles in the
        /// CombatController.
        /// </summary>
        /// <param name="attacker">The unit that will spawn the projectile</param>
        /// <param name="target">The unit that the projectile will travel towards</param>
        public void LaunchAttackAtUnit(Unit attacker, Unit target)
        {
            // TODO where do we want to store projectile speed?
            Projectile newProjectile = new Projectile(attacker, target, 30);

            _pendingProjectiles.Add(newProjectile);
            //Debug.Log(attacker + " launched an attack at " + target + "!");

            SoundPlayer.getInstance ().Play (sounds.light_projectile);
        }
Esempio n. 6
0
        public UnitView(Unit owner, UnitTypes unitType)
        {
            _owner = owner;

            _unit = GuiAPI.CreateUnit(UnitPosition.x, UnitPosition.y, unitType);
        }