Vlue

MP Levels

May 18th, 2014
121
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #MP Levels v0.1b
  2. #Notetags:
  3. # Skills:
  4. #  <MP_LEVEL level> - determines level of magic from 0-3
  5. #
  6. # Skills and Items:
  7. #  <MP_DAMAGE level amount> - skill or item damages mp level that much
  8. #  <MP_HEAL level amount> - opposite of damage
  9. #
  10. # Actors:
  11. #  <MP_LEVEL level 0,1,2,3> - Determines max mp for each level
  12. #
  13. # Equipment:
  14. #  <MP_LEVEL level amount> - Increases max mp for level by amount
  15.  
  16. #True to display skill uses remaining, false to display skill cost
  17. DISPLAY_SKILL_USES = true
  18.  
  19. class Game_BattlerBase
  20.   def mmp_reset
  21.     [4,3,2,1]
  22.   end
  23.   def mmp(lvl = -1)
  24.     return mmp_reset if lvl == -1
  25.     mmp_reset[lvl]
  26.   end
  27.   def mp(lvl = 0)
  28.     @mp[lvl]
  29.   end
  30.   def mp=(mp)
  31.   end
  32.   def set_mp(lvl, mp)
  33.     @mp[lvl] = mp
  34.     @mp[lvl] = [[@mp[lvl],0].max,mmp(lvl)].min
  35.   end
  36.   def gain_mp(lvl, mp)
  37.     set_mp(lvl, @mp[lvl] + mp)
  38.   end
  39.   def skill_mp_cost(skill)
  40.     skill.mp_cost
  41.   end
  42.   def skill_mp_level(skill)
  43.     skill.mp_level
  44.   end
  45.   def pay_skill_cost(skill)
  46.     gain_mp(skill_mp_level(skill), -skill_mp_cost(skill))
  47.     self.tp -= skill_tp_cost(skill)
  48.   end
  49.   def skill_cost_payable?(skill)
  50.     return false unless tp >= skill_tp_cost(skill)
  51.     mp(skill_mp_level(skill)) >= skill_mp_cost(skill)
  52.   end
  53.   def refresh
  54.     state_resist_set.each {|state_id| erase_state(state_id) }
  55.     @hp = [[@hp, mhp].min, 0].max
  56.     @hp == 0 ? add_state(death_state_id) : remove_state(death_state_id)
  57.   end
  58.   def recover_all
  59.     clear_states
  60.     @hp = mhp
  61.     @mp = mmp_reset
  62.   end
  63. end
  64.  
  65. class Game_Battler
  66.   alias mp_level_ed execute_damage
  67.   def execute_damage(user)
  68.     mp_level_ed(user)
  69.     mp_dam = @result.mp_lvl_dam
  70.     mp_drn = @result.mp_lvl_drn
  71.     mp_heal = @result.mp_lvl_heal
  72.     gain_mp(mp_dam[0], -mp_dam[1])
  73.     gain_mp(mp_drn[0], -mp_drn[1])
  74.     #user.gain_mp(mp_drn[0], mp_drn[1])
  75.     gain_mp(mp_heal[0], -mp_heal[1])
  76.   end
  77.   def item_effect_recover_mp(user, item, effect)
  78.   end
  79.   def regenerate_mp
  80.   end
  81. end
  82.  
  83. class Game_Actor
  84.   def mmp_reset
  85.     mp_level_bonus(mp_level_base)
  86.   end
  87.   def mp_level_base
  88.     mp_level = []
  89.     iter = self.level
  90.     while mp_level.empty?
  91.       if self.actor.note =~ /<MP_LEVEL #{iter} (\d+),(\d+),(\d+),(\d+)>/
  92.         return mp_level = [$1.to_i,$2.to_i,$3.to_i,$4.to_i]
  93.       end
  94.       iter -= 1
  95.       return mp_level = [0,0,0,0] if iter == 0
  96.     end
  97.   end
  98.   def mp_level_bonus(mp_level)
  99.     self.equips.each_with_index do |item, i|
  100.       next unless item
  101.       if item.note =~ /<MP_LEVEL 0 (\d+)/
  102.         mp_level[0] += $1.to_i
  103.       end
  104.       if item.note =~ /<MP_LEVEL 1 (\d+)/
  105.         mp_level[1] += $1.to_i
  106.       end
  107.       if item.note =~ /<MP_LEVEL 2 (\d+)/
  108.         mp_level[2] += $1.to_i
  109.       end
  110.       if item.note =~ /<MP_LEVEL 3 (\d+)/
  111.         mp_level[3] += $1.to_i
  112.       end
  113.     end
  114.     mp_level
  115.   end
  116. end
  117.  
  118. class Game_ActionResult
  119.   alias mp_level_md make_damage
  120.   def make_damage(value, item)
  121.     mp_level_md(value, item)
  122.     @mp_damage = 0
  123.     @mp_drain = 0
  124.     @mp_level_damage = item.mp_damage
  125.     @mp_level_drain = item.mp_drain
  126.     @mp_level_heal = item.mp_heal
  127.     @success = true if @mp_level_damage[1] > 0
  128.     @success = true if @mp_level_drain[1] > 0
  129.     @success = true if @mp_level_heal[1] > 0
  130.   end
  131.   def mp_lvl_dam
  132.     @mp_level_damage
  133.   end
  134.   def mp_lvl_drn
  135.     @mp_level_drain
  136.   end
  137.   def mp_lvl_heal
  138.     @mp_level_heal
  139.   end
  140.   def mp_dam_lvl_text
  141.     text = @battler.name + " lost " + @mp_level_damage[1].to_s + " Level "
  142.     text += @mp_level_damage[0].to_s + Vocab::mp_a
  143.   end
  144.   def mp_dam_heal_text
  145.     text = @battler.name + " gained " + @mp_level_heal[1].to_s + " Level "
  146.     text += @mp_level_heal[0].to_s + Vocab::mp_a
  147.   end
  148. end
  149.  
  150. class RPG::Skill < RPG::UsableItem
  151.   def mp_level
  152.     self.note =~ /<MP_LEVEL (\d+)>/ ? $1.to_i : 0
  153.   end
  154. end
  155.  
  156. class RPG::UsableItem
  157.   def mp_damage
  158.     self.note =~ /<MP_DAMAGE (\d+) (\d+)>/ ? [$1.to_i,$2.to_i] : [0,0]
  159.   end
  160.   def mp_drain
  161.     self.note =~ /<MP_DRAIN (\d+) (\d+)>/ ? [$1.to_i,$2.to_i] : [0,0]
  162.   end
  163.   def mp_heal
  164.     self.note =~ /<MP_HEAL (\d+) (\d+)>/ ? [$1.to_i,$2.to_i] : [0,0]
  165.   end
  166. end
  167.  
  168. class Window_Base
  169.   def mp_color(actor, lvl = 0)
  170.     return crisis_color if actor.mp(lvl) == 0
  171.     return normal_color
  172.   end
  173.   def draw_actor_mp(actor, x, y, width = 124)
  174.     change_color(system_color)
  175.     draw_text(x, y, 24, line_height, Vocab::mp_a)
  176.     4.times do |i|
  177.       change_color(mp_color(actor, i))
  178.       draw_text(x + 30 + i*24,y,width,line_height,actor.mp(i))
  179.       change_color(normal_color)
  180.       draw_text(x + 30 + i*24+12,y,width,line_height,"/") unless i == 3
  181.     end
  182.   end
  183. end
  184.  
  185. class Window_BattleLog
  186.   def display_mp_damage(target, item)
  187.     return if target.dead?
  188.     if target.result.mp_damage == 0
  189.       Sound.play_recovery if target.result.mp_damage < 0
  190.       add_text(target.result.mp_damage_text)
  191.       wait
  192.     elsif target.result.mp_lvl_dam[1] > 0
  193.       add_text(target.result.mp_dam_lvl_text)
  194.       wait
  195.     elsif target.result.mp_lvl_heal[1] > 0
  196.       add_text(target.result.mp_heal_lvl_text)
  197.       wait
  198.     end
  199.   end
  200. end
  201.  
  202. class Window_SkillList
  203.   def draw_skill_cost(rect, skill)
  204.     if @actor.skill_tp_cost(skill) > 0
  205.       change_color(tp_cost_color, enable?(skill))
  206.       draw_text(rect, @actor.skill_tp_cost(skill), 2)
  207.     elsif @actor.skill_mp_cost(skill) > 0
  208.       change_color(mp_cost_color, enable?(skill))
  209.       if DISPLAY_SKILL_USES
  210.     text = (@actor.mp(skill.mp_level) / @actor.skill_mp_cost(skill)).to_s
  211.       else
  212.         text = "Lvl " + skill.mp_level.to_s + ": " + @actor.skill_mp_cost(skill).to_s
  213.       end
  214.       draw_text(rect, text, 2)
  215.     end
  216.   end
  217. end
  218.  
  219. class Game_Enemy
  220.   alias mp_lvl_init initialize
  221.   def initialize(index, enemy_id)
  222.     mp_lvl_init(index, enemy_id)
  223.     @mp = mmp_reset
  224.   end
  225. end
  226.  
  227. class Window_BattleStatus
  228.   def draw_gauge_area_without_tp(rect, actor)
  229.     draw_actor_hp(actor, rect.x - 30, rect.y, 130)
  230.     draw_actor_mp(actor, rect.x + 106,  rect.y, 76)
  231.   end
  232. end
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×