Ejemplo n.º 1
0
        public void Add(ManaUnit unit)
        {
            foreach (var colorIndex in unit.Color.Indices)
            {
                _groups[colorIndex].Add(unit);
            }

            // Every mana can be used as colorless.
            // True colorless mana was already added, so we don't add it again.
            if (unit.Color.IsColorless == false)
                _units.Add(unit);
        }
Ejemplo n.º 2
0
        public void AddManaToPool(IManaAmount amount, ManaUsage usage)
        {
            lock (_manaPoolCountLock)
            {
                foreach (var mana in amount)
                {
                    for (var i = 0; i < mana.Count; i++)
                    {
                        var unit = new ManaUnit(mana.Color, 0, usageRestriction: usage);
                        Add(unit);

                        _manaPool.Add(unit);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void RestrictUsingDifferentSourcesFromSameCard(ManaUnit allocated, HashSet<ManaUnit> restricted)
        {
            // Same card cannot be tapped twice, therefore multiple sources
            // from same card cannot be used simultaniously.

            // Add to restricted all units produced by another source
            // of the same card.
            var unitsProducedByAnotherSourceOnSameCard = _units.Where(
              unit => unit.HasSource && allocated.HasSource &&
                unit.Source.OwningCard == allocated.Source.OwningCard
                && unit.Source != allocated.Source);

            foreach (var unit in unitsProducedByAnotherSourceOnSameCard)
            {
                restricted.Add(unit);
            }
        }
Ejemplo n.º 4
0
        private void RemovePermanently(ManaUnit unit)
        {
            foreach (var colorIndex in unit.Color.Indices)
            {
                _groups[colorIndex].Remove(unit);
            }

            _units.Remove(unit);
        }
Ejemplo n.º 5
0
        private bool IsAvailable(ManaUnit unit, HashSet<ManaUnit> restricted, ManaUsage usage)
        {
            if (restricted.Contains(unit))
                return false;

            if (unit.CanActivateSource() == false && _manaPool.Contains(unit) == false)
                return false;

            if (unit.CanBeUsed(usage) == false)
                return false;

            return true;
        }
Ejemplo n.º 6
0
 private int GetManaUnitAllocationOrder(ManaUnit x)
 {
     return _manaPool.Contains(x) ? 0 : x.Rank * 10 + x.Color.Indices.Count;
 }
Ejemplo n.º 7
0
        public void Remove(ManaUnit unit)
        {
            if (_manaPool.Contains(unit))
            {
                _removeList.Add(unit);
                return;
            }

            RemovePermanently(unit);
        }