Exemplo n.º 1
0
        public override ManaAmount Add(ManaAmount amount)
        {
            var dictionary = new Dictionary <ManaColor, int>();

            foreach (var singleColorAmount in amount)
            {
                dictionary[singleColorAmount.Color] = singleColorAmount.Count;
            }

            if (dictionary.Count == 0)
            {
                return(this);
            }

            foreach (var singleColorAmount in _groups)
            {
                if (dictionary.ContainsKey(singleColorAmount.Color))
                {
                    dictionary[singleColorAmount.Color] += singleColorAmount.Count;
                    continue;
                }

                dictionary[singleColorAmount.Color] = singleColorAmount.Count;
            }

            return(new MultiColorManaAmount(dictionary));
        }
Exemplo n.º 2
0
        public override ManaAmount Remove(ManaAmount amount)
        {
            var dictionary = _groups.ToDictionary(x => x.Color, x => x.Count);

            foreach (var singleColor in amount)
            {
                if (dictionary.ContainsKey(singleColor.Color))
                {
                    if (dictionary[singleColor.Color] <= singleColor.Count)
                    {
                        dictionary.Remove(singleColor.Color);
                    }
                    else
                    {
                        dictionary[singleColor.Color] -= singleColor.Count;
                    }
                }
            }

            if (dictionary.Count == 0)
            {
                return(Mana.Zero);
            }

            if (dictionary.Count == 1)
            {
                return(new SingleColorManaAmount(dictionary.Keys.First(), dictionary.Values.First()));
            }

            return(new MultiColorManaAmount(dictionary));
        }
Exemplo n.º 3
0
        public CardTemplate Pump(ManaAmount cost, string text, int powerIncrease, int toughnessIncrease)
        {
            return(ActivatedAbility(p =>
            {
                p.Text = text;
                p.Cost = new PayMana(cost, supportsRepetitions: true);
                p.Effect = () =>
                {
                    var effect = new ApplyModifiersToSelf(() => new AddPowerAndToughness(
                                                              powerIncrease, toughnessIncrease)
                    {
                        UntilEot = true
                    });

                    if (toughnessIncrease > 0)
                    {
                        effect.SetTags(EffectTag.IncreaseToughness);
                    }

                    if (powerIncrease > 0)
                    {
                        effect.SetTags(EffectTag.IncreasePower);
                    }

                    return effect;
                };
                p.TimingRule(new PumpOwningCardTimingRule(powerIncrease, toughnessIncrease));
                p.RepetitionRule(new RepeatMaxTimes());
            })
                   .CombatRule(() => new PumpCombatRule(powerIncrease, toughnessIncrease, cost)));
        }
Exemplo n.º 4
0
        public override ManaAmount Add(ManaAmount amount)
        {
            var dictionary = new Dictionary <ManaColor, int>();

            foreach (var singleColorAmount in amount)
            {
                dictionary[singleColorAmount.Color] = singleColorAmount.Count;
            }

            if (dictionary.Count == 0)
            {
                return(this);
            }

            if (dictionary.ContainsKey(Color))
            {
                dictionary[Color] += Count;
            }
            else
            {
                dictionary[Color] = Count;
            }

            if (dictionary.Count == 1)
            {
                return(new SingleColorManaAmount(Color, dictionary[Color]));
            }

            return(new MultiColorManaAmount(dictionary));
        }
Exemplo n.º 5
0
        private static IEnumerable <CardColor> GetCardColorsFromManaCost(ManaAmount manaCost)
        {
            if (manaCost == null)
            {
                yield return(CardColor.None);

                yield break;
            }

            if (manaCost.Converted == 0)
            {
                yield return(CardColor.Colorless);

                yield break;
            }

            var existing = new HashSet <CardColor>();

            foreach (var mana in manaCost)
            {
                if (mana.Color.IsWhite && !existing.Contains(CardColor.White))
                {
                    existing.Add(CardColor.White);
                    yield return(CardColor.White);
                }

                if (mana.Color.IsBlue && !existing.Contains(CardColor.Blue))
                {
                    existing.Add(CardColor.Blue);
                    yield return(CardColor.Blue);
                }

                if (mana.Color.IsBlack && !existing.Contains(CardColor.Black))
                {
                    existing.Add(CardColor.Black);
                    yield return(CardColor.Black);
                }

                if (mana.Color.IsRed && !existing.Contains(CardColor.Red))
                {
                    existing.Add(CardColor.Red);
                    yield return(CardColor.Red);
                }

                if (mana.Color.IsGreen && !existing.Contains(CardColor.Green))
                {
                    existing.Add(CardColor.Green);
                    yield return(CardColor.Green);
                }
            }

            if (existing.Count == 0)
            {
                yield return(CardColor.Colorless);
            }
        }
Exemplo n.º 6
0
        public bool Has(
            ManaAmount amount,
            ManaUsage usage,
            ConvokeAndDelveOptions convokeAndDelveOptions)
        {
            var allocated = TryToAllocateAmount(
                amount,
                usage,
                convokeAndDelveOptions);

            return(allocated != null && allocated.Lifeloss < _controller.Life);
        }
Exemplo n.º 7
0
        public CardTemplate Regenerate(ManaAmount cost, string text)
        {
            return(ActivatedAbility(p =>
            {
                p.Text = text;
                p.Cost = new PayMana(cost);
                p.Effect = () => new RegenerateOwner();

                p.TimingRule(new RegenerateSelfTimingRule());
            })
                   .CombatRule(() => new RegenerateCombatRule(cost)));
        }
Exemplo n.º 8
0
        private void AddUnits(ManaAmount amount)
        {
            foreach (var singleColor in amount)
            {
                for (var i = 0; i < singleColor.Count; i++)
                {
                    var unit = CreateManaUnit(singleColor.Color);

                    _units.Add(unit);
                    _manaCache.Add(unit);
                }
            }
        }
Exemplo n.º 9
0
        public void AddManaToPool(ManaAmount 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);
                    }
                }
            }
        }
Exemplo n.º 10
0
        public override ManaAmount Remove(ManaAmount amount)
        {
            var count = Count;

            foreach (var singleColor in amount)
            {
                if (singleColor.Color == Color)
                {
                    count -= singleColor.Count;
                }
            }

            if (count > 0)
            {
                return(new SingleColorManaAmount(Color, count));
            }

            return(Mana.Zero);
        }
Exemplo n.º 11
0
        public void Consume(
            ManaAmount amount,
            ManaUsage usage,
            ConvokeAndDelveOptions convokeAndDelveOptions)
        {
            var allocated = TryToAllocateAmount(amount, usage, convokeAndDelveOptions);

            Asrt.True(allocated != null, "Not enough mana available.");

            var sources = GetSourcesToActivate(allocated.Units);

            foreach (var source in sources)
            {
                lock (_manaPoolCountLock)
                {
                    foreach (var unit in source.GetUnits())
                    {
                        _manaPool.Add(unit);
                    }
                }

                source.PayActivationCost();
            }

            lock (_manaPoolCountLock)
            {
                foreach (var unit in allocated.Units)
                {
                    _manaPool.Remove(unit);
                }
            }

            foreach (var unit in allocated.Units.Where(x => !x.HasSource))
            {
                RemovePermanently(unit);
            }

            _controller.Life -= allocated.Lifeloss;
        }
Exemplo n.º 12
0
        private void RemoveUnits(ManaAmount amount)
        {
            if (_units.Count == 0)
            {
                return;
            }

            foreach (var singleColor in amount)
            {
                for (var i = 0; i < singleColor.Count; i++)
                {
                    var unit = _units.FirstOrDefault(x => x.Color == singleColor.Color);
                    if (unit == null)
                    {
                        break;
                    }

                    _units.Remove(unit);
                    _manaCache.Remove(unit);
                }
            }
        }
Exemplo n.º 13
0
 public void AddAditionalAmountAbilityWillProduce(ManaAmount amount)
 {
     AddUnits(amount);
     _p.ManaOutput.AddAditional(amount);
 }
Exemplo n.º 14
0
 public void RemoveAdditionalAmountAbilityWillProduce(ManaAmount amount)
 {
     RemoveUnits(amount);
     _p.ManaOutput.RemoveAdditional(amount);
 }
Exemplo n.º 15
0
 public bool HasMana(ManaAmount amount, ManaUsage usage            = ManaUsage.Any,
                     ConvokeAndDelveOptions convokeAndDelveOptions = null)
 {
     return(ManaCache.Has(amount, usage, convokeAndDelveOptions));
 }
Exemplo n.º 16
0
 public void Consume(ManaAmount amount, ManaUsage usage, ConvokeAndDelveOptions convokeAndDelveOptions = null)
 {
     ManaCache.Consume(amount, usage, convokeAndDelveOptions);
 }
Exemplo n.º 17
0
 public void AddManaToManaPool(ManaAmount manaAmount, ManaUsage usageRestriction = ManaUsage.Any)
 {
     ManaCache.AddManaToPool(manaAmount, usageRestriction);
 }
Exemplo n.º 18
0
 private void OnOutputIncreased(ManaAmount amount)
 {
     AddUnits(amount);
 }
Exemplo n.º 19
0
 public void RemoveAdditional(ManaAmount amount)
 {
     _additionalOutput.Value = _additionalOutput.Value.Remove(amount);
 }
Exemplo n.º 20
0
 public abstract ManaAmount Remove(ManaAmount amount);
Exemplo n.º 21
0
 private void OnOutputDecreased(ManaAmount amount)
 {
     RemoveUnits(amount);
 }
Exemplo n.º 22
0
        private AllocatedAmount TryToAllocateAmount(
            ManaAmount amount,
            ManaUsage usage,
            ConvokeAndDelveOptions convokeAndDelveOptions)
        {
            var restricted = new HashSet <ManaUnit>();
            var allocated  = new AllocatedAmount();

            var additional        = GetAdditionalManaSources(convokeAndDelveOptions);
            var additionalGrouped = GroupAdditionalSources(additional);
            var units             = _units.Concat(additional).ToList();

            var checkAmount = amount
                              .Select(x => new
            {
                Color       = GetColorIndex(x),
                Count       = x.Count,
                IsPhyrexian = x.Color.IsPhyrexian
            })
                              // first check for mana which has only few mana sources
                              .OrderBy(x => _groups[x.Color].Count)
                              .ToArray();

            var allocatedPhyrexian = new List <ManaUnit>();

            foreach (var manaOfSingleColor in checkAmount)
            {
                var ordered = _groups[manaOfSingleColor.Color]
                              .Concat(additionalGrouped[manaOfSingleColor.Color])
                              .OrderBy(GetManaUnitAllocationOrder)
                              .ToList();

                for (var i = 0; i < manaOfSingleColor.Count; i++)
                {
                    var allocatedUnit = ordered.FirstOrDefault(unit => IsAvailable(unit, restricted, usage));

                    // allocation failed
                    if (allocatedUnit == null)
                    {
                        if (manaOfSingleColor.IsPhyrexian)
                        {
                            allocated.Lifeloss += 2;
                            continue;
                        }

                        // if pyrexian is holding the slot, release it and pay life
                        if (allocatedPhyrexian.Count > 0)
                        {
                            var restrictedWithoutPhyrexian = restricted.Where(x => !allocatedPhyrexian.Contains(x)).ToHashSet();
                            allocatedUnit = ordered.FirstOrDefault(unit => IsAvailable(unit, restrictedWithoutPhyrexian, usage));

                            if (allocatedUnit != null)
                            {
                                allocated.Lifeloss += 2;
                                allocatedPhyrexian.Remove(allocatedUnit);
                                continue;
                            }
                        }

                        return(null);
                    }

                    if (manaOfSingleColor.IsPhyrexian)
                    {
                        allocatedPhyrexian.Add(allocatedUnit);
                    }

                    restricted.Add(allocatedUnit);
                    allocated.Units.Add(allocatedUnit);

                    RestrictUsingDifferentSourcesFromSameCard(allocatedUnit, restricted, units);
                }
            }

            return(allocated);
        }
Exemplo n.º 23
0
 public override ManaAmount Add(ManaAmount amount)
 {
     return(amount);
 }
Exemplo n.º 24
0
 public abstract ManaAmount Add(ManaAmount amount);
Exemplo n.º 25
0
 public override ManaAmount Remove(ManaAmount amount)
 {
     return(Mana.Zero);
 }
Exemplo n.º 26
0
 public void ManaAmount(ManaAmount amount)
 {
     ManaOutput = new FixedManaOutput(amount);
     Colors     = amount.Colors.ToList();
 }
Exemplo n.º 27
0
 public void AddAditional(ManaAmount amount)
 {
     _additionalOutput.Value = _additionalOutput.Value.Add(amount);
 }