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/act_clean.go | |
| parent | 2725e2927a1595c7b100d942d1f14146252adeb7 (diff) | |
| download | thehouseoficarus-abd612c15799f604e671e83dc7c410ed2b44185f.tar.gz | |
slop refactor
Diffstat (limited to 'internal/game/act_clean.go')
| -rw-r--r-- | internal/game/act_clean.go | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/internal/game/act_clean.go b/internal/game/act_clean.go new file mode 100644 index 0000000..0c128a1 --- /dev/null +++ b/internal/game/act_clean.go @@ -0,0 +1,105 @@ +package game + +import ( + "strings" + + "thehouseoficarus/internal/behavior" + "thehouseoficarus/internal/engine" + "thehouseoficarus/internal/item" + "thehouseoficarus/internal/net" + "thehouseoficarus/internal/player" +) + +func (g *Game) advanceClean(sess *net.Session, p *player.Player) { + data, ok := p.BackgroundAction.Data.(*behavior.CleanData) + if !ok { + g.cancelBgAction(p) + return + } + phase := data.Phase + filter := data.Filter + + if phase == 0 { + data.Phase = 1 + p.BackgroundAction.WaitLeft = engine.ToTicks(2) + return + } + + items := g.CraftIndex.ByType("clean") + + var matchItem *item.ItemDef + for _, item := range items { + c := item.FirstCraft() + if filter != "" { + if len(c.Consume) == 0 || len(c.Consume[0].Items) == 0 { + continue + } + if !strings.Contains(c.Consume[0].Items[0], filter) && + !strings.Contains(item.ID, filter) { + continue + } + } + if p.Level(player.Pharmacy) < c.Level { + continue + } + if !craftHasAllItems(c, p.HasItem) { + continue + } + matchItem = item + break + } + + if matchItem == nil { + sess.WriteLine("You've finished cleaning herbs.") + g.cancelBgAction(p) + return + } + + craft := matchItem.FirstCraft() + consumeID := craft.Consume[0].Items[0] + + for i := 0; i < 28; i++ { + slot := p.InvSlot(i) + if slot != nil && slot.ItemID == consumeID { + slot.ItemID = matchItem.ID + break + } + } + + if craft.XP > 0 { + g.awardSkillXP(sess, p, player.Pharmacy, craft.XP) + } + g.AccountStore.SaveCharacter(p) + + msg := g.resolveCraftMessage(sess, craft.Message, "You clean the %i1.", craft, matchItem.ID, nil, p.HasItem) + if p.OptionBool("xp_drops") && craft.XP > 0 { + msg += g.formatXpDropSingle(sess, p, player.Pharmacy, craft.XP) + } + sess.WriteLine(msg) + + hasMore := false + for _, item := range items { + c := item.FirstCraft() + if filter != "" { + if len(c.Consume) == 0 || len(c.Consume[0].Items) == 0 { + continue + } + if !strings.Contains(c.Consume[0].Items[0], filter) && + !strings.Contains(item.ID, filter) { + continue + } + } + if p.Level(player.Pharmacy) >= c.Level && craftHasAllItems(c, p.HasItem) { + hasMore = true + break + } + } + + if !hasMore { + sess.WriteLine("You've finished cleaning herbs.") + g.cancelBgAction(p) + return + } + + p.BackgroundAction.WaitLeft = engine.ToTicks(2) +} |
