Today is a long dissection of Rigale crafting, as implemented at build v155 B5 of Phantasy 2018:
first, some scripts
first, some scripts
Code:
# script_cf_player_has_item_without_modifier
# Input: arg1 = item_id, arg2 = modifier
# Output: none (can_fail)
("cf_player_has_item_without_modifier",
[
(store_script_param, ":item_id", 1),
(store_script_param, ":modifier", 2),
(player_has_item, ":item_id"),
#checking if any of the meat is not rotten
(assign, ":has_without_modifier", 0),
(troop_get_inventory_capacity, ":inv_size", "trp_player"),
(try_for_range, ":i_slot", 10, ":inv_size"), # GS was starting at 0 so counted worn items as well
(troop_get_inventory_slot, ":cur_item", "trp_player", ":i_slot"),
(eq, ":cur_item", ":item_id"),
(troop_get_inventory_slot_modifier, ":cur_modifier", "trp_player", ":i_slot"),
(neq, ":cur_modifier", ":modifier"),
(assign, ":has_without_modifier", 1),
(assign, ":inv_size", 10), #break
(try_end),
(eq, ":has_without_modifier", 1),
]),
# script_player_has_item_get_modifier
# Input: arg1 = item_id, arg2 = item_count
# Output: reg3 = sum of imod values for this item
("player_has_item_get_modifier",
[
(store_script_param, ":item_id", 1),
(store_script_param, ":item_count", 2),
(assign, reg3, 0),
(player_has_item, ":item_id"),
(assign, ":counted", 0),
(assign, ":imod_sum", 0),
(troop_get_inventory_capacity, ":inv_size", "trp_player"),
## GS first clean any rotten items
(try_for_range, ":i_slot", 10, ":inv_size"),
(troop_get_inventory_slot_modifier, ":cur_modifier", "trp_player", ":i_slot"),
(eq, ":cur_modifier", imod_rotten),
(troop_set_inventory_slot, "trp_player", ":i_slot", -1),
(try_end),
(try_for_range, ":i_slot", 10, ":inv_size"), # GS start at 10 to skip items player is wearing
(troop_get_inventory_slot, ":cur_item", "trp_player", ":i_slot"),
(eq, ":cur_item", ":item_id"),
(troop_get_inventory_slot_modifier, ":cur_modifier", "trp_player", ":i_slot"),
(assign, ":imod_weighting", 0),
(try_begin),
(this_or_next|eq, ":cur_modifier", imod_plain),
(this_or_next|eq, ":cur_modifier", imod_day_old),
(this_or_next|eq, ":cur_modifier", imod_two_day_old),
(eq, ":cur_modifier", imod_fresh),
(else_try),
(this_or_next|eq, ":cur_modifier", imod_chipped),
(this_or_next|eq, ":cur_modifier", imod_poor),
(this_or_next|eq, ":cur_modifier", imod_cheap),
(this_or_next|eq, ":cur_modifier", imod_old),
(this_or_next|eq, ":cur_modifier", imod_stubborn),
(this_or_next|eq, ":cur_modifier", imod_rough),
(eq, ":cur_modifier", imod_crude),
(assign, ":imod_weighting", -1),
(else_try),
(this_or_next|eq, ":cur_modifier", imod_bent),
(this_or_next|eq, ":cur_modifier", imod_rusty),
(this_or_next|eq, ":cur_modifier", imod_battered),
(this_or_next|eq, ":cur_modifier", imod_ragged),
(this_or_next|eq, ":cur_modifier", imod_tattered),
(this_or_next|eq, ":cur_modifier", imod_swaybacked),
(eq, ":cur_modifier", imod_smelling),
(assign, ":imod_weighting", -2),
(else_try),
(this_or_next|eq, ":cur_modifier", imod_cracked),
(eq, ":cur_modifier", imod_lame),
(assign, ":imod_weighting", -3),
(else_try),
(this_or_next|eq, ":cur_modifier", imod_timid),
(this_or_next|eq, ":cur_modifier", imod_meek),
(this_or_next|eq, ":cur_modifier", imod_sturdy),
(this_or_next|eq, ":cur_modifier", imod_thick),
(this_or_next|eq, ":cur_modifier", imod_sharp),
(eq, ":cur_modifier", imod_fine),
(assign, ":imod_weighting", 1),
(else_try),
(this_or_next|eq, ":cur_modifier", imod_spirited),
(this_or_next|eq, ":cur_modifier", imod_hardened),
(this_or_next|eq, ":cur_modifier", imod_heavy),
(this_or_next|eq, ":cur_modifier", imod_strong),
(this_or_next|eq, ":cur_modifier", imod_powerful),
(this_or_next|eq, ":cur_modifier", imod_deadly),
(eq, ":cur_modifier", imod_well_made),
(assign, ":imod_weighting", 2),
(else_try),
(this_or_next|eq, ":cur_modifier", imod_exquisite),
(this_or_next|eq, ":cur_modifier", imod_reinforced),
(this_or_next|eq, ":cur_modifier", imod_superb),
(this_or_next|eq, ":cur_modifier", imod_tempered),
(eq, ":cur_modifier", imod_balanced),
(assign, ":imod_weighting", 3),
(else_try),
(this_or_next|eq, ":cur_modifier", imod_champion),
(this_or_next|eq, ":cur_modifier", imod_masterwork),
(eq, ":cur_modifier", imod_lordly),
(assign, ":imod_weighting", 4),
(try_end),
(val_add, ":imod_sum", ":imod_weighting"),
(val_add, ":counted", 1),
(try_begin),
(eq, ":counted", ":item_count"),
(assign, ":inv_size", 10), #break
(try_end),
(try_end),
(assign, reg3, ":imod_sum"),
]),
# script_player_remove_crafting_items
# Input: arg1 = item_id, arg2 = item_count
# Output: reg3 = sum of imod values for this item
("player_remove_crafting_items",
[
(store_script_param, ":item_id", 1),
(store_script_param, ":item_count", 2),
(player_has_item, ":item_id"),
(assign, ":counted", 0),
(troop_get_inventory_capacity, ":inv_size", "trp_player"),
(try_for_range, ":i_slot", 10, ":inv_size"),
(troop_get_inventory_slot, ":cur_item", "trp_player", ":i_slot"),
(eq, ":cur_item", ":item_id"),
(val_add, ":counted", 1),
(troop_set_inventory_slot, "trp_player", ":i_slot", -1), # GS item removed
(try_begin),
(eq, ":counted", ":item_count"),
(assign, ":inv_size", 10), #break
(try_end),
(try_end),
]),
## OUTPUT: no change to regs; interprets result in global "$type_of_gathering_success"
# script_rigale_check_crafting_success
("rigale_check_crafting_success",
[
## (store_script_param, ":recipe_type", 1),
(store_script_param, ":difficulty", 2),
(store_script_param, ":imod_bonus", 3),
(try_begin),
(is_between,"$level_of_gathering_skill",0,4),
(assign,":modificateur",-4),
(else_try),
(is_between,"$level_of_gathering_skill",4,7),
(assign,":modificateur",-2),
(else_try),
(is_between,"$level_of_gathering_skill",7,11),
(assign,":modificateur",0),
(else_try),
(is_between,"$level_of_gathering_skill",11,14),
(assign,":modificateur",2),
(else_try),
(is_between,"$level_of_gathering_skill",14,18),
(assign,":modificateur",3),
(else_try),
(ge,"$level_of_gathering_skill",18),
(assign,":modificateur",4),
(try_end),
(assign, ":specific_recipe_knowledge", "$level_of_gathering_skill"),
(val_div,":specific_recipe_knowledge",4), # GS was 7
(store_random_in_range,":random_factor2",2,6),
(store_sub,":final_mod_specific_recipe_knowledge",":specific_recipe_knowledge",":random_factor2"), # modifier from -4 to whatever
(store_random_in_range,":random_factor",1,11),
(val_mul,":random_factor",2), #random 2-20
(assign,":final_factor",":random_factor"),#random 2-20
(val_add,":final_factor",":modificateur"), #add skill mod level
(assign, ":final_difficulty", "$level_of_gathering_skill"),
(val_sub,":final_difficulty",":difficulty"), # substract object difficulty
(val_add,":final_factor",":final_difficulty"),
(val_add,":final_factor",":final_mod_specific_recipe_knowledge"), #add (or substract) specific recipe knowledge
## GS bonus for using good materials here:
(val_add,":final_factor", ":imod_bonus"),
(try_begin),
(this_or_next|eq,":random_factor",2),
(le,":final_factor",3),
(neq,":modificateur",4),#no critical failure for grand masters
(assign, "$type_of_gathering_success", 4), (str_store_string, s2, "@Critical failure!!!"),
(else_try),
(is_between,":final_factor",4,11),
(assign, "$type_of_gathering_success", 3), (str_store_string, s2, "@Failure!!!"),
(else_try),
(is_between,":final_factor",11,18),
(assign, "$type_of_gathering_success", 2), (str_store_string, s2, "@Success!!!"),
(else_try),
(this_or_next|eq,":random_factor",20),
(ge,":final_factor",18),
(assign, "$type_of_gathering_success", 1), (str_store_string, s2, "@Critical success!!!"),
(try_end),
]
),
##OUTPUT: no regs changed
("rigale_remove_some_tools",
[
(store_script_param_1, ":min_number_of_tools"),
(store_script_param_2, ":max_number_of_tools"),
#(troop_get_inventory_slot, ":item_id", "trp_player", 10), # GS ok now we can have tools anywhere
(troop_get_inventory_capacity, ":inv_size", "trp_player"),
(assign,":slot_tools",-1),
(try_for_range, ":i_slot", 10, ":inv_size"),
(troop_get_inventory_slot, ":item_id", "trp_player", ":i_slot"),
(eq, ":item_id", "itm_tools"),
(assign,":slot_tools",":i_slot"), # GS first tools, what slot :)
(assign,":inv_size",":i_slot"), # GS implicit Break
(try_end),
(try_begin),
(eq, ":item_id", "itm_tools"),
(store_random_in_range,":number_of_tools_to_remove",":min_number_of_tools",":max_number_of_tools"),
(assign,reg32,":number_of_tools_to_remove"),
(troop_inventory_slot_get_item_amount,":actual_amount","trp_player",":slot_tools"),
(val_sub,":actual_amount",":number_of_tools_to_remove"),
(try_begin),
(lt,":actual_amount",1),
(troop_remove_item,"trp_player",":item_id"),#(in this case, remove object
(str_store_string,s23,"@You used all your remaining stack of tools."),
(else_try),
(ge,":actual_amount",1),
(troop_inventory_slot_set_item_amount,"trp_player",":slot_tools",":actual_amount"),
(str_store_string,s23,"@You lost {reg32} tools while gathering."),
(try_end),
(try_end),
]
),
## OUTPUT reg1
("rigale_check_number_of_components_available",
[
(store_script_param, ":type_of_components",1),
(assign,":number_of_current_components",0),
(troop_get_inventory_capacity, ":inv_size", "trp_player"),
(try_begin),
(try_for_range, ":i_slot", 10, ":inv_size"), # GS skip equipped/worn items when looking
(troop_get_inventory_slot, ":item_id", "trp_player", ":i_slot"),
(eq, ":item_id", ":type_of_components"),
(neg|call_script, "script_cf_player_has_item_without_modifier", ":item_id", imod_rotten),
(val_add,":number_of_current_components",1),
(try_end),
(try_end), # GS added a missing try_end here
(assign,reg1,":number_of_current_components"),
(set_trigger_result, reg1)
]
),
## OUTPUT sets "$g_b_enough_components_available"
("rigale_check_enough_components_available", #utilisation lumberjacking et mining camps
[
(store_script_param, ":type_of_components",1),
(store_script_param, ":number_of_required_components",2),
(assign,":number_of_current_components",0),
(troop_get_inventory_capacity, ":inv_size", "trp_player"),
(try_begin),
(try_for_range, ":i_slot", 10, ":inv_size"),
(troop_get_inventory_slot, ":item_id", "trp_player", ":i_slot"),
(eq, ":item_id", ":type_of_components"),
(val_add,":number_of_current_components",1),
(try_end),
(try_begin),
(ge,":number_of_current_components",":number_of_required_components"),
(assign, "$g_b_enough_components_available", 1), #instead of reg2
(set_trigger_result, "$g_b_enough_components_available"),
(else_try),
(lt,":number_of_current_components",":number_of_required_components"),
(assign, "$g_b_enough_components_available", 0),
(set_trigger_result, "$g_b_enough_components_available"),
(try_end),
(try_end), # GS added a missing try_end here
]
),
## OUTPUT sets "$g_b_enough_complete_tools_available"
("rigale_check_enough_complete_tools_available",
[
(store_script_param, ":number_of_complete_tools",1),
(assign,":number_of_current_components",0),
(troop_get_inventory_capacity, ":inv_size", "trp_player"),
(try_begin),
(try_for_range, ":i_slot", 10, ":inv_size"),
(troop_get_inventory_slot, ":item_id", "trp_player", ":i_slot"),
(eq, ":item_id", "itm_tools"),
(try_begin),
(troop_inventory_slot_get_item_amount,":tools_amount","trp_player",":i_slot"),
(eq,":tools_amount",50),
(val_add,":number_of_current_components",1),
(try_end),
(try_end),
(try_begin),
(ge,":number_of_current_components",":number_of_complete_tools"),
(assign, "$g_b_enough_complete_tools_available", 1),
(set_trigger_result, "$g_b_enough_complete_tools_available"),
(else_try),
(lt,":number_of_current_components",":number_of_complete_tools"),
(assign, "$g_b_enough_complete_tools_available", 0),
(set_trigger_result, "$g_b_enough_complete_tools_available"),
(try_end),
(try_end), # GS added a try_end here
]
),
## OUTPUT no regs harmed
("rigale_check_crafting_possible_and_start_crafting",
[
(store_script_param, ":slot_specific_recipe",1),
(store_script_param, ":object_difficulty",2),
(store_script_param, ":type_of_component_1",3),
(store_script_param, ":amount_of_required_component_1",4),
(store_script_param, ":type_of_component_2",5),
(store_script_param, ":amount_of_required_component_2",6),
(store_script_param, ":type_of_component_3",7),
(store_script_param, ":amount_of_required_component_3",8),
(store_script_param, ":type_of_component_4",9),
(store_script_param, ":amount_of_required_component_4",10),
(store_script_param, ":type_of_component_5",11),
(store_script_param, ":amount_of_required_component_5",12),
(store_script_param, ":basic_hours_required",13),
(store_script_param, ":particular_type_of_crafted_object",14),
(store_script_param, ":general_type_of_crafted_object",15),
#(assign,":component_types_number",0),
(assign,":number_of_current_components_1",0),
(assign,":number_of_current_components_2",0),
(assign,":number_of_current_components_3",0),
(assign,":number_of_current_components_4",0),
(assign,":number_of_current_components_5",0),
(troop_get_inventory_capacity, ":inv_size", "trp_player"),
(try_for_range, ":i_slot_1", 10, ":inv_size"), # GS need to skip worn/equipped items
(troop_get_inventory_slot, ":item_id", "trp_player", ":i_slot_1"),
(try_begin),
(eq, ":item_id", ":type_of_component_1"),
(neg|call_script, "script_cf_player_has_item_without_modifier", ":type_of_component_1", imod_rotten),
(val_add,":number_of_current_components_1",1),
(try_end),
(try_begin),
(eq, ":item_id", ":type_of_component_2"),
(neg|call_script, "script_cf_player_has_item_without_modifier", ":type_of_component_2", imod_rotten),
(val_add,":number_of_current_components_2",1),
(try_end),
(try_begin),
(eq, ":item_id", ":type_of_component_3"),
(neg|call_script, "script_cf_player_has_item_without_modifier", ":type_of_component_3", imod_rotten),
(val_add,":number_of_current_components_3",1),
(try_end),
(try_begin),
(eq, ":item_id", ":type_of_component_4"),
(neg|call_script, "script_cf_player_has_item_without_modifier", ":type_of_component_4", imod_rotten),
(val_add,":number_of_current_components_4",1),
(try_end),
(try_begin),
(eq, ":item_id", ":type_of_component_5"),
(neg|call_script, "script_cf_player_has_item_without_modifier", ":type_of_component_5", imod_rotten),
(val_add,":number_of_current_components_5",1),
(try_end),
(try_end),
(try_begin),
(assign, ":can_craft", 1), # GS initially assume we CAN craft and then flip it to another value if we find an issue
(gt,":amount_of_required_component_1", 0),
(try_begin),
(lt,":number_of_current_components_1",":amount_of_required_component_1"),
(assign,":can_craft",2),
(try_end),
(try_begin),
(gt,":amount_of_required_component_2", 0),
(try_begin),
(lt,":number_of_current_components_2",":amount_of_required_component_2"),
(assign,":can_craft",2),
(try_end),
# (else_try),
# (eq,":amount_of_required_component_2",0),
# (try_begin),
# (eq,":number_of_current_components_2",0),
# (assign,":can_craft",1),
# (try_end),
(try_end),
(try_begin),
(gt,":amount_of_required_component_3", 0),
(try_begin),
(lt,":number_of_current_components_3",":amount_of_required_component_3"),
(assign,":can_craft",2),
(try_end),
# (else_try),
# (eq,":amount_of_required_component_3",0),
# (try_begin),
# (eq,":number_of_current_components_3",0),
# (assign,":can_craft",1),
# (try_end),
(try_end),
(try_begin),
(gt,":amount_of_required_component_4", 0),
(try_begin),
(lt,":number_of_current_components_4",":amount_of_required_component_4"),
(assign,":can_craft",2),
(try_end),
# (else_try),
# (eq,":amount_of_required_component_4",0),
# (try_begin),
# (eq,":number_of_current_components_4",0),
# (assign,":can_craft",1),
# (try_end),
(try_end),
(try_begin),
(gt,":amount_of_required_component_5", 0),
(try_begin),
(lt,":number_of_current_components_5",":amount_of_required_component_5"),
(assign,":can_craft",2),
(try_end),
# (else_try),
# (eq,":amount_of_required_component_5",0),
# (try_begin),
# (eq,":number_of_current_components_5",0),
# (assign,":can_craft",1),
# (try_end),
(try_end),
(try_begin), # GS technically this was already done before this got called, so commented out for test! (for now)
# (neg|troop_slot_ge,"trp_player", ":slot_specific_recipe:",20), # GS not sure what this was supposed to do, but
(lt, "$level_of_gathering_skill", ":object_difficulty"), # GS this works for now
# GS eventually needs to look at ":slot_specific_recipe" to determine crafting type
# GS then determine skill in that category...
(assign,":can_craft",2),
(try_end),
(assign, ":savereg3", reg3),
(try_begin),
(call_script, "script_time_avail"),
(eq, reg3, 0),
(assign, ":can_craft", 0), # GS only if already busy change the values built so far...
(try_end),
(assign, reg3, ":savereg3"),
(try_begin),
(eq,":can_craft",1),
## GS gather pluses and minuses as a parameter to pass to "script_rigale_check_crafting_success"
(troop_get_inventory_capacity, ":inv_size", "trp_player"),
(assign, ":savereg3", reg3),
(assign, ":imod1", 0),
(assign, ":imod2", 0),
(assign, ":imod3", 0),
(assign, ":imod_weighting", 0),
(call_script, "script_player_has_item_get_modifier", ":type_of_component_1", ":amount_of_required_component_1"),
(assign, ":imod1", reg3),
(val_add, ":imod_weighting", ":imod1"),
(try_begin),
(gt, ":amount_of_required_component_2", 0),
(call_script, "script_player_has_item_get_modifier", ":type_of_component_2", ":amount_of_required_component_2"),
(assign, ":imod2", reg3),
(val_div, ":imod2", 2),
(val_add, ":imod_weighting", ":imod2"),
(try_end),
(try_begin),
(gt, ":amount_of_required_component_3", 0),
(call_script, "script_player_has_item_get_modifier", ":type_of_component_3", ":amount_of_required_component_3"),
(assign, ":imod2", reg3),
(val_div, ":imod3", 3),
(val_add, ":imod_weighting", ":imod3"),
(try_end),
(assign, reg3, ":savereg3"),
### # GS we can skip components 4 and 5 for checking imods
## (try_begin),
## (eq, ":item_id", ":type_of_component_4"),
## (neg|call_script, "script_cf_player_has_item_without_modifier", ":type_of_component_4", imod_rotten),
## (val_add,":number_of_current_components_4",1),
## (try_end),
## (try_begin),
## (eq, ":item_id", ":type_of_component_5"),
## (neg|call_script, "script_cf_player_has_item_without_modifier", ":type_of_component_5", imod_rotten),
## (val_add,":number_of_current_components_5",1),
## (try_end),
# (this_or_next|ge,":number_of_current_components_1",":amount_of_required_component_1"),
# (this_or_next|ge,":number_of_current_components_2",":amount_of_required_component_2"),
# (this_or_next|ge,":number_of_current_components_3",":amount_of_required_component_3"),
# (this_or_next|ge,":number_of_current_components_4",":amount_of_required_component_4"),
# (ge,":number_of_current_components_5",":amount_of_required_component_5"),
# (store_skill_level, "$level_of_gathering_skill", ":skl_used", "trp_player"), #deja dans le menu basique d'arrivee chez le smith
(call_script,"script_rigale_check_crafting_success",":slot_specific_recipe",":object_difficulty", ":imod_weighting"), # GS newly added imod bonus 10 May 2018
(assign,"$crafting_basic_hours_required",":basic_hours_required"),
# (assign,"$crafting_basic_hours_required",2), # GS only for test!
(assign,"$crafted_item",":particular_type_of_crafted_object"),
(assign,"$crafted_object_type",":general_type_of_crafted_object"),
(try_begin),
(ge,":amount_of_required_component_1", 1),
(call_script, "script_player_remove_crafting_items", ":type_of_component_1", ":amount_of_required_component_1"),
(try_end),
(try_begin),
(ge,":amount_of_required_component_2",1),
(call_script, "script_player_remove_crafting_items", ":type_of_component_2", ":amount_of_required_component_2"),
(try_end),
(try_begin),
(ge,":amount_of_required_component_3",1),
(call_script, "script_player_remove_crafting_items", ":type_of_component_3", ":amount_of_required_component_3"),
(try_end),
(try_begin),
(ge,":amount_of_required_component_4",1),
(call_script, "script_player_remove_crafting_items", ":type_of_component_4", ":amount_of_required_component_4"),
(try_end),
(try_begin),
(ge,":amount_of_required_component_5",1),
(call_script, "script_player_remove_crafting_items", ":type_of_component_5", ":amount_of_required_component_5"),
(try_end),
(call_script, "script_set_time_busy", ":basic_hours_required"),
(assign, "$auto_enter_town", -1),
# (assign, "$g_town_visit_after_rest", 1),
(rest_for_hours,":basic_hours_required","$g_phantasy_wait_multiplier",0), # GS this needs changing to use locks scheme
# (change_screen_return),
(change_screen_map), #WR possible bug fix
(else_try),
(ge,":can_craft",2),
(jump_to_menu,"mnu_crafting_no_component"),
(else_try),
(le, ":can_craft", 0),
(call_script, "script_time_aggregate", 1), # GS mention how many hours they should wait based on largest time flag set
(try_end),
(try_end), # GS added missing try_end here
]
),