查看: 5280|回复: 16

[原创发布] 【VA】可堆叠状态系统

[复制链接]
梦石
0
星屑
1803
在线时间
133 小时
注册时间
2013-10-6
回帖
181
发表于 2022-5-19 03:47:39 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 不死鸟之翼 于 2022-5-19 03:57 编辑

# 简介

该系统可以让状态变得可堆叠,也就是说重复获得状态时会累计层数。同时,该系统支持将状态作为战斗资源使用,可以让技能以消费状态层数的方式打出。
ss1.jpg
ss2.jpg

# 使用方式

将脚本粘贴到数据库的单独一页内。

# 如何配置状态
给希望可堆叠的状态的备注栏加入一行:
[stackable]
这样重复获得状态时,不仅会刷新持续时间,还会增加计数。
如果希望限制最大层数,可以增加max属性:
[stackable max=3]

# 如何配置技能的发动条件
给希望消费状态的技能的备注栏加入一行:
[consume_state state=状态在数据库内的编号]
默认会消费全部层数的状态。如果想指定消费数量,可以使用count属性,例如:
[consume_state state=26 count=1]
这会消费一层26号状态。
特别地,如果count为0,表示只有在该状态下才能使出技能,但不会消费状态。

# 如何在脚本中读取状态的层数
使用Game_Battler的state_stack_count(skill_id)方法。

# 如何根据技能消费的状态层数决定威力
虽然理论上可以使用state_stack_count,但是由于VA的默认脚本会先支付技能消耗后使出技能,所以在计算伤害时状态层数已经变化了。
Game_Battler实例的last_state_cost属性表示上一次消耗的状态层数。
例如,伤害公式可以写成
1000 * a.last_state_cost
表示造成1000*攻击者发动技能前身上状态层数的伤害。

# 课后作业
1. 如何实现最多可蓄力3次的攻击?
2. 如何实现宝可梦系列的集气拳类技能(一回合蓄力后下一回合发动,但期间若受到攻击则蓄力会被打消而失败)?
3. 如何实现可以叠加威力的中毒debuff?
4. 如何实现技能连击系统(按照特定顺序使出特定技能的话会获得额外收益)?
5. 如何实现状态叠加到5层时即死?

# 使用许可
MIT

# 源代码
[pre lang="ruby" line="1"]# Stackable States by AzureFx
# Revision 20220519.1
# Licensed under the MIT License

def parse_note(note)
  result=[]
  note.each_line{|line|
    m=/\[\s*([^\s=]+)\s*([^\]]+)?\s*\]/i.match(line)
    if m!=nil
      elem=m[1]
      attr={}
      attr_s=m[2]
      if attr_s!=nil
        attr_s.to_enum(:scan, /([^=\s]+)\s*=\s*([^=\s]+)/)
          .map{Regexp.last_match}
          .each{|m|attr[m[1]]=m[2]}
      end
      result.push([elem,attr])
    end
  }
  result
end


class RPG::State
  def stackable?
    if @stackable==nil
      parse_note_stackable
    end
    return @stackable
  end
  
  def max_stack
    if @max_stack==nil
      parse_note_stackable
    end
    return @max_stack
  end
  
  def parse_note_stackable
    stackable=false
    max_stack=0
    parse_note(note).each{|entry|
    elem, attr=entry
      if elem=='stackable'
        stackable=true
        if attr['max']!=nil
          max_stack=attr['max'].to_i
        end
      end
    }
    @stackable=stackable
    @max_stack=max_stack
  end
  
end

class RPG::Skill
  def consume_stack
    if @consume_stack_parsed==nil
      parse_consume_stack
      @consume_stack_parsed=true
    end
    @consume_stack
  end
  
  def parse_consume_stack
    parse_note(note).each{|entry|
      elem, attr=entry
      if elem=='consume_state'
        if attr['state']!=nil
          state_id=attr['state'].to_i
          @consume_stack={state: state_id}
          if attr['count']!=nil
            @consume_stack[:count]=attr['count'].to_i
          end
        end
      end
    }
  end
end

class Game_BattlerBase
  alias clear_states_b1f2b6 clear_states
  def clear_states
    clear_states_b1f2b6
    @state_stacks={}
  end
  
  alias erase_state_b1f2b6 erase_state
  def erase_state(state_id)
    erase_state_b1f2b6(state_id)
    @state_stacks.delete(state_id)
  end
  
  def state_stack_count(state_id)
    @state_stacks[state_id]||0
  end
  
  def decrease_state_stack(state_id, count)
    new_count=state_stack_count(state_id)-count
    if new_count<=0
      erase_state(state_id)
    else
      @state_stacks[state_id]=new_count
    end
  end
  
  alias skill_cost_payable_b1f2b6? skill_cost_payable?
  def skill_cost_payable?(skill)
    cs=skill.consume_stack
    if cs!=nil
      count=state_stack_count(cs[:state])
      cost=cs[:count]||-1
      return false unless count>0&&count>=cost
    end
    skill_cost_payable_b1f2b6?(skill)
  end
  
  alias pay_skill_cost_b1f2b6 pay_skill_cost
  def pay_skill_cost(skill)
    pay_skill_cost_b1f2b6(skill)
    cs=skill.consume_stack
    if cs!=nil
      cost=cs[:count]||-1
      if cost<0
        cost=state_stack_count(cs[:state])
      end
      @@last_state_cost=cost
      decrease_state_stack(cs[:state], cost)
    end
  end
  
  def last_state_cost
    @@last_state_cost
  end
end

class Game_Battler
  alias reset_state_counts_b1f2b6 reset_state_counts
  def reset_state_counts(state_id)
    reset_state_counts_b1f2b6(state_id)
    state = $data_states[state_id]
    if state.stackable?
      if @state_stacks[state_id]==nil
        @state_stacks[state_id]=0
      end
      if state.max_stack<=0||@state_stacks[state_id]<state.max_stack
        @state_stacks[state_id]+=1
      end
    end
  end
  
  alias on_action_end_b1f2b6 on_action_end
  def on_action_end
    on_action_end_b1f2b6
    @@last_state_cost=nil
  end
end

STACK_COUNT_FONT_SIZE=14
STACK_COUNT_FONT=Font.new
STACK_COUNT_FONT.size=STACK_COUNT_FONT_SIZE
STACK_COUNT_FONT.color=Color.new(0,255,0)
STACK_COUNT_FONT.bold=true
STACK_COUNT_FONT.outline=false
STACK_COUNT_FONT.shadow=true

class Window_Base
  alias draw_actor_icons_b1f2b6 draw_actor_icons
  def draw_actor_icons(actor, x, y, width = 96)
    draw_actor_icons_b1f2b6(actor, x, y, width)
    last_font=contents.font
    last_size=last_font.size
    last_bold=last_font.bold
    contents.font=STACK_COUNT_FONT
    actor.states.select{|s|s.icon_index!=0}.each_with_index {|s, i|
      if s.stackable?
        count=actor.state_stack_count(s.id)
        contents.draw_text(x, y+1, 22, STACK_COUNT_FONT_SIZE, count, 2)
      end
    }
    contents.font=last_font
    contents.font.size=last_size
    contents.font.bold=last_bold
  end
end[/pre]

# 版本历史
Revision 20220519.1 初次在P1发布
←你看到一只经常潜水的萌新。
梦石
0
星屑
259
在线时间
74 小时
注册时间
2021-3-3
回帖
14
发表于 2022-5-21 14:31:28 | 显示全部楼层
4{8HOR)NQ4M[3DPWIO_02OE.png 2U$X)@KEI}3J_@9L2]09LKQ.png
您好 我想设置一个需要充能才能释放的技能
可是在游戏中 该技能不需要充能状态也不消耗充能次数也能释放
是我使用有误吗
回复

使用道具 举报

梦石
0
星屑
30103
在线时间
5741 小时
注册时间
2016-3-8
回帖
1662
发表于 2022-5-21 17:36:34 | 显示全部楼层
hq1107 发表于 2022-5-21 14:31
您好 我想设置一个需要充能才能释放的技能
可是在游戏中 该技能不需要充能状态也不消耗充能次数也能释放
...

用这个不香么?
[pre lang="ruby"]#==============================================================================
#
# ¥ Yami Engine Ace - Charge Skill
# -- Last Updated: 2012.05.13
# -- Level: Easy
# -- Requires: none
#
#==============================================================================

$imported = {} if $imported.nil?
$imported["YSE-ChargeSkill"] = true

#==============================================================================
# ¥ Updates
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# 2012.05.13 - Fixed Enemy Charging.
# 2012.03.30 - Fixed Skill Targets.
# 2012.03.29 - Fixed Auto Battle bug.
# 2012.03.27 - Fixed Cancel Charge bug.
# 2012.03.26 - Fixed Battle End bug.
# 2012.03.18 - Started and Finished Script.
#
#==============================================================================
# ¥ Introduction
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script provides charging skill feature. Charging Skill means that skill
# will be used after some turn it was choosen.
#
#==============================================================================
# ¥ Instructions
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# To install this script, open up your script editor and copy/paste this script
# to an open slot below ¥ Materials/‘fÞ but above ¥ Main. Remember to save.
#
# -----------------------------------------------------------------------------
# Skill/Item Notetags - These notetags go in the skill/item notebox in the database.
# -----------------------------------------------------------------------------
# <charge turn: x>
# Make skill be a charge skill with x charging turns.
# -----------------------------------------------------------------------------
# <start charge message>
# example
# </start charge message>
#
# Set the Charging Start Message to example.
# -----------------------------------------------------------------------------
# <continue charge message>
# example
# </continue charge message>
#
# Set the Charging Continue Message to example.
#
#==============================================================================
# ¥ Compatibility
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
# it will run with RPG Maker VX without adjusting.
#
#==============================================================================

module YSE
  module CHARGE_SKILL
   
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    # - Visual Settings -
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    VISUAL_SETTING = { # Start.
      # Message shows when choose a charge skill.
      # Set this to nil to disable.
      :default_msg_start      =>  "%s is charging %s!",
      # Message shows when end a charging turn.
      # Set this to nil to disable.
      :default_msg_continue   =>  "%s continue charging %s...",
    } # End.
   
  end # CHARGE_SKILL
end # YSE

#==============================================================================
# ¥ Editting anything past this point may potentially result in causing
# computer damage, incontinence, explosion of user's head, coma, death, and/or
# halitosis so edit at your own risk.
#==============================================================================

#==============================================================================
# ¡ Regular Expression
#==============================================================================

module YSE
  module REGEXP
  module USABLEITEM
   
    CHARGE_TURN = /<(?:CHARGE_TURN|charge turn):[ ](\d+)?>/i
    START_MSG_BEGIN = /<(?:START_CHARGE_MESSAGE|start charge message)>/i
    START_MSG_END = /<\/(?:START_CHARGE_MESSAGE|start charge message)>/i
    CONT_MSG_BEGIN = /<(?:CONTINUE_CHARGE_MESSAGE|continue charge message)>/i
    CONT_MSG_END = /<\/(?:CONTINUE_CHARGE_MESSAGE|continue charge message)>/i
   
  end # STATE
  end # REGEXP
end # YSE

#==============================================================================
# ¡ DataManager
#==============================================================================

module DataManager
  
  #--------------------------------------------------------------------------
  # alias method: load_database
  #--------------------------------------------------------------------------
  class <<self; alias load_database_ysecs load_database; end
  def self.load_database
    load_database_ysecs
    load_notetags_ysecs
  end
  
  #--------------------------------------------------------------------------
  # new method: load_notetags_ysecs
  #--------------------------------------------------------------------------
  def self.load_notetags_ysecs
    groups = [$data_skills, $data_items]
    for group in groups
      for obj in group
        next if obj.nil?
        obj.load_notetags_ysecs
      end
    end
  end
  
end # DataManager

#==============================================================================
# ¡ RPG::UsableItem
#==============================================================================

class RPG::UsableItem < RPG::BaseItem
  
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :charge_turn
  attr_accessor :start_msg
  attr_accessor :continue_msg
  
  #--------------------------------------------------------------------------
  # common cache: load_notetags_ysecs
  #--------------------------------------------------------------------------
  def load_notetags_ysecs
    @start_begin = false
    @continue_begin = false
    @charge_turn = 0
    #---
    self.note.split(/[\r\n]+/).each { |line|
      case line
      #---
      when YSE::REGEXP::USABLEITEM::CHARGE_TURN
        @charge_turn = $1.to_i
      when YSE::REGEXP::USABLEITEM::START_MSG_BEGIN
        @start_begin = true
      when YSE::REGEXP::USABLEITEM::START_MSG_END
        @start_begin = false
      when YSE::REGEXP::USABLEITEM::CONT_MSG_BEGIN
        @continue_begin = true
      when YSE::REGEXP::USABLEITEM::CONT_MSG_END
        @continue_begin = false
      else
        @start_msg = line.to_s if @start_msg.nil? && @start_begin
        @start_msg += line.to_s if @start_begin
        @continue_msg = line.to_s if @continue_msg.nil? && @continue_begin
        @continue_msg += line.to_s if @continue_begin
      end
    } # self.note.split
    #---
    @charge_turn = nil if @charge_turn <= 0
    @start_msg = YSE::CHARGE_SKILL::VISUAL_SETTING[:default_msg_start]
    @continue_msg = YSE::CHARGE_SKILL::VISUAL_SETTING[:default_msg_continue]
    @start_msg = nil if @start_msg == ""
    @continue_msg = nil if @continue_msg == ""
  end
  
end # RPG::UsableItem

#==============================================================================
# ¡ Game_Battler
#==============================================================================

class Game_Battler < Game_BattlerBase
  
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :charged
  attr_accessor :first_charge

  #--------------------------------------------------------------------------
  # alias method: auto_battle?
  #--------------------------------------------------------------------------
  alias yse_auto_battle_cs auto_battle?
  def auto_battle?
    charging? ? false : yse_auto_battle_cs
  end
  
  #--------------------------------------------------------------------------
  # new method: charging?
  #--------------------------------------------------------------------------
  def charging?
    !@charging_cache.nil? || @charged
  end
  
  #--------------------------------------------------------------------------
  # new method: start_charge
  #--------------------------------------------------------------------------
  def start_charge
    return false if charging?
    return false if current_action.item.charge_turn.nil?
    @charging_cache = current_action.clone
    @charge_turn = current_action.item.charge_turn
    return true
  end
  
  #--------------------------------------------------------------------------
  # new method: current_charging
  #--------------------------------------------------------------------------
  def current_charging
    @charging_cache
  end
  
  #--------------------------------------------------------------------------
  # new method: end_charge
  #--------------------------------------------------------------------------
  def end_charge
    @actions.push(@charging_cache)
    @charging_cache = nil
    @charge_turn = nil
    @charged = true
    return true
  end
  
  #--------------------------------------------------------------------------
  # new method: cancel_charge
  #--------------------------------------------------------------------------
  def cancel_charge
    clear_actions
    @charging_cache = nil
    @charge_turn = nil
    @charged = false
  end
  
  #--------------------------------------------------------------------------
  # new method: update_charge_skill
  #--------------------------------------------------------------------------
  def update_charge_skill
    @charge_turn -= 1
    return end_charge if @charge_turn == 0
    return false
  end
  
  #--------------------------------------------------------------------------
  # alias method: on_battle_end
  #--------------------------------------------------------------------------
  alias yse_on_battle_end_cs on_battle_end
  def on_battle_end
    cancel_charge
    yse_on_battle_end_cs
  end

end # Game_Battler

#==============================================================================
# ¡ Game_Actor
#==============================================================================

class Game_Actor < Game_Battler
  
  #--------------------------------------------------------------------------
  # alias method: inputable?
  #--------------------------------------------------------------------------
  alias yse_inputable_cs inputable?
  def inputable?
    yse_inputable_cs && !charging?
  end
  
end # Game_Actor

#==============================================================================
# ¡ Game_Enemy
#==============================================================================

class Game_Enemy < Game_Battler
  
  #--------------------------------------------------------------------------
  # alias method: make_actions
  #--------------------------------------------------------------------------
  alias yse_make_actions_cs make_actions
  def make_actions
    return super if charging?
    yse_make_actions_cs
  end
  
end # Game_Enemy

#==============================================================================
# ¡ Scene_Battle
#==============================================================================

class Scene_Battle < Scene_Base
  
  #--------------------------------------------------------------------------
  # alias method: execute_action
  #--------------------------------------------------------------------------
  alias yse_execute_action_bacs execute_action
  def execute_action
    return start_charge if @subject.start_charge
    yse_execute_action_bacs
  end
   
  #--------------------------------------------------------------------------
  # alias method: process_action_end
  #--------------------------------------------------------------------------
  alias yse_process_action_end_bacs process_action_end
  def process_action_end
    process_charge_skill
    yse_process_action_end_bacs
  end
  
  #--------------------------------------------------------------------------
  # new method: start_charge
  #--------------------------------------------------------------------------
  def start_charge
    @subject.first_charge = true
    return if @subject.current_action.item.start_msg.nil?
    str = @subject.current_action.item.start_msg
    skill = @subject.current_action.item
    skill_text = sprintf("\\i[%d]%s", skill.icon_index, skill.name)
    text = sprintf(str, @subject.name, skill_text)
    @log_window.add_text(text)
    3.times do @log_window.wait end
    @log_window.back_one
  end

  #--------------------------------------------------------------------------
  # new method: process_charge_skill
  #--------------------------------------------------------------------------
  def process_charge_skill
    return @subject.first_charge = false if @subject.first_charge
    return unless @subject.charging?
    return unless check_charge_turn
    process_action_charge
  end

  #--------------------------------------------------------------------------
  # new method: check_charge_turn
  #--------------------------------------------------------------------------
  def check_charge_turn
    continue = @subject.update_charge_skill
    if continue
      return true
    else
      return false if @subject.current_charging.item.continue_msg.nil?
      str = @subject.current_charging.item.continue_msg
      skill = @subject.current_charging.item
      skill_text = sprintf("\\i[%d]%s", skill.icon_index, skill.name)
      text = sprintf(str, @subject.name, skill_text)
      @log_window.add_text(text)
      3.times do @log_window.wait end
      @log_window.back_one
    end
    return false
  end
  
  #--------------------------------------------------------------------------
  # new method: process_action_charge
  #--------------------------------------------------------------------------
  def process_action_charge
    loop do
      break if $game_troop.all_dead?
      break unless @subject.current_action
      @subject.current_action.prepare
      execute_action if @subject.current_action.valid?
      @subject.remove_current_action
    end
    @subject.charged = false
  end
  
end # Scene_Battle

#==============================================================================
#
# ¥ End of File
#
#==============================================================================[/pre]
回复

使用道具 举报

梦石
0
星屑
1803
在线时间
133 小时
注册时间
2013-10-6
回帖
181
 楼主| 发表于 2022-5-22 21:10:15 | 显示全部楼层
本帖最后由 不死鸟之翼 于 2022-5-22 22:03 编辑
hq1107 发表于 2022-5-21 14:31
您好 我想设置一个需要充能才能释放的技能
可是在游戏中 该技能不需要充能状态也不消耗充能次数也能释放
..


无法复现问题。可能是和你项目里的脚本有冲突?
我发一个demo你看看,艾里克的强击会附加充能状态,横扫消耗1层状态。
另外,stackable只能出现一次,你有了max=3了就不要第一行了。

Project2.zip (1.43 MB, 下载次数: 43)
←你看到一只经常潜水的萌新。
回复

使用道具 举报

梦石
0
星屑
259
在线时间
74 小时
注册时间
2021-3-3
回帖
14
发表于 2022-5-23 12:12:50 | 显示全部楼层
不死鸟之翼 发表于 2022-5-22 21:10
无法复现问题。可能是和你项目里的脚本有冲突?
我发一个demo你看看,艾里克的强击会附加充能状态,横扫 ...

好吧,是我自己的脚本冲突
回复

使用道具 举报

梦石
0
星屑
26338
在线时间
1602 小时
注册时间
2016-1-6
回帖
3444

超评测参与极短28参与极短27参与极短26参与极短25参与

发表于 2022-5-23 12:48:35 | 显示全部楼层
功能好强大啊,那如果使用睡眠魔法是不是永远都睡不醒了?
回复

使用道具 举报

梦石
0
星屑
1803
在线时间
133 小时
注册时间
2013-10-6
回帖
181
 楼主| 发表于 2022-5-24 03:58:52 | 显示全部楼层
plain666 发表于 2022-5-23 12:48
功能好强大啊,那如果使用睡眠魔法是不是永远都睡不醒了?

没懂什么意思
这个脚本只是重复获得状态时累加计数器而已,刷新持续时间的是自带逻辑,因此就算不用这个脚本,重复附加睡眠的话回合数也会重置的。
←你看到一只经常潜水的萌新。
回复

使用道具 举报

梦石
0
星屑
26338
在线时间
1602 小时
注册时间
2016-1-6
回帖
3444

超评测参与极短28参与极短27参与极短26参与极短25参与

发表于 2022-5-25 21:17:36 | 显示全部楼层
不死鸟之翼 发表于 2022-5-24 03:58
没懂什么意思
这个脚本只是重复获得状态时累加计数器而已,刷新持续时间的是自带逻辑,因此就算不用这个 ...

我是说一直使用睡眠魔法让敌人睡不醒,睡不醒就不能还手,这样我方就安全了,对吧?
回复

使用道具 举报

梦石
0
星屑
346
在线时间
63 小时
注册时间
2020-2-24
回帖
12
发表于 2022-7-17 15:17:12 | 显示全部楼层
这个他会更改字体 不希望它更改得话应该怎么做呢
回复

使用道具 举报

梦石
0
星屑
3037
在线时间
388 小时
注册时间
2015-1-29
回帖
12
发表于 2022-7-25 19:07:08 | 显示全部楼层
这脚本只累计层数,无法叠加特性啊。
一个状态+10%攻击力,就算有3层也只+10%攻击力。
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部