写了个饥荒食谱速查工具

2 天前
 imba97

使用

项目地址: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

数据来源

饥荒中文维基-烹饪

1367 次点击
所在节点    分享创造
11 条回复
wegbjwjm
2 天前
玩了几年了,还是会被狗咬死,被牛顶死,被 boss 踩死
dobelee
2 天前
@wegbjwjm 宫崎英高直呼内行。
imba97
2 天前
@wegbjwjm 最近刚开始玩,也是 kuku 死
VampireDemon
2 天前
一个 mode 解决所有问题
imba97
2 天前
@VampireDemon 也用 mode ,不过食谱 mode 好像只能通过不断放食材才能缩小范围,不然很多不好找
CaCo6
1 天前
这玩意还是跟朋友联机开挂好玩
youngitachi
1 天前
又想起了当年和同学在宿舍玩饥荒的日子啊,一转眼都毕业 6 年多了
imba97
1 天前
@CaCo6 确实,但开挂是啥
imba97
1 天前
@youngitachi 我那时候是狙击手幽灵战士,局域网联机,找人找一通宵😂
CaCo6
23 小时 47 分钟前
@imba97 一行上帝代码 无限资源 想要啥直接点就行 都是解锁的
imba97
19 小时 31 分钟前
@CaCo6 哦哦,倒是知道有各种指令,目前还是老老实实开荒啥的

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://tanronggui.xyz/t/1109450

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX