From 526fe76a45f7fcab8c954e6df7ec256eefb39ea2 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Tue, 9 May 2023 11:22:45 +0200 Subject: [PATCH] Support un-castable cards. --- game/session.go | 6 +++++- lua/luhelp/callback.go | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/game/session.go b/game/session.go index bedc8d8..9379220 100644 --- a/game/session.go +++ b/game/session.go @@ -1307,8 +1307,12 @@ func (s *Session) PlayerCastHand(i int, target string) error { cardId := s.currentFight.Hand[i] - // Only cast a card if points are available and subtract them. + // Only cast a card if castable and points are available and subtract them. if card, _ := s.GetCard(cardId); card != nil { + if !card.Callbacks[CallbackOnCast].Present() { + return errors.New("card is not castable") + } + if s.currentFight.CurrentPoints < card.PointCost { return errors.New("not enough points") } diff --git a/lua/luhelp/callback.go b/lua/luhelp/callback.go index 1d4253e..9fc1b32 100644 --- a/lua/luhelp/callback.go +++ b/lua/luhelp/callback.go @@ -14,3 +14,7 @@ func (cb OwnedCallback) Call(args ...any) (any, error) { return cb(args...) } + +func (cb OwnedCallback) Present() bool { + return cb != nil +}