Advertisement
Zetu

AMPX v3

Nov 30th, 2011
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 17.18 KB | None | 0 0
  1.                             #======================#
  2.                             #  Z-Systems by: Zetu  #
  3. #===========================#======================#===========================#
  4. #                    *  *  *  Alternate MP X v3.01  *  *  *                    #
  5. #------------------------------------------------------------------------------#
  6. #  Will Overwrite Draw Functions for MP.                                       #
  7. #------------------------------------------------------------------------------#
  8. # Known Compatable Battle Systems:                                             #
  9. #   • Tankentai                                                                #
  10. #------------------------------------------------------------------------------#
  11. # Version History                                                              #
  12. #  3.01 ALPHA                                                                  #
  13. #=#==========================================================================#=#
  14.   #  You may need slight scripting knowledge of working with arrays (but     #
  15.   #  not a whole lot!).                                                      #
  16.   #--------------------------------------------------------------------------#
  17.   #   * * Anything in "< >" means replace with the described contents. * *   #
  18.   #  REQUIRED PARAMETERS (Any resource without it will cause an error)       #
  19.   #    :name, <name of resource>                                             #
  20.   #    :abbv, <1 or 2 character abbv. of resource>                           #
  21.   #    :color, <color 1>, <color 2>                                          #
  22.   #        * These color attributes are indexes of the window skin           #
  23.   #  OPTIONAL PARAMETERS                                                     #
  24.   #  Resource Regen for each turn:                                           #
  25.   #    :regen, <type>, <base>                                                #
  26.   #        type can be :maxmp, :atk, :def, :spi, :agi, :set                  #
  27.   #        base is number multiplied by type (:set is considered 1)          #
  28.   #  Resource Regen on Damage                                                #
  29.   #    :regenondamage, <type>, <base>                                        #
  30.   #        type can be :damage, :maxmp, :set, :percentdmg                    #
  31.   #        base in number multipled by type (:set is considered 1)           #
  32.   #        (:percentdmg is ratio of maxmp and damage)                        #
  33.   #    :regenelemental, <element_id>, <type>, <base>                         #
  34.   #        same as :regenondamage, except on elemental damage (of            #
  35.   #        element_ids) (may place more than 1 id)                           #
  36.   #  Resource Change Out of Battle:                                          #
  37.   #    :depleteoob     (Set to 0)                                            #
  38.   #    :regenoob       (Set to Max)                                          #
  39.   #  Resource Inversion                                                      #
  40.   #    :invert                                                               #
  41.   #        this allows the resource to Add instead of Subtract for its cost  #
  42.   #        and disallows skill use if cost will exceed the maxmp             #
  43.   #==========================================================================#
  44. module Z11
  45.  
  46.   RESOURCES = [
  47.         :regen, :maxmp, 0.05,
  48.         :name, "Mana",
  49.         :abbv, "M",
  50.         :color, 23, 22
  51.       ],[
  52.         :depleteoob,
  53.         :regenondamage, :percentdmg, 1.2,
  54.         :max, 100,
  55.         :name, "Rage",
  56.         :abbv, "R",
  57.         :color, 10, 2
  58.       ],[
  59.         :regenoob,
  60.         :regen, :set, 20,
  61.         :max, 100,
  62.         :name, "Energy",
  63.         :abbv, "E",
  64.         :color, 6, 14
  65.       ],[
  66.         :regenoob,
  67.         :regen, :set, 30,
  68.         :regenondamage, :percent, -1.5,
  69.         :max, 100,
  70.         :name, "Focus",
  71.         :abbv, "F",
  72.         :color, 3, 11
  73.       ],[
  74.         :invert,
  75.         :depleteoob,
  76.         :regenelemental, 9, :percent, 2,
  77.         :regenelemental, 10, 12, :percent, -1,
  78.         :regen, :set, -30,
  79.         :max, 150,
  80.         :name, "Heat",
  81.         :abbv, "H",
  82.         :color, 2, 10
  83.       ]
  84.   # If set to false, use RESBYCLASS's indexes as Actor IDs instead of Class IDs
  85.   BIND_TO_CLASS = true
  86.  
  87.   # <Class ID> => <Array of Resources by :name parameter>
  88.   # Recommended max is 2
  89.   RESBYCLASS = {
  90.     1 => ["Mana", "Rage"],
  91.     2 => ["Mana", "Energy"],
  92.     3 => ["Heat", "Rage"],
  93.     4 => ["Rage"]
  94.   }
  95.  
  96.   # Default value if not in RESBYCLASS hash.
  97.   DEF_RES = "Mana"
  98.   #=========================================================================#
  99.   #  Note Tags: To be used in notebox                                       #
  100.   #=========================================================================#
  101.       #Skill Notes
  102.      
  103.       #States what Resource Skill uses.  Use :name parameter (case insensitive)
  104.       #If tag does not exist, will default to actor's primary resource
  105.       RESOURCECOSTTYPE = /<ampx[: ]+(.*)>/i
  106. #========#======================#====#================================#========#
  107. #--------#                      #----# DO NOT EDIT PAST THIS POINT!!! #--------#
  108. #--------# End of Customization #----# Editing will cause death by    #--------#
  109. #--------#                      #----# brain asplosions.              #--------#
  110. #========#======================#====#================================#========#
  111.   def self.get_resource_index(type)
  112.     for array in RESOURCES
  113.       if array[array.index(:name)+1].upcase == type.upcase
  114.         return RESOURCES.index(array)
  115.       end
  116.     end
  117.     return -1
  118.   end
  119.  
  120. end
  121.  
  122. class Game_Resources
  123.  
  124.   attr_reader :name, :abbv, :color1, :color2, :value, :regenelemental,
  125.       :regentype, :regenbase, :regenodtype, :regenodbase, :tags
  126.   attr_accessor :max
  127.  
  128.   def initialize(type, actor)
  129.     @index = Z11::get_resource_index(type)
  130.     @actor = actor
  131.     scan_object_variables(type)
  132.   end
  133.  
  134.   def scan_object_variables(type)
  135.     i = 0
  136.     array=Z11::RESOURCES[@index]
  137.     @tags = []
  138.     @max = @actor.maxmp
  139.     @value = @max
  140.     @maxdefault = true
  141.     @regenelemental = {}
  142.     while (i < array.size)
  143.       case array[i]
  144.       when :name; @name = array[i+1]; i+=1
  145.       when :abbv; @abbv = array[i+1]; i+=1
  146.       when :color; @color1 = array[i+1]; @color2 = array[i+2]; i+=2
  147.       when :regen; @regentype = array[i+1]; @regenbase = array[i+2]; i+=2
  148.       when :regenondamage
  149.         @regenodtype = array[i+1]
  150.         @regenodbase = array[i+2]
  151.         i+=2
  152.       when :regenelemental
  153.         i+=1
  154.         id = []
  155.         while (array[i].is_a?(Integer))
  156.           id.push(array[i])
  157.           i+=1
  158.         end
  159.         for n in id
  160.           @regenelemental[n]= array[i], array[i+1]
  161.         end
  162.         i+=1
  163.       when :max
  164.         @max = array[i+1]
  165.         i+=1
  166.         @value = [@max, @value].min
  167.         @maxdefault = false
  168.       when :depleteoob; @tags.push(:depleteoob); @value = 0
  169.       when :regenoob; @tags.push(:regenoob)
  170.       when :invert; @tags.push(:invert)
  171.       end
  172.       i+=1
  173.     end
  174.   end
  175.  
  176.   def value=(new_value)
  177.     @value = [[new_value, 0].max, @max].min
  178.   end
  179.  
  180. end
  181.  
  182. class Game_Actor < Game_Battler
  183.  
  184.   alias ampx_setup setup
  185.   def setup(actor_id)
  186.     ampx_setup(actor_id)
  187.     @ampx = []
  188.     for resource in self.resources
  189.       @ampx.push(Game_Resources.new(resource,self))
  190.     end
  191.   end
  192.  
  193.   def resources
  194.     if Z11::BIND_TO_CLASS
  195.       result = Z11::RESBYCLASS[self.class_id]
  196.     else
  197.       result = Z11::RESBYCLASS[self.actor_id]
  198.     end
  199.     return result.nil? ? [Z11::DEF_RES] : result
  200.   end
  201.  
  202.   alias z11ed execute_damage unless $@
  203.   def execute_damage(user)
  204.     z11ed(user)
  205.     ampx_on_hit(@hp_damage)
  206.     self.mp -= @mp_damage####
  207.     if @absorbed
  208.       user.mp += @mp_damage####
  209.     end
  210.   end
  211.  
  212.   def resourcenameof(skill)
  213.     skill.note.scan(Z11::RESOURCECOSTTYPE){
  214.       return $1.upcase
  215.     }
  216.     return self.ampx[0].name.upcase
  217.   end
  218.  
  219. end
  220.  
  221. class Game_Enemy < Game_Battler####
  222.  
  223.   alias ampx_initialize initialize
  224.   def initialize(index, enemy_id)
  225.     ampx_initialize(index, enemy_id)
  226.     @ampx = [Game_Resources.new(Z11::DEF_RES,self)]
  227.   end
  228.  
  229.   def resources
  230.     return [Z11::DEF_RES]
  231.   end
  232.  
  233.   def resourcenameof(skill)
  234.     return Z11::DEF_RES
  235.   end
  236.  
  237. end
  238.  
  239. class Game_Battler
  240.   attr_reader :ampx
  241.  
  242.   def skill_can_use?(skill)
  243.     return false unless skill.is_a?(RPG::Skill)
  244.     return false unless movable?
  245.     return false if silent? and skill.spi_f > 0
  246.     resource = skill.resourceof(self)
  247.     return false unless self.ampx.include?(resource)
  248.     if resource.tags.include?(:invert)
  249.       return false if calc_mp_cost(skill) + resource.value > resource.max
  250.     else
  251.       return false if calc_mp_cost(skill) > resource.value
  252.     end
  253.     if $game_temp.in_battle
  254.       return skill.battle_ok?
  255.     else
  256.       return skill.menu_ok?
  257.     end
  258.   end
  259.  
  260.   alias z11ed execute_damage unless $@
  261.   def execute_damage(user)
  262.     z11ed(user)
  263.     ampx_on_hit(@hp_damage)
  264.     self.mp -= @mp_damage####
  265.     if @absorbed
  266.       user.mp += @mp_damage####
  267.     end
  268.   end
  269.  
  270.   def ampx_on_hit(damage)
  271.     return unless damage > 0
  272.     for resource in @ampx
  273.       next if resource.regenodtype.nil?
  274.       value = resource.regenodbase
  275.       case resource.regenodtype
  276.       when :damage
  277.         value *= damage
  278.       when :maxmp
  279.         value *= resource.max
  280.       when :percentdmg
  281.         value *= 100*damage/resource.max
  282.       end
  283.       resource.value += value.to_i
  284.       next if @obj.nil?
  285.       total = 0
  286.       value = 0
  287.       for i in @obj.element_set
  288.         if resource.regenelemental.key?(i)
  289.           value = resource.regenelemental[i][1]
  290.           case resource.regenelemental[i][0]
  291.           when :damage;     value *= damage
  292.           when :maxmp;      value *= resource.max
  293.           when :percentdmg; value *= 100*damage/resource.max
  294.           end
  295.           total+=1
  296.         end
  297.       end
  298.       resource.value += (value/total).to_i if total != 0
  299.     end
  300.   end
  301.  
  302.   def recover_all
  303.     @hp = maxhp
  304.     return if @ampx.nil?
  305.     for resource in @ampx
  306.       unless resource.tags.include?(:depleteoob)
  307.         resource.value = resource.max
  308.       end
  309.     end
  310.     for i in @states.clone
  311.       remove_state(i)
  312.     end
  313.   end
  314.    
  315.   alias z11modv make_obj_damage_value unless $@
  316.   def make_obj_damage_value(user, obj)
  317.     @obj = obj
  318.     z11modv(user,obj)
  319.   end
  320.  
  321.   alias z11madv make_attack_damage_value
  322.   def make_attack_damage_value(attacker)
  323.     @obj = nil
  324.     z11madv(attacker)
  325.   end
  326.    
  327. end
  328.  
  329. class Scene_Base
  330.   alias old_main main unless $@
  331.   def main
  332.     old_main
  333.     refresh_zsr
  334.   end
  335.  
  336.   def refresh_zsr
  337.     for actor in $game_party.members
  338.       for resource in actor.ampx
  339.         if resource.tags.include?(:regenoob)
  340.           resource.value=resource.max
  341.         elsif resource.tags.include?(:depleteoob)
  342.           resource.value=0
  343.         end
  344.       end
  345.     end
  346.   end
  347.  
  348. end
  349.  
  350. class Scene_Battle < Scene_Base
  351.  
  352.   def regen_ampx(actor)
  353.     return if actor.dead?
  354.     for resource in actor.ampx
  355.       next if resource.regentype.nil?
  356.       value = resource.regenbase
  357.       case resource.regentype
  358.       when :maxmp; value *= resource.max
  359.       when :atk;   value *= actor.atk
  360.       when :def;   value *= actor.def
  361.       when :spi;   value *= actor.spi
  362.       when :agi;   value *= actor.agi
  363.       end
  364.       resource.value += value.to_i
  365.     end
  366.     @status_window.refresh
  367.   end
  368.  
  369.   def refresh_zsr
  370.     for actor in $game_party.members
  371.       for resource in actor.ampx
  372.         if resource.tags.include?(:regenoob)
  373.           resource.value = resource.max
  374.         elsif resource.tags.include?(:depleteoob)
  375.           resource.value = 0
  376.         end
  377.       end
  378.     end
  379.   end
  380.  
  381. end
  382.  
  383. class Scene_Skill < Scene_Base
  384.  
  385.   def use_skill_nontarget                                            # OVERWRITE
  386.     Sound.play_use_skill
  387.     resource = @skill.resourceof(@actor)
  388.     if resource.tags.include?(:invert)
  389.       resource.value += @actor.calc_mp_cost(@skill)
  390.     else
  391.       resource.value -= @actor.calc_mp_cost(@skill)
  392.     end
  393.     @status_window.refresh
  394.     @skill_window.refresh
  395.     @target_window.refresh
  396.     if $game_party.all_dead?
  397.       $scene = Scene_Gameover.new
  398.     elsif @skill.common_event_id > 0
  399.       $game_temp.common_event_id = @skill.common_event_id
  400.       $scene = Scene_Map.new
  401.     end
  402.   end
  403.  
  404. end
  405.  
  406. class Scene_Item < Scene_Base
  407.  
  408.   def use_item_nontarget                                             # OVERWRITE
  409.     Sound.play_use_item
  410.     $game_party.consume_item(@item)
  411.     @item_window.draw_item(@item_window.index)
  412.     @target_window.refresh
  413.     if $game_party.all_dead?
  414.       $scene = Scene_Gameover.new
  415.     elsif @item.common_event_id > 0
  416.       $game_temp.common_event_id = @item.common_event_id
  417.       $scene = Scene_Map.new
  418.     end
  419.   end
  420.  
  421. end
  422.  
  423. class RPG::Skill < RPG::UsableItem
  424.  
  425.   def resourceof(actor)
  426.     unless actor.actor?
  427.       return actor.ampx[0]
  428.     end
  429.     name = actor.resourcenameof(self)
  430.     for resource in actor.ampx
  431.       if resource.name.upcase==name
  432.         return resource
  433.       end
  434.     end
  435.     print "Error: def resourceof(#{actor.name}) for skill #{self.name} returned nil, type #{name}"
  436.   end
  437.  
  438. end
  439.  
  440. class Window_Base < Window
  441.  
  442.   def draw_actor_mp(actor, x, y, width = 120)                        # OVERWRITE
  443.     width = width/actor.ampx.size
  444.     offset = width
  445.     if actor.ampx.size != 1
  446.       offset += 1
  447.       width -= 1
  448.     end
  449.     for i in 0...actor.ampx.size
  450.       draw_actor_ampx(actor.ampx[i], x+i*offset,y,width)
  451.     end
  452.   end
  453.  
  454.   def draw_actor_ampx(resource, x, y, width = 120)
  455.     draw_actor_ampx_gauge(resource, x, y, width)
  456.     self.contents.font.color = system_color
  457.     self.contents.draw_text(x, y, 30, WLH, resource.abbv)
  458.     self.contents.font.color = text_color(resource.color1)
  459.     last_font_size = self.contents.font.size
  460.     xr = x + width
  461.     if width < 120
  462.       self.contents.draw_text(xr - 44, y, 44, WLH, resource.value, 2)
  463.     else
  464.       self.contents.draw_text(xr - 99, y, 44, WLH, resource.value, 2)
  465.       self.contents.font.color = normal_color
  466.       self.contents.draw_text(xr - 55, y, 11, WLH, "/", 2)
  467.       self.contents.font.color = text_color(resource.color1)
  468.       self.contents.draw_text(xr - 44, y, 44, WLH, resource.max, 2)
  469.     end
  470.   end
  471.  
  472.   def draw_actor_ampx_gauge(resource, x, y, width = 120)
  473.     gw = width * resource.value / [resource.max, 1].max
  474.     gc1 = text_color(resource.color1)
  475.     gc2 = text_color(resource.color2)
  476.     self.contents.fill_rect(x, y + WLH - 8, width, 6, gauge_back_color)
  477.     self.contents.gradient_fill_rect(x, y + WLH - 8, gw, 6, gc1, gc2)
  478.   end
  479.  
  480. end
  481.  
  482. class Window_BattleStatus < Window_Selectable
  483.  
  484.   def draw_item(index)
  485.     rect = item_rect(index)
  486.     rect.x += 4
  487.     rect.width -= 8
  488.     self.contents.clear_rect(rect)
  489.     self.contents.font.color = normal_color
  490.     actor = $game_party.members[index]
  491.     draw_actor_state(actor, 114, rect.y, 48)
  492.     draw_actor_name(actor, 4, rect.y)
  493.     draw_actor_hp(actor, 124, rect.y, 120)
  494.     draw_actor_mp(actor, 260, rect.y, 120)
  495.   end
  496.  
  497. end
  498.  
  499.  
  500. #BS
  501. class Scene_Battle < Scene_Base
  502.  
  503.   def display_mp_damage(target, obj = nil)                            #OVERWRITE
  504.     return if target.dead?
  505.     return if target.mp_damage == 0
  506.     type = obj.regresource.name
  507.     if target.absorbed
  508.       fmt = target.actor? ? Vocab::ActorDrain : Vocab::EnemyDrain
  509.       text = sprintf(fmt, target.name, type, target.mp_damage)
  510.     elsif target.mp_damage > 0
  511.       fmt = target.actor? ? Vocab::ActorLoss : Vocab::EnemyLoss
  512.       text = sprintf(fmt, target.name, type, target.mp_damage)
  513.     else
  514.       fmt = target.actor? ? Vocab::ActorRecovery : Vocab::EnemyRecovery
  515.       text = sprintf(fmt, target.name, type, -target.mp_damage)
  516.       Sound.play_recovery
  517.     end
  518.     @message_window.add_instant_text(text)
  519.     wait(30)
  520.   end
  521.  
  522.   def execute_action_skill                                            #OVERWRITE
  523.     skill = @active_battler.action.skill
  524.     text = @active_battler.name + skill.message1
  525.     resource = skill.resourceof(@active_battler)
  526.     @message_window.add_instant_text(text)
  527.     unless skill.message2.empty?
  528.       wait(10)
  529.       @message_window.add_instant_text(skill.message2)
  530.     end
  531.     targets = @active_battler.action.make_targets
  532.     display_animation(targets, skill.animation_id)
  533.     if resource.tags.include?(:invert)
  534.       resource.value += @active_battler.calc_mp_cost(skill)
  535.     else
  536.       resource.value -= @active_battler.calc_mp_cost(skill)
  537.     end
  538.     $game_temp.common_event_id = skill.common_event_id
  539.     for target in targets
  540.       target.skill_effect(@active_battler, skill)
  541.       display_action_effects(target, skill)
  542.     end
  543.   end
  544.  
  545.   alias old_battle_end battle_end unless $@
  546.   def battle_end(result)
  547.     old_battle_end(result)
  548.     refresh_zsr
  549.   end
  550.  
  551.   alias res_turn_end turn_end unless $@
  552.   def turn_end(actor = nil)
  553.     if actor.nil?
  554.       res_turn_end
  555.       for actor in $game_party.members
  556.         regen_ampx(actor)
  557.       end
  558.     else
  559.       res_turn_end(actor)
  560.       regen_ampx(actor)      
  561.     end
  562.   end
  563.  
  564. end
  565.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement