void OnActivated(bool upwards) { IsActivating = true; CardActivationEventArgs eventArgs = new CardActivationEventArgs(upwards ? CardActivationAction.Up : CardActivationAction.Down); if (Activated != null) { Activated(this, eventArgs); } if (eventArgs.IsCanceled) { IsActivating = false; return; } if (eventArgs.Slot == null) { Vanish(upwards); } else { if (eventArgs.Slot.CanHoldAdditionalCards) { PlaceInSlot(eventArgs.Slot, TimeSpan.Zero); } else { IsActivating = false; } } OnActivationFinished(IsActivating); }
void Card_Activated(object sender, CardActivationEventArgs e) { discardSlot.SetValue(Canvas.ZIndexProperty, 0); playedCardsLayout.SetValue(Canvas.ZIndexProperty, 0); riverLayout.SetValue(Canvas.ZIndexProperty, 1); if (GameHasFinished) { e.IsCanceled = true; return; } river.IsHitTestVisible = false; Card card = sender as Card; if (e.Action == CardActivationAction.Down) { CardSlot slot = null; switch ((card.DataContext as CardViewModel).Type) { default: break; case CardType.Health: { //slot = discardSlot; HealthViewModel healthContext = health.DataContext as HealthViewModel; int healthBefore = healthContext.Value; int restoredHealth = (card.DataContext as CardViewModel).Value; healthContext.Value += restoredHealth; int healthAfter = healthContext.Value; int consumedHealth = healthAfter - healthBefore; ScoreContext.AmountOfHealthConsumed += consumedHealth; } break; case CardType.Treasure: { slot = treasureSlot; } break; case CardType.Part: { slot = manaSlot; if (manaSlot.HoldsCards && manaSlot.StackCount >= 10) { // limit weapon parts stack to 10 e.IsCanceled = true; } } break; case CardType.Monster: { slot = monsterSlot; if (monsterSlot.HoldsCards) { CardViewModel topCardContext = monsterSlot.TopCard.DataContext as CardViewModel; CardViewModel cardContext = card.DataContext as CardViewModel; if (topCardContext.Value <= cardContext.Value) { e.IsCanceled = true; } } if (!e.IsCanceled) { HealthViewModel healthContext = health.DataContext as HealthViewModel; int damage = (card.DataContext as CardViewModel).Value; if (!weaponSlot.IsEmpty) { Card weapon = weaponSlot.TopCard; CardViewModel weaponCardContext = weapon.DataContext as CardViewModel; damage -= weaponCardContext.Value; } if (damage > 0) { healthContext.Value -= damage; } if (ScoreContext.HighestMonsterStack < 1) { ScoreContext.HighestMonsterStack = 1; } } } break; case CardType.Sword: { slot = weaponSlot; } break; } if (slot != null) { e.Slot = slot; } } else if (e.Action == CardActivationAction.Up) { if ((card.DataContext as CardViewModel).Type != CardType.Monster) { e.Slot = discardSlot; card.Flip(); river.IsHitTestVisible = true; } else { e.IsCanceled = true; } } if (e.IsCanceled) { river.IsHitTestVisible = true; } }