Advertisement
Zetu

AMPXAce v1.01

Dec 5th, 2011
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.39 KB | None | 0 0
  1. #===================================================
  2. # Alternate MP X System :: By Zetu (RMVXAce)
  3. # v1.01
  4. ##==================================================
  5.   #  You may need slight scripting knowledge of working with arrays (but  not a whole lot!).
  6.   #-------------------------------------------------------------------------------------------
  7.   #                      * * Anything in "< >" means replace with the described contents. * *
  8.   #  REQUIRED PARAMETERS (Any resource without it will cause an error)
  9.   #    :name, <name of resource>
  10.   #    :abbv, <1 or 2 character abbv. of resource>
  11.   #    :color, <color 1>, <color 2>
  12.   #        * These color attributes are indexes of the window skin
  13.   #  OPTIONAL PARAMETERS
  14.   #  Resource Regen for each turn:
  15.   #    :regen, <type>, <base>
  16.   #        type can be :mmp, :atk, :def, :spi, :agi, :set
  17.   #        base is number multiplied by type (:set is considered 1)
  18.   #  Resource Regen on Damage
  19.   #    :regenondamage, <type>, <base>
  20.   #        type can be :damage, :mmp, :set, :percentdmg
  21.   #        base in number multipled by type (:set is considered 1)
  22.   #        (:percentdmg is ratio of mmp and damage)
  23.   #    :regenelemental, <element_id>, <type>, <base>
  24.   #        same as :regenondamage, except on elemental damage (of  element_ids)
  25.   #        (may place more than 1 id)
  26.   #  Resource Change Out of Battle:
  27.   #    :depleteoob     (Set to 0)
  28.   #    :regenoob       (Set to Max)
  29.   #  Max Value
  30.   #    :max, <value>
  31.   #  Resource Inversion
  32.   #    :invert
  33.   #        this allows the resource to Add instead of Subtract for its cost and disallows
  34.   #        skill use if cost will exceed the max resource
  35.   #==========================================================================#
  36. module Z02
  37.  
  38.   RESOURCES = [
  39.         :regen, :mmp, 0.05,
  40.         :name, "Mana",
  41.         :abbv, "M",
  42.         :color, 23, 22
  43.       ],[
  44.         :depleteoob,
  45.         :regenondamage, :percent, 12,
  46.         :max, 100,
  47.         :name, "Rage",
  48.         :abbv, "R",
  49.         :color, 10, 2
  50.       ],[
  51.         :regenoob,
  52.         :regen, :set, 20,
  53.         :max, 100,
  54.         :name, "Energy",
  55.         :abbv, "E",
  56.         :color, 6, 14
  57.       ],[
  58.         :regenoob,
  59.         :regen, :set, 30,
  60.         :regenondamage, :percent, -15,
  61.         :max, 100,
  62.         :name, "Focus",
  63.         :abbv, "F",
  64.         :color, 3, 11
  65.       ],[
  66.         :invert,
  67.         :depleteoob,
  68.         :regenelemental, 9, :percent, 2,
  69.         :regenelemental, 10, 12, :percent, -1,
  70.         :regen, :set, -30,
  71.         :max, 150,
  72.         :name, "Heat",
  73.         :abbv, "H",
  74.         :color, 2, 10
  75.       ]
  76.   # If set to false, use RESBYCLASS's indexes as Actor IDs instead of Class IDs
  77.   BIND_TO_CLASS = true
  78.  
  79.   # Place in Class/Actor note to specify what resource(s) they use.
  80.   # (May use more than one.)
  81.   REGEXP_RESOURCES = /<ampx[: ]+(.*)>/i
  82.  
  83.   # Place in Skill note to specify mana cost.  First regexp will default
  84.   # in value in database (MP Cost)
  85.   REGEXP_NOVALUE = /<ampx[: ]+(.+)>/i
  86.   REGEXP_WVALUE  = /<ampx[: ]+(.+) +(\d+)>/i
  87.  
  88.   # Default value if not in RESBYCLASS hash.
  89.   DEF_RES = "Mana"
  90.  
  91. end
  92.  
  93. class Window_Base < Window
  94.  
  95.   def draw_actor_ampx(resource, x, y, width)
  96.     draw_gauge(x, y, width, resource.rate, text_color(resource.color1), text_color(resource.color2))
  97.     change_color(text_color(resource.color2))
  98.     draw_text(x, y, 30, line_height, resource.abbv)
  99.     draw_current_and_max_values(x, y, width, resource.value, resource.max,#~
  100.     mp_color(resource.actor), normal_color)
  101.   end
  102.  
  103.   def draw_actor_mp(actor, x, y, width=124)
  104.     if actor.resources.nil?
  105.         actor.setup(actor.id)
  106.     end
  107.     width /= actor.resources.size
  108.     offset = width
  109.     if actor.resources.size != 1
  110.       offset += 2
  111.       width -= 1
  112.     end
  113.     for i in 0...actor.resources.size
  114.       draw_actor_ampx(actor.resources[i], x+offset*i, y, width)
  115.     end
  116.   end
  117.  
  118. end
  119.  
  120. class Game_Resources
  121.  
  122.   attr_reader :name, :abbv, :color1, :color2, :value, :regenelemental,
  123.       :regentype, :regenbase, :regenodtype, :regenodbase, :tags, :regenouttype,
  124.       :regenoutbase, :actor, :index
  125.   attr_accessor :max
  126.  
  127.   def initialize(type, actor)
  128.     @actor = actor
  129.     @index = get_resource_index(type)
  130.     scan_object_variables(@index)
  131.   end
  132.  
  133.   def scan_object_variables(index)
  134.     i = 0
  135.     array=Z02::RESOURCES[index]
  136.     @tags = []
  137.     @max = @actor.mmp
  138.     @value = @max
  139.     @maxdefault = true
  140.     @regenelemental = {}
  141.     while (i < array.size)
  142.       case array[i]
  143.       when :name; @name = array[i+1]; i+=1
  144.       when :abbv; @abbv = array[i+1]; i+=1
  145.       when :color; @color1 = array[i+1]; @color2 = array[i+2]; i+=2
  146.       when :regen; @regentype = array[i+1]; @regenbase = array[i+2]; i+=2
  147.       when :regenonoutdmg
  148.         @regenouttype = array[i+1]
  149.         @regenoutbase = array[i+2]
  150.         i+=2
  151.       when :regenondamage
  152.         @regenodtype = array[i+1]
  153.         @regenodbase = array[i+2]
  154.         i+=2
  155.       when :regenelemental
  156.         i+=1
  157.         id = []
  158.         while (array[i].is_a?(Integer))
  159.           id.push(array[i])
  160.           i+=1
  161.         end
  162.         for n in id
  163.           @regenelemental[n]= array[i], array[i+1]
  164.         end
  165.         i+=1
  166.       when :max
  167.         @max = array[i+1]
  168.         i+=1
  169.         @value = [@max, @value].min
  170.         @maxdefault = false
  171.       when :depleteoob; @tags.push(:depleteoob); @value = 0
  172.       when :regenoob; @tags.push(:regenoob)
  173.       when :invert; @tags.push(:invert)
  174.       end
  175.       i+=1
  176.     end
  177.   end
  178.  
  179.   def get_resource_index(name)
  180.     for i in 0...Z02::RESOURCES.size
  181.       index = Z02::RESOURCES[i].index(:name)+1
  182.       if Z02::RESOURCES[i][index].upcase==name.upcase
  183.         return i
  184.       end
  185.     end
  186.   end
  187.  
  188.   def reinitialize
  189.     if @tags.include?(:depleteoob)
  190.       self.value=0
  191.     elsif @tags.include?(:regenoob)
  192.       self.value=self.max
  193.     end
  194.   end
  195.  
  196.   def value=(new_value)
  197.     @value = [[new_value, 0].max, @max].min
  198.   end
  199.  
  200.   def rate
  201.     max > 0 ? value.to_f / max : 0
  202.   end
  203.  
  204.   def regen
  205.     return if @actor.dead?
  206.     return if @regentype.nil?
  207.     tvalue = @regenbase
  208.     case @regentype
  209.     when :mmp;   tvalue *= max
  210.     when :atk;   tvalue *= @actor.atk
  211.     when :def;   tvalue *= @actor.def
  212.     when :spi;   tvalue *= @actor.spi
  213.     when :agi;   tvalue *= @actor.agi
  214.     end
  215.     self.value += tvalue.to_i
  216.   end
  217.  
  218.   def regendmg(value)
  219.     return if regenodtype.nil?
  220.     tvalue = regenodbase
  221.     case regenodtype
  222.     when :damage
  223.       value *= tvalue
  224.     when :maxmp
  225.       tvalue *= max
  226.     when :percentdmg
  227.       tvalue *= value.to_f/max
  228.     end
  229.     self.value += tvalue.to_i
  230.   end
  231.  
  232.   def regenoffdmg(value)
  233.     return if regenouttype.nil?
  234.     tvalue = regenoutbase
  235.     case regenouttype
  236.     when :damage
  237.       value *= tvalue
  238.     when :maxmp
  239.       tvalue *= max
  240.     when :percentdmg
  241.       tvalue *= value.to_f/max
  242.     end
  243.     self.value += tvalue.to_i
  244.   end
  245.  
  246.   def pay?(amount)
  247.     if @tags.include?(:invert)
  248.       return (self.value+amount)<=self.max
  249.     else
  250.       return (self.value)>=amount
  251.     end
  252.   end
  253.  
  254.   def pay(amount)
  255.     if @tags.include?(:invert)
  256.       self.value += amount
  257.     else
  258.       self.value -= amount
  259.     end
  260.   end
  261.  
  262. end
  263.  
  264. class Game_Battler < Game_BattlerBase
  265.   attr_reader :resources
  266.  
  267.   def create_resources
  268.   print "Creating Resources for #{self.name}!\n"
  269.     @resources = []
  270.     create_actor_spec_resources
  271.     @resources.push(Game_Resources.new(Z02::DEF_RES, self)) if @resources.size==0
  272.   end
  273.  
  274.   def create_actor_spec_resources
  275.   end
  276.  
  277.   alias z02ote on_turn_end unless $@
  278.   def on_turn_end
  279.     z02ote
  280.     for resource in self.resources
  281.       resource.regen
  282.     end
  283.   end
  284.  
  285.   alias z02od on_damage
  286.   def on_damage(value)
  287.     z02od(value)
  288.     for resource in self.resources
  289.       resource.regendmg(value)
  290.     end
  291.   end
  292.  
  293.   def resourcebyid(id)
  294.     for resource in resources
  295.       return resource if resource.index==id
  296.     end
  297.     return nil
  298.   end
  299.  
  300.   def skill_ampx_costs(skill)
  301.     values = []
  302.     skill.note.scan(Z02::REGEXP_NOVALUE){
  303.       next if (index=self.resources[0].get_resource_index($1)).nil?
  304.       values[index] = skill.mp_cost}
  305.     skill.note.scan(Z02::REGEXP_WVALUE){
  306.       next if (index=self.resources[0].get_resource_index($1)).nil?
  307.       values[index] = $2.to_i}
  308.     if values.size==0
  309.       index = self.resources[0].index
  310.       values[index]=skill.mp_cost
  311.     end
  312.     return values
  313.   end
  314.  
  315.   def skill_cost_payable?(skill)
  316.     values = skill_ampx_costs(skill)
  317.     for i in 0...values.size
  318.       next if values[i].nil?
  319.       return false if (resource = resourcebyid(i)).nil?
  320.       return false unless resource.pay?(values[i])
  321.     end
  322.     return true
  323.   end
  324.  
  325.   alias z02psc pay_skill_cost unless $@
  326.   def pay_skill_cost(skill)
  327.     z02psc(skill)
  328.     values = skill_ampx_costs(skill)
  329.     for i in 0...values.size
  330.       next if values[i].nil?
  331.       return false if (resource = resourcebyid(i)).nil?
  332.       resource.pay(values[i])
  333.     end
  334.   end
  335.  
  336. end
  337.  
  338. class Game_Enemy < Game_Battler
  339.  
  340.   alias z02init initialize unless $@
  341.   def initialize(index, enemy_id)
  342.     z02init(index, enemy_id)
  343.     create_resources
  344.   end
  345.  
  346. end
  347.  
  348. class Game_Actor < Game_Battler
  349.  
  350.   alias z02setup setup unless $@
  351.   def setup(actor_id)
  352.     z02setup(actor_id)
  353.     create_resources
  354.   end
  355.  
  356.   def create_actor_spec_resources
  357.     (Z02::BIND_TO_CLASS ? self.class : self).note.scan(Z02::REGEXP_RESOURCES){
  358.     @resources.push(Game_Resources.new($1, self))}
  359.   end
  360.  
  361. end
  362.  
  363. module SceneManager
  364.  
  365.   class <<self; alias_method :z02call, :call; end
  366.   def self.call(scene_class)
  367.     self.z02call(scene_class)
  368.     for actor in $game_party.members
  369.       next if actor.resources.nil?
  370.       for resource in actor.resources
  371.         resource.reinitialize
  372.       end
  373.     end
  374.   end
  375.  
  376. end
  377.  
  378. class Window_SkillList < Window_Selectable
  379.  
  380.   alias z02dsc draw_skill_cost unless $@
  381.   def draw_skill_cost(rect, skill)
  382.     if @actor.skill_tp_cost(skill) > 0
  383.       z02dsc(rect, skill)
  384.     elsif @actor.skill_mp_cost(skill) > 0
  385.       values = @actor.skill_ampx_costs(skill)
  386.       values.size.downto(0) { |i|
  387.         next if values[i].nil?
  388.         next if (resource = @actor.resourcebyid(i)).nil?
  389.         change_color(text_color(resource.color1), @actor.skill_cost_payable?(skill))
  390.         draw_text(rect, values[i], 2)
  391.         rect.width -= 32
  392.       }
  393.     end
  394.   end
  395.  
  396. end
  397.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement