设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 136|回复: 0

[转载发布] Trilobytes VX Ace #2: Bonus Stat Allocation (v1.11 now available!)

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    9071

    主题

    864

    回帖

    6万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    58883
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    68848

    灌水之王

    发表于 2026-8-2 21:42:31 | 显示全部楼层 |阅读模式


    Bonus Stat Allocation version 1.11
    Created by Trihan


    Introduction
    This script allows you to open a scene to assign a specified number of bonus points to an actor's stats. It is highly configurable and can be used for a variety of things. It was originally commissioned by Clyve for a mercenary system, but as it's been 5 years since the commission request and Clyve no longer appears to be part of the community, I decided to release it to the public.

    Features
    - Open a scene to raise an actor's stats using bonus point allocation.
    - Customise icons, stat labels, which stats to show, points required to raise, and points to raise the stat by.
    - Can specify a variable that will be set to 1 when assignment is complete if you want to do something after the scene closes.

    Screenshots
    Spoiler: Screenshots










    How to Use
    Call the scene by using the script call "bonus_stats(actor_id, points)" replacing actor_id with the ID of the actor you want to assign points to, and points with the number of points to give them. Configuration options such as number of points required to raise are explained in the relevant section of the script.

    Demo
    No demo available at present.

    Script
    Spoiler: Script
                    Code:       
    1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
    2. #  ▼ Bonus stats script
    3. #  Author: Trihan
    4. #  Version 1.11
    5. #  Release date: 10/06/2012
    6. #
    7. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
    8. #-------------------------------------------------------------------------------------------------
    9. #  ▼ UPDATES
    10. #-------------------------------------------------------------------------------------------------
    11. # # 03/07/2020. Fixed a bug where setting stat locks would permanently break the
    12. # # list. Added MDEF to default stat list. Changed positive change green colour
    13. # # to be more easily-readable. Added text to show no assignable stats in the
    14. # # event that all available stats are locked.
    15. # # 12/06/2012. Fixed a bug where the actor's initial stat values would show
    16. # # even when calling the script multiple times.
    17. # # 10/06/2012. Added the actor's name, level and class to the title.
    18. # # 10/06/2012. Added a full HP/MP heal to the actor so you don't have to do it
    19. # # with an event command afterwards.
    20. # # 10/06/2012. Fixed a bug where the confirm and cancel windows weren't
    21. # # handling input properly.
    22. # # 10/06/2012. Fixed a bug where the first event command after the script call
    23. # # wouldn't run.
    24. # # 10/06/2012. Fixed a lag issue with the update method of the stats window.
    25. # # 10/06/2012. Added an explanatory line to each stat that shows how many
    26. # # points it requires to raise and how many points it will rise by.
    27. # # 10/06/2012. Added the class notetags for locking out stats.
    28. # # 10/06/2012. Changed the assignment so that the appropriate number of points
    29. # # are calculated and removed automatically, rather than having to assign each
    30. # # one individually.
    31. # # 10/06/2012. Added another array to determine how many points a stat raises
    32. # # by, which is a part of the original commission I forgot to put in.
    33. # # 10/06/2012. Original release
    34. #-------------------------------------------------------------------------------------------------
    35. #  ▼ TERMS OF USAGE
    36. #-------------------------------------------------------------------------------------------------
    37. # #  You are free to adapt this work to suit your needs.
    38. # #  You can use this work for commercial purposes if you like it.
    39. # #  Credit is appreciated.
    40. # #
    41. # # For support:
    42. # # rmrk.net
    43. # # rpgmaker.net
    44. #-------------------------------------------------------------------------------------------------
    45. #  ▼ INTRODUCTION
    46. #-------------------------------------------------------------------------------------------------
    47. # # Enables a script call to show a window via which you can assign a number of
    48. # # bonus points to an actor's stats. This was originally commissioned for a
    49. # # mercenary system but can easily be tailored to other uses.
    50. # #
    51. #-------------------------------------------------------------------------------------------------
    52. #  ▼ INSTRUCTIONS
    53. #-------------------------------------------------------------------------------------------------
    54. # # In an event, put the following in a call script command:
    55. # #
    56. # # bonus_stats(char, points)
    57. # #
    58. # # Where char is the ID number of the actor to whom you wish to assign points,
    59. # # and points is the number of assignable points to give the player.
    60. # #
    61. # # Class notetags:
    62. # #
    63. # # <bonus_lock X>
    64. # #
    65. # # Where X is the ID of the stat as determined by the param_base property of
    66. # # Game_Actor. If a stat is locked out, it won't appear in the window for a
    67. # # character of that class even if it's included in the stats array.
    68. # #
    69. # # You can customise which stats can be added to and how many bonus points it
    70. # # take to raise the stat. More on that in the editable section.
    71. #-------------------------------------------------------------------------------------------------
    72. #  ▼ COMPATIBILITY
    73. #-------------------------------------------------------------------------------------------------
    74. # # List of aliases and overwrites:
    75. # #
    76. # # RPG::Class
    77. # # stat_locks (new attr method)
    78. # # load_class_notetags (new method)
    79. # #
    80. # # DataManager
    81. # # load_database (alias)
    82. # # load_class_notetags (new method)
    83. # #
    84. # # Game_Interpreter
    85. # # bonus_stats (new method)
    86. # #
    87. # # As most functionality in this script is done via custom classes and methods,
    88. # # there shouldn't be any compatibility issues unless using a script that also
    89. # # deals with bonus_stats which may feasibly have the same names for things.
    90. #-------------------------------------------------------------------------------------------------
    91. $imported = {} if $imported.nil?
    92. $imported['statbonus'] = true
    93. BON_CONFIG = {
    94. # ------------------------------------------------------------------------------
    95. # EDITABLE REGION BEGINS HERE
    96. # ------------------------------------------------------------------------------
    97. # :icons - Determines the icons that will be shown for each stat. It is simply
    98. # an array of icon IDs from the icon sheet.
    99. # ------------------------------------------------------------------------------
    100.   :icons  =>  [122, 10, 11, 13, 14, 15, 12, 125],
    101. # ------------------------------------------------------------------------------
    102. # :labels - Determines the labels that will be shown for each stat in the bonus
    103. # window.
    104. # ------------------------------------------------------------------------------
    105.   :labels =>  ["HP", "MP", "Atk", "Def", "Mag", "Mdf", "Agi", "Luck"],
    106. # ------------------------------------------------------------------------------
    107. # :stats - Determines which stats will be shown in the window. As stated above,
    108. # if a stat is locked out for the actor's class (with <bonus_lock X>) it won't
    109. # be shown in the window even if it's included here.
    110. # ------------------------------------------------------------------------------
    111.   :stats  =>  [0, 1, 2, 3, 4, 5, 6, 7],
    112. # ------------------------------------------------------------------------------
    113. # :costs - Determines how many bonus points it takes to raise the appropriate
    114. # stat by the value determined in "raises". For example, if you have "1" for
    115. # costs and "5" for raises, that stat will rise by 5 points for every 1 point
    116. # you spend.
    117. # ------------------------------------------------------------------------------
    118.   :costs  =>  [1, 3, 2, 2, 2, 2, 1, 1],
    119. # ------------------------------------------------------------------------------
    120. # :raises - Determines how many points the stat raises by when you spend the
    121. # number of points determined by "costs".
    122. # ------------------------------------------------------------------------------
    123.   :raises =>  [5, 1, 1, 1, 1, 1, 1, 1],
    124. # ------------------------------------------------------------------------------
    125. # :assignment_var - This is completely optional and was a specific request in
    126. # the original commission. You can specify a variable which will be set to 1
    127. # when assignment is confirmed (so the event that calls the bonus window can do
    128. # something after assignment has finished successfully).
    129. # ------------------------------------------------------------------------------
    130.   :assignment_var =>  23,
    131. # ------------------------------------------------------------------------------
    132. # :points_on_level - This allows you to specify a number of points that will be
    133. # available for assignment when a character gains a level. If set to 0, the
    134. # feature will be disabled. NOT YET IMPLEMENTED.
    135. # ------------------------------------------------------------------------------
    136.   :points_on_level  =>  10,
    137. # ------------------------------------------------------------------------------
    138. # EDITING ANYTHING BEYOND THIS POINT WILL RESULT IN PREMATURE BALDING AND LOSS
    139. # OF EARNINGS.
    140. # ------------------------------------------------------------------------------
    141. }
    142. # ------------------------------------------------------------------------------
    143. # This module determines the regex required for the stat locking notetag.
    144. # ------------------------------------------------------------------------------
    145. module BONUS
    146.   module REGEXP
    147.     STAT_LOCK = /<bonus_lock (\d+)>/i
    148.   end
    149. end
    150. # ------------------------------------------------------------------------------
    151. # RPG::Class changes
    152. # ------------------------------------------------------------------------------
    153. # stat_locks - new attr method that tracks which stats are "locked" for bonuses.
    154. # load_class_notetags - new method that loads the notetags from the database.
    155. # ------------------------------------------------------------------------------
    156. class RPG::Class
    157.   attr_reader :stat_locks
    158.   #--------------------------------------------------------------------------
    159.     # ● Loads the notetags
    160.     #--------------------------------------------------------------------------
    161.   def load_class_notetags
    162.     @stat_locks = []
    163.         @note.split(/[\r\n]+/).each do |line|
    164.             case line
    165.             when BONUS::REGEXP::STAT_LOCK
    166.         @stat_locks.push($1.to_i)
    167.       end
    168.         end
    169.     end
    170. end
    171. # ------------------------------------------------------------------------------
    172. # DataManager changes
    173. # ------------------------------------------------------------------------------
    174. # load_database - alias created so that notetags can be loaded when the game
    175. # begins.
    176. # load_class_notetags - this just loads the notetags for each class.
    177. # ------------------------------------------------------------------------------
    178. module DataManager
    179.    
    180.   # Initialize Shop Sales data
    181.   class <<self; alias bonus_load_database load_database; end
    182.   #--------------------------------------------------------------------------
    183.     # ● Loads the database
    184.     #--------------------------------------------------------------------------
    185.   def self.load_database
    186.     bonus_load_database
    187.     load_class_notetags
    188.   end
    189.   #--------------------------------------------------------------------------
    190.     # ● Loads the notetags
    191.     #--------------------------------------------------------------------------
    192.   def self.load_class_notetags
    193.     for obj in $data_classes
    194.       next if obj.nil?
    195.       obj.load_class_notetags
    196.     end
    197.         puts "Read: Bonus lock notetags"
    198.     end
    199. end
    200. # ------------------------------------------------------------------------------
    201. # Game_Interpreter changes
    202. # ------------------------------------------------------------------------------
    203. # bonus_stats = new method that allows you to use "bonus_stats(char, points)" in
    204. # an event's call script command, where char is the ID of the actor whose stats
    205. # you wish to assign bonuses to, and points is the number of points you wish to
    206. # give the player for assignment.
    207. # ------------------------------------------------------------------------------
    208. class Game_Interpreter
    209.   def bonus_stats(char, points)
    210.     SceneManager.call(Scene_Bonus)
    211.     SceneManager.scene.prepare(char, points)
    212.     Fiber.yield
    213.   end
    214. end
    215. # ------------------------------------------------------------------------------
    216. # Window_BonusTitle - new class
    217. # ------------------------------------------------------------------------------
    218. # All this window really does is show a helpful string to the player explaining
    219. # what the assignment window is for and how to confirm their choice.
    220. # ------------------------------------------------------------------------------
    221. class Window_BonusTitle < Window_Base
    222.   # ----------------------------------------------------------------------------
    223.   # Creates the window centered on the screen with a width of 400 and tall
    224.   # enough to fit two rows of text.
    225.   # ----------------------------------------------------------------------------
    226.   def initialize(char)
    227.     @char = char
    228.     ww = 400
    229.     wh = fitting_height(2)
    230.     wx = (Graphics.width / 2) - (ww / 2)
    231.     super(wx, 0, ww, wh)
    232.     refresh
    233.   end
    234.   # ----------------------------------------------------------------------------
    235.   # Draws the title text the window will show along with actor's name and class.
    236.   # ----------------------------------------------------------------------------
    237.   def draw_title
    238.     draw_text(0, 0, contents.width, line_height, "Assign Bonus (ENTER to confirm)", 1)
    239.     draw_text(0, 0, contents.width, line_height*3, sprintf("%s - level %d %s", @char.name, @char.level, @char.class.name), 1)
    240.   end
    241.   # ----------------------------------------------------------------------------
    242.   # Refresh the window by drawing the title. No update method needed as this
    243.   # will never change.
    244.   # ----------------------------------------------------------------------------
    245.   def refresh
    246.     draw_title
    247.   end
    248. end
    249. # ------------------------------------------------------------------------------
    250. # Window_BonusStats - new class
    251. # ------------------------------------------------------------------------------
    252. # This is where the magic happens! The bulk of the scene takes place in this
    253. # window, which gives the player an interface for assigning bonus points to
    254. # whichever stats were included in the stats array.
    255. # ------------------------------------------------------------------------------
    256. class Window_BonusStats < Window_Selectable
    257.   # ----------------------------------------------------------------------------
    258.   # Creates the window centered on the screen with a width of 400 and height
    259.   # determined by how many stats need to be displayed.
    260.   # - char is the ID of the actor whose stats will be assigned.
    261.   # - quantity is the number of stats that can be changed.
    262.   # - p_window is the window containing the points value. I do it like this so
    263.   # that I can call the change_points method of the points window from within
    264.   # methods in this class.
    265.   # - bonuses is an array that will store the number of bonus points the player
    266.   # has allocated to each stat in the window.
    267.   # - statups is an array that will store the changes to stats that result from
    268.   # the values in bonuses.
    269.   # ----------------------------------------------------------------------------
    270.   def initialize(char, quantity, points_window, stat_hash)
    271.     @char = char
    272.     @quantity = quantity
    273.     @p_window = points_window
    274.     @bonuses = Array.new(stat_hash[:stats].size, 0)
    275.     @statups = Array.new(stat_hash[:stats].size, 0)
    276.     @stat_hash = stat_hash
    277.     ww = 400
    278.     wh = quantity > 0 ? fitting_height(quantity) : fitting_height(1)
    279.     wx = (Graphics.width / 2) - (ww / 2)
    280.     wy = (Graphics.height / 2) - (wh / 2)
    281.     super(wx, wy, ww, wh)
    282.     refresh
    283.   end
    284.   # ----------------------------------------------------------------------------
    285.   # Returns the value of the (stat_index)th array of the statups array.
    286.   # ----------------------------------------------------------------------------
    287.   def get_statup(stat_index)
    288.     return @statups[stat_index]
    289.   end
    290.   # ----------------------------------------------------------------------------
    291.   # Calls the stat drawing methods for each stat contained in the array.
    292.   # ----------------------------------------------------------------------------
    293.   def draw_stats
    294.     if @quantity > 0
    295.       for i in 0...@quantity
    296.         draw_stat(i)
    297.         draw_raise(i)
    298.         draw_cost(i)
    299.       end
    300.     else
    301.       draw_text(0, 0, contents.width, line_height, "No assignable stats", 1)
    302.     end
    303.   end
    304.   # ----------------------------------------------------------------------------
    305.   # Draws the icon, label, current value (shown in green if a bonus has been
    306.   # applied to it), the number of bonus points that have been applied, and a
    307.   # colon separating the stat value and player selection rectangle.
    308.   # ----------------------------------------------------------------------------
    309.   def draw_stat(i)
    310.     draw_icon(@stat_hash[:icons][i], 0, line_height*i)
    311.     draw_text(30, line_height*i, contents.width, line_height, @stat_hash[:labels][i])
    312.     if @statups[i] > 0
    313.       change_color(Color.new(181, 230, 19, 200))
    314.     end
    315.     draw_text(80, line_height*i, contents.width, line_height, @char.param(@stat_hash[:stats][i]) + @statups[i])
    316.     change_color(normal_color)
    317.     draw_text(120, line_height*i, contents.width, line_height, ":")
    318.     draw_text(160, line_height*i, contents.width, line_height, @bonuses[i])
    319.   end
    320.   # ----------------------------------------------------------------------------
    321.   # Draws the number of points required to raise the stat and how many points
    322.   # the stat will be raised by if you spend that many.
    323.   # ----------------------------------------------------------------------------
    324.   def draw_cost(i)
    325.     draw_text(200, line_height*i, contents.width, line_height, sprintf("%dp > +%d", @stat_hash[:costs][i], @stat_hash[:raises][i]))
    326.   end
    327.   # ----------------------------------------------------------------------------
    328.   # Draws the value by which a stat has been raised on the far right (in green)
    329.   # but only if the number of spent points has resulted in a change.
    330.   # ----------------------------------------------------------------------------
    331.   def draw_raise(i)
    332.     if @statups[i] > 0
    333.       change_color(Color.new(181,230,19,200))
    334.       draw_text(0, line_height*i, contents.width, line_height, sprintf("+%2d", @statups[i]), 2)
    335.       change_color(normal_color)
    336.     end
    337.   end
    338.   # ----------------------------------------------------------------------------
    339.   # Returns the number of columns that the window can show. I don't actually
    340.   # know if I need to specify this to be honest.
    341.   # ----------------------------------------------------------------------------
    342.   def col_max
    343.     return 1
    344.   end
    345.   # ----------------------------------------------------------------------------
    346.   # Returns the number of items that can be selected from (the total number of
    347.   # stats being displayed). I didn't think I needed to specify this but I wasn't
    348.   # able to move the cursor without it.
    349.   # ----------------------------------------------------------------------------
    350.   def item_max
    351.     return @quantity
    352.   end
    353.   # ----------------------------------------------------------------------------
    354.   # All this does is make the cursor rectangle smaller so it only covers the
    355.   # number input for bonus points rather than stretching all the way across the
    356.   # window.
    357.   # ----------------------------------------------------------------------------
    358.   def update_cursor
    359.     cursor_rect.set(155, line_height*self.index, 32, line_height) if @quantity > 0
    360.   end
    361.   # ----------------------------------------------------------------------------
    362.   # When the window refreshes we want to clear the screen then draw our stats.
    363.   # ----------------------------------------------------------------------------
    364.   def refresh
    365.     contents.clear
    366.     draw_stats
    367.   end
    368.   # ----------------------------------------------------------------------------
    369.   # The update method covers our input for pressing the left and right arrow
    370.   # keys, and handles the "buzzer" when we either can't assign enough points or
    371.   # the player tries to remove points when none have been spend.
    372.   # It supports holding down the keys to assign points faster. The reason I put
    373.   # a separate @statups calculation and refresh call in each if statement is so
    374.   # that this only happens when the player is pressing or holding a key.
    375.   # There's no point in performing processor-intensive code when there's nothing
    376.   # to change on the screen.
    377.   # ----------------------------------------------------------------------------
    378.   def update
    379.     super
    380.     if self.active && @quantity > 0
    381.       if Input.repeat?(:LEFT)
    382.         if @bonuses[self.index] == 0
    383.           Sound.play_buzzer
    384.         else
    385.           @p_window.change_points(@stat_hash[:costs][self.index])
    386.           @bonuses[self.index] -= @stat_hash[:costs][self.index]
    387.           @statups[self.index] = (@bonuses[self.index] / @stat_hash[:costs][self.index]) * @stat_hash[:raises][self.index]
    388.           refresh
    389.         end
    390.       end
    391.       if Input.repeat?(:RIGHT)
    392.         if @p_window.points < @stat_hash[:costs][self.index]
    393.           Sound.play_buzzer
    394.         else
    395.           @p_window.change_points(-@stat_hash[:costs][self.index])
    396.           @bonuses[self.index] += @stat_hash[:costs][self.index]
    397.           @statups[self.index] = (@bonuses[self.index] / @stat_hash[:costs][self.index]) * @stat_hash[:raises][self.index]
    398.           refresh
    399.         end
    400.       end
    401.     end
    402.   end
    403. end
    404. # ------------------------------------------------------------------------------
    405. # Window_BonusPoints - new class
    406. # ------------------------------------------------------------------------------
    407. # This window displays the number of bonus points the player has to spend, and
    408. # provides methods for manipulating the points value (so that the stats window
    409. # can update the points as the player spends them).
    410. # ------------------------------------------------------------------------------
    411. class Window_BonusPoints < Window_Base
    412.   # ----------------------------------------------------------------------------
    413.   # Creates the window centered on the screen with a width of 400 and tall
    414.   # enough to fit one row of text.
    415.   # - points is the number of available points (which was passed in from the
    416.   # value provided when the event called the script)
    417.   # ----------------------------------------------------------------------------
    418.   def initialize(points)
    419.     @points = points
    420.     ww = 400
    421.     wh = fitting_height(1)
    422.     wx = (Graphics.width / 2) - (ww / 2)
    423.     super(wx, 0, ww, wh)
    424.     refresh
    425.   end
    426.   # ----------------------------------------------------------------------------
    427.   # Returns the number of points available to the player.
    428.   # ----------------------------------------------------------------------------
    429.   def points
    430.     @points
    431.   end
    432.   # ----------------------------------------------------------------------------
    433.   # Changes the number of points to the provided value. Although I could have
    434.   # done separate methods for adding and subtracting, it's easy enough to
    435.   # subtract points simply by passing a negative value to this one.
    436.   # ----------------------------------------------------------------------------
    437.   def change_points(value)
    438.     @points += value
    439.   end
    440.   # ----------------------------------------------------------------------------
    441.   # Draws the number of points on the screen. As the original request stipulated
    442.   # that only 15 points maximum would be allocated at a time, it's set up to
    443.   # format for 2 digits, though it can display more than this. Be aware that the
    444.   # selection rectangle is positioned to have the value centered when the points
    445.   # value is 2 digits, and there's some overlap if you add a third. If you want
    446.   # to provide more than 99 points for the player to assign, you'll have to
    447.   # make the selection rectangle slightly bigger.
    448.   # ----------------------------------------------------------------------------
    449.   def draw_points
    450.     draw_text(0, 0, contents.width, line_height, sprintf("Remaining points: %02d", @points), 1)
    451.   end
    452.   # ----------------------------------------------------------------------------
    453.   # Clear the screen, draw the points. Simples!
    454.   # ----------------------------------------------------------------------------
    455.   def refresh
    456.     contents.clear
    457.     draw_points
    458.   end
    459.   # ----------------------------------------------------------------------------
    460.   # Points values are going to change as the player adds/subtracts them, so we
    461.   # need to have an update method so the points window will be redrawn.
    462.   # I could actually probably remove this and just call the points window's
    463.   # refresh method when points are changed (which would probably make it process
    464.   # a bit faster) but I haven't had any lag issues with the script so the
    465.   # difference would be negligible.
    466.   # ----------------------------------------------------------------------------
    467.   def update
    468.     refresh
    469.   end
    470. end
    471. # ------------------------------------------------------------------------------
    472. # Window_BonusConfirm - new class
    473. # ------------------------------------------------------------------------------
    474. # Nothing special; just a window that pops up and asks you if you're sure you
    475. # want to confirm your choices. You can either confirm or cancel (which will
    476. # return you to the stats assignment window).
    477. # ------------------------------------------------------------------------------
    478. class Window_BonusConfirm < Window_Command
    479.   # ----------------------------------------------------------------------------
    480.   # Creates the window, opens it (though it'll be hidden on creation) and places
    481.   # it in the center of the screen.
    482.   # ----------------------------------------------------------------------------
    483.   def initialize
    484.     super(0, 0)
    485.     update_placement
    486.     self.openness = 0
    487.     open
    488.     deactivate
    489.   end
    490.   # ----------------------------------------------------------------------------
    491.   # Returns the width of the window. I probably didn't need this comment.
    492.   # ----------------------------------------------------------------------------
    493.   def window_width
    494.     return 220
    495.   end
    496.   # ----------------------------------------------------------------------------
    497.   # This method just places the window in the center of the screen.
    498.   # ----------------------------------------------------------------------------
    499.   def update_placement
    500.     self.x = (Graphics.width - width) / 2
    501.     self.y = (Graphics.height - height) / 2
    502.   end
    503.   # ----------------------------------------------------------------------------
    504.   # Determines the commands that will be in the window. We have two; one to
    505.   # confirm and one to cancel.
    506.   # ----------------------------------------------------------------------------
    507.   def make_command_list
    508.     add_command("Confirm assignment", :ok)
    509.     add_command("Return to assignment", :cancel)
    510.   end
    511. end
    512. # ------------------------------------------------------------------------------
    513. # Window_BonusCancel - new class
    514. # ------------------------------------------------------------------------------
    515. # This one is kind of like the confirm window only for cancelling. I could
    516. # probably have just made one window and changed the commands in it depending
    517. # on which key the player pressed, but making them separate windows just made
    518. # it easier for me to sort out the flow of what happens when.
    519. # ------------------------------------------------------------------------------
    520. class Window_BonusCancel < Window_Command
    521.   # ----------------------------------------------------------------------------
    522.   # Creates the window, opens it (though it'll be hidden on creation) and places
    523.   # it in the center of the screen.
    524.   # ----------------------------------------------------------------------------
    525.   def initialize
    526.     super(0, 0)
    527.     update_placement
    528.     self.openness = 0
    529.     open
    530.     deactivate
    531.   end
    532.   # ----------------------------------------------------------------------------
    533.   # Returns the width of the window. I definitely didn't need this one.
    534.   # ----------------------------------------------------------------------------
    535.   def window_width
    536.     return 220
    537.   end
    538.   # ----------------------------------------------------------------------------
    539.   # This method just places the window in the center of the screen.
    540.   # ----------------------------------------------------------------------------
    541.   def update_placement
    542.     self.x = (Graphics.width - width) / 2
    543.     self.y = (Graphics.height - height) / 2
    544.   end
    545.   # ----------------------------------------------------------------------------
    546.   # Determines the commands that will be in the window. We have two; one to
    547.   # confirm and one to cancel.
    548.   # ----------------------------------------------------------------------------
    549.   def make_command_list
    550.     add_command("Cancel assignment", :ok)
    551.     add_command("Return to assignment", :cancel)
    552.   end
    553. end
    554. # ------------------------------------------------------------------------------
    555. # Scene_Bonus - new class
    556. # ------------------------------------------------------------------------------
    557. # And now we create a new scene that brings together all our windows and
    558. # provides handler functions for input.
    559. # ------------------------------------------------------------------------------
    560. class Scene_Bonus < Scene_MenuBase
    561.   # ----------------------------------------------------------------------------
    562.   # First we prepare the scene and create instance variables for the character
    563.   # and points. I did originally use @actor but for some reason when I did this
    564.   # the ID reverted to 1 when the scene started regardless of what was entered
    565.   # in the script call. I think this might be something to do with @actor
    566.   # already having been determined somewhere else.
    567.   # ----------------------------------------------------------------------------
    568.   def prepare(char, points)
    569.     @char = $game_actors[char]
    570.     @points = points
    571.     @stat_hash = {:icons => [], :labels => [], :stats => [], :costs => [], :raises => []}
    572.     for i in 0...BON_CONFIG[:stats].length
    573.       if !@char.class.stat_locks.include?(BON_CONFIG[:stats][i])
    574.         @stat_hash[:icons].push(BON_CONFIG[:icons][i])
    575.         @stat_hash[:labels].push(BON_CONFIG[:labels][i])
    576.         @stat_hash[:stats].push(BON_CONFIG[:stats][i])
    577.         @stat_hash[:costs].push(BON_CONFIG[:costs][i])
    578.         @stat_hash[:raises].push(BON_CONFIG[:raises][i])
    579.       end
    580.     end
    581.   end
    582.   # ----------------------------------------------------------------------------
    583.   # And here's where we determine what happens when the scene starts. Fairly
    584.   # simple: we'll create the title window, points window, stats window, confirm
    585.   # window and cancel window, then reposition the points and title windows so
    586.   # that no matter how tall the stats window is, both of them will appear
    587.   # directly above/below it.
    588.   # ----------------------------------------------------------------------------
    589.   def start
    590.     super
    591.     create_title_window
    592.     create_points_window
    593.     create_stats_window
    594.     create_confirm_window
    595.     create_cancel_window
    596.     @points_window.y = @stats_window.height + @stats_window.y
    597.     @title_window.y = @stats_window.y - @title_window.height
    598.   end
    599.   # ----------------------------------------------------------------------------
    600.   # Creates the title window, adds it to the viewport.
    601.   # ----------------------------------------------------------------------------
    602.   def create_title_window
    603.     @title_window = Window_BonusTitle.new(@char)
    604.     @title_window.viewport = @viewport
    605.   end
    606.   # ----------------------------------------------------------------------------
    607.   # Creates the points window, adds it to the viewport.
    608.   # ----------------------------------------------------------------------------
    609.   def create_points_window
    610.     @points_window = Window_BonusPoints.new(@points)
    611.     @points_window.viewport = @viewport
    612.   end
    613.   # ----------------------------------------------------------------------------
    614.   # Creates the stats window, adds it to the viewport, activates it, selects the
    615.   # first options, and set handler methods for input. The first loop here looks
    616.   # through the stat locks for the character's class and removes any matches
    617.   # from the config arrays. This means that the stat will not be shown in the
    618.   # window. This is useful if you're assigning for, say, a class that doesn't
    619.   # use MP.
    620.   # ----------------------------------------------------------------------------
    621.   def create_stats_window
    622.     @stats_window = Window_BonusStats.new(@char, @stat_hash[:stats].length, @points_window, @stat_hash)
    623.     @stats_window.viewport = @viewport
    624.     @stats_window.select(0)
    625.     @stats_window.activate
    626.     @stats_window.set_handler(:ok, method(:show_confirm_window))
    627.     @stats_window.set_handler(:cancel, method(:show_cancel_window))
    628.   end
    629.   # ----------------------------------------------------------------------------
    630.   # Creates the confirm window, sets its opacity to 255 (so you can see the text
    631.   # clearly when it's shown over the stats window), hides it (so it isn't
    632.   # visible until it needs to be) and sets handler methods for input.
    633.   # ----------------------------------------------------------------------------
    634.   def create_confirm_window
    635.     @confirm_window = Window_BonusConfirm.new
    636.     @confirm_window.viewport = @viewport
    637.     @confirm_window.back_opacity = 255
    638.     @confirm_window.hide
    639.     @confirm_window.set_handler(:ok, method(:confirm_bonus))
    640.     @confirm_window.set_handler(:cancel, method(:return_to_stats))
    641.   end
    642.   # ----------------------------------------------------------------------------
    643.   # Creates the cancel window, sets its opacity to 255 (so you can see the text
    644.   # clearly when it's shown over the stats window), hides it (so it isn't
    645.   # visible until it needs to be) and sets handler methods for input.
    646.   # ----------------------------------------------------------------------------
    647.   def create_cancel_window
    648.     @cancel_window = Window_BonusCancel.new
    649.     @cancel_window.viewport = @viewport
    650.     @cancel_window.back_opacity = 255
    651.     @cancel_window.hide
    652.     @cancel_window.set_handler(:ok, method(:return_scene))
    653.     @cancel_window.set_handler(:cancel, method(:return_to_stats))
    654.   end
    655.   # ----------------------------------------------------------------------------
    656.   # This is the handler method for pressing OK on the stats window. It activates
    657.   # and shows the confirm window.
    658.   # ----------------------------------------------------------------------------
    659.   def show_confirm_window
    660.     @confirm_window.show.activate
    661.     @confirm_window.select(0)
    662.   end
    663.   # ----------------------------------------------------------------------------
    664.   # This is the handler method for pressing Cancel on the stats window. It
    665.   # activates and shows the cancel window.
    666.   # ----------------------------------------------------------------------------
    667.   def show_cancel_window
    668.     @cancel_window.show.activate
    669.     @cancel_window.select(0)
    670.   end
    671.   # ----------------------------------------------------------------------------
    672.   # This is the handler method for pressing OK on the confirm window. It sets
    673.   # the appropriate variable to 1, applies the character's stat bonuses, fully
    674.   # heals them, and returns to the calling scene.
    675.   # ----------------------------------------------------------------------------
    676.   def confirm_bonus
    677.     $game_variables[BON_CONFIG[:assignment_var]] = 1
    678.     for i in 0...@stat_hash[:stats].length
    679.       if @stats_window.get_statup(i) > 0
    680.         @char.add_param(@stat_hash[:stats][i], @stats_window.get_statup(i))
    681.       end
    682.     end
    683.     @char.hp = @char.mhp
    684.     @char.mp = @char.mmp
    685.     SceneManager.return
    686.   end
    687.   # ----------------------------------------------------------------------------
    688.   # This is the handler method for pressing Cancel on either the confirm or
    689.   # cancel windows. It hides both (as there's no differentiation between which
    690.   # one was visible when the method was called) and reactivates the stats
    691.   # window.
    692.   # ----------------------------------------------------------------------------
    693.   def return_to_stats
    694.     @confirm_window.hide.deactivate
    695.     @cancel_window.hide.deactivate
    696.     @stats_window.activate
    697.   end
    698. end
    复制代码


    FAQ
    No questions at present.

    Credit and Thanks
    - Trihan
    - Thanks to Clyve for making the original commission request.
    - Navas and Sixth for MDEF suggestion and bug report


    本贴来自国际rpgmaker官方论坛作者:Trihan处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/trilobytes-vx-ace-2-bonus-stat-allocation-v1-11-now-available.77018/

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-8-17 08:29 , Processed in 0.145792 second(s), 56 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表