Advertisement
Zetu

AMPX v1.10

Jun 26th, 2011
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 18.40 KB | None | 0 0
  1.                             #======================#
  2.                             #  Z-Systems by: Zetu  #
  3. #===========================#======================#===========================#
  4. #                    *  *  *  Alternate MP X v1.10  *  *  *                    #
  5. #------------------------------------------------------------------------------#
  6. #  Will Overwrite Draw Functions for MP.                                       #
  7. #------------------------------------------------------------------------------#
  8. # Known Compatable Battle Systems:                                             #
  9. #   • Tankentai                                                                #
  10. #------------------------------------------------------------------------------#
  11. # Version History                                                              #
  12. #  1.01 ALPHA                                                                  #
  13. #  1.02                                                                        #
  14. #    * Added Customization (allowing you to easly create your own resources    #
  15. #       without programming knowledge.)                                        #
  16. #    * Added Changes to Resource color (for draw_actor_mp).                    #
  17. #  1.03                                                                        #
  18. #    * Corrected on damage Percent algorithum.                                 #
  19. #  1.04                                                                        #
  20. #    * Updated to define resource by Class (not individual Actor)              #
  21. #  1.05-1.06                                                                   #
  22. #    * Using module instead of global variables.                               #
  23. #    * Now allowing floats for further customization.                          #
  24. #    * Since floats are now allowed, no longer a constant divider on base      #
  25. #        values.                                                               #
  26. #    * Corrected end_turn, since Tankentai uses end_turn(actor).               #
  27. #    * Allowing case insensitivity in DEF.                                     #
  28. #  1.07-1.09                                                                   #
  29. #    * Fixed Refresh (or lack of) glitch (so that the proper values are        #
  30. #        displayed.)                                                           #
  31. #    * Fixed healing items and added notetags.                                 #
  32. #    * Fixed degen when healed.                                                #
  33. #    * Fixed regen when dead.                                                  #
  34. #    * Fixed display on MP damage/Healing (to show custom resource)            #
  35. #  1.10                                                                        #
  36. #    * OVERHAUL                                                                #
  37. #    * Multi Resource Types                                                    #
  38. #=#==========================================================================#=#
  39.   # DEF[type] = [0, 1, 2, ..., 8]                                            #
  40.   # 0 = Defines amount of resource out of battle.                            #
  41.   #   0 = Default (Keep same amount)                                         #
  42.   #   1 = Set to 0                                                           #
  43.   #   2 = Set to Full                                                        #
  44.   # 1 = Defines base resource Regeneration (Float allowed)                   #
  45.   # 2 = Regen Type                                                           #
  46.   #   "Normal" = Multiply base equal to damage * Recomended for max 100 *    #
  47.   #   "Atk"/"Def"/"HP"/"MaxHP"/"MP"/"MaxMP"/"Agi"/"Spi" = Multiply equal to  #
  48.   #       respective user's stat.                                            #
  49.   # 3 = On Damage change to resource (Multiplier / float allowed)            #
  50.   # 4 = On Damage change to resource (Type)                                  #
  51.   #   "Normal" = Gain [3]*Damage MP.                                         #
  52.   #   "Percent" = Gain [3]*(Ratio of damage to MaxMP) as percent to MP       #
  53.   # 5 = Max Resource Value                                                   #
  54.   #   0 = Default (Defined by Database, increases with level)                #
  55.   #   1 = 100                                                                #
  56.   #--------------------------------------------------------------------------#
  57.   # SPEC[type]                                                               #
  58.   # 0 = Vocab of Resource                                                    #
  59.   # 1 = Letter to abbreviate Resource                                        #
  60.   # 2 and 3 = System Color to define resource bar color (as gradient)        #
  61.   # 4 = System Color to define text for particular resource.
  62.   #--------------------------------------------------------------------------#
  63.   #  For mp recovery items, use <regen: TYPE> to force the item to only      #
  64.   #  regenerate that particular mp resource.                                 #
  65.   #==========================================================================#
  66. module Z
  67.   module AMPX
  68.     DEF = {#
  69.       :mana   => [0, 0.05,  "MaxMP",    0,  "Normal", 0, "M", 22, 23],
  70.       :rage   => [1,    0, "Normal",    2, "Percent", 1, "R", 10,  2],
  71.       :energy => [2,   20, "Normal",    0,  "Normal", 1, "E", 14,  6],
  72.       :focus  => [2,   30, "Normal", -1.5, "Percent", 1, "F", 11,  3]}
  73.      
  74.     SPEC = {
  75.       :mana   => ["Mana",   "M", 22, 23, 22],
  76.       :rage   => ["Rage",   "R", 10,  2, 10],
  77.       :energy => ["Energy", "E", 14,  6, 14],
  78.       :focus  => ["Focus",  "F", 11,  3, 11]}
  79.  
  80.     # Customize Char Res types by Class ID
  81.     CLASS = {#It is recommended to have 2 at MOST!
  82.       2 => [:mana, :rage],
  83.       3 => [:energy],
  84.       4 => [:energy, :focus]
  85.     } # DO NOT REMOVE! (If class is not defined, will return [DEF_RES]
  86.     DEF_RES = :mana
  87.     RECOLOR_SINGLE = true # If false, actors with only one resource will not
  88.        # recolor MP cost to match the resource type.
  89.   #==========================================================================#
  90.   # In Skill Notes                                                           #
  91.   #   <ampx: *>  => Skill uses * resource (refer to SPEC[resource][0])       #
  92.   #   <regen: *> => MP healing is done to * resource. (Also works in Item)   #
  93. #=#======#======================#====#================================#======#=#
  94. #--------#                      #----# DO NOT EDIT PAST THIS POINT!!! #--------#
  95. #--------# End of Customization #----# Editing will cause death by    #--------#
  96. #--------#                      #----# brain asplosions.              #--------#
  97. #========#======================#====#================================#========#
  98.     def self.symbol(type)
  99.       for resource in Z::resources
  100.         return resource if SPEC[resource][0].upcase == type[0].upcase
  101.       end
  102.       return DEF_RES
  103.     end
  104.   end
  105.   def self.resources
  106.     return AMPX::DEF.keys
  107.   end
  108. end
  109. $zsys = {} if $zsys.nil?
  110. $zsys["AltRes"] = true
  111.  
  112. class RPG::Skill
  113.  
  114.   def resource(default = Z::AMPX::DEF_RES)
  115.     self.note.scan(/<ampx[:][ ](.*)>/i){|type| return Z::AMPX::symbol(type)}
  116.     return default
  117.   end
  118.  
  119. end
  120.  
  121. class Game_Actor < Game_Battler
  122.  
  123.   alias ampx_setup setup
  124.   def setup(actor_id)
  125.     ampx_setup(actor_id)
  126.     @ampx = {}
  127.     for resource in self.resources
  128.       @ampx[resource] = Game_Resources.new(resource, self)
  129.     end
  130.   end
  131.  
  132.   def resources
  133.     result = Z::AMPX::CLASS[self.class_id]
  134.     return result.nil? ? [Z::AMPX::DEF_RES] : result
  135.   end
  136.  
  137.   def ampx(resource = Z::AMPX::DEF_RES)
  138.     return 0 if @ampx[resource].nil?
  139.     return @ampx[resource].value
  140.   end
  141.  
  142.   def set_ampx(value, resource = Z::AMPX::DEF_RES)
  143.     return if @ampx[resource].nil?
  144.     @ampx[resource].value = value
  145.   end
  146.  
  147.   def var_ampx(value, resource = Z::AMPX::DEF_RES)
  148.     return if @ampx[resource].nil?
  149.     @ampx[resource].value += value
  150.   end
  151.  
  152.   def maxampx(resource = Z::AMPX::DEF_RES)
  153.     case Z::AMPX::DEF[resource][5]
  154.     when 0
  155.       return maxmp
  156.     when 1
  157.       return 100
  158.     end
  159.   end
  160.  
  161.   def ampx_on_hit(damage)
  162.     return unless damage > 0
  163.     for resource in self.resources
  164.       base = Z::AMPX::DEF[resource][3]
  165.       case Z::AMPX::DEF[resource][4].upcase
  166.       when "PERCENT"
  167.         ratio = (100*damage)/self.maxhp
  168.         self.var_ampx((100 * (ratio * base) / self.maxampx(resource)).to_i, resource)
  169.       when "NORMAL"
  170.         self.var_ampx((damage*base).to_i, resource)
  171.       end
  172.     end
  173.   end
  174.  
  175.   alias old_execute_damage execute_damage
  176.   def execute_damage(user)
  177.     old_execute_damage(user)
  178.     ampx_on_hit(@hp_damage)
  179.   end
  180.  
  181.   def item_effective?(user, item)
  182.     if item.for_dead_friend? != dead?
  183.       return false
  184.     end
  185.     if not $game_temp.in_battle and item.for_friend?
  186.       return item_test(user, item)
  187.     end
  188.     return true
  189.   end
  190.  
  191.   def item_test(user, item, resource = Z::AMPX::DEF_RES)              #OVERWRITE
  192.     tester = self.clone
  193.     tester.make_obj_damage_value(user, item)
  194.     tester.apply_state_changes(item)
  195.     if tester.hp_damage < 0 or tester.calc_hp_recovery(user, item) > 0
  196.       return true if tester.hp < tester.maxhp
  197.     end
  198.     if tester.mp_damage < 0 or tester.calc_mp_recovery(user, item, tester) > 0
  199.       return true if tester.ampx(resource) < tester.maxampx(resource)
  200.     end
  201.     return true unless tester.added_states.empty?
  202.     return true unless tester.removed_states.empty?
  203.     return true if item.parameter_type > 0
  204.     return false
  205.   end
  206.  
  207.   def calc_mp_recovery(user, item, target, resource=Z::AMPX::DEF_RES) #OVERWRITE
  208.     result = maxmp * item.mp_recovery_rate / 100 + item.mp_recovery
  209.     result *= 2 if user.pharmacology
  210.     $type = resource
  211.     for line in item.note.split(/[\r\n]+/)
  212.       case line
  213.       when /<regen:[ ](.*)>/i
  214.         $type = Z::AMPX::symbol($1)
  215.         return result
  216.       end
  217.     end
  218.     return result
  219.   end
  220.  
  221.   def item_effect(user, item)                                         #OVERWRITE
  222.     clear_action_results
  223.     unless item_effective?(user, item)
  224.       @skipped = true
  225.       return
  226.     end
  227.     if rand(100) >= calc_hit(user, item)
  228.       @missed = true
  229.       return
  230.     end
  231.     if rand(100) < calc_eva(user, item)
  232.       @evaded = true
  233.       return
  234.     end
  235.     hp_recovery = calc_hp_recovery(user, item)
  236.     mp_recovery = calc_mp_recovery(user, item, self)
  237.     make_obj_damage_value(user, item)
  238.     @hp_damage -= hp_recovery
  239.     @mp_damage -= mp_recovery
  240.     make_obj_absorb_effect(user, item)
  241.     execute_damage(user)
  242.     item_growth_effect(user, item)
  243.     if item.physical_attack and @hp_damage == 0
  244.       return                                    
  245.     end
  246.     apply_state_changes(item)
  247.   end
  248.  
  249.   def skill_can_use?(skill)
  250.     return false unless skill.is_a?(RPG::Skill)
  251.     return false unless movable?
  252.     return false if silent? and skill.spi_f > 0
  253.     return false unless self.resources.include?(skill.resource)
  254.     return false if calc_mp_cost(skill) > self.ampx(skill.resource(self.resources[0]))
  255.     if $game_temp.in_battle
  256.       return skill.battle_ok?
  257.     else
  258.       return skill.menu_ok?
  259.     end
  260.   end
  261.  
  262. end
  263.  
  264. class Game_Resources
  265.  
  266.   def initialize(resource, actor)
  267.     @actor = actor
  268.     @resource = resource
  269.     @value = Z::AMPX::DEF[resource][0] == 1 ? 0 : @actor.maxampx(resource)
  270.   end
  271.  
  272.   def value
  273.     return @value
  274.   end
  275.  
  276.   def value=(new_value)
  277.     @value = [[0, new_value].max, @actor.maxampx(@resource)].min
  278.   end
  279.  
  280.   def resource
  281.     return @resource
  282.   end
  283.  
  284. end
  285.  
  286. class Window_Base < Window
  287.  
  288.   def draw_actor_ampx(actor, x, y, resource, width = 120)
  289.     draw_actor_ampx_gauge(actor, x, y, resource, width)
  290.     self.contents.font.color = system_color
  291.     self.contents.draw_text(x, y, 30, WLH, Z::AMPX::SPEC[resource][1])
  292.     self.contents.font.color = mp_color(actor)
  293.     last_font_size = self.contents.font.size
  294.     xr = x + width
  295.     if width < 120
  296.       self.contents.draw_text(xr - 44, y, 44, WLH, actor.ampx(resource), 2)
  297.     else
  298.       self.contents.draw_text(xr - 99, y, 44, WLH, actor.ampx(resource), 2)
  299.       self.contents.font.color = normal_color
  300.       self.contents.draw_text(xr - 55, y, 11, WLH, "/", 2)
  301.       self.contents.draw_text(xr - 44, y, 44, WLH, actor.maxampx(resource), 2)
  302.     end
  303.   end
  304.  
  305.   def draw_actor_mp(actor, x, y, width = 120)
  306.     size_x = width / actor.resources.size
  307.     offset = size_x
  308.     unless size_x == width
  309.       offset += 1
  310.       size_x -= 1
  311.     end
  312.     for i in 0...actor.resources.size
  313.       draw_actor_ampx(actor, x + offset*i, y, actor.resources[i], size_x)
  314.     end
  315.   end
  316.  
  317.   def draw_actor_ampx_gauge(actor, x, y, resource, width = 120)
  318.     gw = width * actor.ampx(resource) / [actor.maxampx(resource), 1].max
  319.     gc1 = text_color(Z::AMPX::SPEC[resource][2])
  320.     gc2 = text_color(Z::AMPX::SPEC[resource][3])
  321.     self.contents.fill_rect(x, y + WLH - 8, width, 6, gauge_back_color)
  322.     self.contents.gradient_fill_rect(x, y + WLH - 8, gw, 6, gc1, gc2)
  323.   end
  324.  
  325. end
  326.  
  327. class Window_BattleStatus < Window_Selectable
  328.  
  329.   def draw_item(index)
  330.     rect = item_rect(index)
  331.     rect.x += 4
  332.     rect.width -= 8
  333.     self.contents.clear_rect(rect)
  334.     self.contents.font.color = normal_color
  335.     actor = $game_party.members[index]
  336.     draw_actor_state(actor, 114, rect.y, 48)
  337.     draw_actor_name(actor, 4, rect.y)
  338.     draw_actor_hp(actor, 124, rect.y, 120)
  339.     draw_actor_mp(actor, 260, rect.y, 120)
  340.   end
  341.  
  342. end
  343.  
  344. class Window_Skill < Window_Selectable
  345.  
  346.   def draw_item(index)
  347.     rect = item_rect(index)
  348.     self.contents.clear_rect(rect)
  349.     skill = @data[index]
  350.     if skill != nil
  351.       rect.width -= 4
  352.       enabled = @actor.skill_can_use?(skill)
  353.       draw_item_name(skill, rect.x, rect.y, enabled)
  354.       resource = skill.resource(@actor.resources[0])
  355.       bool = Z::AMPX::RECOLOR_SINGLE and @actor.resources.size == 1
  356.       color = text_color(Z::AMPX::RECOLOR_SINGLE ? Z::AMPX::SPEC[resource][2] : 0)
  357.       self.contents.font.color = color
  358.       self.contents.draw_text(rect, @actor.calc_mp_cost(skill), 2)
  359.     end
  360.   end
  361.  
  362. end
  363.  
  364. class Scene_Base
  365.   alias old_main main
  366.   def main
  367.     old_main
  368.     refresh_zsr
  369.   end
  370.  
  371.   def refresh_zsr
  372.     for actor in $game_party.members
  373.       for resource in actor.resources
  374.         case Z::AMPX::DEF[resource][0]
  375.         when 1
  376.           actor.set_ampx(0, resource)
  377.         when 2
  378.           actor.set_ampx(actor.maxampx(resource), resource)
  379.         end
  380.       end
  381.     end
  382.   end
  383.  
  384. end
  385.  
  386. class Scene_Battle < Scene_Base
  387.  
  388.   alias old_battle_end battle_end
  389.   def battle_end(result)
  390.     old_battle_end(result)
  391.     refresh_zsr
  392.   end
  393.  
  394.   alias res_turn_end turn_end
  395.   def turn_end(actor = nil)
  396.     if actor != nil
  397.       res_turn_end(actor)
  398.       regen_mp(actor)
  399.     else
  400.       res_turn_end
  401.       for actor in $game_party.members
  402.         regen_mp(actor)
  403.       end
  404.     end
  405.   end
  406.  
  407.   def regen_mp(actor)
  408.     return if actor.dead?
  409.     for resource in actor.resources
  410.       base = Z::DEF[resource][1]
  411.       var = 0
  412.       case Z::DEF[resource][2].upcase
  413.       when "NORMAL"
  414.         value = base.to_i
  415.       when "ATK", "ATTACK"
  416.         value = (base*actor.atk).to_i
  417.       when "DEF", "DEFENSE"
  418.         value = (base*actor.def).to_i
  419.       when "HP", "HIT POINTS"
  420.         value = (base*actor.hp).to_i
  421.       when "MP", "MAGIC POINTS"
  422.         value = (base*actor.mp).to_i
  423.       when "MAXHP"
  424.         value = (base*actor.maxhp).to_i
  425.       when "MAXMP"
  426.         value = (base*actor.maxampx(resource)).to_i
  427.       when "AGI", "AGILITY"
  428.         value = (base*actor.agi).to_i
  429.       when "SPI", "SPIRIT"
  430.         value = (base*actor.spi).to_i
  431.       end
  432.       actor.var_ampx(value, resource) unless var == 0
  433.     end
  434.   end
  435.  
  436.   def refresh_zsr
  437.     for actor in $game_party.members
  438.       for resource in actor.resources
  439.         case Z::DEF[resource][0]
  440.         when 1
  441.           actor.var_ampx(0, resource)
  442.         when 2
  443.           actor.ampx(actor.maxampx(resource), resource)
  444.         end
  445.       end
  446.     end
  447.   end
  448.  
  449.   alias zsres_update_actor_command_selection update_actor_command_selection
  450.   def update_actor_command_selection
  451.     zsres_update_actor_command_selection
  452.     @status_window.refresh
  453.   end
  454.  
  455.   alias zsres_update_party_command_selection update_party_command_selection
  456.   def update_party_command_selection
  457.     zsres_update_party_command_selection
  458.     @status_window.refresh
  459.   end
  460.  
  461.   def display_mp_damage(target, obj = nil)                            #OVERWRITE
  462.     return if target.dead?
  463.     return if target.mp_damage == 0
  464.     type = "MP!"
  465.     else
  466.     if target.absorbed                      # Absorb
  467.       fmt = target.actor? ? Vocab::ActorDrain : Vocab::EnemyDrain
  468.       text = sprintf(fmt, target.name, type, target.mp_damage)
  469.     elsif target.mp_damage > 0              # Damage
  470.       fmt = target.actor? ? Vocab::ActorLoss : Vocab::EnemyLoss
  471.       text = sprintf(fmt, target.name, type, target.mp_damage)
  472.     else                                    # Recovery
  473.       fmt = target.actor? ? Vocab::ActorRecovery : Vocab::EnemyRecovery
  474.       text = sprintf(fmt, target.name, type, -target.mp_damage)
  475.       Sound.play_recovery
  476.     end
  477.     @message_window.add_instant_text(text)
  478.     wait(30)
  479.   end
  480.  
  481.   def execute_action_skill
  482.     skill = @active_battler.action.skill
  483.     resource = @skill.resource(@active_battler.resources[0])
  484.     text = @active_battler.name + skill.message1
  485.     @message_window.add_instant_text(text)
  486.     unless skill.message2.empty?
  487.       wait(10)
  488.       @message_window.add_instant_text(skill.message2)
  489.     end
  490.     targets = @active_battler.action.make_targets
  491.     display_animation(targets, skill.animation_id)
  492.     @active_battler.ampx_var(-@active_battler.calc_mp_cost(skill), resource)
  493.     $game_temp.common_event_id = skill.common_event_id
  494.     for target in targets
  495.       target.skill_effect(@active_battler, skill)
  496.       display_action_effects(target, skill)
  497.     end
  498.   end
  499.  
  500. end
  501.  
  502. class Scene_Skill < Scene_Base
  503.  
  504.   def use_skill_nontarget
  505.     Sound.play_use_skill
  506.     resource = @skill.resource(@actor.resources[0])
  507.     @actor.var_ampx(-@actor.calc_mp_cost(@skill), resource)
  508.     @status_window.refresh
  509.     @skill_window.refresh
  510.     @target_window.refresh
  511.     if $game_party.all_dead?
  512.       $scene = Scene_Gameover.new
  513.     elsif @skill.common_event_id > 0
  514.       $game_temp.common_event_id = @skill.common_event_id
  515.       $scene = Scene_Map.new
  516.     end
  517.   end
  518.  
  519. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement