V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
imba97
V2EX  ›  分享创造

写了个饥荒食谱速查工具

  •  
  •   imba97 ·
    imba97 · 2 天前 · 1349 次点击

    使用

    项目地址:https://dst-recipe.netlify.app

    基本搜索

    在下方输入框中输入关键字,可以是名称、拼音、拼音首字母

    展示食材基本信息、制作必须食材和条件

    多个结果

    多个结果可以滑动查看

    代码分析

    逻辑上来说是分为两块,一个是食材,一个是食谱

    食材

    每种食材有不同的属性,比如肉度、怪物度、鱼度等等

    所以就需要一个基类来表示食材

    export abstract class IngredientBase extends InstanceClass {
      protected abstract _name: string
    
      /**
       * 肉度
       */
      protected _meat?: number
    
      /**
       * 怪物度
       */
      protected _monster?: number
    
      /**
       * 鱼度
       */
      protected _fish?: number
    
      // ...
    }
    

    实现类

    import icon from '~/assets/images/ingredients/monster-meat.png'
    import { IngredientBase } from '~/composables/ingredient/ingredientBaseClass'
    
    export default class MonsterMeat extends IngredientBase {
      protected _name = '怪物肉'
      protected _image = icon
    
      protected override _meat = 1
      protected override _monster = 1
    }
    

    食谱

    每种食谱有不同的制作条件,比如所需食材、属性度条件等等

    实现方式也相同

    export abstract class FoodBase extends InstanceClass {
      private _pinyin: string = ''
      private _pinyinInitials: string = ''
    
      protected abstract _name: string
      protected abstract _health: number
      protected abstract _hunger: number
      protected abstract _sanity: number
      protected abstract _rot: number
      protected abstract _cooking: number
      protected abstract _priority: number
      protected abstract _image: string
    
      /**
       * 合并条件
       */
      protected _merge: IngredientTypeKey[][] = []
    
      /**
       * 所需食材
       */
      protected _ingredientsCondition: IngredientsCondition = []
    
      /**
       * 仅限沃利
       */
      protected _warlyOnly: boolean = false
    
      /**
       * 所需肉度
       */
      protected _meat?: ComparisonOperator
    
      /**
       * 所需怪物度
       */
      protected _monster?: ComparisonOperator
    
      /**
       * 所需怪物度
       */
      protected _monster?: ComparisonOperator
    
      // ...
    }
    

    除了所需属性度之外,还有一些其他配置,例如 _merge,可以表示某几个属性度任意一个满足即可

    比如火鸡正餐

    import type { IngredientTypeKey } from '~/enums/ingredientType'
    import type { ComparisonOperator } from '~/types/comparisonOperator'
    import type { IngredientsCondition } from '~/types/ingredientsCondition'
    import icon from '~/assets/images/foods/turkey-dinner.png'
    import { FoodBase } from '~/composables/food/foodBaseClass'
    import Drumstick from '~/ingredients/drumstick'
    
    export default class TurkeyDinner extends FoodBase {
      _name = '火鸡正餐'
      _health = 20
      _hunger = 75
      _sanity = 5
      _rot = 6
      _cooking = 60
      _priority = 10
      _image = icon
    
      protected override _ingredientsCondition: IngredientsCondition = [
        {
          ingredients: [
            Drumstick
          ],
          condition: {
            ge: 2
          }
        }
      ]
    
      protected override _merge: IngredientTypeKey[][] = [
        ['vegetable', 'fruit']
      ]
    
      protected override _meat: ComparisonOperator = {
        gt: 1
      }
    
      protected override _vegetable: ComparisonOperator = {
        ge: 0.5
      }
    
      protected override _fruit: ComparisonOperator = {
        gt: 0
      }
    }
    

    会显示为这样

    _ingredientsCondition 是所需食材,有时也需要表示某几种食材满足一种即可

    比如发光浆果慕斯

    import type { ComparisonOperator } from '~/types/comparisonOperator'
    import type { IngredientsCondition } from '~/types/ingredientsCondition'
    import icon from '~/assets/images/foods/glow-berry-mousse.png'
    import { FoodBase } from '~/composables/food/foodBaseClass'
    import GlowBerry from '~/ingredients/glowBerry'
    import LesserGlowBerry from '~/ingredients/lesserGlowBerry'
    
    export default class GlowBerryMousse extends FoodBase {
      _name = '发光浆果慕斯'
      _health = 3
      _hunger = 37.5
      _sanity = 10
      _rot = 8
      _cooking = 20
      _priority = 30
      _image = icon
    
      protected override _ingredientsCondition: IngredientsCondition = [
        [
          {
            ingredients: [
              GlowBerry
            ],
            condition: {
              ge: 1
            }
          },
          {
            ingredients: [
              LesserGlowBerry
            ],
            condition: {
              ge: 2
            }
          }
        ]
      ]
    
      protected override _fish: ComparisonOperator = {
        ge: 1
      }
    
      protected override _notEdible: ComparisonOperator = {
        eq: 0
      }
    
      protected override _warlyOnly = true
    }
    

    会显示为这样

    开源

    imba97/dst-recipe

    数据来源

    饥荒中文维基-烹饪

    11 条回复    2025-02-08 17:37:10 +08:00
    wegbjwjm
        1
    wegbjwjm  
       2 天前 via iPhone
    玩了几年了,还是会被狗咬死,被牛顶死,被 boss 踩死
    dobelee
        2
    dobelee  
       2 天前
    @wegbjwjm 宫崎英高直呼内行。
    imba97
        3
    imba97  
    OP
       2 天前
    @wegbjwjm 最近刚开始玩,也是 kuku 死
    VampireDemon
        4
    VampireDemon  
       2 天前
    一个 mode 解决所有问题
    imba97
        5
    imba97  
    OP
       2 天前
    @VampireDemon 也用 mode ,不过食谱 mode 好像只能通过不断放食材才能缩小范围,不然很多不好找
    CaCo6
        6
    CaCo6  
       1 天前
    这玩意还是跟朋友联机开挂好玩
    youngitachi
        7
    youngitachi  
       1 天前
    又想起了当年和同学在宿舍玩饥荒的日子啊,一转眼都毕业 6 年多了
    imba97
        8
    imba97  
    OP
       1 天前
    @CaCo6 确实,但开挂是啥
    imba97
        9
    imba97  
    OP
       1 天前
    @youngitachi 我那时候是狙击手幽灵战士,局域网联机,找人找一通宵😂
    CaCo6
        10
    CaCo6  
       20 小时 34 分钟前
    @imba97 一行上帝代码 无限资源 想要啥直接点就行 都是解锁的
    imba97
        11
    imba97  
    OP
       16 小时 18 分钟前
    @CaCo6 哦哦,倒是知道有各种指令,目前还是老老实实开荒啥的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2403 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 01:56 · PVG 09:56 · LAX 17:56 · JFK 20:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.