aboutsummaryrefslogtreecommitdiff
path: root/internal/game/sys_construction.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/sys_construction.go')
-rw-r--r--internal/game/sys_construction.go74
1 files changed, 74 insertions, 0 deletions
diff --git a/internal/game/sys_construction.go b/internal/game/sys_construction.go
new file mode 100644
index 0000000..06713cd
--- /dev/null
+++ b/internal/game/sys_construction.go
@@ -0,0 +1,74 @@
+package game
+
+import (
+ "fmt"
+
+ "thehouseoficarus/internal/net"
+ "thehouseoficarus/internal/player"
+)
+
+func (g *Game) processSawmill(sess *net.Session, p *player.Player) {
+ logTypes := map[string]struct {
+ plankID string
+ cost int
+ name string
+ }{
+ "logs": {"planks", 5, "regular planks"},
+ "oak_logs": {"oak_planks", 10, "oak planks"},
+ "teak_logs": {"teak_planks", 20, "teak planks"},
+ "mahogany_logs": {"mahogany_planks", 40, "mahogany planks"},
+ }
+
+ totalCost := 0
+ totalPlanks := 0
+ type plankResult struct {
+ plankID string
+ qty int
+ }
+
+ var results []plankResult
+
+ for logID, info := range logTypes {
+ qty := p.CountItem(logID)
+ if qty == 0 {
+ continue
+ }
+ cost := qty * info.cost
+ totalCost += cost
+ totalPlanks += qty
+ results = append(results, plankResult{info.plankID, qty})
+ p.RemoveItem(logID, qty)
+ }
+
+ if totalPlanks == 0 {
+ sess.WriteLine("You don't have any logs to process.")
+ return
+ }
+
+ if p.Credits < totalCost {
+ sess.WriteLine(fmt.Sprintf("You need %d credits to process all your logs (you have %d).", totalCost, p.Credits))
+ return
+ }
+
+ p.Credits -= totalCost
+
+ processed := 0
+ for _, r := range results {
+ for i := 0; i < r.qty; i++ {
+ freeSlot := p.FirstFreeSlot()
+ if freeSlot == -1 {
+ g.World.AddGroundItem(p.RoomID, r.plankID, r.qty-i)
+ break
+ }
+ p.SetInvSlot(freeSlot, &player.InventorySlot{ItemID: r.plankID, Quantity: 1})
+ processed++
+ }
+ }
+
+ g.AccountStore.SaveCharacter(p)
+
+ sess.WriteLine(fmt.Sprintf("The sawmill operator processes your logs into %d planks for %d credits.", processed, totalCost))
+ if processed < totalPlanks {
+ sess.WriteLine(fmt.Sprintf("Your inventory is full. The remaining %d planks fall to the ground.", totalPlanks-processed))
+ }
+}