aboutsummaryrefslogtreecommitdiff
path: root/internal/game/action.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-10 04:44:31 -0400
committerhistoria <[not public]>2026-06-10 04:44:31 -0400
commit69d8757ad983697cdc9182fdcc1cdb612a77fb41 (patch)
tree348c26d1f6defe3aef64f5aa9e7cefed0e764214 /internal/game/action.go
parenta226d72e51eecb768b13600303f73483118d9104 (diff)
downloadthehouseoficarus-69d8757ad983697cdc9182fdcc1cdb612a77fb41.tar.gz
feat: yaml architecture for complex object interaction
Diffstat (limited to 'internal/game/action.go')
-rw-r--r--internal/game/action.go77
1 files changed, 62 insertions, 15 deletions
diff --git a/internal/game/action.go b/internal/game/action.go
index 029fec3..62cdf62 100644
--- a/internal/game/action.go
+++ b/internal/game/action.go
@@ -427,10 +427,13 @@ func (g *Game) showTalkNode(sess *net.Session, node action.TalkNode) {
return
}
- for i, opt := range node.Options {
- if opt.Condition != nil && !g.checkCondition(sess, opt.Condition) { continue
+ visible := 0
+ for _, opt := range node.Options {
+ if opt.Condition != nil && !g.checkCondition(sess, opt.Condition) {
+ continue
}
- sess.WriteLine(fmt.Sprintf(" %d. %s", i+1, opt.Text))
+ visible++
+ sess.WriteLine(fmt.Sprintf(" %d. %s", visible, opt.Text))
}
sess.State = net.StateTalk
sess.Write("\nChoice: ")
@@ -527,6 +530,12 @@ func (g *Game) applyNodeAction(sess *net.Session, na *action.NodeAction) {
for k, v := range na.SetFlags {
g.WorldFlags[k] = v
}
+ for k, v := range na.SetPlayerFlags {
+ if p.Flags == nil {
+ p.Flags = make(map[string]any)
+ }
+ p.Flags[k] = v
+ }
if na.TakeItem != "" {
if p.HasItem(na.TakeItem) {
p.RemoveItem(na.TakeItem, 1)
@@ -541,10 +550,59 @@ func (g *Game) applyNodeAction(sess *net.Session, na *action.NodeAction) {
g.AccountStore.SaveCharacter(p)
}
}
+ if na.Teleport > 0 {
+ p.RoomID = na.Teleport
+ g.AccountStore.SaveCharacter(p)
+ g.World.SeedGroundItems(p.RoomID)
+ g.seedRoomMobs(p.RoomID)
+ g.ensureRoomObjects(p.RoomID)
+ if g.Hub != nil {
+ g.Hub.EnterRoom(sess, p.RoomID)
+ }
+ g.doLook(sess)
+ g.RunEnterSteps(sess, p.RoomID)
+ }
+ if na.Heal > 0 {
+ p.HP += na.Heal
+ if maxHP := p.MaxHP(); p.HP > maxHP {
+ p.HP = maxHP
+ }
+ g.AccountStore.SaveCharacter(p)
+ sess.WriteLine(fmt.Sprintf("You regain %d hitpoints.", na.Heal))
+ }
}
func (g *Game) checkCondition(sess *net.Session, c *action.Condition) bool {
p, _ := sess.Player.(*player.Player)
+
+ if c.AllOf != nil {
+ for _, sub := range c.AllOf {
+ if !g.checkCondition(sess, &sub) {
+ return false
+ }
+ }
+ return true
+ }
+ if c.AnyOf != nil {
+ for _, sub := range c.AnyOf {
+ if g.checkCondition(sess, &sub) {
+ return true
+ }
+ }
+ return false
+ }
+
+ if c.PlayerFlag != "" {
+ if p == nil || p.Flags == nil {
+ return c.Not
+ }
+ val, ok := p.Flags[c.PlayerFlag]
+ if c.Not {
+ return !ok || val != c.Value
+ }
+ return ok && val == c.Value
+ }
+
if c.Flag != "" {
val, ok := g.WorldFlags[c.Flag]
if c.Not {
@@ -714,24 +772,13 @@ func normalizeVerb(v string) string {
return v
}
-func (g *Game) CheckExitCondition(c *world.ExitCondition) bool {
- if c.Flag != "" {
- val, ok := g.WorldFlags[c.Flag]
- if c.Not {
- return !ok || val != c.Value
- }
- return ok && val == c.Value
- }
- return true
-}
-
func (g *Game) RunEnterSteps(sess *net.Session, roomID int) {
room, err := g.World.LoadRoom(roomID)
if err != nil || len(room.OnEnter) == 0 {
return
}
for _, step := range room.OnEnter {
- if step.Condition != nil && !g.CheckExitCondition(step.Condition) {
+ if step.Condition != nil && !g.checkCondition(sess, step.Condition) {
continue
}
if step.Message != "" {