Class: Battle::Logic::ItemChangeHandler
- Inherits:
-
ChangeHandlerBase
- Object
- ChangeHandlerBase
- Battle::Logic::ItemChangeHandler
- Includes:
- Hooks
- Defined in:
- scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01002 ItemChangeHandler.rb
Overview
Handler responsive of answering properly item changes requests
Constant Summary collapse
- PROTECTED_ITEMS =
List of item that cannot be knocked off
%i[exp_share lucky_egg amulet_coin oak_s_letter gram_1 gram_2 gram_3 prof_s_letter letter greet_mail favored_mail rsvp_mail thanks_mail inquiry_mail like_mail reply_mail bridge_mail_s bridge_mail_d bridge_mail_t bridge_mail_v bridge_mail_m gengarite gardevoirite ampharosite venusaurite charizardite_x blastoisinite mewtwonite_x mewtwonite_y blazikenite medichamite houndoominite aggronite banettite tyranitarite scizorite pinsirite aerodactylite lucarionite abomasite kangaskhanite gyaradosite absolite charizardite_y alakazite heracronite mawilite manectite garchompite latiasite latiosite swampertite sceptilite sablenite altarianite galladite audinite metagrossite sharpedonite slowbronite steelixite pidgeotite glalitite diancite cameruptite lopunnite salamencite beedrillite red_orb blue_orb jade_orb]
- PROTECTED_POKEMON_ITEMS =
TO DO : Add Z-Crystals to PROTECTED_ITEMS (7G) List of items that cannot be knocked off if the holder is a specific Pokemon
{ giratina: %i[griseous_orb], arceus: %i[flame_plate splash_plate zap_plate meadow_plate icicle_plate fist_plate toxic_plate earth_plate sky_plate mind_plate insect_plate stone_plate spooky_plate draco_plate dread_plate iron_plate pixie_plate], genesect: %i[shock_drive burn_drive chill_drive douse_drive] }
Instance Attribute Summary
Attributes inherited from ChangeHandlerBase
Class Method Summary collapse
-
.register_post_item_change_hook(reason) {|handler, db_symbol, target, launcher, skill| ... }
Function that registers a post_item_change hook.
-
.register_pre_item_change_hook(reason) {|handler, db_symbol, target, launcher, skill| ... }
Function that registers a pre_item_change hook.
Instance Method Summary collapse
-
#can_give_item?(giver, target, launcher = giver) ⇒ Boolean
Function that checks if the Pokemon can give its item to a target.
-
#can_lose_item?(target, launcher = nil) ⇒ Boolean
Function that checks if the Pokemon can lose its item.
-
#change_item(db_symbol, overwrite, target, launcher = nil, skill = nil) ⇒ Boolean
Function that change the item held by a Pokemon.
Methods included from Hooks
#exec_hooks, #force_return, included, register, remove, remove_without_name
Methods inherited from ChangeHandlerBase
#initialize, #prevent_change, #process_prevention_reason, #reset_prevention_reason
Constructor Details
This class inherits a constructor from Battle::Logic::ChangeHandlerBase
Class Method Details
.register_post_item_change_hook(reason) {|handler, db_symbol, target, launcher, skill| ... }
Function that registers a post_item_change hook
103 104 105 106 107 108 109 110 111 112 113 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01002 ItemChangeHandler.rb', line 103 def register_post_item_change_hook(reason) Hooks.register(ItemChangeHandler, :post_item_change, reason) do |hook_binding| yield( self, hook_binding.local_variable_get(:db_symbol), hook_binding.local_variable_get(:target), hook_binding.local_variable_get(:launcher), hook_binding.local_variable_get(:skill) ) end end |
.register_pre_item_change_hook(reason) {|handler, db_symbol, target, launcher, skill| ... }
Function that registers a pre_item_change hook
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01002 ItemChangeHandler.rb', line 83 def register_pre_item_change_hook(reason) Hooks.register(ItemChangeHandler, :pre_item_change, reason) do |hook_binding| result = yield( self, hook_binding.local_variable_get(:db_symbol), hook_binding.local_variable_get(:target), hook_binding.local_variable_get(:launcher), hook_binding.local_variable_get(:skill) ) force_return(false) if result == :prevent end end |
Instance Method Details
#can_give_item?(giver, target, launcher = giver) ⇒ Boolean
Function that checks if the Pokemon can give its item to a target
65 66 67 68 69 70 71 72 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01002 ItemChangeHandler.rb', line 65 def can_give_item?(giver, target, launcher = giver) return false unless can_lose_item?(giver, launcher) return false if target.hold_item?(target.item_db_symbol) return false if target.battle_item_db_symbol == :__undef__ return false if PROTECTED_POKEMON_ITEMS.keys.include?(target.db_symbol) return true end |
#can_lose_item?(target, launcher = nil) ⇒ Boolean
Function that checks if the Pokemon can lose its item
49 50 51 52 53 54 55 56 57 58 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01002 ItemChangeHandler.rb', line 49 def can_lose_item?(target, launcher = nil) return false unless target.hold_item?(target.item_db_symbol) return false if %i[none __undef__].include?(target.battle_item_db_symbol) || PROTECTED_ITEMS.include?(target.item_db_symbol) return false if target.dead? return false if launcher&.can_be_lowered_or_canceled?(target.has_ability?(:sticky_hold)) return false if PROTECTED_POKEMON_ITEMS[target.db_symbol]&.include?(target.battle_item_db_symbol) return false if target.effects.has?(:substitute) && target != launcher return true end |
#change_item(db_symbol, overwrite, target, launcher = nil, skill = nil) ⇒ Boolean
Function that change the item held by a Pokemon
33 34 35 36 37 38 39 40 41 42 43 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01002 ItemChangeHandler.rb', line 33 def change_item(db_symbol, overwrite, target, launcher = nil, skill = nil) log_data("# change_item(#{db_symbol}, #{overwrite}, #{target}, #{launcher}, #{skill})") exec_hooks(ItemChangeHandler, :pre_item_change, binding) target.battle_item = db_symbol == :none ? 0 : data_item(db_symbol).id target.item_holding = target.battle_item if overwrite exec_hooks(ItemChangeHandler, :post_item_change, binding) return true rescue Hooks::ForceReturn => e log_data("# FR: change_item #{e.data} from #{e.hook_name} (#{e.reason})") return e.data end |