Project1
标题:
Dual_Wield 轻量级二刀流脚本
[打印本页]
作者:
SailCat
时间:
2012-3-21 23:33
标题:
Dual_Wield 轻量级二刀流脚本
闲话不多说,看注释,插到main前面就可以了
轻量级,只附带二刀流功能(盾当武器),不夹带任何私货等,标准新建工程测试通过
#==============================================================================
# ★ Dual_Wield 轻量级二刀流脚本
#------------------------------------------------------------------------------
# 本脚本#不使用#任何alias,避免冲突
# 本脚本#不追加定义#任何实例变量,避免冲突和制作中途加入带来的存档不兼容问题
# 本脚本未实现二刀流双次动画或双次攻击功能,有意者可自行实现,难度很低
# 二刀流实现原理:当盾的ID小于0时,为双持的武器,否则为盾
# 默认攻击力、属性、状态等为二手直接相加,可以修改base_atk之类定义来进行修改
# 常量DUAL_WIELDER_CLASSES为可以双持武器的职业ID组,请在下面修改
#==============================================================================
# ■ Game_Actor
#------------------------------------------------------------------------------
# 处理角色的类。本类在 Game_Actors 类 ($game_actors)
# 的内部使用、Game_Party 类请参考 ($game_party) 。
#==============================================================================
class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
# ● 常量
#--------------------------------------------------------------------------
DUAL_WIELDER_CLASSES = [3, 4] # 可以双持武器的职业 ID 组
#--------------------------------------------------------------------------
# ● 双持武器判定
#--------------------------------------------------------------------------
def dual_wield?
return DUAL_WIELDER_CLASSES.include?(@class_id)
end
#--------------------------------------------------------------------------
# ● 取得属性修正值
# element_id : 属性 ID
#--------------------------------------------------------------------------
def element_rate(element_id)
# 获取对应属性有效度的数值
table = [0,200,150,100,50,0,-100]
result = table[$data_classes[@class_id].element_ranks[element_id]]
# 防具能防御本属性的情况下效果减半
for i in [[@armor1_id, 0].max, @armor2_id, @armor3_id, @armor4_id]
armor = $data_armors[i]
if armor != nil and armor.guard_element_set.include?(element_id)
result /= 2
end
end
# 状态能防御本属性的情况下效果减半
for i in @states
if $data_states[i].guard_element_set.include?(element_id)
result /= 2
end
end
# 过程结束
return result
end
#--------------------------------------------------------------------------
# ● 判定防御属性
# state_id : 属性 ID
#--------------------------------------------------------------------------
def state_guard?(state_id)
for i in [[@armor1_id, 0].max, @armor2_id, @armor3_id, @armor4_id]
armor = $data_armors[i]
if armor != nil
if armor.guard_state_set.include?(state_id)
return true
end
end
end
return false
end
#--------------------------------------------------------------------------
# ● 获取普通攻击属性
#--------------------------------------------------------------------------
def element_set
elements = []
weapon1 = $data_weapons[@weapon_id]
weapon2 = @armor1_id < 0 ? $data_weapons[-@armor1_id] : nil
elements |= weapon1.element_set if weapon1 != nil
elements |= weapon2.element_set if weapon2 != nil
return elements
end
#--------------------------------------------------------------------------
# ● 获取普通攻击状态变化 (+)
#--------------------------------------------------------------------------
def plus_state_set
plus_states = []
weapon1 = $data_weapons[@weapon_id]
weapon2 = @armor1_id < 0 ? $data_weapons[-@armor1_id] : nil
plus_states |= weapon1.plus_state_set if weapon1 != nil
plus_states |= weapon2.plus_state_set if weapon2 != nil
return plus_states
end
#--------------------------------------------------------------------------
# ● 获取普通攻击状态变化 (-)
#--------------------------------------------------------------------------
def minus_state_set
minus_states = []
weapon1 = $data_weapons[@weapon_id]
weapon2 = @armor1_id < 0 ? $data_weapons[-@armor1_id] : nil
minus_states |= weapon1.minus_state_set if weapon1 != nil
minus_states |= weapon2.minus_state_set if weapon2 != nil
return minus_states
end
#--------------------------------------------------------------------------
# ● 获取基本力量
#--------------------------------------------------------------------------
def base_str
n = $data_actors[@actor_id].parameters[2, @level]
weapon = $data_weapons[@weapon_id]
if @armor1_id >= 0
armor1 = $data_armors[@armor1_id]
else
armor1 = $data_weapons[-@armor1_id]
end
armor2 = $data_armors[@armor2_id]
armor3 = $data_armors[@armor3_id]
armor4 = $data_armors[@armor4_id]
n += weapon != nil ? weapon.str_plus : 0
n += armor1 != nil ? armor1.str_plus : 0
n += armor2 != nil ? armor2.str_plus : 0
n += armor3 != nil ? armor3.str_plus : 0
n += armor4 != nil ? armor4.str_plus : 0
return [[n, 1].max, 999].min
end
#--------------------------------------------------------------------------
# ● 获取基本灵巧
#--------------------------------------------------------------------------
def base_dex
n = $data_actors[@actor_id].parameters[3, @level]
weapon = $data_weapons[@weapon_id]
if @armor1_id >= 0
armor1 = $data_armors[@armor1_id]
else
armor1 = $data_weapons[-@armor1_id]
end
armor2 = $data_armors[@armor2_id]
armor3 = $data_armors[@armor3_id]
armor4 = $data_armors[@armor4_id]
n += weapon != nil ? weapon.dex_plus : 0
n += armor1 != nil ? armor1.dex_plus : 0
n += armor2 != nil ? armor2.dex_plus : 0
n += armor3 != nil ? armor3.dex_plus : 0
n += armor4 != nil ? armor4.dex_plus : 0
return [[n, 1].max, 999].min
end
#--------------------------------------------------------------------------
# ● 获取基本速度
#--------------------------------------------------------------------------
def base_agi
n = $data_actors[@actor_id].parameters[4, @level]
weapon = $data_weapons[@weapon_id]
if @armor1_id >= 0
armor1 = $data_armors[@armor1_id]
else
armor1 = $data_weapons[-@armor1_id]
end
armor2 = $data_armors[@armor2_id]
armor3 = $data_armors[@armor3_id]
armor4 = $data_armors[@armor4_id]
n += weapon != nil ? weapon.agi_plus : 0
n += armor1 != nil ? armor1.agi_plus : 0
n += armor2 != nil ? armor2.agi_plus : 0
n += armor3 != nil ? armor3.agi_plus : 0
n += armor4 != nil ? armor4.agi_plus : 0
return [[n, 1].max, 999].min
end
#--------------------------------------------------------------------------
# ● 获取基本魔力
#--------------------------------------------------------------------------
def base_int
n = $data_actors[@actor_id].parameters[5, @level]
weapon = $data_weapons[@weapon_id]
if @armor1_id >= 0
armor1 = $data_armors[@armor1_id]
else
armor1 = $data_weapons[-@armor1_id]
end
armor2 = $data_armors[@armor2_id]
armor3 = $data_armors[@armor3_id]
armor4 = $data_armors[@armor4_id]
n += weapon != nil ? weapon.int_plus : 0
n += armor1 != nil ? armor1.int_plus : 0
n += armor2 != nil ? armor2.int_plus : 0
n += armor3 != nil ? armor3.int_plus : 0
n += armor4 != nil ? armor4.int_plus : 0
return [[n, 1].max, 999].min
end
#--------------------------------------------------------------------------
# ● 获取基本攻击力
#--------------------------------------------------------------------------
def base_atk
atk = 0
weapon = $data_weapons[@weapon_id]
atk += weapon.atk if weapon != nil
if @armor1_id < 0
weapon = $data_weapons[-@armor1_id]
atk += weapon.atk if weapon != nil
end
return atk
end
#--------------------------------------------------------------------------
# ● 获取基本物理防御
#--------------------------------------------------------------------------
def base_pdef
weapon = $data_weapons[@weapon_id]
if @armor1_id >= 0
armor1 = $data_armors[@armor1_id]
else
armor1 = $data_weapons[-@armor1_id]
end
armor2 = $data_armors[@armor2_id]
armor3 = $data_armors[@armor3_id]
armor4 = $data_armors[@armor4_id]
pdef1 = weapon != nil ? weapon.pdef : 0
pdef2 = armor1 != nil ? armor1.pdef : 0
pdef3 = armor2 != nil ? armor2.pdef : 0
pdef4 = armor3 != nil ? armor3.pdef : 0
pdef5 = armor4 != nil ? armor4.pdef : 0
return pdef1 + pdef2 + pdef3 + pdef4 + pdef5
end
#--------------------------------------------------------------------------
# ● 获取基本魔法防御
#--------------------------------------------------------------------------
def base_mdef
weapon = $data_weapons[@weapon_id]
if @armor1_id >= 0
armor1 = $data_armors[@armor1_id]
else
armor1 = $data_weapons[-@armor1_id]
end
armor2 = $data_armors[@armor2_id]
armor3 = $data_armors[@armor3_id]
armor4 = $data_armors[@armor4_id]
mdef1 = weapon != nil ? weapon.mdef : 0
mdef2 = armor1 != nil ? armor1.mdef : 0
mdef3 = armor2 != nil ? armor2.mdef : 0
mdef4 = armor3 != nil ? armor3.mdef : 0
mdef5 = armor4 != nil ? armor4.mdef : 0
return mdef1 + mdef2 + mdef3 + mdef4 + mdef5
end
#--------------------------------------------------------------------------
# ● 获取基本回避修正
#--------------------------------------------------------------------------
def base_eva
armor1 = @armor1_id >= 0 ? $data_armors[@armor1_id] : nil
armor2 = $data_armors[@armor2_id]
armor3 = $data_armors[@armor3_id]
armor4 = $data_armors[@armor4_id]
eva1 = armor1 != nil ? armor1.eva : 0
eva2 = armor2 != nil ? armor2.eva : 0
eva3 = armor3 != nil ? armor3.eva : 0
eva4 = armor4 != nil ? armor4.eva : 0
return eva1 + eva2 + eva3 + eva4
end
#--------------------------------------------------------------------------
# ● 变更装备
# equip_type : 装备类型
# id : 武器 or 防具 ID (0 为解除装备)
#--------------------------------------------------------------------------
def equip(equip_type, id)
case equip_type
when 0 # 武器
if id == 0 or $game_party.weapon_number(id) > 0
$game_party.gain_weapon(@weapon_id, 1)
@weapon_id = id
$game_party.lose_weapon(id, 1)
end
when 1 # 盾
if id == 0 or (id > 0 and $game_party.armor_number(id) > 0) or
(id < 0 and $game_party.weapon_number(-id) > 0)
old_shield = @armor1_id > 0 ? $data_armors[@armor1_id] : nil
new_shield = id > 0 ? $data_armors[id] : nil
update_auto_state(old_shield, new_shield)
if @armor1_id > 0
$game_party.gain_armor(@armor1_id, 1)
elsif @armor1_id < 0
$game_party.gain_weapon(-@armor1_id, 1)
end
@armor1_id = id
if id > 0
$game_party.lose_armor(id, 1)
elsif id < 0
$game_party.lose_weapon(-id, 1)
end
end
when 2 # 头
if id == 0 or $game_party.armor_number(id) > 0
update_auto_state($data_armors[@armor2_id], $data_armors[id])
$game_party.gain_armor(@armor2_id, 1)
@armor2_id = id
$game_party.lose_armor(id, 1)
end
when 3 # 身体
if id == 0 or $game_party.armor_number(id) > 0
update_auto_state($data_armors[@armor3_id], $data_armors[id])
$game_party.gain_armor(@armor3_id, 1)
@armor3_id = id
$game_party.lose_armor(id, 1)
end
when 4 # 装饰品
if id == 0 or $game_party.armor_number(id) > 0
update_auto_state($data_armors[@armor4_id], $data_armors[id])
$game_party.gain_armor(@armor4_id, 1)
@armor4_id = id
$game_party.lose_armor(id, 1)
end
end
end
#--------------------------------------------------------------------------
# ● 更改职业 ID
# class_id : 新的职业 ID
#--------------------------------------------------------------------------
def class_id=(class_id)
if $data_classes[class_id] != nil
@class_id = class_id
# 避开无法装备的物品
unless equippable?($data_weapons[@weapon_id])
equip(0, 0)
end
unless (@armor1_id > 0 and equippable?($data_armors[@armor1_id])) or
(@armor1_id < 0 and equippable?($data_weapons[-@armor1_id]) and
dual_wield?)
equip(1, 0)
end
unless equippable?($data_armors[@armor2_id])
equip(2, 0)
end
unless equippable?($data_armors[@armor3_id])
equip(3, 0)
end
unless equippable?($data_armors[@armor4_id])
equip(4, 0)
end
end
end
#--------------------------------------------------------------------------
# ● 普通攻击 获取攻击方动画 ID
#--------------------------------------------------------------------------
def animation1_id
weapon = $data_weapons[@weapon_id]
if weapon == nil and dual_wield? and @armor1_id < 0
weapon = $data_weapons[-@armor1_id]
end
return weapon != nil ? weapon.animation1_id : 0
end
#--------------------------------------------------------------------------
# ● 普通攻击 获取对像方动画 ID
#--------------------------------------------------------------------------
def animation2_id
weapon = $data_weapons[@weapon_id]
if weapon == nil and dual_wield? and @armor1_id < 0
weapon = $data_weapons[-@armor1_id]
end
return weapon != nil ? weapon.animation2_id : 0
end
end
#==============================================================================
# ■ Window_EquipRight
#------------------------------------------------------------------------------
# 装备画面、显示角色现在装备的物品的窗口。
#==============================================================================
class Window_EquipRight < Window_Selectable
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
@data = []
@data.push($data_weapons[@actor.weapon_id])
if @actor.armor1_id >= 0
@data.push($data_armors[@actor.armor1_id])
else
@data.push($data_weapons[
[email protected]
_id])
end
@data.push($data_armors[@actor.armor2_id])
@data.push($data_armors[@actor.armor3_id])
@data.push($data_armors[@actor.armor4_id])
@item_max = @data.size
self.contents.font.color = system_color
if @actor.dual_wield?
text1 = "右手"
text2 = "左手"
else
text1 = $data_system.words.weapon
text2 = $data_system.words.armor1
end
self.contents.draw_text(4, 32 * 0, 92, 32, text1)
self.contents.draw_text(4, 32 * 1, 92, 32, text2)
self.contents.draw_text(4, 32 * 2, 92, 32, $data_system.words.armor2)
self.contents.draw_text(4, 32 * 3, 92, 32, $data_system.words.armor3)
self.contents.draw_text(4, 32 * 4, 92, 32, $data_system.words.armor4)
draw_item_name(@data[0], 92, 32 * 0)
draw_item_name(@data[1], 92, 32 * 1)
draw_item_name(@data[2], 92, 32 * 2)
draw_item_name(@data[3], 92, 32 * 3)
draw_item_name(@data[4], 92, 32 * 4)
end
end
#==============================================================================
# ■ Window_EquipItem
#------------------------------------------------------------------------------
# 装备画面、显示浏览变更装备的候补物品的窗口。
#==============================================================================
class Window_EquipItem < Window_Selectable
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
# 添加可以装备的武器
if @equip_type == 0 or (@equip_type == 1 and @actor.dual_wield?)
weapon_set = $data_classes[@actor.class_id].weapon_set
for i in 1...$data_weapons.size
if $game_party.weapon_number(i) > 0 and weapon_set.include?(i)
@data.push($data_weapons[i])
end
end
end
# 添加可以装备的防具
if @equip_type != 0
armor_set = $data_classes[@actor.class_id].armor_set
for i in 1...$data_armors.size
if $game_party.armor_number(i) > 0 and armor_set.include?(i)
if $data_armors[i].kind == @equip_type-1
@data.push($data_armors[i])
end
end
end
end
# 添加空白
@data.push(nil)
# 生成位图、描绘全部项目
@item_max = @data.size
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@item_max-1
draw_item(i)
end
end
end
#==============================================================================
# ■ Scene_Equip
#------------------------------------------------------------------------------
# 处理装备画面的类。
#==============================================================================
class Scene_Equip
#--------------------------------------------------------------------------
# ● 刷新画面 (物品窗口被激活的情况下)
#--------------------------------------------------------------------------
def update_item
# 按下 B 键的情况下
if Input.trigger?(Input::B)
# 演奏取消 SE
$game_system.se_play($data_system.cancel_se)
# 激活右侧窗口
@right_window.active = true
@item_window.active = false
@item_window.index = -1
return
end
# 按下 C 键的情况下
if Input.trigger?(Input::C)
# 演奏装备 SE
$game_system.se_play($data_system.equip_se)
# 获取物品窗口现在选择的装备数据
item = @item_window.item
# 变更装备
if @right_window.index == 1 and item.is_a?(RPG::Weapon)
@actor.equip(@right_window.index, -item.id)
@item_window1.refresh
else
@actor.equip(@right_window.index, item == nil ? 0 : item.id)
@item_window2.refresh if @right_window.index == 0 and @actor.dual_wield?
@item_window1.refresh if @right_window.index == 1 and @actor.dual_wield?
end
# 激活右侧窗口
@right_window.active = true
@item_window.active = false
@item_window.index = -1
# 再生成右侧窗口、物品窗口的内容
@right_window.refresh
@item_window.refresh
return
end
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
# 设置物品窗口的可视状态
@item_window1.visible = (@right_window.index == 0)
@item_window2.visible = (@right_window.index == 1)
@item_window3.visible = (@right_window.index == 2)
@item_window4.visible = (@right_window.index == 3)
@item_window5.visible = (@right_window.index == 4)
# 获取当前装备中的物品
item1 = @right_window.item
# 设置当前的物品窗口到 @item_window
case @right_window.index
when 0
@item_window = @item_window1
when 1
@item_window = @item_window2
when 2
@item_window = @item_window3
when 3
@item_window = @item_window4
when 4
@item_window = @item_window5
end
# 右窗口被激活的情况下
if @right_window.active
# 删除变更装备后的能力
@left_window.set_new_parameters(nil, nil, nil)
end
# 物品窗口被激活的情况下
if @item_window.active
# 获取现在选中的物品
item2 = @item_window.item
# 变更装备
last_hp = @actor.hp
last_sp = @actor.sp
if @right_window.index == 1 and item2.is_a?(RPG::Weapon)
@actor.equip(@right_window.index, -item2.id)
else
@actor.equip(@right_window.index, item2 == nil ? 0 : item2.id)
end
# 获取变更装备后的能力值
new_atk = @actor.atk
new_pdef = @actor.pdef
new_mdef = @actor.mdef
# 返回到装备
if @right_window.index == 1 and item1.is_a?(RPG::Weapon)
@actor.equip(@right_window.index, -item1.id)
else
@actor.equip(@right_window.index, item1 == nil ? 0 : item1.id)
end
@actor.hp = last_hp
@actor.sp = last_sp
# 描画左窗口
@left_window.set_new_parameters(new_atk, new_pdef, new_mdef)
end
end
end
#==============================================================================
# ■ Window_ShopStatus
#------------------------------------------------------------------------------
# 商店画面、显示物品所持数与角色装备的窗口。
#==============================================================================
class Window_ShopStatus < Window_Base
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
if @item == nil
return
end
case @item
when RPG::Item
number = $game_party.item_number(@item.id)
when RPG::Weapon
number = $game_party.weapon_number(@item.id)
when RPG::Armor
number = $game_party.armor_number(@item.id)
end
self.contents.font.color = system_color
self.contents.draw_text(4, 0, 200, 32, "所持数")
self.contents.font.color = normal_color
self.contents.draw_text(204, 0, 32, 32, number.to_s, 2)
if @item.is_a?(RPG::Item)
return
end
# 添加装备品信息
for i in 0...$game_party.actors.size
# 获取角色
actor = $game_party.actors[i]
# 可以装备为普通文字颜色、不能装备设置为无效文字颜色
if actor.equippable?(@item)
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
# 描绘角色名字
self.contents.draw_text(4, 64 + 64 * i, 120, 32, actor.name)
# 获取当前的装备品
if @item.is_a?(RPG::Weapon)
item1 = $data_weapons[actor.weapon_id]
elsif @item.kind == 0
item1 = actor.armor1_id > 0 ? $data_armors[actor.armor1_id] : nil
elsif @item.kind == 1
item1 = $data_armors[actor.armor2_id]
elsif @item.kind == 2
item1 = $data_armors[actor.armor3_id]
else
item1 = $data_armors[actor.armor4_id]
end
# 可以装备的情况
if actor.equippable?(@item)
# 武器的情况
if @item.is_a?(RPG::Weapon)
atk1 = item1 != nil ? item1.atk : 0
atk2 = @item != nil ? @item.atk : 0
change = atk2 - atk1
end
# 防具的情况
if @item.is_a?(RPG::Armor)
pdef1 = item1 != nil ? item1.pdef : 0
mdef1 = item1 != nil ? item1.mdef : 0
pdef2 = @item != nil ? @item.pdef : 0
mdef2 = @item != nil ? @item.mdef : 0
change = pdef2 - pdef1 + mdef2 - mdef1
end
# 描绘能力值变化
self.contents.draw_text(124, 64 + 64 * i, 112, 32,
sprintf("%+d", change), 2)
end
# 描绘物品
if item1 != nil
x = 4
y = 64 + 64 * i + 32
bitmap = RPG::Cache.icon(item1.icon_name)
opacity = self.contents.font.color == normal_color ? 255 : 128
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.draw_text(x + 28, y, 212, 32, item1.name)
end
end
end
end
#==============================================================================
# ■ Window_Status
#------------------------------------------------------------------------------
# 显示状态画面、完全规格的状态窗口。
#==============================================================================
class Window_Status < Window_Base
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
draw_actor_graphic(@actor, 40, 112)
draw_actor_name(@actor, 4, 0)
draw_actor_class(@actor, 4 + 144, 0)
draw_actor_level(@actor, 96, 32)
draw_actor_state(@actor, 96, 64)
draw_actor_hp(@actor, 96, 112, 172)
draw_actor_sp(@actor, 96, 144, 172)
draw_actor_parameter(@actor, 96, 192, 0)
draw_actor_parameter(@actor, 96, 224, 1)
draw_actor_parameter(@actor, 96, 256, 2)
draw_actor_parameter(@actor, 96, 304, 3)
draw_actor_parameter(@actor, 96, 336, 4)
draw_actor_parameter(@actor, 96, 368, 5)
draw_actor_parameter(@actor, 96, 400, 6)
self.contents.font.color = system_color
self.contents.draw_text(320, 48, 80, 32, "EXP")
self.contents.draw_text(320, 80, 80, 32, "NEXT")
self.contents.font.color = normal_color
self.contents.draw_text(320 + 80, 48, 84, 32, @actor.exp_s, 2)
self.contents.draw_text(320 + 80, 80, 84, 32, @actor.next_rest_exp_s, 2)
self.contents.font.color = system_color
self.contents.draw_text(320, 160, 96, 32, "装备")
draw_item_name($data_weapons[@actor.weapon_id], 320 + 16, 208)
if @actor.armor1_id >= 0
draw_item_name($data_armors[@actor.armor1_id], 320 + 16, 256)
else
draw_item_name($data_weapons[
[email protected]
_id], 320 + 16, 256)
end
draw_item_name($data_armors[@actor.armor2_id], 320 + 16, 304)
draw_item_name($data_armors[@actor.armor3_id], 320 + 16, 352)
draw_item_name($data_armors[@actor.armor4_id], 320 + 16, 400)
end
end
复制代码
作者:
小传子
时间:
2012-3-25 21:21
宝刀不老= =,转战ACE去吧猫
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1