aboutsummaryrefslogtreecommitdiff
path: root/internal/game/act_combine.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-07-01 03:21:52 -0400
committerhistoria <[not public]>2026-07-01 03:21:52 -0400
commitfbe5090ac3325ff8ea6989cdf4515c7f077c975b (patch)
tree1811ad9c6a596e7177bb2c42944c389c0a120066 /internal/game/act_combine.go
parent5f37dc9b6f6b79da04da70ae0c33ec8d02998587 (diff)
downloadthehouseoficarus-fbe5090ac3325ff8ea6989cdf4515c7f077c975b.tar.gz
feat: item messaging standardized, custom messages for production paths implemented
Diffstat (limited to 'internal/game/act_combine.go')
-rw-r--r--internal/game/act_combine.go157
1 files changed, 157 insertions, 0 deletions
diff --git a/internal/game/act_combine.go b/internal/game/act_combine.go
new file mode 100644
index 0000000..8937d38
--- /dev/null
+++ b/internal/game/act_combine.go
@@ -0,0 +1,157 @@
+package game
+
+import (
+ "thehouseoficarus/internal/behavior"
+ "thehouseoficarus/internal/engine"
+ "thehouseoficarus/internal/item"
+ "thehouseoficarus/internal/net"
+ "thehouseoficarus/internal/player"
+)
+
+func (g *Game) startCombine(sess *net.Session, p *player.Player, item *item.ItemDef, craft *item.CraftDef, count int) {
+ g.cancelAction(p)
+ g.cancelBgAction(p)
+
+ if !craftHasAllItemsQty(craft, p.CountItem) {
+ sess.WriteLine("You don't have the required materials.")
+ g.reprompt(sess)
+ return
+ }
+
+ outDef, _ := g.ItemStore.Load(item.ID)
+ outputName := item.ID
+ if outDef != nil {
+ outputName = outDef.Name
+ }
+
+ startMsg := g.resolveCraftMessage(sess, craft.StartMessage, "You start combining %i1.", craft, item.ID, nil, p.HasItem)
+ endMsg := g.resolveCraftMessage(sess, craft.EndMessage, "You've finished combining.", craft, item.ID, nil, p.HasItem)
+
+ p.Action = &behavior.Action{
+ Type: behavior.TypeCombine,
+ TargetID: item.ID,
+ TargetName: outputName,
+ Data: &behavior.CombineData{
+ ItemID: item.ID,
+ Phase: 0,
+ StepIndex: 0,
+ Remaining: count,
+ StartMessage: startMsg,
+ EndMessage: endMsg,
+ Wait: craft.Wait,
+ },
+ WaitLeft: engine.ToTicks(1),
+ }
+
+ g.broadcastAction(sess, "%s starts combining.", p.Name)
+}
+
+func (g *Game) advanceCombine(sess *net.Session, p *player.Player) {
+ d, ok := p.Action.Data.(*behavior.CombineData)
+ if !ok {
+ g.cancelAction(p)
+ return
+ }
+
+ item := g.loadCraftItem(d.ItemID)
+ if item == nil {
+ g.cancelAction(p)
+ return
+ }
+ craft := item.FirstCraft()
+
+ switch d.Phase {
+ case 0:
+ if d.StartMessage != "" {
+ sess.WriteLine(d.StartMessage)
+ }
+ d.Phase = 1
+ if len(craft.Steps) > 0 {
+ p.Action.WaitLeft = engine.ToTicks(craft.Steps[0].Delay)
+ } else {
+ firstWait := craft.Wait
+ if firstWait <= 0 {
+ firstWait = 4
+ }
+ p.Action.WaitLeft = engine.ToTicks(firstWait)
+ }
+ return
+
+ case 1:
+ if len(craft.Steps) > 0 && d.StepIndex < len(craft.Steps) {
+ step := craft.Steps[d.StepIndex]
+ sess.WriteLine(g.resolveCraftVar(sess, step.Message, craft, item.ID, nil, p.HasItem))
+ d.StepIndex++
+ if d.StepIndex < len(craft.Steps) {
+ p.Action.WaitLeft = engine.ToTicks(craft.Steps[d.StepIndex].Delay)
+ return
+ }
+ }
+ d.Phase = 2
+ p.Action.WaitLeft = engine.ToTicks(1)
+ return
+
+ case 2:
+ if !craftHasAllItemsQty(craft, p.CountItem) {
+ if d.EndMessage != "" {
+ sess.WriteLine(d.EndMessage)
+ }
+ g.cancelAction(p)
+ return
+ }
+
+ consumeIngredients(craft, p.HasItem, p.RemoveItem)
+
+ outputQty := craft.OutputQty
+ if outputQty <= 0 {
+ outputQty = 1
+ }
+
+ outDef, _ := g.ItemStore.Load(item.ID)
+ placed := false
+ if outDef != nil && outDef.Stackable {
+ for i := 0; i < 28; i++ {
+ slot := p.InvSlot(i)
+ if slot != nil && slot.ItemID == item.ID {
+ slot.Quantity += outputQty
+ placed = true
+ break
+ }
+ }
+ }
+ if !placed {
+ freeSlot := p.FirstFreeSlot()
+ if freeSlot == -1 {
+ sess.WriteLine("Your inventory is too full!")
+ g.cancelAction(p)
+ return
+ }
+ p.SetInvSlot(freeSlot, &player.InventorySlot{ItemID: item.ID, Quantity: outputQty})
+ }
+
+ g.AccountStore.SaveCharacter(p)
+
+ if d.Remaining > 0 {
+ d.Remaining--
+ if d.Remaining <= 0 {
+ if d.EndMessage != "" {
+ sess.WriteLine(d.EndMessage)
+ }
+ g.cancelAction(p)
+ return
+ }
+ }
+
+ if !craftHasAllItemsQty(craft, p.CountItem) {
+ if d.EndMessage != "" {
+ sess.WriteLine(d.EndMessage)
+ }
+ g.cancelAction(p)
+ return
+ }
+
+ d.Phase = 0
+ d.StepIndex = 0
+ p.Action.WaitLeft = engine.ToTicks(1)
+ }
+}