aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_clean.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/cmd_clean.go')
-rw-r--r--internal/game/cmd_clean.go78
1 files changed, 78 insertions, 0 deletions
diff --git a/internal/game/cmd_clean.go b/internal/game/cmd_clean.go
new file mode 100644
index 0000000..b3d8408
--- /dev/null
+++ b/internal/game/cmd_clean.go
@@ -0,0 +1,78 @@
+package game
+
+import (
+ "strings"
+
+ "thehouseoficarus/internal/action"
+ "thehouseoficarus/internal/combat"
+ "thehouseoficarus/internal/engine"
+ "thehouseoficarus/internal/net"
+ "thehouseoficarus/internal/player"
+)
+
+func (g *Game) doClean(sess *net.Session, input string) {
+ p := sess.Player.(*player.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}
+
+ 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
+}