饥荒Mod 开发(八):游戏所有食材和食物

2023-12-07 16:20

本文主要是介绍饥荒Mod 开发(八):游戏所有食材和食物,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

饥荒中内置了很多烹饪的食物,每种食物都可以由不同的食材烹饪出来,今天介绍如何将内置的食物打印出来。

食材

饥荒中的食材可以放入烹饪锅,每个食材都有很多的属性,比如名字,类型,“度数”

-- 为 "meat" 这个食材添加 "meat" 属性,属性的值是 1。
AddIngredientValues({"meat"}, {meat=1}, true, true)-- 为 "monstermeat" 这个食材添加 "meat" 和 "monster" 两个属性,每个属性的值都是 1。
AddIngredientValues({"monstermeat"}, {meat=1, monster=1}, true, true)-- 为 "froglegs"、"drumstick" 和 "batwing" 这些食材添加 "meat" 属性,属性的值是 0.5。
AddIngredientValues({"froglegs", "drumstick", "batwing"}, {meat=.5}, true)-- 为 "smallmeat" 这个食材添加 "meat" 属性,属性的值是 0.5。
AddIngredientValues({"smallmeat"}, {meat=.5}, true, true)-- 为 "plantmeat" 这个食材添加 "meat" 属性,属性的值是 1。
AddIngredientValues({"plantmeat"}, {meat=1}, true)

在这里插入图片描述
我们也可以调用AddIngredientValues 添加自己的食材

食谱

游戏有一个lua代码文件定义了很多的内置食物。每种食物的烹饪时间,食物类型,生命/节/精神值,以及保鲜时间等。代码路径如下:
data\scripts\preparedfoods.lua

--部分代码解释
butterflymuffin =
{-- test 是一个函数,用于检查是否可以制作这个食物。-- 这个函数接受三个参数:cooker(烹饪设备),names(食材的名称),tags(食材的标签)。-- 这个函数返回 true 如果食材中包含蝴蝶翅膀,不包含肉类,并且包含蔬菜。test = function(cooker, names, tags) return names.butterflywings and not tags.meat and tags.veggie end,-- priority 决定了在多个配方都可以制作的情况下,哪个配方会被优先选择。数字越大,优先级越高。priority = 1,-- weight 决定了这个食物的重量,可能影响角色移动速度。weight = 1,-- foodtype 是这个食物的类型,这里是 "VEGGIE",表示这是一个蔬菜类食物。foodtype = "VEGGIE",-- health,hunger,sanity 分别表示这个食物恢复的生命值,饥饿值和精神值。health = TUNING.HEALING_MED,hunger = TUNING.CALORIES_LARGE,sanity = TUNING.SANITY_TINY,-- perishtime 是这个食物的腐烂时间,单位是天。perishtime = TUNING.PERISH_SLOW,-- cooktime 是这个食物的烹饪时间,实际 2 *20 秒。cooktime = 2,
},

食物

如何判断烹饪的结果

饥荒中判断烹饪结果是通过食物的test函数来判断的,当我们放入4个原料的时候,游戏会按照优先级遍历所有的食物,挨个调用test函数,只要test函数返回true,就认为可以烹饪。所以不同的原料是可以烹饪出相同的食物的。
饥荒提供了一个函数用来判断烹饪结果。源码在:data\scripts\cooking.lua

-- 引入 cooking 模块
local cooking = require("cooking")-- 创建一个表来存储食材
local ings = {}-- 向食材表中添加四个 "twigs"
table.insert(ings, "twigs")
table.insert(ings, "twigs")
table.insert(ings, "twigs")
table.insert(ings, "twigs")-- 调用 cooking.CalculateRecipe 函数来计算烹饪的结果和所需的时间
-- "cookpot" 是烹饪设备的类型,ings 是食材表
-- CalculateRecipe 函数返回两个值:烹饪的结果(product)和所需的时间(cooktime)
local product, cooktime = cooking.CalculateRecipe("cookpot", ings)

输出饥荒中所有的食材和食物

在modmain.lua 文件中,复制下面的代码。进入以后洗之后,打开调试页面, 按下键盘F1 键盘,可以将结果输出到文件中,文件的目录比较深,可以用everything 搜索一下,我的路径

C:\WeGameApps\rail_user_data\2000013\76561197981883591\cloud_storage\user_space\2199037600743566342\formal\content\files\myfoods.txt
-- 导入 "cooking" 模块,这个模块包含了食材和食谱的定义。
local cooking = GLOBAL.require("cooking")-- 添加一个按键处理器。这个处理器会在玩家按下或释放一个键时被调用。
GLOBAL.TheInput:AddKeyHandler(function(key, down)-- 检查按下的键是否是 F1 键if (key == GLOBAL.KEY_F1 and not down) thenlocal content = "-----------------原料------------------------"-- 遍历所有的食材。for name, v in pairs(cooking.ingredients) do-- 将食材的名称添加到 content 字符串中。content = content .. tostring(GLOBAL.STRINGS.NAMES[string.upper(name)]) .. "(" .. name .. ")\n"-- 如果这个食材有标签,那么遍历这些标签,并将它们添加到 content 字符串中。if v.tags then              for tag, tagval in pairs(v.tags) docontent = content .. tag .. ":" .. tostring(tagval) .. "\t"endendcontent = content .. "\n"end-- 遍历所有的食谱。content = content .. "-----------------食谱------------------------\n"for cooker, v in pairs(cooking.recipes) do-- 将烹饪设备的名称添加到 content 字符串中。content = content .. cooker .. "\n"-- 遍历这个烹饪设备可以制作的所有食物,并将这些食物的信息添加到 content 字符串中。for name, recipe in pairs(v) docontent = content .. tostring(GLOBAL.STRINGS.NAMES[string.upper(name)]) .. "("..  name .. "):" .. " foodtype:" .. tostring(recipe.foodtype) .. " health:" .. tostring(recipe.health) .. " hunger:" .. tostring(recipe.hunger) .. " sanity:" .. tostring(recipe.sanity) .. " \n\n"endcontent = content .. "\n"end-- 将 content 字符串保存到 "myfoods.txt" 文件中。TheSim:SetPersistentString("myfoods.txt", content)	end
end)
KLEI     1 -----------------原料------------------------蝴蝶翅膀(butterflywings)
decoration:2	熟红蘑菇(red_cap_cooked)
veggie:0.5	precook:1	烤椰子(coconut_cooked)
fruit:1	fat:1	洞穴蝙蝠翅膀(batwing)
meat:0.5	龙虾(lobster)
fish:2	熟甘薯(sweet_potato_cooked)
veggie:1	precook:1	采摘的绿蘑菇(green_cap)
veggie:0.5	鱼(fish)
meat:0.5	fish:1	熟蛙腿(froglegs_cooked)
meat:0.5	precook:1	鼹鼠(mole)
meat:0.5	茄子(eggplant)
veggie:1	榴莲(durian)
monster:1	fruit:1	烤咖啡豆(coffeebeans_cooked)
fruit:1	熟火龙果(dragonfruit_cooked)
fruit:1	precook:1	晾干的水母(jellyjerky)
monster:1	fish:1	jellyfish:1	熟鳗鱼(eel_cooked)
fish:1	meat:0.5	precook:1	采摘的蓝蘑菇(blue_cap)
veggie:0.5	生鱼肉(fish_raw)
meat:0.5	fish:1	nil(monstermeat_cooked)
monster:1	meat:1	precook:1	干海带(seaweed_dried)
dried:1	veggie:1	nil(smallmeat_cooked)
meat:0.5	precook:1	高脚鸟蛋(tallbirdegg)
egg:4	nil(egg_cooked)
egg:1	precook:1	冰(ice)
frozen:1	熟水母(jellyfish_cooked)
monster:1	fish:1	jellyfish:1	鱼翅(shark_fin)
meat:0.5	fish:1	烤桦栗果(acorn_cooked)
seed:1	precook:1	烤茄子(eggplant_cooked)
veggie:1	precook:1	分成两半的椰子(coconut_halved)
fruit:1	fat:1	nil(meat_cooked)
meat:1	precook:1	浆果(berries)
fruit:0.5	蜂蜜(honey)
sweetener:1	热带鱼(tropical_fish)
meat:0.5	fish:1	熟小丑鱼(fish4_cooked)
meat:0.5	fish:1	仙人掌花(cactus_flower)
veggie:0.5	熟小鱼块(fish_raw_small_cooked)
fish:0.5	precook:1	曼德拉草(mandrake)
magic:1	veggie:1	蜂巢(honeycomb)
sweetener:1	洞穴香蕉(cave_banana)
fruit:1	咖啡豆(coffeebeans)
fruit:0.5	兔蟹(crab)
fish:0.5	nil(lobster_cooked)
fish:2	precook:1	熟贻贝(mussel_cooked)
fish:0.5	precook:1	鸟蛋(bird_egg)
egg:1	贻贝(mussel)
fish:0.5	熟帽贝(limpets_cooked)
fish:0.5	precook:1	小丑鱼(fish4)
meat:0.5	fish:1	死狗鱼(fish_med)
meat:0.5	fish:1	鱼卵(roe)
meat:0.5	fish:1	帽贝(limpets)
fish:0.5	蛙腿(froglegs)
meat:0.5	熟彩虹水母(rainbowjellyfish_cooked)
monster:1	fish:1	jellyfish:1	炸鸟腿(drumstick_cooked)
meat:0.5	precook:1	死彩虹水母(rainbowjellyfish_dead)
monster:1	fish:1	jellyfish:1	熟鸟蛋(bird_egg_cooked)
egg:1	precook:1	彩虹水母(rainbowjellyfish)
monster:1	fish:1	jellyfish:1	鳗鱼(eel)
meat:0.5	fish:1	烤胡萝卜(carrot_cooked)
veggie:1	precook:1	小肉(smallmeat)
meat:0.5	死水母(jellyfish_dead)
monster:1	fish:1	jellyfish:1	水母(jellyfish)
monster:1	fish:1	jellyfish:1	超臭榴莲(durian_cooked)
monster:1	fruit:1	precook:1	熟鱼卵(roe_cooked)
meat:0.5	fish:1	熟霓虹鱼(fish5_cooked)
meat:0.5	fish:1	霓虹鱼(fish5)
meat:0.5	fish:1	熟紫石斑鱼(fish3_cooked)
meat:0.5	fish:1	切片熟石榴(pomegranate_cooked)
fruit:1	precook:1	肉干(meat_dried)
dried:1	meat:1	nil(honey_cooked)
sweetener:1	precook:1	树枝(twigs)
inedible:1	熟绿蘑菇(green_cap_cooked)
veggie:0.5	precook:1	南瓜(pumpkin)
veggie:1	nil(tropical_fish_cooked)
fish:1	meat:0.5	precook:1	剑鱼(swordfish)
meat:0.5	fish:1	熟叶肉(plantmeat_cooked)
meat:1	precook:1	胡萝卜(carrot)
veggie:1	鱼排(fish_med_cooked)
meat:0.5	fish:1	背鳍(dorsalfin)
inedible:1	西瓜(watermelon)
fruit:1	渡渡鸟蛋(doydoyegg)
egg:1	熟蓝蘑菇(blue_cap_cooked)
veggie:0.5	precook:1	熟鱼(fish_cooked)
fish:1	meat:0.5	precook:1	烤海带(seaweed_cooked)
veggie:1	precook:1	小鱼块(fish_raw_small)
fish:0.5	玉米(corn)
veggie:1	叶肉(plantmeat)
meat:1	带电的羊奶(goatmilk)
dairy:1	桦栗果(acorn)
seed:1	烤西瓜(watermelon_cooked)
fruit:1	precook:1	nil(honeycomb_cooked)
sweetener:1	precook:1	煎渡渡鸟蛋(doydoyegg_cooked)
egg:1	precook:1	苔藓(cutlichen)
veggie:1	仙人掌肉(cactus_meat)
veggie:1	nil(egg)
egg:1	熟蝙蝠翅膀(batwing_cooked)
meat:0.5	precook:1	怪物肉(monstermeat)
meat:1	monster:1	火龙果(dragonfruit)
fruit:1	紫石斑鱼(fish3)
meat:0.5	fish:1	烤南瓜(pumpkin_cooked)
veggie:1	precook:1	肉(meat)
meat:1	海带(seaweed)
veggie:1	烤浆果(berries_cooked)
fruit:0.5	precook:1	鸟腿(drumstick)
meat:0.5	石榴(pomegranate)
fruit:1	熟仙人掌肉(cactus_meat_cooked)
veggie:1	precook:1	黄油(butter)
dairy:1	fat:1	nil(mandrake_cooked)
veggie:1	magic:1	precook:1	甘薯(sweet_potato)
veggie:1	熟香蕉(cave_banana_cooked)
fruit:1	precook:1	怪物肉干(monstermeat_dried)
dried:1	meat:1	monster:1	小风干肉(smallmeat_dried)
dried:1	meat:0.5	爆米花(corn_cooked)
veggie:1	precook:1	nil(cutlichen_cooked)
veggie:1	precook:1	煎高脚鸟蛋(tallbirdegg_cooked)
egg:4	precook:1	采摘的红蘑菇(red_cap)
veggie:0.5	-----------------食谱------------------------
portablecookpot
贻贝浓汤(musselbouillabaise): foodtype:MEAT health:20 hunger:37.5 sanity:15 怪物鞑靼(monstertartare): foodtype:MEAT health:3 hunger:37.5 sanity:10 甘薯蛋奶酥(sweetpotatosouffle): foodtype:VEGGIE health:20 hunger:37.5 sanity:15 鲜果可丽饼(freshfruitcrepes): foodtype:VEGGIE health:60 hunger:150 sanity:15 cookpot
香蕉冻(bananapop): foodtype:VEGGIE health:20 hunger:12.5 sanity:33 热带鱼汤(tropicalbouillabaisse): foodtype:MEAT health:20 hunger:37.5 sanity:15 鲜贝浓汤(bisque): foodtype:MEAT health:60 hunger:18.75 sanity:5 怪物千层饼(monsterlasagna): foodtype:MEAT health:-20 hunger:37.5 sanity:-20 酸橘汁腌鱼(ceviche): foodtype:MEAT health:20 hunger:25 sanity:5 蛙腿三明治(frogglebunwich): foodtype:MEAT health:20 hunger:37.5 sanity:5 水母冻(jellyopop): foodtype:MEAT health:20 hunger:12.5 sanity:0 南瓜饼干(pumpkincookie): foodtype:VEGGIE health:0 hunger:37.5 sanity:15 潮湿黏糊(wetgoop): foodtype:nil health:0 hunger:0 sanity:0 鳗鱼料理(unagi): foodtype:MEAT health:20 hunger:18.75 sanity:5 火鸡正餐(turkeydinner): foodtype:MEAT health:20 hunger:75 sanity:5 炸鱼排(fishsticks): foodtype:MEAT health:40 hunger:37.5 sanity:5 曼德拉草汤(mandrakesoup): foodtype:VEGGIE health:100 hunger:150 sanity:5 培根煎蛋(baconeggs): foodtype:MEAT health:20 hunger:75 sanity:5 鱼翅汤(sharkfinsoup): foodtype:MEAT health:40 hunger:12.5 sanity:-10 华夫饼(waffles): foodtype:VEGGIE health:60 hunger:37.5 sanity:5 辣椒炖肉(hotchili): foodtype:MEAT health:20 hunger:37.5 sanity:0 水果圣代(fruitmedley): foodtype:VEGGIE health:20 hunger:25 sanity:5 西瓜冰棍(watermelonicle): foodtype:VEGGIE health:3 hunger:12.5 sanity:20 芝士蛋糕(powcake): foodtype:VEGGIE health:-3 hunger:0 sanity:0 加州卷(californiaroll): foodtype:MEAT health:20 hunger:37.5 sanity:10 龙虾汤(lobsterbisque): foodtype:MEAT health:60 hunger:25 sanity:10 蔬菜杂烩(ratatouille): foodtype:VEGGIE health:3 hunger:25 sanity:5 鱼肉玉米卷(fishtacos): foodtype:MEAT health:20 hunger:37.5 sanity:5 炖肉汤(bonestew): foodtype:MEAT health:12 hunger:150 sanity:5 鱼子酱(caviar): foodtype:MEAT health:3 hunger:12.5 sanity:33 肉丸(meatballs): foodtype:MEAT health:3 hunger:62.5 sanity:5 蝴蝶松饼(butterflymuffin): foodtype:VEGGIE health:20 hunger:37.5 sanity:5 冰淇淋(icecream): foodtype:VEGGIE health:0 hunger:25 sanity:50 果酱(jammypreserves): foodtype:VEGGIE health:3 hunger:37.5 sanity:5 海鲜牛排(surfnturf): foodtype:MEAT health:60 hunger:37.5 sanity:33 酿茄子(stuffedeggplant): foodtype:VEGGIE health:3 hunger:37.5 sanity:5 鳄梨酱(guacamole): foodtype:MEAT health:20 hunger:37.5 sanity:0 蜜汁卤肉(honeynuggets): foodtype:MEAT health:20 hunger:37.5 sanity:5 海鲜浓汤(seafoodgumbo): foodtype:MEAT health:40 hunger:37.5 sanity:20 什锦干果(trailmix): foodtype:VEGGIE health:30 hunger:12.5 sanity:5 龙虾正餐(lobsterdinner): foodtype:MEAT health:60 hunger:37.5 sanity:50 太妃糖(taffy): foodtype:VEGGIE health:-3 hunger:25 sanity:15 波兰水饺(perogies): foodtype:MEAT health:40 hunger:37.5 sanity:5 火龙果派(dragonpie): foodtype:VEGGIE health:40 hunger:75 sanity:5 肉串(kabobs): foodtype:MEAT health:3 hunger:37.5 sanity:5 花沙拉(flowersalad): foodtype:VEGGIE health:40 hunger:12.5 sanity:5 咖啡(coffee): foodtype:VEGGIE health:3 hunger:9.375 sanity:-5 蜜汁火腿(honeyham): foodtype:MEAT health:30 hunger:75 sanity:5 

这篇关于饥荒Mod 开发(八):游戏所有食材和食物的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/466524

相关文章

Python实例题之pygame开发打飞机游戏实例代码

《Python实例题之pygame开发打飞机游戏实例代码》对于python的学习者,能够写出一个飞机大战的程序代码,是不是感觉到非常的开心,:本文主要介绍Python实例题之pygame开发打飞机... 目录题目pygame-aircraft-game使用 Pygame 开发的打飞机游戏脚本代码解释初始化部

Python pip下载包及所有依赖到指定文件夹的步骤说明

《Pythonpip下载包及所有依赖到指定文件夹的步骤说明》为了方便开发和部署,我们常常需要将Python项目所依赖的第三方包导出到本地文件夹中,:本文主要介绍Pythonpip下载包及所有依... 目录步骤说明命令格式示例参数说明离线安装方法注意事项总结要使用pip下载包及其所有依赖到指定文件夹,请按照以

使用Python开发一个现代化屏幕取色器

《使用Python开发一个现代化屏幕取色器》在UI设计、网页开发等场景中,颜色拾取是高频需求,:本文主要介绍如何使用Python开发一个现代化屏幕取色器,有需要的小伙伴可以参考一下... 目录一、项目概述二、核心功能解析2.1 实时颜色追踪2.2 智能颜色显示三、效果展示四、实现步骤详解4.1 环境配置4.

Python使用smtplib库开发一个邮件自动发送工具

《Python使用smtplib库开发一个邮件自动发送工具》在现代软件开发中,自动化邮件发送是一个非常实用的功能,无论是系统通知、营销邮件、还是日常工作报告,Python的smtplib库都能帮助我们... 目录代码实现与知识点解析1. 导入必要的库2. 配置邮件服务器参数3. 创建邮件发送类4. 实现邮件

基于Python开发一个有趣的工作时长计算器

《基于Python开发一个有趣的工作时长计算器》随着远程办公和弹性工作制的兴起,个人及团队对于工作时长的准确统计需求日益增长,本文将使用Python和PyQt5打造一个工作时长计算器,感兴趣的小伙伴可... 目录概述功能介绍界面展示php软件使用步骤说明代码详解1.窗口初始化与布局2.工作时长计算核心逻辑3

python web 开发之Flask中间件与请求处理钩子的最佳实践

《pythonweb开发之Flask中间件与请求处理钩子的最佳实践》Flask作为轻量级Web框架,提供了灵活的请求处理机制,中间件和请求钩子允许开发者在请求处理的不同阶段插入自定义逻辑,实现诸如... 目录Flask中间件与请求处理钩子完全指南1. 引言2. 请求处理生命周期概述3. 请求钩子详解3.1

如何基于Python开发一个微信自动化工具

《如何基于Python开发一个微信自动化工具》在当今数字化办公场景中,自动化工具已成为提升工作效率的利器,本文将深入剖析一个基于Python的微信自动化工具开发全过程,有需要的小伙伴可以了解下... 目录概述功能全景1. 核心功能模块2. 特色功能效果展示1. 主界面概览2. 定时任务配置3. 操作日志演示

JavaScript实战:智能密码生成器开发指南

本文通过JavaScript实战开发智能密码生成器,详解如何运用crypto.getRandomValues实现加密级随机密码生成,包含多字符组合、安全强度可视化、易混淆字符排除等企业级功能。学习密码强度检测算法与信息熵计算原理,获取可直接嵌入项目的完整代码,提升Web应用的安全开发能力 目录

一文教你如何解决Python开发总是import出错的问题

《一文教你如何解决Python开发总是import出错的问题》经常朋友碰到Python开发的过程中import包报错的问题,所以本文将和大家介绍一下可编辑安装(EditableInstall)模式,可... 目录摘要1. 可编辑安装(Editable Install)模式到底在解决什么问题?2. 原理3.

Python+PyQt5开发一个Windows电脑启动项管理神器

《Python+PyQt5开发一个Windows电脑启动项管理神器》:本文主要介绍如何使用PyQt5开发一款颜值与功能并存的Windows启动项管理工具,不仅能查看/删除现有启动项,还能智能添加新... 目录开篇:为什么我们需要启动项管理工具功能全景图核心技术解析1. Windows注册表操作2. 启动文件