mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2026-03-17 05:31:05 +00:00
game data
This commit is contained in:
398
Data/Scripts_backup/001_Settings.rb
Normal file
398
Data/Scripts_backup/001_Settings.rb
Normal file
@@ -0,0 +1,398 @@
|
||||
#==============================================================================#
|
||||
# Pokémon Essentials #
|
||||
# Version 19.1.dev #
|
||||
# https://github.com/Maruno17/pokemon-essentials #
|
||||
#==============================================================================#
|
||||
|
||||
module Settings
|
||||
# The version of your game. It has to adhere to the MAJOR.MINOR.PATCH format.
|
||||
GAME_VERSION = '1.0.0'
|
||||
|
||||
# The generation that the battle system follows. Used throughout the battle
|
||||
# scripts, and also by some other settings which are used in and out of battle
|
||||
# (you can of course change those settings to suit your game).
|
||||
# Note that this isn't perfect. Essentials doesn't accurately replicate every
|
||||
# single generation's mechanics. It's considered to be good enough. Only
|
||||
# generations 5 and later are reasonably supported.
|
||||
MECHANICS_GENERATION = 7
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# The default screen width (at a scale of 1.0).
|
||||
SCREEN_WIDTH = 512
|
||||
# The default screen height (at a scale of 1.0).
|
||||
SCREEN_HEIGHT = 384
|
||||
# The default screen scale factor. Possible values are 0.5, 1.0, 1.5 and 2.0.
|
||||
SCREEN_SCALE = 1.0
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# The maximum level Pokémon can reach.
|
||||
MAXIMUM_LEVEL = 100
|
||||
# The level of newly hatched Pokémon.
|
||||
EGG_LEVEL = 1
|
||||
# The odds of a newly generated Pokémon being shiny (out of 65536).
|
||||
SHINY_POKEMON_CHANCE = (MECHANICS_GENERATION >= 6) ? 16 : 8
|
||||
# The odds of a wild Pokémon/bred egg having Pokérus (out of 65536).
|
||||
POKERUS_CHANCE = 3
|
||||
# Whether a bred baby Pokémon can inherit any TM/HM moves from its father. It
|
||||
# can never inherit TM/HM moves from its mother.
|
||||
BREEDING_CAN_INHERIT_MACHINE_MOVES = (MECHANICS_GENERATION <= 5)
|
||||
# Whether a bred baby Pokémon can inherit egg moves from its mother. It can
|
||||
# always inherit egg moves from its father.
|
||||
BREEDING_CAN_INHERIT_EGG_MOVES_FROM_MOTHER = (MECHANICS_GENERATION >= 6)
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# The amount of money the player starts the game with.
|
||||
INITIAL_MONEY = 3000
|
||||
# The maximum amount of money the player can have.
|
||||
MAX_MONEY = 999_999
|
||||
# The maximum number of Game Corner coins the player can have.
|
||||
MAX_COINS = 99_999
|
||||
# The maximum number of Battle Points the player can have.
|
||||
MAX_BATTLE_POINTS = 9_999
|
||||
# The maximum amount of soot the player can have.
|
||||
MAX_SOOT = 9_999
|
||||
# The maximum length, in characters, that the player's name can be.
|
||||
MAX_PLAYER_NAME_SIZE = 10
|
||||
# The maximum number of Pokémon that can be in the party.
|
||||
MAX_PARTY_SIZE = 6
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# A set of arrays each containing a trainer type followed by a Global Variable
|
||||
# number. If the variable isn't set to 0, then all trainers with the
|
||||
# associated trainer type will be named as whatever is in that variable.
|
||||
RIVAL_NAMES = [
|
||||
[:RIVAL1, 12],
|
||||
[:RIVAL2, 12],
|
||||
[:CHAMPION, 12]
|
||||
]
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# Whether outdoor maps should be shaded according to the time of day.
|
||||
TIME_SHADING = true
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# Whether poisoned Pokémon will lose HP while walking around in the field.
|
||||
POISON_IN_FIELD = (MECHANICS_GENERATION <= 4)
|
||||
# Whether poisoned Pokémon will faint while walking around in the field
|
||||
# (true), or survive the poisoning with 1 HP (false).
|
||||
POISON_FAINT_IN_FIELD = (MECHANICS_GENERATION <= 3)
|
||||
# Whether planted berries grow according to Gen 4 mechanics (true) or Gen 3
|
||||
# mechanics (false).
|
||||
NEW_BERRY_PLANTS = (MECHANICS_GENERATION >= 4)
|
||||
# Whether fishing automatically hooks the Pokémon (true), or whether there is
|
||||
# a reaction test first (false).
|
||||
FISHING_AUTO_HOOK = false
|
||||
# The ID of the common event that runs when the player starts fishing (runs
|
||||
# instead of showing the casting animation).
|
||||
FISHING_BEGIN_COMMON_EVENT = -1
|
||||
# The ID of the common event that runs when the player stops fishing (runs
|
||||
# instead of showing the reeling in animation).
|
||||
FISHING_END_COMMON_EVENT = -1
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# The number of steps allowed before a Safari Zone game is over (0=infinite).
|
||||
SAFARI_STEPS = 600
|
||||
# The number of seconds a Bug Catching Contest lasts for (0=infinite).
|
||||
BUG_CONTEST_TIME = 20 * 60 # 20 minutes
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# Pairs of map IDs, where the location signpost isn't shown when moving from
|
||||
# one of the maps in a pair to the other (and vice versa). Useful for single
|
||||
# long routes/towns that are spread over multiple maps.
|
||||
# e.g. [4,5,16,17,42,43] will be map pairs 4,5 and 16,17 and 42,43.
|
||||
# Moving between two maps that have the exact same name won't show the
|
||||
# location signpost anyway, so you don't need to list those maps here.
|
||||
NO_SIGNPOSTS = []
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# Whether you need at least a certain number of badges to use some hidden
|
||||
# moves in the field (true), or whether you need one specific badge to use
|
||||
# them (false). The amounts/specific badges are defined below.
|
||||
FIELD_MOVES_COUNT_BADGES = true
|
||||
# Depending on FIELD_MOVES_COUNT_BADGES, either the number of badges required
|
||||
# to use each hidden move in the field, or the specific badge number required
|
||||
# to use each move. Remember that badge 0 is the first badge, badge 1 is the
|
||||
# second badge, etc.
|
||||
# e.g. To require the second badge, put false and 1.
|
||||
# To require at least 2 badges, put true and 2.
|
||||
BADGE_FOR_CUT = 1
|
||||
BADGE_FOR_FLASH = 2
|
||||
BADGE_FOR_ROCKSMASH = 3
|
||||
BADGE_FOR_SURF = 4
|
||||
BADGE_FOR_FLY = 5
|
||||
BADGE_FOR_STRENGTH = 6
|
||||
BADGE_FOR_DIVE = 7
|
||||
BADGE_FOR_WATERFALL = 8
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# If a move taught by a TM/HM/TR replaces another move, this setting is
|
||||
# whether the machine's move retains the replaced move's PP (true), or whether
|
||||
# the machine's move has full PP (false).
|
||||
TAUGHT_MACHINES_KEEP_OLD_PP = (MECHANICS_GENERATION == 5)
|
||||
# Whether the Black/White Flutes will raise/lower the levels of wild Pokémon
|
||||
# respectively (true), or will lower/raise the wild encounter rate
|
||||
# respectively (false).
|
||||
FLUTES_CHANGE_WILD_ENCOUNTER_LEVELS = (MECHANICS_GENERATION >= 6)
|
||||
# Whether Repel uses the level of the first Pokémon in the party regardless of
|
||||
# its HP (true), or it uses the level of the first unfainted Pokémon (false).
|
||||
REPEL_COUNTS_FAINTED_POKEMON = (MECHANICS_GENERATION >= 6)
|
||||
# Whether Rage Candy Bar acts as a Full Heal (true) or a Potion (false).
|
||||
RAGE_CANDY_BAR_CURES_STATUS_PROBLEMS = (MECHANICS_GENERATION >= 7)
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# The name of the person who created the Pokémon storage system.
|
||||
def self.storage_creator_name
|
||||
return _INTL("Bill")
|
||||
end
|
||||
# The number of boxes in Pokémon storage.
|
||||
NUM_STORAGE_BOXES = 30
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# The names of each pocket of the Bag. Ignore the first entry ("").
|
||||
def self.bag_pocket_names
|
||||
return ["",
|
||||
_INTL("Items"),
|
||||
_INTL("Medicine"),
|
||||
_INTL("Poké Balls"),
|
||||
_INTL("TMs & HMs"),
|
||||
_INTL("Berries"),
|
||||
_INTL("Mail"),
|
||||
_INTL("Battle Items"),
|
||||
_INTL("Key Items")
|
||||
]
|
||||
end
|
||||
# The maximum number of slots per pocket (-1 means infinite number). Ignore
|
||||
# the first number (0).
|
||||
BAG_MAX_POCKET_SIZE = [0, -1, -1, -1, -1, -1, -1, -1, -1]
|
||||
# The maximum number of items each slot in the Bag can hold.
|
||||
BAG_MAX_PER_SLOT = 999
|
||||
# Whether each pocket in turn auto-sorts itself by item ID number. Ignore the
|
||||
# first entry (the 0).
|
||||
BAG_POCKET_AUTO_SORT = [0, false, false, false, true, true, false, false, false]
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# Whether the Pokédex list shown is the one for the player's current region
|
||||
# (true), or whether a menu pops up for the player to manually choose which
|
||||
# Dex list to view if more than one is available (false).
|
||||
USE_CURRENT_REGION_DEX = false
|
||||
# The names of the Pokédex lists, in the order they are defined in the PBS
|
||||
# file "regionaldexes.txt". The last name is for the National Dex and is added
|
||||
# onto the end of this array (remember that you don't need to use it). This
|
||||
# array's order is also the order of $Trainer.pokedex.unlocked_dexes, which
|
||||
# records which Dexes have been unlocked (the first is unlocked by default).
|
||||
# If an entry is just a name, then the region map shown in the Area page while
|
||||
# viewing that Dex list will be the region map of the region the player is
|
||||
# currently in. The National Dex entry should always behave like this.
|
||||
# If an entry is of the form [name, number], then the number is a region
|
||||
# number. That region's map will appear in the Area page while viewing that
|
||||
# Dex list, no matter which region the player is currently in.
|
||||
def self.pokedex_names
|
||||
return [
|
||||
[_INTL("Kanto Pokédex"), 0],
|
||||
[_INTL("Johto Pokédex"), 1],
|
||||
_INTL("National Pokédex")
|
||||
]
|
||||
end
|
||||
# Whether all forms of a given species will be immediately available to view
|
||||
# in the Pokédex so long as that species has been seen at all (true), or
|
||||
# whether each form needs to be seen specifically before that form appears in
|
||||
# the Pokédex (false).
|
||||
DEX_SHOWS_ALL_FORMS = false
|
||||
# An array of numbers, where each number is that of a Dex list (in the same
|
||||
# order as above, except the National Dex is -1). All Dex lists included here
|
||||
# will begin their numbering at 0 rather than 1 (e.g. Victini in Unova's Dex).
|
||||
DEXES_WITH_OFFSETS = []
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# A set of arrays, each containing details of a graphic to be shown on the
|
||||
# region map if appropriate. The values for each array are as follows:
|
||||
# * Region number.
|
||||
# * Game Switch; the graphic is shown if this is ON (non-wall maps only).
|
||||
# * X coordinate of the graphic on the map, in squares.
|
||||
# * Y coordinate of the graphic on the map, in squares.
|
||||
# * Name of the graphic, found in the Graphics/Pictures folder.
|
||||
# * The graphic will always (true) or never (false) be shown on a wall map.
|
||||
REGION_MAP_EXTRAS = [
|
||||
[0, 51, 16, 15, "mapHiddenBerth", false],
|
||||
[0, 52, 20, 14, "mapHiddenFaraday", false]
|
||||
]
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# A list of maps used by roaming Pokémon. Each map has an array of other maps
|
||||
# it can lead to.
|
||||
ROAMING_AREAS = {
|
||||
5 => [ 21, 28, 31, 39, 41, 44, 47, 66, 69],
|
||||
21 => [5, 28, 31, 39, 41, 44, 47, 66, 69],
|
||||
28 => [5, 21, 31, 39, 41, 44, 47, 66, 69],
|
||||
31 => [5, 21, 28, 39, 41, 44, 47, 66, 69],
|
||||
39 => [5, 21, 28, 31, 41, 44, 47, 66, 69],
|
||||
41 => [5, 21, 28, 31, 39, 44, 47, 66, 69],
|
||||
44 => [5, 21, 28, 31, 39, 41, 47, 66, 69],
|
||||
47 => [5, 21, 28, 31, 39, 41, 44, 66, 69],
|
||||
66 => [5, 21, 28, 31, 39, 41, 44, 47, 69],
|
||||
69 => [5, 21, 28, 31, 39, 41, 44, 47, 66 ]
|
||||
}
|
||||
# A set of arrays, each containing the details of a roaming Pokémon. The
|
||||
# information within each array is as follows:
|
||||
# * Species.
|
||||
# * Level.
|
||||
# * Game Switch; the Pokémon roams while this is ON.
|
||||
# * Encounter type (0=any, 1=grass/walking in cave, 2=surfing, 3=fishing,
|
||||
# 4=surfing/fishing). See the bottom of PField_RoamingPokemon for lists.
|
||||
# * Name of BGM to play for that encounter (optional).
|
||||
# * Roaming areas specifically for this Pokémon (optional).
|
||||
ROAMING_SPECIES = [
|
||||
[:LATIAS, 30, 53, 0, "Battle roaming"],
|
||||
[:LATIOS, 30, 53, 0, "Battle roaming"],
|
||||
[:KYOGRE, 40, 54, 2, nil, {
|
||||
2 => [ 21, 31 ],
|
||||
21 => [2, 31, 69],
|
||||
31 => [2, 21, 69],
|
||||
69 => [ 21, 31 ]
|
||||
}],
|
||||
[:ENTEI, 40, 55, 1, nil]
|
||||
]
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# A set of arrays, each containing the details of a wild encounter that can
|
||||
# only occur via using the Poké Radar. The information within each array is as
|
||||
# follows:
|
||||
# * Map ID on which this encounter can occur.
|
||||
# * Probability that this encounter will occur (as a percentage).
|
||||
# * Species.
|
||||
# * Minimum possible level.
|
||||
# * Maximum possible level (optional).
|
||||
POKE_RADAR_ENCOUNTERS = [
|
||||
[5, 20, :STARLY, 12, 15],
|
||||
[21, 10, :STANTLER, 14],
|
||||
[28, 20, :BUTTERFREE, 15, 18],
|
||||
[28, 20, :BEEDRILL, 15, 18]
|
||||
]
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# The Game Switch that is set to ON when the player blacks out.
|
||||
STARTING_OVER_SWITCH = 1
|
||||
# The Game Switch that is set to ON when the player has seen Pokérus in the
|
||||
# Poké Center (and doesn't need to be told about it again).
|
||||
SEEN_POKERUS_SWITCH = 2
|
||||
# The Game Switch which, while ON, makes all wild Pokémon created be shiny.
|
||||
SHINY_WILD_POKEMON_SWITCH = 31
|
||||
# The Game Switch which, while ON, makes all Pokémon created considered to be
|
||||
# met via a fateful encounter.
|
||||
FATEFUL_ENCOUNTER_SWITCH = 32
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# ID of the animation played when the player steps on grass (grass rustling).
|
||||
GRASS_ANIMATION_ID = 1
|
||||
# ID of the animation played when the player lands on the ground after hopping
|
||||
# over a ledge (shows a dust impact).
|
||||
DUST_ANIMATION_ID = 2
|
||||
# ID of the animation played when a trainer notices the player (an exclamation
|
||||
# bubble).
|
||||
EXCLAMATION_ANIMATION_ID = 3
|
||||
# ID of the animation played when a patch of grass rustles due to using the
|
||||
# Poké Radar.
|
||||
RUSTLE_NORMAL_ANIMATION_ID = 1
|
||||
# ID of the animation played when a patch of grass rustles vigorously due to
|
||||
# using the Poké Radar. (Rarer species)
|
||||
RUSTLE_VIGOROUS_ANIMATION_ID = 5
|
||||
# ID of the animation played when a patch of grass rustles and shines due to
|
||||
# using the Poké Radar. (Shiny encounter)
|
||||
RUSTLE_SHINY_ANIMATION_ID = 6
|
||||
# ID of the animation played when a berry tree grows a stage while the player
|
||||
# is on the map (for new plant growth mechanics only).
|
||||
PLANT_SPARKLE_ANIMATION_ID = 7
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# An array of available languages in the game, and their corresponding message
|
||||
# file in the Data folder. Edit only if you have 2 or more languages to choose
|
||||
# from.
|
||||
LANGUAGES = [
|
||||
# ["English", "english.dat"],
|
||||
# ["Deutsch", "deutsch.dat"]
|
||||
]
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# Available speech frames. These are graphic files in "Graphics/Windowskins/".
|
||||
SPEECH_WINDOWSKINS = [
|
||||
"speech hgss 1",
|
||||
"speech hgss 2",
|
||||
"speech hgss 3",
|
||||
"speech hgss 4",
|
||||
"speech hgss 5",
|
||||
"speech hgss 6",
|
||||
"speech hgss 7",
|
||||
"speech hgss 8",
|
||||
"speech hgss 9",
|
||||
"speech hgss 10",
|
||||
"speech hgss 11",
|
||||
"speech hgss 12",
|
||||
"speech hgss 13",
|
||||
"speech hgss 14",
|
||||
"speech hgss 15",
|
||||
"speech hgss 16",
|
||||
"speech hgss 17",
|
||||
"speech hgss 18",
|
||||
"speech hgss 19",
|
||||
"speech hgss 20",
|
||||
"speech pl 18"
|
||||
]
|
||||
|
||||
# Available menu frames. These are graphic files in "Graphics/Windowskins/".
|
||||
MENU_WINDOWSKINS = [
|
||||
"choice 1",
|
||||
"choice 2",
|
||||
"choice 3",
|
||||
"choice 4",
|
||||
"choice 5",
|
||||
"choice 6",
|
||||
"choice 7",
|
||||
"choice 8",
|
||||
"choice 9",
|
||||
"choice 10",
|
||||
"choice 11",
|
||||
"choice 12",
|
||||
"choice 13",
|
||||
"choice 14",
|
||||
"choice 15",
|
||||
"choice 16",
|
||||
"choice 17",
|
||||
"choice 18",
|
||||
"choice 19",
|
||||
"choice 20",
|
||||
"choice 21",
|
||||
"choice 22",
|
||||
"choice 23",
|
||||
"choice 24",
|
||||
"choice 25",
|
||||
"choice 26",
|
||||
"choice 27",
|
||||
"choice 28"
|
||||
]
|
||||
end
|
||||
|
||||
# DO NOT EDIT THESE!
|
||||
module Essentials
|
||||
VERSION = "19.1.dev"
|
||||
ERROR_TEXT = ""
|
||||
end
|
||||
@@ -0,0 +1,40 @@
|
||||
module PBDebug
|
||||
@@log = []
|
||||
|
||||
def self.logonerr
|
||||
begin
|
||||
yield
|
||||
rescue
|
||||
PBDebug.log("")
|
||||
PBDebug.log("**Exception: #{$!.message}")
|
||||
PBDebug.log("#{$!.backtrace.inspect}")
|
||||
PBDebug.log("")
|
||||
# if $INTERNAL
|
||||
pbPrintException($!)
|
||||
# end
|
||||
PBDebug.flush
|
||||
end
|
||||
end
|
||||
|
||||
def self.flush
|
||||
if $DEBUG && $INTERNAL && @@log.length>0
|
||||
File.open("Data/debuglog.txt", "a+b") { |f| f.write("#{@@log}") }
|
||||
end
|
||||
@@log.clear
|
||||
end
|
||||
|
||||
def self.log(msg)
|
||||
if $DEBUG && $INTERNAL
|
||||
@@log.push("#{msg}\r\n")
|
||||
# if @@log.length>1024
|
||||
PBDebug.flush
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
def self.dump(msg)
|
||||
if $DEBUG && $INTERNAL
|
||||
File.open("Data/dumplog.txt", "a+b") { |f| f.write("#{msg}\r\n") }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,51 @@
|
||||
# To use the console, use the executable explicitly built
|
||||
# with the console enabled on Windows. On Linux and macOS,
|
||||
# just launch the executable directly from a terminal.
|
||||
module Console
|
||||
def self.setup_console
|
||||
return unless $DEBUG
|
||||
echoln "--------------------------------"
|
||||
echoln "#{System.game_title} Output Window"
|
||||
echoln "--------------------------------"
|
||||
echoln "If you are seeing this window, you are running"
|
||||
echoln "#{System.game_title} in Debug Mode. This means"
|
||||
echoln "that you're either playing a Debug Version, or"
|
||||
echoln "you are playing from within RPG Maker XP."
|
||||
echoln ""
|
||||
echoln "Closing this window will close the game. If"
|
||||
echoln "you want to get rid of this window, run the"
|
||||
echoln "program from the Shell, or download a Release"
|
||||
echoln "version."
|
||||
echoln ""
|
||||
echoln "--------------------------------"
|
||||
echoln "Debug Output:"
|
||||
echoln "--------------------------------"
|
||||
echoln ""
|
||||
end
|
||||
|
||||
def self.readInput
|
||||
return gets.strip
|
||||
end
|
||||
|
||||
def self.readInput2
|
||||
return self.readInput
|
||||
end
|
||||
|
||||
def self.get_input
|
||||
echo self.readInput2
|
||||
end
|
||||
end
|
||||
|
||||
module Kernel
|
||||
def echo(string)
|
||||
return unless $DEBUG
|
||||
printf(string.is_a?(String) ? string : string.inspect)
|
||||
end
|
||||
|
||||
def echoln(string)
|
||||
echo(string)
|
||||
echo("\r\n")
|
||||
end
|
||||
end
|
||||
|
||||
Console.setup_console
|
||||
@@ -0,0 +1,85 @@
|
||||
#===============================================================================
|
||||
# Exceptions and critical code
|
||||
#===============================================================================
|
||||
class Reset < Exception
|
||||
end
|
||||
|
||||
def pbGetExceptionMessage(e,_script="")
|
||||
emessage = e.message.dup
|
||||
emessage.force_encoding(Encoding::UTF_8)
|
||||
if e.is_a?(Hangup)
|
||||
emessage = "The script is taking too long. The game will restart."
|
||||
elsif e.is_a?(Errno::ENOENT)
|
||||
filename = emessage.sub("No such file or directory - ", "")
|
||||
emessage = "File #{filename} not found."
|
||||
end
|
||||
emessage.gsub!(/Section(\d+)/) { $RGSS_SCRIPTS[$1.to_i][1] } rescue nil
|
||||
return emessage
|
||||
end
|
||||
|
||||
def pbPrintException(e)
|
||||
emessage = ""
|
||||
if $EVENTHANGUPMSG && $EVENTHANGUPMSG!=""
|
||||
emessage = $EVENTHANGUPMSG # Message with map/event ID generated elsewhere
|
||||
$EVENTHANGUPMSG = nil
|
||||
else
|
||||
emessage = pbGetExceptionMessage(e)
|
||||
end
|
||||
# begin message formatting
|
||||
message = "[Pokémon Essentials version #{Essentials::VERSION}]\r\n"
|
||||
message += "#{Essentials::ERROR_TEXT}\r\n" # For third party scripts to add to
|
||||
message += "Exception: #{e.class}\r\n"
|
||||
message += "Message: #{emessage}\r\n"
|
||||
# show last 10/25 lines of backtrace
|
||||
message += "\r\nBacktrace:\r\n"
|
||||
btrace = ""
|
||||
if e.backtrace
|
||||
maxlength = ($INTERNAL) ? 25 : 10
|
||||
e.backtrace[0, maxlength].each { |i| btrace += "#{i}\r\n" }
|
||||
end
|
||||
btrace.gsub!(/Section(\d+)/) { $RGSS_SCRIPTS[$1.to_i][1] } rescue nil
|
||||
message += btrace
|
||||
# output to log
|
||||
errorlog = "errorlog.txt"
|
||||
errorlog = RTP.getSaveFileName("errorlog.txt") if (Object.const_defined?(:RTP) rescue false)
|
||||
File.open(errorlog, "ab") do |f|
|
||||
f.write("\r\n=================\r\n\r\n[#{Time.now}]\r\n")
|
||||
f.write(message)
|
||||
end
|
||||
# format/censor the error log directory
|
||||
errorlogline = errorlog.gsub("/", "\\")
|
||||
errorlogline.sub!(Dir.pwd + "\\", "")
|
||||
errorlogline.sub!(pbGetUserName, "USERNAME")
|
||||
errorlogline = "\r\n" + errorlogline if errorlogline.length > 20
|
||||
# output message
|
||||
print("#{message}\r\nThis exception was logged in #{errorlogline}.\r\nHold Ctrl when closing this message to copy it to the clipboard.")
|
||||
# Give a ~500ms coyote time to start holding Control
|
||||
t = System.delta
|
||||
until (System.delta - t) >= 500000
|
||||
Input.update
|
||||
if Input.press?(Input::CTRL)
|
||||
Input.clipboard = message
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def pbCriticalCode
|
||||
ret = 0
|
||||
begin
|
||||
yield
|
||||
ret = 1
|
||||
rescue Exception
|
||||
e = $!
|
||||
if e.is_a?(Reset) || e.is_a?(SystemExit)
|
||||
raise
|
||||
else
|
||||
pbPrintException(e)
|
||||
if e.is_a?(Hangup)
|
||||
ret = 2
|
||||
raise Reset.new
|
||||
end
|
||||
end
|
||||
end
|
||||
return ret
|
||||
end
|
||||
@@ -0,0 +1,31 @@
|
||||
# The Kernel module is extended to include the validate method.
|
||||
module Kernel
|
||||
private
|
||||
|
||||
# Used to check whether method arguments are of a given class or respond to a method.
|
||||
# @param value_pairs [Hash{Object => Class, Array<Class>, Symbol}] value pairs to validate
|
||||
# @example Validate a class or method
|
||||
# validate foo => Integer, baz => :to_s # raises an error if foo is not an Integer or if baz doesn't implement #to_s
|
||||
# @example Validate a class from an array
|
||||
# validate foo => [Sprite, Bitmap, Viewport] # raises an error if foo isn't a Sprite, Bitmap or Viewport
|
||||
# @raise [ArgumentError] if validation fails
|
||||
def validate(value_pairs)
|
||||
unless value_pairs.is_a?(Hash)
|
||||
raise ArgumentError, "Non-hash argument #{value_pairs.inspect} passed into validate."
|
||||
end
|
||||
errors = value_pairs.map do |value, condition|
|
||||
if condition.is_a?(Array)
|
||||
unless condition.any? { |klass| value.is_a?(klass) }
|
||||
next "Expected #{value.inspect} to be one of #{condition.inspect}, but got #{value.class.name}."
|
||||
end
|
||||
elsif condition.is_a?(Symbol)
|
||||
next "Expected #{value.inspect} to respond to #{condition}." unless value.respond_to?(condition)
|
||||
elsif !value.is_a?(condition)
|
||||
next "Expected #{value.inspect} to be a #{condition.name}, but got #{value.class.name}."
|
||||
end
|
||||
end
|
||||
errors.compact!
|
||||
return if errors.empty?
|
||||
raise ArgumentError, "Invalid argument passed to method.\r\n" + errors.join("\r\n")
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,53 @@
|
||||
# The Deprecation module is used to warn game & plugin creators of deprecated
|
||||
# methods.
|
||||
module Deprecation
|
||||
module_function
|
||||
|
||||
# Sends a warning of a deprecated method into the debug console.
|
||||
# @param method_name [String] name of the deprecated method
|
||||
# @param removal_version [String] version the method is removed in
|
||||
# @param alternative [String] preferred alternative method
|
||||
def warn_method(method_name, removal_version = nil, alternative = nil)
|
||||
text = _INTL('WARN: usage of deprecated method "{1}" or its alias.', method_name)
|
||||
unless removal_version.nil?
|
||||
text += _INTL("\nThe method is slated to be"\
|
||||
" removed in Essentials {1}.", removal_version)
|
||||
end
|
||||
unless alternative.nil?
|
||||
text += _INTL("\nUse \"{1}\" instead.", alternative)
|
||||
end
|
||||
echoln text
|
||||
end
|
||||
end
|
||||
|
||||
# The Module class is extended to allow easy deprecation of instance and class methods.
|
||||
class Module
|
||||
private
|
||||
|
||||
# Creates a deprecated alias for a method.
|
||||
# Using it sends a warning to the debug console.
|
||||
# @param name [Symbol] name of the new alias
|
||||
# @param aliased_method [Symbol] name of the aliased method
|
||||
# @param removal_in [String] version the alias is removed in
|
||||
# @param class_method [Boolean] whether the method is a class method
|
||||
def deprecated_method_alias(name, aliased_method, removal_in: nil, class_method: false)
|
||||
validate name => Symbol, aliased_method => Symbol, removal_in => [NilClass, String],
|
||||
class_method => [TrueClass, FalseClass]
|
||||
|
||||
target = class_method ? self.class : self
|
||||
class_name = self.name
|
||||
|
||||
unless target.method_defined?(aliased_method)
|
||||
raise ArgumentError, "#{class_name} does not have method #{aliased_method} defined"
|
||||
end
|
||||
|
||||
delimiter = class_method ? '.' : '#'
|
||||
|
||||
target.define_method(name) do |*args, **kvargs|
|
||||
alias_name = format('%s%s%s', class_name, delimiter, name)
|
||||
aliased_method_name = format('%s%s%s', class_name, delimiter, aliased_method)
|
||||
Deprecation.warn_method(alias_name, removal_in, aliased_method_name)
|
||||
method(aliased_method).call(*args, **kvargs)
|
||||
end
|
||||
end
|
||||
end
|
||||
37
Data/Scripts_backup/001_Technical/001_MKXP_Compatibility.rb
Normal file
37
Data/Scripts_backup/001_Technical/001_MKXP_Compatibility.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
# Using mkxp-z v2.2.0 - https://gitlab.com/mkxp-z/mkxp-z/-/releases/v2.2.0
|
||||
$VERBOSE = nil
|
||||
Font.default_shadow = false if Font.respond_to?(:default_shadow)
|
||||
Graphics.frame_rate = 40
|
||||
|
||||
def pbSetWindowText(string)
|
||||
System.set_window_title(string || System.game_title)
|
||||
end
|
||||
|
||||
class Bitmap
|
||||
alias mkxp_draw_text draw_text unless method_defined?(:mkxp_draw_text)
|
||||
|
||||
def draw_text(x, y, width, height, text, align = 0)
|
||||
height = text_size(text).height
|
||||
mkxp_draw_text(x, y, width, height, text, align)
|
||||
end
|
||||
end
|
||||
|
||||
module Graphics
|
||||
def self.delta_s
|
||||
return self.delta.to_f / 1_000_000
|
||||
end
|
||||
end
|
||||
|
||||
def pbSetResizeFactor(factor)
|
||||
if !$ResizeInitialized
|
||||
Graphics.resize_screen(Settings::SCREEN_WIDTH, Settings::SCREEN_HEIGHT)
|
||||
$ResizeInitialized = true
|
||||
end
|
||||
if factor < 0 || factor == 4
|
||||
Graphics.fullscreen = true if !Graphics.fullscreen
|
||||
else
|
||||
Graphics.fullscreen = false if Graphics.fullscreen
|
||||
Graphics.scale = (factor + 1) * 0.5
|
||||
Graphics.center
|
||||
end
|
||||
end
|
||||
492
Data/Scripts_backup/001_Technical/002_Files/001_FileTests.rb
Normal file
492
Data/Scripts_backup/001_Technical/002_Files/001_FileTests.rb
Normal file
@@ -0,0 +1,492 @@
|
||||
#===============================================================================
|
||||
# Reads files of certain format from a directory
|
||||
#===============================================================================
|
||||
class Dir
|
||||
#-----------------------------------------------------------------------------
|
||||
# Reads all files in a directory
|
||||
#-----------------------------------------------------------------------------
|
||||
def self.get(dir, filters = "*", full = true)
|
||||
files = []
|
||||
filters = [filters] if !filters.is_a?(Array)
|
||||
self.chdir(dir) do
|
||||
for filter in filters
|
||||
self.glob(filter){ |f| files.push(full ? (dir + "/" + f) : f) }
|
||||
end
|
||||
end
|
||||
return files.sort
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# Generates entire file/folder tree from a certain directory
|
||||
#-----------------------------------------------------------------------------
|
||||
def self.all(dir, filters = "*", full = true)
|
||||
# sets variables for starting
|
||||
files = []
|
||||
subfolders = []
|
||||
for file in self.get(dir, filters, full)
|
||||
# engages in recursion to read the entire file tree
|
||||
if self.safe?(file) # Is a directory
|
||||
subfolders += self.all(file, filters, full)
|
||||
else # Is a file
|
||||
files += [file]
|
||||
end
|
||||
end
|
||||
# returns all found files
|
||||
return files + subfolders
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# Checks for existing directory, gets around accents
|
||||
#-----------------------------------------------------------------------------
|
||||
def self.safe?(dir)
|
||||
return false if !FileTest.directory?(dir)
|
||||
ret = false
|
||||
self.chdir(dir) { ret = true } rescue nil
|
||||
return ret
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# extensions for file class
|
||||
#===============================================================================
|
||||
class File
|
||||
#-----------------------------------------------------------------------------
|
||||
# Checks for existing file, gets around accents
|
||||
#-----------------------------------------------------------------------------
|
||||
def self.safe?(file)
|
||||
ret = false
|
||||
self.open(file, 'rb') { ret = true } rescue nil
|
||||
return ret
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# Checking for files and directories
|
||||
#===============================================================================
|
||||
# Works around a problem with FileTest.directory if directory contains accent marks
|
||||
def safeIsDirectory?(f)
|
||||
ret = false
|
||||
Dir.chdir(f) { ret = true } rescue nil
|
||||
return ret
|
||||
end
|
||||
|
||||
# Works around a problem with FileTest.exist if path contains accent marks
|
||||
def safeExists?(f)
|
||||
return FileTest.exist?(f) if f[/\A[\x20-\x7E]*\z/]
|
||||
ret = false
|
||||
begin
|
||||
File.open(f,"rb") { ret = true }
|
||||
rescue Errno::ENOENT, Errno::EINVAL, Errno::EACCES
|
||||
ret = false
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
# Similar to "Dir.glob", but designed to work around a problem with accessing
|
||||
# files if a path contains accent marks.
|
||||
# "dir" is the directory path, "wildcard" is the filename pattern to match.
|
||||
def safeGlob(dir,wildcard)
|
||||
ret = []
|
||||
afterChdir = false
|
||||
begin
|
||||
Dir.chdir(dir) {
|
||||
afterChdir = true
|
||||
Dir.glob(wildcard) { |f| ret.push(dir+"/"+f) }
|
||||
}
|
||||
rescue Errno::ENOENT
|
||||
raise if afterChdir
|
||||
end
|
||||
if block_given?
|
||||
ret.each { |f| yield(f) }
|
||||
end
|
||||
return (block_given?) ? nil : ret
|
||||
end
|
||||
|
||||
def pbResolveAudioSE(file)
|
||||
return nil if !file
|
||||
if RTP.exists?("Audio/SE/"+file,["",".wav",".mp3",".ogg"])
|
||||
return RTP.getPath("Audio/SE/"+file,["",".wav",".mp3",".ogg"])
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
# Finds the real path for an image file. This includes paths in encrypted
|
||||
# archives. Returns nil if the path can't be found.
|
||||
def pbResolveBitmap(x)
|
||||
return nil if !x
|
||||
noext = x.gsub(/\.(bmp|png|gif|jpg|jpeg)$/,"")
|
||||
filename = nil
|
||||
# RTP.eachPathFor(x) { |path|
|
||||
# filename = pbTryString(path) if !filename
|
||||
# filename = pbTryString(path+".gif") if !filename
|
||||
# }
|
||||
RTP.eachPathFor(noext) { |path|
|
||||
filename = pbTryString(path+".png") if !filename
|
||||
filename = pbTryString(path+".gif") if !filename
|
||||
# filename = pbTryString(path+".jpg") if !filename
|
||||
# filename = pbTryString(path+".jpeg") if !filename
|
||||
# filename = pbTryString(path+".bmp") if !filename
|
||||
}
|
||||
return filename
|
||||
end
|
||||
|
||||
# Finds the real path for an image file. This includes paths in encrypted
|
||||
# archives. Returns _x_ if the path can't be found.
|
||||
def pbBitmapName(x)
|
||||
ret = pbResolveBitmap(x)
|
||||
return (ret) ? ret : x
|
||||
end
|
||||
|
||||
def strsplit(str, re)
|
||||
ret = []
|
||||
tstr = str
|
||||
while re =~ tstr
|
||||
ret[ret.length] = $~.pre_match
|
||||
tstr = $~.post_match
|
||||
end
|
||||
ret[ret.length] = tstr if ret.length
|
||||
return ret
|
||||
end
|
||||
|
||||
def canonicalize(c)
|
||||
csplit = strsplit(c, /[\/\\]/)
|
||||
pos = -1
|
||||
ret = []
|
||||
retstr = ""
|
||||
for x in csplit
|
||||
if x == ".."
|
||||
if pos >= 0
|
||||
ret.delete_at(pos)
|
||||
pos -= 1
|
||||
end
|
||||
elsif x != "."
|
||||
ret.push(x)
|
||||
pos += 1
|
||||
end
|
||||
end
|
||||
for i in 0...ret.length
|
||||
retstr += "/" if i > 0
|
||||
retstr += ret[i]
|
||||
end
|
||||
return retstr
|
||||
end
|
||||
|
||||
|
||||
|
||||
module RTP
|
||||
@rtpPaths = nil
|
||||
|
||||
def self.exists?(filename,extensions=[])
|
||||
return false if nil_or_empty?(filename)
|
||||
eachPathFor(filename) { |path|
|
||||
return true if safeExists?(path)
|
||||
for ext in extensions
|
||||
return true if safeExists?(path+ext)
|
||||
end
|
||||
}
|
||||
return false
|
||||
end
|
||||
|
||||
def self.getImagePath(filename)
|
||||
return self.getPath(filename,["",".png",".gif"]) # ".jpg", ".jpeg", ".bmp"
|
||||
end
|
||||
|
||||
def self.getAudioPath(filename)
|
||||
return self.getPath(filename,["",".mp3",".wav",".wma",".mid",".ogg",".midi"])
|
||||
end
|
||||
|
||||
def self.getPath(filename,extensions=[])
|
||||
return filename if nil_or_empty?(filename)
|
||||
eachPathFor(filename) { |path|
|
||||
return path if safeExists?(path)
|
||||
for ext in extensions
|
||||
file = path+ext
|
||||
return file if safeExists?(file)
|
||||
end
|
||||
}
|
||||
return filename
|
||||
end
|
||||
|
||||
# Gets the absolute RGSS paths for the given file name
|
||||
def self.eachPathFor(filename)
|
||||
return if !filename
|
||||
if filename[/^[A-Za-z]\:[\/\\]/] || filename[/^[\/\\]/]
|
||||
# filename is already absolute
|
||||
yield filename
|
||||
else
|
||||
# relative path
|
||||
RTP.eachPath { |path|
|
||||
if path=="./"
|
||||
yield filename
|
||||
else
|
||||
yield path+filename
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
# Gets all RGSS search paths.
|
||||
# This function basically does nothing now, because
|
||||
# the passage of time and introduction of MKXP make
|
||||
# it useless, but leaving it for compatibility
|
||||
# reasons
|
||||
def self.eachPath
|
||||
# XXX: Use "." instead of Dir.pwd because of problems retrieving files if
|
||||
# the current directory contains an accent mark
|
||||
yield ".".gsub(/[\/\\]/,"/").gsub(/[\/\\]$/,"")+"/"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.getSaveFileName(fileName)
|
||||
File.join(getSaveFolder, fileName)
|
||||
end
|
||||
|
||||
def self.getSaveFolder
|
||||
# MKXP makes sure that this folder has been created
|
||||
# once it starts. The location differs depending on
|
||||
# the operating system:
|
||||
# Windows: %APPDATA%
|
||||
# Linux: $HOME/.local/share
|
||||
# macOS (unsandboxed): $HOME/Library/Application Support
|
||||
System.data_directory
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
module FileTest
|
||||
Image_ext = ['.png', '.gif'] # '.jpg', '.jpeg', '.bmp',
|
||||
Audio_ext = ['.mp3', '.mid', '.midi', '.ogg', '.wav', '.wma']
|
||||
|
||||
def self.audio_exist?(filename)
|
||||
return RTP.exists?(filename,Audio_ext)
|
||||
end
|
||||
|
||||
def self.image_exist?(filename)
|
||||
return RTP.exists?(filename,Image_ext)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
# Used to determine whether a data file exists (rather than a graphics or
|
||||
# audio file). Doesn't check RTP, but does check encrypted archives.
|
||||
|
||||
# Note: pbGetFileChar checks anything added in MKXP's RTP setting,
|
||||
# and matching mount points added through System.mount
|
||||
def pbRgssExists?(filename)
|
||||
if safeExists?("./Game.rgssad")
|
||||
return pbGetFileChar(filename)!=nil
|
||||
else
|
||||
filename = canonicalize(filename)
|
||||
return safeExists?(filename)
|
||||
end
|
||||
end
|
||||
|
||||
# Opens an IO, even if the file is in an encrypted archive.
|
||||
# Doesn't check RTP for the file.
|
||||
|
||||
# Note: load_data checks anything added in MKXP's RTP setting,
|
||||
# and matching mount points added through System.mount
|
||||
def pbRgssOpen(file,mode=nil)
|
||||
#File.open("debug.txt","ab") { |fw| fw.write([file,mode,Time.now.to_f].inspect+"\r\n") }
|
||||
if !safeExists?("./Game.rgssad")
|
||||
if block_given?
|
||||
File.open(file,mode) { |f| yield f }
|
||||
return nil
|
||||
else
|
||||
return File.open(file,mode)
|
||||
end
|
||||
end
|
||||
file = canonicalize(file)
|
||||
Marshal.neverload = true
|
||||
str = load_data(file, true)
|
||||
if block_given?
|
||||
StringInput.open(str) { |f| yield f }
|
||||
return nil
|
||||
else
|
||||
return StringInput.open(str)
|
||||
end
|
||||
end
|
||||
|
||||
# Gets at least the first byte of a file. Doesn't check RTP, but does check
|
||||
# encrypted archives.
|
||||
def pbGetFileChar(file)
|
||||
canon_file = canonicalize(file)
|
||||
if !safeExists?("./Game.rgssad")
|
||||
return nil if !safeExists?(canon_file)
|
||||
return nil if file.last == '/' # Is a directory
|
||||
begin
|
||||
File.open(canon_file, "rb") { |f| return f.read(1) } # read one byte
|
||||
rescue Errno::ENOENT, Errno::EINVAL, Errno::EACCES, Errno::EISDIR
|
||||
return nil
|
||||
end
|
||||
end
|
||||
str = nil
|
||||
begin
|
||||
str = load_data(canon_file, true)
|
||||
rescue Errno::ENOENT, Errno::EINVAL, Errno::EACCES, Errno::EISDIR, RGSSError, MKXPError
|
||||
str = nil
|
||||
end
|
||||
return str
|
||||
end
|
||||
|
||||
def pbTryString(x)
|
||||
ret = pbGetFileChar(x)
|
||||
return (ret!=nil && ret!="") ? x : nil
|
||||
end
|
||||
|
||||
# Gets the contents of a file. Doesn't check RTP, but does check
|
||||
# encrypted archives.
|
||||
|
||||
# Note: load_data will check anything added in MKXP's RTP setting,
|
||||
# and matching mount points added through System.mount
|
||||
def pbGetFileString(file)
|
||||
file = canonicalize(file)
|
||||
if !safeExists?("./Game.rgssad")
|
||||
return nil if !safeExists?(file)
|
||||
begin
|
||||
File.open(file,"rb") { |f| return f.read } # read all data
|
||||
rescue Errno::ENOENT, Errno::EINVAL, Errno::EACCES
|
||||
return nil
|
||||
end
|
||||
end
|
||||
str = nil
|
||||
begin
|
||||
str = load_data(file, true)
|
||||
rescue Errno::ENOENT, Errno::EINVAL, Errno::EACCES, RGSSError, MKXPError
|
||||
str = nil
|
||||
end
|
||||
return str
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class StringInput
|
||||
include Enumerable
|
||||
|
||||
class << self
|
||||
def new( str )
|
||||
if block_given?
|
||||
begin
|
||||
f = super
|
||||
yield f
|
||||
ensure
|
||||
f.close if f
|
||||
end
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
alias open new
|
||||
end
|
||||
|
||||
def initialize( str )
|
||||
@string = str
|
||||
@pos = 0
|
||||
@closed = false
|
||||
@lineno = 0
|
||||
end
|
||||
|
||||
attr_reader :lineno,:string
|
||||
|
||||
def inspect
|
||||
return "#<#{self.class}:#{@closed ? 'closed' : 'open'},src=#{@string[0,30].inspect}>"
|
||||
end
|
||||
|
||||
def close
|
||||
raise IOError, 'closed stream' if @closed
|
||||
@pos = nil
|
||||
@closed = true
|
||||
end
|
||||
|
||||
def closed?; @closed; end
|
||||
|
||||
def pos
|
||||
raise IOError, 'closed stream' if @closed
|
||||
[@pos, @string.size].min
|
||||
end
|
||||
|
||||
alias tell pos
|
||||
|
||||
def rewind; seek(0); end
|
||||
|
||||
def pos=(value); seek(value); end
|
||||
|
||||
def seek(offset, whence=IO::SEEK_SET)
|
||||
raise IOError, 'closed stream' if @closed
|
||||
case whence
|
||||
when IO::SEEK_SET then @pos = offset
|
||||
when IO::SEEK_CUR then @pos += offset
|
||||
when IO::SEEK_END then @pos = @string.size - offset
|
||||
else
|
||||
raise ArgumentError, "unknown seek flag: #{whence}"
|
||||
end
|
||||
@pos = 0 if @pos < 0
|
||||
@pos = [@pos, @string.size + 1].min
|
||||
offset
|
||||
end
|
||||
|
||||
def eof?
|
||||
raise IOError, 'closed stream' if @closed
|
||||
@pos > @string.size
|
||||
end
|
||||
|
||||
def each( &block )
|
||||
raise IOError, 'closed stream' if @closed
|
||||
begin
|
||||
@string.each(&block)
|
||||
ensure
|
||||
@pos = 0
|
||||
end
|
||||
end
|
||||
|
||||
def gets
|
||||
raise IOError, 'closed stream' if @closed
|
||||
if idx = @string.index(?\n, @pos)
|
||||
idx += 1 # "\n".size
|
||||
line = @string[ @pos ... idx ]
|
||||
@pos = idx
|
||||
@pos += 1 if @pos == @string.size
|
||||
else
|
||||
line = @string[ @pos .. -1 ]
|
||||
@pos = @string.size + 1
|
||||
end
|
||||
@lineno += 1
|
||||
line
|
||||
end
|
||||
|
||||
def getc
|
||||
raise IOError, 'closed stream' if @closed
|
||||
ch = @string[@pos]
|
||||
@pos += 1
|
||||
@pos += 1 if @pos == @string.size
|
||||
ch
|
||||
end
|
||||
|
||||
def read( len = nil )
|
||||
raise IOError, 'closed stream' if @closed
|
||||
if !len
|
||||
return nil if eof?
|
||||
rest = @string[@pos ... @string.size]
|
||||
@pos = @string.size + 1
|
||||
return rest
|
||||
end
|
||||
str = @string[@pos, len]
|
||||
@pos += len
|
||||
@pos += 1 if @pos == @string.size
|
||||
str
|
||||
end
|
||||
|
||||
def read_all; read(); end
|
||||
|
||||
alias sysread read
|
||||
end
|
||||
150
Data/Scripts_backup/001_Technical/002_Files/002_FileMixins.rb
Normal file
150
Data/Scripts_backup/001_Technical/002_Files/002_FileMixins.rb
Normal file
@@ -0,0 +1,150 @@
|
||||
module FileInputMixin
|
||||
def fgetb
|
||||
ret = 0
|
||||
each_byte do |i|
|
||||
ret = i || 0
|
||||
break
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def fgetw
|
||||
x = 0
|
||||
ret = 0
|
||||
each_byte do |i|
|
||||
break if !i
|
||||
ret |= (i << x)
|
||||
x += 8
|
||||
break if x == 16
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def fgetdw
|
||||
x = 0
|
||||
ret = 0
|
||||
each_byte do |i|
|
||||
break if !i
|
||||
ret |= (i << x)
|
||||
x += 8
|
||||
break if x == 32
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def fgetsb
|
||||
ret = fgetb
|
||||
ret -= 256 if (ret & 0x80) != 0
|
||||
return ret
|
||||
end
|
||||
|
||||
def xfgetb(offset)
|
||||
self.pos = offset
|
||||
return fgetb
|
||||
end
|
||||
|
||||
def xfgetw(offset)
|
||||
self.pos = offset
|
||||
return fgetw
|
||||
end
|
||||
|
||||
def xfgetdw(offset)
|
||||
self.pos = offset
|
||||
return fgetdw
|
||||
end
|
||||
|
||||
def getOffset(index)
|
||||
self.binmode
|
||||
self.pos = 0
|
||||
offset = fgetdw >> 3
|
||||
return 0 if index >= offset
|
||||
self.pos = index * 8
|
||||
return fgetdw
|
||||
end
|
||||
|
||||
def getLength(index)
|
||||
self.binmode
|
||||
self.pos = 0
|
||||
offset = fgetdw >> 3
|
||||
return 0 if index >= offset
|
||||
self.pos = index * 8 + 4
|
||||
return fgetdw
|
||||
end
|
||||
|
||||
def readName(index)
|
||||
self.binmode
|
||||
self.pos = 0
|
||||
offset = fgetdw >> 3
|
||||
return "" if index >= offset
|
||||
self.pos = index << 3
|
||||
offset = fgetdw
|
||||
length = fgetdw
|
||||
return "" if length == 0
|
||||
self.pos = offset
|
||||
return read(length)
|
||||
end
|
||||
end
|
||||
|
||||
module FileOutputMixin
|
||||
def fputb(b)
|
||||
b &= 0xFF
|
||||
write(b.chr)
|
||||
end
|
||||
|
||||
def fputw(w)
|
||||
2.times do
|
||||
b = w & 0xFF
|
||||
write(b.chr)
|
||||
w >>= 8
|
||||
end
|
||||
end
|
||||
|
||||
def fputdw(w)
|
||||
4.times do
|
||||
b = w & 0xFF
|
||||
write(b.chr)
|
||||
w >>= 8
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class File < IO
|
||||
=begin
|
||||
unless defined?(debugopen)
|
||||
class << self
|
||||
alias debugopen open
|
||||
end
|
||||
end
|
||||
|
||||
def open(f, m = "r")
|
||||
debugopen("debug.txt", "ab") { |file| file.write([f, m, Time.now.to_f].inspect + "\r\n") }
|
||||
if block_given?
|
||||
debugopen(f, m) { |file| yield file }
|
||||
else
|
||||
return debugopen(f, m)
|
||||
end
|
||||
end
|
||||
=end
|
||||
include FileInputMixin
|
||||
include FileOutputMixin
|
||||
end
|
||||
|
||||
class StringInput
|
||||
include FileInputMixin
|
||||
|
||||
def pos=(value)
|
||||
seek(value)
|
||||
end
|
||||
|
||||
def each_byte
|
||||
while !eof?
|
||||
yield getc
|
||||
end
|
||||
end
|
||||
|
||||
def binmode; end
|
||||
end
|
||||
|
||||
class StringOutput
|
||||
include FileOutputMixin
|
||||
end
|
||||
@@ -0,0 +1,85 @@
|
||||
#############################
|
||||
#
|
||||
# HTTP utility functions
|
||||
#
|
||||
#############################
|
||||
def pbPostData(url, postdata, filename=nil, depth=0)
|
||||
if url[/^http:\/\/([^\/]+)(.*)$/]
|
||||
host = $1
|
||||
path = $2
|
||||
path = "/" if path.length==0
|
||||
userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.14) Gecko/2009082707 Firefox/3.0.14"
|
||||
body = postdata.map { |key, value|
|
||||
keyString = key.to_s
|
||||
valueString = value.to_s
|
||||
keyString.gsub!(/[^a-zA-Z0-9_\.\-]/n) { |s| sprintf('%%%02x', s[0]) }
|
||||
valueString.gsub!(/[^a-zA-Z0-9_\.\-]/n) { |s| sprintf('%%%02x', s[0]) }
|
||||
next "#{keyString}=#{valueString}"
|
||||
}.join('&')
|
||||
ret = HTTPLite.post_body(
|
||||
url,
|
||||
body,
|
||||
"application/x-www-form-urlencoded",
|
||||
{
|
||||
"Host" => host, # might not be necessary
|
||||
"Proxy-Connection" => "Close",
|
||||
"Content-Length" => body.bytesize.to_s,
|
||||
"Pragma" => "no-cache",
|
||||
"User-Agent" => userAgent
|
||||
}
|
||||
) rescue ""
|
||||
return ret if !ret.is_a?(Hash)
|
||||
return "" if ret[:status] != 200
|
||||
return ret[:body] if !filename
|
||||
File.open(filename, "wb"){|f|f.write(ret[:body])}
|
||||
return ""
|
||||
end
|
||||
return ""
|
||||
end
|
||||
|
||||
def pbDownloadData(url, filename = nil, authorization = nil, depth = 0, &block)
|
||||
headers = {
|
||||
"Proxy-Connection" => "Close",
|
||||
"Pragma" => "no-cache",
|
||||
"User-Agent" => "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.14) Gecko/2009082707 Firefox/3.0.14"
|
||||
}
|
||||
headers["authorization"] = authorization if authorization
|
||||
ret = HTTPLite.get(url, headers) rescue ""
|
||||
return ret if !ret.is_a?(Hash)
|
||||
return "" if ret[:status] != 200
|
||||
return ret[:body] if !filename
|
||||
File.open(filename, "wb") { |f| f.write(ret[:body]) }
|
||||
return ""
|
||||
end
|
||||
|
||||
def pbDownloadToString(url)
|
||||
begin
|
||||
data = pbDownloadData(url)
|
||||
return data
|
||||
rescue
|
||||
return ""
|
||||
end
|
||||
end
|
||||
|
||||
def pbDownloadToFile(url, file)
|
||||
begin
|
||||
pbDownloadData(url,file)
|
||||
rescue
|
||||
end
|
||||
end
|
||||
|
||||
def pbPostToString(url, postdata)
|
||||
begin
|
||||
data = pbPostData(url, postdata)
|
||||
return data
|
||||
rescue
|
||||
return ""
|
||||
end
|
||||
end
|
||||
|
||||
def pbPostToFile(url, postdata, file)
|
||||
begin
|
||||
pbPostData(url, postdata,file)
|
||||
rescue
|
||||
end
|
||||
end
|
||||
142
Data/Scripts_backup/001_Technical/002_RubyUtilities.rb
Normal file
142
Data/Scripts_backup/001_Technical/002_RubyUtilities.rb
Normal file
@@ -0,0 +1,142 @@
|
||||
#===============================================================================
|
||||
# class Object
|
||||
#===============================================================================
|
||||
class Object
|
||||
alias full_inspect inspect
|
||||
|
||||
def inspect
|
||||
return "#<#{self.class}>"
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# class Class
|
||||
#===============================================================================
|
||||
class Class
|
||||
def to_sym
|
||||
return self.to_s.to_sym
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# class String
|
||||
#===============================================================================
|
||||
class String
|
||||
def starts_with_vowel?
|
||||
return ['a', 'e', 'i', 'o', 'u'].include?(self[0, 1].downcase)
|
||||
end
|
||||
|
||||
def first(n = 1)
|
||||
return self[0...n]
|
||||
end
|
||||
|
||||
def last(n = 1)
|
||||
return self[-n..-1] || self
|
||||
end
|
||||
|
||||
def blank?
|
||||
blank = true
|
||||
s = self.scan(/./)
|
||||
for l in s
|
||||
blank = false if l != ""
|
||||
end
|
||||
return blank
|
||||
end
|
||||
|
||||
def cut(bitmap, width)
|
||||
string = self
|
||||
width -= bitmap.text_size("...").width
|
||||
string_width = 0
|
||||
text = []
|
||||
for char in string.scan(/./)
|
||||
wdh = bitmap.text_size(char).width
|
||||
next if (wdh + string_width) > width
|
||||
string_width += wdh
|
||||
text.push(char)
|
||||
end
|
||||
text.push("...") if text.length < string.length
|
||||
new_string = ""
|
||||
for char in text
|
||||
new_string += char
|
||||
end
|
||||
return new_string
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# class Numeric
|
||||
#===============================================================================
|
||||
class Numeric
|
||||
# Turns a number into a string formatted like 12,345,678.
|
||||
def to_s_formatted
|
||||
return self.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\1,').reverse
|
||||
end
|
||||
|
||||
def to_word
|
||||
ret = [_INTL("zero"), _INTL("one"), _INTL("two"), _INTL("three"),
|
||||
_INTL("four"), _INTL("five"), _INTL("six"), _INTL("seven"),
|
||||
_INTL("eight"), _INTL("nine"), _INTL("ten"), _INTL("eleven"),
|
||||
_INTL("twelve"), _INTL("thirteen"), _INTL("fourteen"), _INTL("fifteen"),
|
||||
_INTL("sixteen"), _INTL("seventeen"), _INTL("eighteen"), _INTL("nineteen"),
|
||||
_INTL("twenty")]
|
||||
return ret[self] if self.is_a?(Integer) && self >= 0 && self <= ret.length
|
||||
return self.to_s
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# class Array
|
||||
#===============================================================================
|
||||
class Array
|
||||
def ^(other) # xor of two arrays
|
||||
return (self|other) - (self&other)
|
||||
end
|
||||
|
||||
def swap(val1, val2)
|
||||
index1 = self.index(val1)
|
||||
index2 = self.index(val2)
|
||||
self[index1] = val2
|
||||
self[index2] = val1
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# module Enumerable
|
||||
#===============================================================================
|
||||
module Enumerable
|
||||
def transform
|
||||
ret = []
|
||||
self.each { |item| ret.push(yield(item)) }
|
||||
return ret
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# Kernel methods
|
||||
#===============================================================================
|
||||
def rand(*args)
|
||||
Kernel.rand(*args)
|
||||
end
|
||||
|
||||
class << Kernel
|
||||
alias oldRand rand unless method_defined?(:oldRand)
|
||||
def rand(a = nil, b = nil)
|
||||
if a.is_a?(Range)
|
||||
lo = a.min
|
||||
hi = a.max
|
||||
return lo + oldRand(hi - lo + 1)
|
||||
elsif a.is_a?(Numeric)
|
||||
if b.is_a?(Numeric)
|
||||
return a + oldRand(b - a + 1)
|
||||
else
|
||||
return oldRand(a)
|
||||
end
|
||||
elsif a.nil?
|
||||
return (b) ? oldRand(b) : oldRand(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def nil_or_empty?(string)
|
||||
return string.nil? || !string.is_a?(String) || string.size == 0
|
||||
end
|
||||
789
Data/Scripts_backup/001_Technical/003_Intl_Messages.rb
Normal file
789
Data/Scripts_backup/001_Technical/003_Intl_Messages.rb
Normal file
@@ -0,0 +1,789 @@
|
||||
def pbAddScriptTexts(items,script)
|
||||
script.scan(/(?:_I)\s*\(\s*\"((?:[^\\\"]*\\\"?)*[^\"]*)\"/) { |s|
|
||||
string=s[0]
|
||||
string.gsub!(/\\\"/,"\"")
|
||||
string.gsub!(/\\\\/,"\\")
|
||||
items.push(string)
|
||||
}
|
||||
end
|
||||
|
||||
def pbAddRgssScriptTexts(items,script)
|
||||
script.scan(/(?:_INTL|_ISPRINTF)\s*\(\s*\"((?:[^\\\"]*\\\"?)*[^\"]*)\"/) { |s|
|
||||
string=s[0]
|
||||
string.gsub!(/\\r/,"\r")
|
||||
string.gsub!(/\\n/,"\n")
|
||||
string.gsub!(/\\1/,"\1")
|
||||
string.gsub!(/\\\"/,"\"")
|
||||
string.gsub!(/\\\\/,"\\")
|
||||
items.push(string)
|
||||
}
|
||||
end
|
||||
|
||||
def pbSetTextMessages
|
||||
Graphics.update
|
||||
begin
|
||||
t = Time.now.to_i
|
||||
texts=[]
|
||||
for script in $RGSS_SCRIPTS
|
||||
if Time.now.to_i - t >= 5
|
||||
t = Time.now.to_i
|
||||
Graphics.update
|
||||
end
|
||||
scr=Zlib::Inflate.inflate(script[2])
|
||||
pbAddRgssScriptTexts(texts,scr)
|
||||
end
|
||||
if safeExists?("Data/PluginScripts.rxdata")
|
||||
plugin_scripts = load_data("Data/PluginScripts.rxdata")
|
||||
for plugin in plugin_scripts
|
||||
for script in plugin[2]
|
||||
if Time.now.to_i - t >= 5
|
||||
t = Time.now.to_i
|
||||
Graphics.update
|
||||
end
|
||||
scr = Zlib::Inflate.inflate(script[1]).force_encoding(Encoding::UTF_8)
|
||||
pbAddRgssScriptTexts(texts,scr)
|
||||
end
|
||||
end
|
||||
end
|
||||
# Must add messages because this code is used by both game system and Editor
|
||||
MessageTypes.addMessagesAsHash(MessageTypes::ScriptTexts,texts)
|
||||
commonevents = load_data("Data/CommonEvents.rxdata")
|
||||
items=[]
|
||||
choices=[]
|
||||
for event in commonevents.compact
|
||||
if Time.now.to_i - t >= 5
|
||||
t = Time.now.to_i
|
||||
Graphics.update
|
||||
end
|
||||
begin
|
||||
neednewline=false
|
||||
lastitem=""
|
||||
for j in 0...event.list.size
|
||||
list = event.list[j]
|
||||
if neednewline && list.code!=401
|
||||
if lastitem!=""
|
||||
lastitem.gsub!(/([^\.\!\?])\s\s+/) { |m| $1+" " }
|
||||
items.push(lastitem)
|
||||
lastitem=""
|
||||
end
|
||||
neednewline=false
|
||||
end
|
||||
if list.code == 101
|
||||
lastitem+="#{list.parameters[0]}"
|
||||
neednewline=true
|
||||
elsif list.code == 102
|
||||
for k in 0...list.parameters[0].length
|
||||
choices.push(list.parameters[0][k])
|
||||
end
|
||||
neednewline=false
|
||||
elsif list.code == 401
|
||||
lastitem+=" " if lastitem!=""
|
||||
lastitem+="#{list.parameters[0]}"
|
||||
neednewline=true
|
||||
elsif list.code == 355 || list.code == 655
|
||||
pbAddScriptTexts(items,list.parameters[0])
|
||||
elsif list.code == 111 && list.parameters[0]==12
|
||||
pbAddScriptTexts(items,list.parameters[1])
|
||||
elsif list.code == 209
|
||||
route=list.parameters[1]
|
||||
for k in 0...route.list.size
|
||||
if route.list[k].code == 45
|
||||
pbAddScriptTexts(items,route.list[k].parameters[0])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if neednewline
|
||||
if lastitem!=""
|
||||
items.push(lastitem)
|
||||
lastitem=""
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if Time.now.to_i - t >= 5
|
||||
t = Time.now.to_i
|
||||
Graphics.update
|
||||
end
|
||||
items|=[]
|
||||
choices|=[]
|
||||
items.concat(choices)
|
||||
MessageTypes.setMapMessagesAsHash(0,items)
|
||||
mapinfos = pbLoadMapInfos
|
||||
mapnames=[]
|
||||
for id in mapinfos.keys
|
||||
mapnames[id]=mapinfos[id].name
|
||||
end
|
||||
MessageTypes.setMessages(MessageTypes::MapNames,mapnames)
|
||||
for id in mapinfos.keys
|
||||
if Time.now.to_i - t >= 5
|
||||
t = Time.now.to_i
|
||||
Graphics.update
|
||||
end
|
||||
filename=sprintf("Data/Map%03d.rxdata",id)
|
||||
next if !pbRgssExists?(filename)
|
||||
map = load_data(filename)
|
||||
items=[]
|
||||
choices=[]
|
||||
for event in map.events.values
|
||||
if Time.now.to_i - t >= 5
|
||||
t = Time.now.to_i
|
||||
Graphics.update
|
||||
end
|
||||
begin
|
||||
for i in 0...event.pages.size
|
||||
neednewline=false
|
||||
lastitem=""
|
||||
for j in 0...event.pages[i].list.size
|
||||
list = event.pages[i].list[j]
|
||||
if neednewline && list.code!=401
|
||||
if lastitem!=""
|
||||
lastitem.gsub!(/([^\.\!\?])\s\s+/) { |m| $1+" " }
|
||||
items.push(lastitem)
|
||||
lastitem=""
|
||||
end
|
||||
neednewline=false
|
||||
end
|
||||
if list.code == 101
|
||||
lastitem+="#{list.parameters[0]}"
|
||||
neednewline=true
|
||||
elsif list.code == 102
|
||||
for k in 0...list.parameters[0].length
|
||||
choices.push(list.parameters[0][k])
|
||||
end
|
||||
neednewline=false
|
||||
elsif list.code == 401
|
||||
lastitem+=" " if lastitem!=""
|
||||
lastitem+="#{list.parameters[0]}"
|
||||
neednewline=true
|
||||
elsif list.code == 355 || list.code==655
|
||||
pbAddScriptTexts(items,list.parameters[0])
|
||||
elsif list.code == 111 && list.parameters[0]==12
|
||||
pbAddScriptTexts(items,list.parameters[1])
|
||||
elsif list.code==209
|
||||
route=list.parameters[1]
|
||||
for k in 0...route.list.size
|
||||
if route.list[k].code==45
|
||||
pbAddScriptTexts(items,route.list[k].parameters[0])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if neednewline
|
||||
if lastitem!=""
|
||||
items.push(lastitem)
|
||||
lastitem=""
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if Time.now.to_i - t >= 5
|
||||
t = Time.now.to_i
|
||||
Graphics.update
|
||||
end
|
||||
items|=[]
|
||||
choices|=[]
|
||||
items.concat(choices)
|
||||
MessageTypes.setMapMessagesAsHash(id,items)
|
||||
if Time.now.to_i - t >= 5
|
||||
t = Time.now.to_i
|
||||
Graphics.update
|
||||
end
|
||||
end
|
||||
rescue Hangup
|
||||
end
|
||||
Graphics.update
|
||||
end
|
||||
|
||||
def pbEachIntlSection(file)
|
||||
lineno=1
|
||||
re=/^\s*\[\s*([^\]]+)\s*\]\s*$/
|
||||
havesection=false
|
||||
sectionname=nil
|
||||
lastsection=[]
|
||||
file.each_line { |line|
|
||||
if lineno==1 && line[0].ord==0xEF && line[1].ord==0xBB && line[2].ord==0xBF
|
||||
line=line[3,line.length-3]
|
||||
end
|
||||
if !line[/^\#/] && !line[/^\s*$/]
|
||||
if line[re]
|
||||
if havesection
|
||||
yield lastsection,sectionname
|
||||
end
|
||||
lastsection.clear
|
||||
sectionname=$~[1]
|
||||
havesection=true
|
||||
else
|
||||
if sectionname==nil
|
||||
raise _INTL("Expected a section at the beginning of the file (line {1})",lineno)
|
||||
end
|
||||
lastsection.push(line.gsub(/\s+$/,""))
|
||||
end
|
||||
end
|
||||
lineno+=1
|
||||
if lineno%500==0
|
||||
Graphics.update
|
||||
end
|
||||
}
|
||||
if havesection
|
||||
yield lastsection,sectionname
|
||||
end
|
||||
end
|
||||
|
||||
def pbGetText(infile)
|
||||
begin
|
||||
file=File.open(infile,"rb")
|
||||
rescue
|
||||
raise _INTL("Can't find {1}",infile)
|
||||
end
|
||||
intldat=[]
|
||||
begin
|
||||
pbEachIntlSection(file) { |section,name|
|
||||
next if section.length==0
|
||||
if !name[/^([Mm][Aa][Pp])?(\d+)$/]
|
||||
raise _INTL("Invalid section name {1}",name)
|
||||
end
|
||||
ismap=$~[1] && $~[1]!=""
|
||||
id=$~[2].to_i
|
||||
itemlength=0
|
||||
if section[0][/^\d+$/]
|
||||
intlhash=[]
|
||||
itemlength=3
|
||||
if ismap
|
||||
raise _INTL("Section {1} can't be an ordered list (section was recognized as an ordered list because its first line is a number)",name)
|
||||
end
|
||||
if section.length%3!=0
|
||||
raise _INTL("Section {1}'s line count is not divisible by 3 (section was recognized as an ordered list because its first line is a number)",name)
|
||||
end
|
||||
else
|
||||
intlhash=OrderedHash.new
|
||||
itemlength=2
|
||||
if section.length%2!=0
|
||||
raise _INTL("Section {1} has an odd number of entries (section was recognized as a hash because its first line is not a number)",name)
|
||||
end
|
||||
end
|
||||
i=0
|
||||
loop do break unless i<section.length
|
||||
if itemlength==3
|
||||
if !section[i][/^\d+$/]
|
||||
raise _INTL("Expected a number in section {1}, got {2} instead",name,section[i])
|
||||
end
|
||||
key=section[i].to_i
|
||||
i+=1
|
||||
else
|
||||
key=MessageTypes.denormalizeValue(section[i])
|
||||
end
|
||||
intlhash[key]=MessageTypes.denormalizeValue(section[i+1])
|
||||
i+=2
|
||||
end
|
||||
if ismap
|
||||
intldat[0]=[] if !intldat[0]
|
||||
intldat[0][id]=intlhash
|
||||
else
|
||||
intldat[id]=intlhash
|
||||
end
|
||||
}
|
||||
ensure
|
||||
file.close
|
||||
end
|
||||
return intldat
|
||||
end
|
||||
|
||||
def pbCompileText
|
||||
outfile=File.open("intl.dat","wb")
|
||||
begin
|
||||
intldat=pbGetText("intl.txt")
|
||||
Marshal.dump(intldat,outfile)
|
||||
rescue
|
||||
raise
|
||||
ensure
|
||||
outfile.close
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class OrderedHash < Hash
|
||||
def initialize
|
||||
@keys=[]
|
||||
super
|
||||
end
|
||||
|
||||
def keys
|
||||
return @keys.clone
|
||||
end
|
||||
|
||||
def inspect
|
||||
str="{"
|
||||
for i in 0...@keys.length
|
||||
str+=", " if i>0
|
||||
str+=@keys[i].inspect+"=>"+self[@keys[i]].inspect
|
||||
end
|
||||
str+="}"
|
||||
return str
|
||||
end
|
||||
|
||||
alias :to_s :inspect
|
||||
|
||||
def []=(key,value)
|
||||
oldvalue=self[key]
|
||||
if !oldvalue && value
|
||||
@keys.push(key)
|
||||
elsif !value
|
||||
@keys|=[]
|
||||
@keys-=[key]
|
||||
end
|
||||
return super(key,value)
|
||||
end
|
||||
|
||||
def self._load(string)
|
||||
ret=self.new
|
||||
keysvalues=Marshal.load(string)
|
||||
keys=keysvalues[0]
|
||||
values=keysvalues[1]
|
||||
for i in 0...keys.length
|
||||
ret[keys[i]]=values[i]
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def _dump(_depth=100)
|
||||
values=[]
|
||||
for key in @keys
|
||||
values.push(self[key])
|
||||
end
|
||||
return Marshal.dump([@keys,values])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class Messages
|
||||
def initialize(filename=nil,delayLoad=false)
|
||||
@messages=nil
|
||||
@filename=filename
|
||||
if @filename && !delayLoad
|
||||
loadMessageFile(@filename)
|
||||
end
|
||||
end
|
||||
|
||||
def delayedLoad
|
||||
if @filename && !@messages
|
||||
loadMessageFile(@filename)
|
||||
@filename=nil
|
||||
end
|
||||
end
|
||||
|
||||
def self.stringToKey(str)
|
||||
if str && str[/[\r\n\t\1]|^\s+|\s+$|\s{2,}/]
|
||||
key=str.clone
|
||||
key.gsub!(/^\s+/,"")
|
||||
key.gsub!(/\s+$/,"")
|
||||
key.gsub!(/\s{2,}/," ")
|
||||
return key
|
||||
end
|
||||
return str
|
||||
end
|
||||
|
||||
def self.normalizeValue(value)
|
||||
if value[/[\r\n\t\x01]|^[\[\]]/]
|
||||
ret=value.clone
|
||||
ret.gsub!(/\r/,"<<r>>")
|
||||
ret.gsub!(/\n/,"<<n>>")
|
||||
ret.gsub!(/\t/,"<<t>>")
|
||||
ret.gsub!(/\[/,"<<[>>")
|
||||
ret.gsub!(/\]/,"<<]>>")
|
||||
ret.gsub!(/\x01/,"<<1>>")
|
||||
return ret
|
||||
end
|
||||
return value
|
||||
end
|
||||
|
||||
def self.denormalizeValue(value)
|
||||
if value[/<<[rnt1\[\]]>>/]
|
||||
ret=value.clone
|
||||
ret.gsub!(/<<1>>/,"\1")
|
||||
ret.gsub!(/<<r>>/,"\r")
|
||||
ret.gsub!(/<<n>>/,"\n")
|
||||
ret.gsub!(/<<\[>>/,"[")
|
||||
ret.gsub!(/<<\]>>/,"]")
|
||||
ret.gsub!(/<<t>>/,"\t")
|
||||
return ret
|
||||
end
|
||||
return value
|
||||
end
|
||||
|
||||
def self.writeObject(f,msgs,secname,origMessages=nil)
|
||||
return if !msgs
|
||||
if msgs.is_a?(Array)
|
||||
f.write("[#{secname}]\r\n")
|
||||
for j in 0...msgs.length
|
||||
next if nil_or_empty?(msgs[j])
|
||||
value=Messages.normalizeValue(msgs[j])
|
||||
origValue=""
|
||||
if origMessages
|
||||
origValue=Messages.normalizeValue(origMessages.get(secname,j))
|
||||
else
|
||||
origValue=Messages.normalizeValue(MessageTypes.get(secname,j))
|
||||
end
|
||||
f.write("#{j}\r\n")
|
||||
f.write(origValue+"\r\n")
|
||||
f.write(value+"\r\n")
|
||||
end
|
||||
elsif msgs.is_a?(OrderedHash)
|
||||
f.write("[#{secname}]\r\n")
|
||||
keys=msgs.keys
|
||||
for key in keys
|
||||
next if nil_or_empty?(msgs[key])
|
||||
value=Messages.normalizeValue(msgs[key])
|
||||
valkey=Messages.normalizeValue(key)
|
||||
# key is already serialized
|
||||
f.write(valkey+"\r\n")
|
||||
f.write(value+"\r\n")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def messages
|
||||
return @messages || []
|
||||
end
|
||||
|
||||
def extract(outfile)
|
||||
# return if !@messages
|
||||
origMessages=Messages.new("Data/messages.dat")
|
||||
File.open(outfile,"wb") { |f|
|
||||
f.write(0xef.chr)
|
||||
f.write(0xbb.chr)
|
||||
f.write(0xbf.chr)
|
||||
f.write("# To localize this text for a particular language, please\r\n")
|
||||
f.write("# translate every second line of this file.\r\n")
|
||||
if origMessages.messages[0]
|
||||
for i in 0...origMessages.messages[0].length
|
||||
msgs=origMessages.messages[0][i]
|
||||
Messages.writeObject(f,msgs,"Map#{i}",origMessages)
|
||||
end
|
||||
end
|
||||
for i in 1...origMessages.messages.length
|
||||
msgs=origMessages.messages[i]
|
||||
Messages.writeObject(f,msgs,i,origMessages)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def setMessages(type,array)
|
||||
@messages=[] if !@messages
|
||||
arr=[]
|
||||
for i in 0...array.length
|
||||
arr[i]=(array[i]) ? array[i] : ""
|
||||
end
|
||||
@messages[type]=arr
|
||||
end
|
||||
|
||||
def addMessages(type,array)
|
||||
@messages=[] if !@messages
|
||||
arr=(@messages[type]) ? @messages[type] : []
|
||||
for i in 0...array.length
|
||||
arr[i]=(array[i]) ? array[i] : (arr[i]) ? arr[i] : ""
|
||||
end
|
||||
@messages[type]=arr
|
||||
end
|
||||
|
||||
def self.createHash(_type,array)
|
||||
arr=OrderedHash.new
|
||||
for i in 0...array.length
|
||||
if array[i]
|
||||
key=Messages.stringToKey(array[i])
|
||||
arr[key]=array[i]
|
||||
end
|
||||
end
|
||||
return arr
|
||||
end
|
||||
|
||||
def self.addToHash(_type,array,hash)
|
||||
hash=OrderedHash.new if !hash
|
||||
for i in 0...array.length
|
||||
if array[i]
|
||||
key=Messages.stringToKey(array[i])
|
||||
hash[key]=array[i]
|
||||
end
|
||||
end
|
||||
return hash
|
||||
end
|
||||
|
||||
def setMapMessagesAsHash(type,array)
|
||||
@messages=[] if !@messages
|
||||
@messages[0]=[] if !@messages[0]
|
||||
@messages[0][type]=Messages.createHash(type,array)
|
||||
end
|
||||
|
||||
def addMapMessagesAsHash(type,array)
|
||||
@messages=[] if !@messages
|
||||
@messages[0]=[] if !@messages[0]
|
||||
@messages[0][type]=Messages.addToHash(type,array,@messages[0][type])
|
||||
end
|
||||
|
||||
def setMessagesAsHash(type,array)
|
||||
@messages=[] if !@messages
|
||||
@messages[type]=Messages.createHash(type,array)
|
||||
end
|
||||
|
||||
def addMessagesAsHash(type,array)
|
||||
@messages=[] if !@messages
|
||||
@messages[type]=Messages.addToHash(type,array,@messages[type])
|
||||
end
|
||||
|
||||
def saveMessages(filename=nil)
|
||||
filename="Data/messages.dat" if !filename
|
||||
File.open(filename,"wb") { |f| Marshal.dump(@messages,f) }
|
||||
end
|
||||
|
||||
def loadMessageFile(filename)
|
||||
begin
|
||||
pbRgssOpen(filename,"rb") { |f| @messages=Marshal.load(f) }
|
||||
if !@messages.is_a?(Array)
|
||||
@messages=nil
|
||||
raise "Corrupted data"
|
||||
end
|
||||
return @messages
|
||||
rescue
|
||||
@messages=nil
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
def set(type,id,value)
|
||||
delayedLoad
|
||||
return if !@messages
|
||||
return if !@messages[type]
|
||||
@messages[type][id]=value
|
||||
end
|
||||
|
||||
def getCount(type)
|
||||
delayedLoad
|
||||
return 0 if !@messages
|
||||
return 0 if !@messages[type]
|
||||
return @messages[type].length
|
||||
end
|
||||
|
||||
def get(type,id)
|
||||
delayedLoad
|
||||
return "" if !@messages
|
||||
return "" if !@messages[type]
|
||||
return "" if !@messages[type][id]
|
||||
return @messages[type][id]
|
||||
end
|
||||
|
||||
def getFromHash(type,key)
|
||||
delayedLoad
|
||||
return key if !@messages || !@messages[type] || !key
|
||||
id=Messages.stringToKey(key)
|
||||
return key if !@messages[type][id]
|
||||
return @messages[type][id]
|
||||
end
|
||||
|
||||
def getFromMapHash(type,key)
|
||||
delayedLoad
|
||||
return key if !@messages
|
||||
return key if !@messages[0]
|
||||
return key if !@messages[0][type] && !@messages[0][0]
|
||||
id=Messages.stringToKey(key)
|
||||
if @messages[0][type] && @messages[0][type][id]
|
||||
return @messages[0][type][id]
|
||||
elsif @messages[0][0] && @messages[0][0][id]
|
||||
return @messages[0][0][id]
|
||||
end
|
||||
return key
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
module MessageTypes
|
||||
# Value 0 is used for common event and map event text
|
||||
Species = 1
|
||||
Kinds = 2
|
||||
Entries = 3
|
||||
FormNames = 4
|
||||
Moves = 5
|
||||
MoveDescriptions = 6
|
||||
Items = 7
|
||||
ItemPlurals = 8
|
||||
ItemDescriptions = 9
|
||||
Abilities = 10
|
||||
AbilityDescs = 11
|
||||
Types = 12
|
||||
TrainerTypes = 13
|
||||
TrainerNames = 14
|
||||
BeginSpeech = 15
|
||||
EndSpeechWin = 16
|
||||
EndSpeechLose = 17
|
||||
RegionNames = 18
|
||||
PlaceNames = 19
|
||||
PlaceDescriptions = 20
|
||||
MapNames = 21
|
||||
PhoneMessages = 22
|
||||
TrainerLoseText = 23
|
||||
ScriptTexts = 24
|
||||
RibbonNames = 25
|
||||
RibbonDescriptions = 26
|
||||
@@messages = Messages.new
|
||||
@@messagesFallback = Messages.new("Data/messages.dat",true)
|
||||
|
||||
def self.stringToKey(str)
|
||||
return Messages.stringToKey(str)
|
||||
end
|
||||
|
||||
def self.normalizeValue(value)
|
||||
return Messages.normalizeValue(value)
|
||||
end
|
||||
|
||||
def self.denormalizeValue(value)
|
||||
Messages.denormalizeValue(value)
|
||||
end
|
||||
|
||||
def self.writeObject(f,msgs,secname)
|
||||
Messages.denormalizeValue(str)
|
||||
end
|
||||
|
||||
def self.extract(outfile)
|
||||
@@messages.extract(outfile)
|
||||
end
|
||||
|
||||
def self.setMessages(type,array)
|
||||
@@messages.setMessages(type,array)
|
||||
end
|
||||
|
||||
def self.addMessages(type,array)
|
||||
@@messages.addMessages(type,array)
|
||||
end
|
||||
|
||||
def self.createHash(type,array)
|
||||
Messages.createHash(type,array)
|
||||
end
|
||||
|
||||
def self.addMapMessagesAsHash(type,array)
|
||||
@@messages.addMapMessagesAsHash(type,array)
|
||||
end
|
||||
|
||||
def self.setMapMessagesAsHash(type,array)
|
||||
@@messages.setMapMessagesAsHash(type,array)
|
||||
end
|
||||
|
||||
def self.addMessagesAsHash(type,array)
|
||||
@@messages.addMessagesAsHash(type,array)
|
||||
end
|
||||
|
||||
def self.setMessagesAsHash(type,array)
|
||||
@@messages.setMessagesAsHash(type,array)
|
||||
end
|
||||
|
||||
def self.saveMessages(filename=nil)
|
||||
@@messages.saveMessages(filename)
|
||||
end
|
||||
|
||||
def self.loadMessageFile(filename)
|
||||
@@messages.loadMessageFile(filename)
|
||||
end
|
||||
|
||||
def self.get(type,id)
|
||||
ret=@@messages.get(type,id)
|
||||
if ret==""
|
||||
ret=@@messagesFallback.get(type,id)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def self.getCount(type)
|
||||
c1=@@messages.getCount(type)
|
||||
c2=@@messagesFallback.getCount(type)
|
||||
return c1>c2 ? c1 : c2
|
||||
end
|
||||
|
||||
def self.getOriginal(type,id)
|
||||
return @@messagesFallback.get(type,id)
|
||||
end
|
||||
|
||||
def self.getFromHash(type,key)
|
||||
@@messages.getFromHash(type,key)
|
||||
end
|
||||
|
||||
def self.getFromMapHash(type,key)
|
||||
@@messages.getFromMapHash(type,key)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def pbLoadMessages(file)
|
||||
return MessageTypes.loadMessageFile(file)
|
||||
end
|
||||
|
||||
def pbGetMessageCount(type)
|
||||
return MessageTypes.getCount(type)
|
||||
end
|
||||
|
||||
def pbGetMessage(type,id)
|
||||
return MessageTypes.get(type,id)
|
||||
end
|
||||
|
||||
def pbGetMessageFromHash(type,id)
|
||||
return MessageTypes.getFromHash(type,id)
|
||||
end
|
||||
|
||||
# Replaces first argument with a localized version and formats the other
|
||||
# parameters by replacing {1}, {2}, etc. with those placeholders.
|
||||
def _INTL(*arg)
|
||||
begin
|
||||
string=MessageTypes.getFromHash(MessageTypes::ScriptTexts,arg[0])
|
||||
rescue
|
||||
string=arg[0]
|
||||
end
|
||||
string=string.clone
|
||||
for i in 1...arg.length
|
||||
string.gsub!(/\{#{i}\}/,"#{arg[i]}")
|
||||
end
|
||||
return string
|
||||
end
|
||||
|
||||
# Replaces first argument with a localized version and formats the other
|
||||
# parameters by replacing {1}, {2}, etc. with those placeholders.
|
||||
# This version acts more like sprintf, supports e.g. {1:d} or {2:s}
|
||||
def _ISPRINTF(*arg)
|
||||
begin
|
||||
string=MessageTypes.getFromHash(MessageTypes::ScriptTexts,arg[0])
|
||||
rescue
|
||||
string=arg[0]
|
||||
end
|
||||
string=string.clone
|
||||
for i in 1...arg.length
|
||||
string.gsub!(/\{#{i}\:([^\}]+?)\}/) { |m|
|
||||
next sprintf("%"+$1,arg[i])
|
||||
}
|
||||
end
|
||||
return string
|
||||
end
|
||||
|
||||
def _I(str)
|
||||
return _MAPINTL($game_map.map_id,str)
|
||||
end
|
||||
|
||||
def _MAPINTL(mapid,*arg)
|
||||
string=MessageTypes.getFromMapHash(mapid,arg[0])
|
||||
string=string.clone
|
||||
for i in 1...arg.length
|
||||
string.gsub!(/\{#{i}\}/,"#{arg[i]}")
|
||||
end
|
||||
return string
|
||||
end
|
||||
|
||||
def _MAPISPRINTF(mapid,*arg)
|
||||
string=MessageTypes.getFromMapHash(mapid,arg[0])
|
||||
string=string.clone
|
||||
for i in 1...arg.length
|
||||
string.gsub!(/\{#{i}\:([^\}]+?)\}/) { |m|
|
||||
next sprintf("%"+$1,arg[i])
|
||||
}
|
||||
end
|
||||
return string
|
||||
end
|
||||
33
Data/Scripts_backup/001_Technical/004_Input.rb
Normal file
33
Data/Scripts_backup/001_Technical/004_Input.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
module Input
|
||||
USE = C
|
||||
BACK = B
|
||||
ACTION = A
|
||||
JUMPUP = X
|
||||
JUMPDOWN = Y
|
||||
SPECIAL = Z
|
||||
AUX1 = L
|
||||
AUX2 = R
|
||||
|
||||
unless defined?(update_KGC_ScreenCapture)
|
||||
class << Input
|
||||
alias update_KGC_ScreenCapture update
|
||||
end
|
||||
end
|
||||
|
||||
def self.update
|
||||
update_KGC_ScreenCapture
|
||||
if trigger?(Input::F8)
|
||||
pbScreenCapture
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Mouse
|
||||
module_function
|
||||
|
||||
# Returns the position of the mouse relative to the game window.
|
||||
def getMousePos(catch_anywhere = false)
|
||||
return nil unless System.mouse_in_window || catch_anywhere
|
||||
return Input.mouse_x, Input.mouse_y
|
||||
end
|
||||
end
|
||||
711
Data/Scripts_backup/001_Technical/005_PluginManager.rb
Normal file
711
Data/Scripts_backup/001_Technical/005_PluginManager.rb
Normal file
@@ -0,0 +1,711 @@
|
||||
#==============================================================================#
|
||||
# Plugin Manager #
|
||||
# by Marin #
|
||||
# support for external plugin scripts by Luka S.J. #
|
||||
# tweaked by Maruno #
|
||||
#------------------------------------------------------------------------------#
|
||||
# Provides a simple interface that allows plugins to require dependencies #
|
||||
# at specific versions, and to specify incompatibilities between plugins. #
|
||||
# #
|
||||
# Supports external scripts that are in .rb files in folders within the #
|
||||
# Plugins folder. #
|
||||
#------------------------------------------------------------------------------#
|
||||
# Usage: #
|
||||
# #
|
||||
# A Pokémon Essentials plugin should register itself using the PluginManager. #
|
||||
# The simplest way to do so, for a plugin without dependencies, is as follows: #
|
||||
# #
|
||||
# PluginManager.register({ #
|
||||
# :name => "Basic Plugin", #
|
||||
# :version => "1.0", #
|
||||
# :link => "https://reliccastle.com/link-to-the-plugin/", #
|
||||
# :credits => "Marin" #
|
||||
# }) #
|
||||
# #
|
||||
# The link portion here is optional, but recommended. This will be shown in #
|
||||
# the error message if the PluginManager detects that this plugin needs to be #
|
||||
# updated. #
|
||||
# #
|
||||
# A plugin's version should be in the format X.Y.Z, but the number of digits #
|
||||
# you use does not matter. You can also use Xa, Xb, Xc, Ya, etc. #
|
||||
# What matters is that you use it consistently, so that it can be compared. #
|
||||
# #
|
||||
# IF there are multiple people to credit, their names should be in an array. #
|
||||
# If there is only one credit, it does not need an array: #
|
||||
# #
|
||||
# :credits => "Marin" #
|
||||
# :credits => ["Marin", "Maruno"], #
|
||||
# #
|
||||
# #
|
||||
# #
|
||||
# Dependency: #
|
||||
# #
|
||||
# A plugin can require another plugin to be installed in order to work. For #
|
||||
# example, the "Simple Extension" plugin depends on the above "Basic Plugin" #
|
||||
# like so: #
|
||||
# #
|
||||
# PluginManager.register({ #
|
||||
# :name => "Simple Extension", #
|
||||
# :version => "1.0", #
|
||||
# :link => "https://reliccastle.com/link-to-the-plugin/", #
|
||||
# :credits => ["Marin", "Maruno"], #
|
||||
# :dependencies => ["Basic Plugin"] #
|
||||
# }) #
|
||||
# #
|
||||
# If there are multiple dependencies, they should be listed in an array. If #
|
||||
# there is only one dependency, it does not need an array: #
|
||||
# #
|
||||
# :dependencies => "Basic Plugin" #
|
||||
# #
|
||||
# To require a minimum version of a dependency plugin, you should turn the #
|
||||
# dependency's name into an array which contains the name and the version #
|
||||
# (both as strings). For example, to require "Basic Plugin" version 1.2 or #
|
||||
# higher, you would write: #
|
||||
# #
|
||||
# :dependencies => [ #
|
||||
# ["Basic Plugin", "1.2"] #
|
||||
# ] #
|
||||
# #
|
||||
# To require a specific version (no higher and no lower) of a dependency #
|
||||
# plugin, you should add the :exact flag as the first thing in the array for #
|
||||
# that dependency: #
|
||||
# #
|
||||
# :dependencies => [ #
|
||||
# [:exact, "Basic Plugin", "1.2"] #
|
||||
# ] #
|
||||
# #
|
||||
# If your plugin can work without another plugin, but it is incompatible with #
|
||||
# an old version of that other plugin, you should list it as an optional #
|
||||
# dependency. If that other plugin is present in a game, then this optional #
|
||||
# dependency will check whether it meets the minimum version required for your #
|
||||
# plugin. Write it in the same way as any other dependency as described above, #
|
||||
# but use the :optional flag instead. #
|
||||
# #
|
||||
# :dependencies => [ #
|
||||
# [:optional, "QoL Improvements", "1.1"] #
|
||||
# ] #
|
||||
# #
|
||||
# The :optional_exact flag is a combination of :optional and :exact. #
|
||||
# #
|
||||
# #
|
||||
# #
|
||||
# Incompatibility: #
|
||||
# #
|
||||
# If your plugin is known to be incompatible with another plugin, you should #
|
||||
# list that other plugin as such. Only one of the two plugins needs to list #
|
||||
# that it is incompatible with the other. #
|
||||
# #
|
||||
# PluginManager.register({ #
|
||||
# :name => "QoL Improvements", #
|
||||
# :version => "1.0", #
|
||||
# :link => "https://reliccastle.com/link-to-the-plugin/", #
|
||||
# :credits => "Marin", #
|
||||
# :incompatibilities => [ #
|
||||
# "Simple Extension" #
|
||||
# ] #
|
||||
# }) #
|
||||
# #
|
||||
#------------------------------------------------------------------------------#
|
||||
# Plugin folder: #
|
||||
# #
|
||||
# The Plugin folder is treated like the PBS folder, but for script files for #
|
||||
# plugins. Each plugin has its own folder within the Plugin folder. Each #
|
||||
# plugin must have a meta.txt file in its folder, which contains information #
|
||||
# about that plugin. Folders without this meta.txt file are ignored. #
|
||||
# #
|
||||
# Scripts must be in .rb files. You should not put any other files into a #
|
||||
# plugin's folder except for script files and meta.txt. #
|
||||
# #
|
||||
# When the game is compiled, scripts in these folders are read and converted #
|
||||
# into a usable format, and saved in the file Data/PluginScripts.rxdata. #
|
||||
# Script files are loaded in order of their name and subfolder, so it is wise #
|
||||
# to name script files "001_first script.rb", "002_second script.rb", etc. to #
|
||||
# ensure they are loaded in the correct order. #
|
||||
# #
|
||||
# When the game is compressed for distribution, the Plugin folder and all its #
|
||||
# contents should be deleted (like the PBS folder), because its contents will #
|
||||
# be unused (they will have been compiled into the PluginScripts.rxdata file). #
|
||||
# #
|
||||
# The contents of meta.txt are as follows: #
|
||||
# #
|
||||
# Name = Simple Extension #
|
||||
# Version = 1.0 #
|
||||
# Requires = Basic Plugin #
|
||||
# Requires = Useful Utilities,1.1 #
|
||||
# Conflicts = Complex Extension #
|
||||
# Conflicts = Extended Windows #
|
||||
# Link = https://reliccastle.com/link-to-the-plugin/ #
|
||||
# Credits = Luka S.J.,Maruno,Marin #
|
||||
# #
|
||||
# These lines are related to what is described above. You can have multiple #
|
||||
# "Requires" and "Conflicts" lines, each listing a single other plugin that is #
|
||||
# either a dependency or a conflict respectively. #
|
||||
# #
|
||||
# Examples of the "Requires" line: #
|
||||
# #
|
||||
# Requires = Basic Plugin #
|
||||
# Requires = Basic Plugin,1.1 #
|
||||
# Requires = Basic Plugin,1.1,exact #
|
||||
# Requires = Basic Plugin,1.1,optional #
|
||||
# Exact = Basic Plugin,1.1 #
|
||||
# Optional = Basic Plugin,1.1 #
|
||||
# #
|
||||
# The "Exact" and "Optional" lines are equivalent to the "Requires" lines #
|
||||
# that contain those keywords. #
|
||||
# #
|
||||
# There is also a "Scripts" line, which lists one or more script files that #
|
||||
# should be loaded first. You can have multiple "Scripts" lines. However, you #
|
||||
# can achieve the same effect by simply naming your script files in #
|
||||
# alphanumeric order to make them load in a particular order, so the "Scripts" #
|
||||
# line should not be necessary. #
|
||||
# #
|
||||
#------------------------------------------------------------------------------#
|
||||
# Please give credit when using this. #
|
||||
#==============================================================================#
|
||||
|
||||
module PluginManager
|
||||
# Holds all registered plugin data.
|
||||
@@Plugins = {}
|
||||
#-----------------------------------------------------------------------------
|
||||
# Registers a plugin and tests its dependencies and incompatibilities.
|
||||
#-----------------------------------------------------------------------------
|
||||
def self.register(options)
|
||||
name = nil
|
||||
version = nil
|
||||
link = nil
|
||||
dependencies = nil
|
||||
incompats = nil
|
||||
credits = []
|
||||
order = [:name, :version, :link, :dependencies, :incompatibilities, :credits]
|
||||
# Ensure it first reads the plugin's name, which is used in error reporting,
|
||||
# by sorting the keys
|
||||
keys = options.keys.sort do |a, b|
|
||||
idx_a = order.index(a)
|
||||
idx_a = order.size if idx_a == -1
|
||||
idx_b = order.index(b)
|
||||
idx_b = order.size if idx_b == -1
|
||||
next idx_a <=> idx_b
|
||||
end
|
||||
for key in keys
|
||||
value = options[key]
|
||||
case key
|
||||
when :name # Plugin name
|
||||
if nil_or_empty?(value)
|
||||
self.error("Plugin name must be a non-empty string.")
|
||||
end
|
||||
if !@@Plugins[value].nil?
|
||||
self.error("A plugin called '#{value}' already exists.")
|
||||
end
|
||||
name = value
|
||||
when :version # Plugin version
|
||||
if nil_or_empty?(value)
|
||||
self.error("Plugin version must be a string.")
|
||||
end
|
||||
version = value
|
||||
when :link # Plugin website
|
||||
if nil_or_empty?(value)
|
||||
self.error("Plugin link must be a non-empty string.")
|
||||
end
|
||||
link = value
|
||||
when :dependencies # Plugin dependencies
|
||||
dependencies = value
|
||||
dependencies = [dependencies] if !dependencies.is_a?(Array) || !dependencies[0].is_a?(Array)
|
||||
for dep in value
|
||||
if dep.is_a?(String) # "plugin name"
|
||||
if !self.installed?(dep)
|
||||
self.error("Plugin '#{name}' requires plugin '#{dep}' to be installed above it.")
|
||||
end
|
||||
elsif dep.is_a?(Array)
|
||||
case dep.size
|
||||
when 1 # ["plugin name"]
|
||||
if dep[0].is_a?(String)
|
||||
dep_name = dep[0]
|
||||
if !self.installed?(dep_name)
|
||||
self.error("Plugin '#{name}' requires plugin '#{dep_name}' to be installed above it.")
|
||||
end
|
||||
else
|
||||
self.error("Expected the plugin name as a string, but got #{dep[0].inspect}.")
|
||||
end
|
||||
when 2 # ["plugin name", "version"]
|
||||
if dep[0].is_a?(Symbol)
|
||||
self.error("A plugin version comparator symbol was given but no version was given.")
|
||||
elsif dep[0].is_a?(String) && dep[1].is_a?(String)
|
||||
dep_name = dep[0]
|
||||
dep_version = dep[1]
|
||||
next if self.installed?(dep_name, dep_version)
|
||||
if self.installed?(dep_name) # Have plugin but lower version
|
||||
msg = "Plugin '#{name}' requires plugin '#{dep_name}' version #{dep_version} or higher, " +
|
||||
"but the installed version is #{self.version(dep_name)}."
|
||||
if dep_link = self.link(dep_name)
|
||||
msg += "\r\nCheck #{dep_link} for an update to plugin '#{dep_name}'."
|
||||
end
|
||||
self.error(msg)
|
||||
else # Don't have plugin
|
||||
self.error("Plugin '#{name}' requires plugin '#{dep_name}' version #{dep_version} " +
|
||||
"or higher to be installed above it.")
|
||||
end
|
||||
end
|
||||
when 3 # [:optional/:exact/:optional_exact, "plugin name", "version"]
|
||||
if !dep[0].is_a?(Symbol)
|
||||
self.error("Expected first dependency argument to be a symbol, but got #{dep[0].inspect}.")
|
||||
end
|
||||
if !dep[1].is_a?(String)
|
||||
self.error("Expected second dependency argument to be a plugin name, but got #{dep[1].inspect}.")
|
||||
end
|
||||
if !dep[2].is_a?(String)
|
||||
self.error("Expected third dependency argument to be the plugin version, but got #{dep[2].inspect}.")
|
||||
end
|
||||
dep_arg = dep[0]
|
||||
dep_name = dep[1]
|
||||
dep_version = dep[2]
|
||||
optional = false
|
||||
exact = false
|
||||
case dep_arg
|
||||
when :optional
|
||||
optional = true
|
||||
when :exact
|
||||
exact = true
|
||||
when :optional_exact
|
||||
optional = true
|
||||
exact = true
|
||||
else
|
||||
self.error("Expected first dependency argument to be one of " +
|
||||
":optional, :exact or :optional_exact, but got #{dep_arg.inspect}.")
|
||||
end
|
||||
if optional
|
||||
if self.installed?(dep_name) && # Have plugin but lower version
|
||||
!self.installed?(dep_name, dep_version, exact)
|
||||
msg = "Plugin '#{name}' requires plugin '#{dep_name}', if installed, to be version #{dep_version}"
|
||||
msg << " or higher" if !exact
|
||||
msg << ", but the installed version was #{self.version(dep_name)}."
|
||||
if dep_link = self.link(dep_name)
|
||||
msg << "\r\nCheck #{dep_link} for an update to plugin '#{dep_name}'."
|
||||
end
|
||||
self.error(msg)
|
||||
end
|
||||
elsif !self.installed?(dep_name, dep_version, exact)
|
||||
if self.installed?(dep_name) # Have plugin but lower version
|
||||
msg = "Plugin '#{name}' requires plugin '#{dep_name}' to be version #{dep_version}"
|
||||
msg << " or later" if !exact
|
||||
msg << ", but the installed version was #{self.version(dep_name)}."
|
||||
if dep_link = self.link(dep_name)
|
||||
msg << "\r\nCheck #{dep_link} for an update to plugin '#{dep_name}'."
|
||||
end
|
||||
self.error(msg)
|
||||
else # Don't have plugin
|
||||
msg = "Plugin '#{name}' requires plugin '#{dep_name}' version #{dep_version} "
|
||||
msg << "or later" if !exact
|
||||
msg << "to be installed above it."
|
||||
self.error(msg)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
when :incompatibilities # Plugin incompatibilities
|
||||
incompats = value
|
||||
incompats = [incompats] if !incompats.is_a?(Array)
|
||||
for incompat in incompats
|
||||
if self.installed?(incompat)
|
||||
self.error("Plugin '#{name}' is incompatible with '#{incompat}'. " +
|
||||
"They cannot both be used at the same time.")
|
||||
end
|
||||
end
|
||||
when :credits # Plugin credits
|
||||
value = [value] if value.is_a?(String)
|
||||
if value.is_a?(Array)
|
||||
for entry in value
|
||||
if !entry.is_a?(String)
|
||||
self.error("Plugin '#{name}'s credits array contains a non-string value.")
|
||||
else
|
||||
credits << entry
|
||||
end
|
||||
end
|
||||
else
|
||||
self.error("Plugin '#{name}'s credits field must contain a string, or a string array.")
|
||||
end
|
||||
else
|
||||
self.error("Invalid plugin registry key '#{key}'.")
|
||||
end
|
||||
end
|
||||
for plugin in @@Plugins.values
|
||||
if plugin[:incompatibilities] && plugin[:incompatibilities].include?(name)
|
||||
self.error("Plugin '#{plugin[:name]}' is incompatible with '#{name}'. " +
|
||||
"They cannot both be used at the same time.")
|
||||
end
|
||||
end
|
||||
# Add plugin to class variable
|
||||
@@Plugins[name] = {
|
||||
:name => name,
|
||||
:version => version,
|
||||
:link => link,
|
||||
:dependencies => dependencies,
|
||||
:incompatibilities => incompats,
|
||||
:credits => credits
|
||||
}
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# Throws a pure error message without stack trace or any other useless info.
|
||||
#-----------------------------------------------------------------------------
|
||||
def self.error(msg)
|
||||
Graphics.update
|
||||
t = Thread.new do
|
||||
echoln "Plugin Error:\r\n#{msg}"
|
||||
p "Plugin Error: #{msg}"
|
||||
Thread.exit
|
||||
end
|
||||
while t.status
|
||||
Graphics.update
|
||||
end
|
||||
Kernel.exit! true
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# Returns true if the specified plugin is installed.
|
||||
# If the version is specified, this version is taken into account.
|
||||
# If mustequal is true, the version must be a match with the specified version.
|
||||
#-----------------------------------------------------------------------------
|
||||
def self.installed?(plugin_name, plugin_version = nil, mustequal = false)
|
||||
plugin = @@Plugins[plugin_name]
|
||||
return false if plugin.nil?
|
||||
return true if plugin_version.nil?
|
||||
comparison = compare_versions(plugin[:version], plugin_version)
|
||||
return true if !mustequal && comparison >= 0
|
||||
return true if mustequal && comparison == 0
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# Returns the string names of all installed plugins.
|
||||
#-----------------------------------------------------------------------------
|
||||
def self.plugins
|
||||
return @@Plugins.keys
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# Returns the installed version of the specified plugin.
|
||||
#-----------------------------------------------------------------------------
|
||||
def self.version(plugin_name)
|
||||
return if !installed?(plugin_name)
|
||||
return @@Plugins[plugin_name][:version]
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# Returns the link of the specified plugin.
|
||||
#-----------------------------------------------------------------------------
|
||||
def self.link(plugin_name)
|
||||
return if !installed?(plugin_name)
|
||||
return @@Plugins[plugin_name][:link]
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# Returns the credits of the specified plugin.
|
||||
#-----------------------------------------------------------------------------
|
||||
def self.credits(plugin_name)
|
||||
return if !installed?(plugin_name)
|
||||
return @@Plugins[plugin_name][:credits]
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# Compares two versions given in string form. v1 should be the plugin version
|
||||
# you actually have, and v2 should be the minimum/desired plugin version.
|
||||
# Return values:
|
||||
# 1 if v1 is higher than v2
|
||||
# 0 if v1 is equal to v2
|
||||
# -1 if v1 is lower than v2
|
||||
#-----------------------------------------------------------------------------
|
||||
def self.compare_versions(v1, v2)
|
||||
d1 = v1.split("")
|
||||
d1.insert(0, "0") if d1[0] == "." # Turn ".123" into "0.123"
|
||||
while d1[-1] == "."; d1 = d1[0..-2]; end # Turn "123." into "123"
|
||||
d2 = v2.split("")
|
||||
d2.insert(0, "0") if d2[0] == "." # Turn ".123" into "0.123"
|
||||
while d2[-1] == "."; d2 = d2[0..-2]; end # Turn "123." into "123"
|
||||
for i in 0...[d1.size, d2.size].max # Compare each digit in turn
|
||||
c1 = d1[i]
|
||||
c2 = d2[i]
|
||||
if c1
|
||||
return 1 if !c2
|
||||
return 1 if c1.to_i(16) > c2.to_i(16)
|
||||
return -1 if c1.to_i(16) < c2.to_i(16)
|
||||
else
|
||||
return -1 if c2
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# formats the error message
|
||||
#-----------------------------------------------------------------------------
|
||||
def self.pluginErrorMsg(name, script)
|
||||
# begin message formatting
|
||||
message = "[Pokémon Essentials version #{Essentials::VERSION}]\r\n"
|
||||
message += "#{Essentials::ERROR_TEXT}\r\n" # For third party scripts to add to
|
||||
message += "Error in Plugin [#{name}]:\r\n"
|
||||
message += "#{$!.class} occurred.\r\n"
|
||||
# go through message content
|
||||
for line in $!.message.split("\r\n")
|
||||
next if nil_or_empty?(line)
|
||||
n = line[/\d+/]
|
||||
err = line.split(":")[-1].strip
|
||||
lms = line.split(":")[0].strip
|
||||
err.gsub!(n, "") if n
|
||||
err = err.capitalize if err.is_a?(String) && !err.empty?
|
||||
linum = n ? "Line #{n}: " : ""
|
||||
message += "#{linum}#{err}: #{lms}\r\n"
|
||||
end
|
||||
# show last 10 lines of backtrace
|
||||
message += "\r\nBacktrace:\r\n"
|
||||
$!.backtrace[0, 10].each { |i| message += "#{i}\r\n" }
|
||||
# output to log
|
||||
errorlog = "errorlog.txt"
|
||||
errorlog = RTP.getSaveFileName("errorlog.txt") if (Object.const_defined?(:RTP) rescue false)
|
||||
File.open(errorlog, "ab") do |f|
|
||||
f.write("\r\n=================\r\n\r\n[#{Time.now}]\r\n")
|
||||
f.write(message)
|
||||
end
|
||||
# format/censor the error log directory
|
||||
errorlogline = errorlog.gsub("/", "\\")
|
||||
errorlogline.sub!(Dir.pwd + "\\", "")
|
||||
errorlogline.sub!(pbGetUserName, "USERNAME")
|
||||
errorlogline = "\r\n" + errorlogline if errorlogline.length > 20
|
||||
# output message
|
||||
print("#{message}\r\nThis exception was logged in #{errorlogline}.\r\nHold Ctrl when closing this message to copy it to the clipboard.")
|
||||
# Give a ~500ms coyote time to start holding Control
|
||||
t = System.delta
|
||||
until (System.delta - t) >= 500000
|
||||
Input.update
|
||||
if Input.press?(Input::CTRL)
|
||||
Input.clipboard = message
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# Used to read the metadata file
|
||||
#-----------------------------------------------------------------------------
|
||||
def self.readMeta(dir, file)
|
||||
filename = "#{dir}/#{file}"
|
||||
meta = {}
|
||||
# read file
|
||||
Compiler.pbCompilerEachPreppedLine(filename) { |line, line_no|
|
||||
# split line up into property name and values
|
||||
if !line[/^\s*(\w+)\s*=\s*(.*)$/]
|
||||
raise _INTL("Bad line syntax (expected syntax like XXX=YYY)\r\n{1}", FileLineData.linereport)
|
||||
end
|
||||
property = $~[1].upcase
|
||||
data = $~[2].split(',')
|
||||
data.each_with_index { |value, i| data[i] = value.strip }
|
||||
# begin formatting data hash
|
||||
case property
|
||||
when 'REQUIRES'
|
||||
meta[:dependencies] = [] if !meta[:dependencies]
|
||||
if data.length < 2 # No version given, just push name of plugin dependency
|
||||
meta[:dependencies].push(data[0])
|
||||
next
|
||||
elsif data.length == 2 # Push name and version of plugin dependency
|
||||
meta[:dependencies].push([data[0], data[1]])
|
||||
else # Push dependency type, name and version of plugin dependency
|
||||
meta[:dependencies].push([data[2].downcase.to_sym, data[0], data[1]])
|
||||
end
|
||||
when 'EXACT'
|
||||
next if data.length < 2 # Exact dependencies must have a version given; ignore if not
|
||||
meta[:dependencies] = [] if !meta[:dependencies]
|
||||
meta[:dependencies].push([:exact, data[0], data[1]])
|
||||
when 'OPTIONAL'
|
||||
next if data.length < 2 # Optional dependencies must have a version given; ignore if not
|
||||
meta[:dependencies] = [] if !meta[:dependencies]
|
||||
meta[:dependencies].push([:optional, data[0], data[1]])
|
||||
when 'CONFLICTS'
|
||||
meta[:incompatibilities] = [] if !meta[:incompatibilities]
|
||||
data.each { |value| meta[:incompatibilities].push(value) if value && !value.empty? }
|
||||
when 'SCRIPTS'
|
||||
meta[:scripts] = [] if !meta[:scripts]
|
||||
data.each { |scr| meta[:scripts].push(scr) }
|
||||
when 'CREDITS'
|
||||
meta[:credits] = data
|
||||
when 'LINK', 'WEBSITE'
|
||||
meta[:link] = data[0]
|
||||
else
|
||||
meta[property.downcase.to_sym] = data[0]
|
||||
end
|
||||
}
|
||||
# generate a list of all script files to be loaded, in the order they are to
|
||||
# be loaded (files listed in the meta file are loaded first)
|
||||
meta[:scripts] = [] if !meta[:scripts]
|
||||
# get all script files from plugin Dir
|
||||
for fl in Dir.all(dir)
|
||||
next if !fl.include?(".rb")
|
||||
meta[:scripts].push(fl.gsub("#{dir}/", ""))
|
||||
end
|
||||
# ensure no duplicate script files are queued
|
||||
meta[:scripts].uniq!
|
||||
# return meta hash
|
||||
return meta
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# Get a list of all the plugin directories to inspect
|
||||
#-----------------------------------------------------------------------------
|
||||
def self.listAll
|
||||
return [] if !$DEBUG || safeExists?("Game.rgssad")
|
||||
# get a list of all directories in the `Plugins/` folder
|
||||
dirs = []
|
||||
Dir.get("Plugins").each { |d| dirs.push(d) if Dir.safe?(d) }
|
||||
# return all plugins
|
||||
return dirs
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# Catch any potential loop with dependencies and raise an error
|
||||
#-----------------------------------------------------------------------------
|
||||
def self.validateDependencies(name, meta, og = nil)
|
||||
# exit if no registered dependency
|
||||
return nil if !meta[name] || !meta[name][:dependencies]
|
||||
og = [name] if !og
|
||||
# go through all dependencies
|
||||
for dname in meta[name][:dependencies]
|
||||
# clean the name to a simple string
|
||||
dname = dname[0] if dname.is_a?(Array) && dname.length == 2
|
||||
dname = dname[1] if dname.is_a?(Array) && dname.length == 3
|
||||
# catch looping dependency issue
|
||||
self.error("Plugin '#{og[0]}' has looping dependencies which cannot be resolved automatically.") if !og.nil? && og.include?(dname)
|
||||
new_og = og.clone
|
||||
new_og.push(dname)
|
||||
self.validateDependencies(dname, meta, new_og)
|
||||
end
|
||||
return name
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# Sort load order based on dependencies (this ends up in reverse order)
|
||||
#-----------------------------------------------------------------------------
|
||||
def self.sortLoadOrder(order, plugins)
|
||||
# go through the load order
|
||||
for o in order
|
||||
next if !plugins[o] || !plugins[o][:dependencies]
|
||||
# go through all dependencies
|
||||
for dname in plugins[o][:dependencies]
|
||||
# clean the name to a simple string
|
||||
dname = dname[0] if dname.is_a?(Array) && dname.length == 2
|
||||
dname = dname[1] if dname.is_a?(Array) && dname.length == 3
|
||||
# catch missing dependency
|
||||
self.error("Plugin '#{o}' requires plugin '#{dname}' to work properly.") if !order.include?(dname)
|
||||
# skip if already sorted
|
||||
next if order.index(dname) > order.index(o)
|
||||
# catch looping dependency issue
|
||||
order.swap(o, dname)
|
||||
order = self.sortLoadOrder(order, plugins)
|
||||
end
|
||||
end
|
||||
return order
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# Get the order in which to load plugins
|
||||
#-----------------------------------------------------------------------------
|
||||
def self.getPluginOrder
|
||||
plugins = {}
|
||||
order = []
|
||||
# Find all plugin folders that have a meta.txt and add them to the list of
|
||||
# plugins.
|
||||
for dir in self.listAll
|
||||
# skip if there is no meta file
|
||||
next if !safeExists?(dir + "/meta.txt")
|
||||
ndx = order.length
|
||||
meta = self.readMeta(dir, "meta.txt")
|
||||
meta[:dir] = dir
|
||||
# raise error if no name defined for plugin
|
||||
self.error("No 'Name' metadata defined for plugin located at '#{dir}'.") if !meta[:name]
|
||||
# raise error if no script defined for plugin
|
||||
self.error("No 'Scripts' metadata defined for plugin located at '#{dir}'.") if !meta[:scripts]
|
||||
plugins[meta[:name]] = meta
|
||||
# raise error if a plugin with the same name already exists
|
||||
self.error("A plugin called '#{meta[:name]}' already exists in the load order.") if order.include?(meta[:name])
|
||||
order.insert(ndx, meta[:name])
|
||||
end
|
||||
# validate all dependencies
|
||||
order.each { |o| self.validateDependencies(o, plugins) }
|
||||
# sort the load order
|
||||
return self.sortLoadOrder(order, plugins).reverse, plugins
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# Check if plugins need compiling
|
||||
#-----------------------------------------------------------------------------
|
||||
def self.needCompiling?(order, plugins)
|
||||
# fixed actions
|
||||
return false if !$DEBUG || safeExists?("Game.rgssad")
|
||||
return true if !safeExists?("Data/PluginScripts.rxdata")
|
||||
Input.update
|
||||
return true if Input.press?(Input::CTRL)
|
||||
# analyze whether or not to push recompile
|
||||
mtime = File.mtime("Data/PluginScripts.rxdata")
|
||||
for o in order
|
||||
# go through all the registered plugin scripts
|
||||
scr = plugins[o][:scripts]
|
||||
dir = plugins[o][:dir]
|
||||
for sc in scr
|
||||
return true if File.mtime("#{dir}/#{sc}") > mtime
|
||||
end
|
||||
return true if File.mtime("#{dir}/meta.txt") > mtime
|
||||
end
|
||||
return false
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# Check if plugins need compiling
|
||||
#-----------------------------------------------------------------------------
|
||||
def self.compilePlugins(order, plugins)
|
||||
echo 'Compiling plugin scripts...'
|
||||
scripts = []
|
||||
# go through the entire order one by one
|
||||
for o in order
|
||||
# save name, metadata and scripts array
|
||||
meta = plugins[o].clone
|
||||
meta.delete(:scripts)
|
||||
meta.delete(:dir)
|
||||
dat = [o, meta, []]
|
||||
# iterate through each file to deflate
|
||||
for file in plugins[o][:scripts]
|
||||
File.open("#{plugins[o][:dir]}/#{file}", 'rb') do |f|
|
||||
dat[2].push([file, Zlib::Deflate.deflate(f.read)])
|
||||
end
|
||||
end
|
||||
# push to the main scripts array
|
||||
scripts.push(dat)
|
||||
end
|
||||
# save to main `PluginScripts.rxdata` file
|
||||
File.open("Data/PluginScripts.rxdata", 'wb') { |f| Marshal.dump(scripts, f) }
|
||||
# collect garbage
|
||||
GC.start
|
||||
echoln ' done.'
|
||||
echoln ''
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# Check if plugins need compiling
|
||||
#-----------------------------------------------------------------------------
|
||||
def self.runPlugins
|
||||
# get the order of plugins to interpret
|
||||
order, plugins = self.getPluginOrder
|
||||
# compile if necessary
|
||||
self.compilePlugins(order, plugins) if self.needCompiling?(order, plugins)
|
||||
# load plugins
|
||||
scripts = load_data("Data/PluginScripts.rxdata")
|
||||
echoed_plugins = []
|
||||
for plugin in scripts
|
||||
# get the required data
|
||||
name, meta, script = plugin
|
||||
# register plugin
|
||||
self.register(meta)
|
||||
# go through each script and interpret
|
||||
for scr in script
|
||||
# turn code into plaintext
|
||||
code = Zlib::Inflate.inflate(scr[1]).force_encoding(Encoding::UTF_8)
|
||||
# get rid of tabs
|
||||
code.gsub!("\t", " ")
|
||||
# construct filename
|
||||
sname = scr[0].gsub("\\","/").split("/")[-1]
|
||||
fname = "[#{name}] #{sname}"
|
||||
# try to run the code
|
||||
begin
|
||||
eval(code, TOPLEVEL_BINDING, fname)
|
||||
echoln "Loaded plugin: #{name}" if !echoed_plugins.include?(name)
|
||||
echoed_plugins.push(name)
|
||||
rescue Exception # format error message to display
|
||||
self.pluginErrorMsg(name, sname)
|
||||
Kernel.exit! true
|
||||
end
|
||||
end
|
||||
end
|
||||
echoln '' if !echoed_plugins.empty?
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
end
|
||||
534
Data/Scripts_backup/001_Technical/006_RPG_Sprite.rb
Normal file
534
Data/Scripts_backup/001_Technical/006_RPG_Sprite.rb
Normal file
@@ -0,0 +1,534 @@
|
||||
class SpriteAnimation
|
||||
@@_animations = []
|
||||
@@_reference_count = {}
|
||||
|
||||
def initialize(sprite)
|
||||
@sprite = sprite
|
||||
end
|
||||
|
||||
%w[
|
||||
x y ox oy viewport flash src_rect opacity tone
|
||||
].each_with_index do |s, _i|
|
||||
eval <<-__END__
|
||||
|
||||
def #{s}(*arg)
|
||||
@sprite.#{s}(*arg)
|
||||
end
|
||||
|
||||
__END__
|
||||
end
|
||||
|
||||
def self.clear
|
||||
@@_animations.clear
|
||||
end
|
||||
|
||||
def dispose
|
||||
dispose_animation
|
||||
dispose_loop_animation
|
||||
end
|
||||
|
||||
def animation(animation, hit, height = 3)
|
||||
dispose_animation
|
||||
@_animation = animation
|
||||
return if @_animation == nil
|
||||
@_animation_hit = hit
|
||||
@_animation_height = height
|
||||
@_animation_duration = @_animation.frame_max
|
||||
fr = 20
|
||||
if @_animation.name[/\[\s*(\d+?)\s*\]\s*$/]
|
||||
fr = $~[1].to_i
|
||||
end
|
||||
@_animation_frame_skip = Graphics.frame_rate / fr
|
||||
animation_name = @_animation.animation_name
|
||||
animation_hue = @_animation.animation_hue
|
||||
bitmap = pbGetAnimation(animation_name, animation_hue)
|
||||
if @@_reference_count.include?(bitmap)
|
||||
@@_reference_count[bitmap] += 1
|
||||
else
|
||||
@@_reference_count[bitmap] = 1
|
||||
end
|
||||
@_animation_sprites = []
|
||||
if @_animation.position != 3 || !@@_animations.include?(animation)
|
||||
16.times do
|
||||
sprite = ::Sprite.new(self.viewport)
|
||||
sprite.bitmap = bitmap
|
||||
sprite.visible = false
|
||||
@_animation_sprites.push(sprite)
|
||||
end
|
||||
unless @@_animations.include?(animation)
|
||||
@@_animations.push(animation)
|
||||
end
|
||||
end
|
||||
update_animation
|
||||
end
|
||||
|
||||
def loop_animation(animation)
|
||||
return if animation == @_loop_animation
|
||||
dispose_loop_animation
|
||||
@_loop_animation = animation
|
||||
return if @_loop_animation == nil
|
||||
@_loop_animation_index = 0
|
||||
fr = 20
|
||||
if @_animation.name[/\[\s*(\d+?)\s*\]\s*$/]
|
||||
fr = $~[1].to_i
|
||||
end
|
||||
@_loop_animation_frame_skip = Graphics.frame_rate / fr
|
||||
animation_name = @_loop_animation.animation_name
|
||||
animation_hue = @_loop_animation.animation_hue
|
||||
bitmap = pbGetAnimation(animation_name, animation_hue)
|
||||
if @@_reference_count.include?(bitmap)
|
||||
@@_reference_count[bitmap] += 1
|
||||
else
|
||||
@@_reference_count[bitmap] = 1
|
||||
end
|
||||
@_loop_animation_sprites = []
|
||||
16.times do
|
||||
sprite = ::Sprite.new(self.viewport)
|
||||
sprite.bitmap = bitmap
|
||||
sprite.visible = false
|
||||
@_loop_animation_sprites.push(sprite)
|
||||
end
|
||||
update_loop_animation
|
||||
end
|
||||
|
||||
def dispose_animation
|
||||
return if @_animation_sprites == nil
|
||||
sprite = @_animation_sprites[0]
|
||||
if sprite != nil
|
||||
@@_reference_count[sprite.bitmap] -= 1
|
||||
if @@_reference_count[sprite.bitmap] == 0
|
||||
sprite.bitmap.dispose
|
||||
end
|
||||
end
|
||||
for sprite in @_animation_sprites
|
||||
sprite.dispose
|
||||
end
|
||||
@_animation_sprites = nil
|
||||
@_animation = nil
|
||||
end
|
||||
|
||||
def dispose_loop_animation
|
||||
return if @_loop_animation_sprites == nil
|
||||
sprite = @_loop_animation_sprites[0]
|
||||
if sprite != nil
|
||||
@@_reference_count[sprite.bitmap] -= 1
|
||||
if @@_reference_count[sprite.bitmap] == 0
|
||||
sprite.bitmap.dispose
|
||||
end
|
||||
end
|
||||
for sprite in @_loop_animation_sprites
|
||||
sprite.dispose
|
||||
end
|
||||
@_loop_animation_sprites = nil
|
||||
@_loop_animation = nil
|
||||
end
|
||||
|
||||
def active?
|
||||
return @_loop_animation_sprites != nil || @_animation_sprites != nil
|
||||
end
|
||||
|
||||
def effect?
|
||||
return @_animation_duration > 0
|
||||
end
|
||||
|
||||
def update
|
||||
if @_animation != nil
|
||||
quick_update = true
|
||||
if Graphics.frame_count % @_animation_frame_skip == 0
|
||||
@_animation_duration -= 1
|
||||
quick_update = false
|
||||
end
|
||||
update_animation(quick_update)
|
||||
end
|
||||
if @_loop_animation != nil
|
||||
quick_update = (Graphics.frame_count % @_loop_animation_frame_skip != 0)
|
||||
update_loop_animation(quick_update)
|
||||
if !quick_update
|
||||
@_loop_animation_index += 1
|
||||
@_loop_animation_index %= @_loop_animation.frame_max
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update_animation(quick_update = false)
|
||||
if @_animation_duration <= 0
|
||||
dispose_animation
|
||||
return
|
||||
end
|
||||
frame_index = @_animation.frame_max - @_animation_duration
|
||||
cell_data = @_animation.frames[frame_index].cell_data
|
||||
position = @_animation.position
|
||||
animation_set_sprites(@_animation_sprites, cell_data, position, quick_update)
|
||||
return if quick_update
|
||||
for timing in @_animation.timings
|
||||
next if timing.frame != frame_index
|
||||
animation_process_timing(timing, @_animation_hit)
|
||||
end
|
||||
end
|
||||
|
||||
def update_loop_animation(quick_update = false)
|
||||
frame_index = @_loop_animation_index
|
||||
cell_data = @_loop_animation.frames[frame_index].cell_data
|
||||
position = @_loop_animation.position
|
||||
animation_set_sprites(@_loop_animation_sprites, cell_data, position, quick_update)
|
||||
return if quick_update
|
||||
for timing in @_loop_animation.timings
|
||||
next if timing.frame != frame_index
|
||||
animation_process_timing(timing, true)
|
||||
end
|
||||
end
|
||||
|
||||
def animation_set_sprites(sprites, cell_data, position, quick_update = false)
|
||||
sprite_x = 320
|
||||
sprite_y = 240
|
||||
if position == 3
|
||||
if self.viewport != nil
|
||||
sprite_x = self.viewport.rect.width / 2
|
||||
sprite_y = self.viewport.rect.height - 160
|
||||
end
|
||||
else
|
||||
sprite_x = self.x - self.ox + self.src_rect.width / 2
|
||||
sprite_y = self.y - self.oy
|
||||
sprite_y += self.src_rect.height / 2 if position == 1
|
||||
sprite_y += self.src_rect.height if position == 2
|
||||
end
|
||||
for i in 0..15
|
||||
sprite = sprites[i]
|
||||
pattern = cell_data[i, 0]
|
||||
if sprite == nil || pattern == nil || pattern == -1
|
||||
sprite.visible = false if sprite != nil
|
||||
next
|
||||
end
|
||||
sprite.x = sprite_x + cell_data[i, 1]
|
||||
sprite.y = sprite_y + cell_data[i, 2]
|
||||
next if quick_update
|
||||
sprite.visible = true
|
||||
sprite.src_rect.set(pattern % 5 * 192, pattern / 5 * 192, 192, 192)
|
||||
case @_animation_height
|
||||
when 0 then sprite.z = 1
|
||||
when 1 then sprite.z = sprite.y+32+15
|
||||
when 2 then sprite.z = sprite.y+32+32+17
|
||||
else sprite.z = 2000
|
||||
end
|
||||
sprite.ox = 96
|
||||
sprite.oy = 96
|
||||
sprite.zoom_x = cell_data[i, 3] / 100.0
|
||||
sprite.zoom_y = cell_data[i, 3] / 100.0
|
||||
sprite.angle = cell_data[i, 4]
|
||||
sprite.mirror = (cell_data[i, 5] == 1)
|
||||
sprite.tone = self.tone
|
||||
sprite.opacity = cell_data[i, 6] * self.opacity / 255.0
|
||||
sprite.blend_type = cell_data[i, 7]
|
||||
end
|
||||
end
|
||||
|
||||
def animation_process_timing(timing, hit)
|
||||
if timing.condition == 0 ||
|
||||
(timing.condition == 1 && hit == true) ||
|
||||
(timing.condition == 2 && hit == false)
|
||||
if timing.se.name != ""
|
||||
se = timing.se
|
||||
pbSEPlay(se)
|
||||
end
|
||||
case timing.flash_scope
|
||||
when 1
|
||||
self.flash(timing.flash_color, timing.flash_duration * 2)
|
||||
when 2
|
||||
if self.viewport != nil
|
||||
self.viewport.flash(timing.flash_color, timing.flash_duration * 2)
|
||||
end
|
||||
when 3
|
||||
self.flash(nil, timing.flash_duration * 2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def x=(x)
|
||||
sx = x - self.x
|
||||
return if sx == 0
|
||||
if @_animation_sprites != nil
|
||||
for i in 0..15
|
||||
@_animation_sprites[i].x += sx
|
||||
end
|
||||
end
|
||||
if @_loop_animation_sprites != nil
|
||||
for i in 0..15
|
||||
@_loop_animation_sprites[i].x += sx
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def y=(y)
|
||||
sy = y - self.y
|
||||
return if sy == 0
|
||||
if @_animation_sprites != nil
|
||||
for i in 0..15
|
||||
@_animation_sprites[i].y += sy
|
||||
end
|
||||
end
|
||||
if @_loop_animation_sprites != nil
|
||||
for i in 0..15
|
||||
@_loop_animation_sprites[i].y += sy
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
module RPG
|
||||
class Sprite < ::Sprite
|
||||
def initialize(viewport = nil)
|
||||
super(viewport)
|
||||
@_whiten_duration = 0
|
||||
@_appear_duration = 0
|
||||
@_escape_duration = 0
|
||||
@_collapse_duration = 0
|
||||
@_damage_duration = 0
|
||||
@_animation_duration = 0
|
||||
@_blink = false
|
||||
@animations = []
|
||||
@loopAnimations = []
|
||||
end
|
||||
|
||||
def dispose
|
||||
dispose_damage
|
||||
dispose_animation
|
||||
dispose_loop_animation
|
||||
super
|
||||
end
|
||||
|
||||
def whiten
|
||||
self.blend_type = 0
|
||||
self.color.set(255, 255, 255, 128)
|
||||
self.opacity = 255
|
||||
@_whiten_duration = 16
|
||||
@_appear_duration = 0
|
||||
@_escape_duration = 0
|
||||
@_collapse_duration = 0
|
||||
end
|
||||
|
||||
def appear
|
||||
self.blend_type = 0
|
||||
self.color.set(0, 0, 0, 0)
|
||||
self.opacity = 0
|
||||
@_appear_duration = 16
|
||||
@_whiten_duration = 0
|
||||
@_escape_duration = 0
|
||||
@_collapse_duration = 0
|
||||
end
|
||||
|
||||
def escape
|
||||
self.blend_type = 0
|
||||
self.color.set(0, 0, 0, 0)
|
||||
self.opacity = 255
|
||||
@_escape_duration = 32
|
||||
@_whiten_duration = 0
|
||||
@_appear_duration = 0
|
||||
@_collapse_duration = 0
|
||||
end
|
||||
|
||||
def collapse
|
||||
self.blend_type = 1
|
||||
self.color.set(255, 64, 64, 255)
|
||||
self.opacity = 255
|
||||
@_collapse_duration = 48
|
||||
@_whiten_duration = 0
|
||||
@_appear_duration = 0
|
||||
@_escape_duration = 0
|
||||
end
|
||||
|
||||
def damage(value, critical)
|
||||
dispose_damage
|
||||
damage_string = (value.is_a?(Numeric)) ? value.abs.to_s : value.to_s
|
||||
bitmap = Bitmap.new(160, 48)
|
||||
bitmap.font.name = "Arial Black"
|
||||
bitmap.font.size = 32
|
||||
bitmap.font.color.set(0, 0, 0)
|
||||
bitmap.draw_text(-1, 12-1, 160, 36, damage_string, 1)
|
||||
bitmap.draw_text(+1, 12-1, 160, 36, damage_string, 1)
|
||||
bitmap.draw_text(-1, 12+1, 160, 36, damage_string, 1)
|
||||
bitmap.draw_text(+1, 12+1, 160, 36, damage_string, 1)
|
||||
if value.is_a?(Numeric) && value < 0
|
||||
bitmap.font.color.set(176, 255, 144)
|
||||
else
|
||||
bitmap.font.color.set(255, 255, 255)
|
||||
end
|
||||
bitmap.draw_text(0, 12, 160, 36, damage_string, 1)
|
||||
if critical
|
||||
bitmap.font.size = 20
|
||||
bitmap.font.color.set(0, 0, 0)
|
||||
bitmap.draw_text(-1, -1, 160, 20, "CRITICAL", 1)
|
||||
bitmap.draw_text(+1, -1, 160, 20, "CRITICAL", 1)
|
||||
bitmap.draw_text(-1, +1, 160, 20, "CRITICAL", 1)
|
||||
bitmap.draw_text(+1, +1, 160, 20, "CRITICAL", 1)
|
||||
bitmap.font.color.set(255, 255, 255)
|
||||
bitmap.draw_text(0, 0, 160, 20, "CRITICAL", 1)
|
||||
end
|
||||
@_damage_sprite = ::Sprite.new(self.viewport)
|
||||
@_damage_sprite.bitmap = bitmap
|
||||
@_damage_sprite.ox = 80
|
||||
@_damage_sprite.oy = 20
|
||||
@_damage_sprite.x = self.x
|
||||
@_damage_sprite.y = self.y - self.oy / 2
|
||||
@_damage_sprite.z = 3000
|
||||
@_damage_duration = 40
|
||||
end
|
||||
|
||||
def pushAnimation(array, anim)
|
||||
for i in 0...array.length
|
||||
next if array[i] && array[i].active?
|
||||
array[i] = anim
|
||||
return
|
||||
end
|
||||
array.push(anim)
|
||||
end
|
||||
|
||||
def animation(animation, hit, height = 3)
|
||||
anim = SpriteAnimation.new(self)
|
||||
anim.animation(animation,hit,height)
|
||||
pushAnimation(@animations,anim)
|
||||
end
|
||||
|
||||
def loop_animation(animation)
|
||||
anim = SpriteAnimation.new(self)
|
||||
anim.loop_animation(animation)
|
||||
pushAnimation(@loopAnimations,anim)
|
||||
end
|
||||
|
||||
def dispose_damage
|
||||
return if @_damage_sprite == nil
|
||||
@_damage_sprite.bitmap.dispose
|
||||
@_damage_sprite.dispose
|
||||
@_damage_sprite = nil
|
||||
@_damage_duration = 0
|
||||
end
|
||||
|
||||
def dispose_animation
|
||||
for a in @animations
|
||||
a.dispose_animation if a
|
||||
end
|
||||
@animations.clear
|
||||
end
|
||||
|
||||
def dispose_loop_animation
|
||||
for a in @loopAnimations
|
||||
a.dispose_loop_animation if a
|
||||
end
|
||||
@loopAnimations.clear
|
||||
end
|
||||
|
||||
def blink_on
|
||||
return if @_blink
|
||||
@_blink = true
|
||||
@_blink_count = 0
|
||||
end
|
||||
|
||||
def blink_off
|
||||
return unless @_blink
|
||||
@_blink = false
|
||||
self.color.set(0, 0, 0, 0)
|
||||
end
|
||||
|
||||
def blink?
|
||||
return @_blink
|
||||
end
|
||||
|
||||
def effect?
|
||||
return true if @_whiten_duration > 0
|
||||
return true if @_appear_duration > 0
|
||||
return true if @_escape_duration > 0
|
||||
return true if @_collapse_duration > 0
|
||||
return true if @_damage_duration > 0
|
||||
for a in @animations
|
||||
return true if a.effect?
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
if @_whiten_duration > 0
|
||||
@_whiten_duration -= 1
|
||||
self.color.alpha = 128 - (16 - @_whiten_duration) * 10
|
||||
end
|
||||
if @_appear_duration > 0
|
||||
@_appear_duration -= 1
|
||||
self.opacity = (16 - @_appear_duration) * 16
|
||||
end
|
||||
if @_escape_duration > 0
|
||||
@_escape_duration -= 1
|
||||
self.opacity = 256 - (32 - @_escape_duration) * 10
|
||||
end
|
||||
if @_collapse_duration > 0
|
||||
@_collapse_duration -= 1
|
||||
self.opacity = 256 - (48 - @_collapse_duration) * 6
|
||||
end
|
||||
if @_damage_duration > 0
|
||||
@_damage_duration -= 1
|
||||
case @_damage_duration
|
||||
when 38..39
|
||||
@_damage_sprite.y -= 4
|
||||
when 36..37
|
||||
@_damage_sprite.y -= 2
|
||||
when 34..35
|
||||
@_damage_sprite.y += 2
|
||||
when 28..33
|
||||
@_damage_sprite.y += 4
|
||||
end
|
||||
@_damage_sprite.opacity = 256 - (12 - @_damage_duration) * 32
|
||||
if @_damage_duration == 0
|
||||
dispose_damage
|
||||
end
|
||||
end
|
||||
for a in @animations
|
||||
a.update
|
||||
end
|
||||
for a in @loopAnimations
|
||||
a.update
|
||||
end
|
||||
if @_blink
|
||||
@_blink_count = (@_blink_count + 1) % 32
|
||||
if @_blink_count < 16
|
||||
alpha = (16 - @_blink_count) * 6
|
||||
else
|
||||
alpha = (@_blink_count - 16) * 6
|
||||
end
|
||||
self.color.set(255, 255, 255, alpha)
|
||||
end
|
||||
SpriteAnimation.clear
|
||||
end
|
||||
|
||||
def update_animation
|
||||
for a in @animations
|
||||
a.update_animation if a && a.active?
|
||||
end
|
||||
end
|
||||
|
||||
def update_loop_animation
|
||||
for a in @loopAnimations
|
||||
a.update_loop_animation if a && a.active?
|
||||
end
|
||||
end
|
||||
|
||||
def x=(x)
|
||||
for a in @animations
|
||||
a.x = x if a
|
||||
end
|
||||
for a in @loopAnimations
|
||||
a.x = x if a
|
||||
end
|
||||
super
|
||||
end
|
||||
|
||||
def y=(y)
|
||||
for a in @animations
|
||||
a.y = y if a
|
||||
end
|
||||
for a in @loopAnimations
|
||||
a.y = y if a
|
||||
end
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
78
Data/Scripts_backup/002_BattleSettings.rb
Normal file
78
Data/Scripts_backup/002_BattleSettings.rb
Normal file
@@ -0,0 +1,78 @@
|
||||
module Settings
|
||||
# Whether a move's physical/special category depends on the move itself as in
|
||||
# newer Gens (true), or on its type as in older Gens (false).
|
||||
MOVE_CATEGORY_PER_MOVE = (MECHANICS_GENERATION >= 4)
|
||||
# Whether turn order is recalculated after a Pokémon Mega Evolves.
|
||||
RECALCULATE_TURN_ORDER_AFTER_MEGA_EVOLUTION = (MECHANICS_GENERATION >= 7)
|
||||
# Whether turn order is recalculated after a Pokémon's Speed stat changes.
|
||||
RECALCULATE_TURN_ORDER_AFTER_SPEED_CHANGES = (MECHANICS_GENERATION >= 8)
|
||||
# Whether critical hits do 1.5x damage and have 4 stages (true), or they do 2x
|
||||
# damage and have 5 stages as in Gen 5 (false). Also determines whether
|
||||
# critical hit rate can be copied by Transform/Psych Up.
|
||||
NEW_CRITICAL_HIT_RATE_MECHANICS = (MECHANICS_GENERATION >= 6)
|
||||
# Whether several effects apply relating to a Pokémon's type:
|
||||
# * Electric-type immunity to paralysis
|
||||
# * Ghost-type immunity to being trapped
|
||||
# * Grass-type immunity to powder moves and Effect Spore
|
||||
# * Poison-type Pokémon can't miss when using Toxic
|
||||
MORE_TYPE_EFFECTS = (MECHANICS_GENERATION >= 6)
|
||||
# Whether weather caused by an ability lasts 5 rounds (true) or forever (false).
|
||||
FIXED_DURATION_WEATHER_FROM_ABILITY = (MECHANICS_GENERATION >= 6)
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# Whether X items (X Attack, etc.) raise their stat by 2 stages (true) or 1
|
||||
# (false).
|
||||
X_STAT_ITEMS_RAISE_BY_TWO_STAGES = (MECHANICS_GENERATION >= 7)
|
||||
# Whether some Poké Balls have catch rate multipliers from Gen 7 (true) or
|
||||
# from earlier generations (false).
|
||||
NEW_POKE_BALL_CATCH_RATES = (MECHANICS_GENERATION >= 7)
|
||||
# Whether Soul Dew powers up Psychic and Dragon-type moves by 20% (true) or
|
||||
# raises the holder's Special Attack and Special Defense by 50% (false).
|
||||
SOUL_DEW_POWERS_UP_TYPES = (MECHANICS_GENERATION >= 7)
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# The minimum number of badges required to boost each stat of a player's
|
||||
# Pokémon by 1.1x, in battle only.
|
||||
NUM_BADGES_BOOST_ATTACK = (MECHANICS_GENERATION >= 4) ? 999 : 1
|
||||
NUM_BADGES_BOOST_DEFENSE = (MECHANICS_GENERATION >= 4) ? 999 : 5
|
||||
NUM_BADGES_BOOST_SPATK = (MECHANICS_GENERATION >= 4) ? 999 : 7
|
||||
NUM_BADGES_BOOST_SPDEF = (MECHANICS_GENERATION >= 4) ? 999 : 7
|
||||
NUM_BADGES_BOOST_SPEED = (MECHANICS_GENERATION >= 4) ? 999 : 3
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# An array of items which act as Mega Rings for the player (NPCs don't need a
|
||||
# Mega Ring item, just a Mega Stone held by their Pokémon).
|
||||
MEGA_RINGS = [:MEGARING, :MEGABRACELET, :MEGACUFF, :MEGACHARM]
|
||||
# The Game Switch which, while ON, prevents all Pokémon in battle from Mega
|
||||
# Evolving even if they otherwise could.
|
||||
NO_MEGA_EVOLUTION = 34
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# Whether the Exp gained from beating a Pokémon should be scaled depending on
|
||||
# the gainer's level.
|
||||
SCALED_EXP_FORMULA = (MECHANICS_GENERATION == 5 || MECHANICS_GENERATION >= 7)
|
||||
# Whether the Exp gained from beating a Pokémon should be divided equally
|
||||
# between each participant (true), or whether each participant should gain
|
||||
# that much Exp (false). This also applies to Exp gained via the Exp Share
|
||||
# (held item version) being distributed to all Exp Share holders.
|
||||
SPLIT_EXP_BETWEEN_GAINERS = (MECHANICS_GENERATION <= 5)
|
||||
# Whether the critical capture mechanic applies. Note that its calculation is
|
||||
# based on a total of 600+ species (i.e. that many species need to be caught
|
||||
# to provide the greatest critical capture chance of 2.5x), and there may be
|
||||
# fewer species in your game.
|
||||
ENABLE_CRITICAL_CAPTURES = (MECHANICS_GENERATION >= 5)
|
||||
# Whether Pokémon gain Exp for capturing a Pokémon.
|
||||
GAIN_EXP_FOR_CAPTURE = (MECHANICS_GENERATION >= 6)
|
||||
# The Game Switch which, whie ON, prevents the player from losing money if
|
||||
# they lose a battle (they can still gain money from trainers for winning).
|
||||
NO_MONEY_LOSS = 33
|
||||
# Whether party Pokémon check whether they can evolve after all battles
|
||||
# regardless of the outcome (true), or only after battles the player won (false).
|
||||
CHECK_EVOLUTION_AFTER_ALL_BATTLES = (MECHANICS_GENERATION >= 6)
|
||||
# Whether fainted Pokémon can try to evolve after a battle.
|
||||
CHECK_EVOLUTION_FOR_FAINTED_POKEMON = true
|
||||
end
|
||||
4202
Data/Scripts_backup/002_Compiler_PBS.old.rb
Normal file
4202
Data/Scripts_backup/002_Compiler_PBS.old.rb
Normal file
File diff suppressed because it is too large
Load Diff
97
Data/Scripts_backup/002_Save data/001_SaveData.rb
Normal file
97
Data/Scripts_backup/002_Save data/001_SaveData.rb
Normal file
@@ -0,0 +1,97 @@
|
||||
# The SaveData module is used to manipulate save data. It contains the {Value}s
|
||||
# that make up the save data and {Conversion}s for resolving incompatibilities
|
||||
# between Essentials and game versions.
|
||||
# @see SaveData.register
|
||||
# @see SaveData.register_conversion
|
||||
module SaveData
|
||||
# Contains the file path of the save file.
|
||||
FILE_PATH = if File.directory?(System.data_directory)
|
||||
System.data_directory + '/Game.rxdata'
|
||||
else
|
||||
'./Game.rxdata'
|
||||
end
|
||||
|
||||
# @return [Boolean] whether the save file exists
|
||||
def self.exists?
|
||||
return File.file?(FILE_PATH)
|
||||
end
|
||||
|
||||
# Fetches the save data from the given file.
|
||||
# Returns an Array in the case of a pre-v19 save file.
|
||||
# @param file_path [String] path of the file to load from
|
||||
# @return [Hash, Array] loaded save data
|
||||
# @raise [IOError, SystemCallError] if file opening fails
|
||||
def self.get_data_from_file(file_path)
|
||||
validate file_path => String
|
||||
save_data = nil
|
||||
File.open(file_path) do |file|
|
||||
data = Marshal.load(file)
|
||||
if data.is_a?(Hash)
|
||||
save_data = data
|
||||
next
|
||||
end
|
||||
save_data = [data]
|
||||
save_data << Marshal.load(file) until file.eof?
|
||||
end
|
||||
return save_data
|
||||
end
|
||||
|
||||
# Fetches save data from the given file. If it needed converting, resaves it.
|
||||
# @param file_path [String] path of the file to read from
|
||||
# @return [Hash] save data in Hash format
|
||||
# @raise (see .get_data_from_file)
|
||||
def self.read_from_file(file_path)
|
||||
validate file_path => String
|
||||
save_data = get_data_from_file(file_path)
|
||||
save_data = to_hash_format(save_data) if save_data.is_a?(Array)
|
||||
if !save_data.empty? && run_conversions(save_data)
|
||||
File.open(file_path, 'wb') { |file| Marshal.dump(save_data, file) }
|
||||
end
|
||||
return save_data
|
||||
end
|
||||
|
||||
# Compiles the save data and saves a marshaled version of it into
|
||||
# the given file.
|
||||
# @param file_path [String] path of the file to save into
|
||||
# @raise [InvalidValueError] if an invalid value is being saved
|
||||
def self.save_to_file(file_path)
|
||||
validate file_path => String
|
||||
save_data = self.compile_save_hash
|
||||
File.open(file_path, 'wb') { |file| Marshal.dump(save_data, file) }
|
||||
end
|
||||
|
||||
# Deletes the save file (and a possible .bak backup file if one exists)
|
||||
# @raise [Error::ENOENT]
|
||||
def self.delete_file
|
||||
File.delete(FILE_PATH)
|
||||
File.delete(FILE_PATH + '.bak') if File.file?(FILE_PATH + '.bak')
|
||||
end
|
||||
|
||||
# Converts the pre-v19 format data to the new format.
|
||||
# @param old_format [Array] pre-v19 format save data
|
||||
# @return [Hash] save data in new format
|
||||
def self.to_hash_format(old_format)
|
||||
validate old_format => Array
|
||||
hash = {}
|
||||
@values.each do |value|
|
||||
data = value.get_from_old_format(old_format)
|
||||
hash[value.id] = data unless data.nil?
|
||||
end
|
||||
return hash
|
||||
end
|
||||
|
||||
# Moves a save file from the old Saved Games folder to the new
|
||||
# location specified by {FILE_PATH}. Does nothing if a save file
|
||||
# already exists in {FILE_PATH}.
|
||||
def self.move_old_windows_save
|
||||
return if File.file?(FILE_PATH)
|
||||
game_title = System.game_title.gsub(/[^\w ]/, '_')
|
||||
home = ENV['HOME'] || ENV['HOMEPATH']
|
||||
return if home.nil?
|
||||
old_location = File.join(home, 'Saved Games', game_title)
|
||||
return unless File.directory?(old_location)
|
||||
old_file = File.join(old_location, 'Game.rxdata')
|
||||
return unless File.file?(old_file)
|
||||
File.move(old_file, FILE_PATH)
|
||||
end
|
||||
end
|
||||
257
Data/Scripts_backup/002_Save data/002_SaveData_Value.rb
Normal file
257
Data/Scripts_backup/002_Save data/002_SaveData_Value.rb
Normal file
@@ -0,0 +1,257 @@
|
||||
module SaveData
|
||||
# Contains Value objects for each save element.
|
||||
# Populated during runtime by SaveData.register calls.
|
||||
# @type [Array<Value>]
|
||||
@values = []
|
||||
|
||||
# An error raised if an invalid save value is being saved or loaded.
|
||||
class InvalidValueError < RuntimeError; end
|
||||
|
||||
#=============================================================================
|
||||
# Represents a single value in save data.
|
||||
# New values are added using {SaveData.register}.
|
||||
class Value
|
||||
# @return [Symbol] the value id
|
||||
attr_reader :id
|
||||
|
||||
# @param id [Symbol] value id
|
||||
def initialize(id, &block)
|
||||
validate id => Symbol, block => Proc
|
||||
@id = id
|
||||
@loaded = false
|
||||
@load_in_bootup = false
|
||||
instance_eval(&block)
|
||||
raise "No save_value defined for save value #{id.inspect}" if @save_proc.nil?
|
||||
raise "No load_value defined for save value #{id.inspect}" if @load_proc.nil?
|
||||
end
|
||||
|
||||
# @param value [Object] value to check
|
||||
# @return [Boolean] whether the given value is valid
|
||||
def valid?(value)
|
||||
return true if @ensured_class.nil?
|
||||
return value.is_a?(Object.const_get(@ensured_class))
|
||||
end
|
||||
|
||||
# Calls the value's load proc with the given argument passed into it.
|
||||
# @param value [Object] load proc argument
|
||||
# @raise [InvalidValueError] if an invalid value is being loaded
|
||||
def load(value)
|
||||
validate_value(value)
|
||||
@load_proc.call(value)
|
||||
@loaded = true
|
||||
end
|
||||
|
||||
# Calls the value's save proc and returns its value.
|
||||
# @return [Object] save proc value
|
||||
# @raise [InvalidValueError] if an invalid value is being saved
|
||||
def save
|
||||
value = @save_proc.call
|
||||
validate_value(value)
|
||||
return value
|
||||
end
|
||||
|
||||
# @return [Boolean] whether the value has a new game value proc defined
|
||||
def has_new_game_proc?
|
||||
return @new_game_value_proc.is_a?(Proc)
|
||||
end
|
||||
|
||||
# Calls the save value's load proc with the value fetched
|
||||
# from the defined new game value proc.
|
||||
# @raise (see #load)
|
||||
def load_new_game_value
|
||||
unless self.has_new_game_proc?
|
||||
raise "Save value #{@id.inspect} has no new_game_value defined"
|
||||
end
|
||||
self.load(@new_game_value_proc.call)
|
||||
end
|
||||
|
||||
# @return [Boolean] whether the value should be loaded during bootup
|
||||
def load_in_bootup?
|
||||
return @load_in_bootup
|
||||
end
|
||||
|
||||
# @return [Boolean] whether the value has been loaded
|
||||
def loaded?
|
||||
return @loaded
|
||||
end
|
||||
|
||||
# Uses the {#from_old_format} proc to select the correct data from
|
||||
# +old_format+ and return it.
|
||||
# Returns nil if the proc is undefined.
|
||||
# @param old_format [Array] old format to load value from
|
||||
# @return [Object] data from the old format
|
||||
def get_from_old_format(old_format)
|
||||
return nil if @old_format_get_proc.nil?
|
||||
return @old_format_get_proc.call(old_format)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Raises an {InvalidValueError} if the given value is invalid.
|
||||
# @param value [Object] value to check
|
||||
# @raise [InvalidValueError] if the value is invalid
|
||||
def validate_value(value)
|
||||
return if self.valid?(value)
|
||||
raise InvalidValueError, "Save value #{@id.inspect} is not a #{@ensured_class} (#{value.class.name} given)"
|
||||
end
|
||||
|
||||
# @!group Configuration
|
||||
|
||||
# If present, ensures that the value is of the given class.
|
||||
# @param class_name [Symbol] class to enforce
|
||||
# @see SaveData.register
|
||||
def ensure_class(class_name)
|
||||
validate class_name => Symbol
|
||||
@ensured_class = class_name
|
||||
end
|
||||
|
||||
# Defines how the loaded value is placed into a global variable.
|
||||
# Requires a block with the loaded value as its parameter.
|
||||
# @see SaveData.register
|
||||
def load_value(&block)
|
||||
raise ArgumentError, 'No block given to load_value' unless block_given?
|
||||
@load_proc = block
|
||||
end
|
||||
|
||||
# Defines what is saved into save data. Requires a block.
|
||||
# @see SaveData.register
|
||||
def save_value(&block)
|
||||
raise ArgumentError, 'No block given to save_value' unless block_given?
|
||||
@save_proc = block
|
||||
end
|
||||
|
||||
# If present, defines what the value is set to at the start of a new game.
|
||||
# @see SaveData.register
|
||||
def new_game_value(&block)
|
||||
raise ArgumentError, 'No block given to new_game_value' unless block_given?
|
||||
@new_game_value_proc = block
|
||||
end
|
||||
|
||||
# If present, sets the value to be loaded during bootup.
|
||||
# @see SaveData.register
|
||||
def load_in_bootup
|
||||
@load_in_bootup = true
|
||||
end
|
||||
|
||||
# If present, defines how the value should be fetched from the pre-v19
|
||||
# save format. Requires a block with the old format array as its parameter.
|
||||
# @see SaveData.register
|
||||
def from_old_format(&block)
|
||||
raise ArgumentError, 'No block given to from_old_format' unless block_given?
|
||||
@old_format_get_proc = block
|
||||
end
|
||||
|
||||
# @!endgroup
|
||||
end
|
||||
|
||||
#=============================================================================
|
||||
# Registers a {Value} to be saved into save data.
|
||||
# Takes a block which defines the value's saving ({Value#save_value})
|
||||
# and loading ({Value#load_value}) procedures.
|
||||
#
|
||||
# It is also possible to provide a proc for fetching the value
|
||||
# from the pre-v19 format ({Value#from_old_format}), define
|
||||
# a value to be set upon starting a new game with {Value#new_game_value}
|
||||
# and ensure that the saved and loaded value is of the correct
|
||||
# class with {Value#ensure_class}.
|
||||
#
|
||||
# Values can be registered to be loaded on bootup with
|
||||
# {Value#load_in_bootup}. If a new_game_value proc is defined, it
|
||||
# will be called when the game is launched for the first time,
|
||||
# or if the save data does not contain the value in question.
|
||||
#
|
||||
# @example Registering a new value
|
||||
# SaveData.register(:foo) do
|
||||
# ensure_class :Foo
|
||||
# save_value { $foo }
|
||||
# load_value { |value| $foo = value }
|
||||
# new_game_value { Foo.new }
|
||||
# from_old_format { |old_format| old_format[16] if old_format[16].is_a?(Foo) }
|
||||
# end
|
||||
# @example Registering a value to be loaded on bootup
|
||||
# SaveData.register(:bar) do
|
||||
# load_in_bootup
|
||||
# save_value { $bar }
|
||||
# load_value { |value| $bar = value }
|
||||
# new_game_value { Bar.new }
|
||||
# end
|
||||
# @param id [Symbol] value id
|
||||
# @yieldself [Value]
|
||||
def self.register(id, &block)
|
||||
validate id => Symbol
|
||||
unless block_given?
|
||||
raise ArgumentError, 'No block given to SaveData.register'
|
||||
end
|
||||
@values << Value.new(id, &block)
|
||||
end
|
||||
|
||||
# @param save_data [Hash] save data to validate
|
||||
# @return [Boolean] whether the given save data is valid
|
||||
def self.valid?(save_data)
|
||||
validate save_data => Hash
|
||||
return @values.all? { |value| value.valid?(save_data[value.id]) }
|
||||
end
|
||||
|
||||
# Loads values from the given save data.
|
||||
# An optional condition can be passed.
|
||||
# @param save_data [Hash] save data to load from
|
||||
# @param condition_block [Proc] optional condition
|
||||
# @api private
|
||||
def self.load_values(save_data, &condition_block)
|
||||
@values.each do |value|
|
||||
next if block_given? && !condition_block.call(value)
|
||||
if save_data.has_key?(value.id)
|
||||
value.load(save_data[value.id])
|
||||
elsif value.has_new_game_proc?
|
||||
value.load_new_game_value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Loads the values from the given save data by
|
||||
# calling each {Value} object's {Value#load_value} proc.
|
||||
# Values that are already loaded are skipped.
|
||||
# If a value does not exist in the save data and has
|
||||
# a {Value#new_game_value} proc defined, that value
|
||||
# is loaded instead.
|
||||
# @param save_data [Hash] save data to load
|
||||
# @raise [InvalidValueError] if an invalid value is being loaded
|
||||
def self.load_all_values(save_data)
|
||||
validate save_data => Hash
|
||||
load_values(save_data) { |value| !value.loaded? }
|
||||
end
|
||||
|
||||
# Loads each value from the given save data that has
|
||||
# been set to be loaded during bootup. Done when a save file exists.
|
||||
# @param save_data [Hash] save data to load
|
||||
# @raise [InvalidValueError] if an invalid value is being loaded
|
||||
def self.load_bootup_values(save_data)
|
||||
validate save_data => Hash
|
||||
load_values(save_data) { |value| !value.loaded? && value.load_in_bootup? }
|
||||
end
|
||||
|
||||
# Goes through each value with {Value#load_in_bootup} enabled and loads their
|
||||
# new game value, if one is defined. Done when no save file exists.
|
||||
def self.initialize_bootup_values
|
||||
@values.each do |value|
|
||||
next unless value.load_in_bootup?
|
||||
value.load_new_game_value if value.has_new_game_proc? && !value.loaded?
|
||||
end
|
||||
end
|
||||
|
||||
# Loads each {Value}'s new game value, if one is defined. Done when starting a
|
||||
# new game.
|
||||
def self.load_new_game_values
|
||||
@values.each do |value|
|
||||
value.load_new_game_value if value.has_new_game_proc? && !value.loaded?
|
||||
end
|
||||
end
|
||||
|
||||
# @return [Hash{Symbol => Object}] a hash representation of the save data
|
||||
# @raise [InvalidValueError] if an invalid value is being saved
|
||||
def self.compile_save_hash
|
||||
save_data = {}
|
||||
@values.each { |value| save_data[value.id] = value.save }
|
||||
return save_data
|
||||
end
|
||||
end
|
||||
221
Data/Scripts_backup/002_Save data/003_SaveData_Conversion.rb
Normal file
221
Data/Scripts_backup/002_Save data/003_SaveData_Conversion.rb
Normal file
@@ -0,0 +1,221 @@
|
||||
module SaveData
|
||||
# Contains Conversion objects for each defined conversion:
|
||||
# {
|
||||
# :essentials => {
|
||||
# '19' => [<Conversion>, ...],
|
||||
# '19.1' => [<Conversion>, ...],
|
||||
# ...
|
||||
# },
|
||||
# :game => {
|
||||
# '1.1.0' => [<Conversion>, ...],
|
||||
# '1.2.0' => [<Conversion>, ...],
|
||||
# ...
|
||||
# }
|
||||
# }
|
||||
# Populated during runtime by SaveData.register_conversion calls.
|
||||
@conversions = {
|
||||
essentials: {},
|
||||
game: {}
|
||||
}
|
||||
|
||||
#=============================================================================
|
||||
# Represents a conversion made to save data.
|
||||
# New conversions are added using {SaveData.register_conversion}.
|
||||
class Conversion
|
||||
# @return [Symbol] conversion ID
|
||||
attr_reader :id
|
||||
# @return [String] conversion title
|
||||
attr_reader :title
|
||||
# @return [Symbol] trigger type of the conversion (+:essentials+ or +:game+)
|
||||
attr_reader :trigger_type
|
||||
# @return [String] trigger version of the conversion
|
||||
attr_reader :version
|
||||
|
||||
# @param id [String] conversion ID
|
||||
def initialize(id, &block)
|
||||
@id = id
|
||||
@value_procs = {}
|
||||
@all_proc = nil
|
||||
@title = "Running conversion #{@id}"
|
||||
@trigger_type = nil
|
||||
@version = nil
|
||||
instance_eval(&block)
|
||||
if @trigger_type.nil? || @version.nil?
|
||||
raise "Conversion #{@id} is missing a condition"
|
||||
end
|
||||
end
|
||||
|
||||
# Returns whether the conversion should be run with the given version.
|
||||
# @param version [String] version to check
|
||||
# @return [Boolean] whether the conversion should be run
|
||||
def should_run?(version)
|
||||
return PluginManager.compare_versions(version, @version) < 0
|
||||
end
|
||||
|
||||
# Runs the conversion on the given save data.
|
||||
# @param save_data [Hash]
|
||||
def run(save_data)
|
||||
@value_procs.each do |value_id, proc|
|
||||
unless save_data.has_key?(value_id)
|
||||
raise "Save data does not have value #{value_id.inspect}"
|
||||
end
|
||||
proc.call(save_data[value_id])
|
||||
end
|
||||
@all_proc.call(save_data) if @all_proc.is_a?(Proc)
|
||||
end
|
||||
|
||||
# Runs the conversion on the given object.
|
||||
# @param object
|
||||
# @param key [Symbol]
|
||||
def run_single(object, key)
|
||||
@value_procs[key].call(object) if @value_procs[key].is_a?(Proc)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# @!group Configuration
|
||||
|
||||
# Sets the conversion's title.
|
||||
# @param new_title [String] conversion title
|
||||
# @note Since conversions are run before loading the player's chosen language,
|
||||
# conversion titles can not be localized.
|
||||
# @see SaveData.register_conversion
|
||||
def display_title(new_title)
|
||||
validate new_title => String
|
||||
@title = new_title
|
||||
end
|
||||
|
||||
# Sets the conversion to trigger for save files created below
|
||||
# the given Essentials version.
|
||||
# @param version [Numeric, String]
|
||||
# @see SaveData.register_conversion
|
||||
def essentials_version(version)
|
||||
validate version => [Numeric, String]
|
||||
raise "Multiple conditions in conversion #{@id}" unless @version.nil?
|
||||
@trigger_type = :essentials
|
||||
@version = version.to_s
|
||||
end
|
||||
|
||||
# Sets the conversion to trigger for save files created below
|
||||
# the given game version.
|
||||
# @param version [Numeric, String]
|
||||
# @see SaveData.register_conversion
|
||||
def game_version(version)
|
||||
validate version => [Numeric, String]
|
||||
raise "Multiple conditions in conversion #{@id}" unless @version.nil?
|
||||
@trigger_type = :game
|
||||
@version = version.to_s
|
||||
end
|
||||
|
||||
# Defines a conversion to the given save value.
|
||||
# @param value_id [Symbol] save value ID
|
||||
# @see SaveData.register_conversion
|
||||
def to_value(value_id, &block)
|
||||
validate value_id => Symbol
|
||||
raise ArgumentError, 'No block given to to_value' unless block_given?
|
||||
if @value_procs[value_id].is_a?(Proc)
|
||||
raise "Multiple to_value definitions in conversion #{@id} for #{value_id}"
|
||||
end
|
||||
@value_procs[value_id] = block
|
||||
end
|
||||
|
||||
# Defines a conversion to the entire save data.
|
||||
# @see SaveData.register_conversion
|
||||
def to_all(&block)
|
||||
raise ArgumentError, 'No block given to to_all' unless block_given?
|
||||
if @all_proc.is_a?(Proc)
|
||||
raise "Multiple to_all definitions in conversion #{@id}"
|
||||
end
|
||||
@all_proc = block
|
||||
end
|
||||
|
||||
# @!endgroup
|
||||
end
|
||||
|
||||
#=============================================================================
|
||||
# Registers a {Conversion} to occur for save data that meets the given criteria.
|
||||
# Two types of criteria can be defined: {Conversion#essentials_version} and
|
||||
# {Conversion#game_version}. The conversion is automatically run on save data
|
||||
# that contains an older version number.
|
||||
#
|
||||
# A single value can be modified with {Conversion#to_value}. The entire save data
|
||||
# is accessed with {Conversion#to_all}, and a conversion title can be specified
|
||||
# with {Conversion#display_title}.
|
||||
# @example Registering a new conversion
|
||||
# SaveData.register_conversion(:my_conversion) do
|
||||
# game_version '1.1.0'
|
||||
# display_title 'Converting some stuff'
|
||||
# to_value :player do |player|
|
||||
# # code that modifies the :player value
|
||||
# end
|
||||
# to_all do |save_data|
|
||||
# save_data[:new_value] = Foo.new
|
||||
# end
|
||||
# end
|
||||
# @yield self [Conversion]
|
||||
def self.register_conversion(id, &block)
|
||||
validate id => Symbol
|
||||
unless block_given?
|
||||
raise ArgumentError, 'No block given to SaveData.register_conversion'
|
||||
end
|
||||
conversion = Conversion.new(id, &block)
|
||||
@conversions[conversion.trigger_type][conversion.version] ||= []
|
||||
@conversions[conversion.trigger_type][conversion.version] << conversion
|
||||
end
|
||||
|
||||
# @param save_data [Hash] save data to get conversions for
|
||||
# @return [Array<Conversion>] all conversions that should be run on the data
|
||||
def self.get_conversions(save_data)
|
||||
conversions_to_run = []
|
||||
versions = {
|
||||
essentials: save_data[:essentials_version] || '18.1',
|
||||
game: save_data[:game_version] || '0.0.0'
|
||||
}
|
||||
[:essentials, :game].each do |trigger_type|
|
||||
# Ensure the versions are sorted from lowest to highest
|
||||
sorted_versions = @conversions[trigger_type].keys.sort do |v1, v2|
|
||||
PluginManager.compare_versions(v1, v2)
|
||||
end
|
||||
sorted_versions.each do |version|
|
||||
@conversions[trigger_type][version].each do |conversion|
|
||||
next unless conversion.should_run?(versions[trigger_type])
|
||||
conversions_to_run << conversion
|
||||
end
|
||||
end
|
||||
end
|
||||
return conversions_to_run
|
||||
end
|
||||
|
||||
# Runs all possible conversions on the given save data.
|
||||
# Saves a backup before running conversions.
|
||||
# @param save_data [Hash] save data to run conversions on
|
||||
# @return [Boolean] whether conversions were run
|
||||
def self.run_conversions(save_data)
|
||||
validate save_data => Hash
|
||||
conversions_to_run = self.get_conversions(save_data)
|
||||
return false if conversions_to_run.none?
|
||||
File.open(SaveData::FILE_PATH + '.bak', 'wb') { |f| Marshal.dump(save_data, f) }
|
||||
echoln "Running #{conversions_to_run.length} conversions..."
|
||||
conversions_to_run.each do |conversion|
|
||||
echo "#{conversion.title}..."
|
||||
conversion.run(save_data)
|
||||
echoln ' done.'
|
||||
end
|
||||
echoln '' if conversions_to_run.length > 0
|
||||
save_data[:essentials_version] = Essentials::VERSION
|
||||
save_data[:game_version] = Settings::GAME_VERSION
|
||||
return true
|
||||
end
|
||||
|
||||
# Runs all possible conversions on the given object.
|
||||
# @param object [Hash] object to run conversions on
|
||||
# @param key [Hash] object's key in save data
|
||||
# @param save_data [Hash] save data to run conversions on
|
||||
def self.run_single_conversions(object, key, save_data)
|
||||
validate key => Symbol
|
||||
conversions_to_run = self.get_conversions(save_data)
|
||||
conversions_to_run.each do |conversion|
|
||||
conversion.run_single(object, key)
|
||||
end
|
||||
end
|
||||
end
|
||||
135
Data/Scripts_backup/002_Save data/004_Game_SaveValues.rb
Normal file
135
Data/Scripts_backup/002_Save data/004_Game_SaveValues.rb
Normal file
@@ -0,0 +1,135 @@
|
||||
# Contains the save values defined in Essentials by default.
|
||||
|
||||
SaveData.register(:player) do
|
||||
ensure_class :Player
|
||||
save_value { $Trainer }
|
||||
load_value { |value| $Trainer = value }
|
||||
new_game_value {
|
||||
trainer_type = nil # Get the first defined trainer type as a placeholder
|
||||
GameData::TrainerType.each { |t| trainer_type = t.id; break }
|
||||
Player.new("Unnamed", trainer_type)
|
||||
}
|
||||
from_old_format { |old_format| old_format[0] }
|
||||
end
|
||||
|
||||
SaveData.register(:frame_count) do
|
||||
ensure_class :Integer
|
||||
save_value { Graphics.frame_count }
|
||||
load_value { |value| Graphics.frame_count = value }
|
||||
new_game_value { 0 }
|
||||
from_old_format { |old_format| old_format[1] }
|
||||
end
|
||||
|
||||
SaveData.register(:game_system) do
|
||||
load_in_bootup
|
||||
ensure_class :Game_System
|
||||
save_value { $game_system }
|
||||
load_value { |value| $game_system = value }
|
||||
new_game_value { Game_System.new }
|
||||
from_old_format { |old_format| old_format[2] }
|
||||
end
|
||||
|
||||
SaveData.register(:pokemon_system) do
|
||||
load_in_bootup
|
||||
ensure_class :PokemonSystem
|
||||
save_value { $PokemonSystem }
|
||||
load_value { |value| $PokemonSystem = value }
|
||||
new_game_value { PokemonSystem.new }
|
||||
from_old_format { |old_format| old_format[3] }
|
||||
end
|
||||
|
||||
SaveData.register(:switches) do
|
||||
ensure_class :Game_Switches
|
||||
save_value { $game_switches }
|
||||
load_value { |value| $game_switches = value }
|
||||
new_game_value { Game_Switches.new }
|
||||
from_old_format { |old_format| old_format[5] }
|
||||
end
|
||||
|
||||
SaveData.register(:variables) do
|
||||
ensure_class :Game_Variables
|
||||
save_value { $game_variables }
|
||||
load_value { |value| $game_variables = value }
|
||||
new_game_value { Game_Variables.new }
|
||||
from_old_format { |old_format| old_format[6] }
|
||||
end
|
||||
|
||||
SaveData.register(:self_switches) do
|
||||
ensure_class :Game_SelfSwitches
|
||||
save_value { $game_self_switches }
|
||||
load_value { |value| $game_self_switches = value }
|
||||
new_game_value { Game_SelfSwitches.new }
|
||||
from_old_format { |old_format| old_format[7] }
|
||||
end
|
||||
|
||||
SaveData.register(:game_screen) do
|
||||
ensure_class :Game_Screen
|
||||
save_value { $game_screen }
|
||||
load_value { |value| $game_screen = value }
|
||||
new_game_value { Game_Screen.new }
|
||||
from_old_format { |old_format| old_format[8] }
|
||||
end
|
||||
|
||||
SaveData.register(:map_factory) do
|
||||
ensure_class :PokemonMapFactory
|
||||
save_value { $MapFactory }
|
||||
load_value { |value| $MapFactory = value }
|
||||
from_old_format { |old_format| old_format[9] }
|
||||
end
|
||||
|
||||
SaveData.register(:game_player) do
|
||||
ensure_class :Game_Player
|
||||
save_value { $game_player }
|
||||
load_value { |value| $game_player = value }
|
||||
new_game_value { Game_Player.new }
|
||||
from_old_format { |old_format| old_format[10] }
|
||||
end
|
||||
|
||||
SaveData.register(:global_metadata) do
|
||||
ensure_class :PokemonGlobalMetadata
|
||||
save_value { $PokemonGlobal }
|
||||
load_value { |value| $PokemonGlobal = value }
|
||||
new_game_value { PokemonGlobalMetadata.new }
|
||||
from_old_format { |old_format| old_format[11] }
|
||||
end
|
||||
|
||||
SaveData.register(:map_metadata) do
|
||||
ensure_class :PokemonMapMetadata
|
||||
save_value { $PokemonMap }
|
||||
load_value { |value| $PokemonMap = value }
|
||||
new_game_value { PokemonMapMetadata.new }
|
||||
from_old_format { |old_format| old_format[12] }
|
||||
end
|
||||
|
||||
SaveData.register(:bag) do
|
||||
ensure_class :PokemonBag
|
||||
save_value { $PokemonBag }
|
||||
load_value { |value| $PokemonBag = value }
|
||||
new_game_value { PokemonBag.new }
|
||||
from_old_format { |old_format| old_format[13] }
|
||||
end
|
||||
|
||||
SaveData.register(:storage_system) do
|
||||
ensure_class :PokemonStorage
|
||||
save_value { $PokemonStorage }
|
||||
load_value { |value| $PokemonStorage = value }
|
||||
new_game_value { PokemonStorage.new }
|
||||
from_old_format { |old_format| old_format[14] }
|
||||
end
|
||||
|
||||
SaveData.register(:essentials_version) do
|
||||
load_in_bootup
|
||||
ensure_class :String
|
||||
save_value { Essentials::VERSION }
|
||||
load_value { |value| $SaveVersion = value }
|
||||
new_game_value { Essentials::VERSION }
|
||||
from_old_format { |old_format| old_format[15] }
|
||||
end
|
||||
|
||||
SaveData.register(:game_version) do
|
||||
load_in_bootup
|
||||
ensure_class :String
|
||||
save_value { Settings::GAME_VERSION }
|
||||
load_value { |value| $game_version = value }
|
||||
new_game_value { Settings::GAME_VERSION }
|
||||
end
|
||||
242
Data/Scripts_backup/002_Save data/005_Game_SaveConversions.rb
Normal file
242
Data/Scripts_backup/002_Save data/005_Game_SaveConversions.rb
Normal file
@@ -0,0 +1,242 @@
|
||||
# Contains conversions defined in Essentials by default.
|
||||
|
||||
SaveData.register_conversion(:v19_define_versions) do
|
||||
essentials_version 19
|
||||
display_title 'Adding game version and Essentials version to save data'
|
||||
to_all do |save_data|
|
||||
unless save_data.has_key?(:essentials_version)
|
||||
save_data[:essentials_version] = Essentials::VERSION
|
||||
end
|
||||
unless save_data.has_key?(:game_version)
|
||||
save_data[:game_version] = Settings::GAME_VERSION
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
SaveData.register_conversion(:v19_convert_PokemonSystem) do
|
||||
essentials_version 19
|
||||
display_title 'Updating PokemonSystem class'
|
||||
to_all do |save_data|
|
||||
new_system = PokemonSystem.new
|
||||
new_system.textspeed = save_data[:pokemon_system].textspeed || new_system.textspeed
|
||||
new_system.battlescene = save_data[:pokemon_system].battlescene || new_system.battlescene
|
||||
new_system.battlestyle = save_data[:pokemon_system].battlestyle || new_system.battlestyle
|
||||
new_system.frame = save_data[:pokemon_system].frame || new_system.frame
|
||||
new_system.textskin = save_data[:pokemon_system].textskin || new_system.textskin
|
||||
new_system.screensize = save_data[:pokemon_system].screensize || new_system.screensize
|
||||
new_system.language = save_data[:pokemon_system].language || new_system.language
|
||||
new_system.runstyle = save_data[:pokemon_system].runstyle || new_system.runstyle
|
||||
new_system.bgmvolume = save_data[:pokemon_system].bgmvolume || new_system.bgmvolume
|
||||
new_system.sevolume = save_data[:pokemon_system].sevolume || new_system.sevolume
|
||||
new_system.textinput = save_data[:pokemon_system].textinput || new_system.textinput
|
||||
save_data[:pokemon_system] = new_system
|
||||
end
|
||||
end
|
||||
|
||||
SaveData.register_conversion(:v19_convert_player) do
|
||||
essentials_version 19
|
||||
display_title 'Converting player trainer class'
|
||||
to_all do |save_data|
|
||||
next if save_data[:player].is_a?(Player)
|
||||
# Conversion of the party is handled in PokeBattle_Trainer.convert
|
||||
save_data[:player] = PokeBattle_Trainer.convert(save_data[:player])
|
||||
end
|
||||
end
|
||||
|
||||
SaveData.register_conversion(:v19_move_global_data_to_player) do
|
||||
essentials_version 19
|
||||
display_title 'Moving some global metadata data to player'
|
||||
to_all do |save_data|
|
||||
global = save_data[:global_metadata]
|
||||
player = save_data[:player]
|
||||
player.character_ID = global.playerID
|
||||
global.playerID = nil
|
||||
global.pokedexUnlocked.each_with_index do |value, i|
|
||||
if value
|
||||
player.pokedex.unlock(i)
|
||||
else
|
||||
player.pokedex.lock(i)
|
||||
end
|
||||
end
|
||||
player.coins = global.coins
|
||||
global.coins = nil
|
||||
player.soot = global.sootsack
|
||||
global.sootsack = nil
|
||||
player.has_running_shoes = global.runningShoes
|
||||
global.runningShoes = nil
|
||||
player.seen_storage_creator = global.seenStorageCreator
|
||||
global.seenStorageCreator = nil
|
||||
player.has_snag_machine = global.snagMachine
|
||||
global.snagMachine = nil
|
||||
player.seen_purify_chamber = global.seenPurifyChamber
|
||||
global.seenPurifyChamber = nil
|
||||
end
|
||||
end
|
||||
|
||||
SaveData.register_conversion(:v19_convert_global_metadata) do
|
||||
essentials_version 19
|
||||
display_title 'Adding encounter version variable to global metadata'
|
||||
to_value :global_metadata do |global|
|
||||
global.bridge ||= 0
|
||||
global.encounter_version ||= 0
|
||||
if global.pcItemStorage
|
||||
global.pcItemStorage.items.each_with_index do |slot, i|
|
||||
item_data = GameData::Item.try_get(slot[0])
|
||||
if item_data
|
||||
slot[0] = item_data.id
|
||||
else
|
||||
global.pcItemStorage.items[i] = nil
|
||||
end
|
||||
end
|
||||
global.pcItemStorage.items.compact!
|
||||
end
|
||||
if global.mailbox
|
||||
global.mailbox.each_with_index do |mail, i|
|
||||
global.mailbox[i] = PokemonMail.convert(mail) if mail
|
||||
end
|
||||
end
|
||||
global.phoneNumbers.each do |contact|
|
||||
contact[1] = GameData::TrainerType.get(contact[1]).id if contact && contact.length == 8
|
||||
end
|
||||
if global.partner
|
||||
global.partner[0] = GameData::TrainerType.get(global.partner[0]).id
|
||||
global.partner[3].each_with_index do |pkmn, i|
|
||||
global.partner[3][i] = PokeBattle_Pokemon.convert(pkmn) if pkmn
|
||||
end
|
||||
end
|
||||
if global.daycare
|
||||
global.daycare.each do |slot|
|
||||
slot[0] = PokeBattle_Pokemon.convert(slot[0]) if slot && slot[0]
|
||||
end
|
||||
end
|
||||
if global.roamPokemon
|
||||
global.roamPokemon.each_with_index do |pkmn, i|
|
||||
global.roamPokemon[i] = PokeBattle_Pokemon.convert(pkmn) if pkmn && pkmn != true
|
||||
end
|
||||
end
|
||||
global.purifyChamber.sets.each do |set|
|
||||
set.shadow = PokeBattle_Pokemon.convert(set.shadow) if set.shadow
|
||||
set.list.each_with_index do |pkmn, i|
|
||||
set.list[i] = PokeBattle_Pokemon.convert(pkmn) if pkmn
|
||||
end
|
||||
end
|
||||
if global.hallOfFame
|
||||
global.hallOfFame.each do |team|
|
||||
next if !team
|
||||
team.each_with_index do |pkmn, i|
|
||||
team[i] = PokeBattle_Pokemon.convert(pkmn) if pkmn
|
||||
end
|
||||
end
|
||||
end
|
||||
if global.triads
|
||||
global.triads.items.each do |card|
|
||||
card[0] = GameData::Species.get(card[0]).id if card && card[0] && card[0] != 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
SaveData.register_conversion(:v19_1_fix_phone_contacts) do
|
||||
essentials_version 19.1
|
||||
display_title 'Fixing phone contacts data'
|
||||
to_value :global_metadata do |global|
|
||||
global.phoneNumbers.each do |contact|
|
||||
contact[1] = GameData::TrainerType.get(contact[1]).id if contact && contact.length == 8
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
SaveData.register_conversion(:v19_convert_bag) do
|
||||
essentials_version 19
|
||||
display_title 'Converting item IDs in Bag'
|
||||
to_value :bag do |bag|
|
||||
bag.instance_eval do
|
||||
for pocket in self.pockets
|
||||
pocket.each_with_index do |item, i|
|
||||
next if !item || !item[0] || item[0] == 0
|
||||
item_data = GameData::Item.try_get(item[0])
|
||||
if item_data
|
||||
item[0] = item_data.id
|
||||
else
|
||||
pocket[i] = nil
|
||||
end
|
||||
end
|
||||
pocket.compact!
|
||||
end
|
||||
self.registeredIndex # Just to ensure this data exists
|
||||
self.registeredItems.each_with_index do |item, i|
|
||||
next if !item
|
||||
if item == 0
|
||||
self.registeredItems[i] = nil
|
||||
else
|
||||
item_data = GameData::Item.try_get(item)
|
||||
if item_data
|
||||
self.registeredItems[i] = item_data.id
|
||||
else
|
||||
self.registeredItems[i] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
self.registeredItems.compact!
|
||||
end # bag.instance_eval
|
||||
end # to_value
|
||||
end
|
||||
|
||||
SaveData.register_conversion(:v19_convert_game_variables) do
|
||||
essentials_version 19
|
||||
display_title 'Converting classes of things in Game Variables'
|
||||
to_all do |save_data|
|
||||
variables = save_data[:variables]
|
||||
for i in 0..5000
|
||||
value = variables[i]
|
||||
next if value.nil?
|
||||
if value.is_a?(Array)
|
||||
value.each_with_index do |value2, j|
|
||||
if value2.is_a?(PokeBattle_Pokemon)
|
||||
value[j] = PokeBattle_Pokemon.convert(value2)
|
||||
end
|
||||
end
|
||||
elsif value.is_a?(PokeBattle_Pokemon)
|
||||
variables[i] = PokeBattle_Pokemon.convert(value)
|
||||
elsif value.is_a?(PokemonBag)
|
||||
SaveData.run_single_conversions(value, :bag, save_data)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
SaveData.register_conversion(:v19_convert_storage) do
|
||||
essentials_version 19
|
||||
display_title 'Converting classes of Pokémon in storage'
|
||||
to_value :storage_system do |storage|
|
||||
storage.instance_eval do
|
||||
for box in 0...self.maxBoxes
|
||||
for i in 0...self.maxPokemon(box)
|
||||
self[box, i] = PokeBattle_Pokemon.convert(self[box, i]) if self[box, i]
|
||||
end
|
||||
end
|
||||
self.unlockedWallpapers # Just to ensure this data exists
|
||||
end # storage.instance_eval
|
||||
end # to_value
|
||||
end
|
||||
|
||||
SaveData.register_conversion(:v19_convert_game_player) do
|
||||
essentials_version 19
|
||||
display_title 'Converting game player character'
|
||||
to_value :game_player do |game_player|
|
||||
game_player.width = 1
|
||||
game_player.height = 1
|
||||
game_player.sprite_size = [Game_Map::TILE_WIDTH, Game_Map::TILE_HEIGHT]
|
||||
game_player.pattern_surf ||= 0
|
||||
game_player.lock_pattern ||= false
|
||||
game_player.move_speed = game_player.move_speed
|
||||
end
|
||||
end
|
||||
|
||||
SaveData.register_conversion(:v19_convert_game_screen) do
|
||||
essentials_version 19
|
||||
display_title 'Converting game screen'
|
||||
to_value :game_screen do |game_screen|
|
||||
game_screen.weather(game_screen.weather_type, game_screen.weather_max, 0)
|
||||
end
|
||||
end
|
||||
420
Data/Scripts_backup/002_Settings_Override.rb
Normal file
420
Data/Scripts_backup/002_Settings_Override.rb
Normal file
@@ -0,0 +1,420 @@
|
||||
GAME_VERSION_NUMBER = "4.8.6.2 - debug build"
|
||||
|
||||
###############################
|
||||
###### Settings ##############
|
||||
###SCRIPTEDIT5
|
||||
##########################
|
||||
NUM_BADGES = 16
|
||||
CONST_NB_POKE = 420
|
||||
NB_POKEMON = CONST_NB_POKE
|
||||
|
||||
#todo: refactor les 2 sont utilisés dans le code pour aucune bonne raison
|
||||
NUM_ZAPMOLCUNO = 176821
|
||||
ZAPMOLCUNO_NB = NUM_ZAPMOLCUNO
|
||||
|
||||
RIVAL_STARTER_PLACEHOLDER_SPECIES = 151 #(MEW)
|
||||
|
||||
#non impémenté parce que ca fuck avec le turbo
|
||||
#OW_FRAMERATE = 40
|
||||
BATTLE_FRAMERATE_MULTI = 1.5
|
||||
BASE_FRAMERATE = 40
|
||||
TURBO_FRAMERATE = 80
|
||||
|
||||
#===============================================================================
|
||||
# * The maximum level Pokémon can reach.
|
||||
# * The level of newly hatched Pokémon.
|
||||
# * The odds of a newly generated Pokémon being shiny (out of 65536).
|
||||
# * The odds of a wild Pokémon/bred egg having Pokérus (out of 65536).
|
||||
#===============================================================================
|
||||
MAXIMUMLEVEL = 100
|
||||
EGGINITIALLEVEL = 1
|
||||
SHINYPOKEMONCHANCE = 0 #64
|
||||
POKERUSCHANCE = 3
|
||||
|
||||
#===============================================================================
|
||||
# * The default screen width (at a zoom of 1.0; size is half this at zoom 0.5).
|
||||
# * The default screen height (at a zoom of 1.0).
|
||||
# * The default screen zoom. (1.0 means each tile is 32x32 pixels, 0.5 means
|
||||
# each tile is 16x16 pixels, 2.0 means each tile is 64x64 pixels.)
|
||||
# * Map view mode (0=original, 1=custom, 2=perspective).
|
||||
#===============================================================================
|
||||
DEFAULTSCREENWIDTH = 512
|
||||
DEFAULTSCREENHEIGHT =384
|
||||
DEFAULTSCREENZOOM = 2
|
||||
MAPVIEWMODE = 0#$game_variables[25]
|
||||
|
||||
|
||||
# To forbid the player from changing the screen size themselves, quote out or
|
||||
# delete the relevant bit of code in the PokemonOptions script section.
|
||||
|
||||
#===============================================================================
|
||||
# * Whether poisoned Pokémon will lose HP while walking around in the field.
|
||||
# * Whether poisoned Pokémon will faint while walking around in the field
|
||||
# (true), or survive the poisoning with 1HP (false).
|
||||
# * Whether fishing automatically hooks the Pokémon (if false, there is a
|
||||
# reaction test first).
|
||||
# * Whether TMs can be used infinitely as in Gen 5 (true), or are one-use-only
|
||||
# as in older Gens (false).
|
||||
# * Whether the player can surface from anywhere while diving (true), or only in
|
||||
# spots where they could dive down from above (false).
|
||||
# * Whether a move's physical/special category depends on the move itself as in
|
||||
# newer Gens (true), or on its type as in older Gens (false).
|
||||
# * Whether the Exp gained from beating a Pokémon should be scaled depending on
|
||||
# the gainer's level as in Gen 5 (true), or not as in older Gens (false).
|
||||
# * Whether planted berries grow according to Gen 4 mechanics (true) or Gen 3
|
||||
# mechanics (false).
|
||||
#===============================================================================
|
||||
POISONINFIELD = true
|
||||
POISONFAINTINFIELD = false
|
||||
FISHINGAUTOHOOK = false
|
||||
INFINITETMS = true
|
||||
DIVINGSURFACEANYWHERE = true
|
||||
USEMOVECATEGORY = true
|
||||
USENEWEXPFORMULA = false
|
||||
NEWBERRYPLANTS = true
|
||||
$Bubble = 0
|
||||
|
||||
#===============================================================================
|
||||
# * Pairs of map IDs, where the location signpost isn't shown when moving from
|
||||
# one of the maps in a pair to the other (and vice versa). Useful for
|
||||
# single long routes/towns that are spread over multiple maps.
|
||||
# e.g. [4,5,16,17,42,43] will be map pairs 4,5 and 16,17 and 42,43.
|
||||
# Moving between two maps that have the exact same name won't show the
|
||||
# location signpost anyway, so you don't need to list those maps here.
|
||||
#===============================================================================
|
||||
NOSIGNPOSTS = []
|
||||
|
||||
#===============================================================================
|
||||
# * Whether outdoor maps should be shaded according to the time of day.
|
||||
#===============================================================================
|
||||
ENABLESHADING = true
|
||||
|
||||
#===============================================================================
|
||||
# * The minimum number of badges required to boost each stat of a player's
|
||||
# Pokémon by 1.1x, while using moves in battle only.
|
||||
# * Whether the badge restriction on using certain hidden moves is either owning
|
||||
# at least a certain number of badges (true), or owning a particular badge
|
||||
# (false).
|
||||
# * Depending on HIDDENMOVESCOUNTBADGES, either the number of badges required to
|
||||
# use each hidden move, or the specific badge number required to use each
|
||||
# move. Remember that badge 0 is the first badge, badge 1 is the second
|
||||
# badge, etc.
|
||||
# e.g. To require the second badge, put false and 1.
|
||||
# To require at least 2 badges, put true and 2.
|
||||
#===============================================================================
|
||||
BADGESBOOSTATTACK = 20
|
||||
BADGESBOOSTDEFENSE = 20
|
||||
BADGESBOOSTSPEED = 20
|
||||
BADGESBOOSTSPATK = 20
|
||||
BADGESBOOSTSPDEF = 20
|
||||
HIDDENMOVESCOUNTBADGES = true
|
||||
BADGEFORCUT = 1
|
||||
BADGEFORFLASH = 2
|
||||
BADGEFORROCKSMASH = 0
|
||||
BADGEFORSURF = 5
|
||||
BADGEFORFLY = 3
|
||||
BADGEFORSTRENGTH = 5
|
||||
BADGEFORDIVE = 9
|
||||
BADGEFORWATERFALL = 8
|
||||
BADGEFORTELEPORT = 3
|
||||
BADGEFORBOUNCE = 8
|
||||
BADGEFORROCKCLIMB = 16
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# * The names of each pocket of the Bag. Leave the first entry blank.
|
||||
# * The maximum number of slots per pocket (-1 means infinite number). Ignore
|
||||
# the first number (0).
|
||||
# * The maximum number of items each slot in the Bag can hold.
|
||||
# * Whether each pocket in turn auto-sorts itself by item ID number. Ignore
|
||||
# the first entry (the 0).
|
||||
# * The pocket number containing all berries. Is opened when choosing one to
|
||||
# plant, and cannot view a different pocket while doing so.
|
||||
#===============================================================================
|
||||
def pbPocketNames; return ["",
|
||||
_INTL("Items"),
|
||||
_INTL("Medicine"),
|
||||
_INTL("Poké Balls"),
|
||||
_INTL("TMs & HMs"),
|
||||
_INTL("Berries"),
|
||||
_INTL("Mail"),
|
||||
_INTL("Battle Items"),
|
||||
_INTL("Key Items")
|
||||
]; end
|
||||
MAXPOCKETSIZE = [0,-1,-1,-1,-1,-1,-1,-1,-1]
|
||||
BAGMAXPERSLOT = 99
|
||||
POCKETAUTOSORT = [0,true,false,false,true,true,false,false,false]
|
||||
BERRYPOCKET = 5
|
||||
|
||||
#===============================================================================
|
||||
# * The name of the person who created the Pokémon storage system.
|
||||
# * The number of boxes in Pokémon storage.
|
||||
#===============================================================================
|
||||
def pbStorageCreator
|
||||
return _INTL("Bill")
|
||||
end
|
||||
STORAGEBOXES = 16
|
||||
|
||||
#===============================================================================
|
||||
# * Whether the Pokédex list shown is the one for the player's current region
|
||||
# (true), or whether a menu pops up for the player to manually choose which
|
||||
# Dex list to view when appropriate (false).
|
||||
# * The names of each Dex list in the game, in order and with National Dex at
|
||||
# the end. This is also the order that $PokemonGlobal.pokedexUnlocked is
|
||||
# in, which records which Dexes have been unlocked (first is unlocked by
|
||||
# default).
|
||||
# You can define which region a particular Dex list is linked to. This
|
||||
# means the area map shown while viewing that Dex list will ALWAYS be that
|
||||
# of the defined region, rather than whichever region the player is
|
||||
# currently in. To define this, put the Dex name and the region number in
|
||||
# an array, like the Kanto and Johto Dexes are. The National Dex isn't in
|
||||
# an array with a region number, therefore its area map is whichever region
|
||||
# the player is currently in.
|
||||
# * Whether all forms of a given species will be immediately available to view
|
||||
# in the Pokédex so long as that species has been seen at all (true), or
|
||||
# whether each form needs to be seen specifically before that form appears
|
||||
# in the Pokédex (false).
|
||||
# * An array of numbers, where each number is that of a Dex list (National Dex
|
||||
# is -1). All Dex lists included here have the species numbers in them
|
||||
# reduced by 1, thus making the first listed species have a species number
|
||||
# of 0 (e.g. Victini).
|
||||
#===============================================================================
|
||||
DEXDEPENDSONLOCATION = false
|
||||
def pbDexNames; return [
|
||||
#[_INTL("Kanto Pokédex"),0],
|
||||
#[_INTL("Johto Pokédex"),1],
|
||||
#_INTL("Pokédex")
|
||||
]; end
|
||||
ALWAYSSHOWALLFORMS = true
|
||||
DEXINDEXOFFSETS = []
|
||||
|
||||
#===============================================================================
|
||||
# * The amount of money the player starts the game with.
|
||||
# * The maximum amount of money the player can have.
|
||||
# * The maximum number of Game Corner coins the player can have.
|
||||
#===============================================================================
|
||||
INITIALMONEY = 3000
|
||||
MAXMONEY = 9999999
|
||||
MAXCOINS = 999999
|
||||
|
||||
#===============================================================================
|
||||
# * A set of arrays each containing a trainer type followed by a Global Variable
|
||||
# number. If the variable isn't set to 0, then all trainers with the
|
||||
# associated trainer type will be named as whatever is in that variable.
|
||||
#===============================================================================
|
||||
RIVALNAMES = [
|
||||
[:RIVAL1,12],
|
||||
[:RIVAL2,12],
|
||||
[:CHAMPION,12]
|
||||
]
|
||||
|
||||
#===============================================================================
|
||||
# * A list of maps used by roaming Pokémon. Each map has an array of other maps
|
||||
# it can lead to.
|
||||
# * A set of arrays each containing the details of a roaming Pokémon. The
|
||||
# information within is as follows:
|
||||
# - Species.
|
||||
# - Level.
|
||||
# - Global Switch; the Pokémon roams while this is ON.
|
||||
# - Encounter type (0=any, 1=grass/walking in cave, 2=surfing, 3=fishing,
|
||||
# 4=surfing/fishing). See bottom of PokemonRoaming for lists.
|
||||
# - Name of BGM to play for that encounter (optional).
|
||||
# - Roaming areas specifically for this Pokémon (optional).
|
||||
#===============================================================================
|
||||
RoamingAreas = {
|
||||
262 => [261,311],
|
||||
311 => [262,312],
|
||||
312 => [311],
|
||||
261 => [262,288,267],
|
||||
288 => [261,267,285],
|
||||
267 => [261,288,300,254],
|
||||
284 => [288,266,285],
|
||||
300 => [267,254],
|
||||
254 => [300,265],
|
||||
266 => [284,265],
|
||||
265 => [266,254],
|
||||
285 => [284,288]}
|
||||
|
||||
seviiRoaming = {
|
||||
528 => [526], #Treasure beach
|
||||
526 => [528,559], #Knot Island
|
||||
559 => [526,561,564], #Kindle Road
|
||||
561 => [559], #Mt. Ember
|
||||
564 => [559,562,563,594], #brine road
|
||||
562 => [564], #boon island
|
||||
563 => [564,600] , #kin island
|
||||
594 => [564,566,603], #water labyrinth
|
||||
600 => [563,619], #bond bridge
|
||||
619 => [600] , #Berry forest
|
||||
566 => [594,603], #Resort gorgeous
|
||||
603 => [566,594], #Chrono Island
|
||||
}
|
||||
|
||||
RoamingSpecies = [
|
||||
[:ENTEI, 50, 350, 1, "Legendary Birds"],
|
||||
[:B245H243, 50, 341, 1, "Legendary Birds"],
|
||||
[:LATIOS, 50, 602, 0, "Legendary Birds",seviiRoaming],
|
||||
[:LATIAS, 50, 602, 0, "Legendary Birds",seviiRoaming],
|
||||
[:FEEBAS, 15, 4, 3, "Pokemon HeartGold and SoulSilver - Wild Pokemon Battle (Kanto)",seviiRoaming]
|
||||
]
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# * A set of arrays each containing details of a wild encounter that can only
|
||||
# occur via using the Poké Radar. The information within is as follows:
|
||||
# - Map ID on which this encounter can occur.
|
||||
# - Probability that this encounter will occur (as a percentage).
|
||||
# - Species.
|
||||
# - Minimum possible level.
|
||||
# - Maximum possible level (optional).
|
||||
#===============================================================================
|
||||
POKERADAREXCLUSIVES=[
|
||||
[78, 30, :FLETCHLING,2,5], #Rt. 1
|
||||
[86, 30, :FLETCHLING,2,5], #Rt. 2
|
||||
[90, 30, :FLETCHLING,2,5], #Rt. 2
|
||||
[491, 30, :SHROOMISH,2,5], #Viridian Forest
|
||||
[490, 30, :BUDEW,4,9], #Rt. 3
|
||||
[106, 30, :NINCADA,8,10], #Rt. 4
|
||||
[12, 30, :TOGEPI,10,10], #Rt. 5
|
||||
[16, 30, :SLAKOTH,12,15], #Rt. 6
|
||||
[413, 30, :DRIFLOON,17,20], #Rt. 7
|
||||
[409, 30, :SHINX,17,18], #Rt. 8
|
||||
[495, 30, :ARON,12,15], #Rt. 9
|
||||
[351, 30, :ARON,12,15], #Rt. 9
|
||||
[154, 30, :KLINK,14,17], #Rt. 10
|
||||
[155, 30, :NINCADA,12,15], #Rt. 11
|
||||
[159, 30, :COTTONEE,22,25], #Rt. 12
|
||||
[437, 30, :COTTONEE,22,25], #Rt. 13
|
||||
[437, 30, :JOLTIK,22,25], #Rt. 13
|
||||
[440, 30, :JOLTIK,22,25], #Rt. 14
|
||||
[444, 30, :SOLOSIS,22,25], #Rt. 15
|
||||
[438, 30, :NATU,22,25], #Rt. 16
|
||||
[146, 30, :KLEFKI,22,25], #Rt. 17
|
||||
[517, 30, :FERROSEED,22,25], #Rt. 18
|
||||
[445, 30, :BAGON,20,20], #Safari zone 1
|
||||
[484, 30, :AXEW,20,20], #Safari zone 2
|
||||
[485, 30, :DEINO,20,20], #Safari zone 3
|
||||
[486, 30, :LARVITAR,20,20], #Safari zone 4
|
||||
[487, 30, :BELDUM,20,20], #Safari zone 5
|
||||
[59, 30, :DUNSPARSE,25,30], #Rt. 21
|
||||
[171, 30, :BIDOOF,2,5], #Rt. 22
|
||||
[143, 30, :RIOLU,25,25], #Rt. 23
|
||||
[8, 30, :BUNEARY,12,13], #Rt. 24
|
||||
[145, 5, :ABSOL,30,35], #Rt. 26
|
||||
[147, 5, :ABSOL,30,35], #Rt. 27
|
||||
[311, 30, :BIDOOF,5,5], #Rt. 29
|
||||
[265, 30, :KIRLIA,25,30], #Rt. 34
|
||||
[300, 30, :ROSELIA,30,30], #National Park
|
||||
[300, 30, :BRELOOM,30,30], #Ilex Forest
|
||||
[670, 30, :WEAVILE,50,50], #Ice mountains
|
||||
[528, 30, :PYUKUMUKU,20,20], #Treasure Beach
|
||||
[690, 30, :OCTILLERY,32,45], #Deep Ocean
|
||||
[561, 30, :MAGMAR,32,45], #Mt. Ember
|
||||
[654, 30, :WHIMSICOTT,32,45], #Brine Road
|
||||
]
|
||||
|
||||
#===============================================================================
|
||||
# * A set of arrays each containing details of a graphic to be shown on the
|
||||
# region map if appropriate. The values for each array are as follows:
|
||||
# - Region number.
|
||||
# - Global Switch; the graphic is shown if this is ON (non-wall maps only).
|
||||
# - X coordinate of the graphic on the map, in squares.
|
||||
# - Y coordinate of the graphic on the map, in squares.
|
||||
# - Name of the graphic, found in the Graphics/Pictures folder.
|
||||
# - The graphic will always (true) or never (false) be shown on a wall map.
|
||||
#===============================================================================
|
||||
REGIONMAPEXTRAS = [
|
||||
[0,51,16,15,"mapHiddenDaroxy",false],
|
||||
[0,52,20,14,"mapHiddenFaraday",false]
|
||||
]
|
||||
|
||||
#===============================================================================
|
||||
# * The number of steps allowed before a Safari Zone game is over (0=infinite).
|
||||
# * The number of seconds a Bug Catching Contest lasts for (0=infinite).
|
||||
#===============================================================================
|
||||
SAFARISTEPS = 500
|
||||
BUGCONTESTTIME = 1200
|
||||
|
||||
#===============================================================================
|
||||
# * The Global Switch that is set to ON when the player whites out.
|
||||
# * The Global Switch that is set to ON when the player has seen Pokérus in the
|
||||
# Poké Center, and doesn't need to be told about it again.
|
||||
# * The Global Switch which, while ON, makes all wild Pokémon created be
|
||||
# shiny.
|
||||
# * The Global Switch which, while ON, makes all Pokémon created considered to
|
||||
# be met via a fateful encounter.
|
||||
# * The Global Switch which determines whether the player will lose money if
|
||||
# they lose a battle (they can still gain money from trainers for winning).
|
||||
# * The Global Switch which, while ON, prevents all Pokémon in battle from Mega
|
||||
# Evolving even if they otherwise could.
|
||||
# * The ID of the common event that runs when the player starts fishing (runs
|
||||
# instead of showing the casting animation).
|
||||
# * The ID of the common event that runs when the player stops fishing (runs
|
||||
# instead of showing the reeling in animation).
|
||||
#===============================================================================
|
||||
STARTING_OVER_SWITCH = 1
|
||||
SEEN_POKERUS_SWITCH = 2
|
||||
SHINY_WILD_POKEMON_SWITCH = 31
|
||||
FATEFUL_ENCOUNTER_SWITCH = 32
|
||||
NO_MONEY_LOSS = 33
|
||||
NO_MEGA_EVOLUTION = 34
|
||||
FISHINGBEGINCOMMONEVENT = -1
|
||||
FISHINGENDCOMMONEVENT = -1
|
||||
|
||||
#===============================================================================
|
||||
# * The ID of the animation played when the player steps on grass (shows grass
|
||||
# rustling).
|
||||
# * The ID of the animation played when a trainer notices the player (an
|
||||
# exclamation bubble).
|
||||
# * The ID of the animation played when a patch of grass rustles due to using
|
||||
# the Poké Radar.
|
||||
# * The ID of the animation played when a patch of grass rustles vigorously due
|
||||
# to using the Poké Radar. (Rarer species)
|
||||
# * The ID of the animation played when a patch of grass rustles and shines due
|
||||
# to using the Poké Radar. (Shiny encounter)
|
||||
# * The ID of the animation played when a berry tree grows a stage while the
|
||||
# player is on the map (for new plant growth mechanics only).
|
||||
#===============================================================================
|
||||
GRASS_ANIMATION_ID = 1
|
||||
DUST_ANIMATION_ID = 2
|
||||
EXCLAMATION_ANIMATION_ID = 3
|
||||
RUSTLE_NORMAL_ANIMATION_ID = 1
|
||||
RUSTLE_VIGOROUS_ANIMATION_ID = 5
|
||||
RUSTLE_SHINY_ANIMATION_ID = 6
|
||||
PLANT_SPARKLE_ANIMATION_ID = 7
|
||||
|
||||
#===============================================================================
|
||||
# * An array of available languages in the game, and their corresponding
|
||||
# message file in the Data folder. Edit only if you have 2 or more
|
||||
# languages to choose from.
|
||||
#===============================================================================
|
||||
LANGUAGES = [
|
||||
# ["English","english.dat"],
|
||||
# ["Deutsch","deutsch.dat"]
|
||||
]
|
||||
|
||||
HIDDEN_MAP_ALWAYS = [178,655,570,356]
|
||||
RANDOM_HIDDEN_MAP_LIST = [8,109,431,446,402,403,467,468,10,23,167,16,19,78,185,86,
|
||||
491,90,40,342,490,102,103,104,105,106,1,12,413,445,484,485,486,140,350,146,
|
||||
149,304,356,307,409,351,495,154,349,322,323,544,198,144,155,444,58,59,229,52,53,54,
|
||||
55,98,173,174,181,187,95,159,162,437,220,440,438,57,171,172,528,265,288,364,329,
|
||||
335,254,261,262,266,230,145,147,258,284,283,267,586,285,286,287,300,311,47,580,529,
|
||||
635,638,646,560,559,526,600,564,594,566,562,619,563,603,561,597,633,640,641,621,312,
|
||||
670,692,643,523,698,
|
||||
602,642,623,569,588,573,362,645,651,376
|
||||
]
|
||||
#the last line is legendary maps
|
||||
|
||||
|
||||
# Various config constants used for sprite scaling
|
||||
# used to scale the trainer bitmaps to 200%
|
||||
TRAINERSPRITESCALE = 1.2
|
||||
|
||||
# used to scale the Pokemon bitmaps to 200%
|
||||
POKEMONSPRITESCALE = 0.66666
|
||||
|
||||
# used to scale the backsprite for battle perspective (200%)
|
||||
BACKSPRITESCALE = 0.875 #0.8
|
||||
|
||||
BATTLER_Y_OFFSET = 20
|
||||
OPPONENT_Y_OFFSET=20
|
||||
123
Data/Scripts_backup/003_Game processing/001_StartGame.rb
Normal file
123
Data/Scripts_backup/003_Game processing/001_StartGame.rb
Normal file
@@ -0,0 +1,123 @@
|
||||
# The Game module contains methods for saving and loading the game.
|
||||
module Game
|
||||
# Initializes various global variables and loads the game data.
|
||||
def self.initialize
|
||||
$PokemonTemp = PokemonTemp.new
|
||||
$game_temp = Game_Temp.new
|
||||
$game_system = Game_System.new
|
||||
$data_animations = load_data('Data/Animations.rxdata')
|
||||
$data_tilesets = load_data('Data/Tilesets.rxdata')
|
||||
$data_common_events = load_data('Data/CommonEvents.rxdata')
|
||||
$data_system = load_data('Data/System.rxdata')
|
||||
pbLoadBattleAnimations
|
||||
GameData.load_all
|
||||
map_file = format('Data/Map%03d.rxdata', $data_system.start_map_id)
|
||||
if $data_system.start_map_id == 0 || !pbRgssExists?(map_file)
|
||||
raise _INTL('No starting position was set in the map editor.')
|
||||
end
|
||||
end
|
||||
|
||||
# Loads bootup data from save file (if it exists) or creates bootup data (if
|
||||
# it doesn't).
|
||||
def self.set_up_system
|
||||
SaveData.move_old_windows_save if System.platform[/Windows/]
|
||||
save_data = (SaveData.exists?) ? SaveData.read_from_file(SaveData::FILE_PATH) : {}
|
||||
if save_data.empty?
|
||||
SaveData.initialize_bootup_values
|
||||
else
|
||||
SaveData.load_bootup_values(save_data)
|
||||
end
|
||||
# Set resize factor
|
||||
pbSetResizeFactor([$PokemonSystem.screensize, 4].min)
|
||||
# Set language (and choose language if there is no save file)
|
||||
if Settings::LANGUAGES.length >= 2
|
||||
$PokemonSystem.language = pbChooseLanguage if save_data.empty?
|
||||
pbLoadMessages('Data/' + Settings::LANGUAGES[$PokemonSystem.language][1])
|
||||
end
|
||||
end
|
||||
|
||||
# Called when starting a new game. Initializes global variables
|
||||
# and transfers the player into the map scene.
|
||||
def self.start_new
|
||||
if $game_map && $game_map.events
|
||||
$game_map.events.each_value { |event| event.clear_starting }
|
||||
end
|
||||
$game_temp.common_event_id = 0 if $game_temp
|
||||
$PokemonTemp.begunNewGame = true
|
||||
$scene = Scene_Map.new
|
||||
SaveData.load_new_game_values
|
||||
$MapFactory = PokemonMapFactory.new($data_system.start_map_id)
|
||||
$game_player.moveto($data_system.start_x, $data_system.start_y)
|
||||
$game_player.refresh
|
||||
$PokemonEncounters = PokemonEncounters.new
|
||||
$PokemonEncounters.setup($game_map.map_id)
|
||||
$game_map.autoplay
|
||||
$game_map.update
|
||||
end
|
||||
|
||||
# Loads the game from the given save data and starts the map scene.
|
||||
# @param save_data [Hash] hash containing the save data
|
||||
# @raise [SaveData::InvalidValueError] if an invalid value is being loaded
|
||||
def self.load(save_data)
|
||||
validate save_data => Hash
|
||||
SaveData.load_all_values(save_data)
|
||||
self.load_map
|
||||
pbAutoplayOnSave
|
||||
$game_map.update
|
||||
$PokemonMap.updateMap
|
||||
$scene = Scene_Map.new
|
||||
end
|
||||
|
||||
# Loads and validates the map. Called when loading a saved game.
|
||||
def self.load_map
|
||||
$game_map = $MapFactory.map
|
||||
magic_number_matches = ($game_system.magic_number == $data_system.magic_number)
|
||||
if !magic_number_matches || $PokemonGlobal.safesave
|
||||
if pbMapInterpreterRunning?
|
||||
pbMapInterpreter.setup(nil, 0)
|
||||
end
|
||||
begin
|
||||
$MapFactory.setup($game_map.map_id)
|
||||
rescue Errno::ENOENT
|
||||
if $DEBUG
|
||||
pbMessage(_INTL('Map {1} was not found.', $game_map.map_id))
|
||||
map = pbWarpToMapList
|
||||
exit unless map
|
||||
$MapFactory.setup(map[0])
|
||||
$game_player.moveto(map[1], map[2])
|
||||
else
|
||||
raise _INTL('The map was not found. The game cannot continue.')
|
||||
end
|
||||
end
|
||||
$game_player.center($game_player.x, $game_player.y)
|
||||
else
|
||||
$MapFactory.setMapChanged($game_map.map_id)
|
||||
end
|
||||
if $game_map.events.nil?
|
||||
raise _INTL('The map is corrupt. The game cannot continue.')
|
||||
end
|
||||
$PokemonEncounters = PokemonEncounters.new
|
||||
$PokemonEncounters.setup($game_map.map_id)
|
||||
pbUpdateVehicle
|
||||
end
|
||||
|
||||
# Saves the game. Returns whether the operation was successful.
|
||||
# @param save_file [String] the save file path
|
||||
# @param safe [Boolean] whether $PokemonGlobal.safesave should be set to true
|
||||
# @return [Boolean] whether the operation was successful
|
||||
# @raise [SaveData::InvalidValueError] if an invalid value is being saved
|
||||
def self.save(save_file = SaveData::FILE_PATH, safe: false)
|
||||
validate save_file => String, safe => [TrueClass, FalseClass]
|
||||
$PokemonGlobal.safesave = safe
|
||||
$game_system.save_count += 1
|
||||
$game_system.magic_number = $data_system.magic_number
|
||||
begin
|
||||
SaveData.save_to_file(save_file)
|
||||
Graphics.frame_reset
|
||||
rescue IOError, SystemCallError
|
||||
$game_system.save_count -= 1
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
228
Data/Scripts_backup/003_Game processing/002_Scene_Map.rb
Normal file
228
Data/Scripts_backup/003_Game processing/002_Scene_Map.rb
Normal file
@@ -0,0 +1,228 @@
|
||||
#===============================================================================
|
||||
# ** Modified Scene_Map class for Pokémon.
|
||||
#-------------------------------------------------------------------------------
|
||||
#
|
||||
#===============================================================================
|
||||
class Scene_Map
|
||||
attr_reader :spritesetGlobal
|
||||
|
||||
def spriteset
|
||||
for i in @spritesets.values
|
||||
return i if i.map==$game_map
|
||||
end
|
||||
return @spritesets.values[0]
|
||||
end
|
||||
|
||||
def createSpritesets
|
||||
@spritesetGlobal = Spriteset_Global.new
|
||||
@spritesets = {}
|
||||
for map in $MapFactory.maps
|
||||
@spritesets[map.map_id] = Spriteset_Map.new(map)
|
||||
end
|
||||
$MapFactory.setSceneStarted(self)
|
||||
updateSpritesets
|
||||
end
|
||||
|
||||
def createSingleSpriteset(map)
|
||||
temp = $scene.spriteset.getAnimations
|
||||
@spritesets[map] = Spriteset_Map.new($MapFactory.maps[map])
|
||||
$scene.spriteset.restoreAnimations(temp)
|
||||
$MapFactory.setSceneStarted(self)
|
||||
updateSpritesets
|
||||
end
|
||||
|
||||
def disposeSpritesets
|
||||
return if !@spritesets
|
||||
for i in @spritesets.keys
|
||||
next if !@spritesets[i]
|
||||
@spritesets[i].dispose
|
||||
@spritesets[i] = nil
|
||||
end
|
||||
@spritesets.clear
|
||||
@spritesets = {}
|
||||
@spritesetGlobal.dispose
|
||||
@spritesetGlobal = nil
|
||||
end
|
||||
|
||||
def autofade(mapid)
|
||||
playingBGM = $game_system.playing_bgm
|
||||
playingBGS = $game_system.playing_bgs
|
||||
return if !playingBGM && !playingBGS
|
||||
map = load_data(sprintf("Data/Map%03d.rxdata", mapid))
|
||||
if playingBGM && map.autoplay_bgm
|
||||
if (PBDayNight.isNight? rescue false)
|
||||
pbBGMFade(0.8) if playingBGM.name!=map.bgm.name && playingBGM.name!=map.bgm.name+"_n"
|
||||
else
|
||||
pbBGMFade(0.8) if playingBGM.name!=map.bgm.name
|
||||
end
|
||||
end
|
||||
if playingBGS && map.autoplay_bgs
|
||||
pbBGMFade(0.8) if playingBGS.name!=map.bgs.name
|
||||
end
|
||||
Graphics.frame_reset
|
||||
end
|
||||
|
||||
def transfer_player(cancelVehicles=true)
|
||||
$game_temp.player_transferring = false
|
||||
pbCancelVehicles($game_temp.player_new_map_id) if cancelVehicles
|
||||
autofade($game_temp.player_new_map_id)
|
||||
pbBridgeOff
|
||||
@spritesetGlobal.playersprite.clearShadows
|
||||
if $game_map.map_id!=$game_temp.player_new_map_id
|
||||
$MapFactory.setup($game_temp.player_new_map_id)
|
||||
end
|
||||
$game_player.moveto($game_temp.player_new_x, $game_temp.player_new_y)
|
||||
case $game_temp.player_new_direction
|
||||
when 2 then $game_player.turn_down
|
||||
when 4 then $game_player.turn_left
|
||||
when 6 then $game_player.turn_right
|
||||
when 8 then $game_player.turn_up
|
||||
end
|
||||
$game_player.straighten
|
||||
$game_map.update
|
||||
disposeSpritesets
|
||||
RPG::Cache.clear
|
||||
createSpritesets
|
||||
if $game_temp.transition_processing
|
||||
$game_temp.transition_processing = false
|
||||
Graphics.transition(20)
|
||||
end
|
||||
$game_map.autoplay
|
||||
Graphics.frame_reset
|
||||
Input.update
|
||||
end
|
||||
|
||||
def call_menu
|
||||
$game_temp.menu_calling = false
|
||||
$game_temp.in_menu = true
|
||||
$game_player.straighten
|
||||
$game_map.update
|
||||
sscene = PokemonPauseMenu_Scene.new
|
||||
sscreen = PokemonPauseMenu.new(sscene)
|
||||
sscreen.pbStartPokemonMenu
|
||||
$game_temp.in_menu = false
|
||||
end
|
||||
|
||||
def call_debug
|
||||
$game_temp.debug_calling = false
|
||||
pbPlayDecisionSE
|
||||
$game_player.straighten
|
||||
pbFadeOutIn { pbDebugMenu }
|
||||
end
|
||||
|
||||
def miniupdate
|
||||
$PokemonTemp.miniupdate = true
|
||||
loop do
|
||||
updateMaps
|
||||
$game_player.update
|
||||
$game_system.update
|
||||
$game_screen.update
|
||||
break unless $game_temp.player_transferring
|
||||
transfer_player
|
||||
break if $game_temp.transition_processing
|
||||
end
|
||||
updateSpritesets
|
||||
$PokemonTemp.miniupdate = false
|
||||
end
|
||||
|
||||
def updateMaps
|
||||
for map in $MapFactory.maps
|
||||
map.update
|
||||
end
|
||||
$MapFactory.updateMaps(self)
|
||||
end
|
||||
|
||||
def updateSpritesets
|
||||
@spritesets = {} if !@spritesets
|
||||
keys = @spritesets.keys.clone
|
||||
for i in keys
|
||||
if !$MapFactory.hasMap?(i)
|
||||
@spritesets[i].dispose if @spritesets[i]
|
||||
@spritesets[i] = nil
|
||||
@spritesets.delete(i)
|
||||
else
|
||||
@spritesets[i].update
|
||||
end
|
||||
end
|
||||
@spritesetGlobal.update
|
||||
for map in $MapFactory.maps
|
||||
@spritesets[map.map_id] = Spriteset_Map.new(map) if !@spritesets[map.map_id]
|
||||
end
|
||||
Events.onMapUpdate.trigger(self)
|
||||
end
|
||||
|
||||
def update
|
||||
loop do
|
||||
updateMaps
|
||||
pbMapInterpreter.update
|
||||
$game_player.update
|
||||
$game_system.update
|
||||
$game_screen.update
|
||||
break unless $game_temp.player_transferring
|
||||
transfer_player
|
||||
break if $game_temp.transition_processing
|
||||
end
|
||||
updateSpritesets
|
||||
if $game_temp.to_title
|
||||
$scene = pbCallTitle
|
||||
return
|
||||
end
|
||||
if $game_temp.transition_processing
|
||||
$game_temp.transition_processing = false
|
||||
if $game_temp.transition_name == ""
|
||||
Graphics.transition(20)
|
||||
else
|
||||
Graphics.transition(40, "Graphics/Transitions/" + $game_temp.transition_name)
|
||||
end
|
||||
end
|
||||
return if $game_temp.message_window_showing
|
||||
if !pbMapInterpreterRunning?
|
||||
if Input.trigger?(Input::USE)
|
||||
$PokemonTemp.hiddenMoveEventCalling = true
|
||||
elsif Input.trigger?(Input::BACK)
|
||||
unless $game_system.menu_disabled || $game_player.moving?
|
||||
$game_temp.menu_calling = true
|
||||
$game_temp.menu_beep = true
|
||||
end
|
||||
elsif Input.trigger?(Input::SPECIAL)
|
||||
unless $game_player.moving?
|
||||
$PokemonTemp.keyItemCalling = true
|
||||
end
|
||||
elsif Input.press?(Input::F9)
|
||||
$game_temp.debug_calling = true if $DEBUG
|
||||
end
|
||||
end
|
||||
unless $game_player.moving?
|
||||
if $game_temp.menu_calling
|
||||
call_menu
|
||||
elsif $game_temp.debug_calling
|
||||
call_debug
|
||||
elsif $PokemonTemp.keyItemCalling
|
||||
$PokemonTemp.keyItemCalling = false
|
||||
$game_player.straighten
|
||||
pbUseKeyItem
|
||||
elsif $PokemonTemp.hiddenMoveEventCalling
|
||||
$PokemonTemp.hiddenMoveEventCalling = false
|
||||
$game_player.straighten
|
||||
Events.onAction.trigger(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def main
|
||||
createSpritesets
|
||||
Graphics.transition(20)
|
||||
loop do
|
||||
Graphics.update
|
||||
Input.update
|
||||
update
|
||||
break if $scene != self
|
||||
end
|
||||
Graphics.freeze
|
||||
disposeSpritesets
|
||||
if $game_temp.to_title
|
||||
Graphics.transition(20)
|
||||
Graphics.freeze
|
||||
end
|
||||
end
|
||||
end
|
||||
453
Data/Scripts_backup/003_Game processing/003_Interpreter.rb
Normal file
453
Data/Scripts_backup/003_Game processing/003_Interpreter.rb
Normal file
@@ -0,0 +1,453 @@
|
||||
#===============================================================================
|
||||
# ** Interpreter
|
||||
#-------------------------------------------------------------------------------
|
||||
# This interpreter runs event commands. This class is used within the
|
||||
# Game_System class and the Game_Event class.
|
||||
#===============================================================================
|
||||
class Interpreter
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Object Initialization
|
||||
# depth : nest depth
|
||||
# main : main flag
|
||||
#-----------------------------------------------------------------------------
|
||||
def initialize(depth = 0, main = false)
|
||||
@depth = depth
|
||||
@main = main
|
||||
if depth > 100
|
||||
print("Common event call has exceeded maximum limit.")
|
||||
exit
|
||||
end
|
||||
clear
|
||||
end
|
||||
|
||||
def inspect
|
||||
str = super.chop
|
||||
str << format(' @event_id: %d>', @event_id)
|
||||
return str
|
||||
end
|
||||
|
||||
def clear
|
||||
@map_id = 0 # map ID when starting up
|
||||
@event_id = 0 # event ID
|
||||
@message_waiting = false # waiting for message to end
|
||||
@move_route_waiting = false # waiting for move completion
|
||||
@wait_count = 0 # wait count
|
||||
@child_interpreter = nil # child interpreter
|
||||
@branch = {} # branch data
|
||||
@buttonInput = false
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Event Setup
|
||||
# list : list of event commands
|
||||
# event_id : event ID
|
||||
#-----------------------------------------------------------------------------
|
||||
def setup(list, event_id, map_id = nil)
|
||||
clear
|
||||
@map_id = map_id || $game_map.map_id
|
||||
@event_id = event_id
|
||||
@list = list
|
||||
@index = 0
|
||||
@branch.clear
|
||||
end
|
||||
|
||||
def setup_starting_event
|
||||
$game_map.refresh if $game_map.need_refresh
|
||||
# Set up common event if one wants to start
|
||||
if $game_temp.common_event_id > 0
|
||||
setup($data_common_events[$game_temp.common_event_id].list, 0)
|
||||
$game_temp.common_event_id = 0
|
||||
return
|
||||
end
|
||||
# Check all map events for one that wants to start, and set it up
|
||||
for event in $game_map.events.values
|
||||
next if !event.starting
|
||||
if event.trigger < 3 # Isn't autorun or parallel processing
|
||||
event.lock
|
||||
event.clear_starting
|
||||
end
|
||||
setup(event.list, event.id, event.map.map_id)
|
||||
return
|
||||
end
|
||||
# Check all common events for one that is autorun, and set it up
|
||||
for common_event in $data_common_events.compact
|
||||
next if common_event.trigger != 1 || !$game_switches[common_event.switch_id]
|
||||
setup(common_event.list, 0)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
def running?
|
||||
return @list != nil
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Frame Update
|
||||
#-----------------------------------------------------------------------------
|
||||
def update
|
||||
@loop_count = 0
|
||||
loop do
|
||||
@loop_count += 1
|
||||
if @loop_count > 100 # Call Graphics.update for freeze prevention
|
||||
Graphics.update
|
||||
@loop_count = 0
|
||||
end
|
||||
# If this interpreter's map isn't the current map or connected to it,
|
||||
# forget this interpreter's event ID
|
||||
if $game_map.map_id != @map_id && !$MapFactory.areConnected?($game_map.map_id, @map_id)
|
||||
@event_id = 0
|
||||
end
|
||||
# Update child interpreter if one exists
|
||||
if @child_interpreter
|
||||
@child_interpreter.update
|
||||
@child_interpreter = nil if !@child_interpreter.running?
|
||||
return if @child_interpreter
|
||||
end
|
||||
# Do nothing if a message is being shown
|
||||
return if @message_waiting
|
||||
# Do nothing if any event or the player is in the middle of a move route
|
||||
if @move_route_waiting
|
||||
return if $game_player.move_route_forcing
|
||||
for event in $game_map.events.values
|
||||
return if event.move_route_forcing
|
||||
end
|
||||
@move_route_waiting = false
|
||||
end
|
||||
# Do nothing while waiting
|
||||
if @wait_count > 0
|
||||
@wait_count -= 1
|
||||
return
|
||||
end
|
||||
# Do nothing if the pause menu is going to open
|
||||
return if $game_temp.menu_calling
|
||||
# If there are no commands in the list, try to find something that wants to run
|
||||
if @list.nil?
|
||||
setup_starting_event if @main
|
||||
return if @list.nil? # Couldn't find anything that wants to run
|
||||
end
|
||||
# Execute the next command
|
||||
return if execute_command == false
|
||||
# Move to the next @index
|
||||
@index += 1
|
||||
end
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Execute script
|
||||
#-----------------------------------------------------------------------------
|
||||
def execute_script(script)
|
||||
begin
|
||||
result = eval(script)
|
||||
return result
|
||||
rescue Exception
|
||||
e = $!
|
||||
raise if e.is_a?(SystemExit) || "#{e.class}" == "Reset"
|
||||
event = get_self
|
||||
s = "Backtrace:\r\n"
|
||||
message = pbGetExceptionMessage(e)
|
||||
if e.is_a?(SyntaxError)
|
||||
script.each_line { |line|
|
||||
line.gsub!(/\s+$/, "")
|
||||
if line[/^\s*\(/]
|
||||
message += "\r\n***Line '#{line}' shouldn't begin with '('. Try\r\n"
|
||||
message += "putting the '(' at the end of the previous line instead,\r\n"
|
||||
message += "or using 'extendtext.exe'."
|
||||
end
|
||||
if line[/\:\:\s*$/]
|
||||
message += "\r\n***Line '#{line}' can't end with '::'. Try putting\r\n"
|
||||
message += "the next word on the same line, e.g. 'PBSpecies:" + ":MEW'"
|
||||
end
|
||||
}
|
||||
else
|
||||
for bt in e.backtrace[0, 10]
|
||||
s += bt + "\r\n"
|
||||
end
|
||||
s.gsub!(/Section(\d+)/) { $RGSS_SCRIPTS[$1.to_i][1] }
|
||||
end
|
||||
message = "Exception: #{e.class}\r\nMessage: " + message + "\r\n"
|
||||
message += "\r\n***Full script:\r\n#{script}\r\n"
|
||||
if event && $game_map
|
||||
map_name = ($game_map.name rescue nil) || "???"
|
||||
err = "Script error in event #{event.id} (coords #{event.x},#{event.y}), map #{$game_map.map_id} (#{map_name}):\r\n"
|
||||
err += "#{message}\r\n#{s}"
|
||||
if e.is_a?(Hangup)
|
||||
$EVENTHANGUPMSG = err
|
||||
raise
|
||||
end
|
||||
elsif $game_map
|
||||
map_name = ($game_map.name rescue nil) || "???"
|
||||
err = "Script error in map #{$game_map.map_id} (#{map_name}):\r\n"
|
||||
err += "#{message}\r\n#{s}"
|
||||
if e.is_a?(Hangup)
|
||||
$EVENTHANGUPMSG = err
|
||||
raise
|
||||
end
|
||||
else
|
||||
err = "Script error in interpreter:\r\n#{message}\r\n#{s}"
|
||||
if e.is_a?(Hangup)
|
||||
$EVENTHANGUPMSG = err
|
||||
raise
|
||||
end
|
||||
end
|
||||
raise err
|
||||
end
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Get Character
|
||||
# parameter : parameter
|
||||
#-----------------------------------------------------------------------------
|
||||
def get_character(parameter = 0)
|
||||
case parameter
|
||||
when -1 # player
|
||||
return $game_player
|
||||
when 0 # this event
|
||||
events = $game_map.events
|
||||
return (events) ? events[@event_id] : nil
|
||||
else # specific event
|
||||
events = $game_map.events
|
||||
return (events) ? events[parameter] : nil
|
||||
end
|
||||
end
|
||||
|
||||
def get_player
|
||||
return get_character(-1)
|
||||
end
|
||||
|
||||
def get_self
|
||||
return get_character(0)
|
||||
end
|
||||
|
||||
def get_event(parameter)
|
||||
return get_character(parameter)
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Freezes all events on the map (for use at the beginning of common events)
|
||||
#-----------------------------------------------------------------------------
|
||||
def pbGlobalLock
|
||||
$game_map.events.values.each { |event| event.minilock }
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Unfreezes all events on the map (for use at the end of common events)
|
||||
#-----------------------------------------------------------------------------
|
||||
def pbGlobalUnlock
|
||||
$game_map.events.values.each { |event| event.unlock }
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Gets the next index in the interpreter, ignoring certain commands between messages
|
||||
#-----------------------------------------------------------------------------
|
||||
def pbNextIndex(index)
|
||||
return -1 if !@list || @list.length == 0
|
||||
i = index + 1
|
||||
loop do
|
||||
return i if i >= @list.length - 1
|
||||
case @list[i].code
|
||||
when 118, 108, 408 # Label, Comment
|
||||
i += 1
|
||||
when 413 # Repeat Above
|
||||
i = pbRepeatAbove(i)
|
||||
when 113 # Break Loop
|
||||
i = pbBreakLoop(i)
|
||||
when 119 # Jump to Label
|
||||
newI = pbJumpToLabel(i, @list[i].parameters[0])
|
||||
i = (newI > i) ? newI : i + 1
|
||||
else
|
||||
return i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def pbRepeatAbove(index)
|
||||
index = @list[index].indent
|
||||
loop do
|
||||
index -= 1
|
||||
return index + 1 if @list[index].indent == indent
|
||||
end
|
||||
end
|
||||
|
||||
def pbBreakLoop(index)
|
||||
indent = @list[index].indent
|
||||
temp_index = index
|
||||
loop do
|
||||
temp_index += 1
|
||||
return index + 1 if temp_index >= @list.size - 1
|
||||
return temp_index + 1 if @list[temp_index].code == 413 &&
|
||||
@list[temp_index].indent < indent
|
||||
end
|
||||
end
|
||||
|
||||
def pbJumpToLabel(index, label_name)
|
||||
temp_index = 0
|
||||
loop do
|
||||
return index + 1 if temp_index >= @list.size - 1
|
||||
return temp_index + 1 if @list[temp_index].code == 118 &&
|
||||
@list[temp_index].parameters[0] == label_name
|
||||
temp_index += 1
|
||||
end
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Various methods to be used in a script event command.
|
||||
#-----------------------------------------------------------------------------
|
||||
# Helper function that shows a picture in a script.
|
||||
def pbShowPicture(number, name, origin, x, y, zoomX = 100, zoomY = 100, opacity = 255, blendType = 0)
|
||||
number = number + ($game_temp.in_battle ? 50 : 0)
|
||||
$game_screen.pictures[number].show(name, origin, x, y, zoomX, zoomY, opacity, blendType)
|
||||
end
|
||||
|
||||
# Erases an event and adds it to the list of erased events so that
|
||||
# it can stay erased when the game is saved then loaded again.
|
||||
def pbEraseThisEvent
|
||||
if $game_map.events[@event_id]
|
||||
$game_map.events[@event_id].erase
|
||||
$PokemonMap.addErasedEvent(@event_id) if $PokemonMap
|
||||
end
|
||||
@index += 1
|
||||
return true
|
||||
end
|
||||
|
||||
# Runs a common event.
|
||||
def pbCommonEvent(id)
|
||||
common_event = $data_common_events[id]
|
||||
return if !common_event
|
||||
if $game_temp.in_battle
|
||||
$game_system.battle_interpreter.setup(common_event.list, 0)
|
||||
else
|
||||
interp = Interpreter.new
|
||||
interp.setup(common_event.list, 0)
|
||||
loop do
|
||||
Graphics.update
|
||||
Input.update
|
||||
interp.update
|
||||
pbUpdateSceneMap
|
||||
break if !interp.running?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Sets another event's self switch (eg. pbSetSelfSwitch(20, "A", true) ).
|
||||
def pbSetSelfSwitch(eventid, switch_name, value, mapid = -1)
|
||||
mapid = @map_id if mapid < 0
|
||||
old_value = $game_self_switches[[mapid, eventid, switch_name]]
|
||||
$game_self_switches[[mapid, eventid, switch_name]] = value
|
||||
if value != old_value && $MapFactory.hasMap?(mapid)
|
||||
$MapFactory.getMap(mapid, false).need_refresh = true
|
||||
end
|
||||
end
|
||||
|
||||
def tsOff?(c)
|
||||
return get_self.tsOff?(c)
|
||||
end
|
||||
alias isTempSwitchOff? tsOff?
|
||||
|
||||
def tsOn?(c)
|
||||
return get_self.tsOn?(c)
|
||||
end
|
||||
alias isTempSwitchOn? tsOn?
|
||||
|
||||
def setTempSwitchOn(c)
|
||||
get_self.setTempSwitchOn(c)
|
||||
end
|
||||
|
||||
def setTempSwitchOff(c)
|
||||
get_self.setTempSwitchOff(c)
|
||||
end
|
||||
|
||||
def getVariable(*arg)
|
||||
if arg.length == 0
|
||||
return nil if !$PokemonGlobal.eventvars
|
||||
return $PokemonGlobal.eventvars[[@map_id, @event_id]]
|
||||
else
|
||||
return $game_variables[arg[0]]
|
||||
end
|
||||
end
|
||||
|
||||
def setVariable(*arg)
|
||||
if arg.length == 1
|
||||
$PokemonGlobal.eventvars = {} if !$PokemonGlobal.eventvars
|
||||
$PokemonGlobal.eventvars[[@map_id, @event_id]] = arg[0]
|
||||
else
|
||||
$game_variables[arg[0]] = arg[1]
|
||||
$game_map.need_refresh = true
|
||||
end
|
||||
end
|
||||
|
||||
def pbGetPokemon(id)
|
||||
return $Trainer.party[pbGet(id)]
|
||||
end
|
||||
|
||||
def pbSetEventTime(*arg)
|
||||
$PokemonGlobal.eventvars = {} if !$PokemonGlobal.eventvars
|
||||
time = pbGetTimeNow
|
||||
time = time.to_i
|
||||
pbSetSelfSwitch(@event_id, "A", true)
|
||||
$PokemonGlobal.eventvars[[@map_id, @event_id]] = time
|
||||
for otherevt in arg
|
||||
pbSetSelfSwitch(otherevt, "A", true)
|
||||
$PokemonGlobal.eventvars[[@map_id, otherevt]] = time
|
||||
end
|
||||
end
|
||||
|
||||
# Used in boulder events. Allows an event to be pushed.
|
||||
def pbPushThisEvent
|
||||
event = get_self
|
||||
old_x = event.x
|
||||
old_y = event.y
|
||||
# Apply strict version of passable, which treats tiles that are passable
|
||||
# only from certain directions as fully impassible
|
||||
return if !event.can_move_in_direction?($game_player.direction, true)
|
||||
case $game_player.direction
|
||||
when 2 then event.move_down
|
||||
when 4 then event.move_left
|
||||
when 6 then event.move_right
|
||||
when 8 then event.move_up
|
||||
end
|
||||
$PokemonMap.addMovedEvent(@event_id) if $PokemonMap
|
||||
if old_x != event.x || old_y != event.y
|
||||
$game_player.lock
|
||||
loop do
|
||||
Graphics.update
|
||||
Input.update
|
||||
pbUpdateSceneMap
|
||||
break if !event.moving?
|
||||
end
|
||||
$game_player.unlock
|
||||
end
|
||||
end
|
||||
|
||||
def pbPushThisBoulder
|
||||
pbPushThisEvent if $PokemonMap.strengthUsed
|
||||
return true
|
||||
end
|
||||
|
||||
def pbSmashThisEvent
|
||||
event = get_self
|
||||
pbSmashEvent(event) if event
|
||||
@index += 1
|
||||
return true
|
||||
end
|
||||
|
||||
def pbTrainerIntro(symbol)
|
||||
return true if $DEBUG && !GameData::TrainerType.exists?(symbol)
|
||||
tr_type = GameData::TrainerType.get(symbol).id
|
||||
pbGlobalLock
|
||||
pbPlayTrainerIntroME(tr_type)
|
||||
return true
|
||||
end
|
||||
|
||||
def pbTrainerEnd
|
||||
pbGlobalUnlock
|
||||
event = get_self
|
||||
event.erase_route if event
|
||||
end
|
||||
|
||||
def setPrice(item, buy_price = -1, sell_price = -1)
|
||||
item = GameData::Item.get(item).id
|
||||
$game_temp.mart_prices[item] = [-1, -1] if !$game_temp.mart_prices[item]
|
||||
$game_temp.mart_prices[item][0] = buy_price if buy_price > 0
|
||||
if sell_price >= 0 # 0=can't sell
|
||||
$game_temp.mart_prices[item][1] = sell_price * 2
|
||||
else
|
||||
$game_temp.mart_prices[item][1] = buy_price if buy_price > 0
|
||||
end
|
||||
end
|
||||
|
||||
def setSellPrice(item, sell_price)
|
||||
setPrice(item, -1, sell_price)
|
||||
end
|
||||
end
|
||||
1027
Data/Scripts_backup/003_Game processing/004_Interpreter_Commands.rb
Normal file
1027
Data/Scripts_backup/003_Game processing/004_Interpreter_Commands.rb
Normal file
File diff suppressed because it is too large
Load Diff
275
Data/Scripts_backup/003_Game processing/005_Event_Handlers.rb
Normal file
275
Data/Scripts_backup/003_Game processing/005_Event_Handlers.rb
Normal file
@@ -0,0 +1,275 @@
|
||||
#===============================================================================
|
||||
# Defines an event that procedures can subscribe to.
|
||||
#===============================================================================
|
||||
class Event
|
||||
def initialize
|
||||
@callbacks = []
|
||||
end
|
||||
|
||||
# Sets an event handler for this event and removes all other event handlers.
|
||||
def set(method)
|
||||
@callbacks.clear
|
||||
@callbacks.push(method)
|
||||
end
|
||||
|
||||
# Removes an event handler procedure from the event.
|
||||
def -(method)
|
||||
for i in 0...@callbacks.length
|
||||
next if @callbacks[i]!=method
|
||||
@callbacks.delete_at(i)
|
||||
break
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
# Adds an event handler procedure from the event.
|
||||
def +(method)
|
||||
for i in 0...@callbacks.length
|
||||
return self if @callbacks[i]==method
|
||||
end
|
||||
@callbacks.push(method)
|
||||
return self
|
||||
end
|
||||
|
||||
# Clears the event of event handlers.
|
||||
def clear
|
||||
@callbacks.clear
|
||||
end
|
||||
|
||||
# Triggers the event and calls all its event handlers. Normally called only
|
||||
# by the code where the event occurred.
|
||||
# The first argument is the sender of the event, the second argument contains
|
||||
# the event's parameters. If three or more arguments are given, this method
|
||||
# supports the following callbacks:
|
||||
# proc { |sender,params| } where params is an array of the other parameters, and
|
||||
# proc { |sender,arg0,arg1,...| }
|
||||
def trigger(*arg)
|
||||
arglist = arg[1,arg.length]
|
||||
for callback in @callbacks
|
||||
if callback.arity>2 && arg.length==callback.arity
|
||||
# Retrofitted for callbacks that take three or more arguments
|
||||
callback.call(*arg)
|
||||
else
|
||||
callback.call(arg[0],arglist)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Triggers the event and calls all its event handlers. Normally called only
|
||||
# by the code where the event occurred. The first argument is the sender of
|
||||
# the event, the other arguments are the event's parameters.
|
||||
def trigger2(*arg)
|
||||
for callback in @callbacks
|
||||
callback.call(*arg)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class HandlerHash
|
||||
def initialize(mod)
|
||||
@mod = mod
|
||||
@hash = {}
|
||||
@addIfs = []
|
||||
@symbolCache = {}
|
||||
end
|
||||
|
||||
def fromSymbol(sym)
|
||||
return sym unless sym.is_a?(Symbol) || sym.is_a?(String)
|
||||
mod = Object.const_get(@mod) rescue nil
|
||||
return nil if !mod
|
||||
return mod.const_get(sym.to_sym) rescue nil
|
||||
end
|
||||
|
||||
def toSymbol(sym)
|
||||
return sym.to_sym if sym.is_a?(Symbol) || sym.is_a?(String)
|
||||
ret = @symbolCache[sym]
|
||||
return ret if ret
|
||||
mod = Object.const_get(@mod) rescue nil
|
||||
return nil if !mod
|
||||
for key in mod.constants
|
||||
next if mod.const_get(key)!=sym
|
||||
ret = key.to_sym
|
||||
@symbolCache[sym] = ret
|
||||
break
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def addIf(conditionProc,handler=nil,&handlerBlock)
|
||||
if ![Proc,Hash].include?(handler.class) && !block_given?
|
||||
raise ArgumentError, "addIf call for #{self.class.name} has no valid handler (#{handler.inspect} was given)"
|
||||
end
|
||||
@addIfs.push([conditionProc,handler || handlerBlock])
|
||||
end
|
||||
|
||||
def add(sym,handler=nil,&handlerBlock) # 'sym' can be an ID or symbol
|
||||
if ![Proc,Hash].include?(handler.class) && !block_given?
|
||||
raise ArgumentError, "#{self.class.name} for #{sym.inspect} has no valid handler (#{handler.inspect} was given)"
|
||||
end
|
||||
id = fromSymbol(sym)
|
||||
@hash[id] = handler || handlerBlock if id
|
||||
symbol = toSymbol(sym)
|
||||
@hash[symbol] = handler || handlerBlock if symbol
|
||||
end
|
||||
|
||||
def copy(src,*dests)
|
||||
handler = self[src]
|
||||
if handler
|
||||
for dest in dests
|
||||
self.add(dest,handler)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def [](sym) # 'sym' can be an ID or symbol
|
||||
id = fromSymbol(sym)
|
||||
ret = nil
|
||||
ret = @hash[id] if id && @hash[id] # Real ID from the item
|
||||
symbol = toSymbol(sym)
|
||||
ret = @hash[symbol] if symbol && @hash[symbol] # Symbol or string
|
||||
unless ret
|
||||
for addif in @addIfs
|
||||
return addif[1] if addif[0].call(id)
|
||||
end
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def trigger(sym,*args)
|
||||
handler = self[sym]
|
||||
return (handler) ? handler.call(fromSymbol(sym),*args) : nil
|
||||
end
|
||||
|
||||
def clear
|
||||
@hash.clear
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# A stripped-down version of class HandlerHash which only deals with symbols and
|
||||
# doesn't care about whether those symbols actually relate to a defined thing.
|
||||
#===============================================================================
|
||||
class HandlerHash2
|
||||
def initialize
|
||||
@hash = {}
|
||||
@add_ifs = []
|
||||
end
|
||||
|
||||
def [](sym)
|
||||
sym = sym.id if !sym.is_a?(Symbol) && sym.respond_to?("id")
|
||||
return @hash[sym] if sym && @hash[sym]
|
||||
for add_if in @add_ifs
|
||||
return add_if[1] if add_if[0].call(sym)
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
def addIf(conditionProc, handler = nil, &handlerBlock)
|
||||
if ![Proc, Hash].include?(handler.class) && !block_given?
|
||||
raise ArgumentError, "addIf call for #{self.class.name} has no valid handler (#{handler.inspect} was given)"
|
||||
end
|
||||
@add_ifs.push([conditionProc, handler || handlerBlock])
|
||||
end
|
||||
|
||||
def add(sym, handler = nil, &handlerBlock)
|
||||
if ![Proc, Hash].include?(handler.class) && !block_given?
|
||||
raise ArgumentError, "#{self.class.name} for #{sym.inspect} has no valid handler (#{handler.inspect} was given)"
|
||||
end
|
||||
@hash[sym] = handler || handlerBlock if sym
|
||||
end
|
||||
|
||||
def copy(src, *dests)
|
||||
handler = self[src]
|
||||
return if !handler
|
||||
for dest in dests
|
||||
self.add(dest, handler)
|
||||
end
|
||||
end
|
||||
|
||||
def clear
|
||||
@hash.clear
|
||||
end
|
||||
|
||||
def trigger(sym, *args)
|
||||
sym = sym.id if !sym.is_a?(Symbol) && sym.respond_to?("id")
|
||||
handler = self[sym]
|
||||
return (handler) ? handler.call(sym, *args) : nil
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# An even more stripped down version of class HandlerHash which just takes
|
||||
# hashes with keys, no matter what the keys are.
|
||||
#===============================================================================
|
||||
class HandlerHashBasic
|
||||
def initialize
|
||||
@ordered_keys = []
|
||||
@hash = {}
|
||||
@addIfs = []
|
||||
end
|
||||
|
||||
def [](entry)
|
||||
ret = nil
|
||||
ret = @hash[entry] if entry && @hash[entry]
|
||||
unless ret
|
||||
for addif in @addIfs
|
||||
return addif[1] if addif[0].call(entry)
|
||||
end
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def each
|
||||
@ordered_keys.each { |key| yield key, @hash[key] }
|
||||
end
|
||||
|
||||
def add(entry, handler = nil, &handlerBlock)
|
||||
if ![Proc,Hash].include?(handler.class) && !block_given?
|
||||
raise ArgumentError, "#{self.class.name} for #{entry.inspect} has no valid handler (#{handler.inspect} was given)"
|
||||
end
|
||||
return if !entry || entry.empty?
|
||||
@ordered_keys.push(entry) if !@ordered_keys.include?(entry)
|
||||
@hash[entry] = handler || handlerBlock
|
||||
end
|
||||
|
||||
def addIf(conditionProc, handler = nil, &handlerBlock)
|
||||
if ![Proc, Hash].include?(handler.class) && !block_given?
|
||||
raise ArgumentError, "addIf call for #{self.class.name} has no valid handler (#{handler.inspect} was given)"
|
||||
end
|
||||
@addIfs.push([conditionProc, handler || handlerBlock])
|
||||
end
|
||||
|
||||
def copy(src, *dests)
|
||||
handler = self[src]
|
||||
return if !handler
|
||||
dests.each { |dest| self.add(dest, handler) }
|
||||
end
|
||||
|
||||
def clear
|
||||
@hash.clear
|
||||
@ordered_keys.clear
|
||||
end
|
||||
|
||||
def trigger(entry, *args)
|
||||
handler = self[entry]
|
||||
return (handler) ? handler.call(*args) : nil
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class SpeciesHandlerHash < HandlerHash2
|
||||
end
|
||||
|
||||
class AbilityHandlerHash < HandlerHash2
|
||||
end
|
||||
|
||||
class ItemHandlerHash < HandlerHash2
|
||||
end
|
||||
|
||||
class MoveHandlerHash < HandlerHash2
|
||||
end
|
||||
@@ -0,0 +1,172 @@
|
||||
#===============================================================================
|
||||
# This module stores events that can happen during the game. A procedure can
|
||||
# subscribe to an event by adding itself to the event. It will then be called
|
||||
# whenever the event occurs.
|
||||
#===============================================================================
|
||||
module Events
|
||||
@@OnMapCreate = Event.new
|
||||
@@OnMapUpdate = Event.new
|
||||
@@OnMapChange = Event.new
|
||||
@@OnMapChanging = Event.new
|
||||
@@OnMapSceneChange = Event.new
|
||||
@@OnSpritesetCreate = Event.new
|
||||
@@OnAction = Event.new
|
||||
@@OnStepTaken = Event.new
|
||||
@@OnLeaveTile = Event.new
|
||||
@@OnStepTakenFieldMovement = Event.new
|
||||
@@OnStepTakenTransferPossible = Event.new
|
||||
@@OnStartBattle = Event.new
|
||||
@@OnEndBattle = Event.new
|
||||
@@OnWildPokemonCreate = Event.new
|
||||
@@OnWildBattleOverride = Event.new
|
||||
@@OnWildBattleEnd = Event.new
|
||||
@@OnTrainerPartyLoad = Event.new
|
||||
@@OnChangeDirection = Event.new
|
||||
|
||||
# Fires whenever a map is created. Event handler receives two parameters: the
|
||||
# map (RPG::Map) and the tileset (RPG::Tileset)
|
||||
def self.onMapCreate; @@OnMapCreate; end
|
||||
def self.onMapCreate=(v); @@OnMapCreate = v; end
|
||||
|
||||
# Fires each frame during a map update.
|
||||
def self.onMapUpdate; @@OnMapUpdate; end
|
||||
def self.onMapUpdate=(v); @@OnMapUpdate = v; end
|
||||
|
||||
# Fires whenever one map is about to change to a different one. Event handler
|
||||
# receives the new map ID and the Game_Map object representing the new map.
|
||||
# When the event handler is called, $game_map still refers to the old map.
|
||||
def self.onMapChanging; @@OnMapChanging; end
|
||||
def self.onMapChanging=(v); @@OnMapChanging = v; end
|
||||
|
||||
# Fires whenever the player moves to a new map. Event handler receives the old
|
||||
# map ID or 0 if none. Also fires when the first map of the game is loaded
|
||||
def self.onMapChange; @@OnMapChange; end
|
||||
def self.onMapChange=(v); @@OnMapChange = v; end
|
||||
|
||||
# Fires whenever the map scene is regenerated and soon after the player moves
|
||||
# to a new map.
|
||||
# Parameters:
|
||||
# e[0] - Scene_Map object.
|
||||
# e[1] - Whether the player just moved to a new map (either true or false). If
|
||||
# false, some other code had called $scene.createSpritesets to
|
||||
# regenerate the map scene without transferring the player elsewhere
|
||||
def self.onMapSceneChange; @@OnMapSceneChange; end
|
||||
def self.onMapSceneChange=(v); @@OnMapSceneChange = v; end
|
||||
|
||||
# Fires whenever a spriteset is created.
|
||||
# Parameters:
|
||||
# e[0] - Spriteset being created. e[0].map is the map associated with the
|
||||
# spriteset (not necessarily the current map).
|
||||
# e[1] - Viewport used for tilemap and characters
|
||||
def self.onSpritesetCreate; @@OnSpritesetCreate; end
|
||||
def self.onSpritesetCreate=(v); @@OnSpritesetCreate = v; end
|
||||
|
||||
# Triggers when the player presses the Action button on the map.
|
||||
def self.onAction; @@OnAction; end
|
||||
def self.onAction=(v); @@OnAction = v; end
|
||||
|
||||
# Fires whenever the player takes a step.
|
||||
def self.onStepTaken; @@OnStepTaken; end
|
||||
def self.onStepTaken=(v); @@OnStepTaken = v; end
|
||||
|
||||
# Fires whenever the player or another event leaves a tile.
|
||||
# Parameters:
|
||||
# e[0] - Event that just left the tile.
|
||||
# e[1] - Map ID where the tile is located (not necessarily
|
||||
# the current map). Use "$MapFactory.getMap(e[1])" to
|
||||
# get the Game_Map object corresponding to that map.
|
||||
# e[2] - X-coordinate of the tile
|
||||
# e[3] - Y-coordinate of the tile
|
||||
def self.onLeaveTile; @@OnLeaveTile; end
|
||||
def self.onLeaveTile=(v); @@OnLeaveTile = v; end
|
||||
|
||||
# Fires whenever the player or another event enters a tile.
|
||||
# Parameters:
|
||||
# e[0] - Event that just entered a tile.
|
||||
def self.onStepTakenFieldMovement; @@OnStepTakenFieldMovement; end
|
||||
def self.onStepTakenFieldMovement=(v); @@OnStepTakenFieldMovement = v; end
|
||||
|
||||
# Fires whenever the player takes a step. The event handler may possibly move
|
||||
# the player elsewhere.
|
||||
# Parameters:
|
||||
# e[0] - Array that contains a single boolean value. If an event handler moves
|
||||
# the player to a new map, it should set this value to true. Other
|
||||
# event handlers should check this parameter's value.
|
||||
def self.onStepTakenTransferPossible; @@OnStepTakenTransferPossible; end
|
||||
def self.onStepTakenTransferPossible=(v); @@OnStepTakenTransferPossible = v; end
|
||||
|
||||
def self.onStartBattle; @@OnStartBattle; end
|
||||
def self.onStartBattle=(v); @@OnStartBattle = v; end
|
||||
|
||||
def self.onEndBattle; @@OnEndBattle; end
|
||||
def self.onEndBattle=(v); @@OnEndBattle = v; end
|
||||
|
||||
# Triggers whenever a wild Pokémon is created
|
||||
# Parameters:
|
||||
# e[0] - Pokémon being created
|
||||
def self.onWildPokemonCreate; @@OnWildPokemonCreate; end
|
||||
def self.onWildPokemonCreate=(v); @@OnWildPokemonCreate = v; end
|
||||
|
||||
# Triggers at the start of a wild battle. Event handlers can provide their
|
||||
# own wild battle routines to override the default behavior.
|
||||
def self.onWildBattleOverride; @@OnWildBattleOverride; end
|
||||
def self.onWildBattleOverride=(v); @@OnWildBattleOverride = v; end
|
||||
|
||||
# Triggers whenever a wild Pokémon battle ends
|
||||
# Parameters:
|
||||
# e[0] - Pokémon species
|
||||
# e[1] - Pokémon level
|
||||
# e[2] - Battle result (1-win, 2-loss, 3-escaped, 4-caught, 5-draw)
|
||||
def self.onWildBattleEnd; @@OnWildBattleEnd; end
|
||||
def self.onWildBattleEnd=(v); @@OnWildBattleEnd = v; end
|
||||
|
||||
# Triggers whenever an NPC trainer's Pokémon party is loaded
|
||||
# Parameters:
|
||||
# e[0] - Trainer
|
||||
# e[1] - Items possessed by the trainer
|
||||
# e[2] - Party
|
||||
def self.onTrainerPartyLoad; @@OnTrainerPartyLoad; end
|
||||
def self.onTrainerPartyLoad=(v); @@OnTrainerPartyLoad = v; end
|
||||
|
||||
# Fires whenever the player changes direction.
|
||||
def self.onChangeDirection; @@OnChangeDirection; end
|
||||
def self.onChangeDirection=(v); @@OnChangeDirection = v; end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
def pbOnSpritesetCreate(spriteset,viewport)
|
||||
Events.onSpritesetCreate.trigger(nil,spriteset,viewport)
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# This module stores encounter-modifying events that can happen during the game.
|
||||
# A procedure can subscribe to an event by adding itself to the event. It will
|
||||
# then be called whenever the event occurs.
|
||||
#===============================================================================
|
||||
module EncounterModifier
|
||||
@@procs = []
|
||||
@@procsEnd = []
|
||||
|
||||
def self.register(p)
|
||||
@@procs.push(p)
|
||||
end
|
||||
|
||||
def self.registerEncounterEnd(p)
|
||||
@@procsEnd.push(p)
|
||||
end
|
||||
|
||||
def self.trigger(encounter)
|
||||
for prc in @@procs
|
||||
encounter = prc.call(encounter)
|
||||
end
|
||||
return encounter
|
||||
end
|
||||
|
||||
def self.triggerEncounterEnd()
|
||||
for prc in @@procsEnd
|
||||
prc.call()
|
||||
end
|
||||
end
|
||||
end
|
||||
154
Data/Scripts_backup/004_Game classes/001_Game_Screen.rb
Normal file
154
Data/Scripts_backup/004_Game classes/001_Game_Screen.rb
Normal file
@@ -0,0 +1,154 @@
|
||||
#===============================================================================
|
||||
# ** Game_Screen
|
||||
#-------------------------------------------------------------------------------
|
||||
# This class handles screen maintenance data, such as change in color tone,
|
||||
# flashing, etc. Refer to "$game_screen" for the instance of this class.
|
||||
#===============================================================================
|
||||
|
||||
class Game_Screen
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Public Instance Variables
|
||||
#-----------------------------------------------------------------------------
|
||||
attr_reader :brightness # brightness
|
||||
attr_reader :tone # color tone
|
||||
attr_reader :flash_color # flash color
|
||||
attr_reader :shake # shake positioning
|
||||
attr_reader :pictures # pictures
|
||||
attr_reader :weather_type # weather type
|
||||
attr_reader :weather_max # max number of weather sprites
|
||||
attr_accessor :weather_duration # ticks in which the weather should fade in
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Object Initialization
|
||||
#-----------------------------------------------------------------------------
|
||||
def initialize
|
||||
@brightness = 255
|
||||
@fadeout_duration = 0
|
||||
@fadein_duration = 0
|
||||
@tone = Tone.new(0, 0, 0, 0)
|
||||
@tone_target = Tone.new(0, 0, 0, 0)
|
||||
@tone_duration = 0
|
||||
@flash_color = Color.new(0, 0, 0, 0)
|
||||
@flash_duration = 0
|
||||
@shake_power = 0
|
||||
@shake_speed = 0
|
||||
@shake_duration = 0
|
||||
@shake_direction = 1
|
||||
@shake = 0
|
||||
@pictures = [nil]
|
||||
for i in 1..100
|
||||
@pictures.push(Game_Picture.new(i))
|
||||
end
|
||||
@weather_type = 0
|
||||
@weather_max = 0.0
|
||||
@weather_duration = 0
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Start Changing Color Tone
|
||||
# tone : color tone
|
||||
# duration : time
|
||||
#-----------------------------------------------------------------------------
|
||||
def start_tone_change(tone, duration)
|
||||
@tone_target = tone.clone
|
||||
@tone_duration = duration
|
||||
if @tone_duration == 0
|
||||
@tone = @tone_target.clone
|
||||
end
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Start Flashing
|
||||
# color : color
|
||||
# duration : time
|
||||
#-----------------------------------------------------------------------------
|
||||
def start_flash(color, duration)
|
||||
@flash_color = color.clone
|
||||
@flash_duration = duration
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Start Shaking
|
||||
# power : strength
|
||||
# speed : speed
|
||||
# duration : time
|
||||
#-----------------------------------------------------------------------------
|
||||
def start_shake(power, speed, duration)
|
||||
@shake_power = power
|
||||
@shake_speed = speed
|
||||
@shake_duration = duration
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Set Weather
|
||||
# type : type
|
||||
# power : strength
|
||||
# duration : time
|
||||
#-----------------------------------------------------------------------------
|
||||
def weather(type, power, duration)
|
||||
@weather_type = GameData::Weather.get(type).id
|
||||
@weather_max = (power + 1) * RPG::Weather::MAX_SPRITES / 10
|
||||
@weather_duration = duration # In 1/20ths of a seconds
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Frame Update
|
||||
#-----------------------------------------------------------------------------
|
||||
def update
|
||||
if @fadeout_duration && @fadeout_duration>=1
|
||||
d = @fadeout_duration
|
||||
@brightness = (@brightness*(d-1))/d
|
||||
@fadeout_duration -= 1
|
||||
end
|
||||
if @fadein_duration && @fadein_duration>=1
|
||||
d = @fadein_duration
|
||||
@brightness = (@brightness*(d-1)+255)/d
|
||||
@fadein_duration -= 1
|
||||
end
|
||||
if @tone_duration>=1
|
||||
d = @tone_duration
|
||||
@tone.red = (@tone.red*(d-1)+@tone_target.red)/d
|
||||
@tone.green = (@tone.green*(d-1)+@tone_target.green)/d
|
||||
@tone.blue = (@tone.blue*(d-1)+@tone_target.blue)/d
|
||||
@tone.gray = (@tone.gray*(d-1)+@tone_target.gray)/d
|
||||
@tone_duration -= 1
|
||||
end
|
||||
if @flash_duration>=1
|
||||
d = @flash_duration
|
||||
@flash_color.alpha = @flash_color.alpha*(d-1)/d
|
||||
@flash_duration -= 1
|
||||
end
|
||||
if @shake_duration>=1 || @shake!=0
|
||||
delta = (@shake_power*@shake_speed*@shake_direction)/10.0
|
||||
if @shake_duration<=1 && @shake*(@shake+delta)<0
|
||||
@shake = 0
|
||||
else
|
||||
@shake += delta
|
||||
end
|
||||
@shake_direction = -1 if @shake>@shake_power*2
|
||||
@shake_direction = 1 if @shake<-@shake_power*2
|
||||
@shake_duration -= 1 if @shake_duration>=1
|
||||
end
|
||||
if $game_temp.in_battle
|
||||
for i in 51..100
|
||||
@pictures[i].update
|
||||
end
|
||||
else
|
||||
for i in 1..50
|
||||
@pictures[i].update
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
def pbToneChangeAll(tone,duration)
|
||||
$game_screen.start_tone_change(tone,duration*Graphics.frame_rate/20)
|
||||
for picture in $game_screen.pictures
|
||||
picture.start_tone_change(tone,duration*Graphics.frame_rate/20) if picture
|
||||
end
|
||||
end
|
||||
|
||||
def pbShake(power,speed,frames)
|
||||
$game_screen.start_shake(power,speed,frames*Graphics.frame_rate/20)
|
||||
end
|
||||
|
||||
def pbFlash(color,frames)
|
||||
$game_screen.start_flash(color,frames*Graphics.frame_rate/20)
|
||||
end
|
||||
@@ -0,0 +1,59 @@
|
||||
#===============================================================================
|
||||
# ** Game_Temp
|
||||
#-------------------------------------------------------------------------------
|
||||
# This class handles temporary data that is not included with save data.
|
||||
# Refer to "$game_temp" for the instance of this class.
|
||||
#===============================================================================
|
||||
class Game_Temp
|
||||
attr_accessor :message_window_showing # message window showing
|
||||
attr_accessor :common_event_id # common event ID
|
||||
attr_accessor :in_battle # in-battle flag
|
||||
attr_accessor :battle_abort # battle flag: interrupt
|
||||
attr_accessor :battleback_name # battleback file name
|
||||
attr_accessor :in_menu # menu is open
|
||||
attr_accessor :menu_beep # menu: play sound effect flag
|
||||
attr_accessor :menu_calling # menu calling flag
|
||||
attr_accessor :debug_calling # debug calling flag
|
||||
attr_accessor :player_transferring # player place movement flag
|
||||
attr_accessor :player_new_map_id # player destination: map ID
|
||||
attr_accessor :player_new_x # player destination: x-coordinate
|
||||
attr_accessor :player_new_y # player destination: y-coordinate
|
||||
attr_accessor :player_new_direction # player destination: direction
|
||||
attr_accessor :transition_processing # transition processing flag
|
||||
attr_accessor :transition_name # transition file name
|
||||
attr_accessor :to_title # return to title screen flag
|
||||
attr_accessor :fadestate # for sprite hashes
|
||||
attr_accessor :background_bitmap
|
||||
attr_accessor :mart_prices
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Object Initialization
|
||||
#-----------------------------------------------------------------------------
|
||||
def initialize
|
||||
@message_window_showing = false
|
||||
@common_event_id = 0
|
||||
@in_battle = false
|
||||
@battle_abort = false
|
||||
@battleback_name = ''
|
||||
@in_menu = false
|
||||
@menu_beep = false
|
||||
@menu_calling = false
|
||||
@debug_calling = false
|
||||
@player_transferring = false
|
||||
@player_new_map_id = 0
|
||||
@player_new_x = 0
|
||||
@player_new_y = 0
|
||||
@player_new_direction = 0
|
||||
@transition_processing = false
|
||||
@transition_name = ""
|
||||
@to_title = false
|
||||
@fadestate = 0
|
||||
@background_bitmap = nil
|
||||
@message_window_showing = false
|
||||
@transition_processing = false
|
||||
@mart_prices = {}
|
||||
end
|
||||
|
||||
def clear_mart_prices
|
||||
@mart_prices = {}
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,30 @@
|
||||
#===============================================================================
|
||||
# ** Game_Switches
|
||||
#-------------------------------------------------------------------------------
|
||||
# This class handles switches. It's a wrapper for the built-in class "Array."
|
||||
# Refer to "$game_switches" for the instance of this class.
|
||||
#===============================================================================
|
||||
class Game_Switches
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Object Initialization
|
||||
#-----------------------------------------------------------------------------
|
||||
def initialize
|
||||
@data = []
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Get Switch
|
||||
# switch_id : switch ID
|
||||
#-----------------------------------------------------------------------------
|
||||
def [](switch_id)
|
||||
return @data[switch_id] if switch_id <= 5000 && @data[switch_id] != nil
|
||||
return false
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Set Switch
|
||||
# switch_id : switch ID
|
||||
# value : ON (true) / OFF (false)
|
||||
#-----------------------------------------------------------------------------
|
||||
def []=(switch_id, value)
|
||||
@data[switch_id] = value if switch_id <= 5000
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,30 @@
|
||||
#===============================================================================
|
||||
# ** Game_Variables
|
||||
#-------------------------------------------------------------------------------
|
||||
# This class handles variables. It's a wrapper for the built-in class "Array."
|
||||
# Refer to "$game_variables" for the instance of this class.
|
||||
#===============================================================================
|
||||
class Game_Variables
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Object Initialization
|
||||
#-----------------------------------------------------------------------------
|
||||
def initialize
|
||||
@data = []
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Get Variable
|
||||
# variable_id : variable ID
|
||||
#-----------------------------------------------------------------------------
|
||||
def [](variable_id)
|
||||
return @data[variable_id] if variable_id <= 5000 && !@data[variable_id].nil?
|
||||
return 0
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Set Variable
|
||||
# variable_id : variable ID
|
||||
# value : the variable's value
|
||||
#-----------------------------------------------------------------------------
|
||||
def []=(variable_id, value)
|
||||
@data[variable_id] = value if variable_id <= 5000
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,29 @@
|
||||
#===============================================================================
|
||||
# ** Game_SelfSwitches
|
||||
#-------------------------------------------------------------------------------
|
||||
# This class handles self switches. It's a wrapper for the built-in class
|
||||
# "Hash." Refer to "$game_self_switches" for the instance of this class.
|
||||
#===============================================================================
|
||||
class Game_SelfSwitches
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Object Initialization
|
||||
#-----------------------------------------------------------------------------
|
||||
def initialize
|
||||
@data = {}
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Get Self Switch
|
||||
# key : key
|
||||
#-----------------------------------------------------------------------------
|
||||
def [](key)
|
||||
return (@data[key]==true) ? true : false
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Set Self Switch
|
||||
# key : key
|
||||
# value : ON (true) / OFF (false)
|
||||
#-----------------------------------------------------------------------------
|
||||
def []=(key, value)
|
||||
@data[key] = value
|
||||
end
|
||||
end
|
||||
286
Data/Scripts_backup/004_Game classes/002_Game_System.rb
Normal file
286
Data/Scripts_backup/004_Game classes/002_Game_System.rb
Normal file
@@ -0,0 +1,286 @@
|
||||
#==============================================================================
|
||||
# ** Game_System
|
||||
#------------------------------------------------------------------------------
|
||||
# This class handles data surrounding the system. Backround music, etc.
|
||||
# is managed here as well. Refer to "$game_system" for the instance of
|
||||
# this class.
|
||||
#==============================================================================
|
||||
class Game_System
|
||||
attr_reader :map_interpreter # map event interpreter
|
||||
attr_reader :battle_interpreter # battle event interpreter
|
||||
attr_accessor :timer # timer
|
||||
attr_accessor :timer_working # timer working flag
|
||||
attr_accessor :save_disabled # save forbidden
|
||||
attr_accessor :menu_disabled # menu forbidden
|
||||
attr_accessor :encounter_disabled # encounter forbidden
|
||||
attr_accessor :message_position # text option: positioning
|
||||
attr_accessor :message_frame # text option: window frame
|
||||
attr_accessor :save_count # save count
|
||||
attr_accessor :magic_number # magic number
|
||||
attr_accessor :autoscroll_x_speed
|
||||
attr_accessor :autoscroll_y_speed
|
||||
attr_accessor :bgm_position
|
||||
|
||||
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
|
||||
@autoscroll_x_speed = 0
|
||||
@autoscroll_y_speed = 0
|
||||
@bgm_position = 0
|
||||
@bgs_position = 0
|
||||
end
|
||||
|
||||
################################################################################
|
||||
|
||||
def bgm_play(bgm)
|
||||
old_pos = @bgm_position
|
||||
@bgm_position = 0
|
||||
bgm_play_internal(bgm,0)
|
||||
@bgm_position = old_pos
|
||||
end
|
||||
|
||||
def bgm_play_internal2(name,volume,pitch,position) # :nodoc:
|
||||
vol = volume
|
||||
vol *= $PokemonSystem.bgmvolume/100.0
|
||||
vol = vol.to_i
|
||||
begin
|
||||
Audio.bgm_play(name,vol,pitch,position)
|
||||
rescue ArgumentError
|
||||
Audio.bgm_play(name,vol,pitch)
|
||||
end
|
||||
end
|
||||
|
||||
def bgm_play_internal(bgm,position) # :nodoc:
|
||||
@bgm_position = position if !@bgm_paused
|
||||
@playing_bgm = (bgm==nil) ? nil : bgm.clone
|
||||
if bgm!=nil && bgm.name!=""
|
||||
if FileTest.audio_exist?("Audio/BGM/"+bgm.name)
|
||||
bgm_play_internal2("Audio/BGM/"+bgm.name,
|
||||
bgm.volume,bgm.pitch,@bgm_position) if !@defaultBGM
|
||||
end
|
||||
else
|
||||
@bgm_position = position if !@bgm_paused
|
||||
@playing_bgm = nil
|
||||
Audio.bgm_stop if !@defaultBGM
|
||||
end
|
||||
if @defaultBGM
|
||||
bgm_play_internal2("Audio/BGM/"+@defaultBGM.name,
|
||||
@defaultBGM.volume,@defaultBGM.pitch,@bgm_position)
|
||||
end
|
||||
Graphics.frame_reset
|
||||
end
|
||||
|
||||
def bgm_pause(fadetime=0.0) # :nodoc:
|
||||
pos = Audio.bgm_pos rescue 0
|
||||
self.bgm_fade(fadetime) if fadetime>0.0
|
||||
@bgm_position = pos
|
||||
@bgm_paused = true
|
||||
end
|
||||
|
||||
def bgm_unpause # :nodoc:
|
||||
@bgm_position = 0
|
||||
@bgm_paused = false
|
||||
end
|
||||
|
||||
def bgm_resume(bgm) # :nodoc:
|
||||
if @bgm_paused
|
||||
self.bgm_play_internal(bgm,@bgm_position)
|
||||
@bgm_position = 0
|
||||
@bgm_paused = false
|
||||
end
|
||||
end
|
||||
|
||||
def bgm_stop # :nodoc:
|
||||
@bgm_position = 0 if !@bgm_paused
|
||||
@playing_bgm = nil
|
||||
Audio.bgm_stop if !@defaultBGM
|
||||
end
|
||||
|
||||
def bgm_fade(time) # :nodoc:
|
||||
@bgm_position = 0 if !@bgm_paused
|
||||
@playing_bgm = nil
|
||||
Audio.bgm_fade((time*1000).floor) if !@defaultBGM
|
||||
end
|
||||
|
||||
def playing_bgm
|
||||
return @playing_bgm
|
||||
end
|
||||
|
||||
# Saves the currently playing background music for later playback.
|
||||
def bgm_memorize
|
||||
@memorized_bgm = @playing_bgm
|
||||
end
|
||||
|
||||
# Plays the currently memorized background music
|
||||
def bgm_restore
|
||||
bgm_play(@memorized_bgm)
|
||||
end
|
||||
|
||||
# Returns an RPG::AudioFile object for the currently playing background music
|
||||
def getPlayingBGM
|
||||
return (@playing_bgm) ? @playing_bgm.clone : nil
|
||||
end
|
||||
|
||||
def setDefaultBGM(bgm,volume=80,pitch=100)
|
||||
bgm = RPG::AudioFile.new(bgm,volume,pitch) if bgm.is_a?(String)
|
||||
if bgm!=nil && bgm.name!=""
|
||||
@defaultBGM = nil
|
||||
self.bgm_play(bgm)
|
||||
@defaultBGM = bgm.clone
|
||||
else
|
||||
@defaultBGM = nil
|
||||
self.bgm_play(@playing_bgm)
|
||||
end
|
||||
end
|
||||
|
||||
################################################################################
|
||||
|
||||
def me_play(me)
|
||||
me = RPG::AudioFile.new(me) if me.is_a?(String)
|
||||
if me!=nil && me.name!=""
|
||||
if FileTest.audio_exist?("Audio/ME/"+me.name)
|
||||
vol = me.volume
|
||||
vol *= $PokemonSystem.bgmvolume/100.0
|
||||
vol = vol.to_i
|
||||
Audio.me_play("Audio/ME/"+me.name,vol,me.pitch)
|
||||
end
|
||||
else
|
||||
Audio.me_stop
|
||||
end
|
||||
Graphics.frame_reset
|
||||
end
|
||||
|
||||
################################################################################
|
||||
|
||||
def bgs_play(bgs)
|
||||
@playing_bgs = (bgs==nil) ? nil : bgs.clone
|
||||
if bgs!=nil && bgs.name!=""
|
||||
if FileTest.audio_exist?("Audio/BGS/"+bgs.name)
|
||||
vol = bgs.volume
|
||||
vol *= $PokemonSystem.sevolume/100.0
|
||||
vol = vol.to_i
|
||||
Audio.bgs_play("Audio/BGS/"+bgs.name,vol,bgs.pitch)
|
||||
end
|
||||
else
|
||||
@bgs_position = 0
|
||||
@playing_bgs = nil
|
||||
Audio.bgs_stop
|
||||
end
|
||||
Graphics.frame_reset
|
||||
end
|
||||
|
||||
def bgs_pause(fadetime=0.0) # :nodoc:
|
||||
if fadetime>0.0
|
||||
self.bgs_fade(fadetime)
|
||||
else
|
||||
self.bgs_stop
|
||||
end
|
||||
@bgs_paused = true
|
||||
end
|
||||
|
||||
def bgs_unpause # :nodoc:
|
||||
@bgs_paused = false
|
||||
end
|
||||
|
||||
def bgs_resume(bgs) # :nodoc:
|
||||
if @bgs_paused
|
||||
self.bgs_play(bgs)
|
||||
@bgs_paused = false
|
||||
end
|
||||
end
|
||||
|
||||
def bgs_stop
|
||||
@bgs_position = 0
|
||||
@playing_bgs = nil
|
||||
Audio.bgs_stop
|
||||
end
|
||||
|
||||
def bgs_fade(time)
|
||||
@bgs_position = 0
|
||||
@playing_bgs = nil
|
||||
Audio.bgs_fade((time*1000).floor)
|
||||
end
|
||||
|
||||
def playing_bgs
|
||||
return @playing_bgs
|
||||
end
|
||||
|
||||
def bgs_memorize
|
||||
@memorized_bgs = @playing_bgs
|
||||
end
|
||||
|
||||
def bgs_restore
|
||||
bgs_play(@memorized_bgs)
|
||||
end
|
||||
|
||||
def getPlayingBGS
|
||||
return (@playing_bgs) ? @playing_bgs.clone : nil
|
||||
end
|
||||
|
||||
################################################################################
|
||||
|
||||
def se_play(se)
|
||||
se = RPG::AudioFile.new(se) if se.is_a?(String)
|
||||
if se!=nil && se.name!="" && FileTest.audio_exist?("Audio/SE/"+se.name)
|
||||
vol = se.volume
|
||||
vol *= $PokemonSystem.sevolume/100.0
|
||||
vol = vol.to_i
|
||||
Audio.se_play("Audio/SE/"+se.name,vol,se.pitch)
|
||||
end
|
||||
end
|
||||
|
||||
def se_stop
|
||||
Audio.se_stop
|
||||
end
|
||||
|
||||
################################################################################
|
||||
|
||||
def battle_bgm
|
||||
return (@battle_bgm) ? @battle_bgm : $data_system.battle_bgm
|
||||
end
|
||||
|
||||
def battle_bgm=(battle_bgm)
|
||||
@battle_bgm = battle_bgm
|
||||
end
|
||||
|
||||
def battle_end_me
|
||||
return (@battle_end_me) ? @battle_end_me : $data_system.battle_end_me
|
||||
end
|
||||
|
||||
def battle_end_me=(battle_end_me)
|
||||
@battle_end_me = battle_end_me
|
||||
end
|
||||
|
||||
################################################################################
|
||||
|
||||
def windowskin_name
|
||||
if @windowskin_name==nil
|
||||
return $data_system.windowskin_name
|
||||
else
|
||||
return @windowskin_name
|
||||
end
|
||||
end
|
||||
|
||||
def windowskin_name=(windowskin_name)
|
||||
@windowskin_name = windowskin_name
|
||||
end
|
||||
|
||||
def update
|
||||
@timer -= 1 if @timer_working && @timer>0
|
||||
if Input.trigger?(Input::SPECIAL) && pbCurrentEventCommentInput(1,"Cut Scene")
|
||||
event = @map_interpreter.get_character(0)
|
||||
@map_interpreter.pbSetSelfSwitch(event.id,"A",true)
|
||||
@map_interpreter.command_end
|
||||
event.start
|
||||
end
|
||||
end
|
||||
end
|
||||
156
Data/Scripts_backup/004_Game classes/003_Game_Picture.rb
Normal file
156
Data/Scripts_backup/004_Game classes/003_Game_Picture.rb
Normal file
@@ -0,0 +1,156 @@
|
||||
#===============================================================================
|
||||
# ** Game_Picture
|
||||
#-------------------------------------------------------------------------------
|
||||
# This class handles the picture. It's used within the Game_Screen class
|
||||
# ($game_screen).
|
||||
#===============================================================================
|
||||
|
||||
class Game_Picture
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Public Instance Variables
|
||||
#-----------------------------------------------------------------------------
|
||||
attr_reader :number # picture number
|
||||
attr_reader :name # file name
|
||||
attr_reader :origin # starting point
|
||||
attr_reader :x # x-coordinate
|
||||
attr_reader :y # y-coordinate
|
||||
attr_reader :zoom_x # x directional zoom rate
|
||||
attr_reader :zoom_y # y directional zoom rate
|
||||
attr_reader :opacity # opacity level
|
||||
attr_reader :blend_type # blend method
|
||||
attr_reader :tone # color tone
|
||||
attr_reader :angle # rotation angle
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Object Initialization
|
||||
# number : picture number
|
||||
#-----------------------------------------------------------------------------
|
||||
def initialize(number)
|
||||
@number = number
|
||||
@name = ""
|
||||
@origin = 0
|
||||
@x = 0.0
|
||||
@y = 0.0
|
||||
@zoom_x = 100.0
|
||||
@zoom_y = 100.0
|
||||
@opacity = 255.0
|
||||
@blend_type = 1
|
||||
@duration = 0
|
||||
@target_x = @x
|
||||
@target_y = @y
|
||||
@target_zoom_x = @zoom_x
|
||||
@target_zoom_y = @zoom_y
|
||||
@target_opacity = @opacity
|
||||
@tone = Tone.new(0, 0, 0, 0)
|
||||
@tone_target = Tone.new(0, 0, 0, 0)
|
||||
@tone_duration = 0
|
||||
@angle = 0
|
||||
@rotate_speed = 0
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Show Picture
|
||||
# name : file name
|
||||
# origin : starting point
|
||||
# x : x-coordinate
|
||||
# y : y-coordinate
|
||||
# zoom_x : x directional zoom rate
|
||||
# zoom_y : y directional zoom rate
|
||||
# opacity : opacity level
|
||||
# blend_type : blend method
|
||||
#-----------------------------------------------------------------------------
|
||||
def show(name, origin, x, y, zoom_x, zoom_y, opacity, blend_type)
|
||||
@name = name
|
||||
@origin = origin
|
||||
@x = x.to_f
|
||||
@y = y.to_f
|
||||
@zoom_x = zoom_x.to_f
|
||||
@zoom_y = zoom_y.to_f
|
||||
@opacity = opacity.to_f
|
||||
@blend_type = blend_type ? blend_type : 0
|
||||
@duration = 0
|
||||
@target_x = @x
|
||||
@target_y = @y
|
||||
@target_zoom_x = @zoom_x
|
||||
@target_zoom_y = @zoom_y
|
||||
@target_opacity = @opacity
|
||||
@tone = Tone.new(0, 0, 0, 0)
|
||||
@tone_target = Tone.new(0, 0, 0, 0)
|
||||
@tone_duration = 0
|
||||
@angle = 0
|
||||
@rotate_speed = 0
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Move Picture
|
||||
# duration : time
|
||||
# origin : starting point
|
||||
# x : x-coordinate
|
||||
# y : y-coordinate
|
||||
# zoom_x : x directional zoom rate
|
||||
# zoom_y : y directional zoom rate
|
||||
# opacity : opacity level
|
||||
# blend_type : blend method
|
||||
#-----------------------------------------------------------------------------
|
||||
def move(duration, origin, x, y, zoom_x, zoom_y, opacity, blend_type)
|
||||
@duration = duration
|
||||
@origin = origin
|
||||
@target_x = x.to_f
|
||||
@target_y = y.to_f
|
||||
@target_zoom_x = zoom_x.to_f
|
||||
@target_zoom_y = zoom_y.to_f
|
||||
@target_opacity = opacity.to_f
|
||||
@blend_type = blend_type ? blend_type : 0
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Change Rotation Speed
|
||||
# speed : rotation speed
|
||||
#-----------------------------------------------------------------------------
|
||||
def rotate(speed)
|
||||
@rotate_speed = speed
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Start Change of Color Tone
|
||||
# tone : color tone
|
||||
# duration : time
|
||||
#-----------------------------------------------------------------------------
|
||||
def start_tone_change(tone, duration)
|
||||
@tone_target = tone.clone
|
||||
@tone_duration = duration
|
||||
if @tone_duration == 0
|
||||
@tone = @tone_target.clone
|
||||
end
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Erase Picture
|
||||
#-----------------------------------------------------------------------------
|
||||
def erase
|
||||
@name = ""
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Frame Update
|
||||
#-----------------------------------------------------------------------------
|
||||
def update
|
||||
if @duration >= 1
|
||||
d = @duration
|
||||
@x = (@x * (d - 1) + @target_x) / d
|
||||
@y = (@y * (d - 1) + @target_y) / d
|
||||
@zoom_x = (@zoom_x * (d - 1) + @target_zoom_x) / d
|
||||
@zoom_y = (@zoom_y * (d - 1) + @target_zoom_y) / d
|
||||
@opacity = (@opacity * (d - 1) + @target_opacity) / d
|
||||
@duration -= 1
|
||||
end
|
||||
if @tone_duration >= 1
|
||||
d = @tone_duration
|
||||
@tone.red = (@tone.red * (d - 1) + @tone_target.red) / d
|
||||
@tone.green = (@tone.green * (d - 1) + @tone_target.green) / d
|
||||
@tone.blue = (@tone.blue * (d - 1) + @tone_target.blue) / d
|
||||
@tone.gray = (@tone.gray * (d - 1) + @tone_target.gray) / d
|
||||
@tone_duration -= 1
|
||||
end
|
||||
if @rotate_speed != 0
|
||||
@angle += @rotate_speed / 2.0
|
||||
while @angle < 0
|
||||
@angle += 360
|
||||
end
|
||||
@angle %= 360
|
||||
end
|
||||
end
|
||||
end
|
||||
468
Data/Scripts_backup/004_Game classes/004_Game_Map.rb
Normal file
468
Data/Scripts_backup/004_Game classes/004_Game_Map.rb
Normal file
@@ -0,0 +1,468 @@
|
||||
#==============================================================================
|
||||
# ** Game_Map
|
||||
#------------------------------------------------------------------------------
|
||||
# This class handles the map. It includes scrolling and passable determining
|
||||
# functions. Refer to "$game_map" for the instance of this class.
|
||||
#==============================================================================
|
||||
class Game_Map
|
||||
attr_accessor :map_id
|
||||
attr_accessor :tileset_name # tileset file name
|
||||
attr_accessor :autotile_names # autotile file name
|
||||
attr_reader :passages # passage table
|
||||
attr_reader :priorities # priority table
|
||||
attr_reader :terrain_tags # terrain tag table
|
||||
attr_reader :events # events
|
||||
attr_accessor :panorama_name # panorama file name
|
||||
attr_accessor :panorama_hue # panorama hue
|
||||
attr_accessor :fog_name # fog file name
|
||||
attr_accessor :fog_hue # fog hue
|
||||
attr_accessor :fog_opacity # fog opacity level
|
||||
attr_accessor :fog_blend_type # fog blending method
|
||||
attr_accessor :fog_zoom # fog zoom rate
|
||||
attr_accessor :fog_sx # fog sx
|
||||
attr_accessor :fog_sy # fog sy
|
||||
attr_reader :fog_ox # fog x-coordinate starting point
|
||||
attr_reader :fog_oy # fog y-coordinate starting point
|
||||
attr_reader :fog_tone # fog color tone
|
||||
attr_accessor :battleback_name # battleback file name
|
||||
attr_reader :display_x # display x-coordinate * 128
|
||||
attr_reader :display_y # display y-coordinate * 128
|
||||
attr_accessor :need_refresh # refresh request flag
|
||||
|
||||
TILE_WIDTH = 32
|
||||
TILE_HEIGHT = 32
|
||||
X_SUBPIXELS = 4
|
||||
Y_SUBPIXELS = 4
|
||||
REAL_RES_X = TILE_WIDTH * X_SUBPIXELS
|
||||
REAL_RES_Y = TILE_HEIGHT * Y_SUBPIXELS
|
||||
|
||||
def initialize
|
||||
@map_id = 0
|
||||
@display_x = 0
|
||||
@display_y = 0
|
||||
end
|
||||
|
||||
def setup(map_id)
|
||||
@map_id = map_id
|
||||
@map = load_data(sprintf("Data/Map%03d.rxdata",map_id))
|
||||
tileset = $data_tilesets[@map.tileset_id]
|
||||
updateTileset
|
||||
@fog_ox = 0
|
||||
@fog_oy = 0
|
||||
@fog_tone = Tone.new(0, 0, 0, 0)
|
||||
@fog_tone_target = Tone.new(0, 0, 0, 0)
|
||||
@fog_tone_duration = 0
|
||||
@fog_opacity_duration = 0
|
||||
@fog_opacity_target = 0
|
||||
self.display_x = 0
|
||||
self.display_y = 0
|
||||
@need_refresh = false
|
||||
Events.onMapCreate.trigger(self,map_id,@map,tileset)
|
||||
@events = {}
|
||||
for i in @map.events.keys
|
||||
@events[i] = Game_Event.new(@map_id, @map.events[i],self)
|
||||
end
|
||||
@common_events = {}
|
||||
for i in 1...$data_common_events.size
|
||||
@common_events[i] = Game_CommonEvent.new(i)
|
||||
end
|
||||
@scroll_direction = 2
|
||||
@scroll_rest = 0
|
||||
@scroll_speed = 4
|
||||
end
|
||||
|
||||
def updateTileset
|
||||
tileset = $data_tilesets[@map.tileset_id]
|
||||
@tileset_name = tileset.tileset_name
|
||||
@autotile_names = tileset.autotile_names
|
||||
@panorama_name = tileset.panorama_name
|
||||
@panorama_hue = tileset.panorama_hue
|
||||
@fog_name = tileset.fog_name
|
||||
@fog_hue = tileset.fog_hue
|
||||
@fog_opacity = tileset.fog_opacity
|
||||
@fog_blend_type = tileset.fog_blend_type
|
||||
@fog_zoom = tileset.fog_zoom
|
||||
@fog_sx = tileset.fog_sx
|
||||
@fog_sy = tileset.fog_sy
|
||||
@battleback_name = tileset.battleback_name
|
||||
@passages = tileset.passages
|
||||
@priorities = tileset.priorities
|
||||
@terrain_tags = tileset.terrain_tags
|
||||
end
|
||||
|
||||
def width; return @map.width; end
|
||||
def height; return @map.height; end
|
||||
def encounter_list; return @map.encounter_list; end
|
||||
def encounter_step; return @map.encounter_step; end
|
||||
def data; return @map.data; end
|
||||
|
||||
def name
|
||||
ret = pbGetMessage(MessageTypes::MapNames,@map_id)
|
||||
ret.gsub!(/\\PN/,$Trainer.name) if $Trainer
|
||||
return ret
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Autoplays background music
|
||||
# Plays music called "[normal BGM]_n" if it's night time and it exists
|
||||
#-----------------------------------------------------------------------------
|
||||
def autoplayAsCue
|
||||
if @map.autoplay_bgm
|
||||
if PBDayNight.isNight? && FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "_n")
|
||||
pbCueBGM(@map.bgm.name+"_n",1.0,@map.bgm.volume,@map.bgm.pitch)
|
||||
else
|
||||
pbCueBGM(@map.bgm,1.0)
|
||||
end
|
||||
end
|
||||
if @map.autoplay_bgs
|
||||
pbBGSPlay(@map.bgs)
|
||||
end
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Plays background music
|
||||
# Plays music called "[normal BGM]_n" if it's night time and it exists
|
||||
#-----------------------------------------------------------------------------
|
||||
def autoplay
|
||||
if @map.autoplay_bgm
|
||||
if PBDayNight.isNight? && FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "_n")
|
||||
pbBGMPlay(@map.bgm.name+"_n",@map.bgm.volume,@map.bgm.pitch)
|
||||
else
|
||||
pbBGMPlay(@map.bgm)
|
||||
end
|
||||
end
|
||||
if @map.autoplay_bgs
|
||||
pbBGSPlay(@map.bgs)
|
||||
end
|
||||
end
|
||||
|
||||
def valid?(x, y)
|
||||
return x>=0 && x<width && y>=0 && y<height
|
||||
end
|
||||
|
||||
def validLax?(x, y)
|
||||
return x>=-10 && x<=width+10 && y>=-10 && y<=height+10
|
||||
end
|
||||
|
||||
def passable?(x, y, d, self_event = nil)
|
||||
return false if !valid?(x, y)
|
||||
bit = (1 << (d / 2 - 1)) & 0x0f
|
||||
for event in events.values
|
||||
next if event.tile_id <= 0
|
||||
next if event == self_event
|
||||
next if !event.at_coordinate?(x, y)
|
||||
next if event.through
|
||||
next if GameData::TerrainTag.try_get(@terrain_tags[event.tile_id]).ignore_passability
|
||||
passage = @passages[event.tile_id]
|
||||
return false if passage & bit != 0
|
||||
return false if passage & 0x0f == 0x0f
|
||||
return true if @priorities[event.tile_id] == 0
|
||||
end
|
||||
return playerPassable?(x, y, d, self_event) if self_event==$game_player
|
||||
# All other events
|
||||
newx = x
|
||||
newy = y
|
||||
case d
|
||||
when 1
|
||||
newx -= 1
|
||||
newy += 1
|
||||
when 2
|
||||
newy += 1
|
||||
when 3
|
||||
newx += 1
|
||||
newy += 1
|
||||
when 4
|
||||
newx -= 1
|
||||
when 6
|
||||
newx += 1
|
||||
when 7
|
||||
newx -= 1
|
||||
newy -= 1
|
||||
when 8
|
||||
newy -= 1
|
||||
when 9
|
||||
newx += 1
|
||||
newy -= 1
|
||||
end
|
||||
return false if !valid?(newx, newy)
|
||||
for i in [2, 1, 0]
|
||||
tile_id = data[x, y, i]
|
||||
terrain = GameData::TerrainTag.try_get(@terrain_tags[tile_id])
|
||||
# If already on water, only allow movement to another water tile
|
||||
if self_event != nil && terrain.can_surf_freely
|
||||
for j in [2, 1, 0]
|
||||
facing_tile_id = data[newx, newy, j]
|
||||
return false if facing_tile_id == nil
|
||||
facing_terrain = GameData::TerrainTag.try_get(@terrain_tags[facing_tile_id])
|
||||
if facing_terrain.id != :None && !facing_terrain.ignore_passability
|
||||
return facing_terrain.can_surf_freely
|
||||
end
|
||||
end
|
||||
return false
|
||||
# Can't walk onto ice
|
||||
elsif terrain.ice
|
||||
return false
|
||||
elsif self_event != nil && self_event.x == x && self_event.y == y
|
||||
# Can't walk onto ledges
|
||||
for j in [2, 1, 0]
|
||||
facing_tile_id = data[newx, newy, j]
|
||||
return false if facing_tile_id == nil
|
||||
facing_terrain = GameData::TerrainTag.try_get(@terrain_tags[facing_tile_id])
|
||||
return false if facing_terrain.ledge
|
||||
break if facing_terrain.id != :None && !facing_terrain.ignore_passability
|
||||
end
|
||||
end
|
||||
# Regular passability checks
|
||||
if !terrain || !terrain.ignore_passability
|
||||
passage = @passages[tile_id]
|
||||
return false if passage & bit != 0 || passage & 0x0f == 0x0f
|
||||
return true if @priorities[tile_id] == 0
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
def playerPassable?(x, y, d, self_event = nil)
|
||||
bit = (1 << (d / 2 - 1)) & 0x0f
|
||||
for i in [2, 1, 0]
|
||||
tile_id = data[x, y, i]
|
||||
terrain = GameData::TerrainTag.try_get(@terrain_tags[tile_id])
|
||||
passage = @passages[tile_id]
|
||||
if terrain
|
||||
# Ignore bridge tiles if not on a bridge
|
||||
next if terrain.bridge && $PokemonGlobal.bridge == 0
|
||||
# Make water tiles passable if player is surfing
|
||||
return true if $PokemonGlobal.surfing && terrain.can_surf && !terrain.waterfall
|
||||
# Prevent cycling in really tall grass/on ice
|
||||
return false if $PokemonGlobal.bicycle && terrain.must_walk
|
||||
# Depend on passability of bridge tile if on bridge
|
||||
if terrain.bridge && $PokemonGlobal.bridge > 0
|
||||
return (passage & bit == 0 && passage & 0x0f != 0x0f)
|
||||
end
|
||||
end
|
||||
# Regular passability checks
|
||||
if !terrain || !terrain.ignore_passability
|
||||
return false if passage & bit != 0 || passage & 0x0f == 0x0f
|
||||
return true if @priorities[tile_id] == 0
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
# Returns whether the position x,y is fully passable (there is no blocking
|
||||
# event there, and the tile is fully passable in all directions)
|
||||
def passableStrict?(x, y, d, self_event = nil)
|
||||
return false if !valid?(x, y)
|
||||
for event in events.values
|
||||
next if event == self_event || event.tile_id < 0 || event.through
|
||||
next if !event.at_coordinate?(x, y)
|
||||
next if GameData::TerrainTag.try_get(@terrain_tags[event.tile_id]).ignore_passability
|
||||
return false if @passages[event.tile_id] & 0x0f != 0
|
||||
return true if @priorities[event.tile_id] == 0
|
||||
end
|
||||
for i in [2, 1, 0]
|
||||
tile_id = data[x, y, i]
|
||||
next if GameData::TerrainTag.try_get(@terrain_tags[tile_id]).ignore_passability
|
||||
return false if @passages[tile_id] & 0x0f != 0
|
||||
return true if @priorities[tile_id] == 0
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
def bush?(x,y)
|
||||
for i in [2, 1, 0]
|
||||
tile_id = data[x, y, i]
|
||||
return false if GameData::TerrainTag.try_get(@terrain_tags[tile_id]).bridge &&
|
||||
$PokemonGlobal.bridge > 0
|
||||
return true if @passages[tile_id] & 0x40 == 0x40
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def deepBush?(x,y)
|
||||
for i in [2, 1, 0]
|
||||
tile_id = data[x, y, i]
|
||||
terrain = GameData::TerrainTag.try_get(@terrain_tags[tile_id])
|
||||
return false if terrain.bridge && $PokemonGlobal.bridge > 0
|
||||
return true if terrain.deep_bush && @passages[tile_id] & 0x40 == 0x40
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def counter?(x,y)
|
||||
for i in [2, 1, 0]
|
||||
tile_id = data[x, y, i]
|
||||
passage = @passages[tile_id]
|
||||
return true if passage & 0x80 == 0x80
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def terrain_tag(x,y,countBridge=false)
|
||||
if valid?(x, y)
|
||||
for i in [2, 1, 0]
|
||||
tile_id = data[x, y, i]
|
||||
terrain = GameData::TerrainTag.try_get(@terrain_tags[tile_id])
|
||||
next if terrain.id == :None || terrain.ignore_passability
|
||||
next if !countBridge && terrain.bridge && $PokemonGlobal.bridge == 0
|
||||
return terrain
|
||||
end
|
||||
end
|
||||
return GameData::TerrainTag.get(:None)
|
||||
end
|
||||
|
||||
# Unused.
|
||||
def check_event(x,y)
|
||||
for event in self.events.values
|
||||
return event.id if event.at_coordinate?(x, y)
|
||||
end
|
||||
end
|
||||
|
||||
def display_x=(value)
|
||||
return if @display_x == value
|
||||
@display_x = value
|
||||
if GameData::MapMetadata.exists?(self.map_id) && GameData::MapMetadata.get(self.map_id).snap_edges
|
||||
max_x = (self.width - Graphics.width*1.0/TILE_WIDTH) * REAL_RES_X
|
||||
@display_x = [0, [@display_x, max_x].min].max
|
||||
end
|
||||
$MapFactory.setMapsInRange if $MapFactory
|
||||
end
|
||||
|
||||
def display_y=(value)
|
||||
return if @display_y == value
|
||||
@display_y = value
|
||||
if GameData::MapMetadata.exists?(self.map_id) && GameData::MapMetadata.get(self.map_id).snap_edges
|
||||
max_y = (self.height - Graphics.height*1.0/TILE_HEIGHT) * REAL_RES_Y
|
||||
@display_y = [0, [@display_y, max_y].min].max
|
||||
end
|
||||
$MapFactory.setMapsInRange if $MapFactory
|
||||
end
|
||||
|
||||
def scroll_up(distance)
|
||||
self.display_y -= distance
|
||||
end
|
||||
|
||||
def scroll_down(distance)
|
||||
self.display_y += distance
|
||||
end
|
||||
|
||||
def scroll_left(distance)
|
||||
self.display_x -= distance
|
||||
end
|
||||
|
||||
def scroll_right(distance)
|
||||
self.display_x += distance
|
||||
end
|
||||
|
||||
def start_scroll(direction, distance, speed)
|
||||
@scroll_direction = direction
|
||||
if direction==2 || direction==8 # down or up
|
||||
@scroll_rest = distance * REAL_RES_Y
|
||||
else
|
||||
@scroll_rest = distance * REAL_RES_X
|
||||
end
|
||||
@scroll_speed = speed
|
||||
end
|
||||
|
||||
def scrolling?
|
||||
return @scroll_rest > 0
|
||||
end
|
||||
|
||||
def start_fog_tone_change(tone,duration)
|
||||
@fog_tone_target = tone.clone
|
||||
@fog_tone_duration = duration
|
||||
if @fog_tone_duration == 0
|
||||
@fog_tone = @fog_tone_target.clone
|
||||
end
|
||||
end
|
||||
|
||||
def start_fog_opacity_change(opacity,duration)
|
||||
@fog_opacity_target = opacity*1.0
|
||||
@fog_opacity_duration = duration
|
||||
if @fog_opacity_duration==0
|
||||
@fog_opacity = @fog_opacity_target
|
||||
end
|
||||
end
|
||||
|
||||
def refresh
|
||||
for event in @events.values
|
||||
event.refresh
|
||||
end
|
||||
for common_event in @common_events.values
|
||||
common_event.refresh
|
||||
end
|
||||
@need_refresh = false
|
||||
end
|
||||
|
||||
def update
|
||||
# refresh maps if necessary
|
||||
if $MapFactory
|
||||
for i in $MapFactory.maps
|
||||
i.refresh if i.need_refresh
|
||||
end
|
||||
$MapFactory.setCurrentMap
|
||||
end
|
||||
# If scrolling
|
||||
if @scroll_rest>0
|
||||
distance = (1<<@scroll_speed)*40.0/Graphics.frame_rate
|
||||
distance = @scroll_rest if distance>@scroll_rest
|
||||
case @scroll_direction
|
||||
when 2 then scroll_down(distance)
|
||||
when 4 then scroll_left(distance)
|
||||
when 6 then scroll_right(distance)
|
||||
when 8 then scroll_up(distance)
|
||||
end
|
||||
@scroll_rest -= distance
|
||||
end
|
||||
# Only update events that are on-screen
|
||||
for event in @events.values
|
||||
event.update
|
||||
end
|
||||
# Update common events
|
||||
for common_event in @common_events.values
|
||||
common_event.update
|
||||
end
|
||||
# Update fog
|
||||
@fog_ox -= @fog_sx/8.0
|
||||
@fog_oy -= @fog_sy/8.0
|
||||
if @fog_tone_duration>=1
|
||||
d = @fog_tone_duration
|
||||
target = @fog_tone_target
|
||||
@fog_tone.red = (@fog_tone.red * (d - 1) + target.red) / d
|
||||
@fog_tone.green = (@fog_tone.green * (d - 1) + target.green) / d
|
||||
@fog_tone.blue = (@fog_tone.blue * (d - 1) + target.blue) / d
|
||||
@fog_tone.gray = (@fog_tone.gray * (d - 1) + target.gray) / d
|
||||
@fog_tone_duration -= 1
|
||||
end
|
||||
if @fog_opacity_duration >= 1
|
||||
d = @fog_opacity_duration
|
||||
@fog_opacity = (@fog_opacity * (d - 1) + @fog_opacity_target) / d
|
||||
@fog_opacity_duration -= 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
def pbScrollMap(direction,distance,speed)
|
||||
if speed==0
|
||||
case direction
|
||||
when 2 then $game_map.scroll_down(distance * Game_Map::REAL_RES_Y)
|
||||
when 4 then $game_map.scroll_left(distance * Game_Map::REAL_RES_X)
|
||||
when 6 then $game_map.scroll_right(distance * Game_Map::REAL_RES_X)
|
||||
when 8 then $game_map.scroll_up(distance * Game_Map::REAL_RES_Y)
|
||||
end
|
||||
else
|
||||
$game_map.start_scroll(direction, distance, speed)
|
||||
oldx = $game_map.display_x
|
||||
oldy = $game_map.display_y
|
||||
loop do
|
||||
Graphics.update
|
||||
Input.update
|
||||
break if !$game_map.scrolling?
|
||||
pbUpdateSceneMap
|
||||
break if $game_map.display_x==oldx && $game_map.display_y==oldy
|
||||
oldx = $game_map.display_x
|
||||
oldy = $game_map.display_y
|
||||
end
|
||||
end
|
||||
end
|
||||
194
Data/Scripts_backup/004_Game classes/005_Game_Map_Autoscroll.rb
Normal file
194
Data/Scripts_backup/004_Game classes/005_Game_Map_Autoscroll.rb
Normal file
@@ -0,0 +1,194 @@
|
||||
#===============================================================================
|
||||
# ** Map Autoscroll
|
||||
#-------------------------------------------------------------------------------
|
||||
# Wachunga
|
||||
# Version 1.02
|
||||
# 2005-12-18
|
||||
#===============================================================================
|
||||
=begin
|
||||
|
||||
This script supplements the built-in "Scroll Map" event command with the
|
||||
aim of simplifying cutscenes (and map scrolling in general). Whereas the
|
||||
normal event command requires a direction and number of tiles to scroll,
|
||||
Map Autoscroll scrolls the map to center on the tile whose x and y
|
||||
coordinates are given.
|
||||
|
||||
FEATURES
|
||||
- automatic map scrolling to given x,y coordinate (or player)
|
||||
- destination is fixed, so it's possible to scroll to same place even if
|
||||
origin is variable (e.g. moving NPC)
|
||||
- variable speed (just like "Scroll Map" event command)
|
||||
- diagonal scrolling supported
|
||||
|
||||
SETUP
|
||||
Instead of a "Scroll Map" event command, use the "Call Script" command
|
||||
and enter on the following on the first line:
|
||||
|
||||
autoscroll(x,y)
|
||||
|
||||
(replacing "x" and "y" with the x and y coordinates of the tile to scroll to)
|
||||
|
||||
To specify a scroll speed other than the default (4), use:
|
||||
|
||||
autoscroll(x,y,speed)
|
||||
|
||||
(now also replacing "speed" with the scroll speed from 1-6)
|
||||
|
||||
Diagonal scrolling happens automatically when the destination is diagonal
|
||||
relative to the starting point (i.e., not directly up, down, left or right).
|
||||
|
||||
To scroll to the player, instead use the following:
|
||||
|
||||
autoscroll_player(speed)
|
||||
|
||||
Note: because of how the interpreter and the "Call Script" event command
|
||||
are setup, the call to autoscroll(...) can only be on the first line of
|
||||
the "Call Script" event command (and not flowing down to subsequent lines).
|
||||
|
||||
For example, the following call may not work as expected:
|
||||
|
||||
autoscroll($game_variables[1],
|
||||
$game_variables[2])
|
||||
|
||||
(since the long argument names require dropping down to a second line)
|
||||
A work-around is to setup new variables with shorter names in a preceding
|
||||
(separate) "Call Script" event command:
|
||||
|
||||
@x = $game_variables[1]
|
||||
@y = $game_variables[2]
|
||||
|
||||
and then use those as arguments:
|
||||
|
||||
autoscroll(@x,@y)
|
||||
|
||||
The renaming must be in a separate "Call Script" because otherwise
|
||||
the call to autoscroll(...) isn't on the first line.
|
||||
|
||||
Originally requested by militantmilo80:
|
||||
http://www.rmxp.net/forums/index.php?showtopic=29519
|
||||
|
||||
=end
|
||||
|
||||
class Interpreter
|
||||
SCROLL_SPEED_DEFAULT = 4
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Map Autoscroll to Coordinates
|
||||
# x : x coordinate to scroll to and center on
|
||||
# y : y coordinate to scroll to and center on
|
||||
# speed : (optional) scroll speed (from 1-6, default being 4)
|
||||
#-----------------------------------------------------------------------------
|
||||
def autoscroll(x,y,speed=SCROLL_SPEED_DEFAULT)
|
||||
if $game_map.scrolling?
|
||||
return false
|
||||
elsif !$game_map.valid?(x,y)
|
||||
print 'Map Autoscroll: given x,y is invalid'
|
||||
return command_skip
|
||||
elsif !(1..6).include?(speed)
|
||||
print 'Map Autoscroll: invalid speed (1-6 only)'
|
||||
return command_skip
|
||||
end
|
||||
center_x = (Graphics.width/2 - Game_Map::TILE_WIDTH/2) * 4 # X coordinate in the center of the screen
|
||||
center_y = (Graphics.height/2 - Game_Map::TILE_HEIGHT/2) * 4 # Y coordinate in the center of the screen
|
||||
max_x = ($game_map.width - Graphics.width*1.0/Game_Map::TILE_WIDTH) * 4 * Game_Map::TILE_WIDTH
|
||||
max_y = ($game_map.height - Graphics.height*1.0/Game_Map::TILE_HEIGHT) * 4 * Game_Map::TILE_HEIGHT
|
||||
count_x = ($game_map.display_x - [0,[x*Game_Map::REAL_RES_X-center_x,max_x].min].max)/Game_Map::REAL_RES_X
|
||||
count_y = ($game_map.display_y - [0,[y*Game_Map::REAL_RES_Y-center_y,max_y].min].max)/Game_Map::REAL_RES_Y
|
||||
if !@diag
|
||||
@diag = true
|
||||
dir = nil
|
||||
if count_x > 0
|
||||
if count_y > 0
|
||||
dir = 7
|
||||
elsif count_y < 0
|
||||
dir = 1
|
||||
end
|
||||
elsif count_x < 0
|
||||
if count_y > 0
|
||||
dir = 9
|
||||
elsif count_y < 0
|
||||
dir = 3
|
||||
end
|
||||
end
|
||||
count = [count_x.abs,count_y.abs].min
|
||||
else
|
||||
@diag = false
|
||||
dir = nil
|
||||
if count_x != 0 && count_y != 0
|
||||
return false
|
||||
elsif count_x > 0
|
||||
dir = 4
|
||||
elsif count_x < 0
|
||||
dir = 6
|
||||
elsif count_y > 0
|
||||
dir = 8
|
||||
elsif count_y < 0
|
||||
dir = 2
|
||||
end
|
||||
count = count_x != 0 ? count_x.abs : count_y.abs
|
||||
end
|
||||
$game_map.start_scroll(dir, count, speed) if dir != nil
|
||||
if @diag
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Map Autoscroll (to Player)
|
||||
# speed : (optional) scroll speed (from 1-6, default being 4)
|
||||
#-----------------------------------------------------------------------------
|
||||
def autoscroll_player(speed=SCROLL_SPEED_DEFAULT)
|
||||
autoscroll($game_player.x,$game_player.y,speed)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class Game_Map
|
||||
def scroll_downright(distance)
|
||||
@display_x = [@display_x + distance,
|
||||
(self.width - Graphics.width*1.0/TILE_WIDTH) * REAL_RES_X].min
|
||||
@display_y = [@display_y + distance,
|
||||
(self.height - Graphics.height*1.0/TILE_HEIGHT) * REAL_RES_Y].min
|
||||
end
|
||||
|
||||
def scroll_downleft(distance)
|
||||
@display_x = [@display_x - distance, 0].max
|
||||
@display_y = [@display_y + distance,
|
||||
(self.height - Graphics.height*1.0/TILE_HEIGHT) * REAL_RES_Y].min
|
||||
end
|
||||
|
||||
def scroll_upright(distance)
|
||||
@display_x = [@display_x + distance,
|
||||
(self.width - Graphics.width*1.0/TILE_WIDTH) * REAL_RES_X].min
|
||||
@display_y = [@display_y - distance, 0].max
|
||||
end
|
||||
|
||||
def scroll_upleft(distance)
|
||||
@display_x = [@display_x - distance, 0].max
|
||||
@display_y = [@display_y - distance, 0].max
|
||||
end
|
||||
|
||||
def update_scrolling
|
||||
# If scrolling
|
||||
if @scroll_rest > 0
|
||||
# Change from scroll speed to distance in map coordinates
|
||||
distance = (1<<@scroll_speed)*40/Graphics.frame_rate
|
||||
distance = @scroll_rest if distance>@scroll_rest
|
||||
# Execute scrolling
|
||||
case @scroll_direction
|
||||
when 1 then scroll_downleft(distance)
|
||||
when 2 then scroll_down(distance)
|
||||
when 3 then scroll_downright(distance)
|
||||
when 4 then scroll_left(distance)
|
||||
when 6 then scroll_right(distance)
|
||||
when 7 then scroll_upleft(distance)
|
||||
when 8 then scroll_up(distance)
|
||||
when 9 then scroll_upright(distance)
|
||||
end
|
||||
# Subtract distance scrolled
|
||||
@scroll_rest -= distance
|
||||
end
|
||||
end
|
||||
end
|
||||
526
Data/Scripts_backup/004_Game classes/006_Game_MapFactory.rb
Normal file
526
Data/Scripts_backup/004_Game classes/006_Game_MapFactory.rb
Normal file
@@ -0,0 +1,526 @@
|
||||
#===============================================================================
|
||||
# Map Factory (allows multiple maps to be loaded at once and connected)
|
||||
#===============================================================================
|
||||
class PokemonMapFactory
|
||||
attr_reader :maps
|
||||
|
||||
def initialize(id)
|
||||
@maps = []
|
||||
@fixup = false
|
||||
@mapChanged = false # transient instance variable
|
||||
setup(id)
|
||||
end
|
||||
|
||||
# Clears all maps and sets up the current map with id. This function also sets
|
||||
# the positions of neighboring maps and notifies the game system of a map
|
||||
# change.
|
||||
def setup(id)
|
||||
@maps.clear
|
||||
@maps[0] = Game_Map.new
|
||||
@mapIndex = 0
|
||||
oldID = ($game_map) ? $game_map.map_id : 0
|
||||
setMapChanging(id,@maps[0]) if oldID!=0 && oldID!=@maps[0].map_id
|
||||
$game_map = @maps[0]
|
||||
@maps[0].setup(id)
|
||||
setMapsInRange
|
||||
setMapChanged(oldID)
|
||||
end
|
||||
|
||||
def map
|
||||
@mapIndex = 0 if !@mapIndex || @mapIndex<0
|
||||
return @maps[@mapIndex] if @maps[@mapIndex]
|
||||
raise "No maps in save file... (mapIndex=#{@mapIndex})" if @maps.length==0
|
||||
if @maps[0]
|
||||
echoln("Using next map, may be incorrect (mapIndex=#{@mapIndex}, length=#{@maps.length})")
|
||||
return @maps[0]
|
||||
end
|
||||
raise "No maps in save file... (all maps empty; mapIndex=#{@mapIndex})"
|
||||
end
|
||||
|
||||
def hasMap?(id)
|
||||
for map in @maps
|
||||
return true if map.map_id==id
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def getMapIndex(id)
|
||||
for i in 0...@maps.length
|
||||
return i if @maps[i].map_id==id
|
||||
end
|
||||
return -1
|
||||
end
|
||||
|
||||
def getMap(id,add=true)
|
||||
for map in @maps
|
||||
return map if map.map_id==id
|
||||
end
|
||||
map = Game_Map.new
|
||||
map.setup(id)
|
||||
@maps.push(map) if add
|
||||
return map
|
||||
end
|
||||
|
||||
def getMapNoAdd(id)
|
||||
return getMap(id,false)
|
||||
end
|
||||
|
||||
def getNewMap(playerX,playerY)
|
||||
id = $game_map.map_id
|
||||
conns = MapFactoryHelper.getMapConnections
|
||||
if conns[id]
|
||||
for conn in conns[id]
|
||||
mapidB = nil
|
||||
newx = 0
|
||||
newy = 0
|
||||
if conn[0] == id
|
||||
mapidB = conn[3]
|
||||
mapB = MapFactoryHelper.getMapDims(conn[3])
|
||||
newx = conn[4] - conn[1] + playerX
|
||||
newy = conn[5] - conn[2] + playerY
|
||||
else
|
||||
mapidB = conn[0]
|
||||
mapB = MapFactoryHelper.getMapDims(conn[0])
|
||||
newx = conn[1] - conn[4] + playerX
|
||||
newy = conn[2] - conn[5] + playerY
|
||||
end
|
||||
if newx >= 0 && newx < mapB[0] && newy >= 0 && newy < mapB[1]
|
||||
return [getMap(mapidB), newx, newy]
|
||||
end
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
# Detects whether the player has moved onto a connected map, and if so, causes
|
||||
# their transfer to that map.
|
||||
def setCurrentMap
|
||||
return if $game_player.moving?
|
||||
return if $game_map.valid?($game_player.x,$game_player.y)
|
||||
newmap = getNewMap($game_player.x,$game_player.y)
|
||||
return if !newmap
|
||||
oldmap=$game_map.map_id
|
||||
if oldmap!=0 && oldmap!=newmap[0].map_id
|
||||
setMapChanging(newmap[0].map_id,newmap[0])
|
||||
end
|
||||
$game_map = newmap[0]
|
||||
@mapIndex = getMapIndex($game_map.map_id)
|
||||
$game_player.moveto(newmap[1],newmap[2])
|
||||
$game_map.update
|
||||
pbAutoplayOnTransition
|
||||
$game_map.refresh
|
||||
setMapChanged(oldmap)
|
||||
$game_screen.weather_duration = 20
|
||||
end
|
||||
|
||||
def setMapsInRange
|
||||
return if @fixup
|
||||
@fixup = true
|
||||
id = $game_map.map_id
|
||||
conns = MapFactoryHelper.getMapConnections
|
||||
if conns[id]
|
||||
for conn in conns[id]
|
||||
if conn[0] == id
|
||||
mapA = getMap(conn[0])
|
||||
newdispx = (conn[4] - conn[1]) * Game_Map::REAL_RES_X + mapA.display_x
|
||||
newdispy = (conn[5] - conn[2]) * Game_Map::REAL_RES_Y + mapA.display_y
|
||||
if hasMap?(conn[3]) || MapFactoryHelper.mapInRangeById?(conn[3], newdispx, newdispy)
|
||||
mapB = getMap(conn[3])
|
||||
mapB.display_x = newdispx if mapB.display_x != newdispx
|
||||
mapB.display_y = newdispy if mapB.display_y != newdispy
|
||||
end
|
||||
else
|
||||
mapA = getMap(conn[3])
|
||||
newdispx = (conn[1] - conn[4]) * Game_Map::REAL_RES_X + mapA.display_x
|
||||
newdispy = (conn[2] - conn[5]) * Game_Map::REAL_RES_Y + mapA.display_y
|
||||
if hasMap?(conn[0]) || MapFactoryHelper.mapInRangeById?(conn[0], newdispx, newdispy)
|
||||
mapB = getMap(conn[0])
|
||||
mapB.display_x = newdispx if mapB.display_x != newdispx
|
||||
mapB.display_y = newdispy if mapB.display_y != newdispy
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@fixup = false
|
||||
end
|
||||
|
||||
def setMapChanging(newID,newMap)
|
||||
Events.onMapChanging.trigger(self,newID,newMap)
|
||||
end
|
||||
|
||||
def setMapChanged(prevMap)
|
||||
Events.onMapChange.trigger(self,prevMap)
|
||||
@mapChanged = true
|
||||
end
|
||||
|
||||
def setSceneStarted(scene)
|
||||
Events.onMapSceneChange.trigger(self,scene,@mapChanged)
|
||||
@mapChanged = false
|
||||
end
|
||||
|
||||
# Similar to Game_Player#passable?, but supports map connections
|
||||
def isPassableFromEdge?(x, y)
|
||||
return true if $game_map.valid?(x, y)
|
||||
newmap = getNewMap(x, y)
|
||||
return false if !newmap
|
||||
return isPassable?(newmap[0].map_id, newmap[1], newmap[2])
|
||||
end
|
||||
|
||||
def isPassable?(mapID, x, y, thisEvent = nil)
|
||||
thisEvent = $game_player if !thisEvent
|
||||
map = getMapNoAdd(mapID)
|
||||
return false if !map
|
||||
return false if !map.valid?(x, y)
|
||||
return true if thisEvent.through
|
||||
# Check passability of tile
|
||||
if thisEvent.is_a?(Game_Player)
|
||||
return false unless ($DEBUG && Input.press?(Input::CTRL)) ||
|
||||
map.passable?(x, y, 0, thisEvent)
|
||||
else
|
||||
return false unless map.passable?(x, y, 0, thisEvent)
|
||||
end
|
||||
# Check passability of event(s) in that spot
|
||||
for event in map.events.values
|
||||
next if event == thisEvent || !event.at_coordinate?(x, y)
|
||||
return false if !event.through && event.character_name != ""
|
||||
end
|
||||
# Check passability of player
|
||||
if !thisEvent.is_a?(Game_Player)
|
||||
if $game_map.map_id == mapID && $game_player.x == x && $game_player.y == y
|
||||
return false if !$game_player.through && $game_player.character_name != ""
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
# Only used by dependent events
|
||||
def isPassableStrict?(mapID,x,y,thisEvent=nil)
|
||||
thisEvent = $game_player if !thisEvent
|
||||
map = getMapNoAdd(mapID)
|
||||
return false if !map
|
||||
return false if !map.valid?(x,y)
|
||||
return true if thisEvent.through
|
||||
if thisEvent==$game_player
|
||||
if !($DEBUG && Input.press?(Input::CTRL))
|
||||
return false if !map.passableStrict?(x,y,0,thisEvent)
|
||||
end
|
||||
else
|
||||
return false if !map.passableStrict?(x,y,0,thisEvent)
|
||||
end
|
||||
for event in map.events.values
|
||||
next if event == thisEvent || !event.at_coordinate?(x, y)
|
||||
return false if !event.through && event.character_name!=""
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
def getTerrainTag(mapid,x,y,countBridge=false)
|
||||
map = getMapNoAdd(mapid)
|
||||
return map.terrain_tag(x,y,countBridge)
|
||||
end
|
||||
|
||||
# NOTE: Assumes the event is 1x1 tile in size. Only returns one terrain tag.
|
||||
def getFacingTerrainTag(dir=nil,event=nil)
|
||||
tile = getFacingTile(dir,event)
|
||||
return GameData::TerrainTag.get(:None) if !tile
|
||||
return getTerrainTag(tile[0],tile[1],tile[2])
|
||||
end
|
||||
|
||||
def getTerrainTagFromCoords(mapid,x,y,countBridge=false)
|
||||
tile = getRealTilePos(mapid,x,y)
|
||||
return GameData::TerrainTag.get(:None) if !tile
|
||||
return getTerrainTag(tile[0],tile[1],tile[2])
|
||||
end
|
||||
|
||||
def areConnected?(mapID1, mapID2)
|
||||
return true if mapID1 == mapID2
|
||||
conns = MapFactoryHelper.getMapConnections
|
||||
if conns[mapID1]
|
||||
for conn in conns[mapID1]
|
||||
return true if conn[0] == mapID2 || conn[3] == mapID2
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def getRelativePos(thisMapID, thisX, thisY, otherMapID, otherX, otherY)
|
||||
if thisMapID == otherMapID # Both events share the same map
|
||||
return [otherX - thisX, otherY - thisY]
|
||||
end
|
||||
conns = MapFactoryHelper.getMapConnections
|
||||
if conns[thisMapID]
|
||||
for conn in conns[thisMapID]
|
||||
if conn[0] == otherMapID
|
||||
posX = thisX + conn[1] - conn[4] + otherX
|
||||
posY = thisY + conn[2] - conn[5] + otherY
|
||||
return [posX, posY]
|
||||
elsif conn[1] == otherMapID
|
||||
posX = thisX + conn[4] - conn[1] + otherX
|
||||
posY = thisY + conn[5] - conn[2] + otherY
|
||||
return [posX, posY]
|
||||
end
|
||||
end
|
||||
end
|
||||
return [0, 0]
|
||||
end
|
||||
|
||||
# Gets the distance from this event to another event. Example: If this event's
|
||||
# coordinates are (2,5) and the other event's coordinates are (5,1), returns
|
||||
# the array (3,-4), because (5-2=3) and (1-5=-4).
|
||||
def getThisAndOtherEventRelativePos(thisEvent,otherEvent)
|
||||
return [0,0] if !thisEvent || !otherEvent
|
||||
return getRelativePos(
|
||||
thisEvent.map.map_id,thisEvent.x,thisEvent.y,
|
||||
otherEvent.map.map_id,otherEvent.x,otherEvent.y)
|
||||
end
|
||||
|
||||
def getThisAndOtherPosRelativePos(thisEvent,otherMapID,otherX,otherY)
|
||||
return [0,0] if !thisEvent
|
||||
return getRelativePos(
|
||||
thisEvent.map.map_id,thisEvent.x,thisEvent.y,otherMapID,otherX,otherY)
|
||||
end
|
||||
|
||||
# Unused
|
||||
def getOffsetEventPos(event,xOffset,yOffset)
|
||||
event = $game_player if !event
|
||||
return nil if !event
|
||||
return getRealTilePos(event.map.map_id,event.x+xOffset,event.y+yOffset)
|
||||
end
|
||||
|
||||
# NOTE: Assumes the event is 1x1 tile in size. Only returns one tile.
|
||||
def getFacingTile(direction=nil,event=nil,steps=1)
|
||||
event = $game_player if event==nil
|
||||
return [0,0,0] if !event
|
||||
x = event.x
|
||||
y = event.y
|
||||
id = event.map.map_id
|
||||
direction = event.direction if direction==nil
|
||||
return getFacingTileFromPos(id,x,y,direction,steps)
|
||||
end
|
||||
|
||||
def getFacingTileFromPos(mapID,x,y,direction=0,steps=1)
|
||||
id = mapID
|
||||
case direction
|
||||
when 1
|
||||
x -= steps
|
||||
y += steps
|
||||
when 2
|
||||
y += steps
|
||||
when 3
|
||||
x += steps
|
||||
y += steps
|
||||
when 4
|
||||
x -= steps
|
||||
when 6
|
||||
x += steps
|
||||
when 7
|
||||
x -= steps
|
||||
y -= steps
|
||||
when 8
|
||||
y -= steps
|
||||
when 9
|
||||
x += steps
|
||||
y -= steps
|
||||
else
|
||||
return [id,x,y]
|
||||
end
|
||||
return getRealTilePos(mapID,x,y)
|
||||
end
|
||||
|
||||
def getRealTilePos(mapID, x, y)
|
||||
id = mapID
|
||||
return [id, x, y] if getMapNoAdd(id).valid?(x, y)
|
||||
conns = MapFactoryHelper.getMapConnections
|
||||
if conns[id]
|
||||
for conn in conns[id]
|
||||
if conn[0] == id
|
||||
newX = x + conn[4] - conn[1]
|
||||
newY = y + conn[5] - conn[2]
|
||||
next if newX < 0 || newY < 0
|
||||
dims = MapFactoryHelper.getMapDims(conn[3])
|
||||
next if newX >= dims[0] || newY >= dims[1]
|
||||
return [conn[3], newX, newY]
|
||||
else
|
||||
newX = x + conn[1] - conn[4]
|
||||
newY = y + conn[2] - conn[5]
|
||||
next if newX < 0 || newY < 0
|
||||
dims = MapFactoryHelper.getMapDims(conn[0])
|
||||
next if newX >= dims[0] || newY >= dims[1]
|
||||
return [conn[0], newX, newY]
|
||||
end
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
def getFacingCoords(x,y,direction=0,steps=1)
|
||||
case direction
|
||||
when 1
|
||||
x -= steps
|
||||
y += steps
|
||||
when 2
|
||||
y += steps
|
||||
when 3
|
||||
x += steps
|
||||
y += steps
|
||||
when 4
|
||||
x -= steps
|
||||
when 6
|
||||
x += steps
|
||||
when 7
|
||||
x -= steps
|
||||
y -= steps
|
||||
when 8
|
||||
y -= steps
|
||||
when 9
|
||||
x += steps
|
||||
y -= steps
|
||||
end
|
||||
return [x,y]
|
||||
end
|
||||
|
||||
def updateMaps(scene)
|
||||
updateMapsInternal
|
||||
$MapFactory.setSceneStarted(scene) if @mapChanged
|
||||
end
|
||||
|
||||
def updateMapsInternal
|
||||
return if $game_player.moving?
|
||||
if !MapFactoryHelper.hasConnections?($game_map.map_id)
|
||||
return if @maps.length==1
|
||||
for i in 0...@maps.length
|
||||
@maps[i] = nil if $game_map.map_id!=@maps[i].map_id
|
||||
end
|
||||
@maps.compact!
|
||||
@mapIndex = getMapIndex($game_map.map_id)
|
||||
return
|
||||
end
|
||||
setMapsInRange
|
||||
deleted = false
|
||||
for i in 0...@maps.length
|
||||
next if MapFactoryHelper.mapInRange?(@maps[i])
|
||||
@maps[i] = nil
|
||||
deleted = true
|
||||
end
|
||||
if deleted
|
||||
@maps.compact!
|
||||
@mapIndex = getMapIndex($game_map.map_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# Map Factory Helper (stores map connection and size data and calculations
|
||||
# involving them)
|
||||
#===============================================================================
|
||||
module MapFactoryHelper
|
||||
@@MapConnections = nil
|
||||
@@MapDims = nil
|
||||
|
||||
def self.clear
|
||||
@@MapConnections = nil
|
||||
@@MapDims = nil
|
||||
end
|
||||
|
||||
def self.getMapConnections
|
||||
if !@@MapConnections
|
||||
@@MapConnections = []
|
||||
conns = load_data("Data/map_connections.dat")
|
||||
conns.each do |conn|
|
||||
# Ensure both maps in a connection are valid
|
||||
dimensions = getMapDims(conn[0])
|
||||
next if dimensions[0] == 0 || dimensions[1] == 0
|
||||
dimensions = getMapDims(conn[3])
|
||||
next if dimensions[0] == 0 || dimensions[1] == 0
|
||||
# Convert first map's edge and coordinate to pair of coordinates
|
||||
edge = getMapEdge(conn[0], conn[1])
|
||||
case conn[1]
|
||||
when "N", "S"
|
||||
conn[1] = conn[2]
|
||||
conn[2] = edge
|
||||
when "E", "W"
|
||||
conn[1] = edge
|
||||
end
|
||||
# Convert second map's edge and coordinate to pair of coordinates
|
||||
edge = getMapEdge(conn[3], conn[4])
|
||||
case conn[4]
|
||||
when "N", "S"
|
||||
conn[4] = conn[5]
|
||||
conn[5] = edge
|
||||
when "E", "W"
|
||||
conn[4] = edge
|
||||
end
|
||||
# Add connection to arrays for both maps
|
||||
@@MapConnections[conn[0]] = [] if !@@MapConnections[conn[0]]
|
||||
@@MapConnections[conn[0]].push(conn)
|
||||
@@MapConnections[conn[3]] = [] if !@@MapConnections[conn[3]]
|
||||
@@MapConnections[conn[3]].push(conn)
|
||||
end
|
||||
end
|
||||
return @@MapConnections
|
||||
end
|
||||
|
||||
def self.hasConnections?(id)
|
||||
conns = MapFactoryHelper.getMapConnections
|
||||
return conns[id] ? true : false
|
||||
end
|
||||
|
||||
# Gets the height and width of the map with id
|
||||
def self.getMapDims(id)
|
||||
# Create cache if doesn't exist
|
||||
@@MapDims = [] if !@@MapDims
|
||||
# Add map to cache if can't be found
|
||||
if !@@MapDims[id]
|
||||
begin
|
||||
map = load_data(sprintf("Data/Map%03d.rxdata", id))
|
||||
@@MapDims[id] = [map.width,map.height]
|
||||
rescue
|
||||
@@MapDims[id] = [0,0]
|
||||
end
|
||||
end
|
||||
# Return map in cache
|
||||
return @@MapDims[id]
|
||||
end
|
||||
|
||||
# Returns the X or Y coordinate of an edge on the map with id.
|
||||
# Considers the special strings "N","W","E","S"
|
||||
def self.getMapEdge(id,edge)
|
||||
return 0 if edge=="N" || edge=="W"
|
||||
dims = getMapDims(id) # Get dimensions
|
||||
return dims[0] if edge=="E"
|
||||
return dims[1] if edge=="S"
|
||||
return dims[0] # real dimension (use width)
|
||||
end
|
||||
|
||||
def self.mapInRange?(map)
|
||||
range = 6 # Number of tiles
|
||||
dispx = map.display_x
|
||||
dispy = map.display_y
|
||||
return false if dispx >= (map.width + range) * Game_Map::REAL_RES_X
|
||||
return false if dispy >= (map.height + range) * Game_Map::REAL_RES_Y
|
||||
return false if dispx <= -(Graphics.width + range * Game_Map::TILE_WIDTH) * Game_Map::X_SUBPIXELS
|
||||
return false if dispy <= -(Graphics.height + range * Game_Map::TILE_HEIGHT) * Game_Map::Y_SUBPIXELS
|
||||
return true
|
||||
end
|
||||
|
||||
def self.mapInRangeById?(id,dispx,dispy)
|
||||
range = 6 # Number of tiles
|
||||
dims = MapFactoryHelper.getMapDims(id)
|
||||
return false if dispx >= (dims[0] + range) * Game_Map::REAL_RES_X
|
||||
return false if dispy >= (dims[1] + range) * Game_Map::REAL_RES_Y
|
||||
return false if dispx <= -(Graphics.width + range * Game_Map::TILE_WIDTH) * Game_Map::X_SUBPIXELS
|
||||
return false if dispy <= -(Graphics.height + range * Game_Map::TILE_HEIGHT) * Game_Map::Y_SUBPIXELS
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
# Unused
|
||||
def updateTilesets
|
||||
maps = $MapFactory.maps
|
||||
for map in maps
|
||||
map.updateTileset if map
|
||||
end
|
||||
end
|
||||
953
Data/Scripts_backup/004_Game classes/007_Game_Character.rb
Normal file
953
Data/Scripts_backup/004_Game classes/007_Game_Character.rb
Normal file
@@ -0,0 +1,953 @@
|
||||
class Game_Character
|
||||
attr_reader :id
|
||||
attr_reader :original_x
|
||||
attr_reader :original_y
|
||||
attr_reader :x
|
||||
attr_reader :y
|
||||
attr_reader :real_x
|
||||
attr_reader :real_y
|
||||
attr_accessor :width
|
||||
attr_accessor :height
|
||||
attr_accessor :sprite_size
|
||||
attr_reader :tile_id
|
||||
attr_accessor :character_name
|
||||
attr_accessor :character_hue
|
||||
attr_reader :opacity
|
||||
attr_reader :blend_type
|
||||
attr_accessor :direction
|
||||
attr_accessor :pattern
|
||||
attr_accessor :pattern_surf
|
||||
attr_accessor :lock_pattern
|
||||
attr_reader :move_route_forcing
|
||||
attr_accessor :through
|
||||
attr_accessor :animation_id
|
||||
attr_accessor :transparent
|
||||
attr_reader :move_speed
|
||||
attr_accessor :walk_anime
|
||||
attr_writer :bob_height
|
||||
|
||||
def initialize(map=nil)
|
||||
@map = map
|
||||
@id = 0
|
||||
@original_x = 0
|
||||
@original_y = 0
|
||||
@x = 0
|
||||
@y = 0
|
||||
@real_x = 0
|
||||
@real_y = 0
|
||||
@width = 1
|
||||
@height = 1
|
||||
@sprite_size = [Game_Map::TILE_WIDTH, Game_Map::TILE_HEIGHT]
|
||||
@tile_id = 0
|
||||
@character_name = ""
|
||||
@character_hue = 0
|
||||
@opacity = 255
|
||||
@blend_type = 0
|
||||
@direction = 2
|
||||
@pattern = 0
|
||||
@pattern_surf = 0
|
||||
@lock_pattern = false
|
||||
@move_route_forcing = false
|
||||
@through = false
|
||||
@animation_id = 0
|
||||
@transparent = false
|
||||
@original_direction = 2
|
||||
@original_pattern = 0
|
||||
@move_type = 0
|
||||
self.move_speed = 3
|
||||
self.move_frequency = 6
|
||||
@move_route = nil
|
||||
@move_route_index = 0
|
||||
@original_move_route = nil
|
||||
@original_move_route_index = 0
|
||||
@walk_anime = true # Whether character should animate while moving
|
||||
@step_anime = false # Whether character should animate while still
|
||||
@direction_fix = false
|
||||
@always_on_top = false
|
||||
@anime_count = 0
|
||||
@stop_count = 0
|
||||
@jump_peak = 0 # Max height while jumping
|
||||
@jump_distance = 0 # Total distance of jump
|
||||
@jump_distance_left = 0 # Distance left to travel
|
||||
@jump_count = 0 # Frames left in a stationary jump
|
||||
@bob_height = 0
|
||||
@wait_count = 0
|
||||
@moved_this_frame = false
|
||||
@locked = false
|
||||
@prelock_direction = 0
|
||||
end
|
||||
|
||||
def at_coordinate?(check_x, check_y)
|
||||
return check_x >= @x && check_x < @x + @width &&
|
||||
check_y > @y - @height && check_y <= @y
|
||||
end
|
||||
|
||||
def in_line_with_coordinate?(check_x, check_y)
|
||||
return (check_x >= @x && check_x < @x + @width) ||
|
||||
(check_y > @y - @height && check_y <= @y)
|
||||
end
|
||||
|
||||
def each_occupied_tile
|
||||
for i in @x...(@x + @width)
|
||||
for j in (@y - @height + 1)..@y
|
||||
yield i, j
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def move_speed=(val)
|
||||
return if val==@move_speed
|
||||
@move_speed = val
|
||||
# @move_speed_real is the number of quarter-pixels to move each frame. There
|
||||
# are 128 quarter-pixels per tile. By default, it is calculated from
|
||||
# @move_speed and has these values (assuming 40 fps):
|
||||
# 1 => 3.2 # 40 frames per tile
|
||||
# 2 => 6.4 # 20 frames per tile
|
||||
# 3 => 12.8 # 10 frames per tile - walking speed
|
||||
# 4 => 25.6 # 5 frames per tile - running speed (2x walking speed)
|
||||
# 5 => 32 # 4 frames per tile - cycling speed (1.25x running speed)
|
||||
# 6 => 64 # 2 frames per tile
|
||||
self.move_speed_real = (val == 6) ? 64 : (val == 5) ? 32 : (2 ** (val + 1)) * 0.8
|
||||
end
|
||||
|
||||
def move_speed_real
|
||||
self.move_speed = @move_speed if !@move_speed_real
|
||||
return @move_speed_real
|
||||
end
|
||||
|
||||
def move_speed_real=(val)
|
||||
@move_speed_real = val * 40.0 / Graphics.frame_rate
|
||||
end
|
||||
|
||||
def jump_speed_real
|
||||
self.jump_speed_real = (2 ** (3 + 1)) * 0.8 if !@jump_speed_real # 3 is walking speed
|
||||
return @jump_speed_real
|
||||
end
|
||||
|
||||
def jump_speed_real=(val)
|
||||
@jump_speed_real = val * 40.0 / Graphics.frame_rate
|
||||
end
|
||||
|
||||
def move_frequency=(val)
|
||||
return if val==@move_frequency
|
||||
@move_frequency = val
|
||||
# @move_frequency_real is the number of frames to wait between each action
|
||||
# in a move route (not forced). Specifically, this is the number of frames
|
||||
# to wait after the character stops moving because of the previous action.
|
||||
# By default, it is calculated from @move_frequency and has these values
|
||||
# (assuming 40 fps):
|
||||
# 1 => 190 # 4.75 seconds
|
||||
# 2 => 144 # 3.6 seconds
|
||||
# 3 => 102 # 2.55 seconds
|
||||
# 4 => 64 # 1.6 seconds
|
||||
# 5 => 30 # 0.75 seconds
|
||||
# 6 => 0 # 0 seconds, i.e. continuous movement
|
||||
self.move_frequency_real = (40 - val * 2) * (6 - val)
|
||||
end
|
||||
|
||||
def move_frequency_real
|
||||
self.move_frequency = @move_frequency if !@move_frequency_real
|
||||
return @move_frequency_real
|
||||
end
|
||||
|
||||
def move_frequency_real=(val)
|
||||
@move_frequency_real = val * Graphics.frame_rate / 40.0
|
||||
end
|
||||
|
||||
def bob_height
|
||||
@bob_height = 0 if !@bob_height
|
||||
return @bob_height
|
||||
end
|
||||
|
||||
def lock
|
||||
return if @locked
|
||||
@prelock_direction = 0 # Was @direction but disabled
|
||||
turn_toward_player
|
||||
@locked = true
|
||||
end
|
||||
|
||||
def minilock
|
||||
@prelock_direction = 0 # Was @direction but disabled
|
||||
@locked = true
|
||||
end
|
||||
|
||||
def lock?
|
||||
return @locked
|
||||
end
|
||||
|
||||
def unlock
|
||||
return unless @locked
|
||||
@locked = false
|
||||
@direction = @prelock_direction if !@direction_fix && @prelock_direction != 0
|
||||
end
|
||||
|
||||
#=============================================================================
|
||||
# Information from map data
|
||||
#=============================================================================
|
||||
def map
|
||||
return (@map) ? @map : $game_map
|
||||
end
|
||||
|
||||
def terrain_tag
|
||||
return self.map.terrain_tag(@x, @y)
|
||||
end
|
||||
|
||||
def bush_depth
|
||||
return @bush_depth || 0
|
||||
end
|
||||
|
||||
def calculate_bush_depth
|
||||
if @tile_id > 0 || @always_on_top || jumping?
|
||||
@bush_depth = 0
|
||||
else
|
||||
deep_bush = regular_bush = false
|
||||
xbehind = @x + (@direction == 4 ? 1 : @direction == 6 ? -1 : 0)
|
||||
ybehind = @y + (@direction == 8 ? 1 : @direction == 2 ? -1 : 0)
|
||||
this_map = (self.map.valid?(@x, @y)) ? [self.map, @x, @y] : $MapFactory.getNewMap(@x, @y)
|
||||
if this_map[0].deepBush?(this_map[1], this_map[2]) && self.map.deepBush?(xbehind, ybehind)
|
||||
@bush_depth = Game_Map::TILE_HEIGHT
|
||||
elsif !moving? && this_map[0].bush?(this_map[1], this_map[2])
|
||||
@bush_depth = 12
|
||||
else
|
||||
@bush_depth = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#=============================================================================
|
||||
# Passability
|
||||
#=============================================================================
|
||||
def passable?(x, y, d, strict = false)
|
||||
new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
|
||||
new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
|
||||
return false unless self.map.valid?(new_x, new_y)
|
||||
return true if @through
|
||||
if strict
|
||||
return false unless self.map.passableStrict?(x, y, d, self)
|
||||
return false unless self.map.passableStrict?(new_x, new_y, 10 - d, self)
|
||||
else
|
||||
return false unless self.map.passable?(x, y, d, self)
|
||||
return false unless self.map.passable?(new_x, new_y, 10 - d, self)
|
||||
end
|
||||
for event in self.map.events.values
|
||||
next if self == event || !event.at_coordinate?(new_x, new_y) || event.through
|
||||
return false if self != $game_player || event.character_name != ""
|
||||
end
|
||||
if $game_player.x == new_x && $game_player.y == new_y
|
||||
return false if !$game_player.through && @character_name != ""
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
def can_move_from_coordinate?(start_x, start_y, dir, strict = false)
|
||||
case dir
|
||||
when 2, 8 # Down, up
|
||||
y_diff = (dir == 8) ? @height - 1 : 0
|
||||
for i in start_x...(start_x + @width)
|
||||
return false if !passable?(i, start_y - y_diff, dir, strict)
|
||||
end
|
||||
return true
|
||||
when 4, 6 # Left, right
|
||||
x_diff = (dir == 6) ? @width - 1 : 0
|
||||
for i in (start_y - @height + 1)..start_y
|
||||
return false if !passable?(start_x + x_diff, i, dir, strict)
|
||||
end
|
||||
return true
|
||||
when 1, 3 # Down diagonals
|
||||
# Treated as moving down first and then horizontally, because that
|
||||
# describes which tiles the character's feet touch
|
||||
for i in start_x...(start_x + @width)
|
||||
return false if !passable?(i, start_y, 2, strict)
|
||||
end
|
||||
x_diff = (dir == 3) ? @width - 1 : 0
|
||||
for i in (start_y - @height + 1)..start_y
|
||||
return false if !passable?(start_x + x_diff, i + 1, dir + 3, strict)
|
||||
end
|
||||
return true
|
||||
when 7, 9 # Up diagonals
|
||||
# Treated as moving horizontally first and then up, because that describes
|
||||
# which tiles the character's feet touch
|
||||
x_diff = (dir == 9) ? @width - 1 : 0
|
||||
for i in (start_y - @height + 1)..start_y
|
||||
return false if !passable?(start_x + x_diff, i, dir - 3, strict)
|
||||
end
|
||||
x_offset = (dir == 9) ? 1 : -1
|
||||
for i in start_x...(start_x + @width)
|
||||
return false if !passable?(i + x_offset, start_y - @height + 1, 8, strict)
|
||||
end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def can_move_in_direction?(dir, strict = false)
|
||||
return can_move_from_coordinate?(@x, @y, dir, strict)
|
||||
end
|
||||
|
||||
#=============================================================================
|
||||
# Screen position of the character
|
||||
#=============================================================================
|
||||
def screen_x
|
||||
ret = ((@real_x - self.map.display_x) / Game_Map::X_SUBPIXELS).round
|
||||
ret += @width * Game_Map::TILE_WIDTH / 2
|
||||
return ret
|
||||
end
|
||||
|
||||
def screen_y_ground
|
||||
ret = ((@real_y - self.map.display_y) / Game_Map::Y_SUBPIXELS).round
|
||||
ret += Game_Map::TILE_HEIGHT
|
||||
return ret
|
||||
end
|
||||
|
||||
def screen_y
|
||||
ret = screen_y_ground
|
||||
if jumping?
|
||||
if @jump_count > 0
|
||||
jump_fraction = ((@jump_count * jump_speed_real / Game_Map::REAL_RES_X) - 0.5).abs # 0.5 to 0 to 0.5
|
||||
else
|
||||
jump_fraction = ((@jump_distance_left / @jump_distance) - 0.5).abs # 0.5 to 0 to 0.5
|
||||
end
|
||||
ret += @jump_peak * (4 * jump_fraction**2 - 1)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def screen_z(height = 0)
|
||||
return 999 if @always_on_top
|
||||
z = screen_y_ground
|
||||
if @tile_id > 0
|
||||
begin
|
||||
return z + self.map.priorities[@tile_id] * 32
|
||||
rescue
|
||||
raise "Event's graphic is an out-of-range tile (event #{@id}, map #{self.map.map_id})"
|
||||
end
|
||||
end
|
||||
# Add z if height exceeds 32
|
||||
return z + ((height > Game_Map::TILE_HEIGHT) ? Game_Map::TILE_HEIGHT - 1 : 0)
|
||||
end
|
||||
|
||||
#=============================================================================
|
||||
# Movement
|
||||
#=============================================================================
|
||||
def moving?
|
||||
return @real_x != @x * Game_Map::REAL_RES_X ||
|
||||
@real_y != @y * Game_Map::REAL_RES_Y
|
||||
end
|
||||
|
||||
def jumping?
|
||||
return (@jump_distance_left || 0) > 0 || @jump_count > 0
|
||||
end
|
||||
|
||||
def straighten
|
||||
@pattern = 0 if @walk_anime || @step_anime
|
||||
@anime_count = 0
|
||||
@prelock_direction = 0
|
||||
end
|
||||
|
||||
def force_move_route(move_route)
|
||||
if @original_move_route == nil
|
||||
@original_move_route = @move_route
|
||||
@original_move_route_index = @move_route_index
|
||||
end
|
||||
@move_route = move_route
|
||||
@move_route_index = 0
|
||||
@move_route_forcing = true
|
||||
@prelock_direction = 0
|
||||
@wait_count = 0
|
||||
move_type_custom
|
||||
end
|
||||
|
||||
def moveto(x, y)
|
||||
@x = x % self.map.width
|
||||
@y = y % self.map.height
|
||||
@real_x = @x * Game_Map::REAL_RES_X
|
||||
@real_y = @y * Game_Map::REAL_RES_Y
|
||||
@prelock_direction = 0
|
||||
calculate_bush_depth
|
||||
triggerLeaveTile
|
||||
end
|
||||
|
||||
def triggerLeaveTile
|
||||
if @oldX && @oldY && @oldMap &&
|
||||
(@oldX!=self.x || @oldY!=self.y || @oldMap!=self.map.map_id)
|
||||
Events.onLeaveTile.trigger(self,self,@oldMap,@oldX,@oldY)
|
||||
end
|
||||
@oldX = self.x
|
||||
@oldY = self.y
|
||||
@oldMap = self.map.map_id
|
||||
end
|
||||
|
||||
def increase_steps
|
||||
@stop_count = 0
|
||||
triggerLeaveTile
|
||||
end
|
||||
|
||||
#=============================================================================
|
||||
# Movement commands
|
||||
#=============================================================================
|
||||
def move_type_random
|
||||
case rand(6)
|
||||
when 0..3 then move_random
|
||||
when 4 then move_forward
|
||||
when 5 then @stop_count = 0
|
||||
end
|
||||
end
|
||||
|
||||
def move_type_toward_player
|
||||
sx = @x + @width / 2.0 - ($game_player.x + $game_player.width / 2.0)
|
||||
sy = @y - @height / 2.0 - ($game_player.y - $game_player.height / 2.0)
|
||||
if sx.abs + sy.abs >= 20
|
||||
move_random
|
||||
return
|
||||
end
|
||||
case rand(6)
|
||||
when 0..3 then move_toward_player
|
||||
when 4 then move_random
|
||||
when 5 then move_forward
|
||||
end
|
||||
end
|
||||
|
||||
def move_type_custom
|
||||
return if jumping? || moving?
|
||||
while @move_route_index < @move_route.list.size
|
||||
command = @move_route.list[@move_route_index]
|
||||
if command.code == 0
|
||||
if @move_route.repeat
|
||||
@move_route_index = 0
|
||||
else
|
||||
if @move_route_forcing
|
||||
@move_route_forcing = false
|
||||
@move_route = @original_move_route
|
||||
@move_route_index = @original_move_route_index
|
||||
@original_move_route = nil
|
||||
end
|
||||
@stop_count = 0
|
||||
end
|
||||
return
|
||||
end
|
||||
if command.code <= 14
|
||||
case command.code
|
||||
when 1 then move_down
|
||||
when 2 then move_left
|
||||
when 3 then move_right
|
||||
when 4 then move_up
|
||||
when 5 then move_lower_left
|
||||
when 6 then move_lower_right
|
||||
when 7 then move_upper_left
|
||||
when 8 then move_upper_right
|
||||
when 9 then move_random
|
||||
when 10 then move_toward_player
|
||||
when 11 then move_away_from_player
|
||||
when 12 then move_forward
|
||||
when 13 then move_backward
|
||||
when 14 then jump(command.parameters[0], command.parameters[1])
|
||||
end
|
||||
@move_route_index += 1 if @move_route.skippable || moving? || jumping?
|
||||
return
|
||||
end
|
||||
if command.code == 15 # Wait
|
||||
@wait_count = (command.parameters[0] * Graphics.frame_rate / 20) - 1
|
||||
@move_route_index += 1
|
||||
return
|
||||
end
|
||||
if command.code >= 16 && command.code <= 26
|
||||
case command.code
|
||||
when 16 then turn_down
|
||||
when 17 then turn_left
|
||||
when 18 then turn_right
|
||||
when 19 then turn_up
|
||||
when 20 then turn_right_90
|
||||
when 21 then turn_left_90
|
||||
when 22 then turn_180
|
||||
when 23 then turn_right_or_left_90
|
||||
when 24 then turn_random
|
||||
when 25 then turn_toward_player
|
||||
when 26 then turn_away_from_player
|
||||
end
|
||||
@move_route_index += 1
|
||||
return
|
||||
end
|
||||
if command.code >= 27
|
||||
case command.code
|
||||
when 27
|
||||
$game_switches[command.parameters[0]] = true
|
||||
self.map.need_refresh = true
|
||||
when 28
|
||||
$game_switches[command.parameters[0]] = false
|
||||
self.map.need_refresh = true
|
||||
when 29 then self.move_speed = command.parameters[0]
|
||||
when 30 then self.move_frequency = command.parameters[0]
|
||||
when 31 then @walk_anime = true
|
||||
when 32 then @walk_anime = false
|
||||
when 33 then @step_anime = true
|
||||
when 34 then @step_anime = false
|
||||
when 35 then @direction_fix = true
|
||||
when 36 then @direction_fix = false
|
||||
when 37 then @through = true
|
||||
when 38 then @through = false
|
||||
when 39
|
||||
old_always_on_top = @always_on_top
|
||||
@always_on_top = true
|
||||
calculate_bush_depth if @always_on_top != old_always_on_top
|
||||
when 40
|
||||
old_always_on_top = @always_on_top
|
||||
@always_on_top = false
|
||||
calculate_bush_depth if @always_on_top != old_always_on_top
|
||||
when 41
|
||||
old_tile_id = @tile_id
|
||||
@tile_id = 0
|
||||
@character_name = command.parameters[0]
|
||||
@character_hue = command.parameters[1]
|
||||
if @original_direction != command.parameters[2]
|
||||
@direction = command.parameters[2]
|
||||
@original_direction = @direction
|
||||
@prelock_direction = 0
|
||||
end
|
||||
if @original_pattern != command.parameters[3]
|
||||
@pattern = command.parameters[3]
|
||||
@original_pattern = @pattern
|
||||
end
|
||||
calculate_bush_depth if @tile_id != old_tile_id
|
||||
when 42 then @opacity = command.parameters[0]
|
||||
when 43 then @blend_type = command.parameters[0]
|
||||
when 44 then pbSEPlay(command.parameters[0])
|
||||
when 45 then eval(command.parameters[0])
|
||||
end
|
||||
@move_route_index += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def move_generic(dir, turn_enabled = true)
|
||||
turn_generic(dir) if turn_enabled
|
||||
if can_move_in_direction?(dir)
|
||||
turn_generic(dir)
|
||||
@x += (dir == 4) ? -1 : (dir == 6) ? 1 : 0
|
||||
@y += (dir == 8) ? -1 : (dir == 2) ? 1 : 0
|
||||
increase_steps
|
||||
else
|
||||
check_event_trigger_touch(dir)
|
||||
end
|
||||
end
|
||||
|
||||
def move_down(turn_enabled = true)
|
||||
move_generic(2, turn_enabled)
|
||||
end
|
||||
|
||||
def move_left(turn_enabled = true)
|
||||
move_generic(4, turn_enabled)
|
||||
end
|
||||
|
||||
def move_right(turn_enabled = true)
|
||||
move_generic(6, turn_enabled)
|
||||
end
|
||||
|
||||
def move_up(turn_enabled = true)
|
||||
move_generic(8, turn_enabled)
|
||||
end
|
||||
|
||||
def move_upper_left
|
||||
unless @direction_fix
|
||||
@direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
|
||||
end
|
||||
if can_move_in_direction?(7)
|
||||
@x -= 1
|
||||
@y -= 1
|
||||
increase_steps
|
||||
end
|
||||
end
|
||||
|
||||
def move_upper_right
|
||||
unless @direction_fix
|
||||
@direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
|
||||
end
|
||||
if can_move_in_direction?(9)
|
||||
@x += 1
|
||||
@y -= 1
|
||||
increase_steps
|
||||
end
|
||||
end
|
||||
|
||||
def move_lower_left
|
||||
unless @direction_fix
|
||||
@direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
|
||||
end
|
||||
if can_move_in_direction?(1)
|
||||
@x -= 1
|
||||
@y += 1
|
||||
increase_steps
|
||||
end
|
||||
end
|
||||
|
||||
def move_lower_right
|
||||
unless @direction_fix
|
||||
@direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
|
||||
end
|
||||
if can_move_in_direction?(3)
|
||||
@x += 1
|
||||
@y += 1
|
||||
increase_steps
|
||||
end
|
||||
end
|
||||
|
||||
def moveLeft90 # anticlockwise
|
||||
case self.direction
|
||||
when 2 then move_right # down
|
||||
when 4 then move_down # left
|
||||
when 6 then move_up # right
|
||||
when 8 then move_left # up
|
||||
end
|
||||
end
|
||||
|
||||
def moveRight90 # clockwise
|
||||
case self.direction
|
||||
when 2 then move_left # down
|
||||
when 4 then move_up # left
|
||||
when 6 then move_down # right
|
||||
when 8 then move_right # up
|
||||
end
|
||||
end
|
||||
|
||||
def move_random
|
||||
case rand(4)
|
||||
when 0 then move_down(false)
|
||||
when 1 then move_left(false)
|
||||
when 2 then move_right(false)
|
||||
when 3 then move_up(false)
|
||||
end
|
||||
end
|
||||
|
||||
def move_random_range(xrange=-1,yrange=-1)
|
||||
dirs = [] # 0=down, 1=left, 2=right, 3=up
|
||||
if xrange<0
|
||||
dirs.push(1); dirs.push(2)
|
||||
elsif xrange>0
|
||||
dirs.push(1) if @x > @original_x - xrange
|
||||
dirs.push(2) if @x < @original_x + xrange
|
||||
end
|
||||
if yrange<0
|
||||
dirs.push(0); dirs.push(3)
|
||||
elsif yrange>0
|
||||
dirs.push(0) if @y < @original_y + yrange
|
||||
dirs.push(3) if @y > @original_y - yrange
|
||||
end
|
||||
return if dirs.length==0
|
||||
case dirs[rand(dirs.length)]
|
||||
when 0 then move_down(false)
|
||||
when 1 then move_left(false)
|
||||
when 2 then move_right(false)
|
||||
when 3 then move_up(false)
|
||||
end
|
||||
end
|
||||
|
||||
def move_random_UD(range=-1)
|
||||
move_random_range(0,range)
|
||||
end
|
||||
|
||||
def move_random_LR(range=-1)
|
||||
move_random_range(range,0)
|
||||
end
|
||||
|
||||
def move_toward_player
|
||||
sx = @x + @width / 2.0 - ($game_player.x + $game_player.width / 2.0)
|
||||
sy = @y - @height / 2.0 - ($game_player.y - $game_player.height / 2.0)
|
||||
return if sx == 0 && sy == 0
|
||||
abs_sx = sx.abs
|
||||
abs_sy = sy.abs
|
||||
if abs_sx == abs_sy
|
||||
(rand(2) == 0) ? abs_sx += 1 : abs_sy += 1
|
||||
end
|
||||
if abs_sx > abs_sy
|
||||
(sx > 0) ? move_left : move_right
|
||||
if !moving? && sy != 0
|
||||
(sy > 0) ? move_up : move_down
|
||||
end
|
||||
else
|
||||
(sy > 0) ? move_up : move_down
|
||||
if !moving? && sx != 0
|
||||
(sx > 0) ? move_left : move_right
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def move_away_from_player
|
||||
sx = @x + @width / 2.0 - ($game_player.x + $game_player.width / 2.0)
|
||||
sy = @y - @height / 2.0 - ($game_player.y - $game_player.height / 2.0)
|
||||
return if sx == 0 && sy == 0
|
||||
abs_sx = sx.abs
|
||||
abs_sy = sy.abs
|
||||
if abs_sx == abs_sy
|
||||
(rand(2) == 0) ? abs_sx += 1 : abs_sy += 1
|
||||
end
|
||||
if abs_sx > abs_sy
|
||||
(sx > 0) ? move_right : move_left
|
||||
if !moving? && sy != 0
|
||||
(sy > 0) ? move_down : move_up
|
||||
end
|
||||
else
|
||||
(sy > 0) ? move_down : move_up
|
||||
if !moving? && sx != 0
|
||||
(sx > 0) ? move_right : move_left
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def move_forward
|
||||
case @direction
|
||||
when 2 then move_down(false)
|
||||
when 4 then move_left(false)
|
||||
when 6 then move_right(false)
|
||||
when 8 then move_up(false)
|
||||
end
|
||||
end
|
||||
|
||||
def move_backward
|
||||
last_direction_fix = @direction_fix
|
||||
@direction_fix = true
|
||||
case @direction
|
||||
when 2 then move_up(false)
|
||||
when 4 then move_right(false)
|
||||
when 6 then move_left(false)
|
||||
when 8 then move_down(false)
|
||||
end
|
||||
@direction_fix = last_direction_fix
|
||||
end
|
||||
|
||||
def jump(x_plus, y_plus)
|
||||
if x_plus != 0 || y_plus != 0
|
||||
if x_plus.abs > y_plus.abs
|
||||
(x_plus < 0) ? turn_left : turn_right
|
||||
else
|
||||
(y_plus < 0) ? turn_up : turn_down
|
||||
end
|
||||
each_occupied_tile { |i, j| return if !passable?(i + x_plus, j + y_plus, 0) }
|
||||
end
|
||||
@x = @x + x_plus
|
||||
@y = @y + y_plus
|
||||
real_distance = Math::sqrt(x_plus * x_plus + y_plus * y_plus)
|
||||
distance = [1, real_distance].max
|
||||
@jump_peak = distance * Game_Map::TILE_HEIGHT * 3 / 8 # 3/4 of tile for ledge jumping
|
||||
@jump_distance = [x_plus.abs * Game_Map::REAL_RES_X, y_plus.abs * Game_Map::REAL_RES_Y].max
|
||||
@jump_distance_left = 1 # Just needs to be non-zero
|
||||
if real_distance > 0 # Jumping to somewhere else
|
||||
@jump_count = 0
|
||||
else # Jumping on the spot
|
||||
@jump_speed_real = nil # Reset jump speed
|
||||
@jump_count = Game_Map::REAL_RES_X / jump_speed_real # Number of frames to jump one tile
|
||||
end
|
||||
@stop_count = 0
|
||||
if self.is_a?(Game_Player)
|
||||
$PokemonTemp.dependentEvents.pbMoveDependentEvents
|
||||
end
|
||||
triggerLeaveTile
|
||||
end
|
||||
|
||||
def jumpForward
|
||||
case self.direction
|
||||
when 2 then jump(0,1) # down
|
||||
when 4 then jump(-1,0) # left
|
||||
when 6 then jump(1,0) # right
|
||||
when 8 then jump(0,-1) # up
|
||||
end
|
||||
end
|
||||
|
||||
def jumpBackward
|
||||
case self.direction
|
||||
when 2 then jump(0,-1) # down
|
||||
when 4 then jump(1,0) # left
|
||||
when 6 then jump(-1,0) # right
|
||||
when 8 then jump(0,1) # up
|
||||
end
|
||||
end
|
||||
|
||||
def turn_generic(dir)
|
||||
return if @direction_fix
|
||||
oldDirection = @direction
|
||||
@direction = dir
|
||||
@stop_count = 0
|
||||
pbCheckEventTriggerAfterTurning if dir != oldDirection
|
||||
end
|
||||
|
||||
def turn_down; turn_generic(2); end
|
||||
def turn_left; turn_generic(4); end
|
||||
def turn_right; turn_generic(6); end
|
||||
def turn_up; turn_generic(8); end
|
||||
|
||||
def turn_right_90
|
||||
case @direction
|
||||
when 2 then turn_left
|
||||
when 4 then turn_up
|
||||
when 6 then turn_down
|
||||
when 8 then turn_right
|
||||
end
|
||||
end
|
||||
|
||||
def turn_left_90
|
||||
case @direction
|
||||
when 2 then turn_right
|
||||
when 4 then turn_down
|
||||
when 6 then turn_up
|
||||
when 8 then turn_left
|
||||
end
|
||||
end
|
||||
|
||||
def turn_180
|
||||
case @direction
|
||||
when 2 then turn_up
|
||||
when 4 then turn_right
|
||||
when 6 then turn_left
|
||||
when 8 then turn_down
|
||||
end
|
||||
end
|
||||
|
||||
def turn_right_or_left_90
|
||||
(rand(2) == 0) ? turn_right_90 : turn_left_90
|
||||
end
|
||||
|
||||
def turn_random
|
||||
case rand(4)
|
||||
when 0 then turn_up
|
||||
when 1 then turn_right
|
||||
when 2 then turn_left
|
||||
when 3 then turn_down
|
||||
end
|
||||
end
|
||||
|
||||
def turn_toward_player
|
||||
sx = @x + @width / 2.0 - ($game_player.x + $game_player.width / 2.0)
|
||||
sy = @y - @height / 2.0 - ($game_player.y - $game_player.height / 2.0)
|
||||
return if sx == 0 && sy == 0
|
||||
if sx.abs > sy.abs
|
||||
(sx > 0) ? turn_left : turn_right
|
||||
else
|
||||
(sy > 0) ? turn_up : turn_down
|
||||
end
|
||||
end
|
||||
|
||||
def turn_away_from_player
|
||||
sx = @x + @width / 2.0 - ($game_player.x + $game_player.width / 2.0)
|
||||
sy = @y - @height / 2.0 - ($game_player.y - $game_player.height / 2.0)
|
||||
return if sx == 0 && sy == 0
|
||||
if sx.abs > sy.abs
|
||||
(sx > 0) ? turn_right : turn_left
|
||||
else
|
||||
(sy > 0) ? turn_down : turn_up
|
||||
end
|
||||
end
|
||||
|
||||
#=============================================================================
|
||||
# Updating
|
||||
#=============================================================================
|
||||
def update
|
||||
@moved_last_frame = @moved_this_frame
|
||||
@stopped_last_frame = @stopped_this_frame
|
||||
if !$game_temp.in_menu
|
||||
# Update command
|
||||
update_command
|
||||
# Update movement
|
||||
(moving? || jumping?) ? update_move : update_stop
|
||||
end
|
||||
# Update animation
|
||||
update_pattern
|
||||
end
|
||||
|
||||
def update_command
|
||||
if @wait_count > 0
|
||||
@wait_count -= 1
|
||||
elsif @move_route_forcing
|
||||
move_type_custom
|
||||
elsif !@starting && !lock? && !moving? && !jumping?
|
||||
update_command_new
|
||||
end
|
||||
end
|
||||
|
||||
def update_command_new
|
||||
# @stop_count is the number of frames since the last movement finished.
|
||||
# @move_frequency has these values:
|
||||
# 1 => @stop_count > 190 # 4.75 seconds
|
||||
# 2 => @stop_count > 144 # 3.6 seconds
|
||||
# 3 => @stop_count > 102 # 2.55 seconds
|
||||
# 4 => @stop_count > 64 # 1.6 seconds
|
||||
# 5 => @stop_count > 30 # 0.75 seconds
|
||||
# 6 => @stop_count > 0 # 0 seconds
|
||||
if @stop_count >= self.move_frequency_real
|
||||
case @move_type
|
||||
when 1 then move_type_random
|
||||
when 2 then move_type_toward_player
|
||||
when 3 then move_type_custom
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update_move
|
||||
# Move the character (the 0.1 catches rounding errors)
|
||||
distance = (jumping?) ? jump_speed_real : move_speed_real
|
||||
dest_x = @x * Game_Map::REAL_RES_X
|
||||
dest_y = @y * Game_Map::REAL_RES_Y
|
||||
if @real_x < dest_x
|
||||
@real_x += distance
|
||||
@real_x = dest_x if @real_x > dest_x - 0.1
|
||||
else
|
||||
@real_x -= distance
|
||||
@real_x = dest_x if @real_x < dest_x + 0.1
|
||||
end
|
||||
if @real_y < dest_y
|
||||
@real_y += distance
|
||||
@real_y = dest_y if @real_y > dest_y - 0.1
|
||||
else
|
||||
@real_y -= distance
|
||||
@real_y = dest_y if @real_y < dest_y + 0.1
|
||||
end
|
||||
# Refresh how far is left to travel in a jump
|
||||
if jumping?
|
||||
@jump_count -= 1 if @jump_count > 0 # For stationary jumps only
|
||||
@jump_distance_left = [(dest_x - @real_x).abs, (dest_y - @real_y).abs].max
|
||||
end
|
||||
# End of a step, so perform events that happen at this time
|
||||
if !jumping? && !moving?
|
||||
Events.onStepTakenFieldMovement.trigger(self, self)
|
||||
calculate_bush_depth
|
||||
@stopped_this_frame = true
|
||||
elsif !@moved_last_frame || @stopped_last_frame # Started a new step
|
||||
calculate_bush_depth
|
||||
@stopped_this_frame = false
|
||||
end
|
||||
# Increment animation counter
|
||||
@anime_count += 1 if @walk_anime || @step_anime
|
||||
@moved_this_frame = true
|
||||
end
|
||||
|
||||
def update_stop
|
||||
@anime_count += 1 if @step_anime
|
||||
@stop_count += 1 if !@starting && !lock?
|
||||
@moved_this_frame = false
|
||||
@stopped_this_frame = false
|
||||
end
|
||||
|
||||
def update_pattern
|
||||
return if @lock_pattern
|
||||
# return if @jump_count > 0 # Don't animate if jumping on the spot
|
||||
# Character has stopped moving, return to original pattern
|
||||
if @moved_last_frame && !@moved_this_frame && !@step_anime
|
||||
@pattern = @original_pattern
|
||||
@anime_count = 0
|
||||
return
|
||||
end
|
||||
# Character has started to move, change pattern immediately
|
||||
if !@moved_last_frame && @moved_this_frame && !@step_anime
|
||||
@pattern = (@pattern + 1) % 4 if @walk_anime
|
||||
@anime_count = 0
|
||||
return
|
||||
end
|
||||
# Calculate how many frames each pattern should display for, i.e. the time
|
||||
# it takes to move half a tile (or a whole tile if cycling). We assume the
|
||||
# game uses square tiles.
|
||||
real_speed = (jumping?) ? jump_speed_real : move_speed_real
|
||||
frames_per_pattern = Game_Map::REAL_RES_X / (real_speed * 2.0)
|
||||
frames_per_pattern *= 2 if move_speed >= 5 # Cycling speed or faster
|
||||
return if @anime_count < frames_per_pattern
|
||||
# Advance to the next animation frame
|
||||
@pattern = (@pattern + 1) % 4
|
||||
@anime_count -= frames_per_pattern
|
||||
end
|
||||
end
|
||||
278
Data/Scripts_backup/004_Game classes/008_Game_Event.rb
Normal file
278
Data/Scripts_backup/004_Game classes/008_Game_Event.rb
Normal file
@@ -0,0 +1,278 @@
|
||||
class Game_Event < Game_Character
|
||||
attr_reader :map_id
|
||||
attr_reader :trigger
|
||||
attr_reader :list
|
||||
attr_reader :starting
|
||||
attr_reader :tempSwitches # Temporary self-switches
|
||||
attr_accessor :need_refresh
|
||||
|
||||
def initialize(map_id, event, map=nil)
|
||||
super(map)
|
||||
@map_id = map_id
|
||||
@event = event
|
||||
@id = @event.id
|
||||
@original_x = @event.x
|
||||
@original_y = @event.y
|
||||
if @event.name[/size\((\d+),(\d+)\)/i]
|
||||
@width = $~[1].to_i
|
||||
@height = $~[2].to_i
|
||||
end
|
||||
@erased = false
|
||||
@starting = false
|
||||
@need_refresh = false
|
||||
@route_erased = false
|
||||
@through = true
|
||||
@to_update = true
|
||||
@tempSwitches = {}
|
||||
moveto(@event.x, @event.y) if map
|
||||
refresh
|
||||
end
|
||||
|
||||
def id; return @event.id; end
|
||||
def name; return @event.name; end
|
||||
|
||||
def set_starting
|
||||
@starting = true
|
||||
end
|
||||
|
||||
def clear_starting
|
||||
@starting = false
|
||||
end
|
||||
|
||||
def start
|
||||
@starting = true if @list.size > 1
|
||||
end
|
||||
|
||||
def erase
|
||||
@erased = true
|
||||
refresh
|
||||
end
|
||||
|
||||
def erase_route
|
||||
@route_erased = true
|
||||
refresh
|
||||
end
|
||||
|
||||
def tsOn?(c)
|
||||
return @tempSwitches && @tempSwitches[c]==true
|
||||
end
|
||||
|
||||
def tsOff?(c)
|
||||
return !@tempSwitches || !@tempSwitches[c]
|
||||
end
|
||||
|
||||
def setTempSwitchOn(c)
|
||||
@tempSwitches[c]=true
|
||||
refresh
|
||||
end
|
||||
|
||||
def setTempSwitchOff(c)
|
||||
@tempSwitches[c]=false
|
||||
refresh
|
||||
end
|
||||
|
||||
def isOff?(c)
|
||||
return !$game_self_switches[[@map_id,@event.id,c]]
|
||||
end
|
||||
|
||||
def switchIsOn?(id)
|
||||
switchname = $data_system.switches[id]
|
||||
return false if !switchname
|
||||
if switchname[/^s\:/]
|
||||
return eval($~.post_match)
|
||||
else
|
||||
return $game_switches[id]
|
||||
end
|
||||
end
|
||||
|
||||
def variable
|
||||
return nil if !$PokemonGlobal.eventvars
|
||||
return $PokemonGlobal.eventvars[[@map_id,@event.id]]
|
||||
end
|
||||
|
||||
def setVariable(variable)
|
||||
$PokemonGlobal.eventvars[[@map_id,@event.id]]=variable
|
||||
end
|
||||
|
||||
def varAsInt
|
||||
return 0 if !$PokemonGlobal.eventvars
|
||||
return $PokemonGlobal.eventvars[[@map_id,@event.id]].to_i
|
||||
end
|
||||
|
||||
def expired?(secs=86400)
|
||||
ontime=self.variable
|
||||
time=pbGetTimeNow
|
||||
return ontime && (time.to_i>ontime+secs)
|
||||
end
|
||||
|
||||
def expiredDays?(days=1)
|
||||
ontime=self.variable.to_i
|
||||
return false if !ontime
|
||||
now=pbGetTimeNow
|
||||
elapsed=(now.to_i-ontime)/86400
|
||||
elapsed+=1 if (now.to_i-ontime)%86400>(now.hour*3600+now.min*60+now.sec)
|
||||
return elapsed>=days
|
||||
end
|
||||
|
||||
def cooledDown?(seconds)
|
||||
return true if expired?(seconds) && tsOff?("A")
|
||||
self.need_refresh = true
|
||||
return false
|
||||
end
|
||||
|
||||
def cooledDownDays?(days)
|
||||
return true if expiredDays?(days) && tsOff?("A")
|
||||
self.need_refresh = true
|
||||
return false
|
||||
end
|
||||
|
||||
def onEvent?
|
||||
return @map_id == $game_map.map_id && at_coordinate?($game_player.x, $game_player.y)
|
||||
end
|
||||
|
||||
def over_trigger?
|
||||
return false if @character_name != "" && !@through
|
||||
return false if @event.name[/hiddenitem/i]
|
||||
each_occupied_tile do |i, j|
|
||||
return true if self.map.passable?(i, j, 0, $game_player)
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def pbCheckEventTriggerAfterTurning
|
||||
return if $game_system.map_interpreter.running? || @starting
|
||||
if @event.name[/trainer\((\d+)\)/i]
|
||||
distance = $~[1].to_i
|
||||
if @trigger==2 && pbEventCanReachPlayer?(self,$game_player,distance)
|
||||
start if !jumping? && !over_trigger?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def check_event_trigger_touch(dir)
|
||||
return if $game_system.map_interpreter.running?
|
||||
return if @trigger != 2 # Event touch
|
||||
case dir
|
||||
when 2
|
||||
return if $game_player.y != @y + 1
|
||||
when 4
|
||||
return if $game_player.x != @x - 1
|
||||
when 6
|
||||
return if $game_player.x != @x + @width
|
||||
when 8
|
||||
return if $game_player.y != @y - @height
|
||||
end
|
||||
return if !in_line_with_coordinate?($game_player.x, $game_player.y)
|
||||
return if jumping? || over_trigger?
|
||||
start
|
||||
end
|
||||
|
||||
def check_event_trigger_auto
|
||||
if @trigger == 2 # Event touch
|
||||
if at_coordinate?($game_player.x, $game_player.y)
|
||||
start if !jumping? && over_trigger?
|
||||
end
|
||||
elsif @trigger == 3 # Autorun
|
||||
start
|
||||
end
|
||||
end
|
||||
|
||||
def refresh
|
||||
new_page = nil
|
||||
unless @erased
|
||||
for page in @event.pages.reverse
|
||||
c = page.condition
|
||||
next if c.switch1_valid && !switchIsOn?(c.switch1_id)
|
||||
next if c.switch2_valid && !switchIsOn?(c.switch2_id)
|
||||
next if c.variable_valid && $game_variables[c.variable_id] < c.variable_value
|
||||
if c.self_switch_valid
|
||||
key = [@map_id, @event.id, c.self_switch_ch]
|
||||
next if $game_self_switches[key] != true
|
||||
end
|
||||
new_page = page
|
||||
break
|
||||
end
|
||||
end
|
||||
return if new_page == @page
|
||||
@page = new_page
|
||||
clear_starting
|
||||
if @page == nil
|
||||
@tile_id = 0
|
||||
@character_name = ""
|
||||
@character_hue = 0
|
||||
@move_type = 0
|
||||
@through = true
|
||||
@trigger = nil
|
||||
@list = nil
|
||||
@interpreter = nil
|
||||
return
|
||||
end
|
||||
@tile_id = @page.graphic.tile_id
|
||||
@character_name = @page.graphic.character_name
|
||||
@character_hue = @page.graphic.character_hue
|
||||
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
|
||||
@opacity = @page.graphic.opacity
|
||||
@blend_type = @page.graphic.blend_type
|
||||
@move_type = @page.move_type
|
||||
self.move_speed = @page.move_speed
|
||||
self.move_frequency = @page.move_frequency
|
||||
@move_route = (@route_erased) ? RPG::MoveRoute.new : @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
|
||||
@always_on_top = @page.always_on_top
|
||||
calculate_bush_depth
|
||||
@trigger = @page.trigger
|
||||
@list = @page.list
|
||||
@interpreter = nil
|
||||
if @trigger == 4 # Parallel Process
|
||||
@interpreter = Interpreter.new
|
||||
end
|
||||
check_event_trigger_auto
|
||||
end
|
||||
|
||||
def should_update?(recalc=false)
|
||||
return @to_update if !recalc
|
||||
return true if @trigger && (@trigger == 3 || @trigger == 4)
|
||||
return true if @move_route_forcing
|
||||
return true if @event.name[/update/i]
|
||||
range = 2 # Number of tiles
|
||||
return false if self.screen_x - @sprite_size[0]/2 > Graphics.width + range * Game_Map::TILE_WIDTH
|
||||
return false if self.screen_x + @sprite_size[0]/2 < -range * Game_Map::TILE_WIDTH
|
||||
return false if self.screen_y_ground - @sprite_size[1] > Graphics.height + range * Game_Map::TILE_HEIGHT
|
||||
return false if self.screen_y_ground < -range * Game_Map::TILE_HEIGHT
|
||||
return true
|
||||
end
|
||||
|
||||
def update
|
||||
@to_update = should_update?(true)
|
||||
return if !@to_update
|
||||
last_moving = moving?
|
||||
super
|
||||
if !moving? && last_moving
|
||||
$game_player.pbCheckEventTriggerFromDistance([2])
|
||||
end
|
||||
if @need_refresh
|
||||
@need_refresh = false
|
||||
refresh
|
||||
end
|
||||
check_event_trigger_auto
|
||||
if @interpreter != nil
|
||||
unless @interpreter.running?
|
||||
@interpreter.setup(@list, @event.id, @map_id)
|
||||
end
|
||||
@interpreter.update
|
||||
end
|
||||
end
|
||||
end
|
||||
442
Data/Scripts_backup/004_Game classes/009_Game_Player.rb
Normal file
442
Data/Scripts_backup/004_Game classes/009_Game_Player.rb
Normal file
@@ -0,0 +1,442 @@
|
||||
#===============================================================================
|
||||
# ** Game_Player
|
||||
#-------------------------------------------------------------------------------
|
||||
# This class handles the player. Its functions include event starting
|
||||
# determinants and map scrolling. Refer to "$game_player" for the one
|
||||
# instance of this class.
|
||||
#===============================================================================
|
||||
class Game_Player < Game_Character
|
||||
attr_accessor :bump_se
|
||||
attr_accessor :charsetData
|
||||
attr_accessor :encounter_count
|
||||
|
||||
SCREEN_CENTER_X = (Settings::SCREEN_WIDTH / 2 - Game_Map::TILE_WIDTH / 2) * Game_Map::X_SUBPIXELS
|
||||
SCREEN_CENTER_Y = (Settings::SCREEN_HEIGHT / 2 - Game_Map::TILE_HEIGHT / 2) * Game_Map::Y_SUBPIXELS
|
||||
|
||||
def initialize(*arg)
|
||||
super(*arg)
|
||||
@lastdir=0
|
||||
@lastdirframe=0
|
||||
@bump_se=0
|
||||
end
|
||||
|
||||
def map
|
||||
@map = nil
|
||||
return $game_map
|
||||
end
|
||||
|
||||
def pbHasDependentEvents?
|
||||
return $PokemonGlobal.dependentEvents.length>0
|
||||
end
|
||||
|
||||
def bump_into_object
|
||||
return if @bump_se && @bump_se>0
|
||||
pbSEPlay("Player bump")
|
||||
@bump_se = Graphics.frame_rate/4
|
||||
end
|
||||
|
||||
def move_generic(dir, turn_enabled = true)
|
||||
turn_generic(dir, true) if turn_enabled
|
||||
if !$PokemonTemp.encounterTriggered
|
||||
if can_move_in_direction?(dir)
|
||||
x_offset = (dir == 4) ? -1 : (dir == 6) ? 1 : 0
|
||||
y_offset = (dir == 8) ? -1 : (dir == 2) ? 1 : 0
|
||||
return if pbLedge(x_offset, y_offset)
|
||||
return if pbEndSurf(x_offset, y_offset)
|
||||
turn_generic(dir, true)
|
||||
if !$PokemonTemp.encounterTriggered
|
||||
@x += x_offset
|
||||
@y += y_offset
|
||||
$PokemonTemp.dependentEvents.pbMoveDependentEvents
|
||||
increase_steps
|
||||
end
|
||||
elsif !check_event_trigger_touch(dir)
|
||||
bump_into_object
|
||||
end
|
||||
end
|
||||
$PokemonTemp.encounterTriggered = false
|
||||
end
|
||||
|
||||
def turn_generic(dir, keep_enc_indicator = false)
|
||||
old_direction = @direction
|
||||
super(dir)
|
||||
if @direction != old_direction && !@move_route_forcing && !pbMapInterpreterRunning?
|
||||
Events.onChangeDirection.trigger(self, self)
|
||||
$PokemonTemp.encounterTriggered = false if !keep_enc_indicator
|
||||
end
|
||||
end
|
||||
|
||||
def pbTriggeredTrainerEvents(triggers,checkIfRunning=true)
|
||||
result = []
|
||||
# If event is running
|
||||
return result if checkIfRunning && $game_system.map_interpreter.running?
|
||||
# All event loops
|
||||
for event in $game_map.events.values
|
||||
next if !event.name[/trainer\((\d+)\)/i]
|
||||
distance = $~[1].to_i
|
||||
# If event coordinates and triggers are consistent
|
||||
if pbEventCanReachPlayer?(event,self,distance) && triggers.include?(event.trigger)
|
||||
# If starting determinant is front event (other than jumping)
|
||||
result.push(event) if !event.jumping? && !event.over_trigger?
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
def pbTriggeredCounterEvents(triggers,checkIfRunning=true)
|
||||
result = []
|
||||
# If event is running
|
||||
return result if checkIfRunning && $game_system.map_interpreter.running?
|
||||
# All event loops
|
||||
for event in $game_map.events.values
|
||||
next if !event.name[/counter\((\d+)\)/i]
|
||||
distance = $~[1].to_i
|
||||
# If event coordinates and triggers are consistent
|
||||
if pbEventFacesPlayer?(event,self,distance) && triggers.include?(event.trigger)
|
||||
# If starting determinant is front event (other than jumping)
|
||||
result.push(event) if !event.jumping? && !event.over_trigger?
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
def pbCheckEventTriggerAfterTurning; end
|
||||
|
||||
def pbCheckEventTriggerFromDistance(triggers)
|
||||
ret = pbTriggeredTrainerEvents(triggers)
|
||||
ret.concat(pbTriggeredCounterEvents(triggers))
|
||||
return false if ret.length==0
|
||||
for event in ret
|
||||
event.start
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
def pbTerrainTag(countBridge = false)
|
||||
return $MapFactory.getTerrainTag(self.map.map_id, @x, @y, countBridge) if $MapFactory
|
||||
return $game_map.terrain_tag(@x, @y, countBridge)
|
||||
end
|
||||
|
||||
def pbFacingEvent(ignoreInterpreter=false)
|
||||
return nil if $game_system.map_interpreter.running? && !ignoreInterpreter
|
||||
# Check the tile in front of the player for events
|
||||
new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
|
||||
new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
|
||||
return nil if !$game_map.valid?(new_x, new_y)
|
||||
for event in $game_map.events.values
|
||||
next if !event.at_coordinate?(new_x, new_y)
|
||||
next if event.jumping? || event.over_trigger?
|
||||
return event
|
||||
end
|
||||
# If the tile in front is a counter, check one tile beyond that for events
|
||||
if $game_map.counter?(new_x, new_y)
|
||||
new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
|
||||
new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
|
||||
for event in $game_map.events.values
|
||||
next if !event.at_coordinate?(new_x, new_y)
|
||||
next if event.jumping? || event.over_trigger?
|
||||
return event
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
def pbFacingTerrainTag(dir = nil)
|
||||
dir = self.direction if !dir
|
||||
return $MapFactory.getFacingTerrainTag(dir, self) if $MapFactory
|
||||
facing = pbFacingTile(dir, self)
|
||||
return $game_map.terrain_tag(facing[1], facing[2])
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Passable Determinants
|
||||
# x : x-coordinate
|
||||
# y : y-coordinate
|
||||
# d : direction (0,2,4,6,8)
|
||||
# * 0 = Determines if all directions are impassable (for jumping)
|
||||
#-----------------------------------------------------------------------------
|
||||
def passable?(x, y, d, strict = false)
|
||||
# Get new coordinates
|
||||
new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
|
||||
new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
|
||||
# If coordinates are outside of map
|
||||
return false if !$game_map.validLax?(new_x, new_y)
|
||||
if !$game_map.valid?(new_x, new_y)
|
||||
return false if !$MapFactory
|
||||
return $MapFactory.isPassableFromEdge?(new_x, new_y)
|
||||
end
|
||||
# If debug mode is ON and Ctrl key was pressed
|
||||
return true if $DEBUG && Input.press?(Input::CTRL)
|
||||
return super
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Set Map Display Position to Center of Screen
|
||||
#-----------------------------------------------------------------------------
|
||||
def center(x, y)
|
||||
self.map.display_x = x * Game_Map::REAL_RES_X - SCREEN_CENTER_X
|
||||
self.map.display_y = y * Game_Map::REAL_RES_Y - SCREEN_CENTER_Y
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Move to Designated Position
|
||||
# x : x-coordinate
|
||||
# y : y-coordinate
|
||||
#-----------------------------------------------------------------------------
|
||||
def moveto(x, y)
|
||||
super
|
||||
# Centering
|
||||
center(x, y)
|
||||
# Make encounter count
|
||||
make_encounter_count
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Make Encounter Count
|
||||
#-----------------------------------------------------------------------------
|
||||
def make_encounter_count
|
||||
# Image of two dice rolling
|
||||
if $game_map.map_id != 0
|
||||
n = $game_map.encounter_step
|
||||
@encounter_count = rand(n) + rand(n) + 1
|
||||
end
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Refresh
|
||||
#-----------------------------------------------------------------------------
|
||||
def refresh
|
||||
@opacity = 255
|
||||
@blend_type = 0
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Trigger event(s) at the same coordinates as self with the appropriate
|
||||
# trigger(s) that can be triggered
|
||||
#-----------------------------------------------------------------------------
|
||||
def check_event_trigger_here(triggers)
|
||||
result = false
|
||||
# If event is running
|
||||
return result if $game_system.map_interpreter.running?
|
||||
# All event loops
|
||||
for event in $game_map.events.values
|
||||
# If event coordinates and triggers are consistent
|
||||
next if !event.at_coordinate?(@x, @y)
|
||||
next if !triggers.include?(event.trigger)
|
||||
# If starting determinant is same position event (other than jumping)
|
||||
next if event.jumping? || !event.over_trigger?
|
||||
event.start
|
||||
result = true
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Front Event Starting Determinant
|
||||
#-----------------------------------------------------------------------------
|
||||
def check_event_trigger_there(triggers)
|
||||
result = false
|
||||
# If event is running
|
||||
return result if $game_system.map_interpreter.running?
|
||||
# Calculate front event coordinates
|
||||
new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
|
||||
new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
|
||||
return false if !$game_map.valid?(new_x, new_y)
|
||||
# All event loops
|
||||
for event in $game_map.events.values
|
||||
# If event coordinates and triggers are consistent
|
||||
next if !event.at_coordinate?(new_x, new_y)
|
||||
next if !triggers.include?(event.trigger)
|
||||
# If starting determinant is front event (other than jumping)
|
||||
next if event.jumping? || event.over_trigger?
|
||||
event.start
|
||||
result = true
|
||||
end
|
||||
# If fitting event is not found
|
||||
if result == false
|
||||
# If front tile is a counter
|
||||
if $game_map.counter?(new_x, new_y)
|
||||
# Calculate coordinates of 1 tile further away
|
||||
new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
|
||||
new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
|
||||
return false if !$game_map.valid?(new_x, new_y)
|
||||
# All event loops
|
||||
for event in $game_map.events.values
|
||||
# If event coordinates and triggers are consistent
|
||||
next if !event.at_coordinate?(new_x, new_y)
|
||||
next if !triggers.include?(event.trigger)
|
||||
# If starting determinant is front event (other than jumping)
|
||||
next if event.jumping? || event.over_trigger?
|
||||
event.start
|
||||
result = true
|
||||
end
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Touch Event Starting Determinant
|
||||
#-----------------------------------------------------------------------------
|
||||
def check_event_trigger_touch(dir)
|
||||
result = false
|
||||
return result if $game_system.map_interpreter.running?
|
||||
# All event loops
|
||||
x_offset = (dir == 4) ? -1 : (dir == 6) ? 1 : 0
|
||||
y_offset = (dir == 8) ? -1 : (dir == 2) ? 1 : 0
|
||||
for event in $game_map.events.values
|
||||
next if ![1, 2].include?(event.trigger) # Player touch, event touch
|
||||
# If event coordinates and triggers are consistent
|
||||
next if !event.at_coordinate?(@x + x_offset, @y + y_offset)
|
||||
if event.name[/trainer\((\d+)\)/i]
|
||||
distance = $~[1].to_i
|
||||
next if !pbEventCanReachPlayer?(event,self,distance)
|
||||
elsif event.name[/counter\((\d+)\)/i]
|
||||
distance = $~[1].to_i
|
||||
next if !pbEventFacesPlayer?(event,self,distance)
|
||||
end
|
||||
# If starting determinant is front event (other than jumping)
|
||||
next if event.jumping? || event.over_trigger?
|
||||
event.start
|
||||
result = true
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Frame Update
|
||||
#-----------------------------------------------------------------------------
|
||||
def update
|
||||
last_real_x = @real_x
|
||||
last_real_y = @real_y
|
||||
super
|
||||
update_screen_position(last_real_x, last_real_y)
|
||||
# Update dependent events
|
||||
$PokemonTemp.dependentEvents.updateDependentEvents
|
||||
# Count down the time between allowed bump sounds
|
||||
@bump_se -= 1 if @bump_se && @bump_se>0
|
||||
# Finish up dismounting from surfing
|
||||
if $PokemonTemp.endSurf && !moving?
|
||||
pbCancelVehicles
|
||||
$PokemonTemp.surfJump = nil
|
||||
$PokemonTemp.endSurf = false
|
||||
end
|
||||
update_event_triggering
|
||||
end
|
||||
|
||||
def update_command_new
|
||||
dir = Input.dir4
|
||||
unless pbMapInterpreterRunning? || $game_temp.message_window_showing ||
|
||||
$PokemonTemp.miniupdate || $game_temp.in_menu
|
||||
# Move player in the direction the directional button is being pressed
|
||||
if @moved_last_frame ||
|
||||
(dir > 0 && dir == @lastdir && Graphics.frame_count - @lastdirframe > Graphics.frame_rate / 20)
|
||||
case dir
|
||||
when 2 then move_down
|
||||
when 4 then move_left
|
||||
when 6 then move_right
|
||||
when 8 then move_up
|
||||
end
|
||||
elsif dir != @lastdir
|
||||
case dir
|
||||
when 2 then turn_down
|
||||
when 4 then turn_left
|
||||
when 6 then turn_right
|
||||
when 8 then turn_up
|
||||
end
|
||||
end
|
||||
end
|
||||
# Record last direction input
|
||||
@lastdirframe = Graphics.frame_count if dir != @lastdir
|
||||
@lastdir = dir
|
||||
end
|
||||
|
||||
# Center player on-screen
|
||||
def update_screen_position(last_real_x, last_real_y)
|
||||
return if self.map.scrolling? || !(@moved_last_frame || @moved_this_frame)
|
||||
self.map.display_x = @real_x - SCREEN_CENTER_X
|
||||
self.map.display_y = @real_y - SCREEN_CENTER_Y
|
||||
end
|
||||
|
||||
def update_event_triggering
|
||||
return if moving?
|
||||
# Try triggering events upon walking into them/in front of them
|
||||
if @moved_this_frame
|
||||
$PokemonTemp.dependentEvents.pbTurnDependentEvents
|
||||
result = pbCheckEventTriggerFromDistance([2])
|
||||
# Event determinant is via touch of same position event
|
||||
result |= check_event_trigger_here([1,2])
|
||||
# No events triggered, try other event triggers upon finishing a step
|
||||
pbOnStepTaken(result)
|
||||
end
|
||||
# Try to manually interact with events
|
||||
if Input.trigger?(Input::USE) && !$PokemonTemp.miniupdate
|
||||
# Same position and front event determinant
|
||||
check_event_trigger_here([0])
|
||||
check_event_trigger_there([0,2])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def pbGetPlayerCharset(meta,charset,trainer=nil,force=false)
|
||||
trainer = $Trainer if !trainer
|
||||
outfit = (trainer) ? trainer.outfit : 0
|
||||
if $game_player && $game_player.charsetData && !force
|
||||
return nil if $game_player.charsetData[0] == $Trainer.character_ID &&
|
||||
$game_player.charsetData[1] == charset &&
|
||||
$game_player.charsetData[2] == outfit
|
||||
end
|
||||
$game_player.charsetData = [$Trainer.character_ID,charset,outfit] if $game_player
|
||||
ret = meta[charset]
|
||||
ret = meta[1] if nil_or_empty?(ret)
|
||||
if pbResolveBitmap("Graphics/Characters/"+ret+"_"+outfit.to_s)
|
||||
ret = ret+"_"+outfit.to_s
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def pbUpdateVehicle
|
||||
meta = GameData::Metadata.get_player($Trainer.character_ID)
|
||||
if meta
|
||||
charset = 1 # Regular graphic
|
||||
if $PokemonGlobal.diving; charset = 5 # Diving graphic
|
||||
elsif $PokemonGlobal.surfing; charset = 3 # Surfing graphic
|
||||
elsif $PokemonGlobal.bicycle; charset = 2 # Bicycle graphic
|
||||
end
|
||||
newCharName = pbGetPlayerCharset(meta,charset)
|
||||
$game_player.character_name = newCharName if newCharName
|
||||
end
|
||||
end
|
||||
|
||||
def pbCancelVehicles(destination=nil)
|
||||
$PokemonGlobal.surfing = false
|
||||
$PokemonGlobal.diving = false
|
||||
$PokemonGlobal.bicycle = false if !destination || !pbCanUseBike?(destination)
|
||||
pbUpdateVehicle
|
||||
end
|
||||
|
||||
def pbCanUseBike?(map_id)
|
||||
map_metadata = GameData::MapMetadata.try_get(map_id)
|
||||
return false if !map_metadata
|
||||
return true if map_metadata.always_bicycle
|
||||
val = map_metadata.can_bicycle || map_metadata.outdoor_map
|
||||
return (val) ? true : false
|
||||
end
|
||||
|
||||
def pbMountBike
|
||||
return if $PokemonGlobal.bicycle
|
||||
$PokemonGlobal.bicycle = true
|
||||
pbUpdateVehicle
|
||||
bike_bgm = GameData::Metadata.get.bicycle_BGM
|
||||
pbCueBGM(bike_bgm, 0.5) if bike_bgm
|
||||
pbPokeRadarCancel
|
||||
end
|
||||
|
||||
def pbDismountBike
|
||||
return if !$PokemonGlobal.bicycle
|
||||
$PokemonGlobal.bicycle = false
|
||||
pbUpdateVehicle
|
||||
$game_map.autoplayAsCue
|
||||
end
|
||||
102
Data/Scripts_backup/004_Game classes/010_Game_Player_Visuals.rb
Normal file
102
Data/Scripts_backup/004_Game classes/010_Game_Player_Visuals.rb
Normal file
@@ -0,0 +1,102 @@
|
||||
class Game_Player < Game_Character
|
||||
@@bobFrameSpeed = 1.0/15
|
||||
|
||||
def fullPattern
|
||||
case self.direction
|
||||
when 2 then return self.pattern
|
||||
when 4 then return self.pattern + 4
|
||||
when 6 then return self.pattern + 8
|
||||
when 8 then return self.pattern + 12
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
def setDefaultCharName(chname,pattern,lockpattern=false)
|
||||
return if pattern<0 || pattern>=16
|
||||
@defaultCharacterName = chname
|
||||
@direction = [2,4,6,8][pattern/4]
|
||||
@pattern = pattern%4
|
||||
@lock_pattern = lockpattern
|
||||
end
|
||||
|
||||
def pbCanRun?
|
||||
return false if $game_temp.in_menu || $game_temp.in_battle ||
|
||||
@move_route_forcing || $game_temp.message_window_showing ||
|
||||
pbMapInterpreterRunning?
|
||||
input = ($PokemonSystem.runstyle == 1) ^ Input.press?(Input::ACTION)
|
||||
return input && $Trainer.has_running_shoes && !jumping? &&
|
||||
!$PokemonGlobal.diving && !$PokemonGlobal.surfing &&
|
||||
!$PokemonGlobal.bicycle && !$game_player.pbTerrainTag.must_walk
|
||||
end
|
||||
|
||||
def pbIsRunning?
|
||||
return moving? && !@move_route_forcing && pbCanRun?
|
||||
end
|
||||
|
||||
def character_name
|
||||
@defaultCharacterName = "" if !@defaultCharacterName
|
||||
return @defaultCharacterName if @defaultCharacterName!=""
|
||||
if !@move_route_forcing && $Trainer.character_ID>=0
|
||||
meta = GameData::Metadata.get_player($Trainer.character_ID)
|
||||
if meta && !$PokemonGlobal.bicycle && !$PokemonGlobal.diving && !$PokemonGlobal.surfing
|
||||
charset = 1 # Display normal character sprite
|
||||
if pbCanRun? && (moving? || @wasmoving) && Input.dir4!=0 && meta[4] && meta[4]!=""
|
||||
charset = 4 # Display running character sprite
|
||||
end
|
||||
newCharName = pbGetPlayerCharset(meta,charset)
|
||||
@character_name = newCharName if newCharName
|
||||
@wasmoving = moving?
|
||||
end
|
||||
end
|
||||
return @character_name
|
||||
end
|
||||
|
||||
def update_command
|
||||
if $game_player.pbTerrainTag.ice
|
||||
self.move_speed = 4.8 # Sliding on ice
|
||||
elsif !moving? && !@move_route_forcing && $PokemonGlobal
|
||||
if $PokemonGlobal.bicycle
|
||||
self.move_speed = 6.2 # Cycling
|
||||
elsif pbCanRun? || $PokemonGlobal.surfing
|
||||
self.move_speed = 4.8 # Running, surfing
|
||||
else
|
||||
self.move_speed = 3.8 # Walking, diving
|
||||
end
|
||||
end
|
||||
super
|
||||
end
|
||||
|
||||
def update_pattern
|
||||
if $PokemonGlobal.surfing || $PokemonGlobal.diving
|
||||
p = ((Graphics.frame_count%60)*@@bobFrameSpeed).floor
|
||||
@pattern = p if !@lock_pattern
|
||||
@pattern_surf = p
|
||||
@bob_height = (p>=2) ? 2 : 0
|
||||
else
|
||||
@bob_height = 0
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
=begin
|
||||
class Game_Character
|
||||
alias update_old2 update
|
||||
|
||||
def update
|
||||
if self.is_a?(Game_Event)
|
||||
if @dependentEvents
|
||||
for i in 0...@dependentEvents.length
|
||||
if @dependentEvents[i][0]==$game_map.map_id &&
|
||||
@dependentEvents[i][1]==self.id
|
||||
self.move_speed_real = $game_player.move_speed_real
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
update_old2
|
||||
end
|
||||
end
|
||||
=end
|
||||
81
Data/Scripts_backup/004_Game classes/011_Game_CommonEvent.rb
Normal file
81
Data/Scripts_backup/004_Game classes/011_Game_CommonEvent.rb
Normal file
@@ -0,0 +1,81 @@
|
||||
#===============================================================================
|
||||
# ** Game_CommonEvent
|
||||
#-------------------------------------------------------------------------------
|
||||
# This class handles common events. It includes execution of parallel process
|
||||
# event. This class is used within the Game_Map class ($game_map).
|
||||
#===============================================================================
|
||||
class Game_CommonEvent
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Object Initialization
|
||||
# common_event_id : common event ID
|
||||
#-----------------------------------------------------------------------------
|
||||
def initialize(common_event_id)
|
||||
@common_event_id = common_event_id
|
||||
@interpreter = nil
|
||||
refresh
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Get Name
|
||||
#-----------------------------------------------------------------------------
|
||||
def name
|
||||
return $data_common_events[@common_event_id].name
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Get Trigger
|
||||
#-----------------------------------------------------------------------------
|
||||
def trigger
|
||||
return $data_common_events[@common_event_id].trigger
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Get Condition Switch ID
|
||||
#-----------------------------------------------------------------------------
|
||||
def switch_id
|
||||
return $data_common_events[@common_event_id].switch_id
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Get List of Event Commands
|
||||
#-----------------------------------------------------------------------------
|
||||
def list
|
||||
return $data_common_events[@common_event_id].list
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Checks if switch is on
|
||||
#-----------------------------------------------------------------------------
|
||||
def switchIsOn?(id)
|
||||
switchName = $data_system.switches[id]
|
||||
return false if !switchName
|
||||
if switchName[/^s\:/]
|
||||
return eval($~.post_match)
|
||||
else
|
||||
return $game_switches[id]
|
||||
end
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Refresh
|
||||
#-----------------------------------------------------------------------------
|
||||
def refresh
|
||||
# Create an interpreter for parallel process if necessary
|
||||
if self.trigger == 2 && switchIsOn?(self.switch_id)
|
||||
if @interpreter == nil
|
||||
@interpreter = Interpreter.new
|
||||
end
|
||||
else
|
||||
@interpreter = nil
|
||||
end
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# * Frame Update
|
||||
#-----------------------------------------------------------------------------
|
||||
def update
|
||||
# If parallel process is valid
|
||||
if @interpreter != nil
|
||||
# If not running
|
||||
unless @interpreter.running?
|
||||
# Set up event
|
||||
@interpreter.setup(self.list, 0)
|
||||
end
|
||||
# Update interpreter
|
||||
@interpreter.update
|
||||
end
|
||||
end
|
||||
end
|
||||
563
Data/Scripts_backup/004_Game classes/012_Game_DependentEvents.rb
Normal file
563
Data/Scripts_backup/004_Game classes/012_Game_DependentEvents.rb
Normal file
@@ -0,0 +1,563 @@
|
||||
class PokemonTemp
|
||||
attr_writer :dependentEvents
|
||||
|
||||
def dependentEvents
|
||||
@dependentEvents = DependentEvents.new if !@dependentEvents
|
||||
return @dependentEvents
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def pbRemoveDependencies()
|
||||
$PokemonTemp.dependentEvents.removeAllEvents()
|
||||
pbDeregisterPartner() rescue nil
|
||||
end
|
||||
|
||||
def pbAddDependency(event)
|
||||
$PokemonTemp.dependentEvents.addEvent(event)
|
||||
end
|
||||
|
||||
def pbRemoveDependency(event)
|
||||
$PokemonTemp.dependentEvents.removeEvent(event)
|
||||
end
|
||||
|
||||
def pbAddDependency2(eventID, eventName, commonEvent)
|
||||
$PokemonTemp.dependentEvents.addEvent($game_map.events[eventID],eventName,commonEvent)
|
||||
end
|
||||
|
||||
# Gets the Game_Character object associated with a dependent event.
|
||||
def pbGetDependency(eventName)
|
||||
return $PokemonTemp.dependentEvents.getEventByName(eventName)
|
||||
end
|
||||
|
||||
def pbRemoveDependency2(eventName)
|
||||
$PokemonTemp.dependentEvents.removeEventByName(eventName)
|
||||
end
|
||||
|
||||
|
||||
|
||||
class PokemonGlobalMetadata
|
||||
attr_writer :dependentEvents
|
||||
|
||||
def dependentEvents
|
||||
@dependentEvents = [] if !@dependentEvents
|
||||
return @dependentEvents
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def pbTestPass(follower,x,y,_direction=nil)
|
||||
return $MapFactory.isPassableStrict?(follower.map.map_id,x,y,follower)
|
||||
end
|
||||
|
||||
# Same map only
|
||||
def moveThrough(follower,direction)
|
||||
oldThrough=follower.through
|
||||
follower.through=true
|
||||
case direction
|
||||
when 2 then follower.move_down
|
||||
when 4 then follower.move_left
|
||||
when 6 then follower.move_right
|
||||
when 8 then follower.move_up
|
||||
end
|
||||
follower.through=oldThrough
|
||||
end
|
||||
|
||||
# Same map only
|
||||
def moveFancy(follower,direction)
|
||||
deltaX=(direction == 6 ? 1 : (direction == 4 ? -1 : 0))
|
||||
deltaY=(direction == 2 ? 1 : (direction == 8 ? -1 : 0))
|
||||
newX = follower.x + deltaX
|
||||
newY = follower.y + deltaY
|
||||
# Move if new position is the player's, or the new position is passable,
|
||||
# or the current position is not passable
|
||||
if ($game_player.x==newX && $game_player.y==newY) ||
|
||||
pbTestPass(follower,newX,newY,0) ||
|
||||
!pbTestPass(follower,follower.x,follower.y,0)
|
||||
oldThrough=follower.through
|
||||
follower.through=true
|
||||
case direction
|
||||
when 2 then follower.move_down
|
||||
when 4 then follower.move_left
|
||||
when 6 then follower.move_right
|
||||
when 8 then follower.move_up
|
||||
end
|
||||
follower.through=oldThrough
|
||||
end
|
||||
end
|
||||
|
||||
# Same map only
|
||||
def jumpFancy(follower,direction,leader)
|
||||
deltaX=(direction == 6 ? 2 : (direction == 4 ? -2 : 0))
|
||||
deltaY=(direction == 2 ? 2 : (direction == 8 ? -2 : 0))
|
||||
halfDeltaX=(direction == 6 ? 1 : (direction == 4 ? -1 : 0))
|
||||
halfDeltaY=(direction == 2 ? 1 : (direction == 8 ? -1 : 0))
|
||||
middle=pbTestPass(follower,follower.x+halfDeltaX,follower.y+halfDeltaY,0)
|
||||
ending=pbTestPass(follower,follower.x+deltaX, follower.y+deltaY, 0)
|
||||
if middle
|
||||
moveFancy(follower,direction)
|
||||
moveFancy(follower,direction)
|
||||
elsif ending
|
||||
if pbTestPass(follower,follower.x,follower.y,0)
|
||||
if leader.jumping?
|
||||
follower.jump_speed_real = leader.jump_speed_real * Graphics.frame_rate / 40.0
|
||||
else
|
||||
follower.jump_speed_real = leader.move_speed_real * Graphics.frame_rate / 20.0
|
||||
end
|
||||
follower.jump(deltaX,deltaY)
|
||||
else
|
||||
moveThrough(follower,direction)
|
||||
moveThrough(follower,direction)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def pbFancyMoveTo(follower,newX,newY,leader)
|
||||
if follower.x-newX==-1 && follower.y==newY
|
||||
moveFancy(follower,6)
|
||||
elsif follower.x-newX==1 && follower.y==newY
|
||||
moveFancy(follower,4)
|
||||
elsif follower.y-newY==-1 && follower.x==newX
|
||||
moveFancy(follower,2)
|
||||
elsif follower.y-newY==1 && follower.x==newX
|
||||
moveFancy(follower,8)
|
||||
elsif follower.x-newX==-2 && follower.y==newY
|
||||
jumpFancy(follower,6,leader)
|
||||
elsif follower.x-newX==2 && follower.y==newY
|
||||
jumpFancy(follower,4,leader)
|
||||
elsif follower.y-newY==-2 && follower.x==newX
|
||||
jumpFancy(follower,2,leader)
|
||||
elsif follower.y-newY==2 && follower.x==newX
|
||||
jumpFancy(follower,8,leader)
|
||||
elsif follower.x!=newX || follower.y!=newY
|
||||
follower.moveto(newX,newY)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class DependentEvents
|
||||
attr_reader :lastUpdate
|
||||
|
||||
def createEvent(eventData)
|
||||
rpgEvent = RPG::Event.new(eventData[3],eventData[4])
|
||||
rpgEvent.id = eventData[1]
|
||||
if eventData[9]
|
||||
# Must setup common event list here and now
|
||||
commonEvent = Game_CommonEvent.new(eventData[9])
|
||||
rpgEvent.pages[0].list = commonEvent.list
|
||||
end
|
||||
newEvent = Game_Event.new(eventData[0],rpgEvent,$MapFactory.getMap(eventData[2]))
|
||||
newEvent.character_name = eventData[6]
|
||||
newEvent.character_hue = eventData[7]
|
||||
case eventData[5] # direction
|
||||
when 2 then newEvent.turn_down
|
||||
when 4 then newEvent.turn_left
|
||||
when 6 then newEvent.turn_right
|
||||
when 8 then newEvent.turn_up
|
||||
end
|
||||
return newEvent
|
||||
end
|
||||
|
||||
def initialize
|
||||
# Original map, Event ID, Current map, X, Y, Direction
|
||||
events=$PokemonGlobal.dependentEvents
|
||||
@realEvents=[]
|
||||
@lastUpdate=-1
|
||||
for event in events
|
||||
@realEvents.push(createEvent(event))
|
||||
end
|
||||
end
|
||||
|
||||
def pbEnsureEvent(event, newMapID)
|
||||
events=$PokemonGlobal.dependentEvents
|
||||
for i in 0...events.length
|
||||
# Check original map ID and original event ID
|
||||
if events[i][0]==event.map_id && events[i][1]==event.id
|
||||
# Change current map ID
|
||||
events[i][2]=newMapID
|
||||
newEvent=createEvent(events[i])
|
||||
# Replace event
|
||||
@realEvents[i]=newEvent
|
||||
@lastUpdate+=1
|
||||
return i
|
||||
end
|
||||
end
|
||||
return -1
|
||||
end
|
||||
|
||||
def pbFollowEventAcrossMaps(leader,follower,instant=false,leaderIsTrueLeader=true)
|
||||
d=leader.direction
|
||||
areConnected=$MapFactory.areConnected?(leader.map.map_id,follower.map.map_id)
|
||||
# Get the rear facing tile of leader
|
||||
facingDirection=10-d
|
||||
if !leaderIsTrueLeader && areConnected
|
||||
relativePos=$MapFactory.getThisAndOtherEventRelativePos(leader,follower)
|
||||
# Assumes leader and follower are both 1x1 tile in size
|
||||
if (relativePos[1]==0 && relativePos[0]==2) # 2 spaces to the right of leader
|
||||
facingDirection=6
|
||||
elsif (relativePos[1]==0 && relativePos[0]==-2) # 2 spaces to the left of leader
|
||||
facingDirection=4
|
||||
elsif relativePos[1]==-2 && relativePos[0]==0 # 2 spaces above leader
|
||||
facingDirection=8
|
||||
elsif relativePos[1]==2 && relativePos[0]==0 # 2 spaces below leader
|
||||
facingDirection=2
|
||||
end
|
||||
end
|
||||
facings=[facingDirection] # Get facing from behind
|
||||
# facings.push([0,0,4,0,8,0,2,0,6][d]) # Get right facing
|
||||
# facings.push([0,0,6,0,2,0,8,0,4][d]) # Get left facing
|
||||
if !leaderIsTrueLeader
|
||||
facings.push(d) # Get forward facing
|
||||
end
|
||||
mapTile=nil
|
||||
if areConnected
|
||||
bestRelativePos=-1
|
||||
oldthrough=follower.through
|
||||
follower.through=false
|
||||
for i in 0...facings.length
|
||||
facing=facings[i]
|
||||
tile=$MapFactory.getFacingTile(facing,leader)
|
||||
# Assumes leader is 1x1 tile in size
|
||||
passable=tile && $MapFactory.isPassableStrict?(tile[0],tile[1],tile[2],follower)
|
||||
if i==0 && !passable && tile &&
|
||||
$MapFactory.getTerrainTag(tile[0],tile[1],tile[2]).ledge
|
||||
# If the tile isn't passable and the tile is a ledge,
|
||||
# get tile from further behind
|
||||
tile=$MapFactory.getFacingTileFromPos(tile[0],tile[1],tile[2],facing)
|
||||
passable=tile && $MapFactory.isPassableStrict?(tile[0],tile[1],tile[2],follower)
|
||||
end
|
||||
if passable
|
||||
relativePos=$MapFactory.getThisAndOtherPosRelativePos(
|
||||
follower,tile[0],tile[1],tile[2])
|
||||
# Assumes follower is 1x1 tile in size
|
||||
distance=Math.sqrt(relativePos[0]*relativePos[0]+relativePos[1]*relativePos[1])
|
||||
if bestRelativePos==-1 || bestRelativePos>distance
|
||||
bestRelativePos=distance
|
||||
mapTile=tile
|
||||
end
|
||||
if i==0 && distance<=1 # Prefer behind if tile can move up to 1 space
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
follower.through=oldthrough
|
||||
else
|
||||
tile=$MapFactory.getFacingTile(facings[0],leader)
|
||||
# Assumes leader is 1x1 tile in size
|
||||
passable=tile && $MapFactory.isPassableStrict?(tile[0],tile[1],tile[2],follower)
|
||||
mapTile=passable ? mapTile : nil
|
||||
end
|
||||
if mapTile && follower.map.map_id==mapTile[0]
|
||||
# Follower is on same map
|
||||
newX=mapTile[1]
|
||||
newY=mapTile[2]
|
||||
deltaX=(d == 6 ? -1 : d == 4 ? 1 : 0)
|
||||
deltaY=(d == 2 ? -1 : d == 8 ? 1 : 0)
|
||||
posX = newX + deltaX
|
||||
posY = newY + deltaY
|
||||
follower.move_speed=leader.move_speed # sync movespeed
|
||||
if (follower.x-newX==-1 && follower.y==newY) ||
|
||||
(follower.x-newX==1 && follower.y==newY) ||
|
||||
(follower.y-newY==-1 && follower.x==newX) ||
|
||||
(follower.y-newY==1 && follower.x==newX)
|
||||
if instant
|
||||
follower.moveto(newX,newY)
|
||||
else
|
||||
pbFancyMoveTo(follower,newX,newY,leader)
|
||||
end
|
||||
elsif (follower.x-newX==-2 && follower.y==newY) ||
|
||||
(follower.x-newX==2 && follower.y==newY) ||
|
||||
(follower.y-newY==-2 && follower.x==newX) ||
|
||||
(follower.y-newY==2 && follower.x==newX)
|
||||
if instant
|
||||
follower.moveto(newX,newY)
|
||||
else
|
||||
pbFancyMoveTo(follower,newX,newY,leader)
|
||||
end
|
||||
elsif follower.x!=posX || follower.y!=posY
|
||||
if instant
|
||||
follower.moveto(newX,newY)
|
||||
else
|
||||
pbFancyMoveTo(follower,posX,posY,leader)
|
||||
pbFancyMoveTo(follower,newX,newY,leader)
|
||||
end
|
||||
end
|
||||
else
|
||||
if !mapTile
|
||||
# Make current position into leader's position
|
||||
mapTile=[leader.map.map_id,leader.x,leader.y]
|
||||
end
|
||||
if follower.map.map_id==mapTile[0]
|
||||
# Follower is on same map as leader
|
||||
follower.moveto(leader.x,leader.y)
|
||||
else
|
||||
# Follower will move to different map
|
||||
events=$PokemonGlobal.dependentEvents
|
||||
eventIndex=pbEnsureEvent(follower,mapTile[0])
|
||||
if eventIndex>=0
|
||||
newFollower=@realEvents[eventIndex]
|
||||
newEventData=events[eventIndex]
|
||||
newFollower.moveto(mapTile[1],mapTile[2])
|
||||
newEventData[3]=mapTile[1]
|
||||
newEventData[4]=mapTile[2]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def debugEcho
|
||||
self.eachEvent { |e,d|
|
||||
echoln d
|
||||
echoln [e.map_id,e.map.map_id,e.id]
|
||||
}
|
||||
end
|
||||
|
||||
def pbMapChangeMoveDependentEvents
|
||||
events=$PokemonGlobal.dependentEvents
|
||||
updateDependentEvents
|
||||
leader=$game_player
|
||||
for i in 0...events.length
|
||||
event=@realEvents[i]
|
||||
pbFollowEventAcrossMaps(leader,event,true,i==0)
|
||||
# Update X and Y for this event
|
||||
events[i][3]=event.x
|
||||
events[i][4]=event.y
|
||||
events[i][5]=event.direction
|
||||
# Set leader to this event
|
||||
leader=event
|
||||
end
|
||||
end
|
||||
|
||||
def pbMoveDependentEvents
|
||||
events=$PokemonGlobal.dependentEvents
|
||||
updateDependentEvents
|
||||
leader=$game_player
|
||||
for i in 0...events.length
|
||||
event=@realEvents[i]
|
||||
pbFollowEventAcrossMaps(leader,event,false,i==0)
|
||||
# Update X and Y for this event
|
||||
events[i][3]=event.x
|
||||
events[i][4]=event.y
|
||||
events[i][5]=event.direction
|
||||
# Set leader to this event
|
||||
leader=event
|
||||
end
|
||||
end
|
||||
|
||||
def pbTurnDependentEvents
|
||||
events=$PokemonGlobal.dependentEvents
|
||||
updateDependentEvents
|
||||
leader=$game_player
|
||||
for i in 0...events.length
|
||||
event=@realEvents[i]
|
||||
pbTurnTowardEvent(event,leader)
|
||||
# Update direction for this event
|
||||
events[i][5]=event.direction
|
||||
# Set leader to this event
|
||||
leader=event
|
||||
end
|
||||
end
|
||||
|
||||
def eachEvent
|
||||
events=$PokemonGlobal.dependentEvents
|
||||
for i in 0...events.length
|
||||
yield @realEvents[i],events[i]
|
||||
end
|
||||
end
|
||||
|
||||
def updateDependentEvents
|
||||
events=$PokemonGlobal.dependentEvents
|
||||
return if events.length==0
|
||||
for i in 0...events.length
|
||||
event=@realEvents[i]
|
||||
next if !@realEvents[i]
|
||||
event.transparent=$game_player.transparent
|
||||
if event.jumping? || event.moving? ||
|
||||
!($game_player.jumping? || $game_player.moving?)
|
||||
event.update
|
||||
elsif !event.starting
|
||||
event.set_starting
|
||||
event.update
|
||||
event.clear_starting
|
||||
end
|
||||
events[i][3]=event.x
|
||||
events[i][4]=event.y
|
||||
events[i][5]=event.direction
|
||||
end
|
||||
# Check event triggers
|
||||
if Input.trigger?(Input::USE) && !$game_temp.in_menu && !$game_temp.in_battle &&
|
||||
!$game_player.move_route_forcing && !$game_temp.message_window_showing &&
|
||||
!pbMapInterpreterRunning?
|
||||
# Get position of tile facing the player
|
||||
facingTile=$MapFactory.getFacingTile()
|
||||
# Assumes player is 1x1 tile in size
|
||||
self.eachEvent { |e,d|
|
||||
next if !d[9]
|
||||
if e.at_coordinate?($game_player.x, $game_player.y)
|
||||
# On same position
|
||||
if !e.jumping? && (!e.respond_to?("over_trigger") || e.over_trigger?)
|
||||
if e.list.size>1
|
||||
# Start event
|
||||
$game_map.refresh if $game_map.need_refresh
|
||||
e.lock
|
||||
pbMapInterpreter.setup(e.list,e.id,e.map.map_id)
|
||||
end
|
||||
end
|
||||
elsif facingTile && e.map.map_id==facingTile[0] &&
|
||||
e.at_coordinate?(facingTile[1], facingTile[2])
|
||||
# On facing tile
|
||||
if !e.jumping? && (!e.respond_to?("over_trigger") || !e.over_trigger?)
|
||||
if e.list.size>1
|
||||
# Start event
|
||||
$game_map.refresh if $game_map.need_refresh
|
||||
e.lock
|
||||
pbMapInterpreter.setup(e.list,e.id,e.map.map_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def removeEvent(event)
|
||||
events=$PokemonGlobal.dependentEvents
|
||||
mapid=$game_map.map_id
|
||||
for i in 0...events.length
|
||||
if events[i][2]==mapid && # Refer to current map
|
||||
events[i][0]==event.map_id && # Event's map ID is original ID
|
||||
events[i][1]==event.id
|
||||
events[i]=nil
|
||||
@realEvents[i]=nil
|
||||
@lastUpdate+=1
|
||||
end
|
||||
end
|
||||
events.compact!
|
||||
@realEvents.compact!
|
||||
end
|
||||
|
||||
def getEventByName(name)
|
||||
events=$PokemonGlobal.dependentEvents
|
||||
for i in 0...events.length
|
||||
if events[i] && events[i][8]==name # Arbitrary name given to dependent event
|
||||
return @realEvents[i]
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
def removeAllEvents
|
||||
events=$PokemonGlobal.dependentEvents
|
||||
events.clear
|
||||
@realEvents.clear
|
||||
@lastUpdate+=1
|
||||
end
|
||||
|
||||
def removeEventByName(name)
|
||||
events=$PokemonGlobal.dependentEvents
|
||||
for i in 0...events.length
|
||||
if events[i] && events[i][8]==name # Arbitrary name given to dependent event
|
||||
events[i]=nil
|
||||
@realEvents[i]=nil
|
||||
@lastUpdate+=1
|
||||
end
|
||||
end
|
||||
events.compact!
|
||||
@realEvents.compact!
|
||||
end
|
||||
|
||||
def addEvent(event,eventName=nil,commonEvent=nil)
|
||||
return if !event
|
||||
events=$PokemonGlobal.dependentEvents
|
||||
for i in 0...events.length
|
||||
if events[i] && events[i][0]==$game_map.map_id && events[i][1]==event.id
|
||||
# Already exists
|
||||
return
|
||||
end
|
||||
end
|
||||
# Original map ID, original event ID, current map ID,
|
||||
# event X, event Y, event direction,
|
||||
# event's filename,
|
||||
# event's hue, event's name, common event ID
|
||||
eventData=[
|
||||
$game_map.map_id,event.id,$game_map.map_id,
|
||||
event.x,event.y,event.direction,
|
||||
event.character_name.clone,
|
||||
event.character_hue,eventName,commonEvent
|
||||
]
|
||||
newEvent=createEvent(eventData)
|
||||
events.push(eventData)
|
||||
@realEvents.push(newEvent)
|
||||
@lastUpdate+=1
|
||||
event.erase
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class DependentEventSprites
|
||||
def initialize(viewport,map)
|
||||
@disposed=false
|
||||
@sprites=[]
|
||||
@map=map
|
||||
@viewport=viewport
|
||||
refresh
|
||||
@lastUpdate=nil
|
||||
end
|
||||
|
||||
def refresh
|
||||
for sprite in @sprites
|
||||
sprite.dispose
|
||||
end
|
||||
@sprites.clear
|
||||
$PokemonTemp.dependentEvents.eachEvent { |event,data|
|
||||
if data[0]==@map.map_id # Check original map
|
||||
@map.events[data[1]].erase
|
||||
end
|
||||
if data[2]==@map.map_id # Check current map
|
||||
@sprites.push(Sprite_Character.new(@viewport,event))
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def update
|
||||
if $PokemonTemp.dependentEvents.lastUpdate!=@lastUpdate
|
||||
refresh
|
||||
@lastUpdate=$PokemonTemp.dependentEvents.lastUpdate
|
||||
end
|
||||
for sprite in @sprites
|
||||
sprite.update
|
||||
end
|
||||
end
|
||||
|
||||
def dispose
|
||||
return if @disposed
|
||||
for sprite in @sprites
|
||||
sprite.dispose
|
||||
end
|
||||
@sprites.clear
|
||||
@disposed=true
|
||||
end
|
||||
|
||||
def disposed?
|
||||
@disposed
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
Events.onSpritesetCreate += proc { |_sender,e|
|
||||
spriteset = e[0] # Spriteset being created
|
||||
viewport = e[1] # Viewport used for tilemap and characters
|
||||
map = spriteset.map # Map associated with the spriteset (not necessarily the current map)
|
||||
spriteset.addUserSprite(DependentEventSprites.new(viewport,map))
|
||||
}
|
||||
|
||||
Events.onMapSceneChange += proc { |_sender,e|
|
||||
mapChanged = e[1]
|
||||
if mapChanged
|
||||
$PokemonTemp.dependentEvents.pbMapChangeMoveDependentEvents
|
||||
end
|
||||
}
|
||||
58
Data/Scripts_backup/005_Sprites/001_Sprite_Picture.rb
Normal file
58
Data/Scripts_backup/005_Sprites/001_Sprite_Picture.rb
Normal file
@@ -0,0 +1,58 @@
|
||||
class Sprite_Picture
|
||||
def initialize(viewport, picture)
|
||||
@viewport = viewport
|
||||
@picture = picture
|
||||
@sprite = nil
|
||||
update
|
||||
end
|
||||
|
||||
def dispose
|
||||
@sprite.dispose if @sprite
|
||||
end
|
||||
|
||||
def update
|
||||
@sprite.update if @sprite
|
||||
# If picture file name is different from current one
|
||||
if @picture_name != @picture.name
|
||||
# Remember file name to instance variables
|
||||
@picture_name = @picture.name
|
||||
# If file name is not empty
|
||||
if @picture_name != ""
|
||||
# Get picture graphic
|
||||
@sprite=IconSprite.new(0,0,@viewport) if !@sprite
|
||||
@sprite.setBitmap("Graphics/Pictures/"+@picture_name)
|
||||
end
|
||||
end
|
||||
# If file name is empty
|
||||
if @picture_name == ""
|
||||
# Set sprite to invisible
|
||||
if @sprite
|
||||
@sprite.dispose if @sprite
|
||||
@sprite=nil
|
||||
end
|
||||
return
|
||||
end
|
||||
# Set sprite to visible
|
||||
@sprite.visible = true
|
||||
# Set transfer starting point
|
||||
if @picture.origin == 0
|
||||
@sprite.ox = 0
|
||||
@sprite.oy = 0
|
||||
else
|
||||
@sprite.ox = @sprite.bitmap.width / 2
|
||||
@sprite.oy = @sprite.bitmap.height / 2
|
||||
end
|
||||
# Set sprite coordinates
|
||||
@sprite.x = @picture.x
|
||||
@sprite.y = @picture.y
|
||||
@sprite.z = @picture.number
|
||||
# Set zoom rate, opacity level, and blend method
|
||||
@sprite.zoom_x = @picture.zoom_x / 100.0
|
||||
@sprite.zoom_y = @picture.zoom_y / 100.0
|
||||
@sprite.opacity = @picture.opacity
|
||||
@sprite.blend_type = @picture.blend_type
|
||||
# Set rotation angle and color tone
|
||||
@sprite.angle = @picture.angle
|
||||
@sprite.tone = @picture.tone
|
||||
end
|
||||
end
|
||||
45
Data/Scripts_backup/005_Sprites/002_Sprite_Timer.rb
Normal file
45
Data/Scripts_backup/005_Sprites/002_Sprite_Timer.rb
Normal file
@@ -0,0 +1,45 @@
|
||||
class Sprite_Timer
|
||||
def initialize(viewport=nil)
|
||||
@viewport=viewport
|
||||
@timer=nil
|
||||
@total_sec=nil
|
||||
@disposed=false
|
||||
end
|
||||
|
||||
def dispose
|
||||
@timer.dispose if @timer
|
||||
@timer=nil
|
||||
@disposed=true
|
||||
end
|
||||
|
||||
def disposed?
|
||||
@disposed
|
||||
end
|
||||
|
||||
def update
|
||||
return if disposed?
|
||||
if $game_system.timer_working
|
||||
@timer.visible = true if @timer
|
||||
if !@timer
|
||||
@timer=Window_AdvancedTextPokemon.newWithSize("",Graphics.width-120,0,120,64)
|
||||
@timer.width=@timer.borderX+96
|
||||
@timer.x=Graphics.width-@timer.width
|
||||
@timer.viewport=@viewport
|
||||
@timer.z=99998
|
||||
end
|
||||
curtime=$game_system.timer / Graphics.frame_rate
|
||||
curtime=0 if curtime<0
|
||||
if curtime != @total_sec
|
||||
# Calculate total number of seconds
|
||||
@total_sec = curtime
|
||||
# Make a string for displaying the timer
|
||||
min = @total_sec / 60
|
||||
sec = @total_sec % 60
|
||||
@timer.text = _ISPRINTF("<ac>{1:02d}:{2:02d}", min, sec)
|
||||
end
|
||||
@timer.update
|
||||
else
|
||||
@timer.visible=false if @timer
|
||||
end
|
||||
end
|
||||
end
|
||||
173
Data/Scripts_backup/005_Sprites/003_Sprite_Character.rb
Normal file
173
Data/Scripts_backup/005_Sprites/003_Sprite_Character.rb
Normal file
@@ -0,0 +1,173 @@
|
||||
class BushBitmap
|
||||
def initialize(bitmap, isTile, depth)
|
||||
@bitmaps = []
|
||||
@bitmap = bitmap
|
||||
@isTile = isTile
|
||||
@isBitmap = @bitmap.is_a?(Bitmap)
|
||||
@depth = depth
|
||||
end
|
||||
|
||||
def dispose
|
||||
@bitmaps.each { |b| b.dispose if b }
|
||||
end
|
||||
|
||||
def bitmap
|
||||
thisBitmap = (@isBitmap) ? @bitmap : @bitmap.bitmap
|
||||
current = (@isBitmap) ? 0 : @bitmap.currentIndex
|
||||
if !@bitmaps[current]
|
||||
if @isTile
|
||||
@bitmaps[current] = pbBushDepthTile(thisBitmap, @depth)
|
||||
else
|
||||
@bitmaps[current] = pbBushDepthBitmap(thisBitmap, @depth)
|
||||
end
|
||||
end
|
||||
return @bitmaps[current]
|
||||
end
|
||||
|
||||
def pbBushDepthBitmap(bitmap, depth)
|
||||
ret = Bitmap.new(bitmap.width, bitmap.height)
|
||||
charheight = ret.height / 4
|
||||
cy = charheight - depth - 2
|
||||
for i in 0...4
|
||||
y = i * charheight
|
||||
if cy >= 0
|
||||
ret.blt(0, y, bitmap, Rect.new(0, y, ret.width, cy))
|
||||
ret.blt(0, y + cy, bitmap, Rect.new(0, y + cy, ret.width, 2), 170)
|
||||
end
|
||||
ret.blt(0, y + cy + 2, bitmap, Rect.new(0, y + cy + 2, ret.width, 2), 85) if cy + 2 >= 0
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def pbBushDepthTile(bitmap, depth)
|
||||
ret = Bitmap.new(bitmap.width, bitmap.height)
|
||||
charheight = ret.height
|
||||
cy = charheight - depth - 2
|
||||
y = charheight
|
||||
if cy >= 0
|
||||
ret.blt(0, y, bitmap, Rect.new(0, y, ret.width, cy))
|
||||
ret.blt(0, y + cy, bitmap, Rect.new(0, y + cy, ret.width, 2), 170)
|
||||
end
|
||||
ret.blt(0, y + cy + 2, bitmap, Rect.new(0, y + cy + 2, ret.width, 2), 85) if cy + 2 >= 0
|
||||
return ret
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class Sprite_Character < RPG::Sprite
|
||||
attr_accessor :character
|
||||
|
||||
def initialize(viewport, character = nil)
|
||||
super(viewport)
|
||||
@character = character
|
||||
@oldbushdepth = 0
|
||||
@spriteoffset = false
|
||||
if !character || character == $game_player || (character.name[/reflection/i] rescue false)
|
||||
@reflection = Sprite_Reflection.new(self, character, viewport)
|
||||
end
|
||||
@surfbase = Sprite_SurfBase.new(self, character, viewport) if character == $game_player
|
||||
update
|
||||
end
|
||||
|
||||
def groundY
|
||||
return @character.screen_y_ground
|
||||
end
|
||||
|
||||
def visible=(value)
|
||||
super(value)
|
||||
@reflection.visible = value if @reflection
|
||||
end
|
||||
|
||||
def dispose
|
||||
@bushbitmap.dispose if @bushbitmap
|
||||
@bushbitmap = nil
|
||||
@charbitmap.dispose if @charbitmap
|
||||
@charbitmap = nil
|
||||
@reflection.dispose if @reflection
|
||||
@reflection = nil
|
||||
@surfbase.dispose if @surfbase
|
||||
@surfbase = nil
|
||||
super
|
||||
end
|
||||
|
||||
def update
|
||||
return if @character.is_a?(Game_Event) && !@character.should_update?
|
||||
super
|
||||
if @tile_id != @character.tile_id ||
|
||||
@character_name != @character.character_name ||
|
||||
@character_hue != @character.character_hue ||
|
||||
@oldbushdepth != @character.bush_depth
|
||||
@tile_id = @character.tile_id
|
||||
@character_name = @character.character_name
|
||||
@character_hue = @character.character_hue
|
||||
@oldbushdepth = @character.bush_depth
|
||||
if @tile_id >= 384
|
||||
@charbitmap.dispose if @charbitmap
|
||||
@charbitmap = pbGetTileBitmap(@character.map.tileset_name, @tile_id,
|
||||
@character_hue, @character.width, @character.height)
|
||||
@charbitmapAnimated = false
|
||||
@bushbitmap.dispose if @bushbitmap
|
||||
@bushbitmap = nil
|
||||
@spriteoffset = false
|
||||
@cw = Game_Map::TILE_WIDTH * @character.width
|
||||
@ch = Game_Map::TILE_HEIGHT * @character.height
|
||||
self.src_rect.set(0, 0, @cw, @ch)
|
||||
self.ox = @cw / 2
|
||||
self.oy = @ch
|
||||
@character.sprite_size = [@cw, @ch]
|
||||
else
|
||||
@charbitmap.dispose if @charbitmap
|
||||
@charbitmap = AnimatedBitmap.new(
|
||||
'Graphics/Characters/' + @character_name, @character_hue)
|
||||
RPG::Cache.retain('Graphics/Characters/', @character_name, @character_hue) if @character == $game_player
|
||||
@charbitmapAnimated = true
|
||||
@bushbitmap.dispose if @bushbitmap
|
||||
@bushbitmap = nil
|
||||
@spriteoffset = @character_name[/offset/i]
|
||||
@cw = @charbitmap.width / 4
|
||||
@ch = @charbitmap.height / 4
|
||||
self.ox = @cw / 2
|
||||
@character.sprite_size = [@cw, @ch]
|
||||
end
|
||||
end
|
||||
@charbitmap.update if @charbitmapAnimated
|
||||
bushdepth = @character.bush_depth
|
||||
if bushdepth == 0
|
||||
self.bitmap = (@charbitmapAnimated) ? @charbitmap.bitmap : @charbitmap
|
||||
else
|
||||
@bushbitmap = BushBitmap.new(@charbitmap, (@tile_id >= 384), bushdepth) if !@bushbitmap
|
||||
self.bitmap = @bushbitmap.bitmap
|
||||
end
|
||||
self.visible = !@character.transparent
|
||||
if @tile_id == 0
|
||||
sx = @character.pattern * @cw
|
||||
sy = ((@character.direction - 2) / 2) * @ch
|
||||
self.src_rect.set(sx, sy, @cw, @ch)
|
||||
self.oy = (@spriteoffset rescue false) ? @ch - 16 : @ch
|
||||
self.oy -= @character.bob_height
|
||||
end
|
||||
if self.visible
|
||||
if @character.is_a?(Game_Event) && @character.name[/regulartone/i]
|
||||
self.tone.set(0, 0, 0, 0)
|
||||
else
|
||||
pbDayNightTint(self)
|
||||
end
|
||||
end
|
||||
self.x = @character.screen_x
|
||||
self.y = @character.screen_y
|
||||
self.z = @character.screen_z(@ch)
|
||||
# self.zoom_x = Game_Map::TILE_WIDTH / 32.0
|
||||
# self.zoom_y = Game_Map::TILE_HEIGHT / 32.0
|
||||
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
|
||||
@reflection.update if @reflection
|
||||
@surfbase.update if @surfbase
|
||||
end
|
||||
end
|
||||
86
Data/Scripts_backup/005_Sprites/004_Sprite_Reflection.rb
Normal file
86
Data/Scripts_backup/005_Sprites/004_Sprite_Reflection.rb
Normal file
@@ -0,0 +1,86 @@
|
||||
class Sprite_Reflection
|
||||
attr_reader :visible
|
||||
attr_accessor :event
|
||||
|
||||
def initialize(sprite,event,viewport=nil)
|
||||
@rsprite = sprite
|
||||
@sprite = nil
|
||||
@event = event
|
||||
@height = 0
|
||||
@fixedheight = false
|
||||
if @event && @event!=$game_player
|
||||
if @event.name[/reflection\((\d+)\)/i]
|
||||
@height = $~[1].to_i || 0
|
||||
@fixedheight = true
|
||||
end
|
||||
end
|
||||
@viewport = viewport
|
||||
@disposed = false
|
||||
update
|
||||
end
|
||||
|
||||
def dispose
|
||||
if !@disposed
|
||||
@sprite.dispose if @sprite
|
||||
@sprite = nil
|
||||
@disposed = true
|
||||
end
|
||||
end
|
||||
|
||||
def disposed?
|
||||
@disposed
|
||||
end
|
||||
|
||||
def visible=(value)
|
||||
@visible = value
|
||||
@sprite.visible = value if @sprite && !@sprite.disposed?
|
||||
end
|
||||
|
||||
def update
|
||||
return if disposed?
|
||||
shouldShow = @rsprite.visible
|
||||
if !shouldShow
|
||||
# Just-in-time disposal of sprite
|
||||
if @sprite
|
||||
@sprite.dispose
|
||||
@sprite = nil
|
||||
end
|
||||
return
|
||||
end
|
||||
# Just-in-time creation of sprite
|
||||
@sprite = Sprite.new(@viewport) if !@sprite
|
||||
if @sprite
|
||||
x = @rsprite.x-@rsprite.ox
|
||||
y = @rsprite.y-@rsprite.oy
|
||||
y -= 32 if @rsprite.character.character_name[/offset/i]
|
||||
@height = $PokemonGlobal.bridge if !@fixedheight
|
||||
y += @height*16
|
||||
width = @rsprite.src_rect.width
|
||||
height = @rsprite.src_rect.height
|
||||
@sprite.x = x+width/2
|
||||
@sprite.y = y+height+height/2
|
||||
@sprite.ox = width/2
|
||||
@sprite.oy = height/2-2 # Hard-coded 2 pixel shift up
|
||||
@sprite.oy -= @rsprite.character.bob_height*2
|
||||
@sprite.z = -50 # Still water is -100, map is 0 and above
|
||||
@sprite.zoom_x = @rsprite.zoom_x
|
||||
@sprite.zoom_y = @rsprite.zoom_y
|
||||
frame = (Graphics.frame_count%40)/10
|
||||
@sprite.zoom_x *= [1.0, 0.95, 1.0, 1.05][frame]
|
||||
@sprite.angle = 180.0
|
||||
@sprite.mirror = true
|
||||
@sprite.bitmap = @rsprite.bitmap
|
||||
@sprite.tone = @rsprite.tone
|
||||
if @height>0
|
||||
@sprite.color = Color.new(48,96,160,255) # Dark still water
|
||||
@sprite.opacity = @rsprite.opacity
|
||||
@sprite.visible = !Settings::TIME_SHADING # Can't time-tone a colored sprite
|
||||
else
|
||||
@sprite.color = Color.new(224,224,224,96)
|
||||
@sprite.opacity = @rsprite.opacity*3/4
|
||||
@sprite.visible = true
|
||||
end
|
||||
@sprite.src_rect = @rsprite.src_rect
|
||||
end
|
||||
end
|
||||
end
|
||||
83
Data/Scripts_backup/005_Sprites/005_Sprite_SurfBase.rb
Normal file
83
Data/Scripts_backup/005_Sprites/005_Sprite_SurfBase.rb
Normal file
@@ -0,0 +1,83 @@
|
||||
class Sprite_SurfBase
|
||||
attr_reader :visible
|
||||
attr_accessor :event
|
||||
|
||||
def initialize(sprite,event,viewport=nil)
|
||||
@rsprite = sprite
|
||||
@sprite = nil
|
||||
@event = event
|
||||
@viewport = viewport
|
||||
@disposed = false
|
||||
@surfbitmap = AnimatedBitmap.new("Graphics/Characters/base_surf")
|
||||
@divebitmap = AnimatedBitmap.new("Graphics/Characters/base_dive")
|
||||
RPG::Cache.retain("Graphics/Characters/base_surf")
|
||||
RPG::Cache.retain("Graphics/Characters/base_dive")
|
||||
@cws = @surfbitmap.width/4
|
||||
@chs = @surfbitmap.height/4
|
||||
@cwd = @divebitmap.width/4
|
||||
@chd = @divebitmap.height/4
|
||||
update
|
||||
end
|
||||
|
||||
def dispose
|
||||
return if @disposed
|
||||
@sprite.dispose if @sprite
|
||||
@sprite = nil
|
||||
@surfbitmap.dispose
|
||||
@divebitmap.dispose
|
||||
@disposed = true
|
||||
end
|
||||
|
||||
def disposed?
|
||||
@disposed
|
||||
end
|
||||
|
||||
def visible=(value)
|
||||
@visible = value
|
||||
@sprite.visible = value if @sprite && !@sprite.disposed?
|
||||
end
|
||||
|
||||
def update
|
||||
return if disposed?
|
||||
if !$PokemonGlobal.surfing && !$PokemonGlobal.diving
|
||||
# Just-in-time disposal of sprite
|
||||
if @sprite
|
||||
@sprite.dispose
|
||||
@sprite = nil
|
||||
end
|
||||
return
|
||||
end
|
||||
# Just-in-time creation of sprite
|
||||
@sprite = Sprite.new(@viewport) if !@sprite
|
||||
if @sprite
|
||||
if $PokemonGlobal.surfing
|
||||
@sprite.bitmap = @surfbitmap.bitmap
|
||||
cw = @cws
|
||||
ch = @chs
|
||||
elsif $PokemonGlobal.diving
|
||||
@sprite.bitmap = @divebitmap.bitmap
|
||||
cw = @cwd
|
||||
ch = @chd
|
||||
end
|
||||
sx = @event.pattern_surf*cw
|
||||
sy = ((@event.direction-2)/2)*ch
|
||||
@sprite.src_rect.set(sx,sy,cw,ch)
|
||||
if $PokemonTemp.surfJump
|
||||
@sprite.x = ($PokemonTemp.surfJump[0]*Game_Map::REAL_RES_X-@event.map.display_x+3)/4+(Game_Map::TILE_WIDTH/2)
|
||||
@sprite.y = ($PokemonTemp.surfJump[1]*Game_Map::REAL_RES_Y-@event.map.display_y+3)/4+(Game_Map::TILE_HEIGHT/2)+16
|
||||
else
|
||||
@sprite.x = @rsprite.x
|
||||
@sprite.y = @rsprite.y
|
||||
end
|
||||
@sprite.ox = cw/2
|
||||
@sprite.oy = ch-16 # Assume base needs offsetting
|
||||
@sprite.oy -= @event.bob_height
|
||||
@sprite.z = @event.screen_z(ch)-1
|
||||
@sprite.zoom_x = @rsprite.zoom_x
|
||||
@sprite.zoom_y = @rsprite.zoom_y
|
||||
@sprite.tone = @rsprite.tone
|
||||
@sprite.color = @rsprite.color
|
||||
@sprite.opacity = @rsprite.opacity
|
||||
end
|
||||
end
|
||||
end
|
||||
30
Data/Scripts_backup/005_Sprites/006_Spriteset_Global.rb
Normal file
30
Data/Scripts_backup/005_Sprites/006_Spriteset_Global.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
class Spriteset_Global
|
||||
attr_reader :playersprite
|
||||
@@viewport2 = Viewport.new(0, 0, Settings::SCREEN_WIDTH, Settings::SCREEN_HEIGHT)
|
||||
@@viewport2.z = 200
|
||||
|
||||
def initialize
|
||||
@playersprite = Sprite_Character.new(Spriteset_Map.viewport, $game_player)
|
||||
@picture_sprites = []
|
||||
for i in 1..100
|
||||
@picture_sprites.push(Sprite_Picture.new(@@viewport2, $game_screen.pictures[i]))
|
||||
end
|
||||
@timer_sprite = Sprite_Timer.new
|
||||
update
|
||||
end
|
||||
|
||||
def dispose
|
||||
@playersprite.dispose
|
||||
@picture_sprites.each { |sprite| sprite.dispose }
|
||||
@timer_sprite.dispose
|
||||
@playersprite = nil
|
||||
@picture_sprites.clear
|
||||
@timer_sprite = nil
|
||||
end
|
||||
|
||||
def update
|
||||
@playersprite.update
|
||||
@picture_sprites.each { |sprite| sprite.update }
|
||||
@timer_sprite.update
|
||||
end
|
||||
end
|
||||
149
Data/Scripts_backup/005_Sprites/007_Spriteset_Map.rb
Normal file
149
Data/Scripts_backup/005_Sprites/007_Spriteset_Map.rb
Normal file
@@ -0,0 +1,149 @@
|
||||
class ClippableSprite < Sprite_Character
|
||||
def initialize(viewport,event,tilemap)
|
||||
@tilemap = tilemap
|
||||
@_src_rect = Rect.new(0,0,0,0)
|
||||
super(viewport,event)
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
@_src_rect = self.src_rect
|
||||
tmright = @tilemap.map_data.xsize*Game_Map::TILE_WIDTH-@tilemap.ox
|
||||
echoln("x=#{self.x},ox=#{self.ox},tmright=#{tmright},tmox=#{@tilemap.ox}")
|
||||
if @tilemap.ox-self.ox<-self.x
|
||||
# clipped on left
|
||||
diff = -self.x-@tilemap.ox+self.ox
|
||||
self.src_rect = Rect.new(@_src_rect.x+diff,@_src_rect.y,
|
||||
@_src_rect.width-diff,@_src_rect.height)
|
||||
echoln("clipped out left: #{diff} #{@tilemap.ox-self.ox} #{self.x}")
|
||||
elsif tmright-self.ox<self.x
|
||||
# clipped on right
|
||||
diff = self.x-tmright+self.ox
|
||||
self.src_rect = Rect.new(@_src_rect.x,@_src_rect.y,
|
||||
@_src_rect.width-diff,@_src_rect.height)
|
||||
echoln("clipped out right: #{diff} #{tmright+self.ox} #{self.x}")
|
||||
else
|
||||
echoln("-not- clipped out left: #{diff} #{@tilemap.ox-self.ox} #{self.x}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class Spriteset_Map
|
||||
attr_reader :map
|
||||
attr_accessor :tilemap
|
||||
@@viewport0 = Viewport.new(0, 0, Settings::SCREEN_WIDTH, Settings::SCREEN_HEIGHT) # Panorama
|
||||
@@viewport0.z = -100
|
||||
@@viewport1 = Viewport.new(0, 0, Settings::SCREEN_WIDTH, Settings::SCREEN_HEIGHT) # Map, events, player, fog
|
||||
@@viewport1.z = 0
|
||||
@@viewport3 = Viewport.new(0, 0, Settings::SCREEN_WIDTH, Settings::SCREEN_HEIGHT) # Flashing
|
||||
@@viewport3.z = 500
|
||||
|
||||
def Spriteset_Map.viewport # For access by Spriteset_Global
|
||||
return @@viewport1
|
||||
end
|
||||
|
||||
def initialize(map=nil)
|
||||
@map = (map) ? map : $game_map
|
||||
@tilemap = TilemapLoader.new(@@viewport1)
|
||||
@tilemap.tileset = pbGetTileset(@map.tileset_name)
|
||||
for i in 0...7
|
||||
autotile_name = @map.autotile_names[i]
|
||||
@tilemap.autotiles[i] = pbGetAutotile(autotile_name)
|
||||
end
|
||||
@tilemap.map_data = @map.data
|
||||
@tilemap.priorities = @map.priorities
|
||||
@tilemap.terrain_tags = @map.terrain_tags
|
||||
@panorama = AnimatedPlane.new(@@viewport0)
|
||||
@fog = AnimatedPlane.new(@@viewport1)
|
||||
@fog.z = 3000
|
||||
@character_sprites = []
|
||||
for i in @map.events.keys.sort
|
||||
sprite = Sprite_Character.new(@@viewport1,@map.events[i])
|
||||
@character_sprites.push(sprite)
|
||||
end
|
||||
@weather = RPG::Weather.new(@@viewport1)
|
||||
pbOnSpritesetCreate(self,@@viewport1)
|
||||
update
|
||||
end
|
||||
|
||||
def dispose
|
||||
@tilemap.tileset.dispose
|
||||
for i in 0...7
|
||||
@tilemap.autotiles[i].dispose
|
||||
end
|
||||
@tilemap.dispose
|
||||
@panorama.dispose
|
||||
@fog.dispose
|
||||
for sprite in @character_sprites
|
||||
sprite.dispose
|
||||
end
|
||||
@weather.dispose
|
||||
@tilemap = nil
|
||||
@panorama = nil
|
||||
@fog = nil
|
||||
@character_sprites.clear
|
||||
@weather = nil
|
||||
end
|
||||
|
||||
def getAnimations
|
||||
return @usersprites
|
||||
end
|
||||
|
||||
def restoreAnimations(anims)
|
||||
@usersprites = anims
|
||||
end
|
||||
|
||||
def update
|
||||
if @panorama_name!=@map.panorama_name || @panorama_hue!=@map.panorama_hue
|
||||
@panorama_name = @map.panorama_name
|
||||
@panorama_hue = @map.panorama_hue
|
||||
@panorama.setPanorama(nil) if @panorama.bitmap!=nil
|
||||
@panorama.setPanorama(@panorama_name,@panorama_hue) if @panorama_name!=""
|
||||
Graphics.frame_reset
|
||||
end
|
||||
if @fog_name!=@map.fog_name || @fog_hue!=@map.fog_hue
|
||||
@fog_name = @map.fog_name
|
||||
@fog_hue = @map.fog_hue
|
||||
@fog.setFog(nil) if @fog.bitmap!=nil
|
||||
@fog.setFog(@fog_name,@fog_hue) if @fog_name!=""
|
||||
Graphics.frame_reset
|
||||
end
|
||||
tmox = (@map.display_x/Game_Map::X_SUBPIXELS).round
|
||||
tmoy = (@map.display_y/Game_Map::Y_SUBPIXELS).round
|
||||
@tilemap.ox = tmox
|
||||
@tilemap.oy = tmoy
|
||||
@@viewport1.rect.set(0,0,Graphics.width,Graphics.height)
|
||||
@@viewport1.ox = 0
|
||||
@@viewport1.oy = 0
|
||||
@@viewport1.ox += $game_screen.shake
|
||||
@tilemap.update
|
||||
@panorama.ox = tmox/2
|
||||
@panorama.oy = tmoy/2
|
||||
@fog.ox = tmox+@map.fog_ox
|
||||
@fog.oy = tmoy+@map.fog_oy
|
||||
@fog.zoom_x = @map.fog_zoom/100.0
|
||||
@fog.zoom_y = @map.fog_zoom/100.0
|
||||
@fog.opacity = @map.fog_opacity
|
||||
@fog.blend_type = @map.fog_blend_type
|
||||
@fog.tone = @map.fog_tone
|
||||
@panorama.update
|
||||
@fog.update
|
||||
for sprite in @character_sprites
|
||||
sprite.update
|
||||
end
|
||||
if self.map!=$game_map
|
||||
@weather.fade_in(:None, 0, 20)
|
||||
else
|
||||
@weather.fade_in($game_screen.weather_type, $game_screen.weather_max, $game_screen.weather_duration)
|
||||
end
|
||||
@weather.ox = tmox
|
||||
@weather.oy = tmoy
|
||||
@weather.update
|
||||
@@viewport1.tone = $game_screen.tone
|
||||
@@viewport3.color = $game_screen.flash_color
|
||||
@@viewport1.update
|
||||
@@viewport3.update
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,86 @@
|
||||
=begin
|
||||
A sprite whose sole purpose is to display an animation. This sprite
|
||||
can be displayed anywhere on the map and is disposed
|
||||
automatically when its animation is finished.
|
||||
Used for grass rustling and so forth.
|
||||
=end
|
||||
class AnimationSprite < RPG::Sprite
|
||||
def initialize(animID,map,tileX,tileY,viewport=nil,tinting=false,height=3)
|
||||
super(viewport)
|
||||
@tileX = tileX
|
||||
@tileY = tileY
|
||||
self.bitmap = Bitmap.new(1, 1)
|
||||
self.bitmap.clear
|
||||
@map = map
|
||||
setCoords
|
||||
pbDayNightTint(self) if tinting
|
||||
self.animation($data_animations[animID],true,height)
|
||||
end
|
||||
|
||||
def setCoords
|
||||
self.x = ((@tileX * Game_Map::REAL_RES_X - @map.display_x) / Game_Map::X_SUBPIXELS).ceil
|
||||
self.x += Game_Map::TILE_WIDTH / 2
|
||||
self.y = ((@tileY * Game_Map::REAL_RES_Y - @map.display_y) / Game_Map::Y_SUBPIXELS).ceil
|
||||
self.y += Game_Map::TILE_HEIGHT
|
||||
end
|
||||
|
||||
def dispose
|
||||
self.bitmap.dispose
|
||||
super
|
||||
end
|
||||
|
||||
def update
|
||||
if !self.disposed?
|
||||
setCoords
|
||||
super
|
||||
self.dispose if !self.effect?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class Spriteset_Map
|
||||
alias _animationSprite_initialize initialize
|
||||
alias _animationSprite_update update
|
||||
alias _animationSprite_dispose dispose
|
||||
|
||||
def initialize(map=nil)
|
||||
@usersprites=[]
|
||||
_animationSprite_initialize(map)
|
||||
end
|
||||
|
||||
def addUserAnimation(animID,x,y,tinting=false,height=3)
|
||||
sprite=AnimationSprite.new(animID,$game_map,x,y,@@viewport1,tinting,height)
|
||||
addUserSprite(sprite)
|
||||
return sprite
|
||||
end
|
||||
|
||||
def addUserSprite(sprite)
|
||||
for i in 0...@usersprites.length
|
||||
if @usersprites[i]==nil || @usersprites[i].disposed?
|
||||
@usersprites[i]=sprite
|
||||
return
|
||||
end
|
||||
end
|
||||
@usersprites.push(sprite)
|
||||
end
|
||||
|
||||
def dispose
|
||||
_animationSprite_dispose
|
||||
for i in 0...@usersprites.length
|
||||
@usersprites[i].dispose
|
||||
end
|
||||
@usersprites.clear
|
||||
end
|
||||
|
||||
def update
|
||||
return if @tilemap.disposed?
|
||||
pbDayNightTint(@tilemap)
|
||||
@@viewport3.tone.set(0,0,0,0)
|
||||
_animationSprite_update
|
||||
for i in 0...@usersprites.length
|
||||
@usersprites[i].update if !@usersprites[i].disposed?
|
||||
end
|
||||
end
|
||||
end
|
||||
258
Data/Scripts_backup/005_Sprites/009_Sprite_DynamicShadows.rb
Normal file
258
Data/Scripts_backup/005_Sprites/009_Sprite_DynamicShadows.rb
Normal file
@@ -0,0 +1,258 @@
|
||||
#===============================================================================
|
||||
# Sprite_Shadow (Sprite_Ombre )
|
||||
# Based on Genzai Kawakami's shadows, dynamisme & features by Rataime, extra
|
||||
# features Boushy
|
||||
# Modified by Peter O. to be compatible with Pokémon Essentials
|
||||
#===============================================================================
|
||||
class Sprite_Shadow < RPG::Sprite
|
||||
attr_accessor :character
|
||||
|
||||
def initialize(viewport, character = nil,params=[])
|
||||
super(viewport)
|
||||
@source = params[0]
|
||||
@anglemin = (params.size>1) ? params[1] : 0
|
||||
@anglemax = (params.size>2) ? params[2] : 0
|
||||
@self_opacity = (params.size>4) ? params[4] : 100
|
||||
@distancemax = (params.size>3) ? params[3] : 350
|
||||
@character = character
|
||||
update
|
||||
end
|
||||
|
||||
def dispose
|
||||
@chbitmap.dispose if @chbitmap
|
||||
super
|
||||
end
|
||||
|
||||
def update
|
||||
if !in_range?(@character, @source, @distancemax)
|
||||
self.opacity = 0
|
||||
return
|
||||
end
|
||||
super
|
||||
if @tile_id != @character.tile_id ||
|
||||
@character_name != @character.character_name ||
|
||||
@character_hue != @character.character_hue
|
||||
@tile_id = @character.tile_id
|
||||
@character_name = @character.character_name
|
||||
@character_hue = @character.character_hue
|
||||
if @tile_id >= 384
|
||||
@chbitmap.dispose if @chbitmap
|
||||
@chbitmap = pbGetTileBitmap(@character.map.tileset_name,
|
||||
@tile_id, @character.character_hue)
|
||||
self.src_rect.set(0, 0, 32, 32)
|
||||
@ch = 32
|
||||
@cw = 32
|
||||
self.ox = 16
|
||||
self.oy = 32
|
||||
else
|
||||
@chbitmap.dispose if @chbitmap
|
||||
@chbitmap = AnimatedBitmap.new(
|
||||
'Graphics/Characters/'+@character.character_name,@character.character_hue)
|
||||
@cw = @chbitmap.width / 4
|
||||
@ch = @chbitmap.height / 4
|
||||
self.ox = @cw / 2
|
||||
self.oy = @ch
|
||||
end
|
||||
end
|
||||
if @chbitmap.is_a?(AnimatedBitmap)
|
||||
@chbitmap.update
|
||||
self.bitmap = @chbitmap.bitmap
|
||||
else
|
||||
self.bitmap = @chbitmap
|
||||
end
|
||||
self.visible = !@character.transparent
|
||||
if @tile_id == 0
|
||||
sx = @character.pattern * @cw
|
||||
sy = (@character.direction - 2) / 2 * @ch
|
||||
if self.angle > 90 || angle < -90
|
||||
case @character.direction
|
||||
when 2 then sy = @ch * 3
|
||||
when 4 then sy = @ch * 2
|
||||
when 6 then sy = @ch
|
||||
when 8 then sy = 0
|
||||
end
|
||||
end
|
||||
self.src_rect.set(sx, sy, @cw, @ch)
|
||||
end
|
||||
self.x = ScreenPosHelper.pbScreenX(@character)
|
||||
self.y = ScreenPosHelper.pbScreenY(@character)-5
|
||||
self.z = ScreenPosHelper.pbScreenZ(@character,@ch)-1
|
||||
self.zoom_x = ScreenPosHelper.pbScreenZoomX(@character)
|
||||
self.zoom_y = ScreenPosHelper.pbScreenZoomY(@character)
|
||||
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
|
||||
@deltax = ScreenPosHelper.pbScreenX(@source) - self.x
|
||||
@deltay = ScreenPosHelper.pbScreenY(@source) - self.y
|
||||
self.color = Color.new(0, 0, 0)
|
||||
@distance = ((@deltax ** 2) + (@deltay ** 2))
|
||||
self.opacity = @self_opacity * 13000 / ((@distance * 370 / @distancemax) + 6000)
|
||||
self.angle = 57.3 * Math.atan2(@deltax, @deltay)
|
||||
@angle_trigo = self.angle+90
|
||||
@angle_trigo += 360 if @angle_trigo < 0
|
||||
if @anglemin != 0 || @anglemax != 0
|
||||
if (@angle_trigo < @anglemin || @angle_trigo > @anglemax) && @anglemin < @anglemax
|
||||
self.opacity = 0
|
||||
return
|
||||
end
|
||||
if @angle_trigo < @anglemin && @angle_trigo > @anglemax && @anglemin > @anglemax
|
||||
self.opacity = 0
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def in_range?(element, object, range) # From Near's Anti Lag Script, edited
|
||||
elemScreenX = ScreenPosHelper.pbScreenX(element)
|
||||
elemScreenY = ScreenPosHelper.pbScreenY(element)
|
||||
objScreenX = ScreenPosHelper.pbScreenX(object)
|
||||
objScreenY = ScreenPosHelper.pbScreenY(object)
|
||||
x = (elemScreenX - objScreenX) * (elemScreenX - objScreenX)
|
||||
y = (elemScreenY - objScreenY) * (elemScreenY - objScreenY)
|
||||
r = x + y
|
||||
return r <= range * range
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===================================================
|
||||
# ? CLASS Sprite_Character edit
|
||||
#===================================================
|
||||
class Sprite_Character < RPG::Sprite
|
||||
alias :shadow_initialize :initialize
|
||||
|
||||
def initialize(viewport, character = nil)
|
||||
@ombrelist = []
|
||||
@character = character
|
||||
shadow_initialize(viewport, @character)
|
||||
end
|
||||
|
||||
def setShadows(map,shadows)
|
||||
if character.is_a?(Game_Event) && shadows.length > 0
|
||||
params = XPML_read(map,"Shadow",@character,4)
|
||||
if params != nil
|
||||
for i in 0...shadows.size
|
||||
@ombrelist.push(Sprite_Shadow.new(viewport, @character, shadows[i]))
|
||||
end
|
||||
end
|
||||
end
|
||||
if character.is_a?(Game_Player) && shadows.length > 0
|
||||
for i in 0...shadows.size
|
||||
@ombrelist.push(Sprite_Shadow.new(viewport, $game_player, shadows[i]))
|
||||
end
|
||||
end
|
||||
update
|
||||
end
|
||||
|
||||
def clearShadows
|
||||
@ombrelist.each { |s| s.dispose if s }
|
||||
@ombrelist.clear
|
||||
end
|
||||
|
||||
alias shadow_update update
|
||||
|
||||
def update
|
||||
shadow_update
|
||||
if @ombrelist.length>0
|
||||
for i in 0...@ombrelist.size
|
||||
@ombrelist[i].update
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===================================================
|
||||
# ? CLASS Game_Event edit
|
||||
#===================================================
|
||||
class Game_Event
|
||||
attr_accessor :id
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===================================================
|
||||
# ? CLASS Spriteset_Map edit
|
||||
#===================================================
|
||||
class Spriteset_Map
|
||||
attr_accessor :shadows
|
||||
|
||||
alias shadow_initialize initialize
|
||||
def initialize(map=nil)
|
||||
@shadows = []
|
||||
warn = false
|
||||
map = $game_map if !map
|
||||
for k in map.events.keys.sort
|
||||
ev = map.events[k]
|
||||
warn = true if (ev.list != nil && ev.list.length > 0 &&
|
||||
ev.list[0].code == 108 &&
|
||||
(ev.list[0].parameters == ["s"] || ev.list[0].parameters == ["o"]))
|
||||
params = XPML_read(map,"Shadow Source", ev, 4)
|
||||
@shadows.push([ev] + params) if params != nil
|
||||
end
|
||||
if warn == true
|
||||
p "Warning : At least one event on this map uses the obsolete way to add shadows"
|
||||
end
|
||||
shadow_initialize(map)
|
||||
for sprite in @character_sprites
|
||||
sprite.setShadows(map, @shadows)
|
||||
end
|
||||
$scene.spritesetGlobal.playersprite.setShadows(map, @shadows)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===================================================
|
||||
# ? XPML Definition, by Rataime, using ideas from Near Fantastica
|
||||
#
|
||||
# Returns nil if the markup wasn't present at all,
|
||||
# returns [] if there wasn't any parameters, else
|
||||
# returns a parameters list with "int" converted as int
|
||||
# eg :
|
||||
# begin first
|
||||
# begin second
|
||||
# param1 1
|
||||
# param2 two
|
||||
# begin third
|
||||
# anything 3
|
||||
#
|
||||
# p XPML_read("first", event_id) -> []
|
||||
# p XPML_read("second", event_id) -> [1, "two"]
|
||||
# p XPML_read("third", event_id) -> [3]
|
||||
# p XPML_read("forth", event_id) -> nil
|
||||
#===================================================
|
||||
def XPML_read(map,markup,event,max_param_number=0)
|
||||
parameter_list = nil
|
||||
return nil if !event || event.list == nil
|
||||
for i in 0...event.list.size
|
||||
if event.list[i].code == 108 &&
|
||||
event.list[i].parameters[0].downcase == "begin " + markup.downcase
|
||||
parameter_list = [] if parameter_list == nil
|
||||
for j in i+1...event.list.size
|
||||
if event.list[j].code == 108
|
||||
parts = event.list[j].parameters[0].split
|
||||
if parts.size != 1 && parts[0].downcase != "begin"
|
||||
if parts[1].to_i != 0 || parts[1] == "0"
|
||||
parameter_list.push(parts[1].to_i)
|
||||
else
|
||||
parameter_list.push(parts[1])
|
||||
end
|
||||
else
|
||||
return parameter_list
|
||||
end
|
||||
else
|
||||
return parameter_list
|
||||
end
|
||||
return parameter_list if max_param_number != 0 && j == i + max_param_number
|
||||
end
|
||||
end
|
||||
end
|
||||
return parameter_list
|
||||
end
|
||||
587
Data/Scripts_backup/005_Sprites/010_ParticleEngine.rb
Normal file
587
Data/Scripts_backup/005_Sprites/010_ParticleEngine.rb
Normal file
@@ -0,0 +1,587 @@
|
||||
# Particle Engine, Peter O., 2007-11-03
|
||||
# Based on version 2 by Near Fantastica, 04.01.06
|
||||
# In turn based on the Particle Engine designed by PinkMan
|
||||
class Particle_Engine
|
||||
def initialize(viewport=nil,map=nil)
|
||||
@map = (map) ? map : $game_map
|
||||
@viewport = viewport
|
||||
@effect = []
|
||||
@disposed = false
|
||||
@firsttime = true
|
||||
@effects = {
|
||||
# PinkMan's Effects
|
||||
"fire" => Particle_Engine::Fire,
|
||||
"smoke" => Particle_Engine::Smoke,
|
||||
"teleport" => Particle_Engine::Teleport,
|
||||
"spirit" => Particle_Engine::Spirit,
|
||||
"explosion" => Particle_Engine::Explosion,
|
||||
"aura" => Particle_Engine::Aura,
|
||||
# BlueScope's Effects
|
||||
"soot" => Particle_Engine::Soot,
|
||||
"sootsmoke" => Particle_Engine::SootSmoke,
|
||||
"rocket" => Particle_Engine::Rocket,
|
||||
"fixteleport" => Particle_Engine::FixedTeleport,
|
||||
"smokescreen" => Particle_Engine::Smokescreen,
|
||||
"flare" => Particle_Engine::Flare,
|
||||
"splash" => Particle_Engine::Splash,
|
||||
# By Peter O.
|
||||
"starteleport" => Particle_Engine::StarTeleport
|
||||
}
|
||||
end
|
||||
|
||||
def dispose
|
||||
return if disposed?
|
||||
for particle in @effect
|
||||
next if particle.nil?
|
||||
particle.dispose
|
||||
end
|
||||
@effect.clear
|
||||
@map = nil
|
||||
@disposed = true
|
||||
end
|
||||
|
||||
def disposed?
|
||||
return @disposed
|
||||
end
|
||||
|
||||
def add_effect(event)
|
||||
@effect[event.id] = pbParticleEffect(event)
|
||||
end
|
||||
|
||||
def remove_effect(event)
|
||||
return if @effect[event.id].nil?
|
||||
@effect[event.id].dispose
|
||||
@effect.delete_at(event.id)
|
||||
end
|
||||
|
||||
def realloc_effect(event,particle)
|
||||
type = pbEventCommentInput(event, 1, "Particle Engine Type")
|
||||
if type.nil?
|
||||
particle.dispose if particle
|
||||
return nil
|
||||
end
|
||||
type = type[0].downcase
|
||||
cls = @effects[type]
|
||||
if cls.nil?
|
||||
particle.dispose if particle
|
||||
return nil
|
||||
end
|
||||
if !particle || !particle.is_a?(cls)
|
||||
particle.dispose if particle
|
||||
particle = cls.new(event,@viewport)
|
||||
end
|
||||
return particle
|
||||
end
|
||||
|
||||
def pbParticleEffect(event)
|
||||
return realloc_effect(event,nil)
|
||||
end
|
||||
|
||||
def update
|
||||
if @firsttime
|
||||
@firsttime = false
|
||||
for event in @map.events.values
|
||||
remove_effect(event)
|
||||
add_effect(event)
|
||||
end
|
||||
end
|
||||
for i in 0...@effect.length
|
||||
particle = @effect[i]
|
||||
next if particle.nil?
|
||||
if particle.event.pe_refresh
|
||||
event = particle.event
|
||||
event.pe_refresh = false
|
||||
particle = realloc_effect(event,particle)
|
||||
@effect[i] = particle
|
||||
end
|
||||
particle.update if particle
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class ParticleEffect
|
||||
attr_accessor :x, :y, :z
|
||||
|
||||
def initialize
|
||||
@x = 0
|
||||
@y = 0
|
||||
@z = 0
|
||||
end
|
||||
|
||||
def update; end
|
||||
def dispose; end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class ParticleSprite
|
||||
attr_accessor :x, :y, :z, :ox, :oy, :opacity, :blend_type
|
||||
attr_reader :bitmap
|
||||
|
||||
def initialize(viewport)
|
||||
@viewport = viewport
|
||||
@sprite = nil
|
||||
@x = 0
|
||||
@y = 0
|
||||
@z = 0
|
||||
@ox = 0
|
||||
@oy = 0
|
||||
@opacity = 255
|
||||
@bitmap = nil
|
||||
@blend_type = 0
|
||||
@minleft = 0
|
||||
@mintop = 0
|
||||
end
|
||||
|
||||
def dispose
|
||||
@sprite.dispose if @sprite
|
||||
end
|
||||
|
||||
def bitmap=(value)
|
||||
@bitmap = value
|
||||
if value
|
||||
@minleft = -value.width
|
||||
@mintop = -value.height
|
||||
else
|
||||
@minleft = 0
|
||||
@mintop = 0
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
w = Graphics.width
|
||||
h = Graphics.height
|
||||
if !@sprite && @x>=@minleft && @y>=@mintop && @x<w && @y<h
|
||||
@sprite = Sprite.new(@viewport)
|
||||
elsif @sprite && (@x<@minleft || @y<@mintop || @x>=w || @y>=h)
|
||||
@sprite.dispose
|
||||
@sprite = nil
|
||||
end
|
||||
if @sprite
|
||||
@sprite.x = @x if @sprite.x!=@x
|
||||
@sprite.x -= @ox
|
||||
@sprite.y = @y if @sprite.y!=@y
|
||||
@sprite.y -= @oy
|
||||
@sprite.z = @z if @sprite.z!=@z
|
||||
@sprite.opacity = @opacity if @sprite.opacity!=@opacity
|
||||
@sprite.blend_type = @blend_type if @sprite.blend_type!=@blend_type
|
||||
@sprite.bitmap = @bitmap if @sprite.bitmap!=@bitmap
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class ParticleEffect_Event < ParticleEffect
|
||||
attr_accessor :event
|
||||
|
||||
def initialize(event,viewport=nil)
|
||||
@event = event
|
||||
@viewport = viewport
|
||||
@particles = []
|
||||
@bitmaps = {}
|
||||
end
|
||||
|
||||
def setParameters(params)
|
||||
@randomhue,@leftright,@fade,
|
||||
@maxparticless,@hue,@slowdown,
|
||||
@ytop,@ybottom,@xleft,@xright,
|
||||
@xgravity,@ygravity,@xoffset,@yoffset,
|
||||
@opacityvar,@originalopacity = params
|
||||
end
|
||||
|
||||
def loadBitmap(filename,hue)
|
||||
key = [filename,hue]
|
||||
bitmap = @bitmaps[key]
|
||||
if !bitmap || bitmap.disposed?
|
||||
bitmap = AnimatedBitmap.new("Graphics/Fogs/"+filename,hue).deanimate
|
||||
@bitmaps[key] = bitmap
|
||||
end
|
||||
return bitmap
|
||||
end
|
||||
|
||||
def initParticles(filename,opacity,zOffset=0,blendtype=1)
|
||||
@particles = []
|
||||
@particlex = []
|
||||
@particley = []
|
||||
@opacity = []
|
||||
@startingx = self.x + @xoffset
|
||||
@startingy = self.y + @yoffset
|
||||
@screen_x = self.x
|
||||
@screen_y = self.y
|
||||
@real_x = @event.real_x
|
||||
@real_y = @event.real_y
|
||||
@filename = filename
|
||||
@zoffset = zOffset
|
||||
@bmwidth = 32
|
||||
@bmheight = 32
|
||||
for i in 0...@maxparticless
|
||||
@particlex[i] = -@xoffset
|
||||
@particley[i] = -@yoffset
|
||||
@particles[i] = ParticleSprite.new(@viewport)
|
||||
@particles[i].bitmap = loadBitmap(filename, @hue) if filename
|
||||
if i==0 && @particles[i].bitmap
|
||||
@bmwidth = @particles[i].bitmap.width
|
||||
@bmheight = @particles[i].bitmap.height
|
||||
end
|
||||
@particles[i].blend_type = blendtype
|
||||
@particles[i].y = @startingy
|
||||
@particles[i].x = @startingx
|
||||
@particles[i].z = self.z+zOffset
|
||||
@opacity[i] = rand(opacity/4)
|
||||
@particles[i].opacity = @opacity[i]
|
||||
@particles[i].update
|
||||
end
|
||||
end
|
||||
|
||||
def x; return ScreenPosHelper.pbScreenX(@event); end
|
||||
def y; return ScreenPosHelper.pbScreenY(@event); end
|
||||
def z; return ScreenPosHelper.pbScreenZ(@event); end
|
||||
|
||||
def update
|
||||
if @viewport &&
|
||||
(@viewport.rect.x >= Graphics.width ||
|
||||
@viewport.rect.y >= Graphics.height)
|
||||
return
|
||||
end
|
||||
selfX = self.x
|
||||
selfY = self.y
|
||||
selfZ = self.z
|
||||
newRealX = @event.real_x
|
||||
newRealY = @event.real_y
|
||||
@startingx = selfX + @xoffset
|
||||
@startingy = selfY + @yoffset
|
||||
@__offsetx = (@real_x==newRealX) ? 0 : selfX-@screen_x
|
||||
@__offsety = (@real_y==newRealY) ? 0 : selfY-@screen_y
|
||||
@screen_x = selfX
|
||||
@screen_y = selfY
|
||||
@real_x = newRealX
|
||||
@real_y = newRealY
|
||||
if @opacityvar>0 && @viewport
|
||||
opac = 255.0/@opacityvar
|
||||
minX = opac*(-@xgravity*1.0 / @slowdown).floor + @startingx
|
||||
maxX = opac*(@xgravity*1.0 / @slowdown).floor + @startingx
|
||||
minY = opac*(-@ygravity*1.0 / @slowdown).floor + @startingy
|
||||
maxY = @startingy
|
||||
minX -= @bmwidth
|
||||
minY -= @bmheight
|
||||
maxX += @bmwidth
|
||||
maxY += @bmheight
|
||||
if maxX<0 || maxY<0 || minX>=Graphics.width || minY>=Graphics.height
|
||||
# echo "skipped"
|
||||
return
|
||||
end
|
||||
end
|
||||
particleZ = selfZ+@zoffset
|
||||
for i in 0...@maxparticless
|
||||
@particles[i].z = particleZ
|
||||
if @particles[i].y <= @ytop
|
||||
@particles[i].y = @startingy + @yoffset
|
||||
@particles[i].x = @startingx + @xoffset
|
||||
@particlex[i] = 0.0
|
||||
@particley[i] = 0.0
|
||||
end
|
||||
if @particles[i].x <= @xleft
|
||||
@particles[i].y = @startingy + @yoffset
|
||||
@particles[i].x = @startingx + @xoffset
|
||||
@particlex[i] = 0.0
|
||||
@particley[i] = 0.0
|
||||
end
|
||||
if @particles[i].y >= @ybottom
|
||||
@particles[i].y = @startingy + @yoffset
|
||||
@particles[i].x = @startingx + @xoffset
|
||||
@particlex[i] = 0.0
|
||||
@particley[i] = 0.0
|
||||
end
|
||||
if @particles[i].x >= @xright
|
||||
@particles[i].y = @startingy + @yoffset
|
||||
@particles[i].x = @startingx + @xoffset
|
||||
@particlex[i] = 0.0
|
||||
@particley[i] = 0.0
|
||||
end
|
||||
if @fade == 0
|
||||
if @opacity[i] <= 0
|
||||
@opacity[i] = @originalopacity
|
||||
@particles[i].y = @startingy + @yoffset
|
||||
@particles[i].x = @startingx + @xoffset
|
||||
@particlex[i] = 0.0
|
||||
@particley[i] = 0.0
|
||||
end
|
||||
else
|
||||
if @opacity[i] <= 0
|
||||
@opacity[i] = 250
|
||||
@particles[i].y = @startingy + @yoffset
|
||||
@particles[i].x = @startingx + @xoffset
|
||||
@particlex[i] = 0.0
|
||||
@particley[i] = 0.0
|
||||
end
|
||||
end
|
||||
calcParticlePos(i)
|
||||
if @randomhue == 1
|
||||
@hue += 0.5
|
||||
@hue = 0 if @hue >= 360
|
||||
@particles[i].bitmap = loadBitmap(@filename, @hue) if @filename
|
||||
end
|
||||
@opacity[i] = @opacity[i] - rand(@opacityvar)
|
||||
@particles[i].opacity = @opacity[i]
|
||||
@particles[i].update
|
||||
end
|
||||
end
|
||||
|
||||
def calcParticlePos(i)
|
||||
@leftright = rand(2)
|
||||
if @leftright == 1
|
||||
xo = -@xgravity*1.0 / @slowdown
|
||||
else
|
||||
xo = @xgravity*1.0 / @slowdown
|
||||
end
|
||||
yo = -@ygravity*1.0 / @slowdown
|
||||
@particlex[i] += xo
|
||||
@particley[i] += yo
|
||||
@particlex[i] -= @__offsetx
|
||||
@particley[i] -= @__offsety
|
||||
@particlex[i] = @particlex[i].floor
|
||||
@particley[i] = @particley[i].floor
|
||||
@particles[i].x = @particlex[i]+@startingx+@xoffset
|
||||
@particles[i].y = @particley[i]+@startingy+@yoffset
|
||||
end
|
||||
|
||||
def dispose
|
||||
for particle in @particles
|
||||
particle.dispose
|
||||
end
|
||||
for bitmap in @bitmaps.values
|
||||
bitmap.dispose
|
||||
end
|
||||
@particles.clear
|
||||
@bitmaps.clear
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class Particle_Engine::Fire < ParticleEffect_Event
|
||||
def initialize(event,viewport)
|
||||
super
|
||||
setParameters([0,0,1,20,40,0.5,-64,
|
||||
Graphics.height,-64,Graphics.width,0.5,0.10,-5,-13,30,0])
|
||||
initParticles("particle",250)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class Particle_Engine::Smoke < ParticleEffect_Event
|
||||
def initialize(event,viewport)
|
||||
super
|
||||
setParameters([0,0,0,80,20,0.5,-64,
|
||||
Graphics.height,-64,Graphics.width,0.5,0.10,-5,-15,5,80])
|
||||
initParticles("smoke",250)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class Particle_Engine::Teleport < ParticleEffect_Event
|
||||
def initialize(event,viewport)
|
||||
super
|
||||
setParameters([1,1,1,10,rand(360),1,-64,
|
||||
Graphics.height,-64,Graphics.width,0,3,-8,-15,20,0])
|
||||
initParticles("wideportal",250)
|
||||
for i in 0...@maxparticless
|
||||
@particles[i].ox = 16
|
||||
@particles[i].oy = 16
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class Particle_Engine::Spirit < ParticleEffect_Event
|
||||
def initialize(event,viewport)
|
||||
super
|
||||
setParameters([1,0,1,20,rand(360),0.5,-64,
|
||||
Graphics.height,-64,Graphics.width,0.5,0.10,-5,-13,30,0])
|
||||
initParticles("particle",250)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class Particle_Engine::Explosion < ParticleEffect_Event
|
||||
def initialize(event,viewport)
|
||||
super
|
||||
setParameters([0,0,1,20,0,0.5,-64,
|
||||
Graphics.height,-64,Graphics.width,0.5,0.10,-5,-13,30,0])
|
||||
initParticles("explosion",250)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class Particle_Engine::Aura < ParticleEffect_Event
|
||||
def initialize(event,viewport)
|
||||
super
|
||||
setParameters([0,0,1,20,0,1,-64,
|
||||
Graphics.height,-64,Graphics.width,2,2,-5,-13,30,0])
|
||||
initParticles("particle",250)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class Particle_Engine::Soot < ParticleEffect_Event
|
||||
def initialize(event,viewport)
|
||||
super
|
||||
setParameters([0,0,0,20,0,0.5,-64,
|
||||
Graphics.height,-64,Graphics.width,0.5,0.10,-5,-15,5,80])
|
||||
initParticles("smoke",100,0,2)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class Particle_Engine::SootSmoke < ParticleEffect_Event
|
||||
def initialize(event,viewport)
|
||||
super
|
||||
setParameters([0,0,0,30,0,0.5,-64,
|
||||
Graphics.height,-64,Graphics.width,0.5,0.10,-5,-15,5,80])
|
||||
initParticles("smoke",100,0)
|
||||
for i in 0...@maxparticless
|
||||
@particles[i].blend_type = rand(6) < 3 ? 1 : 2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class Particle_Engine::Rocket < ParticleEffect_Event
|
||||
def initialize(event,viewport)
|
||||
super
|
||||
setParameters([0,0,0,60,0,0.5,-64,
|
||||
Graphics.height,-64,Graphics.width,0.5,0,-5,-15,5,80])
|
||||
initParticles("smoke",100,-1)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class Particle_Engine::FixedTeleport < ParticleEffect_Event
|
||||
def initialize(event,viewport)
|
||||
super
|
||||
setParameters([1,0,1,10,rand(360),1,
|
||||
-Graphics.height,Graphics.height,0,Graphics.width,0,3,-8,-15,20,0])
|
||||
initParticles("wideportal",250)
|
||||
for i in 0...@maxparticless
|
||||
@particles[i].ox = 16
|
||||
@particles[i].oy = 16
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
# By Peter O.
|
||||
class Particle_Engine::StarTeleport < ParticleEffect_Event
|
||||
def initialize(event,viewport)
|
||||
super
|
||||
setParameters([0,0,1,10,0,1,
|
||||
-Graphics.height,Graphics.height,0,Graphics.width,0,3,-8,-15,10,0])
|
||||
initParticles("star",250)
|
||||
for i in 0...@maxparticless
|
||||
@particles[i].ox = 48
|
||||
@particles[i].oy = 48
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class Particle_Engine::Smokescreen < ParticleEffect_Event
|
||||
def initialize(event,viewport)
|
||||
super
|
||||
setParameters([0,0,0,250,0,0.2,-64,
|
||||
Graphics.height,-64,Graphics.width,0.8,0.8,-5,-15,5,80])
|
||||
initParticles(nil,100)
|
||||
for i in 0...@maxparticless
|
||||
rnd = rand(3)
|
||||
@opacity[i] = (rnd==0) ? 1 : 100
|
||||
filename = (rnd==0) ? "explosionsmoke" : "smoke"
|
||||
@particles[i].bitmap = loadBitmap(filename, @hue)
|
||||
end
|
||||
end
|
||||
|
||||
def calcParticlePos(i)
|
||||
if @randomhue==1
|
||||
filename = (rand(3)==0) ? "explosionsmoke" : "smoke"
|
||||
@particles[i].bitmap = loadBitmap(filename, @hue)
|
||||
end
|
||||
multiple = 1.7
|
||||
xgrav = @xgravity*multiple/@slowdown
|
||||
xgrav = -xgrav if (rand(2)==1)
|
||||
ygrav = @ygravity*multiple/@slowdown
|
||||
ygrav = -ygrav if (rand(2)==1)
|
||||
@particlex[i] += xgrav
|
||||
@particley[i] += ygrav
|
||||
@particlex[i] -= @__offsetx
|
||||
@particley[i] -= @__offsety
|
||||
@particlex[i] = @particlex[i].floor
|
||||
@particley[i] = @particley[i].floor
|
||||
@particles[i].x = @particlex[i]+@startingx+@xoffset
|
||||
@particles[i].y = @particley[i]+@startingy+@yoffset
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class Particle_Engine::Flare < ParticleEffect_Event
|
||||
def initialize(event,viewport)
|
||||
super
|
||||
setParameters([0,0,1,30,10,1,-64,
|
||||
Graphics.height,-64,Graphics.width,2,2,-5,-12,30,0])
|
||||
initParticles("particle",255)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class Particle_Engine::Splash < ParticleEffect_Event
|
||||
def initialize(event,viewport)
|
||||
super
|
||||
setParameters([0,0,1,30,255,1,-64,
|
||||
Graphics.height,-64,Graphics.width,4,2,-5,-12,30,0])
|
||||
initParticles("smoke",50)
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
for i in 0...@maxparticless
|
||||
@particles[i].opacity = 50
|
||||
@particles[i].update
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class Game_Event < Game_Character
|
||||
attr_accessor :pe_refresh
|
||||
|
||||
alias nf_particles_game_map_initialize initialize
|
||||
def initialize(map_id,event,map=nil)
|
||||
@pe_refresh = false
|
||||
begin
|
||||
nf_particles_game_map_initialize(map_id, event, map)
|
||||
rescue ArgumentError
|
||||
nf_particles_game_map_initialize(map_id, event)
|
||||
end
|
||||
end
|
||||
|
||||
alias nf_particles_game_map_refresh refresh
|
||||
def refresh
|
||||
nf_particles_game_map_refresh
|
||||
@pe_refresh = true
|
||||
end
|
||||
end
|
||||
523
Data/Scripts_backup/005_Sprites/011_PictureEx.rb
Normal file
523
Data/Scripts_backup/005_Sprites/011_PictureEx.rb
Normal file
@@ -0,0 +1,523 @@
|
||||
class PictureOrigin
|
||||
TopLeft = 0
|
||||
Center = 1
|
||||
TopRight = 2
|
||||
BottomLeft = 3
|
||||
LowerLeft = 3
|
||||
BottomRight = 4
|
||||
LowerRight = 4
|
||||
Top = 5
|
||||
Bottom = 6
|
||||
Left = 7
|
||||
Right = 8
|
||||
end
|
||||
|
||||
|
||||
|
||||
class Processes
|
||||
XY = 0
|
||||
DeltaXY = 1
|
||||
Z = 2
|
||||
Curve = 3
|
||||
Zoom = 4
|
||||
Angle = 5
|
||||
Tone = 6
|
||||
Color = 7
|
||||
Hue = 8
|
||||
Opacity = 9
|
||||
Visible = 10
|
||||
BlendType = 11
|
||||
SE = 12
|
||||
Name = 13
|
||||
Origin = 14
|
||||
Src = 15
|
||||
SrcSize = 16
|
||||
CropBottom = 17
|
||||
end
|
||||
|
||||
|
||||
|
||||
def getCubicPoint2(src,t)
|
||||
x0 = src[0]; y0 = src[1]
|
||||
cx0 = src[2]; cy0 = src[3]
|
||||
cx1 = src[4]; cy1 = src[5]
|
||||
x1 = src[6]; y1 = src[7]
|
||||
|
||||
x1 = cx1+(x1-cx1)*t
|
||||
x0 = x0+(cx0-x0)*t
|
||||
cx0 = cx0+(cx1-cx0)*t
|
||||
cx1 = cx0+(x1-cx0)*t
|
||||
cx0 = x0+(cx0-x0)*t
|
||||
cx = cx0+(cx1-cx0)*t
|
||||
# a = x1 - 3 * cx1 + 3 * cx0 - x0
|
||||
# b = 3 * (cx1 - 2 * cx0 + x0)
|
||||
# c = 3 * (cx0 - x0)
|
||||
# d = x0
|
||||
# cx = a*t*t*t + b*t*t + c*t + d
|
||||
y1 = cy1+(y1-cy1)*t
|
||||
y0 = y0+(cy0-y0)*t
|
||||
cy0 = cy0+(cy1-cy0)*t
|
||||
cy1 = cy0+(y1-cy0)*t
|
||||
cy0 = y0+(cy0-y0)*t
|
||||
cy = cy0+(cy1-cy0)*t
|
||||
# a = y1 - 3 * cy1 + 3 * cy0 - y0
|
||||
# b = 3 * (cy1 - 2 * cy0 + y0)
|
||||
# c = 3 * (cy0 - y0)
|
||||
# d = y0
|
||||
# cy = a*t*t*t + b*t*t + c*t + d
|
||||
return [cx,cy]
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# PictureEx
|
||||
#===============================================================================
|
||||
class PictureEx
|
||||
attr_accessor :x # x-coordinate
|
||||
attr_accessor :y # y-coordinate
|
||||
attr_accessor :z # z value
|
||||
attr_accessor :zoom_x # x directional zoom rate
|
||||
attr_accessor :zoom_y # y directional zoom rate
|
||||
attr_accessor :angle # rotation angle
|
||||
attr_accessor :tone # tone
|
||||
attr_accessor :color # color
|
||||
attr_accessor :hue # filename hue
|
||||
attr_accessor :opacity # opacity level
|
||||
attr_accessor :visible # visibility boolean
|
||||
attr_accessor :blend_type # blend method
|
||||
attr_accessor :name # file name
|
||||
attr_accessor :origin # starting point
|
||||
attr_reader :src_rect # source rect
|
||||
attr_reader :cropBottom # crops sprite to above this y-coordinate
|
||||
attr_reader :frameUpdates # Array of processes updated in a frame
|
||||
|
||||
def initialize(z)
|
||||
# process: [type, delay, total_duration, frame_counter, cb, etc.]
|
||||
@processes = []
|
||||
@x = 0.0
|
||||
@y = 0.0
|
||||
@z = z
|
||||
@zoom_x = 100.0
|
||||
@zoom_y = 100.0
|
||||
@angle = 0
|
||||
@rotate_speed = 0
|
||||
@tone = Tone.new(0, 0, 0, 0)
|
||||
@tone_duration = 0
|
||||
@color = Color.new(0, 0, 0, 0)
|
||||
@hue = 0
|
||||
@opacity = 255.0
|
||||
@visible = true
|
||||
@blend_type = 0
|
||||
@name = ""
|
||||
@origin = PictureOrigin::TopLeft
|
||||
@src_rect = Rect.new(0,0,-1,-1)
|
||||
@cropBottom = -1
|
||||
@frameUpdates = []
|
||||
end
|
||||
|
||||
def callback(cb)
|
||||
if cb.is_a?(Proc); cb.call(self)
|
||||
elsif cb.is_a?(Array); cb[0].method(cb[1]).call(self)
|
||||
elsif cb.is_a?(Method); cb.call(self)
|
||||
end
|
||||
end
|
||||
|
||||
def setCallback(delay, cb=nil)
|
||||
delay = ensureDelayAndDuration(delay)
|
||||
@processes.push([nil,delay,0,0,cb])
|
||||
end
|
||||
|
||||
def running?
|
||||
return @processes.length>0
|
||||
end
|
||||
|
||||
def totalDuration
|
||||
ret = 0
|
||||
for process in @processes
|
||||
dur = process[1]+process[2]
|
||||
ret = dur if dur>ret
|
||||
end
|
||||
ret *= 20.0/Graphics.frame_rate
|
||||
return ret.to_i
|
||||
end
|
||||
|
||||
def ensureDelayAndDuration(delay, duration=nil)
|
||||
delay = self.totalDuration if delay<0
|
||||
delay *= Graphics.frame_rate/20.0
|
||||
if !duration.nil?
|
||||
duration *= Graphics.frame_rate/20.0
|
||||
return delay.to_i, duration.to_i
|
||||
end
|
||||
return delay.to_i
|
||||
end
|
||||
|
||||
def ensureDelay(delay)
|
||||
return ensureDelayAndDuration(delay)
|
||||
end
|
||||
|
||||
# speed is the angle to change by in 1/20 of a second. @rotate_speed is the
|
||||
# angle to change by per frame.
|
||||
# NOTE: This is not compatible with manually changing the angle at a certain
|
||||
# point. If you make a sprite auto-rotate, you should not try to alter
|
||||
# the angle another way too.
|
||||
def rotate(speed)
|
||||
@rotate_speed = speed*20.0/Graphics.frame_rate
|
||||
while @rotate_speed<0; @rotate_speed += 360; end
|
||||
@rotate_speed %= 360
|
||||
end
|
||||
|
||||
def erase
|
||||
self.name = ""
|
||||
end
|
||||
|
||||
def clearProcesses
|
||||
@processes = []
|
||||
end
|
||||
|
||||
def adjustPosition(xOffset, yOffset)
|
||||
for process in @processes
|
||||
next if process[0]!=Processes::XY
|
||||
process[5] += xOffset
|
||||
process[6] += yOffset
|
||||
process[7] += xOffset
|
||||
process[8] += yOffset
|
||||
end
|
||||
end
|
||||
|
||||
def move(delay, duration, origin, x, y, zoom_x=100.0, zoom_y=100.0, opacity=255)
|
||||
setOrigin(delay,duration,origin)
|
||||
moveXY(delay,duration,x,y)
|
||||
moveZoomXY(delay,duration,zoom_x,zoom_y)
|
||||
moveOpacity(delay,duration,opacity)
|
||||
end
|
||||
|
||||
def moveXY(delay, duration, x, y, cb=nil)
|
||||
delay, duration = ensureDelayAndDuration(delay,duration)
|
||||
@processes.push([Processes::XY,delay,duration,0,cb,@x,@y,x,y])
|
||||
end
|
||||
|
||||
def setXY(delay, x, y, cb=nil)
|
||||
moveXY(delay,0,x,y,cb)
|
||||
end
|
||||
|
||||
def moveCurve(delay, duration, x1, y1, x2, y2, x3, y3, cb=nil)
|
||||
delay, duration = ensureDelayAndDuration(delay,duration)
|
||||
@processes.push([Processes::Curve,delay,duration,0,cb,[@x,@y,x1,y1,x2,y2,x3,y3]])
|
||||
end
|
||||
|
||||
def moveDelta(delay, duration, x, y, cb=nil)
|
||||
delay, duration = ensureDelayAndDuration(delay,duration)
|
||||
@processes.push([Processes::DeltaXY,delay,duration,0,cb,@x,@y,x,y])
|
||||
end
|
||||
|
||||
def setDelta(delay, x, y, cb=nil)
|
||||
moveDelta(delay,0,x,y,cb)
|
||||
end
|
||||
|
||||
def moveZ(delay, duration, z, cb=nil)
|
||||
delay, duration = ensureDelayAndDuration(delay,duration)
|
||||
@processes.push([Processes::Z,delay,duration,0,cb,@z,z])
|
||||
end
|
||||
|
||||
def setZ(delay, z, cb=nil)
|
||||
moveZ(delay,0,z,cb)
|
||||
end
|
||||
|
||||
def moveZoomXY(delay, duration, zoom_x, zoom_y, cb=nil)
|
||||
delay, duration = ensureDelayAndDuration(delay,duration)
|
||||
@processes.push([Processes::Zoom,delay,duration,0,cb,@zoom_x,@zoom_y,zoom_x,zoom_y])
|
||||
end
|
||||
|
||||
def setZoomXY(delay, zoom_x, zoom_y, cb=nil)
|
||||
moveZoomXY(delay,0,zoom_x,zoom_y,cb)
|
||||
end
|
||||
|
||||
def moveZoom(delay, duration, zoom, cb=nil)
|
||||
moveZoomXY(delay,duration,zoom,zoom,cb)
|
||||
end
|
||||
|
||||
def setZoom(delay, zoom, cb=nil)
|
||||
moveZoomXY(delay,0,zoom,zoom,cb)
|
||||
end
|
||||
|
||||
def moveAngle(delay, duration, angle, cb=nil)
|
||||
delay, duration = ensureDelayAndDuration(delay,duration)
|
||||
@processes.push([Processes::Angle,delay,duration,0,cb,@angle,angle])
|
||||
end
|
||||
|
||||
def setAngle(delay, angle, cb=nil)
|
||||
moveAngle(delay,0,angle,cb)
|
||||
end
|
||||
|
||||
def moveTone(delay, duration, tone, cb=nil)
|
||||
delay, duration = ensureDelayAndDuration(delay,duration)
|
||||
target = (tone) ? tone.clone : Tone.new(0,0,0,0)
|
||||
@processes.push([Processes::Tone,delay,duration,0,cb,@tone.clone,target])
|
||||
end
|
||||
|
||||
def setTone(delay, tone, cb=nil)
|
||||
moveTone(delay,0,tone,cb)
|
||||
end
|
||||
|
||||
def moveColor(delay, duration, color, cb=nil)
|
||||
delay, duration = ensureDelayAndDuration(delay,duration)
|
||||
target = (color) ? color.clone : Color.new(0,0,0,0)
|
||||
@processes.push([Processes::Color,delay,duration,0,cb,@color.clone,target])
|
||||
end
|
||||
|
||||
def setColor(delay, color, cb=nil)
|
||||
moveColor(delay,0,color,cb)
|
||||
end
|
||||
|
||||
# Hue changes don't actually work.
|
||||
def moveHue(delay, duration, hue, cb=nil)
|
||||
delay, duration = ensureDelayAndDuration(delay,duration)
|
||||
@processes.push([Processes::Hue,delay,duration,0,cb,@hue,hue])
|
||||
end
|
||||
|
||||
# Hue changes don't actually work.
|
||||
def setHue(delay, hue, cb=nil)
|
||||
moveHue(delay,0,hue,cb)
|
||||
end
|
||||
|
||||
def moveOpacity(delay, duration, opacity, cb=nil)
|
||||
delay, duration = ensureDelayAndDuration(delay,duration)
|
||||
@processes.push([Processes::Opacity,delay,duration,0,cb,@opacity,opacity])
|
||||
end
|
||||
|
||||
def setOpacity(delay, opacity, cb=nil)
|
||||
moveOpacity(delay,0,opacity,cb)
|
||||
end
|
||||
|
||||
def setVisible(delay, visible, cb=nil)
|
||||
delay = ensureDelay(delay)
|
||||
@processes.push([Processes::Visible,delay,0,0,cb,visible])
|
||||
end
|
||||
|
||||
# Only values of 0 (normal), 1 (additive) and 2 (subtractive) are allowed.
|
||||
def setBlendType(delay, blend, cb=nil)
|
||||
delay = ensureDelayAndDuration(delay)
|
||||
@processes.push([Processes::BlendType,delay,0,0,cb,blend])
|
||||
end
|
||||
|
||||
def setSE(delay, seFile, volume=nil, pitch=nil, cb=nil)
|
||||
delay = ensureDelay(delay)
|
||||
@processes.push([Processes::SE,delay,0,0,cb,seFile,volume,pitch])
|
||||
end
|
||||
|
||||
def setName(delay, name, cb=nil)
|
||||
delay = ensureDelay(delay)
|
||||
@processes.push([Processes::Name,delay,0,0,cb,name])
|
||||
end
|
||||
|
||||
def setOrigin(delay, origin, cb=nil)
|
||||
delay = ensureDelay(delay)
|
||||
@processes.push([Processes::Origin,delay,0,0,cb,origin])
|
||||
end
|
||||
|
||||
def setSrc(delay, srcX, srcY, cb=nil)
|
||||
delay = ensureDelay(delay)
|
||||
@processes.push([Processes::Src,delay,0,0,cb,srcX,srcY])
|
||||
end
|
||||
|
||||
def setSrcSize(delay, srcWidth, srcHeight, cb=nil)
|
||||
delay = ensureDelay(delay)
|
||||
@processes.push([Processes::SrcSize,delay,0,0,cb,srcWidth,srcHeight])
|
||||
end
|
||||
|
||||
# Used to cut Pokémon sprites off when they faint and sink into the ground.
|
||||
def setCropBottom(delay, y, cb=nil)
|
||||
delay = ensureDelay(delay)
|
||||
@processes.push([Processes::CropBottom,delay,0,0,cb,y])
|
||||
end
|
||||
|
||||
def update
|
||||
procEnded = false
|
||||
@frameUpdates.clear
|
||||
for i in 0...@processes.length
|
||||
process = @processes[i]
|
||||
# Decrease delay of processes that are scheduled to start later
|
||||
if process[1]>=0
|
||||
# Set initial values if the process will start this frame
|
||||
if process[1]==0
|
||||
case process[0]
|
||||
when Processes::XY
|
||||
process[5] = @x
|
||||
process[6] = @y
|
||||
when Processes::DeltaXY
|
||||
process[5] = @x
|
||||
process[6] = @y
|
||||
process[7] += @x
|
||||
process[8] += @y
|
||||
when Processes::Curve
|
||||
process[5][0] = @x
|
||||
process[5][1] = @y
|
||||
when Processes::Z
|
||||
process[5] = @z
|
||||
when Processes::Zoom
|
||||
process[5] = @zoom_x
|
||||
process[6] = @zoom_y
|
||||
when Processes::Angle
|
||||
process[5] = @angle
|
||||
when Processes::Tone
|
||||
process[5] = @tone.clone
|
||||
when Processes::Color
|
||||
process[5] = @color.clone
|
||||
when Processes::Hue
|
||||
process[5] = @hue
|
||||
when Processes::Opacity
|
||||
process[5] = @opacity
|
||||
end
|
||||
end
|
||||
# Decrease delay counter
|
||||
process[1] -= 1
|
||||
# Process hasn't started yet, skip to the next one
|
||||
next if process[1]>=0
|
||||
end
|
||||
# Update process
|
||||
@frameUpdates.push(process[0]) if !@frameUpdates.include?(process[0])
|
||||
fra = (process[2]==0) ? 1 : process[3] # Frame counter
|
||||
dur = (process[2]==0) ? 1 : process[2] # Total duration of process
|
||||
case process[0]
|
||||
when Processes::XY, Processes::DeltaXY
|
||||
@x = process[5] + fra * (process[7] - process[5]) / dur
|
||||
@y = process[6] + fra * (process[8] - process[6]) / dur
|
||||
when Processes::Curve
|
||||
@x, @y = getCubicPoint2(process[5],fra.to_f/dur)
|
||||
when Processes::Z
|
||||
@z = process[5] + fra * (process[6] - process[5]) / dur
|
||||
when Processes::Zoom
|
||||
@zoom_x = process[5] + fra * (process[7] - process[5]) / dur
|
||||
@zoom_y = process[6] + fra * (process[8] - process[6]) / dur
|
||||
when Processes::Angle
|
||||
@angle = process[5] + fra * (process[6] - process[5]) / dur
|
||||
when Processes::Tone
|
||||
@tone.red = process[5].red + fra * (process[6].red - process[5].red) / dur
|
||||
@tone.green = process[5].green + fra * (process[6].green - process[5].green) / dur
|
||||
@tone.blue = process[5].blue + fra * (process[6].blue - process[5].blue) / dur
|
||||
@tone.gray = process[5].gray + fra * (process[6].gray - process[5].gray) / dur
|
||||
when Processes::Color
|
||||
@color.red = process[5].red + fra * (process[6].red - process[5].red) / dur
|
||||
@color.green = process[5].green + fra * (process[6].green - process[5].green) / dur
|
||||
@color.blue = process[5].blue + fra * (process[6].blue - process[5].blue) / dur
|
||||
@color.alpha = process[5].alpha + fra * (process[6].alpha - process[5].alpha) / dur
|
||||
when Processes::Hue
|
||||
@hue = (process[6] - process[5]).to_f / dur
|
||||
when Processes::Opacity
|
||||
@opacity = process[5] + fra * (process[6] - process[5]) / dur
|
||||
when Processes::Visible
|
||||
@visible = process[5]
|
||||
when Processes::BlendType
|
||||
@blend_type = process[5]
|
||||
when Processes::SE
|
||||
pbSEPlay(process[5],process[6],process[7])
|
||||
when Processes::Name
|
||||
@name = process[5]
|
||||
when Processes::Origin
|
||||
@origin = process[5]
|
||||
when Processes::Src
|
||||
@src_rect.x = process[5]
|
||||
@src_rect.y = process[6]
|
||||
when Processes::SrcSize
|
||||
@src_rect.width = process[5]
|
||||
@src_rect.height = process[6]
|
||||
when Processes::CropBottom
|
||||
@cropBottom = process[5]
|
||||
end
|
||||
# Increase frame counter
|
||||
process[3] += 1
|
||||
if process[3]>process[2]
|
||||
# Process has ended, erase it
|
||||
callback(process[4]) if process[4]
|
||||
@processes[i] = nil
|
||||
procEnded = true
|
||||
end
|
||||
end
|
||||
# Clear out empty spaces in @processes array caused by finished processes
|
||||
@processes.compact! if procEnded
|
||||
# Add the constant rotation speed
|
||||
if @rotate_speed != 0
|
||||
@frameUpdates.push(Processes::Angle) if !@frameUpdates.include?(Processes::Angle)
|
||||
@angle += @rotate_speed
|
||||
while @angle<0; @angle += 360; end
|
||||
@angle %= 360
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
def setPictureSprite(sprite, picture, iconSprite=false)
|
||||
return if picture.frameUpdates.length==0
|
||||
for i in 0...picture.frameUpdates.length
|
||||
case picture.frameUpdates[i]
|
||||
when Processes::XY, Processes::DeltaXY
|
||||
sprite.x = picture.x.round
|
||||
sprite.y = picture.y.round
|
||||
when Processes::Z
|
||||
sprite.z = picture.z
|
||||
when Processes::Zoom
|
||||
sprite.zoom_x = picture.zoom_x / 100.0
|
||||
sprite.zoom_y = picture.zoom_y / 100.0
|
||||
when Processes::Angle
|
||||
if picture.angle < 180
|
||||
sprite.angle = picture.angle
|
||||
else
|
||||
sprite.angle = 359 - picture.angle
|
||||
end
|
||||
when Processes::Tone
|
||||
sprite.tone = picture.tone
|
||||
when Processes::Color
|
||||
sprite.color = picture.color
|
||||
when Processes::Hue
|
||||
# This doesn't do anything.
|
||||
when Processes::BlendType
|
||||
sprite.blend_type = picture.blend_type
|
||||
when Processes::Opacity
|
||||
sprite.opacity = picture.opacity
|
||||
when Processes::Visible
|
||||
sprite.visible = picture.visible
|
||||
when Processes::Name
|
||||
sprite.name = picture.name if iconSprite && sprite.name != picture.name
|
||||
when Processes::Origin
|
||||
case picture.origin
|
||||
when PictureOrigin::TopLeft, PictureOrigin::Left, PictureOrigin::BottomLeft
|
||||
sprite.ox = 0
|
||||
when PictureOrigin::Top, PictureOrigin::Center, PictureOrigin::Bottom
|
||||
sprite.ox = (sprite.bitmap && !sprite.bitmap.disposed?) ? sprite.src_rect.width/2 : 0
|
||||
when PictureOrigin::TopRight, PictureOrigin::Right, PictureOrigin::BottomRight
|
||||
sprite.ox = (sprite.bitmap && !sprite.bitmap.disposed?) ? sprite.src_rect.width : 0
|
||||
end
|
||||
case picture.origin
|
||||
when PictureOrigin::TopLeft, PictureOrigin::Top, PictureOrigin::TopRight
|
||||
sprite.oy = 0
|
||||
when PictureOrigin::Left, PictureOrigin::Center, PictureOrigin::Right
|
||||
sprite.oy = (sprite.bitmap && !sprite.bitmap.disposed?) ? sprite.src_rect.height/2 : 0
|
||||
when PictureOrigin::BottomLeft, PictureOrigin::Bottom, PictureOrigin::BottomRight
|
||||
sprite.oy = (sprite.bitmap && !sprite.bitmap.disposed?) ? sprite.src_rect.height : 0
|
||||
end
|
||||
when Processes::Src
|
||||
next unless iconSprite && sprite.src_rect
|
||||
sprite.src_rect.x = picture.src_rect.x
|
||||
sprite.src_rect.y = picture.src_rect.y
|
||||
when Processes::SrcSize
|
||||
next unless iconSprite && sprite.src_rect
|
||||
sprite.src_rect.width = picture.src_rect.width
|
||||
sprite.src_rect.height = picture.src_rect.height
|
||||
end
|
||||
end
|
||||
if iconSprite && sprite.src_rect && picture.cropBottom>=0
|
||||
spriteBottom = sprite.y-sprite.oy+sprite.src_rect.height
|
||||
if spriteBottom>picture.cropBottom
|
||||
sprite.src_rect.height = [picture.cropBottom-sprite.y+sprite.oy,0].max
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def setPictureIconSprite(sprite, picture)
|
||||
setPictureSprite(sprite,picture,true)
|
||||
end
|
||||
172
Data/Scripts_backup/005_Sprites/012_Interpolators.rb
Normal file
172
Data/Scripts_backup/005_Sprites/012_Interpolators.rb
Normal file
@@ -0,0 +1,172 @@
|
||||
class Interpolator
|
||||
ZOOM_X = 1
|
||||
ZOOM_Y = 2
|
||||
X = 3
|
||||
Y = 4
|
||||
OPACITY = 5
|
||||
COLOR = 6
|
||||
WAIT = 7
|
||||
|
||||
def initialize
|
||||
@tweening = false
|
||||
@tweensteps = []
|
||||
@sprite = nil
|
||||
@frames = 0
|
||||
@step = 0
|
||||
end
|
||||
|
||||
def tweening?
|
||||
return @tweening
|
||||
end
|
||||
|
||||
def tween(sprite,items,frames)
|
||||
@tweensteps = []
|
||||
if sprite && !sprite.disposed? && frames>0
|
||||
@frames = frames
|
||||
@step = 0
|
||||
@sprite = sprite
|
||||
for item in items
|
||||
case item[0]
|
||||
when ZOOM_X
|
||||
@tweensteps[item[0]] = [sprite.zoom_x,item[1]-sprite.zoom_x]
|
||||
when ZOOM_Y
|
||||
@tweensteps[item[0]] = [sprite.zoom_y,item[1]-sprite.zoom_y]
|
||||
when X
|
||||
@tweensteps[item[0]] = [sprite.x,item[1]-sprite.x]
|
||||
when Y
|
||||
@tweensteps[item[0]] = [sprite.y,item[1]-sprite.y]
|
||||
when OPACITY
|
||||
@tweensteps[item[0]] = [sprite.opacity,item[1]-sprite.opacity]
|
||||
when COLOR
|
||||
@tweensteps[item[0]] = [sprite.color.clone,Color.new(
|
||||
item[1].red-sprite.color.red,
|
||||
item[1].green-sprite.color.green,
|
||||
item[1].blue-sprite.color.blue,
|
||||
item[1].alpha-sprite.color.alpha
|
||||
)]
|
||||
end
|
||||
end
|
||||
@tweening = true
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @tweening
|
||||
t = (@step*1.0)/@frames
|
||||
for i in 0...@tweensteps.length
|
||||
item = @tweensteps[i]
|
||||
next if !item
|
||||
case i
|
||||
when ZOOM_X
|
||||
@sprite.zoom_x = item[0]+item[1]*t
|
||||
when ZOOM_Y
|
||||
@sprite.zoom_y = item[0]+item[1]*t
|
||||
when X
|
||||
@sprite.x = item[0]+item[1]*t
|
||||
when Y
|
||||
@sprite.y = item[0]+item[1]*t
|
||||
when OPACITY
|
||||
@sprite.opacity = item[0]+item[1]*t
|
||||
when COLOR
|
||||
@sprite.color = Color.new(
|
||||
item[0].red+item[1].red*t,
|
||||
item[0].green+item[1].green*t,
|
||||
item[0].blue+item[1].blue*t,
|
||||
item[0].alpha+item[1].alpha*t
|
||||
)
|
||||
end
|
||||
end
|
||||
@step += 1
|
||||
if @step==@frames
|
||||
@step = 0
|
||||
@frames = 0
|
||||
@tweening = false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class RectInterpolator
|
||||
def initialize(oldrect,newrect,frames)
|
||||
restart(oldrect,newrect,frames)
|
||||
end
|
||||
|
||||
def restart(oldrect,newrect,frames)
|
||||
@oldrect = oldrect
|
||||
@newrect = newrect
|
||||
@frames = [frames,1].max
|
||||
@curframe = 0
|
||||
@rect = oldrect.clone
|
||||
end
|
||||
|
||||
def set(rect)
|
||||
rect.set(@rect.x,@rect.y,@rect.width,@rect.height)
|
||||
end
|
||||
|
||||
def done?
|
||||
@curframe>@frames
|
||||
end
|
||||
|
||||
def update
|
||||
return if done?
|
||||
t = (@curframe*1.0/@frames)
|
||||
x1 = @oldrect.x
|
||||
x2 = @newrect.x
|
||||
x = x1+t*(x2-x1)
|
||||
y1 = @oldrect.y
|
||||
y2 = @newrect.y
|
||||
y = y1+t*(y2-y1)
|
||||
rx1 = @oldrect.x+@oldrect.width
|
||||
rx2 = @newrect.x+@newrect.width
|
||||
rx = rx1+t*(rx2-rx1)
|
||||
ry1 = @oldrect.y+@oldrect.height
|
||||
ry2 = @newrect.y+@newrect.height
|
||||
ry = ry1+t*(ry2-ry1)
|
||||
minx = x<rx ? x : rx
|
||||
maxx = x>rx ? x : rx
|
||||
miny = y<ry ? y : ry
|
||||
maxy = y>ry ? y : ry
|
||||
@rect.set(minx,miny,maxx-minx,maxy-miny)
|
||||
@curframe += 1
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class PointInterpolator
|
||||
attr_reader :x
|
||||
attr_reader :y
|
||||
|
||||
def initialize(oldx,oldy,newx,newy,frames)
|
||||
restart(oldx,oldy,newx,newy,frames)
|
||||
end
|
||||
|
||||
def restart(oldx,oldy,newx,newy,frames)
|
||||
@oldx = oldx
|
||||
@oldy = oldy
|
||||
@newx = newx
|
||||
@newy = newy
|
||||
@frames = frames
|
||||
@curframe = 0
|
||||
@x = oldx
|
||||
@y = oldy
|
||||
end
|
||||
|
||||
def done?
|
||||
@curframe>@frames
|
||||
end
|
||||
|
||||
def update
|
||||
return if done?
|
||||
t = (@curframe*1.0/@frames)
|
||||
rx1 = @oldx
|
||||
rx2 = @newx
|
||||
@x = rx1+t*(rx2-rx1)
|
||||
ry1 = @oldy
|
||||
ry2 = @newy
|
||||
@y = ry1+t*(ry2-ry1)
|
||||
@curframe += 1
|
||||
end
|
||||
end
|
||||
43
Data/Scripts_backup/005_Sprites/013_ScreenPosHelper.rb
Normal file
43
Data/Scripts_backup/005_Sprites/013_ScreenPosHelper.rb
Normal file
@@ -0,0 +1,43 @@
|
||||
module ScreenPosHelper
|
||||
def self.pbScreenZoomX(ch)
|
||||
return Game_Map::TILE_WIDTH/32.0
|
||||
end
|
||||
|
||||
def self.pbScreenZoomY(ch)
|
||||
return Game_Map::TILE_HEIGHT/32.0
|
||||
end
|
||||
|
||||
def self.pbScreenX(ch)
|
||||
return ch.screen_x
|
||||
end
|
||||
|
||||
def self.pbScreenY(ch)
|
||||
return ch.screen_y
|
||||
end
|
||||
|
||||
@heightcache={}
|
||||
|
||||
def self.bmHeight(bm)
|
||||
h=@heightcache[bm]
|
||||
if !h
|
||||
bmap=AnimatedBitmap.new("Graphics/Characters/"+bm,0)
|
||||
h=bmap.height
|
||||
@heightcache[bm]=h
|
||||
bmap.dispose
|
||||
end
|
||||
return h
|
||||
end
|
||||
|
||||
def self.pbScreenZ(ch,height=nil)
|
||||
if height==nil
|
||||
height=0
|
||||
if ch.tile_id > 0
|
||||
height=32
|
||||
elsif ch.character_name!=""
|
||||
height=bmHeight(ch.character_name)/4
|
||||
end
|
||||
end
|
||||
ret=ch.screen_z(height)
|
||||
return ret
|
||||
end
|
||||
end
|
||||
59
Data/Scripts_backup/006_Map renderer/001_TilemapLoader.rb
Normal file
59
Data/Scripts_backup/006_Map renderer/001_TilemapLoader.rb
Normal file
@@ -0,0 +1,59 @@
|
||||
class TilemapLoader
|
||||
def initialize(viewport)
|
||||
@viewport = viewport
|
||||
@tilemap = nil
|
||||
@color = Color.new(0,0,0,0)
|
||||
@tone = Tone.new(0,0,0,0)
|
||||
updateClass
|
||||
end
|
||||
|
||||
def updateClass
|
||||
setClass(CustomTilemap)
|
||||
end
|
||||
|
||||
def setClass(cls)
|
||||
newtilemap = cls.new(@viewport)
|
||||
if @tilemap
|
||||
newtilemap.tileset = @tilemap.tileset
|
||||
newtilemap.map_data = @tilemap.map_data
|
||||
newtilemap.flash_data = @tilemap.flash_data
|
||||
newtilemap.priorities = @tilemap.priorities
|
||||
newtilemap.terrain_tags = @tilemap.terrain_tags
|
||||
newtilemap.visible = @tilemap.visible
|
||||
newtilemap.ox = @tilemap.ox
|
||||
newtilemap.oy = @tilemap.oy
|
||||
for i in 0...7
|
||||
newtilemap.autotiles[i] = @tilemap.autotiles[i]
|
||||
end
|
||||
@tilemap.dispose
|
||||
@tilemap = newtilemap
|
||||
newtilemap.update
|
||||
else
|
||||
@tilemap = newtilemap
|
||||
end
|
||||
end
|
||||
|
||||
def dispose; @tilemap.dispose; end
|
||||
def disposed?; @tilemap && @tilemap.disposed?; end
|
||||
def update; @tilemap.update; end
|
||||
def viewport; @tilemap.viewport; end
|
||||
def autotiles; @tilemap.autotiles; end
|
||||
def tileset; @tilemap.tileset; end
|
||||
def tileset=(v); @tilemap.tileset = v; end
|
||||
def map_data; @tilemap.map_data; end
|
||||
def map_data=(v); @tilemap.map_data = v; end
|
||||
def flash_data; @tilemap.flash_data; end
|
||||
def flash_data=(v); @tilemap.flash_data = v; end
|
||||
def priorities; @tilemap.priorities; end
|
||||
def priorities=(v); @tilemap.priorities = v; end
|
||||
def terrain_tags; (@tilemap.terrain_tags rescue nil); end
|
||||
def terrain_tags=(v); (@tilemap.terrain_tags = v rescue nil); end
|
||||
def visible; @tilemap.visible; end
|
||||
def visible=(v); @tilemap.visible = v; end
|
||||
def tone; (@tilemap.tone rescue @tone); end
|
||||
def tone=(value); (@tilemap.tone = value rescue nil); end
|
||||
def ox; @tilemap.ox; end
|
||||
def ox=(v); @tilemap.ox = v; end
|
||||
def oy; @tilemap.oy; end
|
||||
def oy=(v); @tilemap.oy = v; end
|
||||
end
|
||||
1018
Data/Scripts_backup/006_Map renderer/002_CustomTilemap.rb
Normal file
1018
Data/Scripts_backup/006_Map renderer/002_CustomTilemap.rb
Normal file
File diff suppressed because it is too large
Load Diff
228
Data/Scripts_backup/006_Map renderer/003_TileDrawingHelper.rb
Normal file
228
Data/Scripts_backup/006_Map renderer/003_TileDrawingHelper.rb
Normal file
@@ -0,0 +1,228 @@
|
||||
class TileDrawingHelper
|
||||
attr_accessor :tileset
|
||||
attr_accessor :autotiles
|
||||
|
||||
Autotiles = [
|
||||
[ [27, 28, 33, 34], [ 5, 28, 33, 34], [27, 6, 33, 34], [ 5, 6, 33, 34],
|
||||
[27, 28, 33, 12], [ 5, 28, 33, 12], [27, 6, 33, 12], [ 5, 6, 33, 12] ],
|
||||
[ [27, 28, 11, 34], [ 5, 28, 11, 34], [27, 6, 11, 34], [ 5, 6, 11, 34],
|
||||
[27, 28, 11, 12], [ 5, 28, 11, 12], [27, 6, 11, 12], [ 5, 6, 11, 12] ],
|
||||
[ [25, 26, 31, 32], [25, 6, 31, 32], [25, 26, 31, 12], [25, 6, 31, 12],
|
||||
[15, 16, 21, 22], [15, 16, 21, 12], [15, 16, 11, 22], [15, 16, 11, 12] ],
|
||||
[ [29, 30, 35, 36], [29, 30, 11, 36], [ 5, 30, 35, 36], [ 5, 30, 11, 36],
|
||||
[39, 40, 45, 46], [ 5, 40, 45, 46], [39, 6, 45, 46], [ 5, 6, 45, 46] ],
|
||||
[ [25, 30, 31, 36], [15, 16, 45, 46], [13, 14, 19, 20], [13, 14, 19, 12],
|
||||
[17, 18, 23, 24], [17, 18, 11, 24], [41, 42, 47, 48], [ 5, 42, 47, 48] ],
|
||||
[ [37, 38, 43, 44], [37, 6, 43, 44], [13, 18, 19, 24], [13, 14, 43, 44],
|
||||
[37, 42, 43, 48], [17, 18, 47, 48], [13, 18, 43, 48], [ 1, 2, 7, 8] ]
|
||||
]
|
||||
|
||||
# converts neighbors returned from tableNeighbors to tile indexes
|
||||
NeighborsToTiles = [
|
||||
46, 44, 46, 44, 43, 41, 43, 40, 46, 44, 46, 44, 43, 41, 43, 40,
|
||||
42, 32, 42, 32, 35, 19, 35, 18, 42, 32, 42, 32, 34, 17, 34, 16,
|
||||
46, 44, 46, 44, 43, 41, 43, 40, 46, 44, 46, 44, 43, 41, 43, 40,
|
||||
42, 32, 42, 32, 35, 19, 35, 18, 42, 32, 42, 32, 34, 17, 34, 16,
|
||||
45, 39, 45, 39, 33, 31, 33, 29, 45, 39, 45, 39, 33, 31, 33, 29,
|
||||
37, 27, 37, 27, 23, 15, 23, 13, 37, 27, 37, 27, 22, 11, 22, 9,
|
||||
45, 39, 45, 39, 33, 31, 33, 29, 45, 39, 45, 39, 33, 31, 33, 29,
|
||||
36, 26, 36, 26, 21, 7, 21, 5, 36, 26, 36, 26, 20, 3, 20, 1,
|
||||
46, 44, 46, 44, 43, 41, 43, 40, 46, 44, 46, 44, 43, 41, 43, 40,
|
||||
42, 32, 42, 32, 35, 19, 35, 18, 42, 32, 42, 32, 34, 17, 34, 16,
|
||||
46, 44, 46, 44, 43, 41, 43, 40, 46, 44, 46, 44, 43, 41, 43, 40,
|
||||
42, 32, 42, 32, 35, 19, 35, 18, 42, 32, 42, 32, 34, 17, 34, 16,
|
||||
45, 38, 45, 38, 33, 30, 33, 28, 45, 38, 45, 38, 33, 30, 33, 28,
|
||||
37, 25, 37, 25, 23, 14, 23, 12, 37, 25, 37, 25, 22, 10, 22, 8,
|
||||
45, 38, 45, 38, 33, 30, 33, 28, 45, 38, 45, 38, 33, 30, 33, 28,
|
||||
36, 24, 36, 24, 21, 6, 21, 4, 36, 24, 36, 24, 20, 2, 20, 0
|
||||
]
|
||||
|
||||
def self.tableNeighbors(data,x,y)
|
||||
return 0 if x < 0 || x >= data.xsize
|
||||
return 0 if y < 0 || y >= data.ysize
|
||||
t = data[x,y]
|
||||
xp1 = [x + 1, data.xsize - 1].min
|
||||
yp1 = [y + 1, data.ysize - 1].min
|
||||
xm1 = [x - 1, 0].max
|
||||
ym1 = [y - 1, 0].max
|
||||
i = 0
|
||||
i |= 0x01 if data[ x, ym1] == t # N
|
||||
i |= 0x02 if data[xp1, ym1] == t # NE
|
||||
i |= 0x04 if data[xp1, y] == t # E
|
||||
i |= 0x08 if data[xp1, yp1] == t # SE
|
||||
i |= 0x10 if data[ x, yp1] == t # S
|
||||
i |= 0x20 if data[xm1, yp1] == t # SW
|
||||
i |= 0x40 if data[xm1, y] == t # W
|
||||
i |= 0x80 if data[xm1, ym1] == t # NW
|
||||
return i
|
||||
end
|
||||
|
||||
def self.fromTileset(tileset)
|
||||
bmtileset=pbGetTileset(tileset.tileset_name)
|
||||
bmautotiles=[]
|
||||
for i in 0...7
|
||||
bmautotiles.push(pbGetAutotile(tileset.autotile_names[i]))
|
||||
end
|
||||
return self.new(bmtileset,bmautotiles)
|
||||
end
|
||||
|
||||
def initialize(tileset, autotiles)
|
||||
if tileset.mega?
|
||||
@tileset = TileWrap::wrapTileset(tileset)
|
||||
tileset.dispose
|
||||
@shouldWrap = true
|
||||
else
|
||||
@tileset = tileset
|
||||
@shouldWrap = false
|
||||
end
|
||||
@autotiles = autotiles
|
||||
end
|
||||
|
||||
def dispose
|
||||
@tileset.dispose if @tileset
|
||||
@tileset = nil
|
||||
for i in 0...@autotiles.length
|
||||
@autotiles[i].dispose
|
||||
@autotiles[i] = nil
|
||||
end
|
||||
end
|
||||
|
||||
def bltSmallAutotile(bitmap,x,y,cxTile,cyTile,id,frame)
|
||||
return if id >= 384 || frame < 0 || !@autotiles
|
||||
autotile = @autotiles[id / 48 - 1]
|
||||
return if !autotile || autotile.disposed?
|
||||
cxTile = [cxTile / 2, 1].max
|
||||
cyTile = [cyTile / 2, 1].max
|
||||
if autotile.height == 32
|
||||
anim = frame * 32
|
||||
src_rect = Rect.new(anim, 0, 32, 32)
|
||||
bitmap.stretch_blt(Rect.new(x, y, cxTile * 2, cyTile * 2), autotile, src_rect)
|
||||
else
|
||||
anim = frame * 96
|
||||
id %= 48
|
||||
tiles = TileDrawingHelper::Autotiles[id >> 3][id & 7]
|
||||
src = Rect.new(0, 0, 0, 0)
|
||||
for i in 0...4
|
||||
tile_position = tiles[i] - 1
|
||||
src.set(tile_position % 6 * 16 + anim, tile_position / 6 * 16, 16, 16)
|
||||
bitmap.stretch_blt(Rect.new(i % 2 * cxTile + x, i / 2 * cyTile + y, cxTile, cyTile),
|
||||
autotile, src)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def bltSmallRegularTile(bitmap,x,y,cxTile,cyTile,id)
|
||||
return if id < 384 || !@tileset || @tileset.disposed?
|
||||
rect = Rect.new((id - 384) % 8 * 32, (id - 384) / 8 * 32, 32, 32)
|
||||
rect = TileWrap::getWrappedRect(rect) if @shouldWrap
|
||||
bitmap.stretch_blt(Rect.new(x, y, cxTile, cyTile), @tileset, rect)
|
||||
end
|
||||
|
||||
def bltSmallTile(bitmap,x,y,cxTile,cyTile,id,frame=0)
|
||||
if id >= 384
|
||||
bltSmallRegularTile(bitmap, x, y, cxTile, cyTile, id)
|
||||
elsif id > 0
|
||||
bltSmallAutotile(bitmap, x, y, cxTile, cyTile, id, frame)
|
||||
end
|
||||
end
|
||||
|
||||
def bltAutotile(bitmap,x,y,id,frame)
|
||||
bltSmallAutotile(bitmap, x, y, 32, 32, id, frame)
|
||||
end
|
||||
|
||||
def bltRegularTile(bitmap,x,y,id)
|
||||
bltSmallRegularTile(bitmap, x, y, 32, 32, id)
|
||||
end
|
||||
|
||||
def bltTile(bitmap,x,y,id,frame=0)
|
||||
if id >= 384
|
||||
bltRegularTile(bitmap, x, y, id)
|
||||
elsif id > 0
|
||||
bltAutotile(bitmap, x, y, id, frame)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
def createMinimap(mapid)
|
||||
map=load_data(sprintf("Data/Map%03d.rxdata",mapid)) rescue nil
|
||||
return BitmapWrapper.new(32,32) if !map
|
||||
bitmap=BitmapWrapper.new(map.width*4,map.height*4)
|
||||
black=Color.new(0,0,0)
|
||||
tilesets=$data_tilesets
|
||||
tileset=tilesets[map.tileset_id]
|
||||
return bitmap if !tileset
|
||||
helper=TileDrawingHelper.fromTileset(tileset)
|
||||
for y in 0...map.height
|
||||
for x in 0...map.width
|
||||
for z in 0..2
|
||||
id=map.data[x,y,z]
|
||||
id=0 if !id
|
||||
helper.bltSmallTile(bitmap,x*4,y*4,4,4,id)
|
||||
end
|
||||
end
|
||||
end
|
||||
bitmap.fill_rect(0,0,bitmap.width,1,black)
|
||||
bitmap.fill_rect(0,bitmap.height-1,bitmap.width,1,black)
|
||||
bitmap.fill_rect(0,0,1,bitmap.height,black)
|
||||
bitmap.fill_rect(bitmap.width-1,0,1,bitmap.height,black)
|
||||
return bitmap
|
||||
end
|
||||
|
||||
def bltMinimapAutotile(dstBitmap,x,y,srcBitmap,id)
|
||||
return if id>=48 || !srcBitmap || srcBitmap.disposed?
|
||||
anim=0
|
||||
cxTile=3
|
||||
cyTile=3
|
||||
tiles = TileDrawingHelper::Autotiles[id>>3][id&7]
|
||||
src=Rect.new(0,0,0,0)
|
||||
for i in 0...4
|
||||
tile_position = tiles[i] - 1
|
||||
src.set(
|
||||
tile_position % 6 * cxTile + anim,
|
||||
tile_position / 6 * cyTile, cxTile, cyTile)
|
||||
dstBitmap.blt(i%2*cxTile+x,i/2*cyTile+y, srcBitmap, src)
|
||||
end
|
||||
end
|
||||
|
||||
def passable?(passages,tile_id)
|
||||
return false if tile_id == nil
|
||||
passage = passages[tile_id]
|
||||
return (passage && passage<15)
|
||||
end
|
||||
|
||||
# Unused
|
||||
def getPassabilityMinimap(mapid)
|
||||
map = load_data(sprintf("Data/Map%03d.rxdata",mapid))
|
||||
tileset = $data_tilesets[map.tileset_id]
|
||||
minimap = AnimatedBitmap.new("Graphics/Pictures/minimap_tiles")
|
||||
ret = Bitmap.new(map.width*6,map.height*6)
|
||||
passtable = Table.new(map.width,map.height)
|
||||
passages = tileset.passages
|
||||
for i in 0...map.width
|
||||
for j in 0...map.height
|
||||
pass=true
|
||||
for z in [2,1,0]
|
||||
if !passable?(passages,map.data[i,j,z])
|
||||
pass=false
|
||||
break
|
||||
end
|
||||
end
|
||||
passtable[i,j]=pass ? 1 : 0
|
||||
end
|
||||
end
|
||||
neighbors=TileDrawingHelper::NeighborsToTiles
|
||||
for i in 0...map.width
|
||||
for j in 0...map.height
|
||||
if passtable[i,j]==0
|
||||
nb=TileDrawingHelper.tableNeighbors(passtable,i,j)
|
||||
tile=neighbors[nb]
|
||||
bltMinimapAutotile(ret,i*6,j*6,minimap.bitmap,tile)
|
||||
end
|
||||
end
|
||||
end
|
||||
minimap.disposes
|
||||
return ret
|
||||
end
|
||||
135
Data/Scripts_backup/007_Objects and windows/001_RPG_Cache.rb
Normal file
135
Data/Scripts_backup/007_Objects and windows/001_RPG_Cache.rb
Normal file
@@ -0,0 +1,135 @@
|
||||
class Hangup < Exception; end
|
||||
|
||||
|
||||
|
||||
module RPG
|
||||
module Cache
|
||||
def self.debug
|
||||
t = Time.now
|
||||
filename = t.strftime("%H %M %S.%L.txt")
|
||||
File.open("cache_" + filename, "wb") { |f|
|
||||
@cache.each do |key, value|
|
||||
if !value
|
||||
f.write("#{key} (nil)\r\n")
|
||||
elsif value.disposed?
|
||||
f.write("#{key} (disposed)\r\n")
|
||||
else
|
||||
f.write("#{key} (#{value.refcount}, #{value.width}x#{value.height})\r\n")
|
||||
end
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def self.setKey(key, obj)
|
||||
@cache[key] = obj
|
||||
end
|
||||
|
||||
def self.fromCache(i)
|
||||
return nil if !@cache.include?(i)
|
||||
obj = @cache[i]
|
||||
return nil if obj && obj.disposed?
|
||||
return obj
|
||||
end
|
||||
|
||||
def self.load_bitmap(folder_name, filename, hue = 0)
|
||||
path = folder_name + filename
|
||||
cached = true
|
||||
ret = fromCache(path)
|
||||
if !ret
|
||||
if filename == ""
|
||||
ret = BitmapWrapper.new(32, 32)
|
||||
else
|
||||
ret = BitmapWrapper.new(path)
|
||||
end
|
||||
@cache[path] = ret
|
||||
cached = false
|
||||
end
|
||||
if hue == 0
|
||||
ret.addRef if cached
|
||||
return ret
|
||||
end
|
||||
key = [path, hue]
|
||||
ret2 = fromCache(key)
|
||||
if ret2
|
||||
ret2.addRef
|
||||
else
|
||||
ret2 = ret.copy
|
||||
ret2.hue_change(hue)
|
||||
@cache[key] = ret2
|
||||
end
|
||||
return ret2
|
||||
end
|
||||
|
||||
def self.tileEx(filename, tile_id, hue, width = 1, height = 1)
|
||||
key = [filename, tile_id, hue, width, height]
|
||||
ret = fromCache(key)
|
||||
if ret
|
||||
ret.addRef
|
||||
else
|
||||
ret = BitmapWrapper.new(32 * width, 32 * height)
|
||||
x = (tile_id - 384) % 8 * 32
|
||||
y = (((tile_id - 384) / 8) - height + 1) * 32
|
||||
tileset = yield(filename)
|
||||
ret.blt(0, 0, tileset, Rect.new(x, y, 32 * width, 32 * height))
|
||||
tileset.dispose
|
||||
ret.hue_change(hue) if hue != 0
|
||||
@cache[key] = ret
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def self.tile(filename, tile_id, hue)
|
||||
return self.tileEx(filename, tile_id, hue) { |f| self.tileset(f) }
|
||||
end
|
||||
|
||||
def self.transition(filename)
|
||||
self.load_bitmap("Graphics/Transitions/", filename)
|
||||
end
|
||||
|
||||
def self.retain(folder_name, filename = "", hue = 0)
|
||||
path = folder_name + filename
|
||||
ret = fromCache(path)
|
||||
if hue > 0
|
||||
key = [path, hue]
|
||||
ret2 = fromCache(key)
|
||||
if ret2
|
||||
ret2.never_dispose = true
|
||||
return
|
||||
end
|
||||
end
|
||||
ret.never_dispose = true if ret
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class BitmapWrapper < Bitmap
|
||||
attr_reader :refcount
|
||||
attr_accessor :never_dispose
|
||||
|
||||
def dispose
|
||||
return if self.disposed?
|
||||
@refcount -= 1
|
||||
super if @refcount <= 0 && !never_dispose
|
||||
end
|
||||
|
||||
def initialize(*arg)
|
||||
super
|
||||
@refcount = 1
|
||||
end
|
||||
|
||||
def resetRef
|
||||
@refcount = 1
|
||||
end
|
||||
|
||||
def copy
|
||||
bm = self.clone
|
||||
bm.resetRef
|
||||
return bm
|
||||
end
|
||||
|
||||
def addRef
|
||||
@refcount += 1
|
||||
end
|
||||
end
|
||||
803
Data/Scripts_backup/007_Objects and windows/002_MessageConfig.rb
Normal file
803
Data/Scripts_backup/007_Objects and windows/002_MessageConfig.rb
Normal file
@@ -0,0 +1,803 @@
|
||||
module MessageConfig
|
||||
LIGHT_TEXT_MAIN_COLOR = Color.new(248, 248, 248)
|
||||
LIGHT_TEXT_SHADOW_COLOR = Color.new(72, 80, 88)
|
||||
DARK_TEXT_MAIN_COLOR = Color.new(80, 80, 88)
|
||||
DARK_TEXT_SHADOW_COLOR = Color.new(160, 160, 168)
|
||||
FONT_NAME = "Power Green"
|
||||
FONT_SIZE = 29
|
||||
SMALL_FONT_NAME = "Power Green Small"
|
||||
SMALL_FONT_SIZE = 25
|
||||
NARROW_FONT_NAME = "Power Green Narrow"
|
||||
NARROW_FONT_SIZE = 29
|
||||
# 0 = Pause cursor is displayed at end of text
|
||||
# 1 = Pause cursor is displayed at bottom right
|
||||
# 2 = Pause cursor is displayed at lower middle side
|
||||
CURSOR_POSITION = 1
|
||||
WINDOW_OPACITY = 255
|
||||
TEXT_SPEED = nil # can be positive to wait frames or negative to
|
||||
# show multiple characters in a single frame
|
||||
@@systemFrame = nil
|
||||
@@defaultTextSkin = nil
|
||||
@@textSpeed = nil
|
||||
@@systemFont = nil
|
||||
@@smallFont = nil
|
||||
@@narrowFont = nil
|
||||
|
||||
def self.pbDefaultSystemFrame
|
||||
if $PokemonSystem
|
||||
return pbResolveBitmap("Graphics/Windowskins/" + Settings::MENU_WINDOWSKINS[$PokemonSystem.frame]) || ""
|
||||
else
|
||||
return pbResolveBitmap("Graphics/Windowskins/" + Settings::MENU_WINDOWSKINS[0]) || ""
|
||||
end
|
||||
end
|
||||
|
||||
def self.pbDefaultSpeechFrame
|
||||
if $PokemonSystem
|
||||
return pbResolveBitmap("Graphics/Windowskins/" + Settings::SPEECH_WINDOWSKINS[$PokemonSystem.textskin]) || ""
|
||||
else
|
||||
return pbResolveBitmap("Graphics/Windowskins/" + Settings::SPEECH_WINDOWSKINS[0]) || ""
|
||||
end
|
||||
end
|
||||
|
||||
def self.pbDefaultWindowskin
|
||||
skin=($data_system) ? $data_system.windowskin_name : nil
|
||||
if skin && skin!=""
|
||||
skin=pbResolveBitmap("Graphics/Windowskins/"+skin) || ""
|
||||
end
|
||||
skin=pbResolveBitmap("Graphics/System/Window") if nil_or_empty?(skin)
|
||||
skin=pbResolveBitmap("Graphics/Windowskins/001-Blue01") if nil_or_empty?(skin)
|
||||
return skin || ""
|
||||
end
|
||||
|
||||
def self.pbGetSystemFrame
|
||||
if !@@systemFrame
|
||||
skin=MessageConfig.pbDefaultSystemFrame
|
||||
skin=MessageConfig.pbDefaultWindowskin if nil_or_empty?(skin)
|
||||
@@systemFrame=skin || ""
|
||||
end
|
||||
return @@systemFrame
|
||||
end
|
||||
|
||||
def self.pbGetSpeechFrame
|
||||
if !@@defaultTextSkin
|
||||
skin=MessageConfig.pbDefaultSpeechFrame
|
||||
skin=MessageConfig.pbDefaultWindowskin if nil_or_empty?(skin)
|
||||
@@defaultTextSkin=skin || ""
|
||||
end
|
||||
return @@defaultTextSkin
|
||||
end
|
||||
|
||||
def self.pbSetSystemFrame(value)
|
||||
@@systemFrame=pbResolveBitmap(value) || ""
|
||||
end
|
||||
|
||||
def self.pbSetSpeechFrame(value)
|
||||
@@defaultTextSkin=pbResolveBitmap(value) || ""
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
def self.pbDefaultTextSpeed
|
||||
return ($PokemonSystem) ? pbSettingToTextSpeed($PokemonSystem.textspeed) : pbSettingToTextSpeed(nil)
|
||||
end
|
||||
|
||||
def self.pbGetTextSpeed
|
||||
@@textSpeed=pbDefaultTextSpeed if !@@textSpeed
|
||||
return @@textSpeed
|
||||
end
|
||||
|
||||
def self.pbSetTextSpeed(value)
|
||||
@@textSpeed=value
|
||||
end
|
||||
|
||||
def self.pbSettingToTextSpeed(speed)
|
||||
case speed
|
||||
when 0 then return 1
|
||||
when 1 then return -2
|
||||
when 2 then return -999
|
||||
end
|
||||
return TEXT_SPEED || 1
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
def self.pbDefaultSystemFontName
|
||||
return MessageConfig.pbTryFonts(FONT_NAME)
|
||||
end
|
||||
|
||||
def self.pbDefaultSmallFontName
|
||||
return MessageConfig.pbTryFonts(SMALL_FONT_NAME)
|
||||
end
|
||||
|
||||
def self.pbDefaultNarrowFontName
|
||||
return MessageConfig.pbTryFonts(NARROW_FONT_NAME)
|
||||
end
|
||||
|
||||
def self.pbGetSystemFontName
|
||||
@@systemFont = pbDefaultSystemFontName if !@@systemFont
|
||||
return @@systemFont
|
||||
end
|
||||
|
||||
def self.pbGetSmallFontName
|
||||
@@smallFont = pbDefaultSmallFontName if !@@smallFont
|
||||
return @@smallFont
|
||||
end
|
||||
|
||||
def self.pbGetNarrowFontName
|
||||
@@narrowFont = pbDefaultNarrowFontName if !@@narrowFont
|
||||
return @@narrowFont
|
||||
end
|
||||
|
||||
def self.pbSetSystemFontName(value)
|
||||
@@systemFont = MessageConfig.pbTryFonts(value)
|
||||
@@systemFont = MessageConfig.pbDefaultSystemFontName if @@systemFont == ""
|
||||
end
|
||||
|
||||
def self.pbSetSmallFontName(value)
|
||||
@@smallFont = MessageConfig.pbTryFonts(value)
|
||||
@@smallFont = MessageConfig.pbDefaultSmallFontName if @@smallFont == ""
|
||||
end
|
||||
|
||||
def self.pbSetNarrowFontName(value)
|
||||
@@narrowFont = MessageConfig.pbTryFonts(value)
|
||||
@@narrowFont = MessageConfig.pbDefaultNarrowFontName if @@narrowFont == ""
|
||||
end
|
||||
|
||||
def self.pbTryFonts(*args)
|
||||
for a in args
|
||||
next if !a
|
||||
if a.is_a?(String)
|
||||
return a if Font.exist?(a)
|
||||
elsif a.is_a?(Array)
|
||||
for aa in a
|
||||
ret = MessageConfig.pbTryFonts(aa)
|
||||
return ret if ret != ""
|
||||
end
|
||||
end
|
||||
end
|
||||
return ""
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# Position a window
|
||||
#===============================================================================
|
||||
def pbBottomRight(window)
|
||||
window.x=Graphics.width-window.width
|
||||
window.y=Graphics.height-window.height
|
||||
end
|
||||
|
||||
def pbBottomLeft(window)
|
||||
window.x=0
|
||||
window.y=Graphics.height-window.height
|
||||
end
|
||||
|
||||
def pbBottomLeftLines(window,lines,width=nil)
|
||||
window.x=0
|
||||
window.width=width ? width : Graphics.width
|
||||
window.height=(window.borderY rescue 32)+lines*32
|
||||
window.y=Graphics.height-window.height
|
||||
end
|
||||
|
||||
def pbPositionFaceWindow(facewindow,msgwindow)
|
||||
return if !facewindow
|
||||
if msgwindow
|
||||
if facewindow.height<=msgwindow.height
|
||||
facewindow.y=msgwindow.y
|
||||
else
|
||||
facewindow.y=msgwindow.y+msgwindow.height-facewindow.height
|
||||
end
|
||||
facewindow.x=Graphics.width-facewindow.width
|
||||
msgwindow.x=0
|
||||
msgwindow.width=Graphics.width-facewindow.width
|
||||
else
|
||||
facewindow.height=Graphics.height if facewindow.height>Graphics.height
|
||||
facewindow.x=0
|
||||
facewindow.y=0
|
||||
end
|
||||
end
|
||||
|
||||
def pbPositionNearMsgWindow(cmdwindow,msgwindow,side)
|
||||
return if !cmdwindow
|
||||
if msgwindow
|
||||
height=[cmdwindow.height,Graphics.height-msgwindow.height].min
|
||||
if cmdwindow.height!=height
|
||||
cmdwindow.height=height
|
||||
end
|
||||
cmdwindow.y=msgwindow.y-cmdwindow.height
|
||||
if cmdwindow.y<0
|
||||
cmdwindow.y=msgwindow.y+msgwindow.height
|
||||
if cmdwindow.y+cmdwindow.height>Graphics.height
|
||||
cmdwindow.y=msgwindow.y-cmdwindow.height
|
||||
end
|
||||
end
|
||||
case side
|
||||
when :left
|
||||
cmdwindow.x=msgwindow.x
|
||||
when :right
|
||||
cmdwindow.x=msgwindow.x+msgwindow.width-cmdwindow.width
|
||||
else
|
||||
cmdwindow.x=msgwindow.x+msgwindow.width-cmdwindow.width
|
||||
end
|
||||
else
|
||||
cmdwindow.height=Graphics.height if cmdwindow.height>Graphics.height
|
||||
cmdwindow.x=0
|
||||
cmdwindow.y=0
|
||||
end
|
||||
end
|
||||
|
||||
# internal function
|
||||
def pbRepositionMessageWindow(msgwindow, linecount=2)
|
||||
msgwindow.height=32*linecount+msgwindow.borderY
|
||||
msgwindow.y=(Graphics.height)-(msgwindow.height)
|
||||
if $game_system && $game_system.respond_to?("message_position")
|
||||
case $game_system.message_position
|
||||
when 0 # up
|
||||
msgwindow.y=0
|
||||
when 1 # middle
|
||||
msgwindow.y=(Graphics.height/2)-(msgwindow.height/2)
|
||||
when 2
|
||||
msgwindow.y=(Graphics.height)-(msgwindow.height)
|
||||
end
|
||||
end
|
||||
if $game_system && $game_system.respond_to?("message_frame")
|
||||
if $game_system.message_frame != 0
|
||||
msgwindow.opacity = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# internal function
|
||||
def pbUpdateMsgWindowPos(msgwindow,event,eventChanged=false)
|
||||
if event
|
||||
if eventChanged
|
||||
msgwindow.resizeToFit2(msgwindow.text,Graphics.width*2/3,msgwindow.height)
|
||||
end
|
||||
msgwindow.y=event.screen_y-48-msgwindow.height
|
||||
if msgwindow.y<0
|
||||
msgwindow.y=event.screen_y+24
|
||||
end
|
||||
msgwindow.x=event.screen_x-(msgwindow.width/2)
|
||||
msgwindow.x=0 if msgwindow.x<0
|
||||
if msgwindow.x>Graphics.width-msgwindow.width
|
||||
msgwindow.x=Graphics.width-msgwindow.width
|
||||
end
|
||||
else
|
||||
curwidth=msgwindow.width
|
||||
if curwidth!=Graphics.width
|
||||
msgwindow.width=Graphics.width
|
||||
msgwindow.width=Graphics.width
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# Determine the colour of a background
|
||||
#===============================================================================
|
||||
def isDarkBackground(background,rect=nil)
|
||||
return true if !background || background.disposed?
|
||||
rect = background.rect if !rect
|
||||
return true if rect.width<=0 || rect.height<=0
|
||||
xSeg = (rect.width/16)
|
||||
xLoop = (xSeg==0) ? 1 : 16
|
||||
xStart = (xSeg==0) ? rect.x+(rect.width/2) : rect.x+xSeg/2
|
||||
ySeg = (rect.height/16)
|
||||
yLoop = (ySeg==0) ? 1 : 16
|
||||
yStart = (ySeg==0) ? rect.y+(rect.height/2) : rect.y+ySeg/2
|
||||
count = 0
|
||||
y = yStart
|
||||
r = 0; g = 0; b = 0
|
||||
yLoop.times do
|
||||
x = xStart
|
||||
xLoop.times do
|
||||
clr = background.get_pixel(x,y)
|
||||
if clr.alpha!=0
|
||||
r += clr.red
|
||||
g += clr.green
|
||||
b += clr.blue
|
||||
count += 1
|
||||
end
|
||||
x += xSeg
|
||||
end
|
||||
y += ySeg
|
||||
end
|
||||
return true if count==0
|
||||
r /= count
|
||||
g /= count
|
||||
b /= count
|
||||
return (r*0.299+g*0.587+b*0.114)<160
|
||||
end
|
||||
|
||||
def isDarkWindowskin(windowskin)
|
||||
return true if !windowskin || windowskin.disposed?
|
||||
if windowskin.width==192 && windowskin.height==128
|
||||
return isDarkBackground(windowskin,Rect.new(0,0,128,128))
|
||||
elsif windowskin.width==128 && windowskin.height==128
|
||||
return isDarkBackground(windowskin,Rect.new(0,0,64,64))
|
||||
elsif windowskin.width==96 && windowskin.height==48
|
||||
return isDarkBackground(windowskin,Rect.new(32,16,16,16))
|
||||
else
|
||||
clr = windowskin.get_pixel(windowskin.width/2, windowskin.height/2)
|
||||
return (clr.red*0.299+clr.green*0.587+clr.blue*0.114)<160
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# Determine which text colours to use based on the darkness of the background
|
||||
#===============================================================================
|
||||
def getSkinColor(windowskin,color,isDarkSkin)
|
||||
if !windowskin || windowskin.disposed? ||
|
||||
windowskin.width!=128 || windowskin.height!=128
|
||||
# Base color, shadow color (these are reversed on dark windowskins)
|
||||
textcolors = [
|
||||
"0070F8","78B8E8", # 1 Blue
|
||||
"E82010","F8A8B8", # 2 Red
|
||||
"60B048","B0D090", # 3 Green
|
||||
"48D8D8","A8E0E0", # 4 Cyan
|
||||
"D038B8","E8A0E0", # 5 Magenta
|
||||
"E8D020","F8E888", # 6 Yellow
|
||||
"A0A0A8","D0D0D8", # 7 Grey
|
||||
"F0F0F8","C8C8D0", # 8 White
|
||||
"9040E8","B8A8E0", # 9 Purple
|
||||
"F89818","F8C898", # 10 Orange
|
||||
colorToRgb32(MessageConfig::DARK_TEXT_MAIN_COLOR),
|
||||
colorToRgb32(MessageConfig::DARK_TEXT_SHADOW_COLOR), # 11 Dark default
|
||||
colorToRgb32(MessageConfig::LIGHT_TEXT_MAIN_COLOR),
|
||||
colorToRgb32(MessageConfig::LIGHT_TEXT_SHADOW_COLOR) # 12 Light default
|
||||
]
|
||||
if color==0 || color>textcolors.length/2 # No special colour, use default
|
||||
if isDarkSkin # Dark background, light text
|
||||
return shadowc3tag(MessageConfig::LIGHT_TEXT_MAIN_COLOR, MessageConfig::LIGHT_TEXT_SHADOW_COLOR)
|
||||
end
|
||||
# Light background, dark text
|
||||
return shadowc3tag(MessageConfig::DARK_TEXT_MAIN_COLOR, MessageConfig::DARK_TEXT_SHADOW_COLOR)
|
||||
end
|
||||
# Special colour as listed above
|
||||
if isDarkSkin && color!=12 # Dark background, light text
|
||||
return sprintf("<c3=%s,%s>",textcolors[2*(color-1)+1],textcolors[2*(color-1)])
|
||||
end
|
||||
# Light background, dark text
|
||||
return sprintf("<c3=%s,%s>",textcolors[2*(color-1)],textcolors[2*(color-1)+1])
|
||||
else # VX windowskin
|
||||
color = 0 if color>=32
|
||||
x = 64 + (color % 8) * 8
|
||||
y = 96 + (color / 8) * 8
|
||||
pixel = windowskin.get_pixel(x, y)
|
||||
return shadowctagFromColor(pixel)
|
||||
end
|
||||
end
|
||||
|
||||
def getDefaultTextColors(windowskin)
|
||||
if !windowskin || windowskin.disposed? ||
|
||||
windowskin.width!=128 || windowskin.height!=128
|
||||
if isDarkWindowskin(windowskin)
|
||||
return [MessageConfig::LIGHT_TEXT_MAIN_COLOR, MessageConfig::LIGHT_TEXT_SHADOW_COLOR] # White
|
||||
else
|
||||
return [MessageConfig::DARK_TEXT_MAIN_COLOR, MessageConfig::DARK_TEXT_SHADOW_COLOR] # Dark gray
|
||||
end
|
||||
else # VX windowskin
|
||||
color = windowskin.get_pixel(64, 96)
|
||||
shadow = nil
|
||||
isDark = (color.red+color.green+color.blue)/3 < 128
|
||||
if isDark
|
||||
shadow = Color.new(color.red+64,color.green+64,color.blue+64)
|
||||
else
|
||||
shadow = Color.new(color.red-64,color.green-64,color.blue-64)
|
||||
end
|
||||
return [color,shadow]
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# Makes sure a bitmap exists
|
||||
#===============================================================================
|
||||
def pbDoEnsureBitmap(bitmap,dwidth,dheight)
|
||||
if !bitmap || bitmap.disposed? || bitmap.width<dwidth || bitmap.height<dheight
|
||||
oldfont = (bitmap && !bitmap.disposed?) ? bitmap.font : nil
|
||||
bitmap.dispose if bitmap
|
||||
bitmap = Bitmap.new([1,dwidth].max,[1,dheight].max)
|
||||
(oldfont) ? bitmap.font = oldfont : pbSetSystemFont(bitmap)
|
||||
bitmap.font.shadow = false if bitmap.font && bitmap.font.respond_to?("shadow")
|
||||
end
|
||||
return bitmap
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# Set a bitmap's font
|
||||
#===============================================================================
|
||||
# Sets a bitmap's font to the system font.
|
||||
def pbSetSystemFont(bitmap)
|
||||
bitmap.font.name = MessageConfig.pbGetSystemFontName
|
||||
bitmap.font.size = MessageConfig::FONT_SIZE
|
||||
end
|
||||
|
||||
# Sets a bitmap's font to the system small font.
|
||||
def pbSetSmallFont(bitmap)
|
||||
bitmap.font.name = MessageConfig.pbGetSmallFontName
|
||||
bitmap.font.size = MessageConfig::SMALL_FONT_SIZE
|
||||
end
|
||||
|
||||
# Sets a bitmap's font to the system narrow font.
|
||||
def pbSetNarrowFont(bitmap)
|
||||
bitmap.font.name = MessageConfig.pbGetNarrowFontName
|
||||
bitmap.font.size = MessageConfig::NARROW_FONT_SIZE
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# Blend colours, set the colour of all bitmaps in a sprite hash
|
||||
#===============================================================================
|
||||
def pbAlphaBlend(dstColor,srcColor)
|
||||
r=(255*(srcColor.red-dstColor.red)/255)+dstColor.red
|
||||
g=(255*(srcColor.green-dstColor.green)/255)+dstColor.green
|
||||
b=(255*(srcColor.blue-dstColor.blue)/255)+dstColor.blue
|
||||
a=(255*(srcColor.alpha-dstColor.alpha)/255)+dstColor.alpha
|
||||
return Color.new(r,g,b,a)
|
||||
end
|
||||
|
||||
def pbSrcOver(dstColor,srcColor)
|
||||
er=srcColor.red*srcColor.alpha/255
|
||||
eg=srcColor.green*srcColor.alpha/255
|
||||
eb=srcColor.blue*srcColor.alpha/255
|
||||
iea=255-srcColor.alpha
|
||||
cr=dstColor.red*dstColor.alpha/255
|
||||
cg=dstColor.green*dstColor.alpha/255
|
||||
cb=dstColor.blue*dstColor.alpha/255
|
||||
ica=255-dstColor.alpha
|
||||
a=255-(iea*ica)/255
|
||||
r=(iea*cr)/255+er
|
||||
g=(iea*cg)/255+eg
|
||||
b=(iea*cb)/255+eb
|
||||
r=(a==0) ? 0 : r*255/a
|
||||
g=(a==0) ? 0 : g*255/a
|
||||
b=(a==0) ? 0 : b*255/a
|
||||
return Color.new(r,g,b,a)
|
||||
end
|
||||
|
||||
def pbSetSpritesToColor(sprites,color)
|
||||
return if !sprites || !color
|
||||
colors={}
|
||||
for i in sprites
|
||||
next if !i[1] || pbDisposed?(i[1])
|
||||
colors[i[0]]=i[1].color.clone
|
||||
i[1].color=pbSrcOver(i[1].color,color)
|
||||
end
|
||||
Graphics.update
|
||||
Input.update
|
||||
for i in colors
|
||||
next if !sprites[i[0]]
|
||||
sprites[i[0]].color=i[1]
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# Update and dispose sprite hashes
|
||||
#===============================================================================
|
||||
def using(window)
|
||||
begin
|
||||
yield if block_given?
|
||||
ensure
|
||||
window.dispose
|
||||
end
|
||||
end
|
||||
|
||||
def pbUpdateSpriteHash(windows)
|
||||
for i in windows
|
||||
window=i[1]
|
||||
if window
|
||||
if window.is_a?(Sprite) || window.is_a?(Window)
|
||||
window.update if !pbDisposed?(window)
|
||||
elsif window.is_a?(Plane)
|
||||
begin
|
||||
window.update if !window.disposed?
|
||||
rescue NoMethodError
|
||||
end
|
||||
elsif window.respond_to?("update")
|
||||
begin
|
||||
window.update
|
||||
rescue RGSSError
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Disposes all objects in the specified hash.
|
||||
def pbDisposeSpriteHash(sprites)
|
||||
return if !sprites
|
||||
for i in sprites.keys
|
||||
pbDisposeSprite(sprites,i)
|
||||
end
|
||||
sprites.clear
|
||||
end
|
||||
|
||||
# Disposes the specified graphics object within the specified hash. Basically
|
||||
# like: sprites[id].dispose
|
||||
def pbDisposeSprite(sprites,id)
|
||||
sprite = sprites[id]
|
||||
sprite.dispose if sprite && !pbDisposed?(sprite)
|
||||
sprites[id] = nil
|
||||
end
|
||||
|
||||
def pbDisposed?(x)
|
||||
return true if !x
|
||||
return x.disposed? if !x.is_a?(Viewport)
|
||||
begin
|
||||
x.rect = x.rect
|
||||
rescue
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# Fades and window activations for sprite hashes
|
||||
#===============================================================================
|
||||
def pbPushFade
|
||||
$game_temp.fadestate = [$game_temp.fadestate+1,0].max if $game_temp
|
||||
end
|
||||
|
||||
def pbPopFade
|
||||
$game_temp.fadestate = [$game_temp.fadestate-1,0].max if $game_temp
|
||||
end
|
||||
|
||||
def pbIsFaded?
|
||||
return ($game_temp) ? $game_temp.fadestate>0 : false
|
||||
end
|
||||
|
||||
# pbFadeOutIn(z) { block }
|
||||
# Fades out the screen before a block is run and fades it back in after the
|
||||
# block exits. z indicates the z-coordinate of the viewport used for this effect
|
||||
def pbFadeOutIn(z=99999,nofadeout=false)
|
||||
col=Color.new(0,0,0,0)
|
||||
viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
|
||||
viewport.z=z
|
||||
numFrames = (Graphics.frame_rate*0.4).floor
|
||||
alphaDiff = (255.0/numFrames).ceil
|
||||
for j in 0..numFrames
|
||||
col.set(0,0,0,j*alphaDiff)
|
||||
viewport.color=col
|
||||
Graphics.update
|
||||
Input.update
|
||||
end
|
||||
pbPushFade
|
||||
begin
|
||||
yield if block_given?
|
||||
ensure
|
||||
pbPopFade
|
||||
if !nofadeout
|
||||
for j in 0..numFrames
|
||||
col.set(0,0,0,(numFrames-j)*alphaDiff)
|
||||
viewport.color=col
|
||||
Graphics.update
|
||||
Input.update
|
||||
end
|
||||
end
|
||||
viewport.dispose
|
||||
end
|
||||
end
|
||||
|
||||
def pbFadeOutInWithUpdate(z,sprites,nofadeout=false)
|
||||
col=Color.new(0,0,0,0)
|
||||
viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
|
||||
viewport.z=z
|
||||
numFrames = (Graphics.frame_rate*0.4).floor
|
||||
alphaDiff = (255.0/numFrames).ceil
|
||||
for j in 0..numFrames
|
||||
col.set(0,0,0,j*alphaDiff)
|
||||
viewport.color=col
|
||||
pbUpdateSpriteHash(sprites)
|
||||
Graphics.update
|
||||
Input.update
|
||||
end
|
||||
pbPushFade
|
||||
begin
|
||||
yield if block_given?
|
||||
ensure
|
||||
pbPopFade
|
||||
if !nofadeout
|
||||
for j in 0..numFrames
|
||||
col.set(0,0,0,(numFrames-j)*alphaDiff)
|
||||
viewport.color=col
|
||||
pbUpdateSpriteHash(sprites)
|
||||
Graphics.update
|
||||
Input.update
|
||||
end
|
||||
end
|
||||
viewport.dispose
|
||||
end
|
||||
end
|
||||
|
||||
# Similar to pbFadeOutIn, but pauses the music as it fades out.
|
||||
# Requires scripts "Audio" (for bgm_pause) and "SpriteWindow" (for pbFadeOutIn).
|
||||
def pbFadeOutInWithMusic(zViewport=99999)
|
||||
playingBGS = $game_system.getPlayingBGS
|
||||
playingBGM = $game_system.getPlayingBGM
|
||||
$game_system.bgm_pause(1.0)
|
||||
$game_system.bgs_pause(1.0)
|
||||
pos = $game_system.bgm_position
|
||||
pbFadeOutIn(zViewport) {
|
||||
yield
|
||||
$game_system.bgm_position = pos
|
||||
$game_system.bgm_resume(playingBGM)
|
||||
$game_system.bgs_resume(playingBGS)
|
||||
}
|
||||
end
|
||||
|
||||
def pbFadeOutAndHide(sprites)
|
||||
visiblesprites = {}
|
||||
numFrames = (Graphics.frame_rate*0.4).floor
|
||||
alphaDiff = (255.0/numFrames).ceil
|
||||
pbDeactivateWindows(sprites) {
|
||||
for j in 0..numFrames
|
||||
pbSetSpritesToColor(sprites,Color.new(0,0,0,j*alphaDiff))
|
||||
(block_given?) ? yield : pbUpdateSpriteHash(sprites)
|
||||
end
|
||||
}
|
||||
for i in sprites
|
||||
next if !i[1]
|
||||
next if pbDisposed?(i[1])
|
||||
visiblesprites[i[0]] = true if i[1].visible
|
||||
i[1].visible = false
|
||||
end
|
||||
return visiblesprites
|
||||
end
|
||||
|
||||
def pbFadeInAndShow(sprites,visiblesprites=nil)
|
||||
if visiblesprites
|
||||
for i in visiblesprites
|
||||
if i[1] && sprites[i[0]] && !pbDisposed?(sprites[i[0]])
|
||||
sprites[i[0]].visible = true
|
||||
end
|
||||
end
|
||||
end
|
||||
numFrames = (Graphics.frame_rate*0.4).floor
|
||||
alphaDiff = (255.0/numFrames).ceil
|
||||
pbDeactivateWindows(sprites) {
|
||||
for j in 0..numFrames
|
||||
pbSetSpritesToColor(sprites,Color.new(0,0,0,((numFrames-j)*alphaDiff)))
|
||||
(block_given?) ? yield : pbUpdateSpriteHash(sprites)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
# Restores which windows are active for the given sprite hash.
|
||||
# _activeStatuses_ is the result of a previous call to pbActivateWindows
|
||||
def pbRestoreActivations(sprites,activeStatuses)
|
||||
return if !sprites || !activeStatuses
|
||||
for k in activeStatuses.keys
|
||||
if sprites[k] && sprites[k].is_a?(Window) && !pbDisposed?(sprites[k])
|
||||
sprites[k].active=activeStatuses[k] ? true : false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Deactivates all windows. If a code block is given, deactivates all windows,
|
||||
# runs the code in the block, and reactivates them.
|
||||
def pbDeactivateWindows(sprites)
|
||||
if block_given?
|
||||
pbActivateWindow(sprites,nil) { yield }
|
||||
else
|
||||
pbActivateWindow(sprites,nil)
|
||||
end
|
||||
end
|
||||
|
||||
# Activates a specific window of a sprite hash. _key_ is the key of the window
|
||||
# in the sprite hash. If a code block is given, deactivates all windows except
|
||||
# the specified window, runs the code in the block, and reactivates them.
|
||||
def pbActivateWindow(sprites,key)
|
||||
return if !sprites
|
||||
activeStatuses={}
|
||||
for i in sprites
|
||||
if i[1] && i[1].is_a?(Window) && !pbDisposed?(i[1])
|
||||
activeStatuses[i[0]]=i[1].active
|
||||
i[1].active=(i[0]==key)
|
||||
end
|
||||
end
|
||||
if block_given?
|
||||
begin
|
||||
yield
|
||||
ensure
|
||||
pbRestoreActivations(sprites,activeStatuses)
|
||||
end
|
||||
return {}
|
||||
else
|
||||
return activeStatuses
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# Create background planes for a sprite hash
|
||||
#===============================================================================
|
||||
# Adds a background to the sprite hash.
|
||||
# _planename_ is the hash key of the background.
|
||||
# _background_ is a filename within the Graphics/Pictures/ folder and can be
|
||||
# an animated image.
|
||||
# _viewport_ is a viewport to place the background in.
|
||||
def addBackgroundPlane(sprites,planename,background,viewport=nil)
|
||||
sprites[planename]=AnimatedPlane.new(viewport)
|
||||
bitmapName=pbResolveBitmap("Graphics/Pictures/#{background}")
|
||||
if bitmapName==nil
|
||||
# Plane should exist in any case
|
||||
sprites[planename].bitmap=nil
|
||||
sprites[planename].visible=false
|
||||
else
|
||||
sprites[planename].setBitmap(bitmapName)
|
||||
for spr in sprites.values
|
||||
if spr.is_a?(Window)
|
||||
spr.windowskin=nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Adds a background to the sprite hash.
|
||||
# _planename_ is the hash key of the background.
|
||||
# _background_ is a filename within the Graphics/Pictures/ folder and can be
|
||||
# an animated image.
|
||||
# _color_ is the color to use if the background can't be found.
|
||||
# _viewport_ is a viewport to place the background in.
|
||||
def addBackgroundOrColoredPlane(sprites,planename,background,color,viewport=nil)
|
||||
bitmapName=pbResolveBitmap("Graphics/Pictures/#{background}")
|
||||
if bitmapName==nil
|
||||
# Plane should exist in any case
|
||||
sprites[planename]=ColoredPlane.new(color,@viewport)
|
||||
else
|
||||
sprites[planename]=AnimatedPlane.new(viewport)
|
||||
sprites[planename].setBitmap(bitmapName)
|
||||
for spr in sprites.values
|
||||
if spr.is_a?(Window)
|
||||
spr.windowskin=nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# Ensure required method definitions
|
||||
#===============================================================================
|
||||
module Graphics
|
||||
if !self.respond_to?("width")
|
||||
def self.width; return 640; end
|
||||
end
|
||||
if !self.respond_to?("height")
|
||||
def self.height; return 480; end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
if !defined?(_INTL)
|
||||
def _INTL(*args)
|
||||
string=args[0].clone
|
||||
for i in 1...args.length
|
||||
string.gsub!(/\{#{i}\}/,"#{args[i]}")
|
||||
end
|
||||
return string
|
||||
end
|
||||
end
|
||||
|
||||
if !defined?(_ISPRINTF)
|
||||
def _ISPRINTF(*args)
|
||||
string=args[0].clone
|
||||
for i in 1...args.length
|
||||
string.gsub!(/\{#{i}\:([^\}]+?)\}/) { |m|
|
||||
next sprintf("%"+$1,args[i])
|
||||
}
|
||||
end
|
||||
return string
|
||||
end
|
||||
end
|
||||
|
||||
if !defined?(_MAPINTL)
|
||||
def _MAPINTL(*args)
|
||||
string=args[1].clone
|
||||
for i in 2...args.length
|
||||
string.gsub!(/\{#{i}\}/,"#{args[i+1]}")
|
||||
end
|
||||
return string
|
||||
end
|
||||
end
|
||||
604
Data/Scripts_backup/007_Objects and windows/003_Window.rb
Normal file
604
Data/Scripts_backup/007_Objects and windows/003_Window.rb
Normal file
@@ -0,0 +1,604 @@
|
||||
class WindowCursorRect < Rect
|
||||
def initialize(window)
|
||||
super(0, 0, 0, 0)
|
||||
@window = window
|
||||
end
|
||||
|
||||
def empty
|
||||
return unless needs_update?(0, 0, 0, 0)
|
||||
|
||||
set(0, 0, 0, 0)
|
||||
end
|
||||
|
||||
def empty?
|
||||
return self.x == 0 && self.y == 0 && self.width == 0 && self.height == 0
|
||||
end
|
||||
|
||||
def set(x, y, width, height)
|
||||
return unless needs_update?(x, y, width, height)
|
||||
|
||||
super(x, y, width, height)
|
||||
|
||||
@window.width = @window.width
|
||||
end
|
||||
|
||||
def height=(value)
|
||||
super(value)
|
||||
@window.width = @window.width
|
||||
end
|
||||
|
||||
def width=(value)
|
||||
super(value)
|
||||
@window.width = @window.width
|
||||
end
|
||||
|
||||
def x=(value)
|
||||
super(value)
|
||||
@window.width = @window.width
|
||||
end
|
||||
|
||||
def y=(value)
|
||||
super(value)
|
||||
@window.width = @window.width
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def needs_update?(x, y, width, height)
|
||||
return self.x != x || self.y != y || self.width != width || self.height != height
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class Window
|
||||
attr_reader :tone
|
||||
attr_reader :color
|
||||
attr_reader :blend_type
|
||||
attr_reader :contents_blend_type
|
||||
attr_reader :viewport
|
||||
attr_reader :contents
|
||||
attr_reader :ox
|
||||
attr_reader :oy
|
||||
attr_reader :x
|
||||
attr_reader :y
|
||||
attr_reader :z
|
||||
attr_reader :width
|
||||
attr_reader :active
|
||||
attr_reader :pause
|
||||
attr_reader :height
|
||||
attr_reader :opacity
|
||||
attr_reader :back_opacity
|
||||
attr_reader :contents_opacity
|
||||
attr_reader :visible
|
||||
attr_reader :cursor_rect
|
||||
attr_reader :openness
|
||||
attr_reader :stretch
|
||||
|
||||
def windowskin
|
||||
@_windowskin
|
||||
end
|
||||
|
||||
def initialize(viewport=nil)
|
||||
@sprites={}
|
||||
@spritekeys=[
|
||||
"back",
|
||||
"corner0","side0","scroll0",
|
||||
"corner1","side1","scroll1",
|
||||
"corner2","side2","scroll2",
|
||||
"corner3","side3","scroll3",
|
||||
"cursor","contents","pause"
|
||||
]
|
||||
@sidebitmaps=[nil,nil,nil,nil]
|
||||
@cursorbitmap=nil
|
||||
@bgbitmap=nil
|
||||
@viewport=viewport
|
||||
for i in @spritekeys
|
||||
@sprites[i]=Sprite.new(@viewport)
|
||||
end
|
||||
@disposed=false
|
||||
@tone=Tone.new(0,0,0)
|
||||
@color=Color.new(0,0,0,0)
|
||||
@blankcontents=Bitmap.new(1,1) # RGSS2 requires this
|
||||
@contents=@blankcontents
|
||||
@_windowskin=nil
|
||||
@rpgvx=false # Set to true to emulate RPGVX windows
|
||||
@x=0
|
||||
@y=0
|
||||
@width=0
|
||||
@openness=255
|
||||
@height=0
|
||||
@ox=0
|
||||
@oy=0
|
||||
@z=0
|
||||
@stretch=true
|
||||
@visible=true
|
||||
@active=true
|
||||
@blend_type=0
|
||||
@contents_blend_type=0
|
||||
@opacity=255
|
||||
@back_opacity=255
|
||||
@contents_opacity=255
|
||||
@cursor_rect=WindowCursorRect.new(self)
|
||||
@cursorblink=0
|
||||
@cursoropacity=255
|
||||
@pause=false
|
||||
@pauseopacity=255
|
||||
@pauseframe=0
|
||||
privRefresh(true)
|
||||
end
|
||||
|
||||
def dispose
|
||||
if !self.disposed?
|
||||
for i in @sprites
|
||||
i[1].dispose if i[1]
|
||||
@sprites[i[0]]=nil
|
||||
end
|
||||
for i in 0...@sidebitmaps.length
|
||||
@sidebitmaps[i].dispose if @sidebitmaps[i]
|
||||
@sidebitmaps[i]=nil
|
||||
end
|
||||
@blankcontents.dispose
|
||||
@cursorbitmap.dispose if @cursorbitmap
|
||||
@backbitmap.dispose if @backbitmap
|
||||
@sprites.clear
|
||||
@sidebitmaps.clear
|
||||
@_windowskin=nil
|
||||
@_contents=nil
|
||||
@disposed=true
|
||||
end
|
||||
end
|
||||
|
||||
def openness=(value)
|
||||
@openness=value
|
||||
@openness=0 if @openness<0
|
||||
@openness=255 if @openness>255
|
||||
privRefresh
|
||||
end
|
||||
|
||||
def stretch=(value)
|
||||
@stretch=value
|
||||
privRefresh(true)
|
||||
end
|
||||
|
||||
def visible=(value)
|
||||
@visible=value
|
||||
privRefresh
|
||||
end
|
||||
|
||||
def viewport=(value)
|
||||
@viewport=value
|
||||
for i in @spritekeys
|
||||
@sprites[i].dispose
|
||||
if @sprites[i].is_a?(Sprite)
|
||||
@sprites[i]=Sprite.new(@viewport)
|
||||
else
|
||||
@sprites[i]=nil
|
||||
end
|
||||
end
|
||||
privRefresh(true)
|
||||
end
|
||||
|
||||
def z=(value)
|
||||
@z=value
|
||||
privRefresh
|
||||
end
|
||||
|
||||
def disposed?
|
||||
return @disposed
|
||||
end
|
||||
|
||||
def contents=(value)
|
||||
@contents=value
|
||||
privRefresh
|
||||
end
|
||||
|
||||
def windowskin=(value)
|
||||
@_windowskin=value
|
||||
if value && value.is_a?(Bitmap) && !value.disposed? && value.width==128
|
||||
@rpgvx=true
|
||||
else
|
||||
@rpgvx=false
|
||||
end
|
||||
privRefresh(true)
|
||||
end
|
||||
|
||||
def ox=(value)
|
||||
@ox=value
|
||||
privRefresh
|
||||
end
|
||||
|
||||
def active=(value)
|
||||
@active=value
|
||||
privRefresh(true)
|
||||
end
|
||||
|
||||
def cursor_rect=(value)
|
||||
if !value
|
||||
@cursor_rect.empty
|
||||
else
|
||||
@cursor_rect.set(value.x,value.y,value.width,value.height)
|
||||
end
|
||||
end
|
||||
|
||||
def oy=(value)
|
||||
@oy=value
|
||||
privRefresh
|
||||
end
|
||||
|
||||
def width=(value)
|
||||
@width=value
|
||||
privRefresh(true)
|
||||
end
|
||||
|
||||
def height=(value)
|
||||
@height=value
|
||||
privRefresh(true)
|
||||
end
|
||||
|
||||
def pause=(value)
|
||||
@pause=value
|
||||
@pauseopacity=0 if !value
|
||||
privRefresh
|
||||
end
|
||||
|
||||
def x=(value)
|
||||
@x=value
|
||||
privRefresh
|
||||
end
|
||||
|
||||
def y=(value)
|
||||
@y=value
|
||||
privRefresh
|
||||
end
|
||||
|
||||
def opacity=(value)
|
||||
@opacity=value
|
||||
@opacity=0 if @opacity<0
|
||||
@opacity=255 if @opacity>255
|
||||
privRefresh
|
||||
end
|
||||
|
||||
def back_opacity=(value)
|
||||
@back_opacity=value
|
||||
@back_opacity=0 if @back_opacity<0
|
||||
@back_opacity=255 if @back_opacity>255
|
||||
privRefresh
|
||||
end
|
||||
|
||||
def contents_opacity=(value)
|
||||
@contents_opacity=value
|
||||
@contents_opacity=0 if @contents_opacity<0
|
||||
@contents_opacity=255 if @contents_opacity>255
|
||||
privRefresh
|
||||
end
|
||||
|
||||
def tone=(value)
|
||||
@tone=value
|
||||
privRefresh
|
||||
end
|
||||
|
||||
def color=(value)
|
||||
@color=value
|
||||
privRefresh
|
||||
end
|
||||
|
||||
def blend_type=(value)
|
||||
@blend_type=value
|
||||
privRefresh
|
||||
end
|
||||
|
||||
def flash(color,duration)
|
||||
return if disposed?
|
||||
for i in @sprites
|
||||
i[1].flash(color,duration)
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
return if disposed?
|
||||
mustchange=false
|
||||
if @active
|
||||
if @cursorblink==0
|
||||
@cursoropacity-=8
|
||||
@cursorblink=1 if @cursoropacity<=128
|
||||
else
|
||||
@cursoropacity+=8
|
||||
@cursorblink=0 if @cursoropacity>=255
|
||||
end
|
||||
mustchange=true if !@cursor_rect.empty?
|
||||
else
|
||||
mustchange=true if @cursoropacity!=128
|
||||
@cursoropacity=128
|
||||
end
|
||||
if @pause
|
||||
@pauseframe=(Graphics.frame_count / 8) % 4
|
||||
@pauseopacity=[@pauseopacity+64,255].min
|
||||
mustchange=true
|
||||
end
|
||||
privRefresh if mustchange
|
||||
for i in @sprites
|
||||
i[1].update
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ensureBitmap(bitmap,dwidth,dheight)
|
||||
if !bitmap||bitmap.disposed?||bitmap.width<dwidth||bitmap.height<dheight
|
||||
bitmap.dispose if bitmap
|
||||
bitmap=Bitmap.new([1,dwidth].max,[1,dheight].max)
|
||||
end
|
||||
return bitmap
|
||||
end
|
||||
|
||||
def tileBitmap(dstbitmap,dstrect,srcbitmap,srcrect)
|
||||
return if !srcbitmap || srcbitmap.disposed?
|
||||
left=dstrect.x
|
||||
top=dstrect.y
|
||||
y=0;loop do break unless y<dstrect.height
|
||||
x=0;loop do break unless x<dstrect.width
|
||||
dstbitmap.blt(x+left,y+top,srcbitmap,srcrect)
|
||||
x+=srcrect.width
|
||||
end
|
||||
y+=srcrect.height
|
||||
end
|
||||
end
|
||||
|
||||
def privRefresh(changeBitmap=false)
|
||||
return if self.disposed?
|
||||
backopac=self.back_opacity*self.opacity/255
|
||||
contopac=self.contents_opacity
|
||||
cursoropac=@cursoropacity*contopac/255
|
||||
for i in 0...4
|
||||
@sprites["corner#{i}"].bitmap=@_windowskin
|
||||
@sprites["scroll#{i}"].bitmap=@_windowskin
|
||||
end
|
||||
@sprites["pause"].bitmap=@_windowskin
|
||||
@sprites["contents"].bitmap=@contents
|
||||
if @_windowskin && !@_windowskin.disposed?
|
||||
for i in 0...4
|
||||
@sprites["corner#{i}"].opacity=@opacity
|
||||
@sprites["corner#{i}"].tone=@tone
|
||||
@sprites["corner#{i}"].color=@color
|
||||
@sprites["corner#{i}"].blend_type=@blend_type
|
||||
@sprites["corner#{i}"].visible=@visible
|
||||
@sprites["side#{i}"].opacity=@opacity
|
||||
@sprites["side#{i}"].tone=@tone
|
||||
@sprites["side#{i}"].color=@color
|
||||
@sprites["side#{i}"].blend_type=@blend_type
|
||||
@sprites["side#{i}"].visible=@visible
|
||||
@sprites["scroll#{i}"].opacity=@opacity
|
||||
@sprites["scroll#{i}"].tone=@tone
|
||||
@sprites["scroll#{i}"].blend_type=@blend_type
|
||||
@sprites["scroll#{i}"].color=@color
|
||||
@sprites["scroll#{i}"].visible=@visible
|
||||
end
|
||||
for i in ["back","cursor","pause","contents"]
|
||||
@sprites[i].color=@color
|
||||
@sprites[i].tone=@tone
|
||||
@sprites[i].blend_type=@blend_type
|
||||
end
|
||||
@sprites["contents"].blend_type=@contents_blend_type
|
||||
@sprites["back"].opacity=backopac
|
||||
@sprites["contents"].opacity=contopac
|
||||
@sprites["cursor"].opacity=cursoropac
|
||||
@sprites["pause"].opacity=@pauseopacity
|
||||
@sprites["back"].visible=@visible
|
||||
@sprites["contents"].visible=@visible && @openness==255
|
||||
@sprites["pause"].visible=@visible && @pause
|
||||
@sprites["cursor"].visible=@visible && @openness==255
|
||||
hascontents=(@contents && !@contents.disposed?)
|
||||
@sprites["scroll0"].visible = @visible && hascontents && @oy > 0
|
||||
@sprites["scroll1"].visible = @visible && hascontents && @ox > 0
|
||||
@sprites["scroll2"].visible = @visible && hascontents &&
|
||||
(@contents.width - @ox) > @width-32
|
||||
@sprites["scroll3"].visible = @visible && hascontents &&
|
||||
(@contents.height - @oy) > @height-32
|
||||
else
|
||||
for i in 0...4
|
||||
@sprites["corner#{i}"].visible=false
|
||||
@sprites["side#{i}"].visible=false
|
||||
@sprites["scroll#{i}"].visible=false
|
||||
end
|
||||
@sprites["contents"].visible=@visible && @openness==255
|
||||
@sprites["contents"].color=@color
|
||||
@sprites["contents"].tone=@tone
|
||||
@sprites["contents"].blend_type=@contents_blend_type
|
||||
@sprites["contents"].opacity=contopac
|
||||
@sprites["back"].visible=false
|
||||
@sprites["pause"].visible=false
|
||||
@sprites["cursor"].visible=false
|
||||
end
|
||||
for i in @sprites
|
||||
i[1].z=@z
|
||||
end
|
||||
if @rpgvx
|
||||
@sprites["cursor"].z=@z # For Compatibility
|
||||
@sprites["contents"].z=@z # For Compatibility
|
||||
@sprites["pause"].z=@z # For Compatibility
|
||||
else
|
||||
@sprites["cursor"].z=@z+1 # For Compatibility
|
||||
@sprites["contents"].z=@z+2 # For Compatibility
|
||||
@sprites["pause"].z=@z+2 # For Compatibility
|
||||
end
|
||||
if @rpgvx
|
||||
trimX=64
|
||||
trimY=0
|
||||
backRect=Rect.new(0,0,64,64)
|
||||
blindsRect=Rect.new(0,64,64,64)
|
||||
else
|
||||
trimX=128
|
||||
trimY=0
|
||||
backRect=Rect.new(0,0,128,128)
|
||||
blindsRect=nil
|
||||
end
|
||||
@sprites["corner0"].src_rect.set(trimX,trimY+0,16,16);
|
||||
@sprites["corner1"].src_rect.set(trimX+48,trimY+0,16,16);
|
||||
@sprites["corner2"].src_rect.set(trimX,trimY+48,16,16);
|
||||
@sprites["corner3"].src_rect.set(trimX+48,trimY+48,16,16);
|
||||
@sprites["scroll0"].src_rect.set(trimX+24, trimY+16, 16, 8) # up
|
||||
@sprites["scroll3"].src_rect.set(trimX+24, trimY+40, 16, 8) # down
|
||||
@sprites["scroll1"].src_rect.set(trimX+16, trimY+24, 8, 16) # left
|
||||
@sprites["scroll2"].src_rect.set(trimX+40, trimY+24, 8, 16) # right
|
||||
cursorX=trimX
|
||||
cursorY=trimY+64
|
||||
sideRects=[
|
||||
Rect.new(trimX+16,trimY+0,32,16),
|
||||
Rect.new(trimX,trimY+16,16,32),
|
||||
Rect.new(trimX+48,trimY+16,16,32),
|
||||
Rect.new(trimX+16,trimY+48,32,16)
|
||||
]
|
||||
if @width>32 && @height>32
|
||||
@sprites["contents"].src_rect.set(@ox,@oy,@width-32,@height-32)
|
||||
else
|
||||
@sprites["contents"].src_rect.set(0,0,0,0)
|
||||
end
|
||||
pauseRects=[
|
||||
trimX+32,trimY+64,
|
||||
trimX+48,trimY+64,
|
||||
trimX+32,trimY+80,
|
||||
trimX+48,trimY+80,
|
||||
]
|
||||
pauseWidth=16
|
||||
pauseHeight=16
|
||||
@sprites["pause"].src_rect.set(
|
||||
pauseRects[@pauseframe*2],
|
||||
pauseRects[@pauseframe*2+1],
|
||||
pauseWidth,pauseHeight
|
||||
)
|
||||
@sprites["pause"].x=@x+(@width/2)-(pauseWidth/2)
|
||||
@sprites["pause"].y=@y+@height-16 # 16 refers to skin margin
|
||||
@sprites["contents"].x=@x+16
|
||||
@sprites["contents"].y=@y+16
|
||||
@sprites["corner0"].x=@x
|
||||
@sprites["corner0"].y=@y
|
||||
@sprites["corner1"].x=@x+@width-16
|
||||
@sprites["corner1"].y=@y
|
||||
@sprites["corner2"].x=@x
|
||||
@sprites["corner2"].y=@y+@height-16
|
||||
@sprites["corner3"].x=@x+@width-16
|
||||
@sprites["corner3"].y=@y+@height-16
|
||||
@sprites["side0"].x=@x+16
|
||||
@sprites["side0"].y=@y
|
||||
@sprites["side1"].x=@x
|
||||
@sprites["side1"].y=@y+16
|
||||
@sprites["side2"].x=@x+@width-16
|
||||
@sprites["side2"].y=@y+16
|
||||
@sprites["side3"].x=@x+16
|
||||
@sprites["side3"].y=@y+@height-16
|
||||
@sprites["scroll0"].x = @x+@width / 2 - 8
|
||||
@sprites["scroll0"].y = @y+8
|
||||
@sprites["scroll1"].x = @x+8
|
||||
@sprites["scroll1"].y = @y+@height / 2 - 8
|
||||
@sprites["scroll2"].x = @x+@width - 16
|
||||
@sprites["scroll2"].y = @y+@height / 2 - 8
|
||||
@sprites["scroll3"].x = @x+@width / 2 - 8
|
||||
@sprites["scroll3"].y = @y+@height - 16
|
||||
@sprites["back"].x=@x+2
|
||||
@sprites["back"].y=@y+2
|
||||
@sprites["cursor"].x=@x+16+@cursor_rect.x
|
||||
@sprites["cursor"].y=@y+16+@cursor_rect.y
|
||||
if changeBitmap && @_windowskin && !@_windowskin.disposed?
|
||||
width=@cursor_rect.width
|
||||
height=@cursor_rect.height
|
||||
if width > 0 && height > 0
|
||||
cursorrects=[
|
||||
# sides
|
||||
Rect.new(cursorX+2, cursorY+0, 28, 2),
|
||||
Rect.new(cursorX+0, cursorY+2, 2, 28),
|
||||
Rect.new(cursorX+30, cursorY+2, 2, 28),
|
||||
Rect.new(cursorX+2, cursorY+30, 28, 2),
|
||||
# corners
|
||||
Rect.new(cursorX+0, cursorY+0, 2, 2),
|
||||
Rect.new(cursorX+30, cursorY+0, 2, 2),
|
||||
Rect.new(cursorX+0, cursorY+30, 2, 2),
|
||||
Rect.new(cursorX+30, cursorY+30, 2, 2),
|
||||
# back
|
||||
Rect.new(cursorX+2, cursorY+2, 28, 28)
|
||||
]
|
||||
margin=2
|
||||
fullmargin=4
|
||||
@cursorbitmap = ensureBitmap(@cursorbitmap, width, height)
|
||||
@cursorbitmap.clear
|
||||
@sprites["cursor"].bitmap=@cursorbitmap
|
||||
@sprites["cursor"].src_rect.set(0,0,width,height)
|
||||
rect = Rect.new(margin,margin,
|
||||
width - fullmargin, height - fullmargin)
|
||||
@cursorbitmap.stretch_blt(rect, @_windowskin, cursorrects[8])
|
||||
@cursorbitmap.blt(0, 0, @_windowskin, cursorrects[4])# top left
|
||||
@cursorbitmap.blt(width-margin, 0, @_windowskin, cursorrects[5]) # top right
|
||||
@cursorbitmap.blt(0, height-margin, @_windowskin, cursorrects[6]) # bottom right
|
||||
@cursorbitmap.blt(width-margin, height-margin, @_windowskin, cursorrects[7]) # bottom left
|
||||
rect = Rect.new(margin, 0,
|
||||
width - fullmargin, margin)
|
||||
@cursorbitmap.stretch_blt(rect, @_windowskin, cursorrects[0])
|
||||
rect = Rect.new(0, margin,
|
||||
margin, height - fullmargin)
|
||||
@cursorbitmap.stretch_blt(rect, @_windowskin, cursorrects[1])
|
||||
rect = Rect.new(width - margin, margin,
|
||||
margin, height - fullmargin)
|
||||
@cursorbitmap.stretch_blt(rect, @_windowskin, cursorrects[2])
|
||||
rect = Rect.new(margin, height-margin,
|
||||
width - fullmargin, margin)
|
||||
@cursorbitmap.stretch_blt(rect, @_windowskin, cursorrects[3])
|
||||
else
|
||||
@sprites["cursor"].visible=false
|
||||
@sprites["cursor"].src_rect.set(0,0,0,0)
|
||||
end
|
||||
for i in 0...4
|
||||
dwidth = (i==0 || i==3) ? @width-32 : 16
|
||||
dheight = (i==0 || i==3) ? 16 : @height-32
|
||||
@sidebitmaps[i]=ensureBitmap(@sidebitmaps[i],dwidth,dheight)
|
||||
@sprites["side#{i}"].bitmap=@sidebitmaps[i]
|
||||
@sprites["side#{i}"].src_rect.set(0,0,dwidth,dheight)
|
||||
@sidebitmaps[i].clear
|
||||
if sideRects[i].width>0 && sideRects[i].height>0
|
||||
@sidebitmaps[i].stretch_blt(@sprites["side#{i}"].src_rect,
|
||||
@_windowskin,sideRects[i])
|
||||
end
|
||||
end
|
||||
backwidth=@width-4
|
||||
backheight=@height-4
|
||||
if backwidth>0 && backheight>0
|
||||
@backbitmap=ensureBitmap(@backbitmap,backwidth,backheight)
|
||||
@sprites["back"].bitmap=@backbitmap
|
||||
@sprites["back"].src_rect.set(0,0,backwidth,backheight)
|
||||
@backbitmap.clear
|
||||
if @stretch
|
||||
@backbitmap.stretch_blt(@sprites["back"].src_rect,@_windowskin,backRect)
|
||||
else
|
||||
tileBitmap(@backbitmap,@sprites["back"].src_rect,@_windowskin,backRect)
|
||||
end
|
||||
if blindsRect
|
||||
tileBitmap(@backbitmap,@sprites["back"].src_rect,@_windowskin,blindsRect)
|
||||
end
|
||||
else
|
||||
@sprites["back"].visible=false
|
||||
@sprites["back"].src_rect.set(0,0,0,0)
|
||||
end
|
||||
end
|
||||
if @openness!=255
|
||||
opn=@openness/255.0
|
||||
for k in @spritekeys
|
||||
sprite=@sprites[k]
|
||||
ratio=(@height<=0) ? 0 : (sprite.y-@y)*1.0/@height
|
||||
sprite.zoom_y=opn
|
||||
sprite.oy=0
|
||||
sprite.y=(@y+(@height/2.0)+(@height*ratio*opn)-(@height/2*opn)).floor
|
||||
end
|
||||
else
|
||||
for k in @spritekeys
|
||||
sprite=@sprites[k]
|
||||
sprite.zoom_y=1.0
|
||||
end
|
||||
end
|
||||
i=0
|
||||
# Ensure Z order
|
||||
for k in @spritekeys
|
||||
sprite=@sprites[k]
|
||||
y=sprite.y
|
||||
sprite.y=i
|
||||
sprite.oy=(sprite.zoom_y<=0) ? 0 : (i-y)/sprite.zoom_y
|
||||
end
|
||||
end
|
||||
end
|
||||
936
Data/Scripts_backup/007_Objects and windows/004_SpriteWindow.rb
Normal file
936
Data/Scripts_backup/007_Objects and windows/004_SpriteWindow.rb
Normal file
@@ -0,0 +1,936 @@
|
||||
#===============================================================================
|
||||
# SpriteWindow is a class based on Window which emulates Window's functionality.
|
||||
# This class is necessary in order to change the viewport of windows (with
|
||||
# viewport=) and to make windows fade in and out (with tone=).
|
||||
#===============================================================================
|
||||
class SpriteWindow < Window
|
||||
attr_reader :tone
|
||||
attr_reader :color
|
||||
attr_reader :viewport
|
||||
attr_reader :contents
|
||||
attr_reader :ox
|
||||
attr_reader :oy
|
||||
attr_reader :x
|
||||
attr_reader :y
|
||||
attr_reader :z
|
||||
attr_reader :zoom_x
|
||||
attr_reader :zoom_y
|
||||
attr_reader :offset_x
|
||||
attr_reader :offset_y
|
||||
attr_reader :width
|
||||
attr_reader :active
|
||||
attr_reader :pause
|
||||
attr_reader :height
|
||||
attr_reader :opacity
|
||||
attr_reader :back_opacity
|
||||
attr_reader :contents_opacity
|
||||
attr_reader :visible
|
||||
attr_reader :cursor_rect
|
||||
attr_reader :contents_blend_type
|
||||
attr_reader :blend_type
|
||||
attr_reader :openness
|
||||
|
||||
def windowskin
|
||||
@_windowskin
|
||||
end
|
||||
|
||||
# Flags used to preserve compatibility
|
||||
# with RGSS/RGSS2's version of Window
|
||||
module CompatBits
|
||||
CorrectZ = 1
|
||||
ExpandBack = 2
|
||||
ShowScrollArrows = 4
|
||||
StretchSides = 8
|
||||
ShowPause = 16
|
||||
ShowCursor = 32
|
||||
end
|
||||
|
||||
attr_reader :compat
|
||||
|
||||
def compat=(value)
|
||||
@compat=value
|
||||
privRefresh(true)
|
||||
end
|
||||
|
||||
def initialize(viewport=nil)
|
||||
@sprites={}
|
||||
@spritekeys=[
|
||||
"back",
|
||||
"corner0","side0","scroll0",
|
||||
"corner1","side1","scroll1",
|
||||
"corner2","side2","scroll2",
|
||||
"corner3","side3","scroll3",
|
||||
"cursor","contents","pause"
|
||||
]
|
||||
@viewport=viewport
|
||||
@sidebitmaps=[nil,nil,nil,nil]
|
||||
@cursorbitmap=nil
|
||||
@bgbitmap=nil
|
||||
for i in @spritekeys
|
||||
@sprites[i]=Sprite.new(@viewport)
|
||||
end
|
||||
@disposed=false
|
||||
@tone=Tone.new(0,0,0)
|
||||
@color=Color.new(0,0,0,0)
|
||||
@blankcontents=Bitmap.new(1,1) # RGSS2 requires this
|
||||
@contents=@blankcontents
|
||||
@_windowskin=nil
|
||||
@rpgvx=false
|
||||
@compat=CompatBits::ExpandBack|CompatBits::StretchSides
|
||||
@x=0
|
||||
@y=0
|
||||
@width=0
|
||||
@height=0
|
||||
@offset_x=0
|
||||
@offset_y=0
|
||||
@zoom_x=1.0
|
||||
@zoom_y=1.0
|
||||
@ox=0
|
||||
@oy=0
|
||||
@z=0
|
||||
@stretch=true
|
||||
@visible=true
|
||||
@active=true
|
||||
@openness=255
|
||||
@opacity=255
|
||||
@back_opacity=255
|
||||
@blend_type=0
|
||||
@contents_blend_type=0
|
||||
@contents_opacity=255
|
||||
@cursor_rect=WindowCursorRect.new(self)
|
||||
@cursorblink=0
|
||||
@cursoropacity=255
|
||||
@pause=false
|
||||
@pauseframe=0
|
||||
@flash=0
|
||||
@pauseopacity=0
|
||||
@skinformat=0
|
||||
@skinrect=Rect.new(0,0,0,0)
|
||||
@trim=[16,16,16,16]
|
||||
privRefresh(true)
|
||||
end
|
||||
|
||||
def dispose
|
||||
if !self.disposed?
|
||||
for i in @sprites
|
||||
i[1].dispose if i[1]
|
||||
@sprites[i[0]]=nil
|
||||
end
|
||||
for i in 0...@sidebitmaps.length
|
||||
@sidebitmaps[i].dispose if @sidebitmaps[i]
|
||||
@sidebitmaps[i]=nil
|
||||
end
|
||||
@blankcontents.dispose
|
||||
@cursorbitmap.dispose if @cursorbitmap
|
||||
@backbitmap.dispose if @backbitmap
|
||||
@sprites.clear
|
||||
@sidebitmaps.clear
|
||||
@_windowskin=nil
|
||||
@disposed=true
|
||||
end
|
||||
end
|
||||
|
||||
def stretch=(value)
|
||||
@stretch=value
|
||||
privRefresh(true)
|
||||
end
|
||||
|
||||
def visible=(value)
|
||||
@visible=value
|
||||
privRefresh
|
||||
end
|
||||
|
||||
def viewport=(value)
|
||||
@viewport=value
|
||||
for i in @spritekeys
|
||||
@sprites[i].dispose if @sprites[i]
|
||||
end
|
||||
for i in @spritekeys
|
||||
if @sprites[i].is_a?(Sprite)
|
||||
@sprites[i]=Sprite.new(@viewport)
|
||||
else
|
||||
@sprites[i]=nil
|
||||
end
|
||||
end
|
||||
privRefresh(true)
|
||||
end
|
||||
|
||||
def z=(value)
|
||||
@z=value
|
||||
privRefresh
|
||||
end
|
||||
|
||||
def disposed?
|
||||
return @disposed
|
||||
end
|
||||
|
||||
def contents=(value)
|
||||
if @contents!=value
|
||||
@contents=value
|
||||
privRefresh if @visible
|
||||
end
|
||||
end
|
||||
|
||||
def ox=(value)
|
||||
if @ox!=value
|
||||
@ox=value
|
||||
privRefresh if @visible
|
||||
end
|
||||
end
|
||||
|
||||
def oy=(value)
|
||||
if @oy!=value
|
||||
@oy=value
|
||||
privRefresh if @visible
|
||||
end
|
||||
end
|
||||
|
||||
def active=(value)
|
||||
@active=value
|
||||
privRefresh(true)
|
||||
end
|
||||
|
||||
def cursor_rect=(value)
|
||||
if !value
|
||||
@cursor_rect.empty
|
||||
else
|
||||
@cursor_rect.set(value.x,value.y,value.width,value.height)
|
||||
end
|
||||
end
|
||||
|
||||
def openness=(value)
|
||||
@openness=value
|
||||
@openness=0 if @openness<0
|
||||
@openness=255 if @openness>255
|
||||
privRefresh
|
||||
end
|
||||
|
||||
def width=(value)
|
||||
@width=value
|
||||
privRefresh(true)
|
||||
end
|
||||
|
||||
def height=(value)
|
||||
@height=value
|
||||
privRefresh(true)
|
||||
end
|
||||
|
||||
def pause=(value)
|
||||
@pause=value
|
||||
@pauseopacity=0 if !value
|
||||
privRefresh if @visible
|
||||
end
|
||||
|
||||
def x=(value)
|
||||
@x=value
|
||||
privRefresh if @visible
|
||||
end
|
||||
|
||||
def y=(value)
|
||||
@y=value
|
||||
privRefresh if @visible
|
||||
end
|
||||
|
||||
def zoom_x=(value)
|
||||
@zoom_x=value
|
||||
privRefresh if @visible
|
||||
end
|
||||
|
||||
def zoom_y=(value)
|
||||
@zoom_y=value
|
||||
privRefresh if @visible
|
||||
end
|
||||
|
||||
def offset_x=(value)
|
||||
@x=value
|
||||
privRefresh if @visible
|
||||
end
|
||||
|
||||
def offset_y=(value)
|
||||
@y=value
|
||||
privRefresh if @visible
|
||||
end
|
||||
|
||||
def opacity=(value)
|
||||
@opacity=value
|
||||
@opacity=0 if @opacity<0
|
||||
@opacity=255 if @opacity>255
|
||||
privRefresh if @visible
|
||||
end
|
||||
|
||||
def back_opacity=(value)
|
||||
@back_opacity=value
|
||||
@back_opacity=0 if @back_opacity<0
|
||||
@back_opacity=255 if @back_opacity>255
|
||||
privRefresh if @visible
|
||||
end
|
||||
|
||||
def contents_opacity=(value)
|
||||
@contents_opacity=value
|
||||
@contents_opacity=0 if @contents_opacity<0
|
||||
@contents_opacity=255 if @contents_opacity>255
|
||||
privRefresh if @visible
|
||||
end
|
||||
|
||||
def tone=(value)
|
||||
@tone=value
|
||||
privRefresh if @visible
|
||||
end
|
||||
|
||||
def color=(value)
|
||||
@color=value
|
||||
privRefresh if @visible
|
||||
end
|
||||
|
||||
def blend_type=(value)
|
||||
@blend_type=value
|
||||
privRefresh if @visible
|
||||
end
|
||||
|
||||
def flash(color,duration)
|
||||
return if disposed?
|
||||
@flash=duration+1
|
||||
for i in @sprites
|
||||
i[1].flash(color,duration)
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
return if disposed?
|
||||
mustchange=false
|
||||
if @active
|
||||
if @cursorblink==0
|
||||
@cursoropacity-=8
|
||||
@cursorblink=1 if @cursoropacity<=128
|
||||
else
|
||||
@cursoropacity+=8
|
||||
@cursorblink=0 if @cursoropacity>=255
|
||||
end
|
||||
privRefreshCursor
|
||||
else
|
||||
@cursoropacity=128
|
||||
privRefreshCursor
|
||||
end
|
||||
if @pause
|
||||
oldpauseframe=@pauseframe
|
||||
oldpauseopacity=@pauseopacity
|
||||
@pauseframe=(Graphics.frame_count / 8) % 4
|
||||
@pauseopacity=[@pauseopacity+64,255].min
|
||||
mustchange=@pauseframe!=oldpauseframe || @pauseopacity!=oldpauseopacity
|
||||
end
|
||||
privRefresh if mustchange
|
||||
if @flash>0
|
||||
for i in @sprites.values
|
||||
i.update
|
||||
end
|
||||
@flash-=1
|
||||
end
|
||||
end
|
||||
|
||||
#############
|
||||
attr_reader :skinformat
|
||||
attr_reader :skinrect
|
||||
|
||||
def loadSkinFile(_file)
|
||||
if (self.windowskin.width==80 || self.windowskin.width==96) &&
|
||||
self.windowskin.height==48
|
||||
# Body = X, Y, width, height of body rectangle within windowskin
|
||||
@skinrect.set(32,16,16,16)
|
||||
# Trim = X, Y, width, height of trim rectangle within windowskin
|
||||
@trim=[32,16,16,16]
|
||||
elsif self.windowskin.width==80 && self.windowskin.height==80
|
||||
@skinrect.set(32,32,16,16)
|
||||
@trim=[32,16,16,48]
|
||||
end
|
||||
end
|
||||
|
||||
def windowskin=(value)
|
||||
oldSkinWidth=(@_windowskin && !@_windowskin.disposed?) ? @_windowskin.width : -1
|
||||
oldSkinHeight=(@_windowskin && !@_windowskin.disposed?) ? @_windowskin.height : -1
|
||||
@_windowskin=value
|
||||
if @skinformat==1
|
||||
@rpgvx=false
|
||||
if @_windowskin && !@_windowskin.disposed?
|
||||
if @_windowskin.width!=oldSkinWidth || @_windowskin.height!=oldSkinHeight
|
||||
# Update skinrect and trim if windowskin's dimensions have changed
|
||||
@skinrect.set((@_windowskin.width-16)/2,(@_windowskin.height-16)/2,16,16)
|
||||
@trim=[@skinrect.x,@skinrect.y,@skinrect.x,@skinrect.y]
|
||||
end
|
||||
else
|
||||
@skinrect.set(16,16,16,16)
|
||||
@trim=[16,16,16,16]
|
||||
end
|
||||
else
|
||||
if value && value.is_a?(Bitmap) && !value.disposed? && value.width==128
|
||||
@rpgvx=true
|
||||
else
|
||||
@rpgvx=false
|
||||
end
|
||||
@trim=[16,16,16,16]
|
||||
end
|
||||
privRefresh(true)
|
||||
end
|
||||
|
||||
def skinrect=(value)
|
||||
@skinrect=value
|
||||
privRefresh
|
||||
end
|
||||
|
||||
def skinformat=(value)
|
||||
if @skinformat!=value
|
||||
@skinformat=value
|
||||
privRefresh(true)
|
||||
end
|
||||
end
|
||||
|
||||
def borderX
|
||||
return 32 if !@trim || skinformat==0
|
||||
if @_windowskin && !@_windowskin.disposed?
|
||||
return @trim[0]+(@_windowskin.width-@trim[2]-@trim[0])
|
||||
end
|
||||
return 32
|
||||
end
|
||||
|
||||
def borderY
|
||||
return 32 if !@trim || skinformat==0
|
||||
if @_windowskin && !@_windowskin.disposed?
|
||||
return @trim[1]+(@_windowskin.height-@trim[3]-@trim[1])
|
||||
end
|
||||
return 32
|
||||
end
|
||||
|
||||
def leftEdge; self.startX; end
|
||||
def topEdge; self.startY; end
|
||||
def rightEdge; self.borderX-self.leftEdge; end
|
||||
def bottomEdge; self.borderY-self.topEdge; end
|
||||
|
||||
def startX
|
||||
return !@trim || skinformat==0 ? 16 : @trim[0]
|
||||
end
|
||||
|
||||
def startY
|
||||
return !@trim || skinformat==0 ? 16 : @trim[1]
|
||||
end
|
||||
|
||||
def endX
|
||||
return !@trim || skinformat==0 ? 16 : @trim[2]
|
||||
end
|
||||
|
||||
def endY
|
||||
return !@trim || skinformat==0 ? 16 : @trim[3]
|
||||
end
|
||||
|
||||
def startX=(value)
|
||||
@trim[0]=value
|
||||
privRefresh
|
||||
end
|
||||
|
||||
def startY=(value)
|
||||
@trim[1]=value
|
||||
privRefresh
|
||||
end
|
||||
|
||||
def endX=(value)
|
||||
@trim[2]=value
|
||||
privRefresh
|
||||
end
|
||||
|
||||
def endY=(value)
|
||||
@trim[3]=value
|
||||
privRefresh
|
||||
end
|
||||
|
||||
#############
|
||||
private
|
||||
|
||||
def ensureBitmap(bitmap,dwidth,dheight)
|
||||
if !bitmap||bitmap.disposed?||bitmap.width<dwidth||bitmap.height<dheight
|
||||
bitmap.dispose if bitmap
|
||||
bitmap=Bitmap.new([1,dwidth].max,[1,dheight].max)
|
||||
end
|
||||
return bitmap
|
||||
end
|
||||
|
||||
def tileBitmap(dstbitmap,dstrect,srcbitmap,srcrect)
|
||||
return if !srcbitmap || srcbitmap.disposed?
|
||||
left=dstrect.x
|
||||
top=dstrect.y
|
||||
y=0;loop do break unless y<dstrect.height
|
||||
x=0;loop do break unless x<dstrect.width
|
||||
dstbitmap.blt(x+left,y+top,srcbitmap,srcrect)
|
||||
x+=srcrect.width
|
||||
end
|
||||
y+=srcrect.height
|
||||
end
|
||||
end
|
||||
|
||||
def privRefreshCursor
|
||||
contopac=self.contents_opacity
|
||||
cursoropac=@cursoropacity*contopac/255
|
||||
@sprites["cursor"].opacity=cursoropac
|
||||
end
|
||||
|
||||
def privRefresh(changeBitmap=false)
|
||||
return if !self || self.disposed?
|
||||
backopac=self.back_opacity*self.opacity/255
|
||||
contopac=self.contents_opacity
|
||||
cursoropac=@cursoropacity*contopac/255
|
||||
haveskin=@_windowskin && !@_windowskin.disposed?
|
||||
for i in 0...4
|
||||
@sprites["corner#{i}"].bitmap=@_windowskin
|
||||
@sprites["scroll#{i}"].bitmap=@_windowskin
|
||||
end
|
||||
@sprites["pause"].bitmap=@_windowskin
|
||||
@sprites["contents"].bitmap=@contents
|
||||
if haveskin
|
||||
for i in 0...4
|
||||
@sprites["corner#{i}"].opacity=@opacity
|
||||
@sprites["corner#{i}"].tone=@tone
|
||||
@sprites["corner#{i}"].color=@color
|
||||
@sprites["corner#{i}"].visible=@visible
|
||||
@sprites["corner#{i}"].blend_type=@blend_type
|
||||
@sprites["side#{i}"].opacity=@opacity
|
||||
@sprites["side#{i}"].tone=@tone
|
||||
@sprites["side#{i}"].color=@color
|
||||
@sprites["side#{i}"].blend_type=@blend_type
|
||||
@sprites["side#{i}"].visible=@visible
|
||||
@sprites["scroll#{i}"].opacity=@opacity
|
||||
@sprites["scroll#{i}"].tone=@tone
|
||||
@sprites["scroll#{i}"].color=@color
|
||||
@sprites["scroll#{i}"].visible=@visible
|
||||
@sprites["scroll#{i}"].blend_type=@blend_type
|
||||
end
|
||||
for i in ["back","cursor","pause","contents"]
|
||||
@sprites[i].color=@color
|
||||
@sprites[i].tone=@tone
|
||||
@sprites[i].blend_type=@blend_type
|
||||
end
|
||||
@sprites["contents"].blend_type=@contents_blend_type
|
||||
@sprites["back"].opacity=backopac
|
||||
@sprites["contents"].opacity=contopac
|
||||
@sprites["cursor"].opacity=cursoropac
|
||||
@sprites["pause"].opacity=@pauseopacity
|
||||
supported=(@skinformat==0)
|
||||
hascontents=(@contents && !@contents.disposed?)
|
||||
@sprites["back"].visible=@visible
|
||||
@sprites["contents"].visible=@visible && @openness==255
|
||||
@sprites["pause"].visible=supported && @visible && @pause &&
|
||||
(@combat & CompatBits::ShowPause)
|
||||
@sprites["cursor"].visible=supported && @visible && @openness==255 &&
|
||||
(@combat & CompatBits::ShowCursor)
|
||||
@sprites["scroll0"].visible = false
|
||||
@sprites["scroll1"].visible = false
|
||||
@sprites["scroll2"].visible = false
|
||||
@sprites["scroll3"].visible = false
|
||||
else
|
||||
for i in 0...4
|
||||
@sprites["corner#{i}"].visible=false
|
||||
@sprites["side#{i}"].visible=false
|
||||
@sprites["scroll#{i}"].visible=false
|
||||
end
|
||||
@sprites["contents"].visible=@visible && @openness==255
|
||||
@sprites["contents"].color=@color
|
||||
@sprites["contents"].tone=@tone
|
||||
@sprites["contents"].blend_type=@contents_blend_type
|
||||
@sprites["contents"].opacity=contopac
|
||||
@sprites["back"].visible=false
|
||||
@sprites["pause"].visible=false
|
||||
@sprites["cursor"].visible=false
|
||||
end
|
||||
for i in @spritekeys
|
||||
@sprites[i].z=@z
|
||||
end
|
||||
if (@compat & CompatBits::CorrectZ)>0 && @skinformat==0 && !@rpgvx
|
||||
# Compatibility Mode: Cursor, pause, and contents have higher Z
|
||||
@sprites["cursor"].z=@z+1
|
||||
@sprites["contents"].z=@z+2
|
||||
@sprites["pause"].z=@z+2
|
||||
end
|
||||
if @skinformat==0
|
||||
startX=16
|
||||
startY=16
|
||||
endX=16
|
||||
endY=16
|
||||
trimStartX=16
|
||||
trimStartY=16
|
||||
trimWidth=32
|
||||
trimHeight=32
|
||||
if @rpgvx
|
||||
trimX=64
|
||||
trimY=0
|
||||
backRect=Rect.new(0,0,64,64)
|
||||
blindsRect=Rect.new(0,64,64,64)
|
||||
else
|
||||
trimX=128
|
||||
trimY=0
|
||||
backRect=Rect.new(0,0,128,128)
|
||||
blindsRect=nil
|
||||
end
|
||||
if @_windowskin && !@_windowskin.disposed?
|
||||
@sprites["corner0"].src_rect.set(trimX,trimY+0,16,16);
|
||||
@sprites["corner1"].src_rect.set(trimX+48,trimY+0,16,16);
|
||||
@sprites["corner2"].src_rect.set(trimX,trimY+48,16,16);
|
||||
@sprites["corner3"].src_rect.set(trimX+48,trimY+48,16,16);
|
||||
@sprites["scroll0"].src_rect.set(trimX+24, trimY+16, 16, 8) # up
|
||||
@sprites["scroll3"].src_rect.set(trimX+24, trimY+40, 16, 8) # down
|
||||
@sprites["scroll1"].src_rect.set(trimX+16, trimY+24, 8, 16) # left
|
||||
@sprites["scroll2"].src_rect.set(trimX+40, trimY+24, 8, 16) # right
|
||||
cursorX=trimX
|
||||
cursorY=trimY+64
|
||||
sideRects=[
|
||||
Rect.new(trimX+16,trimY+0,32,16),
|
||||
Rect.new(trimX,trimY+16,16,32),
|
||||
Rect.new(trimX+48,trimY+16,16,32),
|
||||
Rect.new(trimX+16,trimY+48,32,16)
|
||||
]
|
||||
pauseRects=[
|
||||
trimX+32,trimY+64,
|
||||
trimX+48,trimY+64,
|
||||
trimX+32,trimY+80,
|
||||
trimX+48,trimY+80,
|
||||
]
|
||||
pauseWidth=16
|
||||
pauseHeight=16
|
||||
@sprites["pause"].src_rect.set(
|
||||
pauseRects[@pauseframe*2],
|
||||
pauseRects[@pauseframe*2+1],
|
||||
pauseWidth,pauseHeight
|
||||
)
|
||||
end
|
||||
else
|
||||
trimStartX=@trim[0]
|
||||
trimStartY=@trim[1]
|
||||
trimWidth=@trim[0]+(@skinrect.width-@trim[2]+@trim[0])
|
||||
trimHeight=@trim[1]+(@skinrect.height-@trim[3]+@trim[1])
|
||||
if @_windowskin && !@_windowskin.disposed?
|
||||
# width of left end of window
|
||||
startX=@skinrect.x
|
||||
# width of top end of window
|
||||
startY=@skinrect.y
|
||||
cx=@skinrect.x+@skinrect.width # right side of BODY rect
|
||||
cy=@skinrect.y+@skinrect.height # bottom side of BODY rect
|
||||
# width of right end of window
|
||||
endX=(!@_windowskin || @_windowskin.disposed?) ? @skinrect.x : @_windowskin.width-cx
|
||||
# height of bottom end of window
|
||||
endY=(!@_windowskin || @_windowskin.disposed?) ? @skinrect.y : @_windowskin.height-cy
|
||||
@sprites["corner0"].src_rect.set(0,0,startX,startY);
|
||||
@sprites["corner1"].src_rect.set(cx,0,endX,startY);
|
||||
@sprites["corner2"].src_rect.set(0,cy,startX,endY);
|
||||
@sprites["corner3"].src_rect.set(cx,cy,endX,endY);
|
||||
backRect=Rect.new(@skinrect.x,@skinrect.y,
|
||||
@skinrect.width,@skinrect.height);
|
||||
blindsRect=nil
|
||||
sideRects=[
|
||||
Rect.new(startX,0,@skinrect.width,startY), # side0 (top)
|
||||
Rect.new(0,startY,startX,@skinrect.height), # side1 (left)
|
||||
Rect.new(cx,startY,endX,@skinrect.height), # side2 (right)
|
||||
Rect.new(startX,cy,@skinrect.width,endY) # side3 (bottom)
|
||||
]
|
||||
end
|
||||
end
|
||||
if @width>trimWidth && @height>trimHeight
|
||||
@sprites["contents"].src_rect.set(@ox,@oy,@width-trimWidth,@height-trimHeight)
|
||||
else
|
||||
@sprites["contents"].src_rect.set(0,0,0,0)
|
||||
end
|
||||
@sprites["contents"].x=@x+trimStartX
|
||||
@sprites["contents"].y=@y+trimStartY
|
||||
if (@compat & CompatBits::ShowScrollArrows)>0 && @skinformat==0
|
||||
# Compatibility mode: Make scroll arrows visible
|
||||
if @skinformat==0 && @_windowskin && !@_windowskin.disposed? &&
|
||||
@contents && !@contents.disposed?
|
||||
@sprites["scroll0"].visible = @visible && hascontents && @oy > 0
|
||||
@sprites["scroll1"].visible = @visible && hascontents && @ox > 0
|
||||
@sprites["scroll2"].visible = @visible && (@contents.width - @ox) > @width-trimWidth
|
||||
@sprites["scroll3"].visible = @visible && (@contents.height - @oy) > @height-trimHeight
|
||||
end
|
||||
end
|
||||
if @_windowskin && !@_windowskin.disposed?
|
||||
borderX=startX+endX
|
||||
borderY=startY+endY
|
||||
@sprites["corner0"].x=@x
|
||||
@sprites["corner0"].y=@y
|
||||
@sprites["corner1"].x=@x+@width-endX
|
||||
@sprites["corner1"].y=@y
|
||||
@sprites["corner2"].x=@x
|
||||
@sprites["corner2"].y=@y+@height-endY
|
||||
@sprites["corner3"].x=@x+@width-endX
|
||||
@sprites["corner3"].y=@y+@height-endY
|
||||
@sprites["side0"].x=@x+startX
|
||||
@sprites["side0"].y=@y
|
||||
@sprites["side1"].x=@x
|
||||
@sprites["side1"].y=@y+startY
|
||||
@sprites["side2"].x=@x+@width-endX
|
||||
@sprites["side2"].y=@y+startY
|
||||
@sprites["side3"].x=@x+startX
|
||||
@sprites["side3"].y=@y+@height-endY
|
||||
@sprites["scroll0"].x = @x+@width / 2 - 8
|
||||
@sprites["scroll0"].y = @y+8
|
||||
@sprites["scroll1"].x = @x+8
|
||||
@sprites["scroll1"].y = @y+@height / 2 - 8
|
||||
@sprites["scroll2"].x = @x+@width - 16
|
||||
@sprites["scroll2"].y = @y+@height / 2 - 8
|
||||
@sprites["scroll3"].x = @x+@width / 2 - 8
|
||||
@sprites["scroll3"].y = @y+@height - 16
|
||||
@sprites["cursor"].x=@x+startX+@cursor_rect.x
|
||||
@sprites["cursor"].y=@y+startY+@cursor_rect.y
|
||||
if (@compat & CompatBits::ExpandBack)>0 && @skinformat==0
|
||||
# Compatibility mode: Expand background
|
||||
@sprites["back"].x=@x+2
|
||||
@sprites["back"].y=@y+2
|
||||
else
|
||||
@sprites["back"].x=@x+startX
|
||||
@sprites["back"].y=@y+startY
|
||||
end
|
||||
end
|
||||
if changeBitmap && @_windowskin && !@_windowskin.disposed?
|
||||
if @skinformat==0
|
||||
@sprites["cursor"].x=@x+startX+@cursor_rect.x
|
||||
@sprites["cursor"].y=@y+startY+@cursor_rect.y
|
||||
width=@cursor_rect.width
|
||||
height=@cursor_rect.height
|
||||
if width > 0 && height > 0
|
||||
cursorrects=[
|
||||
# sides
|
||||
Rect.new(cursorX+2, cursorY+0, 28, 2),
|
||||
Rect.new(cursorX+0, cursorY+2, 2, 28),
|
||||
Rect.new(cursorX+30, cursorY+2, 2, 28),
|
||||
Rect.new(cursorX+2, cursorY+30, 28, 2),
|
||||
# corners
|
||||
Rect.new(cursorX+0, cursorY+0, 2, 2),
|
||||
Rect.new(cursorX+30, cursorY+0, 2, 2),
|
||||
Rect.new(cursorX+0, cursorY+30, 2, 2),
|
||||
Rect.new(cursorX+30, cursorY+30, 2, 2),
|
||||
# back
|
||||
Rect.new(cursorX+2, cursorY+2, 28, 28)
|
||||
]
|
||||
margin=2
|
||||
fullmargin=4
|
||||
@cursorbitmap = ensureBitmap(@cursorbitmap, width, height)
|
||||
@cursorbitmap.clear
|
||||
@sprites["cursor"].bitmap=@cursorbitmap
|
||||
@sprites["cursor"].src_rect.set(0,0,width,height)
|
||||
rect = Rect.new(margin,margin,width - fullmargin, height - fullmargin)
|
||||
@cursorbitmap.stretch_blt(rect, @_windowskin, cursorrects[8])
|
||||
@cursorbitmap.blt(0, 0, @_windowskin, cursorrects[4])# top left
|
||||
@cursorbitmap.blt(width-margin, 0, @_windowskin, cursorrects[5]) # top right
|
||||
@cursorbitmap.blt(0, height-margin, @_windowskin, cursorrects[6]) # bottom right
|
||||
@cursorbitmap.blt(width-margin, height-margin, @_windowskin, cursorrects[7]) # bottom left
|
||||
rect = Rect.new(margin, 0,width - fullmargin, margin)
|
||||
@cursorbitmap.stretch_blt(rect, @_windowskin, cursorrects[0])
|
||||
rect = Rect.new(0, margin,margin, height - fullmargin)
|
||||
@cursorbitmap.stretch_blt(rect, @_windowskin, cursorrects[1])
|
||||
rect = Rect.new(width - margin, margin, margin, height - fullmargin)
|
||||
@cursorbitmap.stretch_blt(rect, @_windowskin, cursorrects[2])
|
||||
rect = Rect.new(margin, height-margin, width - fullmargin, margin)
|
||||
@cursorbitmap.stretch_blt(rect, @_windowskin, cursorrects[3])
|
||||
else
|
||||
@sprites["cursor"].visible=false
|
||||
@sprites["cursor"].src_rect.set(0,0,0,0)
|
||||
end
|
||||
end
|
||||
for i in 0..3
|
||||
case i
|
||||
when 0
|
||||
dwidth = @width-startX-endX
|
||||
dheight = startY
|
||||
when 1
|
||||
dwidth = startX
|
||||
dheight = @height-startY-endY
|
||||
when 2
|
||||
dwidth = endX
|
||||
dheight = @height-startY-endY
|
||||
when 3
|
||||
dwidth = @width-startX-endX
|
||||
dheight = endY
|
||||
end
|
||||
@sidebitmaps[i]=ensureBitmap(@sidebitmaps[i],dwidth,dheight)
|
||||
@sprites["side#{i}"].bitmap=@sidebitmaps[i]
|
||||
@sprites["side#{i}"].src_rect.set(0,0,dwidth,dheight)
|
||||
@sidebitmaps[i].clear
|
||||
if sideRects[i].width>0 && sideRects[i].height>0
|
||||
if (@compat & CompatBits::StretchSides)>0 && @skinformat==0
|
||||
# Compatibility mode: Stretch sides
|
||||
@sidebitmaps[i].stretch_blt(@sprites["side#{i}"].src_rect,
|
||||
@_windowskin,sideRects[i])
|
||||
else
|
||||
tileBitmap(@sidebitmaps[i],@sprites["side#{i}"].src_rect,
|
||||
@_windowskin,sideRects[i])
|
||||
end
|
||||
end
|
||||
end
|
||||
if (@compat & CompatBits::ExpandBack)>0 && @skinformat==0
|
||||
# Compatibility mode: Expand background
|
||||
backwidth=@width-4
|
||||
backheight=@height-4
|
||||
else
|
||||
backwidth=@width-borderX
|
||||
backheight=@height-borderY
|
||||
end
|
||||
if backwidth>0 && backheight>0
|
||||
@backbitmap=ensureBitmap(@backbitmap,backwidth,backheight)
|
||||
@sprites["back"].bitmap=@backbitmap
|
||||
@sprites["back"].src_rect.set(0,0,backwidth,backheight)
|
||||
@backbitmap.clear
|
||||
if @stretch
|
||||
@backbitmap.stretch_blt(@sprites["back"].src_rect,@_windowskin,backRect)
|
||||
else
|
||||
tileBitmap(@backbitmap,@sprites["back"].src_rect,@_windowskin,backRect)
|
||||
end
|
||||
if blindsRect
|
||||
tileBitmap(@backbitmap,@sprites["back"].src_rect,@_windowskin,blindsRect)
|
||||
end
|
||||
else
|
||||
@sprites["back"].visible=false
|
||||
@sprites["back"].src_rect.set(0,0,0,0)
|
||||
end
|
||||
end
|
||||
if @openness!=255
|
||||
opn=@openness/255.0
|
||||
for k in @spritekeys
|
||||
sprite=@sprites[k]
|
||||
ratio=(@height<=0) ? 0 : (sprite.y-@y)*1.0/@height
|
||||
sprite.zoom_y=opn
|
||||
sprite.zoom_x=1.0
|
||||
sprite.oy=0
|
||||
sprite.y=(@y+(@height/2.0)+(@height*ratio*opn)-(@height/2*opn)).floor
|
||||
end
|
||||
else
|
||||
for k in @spritekeys
|
||||
sprite=@sprites[k]
|
||||
sprite.zoom_x=1.0
|
||||
sprite.zoom_y=1.0
|
||||
end
|
||||
end
|
||||
i=0
|
||||
# Ensure Z order
|
||||
for k in @spritekeys
|
||||
sprite=@sprites[k]
|
||||
y=sprite.y
|
||||
sprite.y=i
|
||||
sprite.oy=(sprite.zoom_y<=0) ? 0 : (i-y)/sprite.zoom_y
|
||||
sprite.zoom_x*=@zoom_x
|
||||
sprite.zoom_y*=@zoom_y
|
||||
sprite.x*=@zoom_x
|
||||
sprite.y*=@zoom_y
|
||||
sprite.x+=(@offset_x/sprite.zoom_x)
|
||||
sprite.y+=(@offset_y/sprite.zoom_y)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class SpriteWindow_Base < SpriteWindow
|
||||
TEXTPADDING=4 # In pixels
|
||||
|
||||
def initialize(x, y, width, height)
|
||||
super()
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.z = 100
|
||||
@curframe=MessageConfig.pbGetSystemFrame()
|
||||
@curfont=MessageConfig.pbGetSystemFontName()
|
||||
@sysframe=AnimatedBitmap.new(@curframe)
|
||||
RPG::Cache.retain(@curframe) if @curframe && !@curframe.empty?
|
||||
@customskin=nil
|
||||
__setWindowskin(@sysframe.bitmap)
|
||||
__resolveSystemFrame()
|
||||
pbSetSystemFont(self.contents) if self.contents
|
||||
end
|
||||
|
||||
def __setWindowskin(skin)
|
||||
if skin && (skin.width==192 && skin.height==128) || # RPGXP Windowskin
|
||||
(skin.width==128 && skin.height==128) # RPGVX Windowskin
|
||||
self.skinformat=0
|
||||
else
|
||||
self.skinformat=1
|
||||
end
|
||||
self.windowskin=skin
|
||||
end
|
||||
|
||||
def __resolveSystemFrame
|
||||
if self.skinformat==1
|
||||
if !@resolvedFrame
|
||||
@resolvedFrame=MessageConfig.pbGetSystemFrame()
|
||||
@resolvedFrame.sub!(/\.[^\.\/\\]+$/,"")
|
||||
end
|
||||
self.loadSkinFile("#{@resolvedFrame}.txt") if @resolvedFrame!=""
|
||||
end
|
||||
end
|
||||
|
||||
def setSkin(skin) # Filename of windowskin to apply. Supports XP, VX, and animated skins.
|
||||
@customskin.dispose if @customskin
|
||||
@customskin=nil
|
||||
resolvedName=pbResolveBitmap(skin)
|
||||
return if nil_or_empty?(resolvedName)
|
||||
@customskin=AnimatedBitmap.new(resolvedName)
|
||||
RPG::Cache.retain(resolvedName)
|
||||
__setWindowskin(@customskin.bitmap)
|
||||
if self.skinformat==1
|
||||
skinbase=resolvedName.sub(/\.[^\.\/\\]+$/,"")
|
||||
self.loadSkinFile("#{skinbase}.txt")
|
||||
end
|
||||
end
|
||||
|
||||
def setSystemFrame
|
||||
@customskin.dispose if @customskin
|
||||
@customskin=nil
|
||||
__setWindowskin(@sysframe.bitmap)
|
||||
__resolveSystemFrame()
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
if self.windowskin
|
||||
if @customskin
|
||||
if @customskin.totalFrames>1
|
||||
@customskin.update
|
||||
__setWindowskin(@customskin.bitmap)
|
||||
end
|
||||
elsif @sysframe
|
||||
if @sysframe.totalFrames>1
|
||||
@sysframe.update
|
||||
__setWindowskin(@sysframe.bitmap)
|
||||
end
|
||||
end
|
||||
end
|
||||
if @curframe!=MessageConfig.pbGetSystemFrame()
|
||||
@curframe=MessageConfig.pbGetSystemFrame()
|
||||
if @sysframe && !@customskin
|
||||
@sysframe.dispose if @sysframe
|
||||
@sysframe=AnimatedBitmap.new(@curframe)
|
||||
RPG::Cache.retain(@curframe) if @curframe && !@curframe.empty?
|
||||
@resolvedFrame=nil
|
||||
__setWindowskin(@sysframe.bitmap)
|
||||
__resolveSystemFrame()
|
||||
end
|
||||
begin
|
||||
refresh
|
||||
rescue NoMethodError
|
||||
end
|
||||
end
|
||||
if @curfont!=MessageConfig.pbGetSystemFontName()
|
||||
@curfont=MessageConfig.pbGetSystemFontName()
|
||||
if self.contents && !self.contents.disposed?
|
||||
pbSetSystemFont(self.contents)
|
||||
end
|
||||
begin
|
||||
refresh
|
||||
rescue NoMethodError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def dispose
|
||||
self.contents.dispose if self.contents
|
||||
@sysframe.dispose
|
||||
@customskin.dispose if @customskin
|
||||
super
|
||||
end
|
||||
end
|
||||
1365
Data/Scripts_backup/007_Objects and windows/005_SpriteWindow_text.rb
Normal file
1365
Data/Scripts_backup/007_Objects and windows/005_SpriteWindow_text.rb
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,123 @@
|
||||
#===============================================================================
|
||||
# Displays an icon bitmap in a window. Supports animated images.
|
||||
#===============================================================================
|
||||
class IconWindow < SpriteWindow_Base
|
||||
attr_reader :name
|
||||
|
||||
def initialize(x,y,width,height,viewport=nil)
|
||||
super(x,y,width,height)
|
||||
self.viewport=viewport
|
||||
self.contents=nil
|
||||
@name=""
|
||||
@_iconbitmap=nil
|
||||
end
|
||||
|
||||
def dispose
|
||||
clearBitmaps()
|
||||
super
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
if @_iconbitmap
|
||||
@_iconbitmap.update
|
||||
self.contents=@_iconbitmap.bitmap
|
||||
end
|
||||
end
|
||||
|
||||
def clearBitmaps
|
||||
@_iconbitmap.dispose if @_iconbitmap
|
||||
@_iconbitmap=nil
|
||||
self.contents=nil if !self.disposed?
|
||||
end
|
||||
|
||||
# Sets the icon's filename. Alias for setBitmap.
|
||||
def name=(value)
|
||||
setBitmap(value)
|
||||
end
|
||||
|
||||
# Sets the icon's filename.
|
||||
def setBitmap(file,hue=0)
|
||||
clearBitmaps()
|
||||
@name=file
|
||||
return if file==nil
|
||||
if file!=""
|
||||
@_iconbitmap=AnimatedBitmap.new(file,hue)
|
||||
# for compatibility
|
||||
self.contents=@_iconbitmap ? @_iconbitmap.bitmap : nil
|
||||
else
|
||||
@_iconbitmap=nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# Displays an icon bitmap in a window. Supports animated images.
|
||||
# Accepts bitmaps and paths to bitmap files in its constructor.
|
||||
#===============================================================================
|
||||
class PictureWindow < SpriteWindow_Base
|
||||
def initialize(pathOrBitmap)
|
||||
super(0,0,32,32)
|
||||
self.viewport=viewport
|
||||
self.contents=nil
|
||||
@_iconbitmap=nil
|
||||
setBitmap(pathOrBitmap)
|
||||
end
|
||||
|
||||
def picture; @_iconbitmap; end
|
||||
|
||||
def dispose
|
||||
clearBitmaps()
|
||||
super
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
if @_iconbitmap
|
||||
if @_iconbitmap.is_a?(Bitmap)
|
||||
self.contents=@_iconbitmap
|
||||
else
|
||||
@_iconbitmap.update
|
||||
self.contents=@_iconbitmap.bitmap
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def clearBitmaps
|
||||
@_iconbitmap.dispose if @_iconbitmap
|
||||
@_iconbitmap=nil
|
||||
self.contents=nil if !self.disposed?
|
||||
end
|
||||
|
||||
# Sets the icon's bitmap or filename. (hue parameter
|
||||
# is ignored unless pathOrBitmap is a filename)
|
||||
def setBitmap(pathOrBitmap,hue=0)
|
||||
clearBitmaps()
|
||||
if pathOrBitmap!=nil && pathOrBitmap!=""
|
||||
if pathOrBitmap.is_a?(Bitmap)
|
||||
@_iconbitmap=pathOrBitmap
|
||||
self.contents=@_iconbitmap
|
||||
self.width=@_iconbitmap.width+self.borderX
|
||||
self.height=@_iconbitmap.height+self.borderY
|
||||
elsif pathOrBitmap.is_a?(AnimatedBitmap)
|
||||
@_iconbitmap=pathOrBitmap
|
||||
self.contents=@_iconbitmap.bitmap
|
||||
self.width=@_iconbitmap.bitmap.width+self.borderX
|
||||
self.height=@_iconbitmap.bitmap.height+self.borderY
|
||||
else
|
||||
@_iconbitmap=AnimatedBitmap.new(pathOrBitmap,hue)
|
||||
self.contents=@_iconbitmap ? @_iconbitmap.bitmap : nil
|
||||
self.width=@_iconbitmap ? @_iconbitmap.bitmap.width+self.borderX :
|
||||
32+self.borderX
|
||||
self.height=@_iconbitmap ? @_iconbitmap.bitmap.height+self.borderY :
|
||||
32+self.borderY
|
||||
end
|
||||
else
|
||||
@_iconbitmap=nil
|
||||
self.width=32+self.borderX
|
||||
self.height=32+self.borderY
|
||||
end
|
||||
end
|
||||
end
|
||||
359
Data/Scripts_backup/007_Objects and windows/007_SpriteWrapper.rb
Normal file
359
Data/Scripts_backup/007_Objects and windows/007_SpriteWrapper.rb
Normal file
@@ -0,0 +1,359 @@
|
||||
#===============================================================================
|
||||
# SpriteWrapper is a class which wraps (most of) Sprite's properties.
|
||||
#===============================================================================
|
||||
class SpriteWrapper
|
||||
def initialize(viewport=nil)
|
||||
@sprite = Sprite.new(viewport)
|
||||
end
|
||||
|
||||
def dispose; @sprite.dispose; end
|
||||
def disposed?; return @sprite.disposed?; end
|
||||
def viewport; return @sprite.viewport; end
|
||||
def flash(color,duration); return @sprite.flash(color,duration); end
|
||||
def update; return @sprite.update; end
|
||||
def x; @sprite.x; end
|
||||
def x=(value); @sprite.x = value; end
|
||||
def y; @sprite.y; end
|
||||
def y=(value); @sprite.y = value; end
|
||||
def bitmap; @sprite.bitmap; end
|
||||
def bitmap=(value); @sprite.bitmap = value; end
|
||||
def src_rect; @sprite.src_rect; end
|
||||
def src_rect=(value); @sprite.src_rect = value; end
|
||||
def visible; @sprite.visible; end
|
||||
def visible=(value); @sprite.visible = value; end
|
||||
def z; @sprite.z; end
|
||||
def z=(value); @sprite.z = value; end
|
||||
def ox; @sprite.ox; end
|
||||
def ox=(value); @sprite.ox = value; end
|
||||
def oy; @sprite.oy; end
|
||||
def oy=(value); @sprite.oy = value; end
|
||||
def zoom_x; @sprite.zoom_x; end
|
||||
def zoom_x=(value); @sprite.zoom_x = value; end
|
||||
def zoom_y; @sprite.zoom_y; end
|
||||
def zoom_y=(value); @sprite.zoom_y = value; end
|
||||
def angle; @sprite.angle; end
|
||||
def angle=(value); @sprite.angle = value; end
|
||||
def mirror; @sprite.mirror; end
|
||||
def mirror=(value); @sprite.mirror = value; end
|
||||
def bush_depth; @sprite.bush_depth; end
|
||||
def bush_depth=(value); @sprite.bush_depth = value; end
|
||||
def opacity; @sprite.opacity; end
|
||||
def opacity=(value); @sprite.opacity = value; end
|
||||
def blend_type; @sprite.blend_type; end
|
||||
def blend_type=(value); @sprite.blend_type = value; end
|
||||
def color; @sprite.color; end
|
||||
def color=(value); @sprite.color = value; end
|
||||
def tone; @sprite.tone; end
|
||||
def tone=(value); @sprite.tone = value; end
|
||||
|
||||
def viewport=(value)
|
||||
return if self.viewport==value
|
||||
bitmap = @sprite.bitmap
|
||||
src_rect = @sprite.src_rect
|
||||
visible = @sprite.visible
|
||||
x = @sprite.x
|
||||
y = @sprite.y
|
||||
z = @sprite.z
|
||||
ox = @sprite.ox
|
||||
oy = @sprite.oy
|
||||
zoom_x = @sprite.zoom_x
|
||||
zoom_y = @sprite.zoom_y
|
||||
angle = @sprite.angle
|
||||
mirror = @sprite.mirror
|
||||
bush_depth = @sprite.bush_depth
|
||||
opacity = @sprite.opacity
|
||||
blend_type = @sprite.blend_type
|
||||
color = @sprite.color
|
||||
tone = @sprite.tone
|
||||
@sprite.dispose
|
||||
@sprite = Sprite.new(value)
|
||||
@sprite.bitmap = bitmap
|
||||
@sprite.src_rect = src_rect
|
||||
@sprite.visible = visible
|
||||
@sprite.x = x
|
||||
@sprite.y = y
|
||||
@sprite.z = z
|
||||
@sprite.ox = ox
|
||||
@sprite.oy = oy
|
||||
@sprite.zoom_x = zoom_x
|
||||
@sprite.zoom_y = zoom_y
|
||||
@sprite.angle = angle
|
||||
@sprite.mirror = mirror
|
||||
@sprite.bush_depth = bush_depth
|
||||
@sprite.opacity = opacity
|
||||
@sprite.blend_type = blend_type
|
||||
@sprite.color = color
|
||||
@sprite.tone = tone
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# Sprite class that maintains a bitmap of its own.
|
||||
# This bitmap can't be changed to a different one.
|
||||
#===============================================================================
|
||||
class BitmapSprite < SpriteWrapper
|
||||
def initialize(width,height,viewport=nil)
|
||||
super(viewport)
|
||||
self.bitmap=Bitmap.new(width,height)
|
||||
@initialized=true
|
||||
end
|
||||
|
||||
def bitmap=(value)
|
||||
super(value) if !@initialized
|
||||
end
|
||||
|
||||
def dispose
|
||||
self.bitmap.dispose if !self.disposed?
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class AnimatedSprite < SpriteWrapper
|
||||
attr_reader :frame
|
||||
attr_reader :framewidth
|
||||
attr_reader :frameheight
|
||||
attr_reader :framecount
|
||||
attr_reader :animname
|
||||
|
||||
def initializeLong(animname,framecount,framewidth,frameheight,frameskip)
|
||||
@animname=pbBitmapName(animname)
|
||||
@realframes=0
|
||||
@frameskip=[1,frameskip].max
|
||||
@frameskip *= Graphics.frame_rate/20
|
||||
raise _INTL("Frame width is 0") if framewidth==0
|
||||
raise _INTL("Frame height is 0") if frameheight==0
|
||||
begin
|
||||
@animbitmap=AnimatedBitmap.new(animname).deanimate
|
||||
rescue
|
||||
@animbitmap=Bitmap.new(framewidth,frameheight)
|
||||
end
|
||||
if @animbitmap.width%framewidth!=0
|
||||
raise _INTL("Bitmap's width ({1}) is not a multiple of frame width ({2}) [Bitmap={3}]",
|
||||
@animbitmap.width,framewidth,animname)
|
||||
end
|
||||
if @animbitmap.height%frameheight!=0
|
||||
raise _INTL("Bitmap's height ({1}) is not a multiple of frame height ({2}) [Bitmap={3}]",
|
||||
@animbitmap.height,frameheight,animname)
|
||||
end
|
||||
@framecount=framecount
|
||||
@framewidth=framewidth
|
||||
@frameheight=frameheight
|
||||
@framesperrow=@animbitmap.width/@framewidth
|
||||
@playing=false
|
||||
self.bitmap=@animbitmap
|
||||
self.src_rect.width=@framewidth
|
||||
self.src_rect.height=@frameheight
|
||||
self.frame=0
|
||||
end
|
||||
|
||||
# Shorter version of AnimationSprite. All frames are placed on a single row
|
||||
# of the bitmap, so that the width and height need not be defined beforehand
|
||||
def initializeShort(animname,framecount,frameskip)
|
||||
@animname=pbBitmapName(animname)
|
||||
@realframes=0
|
||||
@frameskip=[1,frameskip].max
|
||||
@frameskip *= Graphics.frame_rate/20
|
||||
begin
|
||||
@animbitmap=AnimatedBitmap.new(animname).deanimate
|
||||
rescue
|
||||
@animbitmap=Bitmap.new(framecount*4,32)
|
||||
end
|
||||
if @animbitmap.width%framecount!=0
|
||||
raise _INTL("Bitmap's width ({1}) is not a multiple of frame count ({2}) [Bitmap={3}]",
|
||||
@animbitmap.width,framewidth,animname)
|
||||
end
|
||||
@framecount=framecount
|
||||
@framewidth=@animbitmap.width/@framecount
|
||||
@frameheight=@animbitmap.height
|
||||
@framesperrow=framecount
|
||||
@playing=false
|
||||
self.bitmap=@animbitmap
|
||||
self.src_rect.width=@framewidth
|
||||
self.src_rect.height=@frameheight
|
||||
self.frame=0
|
||||
end
|
||||
|
||||
def initialize(*args)
|
||||
if args.length==1
|
||||
super(args[0][3])
|
||||
initializeShort(args[0][0],args[0][1],args[0][2])
|
||||
else
|
||||
super(args[5])
|
||||
initializeLong(args[0],args[1],args[2],args[3],args[4])
|
||||
end
|
||||
end
|
||||
|
||||
def self.create(animname,framecount,frameskip,viewport=nil)
|
||||
return self.new([animname,framecount,frameskip,viewport])
|
||||
end
|
||||
|
||||
def dispose
|
||||
return if disposed?
|
||||
@animbitmap.dispose
|
||||
@animbitmap=nil
|
||||
super
|
||||
end
|
||||
|
||||
def playing?
|
||||
return @playing
|
||||
end
|
||||
|
||||
def frame=(value)
|
||||
@frame=value
|
||||
@realframes=0
|
||||
self.src_rect.x=@frame%@framesperrow*@framewidth
|
||||
self.src_rect.y=@frame/@framesperrow*@frameheight
|
||||
end
|
||||
|
||||
def start
|
||||
@playing=true
|
||||
@realframes=0
|
||||
end
|
||||
|
||||
alias play start
|
||||
|
||||
def stop
|
||||
@playing=false
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
if @playing
|
||||
@realframes+=1
|
||||
if @realframes==@frameskip
|
||||
@realframes=0
|
||||
self.frame+=1
|
||||
self.frame%=self.framecount
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# Displays an icon bitmap in a sprite. Supports animated images.
|
||||
#===============================================================================
|
||||
class IconSprite < SpriteWrapper
|
||||
attr_reader :name
|
||||
|
||||
def initialize(*args)
|
||||
if args.length==0
|
||||
super(nil)
|
||||
self.bitmap=nil
|
||||
elsif args.length==1
|
||||
super(args[0])
|
||||
self.bitmap=nil
|
||||
elsif args.length==2
|
||||
super(nil)
|
||||
self.x=args[0]
|
||||
self.y=args[1]
|
||||
else
|
||||
super(args[2])
|
||||
self.x=args[0]
|
||||
self.y=args[1]
|
||||
end
|
||||
@name=""
|
||||
@_iconbitmap=nil
|
||||
end
|
||||
|
||||
def dispose
|
||||
clearBitmaps()
|
||||
super
|
||||
end
|
||||
|
||||
# Sets the icon's filename. Alias for setBitmap.
|
||||
def name=(value)
|
||||
setBitmap(value)
|
||||
end
|
||||
|
||||
# Sets the icon's filename.
|
||||
def setBitmap(file,hue=0)
|
||||
oldrc=self.src_rect
|
||||
clearBitmaps()
|
||||
@name=file
|
||||
return if file==nil
|
||||
if file!=""
|
||||
@_iconbitmap=AnimatedBitmap.new(file,hue)
|
||||
# for compatibility
|
||||
self.bitmap=@_iconbitmap ? @_iconbitmap.bitmap : nil
|
||||
self.src_rect=oldrc
|
||||
else
|
||||
@_iconbitmap=nil
|
||||
end
|
||||
end
|
||||
|
||||
def clearBitmaps
|
||||
@_iconbitmap.dispose if @_iconbitmap
|
||||
@_iconbitmap=nil
|
||||
self.bitmap=nil if !self.disposed?
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
return if !@_iconbitmap
|
||||
@_iconbitmap.update
|
||||
if self.bitmap!=@_iconbitmap.bitmap
|
||||
oldrc=self.src_rect
|
||||
self.bitmap=@_iconbitmap.bitmap
|
||||
self.src_rect=oldrc
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# Old GifSprite class, retained for compatibility
|
||||
#===============================================================================
|
||||
class GifSprite < IconSprite
|
||||
def initialize(path)
|
||||
super(0,0)
|
||||
setBitmap(path)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# SpriteWrapper that stores multiple bitmaps, and displays only one at once.
|
||||
#===============================================================================
|
||||
class ChangelingSprite < SpriteWrapper
|
||||
def initialize(x=0,y=0,viewport=nil)
|
||||
super(viewport)
|
||||
self.x = x
|
||||
self.y = y
|
||||
@bitmaps = {}
|
||||
@currentBitmap = nil
|
||||
end
|
||||
|
||||
def addBitmap(key,path)
|
||||
@bitmaps[key].dispose if @bitmaps[key]
|
||||
@bitmaps[key] = AnimatedBitmap.new(path)
|
||||
end
|
||||
|
||||
def changeBitmap(key)
|
||||
@currentBitmap = @bitmaps[key]
|
||||
self.bitmap = (@currentBitmap) ? @currentBitmap.bitmap : nil
|
||||
end
|
||||
|
||||
def dispose
|
||||
return if disposed?
|
||||
for bm in @bitmaps.values; bm.dispose; end
|
||||
@bitmaps.clear
|
||||
super
|
||||
end
|
||||
|
||||
def update
|
||||
return if disposed?
|
||||
for bm in @bitmaps.values; bm.update; end
|
||||
self.bitmap = (@currentBitmap) ? @currentBitmap.bitmap : nil
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,238 @@
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class AnimatedBitmap
|
||||
def initialize(file, hue = 0)
|
||||
raise "Filename is nil (missing graphic)." if file.nil?
|
||||
path = file
|
||||
filename = ""
|
||||
if file.last != '/' # Isn't just a directory
|
||||
split_file = file.split(/[\\\/]/)
|
||||
filename = split_file.pop
|
||||
path = split_file.join('/') + '/'
|
||||
end
|
||||
if filename[/^\[\d+(?:,\d+)?\]/] # Starts with 1 or 2 numbers in square brackets
|
||||
@bitmap = PngAnimatedBitmap.new(path, filename, hue)
|
||||
else
|
||||
@bitmap = GifBitmap.new(path, filename, hue)
|
||||
end
|
||||
end
|
||||
|
||||
def [](index); @bitmap[index]; end
|
||||
def width; @bitmap.bitmap.width; end
|
||||
def height; @bitmap.bitmap.height; end
|
||||
def length; @bitmap.length; end
|
||||
def each; @bitmap.each { |item| yield item }; end
|
||||
def bitmap; @bitmap.bitmap; end
|
||||
def currentIndex; @bitmap.currentIndex; end
|
||||
def totalFrames; @bitmap.totalFrames; end
|
||||
def disposed?; @bitmap.disposed?; end
|
||||
def update; @bitmap.update; end
|
||||
def dispose; @bitmap.dispose; end
|
||||
def deanimate; @bitmap.deanimate; end
|
||||
def copy; @bitmap.copy; end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class PngAnimatedBitmap
|
||||
attr_accessor :frames
|
||||
|
||||
# Creates an animated bitmap from a PNG file.
|
||||
def initialize(dir, filename, hue = 0)
|
||||
@frames = []
|
||||
@currentFrame = 0
|
||||
@framecount = 0
|
||||
panorama = RPG::Cache.load_bitmap(dir, filename, hue)
|
||||
if filename[/^\[(\d+)(?:,(\d+))?\]/] # Starts with 1 or 2 numbers in brackets
|
||||
# File has a frame count
|
||||
numFrames = $1.to_i
|
||||
delay = $2.to_i
|
||||
delay = 10 if delay == 0
|
||||
raise "Invalid frame count in #{filename}" if numFrames <= 0
|
||||
raise "Invalid frame delay in #{filename}" if delay <= 0
|
||||
if panorama.width % numFrames != 0
|
||||
raise "Bitmap's width (#{panorama.width}) is not divisible by frame count: #{filename}"
|
||||
end
|
||||
@frameDelay = delay
|
||||
subWidth = panorama.width / numFrames
|
||||
for i in 0...numFrames
|
||||
subBitmap = BitmapWrapper.new(subWidth, panorama.height)
|
||||
subBitmap.blt(0, 0, panorama, Rect.new(subWidth * i, 0, subWidth, panorama.height))
|
||||
@frames.push(subBitmap)
|
||||
end
|
||||
panorama.dispose
|
||||
else
|
||||
@frames = [panorama]
|
||||
end
|
||||
end
|
||||
|
||||
def [](index)
|
||||
return @frames[index]
|
||||
end
|
||||
|
||||
def width; self.bitmap.width; end
|
||||
def height; self.bitmap.height; end
|
||||
|
||||
def deanimate
|
||||
for i in 1...@frames.length
|
||||
@frames[i].dispose
|
||||
end
|
||||
@frames = [@frames[0]]
|
||||
@currentFrame = 0
|
||||
return @frames[0]
|
||||
end
|
||||
|
||||
def bitmap
|
||||
return @frames[@currentFrame]
|
||||
end
|
||||
|
||||
def currentIndex
|
||||
return @currentFrame
|
||||
end
|
||||
|
||||
def frameDelay(_index)
|
||||
return @frameDelay
|
||||
end
|
||||
|
||||
def length
|
||||
return @frames.length
|
||||
end
|
||||
|
||||
def each
|
||||
@frames.each { |item| yield item }
|
||||
end
|
||||
|
||||
def totalFrames
|
||||
return @frameDelay * @frames.length
|
||||
end
|
||||
|
||||
def disposed?
|
||||
return @disposed
|
||||
end
|
||||
|
||||
def update
|
||||
return if disposed?
|
||||
if @frames.length > 1
|
||||
@framecount += 1
|
||||
if @framecount >= @frameDelay
|
||||
@framecount = 0
|
||||
@currentFrame += 1
|
||||
@currentFrame %= @frames.length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def dispose
|
||||
if !@disposed
|
||||
@frames.each { |f| f.dispose }
|
||||
end
|
||||
@disposed = true
|
||||
end
|
||||
|
||||
def copy
|
||||
x = self.clone
|
||||
x.frames = x.frames.clone
|
||||
for i in 0...x.frames.length
|
||||
x.frames[i] = x.frames[i].copy
|
||||
end
|
||||
return x
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class GifBitmap
|
||||
attr_accessor :bitmap
|
||||
|
||||
# Creates a bitmap from a GIF file. Can also load non-animated bitmaps.
|
||||
def initialize(dir, filename, hue = 0)
|
||||
@bitmap = nil
|
||||
@disposed = false
|
||||
filename = "" if !filename
|
||||
begin
|
||||
@bitmap = RPG::Cache.load_bitmap(dir, filename, hue)
|
||||
rescue
|
||||
@bitmap = nil
|
||||
end
|
||||
@bitmap = BitmapWrapper.new(32, 32) if @bitmap.nil?
|
||||
@bitmap.play if @bitmap&.animated?
|
||||
end
|
||||
|
||||
def [](_index)
|
||||
return @bitmap
|
||||
end
|
||||
|
||||
def deanimate
|
||||
@bitmap&.goto_and_stop(0) if @bitmap&.animated?
|
||||
return @bitmap
|
||||
end
|
||||
|
||||
def currentIndex
|
||||
return @bitmap&.current_frame || 0
|
||||
end
|
||||
|
||||
def length
|
||||
return @bitmap&.frame_count || 1
|
||||
end
|
||||
|
||||
def each
|
||||
yield @bitmap
|
||||
end
|
||||
|
||||
def totalFrames
|
||||
f_rate = @bitmap.frame_rate
|
||||
f_rate = 1 if f_rate.nil? || f_rate == 0
|
||||
return (@bitmap) ? (@bitmap.frame_count / f_rate).floor : 1
|
||||
end
|
||||
|
||||
def disposed?
|
||||
return @disposed
|
||||
end
|
||||
|
||||
def width
|
||||
return @bitmap&.width || 0
|
||||
end
|
||||
|
||||
def height
|
||||
return @bitmap&.height || 0
|
||||
end
|
||||
|
||||
# Gifs are animated automatically by mkxp-z. This function does nothing.
|
||||
def update; end
|
||||
|
||||
def dispose
|
||||
return if @disposed
|
||||
@bitmap.dispose
|
||||
@disposed = true
|
||||
end
|
||||
|
||||
def copy
|
||||
x = self.clone
|
||||
x.bitmap = @bitmap.copy if @bitmap
|
||||
return x
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
def pbGetTileBitmap(filename, tile_id, hue, width = 1, height = 1)
|
||||
return RPG::Cache.tileEx(filename, tile_id, hue, width, height) { |f|
|
||||
AnimatedBitmap.new("Graphics/Tilesets/" + filename).deanimate
|
||||
}
|
||||
end
|
||||
|
||||
def pbGetTileset(name,hue=0)
|
||||
return AnimatedBitmap.new("Graphics/Tilesets/" + name, hue).deanimate
|
||||
end
|
||||
|
||||
def pbGetAutotile(name,hue=0)
|
||||
return AnimatedBitmap.new("Graphics/Autotiles/" + name, hue).deanimate
|
||||
end
|
||||
|
||||
def pbGetAnimation(name,hue=0)
|
||||
return AnimatedBitmap.new("Graphics/Animations/" + name, hue).deanimate
|
||||
end
|
||||
230
Data/Scripts_backup/007_Objects and windows/009_Planes.rb
Normal file
230
Data/Scripts_backup/007_Objects and windows/009_Planes.rb
Normal file
@@ -0,0 +1,230 @@
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class Plane
|
||||
def update; end
|
||||
def refresh; end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# This class works around a limitation that planes are always
|
||||
# 640 by 480 pixels in size regardless of the window's size.
|
||||
#===============================================================================
|
||||
class LargePlane < Plane
|
||||
attr_accessor :borderX
|
||||
attr_accessor :borderY
|
||||
|
||||
def initialize(viewport=nil)
|
||||
@__sprite=Sprite.new(viewport)
|
||||
@__disposed=false
|
||||
@__ox=0
|
||||
@__oy=0
|
||||
@__bitmap=nil
|
||||
@__visible=true
|
||||
@__sprite.visible=false
|
||||
@borderX=0
|
||||
@borderY=0
|
||||
end
|
||||
|
||||
def disposed?
|
||||
return @__disposed
|
||||
end
|
||||
|
||||
def dispose
|
||||
if !@__disposed
|
||||
@__sprite.bitmap.dispose if @__sprite.bitmap
|
||||
@__sprite.dispose
|
||||
@__sprite=nil
|
||||
@__bitmap=nil
|
||||
@__disposed=true
|
||||
end
|
||||
#super
|
||||
end
|
||||
|
||||
def ox; @__ox; end
|
||||
def oy; @__oy; end
|
||||
|
||||
def ox=(value);
|
||||
return if @__ox==value
|
||||
@__ox = value
|
||||
refresh
|
||||
end
|
||||
|
||||
def oy=(value);
|
||||
return if @__oy==value
|
||||
@__oy = value
|
||||
refresh
|
||||
end
|
||||
|
||||
def bitmap
|
||||
return @__bitmap
|
||||
end
|
||||
|
||||
def bitmap=(value)
|
||||
if value==nil
|
||||
if @__bitmap!=nil
|
||||
@__bitmap=nil
|
||||
@__sprite.visible=(@__visible && !@__bitmap.nil?)
|
||||
end
|
||||
elsif @__bitmap!=value && !value.disposed?
|
||||
@__bitmap=value
|
||||
refresh
|
||||
elsif value.disposed?
|
||||
if @__bitmap!=nil
|
||||
@__bitmap=nil
|
||||
@__sprite.visible=(@__visible && !@__bitmap.nil?)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def viewport; @__sprite.viewport; end
|
||||
def zoom_x; @__sprite.zoom_x; end
|
||||
def zoom_y; @__sprite.zoom_y; end
|
||||
def opacity; @__sprite.opacity; end
|
||||
def blend_type; @__sprite.blend_type; end
|
||||
def visible; @__visible; end
|
||||
def z; @__sprite.z; end
|
||||
def color; @__sprite.color; end
|
||||
def tone; @__sprite.tone; end
|
||||
|
||||
def zoom_x=(v);
|
||||
return if @__sprite.zoom_x==v
|
||||
@__sprite.zoom_x = v
|
||||
refresh
|
||||
end
|
||||
|
||||
def zoom_y=(v);
|
||||
return if @__sprite.zoom_y==v
|
||||
@__sprite.zoom_y = v
|
||||
refresh
|
||||
end
|
||||
|
||||
def opacity=(v); @__sprite.opacity=(v); end
|
||||
def blend_type=(v); @__sprite.blend_type=(v); end
|
||||
def visible=(v); @__visible=v; @__sprite.visible=(@__visible && !@__bitmap.nil?); end
|
||||
def z=(v); @__sprite.z=(v); end
|
||||
def color=(v); @__sprite.color=(v); end
|
||||
def tone=(v); @__sprite.tone=(v); end
|
||||
def update; ;end
|
||||
|
||||
def refresh
|
||||
@__sprite.visible = (@__visible && !@__bitmap.nil?)
|
||||
if @__bitmap
|
||||
if !@__bitmap.disposed?
|
||||
@__ox += @__bitmap.width*@__sprite.zoom_x if @__ox<0
|
||||
@__oy += @__bitmap.height*@__sprite.zoom_y if @__oy<0
|
||||
@__ox -= @__bitmap.width*@__sprite.zoom_x if @__ox>@__bitmap.width
|
||||
@__oy -= @__bitmap.height*@__sprite.zoom_y if @__oy>@__bitmap.height
|
||||
dwidth = (Graphics.width/@__sprite.zoom_x+@borderX).to_i # +2
|
||||
dheight = (Graphics.height/@__sprite.zoom_y+@borderY).to_i # +2
|
||||
@__sprite.bitmap = ensureBitmap(@__sprite.bitmap,dwidth,dheight)
|
||||
@__sprite.bitmap.clear
|
||||
tileBitmap(@__sprite.bitmap,@__bitmap,@__bitmap.rect)
|
||||
else
|
||||
@__sprite.visible = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ensureBitmap(bitmap,dwidth,dheight)
|
||||
if !bitmap || bitmap.disposed? || bitmap.width<dwidth || bitmap.height<dheight
|
||||
bitmap.dispose if bitmap
|
||||
bitmap = Bitmap.new([1,dwidth].max,[1,dheight].max)
|
||||
end
|
||||
return bitmap
|
||||
end
|
||||
|
||||
def tileBitmap(dstbitmap,srcbitmap,srcrect)
|
||||
return if !srcbitmap || srcbitmap.disposed?
|
||||
dstrect = dstbitmap.rect
|
||||
left = (dstrect.x-@__ox/@__sprite.zoom_x).to_i
|
||||
top = (dstrect.y-@__oy/@__sprite.zoom_y).to_i
|
||||
while left>0; left -= srcbitmap.width; end
|
||||
while top>0; top -= srcbitmap.height; end
|
||||
y = top
|
||||
while y<dstrect.height
|
||||
x = left
|
||||
while x<dstrect.width
|
||||
dstbitmap.blt(x+@borderX,y+@borderY,srcbitmap,srcrect)
|
||||
x += srcrect.width
|
||||
end
|
||||
y += srcrect.height
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# A plane class that displays a single color.
|
||||
#===============================================================================
|
||||
class ColoredPlane < LargePlane
|
||||
def initialize(color,viewport=nil)
|
||||
super(viewport)
|
||||
self.bitmap=Bitmap.new(32,32)
|
||||
setPlaneColor(color)
|
||||
end
|
||||
|
||||
def dispose
|
||||
self.bitmap.dispose if self.bitmap
|
||||
super
|
||||
end
|
||||
|
||||
def setPlaneColor(value)
|
||||
self.bitmap.fill_rect(0,0,self.bitmap.width,self.bitmap.height,value)
|
||||
self.refresh
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# A plane class that supports animated images.
|
||||
#===============================================================================
|
||||
class AnimatedPlane < LargePlane
|
||||
def initialize(viewport)
|
||||
super(viewport)
|
||||
@bitmap=nil
|
||||
end
|
||||
|
||||
def dispose
|
||||
clearBitmaps()
|
||||
super
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
if @bitmap
|
||||
@bitmap.update
|
||||
self.bitmap=@bitmap.bitmap
|
||||
end
|
||||
end
|
||||
|
||||
def clearBitmaps
|
||||
@bitmap.dispose if @bitmap
|
||||
@bitmap=nil
|
||||
self.bitmap=nil if !self.disposed?
|
||||
end
|
||||
|
||||
def setPanorama(file, hue=0)
|
||||
clearBitmaps()
|
||||
return if file==nil
|
||||
@bitmap=AnimatedBitmap.new("Graphics/Panoramas/"+file,hue)
|
||||
end
|
||||
|
||||
def setFog(file, hue=0)
|
||||
clearBitmaps()
|
||||
return if file==nil
|
||||
@bitmap=AnimatedBitmap.new("Graphics/Fogs/"+file,hue)
|
||||
end
|
||||
|
||||
def setBitmap(file, hue=0)
|
||||
clearBitmaps()
|
||||
return if file==nil
|
||||
@bitmap=AnimatedBitmap.new(file,hue)
|
||||
end
|
||||
end
|
||||
1236
Data/Scripts_backup/007_Objects and windows/010_DrawText.rb
Normal file
1236
Data/Scripts_backup/007_Objects and windows/010_DrawText.rb
Normal file
File diff suppressed because it is too large
Load Diff
982
Data/Scripts_backup/007_Objects and windows/011_Messages.rb
Normal file
982
Data/Scripts_backup/007_Objects and windows/011_Messages.rb
Normal file
@@ -0,0 +1,982 @@
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class Scene_Map
|
||||
def updatemini
|
||||
oldmws=$game_temp.message_window_showing
|
||||
$game_temp.message_window_showing=true
|
||||
loop do
|
||||
$game_map.update
|
||||
$game_player.update
|
||||
$game_system.update
|
||||
if $game_screen
|
||||
$game_screen.update
|
||||
else
|
||||
$game_map.screen.update
|
||||
end
|
||||
break unless $game_temp.player_transferring
|
||||
transfer_player
|
||||
break if $game_temp.transition_processing
|
||||
end
|
||||
$game_temp.message_window_showing=oldmws
|
||||
@spriteset.update if @spriteset
|
||||
@message_window.update if @message_window
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class Scene_Battle
|
||||
def updatemini
|
||||
if self.respond_to?("update_basic")
|
||||
update_basic(true)
|
||||
update_info_viewport # Update information viewport
|
||||
else
|
||||
oldmws=$game_temp.message_window_showing
|
||||
$game_temp.message_window_showing=true
|
||||
# Update system (timer) and screen
|
||||
$game_system.update
|
||||
if $game_screen
|
||||
$game_screen.update
|
||||
else
|
||||
$game_map.screen.update
|
||||
end
|
||||
# If timer has reached 0
|
||||
if $game_system.timer_working && $game_system.timer == 0
|
||||
# Abort battle
|
||||
$game_temp.battle_abort = true
|
||||
end
|
||||
# Update windows
|
||||
@help_window.update if @help_window
|
||||
@party_command_window.update if @party_command_window
|
||||
@actor_command_window.update if @actor_command_window
|
||||
@status_window.update if @status_window
|
||||
$game_temp.message_window_showing=oldmws
|
||||
@message_window.update if @message_window
|
||||
# Update sprite set
|
||||
@spriteset.update if @spriteset
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def pbMapInterpreter
|
||||
if $game_map.respond_to?("interpreter")
|
||||
return $game_map.interpreter
|
||||
elsif $game_system
|
||||
return $game_system.map_interpreter
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
def pbMapInterpreterRunning?
|
||||
interp = pbMapInterpreter
|
||||
return interp && interp.running?
|
||||
end
|
||||
|
||||
def pbRefreshSceneMap
|
||||
if $scene && $scene.is_a?(Scene_Map)
|
||||
if $scene.respond_to?("miniupdate")
|
||||
$scene.miniupdate
|
||||
else
|
||||
$scene.updatemini
|
||||
end
|
||||
elsif $scene && $scene.is_a?(Scene_Battle)
|
||||
$scene.updatemini
|
||||
end
|
||||
end
|
||||
|
||||
def pbUpdateSceneMap
|
||||
if $scene && $scene.is_a?(Scene_Map) && !pbIsFaded?
|
||||
if $scene.respond_to?("miniupdate")
|
||||
$scene.miniupdate
|
||||
else
|
||||
$scene.updatemini
|
||||
end
|
||||
elsif $scene && $scene.is_a?(Scene_Battle)
|
||||
$scene.updatemini
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
def pbEventCommentInput(*args)
|
||||
parameters = []
|
||||
list = *args[0].list # Event or event page
|
||||
elements = *args[1] # Number of elements
|
||||
trigger = *args[2] # Trigger
|
||||
return nil if list == nil
|
||||
return nil unless list.is_a?(Array)
|
||||
for item in list
|
||||
next unless item.code == 108 || item.code == 408
|
||||
if item.parameters[0] == trigger
|
||||
start = list.index(item) + 1
|
||||
finish = start + elements
|
||||
for id in start...finish
|
||||
next if !list[id]
|
||||
parameters.push(list[id].parameters[0])
|
||||
end
|
||||
return parameters
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
def pbCurrentEventCommentInput(elements,trigger)
|
||||
return nil if !pbMapInterpreterRunning?
|
||||
event = pbMapInterpreter.get_character(0)
|
||||
return nil if !event
|
||||
return pbEventCommentInput(event,elements,trigger)
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class ChooseNumberParams
|
||||
def initialize
|
||||
@maxDigits=0
|
||||
@minNumber=0
|
||||
@maxNumber=0
|
||||
@skin=nil
|
||||
@messageSkin=nil
|
||||
@negativesAllowed=false
|
||||
@initialNumber=0
|
||||
@cancelNumber=nil
|
||||
end
|
||||
|
||||
def setMessageSkin(value)
|
||||
@messageSkin=value
|
||||
end
|
||||
|
||||
def messageSkin # Set the full path for the message's window skin
|
||||
@messageSkin
|
||||
end
|
||||
|
||||
def setSkin(value)
|
||||
@skin=value
|
||||
end
|
||||
|
||||
def skin
|
||||
@skin
|
||||
end
|
||||
|
||||
def setNegativesAllowed(value)
|
||||
@negativeAllowed=value
|
||||
end
|
||||
|
||||
def negativesAllowed
|
||||
@negativeAllowed ? true : false
|
||||
end
|
||||
|
||||
def setRange(minNumber,maxNumber)
|
||||
maxNumber=minNumber if minNumber>maxNumber
|
||||
@maxDigits=0
|
||||
@minNumber=minNumber
|
||||
@maxNumber=maxNumber
|
||||
end
|
||||
|
||||
def setDefaultValue(number)
|
||||
@initialNumber=number
|
||||
@cancelNumber=nil
|
||||
end
|
||||
|
||||
def setInitialValue(number)
|
||||
@initialNumber=number
|
||||
end
|
||||
|
||||
def setCancelValue(number)
|
||||
@cancelNumber=number
|
||||
end
|
||||
|
||||
def initialNumber
|
||||
return clamp(@initialNumber,self.minNumber,self.maxNumber)
|
||||
end
|
||||
|
||||
def cancelNumber
|
||||
return @cancelNumber || self.initialNumber
|
||||
end
|
||||
|
||||
def minNumber
|
||||
ret=0
|
||||
if @maxDigits>0
|
||||
ret=-((10**@maxDigits)-1)
|
||||
else
|
||||
ret=@minNumber
|
||||
end
|
||||
ret=0 if !@negativeAllowed && ret<0
|
||||
return ret
|
||||
end
|
||||
|
||||
def maxNumber
|
||||
ret=0
|
||||
if @maxDigits>0
|
||||
ret=((10**@maxDigits)-1)
|
||||
else
|
||||
ret=@maxNumber
|
||||
end
|
||||
ret=0 if !@negativeAllowed && ret<0
|
||||
return ret
|
||||
end
|
||||
|
||||
def setMaxDigits(value)
|
||||
@maxDigits=[1,value].max
|
||||
end
|
||||
|
||||
def maxDigits
|
||||
if @maxDigits>0
|
||||
return @maxDigits
|
||||
else
|
||||
return [numDigits(self.minNumber),numDigits(self.maxNumber)].max
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def clamp(v,mn,mx)
|
||||
return v<mn ? mn : (v>mx ? mx : v)
|
||||
end
|
||||
|
||||
def numDigits(number)
|
||||
ans = 1
|
||||
number=number.abs
|
||||
while number >= 10
|
||||
ans+=1
|
||||
number/=10
|
||||
end
|
||||
return ans
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def pbChooseNumber(msgwindow,params)
|
||||
return 0 if !params
|
||||
ret=0
|
||||
maximum=params.maxNumber
|
||||
minimum=params.minNumber
|
||||
defaultNumber=params.initialNumber
|
||||
cancelNumber=params.cancelNumber
|
||||
cmdwindow=Window_InputNumberPokemon.new(params.maxDigits)
|
||||
cmdwindow.z=99999
|
||||
cmdwindow.visible=true
|
||||
cmdwindow.setSkin(params.skin) if params.skin
|
||||
cmdwindow.sign=params.negativesAllowed # must be set before number
|
||||
cmdwindow.number=defaultNumber
|
||||
pbPositionNearMsgWindow(cmdwindow,msgwindow,:right)
|
||||
loop do
|
||||
Graphics.update
|
||||
Input.update
|
||||
pbUpdateSceneMap
|
||||
cmdwindow.update
|
||||
msgwindow.update if msgwindow
|
||||
yield if block_given?
|
||||
if Input.trigger?(Input::USE)
|
||||
ret=cmdwindow.number
|
||||
if ret>maximum
|
||||
pbPlayBuzzerSE()
|
||||
elsif ret<minimum
|
||||
pbPlayBuzzerSE()
|
||||
else
|
||||
pbPlayDecisionSE()
|
||||
break
|
||||
end
|
||||
elsif Input.trigger?(Input::BACK)
|
||||
pbPlayCancelSE()
|
||||
ret=cancelNumber
|
||||
break
|
||||
end
|
||||
end
|
||||
cmdwindow.dispose
|
||||
Input.update
|
||||
return ret
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class FaceWindowVX < SpriteWindow_Base
|
||||
def initialize(face)
|
||||
super(0,0,128,128)
|
||||
faceinfo=face.split(",")
|
||||
facefile=pbResolveBitmap("Graphics/Faces/"+faceinfo[0])
|
||||
facefile=pbResolveBitmap("Graphics/Pictures/"+faceinfo[0]) if !facefile
|
||||
self.contents.dispose if self.contents
|
||||
@faceIndex=faceinfo[1].to_i
|
||||
@facebitmaptmp=AnimatedBitmap.new(facefile)
|
||||
@facebitmap=BitmapWrapper.new(96,96)
|
||||
@facebitmap.blt(0,0,@facebitmaptmp.bitmap,Rect.new(
|
||||
(@faceIndex % 4) * 96,
|
||||
(@faceIndex / 4) * 96, 96, 96
|
||||
))
|
||||
self.contents=@facebitmap
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
if @facebitmaptmp.totalFrames>1
|
||||
@facebitmaptmp.update
|
||||
@facebitmap.blt(0,0,@facebitmaptmp.bitmap,Rect.new(
|
||||
(@faceIndex % 4) * 96,
|
||||
(@faceIndex / 4) * 96, 96, 96
|
||||
))
|
||||
end
|
||||
end
|
||||
|
||||
def dispose
|
||||
@facebitmaptmp.dispose
|
||||
@facebitmap.dispose if @facebitmap
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
def pbGetBasicMapNameFromId(id)
|
||||
begin
|
||||
map = pbLoadMapInfos
|
||||
return "" if !map
|
||||
return map[id].name
|
||||
rescue
|
||||
return ""
|
||||
end
|
||||
end
|
||||
|
||||
def pbGetMapNameFromId(id)
|
||||
map=pbGetBasicMapNameFromId(id)
|
||||
map.gsub!(/\\PN/,$Trainer.name) if $Trainer
|
||||
return map
|
||||
end
|
||||
|
||||
def pbCsvField!(str)
|
||||
ret=""
|
||||
str.sub!(/\A\s*/,"")
|
||||
if str[0,1]=="\""
|
||||
str[0,1]=""
|
||||
escaped=false
|
||||
fieldbytes=0
|
||||
str.scan(/./) do |s|
|
||||
fieldbytes+=s.length
|
||||
break if s=="\"" && !escaped
|
||||
if s=="\\" && !escaped
|
||||
escaped=true
|
||||
else
|
||||
ret+=s
|
||||
escaped=false
|
||||
end
|
||||
end
|
||||
str[0,fieldbytes]=""
|
||||
if !str[/\A\s*,/] && !str[/\A\s*$/]
|
||||
raise _INTL("Invalid quoted field (in: {1})",ret)
|
||||
end
|
||||
str[0,str.length]=$~.post_match
|
||||
else
|
||||
if str[/,/]
|
||||
str[0,str.length]=$~.post_match
|
||||
ret=$~.pre_match
|
||||
else
|
||||
ret=str.clone
|
||||
str[0,str.length]=""
|
||||
end
|
||||
ret.gsub!(/\s+$/,"")
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def pbCsvPosInt!(str)
|
||||
ret=pbCsvField!(str)
|
||||
if !ret[/\A\d+$/]
|
||||
raise _INTL("Field {1} is not a positive integer",ret)
|
||||
end
|
||||
return ret.to_i
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# Money and coins windows
|
||||
#===============================================================================
|
||||
def pbGetGoldString
|
||||
moneyString=""
|
||||
begin
|
||||
moneyString=_INTL("${1}",$Trainer.money.to_s_formatted)
|
||||
rescue
|
||||
if $data_system.respond_to?("words")
|
||||
moneyString=_INTL("{1} {2}",$game_party.gold,$data_system.words.gold)
|
||||
else
|
||||
moneyString=_INTL("{1} {2}",$game_party.gold,Vocab.gold)
|
||||
end
|
||||
end
|
||||
return moneyString
|
||||
end
|
||||
|
||||
def pbDisplayGoldWindow(msgwindow)
|
||||
moneyString=pbGetGoldString()
|
||||
goldwindow=Window_AdvancedTextPokemon.new(_INTL("Money:\n<ar>{1}</ar>",moneyString))
|
||||
goldwindow.setSkin("Graphics/Windowskins/goldskin")
|
||||
goldwindow.resizeToFit(goldwindow.text,Graphics.width)
|
||||
goldwindow.width=160 if goldwindow.width<=160
|
||||
if msgwindow.y==0
|
||||
goldwindow.y=Graphics.height-goldwindow.height
|
||||
else
|
||||
goldwindow.y=0
|
||||
end
|
||||
goldwindow.viewport=msgwindow.viewport
|
||||
goldwindow.z=msgwindow.z
|
||||
return goldwindow
|
||||
end
|
||||
|
||||
def pbDisplayCoinsWindow(msgwindow,goldwindow)
|
||||
coinString=($Trainer) ? $Trainer.coins.to_s_formatted : "0"
|
||||
coinwindow=Window_AdvancedTextPokemon.new(_INTL("Coins:\n<ar>{1}</ar>",coinString))
|
||||
coinwindow.setSkin("Graphics/Windowskins/goldskin")
|
||||
coinwindow.resizeToFit(coinwindow.text,Graphics.width)
|
||||
coinwindow.width=160 if coinwindow.width<=160
|
||||
if msgwindow.y==0
|
||||
coinwindow.y=(goldwindow) ? goldwindow.y-coinwindow.height : Graphics.height-coinwindow.height
|
||||
else
|
||||
coinwindow.y=(goldwindow) ? goldwindow.height : 0
|
||||
end
|
||||
coinwindow.viewport=msgwindow.viewport
|
||||
coinwindow.z=msgwindow.z
|
||||
return coinwindow
|
||||
end
|
||||
|
||||
def pbDisplayBattlePointsWindow(msgwindow)
|
||||
pointsString = ($Trainer) ? $Trainer.battle_points.to_s_formatted : "0"
|
||||
pointswindow=Window_AdvancedTextPokemon.new(_INTL("Battle Points:\n<ar>{1}</ar>", pointsString))
|
||||
pointswindow.setSkin("Graphics/Windowskins/goldskin")
|
||||
pointswindow.resizeToFit(pointswindow.text,Graphics.width)
|
||||
pointswindow.width=160 if pointswindow.width<=160
|
||||
if msgwindow.y==0
|
||||
pointswindow.y=Graphics.height-pointswindow.height
|
||||
else
|
||||
pointswindow.y=0
|
||||
end
|
||||
pointswindow.viewport=msgwindow.viewport
|
||||
pointswindow.z=msgwindow.z
|
||||
return pointswindow
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
def pbCreateStatusWindow(viewport=nil)
|
||||
msgwindow=Window_AdvancedTextPokemon.new("")
|
||||
if !viewport
|
||||
msgwindow.z=99999
|
||||
else
|
||||
msgwindow.viewport=viewport
|
||||
end
|
||||
msgwindow.visible=false
|
||||
msgwindow.letterbyletter=false
|
||||
pbBottomLeftLines(msgwindow,2)
|
||||
skinfile=MessageConfig.pbGetSpeechFrame()
|
||||
msgwindow.setSkin(skinfile)
|
||||
return msgwindow
|
||||
end
|
||||
|
||||
def pbCreateMessageWindow(viewport=nil,skin=nil)
|
||||
msgwindow=Window_AdvancedTextPokemon.new("")
|
||||
if !viewport
|
||||
msgwindow.z=99999
|
||||
else
|
||||
msgwindow.viewport=viewport
|
||||
end
|
||||
msgwindow.visible=true
|
||||
msgwindow.letterbyletter=true
|
||||
msgwindow.back_opacity=MessageConfig::WINDOW_OPACITY
|
||||
pbBottomLeftLines(msgwindow,2)
|
||||
$game_temp.message_window_showing=true if $game_temp
|
||||
skin=MessageConfig.pbGetSpeechFrame() if !skin
|
||||
msgwindow.setSkin(skin)
|
||||
return msgwindow
|
||||
end
|
||||
|
||||
def pbDisposeMessageWindow(msgwindow)
|
||||
$game_temp.message_window_showing=false if $game_temp
|
||||
msgwindow.dispose
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# Main message-displaying function
|
||||
#===============================================================================
|
||||
def pbMessageDisplay(msgwindow,message,letterbyletter=true,commandProc=nil)
|
||||
return if !msgwindow
|
||||
oldletterbyletter=msgwindow.letterbyletter
|
||||
msgwindow.letterbyletter=(letterbyletter) ? true : false
|
||||
ret=nil
|
||||
commands=nil
|
||||
facewindow=nil
|
||||
goldwindow=nil
|
||||
coinwindow=nil
|
||||
battlepointswindow=nil
|
||||
cmdvariable=0
|
||||
cmdIfCancel=0
|
||||
msgwindow.waitcount=0
|
||||
autoresume=false
|
||||
text=message.clone
|
||||
msgback=nil
|
||||
linecount=(Graphics.height>400) ? 3 : 2
|
||||
### Text replacement
|
||||
text.gsub!(/\\sign\[([^\]]*)\]/i) { # \sign[something] gets turned into
|
||||
next "\\op\\cl\\ts[]\\w["+$1+"]" # \op\cl\ts[]\w[something]
|
||||
}
|
||||
text.gsub!(/\\\\/,"\5")
|
||||
text.gsub!(/\\1/,"\1")
|
||||
if $game_actors
|
||||
text.gsub!(/\\n\[([1-8])\]/i) {
|
||||
m = $1.to_i
|
||||
next $game_actors[m].name
|
||||
}
|
||||
end
|
||||
text.gsub!(/\\pn/i,$Trainer.name) if $Trainer
|
||||
text.gsub!(/\\pm/i,_INTL("${1}",$Trainer.money.to_s_formatted)) if $Trainer
|
||||
text.gsub!(/\\n/i,"\n")
|
||||
text.gsub!(/\\\[([0-9a-f]{8,8})\]/i) { "<c2="+$1+">" }
|
||||
text.gsub!(/\\pg/i,"\\b") if $Trainer && $Trainer.male?
|
||||
text.gsub!(/\\pg/i,"\\r") if $Trainer && $Trainer.female?
|
||||
text.gsub!(/\\pog/i,"\\r") if $Trainer && $Trainer.male?
|
||||
text.gsub!(/\\pog/i,"\\b") if $Trainer && $Trainer.female?
|
||||
text.gsub!(/\\pg/i,"")
|
||||
text.gsub!(/\\pog/i,"")
|
||||
text.gsub!(/\\b/i,"<c3=3050C8,D0D0C8>")
|
||||
text.gsub!(/\\r/i,"<c3=E00808,D0D0C8>")
|
||||
text.gsub!(/\\[Ww]\[([^\]]*)\]/) {
|
||||
w = $1.to_s
|
||||
if w==""
|
||||
msgwindow.windowskin = nil
|
||||
else
|
||||
msgwindow.setSkin("Graphics/Windowskins/#{w}",false)
|
||||
end
|
||||
next ""
|
||||
}
|
||||
isDarkSkin = isDarkWindowskin(msgwindow.windowskin)
|
||||
text.gsub!(/\\[Cc]\[([0-9]+)\]/) {
|
||||
m = $1.to_i
|
||||
next getSkinColor(msgwindow.windowskin,m,isDarkSkin)
|
||||
}
|
||||
loop do
|
||||
last_text = text.clone
|
||||
text.gsub!(/\\v\[([0-9]+)\]/i) { $game_variables[$1.to_i] }
|
||||
break if text == last_text
|
||||
end
|
||||
loop do
|
||||
last_text = text.clone
|
||||
text.gsub!(/\\l\[([0-9]+)\]/i) {
|
||||
linecount = [1,$1.to_i].max
|
||||
next ""
|
||||
}
|
||||
break if text == last_text
|
||||
end
|
||||
colortag = ""
|
||||
if $game_system && $game_system.respond_to?("message_frame") &&
|
||||
$game_system.message_frame != 0
|
||||
colortag = getSkinColor(msgwindow.windowskin,0,true)
|
||||
else
|
||||
colortag = getSkinColor(msgwindow.windowskin,0,isDarkSkin)
|
||||
end
|
||||
text = colortag+text
|
||||
### Controls
|
||||
textchunks=[]
|
||||
controls=[]
|
||||
while text[/(?:\\(f|ff|ts|cl|me|se|wt|wtnp|ch)\[([^\]]*)\]|\\(g|cn|pt|wd|wm|op|cl|wu|\.|\||\!|\^))/i]
|
||||
textchunks.push($~.pre_match)
|
||||
if $~[1]
|
||||
controls.push([$~[1].downcase,$~[2],-1])
|
||||
else
|
||||
controls.push([$~[3].downcase,"",-1])
|
||||
end
|
||||
text=$~.post_match
|
||||
end
|
||||
textchunks.push(text)
|
||||
for chunk in textchunks
|
||||
chunk.gsub!(/\005/,"\\")
|
||||
end
|
||||
textlen = 0
|
||||
for i in 0...controls.length
|
||||
control = controls[i][0]
|
||||
case control
|
||||
when "wt", "wtnp", ".", "|"
|
||||
textchunks[i] += "\2"
|
||||
when "!"
|
||||
textchunks[i] += "\1"
|
||||
end
|
||||
textlen += toUnformattedText(textchunks[i]).scan(/./m).length
|
||||
controls[i][2] = textlen
|
||||
end
|
||||
text = textchunks.join("")
|
||||
signWaitCount = 0
|
||||
signWaitTime = Graphics.frame_rate/2
|
||||
haveSpecialClose = false
|
||||
specialCloseSE = ""
|
||||
for i in 0...controls.length
|
||||
control = controls[i][0]
|
||||
param = controls[i][1]
|
||||
case control
|
||||
when "op"
|
||||
signWaitCount = signWaitTime+1
|
||||
when "cl"
|
||||
text = text.sub(/\001\z/,"") # fix: '$' can match end of line as well
|
||||
haveSpecialClose = true
|
||||
specialCloseSE = param
|
||||
when "f"
|
||||
facewindow.dispose if facewindow
|
||||
facewindow = PictureWindow.new("Graphics/Pictures/#{param}")
|
||||
when "ff"
|
||||
facewindow.dispose if facewindow
|
||||
facewindow = FaceWindowVX.new(param)
|
||||
when "ch"
|
||||
cmds = param.clone
|
||||
cmdvariable = pbCsvPosInt!(cmds)
|
||||
cmdIfCancel = pbCsvField!(cmds).to_i
|
||||
commands = []
|
||||
while cmds.length>0
|
||||
commands.push(pbCsvField!(cmds))
|
||||
end
|
||||
when "wtnp", "^"
|
||||
text = text.sub(/\001\z/,"") # fix: '$' can match end of line as well
|
||||
when "se"
|
||||
if controls[i][2]==0
|
||||
startSE = param
|
||||
controls[i] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
if startSE!=nil
|
||||
pbSEPlay(pbStringToAudioFile(startSE))
|
||||
elsif signWaitCount==0 && letterbyletter
|
||||
pbPlayDecisionSE()
|
||||
end
|
||||
########## Position message window ##############
|
||||
pbRepositionMessageWindow(msgwindow,linecount)
|
||||
if facewindow
|
||||
pbPositionNearMsgWindow(facewindow,msgwindow,:left)
|
||||
facewindow.viewport = msgwindow.viewport
|
||||
facewindow.z = msgwindow.z
|
||||
end
|
||||
atTop = (msgwindow.y==0)
|
||||
########## Show text #############################
|
||||
msgwindow.text = text
|
||||
Graphics.frame_reset if Graphics.frame_rate>40
|
||||
loop do
|
||||
if signWaitCount>0
|
||||
signWaitCount -= 1
|
||||
if atTop
|
||||
msgwindow.y = -msgwindow.height*signWaitCount/signWaitTime
|
||||
else
|
||||
msgwindow.y = Graphics.height-msgwindow.height*(signWaitTime-signWaitCount)/signWaitTime
|
||||
end
|
||||
end
|
||||
for i in 0...controls.length
|
||||
next if !controls[i]
|
||||
next if controls[i][2]>msgwindow.position || msgwindow.waitcount!=0
|
||||
control = controls[i][0]
|
||||
param = controls[i][1]
|
||||
case control
|
||||
when "f"
|
||||
facewindow.dispose if facewindow
|
||||
facewindow = PictureWindow.new("Graphics/Pictures/#{param}")
|
||||
pbPositionNearMsgWindow(facewindow,msgwindow,:left)
|
||||
facewindow.viewport = msgwindow.viewport
|
||||
facewindow.z = msgwindow.z
|
||||
when "ff"
|
||||
facewindow.dispose if facewindow
|
||||
facewindow = FaceWindowVX.new(param)
|
||||
pbPositionNearMsgWindow(facewindow,msgwindow,:left)
|
||||
facewindow.viewport = msgwindow.viewport
|
||||
facewindow.z = msgwindow.z
|
||||
when "g" # Display gold window
|
||||
goldwindow.dispose if goldwindow
|
||||
goldwindow = pbDisplayGoldWindow(msgwindow)
|
||||
when "cn" # Display coins window
|
||||
coinwindow.dispose if coinwindow
|
||||
coinwindow = pbDisplayCoinsWindow(msgwindow,goldwindow)
|
||||
when "pt" # Display battle points window
|
||||
battlepointswindow.dispose if battlepointswindow
|
||||
battlepointswindow = pbDisplayBattlePointsWindow(msgwindow)
|
||||
when "wu"
|
||||
msgwindow.y = 0
|
||||
atTop = true
|
||||
msgback.y = msgwindow.y if msgback
|
||||
pbPositionNearMsgWindow(facewindow,msgwindow,:left)
|
||||
msgwindow.y = -msgwindow.height*signWaitCount/signWaitTime
|
||||
when "wm"
|
||||
atTop = false
|
||||
msgwindow.y = (Graphics.height-msgwindow.height)/2
|
||||
msgback.y = msgwindow.y if msgback
|
||||
pbPositionNearMsgWindow(facewindow,msgwindow,:left)
|
||||
when "wd"
|
||||
atTop = false
|
||||
msgwindow.y = Graphics.height-msgwindow.height
|
||||
msgback.y = msgwindow.y if msgback
|
||||
pbPositionNearMsgWindow(facewindow,msgwindow,:left)
|
||||
msgwindow.y = Graphics.height-msgwindow.height*(signWaitTime-signWaitCount)/signWaitTime
|
||||
when "ts" # Change text speed
|
||||
msgwindow.textspeed = (param=="") ? -999 : param.to_i
|
||||
when "." # Wait 0.25 seconds
|
||||
msgwindow.waitcount += Graphics.frame_rate/4
|
||||
when "|" # Wait 1 second
|
||||
msgwindow.waitcount += Graphics.frame_rate
|
||||
when "wt" # Wait X/20 seconds
|
||||
param = param.sub(/\A\s+/,"").sub(/\s+\z/,"")
|
||||
msgwindow.waitcount += param.to_i*Graphics.frame_rate/20
|
||||
when "wtnp" # Wait X/20 seconds, no pause
|
||||
param = param.sub(/\A\s+/,"").sub(/\s+\z/,"")
|
||||
msgwindow.waitcount = param.to_i*Graphics.frame_rate/20
|
||||
autoresume = true
|
||||
when "^" # Wait, no pause
|
||||
autoresume = true
|
||||
when "se" # Play SE
|
||||
pbSEPlay(pbStringToAudioFile(param))
|
||||
when "me" # Play ME
|
||||
pbMEPlay(pbStringToAudioFile(param))
|
||||
end
|
||||
controls[i] = nil
|
||||
end
|
||||
break if !letterbyletter
|
||||
Graphics.update
|
||||
Input.update
|
||||
facewindow.update if facewindow
|
||||
if autoresume && msgwindow.waitcount==0
|
||||
msgwindow.resume if msgwindow.busy?
|
||||
break if !msgwindow.busy?
|
||||
end
|
||||
if Input.trigger?(Input::USE) || Input.trigger?(Input::BACK)
|
||||
if msgwindow.busy?
|
||||
pbPlayDecisionSE if msgwindow.pausing?
|
||||
msgwindow.resume
|
||||
else
|
||||
break if signWaitCount==0
|
||||
end
|
||||
end
|
||||
pbUpdateSceneMap
|
||||
msgwindow.update
|
||||
yield if block_given?
|
||||
break if (!letterbyletter || commandProc || commands) && !msgwindow.busy?
|
||||
end
|
||||
Input.update # Must call Input.update again to avoid extra triggers
|
||||
msgwindow.letterbyletter=oldletterbyletter
|
||||
if commands
|
||||
$game_variables[cmdvariable]=pbShowCommands(msgwindow,commands,cmdIfCancel)
|
||||
$game_map.need_refresh = true if $game_map
|
||||
end
|
||||
if commandProc
|
||||
ret=commandProc.call(msgwindow)
|
||||
end
|
||||
msgback.dispose if msgback
|
||||
goldwindow.dispose if goldwindow
|
||||
coinwindow.dispose if coinwindow
|
||||
battlepointswindow.dispose if battlepointswindow
|
||||
facewindow.dispose if facewindow
|
||||
if haveSpecialClose
|
||||
pbSEPlay(pbStringToAudioFile(specialCloseSE))
|
||||
atTop = (msgwindow.y==0)
|
||||
for i in 0..signWaitTime
|
||||
if atTop
|
||||
msgwindow.y = -msgwindow.height*i/signWaitTime
|
||||
else
|
||||
msgwindow.y = Graphics.height-msgwindow.height*(signWaitTime-i)/signWaitTime
|
||||
end
|
||||
Graphics.update
|
||||
Input.update
|
||||
pbUpdateSceneMap
|
||||
msgwindow.update
|
||||
end
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# Message-displaying functions
|
||||
#===============================================================================
|
||||
def pbMessage(message,commands=nil,cmdIfCancel=0,skin=nil,defaultCmd=0,&block)
|
||||
ret = 0
|
||||
msgwindow = pbCreateMessageWindow(nil,skin)
|
||||
if commands
|
||||
ret = pbMessageDisplay(msgwindow,message,true,
|
||||
proc { |msgwindow|
|
||||
next Kernel.pbShowCommands(msgwindow,commands,cmdIfCancel,defaultCmd,&block)
|
||||
},&block)
|
||||
else
|
||||
pbMessageDisplay(msgwindow,message,&block)
|
||||
end
|
||||
pbDisposeMessageWindow(msgwindow)
|
||||
Input.update
|
||||
return ret
|
||||
end
|
||||
|
||||
def pbConfirmMessage(message,&block)
|
||||
return (pbMessage(message,[_INTL("Yes"),_INTL("No")],2,&block)==0)
|
||||
end
|
||||
|
||||
def pbConfirmMessageSerious(message,&block)
|
||||
return (pbMessage(message,[_INTL("No"),_INTL("Yes")],1,&block)==1)
|
||||
end
|
||||
|
||||
def pbMessageChooseNumber(message,params,&block)
|
||||
msgwindow = pbCreateMessageWindow(nil,params.messageSkin)
|
||||
ret = pbMessageDisplay(msgwindow,message,true,
|
||||
proc { |msgwindow|
|
||||
next pbChooseNumber(msgwindow,params,&block)
|
||||
},&block)
|
||||
pbDisposeMessageWindow(msgwindow)
|
||||
return ret
|
||||
end
|
||||
|
||||
def pbShowCommands(msgwindow,commands=nil,cmdIfCancel=0,defaultCmd=0)
|
||||
return 0 if !commands
|
||||
cmdwindow=Window_CommandPokemonEx.new(commands)
|
||||
cmdwindow.z=99999
|
||||
cmdwindow.visible=true
|
||||
cmdwindow.resizeToFit(cmdwindow.commands)
|
||||
pbPositionNearMsgWindow(cmdwindow,msgwindow,:right)
|
||||
cmdwindow.index=defaultCmd
|
||||
command=0
|
||||
loop do
|
||||
Graphics.update
|
||||
Input.update
|
||||
cmdwindow.update
|
||||
msgwindow.update if msgwindow
|
||||
yield if block_given?
|
||||
if Input.trigger?(Input::BACK)
|
||||
if cmdIfCancel>0
|
||||
command=cmdIfCancel-1
|
||||
break
|
||||
elsif cmdIfCancel<0
|
||||
command=cmdIfCancel
|
||||
break
|
||||
end
|
||||
end
|
||||
if Input.trigger?(Input::USE)
|
||||
command=cmdwindow.index
|
||||
break
|
||||
end
|
||||
pbUpdateSceneMap
|
||||
end
|
||||
ret=command
|
||||
cmdwindow.dispose
|
||||
Input.update
|
||||
return ret
|
||||
end
|
||||
|
||||
def pbShowCommandsWithHelp(msgwindow,commands,help,cmdIfCancel=0,defaultCmd=0)
|
||||
msgwin=msgwindow
|
||||
msgwin=pbCreateMessageWindow(nil) if !msgwindow
|
||||
oldlbl=msgwin.letterbyletter
|
||||
msgwin.letterbyletter=false
|
||||
if commands
|
||||
cmdwindow=Window_CommandPokemonEx.new(commands)
|
||||
cmdwindow.z=99999
|
||||
cmdwindow.visible=true
|
||||
cmdwindow.resizeToFit(cmdwindow.commands)
|
||||
cmdwindow.height=msgwin.y if cmdwindow.height>msgwin.y
|
||||
cmdwindow.index=defaultCmd
|
||||
command=0
|
||||
msgwin.text=help[cmdwindow.index]
|
||||
msgwin.width=msgwin.width # Necessary evil to make it use the proper margins
|
||||
loop do
|
||||
Graphics.update
|
||||
Input.update
|
||||
oldindex=cmdwindow.index
|
||||
cmdwindow.update
|
||||
if oldindex!=cmdwindow.index
|
||||
msgwin.text=help[cmdwindow.index]
|
||||
end
|
||||
msgwin.update
|
||||
yield if block_given?
|
||||
if Input.trigger?(Input::BACK)
|
||||
if cmdIfCancel>0
|
||||
command=cmdIfCancel-1
|
||||
break
|
||||
elsif cmdIfCancel<0
|
||||
command=cmdIfCancel
|
||||
break
|
||||
end
|
||||
end
|
||||
if Input.trigger?(Input::USE)
|
||||
command=cmdwindow.index
|
||||
break
|
||||
end
|
||||
pbUpdateSceneMap
|
||||
end
|
||||
ret=command
|
||||
cmdwindow.dispose
|
||||
Input.update
|
||||
end
|
||||
msgwin.letterbyletter=oldlbl
|
||||
msgwin.dispose if !msgwindow
|
||||
return ret
|
||||
end
|
||||
|
||||
# frames is the number of 1/20 seconds to wait for
|
||||
def pbMessageWaitForInput(msgwindow,frames,showPause=false)
|
||||
return if !frames || frames<=0
|
||||
msgwindow.startPause if msgwindow && showPause
|
||||
frames = frames*Graphics.frame_rate/20
|
||||
frames.times do
|
||||
Graphics.update
|
||||
Input.update
|
||||
msgwindow.update if msgwindow
|
||||
pbUpdateSceneMap
|
||||
if Input.trigger?(Input::USE) || Input.trigger?(Input::BACK)
|
||||
break
|
||||
end
|
||||
yield if block_given?
|
||||
end
|
||||
msgwindow.stopPause if msgwindow && showPause
|
||||
end
|
||||
|
||||
def pbFreeText(msgwindow,currenttext,passwordbox,maxlength,width=240)
|
||||
window=Window_TextEntry_Keyboard.new(currenttext,0,0,width,64)
|
||||
ret=""
|
||||
window.maxlength=maxlength
|
||||
window.visible=true
|
||||
window.z=99999
|
||||
pbPositionNearMsgWindow(window,msgwindow,:right)
|
||||
window.text=currenttext
|
||||
window.passwordChar="*" if passwordbox
|
||||
Input.text_input = true
|
||||
loop do
|
||||
Graphics.update
|
||||
Input.update
|
||||
if Input.triggerex?(:ESCAPE)
|
||||
ret=currenttext
|
||||
break
|
||||
elsif Input.triggerex?(:RETURN)
|
||||
ret=window.text
|
||||
break
|
||||
end
|
||||
window.update
|
||||
msgwindow.update if msgwindow
|
||||
yield if block_given?
|
||||
end
|
||||
Input.text_input = false
|
||||
window.dispose
|
||||
Input.update
|
||||
return ret
|
||||
end
|
||||
|
||||
def pbMessageFreeText(message,currenttext,passwordbox,maxlength,width=240,&block)
|
||||
msgwindow=pbCreateMessageWindow
|
||||
retval=pbMessageDisplay(msgwindow,message,true,
|
||||
proc { |msgwindow|
|
||||
next pbFreeText(msgwindow,currenttext,passwordbox,maxlength,width,&block)
|
||||
},&block)
|
||||
pbDisposeMessageWindow(msgwindow)
|
||||
return retval
|
||||
end
|
||||
564
Data/Scripts_backup/007_Objects and windows/012_TextEntry.rb
Normal file
564
Data/Scripts_backup/007_Objects and windows/012_TextEntry.rb
Normal file
@@ -0,0 +1,564 @@
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class CharacterEntryHelper
|
||||
attr_reader :text
|
||||
attr_accessor :maxlength
|
||||
attr_reader :passwordChar
|
||||
attr_accessor :cursor
|
||||
|
||||
def initialize(text)
|
||||
@maxlength=-1
|
||||
@text=text
|
||||
@passwordChar=""
|
||||
@cursor=text.scan(/./m).length
|
||||
end
|
||||
|
||||
def text=(value)
|
||||
@text=value
|
||||
end
|
||||
|
||||
def textChars
|
||||
chars=text.scan(/./m)
|
||||
if @passwordChar!=""
|
||||
chars.length.times { |i| chars[i] = @passwordChar }
|
||||
end
|
||||
return chars
|
||||
end
|
||||
|
||||
def passwordChar=(value)
|
||||
@passwordChar=value ? value : ""
|
||||
end
|
||||
|
||||
def length
|
||||
return self.text.scan(/./m).length
|
||||
end
|
||||
|
||||
def canInsert?
|
||||
chars=self.text.scan(/./m)
|
||||
return false if @maxlength>=0 && chars.length>=@maxlength
|
||||
return true
|
||||
end
|
||||
|
||||
def insert(ch)
|
||||
chars=self.text.scan(/./m)
|
||||
return false if @maxlength>=0 && chars.length>=@maxlength
|
||||
chars.insert(@cursor,ch)
|
||||
@text=""
|
||||
for ch in chars
|
||||
@text+=ch if ch
|
||||
end
|
||||
@cursor+=1
|
||||
return true
|
||||
end
|
||||
|
||||
def canDelete?
|
||||
chars=self.text.scan(/./m)
|
||||
return false if chars.length<=0 || @cursor<=0
|
||||
return true
|
||||
end
|
||||
|
||||
def delete
|
||||
chars=self.text.scan(/./m)
|
||||
return false if chars.length<=0 || @cursor<=0
|
||||
chars.delete_at(@cursor-1)
|
||||
@text=""
|
||||
for ch in chars
|
||||
@text+=ch if ch
|
||||
end
|
||||
@cursor-=1
|
||||
return true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ensure
|
||||
return if @maxlength<0
|
||||
chars=self.text.scan(/./m)
|
||||
if chars.length>@maxlength && @maxlength>=0
|
||||
chars=chars[0,@maxlength]
|
||||
end
|
||||
@text=""
|
||||
for ch in chars
|
||||
@text+=ch if ch
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class Window_TextEntry < SpriteWindow_Base
|
||||
def initialize(text,x,y,width,height,heading=nil,usedarkercolor=false)
|
||||
super(x,y,width,height)
|
||||
colors=getDefaultTextColors(self.windowskin)
|
||||
@baseColor=colors[0]
|
||||
@shadowColor=colors[1]
|
||||
if usedarkercolor
|
||||
@baseColor=Color.new(16,24,32)
|
||||
@shadowColor=Color.new(168,184,184)
|
||||
end
|
||||
@helper=CharacterEntryHelper.new(text)
|
||||
@heading=heading
|
||||
self.active=true
|
||||
@frame=0
|
||||
refresh
|
||||
end
|
||||
|
||||
def text
|
||||
@helper.text
|
||||
end
|
||||
|
||||
def maxlength
|
||||
@helper.maxlength
|
||||
end
|
||||
|
||||
def passwordChar
|
||||
@helper.passwordChar
|
||||
end
|
||||
|
||||
def text=(value)
|
||||
@helper.text=value
|
||||
self.refresh
|
||||
end
|
||||
|
||||
def passwordChar=(value)
|
||||
@helper.passwordChar=value
|
||||
refresh
|
||||
end
|
||||
|
||||
def maxlength=(value)
|
||||
@helper.maxlength=value
|
||||
self.refresh
|
||||
end
|
||||
|
||||
def insert(ch)
|
||||
if @helper.insert(ch)
|
||||
@frame=0
|
||||
self.refresh
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def delete
|
||||
if @helper.delete
|
||||
@frame=0
|
||||
self.refresh
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def update
|
||||
@frame += 1
|
||||
@frame %= 20
|
||||
self.refresh if (@frame%10)==0
|
||||
return if !self.active
|
||||
# Moving cursor
|
||||
if Input.repeat?(Input::LEFT) && Input.press?(Input::ACTION)
|
||||
if @helper.cursor > 0
|
||||
@helper.cursor -= 1
|
||||
@frame = 0
|
||||
self.refresh
|
||||
end
|
||||
elsif Input.repeat?(Input::RIGHT) && Input.press?(Input::ACTION)
|
||||
if @helper.cursor < self.text.scan(/./m).length
|
||||
@helper.cursor += 1
|
||||
@frame = 0
|
||||
self.refresh
|
||||
end
|
||||
elsif Input.repeat?(Input::BACK) # Backspace
|
||||
self.delete if @helper.cursor > 0
|
||||
end
|
||||
end
|
||||
|
||||
def refresh
|
||||
self.contents=pbDoEnsureBitmap(self.contents,self.width-self.borderX,
|
||||
self.height-self.borderY)
|
||||
bitmap=self.contents
|
||||
bitmap.clear
|
||||
x=0
|
||||
y=0
|
||||
if @heading
|
||||
textwidth=bitmap.text_size(@heading).width
|
||||
pbDrawShadowText(bitmap,x,y, textwidth+4, 32, @heading,@baseColor,@shadowColor)
|
||||
y+=32
|
||||
end
|
||||
x+=4
|
||||
width=self.width-self.borderX
|
||||
cursorcolor=Color.new(16,24,32)
|
||||
textscan=self.text.scan(/./m)
|
||||
scanlength=textscan.length
|
||||
@helper.cursor=scanlength if @helper.cursor>scanlength
|
||||
@helper.cursor=0 if @helper.cursor<0
|
||||
startpos=@helper.cursor
|
||||
fromcursor=0
|
||||
while (startpos>0)
|
||||
c=(@helper.passwordChar!="") ? @helper.passwordChar : textscan[startpos-1]
|
||||
fromcursor+=bitmap.text_size(c).width
|
||||
break if fromcursor>width-4
|
||||
startpos-=1
|
||||
end
|
||||
for i in startpos...scanlength
|
||||
c=(@helper.passwordChar!="") ? @helper.passwordChar : textscan[i]
|
||||
textwidth=bitmap.text_size(c).width
|
||||
next if c=="\n"
|
||||
# Draw text
|
||||
pbDrawShadowText(bitmap,x,y, textwidth+4, 32, c,@baseColor,@shadowColor)
|
||||
# Draw cursor if necessary
|
||||
if ((@frame/10)&1) == 0 && i==@helper.cursor
|
||||
bitmap.fill_rect(x,y+4,2,24,cursorcolor)
|
||||
end
|
||||
# Add x to drawn text width
|
||||
x += textwidth
|
||||
end
|
||||
if ((@frame/10)&1) == 0 && textscan.length==@helper.cursor
|
||||
bitmap.fill_rect(x,y+4,2,24,cursorcolor)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class Window_TextEntry_Keyboard < Window_TextEntry
|
||||
def update
|
||||
@frame+=1
|
||||
@frame%=20
|
||||
self.refresh if ((@frame%10)==0)
|
||||
return if !self.active
|
||||
# Moving cursor
|
||||
if Input.triggerex?(:LEFT) || Input.repeatex?(:LEFT)
|
||||
if @helper.cursor > 0
|
||||
@helper.cursor-=1
|
||||
@frame=0
|
||||
self.refresh
|
||||
end
|
||||
return
|
||||
elsif Input.triggerex?(:RIGHT) || Input.repeatex?(:RIGHT)
|
||||
if @helper.cursor < self.text.scan(/./m).length
|
||||
@helper.cursor+=1
|
||||
@frame=0
|
||||
self.refresh
|
||||
end
|
||||
return
|
||||
elsif Input.triggerex?(:BACKSPACE) || Input.repeatex?(:BACKSPACE)
|
||||
self.delete if @helper.cursor>0
|
||||
return
|
||||
elsif Input.triggerex?(:RETURN) || Input.triggerex?(:ESCAPE)
|
||||
return
|
||||
end
|
||||
Input.gets.each_char { |c| insert(c) }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class Window_MultilineTextEntry < SpriteWindow_Base
|
||||
def initialize(text,x,y,width,height)
|
||||
super(x,y,width,height)
|
||||
colors=getDefaultTextColors(self.windowskin)
|
||||
@baseColor=colors[0]
|
||||
@shadowColor=colors[1]
|
||||
@helper=CharacterEntryHelper.new(text)
|
||||
@firstline=0
|
||||
@cursorLine=0
|
||||
@cursorColumn=0
|
||||
@frame=0
|
||||
self.active=true
|
||||
refresh
|
||||
end
|
||||
|
||||
attr_reader :baseColor
|
||||
attr_reader :shadowColor
|
||||
|
||||
def baseColor=(value)
|
||||
@baseColor=value
|
||||
refresh
|
||||
end
|
||||
|
||||
def shadowColor=(value)
|
||||
@shadowColor=value
|
||||
refresh
|
||||
end
|
||||
|
||||
def text
|
||||
@helper.text
|
||||
end
|
||||
|
||||
def maxlength
|
||||
@helper.maxlength
|
||||
end
|
||||
|
||||
def text=(value)
|
||||
@helper.text=value
|
||||
@textchars=nil
|
||||
self.refresh
|
||||
end
|
||||
|
||||
def maxlength=(value)
|
||||
@helper.maxlength=value
|
||||
@textchars=nil
|
||||
self.refresh
|
||||
end
|
||||
|
||||
def insert(ch)
|
||||
@helper.cursor=getPosFromLineAndColumn(@cursorLine,@cursorColumn)
|
||||
if @helper.insert(ch)
|
||||
@frame=0
|
||||
@textchars=nil
|
||||
moveCursor(0,1)
|
||||
self.refresh
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def delete
|
||||
@helper.cursor=getPosFromLineAndColumn(@cursorLine,@cursorColumn)
|
||||
if @helper.delete
|
||||
@frame=0
|
||||
moveCursor(0,-1) # use old textchars
|
||||
@textchars=nil
|
||||
self.refresh
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def getTextChars
|
||||
if !@textchars
|
||||
@textchars=getLineBrokenText(self.contents,@helper.text,
|
||||
self.contents.width,nil)
|
||||
end
|
||||
return @textchars
|
||||
end
|
||||
|
||||
def getTotalLines
|
||||
textchars=getTextChars
|
||||
return 1 if textchars.length==0
|
||||
tchar=textchars[textchars.length-1]
|
||||
return tchar[5]+1
|
||||
end
|
||||
|
||||
def getLineY(line)
|
||||
textchars=getTextChars
|
||||
return 0 if textchars.length==0
|
||||
totallines=getTotalLines()
|
||||
line=0 if line<0
|
||||
line=totallines-1 if line>=totallines
|
||||
maximumY=0
|
||||
for i in 0...textchars.length
|
||||
thisline=textchars[i][5]
|
||||
y=textchars[i][2]
|
||||
return y if thisline==line
|
||||
maximumY=y if maximumY<y
|
||||
end
|
||||
return maximumY
|
||||
end
|
||||
|
||||
def getColumnsInLine(line)
|
||||
textchars=getTextChars
|
||||
return 0 if textchars.length==0
|
||||
totallines=getTotalLines()
|
||||
line=0 if line<0
|
||||
line=totallines-1 if line>=totallines
|
||||
endpos=0
|
||||
for i in 0...textchars.length
|
||||
thisline=textchars[i][5]
|
||||
thislength=textchars[i][8]
|
||||
endpos+=thislength if thisline==line
|
||||
end
|
||||
return endpos
|
||||
end
|
||||
|
||||
def getPosFromLineAndColumn(line,column)
|
||||
textchars=getTextChars
|
||||
return 0 if textchars.length==0
|
||||
totallines=getTotalLines()
|
||||
line=0 if line<0
|
||||
line=totallines-1 if line>=totallines
|
||||
endpos=0
|
||||
for i in 0...textchars.length
|
||||
thisline=textchars[i][5]
|
||||
thispos=textchars[i][6]
|
||||
thiscolumn=textchars[i][7]
|
||||
thislength=textchars[i][8]
|
||||
if thisline==line
|
||||
endpos=thispos+thislength
|
||||
# echoln [endpos,thispos+(column-thiscolumn),textchars[i]]
|
||||
if column>=thiscolumn && column<=thiscolumn+thislength && thislength>0
|
||||
return thispos+(column-thiscolumn)
|
||||
end
|
||||
end
|
||||
end
|
||||
# if endpos==0
|
||||
# echoln [totallines,line,column]
|
||||
# echoln textchars
|
||||
# end
|
||||
# echoln "endpos=#{endpos}"
|
||||
return endpos
|
||||
end
|
||||
|
||||
def getLastVisibleLine
|
||||
getTextChars()
|
||||
textheight=[1,self.contents.text_size("X").height].max
|
||||
lastVisible=@firstline+((self.height-self.borderY)/textheight)-1
|
||||
return lastVisible
|
||||
end
|
||||
|
||||
def updateCursorPos(doRefresh)
|
||||
# Calculate new cursor position
|
||||
@helper.cursor=getPosFromLineAndColumn(@cursorLine,@cursorColumn)
|
||||
if doRefresh
|
||||
@frame=0
|
||||
self.refresh
|
||||
end
|
||||
@firstline=@cursorLine if @cursorLine<@firstline
|
||||
lastVisible=getLastVisibleLine()
|
||||
@firstline+=(@cursorLine-lastVisible) if @cursorLine>lastVisible
|
||||
end
|
||||
|
||||
def moveCursor(lineOffset, columnOffset)
|
||||
# Move column offset first, then lines (since column offset
|
||||
# can affect line offset)
|
||||
# echoln ["beforemoving",@cursorLine,@cursorColumn]
|
||||
totalColumns=getColumnsInLine(@cursorLine) # check current line
|
||||
totalLines=getTotalLines()
|
||||
oldCursorLine=@cursorLine
|
||||
oldCursorColumn=@cursorColumn
|
||||
@cursorColumn+=columnOffset
|
||||
if @cursorColumn<0 && @cursorLine>0
|
||||
# Will happen if cursor is moved left from the beginning of a line
|
||||
@cursorLine-=1
|
||||
@cursorColumn=getColumnsInLine(@cursorLine)
|
||||
elsif @cursorColumn>totalColumns && @cursorLine<totalLines-1
|
||||
# Will happen if cursor is moved right from the end of a line
|
||||
@cursorLine+=1
|
||||
@cursorColumn=0
|
||||
end
|
||||
# Ensure column bounds
|
||||
totalColumns=getColumnsInLine(@cursorLine)
|
||||
@cursorColumn=totalColumns if @cursorColumn>totalColumns
|
||||
@cursorColumn=0 if @cursorColumn<0 # totalColumns can be 0
|
||||
# Move line offset
|
||||
@cursorLine+=lineOffset
|
||||
@cursorLine=0 if @cursorLine<0
|
||||
@cursorLine=totalLines-1 if @cursorLine>=totalLines
|
||||
# Ensure column bounds again
|
||||
totalColumns=getColumnsInLine(@cursorLine)
|
||||
@cursorColumn=totalColumns if @cursorColumn>totalColumns
|
||||
@cursorColumn=0 if @cursorColumn<0 # totalColumns can be 0
|
||||
updateCursorPos(
|
||||
oldCursorLine!=@cursorLine ||
|
||||
oldCursorColumn!=@cursorColumn
|
||||
)
|
||||
# echoln ["aftermoving",@cursorLine,@cursorColumn]
|
||||
end
|
||||
|
||||
def update
|
||||
@frame+=1
|
||||
@frame%=20
|
||||
self.refresh if ((@frame%10)==0)
|
||||
return if !self.active
|
||||
# Moving cursor
|
||||
if Input.triggerex?(:UP) || Input.repeatex?(:UP)
|
||||
moveCursor(-1,0)
|
||||
return
|
||||
elsif Input.triggerex?(:DOWN) || Input.repeatex?(:DOWN)
|
||||
moveCursor(1,0)
|
||||
return
|
||||
elsif Input.triggerex?(:LEFT) || Input.repeatex?(:LEFT)
|
||||
moveCursor(0,-1)
|
||||
return
|
||||
elsif Input.triggerex?(:RIGHT) || Input.repeatex?(:RIGHT)
|
||||
moveCursor(0,1)
|
||||
return
|
||||
end
|
||||
if Input.press?(Input::CTRL) && Input.triggerex?(:HOME)
|
||||
# Move cursor to beginning
|
||||
@cursorLine=0
|
||||
@cursorColumn=0
|
||||
updateCursorPos(true)
|
||||
return
|
||||
elsif Input.press?(Input::CTRL) && Input.triggerex?(:END)
|
||||
# Move cursor to end
|
||||
@cursorLine=getTotalLines()-1
|
||||
@cursorColumn=getColumnsInLine(@cursorLine)
|
||||
updateCursorPos(true)
|
||||
return
|
||||
elsif Input.triggerex?(:RETURN) || Input.repeatex?(:RETURN)
|
||||
self.insert("\n")
|
||||
return
|
||||
elsif Input.triggerex?(:BACKSPACE) || Input.repeatex?(:BACKSPACE) # Backspace
|
||||
self.delete
|
||||
return
|
||||
end
|
||||
Input.gets.each_char{|c|insert(c)}
|
||||
end
|
||||
|
||||
def refresh
|
||||
newContents=pbDoEnsureBitmap(self.contents,self.width-self.borderX,
|
||||
self.height-self.borderY)
|
||||
@textchars=nil if self.contents!=newContents
|
||||
self.contents=newContents
|
||||
bitmap=self.contents
|
||||
bitmap.clear
|
||||
getTextChars
|
||||
height=self.height-self.borderY
|
||||
cursorcolor=Color.new(0,0,0)
|
||||
textchars=getTextChars()
|
||||
startY=getLineY(@firstline)
|
||||
for i in 0...textchars.length
|
||||
thisline=textchars[i][5]
|
||||
thiscolumn=textchars[i][7]
|
||||
thislength=textchars[i][8]
|
||||
textY=textchars[i][2]-startY
|
||||
# Don't draw lines before the first or zero-length segments
|
||||
next if thisline<@firstline || thislength==0
|
||||
# Don't draw lines beyond the window's height
|
||||
break if textY >= height
|
||||
c=textchars[i][0]
|
||||
# Don't draw spaces
|
||||
next if c==" "
|
||||
textwidth=textchars[i][3]+4 # add 4 to prevent draw_text from stretching text
|
||||
textheight=textchars[i][4]
|
||||
# Draw text
|
||||
pbDrawShadowText(bitmap, textchars[i][1], textY, textwidth, textheight, c, @baseColor, @shadowColor)
|
||||
end
|
||||
# Draw cursor
|
||||
if ((@frame/10)&1) == 0
|
||||
textheight=bitmap.text_size("X").height
|
||||
cursorY=(textheight*@cursorLine)-startY
|
||||
cursorX=0
|
||||
for i in 0...textchars.length
|
||||
thisline=textchars[i][5]
|
||||
thiscolumn=textchars[i][7]
|
||||
thislength=textchars[i][8]
|
||||
if thisline==@cursorLine && @cursorColumn>=thiscolumn &&
|
||||
@cursorColumn<=thiscolumn+thislength
|
||||
cursorY=textchars[i][2]-startY
|
||||
cursorX=textchars[i][1]
|
||||
textheight=textchars[i][4]
|
||||
posToCursor=@cursorColumn-thiscolumn
|
||||
if posToCursor>=0
|
||||
partialString=textchars[i][0].scan(/./m)[0,posToCursor].join("")
|
||||
cursorX+=bitmap.text_size(partialString).width
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
cursorY+=4
|
||||
cursorHeight=[4,textheight-4,bitmap.text_size("X").height-4].max
|
||||
bitmap.fill_rect(cursorX,cursorY,2,cursorHeight,cursorcolor)
|
||||
end
|
||||
end
|
||||
end
|
||||
171
Data/Scripts_backup/008_Audio/001_Audio.rb
Normal file
171
Data/Scripts_backup/008_Audio/001_Audio.rb
Normal file
@@ -0,0 +1,171 @@
|
||||
#####################################
|
||||
# Needed because RGSS doesn't call at_exit procs on exit
|
||||
# Exit is not called when game is reset (using F12)
|
||||
$AtExitProcs=[] if !$AtExitProcs
|
||||
|
||||
def exit(code=0)
|
||||
for p in $AtExitProcs
|
||||
p.call
|
||||
end
|
||||
raise SystemExit.new(code)
|
||||
end
|
||||
|
||||
def at_exit(&block)
|
||||
$AtExitProcs.push(Proc.new(&block))
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# Methods that determine the duration of an audio file.
|
||||
#===============================================================================
|
||||
def getOggPage(file)
|
||||
fgetdw = proc { |file|
|
||||
(file.eof? ? 0 : (file.read(4).unpack("V")[0] || 0))
|
||||
}
|
||||
dw = fgetdw.call(file)
|
||||
return nil if dw != 0x5367674F
|
||||
header = file.read(22)
|
||||
bodysize = 0
|
||||
hdrbodysize = (file.read(1)[0].ord rescue 0)
|
||||
hdrbodysize.times do
|
||||
bodysize += (file.read(1)[0].ord rescue 0)
|
||||
end
|
||||
ret = [header, file.pos, bodysize, file.pos + bodysize]
|
||||
return ret
|
||||
end
|
||||
|
||||
# internal function
|
||||
def oggfiletime(file)
|
||||
fgetdw = proc { |file|
|
||||
(file.eof? ? 0 : (file.read(4).unpack("V")[0] || 0))
|
||||
}
|
||||
pages = []
|
||||
page = nil
|
||||
loop do
|
||||
page = getOggPage(file)
|
||||
break if !page
|
||||
pages.push(page)
|
||||
file.pos = page[3]
|
||||
end
|
||||
return -1 if pages.length == 0
|
||||
curserial = nil
|
||||
i = -1
|
||||
pcmlengths = []
|
||||
rates = []
|
||||
for page in pages
|
||||
header = page[0]
|
||||
serial = header[10, 4].unpack("V")
|
||||
frame = header[2, 8].unpack("C*")
|
||||
frameno = frame[7]
|
||||
frameno = (frameno << 8) | frame[6]
|
||||
frameno = (frameno << 8) | frame[5]
|
||||
frameno = (frameno << 8) | frame[4]
|
||||
frameno = (frameno << 8) | frame[3]
|
||||
frameno = (frameno << 8) | frame[2]
|
||||
frameno = (frameno << 8) | frame[1]
|
||||
frameno = (frameno << 8) | frame[0]
|
||||
if serial != curserial
|
||||
curserial = serial
|
||||
file.pos = page[1]
|
||||
packtype = (file.read(1)[0].ord rescue 0)
|
||||
string = file.read(6)
|
||||
return -1 if string != "vorbis"
|
||||
return -1 if packtype != 1
|
||||
i += 1
|
||||
version = fgetdw.call(file)
|
||||
return -1 if version != 0
|
||||
rates[i] = fgetdw.call(file)
|
||||
end
|
||||
pcmlengths[i] = frameno
|
||||
end
|
||||
ret = 0.0
|
||||
for i in 0...pcmlengths.length
|
||||
ret += pcmlengths[i].to_f / rates[i].to_f
|
||||
end
|
||||
return ret * 256.0
|
||||
end
|
||||
|
||||
# Gets the length of an audio file in seconds. Supports WAV, MP3, and OGG files.
|
||||
def getPlayTime(filename)
|
||||
if safeExists?(filename)
|
||||
return [getPlayTime2(filename), 0].max
|
||||
elsif safeExists?(filename + ".wav")
|
||||
return [getPlayTime2(filename + ".wav"), 0].max
|
||||
elsif safeExists?(filename + ".mp3")
|
||||
return [getPlayTime2(filename + ".mp3"), 0].max
|
||||
elsif safeExists?(filename + ".ogg")
|
||||
return [getPlayTime2(filename + ".ogg"), 0].max
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
def getPlayTime2(filename)
|
||||
return -1 if !safeExists?(filename)
|
||||
time = -1
|
||||
fgetdw = proc { |file|
|
||||
(file.eof? ? 0 : (file.read(4).unpack("V")[0] || 0))
|
||||
}
|
||||
fgetw = proc { |file|
|
||||
(file.eof? ? 0 : (file.read(2).unpack("v")[0] || 0))
|
||||
}
|
||||
File.open(filename, "rb") { |file|
|
||||
file.pos = 0
|
||||
fdw = fgetdw.call(file)
|
||||
if fdw == 0x46464952 # "RIFF"
|
||||
filesize = fgetdw.call(file)
|
||||
wave = fgetdw.call(file)
|
||||
return -1 if wave != 0x45564157 # "WAVE"
|
||||
fmt = fgetdw.call(file)
|
||||
return -1 if fmt != 0x20746d66 # "fmt "
|
||||
fmtsize = fgetdw.call(file)
|
||||
format = fgetw.call(file)
|
||||
channels = fgetw.call(file)
|
||||
rate = fgetdw.call(file)
|
||||
bytessec = fgetdw.call(file)
|
||||
return -1 if bytessec == 0
|
||||
bytessample = fgetw.call(file)
|
||||
bitssample = fgetw.call(file)
|
||||
data = fgetdw.call(file)
|
||||
return -1 if data != 0x61746164 # "data"
|
||||
datasize = fgetdw.call(file)
|
||||
time = (datasize*1.0)/bytessec
|
||||
return time
|
||||
elsif fdw == 0x5367674F # "OggS"
|
||||
file.pos = 0
|
||||
time = oggfiletime(file)
|
||||
return time
|
||||
end
|
||||
file.pos = 0
|
||||
# Find the length of an MP3 file
|
||||
while true
|
||||
rstr = ""
|
||||
ateof = false
|
||||
while !file.eof?
|
||||
if (file.read(1)[0] rescue 0) == 0xFF
|
||||
begin
|
||||
rstr = file.read(3)
|
||||
rescue
|
||||
ateof = true
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
break if ateof || !rstr || rstr.length != 3
|
||||
if rstr[0] == 0xFB
|
||||
t = rstr[1] >> 4
|
||||
next if t == 0 || t == 15
|
||||
freqs = [44100, 22050, 11025, 48000]
|
||||
bitrates = [32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320]
|
||||
bitrate = bitrates[t]
|
||||
t = (rstr[1] >> 2) & 3
|
||||
freq = freqs[t]
|
||||
t = (rstr[1] >> 1) & 1
|
||||
filesize = FileTest.size(filename)
|
||||
frameLength = ((144000 * bitrate) / freq) + t
|
||||
numFrames = filesize / (frameLength + 4)
|
||||
time = (numFrames * 1152.0 / freq)
|
||||
break
|
||||
end
|
||||
end
|
||||
}
|
||||
return time
|
||||
end
|
||||
292
Data/Scripts_backup/008_Audio/002_Audio_Play.rb
Normal file
292
Data/Scripts_backup/008_Audio/002_Audio_Play.rb
Normal file
@@ -0,0 +1,292 @@
|
||||
def pbStringToAudioFile(str)
|
||||
if str[/^(.*)\:\s*(\d+)\s*\:\s*(\d+)\s*$/] # Of the format "XXX: ###: ###"
|
||||
file = $1
|
||||
volume = $2.to_i
|
||||
pitch = $3.to_i
|
||||
return RPG::AudioFile.new(file,volume,pitch)
|
||||
elsif str[/^(.*)\:\s*(\d+)\s*$/] # Of the format "XXX: ###"
|
||||
file = $1
|
||||
volume = $2.to_i
|
||||
return RPG::AudioFile.new(file,volume,100)
|
||||
else
|
||||
return RPG::AudioFile.new(str,100,100)
|
||||
end
|
||||
end
|
||||
|
||||
# Converts an object to an audio file.
|
||||
# str -- Either a string showing the filename or an RPG::AudioFile object.
|
||||
# Possible formats for _str_:
|
||||
# filename volume and pitch 100
|
||||
# filename:volume pitch 100
|
||||
# filename:volume:pitch
|
||||
# volume -- Volume of the file, up to 100
|
||||
# pitch -- Pitch of the file, normally 100
|
||||
def pbResolveAudioFile(str,volume=nil,pitch=nil)
|
||||
if str.is_a?(String)
|
||||
str = pbStringToAudioFile(str)
|
||||
str.volume = volume || 100
|
||||
str.pitch = pitch || 100
|
||||
end
|
||||
if str.is_a?(RPG::AudioFile)
|
||||
if volume || pitch
|
||||
return RPG::AudioFile.new(str.name,volume || str.volume || 100 ,
|
||||
pitch || str.pitch || 100)
|
||||
else
|
||||
return str
|
||||
end
|
||||
end
|
||||
return str
|
||||
end
|
||||
|
||||
################################################################################
|
||||
|
||||
# Plays a BGM file.
|
||||
# param -- Either a string showing the filename
|
||||
# (relative to Audio/BGM/) or an RPG::AudioFile object.
|
||||
# Possible formats for _param_:
|
||||
# filename volume and pitch 100
|
||||
# filename:volume pitch 100
|
||||
# filename:volume:pitch
|
||||
# volume -- Volume of the file, up to 100
|
||||
# pitch -- Pitch of the file, normally 100
|
||||
def pbBGMPlay(param,volume=nil,pitch=nil)
|
||||
return if !param
|
||||
param=pbResolveAudioFile(param,volume,pitch)
|
||||
if param.name && param.name!=""
|
||||
if $game_system && $game_system.respond_to?("bgm_play")
|
||||
$game_system.bgm_play(param)
|
||||
return
|
||||
elsif (RPG.const_defined?(:BGM) rescue false)
|
||||
b=RPG::BGM.new(param.name,param.volume,param.pitch)
|
||||
if b && b.respond_to?("play")
|
||||
b.play
|
||||
return
|
||||
end
|
||||
end
|
||||
Audio.bgm_play(canonicalize("Audio/BGM/"+param.name),param.volume,param.pitch)
|
||||
end
|
||||
end
|
||||
|
||||
# Fades out or stops BGM playback. 'x' is the time in seconds to fade out.
|
||||
def pbBGMFade(x=0.0); pbBGMStop(x);end
|
||||
|
||||
# Fades out or stops BGM playback. 'x' is the time in seconds to fade out.
|
||||
def pbBGMStop(timeInSeconds=0.0)
|
||||
if $game_system && timeInSeconds>0.0 && $game_system.respond_to?("bgm_fade")
|
||||
$game_system.bgm_fade(timeInSeconds)
|
||||
return
|
||||
elsif $game_system && $game_system.respond_to?("bgm_stop")
|
||||
$game_system.bgm_stop
|
||||
return
|
||||
elsif (RPG.const_defined?(:BGM) rescue false)
|
||||
begin
|
||||
(timeInSeconds>0.0) ? RPG::BGM.fade((timeInSeconds*1000).floor) : RPG::BGM.stop
|
||||
return
|
||||
rescue
|
||||
end
|
||||
end
|
||||
(timeInSeconds>0.0) ? Audio.bgm_fade((timeInSeconds*1000).floor) : Audio.bgm_stop
|
||||
end
|
||||
|
||||
################################################################################
|
||||
|
||||
# Plays an ME file.
|
||||
# param -- Either a string showing the filename
|
||||
# (relative to Audio/ME/) or an RPG::AudioFile object.
|
||||
# Possible formats for _param_:
|
||||
# filename volume and pitch 100
|
||||
# filename:volume pitch 100
|
||||
# filename:volume:pitch
|
||||
# volume -- Volume of the file, up to 100
|
||||
# pitch -- Pitch of the file, normally 100
|
||||
def pbMEPlay(param,volume=nil,pitch=nil)
|
||||
return if !param
|
||||
param=pbResolveAudioFile(param,volume,pitch)
|
||||
if param.name && param.name!=""
|
||||
if $game_system && $game_system.respond_to?("me_play")
|
||||
$game_system.me_play(param)
|
||||
return
|
||||
elsif (RPG.const_defined?(:ME) rescue false)
|
||||
b=RPG::ME.new(param.name,param.volume,param.pitch)
|
||||
if b && b.respond_to?("play")
|
||||
b.play; return
|
||||
end
|
||||
end
|
||||
Audio.me_play(canonicalize("Audio/ME/"+param.name),param.volume,param.pitch)
|
||||
end
|
||||
end
|
||||
|
||||
# Fades out or stops ME playback. 'x' is the time in seconds to fade out.
|
||||
def pbMEFade(x=0.0); pbMEStop(x);end
|
||||
|
||||
# Fades out or stops ME playback. 'x' is the time in seconds to fade out.
|
||||
def pbMEStop(timeInSeconds=0.0)
|
||||
if $game_system && timeInSeconds>0.0 && $game_system.respond_to?("me_fade")
|
||||
$game_system.me_fade(timeInSeconds)
|
||||
return
|
||||
elsif $game_system && $game_system.respond_to?("me_stop")
|
||||
$game_system.me_stop(nil)
|
||||
return
|
||||
elsif (RPG.const_defined?(:ME) rescue false)
|
||||
begin
|
||||
(timeInSeconds>0.0) ? RPG::ME.fade((timeInSeconds*1000).floor) : RPG::ME.stop
|
||||
return
|
||||
rescue
|
||||
end
|
||||
end
|
||||
(timeInSeconds>0.0) ? Audio.me_fade((timeInSeconds*1000).floor) : Audio.me_stop
|
||||
end
|
||||
|
||||
################################################################################
|
||||
|
||||
# Plays a BGS file.
|
||||
# param -- Either a string showing the filename
|
||||
# (relative to Audio/BGS/) or an RPG::AudioFile object.
|
||||
# Possible formats for _param_:
|
||||
# filename volume and pitch 100
|
||||
# filename:volume pitch 100
|
||||
# filename:volume:pitch
|
||||
# volume -- Volume of the file, up to 100
|
||||
# pitch -- Pitch of the file, normally 100
|
||||
def pbBGSPlay(param,volume=nil,pitch=nil)
|
||||
return if !param
|
||||
param=pbResolveAudioFile(param,volume,pitch)
|
||||
if param.name && param.name!=""
|
||||
if $game_system && $game_system.respond_to?("bgs_play")
|
||||
$game_system.bgs_play(param)
|
||||
return
|
||||
elsif (RPG.const_defined?(:BGS) rescue false)
|
||||
b=RPG::BGS.new(param.name,param.volume,param.pitch)
|
||||
if b && b.respond_to?("play")
|
||||
b.play; return
|
||||
end
|
||||
end
|
||||
Audio.bgs_play(canonicalize("Audio/BGS/"+param.name),param.volume,param.pitch)
|
||||
end
|
||||
end
|
||||
|
||||
# Fades out or stops BGS playback. 'x' is the time in seconds to fade out.
|
||||
def pbBGSFade(x=0.0); pbBGSStop(x);end
|
||||
|
||||
# Fades out or stops BGS playback. 'x' is the time in seconds to fade out.
|
||||
def pbBGSStop(timeInSeconds=0.0)
|
||||
if $game_system && timeInSeconds>0.0 && $game_system.respond_to?("bgs_fade")
|
||||
$game_system.bgs_fade(timeInSeconds)
|
||||
return
|
||||
elsif $game_system && $game_system.respond_to?("bgs_play")
|
||||
$game_system.bgs_play(nil)
|
||||
return
|
||||
elsif (RPG.const_defined?(:BGS) rescue false)
|
||||
begin
|
||||
(timeInSeconds>0.0) ? RPG::BGS.fade((timeInSeconds*1000).floor) : RPG::BGS.stop
|
||||
return
|
||||
rescue
|
||||
end
|
||||
end
|
||||
(timeInSeconds>0.0) ? Audio.bgs_fade((timeInSeconds*1000).floor) : Audio.bgs_stop
|
||||
end
|
||||
|
||||
################################################################################
|
||||
|
||||
# Plays an SE file.
|
||||
# param -- Either a string showing the filename
|
||||
# (relative to Audio/SE/) or an RPG::AudioFile object.
|
||||
# Possible formats for _param_:
|
||||
# filename volume and pitch 100
|
||||
# filename:volume pitch 100
|
||||
# filename:volume:pitch
|
||||
# volume -- Volume of the file, up to 100
|
||||
# pitch -- Pitch of the file, normally 100
|
||||
def pbSEPlay(param,volume=nil,pitch=nil)
|
||||
return if !param
|
||||
param = pbResolveAudioFile(param,volume,pitch)
|
||||
if param.name && param.name!=""
|
||||
if $game_system && $game_system.respond_to?("se_play")
|
||||
$game_system.se_play(param)
|
||||
return
|
||||
end
|
||||
if (RPG.const_defined?(:SE) rescue false)
|
||||
b = RPG::SE.new(param.name,param.volume,param.pitch)
|
||||
if b && b.respond_to?("play")
|
||||
b.play
|
||||
return
|
||||
end
|
||||
end
|
||||
Audio.se_play(canonicalize("Audio/SE/"+param.name),param.volume,param.pitch)
|
||||
end
|
||||
end
|
||||
|
||||
# Stops SE playback.
|
||||
def pbSEFade(x=0.0); pbSEStop(x);end
|
||||
|
||||
# Stops SE playback.
|
||||
def pbSEStop(_timeInSeconds=0.0)
|
||||
if $game_system
|
||||
$game_system.se_stop
|
||||
elsif (RPG.const_defined?(:SE) rescue false)
|
||||
RPG::SE.stop rescue nil
|
||||
else
|
||||
Audio.se_stop
|
||||
end
|
||||
end
|
||||
|
||||
################################################################################
|
||||
|
||||
# Plays a sound effect that plays when the player moves the cursor.
|
||||
def pbPlayCursorSE
|
||||
if $data_system && $data_system.respond_to?("cursor_se") &&
|
||||
$data_system.cursor_se && $data_system.cursor_se.name!=""
|
||||
pbSEPlay($data_system.cursor_se)
|
||||
elsif $data_system && $data_system.respond_to?("sounds") &&
|
||||
$data_system.sounds && $data_system.sounds[0] && $data_system.sounds[0].name!=""
|
||||
pbSEPlay($data_system.sounds[0])
|
||||
elsif FileTest.audio_exist?("Audio/SE/GUI sel cursor")
|
||||
pbSEPlay("GUI sel cursor",80)
|
||||
end
|
||||
end
|
||||
|
||||
# Plays a sound effect that plays when a decision is confirmed or a choice is made.
|
||||
def pbPlayDecisionSE
|
||||
if $data_system && $data_system.respond_to?("decision_se") &&
|
||||
$data_system.decision_se && $data_system.decision_se.name!=""
|
||||
pbSEPlay($data_system.decision_se)
|
||||
elsif $data_system && $data_system.respond_to?("sounds") &&
|
||||
$data_system.sounds && $data_system.sounds[1] && $data_system.sounds[1].name!=""
|
||||
pbSEPlay($data_system.sounds[1])
|
||||
elsif FileTest.audio_exist?("Audio/SE/GUI sel decision")
|
||||
pbSEPlay("GUI sel decision",80)
|
||||
end
|
||||
end
|
||||
|
||||
# Plays a sound effect that plays when a choice is canceled.
|
||||
def pbPlayCancelSE
|
||||
if $data_system && $data_system.respond_to?("cancel_se") &&
|
||||
$data_system.cancel_se && $data_system.cancel_se.name!=""
|
||||
pbSEPlay($data_system.cancel_se)
|
||||
elsif $data_system && $data_system.respond_to?("sounds") &&
|
||||
$data_system.sounds && $data_system.sounds[2] && $data_system.sounds[2].name!=""
|
||||
pbSEPlay($data_system.sounds[2])
|
||||
elsif FileTest.audio_exist?("Audio/SE/GUI sel cancel")
|
||||
pbSEPlay("GUI sel cancel",80)
|
||||
end
|
||||
end
|
||||
|
||||
# Plays a buzzer sound effect.
|
||||
def pbPlayBuzzerSE
|
||||
if $data_system && $data_system.respond_to?("buzzer_se") &&
|
||||
$data_system.buzzer_se && $data_system.buzzer_se.name!=""
|
||||
pbSEPlay($data_system.buzzer_se)
|
||||
elsif $data_system && $data_system.respond_to?("sounds") &&
|
||||
$data_system.sounds && $data_system.sounds[3] && $data_system.sounds[3].name!=""
|
||||
pbSEPlay($data_system.sounds[3])
|
||||
elsif FileTest.audio_exist?("Audio/SE/GUI sel buzzer")
|
||||
pbSEPlay("GUI sel buzzer",80)
|
||||
end
|
||||
end
|
||||
|
||||
# Plays a sound effect that plays when the player moves the cursor.
|
||||
def pbPlayCloseMenuSE
|
||||
if FileTest.audio_exist?("Audio/SE/GUI menu close")
|
||||
pbSEPlay("GUI menu close",80)
|
||||
end
|
||||
end
|
||||
1627
Data/Scripts_backup/009_Scenes/001_Transitions.rb
Normal file
1627
Data/Scripts_backup/009_Scenes/001_Transitions.rb
Normal file
File diff suppressed because it is too large
Load Diff
198
Data/Scripts_backup/009_Scenes/002_EventScene.rb
Normal file
198
Data/Scripts_backup/009_Scenes/002_EventScene.rb
Normal file
@@ -0,0 +1,198 @@
|
||||
class PictureSprite < SpriteWrapper
|
||||
def initialize(viewport, picture)
|
||||
super(viewport)
|
||||
@picture = picture
|
||||
@pictureBitmap = nil
|
||||
@customBitmap = nil
|
||||
@customBitmapIsBitmap = true
|
||||
@hue = 0
|
||||
update
|
||||
end
|
||||
|
||||
def dispose
|
||||
@pictureBitmap.dispose if @pictureBitmap
|
||||
super
|
||||
end
|
||||
|
||||
# Doesn't free the bitmap
|
||||
def setCustomBitmap(bitmap)
|
||||
@customBitmap = bitmap
|
||||
@customBitmapIsBitmap = @customBitmap.is_a?(Bitmap)
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
@pictureBitmap.update if @pictureBitmap
|
||||
# If picture file name is different from current one
|
||||
if @customBitmap && @picture.name==""
|
||||
self.bitmap = (@customBitmapIsBitmap) ? @customBitmap : @customBitmap.bitmap
|
||||
elsif @picture_name != @picture.name || @picture.hue.to_i != @hue.to_i
|
||||
# Remember file name to instance variables
|
||||
@picture_name = @picture.name
|
||||
@hue = @picture.hue.to_i
|
||||
# If file name is not empty
|
||||
if @picture_name == ""
|
||||
@pictureBitmap.dispose if @pictureBitmap
|
||||
@pictureBitmap = nil
|
||||
self.visible = false
|
||||
return
|
||||
end
|
||||
# Get picture graphic
|
||||
@pictureBitmap.dispose if @pictureBitmap
|
||||
@pictureBitmap = AnimatedBitmap.new(@picture_name, @hue)
|
||||
self.bitmap = (@pictureBitmap) ? @pictureBitmap.bitmap : nil
|
||||
elsif @picture_name == ""
|
||||
# Set sprite to invisible
|
||||
self.visible = false
|
||||
return
|
||||
end
|
||||
setPictureSprite(self,@picture)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def pbTextBitmap(text, maxwidth=Graphics.width)
|
||||
tmp = Bitmap.new(maxwidth,Graphics.height)
|
||||
pbSetSystemFont(tmp)
|
||||
drawFormattedTextEx(tmp,0,0,maxwidth,text,Color.new(248,248,248),Color.new(168,184,184))
|
||||
return tmp
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# EventScene
|
||||
#===============================================================================
|
||||
class EventScene
|
||||
attr_accessor :onCTrigger,:onBTrigger,:onUpdate
|
||||
|
||||
def initialize(viewport=nil)
|
||||
@viewport = viewport
|
||||
@onCTrigger = Event.new
|
||||
@onBTrigger = Event.new
|
||||
@onUpdate = Event.new
|
||||
@pictures = []
|
||||
@picturesprites = []
|
||||
@usersprites = []
|
||||
@disposed = false
|
||||
end
|
||||
|
||||
def dispose
|
||||
return if disposed?
|
||||
for sprite in @picturesprites
|
||||
sprite.dispose
|
||||
end
|
||||
for sprite in @usersprites
|
||||
sprite.dispose
|
||||
end
|
||||
@onCTrigger.clear
|
||||
@onBTrigger.clear
|
||||
@onUpdate.clear
|
||||
@pictures.clear
|
||||
@picturesprites.clear
|
||||
@usersprites.clear
|
||||
@disposed = true
|
||||
end
|
||||
|
||||
def disposed?
|
||||
return @disposed
|
||||
end
|
||||
|
||||
def addBitmap(x, y, bitmap)
|
||||
# _bitmap_ can be a Bitmap or an AnimatedBitmap
|
||||
# (update method isn't called if it's animated)
|
||||
# EventScene doesn't take ownership of the passed-in bitmap
|
||||
num = @pictures.length
|
||||
picture = PictureEx.new(num)
|
||||
picture.setXY(0,x,y)
|
||||
picture.setVisible(0,true)
|
||||
@pictures[num] = picture
|
||||
@picturesprites[num] = PictureSprite.new(@viewport,picture)
|
||||
@picturesprites[num].setCustomBitmap(bitmap)
|
||||
return picture
|
||||
end
|
||||
|
||||
def addLabel(x, y, width, text)
|
||||
addBitmap(x,y,pbTextBitmap(text,width))
|
||||
end
|
||||
|
||||
def addImage(x, y, name)
|
||||
num = @pictures.length
|
||||
picture = PictureEx.new(num)
|
||||
picture.name = name
|
||||
picture.setXY(0,x,y)
|
||||
picture.setVisible(0,true)
|
||||
@pictures[num] = picture
|
||||
@picturesprites[num] = PictureSprite.new(@viewport,picture)
|
||||
return picture
|
||||
end
|
||||
|
||||
def addUserSprite(sprite)
|
||||
@usersprites.push(sprite)
|
||||
end
|
||||
|
||||
def getPicture(num)
|
||||
return @pictures[num]
|
||||
end
|
||||
|
||||
def wait(frames)
|
||||
frames.times { update }
|
||||
end
|
||||
|
||||
def pictureWait(extraframes=0)
|
||||
loop do
|
||||
hasRunning = false
|
||||
for pic in @pictures
|
||||
hasRunning = true if pic.running?
|
||||
end
|
||||
break if !hasRunning
|
||||
update
|
||||
end
|
||||
extraframes.times { update }
|
||||
end
|
||||
|
||||
def update
|
||||
return if disposed?
|
||||
Graphics.update
|
||||
Input.update
|
||||
for picture in @pictures
|
||||
picture.update
|
||||
end
|
||||
for sprite in @picturesprites
|
||||
sprite.update
|
||||
end
|
||||
for sprite in @usersprites
|
||||
next if !sprite || sprite.disposed? || !sprite.is_a?(Sprite)
|
||||
sprite.update
|
||||
end
|
||||
@onUpdate.trigger(self)
|
||||
if Input.trigger?(Input::BACK)
|
||||
@onBTrigger.trigger(self)
|
||||
elsif Input.trigger?(Input::USE)
|
||||
@onCTrigger.trigger(self)
|
||||
end
|
||||
end
|
||||
|
||||
def main
|
||||
while !disposed?
|
||||
update
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
def pbEventScreen(cls)
|
||||
pbFadeOutIn {
|
||||
viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
|
||||
viewport.z = 99999
|
||||
PBDebug.logonerr {
|
||||
cls.new(viewport).main
|
||||
}
|
||||
viewport.dispose
|
||||
}
|
||||
end
|
||||
229
Data/Scripts_backup/010_Data/001_GameData.rb
Normal file
229
Data/Scripts_backup/010_Data/001_GameData.rb
Normal file
@@ -0,0 +1,229 @@
|
||||
module GameData
|
||||
#=============================================================================
|
||||
# A mixin module for data classes which provides common class methods (called
|
||||
# by GameData::Thing.method) that provide access to data held within.
|
||||
# Assumes the data class's data is stored in a class constant hash called DATA.
|
||||
# For data that is known by a symbol or an ID number.
|
||||
#=============================================================================
|
||||
module ClassMethods
|
||||
def register(hash)
|
||||
self::DATA[hash[:id]] = self::DATA[hash[:id_number]] = self.new(hash)
|
||||
end
|
||||
|
||||
# @param other [Symbol, self, String, Integer]
|
||||
# @return [Boolean] whether the given other is defined as a self
|
||||
def exists?(other)
|
||||
return false if other.nil?
|
||||
validate other => [Symbol, self, String, Integer]
|
||||
other = other.id if other.is_a?(self)
|
||||
other = other.to_sym if other.is_a?(String)
|
||||
return !self::DATA[other].nil?
|
||||
end
|
||||
|
||||
# @param other [Symbol, self, String, Integer]
|
||||
# @return [self]
|
||||
def get(other)
|
||||
validate other => [Symbol, self, String, Integer]
|
||||
return other if other.is_a?(self)
|
||||
other = other.to_sym if other.is_a?(String)
|
||||
# if other.is_a?(Integer)
|
||||
# p "Please switch to symbols, thanks."
|
||||
# end
|
||||
raise "Unknown ID #{other}." unless self::DATA.has_key?(other)
|
||||
return self::DATA[other]
|
||||
end
|
||||
|
||||
# @param other [Symbol, self, String, Integer]
|
||||
# @return [self, nil]
|
||||
def try_get(other)
|
||||
return nil if other.nil?
|
||||
validate other => [Symbol, self, String, Integer]
|
||||
return other if other.is_a?(self)
|
||||
other = other.to_sym if other.is_a?(String)
|
||||
# if other.is_a?(Integer)
|
||||
# p "Please switch to symbols, thanks."
|
||||
# end
|
||||
return (self::DATA.has_key?(other)) ? self::DATA[other] : nil
|
||||
end
|
||||
|
||||
# Returns the array of keys for the data.
|
||||
# @return [Array]
|
||||
def keys
|
||||
return self::DATA.keys
|
||||
end
|
||||
|
||||
# Yields all data in order of their id_number.
|
||||
def each
|
||||
keys = self::DATA.keys.sort { |a, b| self::DATA[a].id_number <=> self::DATA[b].id_number }
|
||||
keys.each { |key| yield self::DATA[key] if !key.is_a?(Integer) }
|
||||
end
|
||||
|
||||
def load
|
||||
const_set(:DATA, load_data("Data/#{self::DATA_FILENAME}"))
|
||||
end
|
||||
|
||||
def save
|
||||
save_data(self::DATA, "Data/#{self::DATA_FILENAME}")
|
||||
end
|
||||
end
|
||||
|
||||
#=============================================================================
|
||||
# A mixin module for data classes which provides common class methods (called
|
||||
# by GameData::Thing.method) that provide access to data held within.
|
||||
# Assumes the data class's data is stored in a class constant hash called DATA.
|
||||
# For data that is only known by a symbol.
|
||||
#=============================================================================
|
||||
module ClassMethodsSymbols
|
||||
def register(hash)
|
||||
self::DATA[hash[:id]] = self.new(hash)
|
||||
end
|
||||
|
||||
# @param other [Symbol, self, String]
|
||||
# @return [Boolean] whether the given other is defined as a self
|
||||
def exists?(other)
|
||||
return false if other.nil?
|
||||
validate other => [Symbol, self, String]
|
||||
other = other.id if other.is_a?(self)
|
||||
other = other.to_sym if other.is_a?(String)
|
||||
return !self::DATA[other].nil?
|
||||
end
|
||||
|
||||
# @param other [Symbol, self, String]
|
||||
# @return [self]
|
||||
def get(other)
|
||||
validate other => [Symbol, self, String]
|
||||
return other if other.is_a?(self)
|
||||
other = other.to_sym if other.is_a?(String)
|
||||
raise "Unknown ID #{other}." unless self::DATA.has_key?(other)
|
||||
return self::DATA[other]
|
||||
end
|
||||
|
||||
# @param other [Symbol, self, String]
|
||||
# @return [self, nil]
|
||||
def try_get(other)
|
||||
return nil if other.nil?
|
||||
validate other => [Symbol, self, String]
|
||||
return other if other.is_a?(self)
|
||||
other = other.to_sym if other.is_a?(String)
|
||||
return (self::DATA.has_key?(other)) ? self::DATA[other] : nil
|
||||
end
|
||||
|
||||
# Returns the array of keys for the data.
|
||||
# @return [Array]
|
||||
def keys
|
||||
return self::DATA.keys
|
||||
end
|
||||
|
||||
# Yields all data in alphabetical order.
|
||||
def each
|
||||
keys = self::DATA.keys.sort { |a, b| self::DATA[a].real_name <=> self::DATA[b].real_name }
|
||||
keys.each { |key| yield self::DATA[key] }
|
||||
end
|
||||
|
||||
def load
|
||||
const_set(:DATA, load_data("Data/#{self::DATA_FILENAME}"))
|
||||
end
|
||||
|
||||
def save
|
||||
save_data(self::DATA, "Data/#{self::DATA_FILENAME}")
|
||||
end
|
||||
end
|
||||
|
||||
#=============================================================================
|
||||
# A mixin module for data classes which provides common class methods (called
|
||||
# by GameData::Thing.method) that provide access to data held within.
|
||||
# Assumes the data class's data is stored in a class constant hash called DATA.
|
||||
# For data that is only known by an ID number.
|
||||
#=============================================================================
|
||||
module ClassMethodsIDNumbers
|
||||
def register(hash)
|
||||
self::DATA[hash[:id]] = self.new(hash)
|
||||
end
|
||||
|
||||
# @param other [self, Integer]
|
||||
# @return [Boolean] whether the given other is defined as a self
|
||||
def exists?(other)
|
||||
return false if other.nil?
|
||||
validate other => [self, Integer]
|
||||
other = other.id if other.is_a?(self)
|
||||
return !self::DATA[other].nil?
|
||||
end
|
||||
|
||||
# @param other [self, Integer]
|
||||
# @return [self]
|
||||
def get(other)
|
||||
validate other => [self, Integer]
|
||||
return other if other.is_a?(self)
|
||||
raise "Unknown ID #{other}." unless self::DATA.has_key?(other)
|
||||
return self::DATA[other]
|
||||
end
|
||||
|
||||
def try_get(other)
|
||||
return nil if other.nil?
|
||||
validate other => [self, Integer]
|
||||
return other if other.is_a?(self)
|
||||
return (self::DATA.has_key?(other)) ? self::DATA[other] : nil
|
||||
end
|
||||
|
||||
# Returns the array of keys for the data.
|
||||
# @return [Array]
|
||||
def keys
|
||||
return self::DATA.keys
|
||||
end
|
||||
|
||||
# Yields all data in numberical order.
|
||||
def each
|
||||
keys = self::DATA.keys.sort
|
||||
keys.each { |key| yield self::DATA[key] }
|
||||
end
|
||||
|
||||
def load
|
||||
const_set(:DATA, load_data("Data/#{self::DATA_FILENAME}"))
|
||||
end
|
||||
|
||||
def save
|
||||
save_data(self::DATA, "Data/#{self::DATA_FILENAME}")
|
||||
end
|
||||
end
|
||||
|
||||
#=============================================================================
|
||||
# A mixin module for data classes which provides common instance methods
|
||||
# (called by thing.method) that analyse the data of a particular thing which
|
||||
# the instance represents.
|
||||
#=============================================================================
|
||||
module InstanceMethods
|
||||
# @param other [Symbol, self.class, String, Integer]
|
||||
# @return [Boolean] whether other represents the same thing as this thing
|
||||
def ==(other)
|
||||
return false if other.nil?
|
||||
if other.is_a?(Symbol)
|
||||
return @id == other
|
||||
elsif other.is_a?(self.class)
|
||||
return @id == other.id
|
||||
elsif other.is_a?(String)
|
||||
return @id_number == other.to_sym
|
||||
elsif other.is_a?(Integer)
|
||||
return @id_number == other
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
#=============================================================================
|
||||
# A bulk loader method for all data stored in .dat files in the Data folder.
|
||||
#=============================================================================
|
||||
def self.load_all
|
||||
Type.load
|
||||
Ability.load
|
||||
Move.load
|
||||
Item.load
|
||||
BerryPlant.load
|
||||
Species.load
|
||||
Ribbon.load
|
||||
Encounter.load
|
||||
TrainerType.load
|
||||
Trainer.load
|
||||
Metadata.load
|
||||
MapMetadata.load
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,190 @@
|
||||
module GameData
|
||||
class GrowthRate
|
||||
attr_reader :id
|
||||
attr_reader :real_name
|
||||
attr_reader :exp_values
|
||||
attr_reader :exp_formula
|
||||
|
||||
DATA = {}
|
||||
|
||||
extend ClassMethodsSymbols
|
||||
include InstanceMethods
|
||||
|
||||
def self.load; end
|
||||
def self.save; end
|
||||
|
||||
# Calculates the maximum level a Pokémon can attain. This can vary during a
|
||||
# game, and here is where you would make it do so. Note that this method is
|
||||
# called by the Compiler, which happens before anything (e.g. Game Switches/
|
||||
# Variables, the player's data) is loaded, so code in this method should
|
||||
# check whether the needed variables exist before using them; if they don't,
|
||||
# this method should return the maximum possible level ever.
|
||||
# @return [Integer] the maximum level attainable by a Pokémon
|
||||
def self.max_level
|
||||
return Settings::MAXIMUM_LEVEL
|
||||
end
|
||||
|
||||
def initialize(hash)
|
||||
@id = hash[:id]
|
||||
@real_name = hash[:name] || "Unnamed"
|
||||
@exp_values = hash[:exp_values]
|
||||
@exp_formula = hash[:exp_formula]
|
||||
end
|
||||
|
||||
# @return [String] the translated name of this growth rate
|
||||
def name
|
||||
return _INTL(@real_name)
|
||||
end
|
||||
|
||||
# @param level [Integer] a level number
|
||||
# @return [Integer] the minimum Exp needed to be at the given level
|
||||
def minimum_exp_for_level(level)
|
||||
return ArgumentError.new("Level #{level} is invalid.") if !level || level <= 0
|
||||
level = [level, GrowthRate.max_level].min
|
||||
return @exp_values[level] if level < @exp_values.length
|
||||
raise "No Exp formula is defined for growth rate #{name}" if !@exp_formula
|
||||
return @exp_formula.call(level)
|
||||
end
|
||||
|
||||
# @return [Integer] the maximum Exp a Pokémon with this growth rate can have
|
||||
def maximum_exp
|
||||
return minimum_exp_for_level(GrowthRate.max_level)
|
||||
end
|
||||
|
||||
# @param exp1 [Integer] an Exp amount
|
||||
# @param exp2 [Integer] an Exp amount
|
||||
# @return [Integer] the sum of the two given Exp amounts
|
||||
def add_exp(exp1, exp2)
|
||||
return (exp1 + exp2).clamp(0, maximum_exp)
|
||||
end
|
||||
|
||||
# @param exp [Integer] an Exp amount
|
||||
# @return [Integer] the level of a Pokémon that has the given Exp amount
|
||||
def level_from_exp(exp)
|
||||
return ArgumentError.new("Exp amount #{level} is invalid.") if !exp || exp < 0
|
||||
max = GrowthRate.max_level
|
||||
return max if exp >= maximum_exp
|
||||
for level in 1..max
|
||||
return level - 1 if exp < minimum_exp_for_level(level)
|
||||
end
|
||||
return max
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
|
||||
GameData::GrowthRate.register({
|
||||
:id => :Medium, # Also known as Medium Fast
|
||||
:name => _INTL("Medium"),
|
||||
:exp_values => [-1,
|
||||
0, 8, 27, 64, 125, 216, 343, 512, 729, 1000,
|
||||
1331, 1728, 2197, 2744, 3375, 4096, 4913, 5832, 6859, 8000,
|
||||
9261, 10648, 12167, 13824, 15625, 17576, 19683, 21952, 24389, 27000,
|
||||
29791, 32768, 35937, 39304, 42875, 46656, 50653, 54872, 59319, 64000,
|
||||
68921, 74088, 79507, 85184, 91125, 97336, 103823, 110592, 117649, 125000,
|
||||
132651, 140608, 148877, 157464, 166375, 175616, 185193, 195112, 205379, 216000,
|
||||
226981, 238328, 250047, 262144, 274625, 287496, 300763, 314432, 328509, 343000,
|
||||
357911, 373248, 389017, 405224, 421875, 438976, 456533, 474552, 493039, 512000,
|
||||
531441, 551368, 571787, 592704, 614125, 636056, 658503, 681472, 704969, 729000,
|
||||
753571, 778688, 804357, 830584, 857375, 884736, 912673, 941192, 970299, 1000000],
|
||||
:exp_formula => proc { |level| next level ** 3 }
|
||||
})
|
||||
|
||||
# Erratic (600000):
|
||||
# For levels 0-50: n**3 * (100 - n) / 50
|
||||
# For levels 51-68: n**3 * (150 - n) / 100
|
||||
# For levels 69-98: n**3 * 1.274 - (n / 150) - p(n mod 3)
|
||||
# where p(x) = array(0.000, 0.008, 0.014)[x]
|
||||
# For levels 99-100: n**3 * (160 - n) / 100
|
||||
GameData::GrowthRate.register({
|
||||
:id => :Erratic,
|
||||
:name => _INTL("Erratic"),
|
||||
:exp_values => [-1,
|
||||
0, 15, 52, 122, 237, 406, 637, 942, 1326, 1800,
|
||||
2369, 3041, 3822, 4719, 5737, 6881, 8155, 9564, 11111, 12800,
|
||||
14632, 16610, 18737, 21012, 23437, 26012, 28737, 31610, 34632, 37800,
|
||||
41111, 44564, 48155, 51881, 55737, 59719, 63822, 68041, 72369, 76800,
|
||||
81326, 85942, 90637, 95406, 100237, 105122, 110052, 115015, 120001, 125000,
|
||||
131324, 137795, 144410, 151165, 158056, 165079, 172229, 179503, 186894, 194400,
|
||||
202013, 209728, 217540, 225443, 233431, 241496, 249633, 257834, 267406, 276458,
|
||||
286328, 296358, 305767, 316074, 326531, 336255, 346965, 357812, 367807, 378880,
|
||||
390077, 400293, 411686, 423190, 433572, 445239, 457001, 467489, 479378, 491346,
|
||||
501878, 513934, 526049, 536557, 548720, 560922, 571333, 583539, 591882, 600000],
|
||||
:exp_formula => proc { |level| next (level ** 4) * 3 / 500 }
|
||||
})
|
||||
|
||||
# Fluctuating (1640000):
|
||||
# For levels 0-15 : n**3 * (24 + ((n + 1) / 3)) / 50
|
||||
# For levels 16-35: n**3 * (14 + n) / 50
|
||||
# For levels 36-100: n**3 * (32 + (n / 2)) / 50
|
||||
GameData::GrowthRate.register({
|
||||
:id => :Fluctuating,
|
||||
:name => _INTL("Fluctuating"),
|
||||
:exp_values => [-1,
|
||||
0, 4, 13, 32, 65, 112, 178, 276, 393, 540,
|
||||
745, 967, 1230, 1591, 1957, 2457, 3046, 3732, 4526, 5440,
|
||||
6482, 7666, 9003, 10506, 12187, 14060, 16140, 18439, 20974, 23760,
|
||||
26811, 30146, 33780, 37731, 42017, 46656, 50653, 55969, 60505, 66560,
|
||||
71677, 78533, 84277, 91998, 98415, 107069, 114205, 123863, 131766, 142500,
|
||||
151222, 163105, 172697, 185807, 196322, 210739, 222231, 238036, 250562, 267840,
|
||||
281456, 300293, 315059, 335544, 351520, 373744, 390991, 415050, 433631, 459620,
|
||||
479600, 507617, 529063, 559209, 582187, 614566, 639146, 673863, 700115, 737280,
|
||||
765275, 804997, 834809, 877201, 908905, 954084, 987754, 1035837, 1071552, 1122660,
|
||||
1160499, 1214753, 1254796, 1312322, 1354652, 1415577, 1460276, 1524731, 1571884, 1640000],
|
||||
:exp_formula => proc { |level|
|
||||
rate = [82 - (level - 100) / 2.0, 40].max
|
||||
next (level ** 4) * rate / 5000
|
||||
}
|
||||
})
|
||||
|
||||
GameData::GrowthRate.register({
|
||||
:id => :Parabolic, # Also known as Medium Slow
|
||||
:name => _INTL("Parabolic"),
|
||||
:exp_values => [-1,
|
||||
0, 9, 57, 96, 135, 179, 236, 314, 419, 560,
|
||||
742, 973, 1261, 1612, 2035, 2535, 3120, 3798, 4575, 5460,
|
||||
6458, 7577, 8825, 10208, 11735, 13411, 15244, 17242, 19411, 21760,
|
||||
24294, 27021, 29949, 33084, 36435, 40007, 43808, 47846, 52127, 56660,
|
||||
61450, 66505, 71833, 77440, 83335, 89523, 96012, 102810, 109923, 117360,
|
||||
125126, 133229, 141677, 150476, 159635, 169159, 179056, 189334, 199999, 211060,
|
||||
222522, 234393, 246681, 259392, 272535, 286115, 300140, 314618, 329555, 344960,
|
||||
360838, 377197, 394045, 411388, 429235, 447591, 466464, 485862, 505791, 526260,
|
||||
547274, 568841, 590969, 613664, 636935, 660787, 685228, 710266, 735907, 762160,
|
||||
789030, 816525, 844653, 873420, 902835, 932903, 963632, 995030, 1027103, 1059860],
|
||||
:exp_formula => proc { |level| next ((level ** 3) * 6 / 5) - 15 * (level ** 2) + 100 * level - 140 }
|
||||
})
|
||||
|
||||
GameData::GrowthRate.register({
|
||||
:id => :Fast,
|
||||
:name => _INTL("Fast"),
|
||||
:exp_values => [-1,
|
||||
0, 6, 21, 51, 100, 172, 274, 409, 583, 800,
|
||||
1064, 1382, 1757, 2195, 2700, 3276, 3930, 4665, 5487, 6400,
|
||||
7408, 8518, 9733, 11059, 12500, 14060, 15746, 17561, 19511, 21600,
|
||||
23832, 26214, 28749, 31443, 34300, 37324, 40522, 43897, 47455, 51200,
|
||||
55136, 59270, 63605, 68147, 72900, 77868, 83058, 88473, 94119, 100000,
|
||||
106120, 112486, 119101, 125971, 133100, 140492, 148154, 156089, 164303, 172800,
|
||||
181584, 190662, 200037, 209715, 219700, 229996, 240610, 251545, 262807, 274400,
|
||||
286328, 298598, 311213, 324179, 337500, 351180, 365226, 379641, 394431, 409600,
|
||||
425152, 441094, 457429, 474163, 491300, 508844, 526802, 545177, 563975, 583200,
|
||||
602856, 622950, 643485, 664467, 685900, 707788, 730138, 752953, 776239, 800000],
|
||||
:exp_formula => proc { |level| (level ** 3) * 4 / 5 }
|
||||
})
|
||||
|
||||
GameData::GrowthRate.register({
|
||||
:id => :Slow,
|
||||
:name => _INTL("Slow"),
|
||||
:exp_values => [-1,
|
||||
0, 10, 33, 80, 156, 270, 428, 640, 911, 1250,
|
||||
1663, 2160, 2746, 3430, 4218, 5120, 6141, 7290, 8573, 10000,
|
||||
11576, 13310, 15208, 17280, 19531, 21970, 24603, 27440, 30486, 33750,
|
||||
37238, 40960, 44921, 49130, 53593, 58320, 63316, 68590, 74148, 80000,
|
||||
86151, 92610, 99383, 106480, 113906, 121670, 129778, 138240, 147061, 156250,
|
||||
165813, 175760, 186096, 196830, 207968, 219520, 231491, 243890, 256723, 270000,
|
||||
283726, 297910, 312558, 327680, 343281, 359370, 375953, 393040, 410636, 428750,
|
||||
447388, 466560, 486271, 506530, 527343, 548720, 570666, 593190, 616298, 640000,
|
||||
664301, 689210, 714733, 740880, 767656, 795070, 823128, 851840, 881211, 911250,
|
||||
941963, 973360, 1005446, 1038230, 1071718, 1105920, 1140841, 1176490, 1212873, 1250000],
|
||||
:exp_formula => proc { |level| (level ** 3) * 5 / 4 }
|
||||
})
|
||||
@@ -0,0 +1,77 @@
|
||||
# If a Pokémon's gender ratio is none of :AlwaysMale, :AlwaysFemale or
|
||||
# :Genderless, then it will choose a random number between 0 and 255 inclusive,
|
||||
# and compare it to the @female_chance. If the random number is lower than this
|
||||
# chance, it will be female; otherwise, it will be male.
|
||||
module GameData
|
||||
class GenderRatio
|
||||
attr_reader :id
|
||||
attr_reader :real_name
|
||||
attr_reader :female_chance
|
||||
|
||||
DATA = {}
|
||||
|
||||
extend ClassMethodsSymbols
|
||||
include InstanceMethods
|
||||
|
||||
def self.load; end
|
||||
def self.save; end
|
||||
|
||||
def initialize(hash)
|
||||
@id = hash[:id]
|
||||
@real_name = hash[:name] || "Unnamed"
|
||||
@female_chance = hash[:female_chance]
|
||||
end
|
||||
|
||||
# @return [String] the translated name of this gender ratio
|
||||
def name
|
||||
return _INTL(@real_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
|
||||
GameData::GenderRatio.register({
|
||||
:id => :AlwaysMale,
|
||||
:name => _INTL("Always Male")
|
||||
})
|
||||
|
||||
GameData::GenderRatio.register({
|
||||
:id => :AlwaysFemale,
|
||||
:name => _INTL("Always Female")
|
||||
})
|
||||
|
||||
GameData::GenderRatio.register({
|
||||
:id => :Genderless,
|
||||
:name => _INTL("Genderless")
|
||||
})
|
||||
|
||||
GameData::GenderRatio.register({
|
||||
:id => :FemaleOneEighth,
|
||||
:name => _INTL("Female One Eighth"),
|
||||
:female_chance => 32
|
||||
})
|
||||
|
||||
GameData::GenderRatio.register({
|
||||
:id => :Female25Percent,
|
||||
:name => _INTL("Female 25 Percent"),
|
||||
:female_chance => 64
|
||||
})
|
||||
|
||||
GameData::GenderRatio.register({
|
||||
:id => :Female50Percent,
|
||||
:name => _INTL("Female 50 Percent"),
|
||||
:female_chance => 128
|
||||
})
|
||||
|
||||
GameData::GenderRatio.register({
|
||||
:id => :Female75Percent,
|
||||
:name => _INTL("Female 75 Percent"),
|
||||
:female_chance => 192
|
||||
})
|
||||
|
||||
GameData::GenderRatio.register({
|
||||
:id => :FemaleSevenEighths,
|
||||
:name => _INTL("Female Seven Eighths"),
|
||||
:female_chance => 224
|
||||
})
|
||||
101
Data/Scripts_backup/010_Data/001_Hardcoded data/003_EggGroup.rb
Normal file
101
Data/Scripts_backup/010_Data/001_Hardcoded data/003_EggGroup.rb
Normal file
@@ -0,0 +1,101 @@
|
||||
module GameData
|
||||
class EggGroup
|
||||
attr_reader :id
|
||||
attr_reader :real_name
|
||||
|
||||
DATA = {}
|
||||
|
||||
extend ClassMethodsSymbols
|
||||
include InstanceMethods
|
||||
|
||||
def self.load; end
|
||||
def self.save; end
|
||||
|
||||
def initialize(hash)
|
||||
@id = hash[:id]
|
||||
@real_name = hash[:name] || "Unnamed"
|
||||
end
|
||||
|
||||
# @return [String] the translated name of this egg group
|
||||
def name
|
||||
return _INTL(@real_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
|
||||
GameData::EggGroup.register({
|
||||
:id => :Undiscovered,
|
||||
:name => _INTL("Undiscovered")
|
||||
})
|
||||
|
||||
GameData::EggGroup.register({
|
||||
:id => :Monster,
|
||||
:name => _INTL("Monster")
|
||||
})
|
||||
|
||||
GameData::EggGroup.register({
|
||||
:id => :Water1,
|
||||
:name => _INTL("Water 1")
|
||||
})
|
||||
|
||||
GameData::EggGroup.register({
|
||||
:id => :Bug,
|
||||
:name => _INTL("Bug")
|
||||
})
|
||||
|
||||
GameData::EggGroup.register({
|
||||
:id => :Flying,
|
||||
:name => _INTL("Flying")
|
||||
})
|
||||
|
||||
GameData::EggGroup.register({
|
||||
:id => :Field,
|
||||
:name => _INTL("Field")
|
||||
})
|
||||
|
||||
GameData::EggGroup.register({
|
||||
:id => :Fairy,
|
||||
:name => _INTL("Fairy")
|
||||
})
|
||||
|
||||
GameData::EggGroup.register({
|
||||
:id => :Grass,
|
||||
:name => _INTL("Grass")
|
||||
})
|
||||
|
||||
GameData::EggGroup.register({
|
||||
:id => :Humanlike,
|
||||
:name => _INTL("Humanlike")
|
||||
})
|
||||
|
||||
GameData::EggGroup.register({
|
||||
:id => :Water3,
|
||||
:name => _INTL("Water 3")
|
||||
})
|
||||
|
||||
GameData::EggGroup.register({
|
||||
:id => :Mineral,
|
||||
:name => _INTL("Mineral")
|
||||
})
|
||||
|
||||
GameData::EggGroup.register({
|
||||
:id => :Amorphous,
|
||||
:name => _INTL("Amorphous")
|
||||
})
|
||||
|
||||
GameData::EggGroup.register({
|
||||
:id => :Water2,
|
||||
:name => _INTL("Water 2")
|
||||
})
|
||||
|
||||
GameData::EggGroup.register({
|
||||
:id => :Ditto,
|
||||
:name => _INTL("Ditto")
|
||||
})
|
||||
|
||||
GameData::EggGroup.register({
|
||||
:id => :Dragon,
|
||||
:name => _INTL("Dragon")
|
||||
})
|
||||
117
Data/Scripts_backup/010_Data/001_Hardcoded data/004_BodyShape.rb
Normal file
117
Data/Scripts_backup/010_Data/001_Hardcoded data/004_BodyShape.rb
Normal file
@@ -0,0 +1,117 @@
|
||||
# NOTE: The id_number is only used to determine the order that body shapes are
|
||||
# listed in the Pokédex search screen. Number 0 (:None) is ignored; they
|
||||
# start with shape 1.
|
||||
# "Graphics/Pictures/Pokedex/icon_shapes.png" contains icons for these
|
||||
# shapes.
|
||||
module GameData
|
||||
class BodyShape
|
||||
attr_reader :id
|
||||
attr_reader :id_number
|
||||
attr_reader :real_name
|
||||
|
||||
DATA = {}
|
||||
|
||||
extend ClassMethods
|
||||
include InstanceMethods
|
||||
|
||||
def self.load; end
|
||||
def self.save; end
|
||||
|
||||
def initialize(hash)
|
||||
@id = hash[:id]
|
||||
@id_number = hash[:id_number] || -1
|
||||
@real_name = hash[:name] || "Unnamed"
|
||||
end
|
||||
|
||||
# @return [String] the translated name of this body shape
|
||||
def name
|
||||
return _INTL(@real_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
|
||||
GameData::BodyShape.register({
|
||||
:id => :Head,
|
||||
:id_number => 1,
|
||||
:name => _INTL("Head")
|
||||
})
|
||||
|
||||
GameData::BodyShape.register({
|
||||
:id => :Serpentine,
|
||||
:id_number => 2,
|
||||
:name => _INTL("Serpentine")
|
||||
})
|
||||
|
||||
GameData::BodyShape.register({
|
||||
:id => :Finned,
|
||||
:id_number => 3,
|
||||
:name => _INTL("Finned")
|
||||
})
|
||||
|
||||
GameData::BodyShape.register({
|
||||
:id => :HeadArms,
|
||||
:id_number => 4,
|
||||
:name => _INTL("Head and arms")
|
||||
})
|
||||
|
||||
GameData::BodyShape.register({
|
||||
:id => :HeadBase,
|
||||
:id_number => 5,
|
||||
:name => _INTL("Head and base")
|
||||
})
|
||||
|
||||
GameData::BodyShape.register({
|
||||
:id => :BipedalTail,
|
||||
:id_number => 6,
|
||||
:name => _INTL("Bipedal with tail")
|
||||
})
|
||||
|
||||
GameData::BodyShape.register({
|
||||
:id => :HeadLegs,
|
||||
:id_number => 7,
|
||||
:name => _INTL("Head and legs")
|
||||
})
|
||||
|
||||
GameData::BodyShape.register({
|
||||
:id => :Quadruped,
|
||||
:id_number => 8,
|
||||
:name => _INTL("Quadruped")
|
||||
})
|
||||
|
||||
GameData::BodyShape.register({
|
||||
:id => :Winged,
|
||||
:id_number => 9,
|
||||
:name => _INTL("Winged")
|
||||
})
|
||||
|
||||
GameData::BodyShape.register({
|
||||
:id => :Multiped,
|
||||
:id_number => 10,
|
||||
:name => _INTL("Multiped")
|
||||
})
|
||||
|
||||
GameData::BodyShape.register({
|
||||
:id => :MultiBody,
|
||||
:id_number => 11,
|
||||
:name => _INTL("Multi Body")
|
||||
})
|
||||
|
||||
GameData::BodyShape.register({
|
||||
:id => :Bipedal,
|
||||
:id_number => 12,
|
||||
:name => _INTL("Bipedal")
|
||||
})
|
||||
|
||||
GameData::BodyShape.register({
|
||||
:id => :MultiWinged,
|
||||
:id_number => 13,
|
||||
:name => _INTL("Multi Winged")
|
||||
})
|
||||
|
||||
GameData::BodyShape.register({
|
||||
:id => :Insectoid,
|
||||
:id_number => 14,
|
||||
:name => _INTL("Insectoid")
|
||||
})
|
||||
@@ -0,0 +1,90 @@
|
||||
# NOTE: The id_number is only used to determine the order that body colors are
|
||||
# listed in the Pokédex search screen.
|
||||
module GameData
|
||||
class BodyColor
|
||||
attr_reader :id
|
||||
attr_reader :id_number
|
||||
attr_reader :real_name
|
||||
|
||||
DATA = {}
|
||||
|
||||
extend ClassMethods
|
||||
include InstanceMethods
|
||||
|
||||
def self.load; end
|
||||
def self.save; end
|
||||
|
||||
def initialize(hash)
|
||||
@id = hash[:id]
|
||||
@id_number = hash[:id_number] || -1
|
||||
@real_name = hash[:name] || "Unnamed"
|
||||
end
|
||||
|
||||
# @return [String] the translated name of this body color
|
||||
def name
|
||||
return _INTL(@real_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
|
||||
GameData::BodyColor.register({
|
||||
:id => :Red,
|
||||
:id_number => 0,
|
||||
:name => _INTL("Red")
|
||||
})
|
||||
|
||||
GameData::BodyColor.register({
|
||||
:id => :Blue,
|
||||
:id_number => 1,
|
||||
:name => _INTL("Blue")
|
||||
})
|
||||
|
||||
GameData::BodyColor.register({
|
||||
:id => :Yellow,
|
||||
:id_number => 2,
|
||||
:name => _INTL("Yellow")
|
||||
})
|
||||
|
||||
GameData::BodyColor.register({
|
||||
:id => :Green,
|
||||
:id_number => 3,
|
||||
:name => _INTL("Green")
|
||||
})
|
||||
|
||||
GameData::BodyColor.register({
|
||||
:id => :Black,
|
||||
:id_number => 4,
|
||||
:name => _INTL("Black")
|
||||
})
|
||||
|
||||
GameData::BodyColor.register({
|
||||
:id => :Brown,
|
||||
:id_number => 5,
|
||||
:name => _INTL("Brown")
|
||||
})
|
||||
|
||||
GameData::BodyColor.register({
|
||||
:id => :Purple,
|
||||
:id_number => 6,
|
||||
:name => _INTL("Purple")
|
||||
})
|
||||
|
||||
GameData::BodyColor.register({
|
||||
:id => :Gray,
|
||||
:id_number => 7,
|
||||
:name => _INTL("Gray")
|
||||
})
|
||||
|
||||
GameData::BodyColor.register({
|
||||
:id => :White,
|
||||
:id_number => 8,
|
||||
:name => _INTL("White")
|
||||
})
|
||||
|
||||
GameData::BodyColor.register({
|
||||
:id => :Pink,
|
||||
:id_number => 9,
|
||||
:name => _INTL("Pink")
|
||||
})
|
||||
@@ -0,0 +1,76 @@
|
||||
module GameData
|
||||
class Habitat
|
||||
attr_reader :id
|
||||
attr_reader :real_name
|
||||
|
||||
DATA = {}
|
||||
|
||||
extend ClassMethodsSymbols
|
||||
include InstanceMethods
|
||||
|
||||
def self.load; end
|
||||
def self.save; end
|
||||
|
||||
def initialize(hash)
|
||||
@id = hash[:id]
|
||||
@real_name = hash[:name] || "Unnamed"
|
||||
end
|
||||
|
||||
# @return [String] the translated name of this habitat
|
||||
def name
|
||||
return _INTL(@real_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
|
||||
GameData::Habitat.register({
|
||||
:id => :None,
|
||||
:name => _INTL("None")
|
||||
})
|
||||
|
||||
GameData::Habitat.register({
|
||||
:id => :Grassland,
|
||||
:name => _INTL("Grassland")
|
||||
})
|
||||
|
||||
GameData::Habitat.register({
|
||||
:id => :Forest,
|
||||
:name => _INTL("Forest")
|
||||
})
|
||||
|
||||
GameData::Habitat.register({
|
||||
:id => :WatersEdge,
|
||||
:name => _INTL("Water's Edge")
|
||||
})
|
||||
|
||||
GameData::Habitat.register({
|
||||
:id => :Sea,
|
||||
:name => _INTL("Sea")
|
||||
})
|
||||
|
||||
GameData::Habitat.register({
|
||||
:id => :Cave,
|
||||
:name => _INTL("Cave")
|
||||
})
|
||||
|
||||
GameData::Habitat.register({
|
||||
:id => :Mountain,
|
||||
:name => _INTL("Mountain")
|
||||
})
|
||||
|
||||
GameData::Habitat.register({
|
||||
:id => :RoughTerrain,
|
||||
:name => _INTL("Rough Terrain")
|
||||
})
|
||||
|
||||
GameData::Habitat.register({
|
||||
:id => :Urban,
|
||||
:name => _INTL("Urban")
|
||||
})
|
||||
|
||||
GameData::Habitat.register({
|
||||
:id => :Rare,
|
||||
:name => _INTL("Rare")
|
||||
})
|
||||
599
Data/Scripts_backup/010_Data/001_Hardcoded data/007_Evolution.rb
Normal file
599
Data/Scripts_backup/010_Data/001_Hardcoded data/007_Evolution.rb
Normal file
@@ -0,0 +1,599 @@
|
||||
module GameData
|
||||
class Evolution
|
||||
attr_reader :id
|
||||
attr_reader :real_name
|
||||
attr_reader :parameter
|
||||
attr_reader :minimum_level # 0 means parameter is the minimum level
|
||||
attr_reader :level_up_proc
|
||||
attr_reader :use_item_proc
|
||||
attr_reader :on_trade_proc
|
||||
attr_reader :after_evolution_proc
|
||||
|
||||
DATA = {}
|
||||
|
||||
extend ClassMethodsSymbols
|
||||
include InstanceMethods
|
||||
|
||||
def self.load; end
|
||||
def self.save; end
|
||||
|
||||
def initialize(hash)
|
||||
@id = hash[:id]
|
||||
@real_name = hash[:id].to_s || "Unnamed"
|
||||
@parameter = hash[:parameter]
|
||||
@minimum_level = hash[:minimum_level] || 0
|
||||
@level_up_proc = hash[:level_up_proc]
|
||||
@use_item_proc = hash[:use_item_proc]
|
||||
@on_trade_proc = hash[:on_trade_proc]
|
||||
@after_evolution_proc = hash[:after_evolution_proc]
|
||||
end
|
||||
|
||||
def call_level_up(*args)
|
||||
return (@level_up_proc) ? @level_up_proc.call(*args) : nil
|
||||
end
|
||||
|
||||
def call_use_item(*args)
|
||||
return (@use_item_proc) ? @use_item_proc.call(*args) : nil
|
||||
end
|
||||
|
||||
def call_on_trade(*args)
|
||||
return (@on_trade_proc) ? @on_trade_proc.call(*args) : nil
|
||||
end
|
||||
|
||||
def call_after_evolution(*args)
|
||||
@after_evolution_proc.call(*args) if @after_evolution_proc
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :None
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :Level,
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.level >= parameter
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :LevelMale,
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.level >= parameter && pkmn.male?
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :LevelFemale,
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.level >= parameter && pkmn.female?
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :LevelDay,
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.level >= parameter && PBDayNight.isDay?
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :LevelNight,
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.level >= parameter && PBDayNight.isNight?
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :LevelMorning,
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.level >= parameter && PBDayNight.isMorning?
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :LevelAfternoon,
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.level >= parameter && PBDayNight.isAfternoon?
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :LevelEvening,
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.level >= parameter && PBDayNight.isEvening?
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :LevelNoWeather,
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.level >= parameter && $game_screen && $game_screen.weather_type == :None
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :LevelSun,
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.level >= parameter && $game_screen &&
|
||||
GameData::Weather.get($game_screen.weather_type).category == :Sun
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :LevelRain,
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.level >= parameter && $game_screen &&
|
||||
[:Rain, :Fog].include?(GameData::Weather.get($game_screen.weather_type).category)
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :LevelSnow,
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.level >= parameter && $game_screen &&
|
||||
GameData::Weather.get($game_screen.weather_type).category == :Hail
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :LevelSandstorm,
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.level >= parameter && $game_screen &&
|
||||
GameData::Weather.get($game_screen.weather_type).category == :Sandstorm
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :LevelCycling,
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.level >= parameter && $PokemonGlobal && $PokemonGlobal.bicycle
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :LevelSurfing,
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.level >= parameter && $PokemonGlobal && $PokemonGlobal.surfing
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :LevelDiving,
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.level >= parameter && $PokemonGlobal && $PokemonGlobal.diving
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :LevelDarkness,
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
map_metadata = GameData::MapMetadata.try_get($game_map.map_id)
|
||||
next pkmn.level >= parameter && map_metadata && map_metadata.dark_map
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :LevelDarkInParty,
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.level >= parameter && $Trainer.has_pokemon_of_type?(:DARK)
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :AttackGreater, # Hitmonlee
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.level >= parameter && pkmn.attack > pkmn.defense
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :AtkDefEqual, # Hitmontop
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.level >= parameter && pkmn.attack == pkmn.defense
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :DefenseGreater, # Hitmonchan
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.level >= parameter && pkmn.attack < pkmn.defense
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :Silcoon,
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.level >= parameter && (((pkmn.personalID >> 16) & 0xFFFF) % 10) < 5
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :Cascoon,
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.level >= parameter && (((pkmn.personalID >> 16) & 0xFFFF) % 10) >= 5
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :Ninjask,
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.level >= parameter
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :Shedinja,
|
||||
:parameter => Integer,
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next false # This is a dummy proc and shouldn't next true
|
||||
},
|
||||
:after_evolution_proc => proc { |pkmn, new_species, parameter, evo_species|
|
||||
next false if $Trainer.party_full?
|
||||
next false if !$PokemonBag.pbHasItem?(:POKEBALL)
|
||||
PokemonEvolutionScene.pbDuplicatePokemon(pkmn, new_species)
|
||||
$PokemonBag.pbDeleteItem(:POKEBALL)
|
||||
next true
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :Happiness,
|
||||
:minimum_level => 1, # Needs any level up
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.happiness >= 220
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :HappinessMale,
|
||||
:minimum_level => 1, # Needs any level up
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.happiness >= 220 && pkmn.male?
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :HappinessFemale,
|
||||
:minimum_level => 1, # Needs any level up
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.happiness >= 220 && pkmn.female?
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :HappinessDay,
|
||||
:minimum_level => 1, # Needs any level up
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.happiness >= 220 && PBDayNight.isDay?
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :HappinessNight,
|
||||
:minimum_level => 1, # Needs any level up
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.happiness >= 220 && PBDayNight.isNight?
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :HappinessMove,
|
||||
:parameter => :Move,
|
||||
:minimum_level => 1, # Needs any level up
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
if pkmn.happiness >= 220
|
||||
next pkmn.moves.any? { |m| m && m.id == parameter }
|
||||
end
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :HappinessMoveType,
|
||||
:parameter => :Type,
|
||||
:minimum_level => 1, # Needs any level up
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
if pkmn.happiness >= 220
|
||||
next pkmn.moves.any? { |m| m && m.id > 0 && m.type == parameter }
|
||||
end
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :HappinessHoldItem,
|
||||
:parameter => :Item,
|
||||
:minimum_level => 1, # Needs any level up
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.item == parameter && pkmn.happiness >= 220
|
||||
},
|
||||
:after_evolution_proc => proc { |pkmn, new_species, parameter, evo_species|
|
||||
next false if evo_species != new_species || !pkmn.hasItem?(parameter)
|
||||
pkmn.item = nil # Item is now consumed
|
||||
next true
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :MaxHappiness,
|
||||
:minimum_level => 1, # Needs any level up
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.happiness == 255
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :Beauty, # Feebas
|
||||
:parameter => Integer,
|
||||
:minimum_level => 1, # Needs any level up
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.beauty >= parameter
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :HoldItem,
|
||||
:parameter => :Item,
|
||||
:minimum_level => 1, # Needs any level up
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.item == parameter
|
||||
},
|
||||
:after_evolution_proc => proc { |pkmn, new_species, parameter, evo_species|
|
||||
next false if evo_species != new_species || !pkmn.hasItem?(parameter)
|
||||
pkmn.item = nil # Item is now consumed
|
||||
next true
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :HoldItemMale,
|
||||
:parameter => :Item,
|
||||
:minimum_level => 1, # Needs any level up
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.item == parameter && pkmn.male?
|
||||
},
|
||||
:after_evolution_proc => proc { |pkmn, new_species, parameter, evo_species|
|
||||
next false if evo_species != new_species || !pkmn.hasItem?(parameter)
|
||||
pkmn.item = nil # Item is now consumed
|
||||
next true
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :HoldItemFemale,
|
||||
:parameter => :Item,
|
||||
:minimum_level => 1, # Needs any level up
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.item == parameter && pkmn.female?
|
||||
},
|
||||
:after_evolution_proc => proc { |pkmn, new_species, parameter, evo_species|
|
||||
next false if evo_species != new_species || !pkmn.hasItem?(parameter)
|
||||
pkmn.item = nil # Item is now consumed
|
||||
next true
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :DayHoldItem,
|
||||
:parameter => :Item,
|
||||
:minimum_level => 1, # Needs any level up
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.item == parameter && PBDayNight.isDay?
|
||||
},
|
||||
:after_evolution_proc => proc { |pkmn, new_species, parameter, evo_species|
|
||||
next false if evo_species != new_species || !pkmn.hasItem?(parameter)
|
||||
pkmn.item = nil # Item is now consumed
|
||||
next true
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :NightHoldItem,
|
||||
:parameter => :Item,
|
||||
:minimum_level => 1, # Needs any level up
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.item == parameter && PBDayNight.isNight?
|
||||
},
|
||||
:after_evolution_proc => proc { |pkmn, new_species, parameter, evo_species|
|
||||
next false if evo_species != new_species || !pkmn.hasItem?(parameter)
|
||||
pkmn.item = nil # Item is now consumed
|
||||
next true
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :HoldItemHappiness,
|
||||
:parameter => :Item,
|
||||
:minimum_level => 1, # Needs any level up
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.item == parameter && pkmn.happiness >= 220
|
||||
},
|
||||
:after_evolution_proc => proc { |pkmn, new_species, parameter, evo_species|
|
||||
next false if evo_species != new_species || !pkmn.hasItem?(parameter)
|
||||
pkmn.item = nil # Item is now consumed
|
||||
next true
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :HasMove,
|
||||
:parameter => :Move,
|
||||
:minimum_level => 1, # Needs any level up
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.moves.any? { |m| m && m.id == parameter }
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :HasMoveType,
|
||||
:parameter => :Type,
|
||||
:minimum_level => 1, # Needs any level up
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next pkmn.moves.any? { |m| m && m.type == parameter }
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :HasInParty,
|
||||
:parameter => :Species,
|
||||
:minimum_level => 1, # Needs any level up
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next $Trainer.has_species?(parameter)
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :Location,
|
||||
:parameter => Integer,
|
||||
:minimum_level => 1, # Needs any level up
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
next $game_map.map_id == parameter
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :Region,
|
||||
:parameter => Integer,
|
||||
:minimum_level => 1, # Needs any level up
|
||||
:level_up_proc => proc { |pkmn, parameter|
|
||||
map_metadata = GameData::MapMetadata.try_get($game_map.map_id)
|
||||
next map_metadata && map_metadata.town_map_position &&
|
||||
map_metadata.town_map_position[0] == parameter
|
||||
}
|
||||
})
|
||||
|
||||
#===============================================================================
|
||||
# Evolution methods that trigger when using an item on the Pokémon
|
||||
#===============================================================================
|
||||
GameData::Evolution.register({
|
||||
:id => :Item,
|
||||
:parameter => :Item,
|
||||
:use_item_proc => proc { |pkmn, parameter, item|
|
||||
next item == parameter
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :ItemMale,
|
||||
:parameter => :Item,
|
||||
:use_item_proc => proc { |pkmn, parameter, item|
|
||||
next item == parameter && pkmn.male?
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :ItemFemale,
|
||||
:parameter => :Item,
|
||||
:use_item_proc => proc { |pkmn, parameter, item|
|
||||
next item == parameter && pkmn.female?
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :ItemDay,
|
||||
:parameter => :Item,
|
||||
:use_item_proc => proc { |pkmn, parameter, item|
|
||||
next item == parameter && PBDayNight.isDay?
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :ItemNight,
|
||||
:parameter => :Item,
|
||||
:use_item_proc => proc { |pkmn, parameter, item|
|
||||
next item == parameter && PBDayNight.isNight?
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :ItemHappiness,
|
||||
:parameter => :Item,
|
||||
:use_item_proc => proc { |pkmn, parameter, item|
|
||||
next item == parameter && pkmn.happiness >= 220
|
||||
}
|
||||
})
|
||||
|
||||
#===============================================================================
|
||||
# Evolution methods that trigger when the Pokémon is obtained in a trade
|
||||
#===============================================================================
|
||||
GameData::Evolution.register({
|
||||
:id => :Trade,
|
||||
:on_trade_proc => proc { |pkmn, parameter, other_pkmn|
|
||||
next true
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :TradeMale,
|
||||
:on_trade_proc => proc { |pkmn, parameter, other_pkmn|
|
||||
next pkmn.male?
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :TradeFemale,
|
||||
:on_trade_proc => proc { |pkmn, parameter, other_pkmn|
|
||||
next pkmn.female?
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :TradeDay,
|
||||
:on_trade_proc => proc { |pkmn, parameter, other_pkmn|
|
||||
next PBDayNight.isDay?
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :TradeNight,
|
||||
:on_trade_proc => proc { |pkmn, parameter, other_pkmn|
|
||||
next PBDayNight.isNight?
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :TradeItem,
|
||||
:parameter => :Item,
|
||||
:on_trade_proc => proc { |pkmn, parameter, other_pkmn|
|
||||
next pkmn.item == parameter
|
||||
},
|
||||
:after_evolution_proc => proc { |pkmn, new_species, parameter, evo_species|
|
||||
next false if evo_species != new_species || !pkmn.hasItem?(parameter)
|
||||
pkmn.item = nil # Item is now consumed
|
||||
next true
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Evolution.register({
|
||||
:id => :TradeSpecies,
|
||||
:parameter => :Species,
|
||||
:on_trade_proc => proc { |pkmn, parameter, other_pkmn|
|
||||
next pkmn.species == parameter && !other_pkmn.hasItem?(:EVERSTONE)
|
||||
}
|
||||
})
|
||||
131
Data/Scripts_backup/010_Data/001_Hardcoded data/008_Stat.rb
Normal file
131
Data/Scripts_backup/010_Data/001_Hardcoded data/008_Stat.rb
Normal file
@@ -0,0 +1,131 @@
|
||||
# The id_number value determines which order the stats are iterated through by
|
||||
# the "each" methods.
|
||||
# The pbs_order value determines the order in which the stats are written in
|
||||
# several PBS files, where base stats/IVs/EVs/EV yields are defined. Only stats
|
||||
# which are yielded by the "each_main" method can have stat numbers defined in
|
||||
# those places. The values of pbs_order defined below should start with 0 and
|
||||
# increase without skipping any numbers.
|
||||
module GameData
|
||||
class Stat
|
||||
attr_reader :id
|
||||
attr_reader :id_number
|
||||
attr_reader :real_name
|
||||
attr_reader :real_name_brief
|
||||
attr_reader :type
|
||||
attr_reader :pbs_order
|
||||
|
||||
DATA = {}
|
||||
|
||||
extend ClassMethods
|
||||
include InstanceMethods
|
||||
|
||||
def self.load; end
|
||||
def self.save; end
|
||||
|
||||
# These stats are defined in PBS files, and should have the :pbs_order
|
||||
# property.
|
||||
def self.each_main
|
||||
self.each { |s| yield s if [:main, :main_battle].include?(s.type) }
|
||||
end
|
||||
|
||||
def self.each_main_battle
|
||||
self.each { |s| yield s if [:main_battle].include?(s.type) }
|
||||
end
|
||||
|
||||
# These stats have associated stat stages in battle.
|
||||
def self.each_battle
|
||||
self.each { |s| yield s if [:main_battle, :battle].include?(s.type) }
|
||||
end
|
||||
|
||||
def initialize(hash)
|
||||
@id = hash[:id]
|
||||
@id_number = hash[:id_number] || -1
|
||||
@real_name = hash[:name] || "Unnamed"
|
||||
@real_name_brief = hash[:name_brief] || "None"
|
||||
@type = hash[:type] || :none
|
||||
@pbs_order = hash[:pbs_order] || -1
|
||||
end
|
||||
|
||||
# @return [String] the translated name of this stat
|
||||
def name
|
||||
return _INTL(@real_name)
|
||||
end
|
||||
|
||||
# @return [String] the translated brief name of this stat
|
||||
def name_brief
|
||||
return _INTL(@real_name_brief)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
|
||||
GameData::Stat.register({
|
||||
:id => :HP,
|
||||
:id_number => 0,
|
||||
:name => _INTL("HP"),
|
||||
:name_brief => _INTL("HP"),
|
||||
:type => :main,
|
||||
:pbs_order => 0
|
||||
})
|
||||
|
||||
GameData::Stat.register({
|
||||
:id => :ATTACK,
|
||||
:id_number => 1,
|
||||
:name => _INTL("Attack"),
|
||||
:name_brief => _INTL("Atk"),
|
||||
:type => :main_battle,
|
||||
:pbs_order => 1
|
||||
})
|
||||
|
||||
GameData::Stat.register({
|
||||
:id => :DEFENSE,
|
||||
:id_number => 2,
|
||||
:name => _INTL("Defense"),
|
||||
:name_brief => _INTL("Def"),
|
||||
:type => :main_battle,
|
||||
:pbs_order => 2
|
||||
})
|
||||
|
||||
GameData::Stat.register({
|
||||
:id => :SPECIAL_ATTACK,
|
||||
:id_number => 3,
|
||||
:name => _INTL("Special Attack"),
|
||||
:name_brief => _INTL("SpAtk"),
|
||||
:type => :main_battle,
|
||||
:pbs_order => 4
|
||||
})
|
||||
|
||||
GameData::Stat.register({
|
||||
:id => :SPECIAL_DEFENSE,
|
||||
:id_number => 4,
|
||||
:name => _INTL("Special Defense"),
|
||||
:name_brief => _INTL("SpDef"),
|
||||
:type => :main_battle,
|
||||
:pbs_order => 5
|
||||
})
|
||||
|
||||
GameData::Stat.register({
|
||||
:id => :SPEED,
|
||||
:id_number => 5,
|
||||
:name => _INTL("Speed"),
|
||||
:name_brief => _INTL("Spd"),
|
||||
:type => :main_battle,
|
||||
:pbs_order => 3
|
||||
})
|
||||
|
||||
GameData::Stat.register({
|
||||
:id => :ACCURACY,
|
||||
:id_number => 6,
|
||||
:name => _INTL("accuracy"),
|
||||
:name_brief => _INTL("Acc"),
|
||||
:type => :battle
|
||||
})
|
||||
|
||||
GameData::Stat.register({
|
||||
:id => :EVASION,
|
||||
:id_number => 7,
|
||||
:name => _INTL("evasiveness"),
|
||||
:name_brief => _INTL("Eva"),
|
||||
:type => :battle
|
||||
})
|
||||
200
Data/Scripts_backup/010_Data/001_Hardcoded data/009_Nature.rb
Normal file
200
Data/Scripts_backup/010_Data/001_Hardcoded data/009_Nature.rb
Normal file
@@ -0,0 +1,200 @@
|
||||
module GameData
|
||||
class Nature
|
||||
attr_reader :id
|
||||
attr_reader :id_number
|
||||
attr_reader :real_name
|
||||
attr_reader :stat_changes
|
||||
|
||||
DATA = {}
|
||||
|
||||
extend ClassMethods
|
||||
include InstanceMethods
|
||||
|
||||
def self.load; end
|
||||
def self.save; end
|
||||
|
||||
def initialize(hash)
|
||||
@id = hash[:id]
|
||||
@id_number = hash[:id_number] || -1
|
||||
@real_name = hash[:name] || "Unnamed"
|
||||
@stat_changes = hash[:stat_changes] || []
|
||||
end
|
||||
|
||||
# @return [String] the translated name of this nature
|
||||
def name
|
||||
return _INTL(@real_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :HARDY,
|
||||
:id_number => 0,
|
||||
:name => _INTL("Hardy")
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :LONELY,
|
||||
:id_number => 1,
|
||||
:name => _INTL("Lonely"),
|
||||
:stat_changes => [[:ATTACK, 10], [:DEFENSE, -10]]
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :BRAVE,
|
||||
:id_number => 2,
|
||||
:name => _INTL("Brave"),
|
||||
:stat_changes => [[:ATTACK, 10], [:SPEED, -10]]
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :ADAMANT,
|
||||
:id_number => 3,
|
||||
:name => _INTL("Adamant"),
|
||||
:stat_changes => [[:ATTACK, 10], [:SPECIAL_ATTACK, -10]]
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :NAUGHTY,
|
||||
:id_number => 4,
|
||||
:name => _INTL("Naughty"),
|
||||
:stat_changes => [[:ATTACK, 10], [:SPECIAL_DEFENSE, -10]]
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :BOLD,
|
||||
:id_number => 5,
|
||||
:name => _INTL("Bold"),
|
||||
:stat_changes => [[:DEFENSE, 10], [:ATTACK, -10]]
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :DOCILE,
|
||||
:id_number => 6,
|
||||
:name => _INTL("Docile")
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :RELAXED,
|
||||
:id_number => 7,
|
||||
:name => _INTL("Relaxed"),
|
||||
:stat_changes => [[:DEFENSE, 10], [:SPEED, -10]]
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :IMPISH,
|
||||
:id_number => 8,
|
||||
:name => _INTL("Impish"),
|
||||
:stat_changes => [[:DEFENSE, 10], [:SPECIAL_ATTACK, -10]]
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :LAX,
|
||||
:id_number => 9,
|
||||
:name => _INTL("Lax"),
|
||||
:stat_changes => [[:DEFENSE, 10], [:SPECIAL_DEFENSE, -10]]
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :TIMID,
|
||||
:id_number => 10,
|
||||
:name => _INTL("Timid"),
|
||||
:stat_changes => [[:SPEED, 10], [:ATTACK, -10]]
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :HASTY,
|
||||
:id_number => 11,
|
||||
:name => _INTL("Hasty"),
|
||||
:stat_changes => [[:SPEED, 10], [:DEFENSE, -10]]
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :SERIOUS,
|
||||
:id_number => 12,
|
||||
:name => _INTL("Serious")
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :JOLLY,
|
||||
:id_number => 13,
|
||||
:name => _INTL("Jolly"),
|
||||
:stat_changes => [[:SPEED, 10], [:SPECIAL_ATTACK, -10]]
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :NAIVE,
|
||||
:id_number => 14,
|
||||
:name => _INTL("Naive"),
|
||||
:stat_changes => [[:SPEED, 10], [:SPECIAL_DEFENSE, -10]]
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :MODEST,
|
||||
:id_number => 15,
|
||||
:name => _INTL("Modest"),
|
||||
:stat_changes => [[:SPECIAL_ATTACK, 10], [:ATTACK, -10]]
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :MILD,
|
||||
:id_number => 16,
|
||||
:name => _INTL("Mild"),
|
||||
:stat_changes => [[:SPECIAL_ATTACK, 10], [:DEFENSE, -10]]
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :QUIET,
|
||||
:id_number => 17,
|
||||
:name => _INTL("Quiet"),
|
||||
:stat_changes => [[:SPECIAL_ATTACK, 10], [:SPEED, -10]]
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :BASHFUL,
|
||||
:id_number => 18,
|
||||
:name => _INTL("Bashful")
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :RASH,
|
||||
:id_number => 19,
|
||||
:name => _INTL("Rash"),
|
||||
:stat_changes => [[:SPECIAL_ATTACK, 10], [:SPECIAL_DEFENSE, -10]]
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :CALM,
|
||||
:id_number => 20,
|
||||
:name => _INTL("Calm"),
|
||||
:stat_changes => [[:SPECIAL_DEFENSE, 10], [:ATTACK, -10]]
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :GENTLE,
|
||||
:id_number => 21,
|
||||
:name => _INTL("Gentle"),
|
||||
:stat_changes => [[:SPECIAL_DEFENSE, 10], [:DEFENSE, -10]]
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :SASSY,
|
||||
:id_number => 22,
|
||||
:name => _INTL("Sassy"),
|
||||
:stat_changes => [[:SPECIAL_DEFENSE, 10], [:SPEED, -10]]
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :CAREFUL,
|
||||
:id_number => 23,
|
||||
:name => _INTL("Careful"),
|
||||
:stat_changes => [[:SPECIAL_DEFENSE, 10], [:SPECIAL_ATTACK, -10]]
|
||||
})
|
||||
|
||||
GameData::Nature.register({
|
||||
:id => :QUIRKY,
|
||||
:id_number => 24,
|
||||
:name => _INTL("Quirky")
|
||||
})
|
||||
@@ -0,0 +1,79 @@
|
||||
# NOTE: The id_number is only used to determine the order of the status icons in
|
||||
# the graphics containing them. Number 0 (:NONE) is ignored; they start
|
||||
# with status 1.
|
||||
# "Graphics/Pictures/statuses.png" also contains icons for being fainted
|
||||
# and for having Pokérus, in that order, at the bottom of the graphic.
|
||||
# "Graphics/Pictures/Battle/icon_statuses.png" also contains an icon for
|
||||
# bad poisoning (toxic), at the bottom of the graphic.
|
||||
# Both graphics automatically handle varying numbers of defined statuses.
|
||||
module GameData
|
||||
class Status
|
||||
attr_reader :id
|
||||
attr_reader :id_number
|
||||
attr_reader :real_name
|
||||
attr_reader :animation
|
||||
|
||||
DATA = {}
|
||||
|
||||
extend ClassMethods
|
||||
include InstanceMethods
|
||||
|
||||
def self.load; end
|
||||
def self.save; end
|
||||
|
||||
def initialize(hash)
|
||||
@id = hash[:id]
|
||||
@id_number = hash[:id_number]
|
||||
@real_name = hash[:name] || "Unnamed"
|
||||
@animation = hash[:animation]
|
||||
end
|
||||
|
||||
# @return [String] the translated name of this status condition
|
||||
def name
|
||||
return _INTL(@real_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
|
||||
GameData::Status.register({
|
||||
:id => :NONE,
|
||||
:id_number => 0,
|
||||
:name => _INTL("None")
|
||||
})
|
||||
|
||||
GameData::Status.register({
|
||||
:id => :SLEEP,
|
||||
:id_number => 1,
|
||||
:name => _INTL("Sleep"),
|
||||
:animation => "Sleep"
|
||||
})
|
||||
|
||||
GameData::Status.register({
|
||||
:id => :POISON,
|
||||
:id_number => 2,
|
||||
:name => _INTL("Poison"),
|
||||
:animation => "Poison"
|
||||
})
|
||||
|
||||
GameData::Status.register({
|
||||
:id => :BURN,
|
||||
:id_number => 3,
|
||||
:name => _INTL("Burn"),
|
||||
:animation => "Burn"
|
||||
})
|
||||
|
||||
GameData::Status.register({
|
||||
:id => :PARALYSIS,
|
||||
:id_number => 4,
|
||||
:name => _INTL("Paralysis"),
|
||||
:animation => "Paralysis"
|
||||
})
|
||||
|
||||
GameData::Status.register({
|
||||
:id => :FROZEN,
|
||||
:id_number => 5,
|
||||
:name => _INTL("Frozen"),
|
||||
:animation => "Frozen"
|
||||
})
|
||||
@@ -0,0 +1,194 @@
|
||||
module GameData
|
||||
class TerrainTag
|
||||
attr_reader :id
|
||||
attr_reader :id_number
|
||||
attr_reader :real_name
|
||||
attr_reader :can_surf
|
||||
attr_reader :waterfall # The main part only, not the crest
|
||||
attr_reader :waterfall_crest
|
||||
attr_reader :can_fish
|
||||
attr_reader :can_dive
|
||||
attr_reader :deep_bush
|
||||
attr_reader :shows_grass_rustle
|
||||
attr_reader :land_wild_encounters
|
||||
attr_reader :double_wild_encounters
|
||||
attr_reader :battle_environment
|
||||
attr_reader :ledge
|
||||
attr_reader :ice
|
||||
attr_reader :bridge
|
||||
attr_reader :shows_reflections
|
||||
attr_reader :must_walk
|
||||
attr_reader :ignore_passability
|
||||
|
||||
DATA = {}
|
||||
|
||||
extend ClassMethods
|
||||
include InstanceMethods
|
||||
|
||||
# @param other [Symbol, self, String, Integer]
|
||||
# @return [self]
|
||||
def self.try_get(other)
|
||||
return self.get(:None) if other.nil?
|
||||
validate other => [Symbol, self, String, Integer]
|
||||
return other if other.is_a?(self)
|
||||
other = other.to_sym if other.is_a?(String)
|
||||
return (self::DATA.has_key?(other)) ? self::DATA[other] : self.get(:None)
|
||||
end
|
||||
|
||||
def self.load; end
|
||||
def self.save; end
|
||||
|
||||
def initialize(hash)
|
||||
@id = hash[:id]
|
||||
@id_number = hash[:id_number]
|
||||
@real_name = hash[:id].to_s || "Unnamed"
|
||||
@can_surf = hash[:can_surf] || false
|
||||
@waterfall = hash[:waterfall] || false
|
||||
@waterfall_crest = hash[:waterfall_crest] || false
|
||||
@can_fish = hash[:can_fish] || false
|
||||
@can_dive = hash[:can_dive] || false
|
||||
@deep_bush = hash[:deep_bush] || false
|
||||
@shows_grass_rustle = hash[:shows_grass_rustle] || false
|
||||
@land_wild_encounters = hash[:land_wild_encounters] || false
|
||||
@double_wild_encounters = hash[:double_wild_encounters] || false
|
||||
@battle_environment = hash[:battle_environment]
|
||||
@ledge = hash[:ledge] || false
|
||||
@ice = hash[:ice] || false
|
||||
@bridge = hash[:bridge] || false
|
||||
@shows_reflections = hash[:shows_reflections] || false
|
||||
@must_walk = hash[:must_walk] || false
|
||||
@ignore_passability = hash[:ignore_passability] || false
|
||||
end
|
||||
|
||||
def can_surf_freely
|
||||
return @can_surf && !@waterfall && !@waterfall_crest
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
|
||||
GameData::TerrainTag.register({
|
||||
:id => :None,
|
||||
:id_number => 0
|
||||
})
|
||||
|
||||
GameData::TerrainTag.register({
|
||||
:id => :Ledge,
|
||||
:id_number => 1,
|
||||
:ledge => true
|
||||
})
|
||||
|
||||
GameData::TerrainTag.register({
|
||||
:id => :Grass,
|
||||
:id_number => 2,
|
||||
:shows_grass_rustle => true,
|
||||
:land_wild_encounters => true,
|
||||
:battle_environment => :Grass
|
||||
})
|
||||
|
||||
GameData::TerrainTag.register({
|
||||
:id => :Sand,
|
||||
:id_number => 3,
|
||||
:battle_environment => :Sand
|
||||
})
|
||||
|
||||
GameData::TerrainTag.register({
|
||||
:id => :Rock,
|
||||
:id_number => 4,
|
||||
:battle_environment => :Rock
|
||||
})
|
||||
|
||||
GameData::TerrainTag.register({
|
||||
:id => :DeepWater,
|
||||
:id_number => 5,
|
||||
:can_surf => true,
|
||||
:can_fish => true,
|
||||
:can_dive => true,
|
||||
:battle_environment => :MovingWater
|
||||
})
|
||||
|
||||
GameData::TerrainTag.register({
|
||||
:id => :StillWater,
|
||||
:id_number => 6,
|
||||
:can_surf => true,
|
||||
:can_fish => true,
|
||||
:battle_environment => :StillWater,
|
||||
:shows_reflections => true
|
||||
})
|
||||
|
||||
GameData::TerrainTag.register({
|
||||
:id => :Water,
|
||||
:id_number => 7,
|
||||
:can_surf => true,
|
||||
:can_fish => true,
|
||||
:battle_environment => :MovingWater
|
||||
})
|
||||
|
||||
GameData::TerrainTag.register({
|
||||
:id => :Waterfall,
|
||||
:id_number => 8,
|
||||
:can_surf => true,
|
||||
:waterfall => true
|
||||
})
|
||||
|
||||
GameData::TerrainTag.register({
|
||||
:id => :WaterfallCrest,
|
||||
:id_number => 9,
|
||||
:can_surf => true,
|
||||
:can_fish => true,
|
||||
:waterfall_crest => true
|
||||
})
|
||||
|
||||
GameData::TerrainTag.register({
|
||||
:id => :TallGrass,
|
||||
:id_number => 10,
|
||||
:deep_bush => true,
|
||||
:land_wild_encounters => true,
|
||||
:double_wild_encounters => true,
|
||||
:battle_environment => :TallGrass,
|
||||
:must_walk => true
|
||||
})
|
||||
|
||||
GameData::TerrainTag.register({
|
||||
:id => :UnderwaterGrass,
|
||||
:id_number => 11,
|
||||
:land_wild_encounters => true
|
||||
})
|
||||
|
||||
GameData::TerrainTag.register({
|
||||
:id => :Ice,
|
||||
:id_number => 12,
|
||||
:battle_environment => :Ice,
|
||||
:ice => true,
|
||||
:must_walk => true
|
||||
})
|
||||
|
||||
GameData::TerrainTag.register({
|
||||
:id => :Neutral,
|
||||
:id_number => 13,
|
||||
:ignore_passability => true
|
||||
})
|
||||
|
||||
# NOTE: This is referenced by ID in an Events.onStepTakenFieldMovement proc that
|
||||
# adds soot to the Soot Sack if the player walks over one of these tiles.
|
||||
GameData::TerrainTag.register({
|
||||
:id => :SootGrass,
|
||||
:id_number => 14,
|
||||
:shows_grass_rustle => true,
|
||||
:land_wild_encounters => true,
|
||||
:battle_environment => :Grass
|
||||
})
|
||||
|
||||
GameData::TerrainTag.register({
|
||||
:id => :Bridge,
|
||||
:id_number => 15,
|
||||
:bridge => true
|
||||
})
|
||||
|
||||
GameData::TerrainTag.register({
|
||||
:id => :Puddle,
|
||||
:id_number => 16,
|
||||
:battle_environment => :Puddle,
|
||||
:shows_reflections => true
|
||||
})
|
||||
163
Data/Scripts_backup/010_Data/001_Hardcoded data/012_Weather.rb
Normal file
163
Data/Scripts_backup/010_Data/001_Hardcoded data/012_Weather.rb
Normal file
@@ -0,0 +1,163 @@
|
||||
# Category has the following effects:
|
||||
# - Determines the in-battle weather.
|
||||
# - Some abilities reduce the encounter rate in certain categories of weather.
|
||||
# - Some evolution methods check the current weather's category.
|
||||
# - The :Rain category treats the last listed particle graphic as a water splash rather
|
||||
# than a raindrop, which behaves differently.
|
||||
# - :Rain auto-waters berry plants.
|
||||
# Delta values are per second.
|
||||
# For the tone_proc, strength goes from 0 to RPG::Weather::MAX_SPRITES (60) and
|
||||
# will typically be the maximum.
|
||||
module GameData
|
||||
class Weather
|
||||
attr_reader :id
|
||||
attr_reader :id_number
|
||||
attr_reader :real_name
|
||||
attr_reader :category # :None, :Rain, :Hail, :Sandstorm, :Sun, :Fog
|
||||
attr_reader :graphics # [[particle file names], [tile file names]]
|
||||
attr_reader :particle_delta_x
|
||||
attr_reader :particle_delta_y
|
||||
attr_reader :particle_delta_opacity
|
||||
attr_reader :tile_delta_x
|
||||
attr_reader :tile_delta_y
|
||||
attr_reader :tone_proc
|
||||
|
||||
DATA = {}
|
||||
|
||||
extend ClassMethods
|
||||
include InstanceMethods
|
||||
|
||||
def self.load; end
|
||||
def self.save; end
|
||||
|
||||
def initialize(hash)
|
||||
@id = hash[:id]
|
||||
@id_number = hash[:id_number]
|
||||
@real_name = hash[:id].to_s || "Unnamed"
|
||||
@category = hash[:category] || :None
|
||||
@particle_delta_x = hash[:particle_delta_x] || 0
|
||||
@particle_delta_y = hash[:particle_delta_y] || 0
|
||||
@particle_delta_opacity = hash[:particle_delta_opacity] || 0
|
||||
@tile_delta_x = hash[:tile_delta_x] || 0
|
||||
@tile_delta_y = hash[:tile_delta_y] || 0
|
||||
@graphics = hash[:graphics] || []
|
||||
@tone_proc = hash[:tone_proc]
|
||||
end
|
||||
|
||||
def has_particles?
|
||||
return @graphics[0] && @graphics[0].length > 0
|
||||
end
|
||||
|
||||
def has_tiles?
|
||||
return @graphics[1] && @graphics[1].length > 0
|
||||
end
|
||||
|
||||
def tone(strength)
|
||||
return (@tone_proc) ? @tone_proc.call(strength) : Tone.new(0, 0, 0, 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
|
||||
GameData::Weather.register({
|
||||
:id => :None,
|
||||
:id_number => 0 # Must be 0 (preset RMXP weather)
|
||||
})
|
||||
|
||||
GameData::Weather.register({
|
||||
:id => :Rain,
|
||||
:id_number => 1, # Must be 1 (preset RMXP weather)
|
||||
:category => :Rain,
|
||||
:graphics => [["rain_1", "rain_2", "rain_3", "rain_4"]], # Last is splash
|
||||
:particle_delta_x => -1200,
|
||||
:particle_delta_y => 4800,
|
||||
:tone_proc => proc { |strength|
|
||||
next Tone.new(-strength * 3 / 4, -strength * 3 / 4, -strength * 3 / 4, 10)
|
||||
}
|
||||
})
|
||||
|
||||
# NOTE: This randomly flashes the screen in RPG::Weather#update.
|
||||
GameData::Weather.register({
|
||||
:id => :Storm,
|
||||
:id_number => 2, # Must be 2 (preset RMXP weather)
|
||||
:category => :Rain,
|
||||
:graphics => [["storm_1", "storm_2", "storm_3", "storm_4"]], # Last is splash
|
||||
:particle_delta_x => -4800,
|
||||
:particle_delta_y => 4800,
|
||||
:tone_proc => proc { |strength|
|
||||
next Tone.new(-strength * 3 / 2, -strength * 3 / 2, -strength * 3 / 2, 20)
|
||||
}
|
||||
})
|
||||
|
||||
# NOTE: This alters the movement of snow particles in RPG::Weather#update_sprite_position.
|
||||
GameData::Weather.register({
|
||||
:id => :Snow,
|
||||
:id_number => 3, # Must be 3 (preset RMXP weather)
|
||||
:category => :Hail,
|
||||
:graphics => [["hail_1", "hail_2", "hail_3"]],
|
||||
:particle_delta_x => -240,
|
||||
:particle_delta_y => 240,
|
||||
:tone_proc => proc { |strength|
|
||||
next Tone.new(strength / 2, strength / 2, strength / 2, 0)
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Weather.register({
|
||||
:id => :Blizzard,
|
||||
:id_number => 4,
|
||||
:category => :Hail,
|
||||
:graphics => [["blizzard_1", "blizzard_2", "blizzard_3", "blizzard_4"], ["blizzard_tile"]],
|
||||
:particle_delta_x => -960,
|
||||
:particle_delta_y => 240,
|
||||
:tile_delta_x => -1440,
|
||||
:tile_delta_y => 720,
|
||||
:tone_proc => proc { |strength|
|
||||
next Tone.new(strength * 3 / 4, strength * 3 / 4, strength * 3 / 4, 0)
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Weather.register({
|
||||
:id => :Sandstorm,
|
||||
:id_number => 5,
|
||||
:category => :Sandstorm,
|
||||
:graphics => [["sandstorm_1", "sandstorm_2", "sandstorm_3", "sandstorm_4"], ["sandstorm_tile"]],
|
||||
:particle_delta_x => -1200,
|
||||
:particle_delta_y => 640,
|
||||
:tile_delta_x => -720,
|
||||
:tile_delta_y => 360,
|
||||
:tone_proc => proc { |strength|
|
||||
next Tone.new(strength / 2, 0, -strength / 2, 0)
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Weather.register({
|
||||
:id => :HeavyRain,
|
||||
:id_number => 6,
|
||||
:category => :Rain,
|
||||
:graphics => [["storm_1", "storm_2", "storm_3", "storm_4"]], # Last is splash
|
||||
:particle_delta_x => -4800,
|
||||
:particle_delta_y => 4800,
|
||||
:tone_proc => proc { |strength|
|
||||
next Tone.new(-strength * 3 / 2, -strength * 3 / 2, -strength * 3 / 2, 20)
|
||||
}
|
||||
})
|
||||
|
||||
# NOTE: This alters the screen tone in RPG::Weather#update_screen_tone.
|
||||
GameData::Weather.register({
|
||||
:id => :Sun,
|
||||
:id_number => 7,
|
||||
:category => :Sun,
|
||||
:tone_proc => proc { |strength|
|
||||
next Tone.new(64, 64, 32, 0)
|
||||
}
|
||||
})
|
||||
|
||||
GameData::Weather.register({
|
||||
:id => :Fog,
|
||||
:category => :Fog,
|
||||
:id_number => 8,
|
||||
:tile_delta_x => -32,
|
||||
:tile_delta_y => 0,
|
||||
:graphics => [nil, ["fog_tile"]]
|
||||
})
|
||||
@@ -0,0 +1,197 @@
|
||||
module GameData
|
||||
class EncounterType
|
||||
attr_reader :id
|
||||
attr_reader :real_name
|
||||
attr_reader :type # :land, :cave, :water, :fishing, :contest, :none
|
||||
attr_reader :trigger_chance
|
||||
attr_reader :old_slots
|
||||
|
||||
DATA = {}
|
||||
|
||||
extend ClassMethodsSymbols
|
||||
include InstanceMethods
|
||||
|
||||
def self.load; end
|
||||
def self.save; end
|
||||
|
||||
def initialize(hash)
|
||||
@id = hash[:id]
|
||||
@real_name = hash[:id].to_s || "Unnamed"
|
||||
@type = hash[:type] || :none
|
||||
@trigger_chance = hash[:trigger_chance] || 0
|
||||
@old_slots = hash[:old_slots]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :Land,
|
||||
:type => :land,
|
||||
:trigger_chance => 21,
|
||||
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :LandDay,
|
||||
:type => :land,
|
||||
:trigger_chance => 21,
|
||||
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :LandNight,
|
||||
:type => :land,
|
||||
:trigger_chance => 21,
|
||||
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :LandMorning,
|
||||
:type => :land,
|
||||
:trigger_chance => 21,
|
||||
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :LandAfternoon,
|
||||
:type => :land,
|
||||
:trigger_chance => 21,
|
||||
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :LandEvening,
|
||||
:type => :land,
|
||||
:trigger_chance => 21,
|
||||
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :Cave,
|
||||
:type => :cave,
|
||||
:trigger_chance => 5,
|
||||
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :CaveDay,
|
||||
:type => :cave,
|
||||
:trigger_chance => 5,
|
||||
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :CaveNight,
|
||||
:type => :cave,
|
||||
:trigger_chance => 5,
|
||||
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :CaveMorning,
|
||||
:type => :cave,
|
||||
:trigger_chance => 5,
|
||||
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :CaveAfternoon,
|
||||
:type => :cave,
|
||||
:trigger_chance => 5,
|
||||
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :CaveEvening,
|
||||
:type => :cave,
|
||||
:trigger_chance => 5,
|
||||
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :Water,
|
||||
:type => :water,
|
||||
:trigger_chance => 2,
|
||||
:old_slots => [60, 30, 5, 4, 1]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :WaterDay,
|
||||
:type => :water,
|
||||
:trigger_chance => 2,
|
||||
:old_slots => [60, 30, 5, 4, 1]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :WaterNight,
|
||||
:type => :water,
|
||||
:trigger_chance => 2,
|
||||
:old_slots => [60, 30, 5, 4, 1]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :WaterMorning,
|
||||
:type => :water,
|
||||
:trigger_chance => 2,
|
||||
:old_slots => [60, 30, 5, 4, 1]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :WaterAfternoon,
|
||||
:type => :water,
|
||||
:trigger_chance => 2,
|
||||
:old_slots => [60, 30, 5, 4, 1]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :WaterEvening,
|
||||
:type => :water,
|
||||
:trigger_chance => 2,
|
||||
:old_slots => [60, 30, 5, 4, 1]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :OldRod,
|
||||
:type => :fishing,
|
||||
:old_slots => [70, 30]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :GoodRod,
|
||||
:type => :fishing,
|
||||
:old_slots => [60, 20, 20]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :SuperRod,
|
||||
:type => :fishing,
|
||||
:old_slots => [40, 40, 15, 4, 1]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :RockSmash,
|
||||
:type => :none,
|
||||
:trigger_chance => 50,
|
||||
:old_slots => [60, 30, 5, 4, 1]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :HeadbuttLow,
|
||||
:type => :none,
|
||||
:old_slots => [30, 25, 20, 10, 5, 5, 4, 1]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :HeadbuttHigh,
|
||||
:type => :none,
|
||||
:old_slots => [30, 25, 20, 10, 5, 5, 4, 1]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :BugContest,
|
||||
:type => :contest,
|
||||
:trigger_chance => 21,
|
||||
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
|
||||
})
|
||||
@@ -0,0 +1,131 @@
|
||||
module GameData
|
||||
class Environment
|
||||
attr_reader :id
|
||||
attr_reader :real_name
|
||||
attr_reader :battle_base
|
||||
|
||||
DATA = {}
|
||||
|
||||
extend ClassMethodsSymbols
|
||||
include InstanceMethods
|
||||
|
||||
def self.load; end
|
||||
def self.save; end
|
||||
|
||||
def initialize(hash)
|
||||
@id = hash[:id]
|
||||
@real_name = hash[:name] || "Unnamed"
|
||||
@battle_base = hash[:battle_base]
|
||||
end
|
||||
|
||||
# @return [String] the translated name of this environment
|
||||
def name
|
||||
return _INTL(@real_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
|
||||
GameData::Environment.register({
|
||||
:id => :None,
|
||||
:name => _INTL("None")
|
||||
})
|
||||
|
||||
GameData::Environment.register({
|
||||
:id => :Grass,
|
||||
:name => _INTL("Grass"),
|
||||
:battle_base => "grass"
|
||||
})
|
||||
|
||||
GameData::Environment.register({
|
||||
:id => :TallGrass,
|
||||
:name => _INTL("Tall grass"),
|
||||
:battle_base => "grass"
|
||||
})
|
||||
|
||||
GameData::Environment.register({
|
||||
:id => :MovingWater,
|
||||
:name => _INTL("Moving water"),
|
||||
:battle_base => "water"
|
||||
})
|
||||
|
||||
GameData::Environment.register({
|
||||
:id => :StillWater,
|
||||
:name => _INTL("Still water"),
|
||||
:battle_base => "water"
|
||||
})
|
||||
|
||||
GameData::Environment.register({
|
||||
:id => :Puddle,
|
||||
:name => _INTL("Puddle"),
|
||||
:battle_basec => "puddle"
|
||||
})
|
||||
|
||||
GameData::Environment.register({
|
||||
:id => :Underwater,
|
||||
:name => _INTL("Underwater")
|
||||
})
|
||||
|
||||
GameData::Environment.register({
|
||||
:id => :Cave,
|
||||
:name => _INTL("Cave")
|
||||
})
|
||||
|
||||
GameData::Environment.register({
|
||||
:id => :Rock,
|
||||
:name => _INTL("Rock")
|
||||
})
|
||||
|
||||
GameData::Environment.register({
|
||||
:id => :Sand,
|
||||
:name => _INTL("Sand"),
|
||||
:battle_base => "sand"
|
||||
})
|
||||
|
||||
GameData::Environment.register({
|
||||
:id => :Forest,
|
||||
:name => _INTL("Forest")
|
||||
})
|
||||
|
||||
GameData::Environment.register({
|
||||
:id => :ForestGrass,
|
||||
:name => _INTL("Forest grass"),
|
||||
:battle_base => "grass"
|
||||
})
|
||||
|
||||
GameData::Environment.register({
|
||||
:id => :Snow,
|
||||
:name => _INTL("Snow")
|
||||
})
|
||||
|
||||
GameData::Environment.register({
|
||||
:id => :Ice,
|
||||
:name => _INTL("Ice"),
|
||||
:battle_base => "ice"
|
||||
})
|
||||
|
||||
GameData::Environment.register({
|
||||
:id => :Volcano,
|
||||
:name => _INTL("Volcano")
|
||||
})
|
||||
|
||||
GameData::Environment.register({
|
||||
:id => :Graveyard,
|
||||
:name => _INTL("Graveyard")
|
||||
})
|
||||
|
||||
GameData::Environment.register({
|
||||
:id => :Sky,
|
||||
:name => _INTL("Sky")
|
||||
})
|
||||
|
||||
GameData::Environment.register({
|
||||
:id => :Space,
|
||||
:name => _INTL("Space")
|
||||
})
|
||||
|
||||
GameData::Environment.register({
|
||||
:id => :UltraSpace,
|
||||
:name => _INTL("Ultra Space")
|
||||
})
|
||||
@@ -0,0 +1,81 @@
|
||||
module GameData
|
||||
class BattleWeather
|
||||
attr_reader :id
|
||||
attr_reader :real_name
|
||||
attr_reader :animation
|
||||
|
||||
DATA = {}
|
||||
|
||||
extend ClassMethodsSymbols
|
||||
include InstanceMethods
|
||||
|
||||
def self.load; end
|
||||
def self.save; end
|
||||
|
||||
def initialize(hash)
|
||||
@id = hash[:id]
|
||||
@real_name = hash[:name] || "Unnamed"
|
||||
@animation = hash[:animation]
|
||||
end
|
||||
|
||||
# @return [String] the translated name of this battle weather
|
||||
def name
|
||||
return _INTL(@real_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
|
||||
GameData::BattleWeather.register({
|
||||
:id => :None,
|
||||
:name => _INTL("None")
|
||||
})
|
||||
|
||||
GameData::BattleWeather.register({
|
||||
:id => :Sun,
|
||||
:name => _INTL("Sun"),
|
||||
:animation => "Sun"
|
||||
})
|
||||
|
||||
GameData::BattleWeather.register({
|
||||
:id => :Rain,
|
||||
:name => _INTL("Rain"),
|
||||
:animation => "Rain"
|
||||
})
|
||||
|
||||
GameData::BattleWeather.register({
|
||||
:id => :Sandstorm,
|
||||
:name => _INTL("Sandstorm"),
|
||||
:animation => "Sandstorm"
|
||||
})
|
||||
|
||||
GameData::BattleWeather.register({
|
||||
:id => :Hail,
|
||||
:name => _INTL("Hail"),
|
||||
:animation => "Hail"
|
||||
})
|
||||
|
||||
GameData::BattleWeather.register({
|
||||
:id => :HarshSun,
|
||||
:name => _INTL("Harsh Sun"),
|
||||
:animation => "HarshSun"
|
||||
})
|
||||
|
||||
GameData::BattleWeather.register({
|
||||
:id => :HeavyRain,
|
||||
:name => _INTL("Heavy Rain"),
|
||||
:animation => "HeavyRain"
|
||||
})
|
||||
|
||||
GameData::BattleWeather.register({
|
||||
:id => :StrongWinds,
|
||||
:name => _INTL("Strong Winds"),
|
||||
:animation => "StrongWinds"
|
||||
})
|
||||
|
||||
GameData::BattleWeather.register({
|
||||
:id => :ShadowSky,
|
||||
:name => _INTL("Shadow Sky"),
|
||||
:animation => "ShadowSky"
|
||||
})
|
||||
@@ -0,0 +1,58 @@
|
||||
# These are in-battle terrain effects caused by moves like Electric Terrain.
|
||||
module GameData
|
||||
class BattleTerrain
|
||||
attr_reader :id
|
||||
attr_reader :real_name
|
||||
attr_reader :animation
|
||||
|
||||
DATA = {}
|
||||
|
||||
extend ClassMethodsSymbols
|
||||
include InstanceMethods
|
||||
|
||||
def self.load; end
|
||||
def self.save; end
|
||||
|
||||
def initialize(hash)
|
||||
@id = hash[:id]
|
||||
@real_name = hash[:name] || "Unnamed"
|
||||
@animation = hash[:animation]
|
||||
end
|
||||
|
||||
# @return [String] the translated name of this battle terrain
|
||||
def name
|
||||
return _INTL(@real_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
|
||||
GameData::BattleTerrain.register({
|
||||
:id => :None,
|
||||
:name => _INTL("None")
|
||||
})
|
||||
|
||||
GameData::BattleTerrain.register({
|
||||
:id => :Electric,
|
||||
:name => _INTL("Electric"),
|
||||
:animation => "ElectricTerrain"
|
||||
})
|
||||
|
||||
GameData::BattleTerrain.register({
|
||||
:id => :Grassy,
|
||||
:name => _INTL("Grassy"),
|
||||
:animation => "GrassyTerrain"
|
||||
})
|
||||
|
||||
GameData::BattleTerrain.register({
|
||||
:id => :Misty,
|
||||
:name => _INTL("Misty"),
|
||||
:animation => "MistyTerrain"
|
||||
})
|
||||
|
||||
GameData::BattleTerrain.register({
|
||||
:id => :Psychic,
|
||||
:name => _INTL("Psychic"),
|
||||
:animation => "PsychicTerrain"
|
||||
})
|
||||
194
Data/Scripts_backup/010_Data/001_Hardcoded data/017_Target.rb
Normal file
194
Data/Scripts_backup/010_Data/001_Hardcoded data/017_Target.rb
Normal file
@@ -0,0 +1,194 @@
|
||||
# NOTE: If adding a new target, you will need to add code in several places to
|
||||
# make them work properly:
|
||||
# - def pbFindTargets
|
||||
# - def pbMoveCanTarget?
|
||||
# - def pbCreateTargetTexts
|
||||
# - def pbFirstTarget
|
||||
# - def pbTargetsMultiple?
|
||||
module GameData
|
||||
class Target
|
||||
attr_reader :id
|
||||
attr_reader :id_number
|
||||
attr_reader :real_name
|
||||
attr_reader :num_targets # 0, 1 or 2 (meaning 2+)
|
||||
attr_reader :targets_foe # Is able to target one or more foes
|
||||
attr_reader :targets_all # Crafty Shield can't protect from these moves
|
||||
attr_reader :affects_foe_side # Pressure also affects these moves
|
||||
attr_reader :long_range # Hits non-adjacent targets
|
||||
|
||||
DATA = {}
|
||||
|
||||
extend ClassMethods
|
||||
include InstanceMethods
|
||||
|
||||
def self.load; end
|
||||
def self.save; end
|
||||
|
||||
def initialize(hash)
|
||||
@id = hash[:id]
|
||||
@real_name = hash[:name] || "Unnamed"
|
||||
@num_targets = hash[:num_targets] || 0
|
||||
@targets_foe = hash[:targets_foe] || false
|
||||
@targets_all = hash[:targets_all] || false
|
||||
@affects_foe_side = hash[:affects_foe_side] || false
|
||||
@long_range = hash[:long_range] || false
|
||||
end
|
||||
|
||||
# @return [String] the translated name of this target
|
||||
def name
|
||||
return _INTL(@real_name)
|
||||
end
|
||||
|
||||
def can_choose_distant_target?
|
||||
return @num_targets == 1 && @long_range
|
||||
end
|
||||
|
||||
def can_target_one_foe?
|
||||
return @num_targets == 1 && @targets_foe
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
|
||||
# Bide, Counter, Metal Burst, Mirror Coat (calculate a target)
|
||||
GameData::Target.register({
|
||||
:id => :None,
|
||||
:id_number => 1,
|
||||
:name => _INTL("None")
|
||||
})
|
||||
|
||||
GameData::Target.register({
|
||||
:id => :User,
|
||||
:id_number => 10,
|
||||
:name => _INTL("User")
|
||||
})
|
||||
|
||||
# Aromatic Mist, Helping Hand, Hold Hands
|
||||
GameData::Target.register({
|
||||
:id => :NearAlly,
|
||||
:id_number => 100,
|
||||
:name => _INTL("Near Ally"),
|
||||
:num_targets => 1
|
||||
})
|
||||
|
||||
# Acupressure
|
||||
GameData::Target.register({
|
||||
:id => :UserOrNearAlly,
|
||||
:id_number => 200,
|
||||
:name => _INTL("User or Near Ally"),
|
||||
:num_targets => 1
|
||||
})
|
||||
|
||||
# Aromatherapy, Gear Up, Heal Bell, Life Dew, Magnetic Flux, Howl (in Gen 8+)
|
||||
GameData::Target.register({
|
||||
:id => :UserAndAllies,
|
||||
:id_number => 5,
|
||||
:name => _INTL("User and Allies"),
|
||||
:num_targets => 2,
|
||||
:long_range => true
|
||||
})
|
||||
|
||||
# Me First
|
||||
GameData::Target.register({
|
||||
:id => :NearFoe,
|
||||
:id_number => 400,
|
||||
:name => _INTL("Near Foe"),
|
||||
:num_targets => 1,
|
||||
:targets_foe => true
|
||||
})
|
||||
|
||||
# Petal Dance, Outrage, Struggle, Thrash, Uproar
|
||||
GameData::Target.register({
|
||||
:id => :RandomNearFoe,
|
||||
:id_number => 2,
|
||||
:name => _INTL("Random Near Foe"),
|
||||
:num_targets => 1,
|
||||
:targets_foe => true
|
||||
})
|
||||
|
||||
GameData::Target.register({
|
||||
:id => :AllNearFoes,
|
||||
:id_number => 4,
|
||||
:name => _INTL("All Near Foes"),
|
||||
:num_targets => 2,
|
||||
:targets_foe => true
|
||||
})
|
||||
|
||||
# For throwing a Poké Ball
|
||||
GameData::Target.register({
|
||||
:id => :Foe,
|
||||
:id_number => 9,
|
||||
:name => _INTL("Foe"),
|
||||
:num_targets => 1,
|
||||
:targets_foe => true,
|
||||
:long_range => true
|
||||
})
|
||||
|
||||
# Unused
|
||||
GameData::Target.register({
|
||||
:id => :AllFoes,
|
||||
:id_number => 6,
|
||||
:name => _INTL("All Foes"),
|
||||
:num_targets => 2,
|
||||
:targets_foe => true,
|
||||
:long_range => true
|
||||
})
|
||||
|
||||
GameData::Target.register({
|
||||
:id => :NearOther,
|
||||
:id_number => 0,
|
||||
:name => _INTL("Near Other"),
|
||||
:num_targets => 1,
|
||||
:targets_foe => true
|
||||
})
|
||||
|
||||
GameData::Target.register({
|
||||
:id => :AllNearOthers,
|
||||
:id_number => 8,
|
||||
:name => _INTL("All Near Others"),
|
||||
:num_targets => 2,
|
||||
:targets_foe => true
|
||||
})
|
||||
|
||||
# Most Flying-type moves, pulse moves (hits non-near targets)
|
||||
GameData::Target.register({
|
||||
:id => :Other,
|
||||
:id_number => 3,
|
||||
:name => _INTL("Other"),
|
||||
:num_targets => 1,
|
||||
:targets_foe => true,
|
||||
:long_range => true
|
||||
})
|
||||
|
||||
# Flower Shield, Perish Song, Rototiller, Teatime
|
||||
GameData::Target.register({
|
||||
:id => :AllBattlers,
|
||||
:id_number => 7,
|
||||
:name => _INTL("All Battlers"),
|
||||
:num_targets => 2,
|
||||
:targets_foe => true,
|
||||
:targets_all => true,
|
||||
:long_range => true
|
||||
})
|
||||
|
||||
GameData::Target.register({
|
||||
:id => :UserSide,
|
||||
:id_number => 40,
|
||||
:name => _INTL("User Side")
|
||||
})
|
||||
|
||||
# Entry hazards
|
||||
GameData::Target.register({
|
||||
:id => :FoeSide,
|
||||
:id_number => 80,
|
||||
:name => _INTL("Foe Side"),
|
||||
:affects_foe_side => true
|
||||
})
|
||||
|
||||
GameData::Target.register({
|
||||
:id => :BothSides,
|
||||
:id_number => 20,
|
||||
:name => _INTL("Both Sides"),
|
||||
:affects_foe_side => true
|
||||
})
|
||||
107
Data/Scripts_backup/010_Data/002_PBS data/001_MiscPBSData.rb
Normal file
107
Data/Scripts_backup/010_Data/002_PBS data/001_MiscPBSData.rb
Normal file
@@ -0,0 +1,107 @@
|
||||
#===============================================================================
|
||||
# Data caches.
|
||||
#===============================================================================
|
||||
class PokemonTemp
|
||||
attr_accessor :townMapData
|
||||
attr_accessor :phoneData
|
||||
attr_accessor :speciesShadowMovesets
|
||||
attr_accessor :regionalDexes
|
||||
attr_accessor :battleAnims
|
||||
attr_accessor :moveToAnim
|
||||
attr_accessor :mapInfos
|
||||
end
|
||||
|
||||
def pbClearData
|
||||
if $PokemonTemp
|
||||
$PokemonTemp.townMapData = nil
|
||||
$PokemonTemp.phoneData = nil
|
||||
$PokemonTemp.speciesShadowMovesets = nil
|
||||
$PokemonTemp.regionalDexes = nil
|
||||
$PokemonTemp.battleAnims = nil
|
||||
$PokemonTemp.moveToAnim = nil
|
||||
$PokemonTemp.mapInfos = nil
|
||||
end
|
||||
MapFactoryHelper.clear
|
||||
$PokemonEncounters.setup($game_map.map_id) if $game_map && $PokemonEncounters
|
||||
if pbRgssExists?("Data/Tilesets.rxdata")
|
||||
$data_tilesets = load_data("Data/Tilesets.rxdata")
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# Method to get Town Map data.
|
||||
#===============================================================================
|
||||
def pbLoadTownMapData
|
||||
$PokemonTemp = PokemonTemp.new if !$PokemonTemp
|
||||
if !$PokemonTemp.townMapData
|
||||
$PokemonTemp.townMapData = load_data("Data/town_map.dat")
|
||||
end
|
||||
return $PokemonTemp.townMapData
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# Method to get phone call data.
|
||||
#===============================================================================
|
||||
def pbLoadPhoneData
|
||||
$PokemonTemp = PokemonTemp.new if !$PokemonTemp
|
||||
if !$PokemonTemp.phoneData
|
||||
if pbRgssExists?("Data/phone.dat")
|
||||
$PokemonTemp.phoneData = load_data("Data/phone.dat")
|
||||
end
|
||||
end
|
||||
return $PokemonTemp.phoneData
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# Method to get Shadow Pokémon moveset data.
|
||||
#===============================================================================
|
||||
def pbLoadShadowMovesets
|
||||
$PokemonTemp = PokemonTemp.new if !$PokemonTemp
|
||||
if !$PokemonTemp.speciesShadowMovesets
|
||||
$PokemonTemp.speciesShadowMovesets = load_data("Data/shadow_movesets.dat") || []
|
||||
end
|
||||
return $PokemonTemp.speciesShadowMovesets
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# Method to get Regional Dexes data.
|
||||
#===============================================================================
|
||||
def pbLoadRegionalDexes
|
||||
$PokemonTemp = PokemonTemp.new if !$PokemonTemp
|
||||
if !$PokemonTemp.regionalDexes
|
||||
$PokemonTemp.regionalDexes = load_data("Data/regional_dexes.dat")
|
||||
end
|
||||
return $PokemonTemp.regionalDexes
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# Methods relating to battle animations data.
|
||||
#===============================================================================
|
||||
def pbLoadBattleAnimations
|
||||
$PokemonTemp = PokemonTemp.new if !$PokemonTemp
|
||||
if !$PokemonTemp.battleAnims
|
||||
if pbRgssExists?("Data/PkmnAnimations.rxdata")
|
||||
$PokemonTemp.battleAnims = load_data("Data/PkmnAnimations.rxdata")
|
||||
end
|
||||
end
|
||||
return $PokemonTemp.battleAnims
|
||||
end
|
||||
|
||||
def pbLoadMoveToAnim
|
||||
$PokemonTemp = PokemonTemp.new if !$PokemonTemp
|
||||
if !$PokemonTemp.moveToAnim
|
||||
$PokemonTemp.moveToAnim = load_data("Data/move2anim.dat") || []
|
||||
end
|
||||
return $PokemonTemp.moveToAnim
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# Method relating to map infos data.
|
||||
#===============================================================================
|
||||
def pbLoadMapInfos
|
||||
$PokemonTemp = PokemonTemp.new if !$PokemonTemp
|
||||
if !$PokemonTemp.mapInfos
|
||||
$PokemonTemp.mapInfos = load_data("Data/MapInfos.rxdata")
|
||||
end
|
||||
return $PokemonTemp.mapInfos
|
||||
end
|
||||
@@ -0,0 +1,31 @@
|
||||
#===============================================================================
|
||||
# Phone data
|
||||
#===============================================================================
|
||||
class PhoneDatabase
|
||||
attr_accessor :generics
|
||||
attr_accessor :greetings
|
||||
attr_accessor :greetingsMorning
|
||||
attr_accessor :greetingsEvening
|
||||
attr_accessor :bodies1
|
||||
attr_accessor :bodies2
|
||||
attr_accessor :battleRequests
|
||||
attr_accessor :trainers
|
||||
|
||||
def initialize
|
||||
@generics = []
|
||||
@greetings = []
|
||||
@greetingsMorning = []
|
||||
@greetingsEvening = []
|
||||
@bodies1 = []
|
||||
@bodies2 = []
|
||||
@battleRequests = []
|
||||
@trainers = []
|
||||
end
|
||||
end
|
||||
|
||||
module PhoneMsgType
|
||||
Generic = 0
|
||||
Greeting = 1
|
||||
Body = 2
|
||||
BattleRequest = 3
|
||||
end
|
||||
132
Data/Scripts_backup/010_Data/002_PBS data/003_Type.rb
Normal file
132
Data/Scripts_backup/010_Data/002_PBS data/003_Type.rb
Normal file
@@ -0,0 +1,132 @@
|
||||
module GameData
|
||||
class Type
|
||||
attr_reader :id
|
||||
attr_reader :id_number
|
||||
attr_reader :real_name
|
||||
attr_reader :special_type
|
||||
attr_reader :pseudo_type
|
||||
attr_reader :weaknesses
|
||||
attr_reader :resistances
|
||||
attr_reader :immunities
|
||||
|
||||
DATA = {}
|
||||
DATA_FILENAME = "types.dat"
|
||||
|
||||
SCHEMA = {
|
||||
"Name" => [1, "s"],
|
||||
"InternalName" => [2, "s"],
|
||||
"IsPseudoType" => [3, "b"],
|
||||
"IsSpecialType" => [4, "b"],
|
||||
"Weaknesses" => [5, "*s"],
|
||||
"Resistances" => [6, "*s"],
|
||||
"Immunities" => [7, "*s"]
|
||||
}
|
||||
|
||||
extend ClassMethods
|
||||
include InstanceMethods
|
||||
|
||||
def initialize(hash)
|
||||
@id = hash[:id]
|
||||
@id_number = hash[:id_number] || -1
|
||||
@real_name = hash[:name] || "Unnamed"
|
||||
@pseudo_type = hash[:pseudo_type] || false
|
||||
@special_type = hash[:special_type] || false
|
||||
@weaknesses = hash[:weaknesses] || []
|
||||
@weaknesses = [@weaknesses] if !@weaknesses.is_a?(Array)
|
||||
@resistances = hash[:resistances] || []
|
||||
@resistances = [@resistances] if !@resistances.is_a?(Array)
|
||||
@immunities = hash[:immunities] || []
|
||||
@immunities = [@immunities] if !@immunities.is_a?(Array)
|
||||
end
|
||||
|
||||
# @return [String] the translated name of this item
|
||||
def name
|
||||
return pbGetMessage(MessageTypes::Types, @id_number)
|
||||
end
|
||||
|
||||
def physical?; return !@special_type; end
|
||||
def special?; return @special_type; end
|
||||
|
||||
def effectiveness(other_type)
|
||||
return Effectiveness::NORMAL_EFFECTIVE_ONE if !other_type
|
||||
return Effectiveness::SUPER_EFFECTIVE_ONE if @weaknesses.include?(other_type)
|
||||
return Effectiveness::NOT_VERY_EFFECTIVE_ONE if @resistances.include?(other_type)
|
||||
return Effectiveness::INEFFECTIVE if @immunities.include?(other_type)
|
||||
return Effectiveness::NORMAL_EFFECTIVE_ONE
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
|
||||
module Effectiveness
|
||||
INEFFECTIVE = 0
|
||||
NOT_VERY_EFFECTIVE_ONE = 1
|
||||
NORMAL_EFFECTIVE_ONE = 2
|
||||
SUPER_EFFECTIVE_ONE = 4
|
||||
NORMAL_EFFECTIVE = NORMAL_EFFECTIVE_ONE ** 3
|
||||
|
||||
module_function
|
||||
|
||||
def ineffective?(value)
|
||||
return value == INEFFECTIVE
|
||||
end
|
||||
|
||||
def not_very_effective?(value)
|
||||
return value > INEFFECTIVE && value < NORMAL_EFFECTIVE
|
||||
end
|
||||
|
||||
def resistant?(value)
|
||||
return value < NORMAL_EFFECTIVE
|
||||
end
|
||||
|
||||
def normal?(value)
|
||||
return value == NORMAL_EFFECTIVE
|
||||
end
|
||||
|
||||
def super_effective?(value)
|
||||
return value > NORMAL_EFFECTIVE
|
||||
end
|
||||
|
||||
def ineffective_type?(attack_type, defend_type1, defend_type2 = nil, defend_type3 = nil)
|
||||
value = calculate(attack_type, defend_type1, defend_type2, defend_type3)
|
||||
return ineffective?(value)
|
||||
end
|
||||
|
||||
def not_very_effective_type?(attack_type, defend_type1, defend_type2 = nil, defend_type3 = nil)
|
||||
value = calculate(attack_type, defend_type1, defend_type2, defend_type3)
|
||||
return not_very_effective?(value)
|
||||
end
|
||||
|
||||
def resistant_type?(attack_type, defend_type1, defend_type2 = nil, defend_type3 = nil)
|
||||
value = calculate(attack_type, defend_type1, defend_type2, defend_type3)
|
||||
return resistant?(value)
|
||||
end
|
||||
|
||||
def normal_type?(attack_type, defend_type1, defend_type2 = nil, defend_type3 = nil)
|
||||
value = calculate(attack_type, defend_type1, defend_type2, defend_type3)
|
||||
return normal?(value)
|
||||
end
|
||||
|
||||
def super_effective_type?(attack_type, defend_type1, defend_type2 = nil, defend_type3 = nil)
|
||||
value = calculate(attack_type, defend_type1, defend_type2, defend_type3)
|
||||
return super_effective?(value)
|
||||
end
|
||||
|
||||
def calculate_one(attack_type, defend_type)
|
||||
return GameData::Type.get(defend_type).effectiveness(attack_type)
|
||||
end
|
||||
|
||||
def calculate(attack_type, defend_type1, defend_type2 = nil, defend_type3 = nil)
|
||||
mod1 = calculate_one(attack_type, defend_type1)
|
||||
mod2 = NORMAL_EFFECTIVE_ONE
|
||||
mod3 = NORMAL_EFFECTIVE_ONE
|
||||
if defend_type2 && defend_type1 != defend_type2
|
||||
mod2 = calculate_one(attack_type, defend_type2)
|
||||
end
|
||||
if defend_type3 && defend_type1 != defend_type3 && defend_type2 != defend_type3
|
||||
mod3 = calculate_one(attack_type, defend_type3)
|
||||
end
|
||||
return mod1 * mod2 * mod3
|
||||
end
|
||||
end
|
||||
31
Data/Scripts_backup/010_Data/002_PBS data/004_Ability.rb
Normal file
31
Data/Scripts_backup/010_Data/002_PBS data/004_Ability.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
module GameData
|
||||
class Ability
|
||||
attr_reader :id
|
||||
attr_reader :id_number
|
||||
attr_reader :real_name
|
||||
attr_reader :real_description
|
||||
|
||||
DATA = {}
|
||||
DATA_FILENAME = "abilities.dat"
|
||||
|
||||
extend ClassMethods
|
||||
include InstanceMethods
|
||||
|
||||
def initialize(hash)
|
||||
@id = hash[:id]
|
||||
@id_number = hash[:id_number] || -1
|
||||
@real_name = hash[:name] || "Unnamed"
|
||||
@real_description = hash[:description] || "???"
|
||||
end
|
||||
|
||||
# @return [String] the translated name of this ability
|
||||
def name
|
||||
return pbGetMessage(MessageTypes::Abilities, @id_number)
|
||||
end
|
||||
|
||||
# @return [String] the translated description of this ability
|
||||
def description
|
||||
return pbGetMessage(MessageTypes::AbilityDescs, @id_number)
|
||||
end
|
||||
end
|
||||
end
|
||||
85
Data/Scripts_backup/010_Data/002_PBS data/005_Move.rb
Normal file
85
Data/Scripts_backup/010_Data/002_PBS data/005_Move.rb
Normal file
@@ -0,0 +1,85 @@
|
||||
module GameData
|
||||
class Move
|
||||
attr_reader :id
|
||||
attr_reader :id_number
|
||||
attr_reader :real_name
|
||||
attr_reader :function_code
|
||||
attr_reader :base_damage
|
||||
attr_reader :type
|
||||
attr_reader :category
|
||||
attr_reader :accuracy
|
||||
attr_reader :total_pp
|
||||
attr_reader :effect_chance
|
||||
attr_reader :target
|
||||
attr_reader :priority
|
||||
attr_reader :flags
|
||||
attr_reader :real_description
|
||||
|
||||
DATA = {}
|
||||
DATA_FILENAME = "moves.dat"
|
||||
|
||||
extend ClassMethods
|
||||
include InstanceMethods
|
||||
|
||||
def initialize(hash)
|
||||
@id = hash[:id]
|
||||
@id_number = hash[:id_number] || -1
|
||||
@real_name = hash[:name] || "Unnamed"
|
||||
@function_code = hash[:function_code]
|
||||
@base_damage = hash[:base_damage]
|
||||
@type = hash[:type]
|
||||
@category = hash[:category]
|
||||
@accuracy = hash[:accuracy]
|
||||
@total_pp = hash[:total_pp]
|
||||
@effect_chance = hash[:effect_chance]
|
||||
@target = hash[:target]
|
||||
@priority = hash[:priority]
|
||||
@flags = hash[:flags]
|
||||
@real_description = hash[:description] || "???"
|
||||
end
|
||||
|
||||
# @return [String] the translated name of this move
|
||||
def name
|
||||
return pbGetMessage(MessageTypes::Moves, @id_number)
|
||||
end
|
||||
|
||||
# @return [String] the translated description of this move
|
||||
def description
|
||||
return pbGetMessage(MessageTypes::MoveDescriptions, @id_number)
|
||||
end
|
||||
|
||||
def physical?
|
||||
return false if @base_damage == 0
|
||||
return @category == 0 if Settings::MOVE_CATEGORY_PER_MOVE
|
||||
return GameData::Type.get(@type).physical?
|
||||
end
|
||||
|
||||
def special?
|
||||
return false if @base_damage == 0
|
||||
return @category == 1 if Settings::MOVE_CATEGORY_PER_MOVE
|
||||
return GameData::Type.get(@type).special?
|
||||
end
|
||||
|
||||
def hidden_move?
|
||||
GameData::Item.each do |i|
|
||||
return true if i.is_HM? && i.move == @id
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# Deprecated methods
|
||||
#===============================================================================
|
||||
# @deprecated This alias is slated to be removed in v20.
|
||||
def pbGetMoveData(move_id, move_data_type = -1)
|
||||
Deprecation.warn_method('pbGetMoveData', 'v20', 'GameData::Move.get(move_id)')
|
||||
return GameData::Move.get(move_id)
|
||||
end
|
||||
|
||||
# @deprecated This alias is slated to be removed in v20.
|
||||
def pbIsHiddenMove?(move)
|
||||
Deprecation.warn_method('pbIsHiddenMove?', 'v20', 'GameData::Move.get(move).hidden_move?')
|
||||
return GameData::Move.get(move).hidden_move?
|
||||
end
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user