From 458916fb78dcef3ff77cb29b7ba98d9f646819fc Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Fri, 19 Jun 2026 02:08:55 -0400 Subject: feat: rough pharmacy skill added --- internal/game/action_clean.go | 123 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 internal/game/action_clean.go (limited to 'internal/game/action_clean.go') diff --git a/internal/game/action_clean.go b/internal/game/action_clean.go new file mode 100644 index 0000000..dab3619 --- /dev/null +++ b/internal/game/action_clean.go @@ -0,0 +1,123 @@ +package game + +import ( + "fmt" + "strings" + + "thehouseoficarus/internal/engine" + "thehouseoficarus/internal/net" + "thehouseoficarus/internal/player" +) + +func (g *Game) advanceClean(sess *net.Session, p *player.Player) { + phase, _ := p.BackgroundAction.Data["phase"].(int) + filter, _ := p.BackgroundAction.Data["filter"].(string) + + if phase == 0 { + p.BackgroundAction.Data["phase"] = 1 + p.BackgroundAction.WaitLeft = engine.ToTicks(2) + return + } + + allRecipes, err := g.RecipeStore.LoadAll() + if err != nil { + g.CancelBackgroundAction(p) + return + } + + var recipe *cleanMatch + for _, r := range allRecipes { + if r.Type != "clean" { + continue + } + if filter != "" { + if len(r.Consume) == 0 || len(r.Consume[0].Items) == 0 { + continue + } + if !strings.Contains(r.Consume[0].Items[0], filter) && + !strings.Contains(r.Output, filter) { + continue + } + } + if p.Level(player.Pharmacy) < r.Level { + continue + } + if !r.HasAllItems(p.HasItem) { + continue + } + recipe = &cleanMatch{r.Consume[0].Items[0], r.Output, r.XP, r.Message} + break + } + + if recipe == nil { + sess.WriteLine("\nYou've finished cleaning herbs.") + g.CancelBackgroundAction(p) + return + } + + for i := 0; i < 28; i++ { + slot := p.InvSlot(i) + if slot != nil && slot.ItemID == recipe.consumeID { + slot.ItemID = recipe.outputID + break + } + } + + if recipe.xp > 0 { + if newLevel := p.AddSkillXP(player.Pharmacy, recipe.xp); newLevel > 0 { + sess.WriteLine(g.colorize(sess, "level_up", + fmt.Sprintf("*** You are now level %d pharmacy! ***", newLevel))) + } + } + g.AccountStore.SaveCharacter(p) + + msg := recipe.message + if msg == "" { + outDef, _ := g.ItemStore.Load(recipe.outputID) + outputName := recipe.outputID + if outDef != nil { + outputName = outDef.Name + } + msg = fmt.Sprintf("You clean a %s.", outputName) + } + if p.OptionBool("xp_drops") && recipe.xp > 0 { + abbr := player.SkillAbbr[player.Pharmacy] + msg += g.colorize(sess, "xp", fmt.Sprintf(" (+%dxp %s)", recipe.xp, abbr)) + } + sess.WriteLine(msg) + + hasMore := false + for _, r := range allRecipes { + if r.Type != "clean" { + continue + } + if filter != "" { + if len(r.Consume) == 0 || len(r.Consume[0].Items) == 0 { + continue + } + if !strings.Contains(r.Consume[0].Items[0], filter) && + !strings.Contains(r.Output, filter) { + continue + } + } + if p.Level(player.Pharmacy) >= r.Level && r.HasAllItems(p.HasItem) { + hasMore = true + break + } + } + + if !hasMore { + sess.WriteLine("\nYou've finished cleaning herbs.") + g.CancelBackgroundAction(p) + return + } + + p.BackgroundAction.WaitLeft = engine.ToTicks(2) +} + +type cleanMatch struct { + consumeID string + outputID string + xp int + message string +} -- cgit v1.2.3