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)); }
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)); }
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))); }
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)); }
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); } }
public bool Has( ManaAmount amount, ManaUsage usage, ConvokeAndDelveOptions convokeAndDelveOptions) { var allocated = TryToAllocateAmount( amount, usage, convokeAndDelveOptions); return(allocated != null && allocated.Lifeloss < _controller.Life); }
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))); }
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); } } }
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); } } } }
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); }
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; }
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); } } }
public void AddAditionalAmountAbilityWillProduce(ManaAmount amount) { AddUnits(amount); _p.ManaOutput.AddAditional(amount); }
public void RemoveAdditionalAmountAbilityWillProduce(ManaAmount amount) { RemoveUnits(amount); _p.ManaOutput.RemoveAdditional(amount); }
public bool HasMana(ManaAmount amount, ManaUsage usage = ManaUsage.Any, ConvokeAndDelveOptions convokeAndDelveOptions = null) { return(ManaCache.Has(amount, usage, convokeAndDelveOptions)); }
public void Consume(ManaAmount amount, ManaUsage usage, ConvokeAndDelveOptions convokeAndDelveOptions = null) { ManaCache.Consume(amount, usage, convokeAndDelveOptions); }
public void AddManaToManaPool(ManaAmount manaAmount, ManaUsage usageRestriction = ManaUsage.Any) { ManaCache.AddManaToPool(manaAmount, usageRestriction); }
private void OnOutputIncreased(ManaAmount amount) { AddUnits(amount); }
public void RemoveAdditional(ManaAmount amount) { _additionalOutput.Value = _additionalOutput.Value.Remove(amount); }
public abstract ManaAmount Remove(ManaAmount amount);
private void OnOutputDecreased(ManaAmount amount) { RemoveUnits(amount); }
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); }
public override ManaAmount Add(ManaAmount amount) { return(amount); }
public abstract ManaAmount Add(ManaAmount amount);
public override ManaAmount Remove(ManaAmount amount) { return(Mana.Zero); }
public void ManaAmount(ManaAmount amount) { ManaOutput = new FixedManaOutput(amount); Colors = amount.Colors.ToList(); }
public void AddAditional(ManaAmount amount) { _additionalOutput.Value = _additionalOutput.Value.Add(amount); }