赞 | 1 |
VIP | 0 |
好人卡 | 0 |
积分 | 92 |
经验 | 0 |
最后登录 | 2024-10-20 |
在线时间 | 466 小时 |
Lv4.逐梦者
- 梦石
- 0
- 星屑
- 9163
- 在线时间
- 466 小时
- 注册时间
- 2015-5-8
- 帖子
- 866
|
6楼
楼主 |
发表于 2021-10-31 16:01:27
|
只看该作者
本帖最后由 taeckle 于 2021-10-31 16:17 编辑
报告大神,我死磕了几天后这个问题终于被咱解决了,给你也分享下咱死磕的成果:
先总结下解决这个问题的整体思路,鉴于我的工程里还没有重名的NPC,我还是决定用事件名称来标记NPC以及其所携带的物品,在此之前得先用到那个显示事件名称脚本(插入到main上面就能用了,下面会有的), 然后得在$game_system里增加个存放NPC携带物品的全局变量, 最后完善偷窃脚本.
第1步: 把这个显示事件名称脚本插入到main上面:
- # 使用方法:插入到main前即可,之后就会显示每个事件的名字。
- # 不想显示名字的NPC直接把名字设置为一个空格就行了。
- #
- # 附加功能:名字颜色区分:比如一个NPC的名字是 小龙,2 就会用2号颜色(红色)显示
- #
- # 修改NPC名的方法:$game_map.events[事件ID编号].name =
- # 比如某个宝箱,原名宝箱,打开后名为“打开的宝箱”,则
- # $game_map.events[@event_id].name = "打开的宝箱" 或者
- # $game_map.events[2].name = "打开的宝箱" (假设宝箱是2号事件)
- #
- # 修改颜色定义:70-88行,131-149行,自己随便改。
- #
- # 给主角带上名字:192行,改 "" 为 "主角" 或者 $game_party.actors[0].name 即可
- #
- # 是否显示姓名的开关:157行,开头的井号去掉。则以后39号开关打开的时候才会显示姓名
- #
- #==============================================================================
- # ■ Game_Event
- #------------------------------------------------------------------------------
- # 处理事件的类。条件判断、事件页的切换、并行处理、执行事件功能
- # 在 Game_Map 类的内部使用。
- #==============================================================================
- class Game_Event < Game_Character
- #——————————————————————————————————————
- # 用来返回名称
- #——————————————————————————————————————
- def name
- return @event.name
- end
- def name=(newname)
- @event.name = newname
- end
- end
- #==============================================================================
- # ■ Sprite_Character
- #------------------------------------------------------------------------------
- # 角色显示用脚本。监视 Game_Character 类的实例、
- # 自动变化脚本状态。
- #==============================================================================
- class Sprite_Character < RPG::Sprite
- def dispose
- super
- @namesprite.dispose unless @namesprite.nil?
- @titlesprite.dispose unless @titlesprite.nil?
- @class_sprite.dispose unless @class_sprite.nil?
- end
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_accessor :character # 角色
- #--------------------------------------------------------------------------
- # ● 初始化对像
- # viewport : 查看端口
- # character : 角色 (Game_Character)
- #--------------------------------------------------------------------------
- def initialize(viewport, character = nil)
- if character == nil
- name = ""
- else
- name = character.name #if character != nil
- end
- super(viewport)
- @npc_name = ["AA","BB","CC","DD"]
- @character = character
- @namesprite = Sprite.new
- @namesprite.bitmap = Bitmap.new(160, 48)
- @namesprite.bitmap.font.name = ["黑体", "楷体", "宋体"]
- @namesprite.bitmap.font.size = 15
- @namesprite.bitmap.font.color.set( 30, 255, 0)
- ################################################
- @titlesprite = Sprite.new
- @titlesprite.bitmap = Bitmap.new(160, 48)#160,48
- @titlesprite.bitmap.font.name = ["黑体", "楷体", "宋体"] #"楷体"
- @titlesprite.bitmap.font.size = 25
- @titlesprite.bitmap.font.color.set(255, 200, 0)
- @class_sprite = Sprite.new
- @class_sprite.bitmap = Bitmap.new(160, 48)#160,48
- @class_sprite.bitmap.font.name = ["黑体", "楷体", "宋体"] #"楷体"
- @class_sprite.bitmap.font.size = 25
- @class_sprite.bitmap.font.color.set( 0, 255, 255)
- ################################################
- @evname = name
- @evname_split = name.split(/,/)[0]
- @evoy = 0
- if name[0, 2]=="EV"
- @evname_split = " "
- end
- #@tile_id = @character.tile_id
- #if @tile_id >= 384 && @character.name.split(/,/)[1] == nil
- # @evname_split = " "
- #end
- if name.split(/,/)[1] != nil
- case name.split(/,/)[1]
- when "0"
- @namesprite.bitmap.font.color.set(255, 255, 255)
- when "1"
- @namesprite.bitmap.font.color.set(120, 120, 120)
- when "2"
- @namesprite.bitmap.font.color.set(255, 0, 0)
- when "3"
- @namesprite.bitmap.font.color.set(30, 255, 0)
- when "4"
- @namesprite.bitmap.font.color.set(0, 112, 221)
- when "5"
- @namesprite.bitmap.font.color.set(163, 53, 238)
- when "6"
- @namesprite.bitmap.font.color.set(247, 102, 0)
- when "7"
- @namesprite.bitmap.font.color.set(255, 210, 0)
- else
- @evoy = name.split(/,/)[1].to_i
- #@namesprite.bitmap.font.color.set(255, 255, 255)
- end
- end
- if @evname_split != "" and @evname_split != nil
- if @character.character_name == "" && @character.tile_id == 0
- @evname_split = ""
- end
- if character.is_a?(Game_Player)
- if character.id == 0
- case $game_variables[16]
- when -999999..-60
- @namesprite.bitmap.font.color.set(255, 0, 0)
- when -59..79
- @namesprite.bitmap.font.color.set(255, 255, 255)
- when 80..999999
- @namesprite.bitmap.font.color.set(255, 255, 0)
- else
- end
- else
- @namesprite.bitmap.font.color.set(30, 255, 0)
- end
- for i in 0..@npc_name.size
- if @evname_split == @npc_name[i]
- @namesprite.bitmap.font.color.set(30, 255, 0)
- end
- end
- end
-
- @namesprite.bitmap.draw_text(0, 24, 160, 36, @evname_split, 1)
- end
- ################################################
-
- if character.is_a?(Game_Player) && character.id == 0
- if $game_party.actors[character.id].armor1_id != 0
- @evtitle = $data_armors[$game_party.actors[character.id].armor1_id].name.to_s
- else
- @evtitle = ""#$game_party.actors[character.id].class_name
- end
- @class_name = $game_party.actors[character.id].class_name
- for i in 0..@npc_name.size
- if @evname_split == @npc_name[i]
- @class_name = ""
- @evtitle = ""
- end
- end
- @class_name = "" if $game_party.actors[character.id].class_id == 1 or $game_party.actors[character.id].class_id == 26
- @titlesprite.bitmap.draw_text(0, 0, 160, 36, @evtitle, 1)#160 36
- @class_sprite.bitmap.draw_text(0, 0, 160, 36, @class_name, 1)
- end
- ################################################
- update
- end
- #--------------------------------------------------------------------------
- # ● 更新画面
- #--------------------------------------------------------------------------
- def update
- super
- return if @character == nil
- # 元件 ID、文件名、色相与现在的情况存在差异的情况下
- if @tile_id != @character.tile_id or
- @character_name != @character.character_name or
- @character_hue != @character.character_hue
- # 记忆元件 ID 与文件名、色相
- @tile_id = @character.tile_id
- @character_name = @character.character_name
- @character_hue = @character.character_hue
- # 元件 ID 为有效值的情况下
- if @tile_id >= 384
- self.bitmap = RPG::Cache.tile($game_map.tileset_name,
- @tile_id, @character.character_hue)
- self.src_rect.set(0, 0, 32, 32)
- self.ox = 16
- self.oy = 32
- # 元件 ID 为无效值的情况下
- else
- self.bitmap = RPG::Cache.character(@character.character_name,
- @character.character_hue)
- @cw = bitmap.width / 4
- @ch = bitmap.height / 4
- self.ox = @cw / 2
- self.oy = @ch
- end
- end
- if @evname != @character.name
- @namesprite.bitmap.clear
- @evname = @character.name
- @evname_split = @character.name.split(/,/)[0]
- if @character.name.split(/,/)[1] != nil
- case @character.name.split(/,/)[1]
- when "0"
- @namesprite.bitmap.font.color.set(255, 255, 255)
- when "1"
- @namesprite.bitmap.font.color.set(120, 120, 120)
- when "2"
- @namesprite.bitmap.font.color.set(255, 0, 0)
- when "3"
- @namesprite.bitmap.font.color.set( 30, 255, 0)
- when "4"
- @namesprite.bitmap.font.color.set( 0, 112, 221)
- when "5"
- @namesprite.bitmap.font.color.set(163, 53, 238)
- when "6"
- @namesprite.bitmap.font.color.set(255, 128, 0)
- when "7"
- @namesprite.bitmap.font.color.set(229, 204, 128)
- else
- @namesprite.bitmap.font.color.set(255, 255, 255)
- end
- end
-
- if @evname_split != "" and @evname_split != nil
- if character.character_name == "" && character.tile_id == 0
- @evname_split = ""
- end
- if character.is_a?(Game_Player)
- if character.id == 0
- case $game_variables[16]
- when -999999..-150
- @namesprite.bitmap.font.color.set(255, 0, 0)
- when -149..79
- @namesprite.bitmap.font.color.set(255, 255, 255)
- when 80..999999
- @namesprite.bitmap.font.color.set(247, 102, 0)
- else
- end
- else
- @namesprite.bitmap.font.color.set(30, 255, 0)
- end
- for i in 0..@npc_name.size
- if @evname_split == @npc_name[i]
- @namesprite.bitmap.font.color.set(30, 255, 0)
- end
- end
- end
- @namesprite.bitmap.draw_text(0, 24, 160, 36, @evname_split, 1)
- end
- ################################################
-
- if character.is_a?(Game_Player)
- if $game_party.actors[character.id].armor1_id != 0
- @evtitle = $data_armors[$game_party.actors[character.id].armor1_id].name.to_s
- else
- @evtitle = ""#$game_party.actors[character.id].class_name
- end
- @class_name = $game_party.actors[character.id].class_name
- for i in 0..@npc_name.size
- if @evname_split == @npc_name[i]
- @class_name = ""
- @evtitle = ""
- end
- end
- @class_name = "" if $game_party.actors[character.id].class_id == 1 or $game_party.actors[character.id].class_id == 26
- @titlesprite.bitmap.draw_text(0, 0, 160, 36, @evtitle, 1)#160 36
- @class_sprite.bitmap.draw_text(0, 0, 160, 36, @class_name, 1)
- end
- ################################################
- end
- @namesprite.x = self.x-80
- @namesprite.y = self.y-self.oy-10-@evoy
- ################################################
- if @class_name == ""
- @titlesprite.x = self.x-80
- @titlesprite.y = self.y-123
-
- @class_sprite.x = self.x-80
- @class_sprite.y = self.y-123
- else
- @titlesprite.x = self.x-80
- #@titlesprite.y = self.y-148 #原人物模型位置
- @titlesprite.y = self.y-141
-
- @class_sprite.x = self.x-80
- #@class_sprite.y = self.y-130 #原人物模型位置
- @class_sprite.y = self.y-123
- end
- # @namesprite.visible = $game_switches[12]
- # 设置可视状态
- self.visible = (not @character.transparent)
- # 图形是角色的情况下
- if @tile_id == 0
- # 设置传送目标的矩形
- sx = @character.pattern * @cw
- sy = (@character.direction - 2) / 2 * @ch
- self.src_rect.set(sx, sy, @cw, @ch)
- end
- # 设置脚本的坐标
- self.x = @character.screen_x
- self.y = @character.screen_y
- self.z = @character.screen_z(@ch)
- # 设置不透明度、合成方式、茂密
- self.opacity = @character.opacity
- self.blend_type = @character.blend_type
- self.bush_depth = @character.bush_depth
- # 动画
- if @character.animation_id != 0
- animation = $data_animations[@character.animation_id]
- animation(animation, true)
- @character.animation_id = 0
- end
- end
- end
- #==============================================================================
- # ■ Game_Player
- #------------------------------------------------------------------------------
- # 处理主角的类。事件启动的判定、以及地图的滚动等功能。
- # 本类的实例请参考 $game_player。
- #==============================================================================
- class Game_Player < Game_Character
- def name
- return $game_party.actors[0].name
- end
- end
复制代码
第2步: 在$game_system里增加个存放NPC携带物品的全局变量:
#============================================================================== # ■ Game_System #------------------------------------------------------------------------------ # 处理系统附属数据的类。也可执行诸如 BGM 管理之类的功能。本类的实例请参考 # $game_system 。 #============================================================================== class Game_System #-------------------------------------------------------------------------- # ● 定义实例变量 #-------------------------------------------------------------------------- attr_reader :map_interpreter # 地图事件用解释程序 attr_reader :battle_interpreter # 战斗事件用解释程序 attr_accessor :timer # 计时器 attr_accessor :timer_working # 计时器执行中的标志 attr_accessor :save_disabled # 禁止存档 attr_accessor :menu_disabled # 禁止菜单 attr_accessor :encounter_disabled # 禁止遇敌 attr_accessor :message_position # 文章选项 显示位置 attr_accessor :message_frame # 文章选项 窗口外关 attr_accessor :save_count # 存档次数 attr_accessor :magic_number # 魔法编号 attr_accessor :npc_carry_items # NPC携带的物品集合 #-------------------------------------------------------------------------- # ● 初始化对像 #-------------------------------------------------------------------------- def initialize @map_interpreter = Interpreter.new(0, true) @battle_interpreter = Interpreter.new(0, false) @timer = 0 @timer_working = false @save_disabled = false @menu_disabled = false @encounter_disabled = false @message_position = 2 @message_frame = 0 @save_count = 0 @magic_number = 0 @npc_carry_items = Hash["偷窃对象1"=>[[1,11],[2,12],[3,13]], "偷窃对象2"=>[[5,15],[6,16],[7,17]], "guoxiaomi"=>[[2],[3],[5,5,5]], "待定"=>[[],[],[]]] end #-------------------------------------------------------------------------- # ● 演奏 BGM # bgm : 演奏的 BGM #-------------------------------------------------------------------------- def bgm_play(bgm) @playing_bgm = bgm if bgm != nil and bgm.name != "" Audio.bgm_play("Audio/BGM/" + bgm.name, bgm.volume, bgm.pitch) else Audio.bgm_stop end Graphics.frame_reset end #-------------------------------------------------------------------------- # ● 停止 BGM #-------------------------------------------------------------------------- def bgm_stop Audio.bgm_stop end #-------------------------------------------------------------------------- # ● BGM 的淡出 # time : 淡出时间 (秒) #-------------------------------------------------------------------------- def bgm_fade(time) @playing_bgm = nil Audio.bgm_fade(time * 1000) end #-------------------------------------------------------------------------- # ● 记忆 BGM #-------------------------------------------------------------------------- def bgm_memorize @memorized_bgm = @playing_bgm end #-------------------------------------------------------------------------- # ● 还原 BGM #-------------------------------------------------------------------------- def bgm_restore bgm_play(@memorized_bgm) end #-------------------------------------------------------------------------- # ● 演奏 BGS # bgs : 演奏的 BGS #-------------------------------------------------------------------------- def bgs_play(bgs) @playing_bgs = bgs if bgs != nil and bgs.name != "" Audio.bgs_play("Audio/BGS/" + bgs.name, bgs.volume, bgs.pitch) else Audio.bgs_stop end Graphics.frame_reset end #-------------------------------------------------------------------------- # ● BGS 的淡出 # time : 淡出时间 (秒) #-------------------------------------------------------------------------- def bgs_fade(time) @playing_bgs = nil Audio.bgs_fade(time * 1000) end #-------------------------------------------------------------------------- # ● 记忆 BGS #-------------------------------------------------------------------------- def bgs_memorize @memorized_bgs = @playing_bgs end #-------------------------------------------------------------------------- # ● 还原 BGS #-------------------------------------------------------------------------- def bgs_restore bgs_play(@memorized_bgs) end #-------------------------------------------------------------------------- # ● ME 的演奏 # me : 演奏的 ME #-------------------------------------------------------------------------- def me_play(me) if me != nil and me.name != "" Audio.me_play("Audio/ME/" + me.name, me.volume, me.pitch) else Audio.me_stop end Graphics.frame_reset end #-------------------------------------------------------------------------- # ● SE 的演奏 # se : 演奏的 SE #-------------------------------------------------------------------------- def se_play(se) if se != nil and se.name != "" Audio.se_play("Audio/SE/" + se.name, se.volume, se.pitch) end end #-------------------------------------------------------------------------- # ● 停止 SE #-------------------------------------------------------------------------- def se_stop Audio.se_stop end #-------------------------------------------------------------------------- # ● 获取演奏中 BGM #-------------------------------------------------------------------------- def playing_bgm return @playing_bgm end #-------------------------------------------------------------------------- # ● 获取演奏中 BGS #-------------------------------------------------------------------------- def playing_bgs return @playing_bgs end #-------------------------------------------------------------------------- # ● 获取窗口外观的文件名 #-------------------------------------------------------------------------- def windowskin_name if @windowskin_name == nil return $data_system.windowskin_name else return @windowskin_name end end #-------------------------------------------------------------------------- # ● 设置窗口外观的文件名 # windowskin_name : 新的窗口外观文件名 #-------------------------------------------------------------------------- def windowskin_name=(windowskin_name) @windowskin_name = windowskin_name end #-------------------------------------------------------------------------- # ● 获取战斗 BGM #-------------------------------------------------------------------------- def battle_bgm if @battle_bgm == nil return $data_system.battle_bgm else return @battle_bgm end end #-------------------------------------------------------------------------- # ● 设置战斗 BGM # battle_bgm : 新的战斗 BGM #-------------------------------------------------------------------------- def battle_bgm=(battle_bgm) @battle_bgm = battle_bgm end #-------------------------------------------------------------------------- # ● 获取战斗结束的 BGM #-------------------------------------------------------------------------- def battle_end_me if @battle_end_me == nil return $data_system.battle_end_me else return @battle_end_me end end #-------------------------------------------------------------------------- # ● 设置战斗结束的 BGM # battle_end_me : 新的战斗结束 BGM #-------------------------------------------------------------------------- def battle_end_me=(battle_end_me) @battle_end_me = battle_end_me end #-------------------------------------------------------------------------- # ● 刷新画面 #-------------------------------------------------------------------------- def update # 计时器减 1 if @timer_working and @timer > 0 @timer -= 1 end end end
#==============================================================================
# ■ Game_System
#------------------------------------------------------------------------------
# 处理系统附属数据的类。也可执行诸如 BGM 管理之类的功能。本类的实例请参考
# $game_system 。
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_reader :map_interpreter # 地图事件用解释程序
attr_reader :battle_interpreter # 战斗事件用解释程序
attr_accessor :timer # 计时器
attr_accessor :timer_working # 计时器执行中的标志
attr_accessor :save_disabled # 禁止存档
attr_accessor :menu_disabled # 禁止菜单
attr_accessor :encounter_disabled # 禁止遇敌
attr_accessor :message_position # 文章选项 显示位置
attr_accessor :message_frame # 文章选项 窗口外关
attr_accessor :save_count # 存档次数
attr_accessor :magic_number # 魔法编号
attr_accessor :npc_carry_items # NPC携带的物品集合
#--------------------------------------------------------------------------
# ● 初始化对像
#--------------------------------------------------------------------------
def initialize
@map_interpreter = Interpreter.new(0, true)
@battle_interpreter = Interpreter.new(0, false)
@timer = 0
@timer_working = false
@save_disabled = false
@menu_disabled = false
@encounter_disabled = false
@message_position = 2
@message_frame = 0
@save_count = 0
@magic_number = 0
@npc_carry_items = Hash["偷窃对象1"=>[[1,11],[2,12],[3,13]],
"偷窃对象2"=>[[5,15],[6,16],[7,17]],
"guoxiaomi"=>[[2],[3],[5,5,5]],
"待定"=>[[],[],[]]]
end
#--------------------------------------------------------------------------
# ● 演奏 BGM
# bgm : 演奏的 BGM
#--------------------------------------------------------------------------
def bgm_play(bgm)
@playing_bgm = bgm
if bgm != nil and bgm.name != ""
Audio.bgm_play("Audio/BGM/" + bgm.name, bgm.volume, bgm.pitch)
else
Audio.bgm_stop
end
Graphics.frame_reset
end
#--------------------------------------------------------------------------
# ● 停止 BGM
#--------------------------------------------------------------------------
def bgm_stop
Audio.bgm_stop
end
#--------------------------------------------------------------------------
# ● BGM 的淡出
# time : 淡出时间 (秒)
#--------------------------------------------------------------------------
def bgm_fade(time)
@playing_bgm = nil
Audio.bgm_fade(time * 1000)
end
#--------------------------------------------------------------------------
# ● 记忆 BGM
#--------------------------------------------------------------------------
def bgm_memorize
@memorized_bgm = @playing_bgm
end
#--------------------------------------------------------------------------
# ● 还原 BGM
#--------------------------------------------------------------------------
def bgm_restore
bgm_play(@memorized_bgm)
end
#--------------------------------------------------------------------------
# ● 演奏 BGS
# bgs : 演奏的 BGS
#--------------------------------------------------------------------------
def bgs_play(bgs)
@playing_bgs = bgs
if bgs != nil and bgs.name != ""
Audio.bgs_play("Audio/BGS/" + bgs.name, bgs.volume, bgs.pitch)
else
Audio.bgs_stop
end
Graphics.frame_reset
end
#--------------------------------------------------------------------------
# ● BGS 的淡出
# time : 淡出时间 (秒)
#--------------------------------------------------------------------------
def bgs_fade(time)
@playing_bgs = nil
Audio.bgs_fade(time * 1000)
end
#--------------------------------------------------------------------------
# ● 记忆 BGS
#--------------------------------------------------------------------------
def bgs_memorize
@memorized_bgs = @playing_bgs
end
#--------------------------------------------------------------------------
# ● 还原 BGS
#--------------------------------------------------------------------------
def bgs_restore
bgs_play(@memorized_bgs)
end
#--------------------------------------------------------------------------
# ● ME 的演奏
# me : 演奏的 ME
#--------------------------------------------------------------------------
def me_play(me)
if me != nil and me.name != ""
Audio.me_play("Audio/ME/" + me.name, me.volume, me.pitch)
else
Audio.me_stop
end
Graphics.frame_reset
end
#--------------------------------------------------------------------------
# ● SE 的演奏
# se : 演奏的 SE
#--------------------------------------------------------------------------
def se_play(se)
if se != nil and se.name != ""
Audio.se_play("Audio/SE/" + se.name, se.volume, se.pitch)
end
end
#--------------------------------------------------------------------------
# ● 停止 SE
#--------------------------------------------------------------------------
def se_stop
Audio.se_stop
end
#--------------------------------------------------------------------------
# ● 获取演奏中 BGM
#--------------------------------------------------------------------------
def playing_bgm
return @playing_bgm
end
#--------------------------------------------------------------------------
# ● 获取演奏中 BGS
#--------------------------------------------------------------------------
def playing_bgs
return @playing_bgs
end
#--------------------------------------------------------------------------
# ● 获取窗口外观的文件名
#--------------------------------------------------------------------------
def windowskin_name
if @windowskin_name == nil
return $data_system.windowskin_name
else
return @windowskin_name
end
end
#--------------------------------------------------------------------------
# ● 设置窗口外观的文件名
# windowskin_name : 新的窗口外观文件名
#--------------------------------------------------------------------------
def windowskin_name=(windowskin_name)
@windowskin_name = windowskin_name
end
#--------------------------------------------------------------------------
# ● 获取战斗 BGM
#--------------------------------------------------------------------------
def battle_bgm
if @battle_bgm == nil
return $data_system.battle_bgm
else
return @battle_bgm
end
end
#--------------------------------------------------------------------------
# ● 设置战斗 BGM
# battle_bgm : 新的战斗 BGM
#--------------------------------------------------------------------------
def battle_bgm=(battle_bgm)
@battle_bgm = battle_bgm
end
#--------------------------------------------------------------------------
# ● 获取战斗结束的 BGM
#--------------------------------------------------------------------------
def battle_end_me
if @battle_end_me == nil
return $data_system.battle_end_me
else
return @battle_end_me
end
end
#--------------------------------------------------------------------------
# ● 设置战斗结束的 BGM
# battle_end_me : 新的战斗结束 BGM
#--------------------------------------------------------------------------
def battle_end_me=(battle_end_me)
@battle_end_me = battle_end_me
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
# 计时器减 1
if @timer_working and @timer > 0
@timer -= 1
end
end
end
第3步: 完善偷窃脚本:
#------------------------------------------------------------------------- # ★★★★★★ #------------------------------------------------------------------------- module Stolen STEAL_SKILL_ID = 1 # 偷盗特技id end #------------------------------------------------------------------------- # ★★★★★★ #------------------------------------------------------------------------- class Scene_Map attr_accessor :spriteset end #------------------------------------------------------------------------- # ★★★★★★ #------------------------------------------------------------------------- class Window_Npc_Item < Window_Selectable #-------------------------------------------------------------------------- # ● 初始化对像 #-------------------------------------------------------------------------- def initialize(item) super(224, 80, 188+100, 320) @column_max = 1 @item = item @item_max = @item.size self.height = @item.size*32+32 self.y = (480-self.height)/2 self.opacity = 160 refresh self.index = 0 end #-------------------------------------------------------------------------- def item return @item[self.index] end #-------------------------------------------------------------------------- def refresh if self.contents != nil self.contents.dispose self.contents = nil end if @item_max > 0 self.contents = Bitmap.new(width - 32, row_max * 32) for i in 0...@item_max draw_item(i) end end end #-------------------------------------------------------------------------- def draw_item(index) item = @item[index] x = 4 y = index * 32 bitmap = RPG::Cache.icon(item.icon_name) self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24)) self.contents.draw_text(x + 28, y, 212, 32, item.name, 0) end end #------------------------------------------------------------------------- # ★★★★★★ #------------------------------------------------------------------------- class Game_Party attr_reader :stealexp attr_accessor :stealnpc alias initialize_old initialize def initialize initialize_old @stealexp = 0 @stealnpc = {} end def add_sexp(n) @stealexp = [[@stealexp + n, 0].max, 100].min end end #------------------------------------------------------------------------- # ★★★★★★ #------------------------------------------------------------------------- class Interpreter def judge @npc_item = [] @npc_item.clear if @list[0].code == 108 if @list[0].parameters[0].split(/:/)[0] == "可偷盗对象" unless @list[0].parameters[0].split(/:/)[1] == nil @npc_item = eval(@list[0].parameters[0].split(/:/)[1]) end end end end #偷盗 def steal unless judge_skill @message_waiting = true $game_temp.message_proc = Proc.new { @message_waiting = false } $game_temp.message_text = "无人会偷盗技能!" return true end if @npc_item.size == 0 @message_waiting = true $game_temp.message_proc = Proc.new { @message_waiting = false } $game_temp.message_text = "对方已无任何道具." return true end win = Window_Npc_Item.new(@npc_item) loop do $game_map.update $scene.spriteset.update Graphics.update Input.update win.update if Input.trigger?(Input::B) win.dispose $game_system.se_play($data_system.cancel_se) return true end if Input.trigger?(Input::C) win.dispose $game_map.events[@event_id].animation_id = $data_skills[Stolen::STEAL_SKILL_ID].animation2_id for i in 1..$data_animations[$data_skills[Stolen::STEAL_SKILL_ID].animation2_id].frame_max*4 Graphics.update $game_map.update $game_player.update $scene.spriteset.update end if successful?(@list[2].parameters[0].split(/,/)[1].split(/:/)[1].to_i) $game_party.add_sexp(2) #偷盗经验值上升 item = win.item case item when RPG::Item $game_party.gain_item(item.id, 1) g_npc=$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][0] g_npc.delete_at g_npc.index item.id #这里最好用指令arr.delete_at arr.index,用delete的话会把所有item.id号物品全删了 when RPG::Weapon $game_party.gain_weapon(item.id, 1) g_npc=$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][1] g_npc.delete_at g_npc.index item.id when RPG::Armor $game_party.gain_armor(item.id, 1) g_npc=$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][2] g_npc.delete_at g_npc.index item.id end @wait_count = 1 return true else #$game_party.add_sexp(1) #偷盗经验值上升 @message_waiting = true $game_temp.message_proc = Proc.new { @message_waiting = false } $game_temp.message_text = "盗取失败,被发现了!" Audio.se_play("Audio/SE/"+"Glass1",80,100) @wait_count = 1 if $data_troops[@list[3].parameters[0].split(/:/)[1].to_i] != nil $game_temp.battle_abort = true $game_temp.battle_calling = true $game_temp.battle_troop_id = @list[3].parameters[0].split(/:/)[1].to_i $game_temp.battle_can_escape = false $game_temp.battle_can_lose = false current_indent = @list[@index].indent $game_temp.battle_proc = Proc.new { |n| @branch[current_indent] = n } end end break end # end of C键 end #end of loop do end #end of def #是否有“盗窃”技能判断 def judge_skill actor = $game_party.actors for i in 0...actor.size if actor[i].skills.include?(Stolen::STEAL_SKILL_ID) return true end end return false end #取得物品 def get_item temp_item = [] #生成物品列表 for i in 0...$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][0].size temp_item.push($data_items[$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][0][i].to_i]) end #生成武器列表 for i in 0...$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][1].size temp_item.push($data_weapons[$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][1][i].to_i]) end #生成防具列表 for i in 0...$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][2].size temp_item.push($data_armors[$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][2][i].to_i]) end #返回物品数组 return temp_item end #偷盗成功判断 def successful?(n) # n - 对象npc的过失率, 这里暂时设定为100%成功 s_rate = 101 return rand(101) < s_rate end #------------------------------------------ end
#-------------------------------------------------------------------------
# ★★★★★★
#-------------------------------------------------------------------------
module Stolen
STEAL_SKILL_ID = 1 # 偷盗特技id
end
#-------------------------------------------------------------------------
# ★★★★★★
#-------------------------------------------------------------------------
class Scene_Map
attr_accessor :spriteset
end
#-------------------------------------------------------------------------
# ★★★★★★
#-------------------------------------------------------------------------
class Window_Npc_Item < Window_Selectable
#--------------------------------------------------------------------------
# ● 初始化对像
#--------------------------------------------------------------------------
def initialize(item)
super(224, 80, 188+100, 320)
@column_max = 1
@item = item
@item_max = @item.size
self.height = @item.size*32+32
self.y = (480-self.height)/2
self.opacity = 160
refresh
self.index = 0
end
#--------------------------------------------------------------------------
def item
return @item[self.index]
end
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@item_max
draw_item(i)
end
end
end
#--------------------------------------------------------------------------
def draw_item(index)
item = @item[index]
x = 4
y = index * 32
bitmap = RPG::Cache.icon(item.icon_name)
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
end
end
#-------------------------------------------------------------------------
# ★★★★★★
#-------------------------------------------------------------------------
class Game_Party
attr_reader :stealexp
attr_accessor :stealnpc
alias initialize_old initialize
def initialize
initialize_old
@stealexp = 0
@stealnpc = {}
end
def add_sexp(n)
@stealexp = [[@stealexp + n, 0].max, 100].min
end
end
#-------------------------------------------------------------------------
# ★★★★★★
#-------------------------------------------------------------------------
class Interpreter
def judge
@npc_item = []
@npc_item.clear
if @list[0].code == 108
if @list[0].parameters[0].split(/:/)[0] == "可偷盗对象"
unless @list[0].parameters[0].split(/:/)[1] == nil
@npc_item = eval(@list[0].parameters[0].split(/:/)[1])
end
end
end
end
#偷盗
def steal
unless judge_skill
@message_waiting = true
$game_temp.message_proc = Proc.new { @message_waiting = false }
$game_temp.message_text = "无人会偷盗技能!"
return true
end
if @npc_item.size == 0
@message_waiting = true
$game_temp.message_proc = Proc.new { @message_waiting = false }
$game_temp.message_text = "对方已无任何道具."
return true
end
win = Window_Npc_Item.new(@npc_item)
loop do
$game_map.update
$scene.spriteset.update
Graphics.update
Input.update
win.update
if Input.trigger?(Input::B)
win.dispose
$game_system.se_play($data_system.cancel_se)
return true
end
if Input.trigger?(Input::C)
win.dispose
$game_map.events[@event_id].animation_id = $data_skills[Stolen::STEAL_SKILL_ID].animation2_id
for i in 1..$data_animations[$data_skills[Stolen::STEAL_SKILL_ID].animation2_id].frame_max*4
Graphics.update
$game_map.update
$game_player.update
$scene.spriteset.update
end
if successful?(@list[2].parameters[0].split(/,/)[1].split(/:/)[1].to_i)
$game_party.add_sexp(2) #偷盗经验值上升
item = win.item
case item
when RPG::Item
$game_party.gain_item(item.id, 1)
g_npc=$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][0]
g_npc.delete_at g_npc.index item.id #这里最好用指令arr.delete_at arr.index,用delete的话会把所有item.id号物品全删了
when RPG::Weapon
$game_party.gain_weapon(item.id, 1)
g_npc=$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][1]
g_npc.delete_at g_npc.index item.id
when RPG::Armor
$game_party.gain_armor(item.id, 1)
g_npc=$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][2]
g_npc.delete_at g_npc.index item.id
end
@wait_count = 1
return true
else
#$game_party.add_sexp(1) #偷盗经验值上升
@message_waiting = true
$game_temp.message_proc = Proc.new { @message_waiting = false }
$game_temp.message_text = "盗取失败,被发现了!"
Audio.se_play("Audio/SE/"+"Glass1",80,100)
@wait_count = 1
if $data_troops[@list[3].parameters[0].split(/:/)[1].to_i] != nil
$game_temp.battle_abort = true
$game_temp.battle_calling = true
$game_temp.battle_troop_id = @list[3].parameters[0].split(/:/)[1].to_i
$game_temp.battle_can_escape = false
$game_temp.battle_can_lose = false
current_indent = @list[@index].indent
$game_temp.battle_proc = Proc.new { |n| @branch[current_indent] = n }
end
end
break
end # end of C键
end #end of loop do
end #end of def
#是否有“盗窃”技能判断
def judge_skill
actor = $game_party.actors
for i in 0...actor.size
if actor[i].skills.include?(Stolen::STEAL_SKILL_ID)
return true
end
end
return false
end
#取得物品
def get_item
temp_item = []
#生成物品列表
for i in 0...$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][0].size
temp_item.push($data_items[$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][0][i].to_i])
end
#生成武器列表
for i in 0...$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][1].size
temp_item.push($data_weapons[$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][1][i].to_i])
end
#生成防具列表
for i in 0...$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][2].size
temp_item.push($data_armors[$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][2][i].to_i])
end
#返回物品数组
return temp_item
end
#偷盗成功判断
def successful?(n) # n - 对象npc的过失率, 这里暂时设定为100%成功
s_rate = 101
return rand(101) < s_rate
end
#------------------------------------------
end
|
|