Some more stuff for generating recipes

This commit is contained in:
Pao
2023-02-14 02:33:40 +01:00
parent a70ed024a0
commit 4c83d38450
2 changed files with 73 additions and 46 deletions

View File

@@ -37,7 +37,7 @@ def generate_clothing_item(name, model, texture_choices):
tree = gfg.ElementTree(root) tree = gfg.ElementTree(root)
path = r'python_helpers/outputs/output_clothing/' + name + ".xml" path = r'outputs/output_clothing/' + name + ".xml"
with open(path, "wb") as file: with open(path, "wb") as file:
tree.write(file, encoding='utf-8', xml_declaration=True, pretty_print=True ) tree.write(file, encoding='utf-8', xml_declaration=True, pretty_print=True )
@@ -63,31 +63,35 @@ def generate_clothing_item(name, model, texture_choices):
path_idtable = r'python_helpers/outputs/fileGuidTable.xml' path_idtable = r'outputs/fileGuidTable.xml'
with open(path_idtable, "ab") as file: with open(path_idtable, "ab") as file:
tree_guid.write(file, encoding='utf-8', pretty_print=True) tree_guid.write(file, encoding='utf-8', pretty_print=True)
def generate_recipe(recipe_name, recipe_items, result_name, time, skill_required, tooltip): def generate_recipe(recipe_name, recipe_items, on_create_func, time, skill_required, tooltip):
root_element = f"recipe {recipe_name}\n" root_element = f"recipe {recipe_name}\n"
root_element += "\t{\n" root_element += "\t{\n"
for item in recipe_items: for item in recipe_items:
root_element += f"\t\t{item},\n" root_element += f"\t\t{item},\n"
root_element += f"\n\n\t\tResult: {result_name},\n" root_element += "\n\n"
# if result != "":
# root_element += f"\t\tResult: {result_name},\n"
root_element += f"\t\tTime: {time:.2f},\n" root_element += f"\t\tTime: {time:.2f},\n"
root_element += "\t\tNeedToBeLearn: true,\n" root_element += "\t\tNeedToBeLearn: true,\n"
root_element += "\t\tCanBeDoneFromFloor: false,\n" root_element += "\t\tCanBeDoneFromFloor: false,\n"
root_element += "\t\tOnGiveXP: NoXP_OnGiveXP,\n" root_element += "\t\tOnGiveXP: NoXP_OnGiveXP,\n"
root_element += f"\t\tSkillRequired: {skill_required[0]}={skill_required[1]},\n" root_element += f"\t\tSkillRequired: {skill_required[0]}={skill_required[1]},\n"
root_element += "\t\tCategory: Surgeon,\n" root_element += "\t\tCategory: Surgeon,\n"
root_element += f"\t\tOnCreate:{on_create_func},\n"
root_element += f"\t\tTooltip: {tooltip},\n" root_element += f"\t\tTooltip: {tooltip},\n"
root_element += "\t}\n" root_element += "\t}\n"
path = r'python_helpers/outputs/output_recipe/script.txt' path = r'outputs/output_recipe/script.txt'
with open(path, "at") as file: with open(path, "at") as file:
file.write(root_element) file.write(root_element)
@@ -114,7 +118,7 @@ def generate_item(item_name, weight, item_type, display_category, display_name,
root_element += "\t}\n" root_element += "\t}\n"
path = r'python_helpers/outputs/output_item/script.txt' path = r'outputs/output_item/script.txt'
with open(path, "at") as file: with open(path, "at") as file:
file.write(root_element) file.write(root_element)
@@ -140,7 +144,7 @@ def read_table(file_name: str, table_name: str) -> pd.DataFrame:
########################################################################################### ###########################################################################################
excel_path = r'python_helpers/modules_prost.xlsx' excel_path = r'modules_prost.xlsx'
df_base = read_table(excel_path, "BaseTable") df_base = read_table(excel_path, "BaseTable")
df_top = read_table(excel_path, "TopTable") df_top = read_table(excel_path, "TopTable")
@@ -182,37 +186,65 @@ for base_row in df_base.iterrows():
icon = "metalLeg" icon = "metalLeg"
generate_item(item_id, weight, item_type, display_category, display_name, icon, "TempTooltip", "false", clothing_item_name, bl, "Hands") generate_item(item_id, weight, item_type, display_category, display_name, icon, "TempTooltip", "false", clothing_item_name, bl, "Hands")
# ITEM GENERATION PASS - Single item to assemble stuff # ITEM GENERATION PASS - Single item to assemble stuff
def generate_normal_items(df, type): def generate_normal_items(df, part_type):
for row in df.iterrows(): for row in df.iterrows():
item_id = "ProstPart_" + row[1][type] item_id = "ProstPart_" + row[1][part_type]
item_type = "Normal" item_type = "Normal"
weight = "{0:.2f}".format(float(row[1]["Weight"])) weight = "{0:.2f}".format(float(row[1]["Weight"]))
display_category = "Prosthesis" display_category = "Prosthesis"
display_name = row[1]["Display Name"] display_name = row[1]["Display Name"]
icon = "ProstTest" + type icon = "ProstTest" + part_type
generate_item(item_id, weight, item_type, display_category, display_name, icon, "TempTooltip", "false") generate_item(item_id, weight, item_type, display_category, display_name, icon, "TempTooltip", "false")
generate_normal_items(df_base, "Base") generate_normal_items(df_base, "Base")
generate_normal_items(df_top, "Top") generate_normal_items(df_top, "Top")
# RECIPE GENERATION PASS # RECIPE GENERATION PASS - Assembly
for base_row in df_base.iterrows():
for top_row in df_top.iterrows():
base_name = base_row[1]["Base"]
top_name = top_row[1]["Top"]
base_display_name = base_row[1]["Display Name"]
top_display_name = top_row[1]["Display Name"]
recipe_name = f"Craft prosthesis with {base_display_name} and {top_display_name}"
first_item = "ProstPart_" + base_row[1]["Base"]
second_item = "ProstPart_" + top_row[1]["Top"]
# TODO add screwdriver and some screws to the items
recipe_items = [first_item, second_item]
on_create_func = "ProsthesisRecipes.OnCreateProsthesis"
time = 10 # TODO Change this
skill_required = ["FirstAid", "2"] # TODO Change this
tooltip = "Tooltip_test"
generate_recipe(recipe_name, recipe_items, on_create_func, time, skill_required, tooltip)
# RECIPE GENERATION PASS - Disassembly
for base_row in df_base.iterrows(): for base_row in df_base.iterrows():
for top_row in df_top.iterrows(): for top_row in df_top.iterrows():
base_name = base_row[1]["Base"] base_name = base_row[1]["Base"]
top_name = top_row[1]["Top"] top_name = top_row[1]["Top"]
base_display_name = base_row[1]["Display Name"]
top_display_name = top_row[1]["Display Name"]
recipe_name = f"Craft prosthesis with {base_name} and {top_name}" recipe_name = f"Disassemble prosthesis with {base_display_name} and {top_display_name}"
recipe_item = [f"Prost_{base_name}_{top_name}"]
first_item = "ProstPart_" + base_row[1]["Base"] on_create_func = "ProsthesisRecipes.OnDisassembleProsthesis"
second_item = "ProstPart_" + top_row[1]["Top"]
recipe_items = [first_item, second_item]
result = "Prost_" + base_name + "_" + top_name
time = 10 # TODO Change this time = 10 # TODO Change this
skill_required = ["FirstAid", "2"] # TODO Change this skill_required = ["FirstAid", "2"] # TODO Change this
tooltip = "Tooltip_test" tooltip = "Tooltip_test"
generate_recipe(recipe_name, recipe_items, result, time, skill_required, tooltip) generate_recipe(recipe_name, recipe_item, on_create_func, time, skill_required, tooltip)
# RECIPE GENERATION PASS - Single parts - Base
# TODO do this

View File

@@ -17,8 +17,6 @@ local base_table = {
} }
local top_table = { local top_table = {
MetalHook = { MetalHook = {
durability = 1, durability = 1,
@@ -53,7 +51,7 @@ end
---@param prosthesis_item any Normal item ---@param prosthesis_item any Normal item
---@param inventory any player inventory ---@param inventory any player inventory
---@param limb any ---@param limb any
---@return unknown equipped_prosthesis clothing item equipped prosthesis ---@return any equipped_prosthesis clothing item equipped prosthesis
function GenerateEquippedProsthesis(prosthesis_item, inventory, limb) function GenerateEquippedProsthesis(prosthesis_item, inventory, limb)
-- TODO Durability should be decided from the clothing item xml. Same thing for disassembling stuff -- TODO Durability should be decided from the clothing item xml. Same thing for disassembling stuff
-- TODO some stuff should be defined by the limb, like -10 if forearm in speed -- TODO some stuff should be defined by the limb, like -10 if forearm in speed
@@ -63,8 +61,6 @@ function GenerateEquippedProsthesis(prosthesis_item, inventory, limb)
local prosthesis_name = prosthesis_item:getFullType() local prosthesis_name = prosthesis_item:getFullType()
local item_mod_data = prosthesis_item:getModData() local item_mod_data = prosthesis_item:getModData()
local durability_base = 0 local durability_base = 0
local speed_base = 0 local speed_base = 0
@@ -100,8 +96,13 @@ end
ProsthesisRecipes = {} ProsthesisRecipes = {}
-- Parts should have a default condition max set at creation
-- When we create a prosthesis, we carry the condition from the parts
-- If we disassemble the prosthesis, the condition will be carried back to the parts
-- Speed stat should be managed in another way, so change it
local function GetProshetsisPartName(array_stats, prosthesis_name)
local function GetProsthesisPartName(array_stats, prosthesis_name)
for name, _ in pairs(array_stats) do for name, _ in pairs(array_stats) do
if string.find(prosthesis_name, name) then if string.find(prosthesis_name, name) then
return name return name
@@ -151,8 +152,8 @@ function ProsthesisRecipes.OnDisassembleProsthesis(item, result_items, player, s
-- Check name of the item -- Check name of the item
local prosthesis_item_name = item:getFullType() local prosthesis_item_name = item:getFullType()
local base_name = GetProshetsisPartName(base_table, prosthesis_item_name) local base_name = GetProsthesisPartName(base_table, prosthesis_item_name)
local top_name = GetProshetsisPartName(top_table, prosthesis_item_name) local top_name = GetProsthesisPartName(top_table, prosthesis_item_name)
print("TOC: " .. base_name .. " and " .. top_name) print("TOC: " .. base_name .. " and " .. top_name)
@@ -179,9 +180,3 @@ end
-- Parts should have a default condition max set at creation
-- When we create a prosthesis, we carry the condition from the parts
-- If we disassemble the prosthesis, the condition will be carried back to the parts
-- Speed stat should be managed in another way, so change it