赞 | 1 |
VIP | 246 |
好人卡 | 87 |
积分 | 1 |
经验 | 34142 |
最后登录 | 2015-1-15 |
在线时间 | 323 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 55
- 在线时间
- 323 小时
- 注册时间
- 2010-8-21
- 帖子
- 666
|
- #encoding:utf-8
- #==============================================================================
- # ■ Game_Event
- #------------------------------------------------------------------------------
- # 处理事件的类。拥有条件判断、事件页的切换、并行处理、执行事件等功能。
- # 在 Game_Map 类的内部使用。
- #==============================================================================
- class Game_Event < Game_Character
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_reader :trigger # 启动方式
- attr_reader :list # 执行内容
- attr_reader :starting # 启动中的标志
- #--------------------------------------------------------------------------
- # ● 初始化对象
- # event : RPG::Event
- #--------------------------------------------------------------------------
- def initialize(map_id, event)
- super()
- @map_id = map_id
- @event = event
- @id = @event.id
- moveto(@event.x, @event.y)
- refresh
- @manster = false
- if self.name[/.*\[距离:(\d),速度:(\d+),频率:(\d+),尸体:(.+)\].*/]
- @manster = true
- @body = $4
- @manster_distance = $1.to_i
- @manster_speed = $2.to_i
- @manster_frequency = $3.to_i
- @manster_old_frequency = @move_frequency
- @manster_old_speed = self.move_speed
- @manster_old_type = @move_type
- end
- end
- #--------------------------------------------------------------------------
- # ● 事件名称
- #--------------------------------------------------------------------------
- def name
- @event.name
- end
- #--------------------------------------------------------------------------
- # ● 初始化公有成员变量
- #--------------------------------------------------------------------------
- def init_public_members
- super
- @trigger = 0
- @list = nil
- @starting = false
- end
- #--------------------------------------------------------------------------
- # ● 初始化私有成员变量
- #--------------------------------------------------------------------------
- def init_private_members
- super
- @move_type = 0 # 移动类型
- @erased = false # 暂时消除的标志
- @page = nil # 事件页
- end
- #--------------------------------------------------------------------------
- # ● 判定是否与人物碰撞
- #--------------------------------------------------------------------------
- def collide_with_characters?(x, y)
- super || collide_with_player_characters?(x, y)
- end
- #--------------------------------------------------------------------------
- # ● 判定是否与玩家碰撞(包括跟随角色)
- #--------------------------------------------------------------------------
- def collide_with_player_characters?(x, y)
- normal_priority? && $game_player.collide?(x, y)
- end
- #--------------------------------------------------------------------------
- # ● 锁定(立即停止执行中的事件)
- #--------------------------------------------------------------------------
- def lock
- unless @locked
- @prelock_direction = @direction
- turn_toward_player
- @locked = true
- end
- end
- #--------------------------------------------------------------------------
- # ● 解锁
- #--------------------------------------------------------------------------
- def unlock
- if @locked
- @locked = false
- set_direction(@prelock_direction)
- end
- end
- #--------------------------------------------------------------------------
- # ● 停止时的更新
- #--------------------------------------------------------------------------
- def update_stop
- super
- update_self_movement unless @move_route_forcing
- end
- #--------------------------------------------------------------------------
- # ● 自动移动的更新
- #--------------------------------------------------------------------------
- def update_self_movement
- if near_the_screen? && @stop_count > stop_count_threshold
- case @move_type
- when 1; move_type_random
- when 2; move_type_toward_player
- when 3; move_type_custom
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 判定是否在画面的可视区域內
- # dx : 从画面中央开始计算,左右有多少个图块。
- # dy : 从画面中央开始计算,上下有多少个图块。
- #--------------------------------------------------------------------------
- def near_the_screen?(dx = 12, dy = 8)
- ax = $game_map.adjust_x(@real_x) - Graphics.width / 2 / 32
- ay = $game_map.adjust_y(@real_y) - Graphics.height / 2 / 32
- ax >= -dx && ax <= dx && ay >= -dy && ay <= dy
- end
- #--------------------------------------------------------------------------
- # ● 计算自动移动时停止计数最低值
- #--------------------------------------------------------------------------
- def stop_count_threshold
- 30 * (5 - @move_frequency)
- end
- #--------------------------------------------------------------------------
- # ● 移动类型 : 随机
- #--------------------------------------------------------------------------
- def move_type_random
- case rand(6)
- when 0..1; move_random
- when 2..4; move_forward
- when 5; @stop_count = 0
- end
- end
- #--------------------------------------------------------------------------
- # ● 移动类型 : 接近
- #--------------------------------------------------------------------------
- def move_type_toward_player
- if near_the_player?
- case rand(6)
- when 0..3; move_toward_player
- when 4; move_random
- when 5; move_forward
- end
- else
- move_random
- end
- end
- #--------------------------------------------------------------------------
- # ● 判定事件是否临近玩家
- #--------------------------------------------------------------------------
- def near_the_player?
- sx = distance_x_from($game_player.x).abs
- sy = distance_y_from($game_player.y).abs
- sx + sy < 20
- end
- #--------------------------------------------------------------------------
- # ● 移动类型 : 自定义
- #--------------------------------------------------------------------------
- def move_type_custom
- update_routine_move
- end
- #--------------------------------------------------------------------------
- # ● 清除启动中的标志
- #--------------------------------------------------------------------------
- def clear_starting_flag
- @starting = false
- end
- #--------------------------------------------------------------------------
- # ● 判定执行内容是否为空
- #--------------------------------------------------------------------------
- def empty?
- !@list || @list.size <= 1
- end
- #--------------------------------------------------------------------------
- # ● 判定指定的启动方式是否能启动事件
- # triggers : 启动方式的数组
- #--------------------------------------------------------------------------
- def trigger_in?(triggers)
- triggers.include?(@trigger)
- end
- #--------------------------------------------------------------------------
- # ● 事件启动
- #--------------------------------------------------------------------------
- def start
- return if empty?
- @starting = true
- lock if trigger_in?([0,1,2])
- end
- #--------------------------------------------------------------------------
- # ● 暂时消除
- #--------------------------------------------------------------------------
- def erase
- @erased = true
- refresh
- end
- #--------------------------------------------------------------------------
- # ● 刷新
- #--------------------------------------------------------------------------
- def refresh
- new_page = @erased ? nil : find_proper_page
- setup_page(new_page) if !new_page || new_page != @page
- end
- #--------------------------------------------------------------------------
- # ● 寻找条件符合的事件页
- #--------------------------------------------------------------------------
- def find_proper_page
- @event.pages.reverse.find {|page| conditions_met?(page) }
- end
- #--------------------------------------------------------------------------
- # ● 判定事件页的条件是否符合
- #--------------------------------------------------------------------------
- def conditions_met?(page)
- c = page.condition
- if c.switch1_valid
- return false unless $game_switches[c.switch1_id]
- end
- if c.switch2_valid
- return false unless $game_switches[c.switch2_id]
- end
- if c.variable_valid
- return false if $game_variables[c.variable_id] < c.variable_value
- end
- if c.self_switch_valid
- key = [@map_id, @event.id, c.self_switch_ch]
- return false if $game_self_switches[key] != true
- end
- if c.item_valid
- item = $data_items[c.item_id]
- return false unless $game_party.has_item?(item)
- end
- if c.actor_valid
- actor = $game_actors[c.actor_id]
- return false unless $game_party.members.include?(actor)
- end
- return true
- end
- #--------------------------------------------------------------------------
- # ● 设置事件页
- #--------------------------------------------------------------------------
- def setup_page(new_page)
- @page = new_page
- if @page
- setup_page_settings
- else
- clear_page_settings
- end
- update_bush_depth
- clear_starting_flag
- check_event_trigger_auto
- end
- #--------------------------------------------------------------------------
- # ● 清除事件页的设置
- #--------------------------------------------------------------------------
- def check_moster
- return unless @manster
- return if $game_self_switches[[$game_map.map_id,@id, @body]]
- if ($game_player.x-self.x).abs <= @manster_distance &&
- ($game_player.y-self.y).abs <= @manster_distance
- @move_speed = @manster_speed
- @move_type = 2
- @move_frequency = @manster_frequency
- else
- @move_speed = @manster_old_speed
- @move_type = @manster_old_type
- @move_frequency = @manster_old_frequency
- end
- end
- #--------------------------------------------------------------------------
- # ● 清除事件页的设置
- #--------------------------------------------------------------------------
- def clear_page_settings
- @tile_id = 0
- @character_name = ""
- @character_index = 0
- @move_type = 0
- @through = true
- @trigger = nil
- @list = nil
- @interpreter = nil
- end
- #--------------------------------------------------------------------------
- # ● 设置事件页的设置
- #--------------------------------------------------------------------------
- def setup_page_settings
- @tile_id = @page.graphic.tile_id
- @character_name = @page.graphic.character_name
- @character_index = @page.graphic.character_index
- if @original_direction != @page.graphic.direction
- @direction = @page.graphic.direction
- @original_direction = @direction
- @prelock_direction = 0
- end
- if @original_pattern != @page.graphic.pattern
- @pattern = @page.graphic.pattern
- @original_pattern = @pattern
- end
- @move_type = @page.move_type
- @move_speed = @page.move_speed
- @move_frequency = @page.move_frequency
- @move_route = @page.move_route
- @move_route_index = 0
- @move_route_forcing = false
- @walk_anime = @page.walk_anime
- @step_anime = @page.step_anime
- @direction_fix = @page.direction_fix
- @through = @page.through
- @priority_type = @page.priority_type
- @trigger = @page.trigger
- @list = @page.list
- @interpreter = @trigger == 4 ? Game_Interpreter.new : nil
- end
- #--------------------------------------------------------------------------
- # ● 接触事件的启动判定
- #--------------------------------------------------------------------------
- def check_event_trigger_touch(x, y)
- return if $game_map.interpreter.running?
- if @trigger == 2 && $game_player.pos?(x, y)
- start if !jumping? && normal_priority?
- end
- end
- #--------------------------------------------------------------------------
- # ● 自动事件的启动判定
- #--------------------------------------------------------------------------
- def check_event_trigger_auto
- start if @trigger == 3
- end
- #--------------------------------------------------------------------------
- # ● 更新画面
- #--------------------------------------------------------------------------
- def update
- super
- check_moster
- check_event_trigger_auto
- return unless @interpreter
- @interpreter.setup(@list, @event.id) unless @interpreter.running?
- @interpreter.update
- end
- end
复制代码 事件名例子
敌人[距离:5,速度:5,频率:6,尸体:A]
前面没什么好说的
多了个半角逗号和尸体
A代表事件独立开关A打开时,脚本不起作用了
Project1.7z
(290.12 KB, 下载次数: 73)
范例:
为节约,范例没有dll文件,请自行添加
|
|