Documentation ¶
Index ¶
- Constants
- func ExposeDebug(port int, session *Session, l *lua.LState, log *log.Logger) func() error
- func NewGuid(tags ...string) string
- func SessionAdapter(session *Session) (*lua.LState, *ludoc.Docs)
- func WithDebugEnabled(port int) func(s *Session)
- func WithLogging(logger *log.Logger) func(s *Session)
- func WithMods(mods []string) func(s *Session)
- func WithOnLuaError(fn func(file string, line int, callback string, typeId string, err error)) func(s *Session)
- type Actor
- type Artifact
- type ArtifactInstance
- type Card
- type CardInstance
- type Context
- type DecayBehaviour
- type Enemy
- type Event
- type EventChoice
- type FightState
- type GameState
- type LogEntry
- type LogType
- type LuaError
- type MerchantState
- type Mod
- type ResourcesManager
- type SavedState
- type Session
- func (s *Session) ActiveTeller() *StoryTeller
- func (s *Session) ActorAddHP(id string, val int)
- func (s *Session) ActorAddMaxHP(id string, val int)
- func (s *Session) AddActor(actor Actor)
- func (s *Session) AddActorFromEnemy(id string) string
- func (s *Session) AddMerchantArtifact()
- func (s *Session) AddMerchantCard()
- func (s *Session) AddStatusEffectStacks(guid string, stacks int)
- func (s *Session) BuyRemoveCard(guid string) bool
- func (s *Session) BuyUpgradeCard(guid string) bool
- func (s *Session) CastCard(guid string, target string) bool
- func (s *Session) CleanUpFight()
- func (s *Session) Close()
- func (s *Session) DealDamage(source string, target string, damage int, flat bool) int
- func (s *Session) DealDamageMulti(source string, targets []string, damage int, flat bool) []int
- func (s *Session) EnemyTurn()
- func (s *Session) Fetch(key string) any
- func (s *Session) FinishEvent(choice int)
- func (s *Session) FinishFight() bool
- func (s *Session) FinishPlayerTurn()
- func (s *Session) GetActor(id string) Actor
- func (s *Session) GetActorIntend(guid string) string
- func (s *Session) GetActorStatusEffects(guid string) []string
- func (s *Session) GetActors() []string
- func (s *Session) GetArtifact(guid string) (*Artifact, ArtifactInstance)
- func (s *Session) GetArtifactOrder(guid string) int
- func (s *Session) GetArtifacts(owner string) []string
- func (s *Session) GetCard(guid string) (*Card, CardInstance)
- func (s *Session) GetCardState(guid string) string
- func (s *Session) GetCards(owner string) []string
- func (s *Session) GetEnemy(typeId string) *Enemy
- func (s *Session) GetEvent() *Event
- func (s *Session) GetEventChoiceDescription(i int) string
- func (s *Session) GetEventHistory() []string
- func (s *Session) GetFight() FightState
- func (s *Session) GetFightRound() int
- func (s *Session) GetFormerState(index int) *Session
- func (s *Session) GetGameState() GameState
- func (s *Session) GetInstance(guid string) any
- func (s *Session) GetInstances() []string
- func (s *Session) GetLoadedMods() []string
- func (s *Session) GetMerchant() MerchantState
- func (s *Session) GetMerchantGoldMax() int
- func (s *Session) GetOpponentByIndex(viewpoint string, i int) Actor
- func (s *Session) GetOpponentCount(viewpoint string) int
- func (s *Session) GetOpponentGUIDs(viewpoint string) []string
- func (s *Session) GetOpponents(viewpoint string) []Actor
- func (s *Session) GetPlayer() Actor
- func (s *Session) GetRandomArtifact(maxGold int) string
- func (s *Session) GetRandomArtifactType(maxPrice int) string
- func (s *Session) GetRandomCard(maxGold int) string
- func (s *Session) GetResources() *ResourcesManager
- func (s *Session) GetStagesCleared() int
- func (s *Session) GetStatusEffect(guid string) *StatusEffect
- func (s *Session) GetStatusEffectInstance(guid string) StatusEffectInstance
- func (s *Session) GetStatusEffectOrder(guid string) int
- func (s *Session) GetStatusEffectState(guid string) string
- func (s *Session) GiveArtifact(typeId string, owner string) string
- func (s *Session) GiveCard(typeId string, owner string) string
- func (s *Session) GivePlayerGold(amount int)
- func (s *Session) GiveStatusEffect(typeId string, owner string, stacks int) string
- func (s *Session) GobDecode(data []byte) error
- func (s *Session) GobEncode() ([]byte, error)
- func (s *Session) HadEvent(id string) bool
- func (s *Session) HadEvents(ids []string) bool
- func (s *Session) HadEventsAny(ids []string) bool
- func (s *Session) Heal(source string, target string, heal int, flat bool) int
- func (s *Session) LeaveMerchant()
- func (s *Session) LetTellerDecide()
- func (s *Session) LoadSavedState(save SavedState)
- func (s *Session) Log(t LogType, msg string)
- func (s *Session) LuaDocs() *ludoc.Docs
- func (s *Session) LuaErrors() chan LuaError
- func (s *Session) MarkState() StateCheckpointMarker
- func (s *Session) PlayerBuyArtifact(t string) bool
- func (s *Session) PlayerBuyCard(t string) bool
- func (s *Session) PlayerCastHand(i int, target string) error
- func (s *Session) PlayerDrawCard(amount int)
- func (s *Session) PlayerGiveActionPoints(amount int)
- func (s *Session) PushState(events map[StateEvent]any)
- func (s *Session) RemoveActor(id string)
- func (s *Session) RemoveAllStatusEffects()
- func (s *Session) RemoveArtifact(guid string)
- func (s *Session) RemoveCard(guid string)
- func (s *Session) RemoveNonPlayer()
- func (s *Session) RemoveStatusEffect(guid string)
- func (s *Session) SetEvent(id string)
- func (s *Session) SetFightDescription(description string)
- func (s *Session) SetGameState(state GameState)
- func (s *Session) SetOnLuaError(fn func(file string, line int, callback string, typeId string, err error))
- func (s *Session) SetStatusEffectStacks(guid string, stacks int)
- func (s *Session) SetupFight()
- func (s *Session) SetupMerchant()
- func (s *Session) Store(key string, value any)
- func (s *Session) ToSVG() ([]byte, string, error)
- func (s *Session) ToSavedState() SavedState
- func (s *Session) TraverseArtifactsStatus(guids []string, artifact func(instance ArtifactInstance, artifact *Artifact), ...)
- func (s *Session) TriggerOnActorDie(guids []string, source string, target string, damage int)
- func (s *Session) TriggerOnDamage(guids []string, source string, target string, damage int)
- func (s *Session) TriggerOnDamageCalc(guids []string, source string, target string, damage int) int
- func (s *Session) TriggerOnPlayerTurn()
- func (s *Session) UpdateActor(id string, update func(actor *Actor) bool)
- func (s *Session) UpdatePlayer(update func(actor *Actor) bool)
- func (s *Session) UpgradeCard(guid string) bool
- func (s *Session) UpgradeRandomCard(owner string) bool
- type StateCheckpoint
- type StateCheckpointMarker
- type StateEvent
- type StateEventDamageData
- type StateEventDeathData
- type StateEventHealData
- type StateEventMoneyData
- type StatusEffect
- type StatusEffectInstance
- type StoryTeller
- type StringSet
- func (s *StringSet) Add(val string)
- func (s *StringSet) Append(vals ...string)
- func (s *StringSet) Clear()
- func (s *StringSet) Clone() *StringSet
- func (s *StringSet) GobDecode(data []byte) error
- func (s *StringSet) GobEncode() ([]byte, error)
- func (s *StringSet) Has(val string) bool
- func (s *StringSet) Remove(val string)
- func (s *StringSet) ToSlice() []string
Constants ¶
const ( CallbackOnDamage = "OnDamage" CallbackOnDamageCalc = "OnDamageCalc" CallbackOnHealCalc = "OnHealCalc" CallbackOnCast = "OnCast" CallbackOnInit = "OnInit" CallbackOnPickUp = "OnPickUp" CallbackOnTurn = "OnTurn" CallbackOnPlayerTurn = "OnPlayerTurn" CallbackOnStatusAdd = "OnStatusAdd" CallbackOnStatusStack = "OnStatusStack" CallbackOnStatusRemove = "OnStatusRemove" CallbackOnRemove = "OnRemove" CallbackOnActorDie = "OnActorDie" CallbackOnMerchantEnter = "OnMerchantEnter" )
const ( StateEventDeath = StateEvent("Death") StateEventDamage = StateEvent("Damage") StateEventHeal = StateEvent("Heal") StateEventMoney = StateEvent("Money") )
const ( LogTypeInfo = LogType("INFO") LogTypeWarning = LogType("WARNING") LogTypeDanger = LogType("DANGER") LogTypeSuccess = LogType("SUCCESS") )
const ( GameStateFight = GameState("FIGHT") GameStateMerchant = GameState("MERCHANT") GameStateEvent = GameState("EVENT") GameStateRandom = GameState("RANDOM") GameStateGameOver = GameState("GAME_OVER") )
const ( DefaultUpgradeCost = 65 DefaultRemoveCost = 50 PointsPerRound = 3 DrawSize = 3 )
const ( DecayAll = DecayBehaviour("DecayAll") DecayOne = DecayBehaviour("DecayOne") DecayNone = DecayBehaviour("DecayNone") )
const PlayerActorID = "PLAYER"
Variables ¶
This section is empty.
Functions ¶
func ExposeDebug ¶
func SessionAdapter ¶
SessionAdapter creates a lua vm that is bound to the session in the given Session.
func WithDebugEnabled ¶
WithDebugEnabled enables the lua debugging. With lua debugging a server will be started on the given bind port. This exposes the /ws route to connect over websocket to. In essence, it exposes REPL access to the internal lua state which is helpful to debug problems. You can use the debug_r function to send data back to the websocket.
Tip: Use https://github.com/websockets/wscat to connect and talk with it.
func WithLogging ¶
WithLogging sets the internal logger.
Types ¶
type Actor ¶
type Actor struct { GUID string `lua:"guid"` TypeID string Name string Description string HP int MaxHP int Gold int Artifacts *StringSet Cards *StringSet StatusEffects *StringSet }
Actor represents a player or enemy.
type ArtifactInstance ¶
type Card ¶
type Card struct { ID string Name string Description string State luhelp.OwnedCallback Color string PointCost int MaxLevel int DoesExhaust bool NeedTarget bool Price int Callbacks map[string]luhelp.OwnedCallback }
Card represents a playable card definition.
type CardInstance ¶
CardInstance represents an instance of a card owned by some actor.
func (CardInstance) IsNone ¶
func (c CardInstance) IsNone() bool
type Context ¶
func CreateContext ¶
type DecayBehaviour ¶
type DecayBehaviour string
type Enemy ¶
type Enemy struct { ID string Name string Description string InitialHP int MaxHP int Look string Color string Intend luhelp.OwnedCallback Callbacks map[string]luhelp.OwnedCallback }
Enemy represents a definition of a enemy that can be linked from a Actor.
type Event ¶
type Event struct { ID string Name string Description string Choices []EventChoice OnEnter luhelp.OwnedCallback OnEnd luhelp.OwnedCallback }
Event represents a encounter-able event.
type EventChoice ¶
type EventChoice struct { Description string DescriptionFn luhelp.OwnedCallback Callback luhelp.OwnedCallback }
EventChoice represents a possible choice in the Event.
type FightState ¶
type FightState struct { Round int Description string CurrentPoints int Deck []string Hand []string Used []string Exhausted []string }
FightState represents the current state of the fight in regard to the deck of the player.
type MerchantState ¶
type Mod ¶
type Mod struct { Name string `json:"name"` Author string `json:"author"` Description string `json:"description"` Version string `json:"version"` URL string `json:"url"` }
func ModDescription ¶
type ResourcesManager ¶
type ResourcesManager struct { Artifacts map[string]*Artifact Cards map[string]*Card Events map[string]*Event Enemies map[string]*Enemy StatusEffects map[string]*StatusEffect StoryTeller map[string]*StoryTeller // contains filtered or unexported fields }
ResourcesManager can load Artifacts, Cards, Events, Enemy and StoryTeller data from lua. The manager will walk the ./scripts directory and evaluate all found .lua files.
func NewResourcesManager ¶
type SavedState ¶
type SavedState struct { State GameState Actors map[string]Actor Instances map[string]any StagesCleared int CurrentEvent string CurrentFight FightState Merchant MerchantState EventHistory []string StateCheckpoints []StateCheckpoint CtxData map[string]any LoadedMods []string }
SavedState represents a save file that don't contain any pointer so the lua runtime or other pointer.
type Session ¶
type Session struct { Logs []LogEntry // contains filtered or unexported fields }
Session represents the state inside a game session.
func NewSession ¶
NewSession creates a new game session.
func (*Session) ActiveTeller ¶
func (s *Session) ActiveTeller() *StoryTeller
ActiveTeller returns the active storyteller. The storyteller is responsible for deciding what enemies or events the player will encounter next.
func (*Session) ActorAddHP ¶
func (*Session) ActorAddMaxHP ¶
func (*Session) AddActorFromEnemy ¶
func (*Session) AddMerchantArtifact ¶
func (s *Session) AddMerchantArtifact()
AddMerchantArtifact adds another artifact to the wares of the merchant.
func (*Session) AddMerchantCard ¶
func (s *Session) AddMerchantCard()
AddMerchantCard adds another card to the wares of the merchant.
func (*Session) AddStatusEffectStacks ¶
AddStatusEffectStacks increases the stacks of a certain status effect by guid.
func (*Session) BuyRemoveCard ¶
func (*Session) BuyUpgradeCard ¶
func (*Session) CleanUpFight ¶
func (s *Session) CleanUpFight()
CleanUpFight resets the fight state.
func (*Session) Close ¶
func (s *Session) Close()
Close closes the internal lua state and everything else.
func (*Session) DealDamage ¶
func (*Session) DealDamageMulti ¶
func (*Session) FinishEvent ¶
FinishEvent finishes an event with the given choice. If the game state is not in the EVENT state this does nothing.
func (*Session) FinishFight ¶
FinishFight tries to finish the fight. This will return true if the fight is really over.
func (*Session) FinishPlayerTurn ¶
func (s *Session) FinishPlayerTurn()
FinishPlayerTurn signals that the player is done with its turn. All enemies act now, status effects are evaluated, if the fight is over is checked and if not this will advance to the next round and draw cards for the player.
func (*Session) GetActorIntend ¶
func (*Session) GetActorStatusEffects ¶
GetActorStatusEffects returns the guids of all the status effects a certain actor owns.
func (*Session) GetArtifact ¶
func (s *Session) GetArtifact(guid string) (*Artifact, ArtifactInstance)
GetArtifact returns an artifact, and instance by guid or type id. If a type id is given only the Artifact will be returned.
func (*Session) GetArtifactOrder ¶
GetArtifactOrder returns the order value of a certain artifact by guid.
func (*Session) GetArtifacts ¶
GetArtifacts returns all artifacts owned by a actor.
func (*Session) GetCardState ¶
func (*Session) GetEvent ¶
GetEvent returns the event definition of the current event. Will be nil if no event is present. It is not allowed to change the Event data, as this points to the event data created in lua!
func (*Session) GetEventChoiceDescription ¶
func (*Session) GetEventHistory ¶
GetEventHistory returns the ordered list of all events encountered so far.
func (*Session) GetFight ¶
func (s *Session) GetFight() FightState
GetFight returns the fight state. This will return a fight state even if no fight is active at the moment.
func (*Session) GetFightRound ¶
GetFightRound returns the current round of the fight.
func (*Session) GetFormerState ¶
GetFormerState iterates backwards over the states, so index == -1 means the last state and so on.
func (*Session) GetGameState ¶
GetGameState returns the current game state.
func (*Session) GetInstance ¶
GetInstance returns an instance by guid. An instance is a CardInstance or ArtifactInstance.
func (*Session) GetInstances ¶
func (*Session) GetLoadedMods ¶
func (*Session) GetMerchant ¶
func (s *Session) GetMerchant() MerchantState
GetMerchant return the merchant state.
func (*Session) GetMerchantGoldMax ¶
GetMerchantGoldMax returns what the max cost of a artifact or card is that the merchant might offer.
func (*Session) GetOpponentByIndex ¶
func (*Session) GetOpponentCount ¶
func (*Session) GetOpponentGUIDs ¶
func (*Session) GetOpponents ¶
func (*Session) GetRandomArtifact ¶
GetRandomArtifact returns the type id of a random artifact with a price lower than the given value.
func (*Session) GetRandomArtifactType ¶
GetRandomArtifactType returns a random artifact type with a given max price.
func (*Session) GetRandomCard ¶
GetRandomCard returns the type id of a random card with a price lower than the given value.
func (*Session) GetResources ¶
func (s *Session) GetResources() *ResourcesManager
func (*Session) GetStagesCleared ¶
GetStagesCleared returns the amount of stages cleared so far. Each fight represent a stage.
func (*Session) GetStatusEffect ¶
func (s *Session) GetStatusEffect(guid string) *StatusEffect
GetStatusEffect returns status effect by guid.
func (*Session) GetStatusEffectInstance ¶
func (s *Session) GetStatusEffectInstance(guid string) StatusEffectInstance
GetStatusEffectInstance returns status effect instance by guid.
func (*Session) GetStatusEffectOrder ¶
GetStatusEffectOrder returns the order value of a status effect by guid.
func (*Session) GetStatusEffectState ¶
GetStatusEffectState returns the rendered state of the status effect.
func (*Session) GiveArtifact ¶
GiveArtifact gives an artifact to an actor.
func (*Session) GivePlayerGold ¶
func (*Session) GiveStatusEffect ¶
GiveStatusEffect gives the owner a status effect of a certain type. Status effects are singleton per actor, so if the actor already has the status effect the stacks will be increased.
func (*Session) HadEventsAny ¶
HadEventsAny checks if at least one of the given events already happened in this run.
func (*Session) LeaveMerchant ¶
func (s *Session) LeaveMerchant()
LeaveMerchant finishes the merchant state and lets the storyteller decide what to do next.
func (*Session) LetTellerDecide ¶
func (s *Session) LetTellerDecide()
LetTellerDecide lets the currently active storyteller decide what the next game state will be.
func (*Session) LoadSavedState ¶
func (s *Session) LoadSavedState(save SavedState)
LoadSavedState applies a saved state to the session. This will overwrite all game related data, but not the lua state, logging etc. This also means that for a save file to work the same lua scripts should be loaded or the state could be corrupted.
func (*Session) MarkState ¶
func (s *Session) MarkState() StateCheckpointMarker
MarkState creates a checkpoint of the session state that can be used to diff and see what happened between two points in time.
func (*Session) PlayerBuyArtifact ¶
PlayerBuyArtifact buys the artifact with the given type id. The artifact needs to be in the wares of the merchant.
func (*Session) PlayerBuyCard ¶
PlayerBuyCard buys the card with the given type id. The card needs to be in the wares of the merchant.
func (*Session) PlayerDrawCard ¶
func (*Session) PlayerGiveActionPoints ¶
func (*Session) PushState ¶
func (s *Session) PushState(events map[StateEvent]any)
PushState pushes a new state to the session. New states are relevant information like damage done, money received, actor death etc.
func (*Session) RemoveActor ¶
func (*Session) RemoveAllStatusEffects ¶
func (s *Session) RemoveAllStatusEffects()
RemoveAllStatusEffects clears all present status effects.
func (*Session) RemoveArtifact ¶
RemoveArtifact removes a artifact by guid.
func (*Session) RemoveCard ¶
func (*Session) RemoveNonPlayer ¶
func (s *Session) RemoveNonPlayer()
func (*Session) RemoveStatusEffect ¶
RemoveStatusEffect removes a status effect by guid.
func (*Session) SetEvent ¶
SetEvent changes the active event, but won't set the game state to EVENT. So this can be used to set the next event even before a fight or merchant interaction is over.
func (*Session) SetFightDescription ¶
SetFightDescription sets the description of the fight.
func (*Session) SetGameState ¶
SetGameState sets the game state and applies all needed setups for the new state to be valid.
func (*Session) SetOnLuaError ¶
func (*Session) SetStatusEffectStacks ¶
SetStatusEffectStacks sets the stacks of a certain status effect by guid.
func (*Session) SetupFight ¶
func (s *Session) SetupFight()
SetupFight setups the fight state, which means removing all leftover status effects, cleaning the state drawing the initial hand size and trigger the first wave of OnPlayerTurn callbacks.
Additionally, this will create a save file as this is a clean state to save.
func (*Session) SetupMerchant ¶
func (s *Session) SetupMerchant()
SetupMerchant sets up the merchant, which means generating a new face, text and initial wares.
func (*Session) ToSVG ¶
ToSVG creates an SVG representation from the internal state. The returned string is the d2 representation of the SVG (https://d2lang.com/).
func (*Session) ToSavedState ¶
func (s *Session) ToSavedState() SavedState
ToSavedState creates a saved state of the session that can be serialized with Gob.
func (*Session) TraverseArtifactsStatus ¶
func (s *Session) TraverseArtifactsStatus(guids []string, artifact func(instance ArtifactInstance, artifact *Artifact), status func(instance StatusEffectInstance, statusEffect *StatusEffect))
func (*Session) TriggerOnActorDie ¶
func (*Session) TriggerOnDamage ¶
func (*Session) TriggerOnDamageCalc ¶
func (*Session) TriggerOnPlayerTurn ¶
func (s *Session) TriggerOnPlayerTurn()
func (*Session) UpdateActor ¶
func (*Session) UpdatePlayer ¶
func (*Session) UpgradeCard ¶
func (*Session) UpgradeRandomCard ¶
type StateCheckpoint ¶
type StateCheckpoint struct { Session *Session // Events describe the events that Events map[StateEvent]any }
StateCheckpoint saves the state of a session at a certain point. This can be used to retroactively check what happened between certain actions.
type StateCheckpointMarker ¶
type StateCheckpointMarker struct {
// contains filtered or unexported fields
}
StateCheckpointMarker is a saved state of a checkpoint log.
func (StateCheckpointMarker) Diff ¶
func (sm StateCheckpointMarker) Diff(session *Session) []StateCheckpoint
Diff returns the new states that happened between the marker and a new session.
func (StateCheckpointMarker) DiffEvent ¶
func (sm StateCheckpointMarker) DiffEvent(session *Session, event StateEvent) []StateCheckpoint
DiffEvent returns the new states that happened between the marker and a new session that contain a certain event.
type StateEvent ¶
type StateEvent string
type StateEventDamageData ¶
type StateEventDeathData ¶
type StateEventHealData ¶
type StateEventMoneyData ¶
type StatusEffect ¶
type StatusEffect struct { ID string Name string Description string State luhelp.OwnedCallback Look string Foreground string Order int CanStack bool Decay DecayBehaviour Rounds int Callbacks map[string]luhelp.OwnedCallback }
type StatusEffectInstance ¶
type StoryTeller ¶
type StoryTeller struct { ID string Active luhelp.OwnedCallback Decide luhelp.OwnedCallback }
type StringSet ¶
type StringSet struct {
// contains filtered or unexported fields
}
StringSet represents a string set that can be serialized by Gob.
Note: As the GobDecode needs to overwrite its receiver we need to have the map behind a struct pointer.
func NewStringSet ¶
func NewStringSet() *StringSet