Project1

标题: 如何实现人物多了可自由选择4个参与战斗。 [打印本页]

作者: 母乳到六岁    时间: 2011-8-6 23:53
标题: 如何实现人物多了可自由选择4个参与战斗。
采用RMXP原战斗系统,由于设定主角一行人数比较多   如果实现像《堕落天使》中自由选择几个人物参战的脚本~
dsu_plus_rewardpost_czw
作者: Cola酱    时间: 2011-8-7 07:46
http://www.66rpg.com/htm/news472.htm
可以参照这个样例修改
作者: 2719358    时间: 2011-8-7 08:05
人物 仓库
  1. #==============================================================================
  2. # ■ chaochao的人物仓库ver1.02正式版
  3. # 修改了Game_Party
  4. # 功能:
  5. # 用来存放角色的仓库……
  6. # 召唤画面用$scene = Chaochao_Scene_Party.new
  7. # 其它使用说明在代码里已经备注。
  8. #------------------------------------------------------------------------------
  9. # 作者:chaochao
  10. # [url]http://zhuchao.go1.icpcn.com[/url]
  11. #==============================================================================
  12. class Chaochao_Window_PartyLeft < Window_Selectable
  13.   def initialize
  14.     super(0, 0, 320, 224)
  15.     self.contents = Bitmap.new(width - 32, height - 32)
  16.     self.index = 0
  17.     refresh
  18.   end
  19.   def actor
  20.     return @actors[self.index]
  21.   end
  22.   def refresh
  23.     if self.contents != nil
  24.       self.contents.dispose
  25.       self.contents = nil
  26.     end
  27.     @actors = []
  28.     for i in 0...$game_party.actors.size
  29.       @actors.push($game_party.actors[i])
  30.     end
  31.    
  32.     @item_max = 4
  33.     if @item_max > 0
  34.       self.contents = Bitmap.new(width - 32, (row_max+1) * 32)
  35.       for i in 0...@item_max
  36.         draw_item(i)
  37.       end
  38.     end
  39.   end
  40.   def draw_item(index)
  41.     if @actors[index] != nil
  42.       actor = @actors[index]
  43.       text = @actors[index].name
  44.       lv = @actors[index].level.to_s + " "
  45.       if $game_party.chaochao.include?(actor.id) or $game_party.actors.size <= 1
  46.         self.contents.font.color = Color.new(255, 0, 0) #不能被移动的颜色
  47.       else
  48.         self.contents.font.color = Color.new(0, 255, 0) #可以被移动的颜色
  49.       end
  50.       self.contents.draw_text(4, index * 32 + 32, 288, 32, text)
  51.       self.contents.font.color = normal_color
  52.       self.contents.font.size = 16
  53.       self.contents.draw_text(4, index * 32 + 36, 288, 32,  "Level:   ", 2)
  54.       colorx = [255.0000 - 255.0000/60 * @actors[index].level,0].max
  55.       colory = [255.0000 / 60 * @actors[index].level,255].min
  56.       self.contents.font.color = Color.new(colorx, colory, 0)
  57.       self.contents.draw_text(4, index * 32 + 36, 288, 32,  lv, 2)
  58.       self.contents.font.color = normal_color
  59.       self.contents.font.size = 22
  60.     else
  61.       self.contents.draw_text(4, index * 32 + 32, 288, 32,  "米有人物!")
  62.     end
  63.   end
  64.   def update_cursor_rect
  65.     if @index < 0
  66.       self.cursor_rect.empty
  67.       return
  68.     end
  69.     row = @index / @column_max
  70.     if row < self.top_row
  71.       self.top_row = row
  72.     end
  73.     if row > self.top_row + (self.page_row_max - 1)
  74.       self.top_row = row - (self.page_row_max - 1)
  75.     end
  76.     cursor_width = self.width / @column_max - 32
  77.     x = @index % @column_max * (cursor_width + 32)
  78.     y = @index / @column_max * 32 - self.oy + 32
  79.     self.cursor_rect.set(x, y, cursor_width, 32)
  80.   end
  81.   def item_max
  82.     return @item_max
  83.   end
  84.   def actor?(index)
  85.     return @actors[index] == nil ? false : true
  86.   end
  87.   def set_index(x)
  88.     @index = x
  89.   end
  90. end

  91. #------------------------------------------------------------------------------

  92. class Chaochao_Window_PartyRight < Window_Selectable
  93.   def initialize
  94.     super(320, 0, 320, 224)
  95.     self.contents = Bitmap.new(width - 32, height - 32)
  96.     self.index = -1
  97.     refresh
  98.   end
  99.   def actor
  100.     return @actors[self.index]
  101.   end
  102.   def refresh
  103.     if self.contents != nil
  104.       self.contents.dispose
  105.       self.contents = nil
  106.     end
  107.     @actors = []
  108.     for i in 0...$game_party.actors2.size
  109.       @actors.push($game_party.actors2[i])
  110.     end
  111.    
  112.     @item_max = $game_party.actors2.size
  113.     if @item_max > 0
  114.       self.contents = Bitmap.new(width - 32, row_max * 32)
  115.       for i in 0...@item_max
  116.         draw_item(i)
  117.       end
  118.     elsif @item_max == 0
  119.       
  120.     end
  121.   end
  122.   def draw_item(index)
  123.     actor = @actors[index]
  124.     text = @actors[index].name
  125.     lv = @actors[index].level.to_s + " "
  126.     if $game_party.chaochao2.include?(actor.id) or $game_party.actors.size >= 4
  127.         self.contents.font.color = Color.new(255, 0, 0) #不能被移动的颜色
  128.       else
  129.         self.contents.font.color = Color.new(0, 255, 0) #可以被移动的颜色
  130.       end
  131.     self.contents.draw_text(4, index * 32, 288, 32, text)
  132.     self.contents.font.color = normal_color
  133.     self.contents.font.size = 16
  134.     self.contents.draw_text(4, index * 32 + 4, 288, 32,  "Level:   ", 2)
  135.     colorx = [255.0000 - 255.0000/60 * @actors[index].level,0].max
  136.     colory = [255.0000 / 60 * @actors[index].level,255].min
  137.     self.contents.font.color = Color.new(colorx, colory, 0)
  138.     self.contents.draw_text(4, index * 32 + 4, 288, 32,  lv, 2)
  139.     self.contents.font.color = normal_color
  140.     self.contents.font.size = 22
  141.   end
  142.   def update_cursor_rect
  143.     if @index < 0
  144.       self.cursor_rect.empty
  145.       return
  146.     end
  147.     row = @index / @column_max
  148.     if row < self.top_row
  149.       self.top_row = row
  150.     end
  151.     if row > self.top_row + (self.page_row_max - 1)
  152.       self.top_row = row - (self.page_row_max - 1)
  153.     end
  154.     cursor_width = self.width / @column_max - 32
  155.     x = @index % @column_max * (cursor_width + 32)
  156.     y = @index / @column_max * 32 - self.oy
  157.     self.cursor_rect.set(x, y, cursor_width, 32)
  158.   end
  159.   def item_max
  160.     return @item_max
  161.   end
  162.   def actor?(index)
  163.     return @actors[index] == nil ? false : true
  164.   end
  165.   def set_index(x)
  166.     @index = x
  167.   end
  168. end

  169. #------------------------------------------------------------------------------

  170. class Chaochao_Window_PartyData < Window_Base
  171.   
  172.   def initialize
  173.     super(0, 224, 640, 256)
  174.     self.contents = Bitmap.new(width - 32, height - 32)
  175.     @actor = nil
  176.   end
  177.   
  178.   def set_actor(actor)
  179.     self.contents.clear
  180.     draw_actor_name(actor, 4, 0)
  181.     draw_actor_state(actor, 140, 0)
  182.     draw_actor_hp(actor, 284, 0)
  183.     draw_actor_sp(actor, 460, 0)
  184.     @actor = actor
  185.     self.visible = true
  186.   end
  187.   def clear
  188.     self.contents.clear
  189.   end
  190. end

  191. #------------------------------------------------------------------------------

  192. class Game_Party
  193.   attr_reader   :actors2
  194.   attr_reader   :chaochao#不能从队伍向备用角色移动的角色ID
  195.   attr_reader   :chaochao2#不能从备用角色向队伍移动的角色ID
  196.   def initialize
  197.     @actors = []
  198.     @gold = 0
  199.     @steps = 0
  200.     @items = {}
  201.     @weapons = {}
  202.     @armors = {}
  203.     @actors2 = []
  204.     @chaochao = []
  205.     @chaochao2 = []
  206.   end
  207.   def add_actor(actor_id,type=1)#type为1是向队伍中添加,为2则相反。
  208.     case type
  209.     when 1
  210.       if $game_actors[actor_id] != nil
  211.         actor = $game_actors[actor_id]
  212.         #如果队伍没有满和队伍中没有此角色
  213.         if @actors.size < 4 and not @actors.include?(actor) and not @actors2.include?(actor)
  214.           @actors.push(actor)
  215.           $game_player.refresh
  216.         end
  217.       end
  218.     when 2
  219.       if $game_actors[actor_id] != nil
  220.         actor = $game_actors[actor_id]
  221.         #如果角色不在队伍中和不在备用角色队伍中的情况下
  222.         #向备用角色中添加角色
  223.         if not @actors.include?(actor) and not @actors2.include?(actor)
  224.           @actors2.push(actor)
  225.           $game_player.refresh
  226.         end
  227.       end
  228.     end
  229.   end
  230.   
  231.   def huanren(index,type=1)#type为1是从备用角色向队伍中移动,为2则相反。
  232.     actor = $game_actors[index]
  233.     case type
  234.     when 1
  235.       if @actors.size < 4 and @actors2.include?(actor) and not @chaochao2.include?(index) and not @actors.include?(actor)
  236.         @actors.push(actor)
  237.         @actors2.delete(actor)
  238.         $game_system.se_play($data_system.decision_se)
  239.         $game_player.refresh
  240.       end
  241.     when 2
  242.       if @actors.include?(actor) and not @chaochao.include?(index) and not @actors2.include?(actor)
  243.         @actors2.push(actor)
  244.         @actors.delete(actor)
  245.         $game_system.se_play($data_system.decision_se)
  246.         $game_player.refresh
  247.       end
  248.     end
  249.   end
  250.   
  251.   #type1,1是操作队伍中的角色能否向备用队伍移动,2则相反。
  252.   #type2,1是添加不能移动的,2是删除不能移动的。
  253.   def yidong(actor_id,type1,type2=1)
  254.     case type2
  255.     when 1
  256.       case type1
  257.       when 1
  258.         @chaochao.push(actor_id)
  259.       when 2
  260.         @chaochao2.push(actor_id)
  261.       end
  262.     when 2
  263.       case type1
  264.       when 1
  265.         @chaochao.delete(actor_id)
  266.       when 2
  267.         @chaochao2.delete(actor_id)
  268.       end
  269.     end
  270.   end
  271.   
  272.   #type,1从队伍中离开,2从备用角色中离开,3从队伍和备用角色中离开。
  273.   def remove_actor(actor_id,type=1)
  274.     actor = $game_actors[actor_id]
  275.     case type
  276.     when 1
  277.       @actors.delete(actor)
  278.       $game_player.refresh
  279.     when 2
  280.       @actors2.delete(actor)
  281.       $game_player.refresh
  282.     when 3
  283.       @actors.delete(actor)
  284.       @actors2.delete(actor)
  285.       $game_player.refresh
  286.     end
  287.   end
  288.   
  289.   def refresh
  290.     new_actors = []
  291.     new_actors2 = []
  292.     for i in [email][email protected][/email]
  293.       if $data_actors[@actors[i].id] != nil
  294.         new_actors.push($game_actors[@actors[i].id])
  295.       end
  296.     end
  297.     @actors = new_actors
  298.     for i in [email][email protected][/email]
  299.       if $data_actors[@actors2[i].id] != nil
  300.         new_actors2.push($game_actors[@actors2[i].id])
  301.       end
  302.     end
  303.     @actors2 = new_actors2
  304.   end
  305. end

  306. #------------------------------------------------------------------------------

  307. class Chaochao_Scene_Party
  308.   def main
  309.     @left_temp_command = 0
  310.     @right_temp_command = 0
  311.     @temp = 0
  312.     @left_window = Chaochao_Window_PartyLeft.new
  313.     @left_window.active = true
  314.     @right_window = Chaochao_Window_PartyRight.new
  315.     @right_window.active = false
  316.     @data_window = Chaochao_Window_PartyData.new
  317.     update_data
  318.     Graphics.transition
  319.     loop do
  320.       Graphics.update
  321.       Input.update
  322.       update
  323.       if $scene != self
  324.         break
  325.       end
  326.     end
  327.     Graphics.freeze
  328.     @left_window.dispose
  329.     @right_window.dispose
  330.     @data_window.dispose
  331.   end
  332.   
  333.   def update
  334.     @left_window.update
  335.     @right_window.update
  336.     @data_window.update
  337.     update_command
  338.     update_data
  339.   end
  340.   
  341.   def update_command
  342.     if Input.trigger?(Input::B)
  343.       $game_system.se_play($data_system.cancel_se)
  344.       #画面切换
  345.       $scene = Scene_Map.new
  346.       return
  347.     end
  348.     if @left_window.active
  349.       update_left
  350.       return
  351.     end
  352.     if @right_window.active
  353.       update_right
  354.       return
  355.     end
  356.   end
  357.   
  358.   def update_left
  359.     if Input.trigger?(Input::RIGHT)
  360.       if @right_window.item_max > 0
  361.         @left_temp_command = @left_window.index
  362.         @left_window.set_index(-1)
  363.         $game_system.se_play($data_system.cursor_se)
  364.         @left_window.active = false
  365.         @right_window.active = true
  366.         @left_window.refresh
  367.         @right_window.refresh
  368.         @right_window.set_index(@right_temp_command)
  369.         return
  370.       else
  371.         $game_system.se_play($data_system.buzzer_se)
  372.         return
  373.       end
  374.     end
  375.     if Input.trigger?(Input::C)
  376.       if @left_window.active and @left_window.actor?(@left_window.index) and $game_party.actors.size > 1 and not $game_party.chaochao.include?($game_party.actors[@left_window.index].id)
  377.         $game_party.huanren($game_party.actors[@left_window.index].id,2)#type为1是从备用角色向队伍中移动,为2则相反。
  378.         @left_window.refresh
  379.         @right_window.refresh
  380.       else
  381.         $game_system.se_play($data_system.buzzer_se)
  382.       end
  383.     end
  384.     return
  385.   end
  386.   
  387.   def update_right
  388.     if Input.trigger?(Input::LEFT)
  389.       if @left_window.item_max > 0
  390.         @right_temp_command = @right_window.index
  391.         @right_window.set_index(-1)
  392.         $game_system.se_play($data_system.cursor_se)
  393.         @left_window.active = true
  394.         @right_window.active = false
  395.         @left_window.refresh
  396.         @right_window.refresh
  397.         @left_window.set_index(@left_temp_command)
  398.         return
  399.       else
  400.         $game_system.se_play($data_system.buzzer_se)
  401.         return
  402.       end
  403.     end
  404.     if Input.trigger?(Input::C)
  405.       if $game_party.actors.size >= 4
  406.         $game_system.se_play($data_system.buzzer_se)
  407.         return
  408.       end
  409.       if @right_window.active and @right_window.actor?(@right_window.index) and not $game_party.chaochao2.include?($game_party.actors2[@right_window.index].id)
  410.         $game_party.huanren($game_party.actors2[@right_window.index].id,1)#type为1是从备用角色向队伍中移动,为2则相反。
  411.         if $game_party.actors2.size == 0
  412.           @right_temp_command = @right_window.index
  413.           @right_window.set_index(-1)
  414.           $game_system.se_play($data_system.cursor_se)
  415.           @left_window.active = true
  416.           @right_window.active = false
  417.           @left_window.refresh
  418.           @right_window.refresh
  419.           @left_window.set_index(@left_temp_command)
  420.         end
  421.         if @right_window.index > 0
  422.           @right_window.set_index(@right_window.index-1)
  423.         end
  424.         @left_window.refresh
  425.         @right_window.refresh
  426.       else
  427.         $game_system.se_play($data_system.buzzer_se)
  428.       end
  429.     end
  430.     return
  431.   end
  432.   
  433.   def update_data
  434.     if @left_window.active
  435.       if $game_party.actors[@left_window.index] != nil
  436.         @data_window.set_actor($game_party.actors[@left_window.index])
  437.       else
  438.         @data_window.clear
  439.       end
  440.       return
  441.     end
  442.     if @right_window.active
  443.       if $game_party.actors2[@right_window.index] != nil
  444.         @data_window.set_actor($game_party.actors2[@right_window.index])
  445.       else
  446.         @data_window.clear
  447.       end
  448.       return
  449.     end
  450.   end
  451. end
复制代码

作者: 母乳到六岁    时间: 2011-8-7 14:59
感谢大家~~
作者: qq175908660    时间: 2011-8-7 15:08
提示: 作者被禁止或删除 内容自动屏蔽




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