###########
# Multiplayer & singleplayer
# weapon breaking.
# Chaalaak.
###########
multiplayer_weapon_break = (
0.4, 0, 0,
[(game_in_multiplayer_mode)],
[
(set_fixed_point_multiplier, 100),
(multiplayer_get_my_player, ":player"),
(player_get_agent_id, ":agent", ":player"),
(ge, ":agent", 0),
(agent_get_attack_action, ":attack_action", ":agent"),
(agent_get_defend_action, ":defend_action", ":agent"),
(agent_get_wielded_item, ":wielded_item", ":agent", 0),
(ge, ":wielded_item", 0),
(store_random_in_range, ":chance", 0, 100),
#Calculate chance.
(try_begin),
(eq, ":attack_action", 3), #Completing attack.
(item_get_type, ":weapon_type", ":wielded_item"),
(try_begin),
(agent_get_horse, ":horse", ":agent"),
(ge, ":horse", 0),
(val_mul, ":chance", 110),
(val_div, ":chance", 100),
(try_end),
(try_begin),
(eq, ":weapon_type", itp_type_polearm), #Polearm.
(val_mul, ":chance", 103),
(val_div, ":chance", 100),
(else_try),
(eq, ":weapon_type", itp_type_one_handed_wpn), #1-handed.
(val_mul, ":chance", 102),
(val_div, ":chance", 100),
(else_try),
(eq, ":weapon_type", itp_type_two_handed_wpn), #2-handed.
(val_mul, ":chance", 103),
(val_div, ":chance", 100),
(try_end),
(else_try),
(eq, ":defend_action", 1), #Parrying.
(item_get_type, ":weapon_type", ":wielded_item"),
(try_begin),
(agent_get_horse, ":horse", ":agent"),
(ge, ":horse", 0),
(val_mul, ":chance", 110),
(val_div, ":chance", 100),
(try_end),
(try_begin),
(eq, ":weapon_type", itp_type_polearm), #Polearm.
(val_mul, ":chance", 105),
(val_div, ":chance", 100),
(else_try),
(eq, ":weapon_type", itp_type_one_handed_wpn), #1-handed.
(val_mul, ":chance", 103),
(val_div, ":chance", 100),
(else_try),
(eq, ":weapon_type", itp_type_two_handed_wpn), #2-handed.
(val_mul, ":chance", 105),
(val_div, ":chance", 100),
(try_end),
(try_end),
#Determine weapon breaking based on chance.
(ge, ":chance", 95),
(display_message, "@Your weapon has broken!", 0xCC0000), #Red color.
(multiplayer_send_int_to_server, multiplayer_weapon_break_event, ":wielded_item"),
])
#Meant only for AI.
single_and_multiplayer_weapon_break = (
1, 0, 0,
[],
[
(this_or_next|multiplayer_is_server),
(neg|game_in_multiplayer_mode),
(set_fixed_point_multiplier, 100),
(try_for_agents, ":agent"),
(agent_is_non_player, ":agent"),
(agent_is_alive, ":agent"),
(agent_is_human, ":agent"),
(agent_get_attack_action, ":attack_action", ":agent"),
(agent_get_defend_action, ":defend_action", ":agent"),
(agent_get_wielded_item, ":wielded_item", ":agent", 0),
(ge, ":wielded_item", 0),
(store_random_in_range, ":chance", 0, 100),
#Calculate chance.
(try_begin),
(eq, ":attack_action", 3), #Completing attack.
(item_get_type, ":weapon_type", ":wielded_item"),
(try_begin),
(agent_get_horse, ":horse", ":agent"),
(ge, ":horse", 0),
(val_mul, ":chance", 110),
(val_div, ":chance", 100),
(try_end),
(try_begin),
(eq, ":weapon_type", itp_type_polearm), #Polearm.
(val_mul, ":chance", 105),
(val_div, ":chance", 100),
(else_try),
(eq, ":weapon_type", itp_type_one_handed_wpn), #1-handed.
(val_mul, ":chance", 102),
(val_div, ":chance", 100),
(else_try),
(eq, ":weapon_type", itp_type_two_handed_wpn), #2-handed.
(val_mul, ":chance", 103),
(val_div, ":chance", 100),
(try_end),
(else_try),
(eq, ":defend_action", 1), #Parrying.
(item_get_type, ":weapon_type", ":wielded_item"),
(try_begin),
(agent_get_horse, ":horse", ":agent"),
(ge, ":horse", 0),
(val_mul, ":chance", 110),
(val_div, ":chance", 100),
(try_end),
(try_begin),
(eq, ":weapon_type", itp_type_polearm), #Polearm.
(val_mul, ":chance", 10
,
(val_div, ":chance", 100),
(else_try),
(eq, ":weapon_type", itp_type_one_handed_wpn), #1-handed.
(val_mul, ":chance", 103),
(val_div, ":chance", 100),
(else_try),
(eq, ":weapon_type", itp_type_two_handed_wpn), #2-handed.
(val_mul, ":chance", 105),
(val_div, ":chance", 100),
(try_end),
(try_end),
#Determine weapon breaking based on chance.
(ge, ":chance", 95),
(try_begin),
(game_in_multiplayer_mode),
(multiplayer_send_int_to_server, multiplayer_weapon_break_event_2, ":agent", ":wielded_item"),
(else_try),
(agent_play_sound, ":agent", "snd_shield_broken"),
(agent_unequip_item, ":agent", ":weapon"),
(try_end),
(try_end),
])
#Meant only for player.
singleplayer_weapon_break = (
0.4, 0, 0,
[(neg|game_in_multiplayer_mode)],
[
(set_fixed_point_multiplier, 100),
(get_player_agent_no, ":agent"),
(agent_get_attack_action, ":attack_action", ":agent"),
(agent_get_defend_action, ":defend_action", ":agent"),
(agent_get_wielded_item, ":wielded_item", ":agent", 0),
(ge, ":wielded_item", 0),
(store_random_in_range, ":chance", 0, 100),
#Calculate chance.
(try_begin),
(eq, ":attack_action", 3), #Completing attack.
(item_get_type, ":weapon_type", ":wielded_item"),
(try_begin),
(agent_get_horse, ":horse", ":agent"),
(ge, ":horse", 0),
(val_mul, ":chance", 110),
(val_div, ":chance", 100),
(try_end),
(try_begin),
(eq, ":weapon_type", itp_type_polearm), #Polearm.
(val_mul, ":chance", 103),
(val_div, ":chance", 100),
(else_try),
(eq, ":weapon_type", itp_type_one_handed_wpn), #1-handed.
(val_mul, ":chance", 102),
(val_div, ":chance", 100),
(else_try),
(eq, ":weapon_type", itp_type_two_handed_wpn), #2-handed.
(val_mul, ":chance", 103),
(val_div, ":chance", 100),
(try_end),
(else_try),
(eq, ":defend_action", 1), #Parrying.
(item_get_type, ":weapon_type", ":wielded_item"),
(try_begin),
(agent_get_horse, ":horse", ":agent"),
(ge, ":horse", 0),
(val_mul, ":chance", 110),
(val_div, ":chance", 100),
(try_end),
(try_begin),
(eq, ":weapon_type", itp_type_polearm), #Polearm.
(val_mul, ":chance", 105),
(val_div, ":chance", 100),
(else_try),
(eq, ":weapon_type", itp_type_one_handed_wpn), #1-handed.
(val_mul, ":chance", 103),
(val_div, ":chance", 100),
(else_try),
(eq, ":weapon_type", itp_type_two_handed_wpn), #2-handed.
(val_mul, ":chance", 105),
(val_div, ":chance", 100),
(try_end),
(try_end),
#Determine weapon breaking based on chance.
(ge, ":chance", 95),
(display_message, "@Your weapon has broken!", 0xCC0000), #Red color.
(agent_play_sound, ":agent", "snd_shield_broken"),
(agent_unequip_item, ":agent", ":weapon"),
(troop_remove_item, "trp_player", ":weapon"),
])
###########