设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 2504|回复: 9
打印 上一主题 下一主题

[已经解决] [已解决]想实现一个NPC队友功能,战斗不受我方控制。

[复制链接]

Lv4.逐梦者

梦石
0
星屑
14096
在线时间
2139 小时
注册时间
2019-1-24
帖子
1121

R考场第七期纪念奖

跳转到指定楼层
1
发表于 2019-10-21 12:08:18 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 miantouchi 于 2019-10-24 06:57 编辑

初步想法是打个比方,
场景1:我方坚持打到第5回合时,这个npc会加入到游戏战斗画面里面,所在的位置是我方队友的位置。
            我方无法进行控制,到了这个npc行动时,会自动释放大型技能。
             厉害的npc会秒杀BOSS.
场景2.弱点的npc,是个医生职业一直普通攻击和初级治疗。
共同点是
这一次战役(也就是这次的剧情完事)打完后,npc离开。
  系统现在只有敌人中途出现,敌人使用某个技能释放几率这些设置,然而没有一个npc有这种情况。

增加这个npc不受控的会有不少乐趣,可翻了论坛基本也没找到这个方面的。

不同战役,失败条件不同,例如需要保护的npc挂了直接失败。

欢迎大家来讨论!!!

只有我方和敌方的战斗太单调了!

Lv5.捕梦者

梦石
0
星屑
33143
在线时间
10485 小时
注册时间
2009-3-15
帖子
4756
2
发表于 2019-10-21 13:46:25 | 只看该作者
RUBY 代码复制
  1. #==============================================================================
  2. # ■ XP-RGSS-47 オート行動キャラクタ [Ver.1.0.0]          by Claimh
  3. #------------------------------------------------------------------------------
  4. #  特定のキャラクタのみオート行動させることが出来ます。
  5. #------------------------------------------------------------------------------
  6. # ● オート行動者の変更(イベントコマンド)
  7. #   $game_actors[アクターID].auto_play = true/false
  8. #     true  :オート行動者に設定
  9. #     false ;オート行動者を解除
  10. #------------------------------------------------------------------------------
  11. # ● オート行動者の変更
  12. #   設定カスタマイズで設定しているPT_SW[アクターID]で指定した変数を変更する。
  13. #   対応する行動パターンが設定されていないと「何もしない」
  14. #==============================================================================
  15.  
  16. module AutoPlayer
  17.   AUTO_MODE = []
  18.   PT_SW = []
  19.   RATING_PLUS = 5
  20.   RETRY_TIME = 10
  21. #------------------------------------------------------------------------------
  22. # ★設定カスタマイズ
  23. #------------------------------------------------------------------------------
  24.   # 初期状態からオート行動キャラクタ
  25.   # AUTO_PLAYER = [アクターID,・・・]
  26.   AUTO_PLAYER = [1, 3]
  27.  
  28.   # オート行動パターン切り替え用変数
  29.   # PT_SW[アクターID] = 変数ID
  30.   PT_SW[1] = 1
  31.   PT_SW[2] = 2
  32.   PT_SW[3] = 3
  33.   PT_SW[4] = 4
  34.  
  35.   # 瀕死条件と判定するHP(%)
  36.   CRISIS = 25
  37.  
  38.   #-----------------------------------------------------------
  39.   # ◆オート行動パターン設定
  40.   #     行動パターンの設定です。
  41.   #     レーティングに応じて行動をランダムに行動します。
  42.   #     行動優先条件に適合する際は設定されたレーティング+5
  43.   #-----------------------------------------------------------
  44.     # 定数名 = [
  45.     #     レーティング(1~10),
  46.     #     行動優先条件(0:指定なし, 1:味方ピンチ, 2:敵が瀕死状態),
  47.     #     行動種類(0:通常攻撃, 1:防御, 2:スキル, 3:アイテム),
  48.     #     使用スキルID or 使用アイテムID(通常攻撃、防御の場合はnil),
  49.     #     ターゲット選択条件(0:ランダム, 1:残HPの低い者, 2:残HPの高い者)
  50.     # ]
  51.  
  52.   #---------アクター1---------#
  53.   # アクター1:パターン0
  54.   AT_PATTERN_1_0 = [
  55.     [5, 0, 0, nil, 0],   # レーティング5:条件なし:通常攻撃:ランダム
  56.     [2, 0, 2,  57, 2],   # レーティング2:条件なし:スキル:クロスカット;残HP高
  57.     [1, 0, 1, nil, 0]    # レーティング1:条件なし:防御
  58.   ]
  59.  
  60.   # アクター1:パターン1
  61.   AT_PATTERN_1_1 = [
  62.     [2, 0, 0, nil, 0],   # レーティング2:条件なし:通常攻撃:ランダム
  63.     [5, 0, 2, nil, 0]    # レーティング5:条件なし:防御
  64.   ]
  65.  
  66.   #---------アクター2---------#
  67.   # アクター2:パターン0
  68.   AT_PATTERN_2_0 = [
  69.     [5, 0, 0, nil, 0],   # レーティング5:条件なし:通常攻撃:ランダム
  70.     [1, 0, 0, nil, 1],   # レーティング1:条件なし:防御
  71.     [2, 0, 2,   7, 2]    # レーティング2:条件なし:スキル:ファイア;残HP高
  72.   ]
  73.  
  74.   # アクター2:パターン1
  75.   AT_PATTERN_2_1 = [
  76.     [2, 0, 0, nil, 0],   # レーティング2:条件なし:通常攻撃:ランダム
  77.     [5, 0, 2, nil, 0]    # レーティング5:条件なし:防御
  78.   ]
  79.  
  80.   #---------アクター3---------#
  81.   # アクター3:パターン0
  82.   AT_PATTERN_3_0 = [
  83.     [5, 0, 0, nil, 1],   # レーティング5:条件なし:通常攻撃:残HP低
  84.     [2, 0, 1, nil, 0],   # レーティング2:条件なし:防御
  85.     [3, 1, 2,   1, 1]    # レーティング3:味方ピンチ:スキル:ヒール:残HP低
  86.   ]
  87.  
  88.   # アクター3:パターン1
  89.   AT_PATTERN_3_1 = [
  90.     [2, 0, 1, nil, 0],   # レーティング2:条件なし:防御
  91.     [5, 1, 2,   1, 1]    # レーティング5:味方ピンチ:スキル:ヒール:残HP低
  92.   ]
  93.  
  94.   #---------アクター4---------#
  95.   # アクター4:パターン0
  96.   AT_PATTERN_4_0 = [
  97.     [5, 0, 0, nil, 1],   # レーティング5:条件なし:通常攻撃:残HP低
  98.     [3, 2, 0, nil, 1],   # レーティング2:敵瀕死:通常攻撃:残HP低
  99.     [1, 0, 1, nil, 0]    # レーティング1:条件なし:防御
  100.   ]
  101.  
  102.   # アクター4:パターン1
  103.   AT_PATTERN_4_1 = [
  104.     [2, 0, 0, nil, 1],   # レーティング2:条件なし:通常攻撃:残HP低
  105.     [5, 0, 2, nil, 0]    # レーティング5:条件なし:防御
  106.   ]
  107.  
  108.  
  109.   #-----------------------------------------------------------
  110.   # ◆オート行動設定
  111.   #     各キャラクタの行動パターンの設定
  112.   #-----------------------------------------------------------
  113.   # AUTO_MODE[アクターID] = {
  114.   #   PT_SW[アクターID]で指定した変数の値 => [オート行動パターン]
  115.   # }
  116.   # アクター1
  117.   AUTO_MODE[1] = {
  118.     0 => AT_PATTERN_1_0,    # アクター1:パターン0
  119.     1 => AT_PATTERN_1_1     # アクター1:パターン1
  120.   }
  121.  
  122.   # アクター2
  123.   AUTO_MODE[2] = {
  124.     0 => AT_PATTERN_2_0,    # アクター2:パターン0
  125.     1 => AT_PATTERN_2_1     # アクター2:パターン1
  126.   }
  127.  
  128.   # アクター3
  129.   AUTO_MODE[3] = {
  130.     0 => AT_PATTERN_3_0,    # アクター3:パターン0
  131.     1 => AT_PATTERN_3_1     # アクター3:パターン1
  132.   }
  133.  
  134.   # アクター4
  135.   AUTO_MODE[4] = {
  136.     0 => AT_PATTERN_4_0,    # アクター4:パターン0
  137.     1 => AT_PATTERN_4_1     # アクター4:パターン1
  138.   }
  139.  
  140. #------------------------------------------------------------------------------
  141. end
  142.  
  143.  
  144. #==============================================================================
  145. # ■ Scene_Battle
  146. #==============================================================================
  147. class Game_Actor < Game_Battler
  148.   #--------------------------------------------------------------------------
  149.   # ● 公開インスタンス変数
  150.   #--------------------------------------------------------------------------
  151.   attr_accessor   :auto_play                 # オート行動
  152.   #--------------------------------------------------------------------------
  153.   # ● オブジェクト初期化
  154.   #     actor_id : アクター ID
  155.   #--------------------------------------------------------------------------
  156.   alias init_auto_chara initialize
  157.   def initialize(actor_id)
  158.     init_auto_chara(actor_id)
  159.     @auto_play = AutoPlayer::AUTO_PLAYER.include?(actor_id)
  160.   end
  161.   #--------------------------------------------------------------------------
  162.   # ● コマンド入力可能判定
  163.   #--------------------------------------------------------------------------
  164.   def inputable?
  165.     ret = super
  166.     ret = false if @auto_play
  167.     return ret
  168.   end
  169. end
  170.  
  171.  
  172. #==============================================================================
  173. # ■ Scene_Battle
  174. #==============================================================================
  175. class Scene_Battle
  176.   #--------------------------------------------------------------------------
  177.   # ● フレーム更新 (メインフェーズ ステップ 2 : アクション開始)
  178.   #--------------------------------------------------------------------------
  179.   alias update_phase4_step2_auto_player update_phase4_step2
  180.   def update_phase4_step2
  181.     # オート行動者か?
  182.     if @active_battler.is_a?(Game_Actor) and @active_battler.auto_play
  183.       make_auto_player_actions
  184.     end
  185.     update_phase4_step2_auto_player
  186.   end
  187.   #--------------------------------------------------------------------------
  188.   # ● オート行動者の行動選択
  189.   #--------------------------------------------------------------------------
  190.   def make_auto_player_actions
  191.     # 行動パターン抽出
  192.     action_motion = at_judge_auto_pattern?
  193.     return if action_motion.nil?  # 抽出失敗
  194.     # 行動が決まるまでリトライ(RETRY_TIMEまで)
  195.     for i in 0...AutoPlayer::RETRY_TIME
  196.       # 行動判定処理
  197.       action = make_auto_play_pattern(action_motion)
  198.       # 行動パターンが設定されていない
  199.       if action.nil?
  200.         # 何もしない
  201.         @active_battler.current_action.kind = 0
  202.         @active_battler.current_action.basic = 3
  203.         return
  204.       end
  205.       # 行動設定処理
  206.       ret = make_auto_play_motion(action)
  207.       return if ret   # 正常終了
  208.     end
  209.     # 行動選択に失敗 = 何もしない
  210.     ## 味方全員生存している状態で、味方(HP0)対象のスキル、アイテムが
  211.     ## 連続して発生しない限りここにはこない。
  212.     ## 安全策のために何もしないを入れておく。
  213.     @active_battler.current_action.kind = 0
  214.     @active_battler.current_action.basic = 3
  215.   end
  216.   #--------------------------------------------------------------------------
  217.   # ● 行動パターン抽出
  218.   #--------------------------------------------------------------------------
  219.   def at_judge_auto_pattern?
  220.     # 行動が設定されていない
  221.     vari = $game_variables[AutoPlayer::PT_SW[@active_battler.id]]
  222.     if AutoPlayer::AUTO_MODE[@active_battler.id].nil? or vari.nil?
  223.       # 何もしない
  224.       @active_battler.current_action.kind = 0
  225.       @active_battler.current_action.basic = 3
  226.       return nil
  227.     end
  228.     action_motion = AutoPlayer::AUTO_MODE[@active_battler.id][vari]
  229.     # 行動パターンが設定されていない
  230.     if action_motion.nil?
  231.       # 何もしない
  232.       @active_battler.current_action.kind = 0
  233.       @active_battler.current_action.basic = 3
  234.       return nil
  235.     end
  236.     return action_motion
  237.   end
  238.   #--------------------------------------------------------------------------
  239.   # ● 優先条件"味方ピンチ"の判定
  240.   #--------------------------------------------------------------------------
  241.   def at_judge_party_crisis?
  242.     for actor in $game_party.actors
  243.       # 瀕死状態?
  244.       if actor.hp <= (actor.maxhp * AutoPlayer::CRISIS / 100)
  245.         return true
  246.       end
  247.     end
  248.     return false
  249.   end
  250.   #--------------------------------------------------------------------------
  251.   # ● 優先条件"味方ピンチ"の判定
  252.   #--------------------------------------------------------------------------
  253.   def at_judge_enemy_crisis?
  254.     for enemy in $game_troop.enemies
  255.       # 瀕死状態?
  256.       if enemy.hp <= (enemy.maxhp * AutoPlayer::CRISIS / 100)
  257.         return true
  258.       end
  259.     end
  260.     return false
  261.   end
  262.   #--------------------------------------------------------------------------
  263.   # ● オート行動者の行動パターン判定
  264.   #--------------------------------------------------------------------------
  265.   def make_auto_play_pattern(action_pattern)
  266.     # 優先条件の有無をチェックする
  267.     pt_crisis = at_judge_party_crisis?
  268.     tr_crisis = at_judge_enemy_crisis?
  269.     # レーティング合計値
  270.     total_rating = 0
  271.     rating_box = []
  272.     for i in 0...action_pattern.size
  273.       rating_plus = 0
  274.       case action_pattern[i][1]
  275.       when 0    # 条件なし
  276.       when 1    # 味方ピンチ
  277.         rating_plus = AutoPlayer::RATING_PLUS if pt_crisis
  278.       when 2    # 敵が瀕死状態
  279.         rating_plus = AutoPlayer::RATING_PLUS if tr_crisis
  280.       else
  281.         p "行動パターン::優先行動条件 設定ミス"
  282.         exit
  283.       end
  284.       rating_box[i] = action_pattern[i][0] + rating_plus
  285.       total_rating += rating_box[i]
  286.     end
  287.     # レーティングによる行動選択
  288.     rating_randam = rand(total_rating)
  289.     before_rating = 0
  290.     for i in 0...action_pattern.size
  291.       if rating_randam < (rating_box[i] + before_rating)
  292.         return action_pattern[i]
  293.       end
  294.       before_rating += rating_box[i]
  295.     end
  296.     return nil    # 行動選択失敗
  297.   end
  298.   #--------------------------------------------------------------------------
  299.   # ● 行動選択
  300.   #--------------------------------------------------------------------------
  301.   def make_auto_play_motion(action)
  302.     ret = true
  303.     case action[2]
  304.     when 0  # 通常攻撃
  305.       @active_battler.current_action.kind = 0
  306.       @active_battler.current_action.basic = 0
  307.       ret = make_auto_play_target(action[4], 1)
  308.     when 1  # 防御
  309.       @active_battler.current_action.kind = 0
  310.       @active_battler.current_action.basic = 1
  311.     when 2  # スキル
  312.       @active_battler.current_action.kind = 1
  313.       @active_battler.current_action.skill_id = skill_id = action[3]
  314.       # 使えない場合は再選択
  315.       return nil unless @active_battler.skill_can_use?(skill_id)
  316.       # ターゲット選択
  317.       ret = make_auto_play_target(action[4], $data_skills[skill_id].scope)
  318.     when 3  # アイテム
  319.       @active_battler.current_action.kind = 2
  320.       @active_battler.current_action.item_id = item_id = action[3]
  321.       # 持ってない場合は再選択
  322.       return nil if $game_party.item_number(item_id) == 0
  323.       # ターゲット選択
  324.       ret = make_auto_play_target(action[4], $data_items[item_id].scope)
  325.     else
  326.       p "行動パターン::行動種類 設定ミス"
  327.       exit
  328.     end
  329.     return ret
  330.   end
  331.   #--------------------------------------------------------------------------
  332.   # ● ターゲット選択
  333.   #--------------------------------------------------------------------------
  334.   def make_auto_play_target(mode, scope)
  335.     case scope
  336.     when 0, 2, 4, 6, 7   # 全体攻撃なので設定不要
  337.       @active_battler.current_action.target_index = 0
  338.     else  # その他単体攻撃
  339.       # ターゲット選択
  340.       case mode
  341.       when 0  # ランダム
  342.         case scope
  343.         when 1    # 敵
  344.           @active_battler.current_action.target_index = make_randum_target($game_troop.enemies)
  345.         when 3, 5 # 味方
  346.           @active_battler.current_action.target_index = make_randum_target($game_party.actors)
  347.         end
  348.       when 1  # 残HPの低い者
  349.         case scope
  350.         when 1    # 敵
  351.           @active_battler.current_action.target_index = make_crisis_target($game_troop.enemies)
  352.         when 3
  353.           @active_battler.current_action.target_index = make_crisis_target($game_party.actors)
  354.         when 5    # 味方(HP0)
  355.           target = make_dead_target
  356.           return nil if target.nil?   # 選び直し
  357.           @active_battler.current_action.target_index = target
  358.         end
  359.       when 2  # 残HPの高い者
  360.         case scope
  361.         when 1    # 敵
  362.           @active_battler.current_action.target_index = make_vigour_target($game_troop.enemies)
  363.         when 3    # 味方
  364.           @active_battler.current_action.target_index = make_vigour_target($game_party.actors)
  365.         when 5    # 味方(HP0)
  366.           target = make_dead_target
  367.           return nil if target.nil?   # 選び直し
  368.           @active_battler.current_action.target_index = target
  369.         end
  370.       else
  371.         p "行動パターン::ターゲット 設定ミス"
  372.         exit
  373.       end
  374.     end
  375.     return true
  376.   end
  377.   #--------------------------------------------------------------------------
  378.   # ● ランダムターゲット選択
  379.   #--------------------------------------------------------------------------
  380.   def make_randum_target(targets)
  381.     while 0
  382.       index = rand(targets.size)
  383.       if targets[index].exist?
  384.         return index
  385.       end
  386.     end
  387.   end
  388.   #--------------------------------------------------------------------------
  389.   # ● 残HP低ターゲット選択
  390.   #--------------------------------------------------------------------------
  391.   def make_crisis_target(targets)
  392.     target_hp = 1000000
  393.     target_index = make_randum_target(targets)
  394.     for index in 0...targets.size
  395.       if targets[index].hp < target_hp
  396.         target_hp = targets[index].hp
  397.         target_index = index
  398.       end
  399.     end
  400.     return target_index
  401.   end
  402.   #--------------------------------------------------------------------------
  403.   # ● 残HP高ターゲット選択
  404.   #--------------------------------------------------------------------------
  405.   def make_vigour_target(targets)
  406.     target_hp = 0
  407.     target_index = make_randum_target(targets)
  408.     for index in 0...targets.size
  409.       if targets[index].hp > target_hp
  410.         target_hp = targets[index].hp
  411.         target_index = index
  412.       end
  413.     end
  414.     return target_index
  415.   end
  416.   #--------------------------------------------------------------------------
  417.   # ● 残HP0ターゲット選択
  418.   #--------------------------------------------------------------------------
  419.   def make_dead_target
  420.     target_index = []
  421.     for index in 0...$game_party.actors.size
  422.       if $game_party.actors[index].dead?
  423.         target_index.push(index)
  424.       end
  425.     end
  426.     return nil if target_index.empty
  427.     return target_index[rand(target_index.size)]
  428.   end
  429. end

评分

参与人数 2星屑 +50 +1 收起 理由
RyanBern + 50 认可答案
miantouchi + 1 是好东西,日文脑袋大。。。

查看全部评分

回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
14096
在线时间
2139 小时
注册时间
2019-1-24
帖子
1121

R考场第七期纪念奖

3
 楼主| 发表于 2019-10-21 22:37:37 | 只看该作者
本帖最后由 miantouchi 于 2019-10-21 22:43 编辑
soulsaga 发表于 2019-10-21 13:46
#==============================================================================
# ■ XP-RGSS-47 オー ...


帮我看下
第1.
  PT_SW[1] = 1 这个是指第1个角色用默认1模式
  PT_SW[2] = 2 这个是指第2个角色用默认2模式(默认脚本没有设置角色2的模式2)
  PT_SW[3] = 3 这个是指第3个角色用默认3模式(默认脚本没有设置角色3的模式3)
  PT_SW[4] = 4 这个是指第4个角色用默认4模式(默认脚本没有设置角色4的模式4)
是这个意思吗
第2.分级1-10是优先级的意思吗?
AT_PATTERN_1_0 = [
    [5, 0, 0, nil, 0],   # 分级5:无条件:普通攻击:随机
    [2, 0, 2,  57, 2],   # 分级2:无条件:技能:十字斩;剩余HP较高者
    [1, 0, 1, nil, 0]    # 分级1:无条件:防御
  ]
这个是不是意思是普通攻击占一半几率,十字斩,占20%,防御10%几率
另外我要添加多个技能咋办?
AT_PATTERN_1_0 = [
    [5, 0, 0, nil, 0],   # 分级5:无条件:普通攻击:随机
    [2, 0, 2,  57, 2],   # 分级2:无条件:技能:十字斩;剩余HP较高者
    [1, 0, 1, nil, 0],   # 分级1:无条件:防御
    [2, 0, 2,  58, 2]   # 分级2:无条件:技能:十字斩;剩余HP较高者
  ]
我在后边加上58号特技好像没反应

1.png (78.38 KB, 下载次数: 8)

1.png

2.png (77.66 KB, 下载次数: 11)

2.png
回复 支持 反对

使用道具 举报

Lv5.捕梦者

梦石
0
星屑
33143
在线时间
10485 小时
注册时间
2009-3-15
帖子
4756
4
发表于 2019-10-21 22:41:15 | 只看该作者

没错是权重..也就是优先度..
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-19 21:23

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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