Advertisement
LiTTleDRAgo

[RGSS/2/3] Drago - Custom Page Condition

Sep 6th, 2014
617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.05 KB | None | 0 0
  1. #==============================================================================
  2. # ** Drago - Custom Page Condition
  3. # Version : 1.00
  4. # Contact : littledrago.blogspot.com / forum.chaos-project.com
  5. #==============================================================================
  6. ($imported ||= {})[:drg_custom_page_condition] = 1.00
  7.  
  8. core = "This script needs Drago - Core Engine ver 1.47 or above"
  9. ($imported[:drg_core_engine] || 0) >= 1.47 || raise(core)
  10.  
  11. #==============================================================================
  12. # ** Game_Event
  13. #------------------------------------------------------------------------------
  14. #  This class deals with events. It handles functions including event page
  15. #  switching via condition determinants, and running parallel process events.
  16. #  It's used within the Game_Map class.
  17. #==============================================================================
  18.  
  19. class Game_Event
  20.   #--------------------------------------------------------------------------
  21.   # * Constant
  22.   #--------------------------------------------------------------------------
  23.   PARTY_EQSIZE = carrot do |t,i|
  24.     $game_party.members.map do |a|
  25.       a.equips.select {|e| e.is_a?(t) && e.id == i.id }.size
  26.     end.sum
  27.   end
  28.   #--------------------------------------------------------------------------
  29.   # * Public Instance Variables
  30.   #--------------------------------------------------------------------------
  31.   attr_sec_reader :cond_page_eval, 'Array.new'
  32.   #--------------------------------------------------------------------------
  33.   # * Alias Listing
  34.   #--------------------------------------------------------------------------
  35.   alias_sec_method :drg_refresh_eval_conditions, :refresh
  36.   alias_sec_method :drg_update_eval_conditions,  :update
  37.   #--------------------------------------------------------------------------
  38.   # * Define Secondary Listing
  39.   #--------------------------------------------------------------------------
  40.   define_sec_method(:refresh_trigger_conditions) { find_proper_page }
  41.   #--------------------------------------------------------------------------
  42.   # * Refresh
  43.   #--------------------------------------------------------------------------
  44.   def refresh(*args)
  45.     cond_page_eval.clear
  46.     new_page = @erased ? nil : refresh_trigger_conditions
  47.     pages = @event.pages
  48.     if new_page != @page
  49.       @event.pages = [new_page ? new_page.clone : nil]
  50.       @event.pages[0] && @event.pages[0].condition.variable_valid = false
  51.     end
  52.     drg_refresh_eval_conditions(*args)
  53.     @event.pages = pages
  54.   end
  55.   #--------------------------------------------------------------------------
  56.   # * Frame Update
  57.   #--------------------------------------------------------------------------
  58.   def update(*args)
  59.     check_page_eval
  60.     drg_update_eval_conditions(*args)
  61.   end
  62.   #--------------------------------------------------------------------------
  63.   # * Find Event Page Meeting Conditions
  64.   #--------------------------------------------------------------------------
  65.   unless method_defined?(:find_proper_page)
  66.     def find_proper_page
  67.       @event.pages.reverse.find {|page| conditions_met?(page) }
  68.     end
  69.   end
  70.   #--------------------------------------------------------------------------
  71.   # * Determine if Event Page Conditions Are Met
  72.   #--------------------------------------------------------------------------
  73.   def conditions_met?(page)
  74.     c = page.condition
  75.     if c.switch1_valid
  76.       return false if $game_switches[c.switch1_id] == false
  77.     end
  78.     if c.switch2_valid
  79.       return false if $game_switches[c.switch2_id] == false
  80.     end
  81.     if c.self_switch_valid
  82.       key = [@map_id,@event.id,c.self_switch_ch]
  83.       return false if $game_self_switches[key] == false
  84.     end
  85.     if c.variable_valid
  86.       var    = page.note[/cond[-_ ]?self[-_ ]?variable/i]
  87.       item   = page.note[/cond[-_ ]?item[-_ ]?number/i]
  88.       weapon = page.note[/cond[-_ ]?weapon[-_ ]?number/i]
  89.       armor  = page.note[/cond[-_ ]?armor[-_ ]?number/i]
  90.       gold   = page.note[/cond[-_ ]?gold/i]
  91.       if item || weapon || armor || gold
  92.         if item
  93.           i = $data_items[c.variable_id]
  94.           var  = $game_party.item_number(i)
  95.         elsif weapon
  96.           i = $data_weapons[c.variable_id]
  97.           var = $game_party.item_number(i) + PARTY_EQSIZE.call(RPG::Weapon,i)
  98.         elsif armor
  99.           i = $data_armors[c.variable_id]
  100.           var = $game_party.item_number(i) + PARTY_EQSIZE.call(RPG::Armor,i)
  101.         elsif gold
  102.           var = $game_party.gold
  103.         end
  104.       else
  105.         key = [@map_id,@event.id,c.variable_id]
  106.         var &&= $drago_game_variable
  107.         var = var ? $game_variables[key] : $game_variables[c.variable_id]
  108.         if $xrxs_xas
  109.           impact = c.variable_id == XAS::HIT_ID
  110.           impact &&= c.variable_value == self.reaction_valid_attack_id
  111.           return false unless impact
  112.         end
  113.       end
  114.       return false if var < c.variable_value
  115.     end
  116.     if c.respond_to?(:item_valid) && c.item_valid
  117.       item = $data_items[c.item_id]
  118.       return false if $game_party.item_number(item) < 1
  119.     end
  120.     if c.respond_to?(:actor_valid) && c.actor_valid
  121.       actor = $game_actors[c.actor_id]
  122.       return false if $game_party.members.not.include?(actor)
  123.     end
  124.     if page.cond_eval_valid
  125.       cond_page_eval.push(cond = page.cond_eval_valid.gsub("\\n","\n "))
  126.       return false unless cond_eval_execute(cond)
  127.     end
  128.     return true
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   # * New method: cond_eval_execute
  132.   #--------------------------------------------------------------------------
  133.   def cond_eval_execute(command)
  134.     eval(command)
  135.   end
  136.   #--------------------------------------------------------------------------
  137.   # * New method: check_page_eval
  138.   #--------------------------------------------------------------------------
  139.   def check_page_eval
  140.     if cond_page_eval.not.empty?
  141.       command = cond_page_eval.map {|s| cond_eval_execute(s)}
  142.       @cond_eval_result != command && [@cond_eval_result = command, refresh]
  143.     else
  144.       @cond_eval_result = nil
  145.     end
  146.   end
  147. end
  148.  
  149. #==============================================================================
  150. # ** Game_Party
  151. #------------------------------------------------------------------------------
  152. #  This class handles the party. It includes information on amount of gold
  153. #  and items. Refer to "$game_party" for the instance of this class.
  154. #==============================================================================
  155. class Game_Party
  156.   #--------------------------------------------------------------------------
  157.   # ● Alias Listing
  158.   #--------------------------------------------------------------------------
  159.   [:gain_item,:gain_weapon,:gain_armor,:gain_gold].each do |meth|
  160.     next unless method_defined?(:"#{meth}")
  161.     alias_sec_method :"drg_#{meth}_event_refresh", :"#{meth}"
  162.     #--------------------------------------------------------------------------
  163.     # * Aliased method: gain_item
  164.     #--------------------------------------------------------------------------
  165.     define_method(:"#{meth}") do |*args|
  166.       send(:"drg_#{meth}_event_refresh",*args)
  167.       $game_map.need_refresh = true
  168.     end
  169.   end
  170. end
  171.  
  172. #==============================================================================
  173. # ** Game_Actor
  174. #------------------------------------------------------------------------------
  175. #  This class handles actors. It is used within the Game_Actors class
  176. # ($game_actors) and is also referenced from the Game_Party class ($game_party).
  177. #==============================================================================
  178. class Game_Actor
  179.   #--------------------------------------------------------------------------
  180.   # ● Redefined method: equips
  181.   #--------------------------------------------------------------------------
  182.   unless method_defined?(:equips)
  183.     def equips
  184.       result = []
  185.       result << $data_weapons[@weapon_id]
  186.       result << $data_armors[@armor1_id]
  187.       result << $data_armors[@armor2_id]
  188.       result << $data_armors[@armor3_id]
  189.       result << $data_armors[@armor4_id]
  190.       result
  191.     end
  192.   end
  193. end
  194.  
  195. #==============================================================================
  196. # ** RPG::Event::Page
  197. #------------------------------------------------------------------------------
  198. #  
  199. #==============================================================================
  200. class RPG::Event::Page
  201.   #--------------------------------------------------------------------------
  202.   # ● New method: note
  203.   #--------------------------------------------------------------------------
  204.   def note
  205.     @note ||= (
  206.       note = list.select {|l| [108,408].include?(l.code)}
  207.       note = list.map {|l| l.parameters[0]} .join('\n')
  208.     )
  209.   end
  210.   #--------------------------------------------------------------------------
  211.   # ● New method: cond_eval_valid
  212.   #--------------------------------------------------------------------------
  213.   def cond_eval_valid
  214.     @cond_eval_valid ||= $1 if note[/cond:\s*(.*);/i]
  215.   end
  216. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement