Declan Hopkins

software & game developer

[18] Cooking

02/09/2020, 09:05pm

Recently, I've been working on adding the cooking skill to the game. The core implementation is done, but I left a lot of room for improvements and polish while I iterate on it. Consumable items were already implemented, so along with this addition it's now possible for players to cook various foods and eat them for healing and other benefits.

Recipes and Cookware

To cook, players need to be at a campfire, stove, or some other cooking "appliance". They also need some cookware like a pot or pan. Pots can be used for soups and stews, while pans can be used for fried fish, meat, and other stuff. I've only added a handful of recipes to the game so far. Recipes are written as part of an item definition. Here's the item definition for Chonkrat Stew, which can be made by cooking some Raw Chonkrat Meat inside any Pot. The player also needs to have at least level 2 in cooking - cooking a recipe that your character is not skilled enough for will most likely result in some Ruined Food.

chonkrat-stew.toml id = 25 [item] name = "Chonkrat Stew" description = "It's got stuff floating in it!" type = "consumable" model_id = 0 is_stackable = false [attributes] heal_amount = 7 [recipe] req_crafting_station = "cooking" req_crafting_equipment = "pot" input_item_res_names = ["raw-chonkrat-meat"] req_skill_lvl = 2 skill_exp_award = 20

I haven't really figured out how players are meant to "discover" recipes yet. I am going to have a skill guide available in the game, to give players an idea of what they can do and what they are working towards. Along with this, I'm kicking around the idea of having individual recipes be items that have to be purchased at a shop, found in the world, or read in a book. I'll see how it feels once I add more recipes and flesh out all the effects of cooked food.


To support all this, I had to do a little refactor to the interaction system, and also added a right-click menu on the client so there was somewhere to tuck away the new interactions. One of those new interactions is examine, so you can examine entities similarly to how you can already examine items in your inventory.

It's easy to specify various interactions on an entity. Here's how the entity definition for the chonkrat looks these days, including the (one line) interaction list.

chonkrat.toml id = 1 [networked] [info] name = "Chonkrat" model_id = 2 description = "A bit on the heavy side." [transform] [npc] sayings = ["squeak!"] combat_sayings = ["eek!", "scree!"] wander_radius = 40.0 [interactable] interactions = ["attack", "walk-to", "examine"] [movement] [health] max_hp = 8 [combat] [stats] stamina = 2 strength = 3 smarts = 1 speed = 3 [drop_table] drops = [ ["any", "0, 10.0, 2-6", "1, 100.0", "2, 100.0", "10, 20.0, 1-2", "11, 15.0", ], ["one", "!rusty-weapons", ], ]

New Packets

This feature brought a ton of new packets along with it. I'm probably going to end up refactoring and reusing a lot of these for other crafting skills. I'm already starting to notice that I have a lot of empty "event packets" in the protocol these days, which really should just be wrapped up into some common RPC (remote procedure call) type packet. I'll get to it some day.

Server - 0x1E (30) - Cooking Open station_net_ent_id: u64 (4 bytes) Client - 0x1F (31) - Cooking Close Request cooking_slot_type: u8 (1 byte) slot: u8 (1 byte) Server - 0x20 (32) - Cooking Close (0 byte body, event packet) Client - 0x21 (33) - Cooking Add Item Request cooking_slot_type: u8 (1 byte) dest_slot: u8 (1 byte) src_bag_slot: u8 (1 byte) Client - 0x22 (34) - Cooking Remove Item Request cooking_slot_type: u8 (1 byte) slot: u8 (1 byte) Server - 0x23 (35) - Cooking Add Item cooking_slot_type: u8 (1 byte) src_bag_slot: u8 (1 byte) dest_slot: u8 (1 byte) Server - 0x24 (36) - Cooking Remove Item cooking_slot_type: u8 (1 byte) src_slot: u8 (1 byte) dest_bag_slot: u8 (1 byte) Client - 0x25 (37) - Cooking Begin Request (0 byte body, event packet) Server - 0x26 (38) - Cooking Begin Unused for now Server - 0x27 (39) - Cooking Finish (0 byte body, event packet)


On the art side of things, my texturing skills have "improved". After all this time, at least I have figured out how to unwrap objects more complex than a cube.

With cooking implemented, the game is feeling a lot more interesting. Since monsters can drop ingredients, and players can cook food for combat and recovery, game systems are starting to feed into each other. When I add things like shops and trading, cooking will also be able to contribute to some minor economy. The new interaction stuff was a big blocker for friendly NPCs, shopkeepers, and banks, so I will be tackling those sometime soon.