查看: 3395|回复: 9

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

[复制链接]
梦石
0
星屑
15106
在线时间
2234 小时
注册时间
2019-1-24
回帖
964

R考场第七期纪念奖

发表于 2019-10-21 12:08:18 | 显示全部楼层 |阅读模式

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

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

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

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

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

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

欢迎大家来讨论!!!

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

梦石
0
星屑
39336
在线时间
11161 小时
注册时间
2009-3-15
回帖
4768
发表于 2019-10-21 13:46:25 | 显示全部楼层
  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. module AutoPlayer
  16.   AUTO_MODE = []
  17.   PT_SW = []
  18.   RATING_PLUS = 5
  19.   RETRY_TIME = 10
  20. #------------------------------------------------------------------------------
  21. # ★設定カスタマイズ
  22. #------------------------------------------------------------------------------
  23.   # 初期状態からオート行動キャラクタ
  24.   # AUTO_PLAYER = [アクターID,・・・]
  25.   AUTO_PLAYER = [1, 3]

  26.   # オート行動パターン切り替え用変数
  27.   # PT_SW[アクターID] = 変数ID
  28.   PT_SW[1] = 1
  29.   PT_SW[2] = 2
  30.   PT_SW[3] = 3
  31.   PT_SW[4] = 4

  32.   # 瀕死条件と判定するHP(%)
  33.   CRISIS = 25

  34.   #-----------------------------------------------------------
  35.   # ◆オート行動パターン設定
  36.   #     行動パターンの設定です。
  37.   #     レーティングに応じて行動をランダムに行動します。
  38.   #     行動優先条件に適合する際は設定されたレーティング+5
  39.   #-----------------------------------------------------------
  40.     # 定数名 = [
  41.     #     レーティング(1~10),
  42.     #     行動優先条件(0:指定なし, 1:味方ピンチ, 2:敵が瀕死状態),
  43.     #     行動種類(0:通常攻撃, 1:防御, 2:スキル, 3:アイテム),
  44.     #     使用スキルID or 使用アイテムID(通常攻撃、防御の場合はnil),
  45.     #     ターゲット選択条件(0:ランダム, 1:残HPの低い者, 2:残HPの高い者)
  46.     # ]

  47.   #---------アクター1---------#
  48.   # アクター1:パターン0
  49.   AT_PATTERN_1_0 = [
  50.     [5, 0, 0, nil, 0],   # レーティング5:条件なし:通常攻撃:ランダム
  51.     [2, 0, 2,  57, 2],   # レーティング2:条件なし:スキル:クロスカット;残HP高
  52.     [1, 0, 1, nil, 0]    # レーティング1:条件なし:防御
  53.   ]

  54.   # アクター1:パターン1
  55.   AT_PATTERN_1_1 = [
  56.     [2, 0, 0, nil, 0],   # レーティング2:条件なし:通常攻撃:ランダム
  57.     [5, 0, 2, nil, 0]    # レーティング5:条件なし:防御
  58.   ]

  59.   #---------アクター2---------#
  60.   # アクター2:パターン0
  61.   AT_PATTERN_2_0 = [
  62.     [5, 0, 0, nil, 0],   # レーティング5:条件なし:通常攻撃:ランダム
  63.     [1, 0, 0, nil, 1],   # レーティング1:条件なし:防御
  64.     [2, 0, 2,   7, 2]    # レーティング2:条件なし:スキル:ファイア;残HP高
  65.   ]

  66.   # アクター2:パターン1
  67.   AT_PATTERN_2_1 = [
  68.     [2, 0, 0, nil, 0],   # レーティング2:条件なし:通常攻撃:ランダム
  69.     [5, 0, 2, nil, 0]    # レーティング5:条件なし:防御
  70.   ]

  71.   #---------アクター3---------#
  72.   # アクター3:パターン0
  73.   AT_PATTERN_3_0 = [
  74.     [5, 0, 0, nil, 1],   # レーティング5:条件なし:通常攻撃:残HP低
  75.     [2, 0, 1, nil, 0],   # レーティング2:条件なし:防御
  76.     [3, 1, 2,   1, 1]    # レーティング3:味方ピンチ:スキル:ヒール:残HP低
  77.   ]

  78.   # アクター3:パターン1
  79.   AT_PATTERN_3_1 = [
  80.     [2, 0, 1, nil, 0],   # レーティング2:条件なし:防御
  81.     [5, 1, 2,   1, 1]    # レーティング5:味方ピンチ:スキル:ヒール:残HP低
  82.   ]

  83.   #---------アクター4---------#
  84.   # アクター4:パターン0
  85.   AT_PATTERN_4_0 = [
  86.     [5, 0, 0, nil, 1],   # レーティング5:条件なし:通常攻撃:残HP低
  87.     [3, 2, 0, nil, 1],   # レーティング2:敵瀕死:通常攻撃:残HP低
  88.     [1, 0, 1, nil, 0]    # レーティング1:条件なし:防御
  89.   ]

  90.   # アクター4:パターン1
  91.   AT_PATTERN_4_1 = [
  92.     [2, 0, 0, nil, 1],   # レーティング2:条件なし:通常攻撃:残HP低
  93.     [5, 0, 2, nil, 0]    # レーティング5:条件なし:防御
  94.   ]


  95.   #-----------------------------------------------------------
  96.   # ◆オート行動設定
  97.   #     各キャラクタの行動パターンの設定
  98.   #-----------------------------------------------------------
  99.   # AUTO_MODE[アクターID] = {
  100.   #   PT_SW[アクターID]で指定した変数の値 => [オート行動パターン]
  101.   # }
  102.   # アクター1
  103.   AUTO_MODE[1] = {
  104.     0 => AT_PATTERN_1_0,    # アクター1:パターン0
  105.     1 => AT_PATTERN_1_1     # アクター1:パターン1
  106.   }

  107.   # アクター2
  108.   AUTO_MODE[2] = {
  109.     0 => AT_PATTERN_2_0,    # アクター2:パターン0
  110.     1 => AT_PATTERN_2_1     # アクター2:パターン1
  111.   }

  112.   # アクター3
  113.   AUTO_MODE[3] = {
  114.     0 => AT_PATTERN_3_0,    # アクター3:パターン0
  115.     1 => AT_PATTERN_3_1     # アクター3:パターン1
  116.   }

  117.   # アクター4
  118.   AUTO_MODE[4] = {
  119.     0 => AT_PATTERN_4_0,    # アクター4:パターン0
  120.     1 => AT_PATTERN_4_1     # アクター4:パターン1
  121.   }

  122. #------------------------------------------------------------------------------
  123. end


  124. #==============================================================================
  125. # ■ Scene_Battle
  126. #==============================================================================
  127. class Game_Actor < Game_Battler
  128.   #--------------------------------------------------------------------------
  129.   # ● 公開インスタンス変数
  130.   #--------------------------------------------------------------------------
  131.   attr_accessor   :auto_play                 # オート行動
  132.   #--------------------------------------------------------------------------
  133.   # ● オブジェクト初期化
  134.   #     actor_id : アクター ID
  135.   #--------------------------------------------------------------------------
  136.   alias init_auto_chara initialize
  137.   def initialize(actor_id)
  138.     init_auto_chara(actor_id)
  139.     @auto_play = AutoPlayer::AUTO_PLAYER.include?(actor_id)
  140.   end
  141.   #--------------------------------------------------------------------------
  142.   # ● コマンド入力可能判定
  143.   #--------------------------------------------------------------------------
  144.   def inputable?
  145.     ret = super
  146.     ret = false if @auto_play
  147.     return ret
  148.   end
  149. end


  150. #==============================================================================
  151. # ■ Scene_Battle
  152. #==============================================================================
  153. class Scene_Battle
  154.   #--------------------------------------------------------------------------
  155.   # ● フレーム更新 (メインフェーズ ステップ 2 : アクション開始)
  156.   #--------------------------------------------------------------------------
  157.   alias update_phase4_step2_auto_player update_phase4_step2
  158.   def update_phase4_step2
  159.     # オート行動者か?
  160.     if @active_battler.is_a?(Game_Actor) and @active_battler.auto_play
  161.       make_auto_player_actions
  162.     end
  163.     update_phase4_step2_auto_player
  164.   end
  165.   #--------------------------------------------------------------------------
  166.   # ● オート行動者の行動選択
  167.   #--------------------------------------------------------------------------
  168.   def make_auto_player_actions
  169.     # 行動パターン抽出
  170.     action_motion = at_judge_auto_pattern?
  171.     return if action_motion.nil?  # 抽出失敗
  172.     # 行動が決まるまでリトライ(RETRY_TIMEまで)
  173.     for i in 0...AutoPlayer::RETRY_TIME
  174.       # 行動判定処理
  175.       action = make_auto_play_pattern(action_motion)
  176.       # 行動パターンが設定されていない
  177.       if action.nil?
  178.         # 何もしない
  179.         @active_battler.current_action.kind = 0
  180.         @active_battler.current_action.basic = 3
  181.         return
  182.       end
  183.       # 行動設定処理
  184.       ret = make_auto_play_motion(action)
  185.       return if ret   # 正常終了
  186.     end
  187.     # 行動選択に失敗 = 何もしない
  188.     ## 味方全員生存している状態で、味方(HP0)対象のスキル、アイテムが
  189.     ## 連続して発生しない限りここにはこない。
  190.     ## 安全策のために何もしないを入れておく。
  191.     @active_battler.current_action.kind = 0
  192.     @active_battler.current_action.basic = 3
  193.   end
  194.   #--------------------------------------------------------------------------
  195.   # ● 行動パターン抽出
  196.   #--------------------------------------------------------------------------
  197.   def at_judge_auto_pattern?
  198.     # 行動が設定されていない
  199.     vari = $game_variables[AutoPlayer::PT_SW[@active_battler.id]]
  200.     if AutoPlayer::AUTO_MODE[@active_battler.id].nil? or vari.nil?
  201.       # 何もしない
  202.       @active_battler.current_action.kind = 0
  203.       @active_battler.current_action.basic = 3
  204.       return nil
  205.     end
  206.     action_motion = AutoPlayer::AUTO_MODE[@active_battler.id][vari]
  207.     # 行動パターンが設定されていない
  208.     if action_motion.nil?
  209.       # 何もしない
  210.       @active_battler.current_action.kind = 0
  211.       @active_battler.current_action.basic = 3
  212.       return nil
  213.     end
  214.     return action_motion
  215.   end
  216.   #--------------------------------------------------------------------------
  217.   # ● 優先条件"味方ピンチ"の判定
  218.   #--------------------------------------------------------------------------
  219.   def at_judge_party_crisis?
  220.     for actor in $game_party.actors
  221.       # 瀕死状態?
  222.       if actor.hp <= (actor.maxhp * AutoPlayer::CRISIS / 100)
  223.         return true
  224.       end
  225.     end
  226.     return false
  227.   end
  228.   #--------------------------------------------------------------------------
  229.   # ● 優先条件"味方ピンチ"の判定
  230.   #--------------------------------------------------------------------------
  231.   def at_judge_enemy_crisis?
  232.     for enemy in $game_troop.enemies
  233.       # 瀕死状態?
  234.       if enemy.hp <= (enemy.maxhp * AutoPlayer::CRISIS / 100)
  235.         return true
  236.       end
  237.     end
  238.     return false
  239.   end
  240.   #--------------------------------------------------------------------------
  241.   # ● オート行動者の行動パターン判定
  242.   #--------------------------------------------------------------------------
  243.   def make_auto_play_pattern(action_pattern)
  244.     # 優先条件の有無をチェックする
  245.     pt_crisis = at_judge_party_crisis?
  246.     tr_crisis = at_judge_enemy_crisis?
  247.     # レーティング合計値
  248.     total_rating = 0
  249.     rating_box = []
  250.     for i in 0...action_pattern.size
  251.       rating_plus = 0
  252.       case action_pattern[i][1]
  253.       when 0    # 条件なし
  254.       when 1    # 味方ピンチ
  255.         rating_plus = AutoPlayer::RATING_PLUS if pt_crisis
  256.       when 2    # 敵が瀕死状態
  257.         rating_plus = AutoPlayer::RATING_PLUS if tr_crisis
  258.       else
  259.         p "行動パターン::優先行動条件 設定ミス"
  260.         exit
  261.       end
  262.       rating_box[i] = action_pattern[i][0] + rating_plus
  263.       total_rating += rating_box[i]
  264.     end
  265.     # レーティングによる行動選択
  266.     rating_randam = rand(total_rating)
  267.     before_rating = 0
  268.     for i in 0...action_pattern.size
  269.       if rating_randam < (rating_box[i] + before_rating)
  270.         return action_pattern[i]
  271.       end
  272.       before_rating += rating_box[i]
  273.     end
  274.     return nil    # 行動選択失敗
  275.   end
  276.   #--------------------------------------------------------------------------
  277.   # ● 行動選択
  278.   #--------------------------------------------------------------------------
  279.   def make_auto_play_motion(action)
  280.     ret = true
  281.     case action[2]
  282.     when 0  # 通常攻撃
  283.       @active_battler.current_action.kind = 0
  284.       @active_battler.current_action.basic = 0
  285.       ret = make_auto_play_target(action[4], 1)
  286.     when 1  # 防御
  287.       @active_battler.current_action.kind = 0
  288.       @active_battler.current_action.basic = 1
  289.     when 2  # スキル
  290.       @active_battler.current_action.kind = 1
  291.       @active_battler.current_action.skill_id = skill_id = action[3]
  292.       # 使えない場合は再選択
  293.       return nil unless @active_battler.skill_can_use?(skill_id)
  294.       # ターゲット選択
  295.       ret = make_auto_play_target(action[4], $data_skills[skill_id].scope)
  296.     when 3  # アイテム
  297.       @active_battler.current_action.kind = 2
  298.       @active_battler.current_action.item_id = item_id = action[3]
  299.       # 持ってない場合は再選択
  300.       return nil if $game_party.item_number(item_id) == 0
  301.       # ターゲット選択
  302.       ret = make_auto_play_target(action[4], $data_items[item_id].scope)
  303.     else
  304.       p "行動パターン::行動種類 設定ミス"
  305.       exit
  306.     end
  307.     return ret
  308.   end
  309.   #--------------------------------------------------------------------------
  310.   # ● ターゲット選択
  311.   #--------------------------------------------------------------------------
  312.   def make_auto_play_target(mode, scope)
  313.     case scope
  314.     when 0, 2, 4, 6, 7   # 全体攻撃なので設定不要
  315.       @active_battler.current_action.target_index = 0
  316.     else  # その他単体攻撃
  317.       # ターゲット選択
  318.       case mode
  319.       when 0  # ランダム
  320.         case scope
  321.         when 1    # 敵
  322.           @active_battler.current_action.target_index = make_randum_target($game_troop.enemies)
  323.         when 3, 5 # 味方
  324.           @active_battler.current_action.target_index = make_randum_target($game_party.actors)
  325.         end
  326.       when 1  # 残HPの低い者
  327.         case scope
  328.         when 1    # 敵
  329.           @active_battler.current_action.target_index = make_crisis_target($game_troop.enemies)
  330.         when 3
  331.           @active_battler.current_action.target_index = make_crisis_target($game_party.actors)
  332.         when 5    # 味方(HP0)
  333.           target = make_dead_target
  334.           return nil if target.nil?   # 選び直し
  335.           @active_battler.current_action.target_index = target
  336.         end
  337.       when 2  # 残HPの高い者
  338.         case scope
  339.         when 1    # 敵
  340.           @active_battler.current_action.target_index = make_vigour_target($game_troop.enemies)
  341.         when 3    # 味方
  342.           @active_battler.current_action.target_index = make_vigour_target($game_party.actors)
  343.         when 5    # 味方(HP0)
  344.           target = make_dead_target
  345.           return nil if target.nil?   # 選び直し
  346.           @active_battler.current_action.target_index = target
  347.         end
  348.       else
  349.         p "行動パターン::ターゲット 設定ミス"
  350.         exit
  351.       end
  352.     end
  353.     return true
  354.   end
  355.   #--------------------------------------------------------------------------
  356.   # ● ランダムターゲット選択
  357.   #--------------------------------------------------------------------------
  358.   def make_randum_target(targets)
  359.     while 0
  360.       index = rand(targets.size)
  361.       if targets[index].exist?
  362.         return index
  363.       end
  364.     end
  365.   end
  366.   #--------------------------------------------------------------------------
  367.   # ● 残HP低ターゲット選択
  368.   #--------------------------------------------------------------------------
  369.   def make_crisis_target(targets)
  370.     target_hp = 1000000
  371.     target_index = make_randum_target(targets)
  372.     for index in 0...targets.size
  373.       if targets[index].hp < target_hp
  374.         target_hp = targets[index].hp
  375.         target_index = index
  376.       end
  377.     end
  378.     return target_index
  379.   end
  380.   #--------------------------------------------------------------------------
  381.   # ● 残HP高ターゲット選択
  382.   #--------------------------------------------------------------------------
  383.   def make_vigour_target(targets)
  384.     target_hp = 0
  385.     target_index = make_randum_target(targets)
  386.     for index in 0...targets.size
  387.       if targets[index].hp > target_hp
  388.         target_hp = targets[index].hp
  389.         target_index = index
  390.       end
  391.     end
  392.     return target_index
  393.   end
  394.   #--------------------------------------------------------------------------
  395.   # ● 残HP0ターゲット選択
  396.   #--------------------------------------------------------------------------
  397.   def make_dead_target
  398.     target_index = []
  399.     for index in 0...$game_party.actors.size
  400.       if $game_party.actors[index].dead?
  401.         target_index.push(index)
  402.       end
  403.     end
  404.     return nil if target_index.empty
  405.     return target_index[rand(target_index.size)]
  406.   end
  407. end
复制代码

点评

百度是个好东西汉化了,好东西啊,正在研究。  发表于 2019-10-21 21:17

评分

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

查看全部评分

回复 1 0

使用道具 举报

梦石
0
星屑
15106
在线时间
2234 小时
注册时间
2019-1-24
回帖
964

R考场第七期纪念奖

 楼主| 发表于 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
2.png
回复

使用道具 举报

梦石
0
星屑
39336
在线时间
11161 小时
注册时间
2009-3-15
回帖
4768
发表于 2019-10-21 22:41:15 | 显示全部楼层

没错是权重..也就是优先度..

点评

终于搞明白怎么用了。  发表于 2019-10-22 12:00
好吧  发表于 2019-10-22 07:04
我没用过...你自行趼究..  发表于 2019-10-21 23:00
我又补充了下,麻烦帮我看看  发表于 2019-10-21 22:44
回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部