Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # ** Drago - Custom Page Condition
- # Version : 1.00
- # Contact : littledrago.blogspot.com / forum.chaos-project.com
- #==============================================================================
- ($imported ||= {})[:drg_custom_page_condition] = 1.00
- core = "This script needs Drago - Core Engine ver 1.47 or above"
- ($imported[:drg_core_engine] || 0) >= 1.47 || raise(core)
- #==============================================================================
- # ** Game_Event
- #------------------------------------------------------------------------------
- # This class deals with events. It handles functions including event page
- # switching via condition determinants, and running parallel process events.
- # It's used within the Game_Map class.
- #==============================================================================
- class Game_Event
- #--------------------------------------------------------------------------
- # * Constant
- #--------------------------------------------------------------------------
- PARTY_EQSIZE = carrot do |t,i|
- $game_party.members.map do |a|
- a.equips.select {|e| e.is_a?(t) && e.id == i.id }.size
- end.sum
- end
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_sec_reader :cond_page_eval, 'Array.new'
- #--------------------------------------------------------------------------
- # * Alias Listing
- #--------------------------------------------------------------------------
- alias_sec_method :drg_refresh_eval_conditions, :refresh
- alias_sec_method :drg_update_eval_conditions, :update
- #--------------------------------------------------------------------------
- # * Define Secondary Listing
- #--------------------------------------------------------------------------
- define_sec_method(:refresh_trigger_conditions) { find_proper_page }
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh(*args)
- cond_page_eval.clear
- new_page = @erased ? nil : refresh_trigger_conditions
- pages = @event.pages
- if new_page != @page
- @event.pages = [new_page ? new_page.clone : nil]
- @event.pages[0] && @event.pages[0].condition.variable_valid = false
- end
- drg_refresh_eval_conditions(*args)
- @event.pages = pages
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update(*args)
- check_page_eval
- drg_update_eval_conditions(*args)
- end
- #--------------------------------------------------------------------------
- # * Find Event Page Meeting Conditions
- #--------------------------------------------------------------------------
- unless method_defined?(:find_proper_page)
- def find_proper_page
- @event.pages.reverse.find {|page| conditions_met?(page) }
- end
- end
- #--------------------------------------------------------------------------
- # * Determine if Event Page Conditions Are Met
- #--------------------------------------------------------------------------
- def conditions_met?(page)
- c = page.condition
- if c.switch1_valid
- return false if $game_switches[c.switch1_id] == false
- end
- if c.switch2_valid
- return false if $game_switches[c.switch2_id] == false
- end
- if c.self_switch_valid
- key = [@map_id,@event.id,c.self_switch_ch]
- return false if $game_self_switches[key] == false
- end
- if c.variable_valid
- var = page.note[/cond[-_ ]?self[-_ ]?variable/i]
- item = page.note[/cond[-_ ]?item[-_ ]?number/i]
- weapon = page.note[/cond[-_ ]?weapon[-_ ]?number/i]
- armor = page.note[/cond[-_ ]?armor[-_ ]?number/i]
- gold = page.note[/cond[-_ ]?gold/i]
- if item || weapon || armor || gold
- if item
- i = $data_items[c.variable_id]
- var = $game_party.item_number(i)
- elsif weapon
- i = $data_weapons[c.variable_id]
- var = $game_party.item_number(i) + PARTY_EQSIZE.call(RPG::Weapon,i)
- elsif armor
- i = $data_armors[c.variable_id]
- var = $game_party.item_number(i) + PARTY_EQSIZE.call(RPG::Armor,i)
- elsif gold
- var = $game_party.gold
- end
- else
- key = [@map_id,@event.id,c.variable_id]
- var &&= $drago_game_variable
- var = var ? $game_variables[key] : $game_variables[c.variable_id]
- if $xrxs_xas
- impact = c.variable_id == XAS::HIT_ID
- impact &&= c.variable_value == self.reaction_valid_attack_id
- return false unless impact
- end
- end
- return false if var < c.variable_value
- end
- if c.respond_to?(:item_valid) && c.item_valid
- item = $data_items[c.item_id]
- return false if $game_party.item_number(item) < 1
- end
- if c.respond_to?(:actor_valid) && c.actor_valid
- actor = $game_actors[c.actor_id]
- return false if $game_party.members.not.include?(actor)
- end
- if page.cond_eval_valid
- cond_page_eval.push(cond = page.cond_eval_valid.gsub("\\n","\n "))
- return false unless cond_eval_execute(cond)
- end
- return true
- end
- #--------------------------------------------------------------------------
- # * New method: cond_eval_execute
- #--------------------------------------------------------------------------
- def cond_eval_execute(command)
- eval(command)
- end
- #--------------------------------------------------------------------------
- # * New method: check_page_eval
- #--------------------------------------------------------------------------
- def check_page_eval
- if cond_page_eval.not.empty?
- command = cond_page_eval.map {|s| cond_eval_execute(s)}
- @cond_eval_result != command && [@cond_eval_result = command, refresh]
- else
- @cond_eval_result = nil
- end
- end
- end
- #==============================================================================
- # ** Game_Party
- #------------------------------------------------------------------------------
- # This class handles the party. It includes information on amount of gold
- # and items. Refer to "$game_party" for the instance of this class.
- #==============================================================================
- class Game_Party
- #--------------------------------------------------------------------------
- # ● Alias Listing
- #--------------------------------------------------------------------------
- [:gain_item,:gain_weapon,:gain_armor,:gain_gold].each do |meth|
- next unless method_defined?(:"#{meth}")
- alias_sec_method :"drg_#{meth}_event_refresh", :"#{meth}"
- #--------------------------------------------------------------------------
- # * Aliased method: gain_item
- #--------------------------------------------------------------------------
- define_method(:"#{meth}") do |*args|
- send(:"drg_#{meth}_event_refresh",*args)
- $game_map.need_refresh = true
- end
- end
- end
- #==============================================================================
- # ** Game_Actor
- #------------------------------------------------------------------------------
- # This class handles actors. It is used within the Game_Actors class
- # ($game_actors) and is also referenced from the Game_Party class ($game_party).
- #==============================================================================
- class Game_Actor
- #--------------------------------------------------------------------------
- # ● Redefined method: equips
- #--------------------------------------------------------------------------
- unless method_defined?(:equips)
- def equips
- result = []
- result << $data_weapons[@weapon_id]
- result << $data_armors[@armor1_id]
- result << $data_armors[@armor2_id]
- result << $data_armors[@armor3_id]
- result << $data_armors[@armor4_id]
- result
- end
- end
- end
- #==============================================================================
- # ** RPG::Event::Page
- #------------------------------------------------------------------------------
- #
- #==============================================================================
- class RPG::Event::Page
- #--------------------------------------------------------------------------
- # ● New method: note
- #--------------------------------------------------------------------------
- def note
- @note ||= (
- note = list.select {|l| [108,408].include?(l.code)}
- note = list.map {|l| l.parameters[0]} .join('\n')
- )
- end
- #--------------------------------------------------------------------------
- # ● New method: cond_eval_valid
- #--------------------------------------------------------------------------
- def cond_eval_valid
- @cond_eval_valid ||= $1 if note[/cond:\s*(.*);/i]
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement