IceDragon200

[IEI]Runick (0x0800C) (Lib)

Jun 24th, 2012
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 20.67 KB | None | 0 0
  1. =begin
  2.  ♥ IEI - Runick
  3.  ──────────────────────────────────────────────────────────────────────────────
  4.  • Created By    : IceDragon
  5.  • Data Created  : 24/06/2012
  6.  • Data Modified : 12/07/2012
  7.  • Version       : 0x0800C
  8.  ──────────────────────────────────────────────────────────────────────────────
  9.  ─┐ ● Requirements ┌───────────────────────────────────────────────────────────
  10.   └────────────────┘
  11.   This script is standalone.
  12.  ─┐ ● Introduction ┌───────────────────────────────────────────────────────────
  13.   └────────────────┘
  14.   Welcome to IEI - Runick.
  15.   This script replaces your regular attack command with a
  16.   Rune/Skill matches. Actually that makes no sense..
  17.   1 + 2 = 3
  18.   You merge multiple skills together to use another.
  19.   However these merged skills will use the skill cost of
  20.   all the runes together.
  21.   So you use Fire (5MP) and Slash (2MP) to use
  22.   Fire Slash, in all this costs (7MP).
  23.    
  24.  ─┐ ● Instruction Manual ┌─────────────────────────────────────────────────────
  25.   └──────────────────────┘
  26.   In order for rune skills to show in the Rune Skill Window
  27.   you need to put aside a Skill type ID, default this is 3.
  28.    
  29.  ─┐ ● Reference Manual ┌───────────────────────────────────────────────────────
  30.   └────────────────────┘
  31.   -Script Calls-
  32.     $game_party.rune_limit = new_limit
  33.       Changes the global rune limit
  34.   -Notetags-
  35.     Skill
  36.       <rune: n>
  37.         Sets the skill as n rune
  38.         NOTE: rune names are case sensitive.
  39.           fire is not the same as Fire or FIRE
  40.       <rune recipe: n,n,n>  
  41.         Using skills that have the <rune: n> tag
  42.         this skill will be used when all the runes
  43.         are present.
  44.       EG:
  45.         Skill 2 (Fire)  
  46.           <rune: fire>
  47.         Skill 22 (Fire III)  
  48.           <rune: fire>
  49.         Skill 12 (Slash)  
  50.           <rune: slash>
  51.         Skill 32 (Slash III)  
  52.           <rune: slash>
  53.         Skill 42 (Fire Slash)  
  54.           <rune recipe: fire,slash>
  55.         Skill 2 + Skill 12
  56.           Skill 42 (Fire Slash)
  57.         Skill 22 + Skill 12
  58.           Skill 42 (Fire Slash)
  59.         Skill 22 + Skill 42
  60.           Skill 42 (Fire Slash)
  61.  ──────────────────────────────────────────────────────────────────────────────
  62. =end
  63. ($imported||={})["IEI::Runick"] = 0x0800C
  64. # ╒╕ ■                                                          IEI::Runick ╒╕
  65. # └┴────────────────────────────────────────────────────────────────────────┴┘
  66. module IEI
  67.   module Runick
  68. # ─┤ ● Start Customization ├──────────────────────────────────────────────────
  69.     RUNE_STYPE_ID       = 3     # // Rune Skill Type ID
  70.     UNKNOWN_RUNE        = '???' # // Text used for unknown runes
  71.     FAIL_RUNE           = '---' # // Fail
  72.     DEFAULT_RUNE_NUMBER = 2     # // default number of 'same' runes
  73.     DEFAULT_RUNE_LIMIT  = 2     # // default max number of runes
  74.     DEFAULT_RUNE_ICON   = 184   # // Default icon index for runes
  75. # ─┤ ● End Customization ├────────────────────────────────────────────────────
  76.   end
  77. end
  78. # ╒╕ ■                                                          IEI::Runick ╒╕
  79. # └┴────────────────────────────────────────────────────────────────────────┴┘
  80. module IEI
  81.   module Runick
  82.     def self.recipe_list
  83.       @recipe_list
  84.     end
  85.     def self.skills2recipe *skills
  86.       runes = skills.collect &:rune
  87.     end
  88.     def self.sort_recipe array
  89.       array.sort
  90.     end
  91.     def self.mk_recipe_list! items
  92.       @recipe_list = mk_recipe_list_abs items unless @recipe_list
  93.     end
  94.     def self.mk_recipe_list_abs items
  95.       recipe_list = {}
  96.       pc = item = nil # // Forward Dec.
  97.       items.each do |item|
  98.         item.rune_recipes.each do |r|
  99.           recipe_list[sort_recipe(r)] = IEI.item2sym_a(item)
  100.         end
  101.       end
  102.       return recipe_list
  103.     end # // mk_recipe_list
  104.     def self.get_skill recipe
  105.       IEI.sym_a2item @recipe_list[recipe]
  106.     end
  107.     #add_recipe sort_recipe(recipe), skills
  108.   end
  109.   def self.item2sym_a item
  110.     return [item_sym(item), item ? item.id : nil]
  111.   end
  112.   def self.item_sym item
  113.     case item
  114.       when RPG::Item  ; :item
  115.       when RPG::Skill ; :skill
  116.       when RPG::Weapon; :weapon
  117.       when RPG::Armor ; :armor
  118.       else            ; :nil
  119.     end
  120.   end
  121.   def self.sym_a2item sym_a
  122.     return nil unless sym_a
  123.     sym, id = sym_a
  124.     case sym
  125.       when :item   ; $data_items[id]
  126.       when :skill  ; $data_skills[id]  # // Still not used
  127.       when :weapon ; $data_weapons[id]
  128.       when :armor  ; $data_armors[id]
  129.       else         ; nil
  130.     end
  131.   end
  132. end
  133. # ╒╕ ■                                                          DataManager ╒╕
  134. # └┴────────────────────────────────────────────────────────────────────────┴┘
  135. class << DataManager
  136.   alias :iei_rune_load_database :load_database
  137.   def load_database *args,&block
  138.     iei_rune_load_database *args,&block
  139.     IEI::Runick.mk_recipe_list! ($data_skills+$data_items).compact
  140.     #puts IEI::Runick.recipe_list
  141.   end
  142. end
  143. # ╒╕ ♥                                                      RPG::UsableItem ╒╕
  144. # └┴────────────────────────────────────────────────────────────────────────┴┘
  145. class RPG::UsableItem < RPG::BaseItem
  146.   def rune?
  147.     !rune.empty?
  148.   end
  149.   def need_rune?
  150.     !rune_recipes.empty?
  151.   end
  152.   def rune_ceil
  153.     @rune_ceil ||= (@note.match(/<rune[_ ]?(?:number|ceil):\s*(\d+)>/i)||[nil,IEI::Runick::DEFAULT_RUNE_NUMBER])[1].to_i
  154.   end
  155.   def rune
  156.     @runes ||= (@note.match(/<rune:\s*(\w+)>/i)||[nil,''])[1]
  157.   end
  158.   def rune_recipes
  159.     unless @rune_recipes
  160.       @rune_recipes = []
  161.       @note.scan(/<rune[_ ]?recipe:\s*(\w+(?:\s*,\s*\w+)*)>/i).each do |s|
  162.         @rune_recipes << s[0].scan(/\w+/)
  163.       end
  164.     end
  165.     @rune_recipes
  166.   end
  167. end
  168. # ╒╕ ♥                                                          Game_Action ╒╕
  169. # └┴────────────────────────────────────────────────────────────────────────┴┘
  170. class Game_Action
  171.   attr_accessor :runes
  172.   alias :rune_clear :clear
  173.   def clear
  174.     rune_clear
  175.     @runes = []
  176.   end
  177.   def rune?
  178.     !@runes.empty?
  179.   end
  180.   def rune_skill_stack?
  181.     @runes.size > 1 and !rune_skill
  182.   end
  183.   def rune_skill
  184.     return @runes.first if @runes.size == 1
  185.     recipe = IEI::Runick.skills2recipe *@runes
  186.     IEI::Runick.get_skill IEI::Runick.sort_recipe(recipe)
  187.   end
  188. end
  189. # ╒╕ ♥                                                         Game_Battler ╒╕
  190. # └┴────────────────────────────────────────────────────────────────────────┴┘
  191. class Game_Battler
  192.   alias :org_use_item :use_item
  193.   def use_item item
  194.     org_use_item item
  195.     act = current_action
  196.     if act.rune?
  197.       runes = act.runes
  198.       pay_rune_cost runes
  199.       set_known_rune! runes,2
  200.     end if act
  201.   end
  202.   alias :org_usable? :usable?
  203.   def usable? item
  204.     res  = org_usable? item
  205.     act  = current_action
  206.     res&&= rune_usable? act.runes if act.rune? if act
  207.     res
  208.   end
  209.   def mk_cost_stack objs
  210.     costs = objs.collect do |i|
  211.       {hp: 0, mp: skill_mp_cost(i), tp: skill_tp_cost(i)}
  212.     end
  213.     costs.inject({hp: 0, mp: 0, tp: 0}) do |main_hash,costs|
  214.       main_hash[:hp] += costs[:hp]
  215.       main_hash[:mp] += costs[:mp]
  216.       main_hash[:tp] += costs[:tp]
  217.       main_hash
  218.     end
  219.   end
  220.   def can_pay_cost_stack? hash
  221.     return false if hash[:hp] > hp
  222.     return false if hash[:mp] > mp
  223.     return false if hash[:tp] > tp
  224.     return true
  225.   end
  226.   def pay_rune_cost objs
  227.     objs.each do |i| org_use_item i end
  228.   end
  229.   def rune_usable? objs
  230.     return false unless can_pay_cost_stack? mk_cost_stack(objs)
  231.     objs.all? do |i| org_usable? i end
  232.   end
  233.   def runes_known
  234.     $game_party.runes_known
  235.   end
  236.   def rune_ceil skill
  237.     skill ? skill.rune_ceil : 0
  238.   end
  239.   #def rune_limit
  240.   #  $game_party.rune_limit
  241.   #end
  242.   def rune_limit
  243.     @rune_limit ||= IEI::Runick::DEFAULT_RUNE_LIMIT
  244.   end
  245.   attr_writer :rune_limit
  246.   def rune_limit_reached?
  247.     act = current_action
  248.     return false unless act
  249.     current_action.runes.size >= rune_limit
  250.   end
  251.   def rune_queue_usable? item
  252.     runes = current_action.runes
  253.     rune_usable? runes + [item]
  254.   end
  255.   def rune_known? runes
  256.     return false unless runes
  257.     set_known_rune runes,2 if runes.size == 1
  258.     #runes_known.push item.id unless runes_known.include? item.id
  259.     (sym_a = runes.collect do |r| IEI.item2sym_a r end).sort!
  260.     runes_known[sym_a]
  261.   end
  262.   def set_known_rune runes,n
  263.     (sym_a = runes.collect do |r| IEI.item2sym_a r end).sort!
  264.     set_known_rune! runes,n unless runes_known[sym_a]
  265.   end
  266.   def set_known_rune! runes,n
  267.     (sym_a = runes.collect do |r| IEI.item2sym_a r end).sort!
  268.     runes_known[sym_a] = n
  269.   end
  270. end
  271. # ╒╕ ♥                                                           Game_Actor ╒╕
  272. # └┴────────────────────────────────────────────────────────────────────────┴┘
  273. class Game_Actor
  274.   def prior_command
  275.     return false if @action_input_index <= 0
  276.     current_action.clear if current_action
  277.     @action_input_index -= 1
  278.     return true
  279.   end
  280. end  
  281. # ╒╕ ♥                                                           Game_Party ╒╕
  282. # └┴────────────────────────────────────────────────────────────────────────┴┘
  283. class Game_Party
  284.   attr_writer :rune_limit, :runes_known
  285.   def runes_known
  286.     @runes_known ||= {}
  287.   end
  288.   def rune_limit
  289.     @rune_limit ||= IEI::Runick::DEFAULT_RUNE_LIMIT
  290.   end
  291. end
  292. # ╒╕ ♥                                                     Window_SkillRune ╒╕
  293. # └┴────────────────────────────────────────────────────────────────────────┴┘
  294. class Window_Runes < Window_SkillList
  295.   attr_reader :actor
  296.   NULL_SKILL = RPG::Skill.new
  297.   NULL_SKILL.id = -1
  298.   NULL_SKILL.icon_index = 187
  299.   NULL_SKILL.name = '-DONE-'
  300.   def done_skill_index
  301.     @data.index NULL_SKILL
  302.   end
  303.   def make_item_list
  304.     super
  305.     @data.unshift NULL_SKILL
  306.     #@data.push NULL_SKILL
  307.   end
  308.   def refresh
  309.     unless @actor
  310.       self.contents.clear
  311.     else
  312.       super
  313.     end
  314.     self
  315.   end
  316.   def include? skill
  317.     skill and skill.rune? and super skill
  318.   end
  319.   def enable? item
  320.     return false unless @actor
  321.     if item and item.id == -1
  322.       return true if @actor.current_action.rune_skill_stack?
  323.       return true if @actor.current_action.rune? and rune_skill
  324.       return false
  325.     end
  326.     return false unless @actor.rune_queue_usable? item
  327.     return false if @actor.rune_limit_reached?
  328.     return false if @actor.current_action.runes.count(item) >= @actor.rune_ceil(item)
  329.     super item
  330.   end
  331.   def rune_skill
  332.     return nil unless @actor
  333.     act = @actor.current_action
  334.     #return nil unless act
  335.     act.rune_skill
  336.   end
  337.   def select_done!
  338.     select done_skill_index  
  339.   end
  340. end
  341. # ╒╕ ♥                                                     Window_RuneStack ╒╕
  342. # └┴────────────────────────────────────────────────────────────────────────┴┘
  343. class Window_RuneStack < Window_Selectable
  344.   def initialize x,y,w,h
  345.     @runes = []
  346.     super
  347.   end
  348.   def contents_height
  349.     self.height - (self.padding * 2)
  350.   end
  351.   def update_padding_bottom
  352.   end
  353.   attr_reader :rune_window
  354.   def rune_window= win
  355.     @rune_window = win
  356.     refresh
  357.     self
  358.   end
  359.   def col_max
  360.     item_max
  361.   end
  362.   def spacing
  363.     2
  364.   end
  365.   def item_max
  366.     [$game_party.rune_limit,1].max
  367.   end
  368.   def item_width
  369.     24
  370.   end
  371.   def item_height
  372.     24
  373.   end
  374.   def actor
  375.     @rune_window.actor
  376.   end
  377.   def skill
  378.     @rune_window.rune_skill
  379.   end
  380.   def draw_fraction x,y,width,height,num,den,align=1
  381.     h = height / 2.0
  382.     size = contents.font.size
  383.     contents.font.size = [h,16].max
  384.     contents.fill_rect x,y+h,width,1,contents.font.color
  385.     draw_text x,y,width,h,num,align
  386.     draw_text x,y+h,width,h,den,align
  387.     contents.font.size = size
  388.   end
  389.   def draw_rune_name item,x,y,enabled=true
  390.     change_color normal_color
  391.     case @rune_window.actor.rune_known? @rune_window.actor.current_action.runes
  392.     when 0,nil # // none
  393.       change_color normal_color,enabled
  394.       draw_text x+24,y,196,line_height,IEI::Runick::UNKNOWN_RUNE
  395.     when 1 # // failed
  396.       change_color normal_color#,enabled
  397.       draw_text x+24,y,196,line_height,IEI::Runick::FAIL_RUNE
  398.     when 2 # // sucess
  399.       draw_item_name item,x,y,enabled
  400.     end
  401.     change_color normal_color
  402.   end
  403.   def refresh
  404.     unless actor
  405.       self.contents.clear
  406.       return
  407.     end
  408.     @runes = actor.current_action.runes.dup
  409.     super
  410.     skl = skill
  411.     wd = 196
  412.     h = contents.height
  413.     en = actor.org_usable?(skl)||!skl
  414.     draw_rune_name skl,self.width-wd,(h-line_height)/2,en
  415.     cost_stack = actor.mk_cost_stack @runes
  416.     wd += 32 + spacing
  417.     draw_fraction self.width-wd,0,32,h,cost_stack[:tp],(actor.tp_rate * 100).to_i # // Tp
  418.     wd += 34 + spacing
  419.     draw_fraction self.width-wd,0,32,h,cost_stack[:mp],actor.mp # // Mp
  420.   end
  421.   def item_rect index
  422.     rect = super
  423.     rect.x += (contents.width-266-item_max*rect.width) / 2
  424.     rect
  425.   end
  426.   def draw_item index
  427.     rect = item_rect index
  428.     rect.y += (contents.height - rect.height) / 2.0
  429.     item = @runes[index]    
  430.     icon_index = item ? item.icon_index : IEI::Runick::DEFAULT_RUNE_ICON
  431.     draw_icon icon_index,rect.x,rect.y
  432.   end
  433.   def update
  434.     super
  435.     if @rune_window.actor
  436.       if n = @rune_window.actor.current_action
  437.         refresh if @runes != n.runes
  438.       end
  439.     end
  440.   end
  441. end
  442. # ╒╕ ♥                                                         Scene_Battle ╒╕
  443. # └┴────────────────────────────────────────────────────────────────────────┴┘
  444. class Scene_Battle
  445.   alias :iei_caw_rune :create_all_windows
  446.   def create_all_windows
  447.     iei_caw_rune
  448.     create_rune_window
  449.   end
  450.   def create_rune_window
  451.     y = @help_window.y + @help_window.height
  452.     rsw_h = 64
  453.     h = Graphics.height - @help_window.height - @actor_window.height - rsw_h
  454.     @rune_window = Window_Runes.new @help_window.x, y, @help_window.width, h
  455.     @rune_window.set_handler :ok    , method(:on_rune_ok)
  456.     @rune_window.set_handler :cancel, method(:on_rune_cancel)
  457.     @rune_window.help_window = @help_window
  458.     @rune_window.stype_id    = IEI::Runick::RUNE_STYPE_ID
  459.     @rune_window.select 0
  460.     y = @rune_window.y + @rune_window.height
  461.     @rune_stack_window = Window_RuneStack.new @rune_window.x,y,@rune_window.width,rsw_h
  462.     @rune_stack_window.rune_window = @rune_window
  463.     @rune_window.deactivate.hide
  464.     @rune_stack_window.deactivate.hide
  465.   end
  466.   alias :iei_cacw_rune :create_actor_command_window
  467.   def create_actor_command_window
  468.     iei_cacw_rune
  469.     @actor_command_window.set_handler :attack, method(:command_rune)
  470.   end
  471.   alias :iei_rune_prior_command :prior_command
  472.   def prior_command
  473.     iei_rune_prior_command
  474.     act = BattleManager.actor
  475.     act.current_action.clear if act && act.current_action
  476.   end
  477.   def command_rune
  478.     start_rune_entry
  479.   end
  480.   def start_rune_entry
  481.     @rune_window.actor = BattleManager.actor
  482.     @help_window.show
  483.     @rune_window.refresh.show.activate
  484.     @rune_stack_window.refresh
  485.     @rune_stack_window.show
  486.    
  487.   end
  488.   def on_rune_ok
  489.     item  = @rune_window.item
  490.     actor = BattleManager.actor
  491.     act   = actor.current_action
  492.     if item.id == -1
  493.       runes = act.runes
  494.       if act.rune_skill_stack?
  495.         actor.clear_actions
  496.         runes[0...runes.size].each do |skill|
  497.           nact = Game_Action.new actor
  498.           nact.set_skill skill.id
  499.           actor.actions.push nact
  500.         end
  501.         until actor.next_command ; end
  502.       else
  503.         skill = @rune_window.rune_skill
  504.         actor.clear_actions
  505.         nact = Game_Action.new actor
  506.         nact.set_skill skill.id
  507.         nact.runes = runes if runes.size > 1
  508.         actor.actions.push nact
  509.       end
  510.       end_rune_selection      
  511.       @skill = actor.current_action.item
  512.       skill_target_selection
  513.       actor.actions.each do |a| a.target_index = actor.current_action.target_index end
  514.       actor.set_known_rune runes, 1
  515.       #end
  516.       #next_command
  517.     else
  518.       BattleManager.actor.current_action.runes << item
  519.       @rune_window.select_done! if actor.rune_limit_reached?
  520.       @rune_window.refresh
  521.       @rune_window.activate
  522.     end
  523.   end
  524.   def skill_target_selection
  525.     BattleManager.actor.last_skill.object = @skill
  526.     if !@skill.need_selection?
  527.       next_command
  528.     elsif @skill.for_opponent?
  529.       select_enemy_selection
  530.     else
  531.       select_actor_selection
  532.     end
  533.   end
  534.   def on_rune_cancel
  535.     runes = BattleManager.actor.current_action.runes
  536.     if runes.empty?
  537.       end_rune_selection
  538.       @actor_command_window.show.activate
  539.     else
  540.       runes.clear
  541.       @rune_window.refresh
  542.       @rune_window.activate
  543.     end
  544.   end
  545.   #alias :iei_rune_on_skill_cancel :on_skill_cancel
  546.   #def on_skill_cancel
  547.   #  iei_rune_on_skill_cancel
  548.   #  BattleManager.actor.current_action.runes.clear
  549.   #end
  550.   def end_rune_selection
  551.     @rune_stack_window.hide
  552.     @rune_window.hide
  553.     #@rune_stack_window = nil
  554.     #@rune_window.help_window = nil
  555.     #@rune_window.dispose
  556.     #@rune_window = nil
  557.     @help_window.hide
  558.   end
  559.   def on_actor_cancel
  560.     @actor_window.hide
  561.     case @actor_command_window.current_symbol
  562.     when :attack
  563.       start_rune_entry  
  564.     when :skill
  565.       @skill_window.activate
  566.     when :item
  567.       @item_window.activate
  568.     end
  569.   end
  570.   def on_enemy_cancel
  571.     @enemy_window.hide
  572.     case @actor_command_window.current_symbol
  573.     when :attack
  574.       start_rune_entry
  575.     when :skill
  576.       @skill_window.activate
  577.     when :item
  578.       @item_window.activate
  579.     end
  580.   end
  581. end
  582. # ┌┬────────────────────────────────────────────────────────────────────────┬┐
  583. # ╘╛ ● End of File ●                                                        ╘╛
Advertisement
Add Comment
Please, Sign In to add comment