Project1
标题:
只想在VA默认的战斗系统上增加伤害值显示,怎么弄?
[打印本页]
作者:
humzlo
时间:
2012-2-27 22:43
标题:
只想在VA默认的战斗系统上增加伤害值显示,怎么弄?
本帖最后由 humzlo 于 2012-2-28 17:16 编辑
只想在VA默认的战斗系统上增加伤害值显示,怎么弄?下了一个横版的战斗脚本 只喜欢那个伤害值显示
哪位高人指点一下?谢谢
作者:
逆天浚
时间:
2012-3-12 12:50
我也很想知道!!
作者:
殇殃
时间:
2012-3-13 10:49
#==============================================================================
# 功能:战斗中显示怪物受到的伤害和回复
# 适用:RMVX Ace
# 作者:殇殃 2012.3.13 改自 后知后觉的横版战斗模板v1.7 2012-02-09
# 使用方法:复制整个脚本插入到Main之前
#==============================================================================
# ■ Sprite_Damage (新增类)
#==============================================================================
class Sprite_Damage < Sprite
#--------------------------------------------------------------------------
# ● 获取/生成伤害值源图
#--------------------------------------------------------------------------
@@obmp = nil
def self.obmp
if @@obmp.nil? or @@obmp.disposed?
@@obmp = Bitmap.new(180, 256)
#@@obmp.font.bold = true #粗黑体
#@@obmp.font.shadow = false #阴影
#@@obmp.font.outline = true #数字外围边框
@@obmp.font.out_color = Color.new(255, 255, 255, 255)
@@obmp.font.size = 32
colors = []
colors.push(Color.new(255, 0, 0, 255))#HP伤害颜色(红)
colors.push(Color.new( 0, 224, 96, 255))#HP回复颜色(亮绿)
colors.push(Color.new( 0, 0, 255, 255))#MP伤害颜色(蓝)
colors.push(Color.new(255, 255, 64, 255))#MP回复颜色(亮黄)
colors.push(Color.new( 0, 0, 0, 255))#TP伤害颜色(深黑)
colors.push(Color.new(255, 255, 255, 255))#TP回复颜色(白)
#Graphics/System/damage.png伤害图8行10列180×256
#第 1 行 HP 伤害数字0~9
#第 2 行 HP 回复数字0~9
#第 3 行 MP 伤害数字0~9
#第 4 行 MP 回复数字0~9
#第 5 行 TP 伤害数字0~9
#第 6 行 TP 回复数字0~9
#第 7 行 左边暴击(Critical)右边 攻击落空(Miss)
#第 8 行 左边闪避(Evasion) 右边 留空
colors.each_with_index do |color, hi| #每个数字占18×32
@@obmp.font.color = color
for wi in 0..9
@@obmp.draw_text(wi * 18, hi * 32, 18, 32, "#{wi}", 1)
end
end
@@obmp.font.size = 24 #字体大小
#@@obmp.font.italic = true #斜体
@@obmp.font.out_color = Color.new(0, 0, 0, 255)
@@obmp.font.color = Color.new(255, 0, 255, 255)#暴击等文字的颜色(亮粉红)
@@obmp.draw_text( 0, 192, 90, 32, "暴击", 1)
@@obmp.draw_text(90, 192, 90, 32, "Miss", 1)
@@obmp.draw_text( 0, 224, 90, 32, "闪避", 1)
#@@obmp.hue_change(0)# 设置伤害值图形的色相 取值范围 0~360
end
return @@obmp
end
#--------------------------------------------------------------------------
# ● 初始化
#--------------------------------------------------------------------------
def initialize(viewport, args)
super(viewport)
@type = args[0] #伤害类型hp、mp、tp
@value = args[1] #伤害值
@critical = args[2] #是否暴击
self.x = args[4]
self.y = args[5]
self.z = args[6] + Graphics.height * 5
make_move(args[3])
refresh
end
#--------------------------------------------------------------------------
# ● 生成移动数据
#--------------------------------------------------------------------------
def make_move(battler_obj_class)
@move = []
case battler_obj_class
when :actor
make_move_actor
when :enemy
make_move_enemy
else
make_move_default
end
end
#--------------------------------------------------------------------------
# ● 生成移动数据 默认
#--------------------------------------------------------------------------
def make_move_default
45.times do |n|
if n % 3 == 0
ady = n < 21 ? -6 : -1
opa = n < 21 ? 255 : 255-(n-21)*6
@move.push([0, ady, opa])
else
@move.push([0, 0, -1])
end
end
end
#--------------------------------------------------------------------------
# ● 生成移动数据 角色
#--------------------------------------------------------------------------
def make_move_actor
make_move_default
end
#--------------------------------------------------------------------------
# ● 生成移动数据 敌人
#--------------------------------------------------------------------------
def make_move_enemy
make_move_default
end
#--------------------------------------------------------------------------
# ● 描绘
#--------------------------------------------------------------------------
def refresh
if not self.bitmap.nil?
self.bitmap.dispose
self.bitmap = nil
end
begin
@obmp = Cache.system("damage")
rescue Errno::ENOENT
@obmp = Sprite_Damage.obmp #找不到伤害值显示图则使用自建的代替图
end
@numw = @obmp.width / 10
@numh = @obmp.height / 8
@strw = @obmp.width / 2
case @value
when Numeric #伤害值是数字
blt_obmp_numeric
when Symbol #伤害值是文字
blt_obmp_text
end
end
#--------------------------------------------------------------------------
# ● 通过源图描绘数字
#--------------------------------------------------------------------------
def blt_obmp_numeric
nums = @value.to_i.abs.to_s.split("")
nbmpw = nums.size * @numw
bmph = @numh
cbmpw = 0
crect = nil
dy = 0
if @critical
cbmpw = @strw
bmph *= 2
crect = Rect.new(0, @numh * 6, @strw, @numh)
dy = @numh
end
self.bitmap = Bitmap.new([nbmpw, cbmpw, 32].max, [bmph, 32].max)
self.ox = bitmap.width / 2
self.oy = bmph /2
bitmap.blt((bitmap.width - cbmpw) / 2, 0, @obmp, crect) if crect
dx = (bitmap.width - nbmpw) / 2
ry = 0
case @type
when :hp
ry = @value >= 0 ? 0 : @numh
when :mp
ry = @value >= 0 ? @numh * 2 : @numh * 3
when :tp
ry = @value >= 0 ? @numh * 4 : @numh * 5
else
return
end
rect = Rect.new(0, ry, @numw, @numh)
nums.each_with_index do |str, i|
rect.x = str.to_i * @numw
bitmap.blt(dx, dy, @obmp, rect)
dx += @numw
end
end
#--------------------------------------------------------------------------
# ● 通过源图描绘文字
#--------------------------------------------------------------------------
def blt_obmp_text
self.bitmap = Bitmap.new([@strw, 32].max, [@numh, 32].max)
self.ox = @strw / 2
self.oy = @numh / 2
rx = ry = 0
case @type
when :miss
rx = @strw
ry = @numh * 6
when :eva
ry = @numh * 7
else
return
end
rect = Rect.new(rx, ry, @strw, @numh)
bitmap.blt(0, 0, @obmp, rect)
end
#--------------------------------------------------------------------------
# ● 释放
#--------------------------------------------------------------------------
def dispose
bitmap.dispose if bitmap
super
end
#--------------------------------------------------------------------------
# ● 移动中判定
#--------------------------------------------------------------------------
def moving?
return (not @move.empty?)
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def update
super
if moving?
ary = @move.shift
self.x += ary[0]
self.y += ary[1]
self.opacity = ary[2] if ary[2] >= 0
end
end
end
#==============================================================================
# ■ Window_BattleLog
#==============================================================================
class Window_BattleLog < Window_Selectable
#--------------------------------------------------------------------------
# ● 显示 MISS (追加定义)
#--------------------------------------------------------------------------
alias hzhj_old_display_miss_for_display_damage_wnd_btlog display_miss
def display_miss(target, item)
target.damage_for_show = [:miss, :miss, false]
hzhj_old_display_miss_for_display_damage_wnd_btlog(target, item)
end
#--------------------------------------------------------------------------
# ● 显示回避 (追加定义)
#--------------------------------------------------------------------------
alias hzhj_old_display_evasion_for_display_damage_wnd_btlog display_evasion
def display_evasion(target, item)
target.damage_for_show = [:eva, :evasion, false]
hzhj_old_display_evasion_for_display_damage_wnd_btlog(target, item)
end
#--------------------------------------------------------------------------
# ● 显示 HP 伤害 (追加定义)
#--------------------------------------------------------------------------
alias hzhj_old_display_hp_damage_for_display_damage_wnd_btlog display_hp_damage
def display_hp_damage(target, item)
return if target.result.hp_damage == 0 && item && !item.damage.to_hp?
value = target.result.hp_damage
critical = target.result.critical
target.damage_for_show = [:hp, value, critical]
hzhj_old_display_hp_damage_for_display_damage_wnd_btlog(target, item)
end
#--------------------------------------------------------------------------
# ● 显示 MP 伤害 (追加定义)
#--------------------------------------------------------------------------
alias hzhj_old_display_mp_damage_for_display_damage_wnd_btlog display_mp_damage
def display_mp_damage(target, item)
return if target.dead? || target.result.mp_damage == 0
value = target.result.mp_damage
critical = target.result.critical
target.damage_for_show = [:mp, value, critical]
hzhj_old_display_mp_damage_for_display_damage_wnd_btlog(target, item)
end
#--------------------------------------------------------------------------
# ● 显示 TP 伤害 (追加定义)
#--------------------------------------------------------------------------
alias hzhj_old_display_tp_damage_for_display_damage_wnd_btlog display_tp_damage
def display_tp_damage(target, item)
return if target.dead? || target.result.tp_damage == 0
value = target.result.tp_damage
critical = target.result.critical
target.damage_for_show = [:tp, value, critical]
hzhj_old_display_tp_damage_for_display_damage_wnd_btlog(target, item)
end
end
#==============================================================================
# ■ Sprite_Base
#==============================================================================
class Sprite_Base < Sprite
#--------------------------------------------------------------------------
# ● 初始化(追加定义)
#--------------------------------------------------------------------------
alias hzhj_old_init_for_display_damage_spr_base initialize
def initialize(*args)
hzhj_old_init_for_display_damage_spr_base(*args)
@damage_num_sprites = []
end
#--------------------------------------------------------------------------
# ● 释放(追加定义)
#--------------------------------------------------------------------------
alias hzhj_old_dispose_for_display_damage_spr_base dispose
def dispose
hzhj_old_dispose_for_display_damage_spr_base
dispose_damage
end
#--------------------------------------------------------------------------
# ● 判断是否有伤害在显示(新增定义)
#--------------------------------------------------------------------------
def damage?
return (not @damage_num_sprites.empty?)
end
#--------------------------------------------------------------------------
# ● 开始显示伤害(新增定义)
#--------------------------------------------------------------------------
def start_damage(args)
args[4] = x - ox + width / 2
args[5] = y - oy + height / 2
args[6] = z
@damage_num_sprites.push(Sprite_Damage.new(viewport, args))
end
#--------------------------------------------------------------------------
# ● 释放所有伤害显示(新增定义)
#--------------------------------------------------------------------------
def dispose_damage
return unless damage?
@damage_num_sprites.each{|sprite|sprite.dispose}
@damage_num_sprites.clear
end
#--------------------------------------------------------------------------
# ● 刷新(追加定义)
#--------------------------------------------------------------------------
alias hzhj_old_update_for_display_damage_spr_base update
def update
hzhj_old_update_for_display_damage_spr_base
update_damage
end
#--------------------------------------------------------------------------
# ● 刷新显示伤害(新增定义)
#--------------------------------------------------------------------------
def update_damage
return unless damage?
@damage_num_sprites.each_with_index do |sprite, i|
if sprite.moving?
sprite.update
else
sprite.dispose
@damage_num_sprites[i] = nil
end
end
@damage_num_sprites.delete(nil)
end
end
#==============================================================================
# ■ Sprite_Battler
#==============================================================================
class Sprite_Battler < Sprite_Base
#--------------------------------------------------------------------------
# ● 刷新(追加定义)
#--------------------------------------------------------------------------
alias hzhj_old_update_for_display_damage_spr_battler update
def update
hzhj_old_update_for_display_damage_spr_battler
if @battler
if not @battler.damage_for_show.empty?
#unless @battler.damage_section_displayed
args = @battler.damage_for_show.clone
args[3] = @battler.actor? ? :actor : (@battler.enemy? ? :enemy : nil)
start_damage(args)
#end
@battler.damage_for_show.clear
end
end
end
end
#==============================================================================
# ■ Game_BattlerBase
#==============================================================================
class Game_BattlerBase
#--------------------------------------------------------------------------
# ● 实例变量(新增定义)
#--------------------------------------------------------------------------
attr_accessor :damage_for_show #hzhj_damage
#--------------------------------------------------------------------------
# ● 初始化(追加定义)
#--------------------------------------------------------------------------
alias hzhj_old_init_for_display_damage_game_battler_base initialize
def initialize
@damage_for_show = []
hzhj_old_init_for_display_damage_game_battler_base
end
end
复制代码
怪物伤害显示.png
(333.06 KB, 下载次数: 54)
下载附件
保存到相册
2012-3-13 10:49 上传
作者:
saron7890
时间:
2012-4-23 15:35
本帖最后由 saron7890 于 2012-4-23 15:38 编辑
请问植入以上代码有什么需要注意的事项吗?
我加入后,进入游戏,开始战斗出错,在352行左右
但只是在“数据库”中的“敌群”中测试正常。
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1