Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =begin
- #==============================================================================
- ** Event Wrapper
- Автор: Tsukihime
- Переводчик: DeadElf79
- Дата релиза: Июль 10, 2012
- Дата перевода: 05.05 - 07.05.2015, 30.07.2015, 02.08.2015
- ------------------------------------------------------------------------------
- ** Список изменений
- Февраль 14, 2015
- - добавлена поддерержка удаления сторонних событий по вызову
- Декабрь 16, 2014
- - исправлен асинхронный спавн ивентов из параллельных событий
- Ноябрь 5, 2013
- - добавлен простой экспорт событий, чтобы вы могли посмотреть их
- прямо из редактора, если захотите
- - исправлена ошибка, при которой конвертация булевых значений
- происходила неправильно
- Декабрь 18, 2012
- - удалено хранение оригинального блока. Позднее будет заменено
- на строку для правильного марашлинга (сериализации)
- Октябрь 7, 2012
- - исправлена ошибка, когда паттерны ивентов нельзя было использовать
- Август 16, 2012
- - добавлены методы экземпляра для класса EventBuilder
- Август 14, 2012
- - добавлена команда "delete". Использовать для сторонних событий!
- Август 2,2012
- - улучшен код ветвления условий. Теперь принимается вызов скрипта
- Июль 11,2012
- - добавлено управление движением (move_route)
- - добавлен конвертор для возможности использовать 0/1 или true/false
- - команда add_message может принимать массив строк теперь
- - добавлен отдельный класс EventBuilder для сторонних событий
- Июль 10, 2012
- - реализовано создание содержимого ивента при помощи DSL
- - добавлена возможность создавать условия
- - добавлена куча функций из оригинального редактора событий
- Июль 9, 2012
- - Первый релиз
- ------------------------------------------------------------------------------
- Данный скрипт создает обёртку (wrapper) для работы над экземплярами
- класса RPG::Event, добавляя дополнительные методы для создания
- и наполнения событий при помози скриптов. Все названия команд
- перенесены из окна редактора событий, чтобы вы могли
- сразу же использовать привычные команды.
- Пример создания нового события.
- 1. Создайте экземпляр класса Event и укажите координаты, где появится событие
- event = Event.new(2, 4)
- 2. Укажите один или несколько параметров события, например, графику персонажа
- event.character_name = "actor1"
- Вы также можете указать графику персонажа для каждой страницы события
- по отдельности:
- event.page[0].character_name = "actor1"
- Так как первая страница в событии имеет номер 0 (запомните это!),
- то оба примера кода выше делают одно и то же.
- Вы также можете указать текущую страницу (необходимо для создания
- содержимого для всех страниц, кроме нулевой).
- event.set_page(n)
- n - номер страницы
- 3. Укажите условия для выбранных страниц события.
- Подробнее об это - см. класс Event_Condition
- # это значит, что переключатель 2 должен быть ВКЛ.
- event.condition.switch1_id = 2
- # актёр под номером 4 должен быть в партии
- event.condition.actor_id = 4
- 4. Не забудьте добавить только что созданное событие на карту
- (в данном примере - на текущую).
- $game_map.add_event(event)
- Теперь, освоив азы, вы можете создать отдельные функции в редакторе скриптов,
- которые будут вызывать создание определенных событий тогда, когда
- вам это будет нужно. Вы можете добавить эти функции в Game_Interpreter
- или создать для них отдельный модуль или класс.
- Я покажу вам еще несколько примеров. На сей раз - создание содержимого
- события, то есть добавление в него команд и условий. Мной был добавлен
- специальный класс Event_Builder для того, чтобы вы могли
- использовать синтаксис, отличный от привычного синтаксиса Ruby,
- который будет при это куда удобнее.
- Все методы доступны в классе EventCommands.
- Давайте создадим наше первое сообщение, которое будет показано
- при активации события (когда игрок на него нажмёт)
- event.build {
- # зададим название файла графики лиц и укажем номер лица в файле
- # (отсчёт идёт от нуля)
- show_text("actor1", 1)
- # зададим текст для сообщения, чтобы оно не было пустым
- add_message("Приветствую тебя, игрок!")
- }
- При создании содержимого события вы можете добавлять условия,
- окно с возможностью выбора и многие другие вещи.
- Данный пример показывает, как вы можете создать список
- вариантов для выбора и также установить действия,
- которые будут осуществлены при выборе.
- event.build {
- show_text("actor1", 1)
- add_message("Что ты хотел бы восстановить?")
- show_choices(["Здоровье", "Ману", "Мир во всем мире"], 0)
- choice_branch(0) {
- show_text("actor1", 1)
- add_message("Так будь здоров и не кашляй")
- }
- choice_branch(1) {
- show_text("actor1", 1)
- add_message("Скушай вот этот кристалл, полегчает")
- }
- choice_branch(2) {
- show_text("actor1", 1)
- add_message("Ишь чего захотел!")
- }
- }
- Если вы знаете Ruby, то вы может использовать и его синтаксис
- при создании событий тоже. Вот, например, этот скрипт
- отобразит окно выбора с именами всех членов партии (Game_Party)
- и после выбора одного из них, покажет его имя, уровень и класс
- в обычном окне как если бы это был диалог.
- event.build {
- show_text("actor2", 5)
- add_message("Which party member do you wish to view?")
- actors = $game_party.members.collect {|actor| actor.name }
- show_choices(actors, 0)
- $game_party.members.each_with_index { |actor, i|
- choice_branch(i) {
- show_text(actor.face_name, actor.face_index)
- add_message("%s is a level %d %s" %[actor.name, actor.level, actor.class.name])
- }
- }
- }
- А этот пример демонстрирует работу с движением событий.
- event.build {
- route = MoveRoute.new
- route.build {
- # Шаг вверх
- move_up
- # Два шага вниз
- move_down(2)
- # "Короткая" запись распространенных движений
- # Сделаем 2 шага влево, а затем еще 2 - вправо.
- move("2L2R")
- }
- set_move_route(-1, route)
- }
- "Короткая" запись позволяет указать направления движения события одной небольшой строкой,
- которая избавит вас от копирования одних и тех же повторяющихся команд
- по несколько раз подряд.
- Без короткой записи:
- event.build {
- route = MoveRoute.new
- route.build {
- move_up
- move_up
- move_up
- move_up
- # Или
- move_up(4)
- }
- }
- "Короткая" запись:
- event.build {
- route = MoveRoute.new
- route.build {
- move("4U")
- }
- }
- Список символов для "короткой" записи:
- U - вверх
- D - вниз
- L - влево
- R - вправо
- Q -
- W -
- A -
- S -
- Небольшой пример использования условий в событии (не для страниц, а именно
- внутри них):
- def make_condition_event(x, y)
- event = Event.new(x, y)
- event.character_name = "actor1"
- event.character_index = 2
- event.build {
- cond_if("$game_actors[1].level > 5") {
- show_text("actor1", 2)
- add_message("Приветствую! Как ты вырос!")
- change_followers(true)
- }
- cond_else {
- show_text("actor1", 2)
- add_message("Твой уровень недостаточно высок для меня")
- }
- }
- $game_map.add_event(event)
- end
- Вы можете экспортировать ваше событие ("вшить" его в карту) при помощи
- вызова следующего скрипта:
- EventWrapper.export_event(map_id,x,y,event)
- #==============================================================================
- =end
- $imported = {} if $imported.nil?
- $imported["Event_Wrapper"] = true
- #==============================================================================
- # ** Здесь начинается скрипт
- #==============================================================================
- module Tsuki
- module Event_Wrapper
- # Следующая строка объясняет какую-то неведомую переводчику магию
- # This hash maps "nice" names to internal ID's used by conditional branches
- Cond_Table = {
- "switch" => 0,
- "variable" => 1, # ["variable", ID, value, value, operation]
- "self-switch" => 2,
- "timer" => 3,
- "actor" => 4,
- "enemy" => 5,
- "character" => 6,
- "gold" => 7,
- "item" => 8,
- "weapon" => 9,
- "armor" => 10,
- "button" => 11,
- "script" => 12,
- "vehicle" => 13
- }
- Move_String_Regex = /(\d*)([UDLRQWAS])/
- end
- end
- module EventWrapper
- def self.export_event(map_id, x, y, event)
- event = Marshal.load(Marshal.dump(event))
- filename = sprintf("Data/Map%03d.rvdata2", map_id)
- map = load_data(filename)
- new_id = map.events.keys.max + 1
- rawEvent = to_raw_event(event, x, y)
- rawEvent.id = new_id
- map.events[new_id] = rawEvent
- save_data(map, filename)
- end
- def self.to_raw_event(event, x, y)
- event.pages.each do |page|
- # Запишем все проверки условий
- condition = RPG::Event::Page::Condition.new
- condition.switch1_valid = page.condition.switch1_valid
- condition.switch2_valid = page.condition.switch2_valid
- condition.variable_valid = page.condition.variable_valid
- condition.self_switch_valid = page.condition.self_switch_valid
- condition.item_valid = page.condition.item_valid
- condition.actor_valid = page.condition.actor_valid
- condition.switch1_id = page.condition.switch1_id
- condition.switch2_id = page.condition.switch2_id
- condition.variable_id = page.condition.variable_id
- condition.variable_value = page.condition.variable_value
- condition.self_switch_ch = page.condition.self_switch_ch
- condition.item_id = page.condition.item_id
- condition.actor_id = page.condition.actor_id
- page.condition = condition
- # А также пропишем все пути движения в событие
- page.list.each do |cmd|
- if cmd.code == 205
- rawRoute = RPG::MoveRoute.new
- route = cmd.parameters[1]
- rawRoute.repeat = route.repeat
- rawRoute.skippable = route.skippable
- rawRoute.wait = route.wait
- rawRoute.list = route.list
- cmd.parameters[1] = rawRoute
- end
- end
- end
- ev = RPG::Event.new(x, y)
- ev.name = event.name
- ev.pages = event.pages
- return ev
- end
- end
- # Данный класс содержит обёртку (wrapper) всех команд, присутствующих в событиях.
- # Используется классом Event для конвертации скриптов в события.
- class EventCommands
- def initialize(list, indent)
- @indent = indent
- @list = list
- @choices = []
- end
- # Вставляет команду события в список. Пустая команда может быть
- # использована для индикации конца текущей ветки условия или страницы.
- def add_command(code, parameters=[])
- @list.insert(@list.size - 1, RPG::EventCommand.new(code, @indent, parameters))
- end
- #-----------------------------------------------------------------------------
- #
- #-----------------------------------------------------------------------------
- def eval_bool(value)
- return 0 if value.is_a?(TrueClass)
- return 1 if value.is_a?(FalseClass)
- return value
- end
- def process_block(&block)
- EventCommands.new(@list, @indent + 1).instance_eval(&block)
- end
- def process_method(receiver, method_name, *args)
- other_eb = receiver.send(method_name, *args)
- @list.insert(@list.size - 1, *other_eb.list[0...-1])
- end
- def method_missing(m, *args, &block)
- raise "Error in Event Builder: there's no method called `#{m}`"
- end
- #=============================================================================
- # Команды, управляющие сообщениями
- #=============================================================================
- # установка окна сообщений
- def show_text(face_name="", face_index=0, background=0, position=2)
- add_command(101, [face_name, face_index, background, position])
- end
- # добавляет текст в окно сообщений. этот метод должен быть вызван
- # сразу же после метода show_text.
- # заметьте: управляющие символы должы иметь два слеша, чтобы
- # быть правильно отображёнными впоследствии, например
- # "Значение второй переменной - \\v[2]"
- # вы можете добавить несколько строк, каждая из которых станет
- # отдельным сообщением
- def add_message(*strings)
- strings.each {|str| add_command(401, [str]) }
- end
- # добавляет окно выбора
- # choices: array of strings (eg: ["yes", "no"])
- # cancel_option: какой из вариантов будет применен по умолчанию
- # если не выбран ни один из вариантов:
- # 0 = никакой
- # 1 = первый
- # 2 = второй, ...
- # 5 = branch
- def show_choices(choices, cancel_option)
- add_command(102, [choices, cancel_option])
- end
- # Устанавливает проверку выбора из окна выбора,
- # а также действие для каждого из возможных вариантов
- # index: 0 - первый вариант, 1 - второй, 2 - третий и т.д.
- # name: опционально. не имеет смысла, на самом деле
- def choice_branch(index, name="", &block)
- name = @choices[index]
- add_command(402, [index, name])
- process_block(&block)
- end
- # не уверен, может быть, это конец?
- def end_choices
- add_command(404)
- end
- # ввод числа
- def input_number(var_id, digit)
- add_command(103, [var_id, digit])
- end
- # Помещает ID клюевого предмета в выбранную переменную
- def select_key_item(var_id)
- add_command(104, [var_id])
- end
- # отображение прокручивающегося текста
- # string_list: массив строк, которые должны быть отображены
- # speed: скорость прокрутки
- # fast_forward: пользователь может ускорять прокрутку
- def show_scrolling_text(string_list, speed=2, fast_forward=false)
- add_command(105, [speed, fast_forward])
- string_list.each { |str| add_command(405, [str]) }
- end
- #=============================================================================
- # Управление переменными, переключателями и таймером)
- #=============================================================================
- # Пояснение: batch_process, который упоминается ниже - это
- # устанавливает значение переключателя
- # start_var: номер переключателя (при batch_process - номер первого из списка)
- # end_var: при batch_process - номер последнего из списка
- # value: 0 for True, 1 for False
- def control_switches(start_var, end_var, bool)
- value = eval_bool(bool)
- add_command(121, [start_var, end_var, value])
- end
- # start_var: номер переменной (при batch_process - номер первого из списка)
- # end_var: при batch_process - номер последнего из списка
- def control_variables(*args)
- add_command(122, args)
- end
- # устанавливает значение для self-switch
- # id: название свича, который будет измненен. По умолчанию это "A", "B", "C" или "D"
- # bool: 0 = ВКЛ; 1 = ВЫКЛ
- def control_self_switch(id, bool)
- value = eval_bool(bool)
- add_command(123, [id, value])
- end
- # запускает таймер на указанное время
- def start_timer(minutes, seconds)
- add_command(124, [0, minutes * 60 + seconds])
- end
- # останавливает таймер
- def stop_timer
- add_command(124, [1])
- end
- #=============================================================================
- # Команды управления ходом действий
- #=============================================================================
- # Проверка условия, IF. Не слишком дружелюбное, необходимо точно
- # знать, чего вы хотите добиться и как это правильно записать
- # type: ID из встренной хэш-таблицы для проверки условия (пример: switch)
- # args: массив аргументов к заданному условию
- def cond_if(*args, &block)
- # По умолчанию производит проверку условия по скрипту
- #add_command(111, args)
- add_command(111, [12, args[0]])
- process_block(&block)
- end
- # Проверка условия "иначе", ELSE. Требует проверки условия IF.
- def cond_else(&block)
- add_command(411)
- process_block(&block)
- end
- # Обязательно необходимо закрывать ветки проверов.
- def cond_end
- add_command(412)
- end
- # Бесконечный цикл, LOOP
- def loop(&block)
- add_command(112)
- process_block(&block)
- add_command(413)
- end
- # Выход из цикла
- def break_loop
- add_command(113)
- end
- def exit_event
- add_command(115)
- end
- # Вызов общего события
- def call_common_event(common_id)
- add_command(117, [common_id])
- end
- # Установка метки
- def label(str)
- add_command(118, [str])
- end
- # Переход к установленной метке
- def goto_label(str)
- add_command(119, [str])
- end
- # Добавление комментария (для работы дополнительных скриптов, не иначе)
- def add_comment(comment)
- add_command(108, [comment])
- end
- #=============================================================================
- # Команды, связанные с партией
- #=============================================================================
- #-----------------------------------------------------------------------------
- # Command_125: Изменение количества золота
- #-----------------------------------------------------------------------------
- def add_gold(count=1, value_type=0)
- add_command(125, [0, value_type, count])
- end
- def lose_gold(count=1, value_type=0)
- add_command(125, [1, value_type, count])
- end
- #-----------------------------------------------------------------------------
- # Command_126: Добавление/удаление предмета
- # id: номер предмета в базе данных
- # count: количество предметов или номер переменной из $game_variables
- # type: определеяет тип предыдущей переменной.
- # если type = 0, то count - константа
- # если type = 1, то count - номер переменной
- #-----------------------------------------------------------------------------
- def add_item(id, count, type=0)
- add_command(126, [id, 0, type, count])
- end
- def lose_item(id, count, type=0)
- add_command(126, [id, 1, type, count])
- end
- #-----------------------------------------------------------------------------
- # Command_127 and 128: Добавление/удаление оружия и брони
- # id: номер предмета в базе данных
- # count: количество предметов или номер переменной из $game_variables
- # type: определеяет тип предыдущей переменной.
- # если type = 0, то count - константа
- # если type = 1, то count - номер переменной
- # include_equip: используется для удаления надетых оружия или брони
- # (возможен неточный перевод)
- #-----------------------------------------------------------------------------
- def add_weapon(id, count, type, include_equip)
- add_command(127, [id, 0, type, count, include_equip])
- end
- def lose_weapon(id, count, type, include_equip)
- add_command(127, [id, 1, type, count, include_equip])
- end
- def add_armor(id, count, type, include_equip)
- add_command(128, [id, 0, type, count, include_equip])
- end
- def lose_armor(id, count, type, include_equip)
- add_command(128, [id, 1, type, count, include_equip])
- end
- #-----------------------------------------------------------------------------
- # Command_129: Изменение состава партии
- # actor_id: номер актёра из базы данных, которого нужно добавить/удалить
- # initialize: вернуть характеристики персонажа к тем, что в базе данных
- # 0 - нет, 1 - да
- #-----------------------------------------------------------------------------
- def add_actor(actor_id, initialize=0)
- add_command(129, [actor_id, 0, initialize])
- end
- def lose_actor(actor_id, initialize=0)
- add_command(129, [actor_id, 1, initialize])
- end
- # Изменение количества здоровья у всех членов партии разом
- # amount: количество здоровья или же ID переменной, в которой есть это значение
- # value_type: 0 = константа, 1 = значение переменной
- # allow_knockout: возможность убить всех при отрицитальном значении amount
- #
- # operand (3rd element) is always "increase" since the amount can be negative
- def change_party_hp(amount, value_type=0, allow_knockout=false)
- add_command(311, [0, 0, 0, value_type, amount, allow_knockout])
- end
- # аналогично - изменяет количество маны
- def change_party_mp(amount, value_type=0)
- add_command(312, [0, 0, 0, value_type, amount])
- end
- # Накладывает статус на всю партию
- def add_party_state(state_id)
- add_command(313, [0, 0, 0, state_id])
- end
- # Снимает статус со всей партии
- def remove_party_state(state_id)
- add_command(313, [0, 0, 1, state_id])
- end
- #=============================================================================
- # Команды, связанные с актерами
- #=============================================================================
- #=============================================================================
- # Команды, связанные с движением
- #=============================================================================
- # Перемещает игрока на опеределенную карту
- # type: тип телепортации:
- # 0 - в map_id записан точный номер карты, а в x и y - точные координаты
- # 1 - в map_id,x и y записаны номера переменных, в которых есть координаты
- # direction: направление
- # 0 - не менять
- # 2 - вниз
- # 4 - влево
- # 6 - вправо
- # 8 - вверх
- # fadeout: визуальный переход
- # 1 - как обычно (затемнение)
- # 1 - высветление (белый экран)
- # 1 - не использовать перехода вообще
- def transfer_player(type, map_id, x, y, direction=0, fadeout=0)
- add_command(201, [type, map_id, x, y, direction, fadeout])
- end
- # transfers vehicle to a map
- # vehicle: 0 = boat, 1 = ship, 2 = airship
- # type: 0 = direct designation, 1 = variable designation
- def set_vehicle_location(vehicle, type, map_id, x, y)
- add_command(202, [vehicle, type, map_id, x, y])
- end
- # changes the event location
- # type: 0 = direct designation, 1 = variable designation
- def set_event_location(event_id, type, x, y, direction)
- add_command(203, [event_id, type, x, y, direction])
- end
- # swaps event location with another event
- def swap_event_location(event_id, target_event_id, direction)
- set_event_location(event_id, 2, target_event_id, 0, direction)
- end
- def scroll_map(direction, distance, speed=4)
- add_command(204, [direction, distance, speed])
- end
- # event_id: -1 = игрок, 0 = "это событие", 1+ = любое событие,
- # имеющееся на карте
- # move_route: a RPG::MoveRoute (or wrapped Move_Route) object
- def set_move_route(event_id, move_route)
- add_command(205, [event_id, move_route])
- # now add each move route as a separate command just for the editor
- move_route.list.each do |move_cmd|
- add_command(505, [move_cmd])
- end
- end
- # Войти/выйти из транспорта
- def toggle_vehicle
- add_command(206)
- end
- #=============================================================================
- # Команды, связанные с персонажами
- #=============================================================================
- # turn on or off player invisibility
- # bool: 0 = ON, 1 = OF
- def change_transparency(bool)
- value = eval_bool(bool)
- add_command(211, [value])
- end
- # turn on or off followers
- # bool: 0 = ON, 1 = OFF
- def change_followers(bool)
- value = eval_bool(bool)
- add_command(216, [value])
- end
- def gather_followers
- add_command(217)
- end
- def show_animation(animation_id, event_id, wait_completion=true)
- add_command(212, [event_id, animation_id, wait_completion])
- end
- #-----------------------------------------------------------------------------
- # plays balloon animation above character
- # balloon_id: Id of the balloon animation
- # event_id: -1 = player; 0 = this event; 1 or up = specific event
- # wait_completion: true or false
- #-----------------------------------------------------------------------------
- def show_balloon_icon(balloon_id=0, event_id=0, wait_completion=true)
- add_command(213, [event_id, balloon_id, wait_completion])
- end
- def erase
- add_command(214)
- end
- # custom command. Deletes the event permanently.
- def delete
- add_command(214)
- add_command(215)
- end
- #=============================================================================
- # Команды, связанные с эффектами экрана
- #=============================================================================
- def fadeout_screen
- add_command(221)
- end
- def fadein_screen
- add_command(222)
- end
- # tints the screen to the specified color.
- # color is an array of the form (red, green, blue, gray)
- def tint_screen(color, frames, wait_completion=true)
- add_command(223, [Color.new(*color), frames, wait_completion])
- end
- # color is an array of the form (red, green, blue, strength)
- def flash_screen(color, frames, wait_completion=true)
- add_command(224, [Color.new(*color), frames, wait_completion])
- end
- def shake_screen(power, speed, frames, wait_completion=true)
- add_command(225, [power, speed, frames, wait_completion])
- end
- #=============================================================================
- # Команды, связанные со временем
- #=============================================================================
- def wait(frames)
- add_command(230, [frames])
- end
- #=============================================================================
- # Команды, связанные с Изображениями и Погодой
- #=============================================================================
- # Show a picture
- # origin: 0 for upper left, 1 for center
- # coord_type: 0 for constant, 1 for variable designation
- def show_picture(id, name, origin, coord_type, x, y, zoom_x, zoom_y, opacity, blend_type)
- add_command(231, [id, name, origin, coord_type, x, y, zoom_x, zoom_y, opacity, blend_type])
- end
- def move_picture(id, origin, coord_type, x, y, zoom_x, zoom_y, opacity, blend_type, frames=60, wait_complete=true)
- name = $game_screen.pictures[id].name
- add_command(232, [id, name, origin, coord_type, x, y, zoom_x, zoom_y, opacity, blend_type, frames, wait_complete])
- end
- def rotate_picture(id, speed)
- add_command(233, [id, speed])
- end
- def tint_picture(id, color, frames=60, wait_complete=true)
- add_command(234, [id, Color.new(*color), frames, wait_complete])
- end
- def erase_picture(id)
- add_command(235, [id])
- end
- # changes the weather
- # type: one of :none, :rain, :storm, :snow
- def set_weather_effects(type, power, frames=0, wait_complete=false)
- add_command(236, [type, power, frames, wait_complete])
- end
- #=============================================================================
- # Команды, связанные с музыкой и звуком
- #=============================================================================
- def play_bgm(filename, volume=80, pitch=100)
- add_command(241, [RPG::BGM.new(filename, volume, pitch)])
- end
- def fadeout_bgm(seconds)
- add_command(242, [seconds])
- end
- def save_bgm
- add_command(243)
- end
- def replay_bgm
- add_command(244)
- end
- def play_bgs(filename, volume=80, pitch=100)
- add_command(245, [RPG::BGS.new(filename, volume, pitch)])
- end
- def fadeout_bgs(seconds)
- add_command(246, [seconds])
- end
- def play_me(filename, volume=100, pitch=100)
- add_command(249, [RPG::ME.new(filename, volume, pitch)])
- end
- def play_se(filename, volume=80, pitch=100)
- add_command(250, [RPG::SE.new(filename, volume, pitch)])
- end
- def stop_se
- add_command(251)
- end
- #=============================================================================
- # Команды, управляющие сценами
- #=============================================================================
- # id: troop ID or variable ID
- # enc_type: 0 = direct designation, 1 = variable
- def call_battle(id, enc_type=0, can_escape=false, can_lose=false, &block)
- add_command(301, [enc_type, id, can_escape, can_lose])
- if (can_lose || can_escape)
- #hack because call_battle shouldn't be indenting
- @indent -= 1
- process_block(&block)
- # insert 'branch end'
- add_command(604)
- end
- end
- def battle_win(&block)
- add_command(601)
- process_block(&block)
- end
- def battle_lose(&block)
- add_command(603)
- process_block(&block)
- end
- def battle_escape(&block)
- add_command(602)
- process_block(&block)
- end
- # Same as call battle except treated as random encounter
- def random_battle(can_escape=false, can_lose=false)
- call_battle(0, 2, can_escape, can_lose)
- end
- # opens the shop scene
- # item_type: 0 for item, 1 for weapon, 2 for armor
- # id: database ID of the item
- # price_type: 0 for standard, 1 for custom
- # amount: 0 for standard, > 0 for custom
- def call_shop(item_type, id, price_type=0, amount=0, purchase_only=false)
- add_command(302, [item_type, id, price_type, amount, purchase_only])
- end
- # for adding additional items to the shop
- def add_shop_item(item_type, id, price_type, amount)
- add_command(605, [item_type, id, price_type, amount])
- end
- def process_name(actor_id, max_chars)
- add_command(303, [actor_id, max_chars])
- end
- def open_menu_screen
- add_command(351)
- end
- def open_save_screen
- add_command(352)
- end
- def game_over
- add_command(353)
- end
- def return_title
- add_command(354)
- end
- #=============================================================================
- # System Settings commands
- #=============================================================================
- def change_battle_bgm(name, volume=100, pitch=100)
- add_command(132, [RPG::BGM.new(name, volume, pitch)])
- end
- # change battle victory ME
- def change_battle_me(name, volume=80, pitch=100)
- add_command(133, [RPG::ME.new(name, volume, pitch)])
- end
- # enable/disable opening save scene
- def change_save_access(bool)
- value = eval_bool(bool)
- add_command(134, [value])
- end
- # enable/disable opening menu
- def change_menu_access(bool)
- value = eval_bool(bool)
- add_command(135, [value])
- end
- # enable/disable encounters
- def change_encounter(bool)
- value = eval_bool(bool)
- add_command(136, [value])
- end
- # enable/disable formation change
- def change_formation_access(bool)
- value = eval_bool(bool)
- add_command(137, [value])
- end
- # Changes the color of the window.
- def change_window_color(color)
- add_command(138, [Color.new(*color)])
- end
- # change character sprite and face picture
- def change_actor_graphics(actor_id, char_name, char_index, face_name, face_index)
- add_command(322, [actor_id, char_name, index, face_name, face_index])
- end
- # change character sprite
- def change_actor_char(actor_id, char_name, char_index)
- face_name = $game_actors[actor_id].face_name
- face_index = $game_actors[actor_id].face_index
- change_actor_graphics(actor_id, char_name, char_index, face_name, face_index)
- end
- # change face picture
- def change_actor_face(actor_id, face_name, face_index)
- char_name = $game_actors[actor_id].character_name
- char_index = $game_actors[actor_id].character_index
- change_actor_graphics(actor_id, char_name, char_index, face_name, face_index)
- end
- # change vehicle sprite
- # vehicle_id: 0 = boat, 1 = ship, 2 = airship
- def change_vehicle_graphic(vehicle_id, name, index)
- add_command(323, [vehicle_id, name, index])
- end
- #=============================================================================
- # Movie commands
- #=============================================================================
- # play a movie
- def play_move(name)
- add_command(261, [name])
- end
- #=============================================================================
- # Map commands
- #=============================================================================
- # Enable/disable map name display when entering map
- # value: 0 = disable, 1 = enable
- def change_map_name_display(value)
- add_command(281, [value])
- end
- # switch to the specified tileset by ID
- def change_tileset(tileset_id)
- add_command(282, [tileset_id])
- end
- # change the battleback
- def change_battleback(front_name, back_name)
- add_command(283, [front_name, back_name])
- end
- def change_parallax(name, h_loop, v_loop, h_scroll, v_scroll)
- add_command(284, [name, h_loop, v_loop, h_dir, v_dir])
- end
- def get_location_info
- end
- #=============================================================================
- # Battle commands
- #=============================================================================
- #=============================================================================
- # Advanced commands
- #=============================================================================
- def call_script(script)
- add_command(355, [script])
- end
- end
- class MoveCommands
- # note that all move command codes are available in Game_Character
- def initialize(list)
- @list = list
- @northDir = 8 # default "facing up"
- end
- def add_command(code, parameters=[])
- @list.insert(@list.size - 1, RPG::MoveCommand.new(code, parameters))
- end
- def move(string)
- cmds = string.scan(Tsuki::Event_Wrapper::Move_String_Regex)
- cmds.each do |cmd|
- num = cmd[0].empty? ? 1 : cmd[0].to_i rescue 1
- case cmd[1]
- when "U"; code = 4
- when "D"; code = 1
- when "L"; code = 2
- when "R"; code = 3
- when "Q"; code = 7
- when "W"; code = 8
- when "A"; code = 5
- when "S"; code = 6
- end
- num.times do |i|
- add_command(code)
- end
- end
- end
- # compass-direction based movement
- def set_north(direction)
- @northDir = direction
- end
- def move_north(count=1)
- case @northDir
- when 2
- move_down(count)
- when 4
- move_left(count)
- when 6
- move_right(count)
- when 8
- move_up(count)
- end
- end
- def move_west(count=1)
- case @northDir
- when 2
- move_right(count)
- when 4
- move_down(count)
- when 6
- move_up(count)
- when 8
- move_left(count)
- end
- end
- def move_east(count=1)
- case @northDir
- when 2
- move_left(count)
- when 4
- move_up(count)
- when 6
- move_down(count)
- when 8
- move_right(count)
- end
- end
- def move_south(count=1)
- case @northDir
- when 2
- move_up(count)
- when 4
- move_right(count)
- when 6
- move_left(count)
- when 8
- move_down(count)
- end
- end
- def turn_north
- case @northDir
- when 2
- turn_down
- when 4
- turn_left
- when 6
- turn_right
- when 8
- turn_up
- end
- end
- def turn_east
- case @northDir
- when 2
- turn_left
- when 4
- turn_up
- when 6
- turn_down
- when 8
- turn_right
- end
- end
- def turn_west
- case @northDir
- when 2
- turn_right
- when 4
- turn_down
- when 6
- turn_up
- when 8
- turn_left
- end
- end
- def turn_south
- case @northDir
- when 2
- turn_up
- when 4
- turn_right
- when 6
- turn_left
- when 8
- turn_down
- end
- end
- def move_down(count=1)
- count.times { |i| add_command(1) }
- end
- def move_left(count=1)
- count.times { |i| add_command(2) }
- end
- def move_right(count=1)
- count.times { |i| add_command(3) }
- end
- def move_up(count=1)
- count.times { |i| add_command(4) }
- end
- def move_lower_left(count=1)
- count.times { |i| add_command(5) }
- end
- def move_lower_right(count=1)
- count.times { |i| add_command(6) }
- end
- def move_upper_left(count=1)
- count.times { |i| add_command(7) }
- end
- def move_upper_right(count=1)
- count.times { |i| add_command(8) }
- end
- def move_random(count=1)
- count.times { |i| add_command(9) }
- end
- def move_toward_player(count=1)
- count.times { |i| add_command(10) }
- end
- def move_away_from_player(count=1)
- count.times { |i| add_command(11) }
- end
- def step_forward(count=1)
- count.times { |i| add_command(12) }
- end
- def step_backward(count=1)
- count.times { |i| add_command(13) }
- end
- def jump(count=1)
- count.times { |i| add_command(14) }
- end
- def wait(frames)
- add_command(15, [frames])
- end
- def turn_down
- add_command(16)
- end
- def turn_left
- add_command(17)
- end
- def turn_right
- add_command(18)
- end
- def turn_up
- add_command(19)
- end
- def turn90_right(count=1)
- count.times { |i| add_command(20) }
- end
- def turn90_left(count=1)
- count.times { |i| add_command(21) }
- end
- def turn180(count=1)
- count.times { |i| add_command(22) }
- end
- # turn 90 degrees right or left
- def turn90_random(count=1)
- count.times { |i| add_command(23) }
- end
- def turn_random(count=1)
- count.times { |i| add_command(24) }
- end
- def turn_toward_player
- add_command(25)
- end
- def turn_away_from_player
- add_command(26)
- end
- def change_switch(id, value)
- value == 0 ? add_command(27, [id]) : add_command(28, [id])
- end
- def change_speed(number)
- add_command(29, [number])
- end
- def change_freq(number)
- add_command(30, [number])
- end
- # value: 0 = ON, 1 = OFF
- def walk_anim(value)
- value == 0 ? add_command(31) : add_command(32)
- end
- # value: 0 = ON, 1 = OFF
- def step_anim(value)
- value == 0 ? add_command(33) : add_command(34)
- end
- # value: 0 = ON, 1 = OFF
- def direction_fix(value)
- value == 0 ? add_command(35) : add_command(36)
- end
- # value: 0 = ON, 1 = OFF
- def through(value)
- value == 0 ? add_command(37) : add_command(38)
- end
- # value: 0 = ON, 1 = OFF
- def transparent(value)
- value == 0 ? add_command(39) : add_command(40)
- end
- def change_graphic(name, index)
- add_command(41, [name, index])
- end
- def change_opacity(value)
- add_command(42, [value])
- end
- def change_blending(value)
- add_command(43, [value])
- end
- def play_se(name, volume=80, pitch=100)
- add_command(44, [RPG::SE.new(name, volume, pitch)])
- end
- def call_script(string)
- add_command(45, [string])
- end
- end
- # This is a wrapper for RPG::MoveRoute. It provides methods that allow you
- # to create move routes easily
- class MoveRoute < RPG::MoveRoute
- # Instance Variables
- # repeat
- # skippable
- # wait
- # list
- def initialize
- super
- @repeat = false
- @skippable = true
- end
- def build(&block)
- MoveCommands.new(@list).instance_eval(&block)
- end
- end
- # This is a standalone event builder. It returns an event command list
- # which you can then assign to an event to use. This allows you to
- # write re-usable event creation methods
- class EventBuilder
- attr_reader :list
- # this is preferred, since you can actually pass around a builder
- def initialize(list=nil, &block)
- @list = list || [RPG::EventCommand.new]
- @indent = 0
- EventCommands.new(@list, @indent).instance_eval(&block)
- end
- # if you just need to quickly build something
- def self.build(list=nil, &block)
- @list = list || [RPG::EventCommand.new]
- @indent = 0
- EventCommands.new(@list, @indent).instance_eval(&block)
- return @list
- end
- end
- # This is a wrapper for RPG::Event. It provides methods that allow you to
- # create event commands the way you would do it with the editor
- class Event < RPG::Event
- attr_reader :condition
- attr_reader :graphic
- attr_reader :list
- def initialize(x=0, y=0)
- super
- @page = @pages[0] = create_page
- @condition = @page.condition = Event_Condition.new
- @graphic = @page.graphic
- @list = @page.list
- @indent = 0
- end
- # change the current page.
- def set_page(page_number)
- @page = @pages[page_number] ||= create_page
- @condition = @page.condition
- @graphic = @page.graphic
- @list = @page.list
- end
- # create a new page, set some defaults
- def create_page
- page = RPG::Event::Page.new
- page.condition = Event_Condition.new
- page.priority_type = 1
- return page
- end
- # A builder method that recursively evaluates a block of commands
- # and creates the appropriate RPG::EventCommand objects.
- def build(&block)
- #@orig_block = block
- EventCommands.new(@list, @indent).instance_eval(&block)
- end
- # rebuilds all of the event's pages
- def rebuild
- # Not supported atm since proc's cannot be lambda'd
- #EventCommands.new(@list, @indent).instance_eval(&@orig_block)
- end
- #=============================================================================
- # Event page property related methods.
- #=============================================================================
- # set the event command list with the given list
- def list=(list)
- @page.list = list
- end
- def move_type=(type)
- @page.move_type = type
- end
- def move_speed=(speed)
- @page.move_speed = speed
- end
- def move_frequency=(freq)
- @page.move_frequency = freq
- end
- def move_route=(route)
- @page.move_route = route
- end
- def walk_anime=(bool)
- @page.walk_anime = bool
- end
- def step_anime=(bool)
- @page.step_anime = bool
- end
- def direction_fix=(bool)
- @page.direction_fix = bool
- end
- def through=(bool)
- @page.through = bool
- end
- # The priority type
- # 0: below characters
- # 1: same as characters
- # 2: above characters
- def priority_type=(type)
- @page.priority_type = type
- end
- # The event trigger
- # 0: action button
- # 1: player touch
- # 2: event touch
- # 3: autorun
- # 4: parallel
- def trigger=(trigger_id)
- @page.trigger = trigger_id
- end
- #=============================================================================
- # Event graphic related methods. Same as accessing
- # event.pages[page_num].graphic
- #=============================================================================
- def tile_id=(id)
- @graphic.tile_id = id
- end
- def direction=(dir)
- @graphic.direction = dir
- end
- def pattern=(index)
- @graphic.pattern = index
- end
- def character_name=(name)
- @graphic.character_name = name
- end
- def character_index=(index)
- @graphic.character_index = index
- end
- end
- class Event_Condition < RPG::Event::Page::Condition
- #=============================================================================
- # Event conditions related methods. If a condition is specified then
- # it is automatically valid
- #=============================================================================
- def switch1_id=(switch_id)
- @switch1_valid = true
- @switch1_id = switch_id
- end
- def switch2_id=(switch_id)
- @switch2_valid = true
- @switch2_id = switch_id
- end
- def variable_cond=(var_id, value)
- @variable_valid = true
- @variable_id = var_id
- @variable_value = value
- end
- def self_switch=(letter)
- @self_switch_valid = true
- @self_switch_ch = letter
- end
- def item_id=(id)
- @item_valid = true
- @item_id = id
- end
- def actor_id=(id)
- @actor_valid = true
- @actor_id = id
- end
- end
- # Сторонние события, созданные скриптами, не сохраняются в данных карты
- # (файлах с именем MapXXX.rvdata2), поэтому мы копируем их
- # в модуль Game_System, чтобы они не потерялись при переходе с карты на карту
- class Game_System
- def init_custom_events(map_id)
- @custom_events = {} if @custom_events.nil?
- @custom_events[map_id] = {} if @custom_events[map_id].nil?
- end
- def add_custom_event(map_id, event)
- init_custom_events(map_id)
- @custom_events[map_id][event.id] = event
- SceneManager.scene.refresh_spriteset if SceneManager.scene_is?(Scene_Map)
- $game_temp.queue_event(event)
- end
- def remove_custom_event(map_id, event_id)
- init_custom_events(map_id)
- @custom_events[map_id].delete(event_id)
- SceneManager.scene.refresh_spriteset if SceneManager.scene_is?(Scene_Map)
- end
- def clear_custom_events(map_id)
- init_custom_events(map_id)
- @custom_events[map_id] = {}
- SceneManager.scene.refresh_spriteset if SceneManager.scene_is?(Scene_Map)
- end
- def get_custom_events(map_id)
- init_custom_events(map_id)
- return @custom_events[map_id]
- SceneManager.scene.refresh_spriteset if SceneManager.scene_is?(Scene_Map)
- end
- end
- class Game_Temp
- attr_reader :queued_add_events
- alias :th_event_wrapper_initialize :initialize
- def initialize
- th_event_wrapper_initialize
- clear_queued_events
- end
- def queue_event(event)
- @queued_add_events[event.id] = event
- end
- def clear_queued_events
- @queued_add_events = {}
- end
- end
- class Game_Map
- alias :th_event_wrapper_setup_events :setup_events
- def setup_events
- th_event_wrapper_setup_events
- $game_system.get_custom_events(@map_id).each {|i, event|
- @events[i] = Game_Event.new(@map_id, event)
- }
- end
- alias :th_event_wrapper_update_events :update_events
- def update_events
- th_event_wrapper_update_events
- add_queued_events
- end
- def add_event(event)
- return unless event
- puts "event valid"
- # Находим доступный номер для ивента
- if $game_temp.queued_add_events.empty?
- index = @events.empty? ? 1 : @events.keys.max + 1
- else
- index = $game_temp.queued_add_events.keys.max + 1
- end
- event.id = index
- # Сохраняем его в $game_system, так как он не привязан к карте
- $game_system.add_custom_event(@map_id, event)
- # Правка из версии от 10.6.12
- @events[index] = Game_Event.new(@map_id, event)
- SceneManager.scene.refresh_spriteset if SceneManager.scene_is?(Scene_Map)
- end
- def remove_event(event_id, map_id=$game_map.map_id)
- @events.delete(event_id)
- $game_system.remove_custom_event(map_id, event_id)
- end
- #-----------------------------------------------------------------------------
- # В этом методе находятся все события, которые должны быть добавлены
- #-----------------------------------------------------------------------------
- def add_queued_events
- events = $game_temp.queued_add_events
- return if events.empty?
- events.each do |index, ev|
- @events[index] = Game_Event.new(@map_id, ev)
- end
- events.clear
- SceneManager.scene.refresh_spriteset if SceneManager.scene_is?(Scene_Map)
- end
- end
- class Scene_Map
- def refresh_spriteset
- @spriteset.refresh_characters
- end
- end
- class Game_Interpreter
- def command_215
- map_id = $game_map.map_id # bad implementation
- $game_system.remove_custom_event(map_id, @event_id)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement