package game import ( "fmt" "strings" "thehouseoficarus/internal/action" "thehouseoficarus/internal/combat" "thehouseoficarus/internal/engine" "thehouseoficarus/internal/net" "thehouseoficarus/internal/player" ) func (g *Game) executeClean(sess *net.Session, args []string, rawInput string) { g.doClean(sess, strings.Join(args, " ")) } func (g *Game) doClean(sess *net.Session, input string) { p := sess.Player if combat.GetCombat(p.Name) != nil { sess.WriteLine("You can't do that during combat!") return } allRecipes, err := g.RecipeStore.LoadAll() if err != nil { sess.WriteLine("Error loading recipes.") return } filter := strings.TrimSpace(input) found := false for _, r := range allRecipes { if r.Type != "clean" { continue } if filter != "" && !matchesCleanFilter(r, filter) { continue } if p.Level(player.Pharmacy) < r.Level { continue } if !r.HasAllItems(p.HasItem) { continue } found = true break } if !found { sess.WriteLine("You don't have any herbs to clean.") return } g.cancelBackgroundAction(p) p.BackgroundAction = &action.Action{ Type: "clean", TargetID: "clean_herbs", Data: map[string]any{ "phase": 0, "filter": filter, }, WaitLeft: engine.ToTicks(1), } p.BackgroundActionState = &ActionState{Type: ActionCleaning} if g.Hub != nil { for _, other := range g.Hub.PlayersInRoom(p.RoomID) { if other != sess && other.Player != nil { other.WriteLine(g.colorize(other, "broadcast", fmt.Sprintf("\n%s starts cleaning herbs.", p.Name))) } } } sess.WriteLine("\nYou begin cleaning herbs.") } func matchesCleanFilter(r action.RecipeDef, filter string) bool { if len(r.Consume) > 0 && len(r.Consume[0].Items) > 0 { if strings.Contains(r.Consume[0].Items[0], filter) { return true } } if strings.Contains(r.Output, filter) { return true } return false }