Advertisement
Zetu

Z02 v1.03

Dec 22nd, 2011
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.                             #======================#
  2.                             #  Z-Systems by: Zetu  #
  3. #===========================#======================#===========================#
  4. #                 *  *  *  Z02 AMPX Ace Version v1.03  *  *  *                 #
  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, :spi, :agi, :set                    #
  19.   #        base is number multiplied by type (:set is considered 1)          #
  20.   #  Resource Regen on Damage                                                #
  21.   #    :regenondamage, <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, <type>, <element_id(s)>, <base>                      #
  26.   #        same as :regenondamage, except on elemental damage (of            #
  27.   #        element_ids) (may place more than 1 id)                           #
  28.   #  Resource Change Out of Battle:                                          #
  29.   #    :depleteoob     (Set to 0)                                            #
  30.   #    :regenoob       (Set to Max)                                          #
  31.   #  Max Value                                                               #
  32.   #    :max, <value>                                                         #
  33.   #  Resource Inversion                                                      #
  34.   #    :invert                                                               #
  35.   #        this allows the resource to Add instead of Subtract for its cost  #
  36.   #        and disallows skill use if cost will exceed the max resource.     #
  37.   #==========================================================================#
  38. module Z02
  39.  
  40.   RESOURCES = [[
  41.         :regen, :mmp, 0.05,
  42.         :name, "Mana",
  43.         :abbv, "M",
  44.         :color, 23, 22
  45.       ],[
  46.         :depleteoob,
  47.         :regenondamage, :percentdmg, 120,
  48.         :max, 100,
  49.         :name, "Rage",
  50.         :abbv, "R",
  51.         :color, 10, 2
  52.       ],[
  53.         :regenoob,
  54.         :regen, :set, 20,
  55.         :max, 100,
  56.         :name, "Energy",
  57.         :abbv, "E",
  58.         :color, 6, 14
  59.       ],[
  60.         :regenoob,
  61.         :regen, :set, 30,
  62.         :regenondamage, :percentdmg, -150,
  63.         :max, 100,
  64.         :name, "Focus",
  65.         :abbv, "F",
  66.         :color, 3, 11
  67.       ],[
  68.         :invert,
  69.         :depleteoob,
  70.         :regenelemental, 3, :percent, 80,
  71.         :regenelemental, 4, 6, :percent, -120,
  72.         :regen, :set, -30,
  73.         :max, 150,
  74.         :name, "Heat",
  75.         :abbv, "H",
  76.         :color, 2, 10
  77.       ]]
  78.  
  79.   # Place in Class/Actor note to specify what resource(s) they use.
  80.   # (May use more than one.)
  81.   REGEXP_RESOURCES = /<ampx[:]*\s*(.*)>/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 = /<ampxcost[:]*\s*(.+)>/i
  86.   REGEXP_WVALUE  = /<ampxcost[:]*\s*(.+) +(\d+)>/i
  87.  
  88.   # If skill does MP damage/healing, use this to tell what resource.
  89.   REGEXP_AMPX = /<ampxvalue[:]*\s*(.+)>/i
  90.  
  91.   # Default value if not in RESBYCLASS hash.
  92.   DEF_RES = "Mana"
  93. #========#======================#====#================================#========#
  94. #--------#                      #----# DO NOT EDIT PAST THIS POINT!!! #--------#
  95. #--------# End of Customization #----# Editing will cause death by    #--------#
  96. #--------#                      #----# brain asplosions.              #--------#
  97. #========#======================#====#================================#========#
  98. end
  99. ($imported||={})[:z02]=true
  100. class Window_Base < Window
  101.   #--------------------------------------------------------------------------
  102.   # * New method: draw_actor_ampx
  103.   #--------------------------------------------------------------------------
  104.   def draw_actor_ampx(resource, x, y, width)
  105.     draw_gauge(x, y, width, resource.rate, text_color(resource.color1), text_color(resource.color2))
  106.     change_color(text_color(resource.color2))
  107.     draw_text(x, y, 30, line_height, resource.abbv)
  108.     draw_current_and_max_values(x, y, width, resource.value, resource.max,#~
  109.     mp_color(resource.actor), normal_color)
  110.   end
  111.   #--------------------------------------------------------------------------
  112.   # * Overwrite method: draw_actor_mp
  113.   #--------------------------------------------------------------------------
  114.   def draw_actor_mp(actor, x, y, width=124)
  115.       if actor.resources.nil?
  116.         actor.setup(actor.id)
  117.       end
  118.     width /= actor.resources.size
  119.     offset = width
  120.     if actor.resources.size != 1
  121.       offset += 2
  122.       width -= 1
  123.     end
  124.     for i in 0...actor.resources.size
  125.       draw_actor_ampx(actor.resources[i], x+offset*i, y, width)
  126.     end
  127.   end
  128.  
  129. end
  130.  
  131. class Game_Resources
  132.   attr_reader :name, :abbv, :color1, :color2, :value, :regenelemental,
  133.       :regentype, :regenbase, :regenodtype, :regenodbase, :tags, :regenouttype,
  134.       :regenoutbase, :actor, :index
  135.   attr_writer :max
  136.  
  137.   def initialize(type, actor)
  138.     @actor = actor
  139.     @index = get_resource_index(type)
  140.     scan_object_variables(@index)
  141.   end
  142.  
  143.   def scan_object_variables(index)
  144.     i = 0
  145.     array=Z02::RESOURCES[index]
  146.     @tags = []
  147.     @value = max
  148.     @maxdefault = true
  149.     @regenelemental = {}
  150.     while (i < array.size)
  151.       case array[i]
  152.       when :name; @name = array[i+1]; i+=1
  153.       when :abbv; @abbv = array[i+1]; i+=1
  154.       when :color; @color1 = array[i+1]; @color2 = array[i+2]; i+=2
  155.       when :regen; @regentype = array[i+1]; @regenbase = array[i+2]; i+=2
  156.       when :regenonoutdmg
  157.         @regenouttype = array[i+1]
  158.         @regenoutbase = array[i+2]
  159.         i+=2
  160.       when :regenondamage
  161.         @regenodtype = array[i+1]
  162.         @regenodbase = array[i+2]
  163.         i+=2
  164.       when :regenelemental
  165.         i+=1
  166.         id = []
  167.         while (array[i].is_a?(Integer))
  168.           id.push(array[i])
  169.           i+=1
  170.         end
  171.         for n in id
  172.           @regenelemental[n]= [array[i], array[i+1]]
  173.         end
  174.         i+=1
  175.       when :max
  176.         @max = array[i+1]
  177.         i+=1
  178.         @value = [@max, @value].min
  179.         @maxdefault = false
  180.       when :depleteoob; @tags.push(:depleteoob); @value = 0
  181.       when :regenoob; @tags.push(:regenoob)
  182.       when :invert; @tags.push(:invert)
  183.       end
  184.       i+=1
  185.     end
  186.   end
  187.  
  188.   def max
  189.     @max.nil? ? @actor.mmp : @max
  190.   end
  191.  
  192.   def get_resource_index(name)
  193.     for i in 0...Z02::RESOURCES.size
  194.       index = Z02::RESOURCES[i].index(:name)+1
  195.       if Z02::RESOURCES[i][index].upcase==name.upcase
  196.         return i
  197.       end
  198.     end
  199.   end
  200.  
  201.   def reinitialize
  202.     if @tags.include?(:depleteoob)
  203.       self.value=0
  204.     elsif @tags.include?(:regenoob)
  205.       self.value=max
  206.     end
  207.   end
  208.  
  209.   def value=(new_value)
  210.     @value = [[new_value, 0].max, max].min
  211.   end
  212.  
  213.   def rate
  214.     max > 0 ? value.to_f / max : 0
  215.   end
  216.  
  217.   def regen
  218.     return if @actor.dead?
  219.     return if @regentype.nil?
  220.     tvalue = @regenbase
  221.     case @regentype
  222.     when :mmp;   tvalue *= max
  223.     when :atk;   tvalue *= @actor.atk
  224.     when :def;   tvalue *= @actor.def
  225.     when :spi;   tvalue *= @actor.spi
  226.     when :agi;   tvalue *= @actor.agi
  227.     end
  228.     self.value += tvalue.to_i
  229.   end
  230.  
  231.   def regenoffdmg(amt)
  232.     return if regenouttype.nil?
  233.     return if amt < 1
  234.     tvalue = regenoutbase
  235.     case regenouttype
  236.     when :damage;     tvalue *= amt
  237.     when :maxmp;      tvalue *= max
  238.     when :percentdmg; tvalue *= amt.to_f/@actor.mhp
  239.     end
  240.     self.value += tvalue.to_i
  241.   end
  242.  
  243.   def regendmg(amt, element_id=0)
  244.     regendmgreg(amt)
  245.     regendmgele(amt, element_id)
  246.   end
  247.  
  248.   def regendmgreg(amt)
  249.     return if regenodtype.nil?
  250.     return if amt < 1
  251.     tvalue = regenodbase
  252.     case regenodtype
  253.     when :damage;     tvalue *= amt
  254.     when :maxmp;      tvalue *= max
  255.     when :percentdmg; tvalue *= amt.to_f/@actor.mhp
  256.     end
  257.     self.value += tvalue.to_i
  258.   end
  259.  
  260.   def regendmgele(amt, element_id)
  261.     return if regenelemental.nil?
  262.     return if regenelemental[element_id].nil?
  263.     return if amt < 1
  264.     tvalue = regenelemental[element_id][1]
  265.     case regenelemental[element_id][0]
  266.     when :damage;     tvalue *= amt
  267.     when :maxmp;      tvalue *= max
  268.     when :percentdmg; tvalue *= amt.to_f/@actor.mhp
  269.     end
  270.     self.value += tvalue.to_i
  271.   end
  272.  
  273.   def pay?(amount)
  274.     if @tags.include?(:invert)
  275.       return (@value+amount)<=@max
  276.     else
  277.       return (@value)>=amount
  278.     end
  279.   end
  280.  
  281.   def pay(amt)
  282.     if @tags.include?(:invert)
  283.       @value += amt
  284.     else
  285.       @value -= amt
  286.     end
  287.   end
  288.  
  289. end
  290.  
  291. class Game_Battler < Game_BattlerBase
  292.   attr_reader :resources
  293.   #--------------------------------------------------------------------------
  294.   # * New method: create_resources
  295.   #--------------------------------------------------------------------------
  296.   def create_resources
  297.     @resources = []
  298.     create_actor_spec_resources
  299.     @resources.push(Game_Resources.new(Z02::DEF_RES, self)) if @resources.size==0
  300.   end
  301.   #--------------------------------------------------------------------------
  302.   # * New method: create_actor_spec_resources
  303.   #--------------------------------------------------------------------------
  304.   def create_actor_spec_resources
  305.   end
  306.   #--------------------------------------------------------------------------
  307.   # * Alias method: on_turn_end
  308.   #--------------------------------------------------------------------------
  309.   alias :z02ote :on_turn_end
  310.   def on_turn_end
  311.     z02ote
  312.     for resource in @resources
  313.       resource.regen
  314.     end
  315.   end
  316.   #--------------------------------------------------------------------------
  317.   # * New method: resourcebyid
  318.   #--------------------------------------------------------------------------
  319.   def resourcebyid(id)
  320.     for resource in @resources
  321.       return resource if resource.index==id
  322.     end
  323.     return nil
  324.   end
  325.   #--------------------------------------------------------------------------
  326.   # * New method: skill_ampx_costs
  327.   #--------------------------------------------------------------------------
  328.   def skill_ampx_costs(skill)
  329.     values = []
  330.     skill.note.scan(Z02::REGEXP_NOVALUE){
  331.       next if (index=self.resources[0].get_resource_index($1)).nil?
  332.       values[index] = skill.mp_cost}
  333.     skill.note.scan(Z02::REGEXP_WVALUE){
  334.       next if (index=self.resources[0].get_resource_index($1)).nil?
  335.       values[index] = $2.to_i}
  336.     if values.size==0
  337.       index = self.resources[0].index
  338.       values[index]=skill.mp_cost
  339.     end
  340.     return values
  341.   end
  342.   #--------------------------------------------------------------------------
  343.   # * Overwrite method: skill_cost_payable?
  344.   #--------------------------------------------------------------------------
  345.   def skill_cost_payable?(skill)
  346.     values = skill_ampx_costs(skill)
  347.     for i in 0...values.size
  348.       next if values[i].nil?
  349.       return false if (resource = resourcebyid(i)).nil?
  350.       return false unless resource.pay?(values[i])
  351.     end
  352.     return true
  353.   end
  354.   #--------------------------------------------------------------------------
  355.   # * Alias method: pay_skill_cost
  356.   #--------------------------------------------------------------------------
  357.   alias :z02psc :pay_skill_cost
  358.   def pay_skill_cost(skill)
  359.     z02psc(skill)
  360.     values = skill_ampx_costs(skill)
  361.     for i in 0...values.size
  362.       next if values[i].nil?
  363.       return false if (resource = resourcebyid(i)).nil?
  364.       resource.pay(values[i])
  365.     end
  366.   end
  367.   #--------------------------------------------------------------------------
  368.   # * Alias method: item_apply
  369.   #--------------------------------------------------------------------------
  370.   alias :z02ia :item_apply
  371.   def item_apply(user, item)
  372.     z02ia(user, item)
  373.     if @result.hit?
  374.       unless item.damage.none?
  375.         ampx_ondamage(user, item.damage.element_id)
  376.         resource = resource(item)
  377.         unless resource.nil?
  378.           resource.value -= @result.mp_damage
  379.           ####user.mp += @result.mp_drain#### NEED TO ADD DRAIN
  380.         end
  381.       end
  382.     end
  383.   end
  384.  
  385.   def ampx_ondamage(user, element_id)
  386.     return if @result.hp_damage==0
  387.     for resource in @resources
  388.       resource.regendmg(@result.hp_damage, element_id)
  389.     end
  390.     for resource in user.resources
  391.       resource.regenoffdmg(@result.hp_damage)
  392.     end
  393.   end
  394.  
  395.   def resource(item)
  396.     name = item.resourcename
  397.     for resource in resources
  398.       return resource if resource.name.upcase==name.upcase
  399.     end
  400.     return nil
  401.   end
  402.  
  403. end
  404.  
  405. class Game_Enemy < Game_Battler
  406.   #--------------------------------------------------------------------------
  407.   # * Alias method: initialize
  408.   #--------------------------------------------------------------------------
  409.   alias :z02init :initialize
  410.   def initialize(index, enemy_id)
  411.     z02init(index, enemy_id)
  412.     create_resources
  413.   end
  414.  
  415. end
  416.  
  417. class Game_Actor < Game_Battler
  418.   #--------------------------------------------------------------------------
  419.   # * Alias method: setup
  420.   #--------------------------------------------------------------------------
  421.   alias :z02setup :setup
  422.   def setup(actor_id)
  423.     z02setup(actor_id)
  424.     create_resources
  425.   end
  426.   #--------------------------------------------------------------------------
  427.   # * New method: create_actor_spec_resources
  428.   #--------------------------------------------------------------------------
  429.   def create_actor_spec_resources
  430.     self.class.note.scan(Z02::REGEXP_RESOURCES){
  431.     @resources.push(Game_Resources.new($1, self))}
  432.   end
  433.  
  434. end
  435.  
  436. module SceneManager
  437.   #--------------------------------------------------------------------------
  438.   # * Alias method: call
  439.   #--------------------------------------------------------------------------
  440.   class <<self; alias_method :z02call, :call; end
  441.   def self.call(scene_class)
  442.     self.z02call(scene_class)
  443.     for actor in $game_party.members
  444.         next if actor.resources.nil?
  445.       for resource in actor.resources
  446.         resource.reinitialize
  447.       end
  448.     end
  449.   end
  450.  
  451. end
  452.  
  453. class Window_SkillList < Window_Selectable
  454.   #--------------------------------------------------------------------------
  455.   # * Alias method: draw_skill_cost
  456.   #--------------------------------------------------------------------------
  457.   alias :z02dsc :draw_skill_cost
  458.   def draw_skill_cost(rect, skill)
  459.     if @actor.skill_tp_cost(skill) > 0
  460.       z02dsc(rect, skill)
  461.     elsif @actor.skill_mp_cost(skill) > 0
  462.       values = @actor.skill_ampx_costs(skill)
  463.       values.size.downto(0) { |i|
  464.         next if values[i].nil?
  465.         next if (resource = @actor.resourcebyid(i)).nil?
  466.         change_color(text_color(resource.color1),
  467.           @actor.skill_cost_payable?(skill))
  468.         draw_text(rect, values[i], 2)
  469.         rect.width -= 32
  470.       }
  471.     end
  472.   end
  473.  
  474. end
  475.  
  476. class RPG::UsableItem < RPG::BaseItem
  477.  
  478.   def resourcename
  479.     self.note.scan(Z02::REGEXP_AMPX){
  480.       return $1}
  481.     return Z02::DEF_RES
  482.   end
  483.  
  484. end
  485.  
  486. class Game_ActionResult
  487.  
  488.   def ampx_damage_text(name)
  489.     if @mp_drain > 0
  490.       fmt = @battler.actor? ? Vocab::ActorDrain : Vocab::EnemyDrain
  491.       sprintf(fmt, @battler.name, name, @mp_drain)
  492.     elsif @mp_damage > 0
  493.       fmt = @battler.actor? ? Vocab::ActorLoss : Vocab::EnemyLoss
  494.       sprintf(fmt, @battler.name, name, @mp_damage)
  495.     elsif @mp_damage < 0
  496.       fmt = @battler.actor? ? Vocab::ActorRecovery : Vocab::EnemyRecovery
  497.       sprintf(fmt, @battler.name, name, -@mp_damage)
  498.     else
  499.       ""
  500.     end
  501.   end
  502.  
  503. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement