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

Project1

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

[已经解决] 敌人SP不足时的行动判定

 关闭 [复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
9 小时
注册时间
2011-3-23
帖子
8
跳转到指定楼层
1
发表于 2011-3-23 00:58:04 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 space20021 于 2011-3-25 18:24 编辑

我设定敌人会使用一招消耗SP的招式,可是问题是当SP耗光后敌人就不会动了……汗

为了解决这个问题,我另外弄了一个可以回复SP的招式,而我的目标是想把这个敌人设定成「SP不足的时候就回复SP」,不知道该如何实现?

我曾经试着改Game_Enemy里面的脚本,把敌人行动设定当中等级判定那一栏输入的数字当作是判定的SP量,没想到一改动之后敌人就完全不会做任何动作了……

Game_Enemy 276行

if $game_party.max_level < action.condition_level
        next
      end

改成

if self.sp >= action.condition_level
        next
      end

点评

可能是我没写清楚造成你的误解……已于文章中加入补充文字(红色部分)。所以我要问的其实是如何设定SP判定。  发表于 2011-3-25 18:27
请勿一题多问……  发表于 2011-3-25 17:33

Lv1.梦旅人

梦石
0
星屑
50
在线时间
63 小时
注册时间
2008-11-20
帖子
45
2
发表于 2011-3-23 23:34:42 | 只看该作者
这样应该行的.....你去试试。你对脚本有一定的了解,所以应该能看懂原理.
就是用回合(只有这个东西我看是两个变量)加载定义了一个跟hp判定类似的sp判定,回合的第一个格子是turn_a,第二个是turn_b     当turn_a为900的时候 返回turn_b(这个数字是你想要的sp百分比)
  1. #==============================================================================
  2. # ■ Game_Enemy
  3. #------------------------------------------------------------------------------
  4. #  處理敵人的類別。本類別在 Game_Troop 類別 ($game_troop) 的
  5. #  內部使用。
  6. #==============================================================================

  7. module RPG
  8.   class Enemy
  9.     class Action
  10.       #------------------------------------------------------------------------
  11.       #定义condition_sp   (标识为回合a=900,回合b=sp百分比)
  12.       #作用方法基本同等于hp百分比
  13.       #------------------------------------------------------------------------
  14.       def condition_sp
  15.         return @condition_turn_a == 900 ? @condition_turn_b : 100
  16.       end
  17.       #------------------------------------------------------------------------
  18.       #重新定义turn_a & turn_b
  19.       #------------------------------------------------------------------------
  20.       def condition_turn_a
  21.         return @condition_turn_a != 900 ? @condition_turn_a : 0
  22.       end
  23.       def condition_turn_b
  24.         return @condition_turn_a != 900 ? @condition_turn_b : 1
  25.       end
  26.     end
  27.   end
  28. end


  29. #==============================================================================
  30. # ■ Game_Enemy
  31. #------------------------------------------------------------------------------
  32. #  處理敵人的類別。本類別在 Game_Troop 類別 ($game_troop) 的
  33. #  內部使用。
  34. #==============================================================================

  35. class Game_Enemy < Game_Battler
  36.   #--------------------------------------------------------------------------
  37.   # ● 初始化物件
  38.   #     troop_id     : 循環 ID
  39.   #     member_index : 循環成員的索引
  40.   #--------------------------------------------------------------------------
  41.   def initialize(troop_id, member_index)
  42.     super()
  43.     @troop_id = troop_id
  44.     @member_index = member_index
  45.     troop = $data_troops[@troop_id]
  46.     @enemy_id = troop.members[@member_index].enemy_id
  47.     enemy = $data_enemies[@enemy_id]
  48.     @battler_name = enemy.battler_name
  49.     @battler_hue = enemy.battler_hue
  50.     @hp = maxhp
  51.     @sp = maxsp
  52.     @hidden = troop.members[@member_index].hidden
  53.     @immortal = troop.members[@member_index].immortal
  54.   end
  55.   #--------------------------------------------------------------------------
  56.   # ● 獲取敵人 ID
  57.   #--------------------------------------------------------------------------
  58.   def id
  59.     return @enemy_id
  60.   end
  61.   #--------------------------------------------------------------------------
  62.   # ● 獲取索引
  63.   #--------------------------------------------------------------------------
  64.   def index
  65.     return @member_index
  66.   end
  67.   #--------------------------------------------------------------------------
  68.   # ● 獲取名稱
  69.   #--------------------------------------------------------------------------
  70.   def name
  71.     return $data_enemies[@enemy_id].name
  72.   end
  73.   #--------------------------------------------------------------------------
  74.   # ● 獲取基本 MaxHP
  75.   #--------------------------------------------------------------------------
  76.   def base_maxhp
  77.     return $data_enemies[@enemy_id].maxhp
  78.   end
  79.   #--------------------------------------------------------------------------
  80.   # ● 獲取基本 MaxSP
  81.   #--------------------------------------------------------------------------
  82.   def base_maxsp
  83.     return $data_enemies[@enemy_id].maxsp
  84.   end
  85.   #--------------------------------------------------------------------------
  86.   # ● 獲取基本力量
  87.   #--------------------------------------------------------------------------
  88.   def base_str
  89.     return $data_enemies[@enemy_id].str
  90.   end
  91.   #--------------------------------------------------------------------------
  92.   # ● 獲取基本熟練
  93.   #--------------------------------------------------------------------------
  94.   def base_dex
  95.     return $data_enemies[@enemy_id].dex
  96.   end
  97.   #--------------------------------------------------------------------------
  98.   # ● 獲取基本速度
  99.   #--------------------------------------------------------------------------
  100.   def base_agi
  101.     return $data_enemies[@enemy_id].agi
  102.   end
  103.   #--------------------------------------------------------------------------
  104.   # ● 獲取基本魔力
  105.   #--------------------------------------------------------------------------
  106.   def base_int
  107.     return $data_enemies[@enemy_id].int
  108.   end
  109.   #--------------------------------------------------------------------------
  110.   # ● 獲取基本攻擊力
  111.   #--------------------------------------------------------------------------
  112.   def base_atk
  113.     return $data_enemies[@enemy_id].atk
  114.   end
  115.   #--------------------------------------------------------------------------
  116.   # ● 獲取基本物理防禦
  117.   #--------------------------------------------------------------------------
  118.   def base_pdef
  119.     return $data_enemies[@enemy_id].pdef
  120.   end
  121.   #--------------------------------------------------------------------------
  122.   # ● 獲取基本魔法防禦
  123.   #--------------------------------------------------------------------------
  124.   def base_mdef
  125.     return $data_enemies[@enemy_id].mdef
  126.   end
  127.   #--------------------------------------------------------------------------
  128.   # ● 獲取基本迴避修正
  129.   #--------------------------------------------------------------------------
  130.   def base_eva
  131.     return $data_enemies[@enemy_id].eva
  132.   end
  133.   #--------------------------------------------------------------------------
  134.   # ● 普通攻擊 獲取攻擊方動畫 ID
  135.   #--------------------------------------------------------------------------
  136.   def animation1_id
  137.     return $data_enemies[@enemy_id].animation1_id
  138.   end
  139.   #--------------------------------------------------------------------------
  140.   # ● 普通攻擊 獲取對像方動畫 ID
  141.   #--------------------------------------------------------------------------
  142.   def animation2_id
  143.     return $data_enemies[@enemy_id].animation2_id
  144.   end
  145.   #--------------------------------------------------------------------------
  146.   # ● 獲取屬性修正值
  147.   #     element_id : 屬性 ID
  148.   #--------------------------------------------------------------------------
  149.   def element_rate(element_id)
  150.     # 獲取對應屬性有效度的數值
  151.     table = [0,200,150,100,50,0,-100]
  152.     result = table[$data_enemies[@enemy_id].element_ranks[element_id]]
  153.     # 狀態能防禦本屬性的情況下效果減半
  154.     for i in @states
  155.       if $data_states[i].guard_element_set.include?(element_id)
  156.         result /= 2
  157.       end
  158.     end
  159.     # 過程結束
  160.     return result
  161.   end
  162.   #--------------------------------------------------------------------------
  163.   # ● 獲取屬性有效度
  164.   #--------------------------------------------------------------------------
  165.   def state_ranks
  166.     return $data_enemies[@enemy_id].state_ranks
  167.   end
  168.   #--------------------------------------------------------------------------
  169.   # ● 屬性防禦判定
  170.   #     state_id : 狀態 ID
  171.   #--------------------------------------------------------------------------
  172.   def state_guard?(state_id)
  173.     return false
  174.   end
  175.   #--------------------------------------------------------------------------
  176.   # ● 獲取普通攻擊屬性
  177.   #--------------------------------------------------------------------------
  178.   def element_set
  179.     return []
  180.   end
  181.   #--------------------------------------------------------------------------
  182.   # ● 獲取普通攻擊的狀態變化 (+)
  183.   #--------------------------------------------------------------------------
  184.   def plus_state_set
  185.     return []
  186.   end
  187.   #--------------------------------------------------------------------------
  188.   # ● 獲取普通攻擊的狀態變化 (-)
  189.   #--------------------------------------------------------------------------
  190.   def minus_state_set
  191.     return []
  192.   end
  193.   #--------------------------------------------------------------------------
  194.   # ● 獲取行動
  195.   #--------------------------------------------------------------------------
  196.   def actions
  197.     return $data_enemies[@enemy_id].actions
  198.   end
  199.   #--------------------------------------------------------------------------
  200.   # ● 獲取 EXP
  201.   #--------------------------------------------------------------------------
  202.   def exp
  203.     return $data_enemies[@enemy_id].exp
  204.   end
  205.   #--------------------------------------------------------------------------
  206.   # ● 獲取金錢
  207.   #--------------------------------------------------------------------------
  208.   def gold
  209.     return $data_enemies[@enemy_id].gold
  210.   end
  211.   #--------------------------------------------------------------------------
  212.   # ● 獲取物品 ID
  213.   #--------------------------------------------------------------------------
  214.   def item_id
  215.     return $data_enemies[@enemy_id].item_id
  216.   end
  217.   #--------------------------------------------------------------------------
  218.   # ● 獲取武器 ID
  219.   #--------------------------------------------------------------------------
  220.   def weapon_id
  221.     return $data_enemies[@enemy_id].weapon_id
  222.   end
  223.   #--------------------------------------------------------------------------
  224.   # ● 獲取防具 ID
  225.   #--------------------------------------------------------------------------
  226.   def armor_id
  227.     return $data_enemies[@enemy_id].armor_id
  228.   end
  229.   #--------------------------------------------------------------------------
  230.   # ● 獲取寶物出現率
  231.   #--------------------------------------------------------------------------
  232.   def treasure_prob
  233.     return $data_enemies[@enemy_id].treasure_prob
  234.   end
  235.   #--------------------------------------------------------------------------
  236.   # ● 取得戰鬥畫面 X 座標
  237.   #--------------------------------------------------------------------------
  238.   def screen_x
  239.     return $data_troops[@troop_id].members[@member_index].x
  240.   end
  241.   #--------------------------------------------------------------------------
  242.   # ● 取得戰鬥畫面 Y 座標
  243.   #--------------------------------------------------------------------------
  244.   def screen_y
  245.     return $data_troops[@troop_id].members[@member_index].y
  246.   end
  247.   #--------------------------------------------------------------------------
  248.   # ● 取得戰鬥畫面 Z 座標
  249.   #--------------------------------------------------------------------------
  250.   def screen_z
  251.     return screen_y
  252.   end
  253.   #--------------------------------------------------------------------------
  254.   # ● 逃跑
  255.   #--------------------------------------------------------------------------
  256.   def escape
  257.     # 設定擊中標誌
  258.     @hidden = true
  259.     # 清除目前行動
  260.     self.current_action.clear
  261.   end
  262.   #--------------------------------------------------------------------------
  263.   # ● 變身
  264.   #     enemy_id : 變身為的敵人 ID
  265.   #--------------------------------------------------------------------------
  266.   def transform(enemy_id)
  267.     # 變更敵人 ID
  268.     @enemy_id = enemy_id
  269.     # 變更戰鬥圖形
  270.     @battler_name = $data_enemies[@enemy_id].battler_name
  271.     @battler_hue = $data_enemies[@enemy_id].battler_hue
  272.     # 在產生行動
  273.     make_action
  274.   end
  275.   #--------------------------------------------------------------------------
  276.   # ● 產生行動
  277.   #--------------------------------------------------------------------------
  278.   def make_action
  279.     # 清除目前行動
  280.     self.current_action.clear
  281.     # 無法行動的情況
  282.     unless self.movable?
  283.       # 過程結束
  284.       return
  285.     end
  286.     # 抽取現在有效的行動
  287.     available_actions = []
  288.     rating_max = 0
  289.     for action in self.actions
  290.       # 確認回合條件
  291.       n = $game_temp.battle_turn
  292.       a = action.condition_turn_a
  293.       b = action.condition_turn_b
  294.       if (b == 0 and n != a) or
  295.          (b > 0 and (n < 1 or n < a or n % b != a % b))
  296.         next
  297.       end
  298.       # 確認 HP 條件
  299.       if self.hp * 100.0 / self.maxhp > action.condition_hp
  300.         next
  301.       end
  302. #------------------------------------------------------------------------------      
  303.       # 確認 SP 條件
  304.       if self.sp * 100.0 / self.maxsp > action.condition_sp
  305.         next
  306.       end
  307. #------------------------------------------------------------------------------      
  308.       # 確認等級條件
  309.       if $game_party.max_level < action.condition_level
  310.         next
  311.       end
  312.       # 確認開關條件
  313.       switch_id = action.condition_switch_id
  314.       if switch_id > 0 and $game_switches[switch_id] == false
  315.         next
  316.       end
  317.       # 符合條件 : 加入本行動
  318.       available_actions.push(action)
  319.       if action.rating > rating_max
  320.         rating_max = action.rating
  321.       end
  322.     end
  323.     # 最大概率值作為 3 合計計算(0 除外)
  324.     ratings_total = 0
  325.     for action in available_actions
  326.       if action.rating > rating_max - 3
  327.         ratings_total += action.rating - (rating_max - 3)
  328.       end
  329.     end
  330.     # 概率合計不為 0 的情況下
  331.     if ratings_total > 0
  332.       # 產生隨機數
  333.       value = rand(ratings_total)
  334.       # 設定對應產生隨機數的目前行動
  335.       for action in available_actions
  336.         if action.rating > rating_max - 3
  337.           if value < action.rating - (rating_max - 3)
  338.             self.current_action.kind = action.kind
  339.             self.current_action.basic = action.basic
  340.             self.current_action.skill_id = action.skill_id
  341.             self.current_action.decide_random_target_for_enemy
  342.             return
  343.           else
  344.             value -= action.rating - (rating_max - 3)
  345.           end
  346.         end
  347.       end
  348.     end
  349.   end
  350. end
复制代码
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
9 小时
注册时间
2011-3-23
帖子
8
3
 楼主| 发表于 2011-3-24 22:49:37 | 只看该作者
本帖最后由 space20021 于 2011-3-25 18:23 编辑

我把你的脚本整个贴上来之后,试了发现它的判定好像有问题
明明SP还足够,可是却不使用这一项技能,跳到下一个技能去了
(动作设定的优先级那边有检查过了,两个技能优先级的差值确实有超过2)
回复

使用道具 举报

Lv2.观梦者

虚構歪曲

梦石
0
星屑
334
在线时间
1196 小时
注册时间
2010-12-18
帖子
3928

贵宾

4
发表于 2011-3-25 17:34:42 | 只看该作者
我设定敌人会使用一招消耗SP的招式,可是问题是当SP耗光后敌人就不会动了……汗

请确定你在本技能外还存在其他行动。
如果存在的场合,可以修改优先级,或者给技能加个SP的发动判定。
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
9 小时
注册时间
2011-3-23
帖子
8
5
 楼主| 发表于 2011-3-25 21:18:03 | 只看该作者
忧雪の伤 发表于 2011-3-25 17:34
请确定你在本技能外还存在其他行动。
如果存在的场合,可以修改优先级,或者给技能加个SP的发动判定。 ...

嗯,有另外一个回复SP的行动,现在的问题就是不知道怎么做出SP判定
回复

使用道具 举报

Lv2.观梦者

虚構歪曲

梦石
0
星屑
334
在线时间
1196 小时
注册时间
2010-12-18
帖子
3928

贵宾

6
发表于 2011-3-26 09:40:52 | 只看该作者
本帖最后由 忧雪の伤 于 2011-3-26 09:41 编辑
space20021 发表于 2011-3-25 21:18
嗯,有另外一个回复SP的行动,现在的问题就是不知道怎么做出SP判定
  1. module RPG
  2.   class Enemy
  3.     class Action
  4.       alias :old_initialize :initialize
  5.       def initialize
  6.         old_initialize
  7.         @condition_level = 0
  8.       end
  9.     end
  10.   end
  11. end



  12. class Game_Enemy < Game_Battler
  13.   def make_action
  14.     self.current_action.clear
  15.     unless self.movable?
  16.       return
  17.     end
  18.     available_actions = []
  19.     rating_max = 0
  20.     for action in self.actions
  21.       n = $game_temp.battle_turn
  22.       a = action.condition_turn_a
  23.       b = action.condition_turn_b
  24.       if (b == 0 and n != a) or
  25.          (b > 0 and (n < 1 or n < a or n % b != a % b))
  26.         next
  27.       end
  28.       if self.hp * 100.0 / self.maxhp > action.condition_hp
  29.         next
  30.       end
  31.       if self.sp <= action.condition_level
  32.         next
  33.       end
  34.       switch_id = action.condition_switch_id
  35.       if switch_id > 0 and $game_switches[switch_id] == false
  36.         next
  37.       end
  38.       available_actions.push(action)
  39.       if action.rating > rating_max
  40.         rating_max = action.rating
  41.       end
  42.     end
  43.     ratings_total = 0
  44.     for action in available_actions
  45.       if action.rating > rating_max - 3
  46.         ratings_total += action.rating - (rating_max - 3)
  47.       end
  48.     end
  49.     if ratings_total > 0
  50.       value = rand(ratings_total)
  51.       for action in available_actions
  52.         if action.rating > rating_max - 3
  53.           if value < action.rating - (rating_max - 3)
  54.             self.current_action.kind = action.kind
  55.             self.current_action.basic = action.basic
  56.             self.current_action.skill_id = action.skill_id
  57.             self.current_action.decide_random_target_for_enemy
  58.             return
  59.           else
  60.             value -= action.rating - (rating_max - 3)
  61.           end
  62.         end
  63.       end
  64.     end
  65.   end
  66. end
复制代码


使用方法就是把行动里面的等级变成了sp……跟你的思路一样……
回复

使用道具 举报

头像被屏蔽

Lv1.梦旅人 (禁止发言)

梦石
0
星屑
50
在线时间
31 小时
注册时间
2011-3-2
帖子
122
7
发表于 2011-3-26 09:41:10 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
签名被屏蔽
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
9 小时
注册时间
2011-3-23
帖子
8
8
 楼主| 发表于 2011-3-26 14:22:33 | 只看该作者
本帖最后由 space20021 于 2011-3-26 14:27 编辑

感谢大家,不过不知道为什么还是有个小bug
比如我设定

等级 50 以上时(也就是SP 50 以上时),「使用A技能」
如果SP不够就「攻击」

实际测试战斗,当敌人SP剩余量不足50但大于0的时候,
敌人会按照预定的设定进行「攻击」
但是当敌人SP只剩0的时候,他不会「攻击」,而是呆站着不动
回复

使用道具 举报

Lv2.观梦者

虚構歪曲

梦石
0
星屑
334
在线时间
1196 小时
注册时间
2010-12-18
帖子
3928

贵宾

9
发表于 2011-3-26 14:27:21 | 只看该作者
space20021 发表于 2011-3-26 14:22
感谢大家,不过不知道为什么还是有个小bug
比如我设定

@condition_level = 0
改为
@condition_level = -1
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
9 小时
注册时间
2011-3-23
帖子
8
10
 楼主| 发表于 2011-3-26 15:37:20 | 只看该作者
还是不行…..
我开了一个新的project来测试以避免脚本冲突问题,不过那个bug还是存在
你那边测试的话可以成功吗?如果可以的话就是我自己的问题了……
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2025-7-20 02:35

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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