Project1
标题: [已解决]如何让EFS_Battler.new(2)<< 5号勋章 [打印本页]
作者: 金芒芒 时间: 3 天前
标题: [已解决]如何让EFS_Battler.new(2)<< 5号勋章
本帖最后由 金芒芒 于 2025-1-9 13:56 编辑
根据脚本生成 魏国远征军 = [ EFS_Battler.new(2), EFS_Battler.new(4), EFS_Battler.new(9), EFS_Battler.new(13), EFS_Battler.new(8) ]
class Scene_EFS_Equip
class Window_EFS_EquipLeft < Window_Base
class Window_EFS_Selectable < Window_Base
class Window_EFS_EquipItem < Window_Selectable
class Scene_EFS_Equip
def initialize
@角色索引 = 0
@装备索引 = 0
create_windows
end
def create_windows
@left_window = Window_EFS_EquipLeft.new
@selectable_window = Window_EFS_Selectable.new
@equip_item_window = Window_EFS_EquipItem.new
end
end
class Window_EFS_EquipLeft < Window_Base
def initialize
super(0, 0, 160, Graphics.height)
refresh
end
def refresh
self.contents.clear
# 这里可以添加代码来显示左侧角色相关信息等
end
end
class Window_EFS_Selectable < Window_Base
def initialize
super(160, 0, Graphics.width - 160, Graphics.height / 2)
refresh
end
def refresh
self.contents.clear
# 这里可以添加代码来显示可选择的勋章等相关信息
end
end
class Window_EFS_EquipItem < Window_Selectable
def initialize
super(160, Graphics.height / 2, Graphics.width - 160, Graphics.height / 2)
refresh
end
def refresh
self.contents.clear
# 这里可以添加代码来显示已装备的勋章等相关信息
end
end
4. 在主脚本中使用示例
ruby
# 初始化角色数组
$魏国远征军 = [
EFS_Battler.new(2),
EFS_Battler.new(4),
EFS_Battler.new(9),
EFS_Battler.new(13),
EFS_Battler.new(8)
]
module Xunzhang_data
@data_id = 0
ICON = []
NAME = []
DISCRIPTION = []
PRICE = []
TYPE = []
LIMIT = []
AMMOR_HP = []
SHD_HP = []
LIVE_CHANCE = []
MOVEMENT_SPEED = []
CRITICAL = []
BASE_ATK = []
BRO_ATK = []
S_BASE_ATK = []
S_BRO_ATK = []
ANTI_CAV = []
ANTI_INF = []
ATK_FR = []
ACCURATCY = []
ENGAGE_RANGE = []
AMMO_MAX = []
MORALE = []
def self.get_num_Xunzhang #定义自我。获得号码装备
return @data_id #返回@data_id
end
module Xunzhang_data
@data_id = 0
ICON = []
NAME = []
DISCRIPTION = []
PRICE = []
TYPE = []
LIMIT = []
AMMOR_HP = []
SHD_HP = []
LIVE_CHANCE = []
MOVEMENT_SPEED = []
CRITICAL = []
BASE_ATK = []
BRO_ATK = []
S_BASE_ATK = []
S_BRO_ATK = []
ANTI_CAV = []
ANTI_INF = []
ATK_FR = []
ACCURATCY = []
ENGAGE_RANGE = []
AMMO_MAX = []
MORALE = []
def self.get_num_Xunzhang #定义自我。获得号码装备
return @data_id #返回@data_id
end
module Xunzhang_data
#module Equips_data
@data_id = 5
ICON[@data_id] = "icon_1280"
NAME[@data_id] = "测试刀"
DISCRIPTION[@data_id] = "测试用的刀,非常坚固,非常OP"
PRICE[@data_id] = 999
#类型: 1.甲 2.盾 3.近战武器 4.远程武器 5.马
TYPE[@data_id] = 3
#限制:只有特定兵种才能装,nil都能装
LIMIT[@data_id] = nil
#防具类, 都是加成
AMMOR_HP[@data_id] = 0
SHD_HP[@data_id] = 0
LIVE_CHANCE[@data_id] = 0
MOVEMENT_SPEED[@data_id] = 0
CRITICAL[@data_id] = 0
BASE_ATK[@data_id] = 50
BRO_ATK[@data_id] = 0
S_BASE_ATK[@data_id] = 0
S_BRO_ATK[@data_id] = 0
ANTI_CAV[@data_id] = 0
ANTI_INF[@data_id] = 0
ATK_FR[@data_id] = 0
ACCURATCY[@data_id] = 0
ENGAGE_RANGE[@data_id] = 0
AMMO_MAX[@data_id] = 0
MORALE[@data_id] = 0
end
module Xunzhang_data
#module Equips_data
@data_id = 5
ICON[@data_id] = "icon_1280"
NAME[@data_id] = "测试刀"
DISCRIPTION[@data_id] = "测试用的刀,非常坚固,非常OP"
PRICE[@data_id] = 999
#类型: 1.甲 2.盾 3.近战武器 4.远程武器 5.马
TYPE[@data_id] = 3
#限制:只有特定兵种才能装,nil都能装
LIMIT[@data_id] = nil
#防具类, 都是加成
AMMOR_HP[@data_id] = 0
SHD_HP[@data_id] = 0
LIVE_CHANCE[@data_id] = 0
MOVEMENT_SPEED[@data_id] = 0
CRITICAL[@data_id] = 0
BASE_ATK[@data_id] = 50
BRO_ATK[@data_id] = 0
S_BASE_ATK[@data_id] = 0
S_BRO_ATK[@data_id] = 0
ANTI_CAV[@data_id] = 0
ANTI_INF[@data_id] = 0
ATK_FR[@data_id] = 0
ACCURATCY[@data_id] = 0
ENGAGE_RANGE[@data_id] = 0
AMMO_MAX[@data_id] = 0
MORALE[@data_id] = 0
end
class EFS_Battler < Game_Character
attr_accessor :character_name, :base_atk, :Xunzhang
attr_reader :soldier_id
def initialize(data_id)
super()
@character_name = Figter_data::CHARACTER_NAME[data_id]
@base_atk = Figter_data::BASE_ATK[data_id]
@base_base_atk = @base_atk
@soldier_id = data_id
@Xunzhang = []
end
def equip_xunzhang
unless @Xunzhang.include?(Xunzhang_data.get_num_Xunzhang)
@Xunzhang << Xunzhang_data.get_num_Xunzhang
calculate_Xunzhang
end
end
def replace_xunzhang(new_xunzhang_id)
index = @Xunzhang.index(Xunzhang_data.get_num_Xunzhang)
if index
@Xunzhang[index] = new_xunzhang_id
else
equip_xunzhang
end
calculate_Xunzhang
end
def unequip_xunzhang
@Xunzhang.delete(Xunzhang_data.get_num_Xunzhang)
calculate_Xunzhang
end
def refill
calculate_Xunzhang
end
def calculate_Xunzhang
@base_base_atk = get_Xunzhang_base_atk
end
def get_Xunzhang_base_atk(const = false)
n = const? Figter_data::BASE_ATK[@soldier_id] : @base_base_atk
@Xunzhang.each do |i|
next if i.nil?
n += Xunzhang_data::BASE_ATK[i]
end
n
end
end
class EFS_Battler < Game_Character
attr_accessor :character_name, :base_atk, :Xunzhang
attr_reader :soldier_id
def initialize(data_id)
super()
@character_name = Figter_data::CHARACTER_NAME[data_id]
@base_atk = Figter_data::BASE_ATK[data_id]
@base_base_atk = @base_atk
@soldier_id = data_id
@Xunzhang = []
end
def equip_xunzhang
unless @Xunzhang.include?(Xunzhang_data.get_num_Xunzhang)
@Xunzhang << Xunzhang_data.get_num_Xunzhang
calculate_Xunzhang
end
end
def replace_xunzhang(new_xunzhang_id)
index = @Xunzhang.index(Xunzhang_data.get_num_Xunzhang)
if index
@Xunzhang[index] = new_xunzhang_id
else
equip_xunzhang
end
calculate_Xunzhang
end
def unequip_xunzhang
@Xunzhang.delete(Xunzhang_data.get_num_Xunzhang)
calculate_Xunzhang
end
def refill
calculate_Xunzhang
end
def calculate_Xunzhang
@base_base_atk = get_Xunzhang_base_atk
end
def get_Xunzhang_base_atk(const = false)
n = const? Figter_data::BASE_ATK[@soldier_id] : @base_base_atk
@Xunzhang.each do |i|
next if i.nil?
n += Xunzhang_data::BASE_ATK[i]
end
n
end
end
作者: 金芒芒 时间: 前天 13:55
- class Scene_EFS_Equip
- def create_and_set_xunzhang(data_ids, xunzhang_options)
- # 假设 data_ids 和 xunzhang_options 是已经给定的数组
- # data_ids = [2, 5, 8, 6, 9]
- # xunzhang_options = [13, 5, 3, 20, 15, 8]
-
- # 创建一个数组来存储 EFS_Battler 实例
- battlers = []
-
- # 遍历 data_ids 数组,为每个 data_id 创建一个 EFS_Battler 实例
- data_ids.each_with_index do |data_id, index|
- # 从 xunzhang_options 中选择一个 xunzhang 值
- # 这里为了示例,我们简单地选择 xunzhang_options[index % xunzhang_options.length]
- # 但在实际应用中,你可能需要根据某种逻辑或用户输入来选择
- selected_xunzhang = xunzhang_options[index % xunzhang_options.length]
-
- # 创建 EFS_Battler 实例
- battler = EFS_Battler.new(data_id)
-
- # 设置 xunzhang 值(这里需要修改 EFS_Battler 类以允许外部设置 xunzhang)
- # 假设我们添加了一个 set_xunzhang 方法来设置 xunzhang
- battler.set_xunzhang(selected_xunzhang)
-
- # 将创建的 battler 实例添加到数组中
- battlers << battler
- end
-
- # 返回创建的 battler 实例数组(如果需要)
- battlers
- end
- end
- # 修改 EFS_Battler 类以添加 set_xunzhang 方法
- class EFS_Battler < Game_Character
- attr_accessor :character_name, :base_atk, :Xunzhang, :soldier_id
- attr_reader :soldier_id
-
- def initialize(data_id)
- super()
- @character_name = Figter_data::CHARACTER_NAME[data_id]
- @base_atk = Figter_data::BASE_ATK[data_id]
- @base_base_atk = @base_atk
- @soldier_id = data_id
- @Xunzhang = []
- set_xunzhang_to_specific_value # 这个方法现在可能不是必需的,取决于你的具体实现
- end
-
- # 添加一个方法来设置 xunzhang
- def set_xunzhang(value)
- @Xunzhang = [value]
- end
-
- # 保留原有的 set_xunzhang_to_specific_value 方法,如果它有其他用途
- def set_xunzhang_to_specific_value
- @Xunzhang = :ml-citation{ref="1" data="citationList"} # 这个方法现在被新的 set_xunzhang 方法替代,可以保留或删除
- end
- end
- # 示例使用
- scene = Scene_EFS_Equip.new
- data_ids = [2, 5, 8, 6, 9]
- xunzhang_options = [13, 5, 3, 20, 15, 8]
- battlers = scene.create_and_set_xunzhang(data_ids, xunzhang_options)
- # 输出每个 battler 的 xunzhang 值以验证
- battlers.each do |battler|
- puts "Battler #{battler.soldier_id} has xunzhang #{battler.Xunzhang.first}"
- end
复制代码
欢迎光临 Project1 (https://rpg.blue/) |
Powered by Discuz! X3.1 |