Project1

标题: 【求助】如何一键加点,小树的RMVA加点系统 [打印本页]

作者: 神隐的主犯    时间: 2024-10-17 20:33
标题: 【求助】如何一键加点,小树的RMVA加点系统
RUBY 代码复制
  1. #encoding:utf-8
  2. #=============================================================================
  3. #-----------RMVA加点系统正常向-v1.03---By:救世小树--------转载请注明出处-------
  4. #=============================================================================
  5.  
  6. module Point_Tree
  7.  
  8.   POINT_KIND     = 5       #设定加点种类
  9.   LEVEL_UP_POINT = 5       #每升一级自由属性点增加数(998额外加点量)
  10.   RESET_ITEM     = 20      #洗点水编号
  11.  
  12.   STR_POINT        = ["增加体质","力量","灵巧","速度","魔力","???"]
  13.  
  14.   #分别对应增加       [MHP,MMP,物攻,物防,魔攻,魔防,敏捷,幸运]
  15.   POINT_ADD_PARAM = [[25 , 20,   1,  0.2,   1, 0.2,   0,   0],     #体力
  16.                      [15 ,  2,   3,  0.3,   0,   0,   0,   0],     #力量
  17.                      [2  ,  2,   0,    0,   0,   0,   0,   0],     #灵巧
  18.                      [0  ,  0,   0, -0.1,   0,-0.1,   2,   0],     #速度
  19.                      [2  , 15,   0,    0,   3, 0.5,   0,   0],     #魔力
  20.  
  21.                      [0,0,0,0,0,0,0,0]]
  22.                      #可以按上面的格式添加下去,不过要改POINT_KIND,STR_ALL,不然加了也白加
  23.  
  24.   #分别对应增加       [物理命中,物理闪避,必杀,必杀闪避,魔法闪避,魔法反射,物理反击,HP再生,Mp再生,Tp再生]
  25.   POINT_ADD_XPARAM = [[0 , 0, 0, 0, 0, 0, 0, 2, 0, 0],
  26.                       [0 , 0, 0, 0, 0, 0, 0, 0, 0, 0],
  27.                       [2 , 0, 4, 0, 0, 0, 0, 0, 0, 0],
  28.                       [0 , 3, 0, 0, 3, 0, 0, 0, 0, 0],
  29.                       [0 , 0, 0, 0, 0, 0, 0, 0, 2, 0],
  30.  
  31.                       [0,0,0,0,0,0,0,0,0,0]]
  32.                      #这里的单位是万分之一数值也就是0.01%,我随便填了下【别嫌小,够大了,有心情你可以算算看平衡性】
  33.  
  34.   #各种名称
  35.  
  36.   ADDPOINT       = "境界之力"     #菜单中选项
  37.   POINT_NAME     = "灵力点"   #未分配点数
  38.  
  39.   XARAM_NAME     = ["命中","物理闪避","暴击率","暴击抵抗","魔法闪避","魔法反射","物理反击","HP再生","Mp再生","Tp再生"]
  40.  
  41.  
  42.   def temp_all
  43.     r = 0
  44.     for i in 0 .. POINT_KIND-1
  45.       r+=$temp_point[i]
  46.     end
  47.     return r
  48.   end
  49.  
  50.   def reset(actor_id)
  51.     for i in 1..5
  52.       $game_actors[actor_id].point[0] += $game_actors[actor_id].point[i]
  53.       $game_actors[actor_id].point[i] =0
  54.     end
  55.   end
  56.  
  57. end
  58.  
  59. $temp_point = []
  60. for i in 0 .. Point_Tree::POINT_KIND-1
  61.   $temp_point.push(0)
  62. end
  63.  
  64. class Game_Actor < Game_Battler
  65.   include Point_Tree
  66.   attr_accessor :point
  67.  
  68.   alias setup_tre setup
  69.   def setup(actor_id)
  70.     @point = []
  71.     for i in 0 .. POINT_KIND
  72.       @point.push(0)
  73.     end
  74.     setup_tre(actor_id)
  75.   end
  76.  
  77.  
  78.  
  79.  
  80.   alias level_up_tre level_up
  81.   def level_up
  82.     level_up_tre
  83.     @hp += mhp
  84.     @mp += mmp
  85.     @point[0] += LEVEL_UP_POINT + $game_variables[998]
  86.   end
  87.  
  88.  
  89.  
  90.   def point_plus(param_id)
  91.     r=0
  92.     for i in 1 .. POINT_KIND
  93.       r+=@point[i]*POINT_ADD_PARAM[i-1][param_id]
  94.     end
  95.     return r
  96.   end
  97.  
  98.   alias point_base_param param
  99.  
  100.   def param(param_id)
  101.     value = param_base(param_id) + param_plus(param_id) + point_plus(param_id)
  102.     value *= param_rate(param_id) * param_buff_rate(param_id)
  103.     [[value, param_max(param_id)].min, param_min(param_id)].max.to_i
  104.   end
  105.   def xparam(xparam_id,extra_add = 0)
  106.     xp = super(xparam_id)
  107.     for i in 0 .. POINT_KIND-1
  108.       xp+=(@point[i+1]*POINT_ADD_XPARAM[i][xparam_id]/10000.0)
  109.     end
  110.     return xp
  111.   end
  112.  
  113.   def item_apply(user, item)
  114.     super(user, item)
  115.     if item.id == RESET_ITEM and item.is_a?(RPG::Item)
  116.       reset(@actor_id)
  117.       self.hp = [self.hp,self.mhp].min
  118.       self.mp = [self.mp,self.mmp].min
  119.     end
  120.   end
  121.  
  122. end
  123.  
  124. class Window_Point_Command < Window_Command
  125.  
  126.   include Point_Tree
  127.   #--------------------------------------------------------------------------
  128.   # ● 初始化指令选择位置(类方法)
  129.   #--------------------------------------------------------------------------
  130.   def self.init_command_position
  131.     @@last_command_symbol = nil
  132.   end
  133.   #--------------------------------------------------------------------------
  134.   # ● 初始化对象
  135.   #--------------------------------------------------------------------------
  136.   def initialize(actor)
  137.     @status_window = nil
  138.     @actor = actor
  139.     super(0,0)
  140.     select_last
  141.   end
  142.   def actor=(actor)
  143.     return if @actor == actor
  144.     @actor = actor
  145.     refresh
  146.   end
  147.   def status_window=(status_window)
  148.     return if @status_window == status_window
  149.     @status_window = status_window
  150.   end
  151.   #--------------------------------------------------------------------------
  152.   # ● 获取窗口的宽度
  153.   #--------------------------------------------------------------------------
  154.   def window_width
  155.     return 160
  156.   end
  157.   #--------------------------------------------------------------------------
  158.   # ● 获取显示行数
  159.   #--------------------------------------------------------------------------
  160.   def visible_line_number
  161.     item_max
  162.   end
  163.   def get_actor_point(index)
  164.     s = @actor.point[index+1].to_s
  165.     return "("+s+")+"+$temp_point[index].to_s
  166.   end
  167.   #--------------------------------------------------------------------------
  168.   # ● 生成指令列表
  169.   #--------------------------------------------------------------------------
  170.   def make_command_list
  171.     for i in 0 .. POINT_KIND-1
  172.       add_command(STR_POINT[i]   + get_actor_point(i)  , :point_add  ,add_enabled)
  173.     end
  174.     add_command("确认",  :point_ok)
  175.     add_command("取消",  :point_cancle)
  176.   end
  177.   #--------------------------------------------------------------------------
  178.   # ● 按下确定键时的处理
  179.   #--------------------------------------------------------------------------
  180.   def process_ok
  181.     @@last_command_symbol = current_symbol
  182.     super
  183.   end
  184.   #--------------------------------------------------------------------------
  185.   # ● 返回最后一个选项的位置
  186.   #--------------------------------------------------------------------------
  187.   def select_last
  188.     select_symbol(@@last_command_symbol)
  189.   end
  190.  
  191.   def add_enabled
  192.     temp_all < @actor.point[0]
  193.   end
  194.  
  195.   def update_help
  196.     @help_window.set_text(self.index+1) if @help_window
  197.     @status_window.index = self.index if @status_window
  198.   end
  199. end
  200.  
  201. #帮助窗口
  202. class Window_Point_Help < Window_Base
  203.   include Point_Tree
  204.   def initialize(x,y,w,h)
  205.     super(x, y, w, h)
  206.  
  207.  
  208.   end
  209.   def set_text(id)
  210.     contents.clear
  211.     if id <= POINT_KIND
  212.       text = "\\}提升一点该属性"
  213.     elsif id == POINT_KIND+1
  214.       text = "\\}确认此次加点分配"
  215.     elsif  id == POINT_KIND+2
  216.       text = "\\}取消此次加点分配"
  217.     end
  218.     draw_text_ex(8, 8, text)
  219.   end
  220. end
  221.  
  222.  
  223. #角色状态窗口
  224. class Window_Point_Actor < Window_Base
  225.   include Point_Tree
  226.  
  227.  
  228.   def initialize(actor)
  229.     super(160, 0, Graphics.width - 160, Graphics.height)
  230.     @actor = actor
  231.     @index = 0
  232.     refresh
  233.   end
  234.   def actor=(actor)
  235.     return if @actor == actor
  236.     @actor = actor
  237.     refresh
  238.   end
  239.   def index=(index)
  240.     return if @index == index
  241.     @index = index
  242.     refresh
  243.   end
  244.   def line_height
  245.     return 24
  246.   end
  247.   def refresh
  248.     contents.clear
  249.     contents.font.size = 24
  250.     draw_actor_name(@actor, 100, 0)
  251.     draw_actor_class(@actor, 240, 0)
  252.     draw_actor_face(@actor, 2, 0)
  253.     contents.font.size = 20
  254.     draw_actor_level(@actor, 102,  24)
  255.     draw_actor_point(100,48)
  256.     contents.font.size = 16
  257.     draw_actor_param_point(8,16 * 6)
  258.     draw_actor_xparam_point(8,16 * 14)
  259.   end
  260.   def draw_actor_point(x,y)
  261.     draw_text(x,y,200,line_height,"  未分配"+POINT_NAME + ":" + @actor.point[0].to_s)
  262.     draw_text(x,y+line_height,200,line_height,"此次分配"+POINT_NAME + ":" + temp_all.to_s)
  263.   end
  264.   def draw_actor_param_point(x,y)
  265.     8.times {|i| draw_actor_param_to_s(x,y,i)}
  266.   end
  267.   def draw_actor_xparam_point(x,y)
  268.     10.times {|i| draw_actor_xparam_to_s(x,y,i)}
  269.   end
  270.  
  271.   def draw_actor_param_to_s(x,y,param_id)
  272.     a=0
  273.     for i in 0 .. POINT_KIND-1
  274.       a+=$temp_point[i]*POINT_ADD_PARAM[i][param_id]
  275.     end
  276.     s1 = Vocab::param(param_id)
  277.     s2 = @actor.param(param_id).to_s
  278.     s3 = (@actor.param(param_id)+a).to_s
  279.     if @index < POINT_KIND
  280.       if POINT_ADD_PARAM[@index][param_id]==0
  281.         s4 = ""
  282.       else
  283.         s4 = "+" + POINT_ADD_PARAM[@index][param_id].to_s
  284.       end
  285.     else
  286.       s4 = ""
  287.     end
  288.  
  289.     change_color(system_color)
  290.     draw_text(x,y+16*param_id,100,line_height,s1)
  291.     change_color(normal_color)
  292.     s2+= " →"
  293.     draw_text(x+82,y+16*param_id,120,line_height,s2,2)
  294.     change_color(system_color)
  295.     draw_text(x+150,y+16*param_id,100,line_height,s3,2)
  296.     change_color(normal_color)
  297.     contents.font.size = 16
  298.     draw_text(x+266,y+16*param_id,100,line_height,s4)
  299.     contents.font.size = 16
  300.   end
  301.   def draw_actor_xparam_to_s(x,y,xparam_id)
  302.     a=0.00
  303.     for i in 0 .. POINT_KIND-1
  304.       a+=($temp_point[i]*POINT_ADD_XPARAM[i][xparam_id]/10000.0)
  305.     end
  306.     s1 = XARAM_NAME[xparam_id]
  307.     s2 = sprintf("%02.2f%%",@actor.xparam(xparam_id)*100)
  308.     s3 = sprintf("%02.2f%%",(@actor.xparam(xparam_id) + a)*100)
  309.  
  310.     if @index < POINT_KIND
  311.       if POINT_ADD_XPARAM[@index][xparam_id]==0
  312.         s4=""
  313.       else
  314.         s4 = sprintf("+%02.2f%%",POINT_ADD_XPARAM[@index][xparam_id]/100.0)
  315.       end
  316.     else
  317.       s4 = ""
  318.     end
  319.  
  320.     change_color(system_color)
  321.     draw_text(x,y+16*xparam_id,100,line_height,s1)
  322.     change_color(normal_color)
  323.     s2+= " →"
  324.     draw_text(x+82,y+16*xparam_id,120,line_height,s2,2)
  325.     change_color(system_color)
  326.     draw_text(x+150,y+16*xparam_id,100,line_height,s3,2)
  327.     change_color(normal_color)
  328.     contents.font.size = 16
  329.     draw_text(x+266,y+16*xparam_id,100,line_height,s4)
  330.     contents.font.size = 16
  331.  
  332.  
  333.   end
  334. end
  335.  
  336. class Scene_Point < Scene_Base
  337.   include Point_Tree
  338.   def start
  339.     super
  340.     create_background
  341.     @actor = $game_party.menu_actor
  342.     create_command_window
  343.     create_status_window
  344.     create_help_window
  345.     @command_window.activate
  346.   end
  347.   def terminate
  348.     super
  349.     dispose_background
  350.   end
  351.   def create_background
  352.     @background_sprite = Sprite.new
  353.     @background_sprite.bitmap = SceneManager.background_bitmap
  354.     @background_sprite.color.set(16, 16, 16, 128)
  355.   end
  356.   def dispose_background
  357.     @background_sprite.dispose
  358.   end
  359.  
  360.   def create_command_window
  361.     @command_window = Window_Point_Command.new(@actor)
  362.     @command_window.set_handler(:cancel,      method(:return_scene))
  363.     @command_window.set_handler(:pagedown,    method(:next_actor))
  364.     @command_window.set_handler(:pageup,      method(:prev_actor))
  365.     @command_window.set_handler(:point_add,   method(:add_point))
  366.     @command_window.set_handler(:point_ok,    method(:add_ok))
  367.     @command_window.set_handler(:point_cancle,method(:add_cancle))
  368.  
  369.   end
  370.   def return_scene
  371.     add_cancle
  372.     SceneManager.return
  373.   end
  374.   def create_status_window
  375.     @status_window = Window_Point_Actor.new(@actor)
  376.     @command_window.status_window = @status_window
  377.   end
  378.   def create_help_window
  379.     @help_window = Window_Point_Help.new(0,@command_window.height,160,Graphics.height-@command_window.height)
  380.     #(0, 216, 160, 200)
  381.     @help_window.viewport = @viewport
  382.     @command_window.help_window = @help_window
  383.   end
  384.  
  385.   def add_point
  386.     if temp_all >= @actor.point[0]
  387.       @command_window.activate
  388.       return
  389.     end
  390.     $temp_point[@command_window.index] += 1
  391.     @status_window.refresh
  392.     @command_window.refresh
  393.     @command_window.activate
  394.   end
  395.  
  396.  
  397.   def add_ok
  398.     for i in 0 .. POINT_KIND-1
  399.       @actor.point[i+1] += $temp_point[i]
  400.     end
  401.     @actor.point[0]-= temp_all
  402.     add_cancle
  403.   end
  404.  
  405.   def add_cancle
  406.     for i in 0 .. POINT_KIND-1
  407.       $temp_point[i]=0
  408.     end
  409.     @status_window.refresh
  410.     @command_window.refresh
  411.     @command_window.activate
  412.   end
  413.  
  414.  
  415.   def next_actor
  416.     @actor = $game_party.menu_actor_next
  417.     on_actor_change
  418.   end
  419.   #--------------------------------------------------------------------------
  420.   # ● 切换到上一个角色
  421.   #--------------------------------------------------------------------------
  422.   def prev_actor
  423.     @actor = $game_party.menu_actor_prev
  424.     on_actor_change
  425.   end
  426.   #--------------------------------------------------------------------------
  427.   # ● 切换角色
  428.   #--------------------------------------------------------------------------
  429.   def on_actor_change
  430.     add_cancle
  431.     @status_window.actor = @actor
  432.     @command_window.actor = @actor
  433.     @command_window.activate
  434.   end
  435.  
  436. end
  437.  
  438. class Window_MenuCommand < Window_Command
  439.   alias add_original_commands_old add_original_commands
  440.   def add_original_commands
  441.     add_original_commands_old
  442.     add_command(Point_Tree::ADDPOINT,    :addpoint)
  443.   end
  444. end
  445.  
  446. class Scene_Menu < Scene_MenuBase
  447.   alias create_command_window_old create_command_window
  448.   def create_command_window
  449.     create_command_window_old
  450.     @command_window.set_handler(:addpoint,method(:add_point))
  451.   end
  452.   def add_point
  453.     @status_window.select_last
  454.     @status_window.activate
  455.     @status_window.set_handler(:ok,     method(:on_ok))
  456.     @status_window.set_handler(:cancel, method(:on_personal_cancel))
  457.   end
  458.   def on_ok
  459.     SceneManager.call(Scene_Point)
  460.     Window_Point_Command::init_command_position
  461.   end
  462. end
  463.  
  464.  
  465.  
  466. class Scene_ItemBase < Scene_MenuBase
  467.   def item_usable?
  468.     if item.id == Point_Tree::RESET_ITEM and item.is_a?(RPG::Item)
  469.       return true
  470.     end
  471.     user.usable?(item) && item_effects_valid?
  472.   end
  473. end


直接上代码,是小树的加点系统,前期勇者还好。但是游戏做到一小半我意识到这样下去我测试战斗难度会越来越难,每次都给每个角色点400点属性什么的太腱鞘炎了。

而且我的游戏是可以多周目的,对于多周目的玩家也非常不友好。所以我真的非常想给这个功能加一个一键加点啊…………或者记忆加点什么的解放双手的功能。

球球大佬们
作者: 魔法丶小肉包    时间: 2024-10-17 20:33
直接使用即可,选项里会多出个一键分配,按一下激活/取消激活,激活后再点想分配的项目会出现一个数字输入的窗口

RUBY 代码复制
  1. class Window_Point_Command
  2.   attr_accessor :point_all
  3.   alias mf241017initialize initialize
  4.   def initialize(actor)
  5.     mf241017initialize(actor)
  6.     @point_all = false
  7.   end
  8.   alias mf241017make_command_list make_command_list
  9.   def make_command_list
  10.     mf241017make_command_list
  11.     add_command(point_all ? "一键分配开启中" : "一键分配",:point_all)
  12.   end
  13. end
  14. class Scene_Point
  15.   alias mf241017create_command_window create_command_window
  16.   def create_command_window
  17.     mf241017create_command_window
  18.     @command_window.set_handler(:point_all,method(:add_point_all))
  19.     @pointnumber_window = Window_Point_Number.new
  20.     @pointnumber_window.set_handler(:ok,method(:set_number_ok))
  21.     @pointnumber_window.set_handler(:cancel,method(:set_number_cancel))
  22.   end
  23.   def set_number_ok
  24.     $temp_point[@command_window.index] += @pointnumber_window.number
  25.     @status_window.refresh
  26.     @command_window.refresh
  27.     @command_window.activate
  28.   end
  29.   def set_number_cancel
  30.     @command_window.activate
  31.   end
  32.   def add_point_all
  33.     @command_window.point_all = !@command_window.point_all
  34.     @command_window.refresh
  35.     @command_window.activate
  36.   end
  37.   alias mf241017add_point add_point
  38.   def add_point
  39.     return mf241017add_point unless @command_window.point_all
  40.     @command_window.deactivate
  41.     all_temp = 0
  42.     $temp_point.each {|i| all_temp += i}
  43.     @pointnumber_window.max_number = @actor.point[0] - all_temp
  44.     @pointnumber_window.number_init
  45.     @pointnumber_window.show.refresh
  46.     @pointnumber_window.activate
  47.   end
  48. end
  49. class Window_Point_Number < Window_Selectable
  50.   attr_reader :number
  51.   def initialize
  52.     super(200, 200, 100, 60)
  53.     self.z = 500
  54.     @number = 0
  55.     @max_number = 0
  56.     @digits_max = 3
  57.     @index = 0
  58.     create_contents
  59.     refresh
  60.     hide
  61.     deactivate
  62.   end
  63.   def number_init
  64.     @number = 0
  65.   end
  66.   def max_number=(i)
  67.     @max_number = i
  68.     @digits_max = @max_number.to_s.size
  69.   end
  70.   def process_ok
  71.     super
  72.     hide
  73.   end
  74.   def process_cancel
  75.     super
  76.     @number = 0
  77.     hide
  78.   end
  79.   def cursor_right(wrap)
  80.     if @index < @digits_max - 1 || wrap
  81.       @index = (@index + 1) % @digits_max
  82.     end
  83.   end
  84.   def cursor_left(wrap)
  85.     if @index > 0 || wrap
  86.       @index = (@index + @digits_max - 1) % @digits_max
  87.     end
  88.   end
  89.   def update
  90.     super
  91.     process_digit_change
  92.     update_cursor
  93.   end
  94.   def process_cursor_move
  95.     return unless active
  96.     last_index = @index
  97.     cursor_right(Input.trigger?(:RIGHT)) if Input.repeat?(:RIGHT)
  98.     cursor_left (Input.trigger?(:LEFT))  if Input.repeat?(:LEFT)
  99.     Sound.play_cursor if @index != last_index
  100.   end
  101.   def process_digit_change
  102.     return unless active
  103.     if Input.repeat?(:UP) || Input.repeat?(:DOWN)
  104.       Sound.play_cursor
  105.       place = 10 ** (@digits_max - 1 - @index)
  106.       n = @number / place % 10
  107.       @number -= n * place
  108.       n = (n + 1) % 10 if Input.repeat?(:UP)
  109.       n = (n + 9) % 10 if Input.repeat?(:DOWN)
  110.       @number += n * place
  111.       @number = [@number,@max_number].min
  112.       refresh
  113.     end
  114.   end
  115.   def item_rect(index)
  116.     Rect.new(index * 20, 0, 20, line_height)
  117.   end
  118.   def refresh
  119.     contents.clear
  120.     change_color(normal_color)
  121.     s = sprintf("%0*d", @digits_max, @number)
  122.     @digits_max.times do |i|
  123.       rect = item_rect(i)
  124.       rect.x += 1
  125.       draw_text(rect, s[i,1], 1)
  126.     end
  127.   end
  128.   def update_cursor
  129.     cursor_rect.set(item_rect(@index))
  130.   end
  131. end





欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1