Advertisement
Zetu

Z02 v1.04

Apr 17th, 2012
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 16.21 KB | None | 0 0
  1.                             #======================#
  2.                             #  Z-Systems by: Zetu  #
  3. #===========================#======================#===========================#
  4. #                 *  *  *  Z02 AMPX Ace Version v1.04  *  *  *                 #
  5. #=#==========================================================================#=#
  6.   #  You may need slight scripting knowledge of working with arrays (but     #
  7.   #  not a whole lot!).                                                      #
  8.   #--------------------------------------------------------------------------#
  9.   #   * * Anything in "< >" means replace with the described contents. * *   #
  10.   #  REQUIRED PARAMETERS (Any resource without it will cause an error)       #
  11.   #    :name, <name of resource>                                             #
  12.   #    :abbv, <1 or 2 character abbv. of resource>                           #
  13.   #    :color, <color 1>, <color 2>                                          #
  14.   #        * These color attributes are indexes of the window skin           #
  15.   #  OPTIONAL PARAMETERS                                                     #
  16.   #  Resource Regen for each turn:                                           #
  17.   #    :regen, <type>, <base>                                                #
  18.   #        type can be :mmp, :atk, :def, :mat, :agi, :set                    #
  19.   #        base is number multiplied by type (:set is considered 1)          #
  20.   #  Resource Regen on Damage                                                #
  21.   #    :regendmg, <type>, <base>                                             #
  22.   #        type can be :damage, :mmp, :set, :percentdmg                      #
  23.   #        base in number multipled by type (:set is considered 1)           #
  24.   #        (:percentdmg is ratio of mmp and damage)                          #
  25.   #    :regenelemental, <element_id>, <type>, <base>                         #
  26.   #        same as :regendmg, except on elemental damage (of                 #
  27.   #        element_ids) (may place more than 1 id)                           #
  28.   #  Resource Regen on Inflicting Damage                                     #
  29.   #    :regenoffdmg, <type>, <base>                                          #
  30.   #        type can be :damage, :mmp, :set, :percentdmg                      #
  31.   #        base in number multipled by type (:set is considered 1)           #
  32.   #        (:percentdmg is ratio of mmp and damage)                          #
  33.   #  Resource Change Out of Battle:                                          #
  34.   #    :depleteoob     (Set to 0)                                            #
  35.   #    :regenoob       (Set to Max)                                          #
  36.   #  Max Value                                                               #
  37.   #    :max, <value>                                                         #
  38.   #  Resource Inversion                                                      #
  39.   #    :invert   #=// NOT INCLUDED IN THIS VERSION                           #
  40.   #        this allows the resource to Add instead of Subtract for its cost  #
  41.   #        and disallows skill use if cost will exceed the max resource.     #
  42.   #--------------------------------------------------------------------------#
  43.   #  NOTE :: Case Sensitivity Applies to Resource Names in these tags        #
  44.   #    * I apologize and will fix this next patch *                          #
  45.   #  REGEXP!                                                                 #
  46.   #  <Class/Actor Note>                                                      #
  47.   #    <AMPX: X>  #=> X = Name of Resource                                   #
  48.   #      Adds the Resource to Actor.  If no resources exisit, will give      #
  49.   #      actor DEF_RES as only resource.                                     #
  50.   #  <Skill Note>                                                            #
  51.   #    <AMPX DAMAGE: X>  #=> X = Name of Resource                            #
  52.   #      When skill does MP damage, it will damage all resources with this   #
  53.   #      tag. Will damage DEF_RES if tag does not exist.  Also allowed in    #
  54.   #      Items.  (This tag also is used for healing)                         #
  55.   #    <AMPX COST: X *Y>  #=> X = Name of Resource; *Y = Amount (Optional)   #
  56.   #      Add cost to skill.  If not used, will cost default amount to first  #
  57.   #      resource defined.  If *Y is not defined, will default in the        #
  58.   #      default skill cost.                                                 #
  59.   #--------------------------------------------------------------------------#
  60.   #  Getting Values of Resources (ADVANCED)                                  #
  61.   #  <Battler>.resource(NAME) #=> <Game_Resource>                            #
  62.   #  <Battler>.resources #=> <Game_Resource[]> Array                         #
  63.   #  
  64.   #==========================================================================#
  65. module Z02
  66.  
  67.   RESOURCES = [[
  68.       :regen, :mmp, 0.05,
  69.       :name, "Mana",
  70.       :abbv, "M",
  71.       :color, 23, 22
  72.     ],[
  73.       :deplete,
  74.       :regendmg, :percentdmg, 120,
  75.       :regen, :set, -5,
  76.       :max, 100,
  77.       :name, "Rage",
  78.       :abbv, "R",
  79.       :color, 10, 2
  80.     ],[
  81.       :replenish,
  82.       :regen, :set, 20,
  83.       :max, 100,
  84.       :name, "Energy",
  85.       :abbv, "E",
  86.       :color, 6, 14
  87.     ],[
  88.       :replenish,
  89.       :regen, :set, 30,
  90.       :regendmg, :percentdmg, -150,
  91.       :max, 100,
  92.       :name, "Focus",
  93.       :abbv, "F",
  94.       :color, 3, 11
  95.     ],[
  96.       :invert,
  97.       :deplete,
  98.       :regenelemental, 3, :percent, 80,
  99.       :regenelemental, 4, :percent, -120,
  100.       :regenelemental, 6, :percent, -120,
  101.       :regen, :set, -30,
  102.       :max, 150,
  103.       :name, "Heat",
  104.       :abbv, "H",
  105.       :color, 2, 10
  106.     ]
  107.   ]
  108.  
  109.   DEF_RES = "Mana"
  110.  
  111. #========#======================#====#================================#========#
  112. #--------#                      #----# DO NOT EDIT PAST THIS POINT!!! #--------#
  113. #--------# End of Customization #----# Editing will cause death by    #--------#
  114. #--------#                      #----# brain asplosions.              #--------#
  115. #========#======================#====#================================#========#
  116.   module REGEXP
  117.     USED_RESOURCES = /<AMPX[:]*\s*(\w+)>/i
  118.     SCOST_WOVALUE  = /<AMPX\s*COST[:]*\s*(\w+)>/i
  119.     SCOST_WVALUE   = /<AMPX\s*COST[:]*\s*(\w+)\s*(\d+)>/i
  120.     DAMAGE_TARGET  = /<AMPX\s*DAMAGE[:]*\s*(\w+)>/i
  121.   end
  122. end
  123.  
  124. ($imported||={})[:z02]=true
  125.  
  126. class Data_Resource
  127.   attr_reader :params, :regenelemental
  128.  
  129.   def initialize(index)
  130.     array=Z02::RESOURCES[index]
  131.     @params = {}
  132.     @params[:regenelemental] = {}
  133.     i=0
  134.     while (i < array.size)
  135.       case (symbol = array[i])
  136.       when :regenelemental
  137.         @params[symbol][array[i+=1]] = [array[i+=1], array[i+=1]]
  138.       when :invert, :deplete, :replenish
  139.         @params[symbol] = true
  140.       when :abbv, :name, :max
  141.         @params[symbol] = [array[i+=1]]
  142.       when :regendmg, :regen, :color, :regenoffdmg
  143.         @params[symbol] = [array[i+=1], array[i+=1]]
  144.       else
  145.         puts "Unusable symbol! ##{symbol}"
  146.       end
  147.       i+=1
  148.     end
  149.     $def_res_i = index if params[:name][0].upcase == Z02::DEF_RES
  150.   end
  151.  
  152. end
  153.  
  154. $data_resources = (0...Z02::RESOURCES.size).map{|i| Data_Resource.new(i)}
  155. $def_res_i = 0
  156.  
  157. class Game_Resources
  158.   attr_reader :battler
  159.  
  160.   class Resource #==============================================================
  161.     attr_reader :value, :index
  162.    
  163.     def initialize(name, list)
  164.       $data_resources.each_with_index do |data_resource,i|
  165.         if data_resource.params[:name][0].upcase == name.upcase
  166.           @name  = data_resource.params[:name][0]
  167.           @index = i
  168.           break
  169.         end
  170.       end
  171.       @list = list
  172.       @value = max
  173.       replenish
  174.     end
  175.    
  176.     def battler
  177.       @list.battler
  178.     end
  179.    
  180.     def value=(new_value)
  181.       @value = [[new_value, 0].max, max].min
  182.     end
  183.    
  184.     def max
  185.       begin
  186.         return params[:max][0]
  187.       rescue
  188.         return battler.mmp
  189.       end
  190.     end
  191.    
  192.     def replenish
  193.       if params[:replenish]
  194.         self.value = max
  195.       elsif params[:deplete]
  196.         self.value = 0
  197.       end
  198.     end
  199.    
  200.     def params
  201.       return $data_resources[@index].params
  202.     end
  203.    
  204.     def rate
  205.       value.to_f / max
  206.     end
  207.    
  208.     def include?(symbol)
  209.       !params[symbol].nil?
  210.     end
  211.    
  212.   end #==//==END class Resource=================================================
  213.  
  214.   def initialize(battler)
  215.     @battler = battler
  216.     @resources = []
  217.     all_notes.scan(Z02::REGEXP::USED_RESOURCES) do |name|
  218.       @resources << Resource.new(name[0], self)
  219.     end
  220.     @resources << Resource.new(Z02::DEF_RES, self) if @resources.empty?
  221.   end
  222.  
  223.   def [](value)
  224.     return @resources[value] if value.is_a? Integer
  225.     return resource_of(value) if value.is_a? String
  226.   end
  227.  
  228.   def size
  229.     @resources.size
  230.   end
  231.  
  232.   def resource_of(value)
  233.     if value.is_a? String
  234.       @resources.each do |resource|
  235.         return resource if resource.name.upcase == string.upcase
  236.       end
  237.     else
  238.       @resources.each do |resource|
  239.         return resource if resource.index == value
  240.       end
  241.     end
  242.     return nil
  243.   end
  244.  
  245.   def all_notes
  246.     if @battler.actor?
  247.       return @battler.class.note + "\n" + @battler.actor.note
  248.     else
  249.       return @battler.enemy.note
  250.     end
  251.   end
  252.  
  253.   def first_index
  254.     @resources[0].index
  255.   end
  256.    
  257.   def each
  258.     @resources
  259.   end
  260.  
  261. end
  262.  
  263. class Window_Base < Window
  264.   #--------------------------------------------------------------------------
  265.   # * New method: draw_actor_ampx
  266.   #--------------------------------------------------------------------------
  267.   def draw_actor_ampx(resource, x, y, width)
  268.     color1, color2 = resource.params[:color]
  269.     draw_gauge(x, y, width, resource.rate,
  270.         text_color(color1), text_color(color2))
  271.     change_color(text_color(color2))
  272.     draw_text(x, y, 30, line_height, resource.params[:abbv][0])
  273.     draw_current_and_max_values(x, y, width, resource.value, resource.max,
  274.       mp_color(resource.battler), normal_color)
  275.   end
  276.   #--------------------------------------------------------------------------
  277.   # * Overwrite method: draw_actor_mp
  278.   #--------------------------------------------------------------------------
  279.   def draw_actor_mp(actor, x, y, width=124)
  280.       if actor.resources.nil?
  281.         actor.setup(actor.id)
  282.       end
  283.     width /= actor.resources.size
  284.     offset = width
  285.     if actor.resources.size != 1
  286.       offset += 2
  287.       width -= 1
  288.     end
  289.     for i in 0...actor.resources.size
  290.       draw_actor_ampx(actor.resources[i], x+offset*i, y, width)
  291.     end
  292.   end
  293.  
  294. end
  295.  
  296. class Window_SkillList < Window_Selectable
  297.   #--------------------------------------------------------------------------
  298.   # * Alias method: draw_skill_cost
  299.   #--------------------------------------------------------------------------
  300.   alias :z02dsc :draw_skill_cost
  301.   def draw_skill_cost(rect, skill)
  302.     if @actor.skill_tp_cost(skill) > 0
  303.       z02dsc(rect, skill)
  304.     elsif @actor.skill_mp_cost(skill) > 0
  305.       skill.skill_cost(@actor).each do |index, value|
  306.         next if (resource = @actor.resources.resource_of(index)).nil?
  307.         next if value <= 0
  308.         change_color(text_color(resource.params[:color][0]),
  309.           @actor.skill_cost_payable?(skill))
  310.         draw_text(rect, value, 2)
  311.         rect.width -= 32
  312.       end
  313.     end
  314.   end
  315.  
  316. end
  317.  
  318. class Game_BattlerBase
  319.  
  320.   def skill_cost_payable?(skill)
  321.     tp >= skill_tp_cost(skill) && ampx_skill_cost_payable?(skill)
  322.   end
  323.  
  324.   def pay_skill_cost(skill)
  325.     ampx_pay_skill_cost(skill)
  326.     self.tp -= skill_tp_cost(skill)
  327.   end
  328.  
  329.   def ampx_skill_cost_payable?(skill)
  330.     puts skill.skill_cost(self)
  331.     skill.skill_cost(self).each do |index, value|
  332.       return false if (resource = @resources.resource_of(index)).nil?
  333.       return false if resource.value < value
  334.     end
  335.     return true
  336.   end
  337.  
  338.   def ampx_pay_skill_cost(skill)
  339.     skill.skill_cost(self).each do |index, value|
  340.       next if (resource = @resources.resource_of(index)).nil?
  341.       resource.value -= value
  342.     end
  343.   end
  344.  
  345.   def resource_obj(item)
  346.     item.note.scan(Z02::REGEXP::DAMAGE_TARGET) do |name|
  347.       return resource unless (resource = @resources.resource_of(name[0])).nil?
  348.     end
  349.   end
  350.  
  351. end
  352.  
  353. class Game_Battler < Game_BattlerBase
  354.  
  355.  
  356.  
  357.   alias :z02ote :on_turn_end
  358.   def on_turn_end
  359.     z02ote
  360.     apply_regen
  361.   end
  362.  
  363.   alias :z02ia :item_apply
  364.   def item_apply(user, item)
  365.     z02ia(user, item)
  366.     if @result.hit?
  367.       unless item.damage.none?
  368.         ampx_ondamage(user, item.damage.element_id)
  369.         resource = resource_obj(item)
  370.         unless resource.nil?
  371.           resource.value -= @result.mp_damage
  372.           ####user.mp += @result.mp_drain#### NEED TO ADD DRAIN
  373.         end
  374.       end
  375.     end
  376.   end
  377.  
  378.   def ampx_ondamage(user, element_id)
  379.     return if @result.hp_damage==0
  380.     @resources.each do |resource|
  381.       apply_damage_regen(@result.hp_damage, element_id)
  382.     end
  383.     @resources.each do |resource|
  384.       user.apply_offdamage_regen(@result.hp_damage)
  385.     end
  386.   end
  387.  
  388.   def apply_regen
  389.     return if @actor.dead?
  390.     @resources.each do |resource|
  391.       next unless resource.include? :regen
  392.       type, base = resource.params[:regen]
  393.       case type
  394.       when :mmp;   base *= max
  395.       when :atk;   base *= @actor.atk
  396.       when :def;   base *= @actor.def
  397.       when :spi;   base *= @actor.spi
  398.       when :agi;   base *= @actor.agi
  399.       end
  400.       self.value += base.to_i
  401.     end
  402.   end
  403.  
  404.   def apply_damage_regen(amount, element_id=0)
  405.     return if @actor.dead?
  406.     @resources.each do |resource|
  407.       next unless resource.include? :regendmg
  408.       type, base = resource.params[:regendmg]
  409.       case type
  410.       when :mmp;     base *= max
  411.       when :damage;  base *= damage
  412.       when :percent; base *= damage.to_f/@actor.mhp
  413.       end
  414.       self.value += base.to_i
  415.       next if (array=resource.params[:regenelemental][element_id]).nil?
  416.       type, base = array
  417.       case type
  418.       when :mmp;     base *= max
  419.       when :damage;  base *= damage
  420.       when :percent; base *= damage.to_f/@actor.mhp
  421.       end
  422.       self.value += base.to_i
  423.     end
  424.   end
  425.  
  426.   def apply_offdamage_regen(amount)
  427.     return if @actor.dead?
  428.     @resources.each do |resource|
  429.       next unless resource.include? :regenoffdmg
  430.       type, base = resource.params[:regenoffdmg]
  431.       case type
  432.       when :mmp;     base *= max
  433.       when :damage;  base *= damage
  434.       when :percent; base *= damage.to_f/@actor.mhp
  435.       end
  436.     end
  437.   end
  438.  
  439. end
  440.  
  441. class Game_Actor < Game_Battler
  442.   attr_reader :resources
  443.  
  444.   alias :z02s :setup
  445.   def setup(actor_id)
  446.     z02s actor_id
  447.     @resources = Game_Resources.new(self)
  448.   end
  449.  
  450. end
  451.  
  452. class Game_Enemy
  453.   attr_reader :resources
  454.  
  455.   alias :z02i :initialize
  456.   def initialize(index, enemy_id)
  457.     z02i index, enemy_id
  458.     @resources = Game_Resources.new(self)
  459.   end
  460.  
  461. end
  462.  
  463. class RPG::Skill < RPG::UsableItem
  464.  
  465.   def skill_cost(actor = nil)
  466.     r = {}
  467.     self.note.scan(Z02::REGEXP::SCOST_WOVALUE) do |name|
  468.       $data_resources.each_with_index do |data_resource,i|
  469.         next unless data_resource.params[:name][0].upcase == name[0].upcase
  470.         r[i] = mp_cost
  471.         break
  472.       end
  473.     end
  474.     self.note.scan(Z02::REGEXP::SCOST_WVALUE) do |name, value|
  475.       $data_resources.each_with_index do |data_resource,i|
  476.         next unless data_resource.params[:name][0].upcase == name.upcase
  477.         r[i] = value.to_i
  478.         break
  479.       end
  480.     end
  481.     if actor.nil?
  482.       r[$def_res_i] = mp_cost if r.empty?
  483.     else
  484.       r[actor.resources.first_index] = mp_cost if r.empty?
  485.     end
  486.     return r
  487.   end
  488.  
  489. end
  490.  
  491. module SceneManager
  492.   #--------------------------------------------------------------------------
  493.   # * Alias method: call
  494.   #--------------------------------------------------------------------------
  495.   class <<self; alias_method :z02call, :call; end
  496.   def self.call(scene_class)
  497.     self.z02call(scene_class)
  498.     for actor in $game_party.members
  499.         next if actor.resources.nil?
  500.       actor.resources.each do |resource|
  501.         resource.replenish
  502.       end
  503.     end
  504.   end
  505.  
  506. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement