public OID CreateObject(MTGObject obj) { OID oid = new OID(); objects.Add(oid, obj); return(oid); }
protected override string OptionString(OID option) { MTGObject obj = MTG.Instance.objects[option]; string str = obj.attr.name + " -"; foreach (var cardType in obj.attr.cardTypes) { str += " " + cardType.GetString(); } return(str); }
public void CalculateBoardState() { UpdateAllModifications(); UpdateAllTriggeredAbilities(); foreach (var x in objects) { OID oid = x.Key; MTGObject obj = x.Value; obj.CalculateAttributes(); } HandlePendingTriggers(); }
protected override string OptionString(PlayerOrOID option) { switch (option.type) { case PlayerOrOID.ValueType.OID: MTGObject obj = MTG.Instance.objects[option.OID]; string str = obj.attr.name + " -"; foreach (var cardType in obj.attr.cardTypes) { str += " " + cardType.GetString(); } return(str); case PlayerOrOID.ValueType.Player: return("Player " + option.Player.ToString()); default: throw new NotImplementedException(); } }
public MTG(params List <MTGObject.BaseCardAttributes>[] libraries) { instance = this; int playerIndex = 0; foreach (var library in libraries) { Player player = new Player(); foreach (var i in library) { var cardattr = i; cardattr.owner = playerIndex; MTGObject mtgObject = new MTGObject(cardattr); OID oid = CreateObject(mtgObject); player.library.Add(oid); } players.Add(player); playerIndex++; } }
public ManaChoice(List <ManaSymbol> manaSymbols, ManaSymbol manaToPay, int playerIndex) { Title = $"Choose which mana to use to pay for {manaToPay}"; Min = 1; Max = 1; Options = new List <ManaChoiceOption>(); Cancellable = true; foreach (var mana in manaSymbols) { Options.Add(new ManaChoiceOption { type = ManaChoiceOption.OptionType.UseMana, manaSymbol = mana }); } foreach (var kvp in MTG.Instance.objects) { OID oid = kvp.Key; MTGObject obj = kvp.Value; if (obj.attr.controller != playerIndex) { continue; } foreach (var ability in obj.attr.activatedAbilities) { if (ability is ManaAbility && ability.CanBeActivated(oid)) { Options.Add(new ManaChoiceOption { type = ManaChoiceOption.OptionType.ActivateManaAbility, manaAbilitySource = oid, manaAbility = ability as ManaAbility }); } } } }
public void ResolveTop() { MTG mtg = MTG.Instance; OID oid = Get(0); MTGObject obj = mtg.objects[oid]; obj.Resolve(); if (obj is AbilityObject) { mtg.DeleteObject(oid); } else { if (obj.CanBePermanent) { mtg.MoveZone(oid, this, mtg.battlefield); } else { mtg.MoveZone(oid, this, mtg.players[obj.owner].graveyard); } } }
public PriorityChoice() { Min = 1; Max = 1; Title = "Choose what to do with your priority!"; var mtg = MTG.Instance; var player = mtg.players[mtg.turn.playerPriorityIndex]; // What can a player do when they have priority? Options = new List <PriorityOption>(); // They can pass, of course Options.Add(new PriorityOption { type = PriorityOption.OptionType.PassPriority }); // 117.1a A player may cast an instant spell any time they have priority. A player may cast a noninstant spell during their main phase any time they have priority and the stack is empty. foreach (var oid in player.hand) { var cardtypes = mtg.objects[oid].attr.cardTypes; // TODO - This is an oversimplification if (cardtypes.Contains(MTGObject.CardType.Land)) { continue; } // TODO - Also an oversimplification :) (for the card type check at least) if (!mtg.CanCastSorceries && !cardtypes.Contains(MTGObject.CardType.Instant)) { continue; } if (!mtg.objects[oid].CanPayCastingCosts()) { continue; } Options.Add(new PriorityOption { type = PriorityOption.OptionType.CastSpell, source = oid, }); } // 117.1b A player may activate an activated ability any time they have priority. foreach (var kvp in mtg.objects) { OID oid = kvp.Key; MTGObject obj = kvp.Value; if (obj.attr.controller != mtg.turn.playerPriorityIndex) { continue; } foreach (var ability in obj.attr.activatedAbilities) { if (!(ability is ManaAbility) && ability.CanBeActivated(oid)) { Options.Add(new PriorityOption { type = PriorityOption.OptionType.ActivateAbility, source = oid, activatedAbility = ability }); } } } // 117.1c A player may take some special actions any time they have priority.A player may take other special actions during their main phase any time they have priority and the stack is empty.See rule 116, “Special Actions.” foreach (var oid in player.hand) { var cardtypes = mtg.objects[oid].attr.cardTypes; if (mtg.CanCastSorceries && cardtypes.Contains(MTGObject.CardType.Land)) { // TODO - One land per turn. Need the events log and a land drop total system Options.Add(new PriorityOption { type = PriorityOption.OptionType.PlayLand, source = oid }); } } // 117.1d A player may activate a mana ability whenever they have priority, whenever they are casting a spell or activating an ability that requires a mana payment, or whenever a rule or effect asks for a mana payment(even in the middle of casting or resolving a spell or activating or resolving an ability). foreach (var kvp in mtg.objects) { OID oid = kvp.Key; MTGObject obj = kvp.Value; if (obj.attr.controller != mtg.turn.playerPriorityIndex) { continue; } foreach (var ability in obj.attr.activatedAbilities) { if (ability is ManaAbility && ability.CanBeActivated(oid)) { Options.Add(new PriorityOption { type = PriorityOption.OptionType.ManaAbility, source = oid, activatedAbility = ability }); } } } }