Ejemplo n.º 1
0
    /// <summary>
    /// Select a unit stack from a list of existing ones and make an illusory clone of it
    /// </summary>
    /// <param name="existing">The list of existing unit stacks</param>
    public override UnitStack Create(List <UnitStack> existing)
    {
        if (existing.Count > 0)
        {
            UnitStack toClone = existing[0];
            int       qty     = toClone.GetTotalQty();
            int       candidateQty;
            for (int i = 1; i < existing.Count; i++)
            {
                candidateQty = existing[i].GetTotalQty();
                if (candidateQty > qty)
                {
                    toClone = existing[i];
                    qty     = candidateQty;
                }
            }

            UnitType illusion = new UnitType(toClone.GetUnitType());
            illusion.SetShield(0);
            illusion.SetArmor(0);
            illusion.SetHitPoints(1);
            illusion.AddAttackQuality(AttackData.Quality.ILLUSORY);

            Unit      mirrorImage = new Unit(illusion, toClone.GetTotalQty());
            UnitStack stack       = new UnitStack(mirrorImage, toClone.GetProvinceToRetreat());
            stack.AffectBySpell(this);

            return(stack);
        }
        return(null);
    }
Ejemplo n.º 2
0
    private void CreateUnitStackViewsForSide(GameObject[] spawnPoints)
    {
        bool             areProcessingAttackers = spawnPoints == _attackersSpawnPoints;
        List <UnitStack> stacks = _model.GetUnitStacks(areProcessingAttackers);
        Dictionary <UnitStack, UnitStackView> stackViews = areProcessingAttackers ? _attackerStackViews : _defenderStackViews;
        int offset = areProcessingAttackers ? _attackerStackViewsOffset : _defenderStackViewsOffset;

        int count = Mathf.Min(stacks.Count - offset, spawnPoints.Length);

        for (int i = 0; i < count; i++)
        {
            UnitStack currentStack = stacks[i + offset];

            UnitStackView view = (UnitStackView)Instantiate(_unitStackViewPrefab, spawnPoints[i].transform.position, Quaternion.identity);
            view.transform.parent = spawnPoints[i].transform;
            view.SetModel(currentStack);
            if (currentStack.GetProvinceToRetreat().GetOwnersFaction().IsPC())
            {
                view.StackSelected += OnPlayerSelectedDefendingUnitStack;
            }
            view.ExplosionAnimationCompleted += OnExplosionAnimationCompleted;
            view.StackInspected       += OnStackInspected;
            view.StackInspectionEnded += OnUnitTypeInspectionEnded;
            stackViews[currentStack]   = view;
        }
    }
Ejemplo n.º 3
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="stack">The unit stack to clone</param>
 public UnitStack(UnitStack stack)
 {
     _baseUnit              = new Unit(stack.GetBaseUnit());
     _provinceToRetreat     = stack.GetProvinceToRetreat();
     _hitPointsDistribution = new int[_baseUnit.GetUnitType().GetHitPoints()];
     for (int i = 0; i < _hitPointsDistribution.Length; i++)
     {
         _hitPointsDistribution[i] = stack._hitPointsDistribution[i];
     }
     _affectingSpells = new List <Spell>();
 }