Dragor

YEA - JP Manager

Dec 2nd, 2012
274
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. #
  3. # ▼ Yanfly Engine Ace - JP Manager v1.00
  4. # -- Last Updated: 2012.01.07
  5. # -- Level: Normal, Hard
  6. # -- Requires: n/a
  7. #
  8. #==============================================================================
  9.  
  10. $imported = {} if $imported.nil?
  11. $imported["YEA-JPManager"] = true
  12.  
  13. #==============================================================================
  14. # ▼ Updates
  15. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  16. # 2012.12.03 - Bug Fixed: No more JP gain when switching class. By SoundReaper.
  17. # 2012.01.07 - Started Script and Finished.
  18. #
  19. #==============================================================================
  20. # ▼ Introduction
  21. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  22. # This script provides a base for JP implementation. JP is a currency similar
  23. # to EXP that's gained through performing actions and leveling up in addition
  24. # to killing enemies. This script provides modifiers that adjust the gains for
  25. # JP through rates, individual gains per skill or item, and per enemy. Though
  26. # this script provides no usage of JP by itself, future Yanfly Engine Ace
  27. # scripts may make use of it.
  28. #
  29. #==============================================================================
  30. # ▼ Instructions
  31. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  32. # To install this script, open up your script editor and copy/paste this script
  33. # to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.
  34. #
  35. # -----------------------------------------------------------------------------
  36. # Actor Notetags - These notetags go in the actors notebox in the database.
  37. # -----------------------------------------------------------------------------
  38. # <jp rate: x%>
  39. # Changes the JP earned rate to x%. This affects JP earned and not JP directly
  40. # gained. If this notetag isn't used, the object will default to 100%.
  41. #
  42. # -----------------------------------------------------------------------------
  43. # Class Notetags - These notetags go in the class notebox in the database.
  44. # -----------------------------------------------------------------------------
  45. # <jp rate: x%>
  46. # Changes the JP earned rate to x%. This affects JP earned and not JP directly
  47. # gained. If this notetag isn't used, the object will default to 100%.
  48. #
  49. # -----------------------------------------------------------------------------
  50. # Skill Notetags - These notetags go in the skills notebox in the database.
  51. # -----------------------------------------------------------------------------
  52. # <jp gain: x>
  53. # When the actor successfully hits an target with this action, the actor will
  54. # earn x JP. If this notetag isn't used, the amount of JP earned will equal to
  55. # the ACTION_JP constant in the module.
  56. #
  57. # -----------------------------------------------------------------------------
  58. # Item Notetags - These notetags go in the items notebox in the database.
  59. # -----------------------------------------------------------------------------
  60. # <jp gain: x>
  61. # When the actor successfully hits an target with this action, the actor will
  62. # earn x JP. If this notetag isn't used, the amount of JP earned will equal to
  63. # the ACTION_JP constant in the module.
  64. #
  65. # -----------------------------------------------------------------------------
  66. # Weapon Notetags - These notetags go in the weapon notebox in the database.
  67. # -----------------------------------------------------------------------------
  68. # <jp rate: x%>
  69. # Changes the JP earned rate to x%. This affects JP earned and not JP directly
  70. # gained. If this notetag isn't used, the object will default to 100%.
  71. #
  72. # -----------------------------------------------------------------------------
  73. # Armour Notetags - These notetags go in the armour notebox in the database.
  74. # -----------------------------------------------------------------------------
  75. # <jp rate: x%>
  76. # Changes the JP earned rate to x%. This affects JP earned and not JP directly
  77. # gained. If this notetag isn't used, the object will default to 100%.
  78. #
  79. # -----------------------------------------------------------------------------
  80. # Enemy Notetags - These notetags go in the enemy notebox in the database.
  81. # -----------------------------------------------------------------------------
  82. # <jp gain: x>
  83. # Changes the amount of JP gained for killing the enemy to x. If this notetag
  84. # isn't used, then the default JP gain will be equal to the amount set in the
  85. # module through the constant ENEMY_KILL.
  86. #
  87. # -----------------------------------------------------------------------------
  88. # State Notetags - These notetags go in the states notebox in the database.
  89. # -----------------------------------------------------------------------------
  90. # <jp rate: x%>
  91. # Changes the JP earned rate to x%. This affects JP earned and not JP directly
  92. # gained. If this notetag isn't used, the object will default to 100%.
  93. #
  94. # -----------------------------------------------------------------------------
  95. # Script Calls - These commands are used with script calls.
  96. # -----------------------------------------------------------------------------
  97. # $game_actors[x].earn_jp(y)
  98. # $game_actors[x].earn_jp(y, z)
  99. # This will cause actor x to earn y amount of JP. JP earned will be modified by
  100. # any JP Rate traits provided through notetags. If z is used, z will be the
  101. # class the JP is earned for.
  102. #
  103. # $game_actors[x].gain_jp(y)
  104. # $game_actors[x].gain_jp(y, z)
  105. # This will cause actor x to gain y amount of JP. JP gained this way will not
  106. # be modified by any JP Rate traits provided through notetags. If z is used,
  107. # z will be the class the JP is gained for.
  108. #
  109. # $game_actors[x].lose_jp(y)
  110. # $game_actors[x].lose_jp(y, z)
  111. # This will cause actor x to lose y amount of JP. JP lost this way will not be
  112. # modified by any JP Rate traits provided through notetags. If z is used, z
  113. # will be the class the JP is lost from.
  114. #
  115. #==============================================================================
  116. # ▼ Compatibility
  117. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  118. # This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
  119. # it will run with RPG Maker VX without adjusting.
  120. #
  121. # This script is compatible with Yanfly Engine Ace - Victory Aftermath v1.03+.
  122. # If you wish to have Victory Aftermath display JP gains, make sure the version
  123. # is 1.03+. Script placement of these two scripts don't matter.
  124. #
  125. #==============================================================================
  126.  
  127. module YEA
  128.   module JP
  129.    
  130.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  131.     # - General JP Settings -
  132.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  133.     # This adjusts the way JP appears visually in your game. Change the icon
  134.     # used and the vocabulary used here. Furthermore, adjust the maximum amount
  135.     # of JP that an actor can have at a time.
  136.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  137.     ICON   = 0           # Icon index used to represent JP.
  138.     VOCAB  = "PC"        # What JP will be called in your game.
  139.     MAX_JP = 99999999    # Maximum JP an actor can have.
  140.    
  141.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  142.     # - Default JP Gain Settings -
  143.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  144.     # The following constants adjust how much JP is earned by default through
  145.     # enemy kills, leveling up, and performing actions.
  146.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  147.     ENEMY_KILL = 20     # JP earned for the whole party.
  148.     LEVEL_UP   = 100    # JP earned when leveling up!
  149.     ACTION_JP  = 5      # JP earned per successful hit.
  150.    
  151.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  152.     # - Victory Message -
  153.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  154.     # This adjusts the victory message shown for the default battle system and
  155.     # the Yanfly Engine Ace - Victory Aftermath script (if used together).
  156.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  157.     VICTORY_MESSAGE   = "%s a gagné %s %s!"
  158.     VICTORY_AFTERMATH = "+%s%s"
  159.    
  160.   end # JP
  161. end # YEA
  162.  
  163. #==============================================================================
  164. # ▼ Editting anything past this point may potentially result in causing
  165. # computer damage, incontinence, explosion of user's head, coma, death, and/or
  166. # halitosis so edit at your own risk.
  167. #==============================================================================
  168.  
  169. module YEA
  170.   module REGEXP
  171.   module BASEITEM
  172.    
  173.     JP_RATE = /<(?:JP_RATE|jp rate):[ ](\d+)([%])>/i
  174.    
  175.   end # BASEITEM
  176.   module USABLEITEM
  177.    
  178.     JP_GAIN = /<(?:JP_GAIN|jp gain):[ ](\d+)>/i
  179.    
  180.   end # USABLEITEM
  181.   module ENEMY
  182.    
  183.     JP_GAIN = /<(?:JP_GAIN|jp gain):[ ](\d+)>/i
  184.    
  185.   end # ENEMY
  186.   end # REGEXP
  187. end # YEA
  188.  
  189. #==============================================================================
  190. # ■ Vocab
  191. #==============================================================================
  192.  
  193. module Vocab
  194.  
  195.   #--------------------------------------------------------------------------
  196.   # new method: self.jp
  197.   #--------------------------------------------------------------------------
  198.   def self.jp
  199.     return YEA::JP::VOCAB
  200.   end
  201.  
  202. end # Vocab
  203.  
  204. #==============================================================================
  205. # ■ Icon
  206. #==============================================================================
  207.  
  208. module Icon
  209.  
  210.   #--------------------------------------------------------------------------
  211.   # self.jp
  212.   #--------------------------------------------------------------------------
  213.   def self.jp; return YEA::JP::ICON; end
  214.    
  215. end # Icon
  216.  
  217. #==============================================================================
  218. # ■ Numeric
  219. #==============================================================================
  220.  
  221. class Numeric
  222.  
  223.   #--------------------------------------------------------------------------
  224.   # new method: group_digits
  225.   #--------------------------------------------------------------------------
  226.   unless $imported["YEA-CoreEngine"]
  227.   def group; return self.to_s; end
  228.   end # $imported["YEA-CoreEngine"]
  229.    
  230. end # Numeric
  231.  
  232. #==============================================================================
  233. # ■ DataManager
  234. #==============================================================================
  235.  
  236. module DataManager
  237.  
  238.   #--------------------------------------------------------------------------
  239.   # alias method: load_database
  240.   #--------------------------------------------------------------------------
  241.   class <<self; alias load_database_jp load_database; end
  242.   def self.load_database
  243.     load_database_jp
  244.     load_notetags_jp
  245.   end
  246.  
  247.   #--------------------------------------------------------------------------
  248.   # new method: load_notetags_jp
  249.   #--------------------------------------------------------------------------
  250.   def self.load_notetags_jp
  251.     groups = [$data_actors, $data_classes, $data_weapons, $data_armors,
  252.       $data_states, $data_enemies, $data_items, $data_skills]
  253.     for group in groups
  254.       for obj in group
  255.         next if obj.nil?
  256.         obj.load_notetags_jp
  257.       end
  258.     end
  259.   end
  260.  
  261. end # DataManager
  262.  
  263. #==============================================================================
  264. # ■ RPG::BaseItem
  265. #==============================================================================
  266.  
  267. class RPG::BaseItem
  268.  
  269.   #--------------------------------------------------------------------------
  270.   # public instance variables
  271.   #--------------------------------------------------------------------------
  272.   attr_accessor :jp_rate
  273.  
  274.   #--------------------------------------------------------------------------
  275.   # common cache: load_notetags_jp
  276.   #--------------------------------------------------------------------------
  277.   def load_notetags_jp
  278.     @jp_rate = 1.0
  279.     #---
  280.     self.note.split(/[\r\n]+/).each { |line|
  281.       case line
  282.       #---
  283.       when YEA::REGEXP::BASEITEM::JP_RATE
  284.         @jp_rate = $1.to_i * 0.01
  285.       #---
  286.       end
  287.     } # self.note.split
  288.     #---
  289.   end
  290.  
  291. end # RPG::BaseItem
  292.  
  293. #==============================================================================
  294. # ■ RPG::UsableItem
  295. #==============================================================================
  296.  
  297. class RPG::UsableItem < RPG::BaseItem
  298.  
  299.   #--------------------------------------------------------------------------
  300.   # public instance variables
  301.   #--------------------------------------------------------------------------
  302.   attr_accessor :jp_gain
  303.  
  304.   #--------------------------------------------------------------------------
  305.   # common cache: load_notetags_jp
  306.   #--------------------------------------------------------------------------
  307.   def load_notetags_jp
  308.     @jp_gain = YEA::JP::ACTION_JP
  309.     #---
  310.     self.note.split(/[\r\n]+/).each { |line|
  311.       case line
  312.       #---
  313.       when YEA::REGEXP::USABLEITEM::JP_GAIN
  314.         @jp_gain = $1.to_i
  315.       #---
  316.       end
  317.     } # self.note.split
  318.     #---
  319.   end
  320.  
  321. end # RPG::UsableItem
  322.  
  323. #==============================================================================
  324. # ■ RPG::Enemy
  325. #==============================================================================
  326.  
  327. class RPG::Enemy < RPG::BaseItem
  328.  
  329.   #--------------------------------------------------------------------------
  330.   # public instance variables
  331.   #--------------------------------------------------------------------------
  332.   attr_accessor :jp_gain
  333.  
  334.   #--------------------------------------------------------------------------
  335.   # common cache: load_notetags_jp
  336.   #--------------------------------------------------------------------------
  337.   def load_notetags_jp
  338.     @jp_gain = YEA::JP::ENEMY_KILL
  339.     #---
  340.     self.note.split(/[\r\n]+/).each { |line|
  341.       case line
  342.       #---
  343.       when YEA::REGEXP::ENEMY::JP_GAIN
  344.         @jp_gain = $1.to_i
  345.       #---
  346.       end
  347.     } # self.note.split
  348.     #---
  349.   end
  350.  
  351. end # RPG::Enemy
  352.  
  353. #==============================================================================
  354. # ■ BattleManager
  355. #==============================================================================
  356.  
  357. module BattleManager
  358.  
  359.   #--------------------------------------------------------------------------
  360.   # alias method: display_exp
  361.   #--------------------------------------------------------------------------
  362.   unless $imported["YEA-VictoryAftermath"]
  363.   class <<self; alias battlemanager_display_exp_jp display_exp; end
  364.   def self.display_exp
  365.     battlemanager_display_exp_jp
  366.     gain_jp
  367.   end
  368.   end # $imported["YEA-VictoryAftermath"]
  369.  
  370.   #--------------------------------------------------------------------------
  371.   # new method: gain_jp
  372.   #--------------------------------------------------------------------------
  373.   def self.gain_jp
  374.     amount = $game_troop.jp_total
  375.     fmt = YEA::JP::VICTORY_MESSAGE
  376.     for member in $game_party.members
  377.       member.earn_jp(amount)
  378.       next if $imported["YEA-VictoryAftermath"]
  379.       value = member.battle_jp_earned.group
  380.       $game_message.add('\.' + sprintf(fmt, member.name, value, Vocab::jp))
  381.     end
  382.     wait_for_message unless $imported["YEA-VictoryAftermath"]
  383.   end
  384.  
  385. end # BattleManager
  386.  
  387. #==============================================================================
  388. # ■ Game_BattlerBase
  389. #==============================================================================
  390.  
  391. class Game_BattlerBase
  392.  
  393.   #--------------------------------------------------------------------------
  394.   # new method: jpr
  395.   #--------------------------------------------------------------------------
  396.   def jpr
  397.     n = 1.0
  398.     if actor?
  399.       n *= self.actor.jp_rate
  400.       n *= self.class.jp_rate
  401.       for equip in equips
  402.         next if equip.nil?
  403.         n *= equip.jp_rate
  404.       end
  405.     end
  406.     for state in states
  407.       next if state.nil?
  408.       n *= state.jp_rate
  409.     end
  410.     return n
  411.   end
  412.  
  413. end # Game_BattlerBase
  414.  
  415. #==============================================================================
  416. # ■ Game_Battler
  417. #==============================================================================
  418.  
  419. class Game_Battler < Game_BattlerBase
  420.  
  421.   #--------------------------------------------------------------------------
  422.   # public instance variables
  423.   #--------------------------------------------------------------------------
  424.   attr_accessor :battle_jp_earned
  425.  
  426.   #--------------------------------------------------------------------------
  427.   # alias method: on_battle_start
  428.   #--------------------------------------------------------------------------
  429.   alias game_battler_on_battle_start_jp on_battle_start
  430.   def on_battle_start
  431.     game_battler_on_battle_start_jp
  432.     @battle_jp_earned = 0
  433.   end
  434.  
  435.   #--------------------------------------------------------------------------
  436.   # alias method: on_battle_end
  437.   #--------------------------------------------------------------------------
  438.   alias game_battler_on_battle_end_jp on_battle_end
  439.   def on_battle_end
  440.     game_battler_on_battle_end_jp
  441.     @battle_jp_earned = 0
  442.   end
  443.  
  444.   #--------------------------------------------------------------------------
  445.   # alias method: item_user_effect
  446.   #--------------------------------------------------------------------------
  447.   alias game_battler_item_user_effect_jp item_user_effect
  448.   def item_user_effect(user, item)
  449.     game_battler_item_user_effect_jp(user, item)
  450.     user.earn_jp(item.jp_gain) if user.actor?
  451.   end
  452.  
  453. end # Game_Battler
  454.  
  455. #==============================================================================
  456. # ■ Game_Actor
  457. #==============================================================================
  458.  
  459. class Game_Actor < Game_Battler
  460.  
  461.   #--------------------------------------------------------------------------
  462.   # alias method: setup
  463.   #--------------------------------------------------------------------------
  464.   alias game_actor_setup_jp setup
  465.   def setup(actor_id)
  466.     game_actor_setup_jp(actor_id)
  467.     init_jp
  468.   end
  469.  
  470.   #--------------------------------------------------------------------------
  471.   # new method: init_jp
  472.   #--------------------------------------------------------------------------
  473.   def init_jp
  474.     @jp = {}
  475.     @jp[@class_id] = 0
  476.   end
  477.  
  478.   #--------------------------------------------------------------------------
  479.   # new method: earn_jp
  480.   #--------------------------------------------------------------------------
  481.   def earn_jp(jp, class_id = nil)
  482.     gain_jp(jp * jpr, class_id)
  483.   end
  484.  
  485.   #--------------------------------------------------------------------------
  486.   # new method: gain_jp
  487.   #--------------------------------------------------------------------------
  488.   def gain_jp(jp, class_id = nil)
  489.     init_jp if @jp.nil?
  490.     class_id = @class_id if class_id.nil?
  491.     @jp[class_id] = 0 if @jp[class_id].nil?
  492.     @jp[class_id] += jp.to_i
  493.     @jp[class_id] = [[@jp[class_id], YEA::JP::MAX_JP].min, 0].max
  494.     @battle_jp_earned = 0 if @battle_jp_earned.nil? && $game_party.in_battle
  495.     @battle_jp_earned += jp.to_i if $game_party.in_battle
  496.   end
  497.  
  498.   #--------------------------------------------------------------------------
  499.   # new method: lose_jp
  500.   #--------------------------------------------------------------------------
  501.   def lose_jp(jp, class_id = nil)
  502.     gain_jp(-jp, class_id)
  503.   end
  504.  
  505.   #--------------------------------------------------------------------------
  506.   # new method: jp
  507.   #--------------------------------------------------------------------------
  508.   def jp(class_id = nil)
  509.     class_id = @class_id if class_id.nil?
  510.     @jp[class_id] = 0 if @jp[class_id].nil?
  511.     return @jp[class_id]
  512.   end
  513.  
  514.   #--------------------------------------------------------------------------
  515.   # alias method: level_up
  516.   #--------------------------------------------------------------------------
  517.   alias game_actor_level_up_jp level_up
  518.   def level_up
  519.     game_actor_level_up_jp
  520.     if $imported["YEA-ClassSystem"] && !@class_switched
  521.       earn_jp(YEA::JP::LEVEL_UP)
  522.     end
  523.   end
  524.  
  525. end # Game_Actor
  526.  
  527. #==============================================================================
  528. # ■ Game_Enemy
  529. #==============================================================================
  530.  
  531. class Game_Enemy < Game_Battler
  532.  
  533.   #--------------------------------------------------------------------------
  534.   # new method: jp
  535.   #--------------------------------------------------------------------------
  536.   def jp
  537.     return enemy.jp_gain
  538.   end
  539.  
  540. end # Game_Enemy
  541.  
  542. #==============================================================================
  543. # ■ Game_Troop
  544. #==============================================================================
  545.  
  546. class Game_Troop < Game_Unit
  547.  
  548.   #--------------------------------------------------------------------------
  549.   # new method: jp_total
  550.   #--------------------------------------------------------------------------
  551.   def jp_total
  552.     dead_members.inject(0) {|r, enemy| r += enemy.jp }
  553.   end
  554.  
  555. end # Game_Troop
  556.  
  557. #==============================================================================
  558. # ■ Window_Base
  559. #==============================================================================
  560.  
  561. class Window_Base < Window
  562.  
  563.   #--------------------------------------------------------------------------
  564.   # new method: draw_actor_jp
  565.   #--------------------------------------------------------------------------
  566.   def draw_actor_jp(actor, dx, dy, dw = 112)
  567.     draw_icon(Icon.jp, dx + dw - 24, dy) if Icon.jp > 0
  568.     dw -= 24 if Icon.jp > 0
  569.     change_color(system_color)
  570.     draw_text(dx, dy, dw, line_height, Vocab::jp, 2)
  571.     dw -= text_size(Vocab::jp).width
  572.     change_color(normal_color)
  573.     draw_text(dx, dy, dw, line_height, actor.jp.group, 2)
  574.   end
  575.  
  576.   #--------------------------------------------------------------------------
  577.   # new method: draw_actor_jp_class
  578.   #--------------------------------------------------------------------------
  579.   def draw_actor_jp_class(actor, class_id, dx, dy, dw = 112)
  580.     draw_icon(Icon.jp, dx + dw - 24, dy) if Icon.jp > 0
  581.     dw -= 24 if Icon.jp > 0
  582.     change_color(system_color)
  583.     draw_text(dx, dy, dw, line_height, Vocab::jp, 2)
  584.     dw -= text_size(Vocab::jp).width
  585.     change_color(normal_color)
  586.     draw_text(dx, dy, dw, line_height, actor.jp(class_id).group, 2)
  587.   end
  588.  
  589. end # Window_Base
  590.  
  591. #==============================================================================
  592. #
  593. # ▼ End of File
  594. #
  595. #==============================================================================
RAW Paste Data