Ejemplo n.º 1
0
            public override void DoAction(float strength, SquadContainer teammates, SquadContainer enemies, SimpleCallbackDelegate onOverCallback)
            {
                if (enemies == null)
                {
                    Utils.Logger.GetInstance().Error("enemies is null");
                    onOverCallback();
                    return;
                }
                SquadUnitController[] distancelineEnemies = enemies.GetDistanceLineUnits();
                if (distancelineEnemies == null || distancelineEnemies.Length <= 0)
                {
                    Utils.Logger.GetInstance().Message("failed to get distanceline enemies");
                    onOverCallback();
                    return;
                }
                SquadUnitController enemy = distancelineEnemies[Randomizer.Range(0, distancelineEnemies.Length)];

                if (enemy == null || enemy.Damagable == null)
                {
                    onOverCallback();
                    return;
                }
                AttackAnimation.DoAnimation(enemy.transform.position, () =>
                {
                    enemy.Damagable.ReceiveDamage(strength);
                }, () =>
                {
                    onOverCallback();
                });
            }
Ejemplo n.º 2
0
        internal void Action(ActionType type, float attackStrength, SimpleCallbackDelegate attackOverCallback)
        {
            if (type == ActionType.Defence)
            {
                Defence(attackStrength, attackOverCallback);
                return;
            }
            SquadUnitController unit = currentSquad.GetUnitByType(GetUnitTypeByActionType(type));

            if (unit == null)
            {
                Utils.Logger.GetInstance().Message("Failed to fine unit with type Close");
                return;
            }
            if (unit.Actionable != null)
            {
                if (unit.Statistic != null && !unit.Statistic.IsDied)
                {
                    unit.Actionable.DoAction(attackStrength, currentSquad, enemySquad, attackOverCallback);
                }
                else
                {
                    attackOverCallback();
                }
            }
        }
Ejemplo n.º 3
0
        internal void Init()
        {
            currentSquad = new SquadContainer(2, 2);
            for (int i = 0; i < 4; i++)
            {
                UnitType   type   = i == 0 ? UnitType.CloseAttack : i == 1 ? UnitType.MassiveAttack : i == 2 ? UnitType.DistanceAttack : UnitType.Healer;
                GameObject prefab = (GameObject)Resources.Load(prefabPaths[i]);
                GameObject go     = Instantiate(prefab);
                go.transform.parent = this.transform;
                //if (this.transform.localPosition.x > 0.0f)
                //{
                //    go.transform.localPosition = new Vector3(i / 2 == 0 ? -1.5f : 1.5f, 1.0f, i % 2 == 0 ? 0.5f : -0.5f);
                //}
                //else
                //{
                //    go.transform.localPosition = new Vector3(i / 2 == 0 ? 1.5f : -1.5f, 1.0f, i % 2 == 0 ? 0.5f : -0.5f);
                //}
                go.transform.localPosition = charactersPositions[i];

                SquadUnitController unit = (SquadUnitController)go.GetComponent <SquadUnitController>();
                currentSquad.SetUnit(unit, i / 2, i % 2);
                unit.Type           = type;
                unit.OnDieEvent    += OnUnitDiedEvent;
                unit.OnReviveEvent += OnUnitReviveEvent;
            }
        }
Ejemplo n.º 4
0
 private void OnUnitDiedEvent(SquadUnitController sender)
 {
     diedUnitsCount++;
     if (diedUnitsCount == 4)
     {
         Utils.Logger.GetInstance().Message(gameObject.name + ": GAME OVER");
         if (null != OnSquadDefeatedEvent)
         {
             OnSquadDefeatedEvent(this);
         }
     }
 }
Ejemplo n.º 5
0
 internal void SetUnit(SquadUnitController unit, int d, int l)
 {
     if (d >= depth || l >= lines)
     {
         Utils.Logger.GetInstance().Error("Position[" + d + "," + l + "] is out of range");
         return;
     }
     if (units[d * lines + l] != null)
     {
         Utils.Logger.GetInstance().Error("Position[" + d + "," + l + "] is not empty");
     }
     units[d * lines + l] = unit;
 }
Ejemplo n.º 6
0
 private void OnUnitReviveEvent(SquadUnitController sender)
 {
     diedUnitsCount--;
 }