diff options
| author | historia <[not public]> | 2026-06-25 15:40:48 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-06-25 15:40:48 -0400 |
| commit | abd612c15799f604e671e83dc7c410ed2b44185f (patch) | |
| tree | 0597ca92350de73aac2a7cf26b2f2d6595dac0cc /internal/game/action_fletch.go | |
| parent | 2725e2927a1595c7b100d942d1f14146252adeb7 (diff) | |
| download | thehouseoficarus-abd612c15799f604e671e83dc7c410ed2b44185f.tar.gz | |
slop refactor
Diffstat (limited to 'internal/game/action_fletch.go')
| -rw-r--r-- | internal/game/action_fletch.go | 214 |
1 files changed, 0 insertions, 214 deletions
diff --git a/internal/game/action_fletch.go b/internal/game/action_fletch.go deleted file mode 100644 index 53346a2..0000000 --- a/internal/game/action_fletch.go +++ /dev/null @@ -1,214 +0,0 @@ -package game - -import ( - "fmt" - - "thehouseoficarus/internal/action" - "thehouseoficarus/internal/engine" - "thehouseoficarus/internal/net" - "thehouseoficarus/internal/object" - "thehouseoficarus/internal/player" -) - -func (g *Game) startFletchAction(sess *net.Session, p *player.Player, item *object.ItemDef, count int) { - p.EnsureFlags() - p.Flags["last_fletch"] = item.ID - g.AccountStore.SaveCharacter(p) - - if item.FirstCraft().Wait <= 0 { - g.doInstantFletch(sess, p, item, count) - return - } - - g.startTimedFletch(sess, p, item, count) -} - -func (g *Game) doInstantFletch(sess *net.Session, p *player.Player, item *object.ItemDef, count int) { - c := item.FirstCraft() - outputQty := c.OutputQty - if outputQty <= 0 { - outputQty = 1 - } - - batches := 0 - totalOutput := 0 - skill := player.SkillName(c.EffectiveSkill()) - tmpItem := &object.ItemDef{Craft: object.CraftList{*c}} - for { - if !g.canDoFletchItem(p, tmpItem) { - break - } - - placed := false - if item.Stackable { - for i := 0; i < 28; i++ { - slot := p.InvSlot(i) - if slot != nil && slot.ItemID == item.ID { - craftConsumeAll(c, p.HasItem, p.RemoveItem) - slot.Quantity += outputQty - placed = true - break - } - } - } - if !placed { - craftConsumeAll(c, p.HasItem, p.RemoveItem) - freeSlot := p.FirstFreeSlot() - if freeSlot == -1 { - break - } - p.SetInvSlot(freeSlot, &player.InventorySlot{ItemID: item.ID, Quantity: outputQty}) - } - - if c.XP > 0 { - g.awardSkillXP(sess, p, skill, c.XP) - } - - batches++ - totalOutput += outputQty - - if count > 0 { - count-- - if count <= 0 { - break - } - } - } - - if batches == 0 { - sess.WriteLine("You don't have the materials for that.") - return - } - - g.AccountStore.SaveCharacter(p) - - outDef, _ := g.ItemStore.Load(item.ID) - outputName := item.Name - if outDef != nil { - outputName = g.itemColorize(sess, outDef, outDef.Name) - } - msg := fmt.Sprintf("You fletch %d %s.", totalOutput, outputName) - if p.OptionBool("xp_drops") && c.XP > 0 { - msg += g.formatXpDropSingle(sess, p, skill, c.XP*batches) - } - sess.WriteLine(msg) -} - -func (g *Game) startTimedFletch(sess *net.Session, p *player.Player, item *object.ItemDef, count int) { - craft := item.FirstCraft() - - startMsg := g.resolveCraftMessage(sess, craft.StartMessage, "You begin fletching %i1.", craft, item.ID, nil, p.HasItem) - - sess.WriteLine(startMsg) - - broadcastName := item.Name - if def, _ := g.ItemStore.Load(item.ID); def != nil { - broadcastName = def.Name - } - g.broadcastAction(sess, "%s starts fletching.", p.Name) - _ = broadcastName - - p.BackgroundAction = &action.Action{ - Type: "fletch", - TargetID: item.ID, - TargetName: item.Name, - Data: &action.FletchData{ - ItemID: item.ID, - Phase: 0, - Wait: craft.Wait, - Remaining: count, - }, - WaitLeft: engine.ToTicks(1), - } -} - -func (g *Game) advanceFletch(sess *net.Session, p *player.Player) { - data, ok := p.BackgroundAction.Data.(*action.FletchData) - if !ok { - g.cancelBgAction(p) - return - } - itemID := data.ItemID - phase := data.Phase - wait := data.Wait - remaining := data.Remaining - - item := g.loadCraftItem(itemID) - if item == nil { - g.cancelBgAction(p) - return - } - c := item.FirstCraft() - - if phase == 0 { - data.Phase = 1 - p.BackgroundAction.WaitLeft = engine.ToTicks(wait) - return - } - - tmpItem := &object.ItemDef{Craft: object.CraftList{*c}} - if !g.canDoFletchItem(p, tmpItem) { - sess.WriteLine("You've run out of fletching materials.") - g.cancelBgAction(p) - return - } - - outputQty := c.OutputQty - if outputQty <= 0 { - outputQty = 1 - } - - skill := player.SkillName(c.EffectiveSkill()) - - placed := false - if item.Stackable { - for i := 0; i < 28; i++ { - slot := p.InvSlot(i) - if slot != nil && slot.ItemID == item.ID { - craftConsumeAll(c, p.HasItem, p.RemoveItem) - slot.Quantity += outputQty - placed = true - break - } - } - } - if !placed { - craftConsumeAll(c, p.HasItem, p.RemoveItem) - freeSlot := p.FirstFreeSlot() - if freeSlot == -1 { - sess.WriteLine("Your inventory is too full!") - g.cancelBgAction(p) - return - } - p.SetInvSlot(freeSlot, &player.InventorySlot{ItemID: item.ID, Quantity: outputQty}) - } - - if c.XP > 0 { - g.awardSkillXP(sess, p, skill, c.XP) - } - g.AccountStore.SaveCharacter(p) - - msg := g.resolveCraftMessage(sess, c.Message, "You fletch a %n.", c, item.ID, nil, p.HasItem) - if p.OptionBool("xp_drops") && c.XP > 0 { - msg += g.formatXpDropSingle(sess, p, skill, c.XP) - } - sess.WriteLine(msg) - - if remaining > 0 { - remaining-- - data.Remaining = remaining - if remaining <= 0 { - sess.WriteLine("You've finished fletching.") - g.cancelBgAction(p) - return - } - } - - if !g.canContinueProduction(p, item) { - sess.WriteLine("You've run out of fletching materials.") - g.cancelBgAction(p) - return - } - - p.BackgroundAction.WaitLeft = engine.ToTicks(wait) -} |
