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 }