Advertisement
Guest User

Yanfly Engine Ace – JP Manager v1.00 Edit

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