Creating Instanced Items #
In this section, we’ll demonstrate how to create a custom unique instanced item type called “gear.” To create gear we’ll go over the following steps:
- Create the gear’s
extinstanced item template (ExtInstancedSpec) andextitem mold (ExtInstancedItem) in protos. - Define the catalog of gear instanced items in JSON.
- Customize an
InstancedItemPluginin Kotlin that buildsextdata for gear.
Get started #
Run the following commands in the terminal from the platform directory to build the engine and make 5-ext if it doesn’t already exist:
make skip-tests protos enginemake ext
Define the protos #
In this section, we’ll define the two protobuf definitions that make up ext data for instanced items:
ExtInstancedSpectemplates the item’s customextdataExtInstancedItemcontains theextdata of instanced items built in theInstancedItemPlugin.
Edit the inventory content ext file #
Define the ExtInstancedSpec templates for the gear-type items’ custom ext data.
- Open
5-ext/ext-protos/src/main/proto/shared/inventoryContentExt.proto. - In the
ExtInstancedSpecmessage, add the following code to define theGearSpec:
message ExtInstancedSpec {
oneof data {
GearSpec gear_spec = 1;
}
}
- Define custom
GearSpeccomponents by inserting the following message below theExtInstancedSpecmessage. This message lists the values required when creating anextdata for a gear-type item.
message GearSpec {
int32 level_to_equip = 1;
string primary_attribute_spec_id = 2;
int32 primary_attribute_value_min = 3;
int32 primary_attribute_value_max = 4;
}
Edit the inventory ext file #
Define the ExtInstancedItem mold that contains the ext data for gear-type items.
- Open
5-ext/ext-protos/src/main/proto/shared/inventoryExt.proto. - Edit the
ExtInstancedItemmessage by inserting the following code:
message ExtInstancedItem {
oneof data {
Gear gear = 1;
}
}
- Define
Gearby inserting the following message below theExtInstancedItemmessage:
message Gear {
int32 attribute_value = 1;
repeated string socketed_runestones = 2;
}
Apply proto changes #
Run the following make command using platform as the working directory to apply protobuf changes:
make ext-protos
Define the JSON catalog #
Instanced items are defined in a JSON item catalog with shared identifiers and configurations for all game content managed by the platform. This is where designers create player inventory specifications and include ext data with their items.
If you do not already have the content source files initialized, runmake init-inventory-contentusing a terminal from theplatformdirectory.
Edit the instanced specs catalog #
Define gear-type items metal_sword_1, metal_chest_2, and metal_hat_3 in the instanced specs JSON catalog.
- Open
5-ext/content/src/InstancedSpecs.json. - Insert the following code into the JSON catalog:
[
{
"catalogId": "metal_sword_1",
"name": "Copper Sword",
"tags": [
"weapon",
"1h"
],
"ext": {
"gearSpec": {
"levelToEquip": 1,
"primaryAttributeSpecId": "damage_physical",
"primaryAttributeValueMin": 5,
"primaryAttributeValueMax": 10
}
}
},
{
"catalogId": "metal_chest_2",
"name": "Bronze Breastplate",
"tags": [
"armor",
"chest",
"heavy-armor"
],
"ext": {
"gearSpec": {
"levelToEquip": 2,
"primaryAttributeSpecId": "resistance_physical",
"primaryAttributeValueMin": 35,
"primaryAttributeValueMax": 40
}
}
},
{
"catalogId": "metal_hat_3",
"name": "Iron Helmet",
"tags": [
"armor",
"head",
"heavy-armor"
],
"ext": {
"gearSpec": {
"levelToEquip": 3,
"primaryAttributeSpecId": "resistance_physical",
"primaryAttributeValueMin": 20,
"primaryAttributeValueMax": 25
}
}
}
]
Apply content data #
In order to register the content you just defined with Pragma Engine, you must apply your content data changes. You may apply content data either using the command line with make or via an IntelliJ run configuration.