public bool ExecutePlay(Card card) { var args = new PlayCardEventArgs(this, card); PlayCardEvent.Call(args); return(args.succesful); }
public void ClientRequestPlayCard(Card card) { if (isLocalPlayer && CanPlayCard(card)) { SoundLibrary.PlaySound("card"); PlayCardEvent playEvent = new PlayCardEvent(this, card); CmdSendPlayCardEvent(playEvent); } }
public Player(string name, Card[] deck) { this.name = name; this.deck = new Deck(deck, this); hand = new Hand(this); field = new Field(this); grave = new Grave(this); DrawEvent.Subscribe(this, 0, Draw); PlayCardEvent.Subscribe(this, 0, Play); AttackOrderEvent.Subscribe(this, 0, AttackOrder); AttackEvent.Subscribe(this, 0, Attack); DamageEvent.Subscribe(this, 0, Damage); DeathEvent.Subscribe(this, 0, Death); }
private void HandleTargetEvent(TargetSelectionEvent targetEvent) { // Validate all targets Card card = gameSession.GetPendingCard(targetEvent.playerId.GetComponent <PlayerController>()); bool isValid = false; if (card != null && targetEvent.playerId == gameSession.GetWaitingOnPlayer().netIdentity) { PlayerController player = gameSession.GetWaitingOnPlayer(); TriggerCondition triggerCondition = gameSession.GetPendingTriggerCondition(); NetworkIdentity[][] targets = targetEvent.ReconstructTargets(); List <ITargettingDescription> selectableTargetDescriptions = null; GameSession.PendingType pendingType = gameSession.GetPendingActionType(); if (pendingType == GameSession.PendingType.REPLACE_CREATURE) { selectableTargetDescriptions = GameUtils.ReplaceCreatureTargetDescriptions(); } else { switch (card.cardData.GetCardType()) { case CardType.CREATURE: selectableTargetDescriptions = card.cardData.GetSelectableTargets(triggerCondition); break; case CardType.SPELL: case CardType.TRAP: selectableTargetDescriptions = card.cardData.GetSelectableTargets(TriggerCondition.NONE); break; } } if (selectableTargetDescriptions != null && selectableTargetDescriptions.Count == targets.Length) { isValid = true; for (int i = 0; i < selectableTargetDescriptions.Count; i++) { ITargettingDescription desc = selectableTargetDescriptions[i]; if (desc.targettingType == TargettingType.EXCEPT) { ExceptTargetDescription exceptDesc = (ExceptTargetDescription)desc; desc = exceptDesc.targetDescription; } switch (desc.targettingType) { case TargettingType.TARGET: { TargetXDescription targetDesc = (TargetXDescription)desc; if (targetDesc.amount == targets[i].Length) { TargettingQuery query = new TargettingQuery(targetDesc, player, pendingType != GameSession.PendingType.REPLACE_CREATURE); for (int j = 0; j < targets[i].Length; j++) { Targettable targettable = targets[i][j].GetComponent <Targettable>(); if (!targettable.IsTargettable(query)) { isValid = false; break; } } } else { isValid = false; } break; } case TargettingType.UP_TO_TARGET: { UpToXTargetDescription targetDesc = (UpToXTargetDescription)desc; if (targetDesc.amount >= targets[i].Length) { TargettingQuery query = new TargettingQuery(targetDesc, player, pendingType != GameSession.PendingType.REPLACE_CREATURE); for (int j = 0; j < targets[i].Length; j++) { Targettable targettable = targets[i][j].GetComponent <Targettable>(); if (!targettable.IsTargettable(query)) { isValid = false; break; } } } else { isValid = false; } break; } } if (!isValid) { break; } } } if (isValid) { switch (pendingType) { case GameSession.PendingType.PLAY_CARD: PlayCardEvent playCardEvent = new PlayCardEvent(player, card, targetEvent.flattenedTargets, targetEvent.indexes); gameSession.HandleEvent(playCardEvent); gameSession.ServerPopState(); break; case GameSession.PendingType.TRIGGER_EFFECT: gameSession.ServerAddEffectToStack(gameSession.GetPendingCreature(player), card, triggerCondition, targetEvent.flattenedTargets, targetEvent.indexes); gameSession.ResetPendingCreature(); gameSession.ServerPopState(); break; case GameSession.PendingType.USE_TRAP: UseTrapEvent trapEvent = new UseTrapEvent(player, card, targetEvent.flattenedTargets, targetEvent.indexes); gameSession.HandleEvent(trapEvent); gameSession.ServerPopState(); break; case GameSession.PendingType.REPLACE_CREATURE: // Replace creature should only have one target Creature creatureToReplace = targets[0][0].GetComponent <Creature>(); // Destroying the creature makes it so we can't target it for the on enter effect of the replacing creature which is what we want creatureToReplace.GetCreatureState().ServerDestroyCard(); gameSession.SetPendingCreature(creatureToReplace); PlayCardEvent playReplaceCreatureEvent = new PlayCardEvent(player, card); gameSession.HandleEvent(playReplaceCreatureEvent); gameSession.ServerPopState(); break; } } else { CancelPlayCard(); } } }
public void CmdSendPlayCardEvent(PlayCardEvent eventInfo) { gameSession.HandleEvent(eventInfo); }