设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 114|回复: 0

[转载发布] Layered States

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    9071

    主题

    864

    回帖

    6万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    58883
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    68848

    灌水之王

    发表于 2026-8-2 12:30:19 | 显示全部楼层 |阅读模式
    Credits: Harosata

    Terms of Use:  Free To Use, though a spot on the credit roll would be nice.  

    Here's a script if you want to layer some of your states like a sandwich.  Think of this like Himework's Permanent States and Neon Black's Stacking States having a well-behaved baby.

    Okay, let me give you a better example.  Barrier States (tagged with <LayerState>) will go into one array while your normal states do their own business.  The latest layered state plus other layered <LayerActive> states  will give you a multiplicative boost, though only the latest layered state will be affected by sources of removals.  You can also add on other tags to change when you can apply these states, for example, adding on Level 2 Barriers when you have Level 1 Barriers present.  Also features <LayerPurge> if you care little about the stacking feature.

    While this script is affected by adding/removing states normally, the Layered States were designed not to be removed on Death (unless you use <LayerPurgeDeath>).

                    Ruby:       
    1. module DL
    2.   module LAYERSTATE
    3.     MAXLAYER = 10
    4.    
    5. =begin
    6. #==============================================================================
    7. ** Layered States
    8. Author: Harosata
    9. ------------------------------------------------------------------------------
    10. Ever want to place layers upon layers of protection spells?
    11. Any State you notetag with <LayerState> will head into a shared array where the
    12. latest state plus any <LayerActive> states will be effective.  Damage will remove
    13. the latest state, though you can place <LayerRemove: n> on a Skill
    14. to remove more layers at once!  Set MAXLAYER to the max amount of Layered States.
    15. ------------------------------------------------------------------------------
    16. You can also tag both layered and regular states to limit when they apply.
    17. Use <ApplyWhen: state_ids> once you have a required state or
    18. <RestrictWhen: state_ids> to stop adding more when you have that state.
    19. Use <ApplyCurrent: state_ids> to add a state or <RestrictCurrent: state_ids>
    20. to prevent a state based on the latest layered state. You can also place
    21. <FinalLayer> to stop adding more Layered States!
    22. ------------------------------------------------------------------------------
    23. Finaly, you can place <LayerPurge> on a layered state or skill if you want
    24. to remove all the involved Layered States when that state is removed.
    25. Or you can place <LayerPurgeDeath> on a state if you want them gone when you die.
    26. ------------------------------------------------------------------------------
    27. And also, there are a few methods for battlers if you need some information.
    28. .layer_state_count can count your layered states or used with a (state_id)
    29. for a specific counter.  .layer_state_current will return the id of the latest
    30. layered state.  .layer_state_clear will clean up your layered states quickly!
    31. ------------------------------------------------------------------------------
    32. =end
    33.     #use commas on Restrict/Apply for more states.
    34.     Regex1 = /<LayerState>/i #Marks this state for Layer Array
    35.     Regex2 = /<RestrictWhen:\s*(.*)\s*>/i #Cannot add when one of these states is present.
    36.     Regex2a = /<ApplyWhen:\s*(.*)\s*>/i #Add only when one of these states present
    37.     Regex3 = /<ApplyCurrent:\s*(.*)\s*>/i #add if the current layer is one of these.
    38.     Regex3a = /<RestrictCurrent:\s*(.*)\s*>/i #don't add if the current layer is not one of these.
    39.     Regex4 = /<LayerRemove:\s*(\d+)\s*>/i #remove this many layers with the skill
    40.     Regex5 = /<LayerPurge>/i #Remove states regardless of position
    41.     Regex5a = /<LayerPurgeDeath>/i #remove states on death regardless of position
    42.     Regex6 = /<LayerActive>/i #remove states on death regardless of position
    43.     Regex7 = /<FinalLayer>/i #No other layered states can be applied after this.
    44.   end
    45. end
    46. module RPG
    47.   class BaseItem
    48.    
    49.     def layered?
    50.       res = self.note.match(DL::LAYERSTATE::Regex1)
    51.       return res
    52.     end
    53.    
    54.     def restrict_when
    55.       if @note =~ DL::LAYERSTATE::Regex2
    56.         ints = []
    57.         for x in $1.split(",")
    58.           ints.push(x.to_i)
    59.         end
    60.         return ints
    61.       else
    62.         return []
    63.       end
    64.     end
    65.     def apply_when
    66.       if @note =~ DL::LAYERSTATE::Regex2a
    67.         ints = []
    68.         for x in $1.split(",")
    69.           ints.push(x.to_i)
    70.         end
    71.         return ints
    72.       else
    73.         return []
    74.       end
    75.     end
    76.       
    77.     def current_apply
    78.       if @note =~ DL::LAYERSTATE::Regex3
    79.         ints = []
    80.         for x in $1.split(",")
    81.           ints.push(x.to_i)
    82.         end
    83.         return ints
    84.       else
    85.         return []
    86.       end
    87.     end
    88.     def current_restrict
    89.       if @note =~ DL::LAYERSTATE::Regex3a
    90.         ints = []
    91.         for x in $1.split(",")
    92.           ints.push(x.to_i)
    93.         end
    94.         return ints
    95.       else
    96.         return []
    97.       end
    98.     end
    99.    
    100.     def layer_remove
    101.       bob = 1
    102.       res = self.note.match(DL::LAYERSTATE::Regex4)
    103.       bob = res[1].to_i if res
    104.       return bob
    105.     end
    106.     def layer_purge
    107.       res = self.note.match(DL::LAYERSTATE::Regex5)
    108.       return res
    109.     end
    110.     def layer_purge_death
    111.       res = self.note.match(DL::LAYERSTATE::Regex5a)
    112.       return res
    113.     end
    114.     def active_layer?
    115.       res = self.note.match(DL::LAYERSTATE::Regex6)
    116.       return res
    117.     end
    118.     def final_layer?
    119.       res = self.note.match(DL::LAYERSTATE::Regex7)
    120.       return res
    121.     end
    122.    
    123.   end
    124. end
    125. class Game_Battler < Game_BattlerBase
    126.   alias :dl_layer_initialize :initialize
    127.   def initialize
    128.     @layer_states ||= []
    129.     @layer_turns ||= []
    130.     dl_layer_initialize
    131.   end
    132.   def feature_objects
    133.     layer_states + super
    134.   end
    135.   def layer_states(pure = false)
    136.     return @layer_states.collect {|i| $data_states[i]} if pure
    137.     bob = @layer_states.select{|i| $data_states[i].active_layer?}
    138.     bob = bob.collect{|i| $data_states[i]}
    139.     bob << $data_states[@layer_states.last] if @layer_states.count > 0 and !$data_states[@layer_states.last].active_layer?
    140.     return bob
    141.   end
    142.   alias :dl_layer_die :die
    143.   def die
    144.     dl_layer_die
    145.     @layer_states.count.times.each do |i|
    146.       if $data_states[@layer_states[i]].layer_purge_death
    147.         @layer_states[i] = nil
    148.         @layer_turns[i] = nil
    149.       end
    150.     end
    151.     @layer_states = @layer_states.compact
    152.     @layer_turns = @layer_turns.compact
    153.   end
    154.   def layer_states_apply(state_id, full = true)
    155.     if full
    156.       return false if @layer_states.count >= DL::LAYERSTATE::MAXLAYER
    157.       return false if layer_states(true).any? {|s| s.final_layer?}
    158.       return false if states.any? {|s| s.final_layer?}
    159.     end
    160.     bob = $data_states[state_id]
    161.     sam = @states + @layer_states
    162.     return false if  bob.restrict_when.count > 0 and bob.restrict_when.any? {|s| sam.include?(s)}
    163.     return true if  bob.apply_when.count > 0 and bob.apply_when.any? {|s| sam.include?(s)}
    164.     return false if  bob.current_restrict.count > 0 and @layer_states.count > 0 and bob.current_restrict.any? {|s| @layer_states.last == s}
    165.     return true if  bob.current_apply.count > 0 and @layer_states.count > 0 and bob.current_apply.any?{|s| @layer_states.last == s}
    166.     return (bob.apply_when.count > 0  or bob.current_apply.count > 0 ) ? false : true
    167.   end
    168.   alias :dl_layer_remove_battle_states :remove_battle_states
    169.   def remove_battle_states
    170.     dl_layer_remove_battle_states
    171.     layer_states(true).reverse.each do |state|
    172.       state.remove_at_battle_end ? remove_state(state.id) : break
    173.     end
    174.     bob = []
    175.     layer_states(true).each do |s|
    176.       if s.layer_purge and s.remove_at_battle_end
    177.         bob << s.id
    178.       end
    179.     end
    180.     bob = bob.uniq
    181.     if bob.count > 0
    182.       @layer_states.count.times.each do |i|
    183.         @layer_turns[i] = nil if bob.include?(@layer_states[i])
    184.         @layer_states[i] = nil if bob.include?(@layer_states[i])
    185.       end
    186.       @layer_states = @layer_states.compact
    187.       @layer_turns = @layer_turns.compact
    188.     end
    189.   end
    190.   def item_effect_test(user, item, effect)
    191.     case effect.code
    192.     when EFFECT_RECOVER_HP
    193.       hp < mhp || effect.value1 < 0 || effect.value2 < 0
    194.     when EFFECT_RECOVER_MP
    195.       mp < mmp || effect.value1 < 0 || effect.value2 < 0
    196.     when EFFECT_ADD_STATE
    197.       $data_states[effect.data_id].layered? ? (layer_states_apply(effect.data_id)) : (!state?(effect.data_id) and layer_states_apply(effect.data_id, false))
    198.     when EFFECT_REMOVE_STATE
    199.       if @layer_states.count > 0 and $data_states[effect.data_id].layered?
    200.         return true if @layer_states.include?(effect.data_id) and (item.layer_purge or $data_states[effect.data_id].layer_purge)
    201.         return true if @layer_states.last == effect.data_id
    202.         return false
    203.       else
    204.         return state?(effect.data_id)
    205.       end
    206.     when EFFECT_ADD_BUFF
    207.       !buff_max?(effect.data_id)
    208.     when EFFECT_ADD_DEBUFF
    209.       !debuff_max?(effect.data_id)
    210.     when EFFECT_REMOVE_BUFF
    211.       buff?(effect.data_id)
    212.     when EFFECT_REMOVE_DEBUFF
    213.       debuff?(effect.data_id)
    214.     when EFFECT_LEARN_SKILL
    215.       actor? && !skills.include?($data_skills[effect.data_id])
    216.     else
    217.       true
    218.     end
    219.   end
    220.   alias :dl_layer_add_state :add_state
    221.   def add_state(state_id)
    222.     if layer_state_addable?(state_id)
    223.       if layer_states_apply(state_id)
    224.         add_new_layer_state(state_id)
    225.         @result.added_states.push(state_id)
    226.       end
    227.     elsif layer_states_apply(state_id, false)
    228.       dl_layer_add_state(state_id)
    229.     end
    230.   end
    231.   def add_new_layer_state(state_id)
    232.     bob = $data_states[state_id]
    233.     @layer_states.push(state_id)
    234.     @layer_turns.push([bob.min_turns + rand(1 + [bob.max_turns - bob.min_turns, 0].max), bob.steps_to_remove])
    235.     on_restrict if restriction > 0
    236.     refresh
    237.   end
    238.   def layer_state_addable?(state_id)
    239.     $data_states[state_id] && $data_states[state_id].layered? && !state_resist?(state_id)
    240.   end
    241.   alias :dl_layer_update_state_turns :update_state_turns
    242.   def update_state_turns
    243.     dl_layer_update_state_turns
    244.     if @layer_states.count > 0
    245.       @layer_turns.last[0] -= 1 if @layer_turns.last[0] > 0
    246.     end
    247.   end
    248.   alias :dl_layer_remove_state :remove_state
    249.   def remove_state(state_id)
    250.     if @layer_states.count > 0
    251.       if @layer_states.include?(state_id) and $data_states[state_id].layer_purge
    252.         @layer_states.count.times.each do |i|
    253.           @layer_turns[i] = nil if  @layer_states[i] == state_id
    254.           @layer_states[i] = nil if  @layer_states[i] == state_id
    255.         end
    256.         @layer_states = @layer_states.compact
    257.         @layer_turns = @layer_turns.compact
    258.         refresh
    259.         @result.removed_states.push(state_id).uniq!
    260.       elsif @layer_states.last == state_id
    261.         @layer_states.pop
    262.         @layer_turns.pop
    263.         refresh
    264.         @result.removed_states.push(state_id)
    265.       end
    266.     else
    267.       dl_layer_remove_state(state_id)
    268.     end
    269.   end
    270.   alias :dl_layer_remove_states_auto :remove_states_auto
    271.   def remove_states_auto(timing)
    272.     dl_layer_remove_states_auto(timing)
    273.     if @layer_states.count > 0
    274.       if @layer_turns.last[0] == 0 and $data_states[@layer_states.last].auto_removal_timing == timing
    275.         remove_state(@layer_states.last)
    276.       end
    277.     end
    278.   end
    279.   alias :dl_layer_remove_states_by_damage :remove_states_by_damage
    280.   def remove_states_by_damage
    281.     dl_layer_remove_states_by_damage
    282.     if @layer_states.count > 0
    283.       remove_state(@layer_states.last) if $data_states[@layer_states.last].remove_by_damage && rand(100) < $data_states[@layer_states.last].chance_by_damage
    284.     end
    285.   end
    286.   alias :dl_layer_item_effect_remove_state :item_effect_remove_state
    287.   def item_effect_remove_state(user, item, effect)
    288.     if $data_states[effect.data_id].layered?
    289.       if ($data_states[effect.data_id].layer_purge or item.layer_purge)
    290.         if @layer_states.include?(effect.data_id) and rand < effect.value1
    291.           @layer_states.count.times.each do |i|
    292.             @layer_turns[i] = nil if  @layer_states[i] == effect.data_id
    293.             @layer_states[i] = nil if  @layer_states[i] == effect.data_id
    294.           end
    295.           @layer_states = @layer_states.compact
    296.           @layer_turns = @layer_turns.compact
    297.           refresh
    298.           @result.removed_states.push(effect.data_id).uniq!
    299.           @result.success = true
    300.         end
    301.       else
    302.         @layer_remove.push([effect.data_id, effect.value1])
    303.       end
    304.     else
    305.       dl_layer_item_effect_remove_state(user, item, effect)
    306.     end
    307.   end
    308.   alias :dl_layer_item_apply :item_apply
    309.   def item_apply(user, item)
    310.     @layer_remove = []
    311.     dl_layer_item_apply(user, item)
    312.     if @result.hit? and @layer_remove.count > 0
    313.       item.layer_remove.times.each do |i|
    314.         break if @layer_states.count == 0
    315.         bob = false
    316.         @layer_remove.each do |lr|
    317.           if lr[0] == @layer_states.last and rand < lr[1]
    318.             bob = true
    319.             @success = true
    320.           end
    321.         end
    322.         if bob
    323.           @layer_states.pop
    324.           @layer_turns.pop
    325.         end
    326.       end
    327.     end
    328.   end
    329.   def layer_state_icons
    330.     bob = [0]
    331.     if @layer_states.count > 0
    332.       @layer_states.each do |s|
    333.         bob.push($data_states[s].icon_index)
    334.       end
    335.     end
    336.     bob.delete(0)
    337.     return bob
    338.   end
    339.   alias :dl_layer_most_important_state_text :most_important_state_text
    340.   def most_important_state_text
    341.     return layer_states.last.message3 if layer_states.last and !state.message3.empty?
    342.     return dl_layer_most_important_state_text
    343.   end
    344.   def layer_state_count(type = 0)
    345.     return type > 0 ? @layer_states.count(type) : @layer_states.count
    346.   end
    347.   def layer_state_current
    348.     return nil if @layer_states == 0
    349.     return @layer_states.last
    350.   end
    351.    
    352.   def layer_states_clear
    353.     @layer_states = []
    354.     @layer_turns = []
    355.   end
    356. end
    357. class Game_Actor < Game_Battler
    358.   alias :dl_layer_on_player_walk :on_player_walk
    359.   def on_player_walk
    360.     dl_layer_on_player_walk
    361.     if $game_player.normal_walk?
    362.       if @layer_states.count > 0
    363.         @layer_turns.last[1] -= 1 if @layer_turns.last[1] > 0
    364.         remove_state(@layer_states.last) if @layer_turns.last[1] == 0
    365.       end
    366.     end
    367.   end
    368. end
    369. class Window_Base < Window
    370.   def draw_actor_icons(actor, x, y, width = 96)
    371.     licons = (actor.layer_state_icons)[[actor.layer_state_icons.count - 4, 0].max, DL::LAYERSTATE::MAXLAYER]
    372.     licons.each_with_index {|n, i| draw_icon(n, x + 1 * i, y) }
    373.     icons = (actor.state_icons + actor.buff_icons)[0, [(width - (licons.count > 0 ? 24 : 0)) / 24,0].max]
    374.     icons.each_with_index {|n, i| draw_icon(n, x + (licons.count > 0 ? 24: 0) + 24 * i, y) }
    375.   end
    376. end
    复制代码




    本贴来自国际rpgmaker官方论坛作者:Harosata处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/layered-states.116528/
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-8-17 11:39 , Processed in 0.113355 second(s), 52 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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