1798 lines
68 KiB
Ruby
1798 lines
68 KiB
Ruby
#==============================================================================
|
|
# LonaCraft - 100_Homes.rb
|
|
# 1.1.2: Three-bank-house picker for NoerHome, with bought entries hidden;
|
|
# preserves NoerHome purchase code and LonaCraft save state independently.
|
|
# What it does:
|
|
# * Homes, one LOCATIONS row each, bought (:mode :buy, the default) or
|
|
# rented by the week (:mode :rent). Switch the whole feature off with
|
|
# ENABLED = false (no door, no offer, no map, no room clearing; furniture
|
|
# is then allowed nowhere).
|
|
# * Two kinds of home:
|
|
# - a house with its own map (:interior): a map file in the mod
|
|
# (Maps/*.rvdata2, the game's own tiles and tileset), entered through a
|
|
# door event (:door). Registered at DataManager.load_mod_database the way
|
|
# the game registers mod maps (DataManager.extra_map_register,
|
|
# 5_DataManager.rb:390-405, used by RolePlayS 0_CORE.rb:138-139):
|
|
# $data_mapinfos[<file path>] with .name, .filename and a FIXED runtime
|
|
# map number (MAP_ID_BASE + row) instead of "highest + 1", so placed
|
|
# furniture (90_Furniture.rb records the map number) stays in its home
|
|
# whatever other mods are loaded. Game_Map#setup loads
|
|
# $data_mapinfos[map_id].filename (31_Game_Map.rb:170-172), so the file
|
|
# path is the map id of the transfer; nothing else is redirected. Also
|
|
# listed in $data_tag_maps["LonaCraftHome"] / ["LonaCraftHome_<id>"].
|
|
# - a room on an existing game map (:map + :room_seed): the room is the
|
|
# set of floor tiles reached from :room_seed (4 directions, the map's
|
|
# own passage flags, never through :door_tiles, inside :room_bounds),
|
|
# plus the :tile_overrides tiles; worked out at every setup of that map.
|
|
# While owned (or rented), at every setup: :tile_overrides tiles take
|
|
# the layers of their reference tile, events on :remove_event_tiles go,
|
|
# every map event standing in the room goes (names in :keep stay;
|
|
# "-point-" events, which the game's scripts look up by name, stay as
|
|
# invisible points, moved by :move_points), and decor tiles in the room
|
|
# take the :floor_ref floor. The map file itself is never changed; once
|
|
# the rent runs out the next setup shows the room as the game made it.
|
|
# * Door of a house (Game_Map#setup_event_hack, as the town stations in
|
|
# 90_Furniture.rb). In this game the city of Noer is the world map
|
|
# (OvermapMain): every Noer building is a point on it that leads into its
|
|
# own map, so the shack's door is such a point in the bottom-left corner
|
|
# of the city. Owned: "Enter" (Homes.enter, the steps of the game's
|
|
# change_map_enter_tag, 34_Functions_ChangeMap.rb:200-215). Not owned:
|
|
# "Locked. The bank sells this house." Inside, the map's own BIOS,
|
|
# -point-StartPoint and -point-ExitPoint (change_map_tag_map_exit) work as
|
|
# in the game's building maps.
|
|
# * Sellers: each seller NPC's game script is redirected through
|
|
# $mod_load_script (102_ScriptImport.rb:63) to HCGframes/<script name>,
|
|
# which calls lonacraft_home_seller: it runs the script the NPC ran before
|
|
# (game or another mod) unchanged. The first menu of that script that
|
|
# lists the seller's marker option (Barter) gets the home lines at the
|
|
# end (Buy, or Rent / Extend / Rent status / Collect stored belongings),
|
|
# whether the script shows it through show_npc_info or call_msg. Picking
|
|
# one runs it here; the choice is then cleared, so the script's own case
|
|
# finds nothing and it ends as on Cancel.
|
|
# * Rent: the price is per week (RENT_DAYS days) in :coin. The end is kept
|
|
# as a $game_date.dateAmt value (half days: Game_Date::DAY_LENGTH = 2 per
|
|
# day, 123_Game_Date.rb:9; $game_date.day_count is never advanced by the
|
|
# game). Rent runs out when dateAmt passes it. Checked at every map setup,
|
|
# every time the game date moves (Game_Date#shift, used by every nap,
|
|
# 70_Game_Map_DayNightAndOvermap.rb:14, and addDays / oneDayForward) and
|
|
# when the seller's menu opens. Running out: every placed piece in the
|
|
# room goes into the stored list (a chest's contents too, its box is
|
|
# freed), a popup tells Lona, and the seller hands it all back later.
|
|
# * Sleeping in an owned/rented room: an inn map's NapEvent script
|
|
# (:nap_script, e.g. NoerTavern_Nap.rb, which turns Lona out without a
|
|
# room key) is redirected the same way. It always runs the inn's own
|
|
# script; while Lona stands inside the rented room the room keys count as
|
|
# held and none is taken, so she gets the inn's paid sleep (meal, bath,
|
|
# full restore) and is never turned out for a missing key; anywhere else
|
|
# on the map the inn's script runs unchanged. Houses (the shack) have no
|
|
# NapEvent: a placed bed runs Command_AreaNap.rb -> handleNap, the plain
|
|
# field nap (no meal; stamina from satiety, satiety goes down).
|
|
# * Inns (board R16, docs/RESEARCH_INNS.md, owner 2026-10-06): every inn of
|
|
# the game has a room rented like the Noer one: Pirate's Bane (Map081),
|
|
# Doom Fortress (Map097), Fish Town (Map117), the south front-line camp
|
|
# (Map135) and the Coastal Fortress (Map148), each keeper a SELLERS row and
|
|
# each inn's nap script a :nap_script. Fish Town's keeper shows her menu
|
|
# through a text key (call_msg("TagMapFishTownInn:InnKeeper/Begin")) whose
|
|
# text holds the \optB list: the call_msg alias resolves such keys while
|
|
# home lines are pending and shows the extended text through a runtime
|
|
# key. A room's rent prompt is "<id>/rent_weeks" when that text exists,
|
|
# else "common/rent_weeks" (Noer's).
|
|
# * Wall tiles (wall_tiles / wall_allowed_at?): the impassable tile above
|
|
# each floor tile of an owned place, minus :window_tiles, for wall-hung
|
|
# decorations.
|
|
# * Save data (plain types in the game's own system data, no save hook;
|
|
# 60_Skill.rb): $game_system.lonacraft_data["homes"] = {id => true},
|
|
# ["rent"] = {id => {"until" => dateAmt}}, ["stored"] = {id => [[item_name, count], ...]}.
|
|
# * API: Homes.enabled?, owned?(id) (true while rented too), owned_ids,
|
|
# rented?(id), rent_days_left(id), pay_rent(id, weeks), expire!(id),
|
|
# stored(id), collect_stored(id), location(id), map_id_for(id),
|
|
# map_key(id), home_at_map?(map), furniture_allowed?(map),
|
|
# furniture_allowed_at?(map, x, y), inside_owned_area?(map, x, y),
|
|
# floor_tiles(map, id), wall_tiles(map, id), wall_allowed_at?(map, x, y),
|
|
# room_tiles(map, id), buy(id), enter(id), offers_for(seller),
|
|
# debug_own_all.
|
|
#==============================================================================
|
|
module LonaCraft
|
|
module Homes
|
|
# Owner option: homes on/off.
|
|
ENABLED = true
|
|
|
|
TEXT = "LonaCraft:Homes:"
|
|
COIN = "ItemCoin3" # Gold Coin, the default :coin
|
|
MAP_ID_BASE = 9001 # runtime map number of LOCATIONS[0]; row n gets MAP_ID_BASE + n
|
|
TAG = "LonaCraftHome" # $data_tag_maps key listing every home map
|
|
POINT_RE = /\A-point-/ # storypoint events (Game_Map#setup_storypoint_map)
|
|
RENT_DAYS = 7 # one rent week
|
|
RENT_WEEKS = [1, 2, 4] # the choices when paying rent (Homes.txt common/rent_weeks)
|
|
DEBUG_RENT_WEEKS = 52 # Numpad 5 (95_Debug.rb)
|
|
# Buy-homes mirrored into $story_stats for cloud restore (lonacraft_data
|
|
# is not serialized online). Same ids as 101_NoerHomeThreeHouses BANK_HOUSE_IDS.
|
|
CLOUD_BUY_IDS = ["noer_shack", "noer_stonehouse"]
|
|
STORY_HOME_PREFIX = "LonaCraftHome_"
|
|
|
|
# Seller key => [the game script that NPC runs, text key of the option
|
|
# that marks that NPC's main menu]. HCGframes/<script file name> in the
|
|
# mod replaces the script (lonacraft_home_seller below).
|
|
SELLERS = {
|
|
# Maani, the bank clerk who keeps the storage (NoerBank -point-Maani);
|
|
# her menu is show_npc_info(..., "\\optB[...]"), NoerBankMaani.rb:10-22
|
|
"NoerBankMaani" => ["Data/HCGframes/event/NoerBankMaani.rb", "commonNPC:commonNPC/Barter"],
|
|
# Boss Mama, the Noer tavern keeper (NoerTavern -point-TavernWaifu);
|
|
# her menu is call_msg("\\optB[...]"), NoerTavernWaifu.rb:202-216
|
|
"NoerTavernWaifu" => ["Data/HCGframes/event/NoerTavernWaifu.rb", "commonNPC:commonNPC/Barter"],
|
|
# R16 inn keepers (docs/RESEARCH_INNS.md 1, 5): call_msg("\\optB[...]")
|
|
"PirateBaneInnKeeper" => ["Data/HCGframes/event/PirateBaneInnKeeper.rb", "commonNPC:commonNPC/Barter"],
|
|
"DoomFortressInnKeeper" => ["Data/HCGframes/event/DoomFortressInnKeeper.rb", "commonNPC:commonNPC/Barter"],
|
|
# menu is a text key (FishTownInnKeeper.rb:12) whose \optB has its own
|
|
# words: no marker (the UKR text names Barter differently there than in commonNPC/Barter)
|
|
"FishTownInnKeeper" => ["Data/HCGframes/event/FishTownInnKeeper.rb", nil],
|
|
"InnKeeper_SouthFL_INN" => ["Data/HCGframes/event/InnKeeper_SouthFL_INN.rb", "commonNPC:commonNPC/Barter"],
|
|
"NorthFL_INN_Keeper" => ["Data/HCGframes/event/NorthFL_INN_Keeper.rb", "commonNPC:commonNPC/Barter"]
|
|
}
|
|
|
|
# One row per place.
|
|
# :id key in the save
|
|
# :name text key in Text/<lang>/Homes.txt (the place's name)
|
|
# :mode :buy (default, owned for good) or :rent (per week)
|
|
# :price coins to buy, or coins per rent week
|
|
# :coin item name of the coin (default COIN, Gold Coin)
|
|
# :seller SELLERS key: whose menu offers it
|
|
# :clear_existing true: the place holds the game's own objects, which
|
|
# are removed while it is owned (rooms, see above)
|
|
# A house with its own map:
|
|
# :door [map name, x, y, [character sheet, index, direction, pattern]]
|
|
# x, y are tiles of that map; move the door by editing them.
|
|
# On the world map the door is a point like the game's own
|
|
# buildings (below characters, walk onto it, action key);
|
|
# on any other map it stands like an event in a wall.
|
|
# :interior [map file in the mod, display-name text key, entry x, entry y]
|
|
# entry x, y = the map's -point-StartPoint (the BIOS puts Lona there).
|
|
# A room on an existing game map:
|
|
# :map the game map's name (MapInfos)
|
|
# :room_seed [x, y] a floor tile inside the room
|
|
# :room_bounds [x1, y1, x2, y2] safety box (inclusive); the room never leaves it
|
|
# :door_tiles [[x, y], ...] tiles the room stops at (its door, a blocked stair)
|
|
# :keep event names in the room that are left as they are
|
|
# :move_points {"-point-Name" => [x, y]} room points moved out of the room
|
|
# :tile_overrides [[x, y, ref_x, ref_y], ...] tiles that take all four
|
|
# layers of the reference tile (baked furniture); they belong to the room
|
|
# :remove_event_tiles [[x, y], ...] map events on these tiles go too (outside the room)
|
|
# :floor_ref [x, y] floor tile whose layers replace decor tiles in the room
|
|
# :floor_layers [z, ...] the layers :floor_ref compares and copies
|
|
# (default [0, 1, 2]; [2] keeps a layer-1 carpet border and
|
|
# clears only the layer-2 clutter)
|
|
# :nap_script the map NapEvent's script; inside the room it runs with
|
|
# the :nap_keys (item names or $data_items ids) counted as
|
|
# held and never taken
|
|
# :window_tiles [[x, y], ...] wall tiles that take no wall decoration
|
|
# :floor_seed / :floor_bounds (houses) floor flood fill for wall_tiles
|
|
LOCATIONS = [
|
|
{:id => "noer_shack", :name => "noer_shack/name", :price => 5, :seller => "NoerBankMaani",
|
|
# bottom-left corner of Noer on the world map: the last house tile
|
|
# inside the wall, far from the east (40,99) and north (31,95) gates
|
|
:door => ["OvermapMain", 23, 100, ["!World Map 02", 0, 8, 0]],
|
|
# one empty room (6 x 4 floor, weathered boards) built from the middle
|
|
# room of NoerTransHouse's left building (Data/Map195)
|
|
:interior => ["Maps/NoerShack.rvdata2", "noer_shack/display", 15, 17],
|
|
# floor of the room (wall_tiles): 24 tiles x 11..16, y 13..16 and the
|
|
# stairs (15,17); the two windows are A3/A4 tiles at x 12 and 15, y 11..12
|
|
:floor_seed => [13, 14], :floor_bounds => [11, 13, 16, 17],
|
|
:window_tiles => [[12, 11], [12, 12], [15, 11], [15, 12]],
|
|
:clear_existing => false},
|
|
# The right one of the two rooms at the top-left of the Noer tavern
|
|
# (Data/Map059 NoerTavern; the left one is Cocona's). Floor 10 tiles:
|
|
# (32..34,29) (31..34,30) (31,31) (33,31) (31,32), plus the table tile
|
|
# (31,29) once cleared. Its door is the WoodenDoorSide4 event at
|
|
# (31,33); (33,32) is the MapBlockBox that closes the stair to
|
|
# NoerTavern2F. Room events: -point-WakeUp (the inn bed,
|
|
# Command_AreaNap.rb), EV087 (the water bucket, Command_AreaWater.rb),
|
|
# -point-SexPoint2.
|
|
{:id => "noer_inn_room", :name => "noer_inn_room/name", :mode => :rent,
|
|
:price => 2, :coin => "ItemCoin2", :seller => "NoerTavernWaifu",
|
|
:map => "NoerTavern",
|
|
:room_seed => [32, 30], :room_bounds => [30, 27, 35, 33],
|
|
:door_tiles => [[31, 33], [33, 32]],
|
|
:keep => [],
|
|
# the game places Lona on these points (WakeUp after capture,
|
|
# 34_Functions_ChangeMap.rb:74; SexPoint for scenes,
|
|
# 28_Functions_Chcg_Events.rb:1002-1009), so they move to walkable
|
|
# corridor tiles just below the room's door instead of blocking it
|
|
:move_points => {"-point-WakeUp" => [31, 34], "-point-SexPoint2" => [32, 34]},
|
|
# the small table: a baked tile (layer 1, A2 3198 on floor 1563) at
|
|
# (31,29); (31,30) below it is the same floor with the same wall shadow
|
|
:tile_overrides => [[31, 29, 31, 30]],
|
|
# the wall torch above the table: event EV024 (!_fire, give_light
|
|
# "torch_weak") on the wall tile (31,28); its light goes with it
|
|
:remove_event_tiles => [[31, 28]],
|
|
:floor_ref => [32, 30],
|
|
# the window on the back wall (layer 2 tile 860), no wall decorations
|
|
:window_tiles => [[33, 27]],
|
|
:nap_script => "Data/HCGframes/event/NoerTavern_Nap.rb",
|
|
# the inn's room keys: while Lona sleeps inside the rented room the
|
|
# nap script sees them as held and cannot take one
|
|
# (NoerTavern_Nap.rb:117, 125, 129-130)
|
|
:nap_keys => ["ItemNoerTavernNapKey", 106],
|
|
:clear_existing => true},
|
|
# R16: Pirate's Bane inn (Data/Map081 PirateBaneInn), the paid bedroom (the
|
|
# right one of the three cells at the top; the other two hold sleeping
|
|
# customers EV23/EV24). Floor 5 tiles (41,20..22) (42,21..22) plus the
|
|
# small table (42,20). Doors: WoodenDoorSide4 EV6 (41,23), EV4 (42,23).
|
|
# Room events: -point-WakeUp EV11 and -point-SexPoint2 EV27 (moved),
|
|
# the bed head MapBlockBox EV38 (goes).
|
|
{:id => "piratebane_inn_room", :name => "piratebane_inn_room/name", :mode => :rent,
|
|
:price => 3, :coin => "ItemCoin2", :seller => "PirateBaneInnKeeper",
|
|
:map => "PirateBaneInn",
|
|
:room_seed => [41, 21], :room_bounds => [40, 19, 43, 23],
|
|
:door_tiles => [[41, 23], [42, 23]],
|
|
:keep => [],
|
|
:move_points => {"-point-WakeUp" => [41, 24], "-point-SexPoint2" => [42, 24]},
|
|
# the small table (A2 3198 on floor 1590)
|
|
:tile_overrides => [[42, 20, 42, 21]],
|
|
:remove_event_tiles => [],
|
|
# no :floor_ref: the door curtains (layer 2, 41,22 / 42,22) stay
|
|
:window_tiles => [],
|
|
:nap_script => "Data/HCGframes/event/PirateBaneInn_Nap.rb",
|
|
# PirateBaneInn_Nap.rb:128, 133-134 (by name)
|
|
:nap_keys => ["ItemPirateBaneInnNapKey", 114],
|
|
:clear_existing => true},
|
|
# R16: Doom Fortress inn (Data/Map097 DoomFortressInn), the middle cell of
|
|
# the three at the top: 2 x 2 floor + the passage to its door EV5
|
|
# (30,26), plus the small table (30,22). Room events: -point-WakeUp EV23,
|
|
# -point-SexPoint2 EV15 (moved), the bed head MapBlockBox EV24 (goes).
|
|
{:id => "doomfortress_inn_room", :name => "doomfortress_inn_room/name", :mode => :rent,
|
|
:price => 2, :coin => "ItemCoin2", :seller => "DoomFortressInnKeeper",
|
|
:map => "DoomFortressInn",
|
|
:room_seed => [29, 22], :room_bounds => [27, 20, 31, 26],
|
|
:door_tiles => [[30, 26]],
|
|
:keep => [],
|
|
:move_points => {"-point-WakeUp" => [29, 27], "-point-SexPoint2" => [31, 27]},
|
|
:tile_overrides => [[30, 22, 30, 23]],
|
|
:remove_event_tiles => [],
|
|
:window_tiles => [],
|
|
:nap_script => "Data/HCGframes/event/DoomFortressInn_Nap.rb",
|
|
# DoomFortressInn_Nap.rb:131, 136-137
|
|
:nap_keys => ["ItemDoomFortressInnNapKey", 116],
|
|
:clear_existing => true},
|
|
# R16: Fish Town inn (Data/Map117 FishTownInn), the bottom-left room: 3 x 3
|
|
# floor with the small table (22,21); door EV34 (24,23). Room events:
|
|
# -point-WakeUp EV63, -point-SexPoint4 EV64 (moved), the bed head
|
|
# LinkBox EV62 and the water bucket EV1 (go).
|
|
{:id => "fishtown_inn_room", :name => "fishtown_inn_room/name", :mode => :rent,
|
|
:price => 4, :coin => "ItemCoin2", :seller => "FishTownInnKeeper",
|
|
:map => "FishTownInn",
|
|
:room_seed => [22, 22], :room_bounds => [20, 19, 24, 24],
|
|
:door_tiles => [[24, 23]],
|
|
:keep => [],
|
|
:move_points => {"-point-WakeUp" => [25, 22], "-point-SexPoint4" => [25, 21]},
|
|
:tile_overrides => [[22, 21, 22, 22]],
|
|
:remove_event_tiles => [],
|
|
# floor 1595: clears the layer-2 clutter at (21,23) and (23,22);
|
|
# layer 2 only, so (23,22) keeps its own floor 1603
|
|
:floor_ref => [22, 23], :floor_layers => [2],
|
|
:window_tiles => [],
|
|
:nap_script => "Data/HCGframes/event/FishTownInn_Nap.rb",
|
|
# FishTownInn_Nap.rb:129, 136-137
|
|
:nap_keys => ["ItemFishTownInnNapKey", 119],
|
|
:clear_existing => true},
|
|
# R16: south front-line camp inn (Data/Map135 SouthFL_INN), the top-left
|
|
# room; door EV22 (16,22). (13,22) is the torch stand (EV56, its light
|
|
# goes), made floor. Room events: -point-WakeUp EV19, -point-SexPoint2
|
|
# EV32 (moved), the bed head MapBlockBox EV20 (goes).
|
|
{:id => "southfl_inn_room", :name => "southfl_inn_room/name", :mode => :rent,
|
|
:price => 8, :coin => "ItemCoin1", :seller => "InnKeeper_SouthFL_INN",
|
|
:map => "SouthFL_INN",
|
|
:room_seed => [14, 21], :room_bounds => [12, 19, 16, 23],
|
|
:door_tiles => [[16, 22]],
|
|
:keep => [],
|
|
:move_points => {"-point-WakeUp" => [17, 22], "-point-SexPoint2" => [18, 22]},
|
|
:tile_overrides => [[13, 22, 13, 21]],
|
|
:remove_event_tiles => [],
|
|
# the carpet is a layer-1 autotile: only layer 2 (clutter 627, 11) is cleared
|
|
:floor_ref => [14, 21], :floor_layers => [2],
|
|
:window_tiles => [],
|
|
:nap_script => "Data/HCGframes/event/SouthFL_INN_Nap.rb",
|
|
# SouthFL_INN_Nap.rb:122-123
|
|
:nap_keys => ["ItemSouthFL_INN_Key", 125],
|
|
:clear_existing => true},
|
|
# R16: Coastal Fortress inn (Data/Map148 NorthFL_INN), the right one of
|
|
# the three cells at the top: 2 x 2 + the passage to its door EV19
|
|
# (33,18), plus the small table (32,14). The inn bed -point-WakeUp2 EV6
|
|
# stays as an invisible point (nothing on this map looks it up; only
|
|
# NoerArenaB1_Begin.rb:213, another map); -point-SexPoint2 EV36 moves;
|
|
# the water bucket EV23 goes.
|
|
{:id => "northfl_inn_room", :name => "northfl_inn_room/name", :mode => :rent,
|
|
:price => 1, :coin => "ItemCoin2", :seller => "NorthFL_INN_Keeper",
|
|
:map => "NorthFL_INN",
|
|
:room_seed => [31, 14], :room_bounds => [30, 12, 34, 18],
|
|
:door_tiles => [[33, 18]],
|
|
:keep => [],
|
|
:move_points => {"-point-SexPoint2" => [33, 19]},
|
|
:tile_overrides => [[32, 14, 32, 15]],
|
|
# the wall torch above the table (EV43, give_light "torch_weak")
|
|
:remove_event_tiles => [[32, 13]],
|
|
:floor_ref => [32, 15],
|
|
:window_tiles => [],
|
|
:nap_script => "Data/HCGframes/event/NorthFL_INN_Nap.rb",
|
|
# NorthFL_INN_Nap.rb:167, 172-173
|
|
:nap_keys => ["ItemNorthFL_INN_Key", 129],
|
|
:clear_existing => true},
|
|
{:id => "noer_stonehouse", :name => "noer_stonehouse/name", :price => 15, :seller => "NoerBankMaani",
|
|
# near the centre of Noer on the world map: a free house tile two
|
|
# left of the tavern (33,100), below the back street (31,97)
|
|
:door => ["OvermapMain", 31, 100, ["!World Map 02", 3, 8, 1]],
|
|
# one empty room (8 x 5 floor, grey flagstone, grey dressed-stone
|
|
# walls) laid out like the shack, stairs at the bottom
|
|
:interior => ["Maps/NoerStoneHouse.rvdata2", "noer_stonehouse/display", 15, 18],
|
|
# floor of the room (wall_tiles): 40 tiles x 11..18, y 13..17 and the
|
|
# stairs (15,18); the two windows are A3/A4 tiles at x 12 and 17, y 11..12
|
|
:floor_seed => [14, 15], :floor_bounds => [11, 13, 18, 18],
|
|
:window_tiles => [[12, 11], [12, 12], [17, 11], [17, 12]],
|
|
:clear_existing => false}
|
|
]
|
|
|
|
@ids = {} # location id => runtime map number (houses)
|
|
@keys = {} # location id => $data_mapinfos key, the map file path (houses)
|
|
@previous = {} # game script => script it ran before LonaCraft
|
|
@static_rooms = {} # location id => room tiles worked out from the map file
|
|
@notices = [] # popup text keys waiting for the map scene
|
|
@providers = {} # seller => [proc returning [[label, proc], ...]] (170_Maid.rb)
|
|
|
|
def self.enabled?
|
|
ENABLED ? true : false
|
|
end
|
|
|
|
# NoerHome owns its own house payment; LonaCraft handles the other two.
|
|
# Look at ModManager, NOT load order: NoerHome might be loaded after
|
|
# LonaCraft and its ruby constants / config might not exist yet.
|
|
# When NoerHome is disabled, LonaCraft's original bank lines return.
|
|
def self.noerhome_active?
|
|
return false unless defined?($mod_manager) && $mod_manager && $mod_manager.respond_to?(:mods)
|
|
mod = $mod_manager.mods["NoerHome"]
|
|
return false unless mod && mod.respond_to?(:enabled) && mod.enabled
|
|
# When NoerHome has loaded its own module configuration, honour
|
|
# mod.cfg's enabled=false setting too.
|
|
if defined?($noer_home_config) && $noer_home_config
|
|
cfg = $noer_home_config["noer_home"] rescue nil
|
|
return false if cfg && cfg["enabled"].to_s == "false"
|
|
end
|
|
true
|
|
rescue => e
|
|
p "LonaCraft Homes NoerHome check error #{e.class} #{e.message}"
|
|
false
|
|
end
|
|
|
|
def self.text_key(key)
|
|
"#{TEXT}#{key}"
|
|
end
|
|
|
|
def self.text(key)
|
|
$game_text[text_key(key)].to_s
|
|
end
|
|
|
|
def self.location(id)
|
|
return nil if id.nil?
|
|
LOCATIONS.find{|loc| loc[:id] == id.to_s }
|
|
end
|
|
|
|
def self.rent?(loc)
|
|
!loc.nil? && loc[:mode] == :rent
|
|
end
|
|
|
|
def self.room?(loc)
|
|
!loc.nil? && !loc[:map].nil? && loc[:room_seed].is_a?(Array)
|
|
end
|
|
|
|
def self.coin_of(loc)
|
|
$data_ItemName[(loc[:coin] || COIN).to_s]
|
|
end
|
|
|
|
# true when the place can be used this session (house map registered,
|
|
# or a room on a game map)
|
|
def self.available?(loc)
|
|
return false if loc.nil?
|
|
return true if room?(loc)
|
|
@keys[loc[:id]] ? true : false
|
|
end
|
|
|
|
#----------------------------------------------------------------------
|
|
# Save data ($game_system.lonacraft_data, 60_Skill.rb)
|
|
#----------------------------------------------------------------------
|
|
def self.root
|
|
return nil if $game_system.nil? || !$game_system.respond_to?(:lonacraft_data)
|
|
$game_system.lonacraft_data
|
|
end
|
|
|
|
def self.section(name)
|
|
d = root
|
|
return nil if d.nil?
|
|
d[name] = {} unless d[name].is_a?(Hash)
|
|
d[name]
|
|
end
|
|
|
|
def self.data
|
|
section("homes")
|
|
end
|
|
|
|
def self.story_home_key(id)
|
|
"#{STORY_HOME_PREFIX}#{id}"
|
|
end
|
|
|
|
def self.cloud_buy_id?(id)
|
|
CLOUD_BUY_IDS.include?(id.to_s)
|
|
end
|
|
|
|
def self.story_home_bought?(id)
|
|
return false unless cloud_buy_id?(id)
|
|
return false unless defined?($story_stats) && $story_stats
|
|
$story_stats[story_home_key(id)].to_i != 0
|
|
rescue StandardError
|
|
false
|
|
end
|
|
|
|
def self.mirror_story_home(id, flag)
|
|
return unless cloud_buy_id?(id)
|
|
return unless defined?($story_stats) && $story_stats && $story_stats.respond_to?(:[]=)
|
|
key = story_home_key(id)
|
|
if flag
|
|
$story_stats[key] = 1
|
|
else
|
|
$story_stats[key] = 0
|
|
end
|
|
rescue StandardError
|
|
end
|
|
|
|
# Pull cloud-bought homes from $story_stats into lonacraft_data["homes"].
|
|
def self.rehydrate_from_story!
|
|
h = data
|
|
return false if h.nil?
|
|
changed = false
|
|
CLOUD_BUY_IDS.each{|id|
|
|
next unless story_home_bought?(id)
|
|
next if h[id] == true
|
|
h[id] = true
|
|
changed = true
|
|
}
|
|
changed
|
|
rescue StandardError
|
|
false
|
|
end
|
|
|
|
# Push already-owned buy homes into $story_stats so a local save that
|
|
# never mirrored still reaches the cloud profile.
|
|
def self.sync_story_from_data!
|
|
h = data
|
|
return false if h.nil?
|
|
CLOUD_BUY_IDS.each{|id|
|
|
mirror_story_home(id, h[id] == true)
|
|
}
|
|
true
|
|
rescue StandardError
|
|
false
|
|
end
|
|
|
|
def self.sync_cloud_homes!
|
|
rehydrate_from_story!
|
|
sync_story_from_data!
|
|
rescue StandardError
|
|
false
|
|
end
|
|
|
|
# true while the place is Lona's: bought, or rent not run out
|
|
def self.owned?(id)
|
|
loc = location(id)
|
|
return false if loc.nil?
|
|
return rented?(id) if rent?(loc)
|
|
rehydrate_from_story! if cloud_buy_id?(id)
|
|
h = data
|
|
return false if h.nil?
|
|
h[id.to_s] == true
|
|
end
|
|
|
|
def self.owned_ids
|
|
LOCATIONS.map{|loc| loc[:id] }.select{|id| owned?(id) }
|
|
end
|
|
|
|
def self.set_owned(id, flag = true)
|
|
h = data
|
|
return false if h.nil? || location(id).nil?
|
|
if flag
|
|
h[id.to_s] = true
|
|
else
|
|
h.delete(id.to_s)
|
|
end
|
|
mirror_story_home(id, flag)
|
|
true
|
|
end
|
|
|
|
# :ok, :no_gold, :owned; :unknown for an id that is not a :buy place
|
|
# (or homes are off). +interp+: the event's interpreter, for the game's
|
|
# "coins lost" popup; without one the coins are taken silently.
|
|
def self.buy(id, interp = nil)
|
|
loc = location(id)
|
|
return :unknown if loc.nil? || rent?(loc) || !enabled? || data.nil?
|
|
return :owned if owned?(id)
|
|
return :no_gold unless take_coins(loc, loc[:price].to_i, interp)
|
|
set_owned(id, true)
|
|
clear_existing!(id) if loc[:clear_existing]
|
|
:ok
|
|
end
|
|
|
|
# false when Lona has fewer than +amount+ of the place's coin
|
|
def self.take_coins(loc, amount, interp)
|
|
return true if amount <= 0
|
|
coin = coin_of(loc)
|
|
return false if coin.nil? || $game_party.item_number(coin) < amount
|
|
if interp && interp.respond_to?(:optain_lose_item)
|
|
interp.optain_lose_item(coin, amount)
|
|
else
|
|
$game_party.lose_item(coin, amount)
|
|
end
|
|
true
|
|
end
|
|
|
|
#----------------------------------------------------------------------
|
|
# Rent
|
|
#----------------------------------------------------------------------
|
|
def self.date_now
|
|
$game_date.nil? ? 0 : $game_date.dateAmt.to_i
|
|
end
|
|
|
|
def self.units_per_day
|
|
defined?(Game_Date::DAY_LENGTH) ? Game_Date::DAY_LENGTH : 2
|
|
end
|
|
|
|
def self.rent_record(id)
|
|
r = section("rent")
|
|
return nil if r.nil?
|
|
rec = r[id.to_s]
|
|
rec.is_a?(Hash) ? rec : nil
|
|
end
|
|
|
|
def self.rented?(id)
|
|
rec = rent_record(id)
|
|
return false if rec.nil?
|
|
date_now <= rec["until"].to_i
|
|
end
|
|
|
|
# whole days left (0 when not rented)
|
|
def self.rent_days_left(id)
|
|
return 0 unless rented?(id)
|
|
per = units_per_day
|
|
left = rent_record(id)["until"].to_i - date_now
|
|
(left + per - 1) / per
|
|
end
|
|
|
|
# Pays +weeks+ of rent: :ok, :no_coins, :unknown. Paying ahead adds to
|
|
# the current end; paying after it ran out starts from now.
|
|
def self.pay_rent(id, weeks, interp = nil)
|
|
loc = location(id)
|
|
weeks = weeks.to_i
|
|
return :unknown if loc.nil? || !rent?(loc) || !enabled? || weeks < 1
|
|
r = section("rent")
|
|
return :unknown if r.nil?
|
|
was = rented?(id)
|
|
return :no_coins unless take_coins(loc, loc[:price].to_i * weeks, interp)
|
|
base = was ? rent_record(id)["until"].to_i : date_now
|
|
r[id.to_s] = {"until" => base + weeks * RENT_DAYS * units_per_day}
|
|
clear_existing!(id) if !was && loc[:clear_existing]
|
|
:ok
|
|
end
|
|
|
|
# Rent ran out: every placed piece in the room into the stored list
|
|
# (chests with their contents), the rent record goes, a popup tells Lona.
|
|
def self.expire!(id)
|
|
loc = location(id)
|
|
return false if loc.nil? || !rent?(loc)
|
|
r = section("rent")
|
|
r.delete(id.to_s) if r
|
|
store_pieces(loc)
|
|
@static_rooms.delete(loc[:id])
|
|
notice(text_key("#{loc[:id]}/expired"))
|
|
true
|
|
rescue => e
|
|
p "LonaCraft Homes expire error #{e.class} #{e.message}"
|
|
false
|
|
end
|
|
|
|
# Expires every rent that ran out. Safe to call any time.
|
|
def self.check_rent_expiry
|
|
return unless enabled?
|
|
r = section("rent")
|
|
return if r.nil? || r.empty?
|
|
now = date_now
|
|
LOCATIONS.each{|loc|
|
|
next unless rent?(loc)
|
|
rec = rent_record(loc[:id])
|
|
next if rec.nil?
|
|
expire!(loc[:id]) if now > rec["until"].to_i
|
|
}
|
|
rescue => e
|
|
p "LonaCraft Homes rent check error #{e.class} #{e.message}"
|
|
end
|
|
|
|
# [[item_name, count], ...] held for Lona
|
|
def self.stored(id)
|
|
s = section("stored")
|
|
return [] if s.nil?
|
|
s[id.to_s] = [] unless s[id.to_s].is_a?(Array)
|
|
s[id.to_s]
|
|
end
|
|
|
|
def self.add_stored(id, item_name, count)
|
|
return if item_name.nil? || count.to_i < 1
|
|
list = stored(id)
|
|
row = list.find{|entry| entry.is_a?(Array) && entry[0] == item_name.to_s }
|
|
if row
|
|
row[1] = row[1].to_i + count.to_i
|
|
else
|
|
list << [item_name.to_s, count.to_i]
|
|
end
|
|
end
|
|
|
|
# Gives every stored item back; returns how many were given. Items that
|
|
# no longer exist are skipped with a console note (and dropped).
|
|
def self.collect_stored(id)
|
|
list = stored(id)
|
|
given = 0
|
|
list.each{|entry|
|
|
next unless entry.is_a?(Array)
|
|
item = $data_ItemName[entry[0].to_s]
|
|
if item.nil?
|
|
p "LonaCraft Homes: stored #{entry[1]} x #{entry[0]} no longer exists, skipped"
|
|
next
|
|
end
|
|
$game_party.gain_item(item, entry[1].to_i)
|
|
given += entry[1].to_i
|
|
}
|
|
list.clear
|
|
given
|
|
end
|
|
|
|
# The game map number of a room's map (MapInfos name), or nil
|
|
def self.room_map_number(loc)
|
|
return nil if $data_mapinfos.nil?
|
|
$data_mapinfos.each{|key, info|
|
|
next unless key.is_a?(Integer) && info
|
|
return (info.respond_to?(:id) && info.id ? info.id : key) if info.name.to_s == loc[:map].to_s
|
|
}
|
|
nil
|
|
end
|
|
|
|
# Placed pieces in the room -> stored list; chest contents too.
|
|
def self.store_pieces(loc)
|
|
return unless room?(loc) && defined?(LonaCraft::Furniture)
|
|
fur = LonaCraft::Furniture
|
|
map_number = room_map_number(loc)
|
|
return if map_number.nil?
|
|
tiles = room_tiles_anywhere(loc)
|
|
return if tiles.nil?
|
|
hits = fur.records.select{|rec| rec.is_a?(Hash) && rec["map_id"] == map_number && tiles[[rec["x"].to_i, rec["y"].to_i]] }
|
|
hits.each{|rec|
|
|
add_stored(loc[:id], rec["item_name"], 1)
|
|
box_id = rec["box"].to_i
|
|
box = fur.box_contents(box_id)
|
|
if box.is_a?(Hash)
|
|
box.each{|key, count|
|
|
next unless key.respond_to?(:item_name)
|
|
add_stored(loc[:id], key.item_name, count.to_i)
|
|
}
|
|
$game_boxes.write_box(box_id, nil)
|
|
end
|
|
if $game_map
|
|
fur.remove($game_map, rec["uid"]) # its events (nap-proof) and record
|
|
else
|
|
fur.records.delete(rec)
|
|
end
|
|
}
|
|
end
|
|
|
|
#----------------------------------------------------------------------
|
|
# Popups (shown when the map scene is up, as 60_Skill.rb does)
|
|
#----------------------------------------------------------------------
|
|
# Queued, shown by Scene_Map#update on a later frame: a nap runs out
|
|
# the rent inside Game_Map#nap and sets the map up again in the same
|
|
# frame (handleNap, Game_Interpreter_Modifies_OM.rb:21-24), which
|
|
# disposes popups shown before it (31_Game_Map.rb:160).
|
|
def self.notice(key)
|
|
@notices << key
|
|
end
|
|
|
|
def self.flush_notices
|
|
return if @notices.empty?
|
|
return unless SceneManager.scene_is?(Scene_Map)
|
|
return if $game_map.nil? || ($game_message && $game_message.busy?)
|
|
list = @notices
|
|
@notices = []
|
|
list.each{|key| $game_map.popup(0, key, 0, 0) }
|
|
rescue => e
|
|
p "LonaCraft Homes popup error #{e.class} #{e.message}"
|
|
end
|
|
|
|
# Debug (95_Debug.rb, Numpad 5): own every home, rent the rentable ones
|
|
# for DEBUG_RENT_WEEKS. Returns how many changed.
|
|
def self.debug_own_all
|
|
n = 0
|
|
LOCATIONS.each{|loc|
|
|
if rent?(loc)
|
|
r = section("rent")
|
|
next if r.nil?
|
|
was = rented?(loc[:id])
|
|
r[loc[:id]] = {"until" => date_now + DEBUG_RENT_WEEKS * RENT_DAYS * units_per_day}
|
|
n += 1
|
|
clear_existing!(loc[:id]) if !was && loc[:clear_existing]
|
|
else
|
|
next if owned?(loc[:id])
|
|
next unless set_owned(loc[:id], true)
|
|
n += 1
|
|
clear_existing!(loc[:id]) if loc[:clear_existing]
|
|
end
|
|
}
|
|
n
|
|
end
|
|
|
|
#----------------------------------------------------------------------
|
|
# Maps (houses)
|
|
#----------------------------------------------------------------------
|
|
def self.map_key(id)
|
|
return nil if id.nil?
|
|
@keys[id.to_s]
|
|
end
|
|
|
|
def self.map_id_for(id)
|
|
return nil if id.nil?
|
|
@ids[id.to_s]
|
|
end
|
|
|
|
def self.map_name(loc)
|
|
"#{TAG}_#{loc[:id]}"
|
|
end
|
|
|
|
# A runtime map number nothing else uses, starting at +want+.
|
|
def self.free_map_id(want, key)
|
|
used = {}
|
|
$data_mapinfos.each{|k, v|
|
|
next if v.nil? || k == key
|
|
used[v.id] = true if v.respond_to?(:id)
|
|
}
|
|
want += 1 while used[want]
|
|
want
|
|
end
|
|
|
|
# Called after the game and the other mods built their map lists
|
|
# (DataManager.load_mod_database alias at the end of this file).
|
|
def self.register_maps
|
|
@ids = {}
|
|
@keys = {}
|
|
@static_rooms = {}
|
|
return unless enabled?
|
|
return if $data_mapinfos.nil?
|
|
$data_tag_maps[TAG] = [] if $data_tag_maps
|
|
LOCATIONS.each_with_index{|loc, i|
|
|
next unless loc[:interior].is_a?(Array)
|
|
file = LonaCraft.resource(loc[:interior][0].to_s)
|
|
unless File.exist?(file)
|
|
p "LonaCraft Homes: missing map #{file}, home #{loc[:id]} left out"
|
|
next
|
|
end
|
|
info = $data_mapinfos[file]
|
|
info = RPG::MapInfo.new unless info.is_a?(RPG::MapInfo)
|
|
info.name = map_name(loc)
|
|
info.filename = file
|
|
info.id = free_map_id(MAP_ID_BASE + i, file)
|
|
$data_mapinfos[file] = info
|
|
@ids[loc[:id]] = info.id
|
|
@keys[loc[:id]] = file
|
|
if $data_tag_maps
|
|
$data_tag_maps[TAG] << file
|
|
$data_tag_maps["#{TAG}_#{loc[:id]}"] = [file]
|
|
end
|
|
p "LonaCraft Homes: #{loc[:id]} is map #{info.id} (#{file})" if info.id != MAP_ID_BASE + i
|
|
}
|
|
rescue => e
|
|
p "LonaCraft Homes register error #{e.class} #{e.message}"
|
|
end
|
|
|
|
# DataManager.reload_map_if_updated (5_DataManager.rb:994-1000) calls
|
|
# setup with the map NUMBER; a house is keyed by its file path.
|
|
def self.setup_key(map_id)
|
|
return map_id unless map_id.is_a?(Integer)
|
|
return map_id if $data_mapinfos.nil? || $data_mapinfos[map_id]
|
|
@ids.each{|id, n| return @keys[id] if n == map_id && @keys[id] }
|
|
map_id
|
|
rescue => e
|
|
map_id
|
|
end
|
|
|
|
# Take Lona inside a house. As change_map_enter_tag
|
|
# (34_Functions_ChangeMap.rb:200-215), but to the entry tile; the way
|
|
# back (change_map_tag_map_exit) goes to LastOverMapX/Y, so those are
|
|
# only set on the world map. reserve_transfer moves at once
|
|
# (35_Game_Player.rb:203-211).
|
|
def self.enter(id, interp = nil)
|
|
loc = location(id)
|
|
key = map_key(id)
|
|
return false if loc.nil? || key.nil? || !enabled?
|
|
return false if $data_mapinfos.nil? || $data_mapinfos[key].nil?
|
|
interp = $game_map.interpreter if interp.nil?
|
|
if $game_map.isOverMap
|
|
$story_stats["LastOverMapX"] = $game_player.x
|
|
$story_stats["LastOverMapY"] = $game_player.y
|
|
end
|
|
interp.change_map_weather_cleaner
|
|
$game_player.reserve_transfer(key, loc[:interior][2].to_i, loc[:interior][3].to_i, 8)
|
|
interp.change_map_story_stats_fix
|
|
true
|
|
rescue => e
|
|
p "LonaCraft Homes enter error #{e.class} #{e.message}"
|
|
false
|
|
end
|
|
|
|
#----------------------------------------------------------------------
|
|
# Room tiles
|
|
#----------------------------------------------------------------------
|
|
# Passage of the map layers only (Game_Map#check_passage,
|
|
# 31_Game_Map.rb:734-742, without events). +data+ is the map's Table.
|
|
def self.layer_pass?(data, flags, w, h, x, y, d)
|
|
return false if x < 0 || y < 0 || x >= w || y >= h
|
|
bit = 1 << (d / 2 - 1)
|
|
[2, 1, 0].each{|z|
|
|
flag = flags[data[x, y, z] || 0]
|
|
next if flag & 0x10 != 0
|
|
return true if flag & bit == 0
|
|
return false if flag & bit == bit
|
|
}
|
|
false
|
|
end
|
|
|
|
# {[x, y] => true}: flood fill from :room_seed, plus :tile_overrides tiles.
|
|
def self.flood_room(data, flags, w, h, loc)
|
|
seed = loc[:room_seed]
|
|
bx1, by1, bx2, by2 = loc[:room_bounds].is_a?(Array) ? loc[:room_bounds] : [0, 0, w - 1, h - 1]
|
|
stop = {}
|
|
(loc[:door_tiles] || []).each{|t| stop[[t[0].to_i, t[1].to_i]] = true }
|
|
start = [seed[0].to_i, seed[1].to_i]
|
|
tiles = {start => true}
|
|
queue = [start]
|
|
steps = [[2, 0, 1, 8], [4, -1, 0, 6], [6, 1, 0, 4], [8, 0, -1, 2]]
|
|
until queue.empty?
|
|
x, y = queue.shift
|
|
steps.each{|d, dx, dy, back|
|
|
nx = x + dx
|
|
ny = y + dy
|
|
next if nx < bx1 || nx > bx2 || ny < by1 || ny > by2
|
|
key = [nx, ny]
|
|
next if tiles[key] || stop[key]
|
|
next unless layer_pass?(data, flags, w, h, x, y, d) && layer_pass?(data, flags, w, h, nx, ny, back)
|
|
tiles[key] = true
|
|
queue << key
|
|
}
|
|
end
|
|
(loc[:tile_overrides] || []).each{|o| tiles[[o[0].to_i, o[1].to_i]] = true }
|
|
tiles
|
|
end
|
|
|
|
# Room tiles worked out from the map file (when Lona is elsewhere).
|
|
def self.static_room_tiles(loc)
|
|
return @static_rooms[loc[:id]] if @static_rooms[loc[:id]]
|
|
number = room_map_number(loc)
|
|
return nil if number.nil?
|
|
info = $data_mapinfos[number]
|
|
file = info && info.respond_to?(:filename) && info.filename ? info.filename : sprintf("Data/Map%03d.rvdata2", number)
|
|
map = load_data(file)
|
|
ts = $data_tilesets[map.tileset_id]
|
|
return nil if ts.nil?
|
|
@static_rooms[loc[:id]] = flood_room(map.data, ts.flags, map.width, map.height, loc)
|
|
rescue => e
|
|
p "LonaCraft Homes room tiles error #{e.class} #{e.message}"
|
|
nil
|
|
end
|
|
|
|
# The live map's tiles when Lona is on the room's map, else the file's.
|
|
def self.room_tiles_anywhere(loc)
|
|
if $game_map && $game_map.respond_to?(:lonacraft_home_room_tiles) && map_name_of($game_map) == loc[:map].to_s
|
|
return $game_map.lonacraft_home_room_tiles(loc)
|
|
end
|
|
static_room_tiles(loc)
|
|
end
|
|
|
|
#----------------------------------------------------------------------
|
|
# Where Lona's things may go (contract with 90_Furniture.rb)
|
|
#----------------------------------------------------------------------
|
|
def self.map_name_of(map)
|
|
map.respond_to?(:name) ? map.name.to_s : ""
|
|
end
|
|
|
|
# Location id of the house +map+ (a Game_Map) is, or of the first room
|
|
# on it, or nil.
|
|
def self.home_at_map?(map = $game_map)
|
|
return nil unless enabled?
|
|
return nil if map.nil?
|
|
rec = map.respond_to?(:map_id_rec) ? map.map_id_rec : nil
|
|
num = map.respond_to?(:map_id) ? map.map_id : nil
|
|
@keys.each{|id, key| return id if !rec.nil? && rec == key }
|
|
@ids.each{|id, n| return id if !num.nil? && num == n }
|
|
name = map_name_of(map)
|
|
LOCATIONS.each{|loc| return loc[:id] if room?(loc) && loc[:map].to_s == name }
|
|
nil
|
|
rescue => e
|
|
p "LonaCraft Homes home_at_map? error #{e.class} #{e.message}"
|
|
nil
|
|
end
|
|
|
|
# Owned (or rented) rooms on +map+
|
|
def self.owned_rooms_on(map)
|
|
name = map_name_of(map)
|
|
LOCATIONS.select{|loc| room?(loc) && loc[:map].to_s == name && owned?(loc[:id]) }
|
|
end
|
|
|
|
# Coarse check: some owned area exists on +map+ (the whole house map,
|
|
# or an owned room on it).
|
|
def self.furniture_allowed?(map = $game_map)
|
|
return false unless enabled?
|
|
return false if map.nil?
|
|
id = home_at_map?(map)
|
|
loc = location(id)
|
|
return false if loc.nil?
|
|
return owned?(id) unless room?(loc)
|
|
!owned_rooms_on(map).empty?
|
|
rescue => e
|
|
p "LonaCraft Homes furniture_allowed? error #{e.class} #{e.message}"
|
|
false
|
|
end
|
|
|
|
# Per tile: (x, y) of +map+ is inside an owned house map, or inside the
|
|
# tile set of an owned (rented) room on it.
|
|
def self.furniture_allowed_at?(map, x, y)
|
|
return false unless enabled?
|
|
return false if map.nil?
|
|
id = home_at_map?(map)
|
|
loc = location(id)
|
|
return false if loc.nil?
|
|
return owned?(id) unless room?(loc)
|
|
owned_rooms_on(map).any?{|room|
|
|
tiles = room_tiles(map, room[:id])
|
|
!tiles.nil? && tiles[[x.to_i, y.to_i]] ? true : false
|
|
}
|
|
rescue => e
|
|
p "LonaCraft Homes furniture_allowed_at? error #{e.class} #{e.message}"
|
|
false
|
|
end
|
|
|
|
def self.inside_owned_area?(map, x, y)
|
|
furniture_allowed_at?(map, x, y)
|
|
end
|
|
|
|
# Floor tiles of place +id+ on +map+: a room's tile set, or a house's
|
|
# floor (flood fill from :floor_seed, or the entry tile, inside
|
|
# :floor_bounds). nil when +map+ is not that place's map.
|
|
def self.floor_tiles(map, id)
|
|
loc = location(id)
|
|
return nil if loc.nil? || map.nil?
|
|
return room_tiles(map, id) if room?(loc)
|
|
return nil unless home_at_map?(map) == loc[:id]
|
|
return nil unless map.respond_to?(:lonacraft_home_floor_tiles)
|
|
map.lonacraft_home_floor_tiles(loc)
|
|
end
|
|
|
|
# Wall tiles of place +id+ on +map+ for wall-hung decorations: for every
|
|
# floor tile (x, y), the tile (x, y - 1) when it is impassable from every
|
|
# side and not floor itself, minus :window_tiles. {[x, y] => true} or nil.
|
|
def self.wall_tiles(map, id)
|
|
loc = location(id)
|
|
floor = floor_tiles(map, id)
|
|
return nil if floor.nil?
|
|
return nil unless map.respond_to?(:lonacraft_home_wall_tiles)
|
|
map.lonacraft_home_wall_tiles(loc, floor)
|
|
end
|
|
|
|
# true when (x, y) is a wall tile of a place Lona owns (or rents) on +map+
|
|
def self.wall_allowed_at?(map, x, y)
|
|
return false unless enabled?
|
|
return false if map.nil?
|
|
LOCATIONS.any?{|loc|
|
|
next false unless owned?(loc[:id])
|
|
walls = wall_tiles(map, loc[:id])
|
|
!walls.nil? && walls[[x.to_i, y.to_i]] ? true : false
|
|
}
|
|
rescue => e
|
|
p "LonaCraft Homes wall_allowed_at? error #{e.class} #{e.message}"
|
|
false
|
|
end
|
|
|
|
#----------------------------------------------------------------------
|
|
# Inn keys while sleeping in a rented room (Game_Party aliases below)
|
|
#----------------------------------------------------------------------
|
|
# Set only while an inn's nap script runs for Lona inside the room.
|
|
def self.nap_keys_active
|
|
@nap_keys_active
|
|
end
|
|
|
|
def self.nap_keys_active=(loc)
|
|
@nap_keys_active = loc
|
|
end
|
|
|
|
# true when +item+ (name, id or item object) is one of the active keys
|
|
def self.nap_key?(item)
|
|
loc = @nap_keys_active
|
|
return false if loc.nil? || !loc[:nap_keys].is_a?(Array)
|
|
name = nil
|
|
if item.is_a?(String)
|
|
name = item
|
|
elsif item.is_a?(Integer)
|
|
obj = $data_items[item]
|
|
name = obj.item_name.to_s if obj && obj.respond_to?(:item_name)
|
|
elsif item.is_a?(RPG::Item)
|
|
name = item.item_name.to_s
|
|
end
|
|
return false if name.nil?
|
|
loc[:nap_keys].any?{|key|
|
|
if key.is_a?(Integer)
|
|
obj = $data_items[key]
|
|
!obj.nil? && obj.respond_to?(:item_name) && obj.item_name.to_s == name
|
|
else
|
|
key.to_s == name
|
|
end
|
|
}
|
|
rescue => e
|
|
false
|
|
end
|
|
|
|
# The rented room on the current map Lona stands in, or nil
|
|
def self.room_at_player
|
|
return nil if $game_map.nil? || $game_player.nil?
|
|
owned_rooms_on($game_map).find{|loc|
|
|
tiles = room_tiles($game_map, loc[:id])
|
|
!tiles.nil? && tiles[[$game_player.x, $game_player.y]]
|
|
}
|
|
end
|
|
|
|
# {[x, y] => true} of room +id+ on +map+ (worked out on first use after
|
|
# each setup of that map, see Game_Map#lonacraft_home_room_tiles).
|
|
def self.room_tiles(map, id)
|
|
loc = location(id)
|
|
return nil unless room?(loc)
|
|
return nil unless map.respond_to?(:lonacraft_home_room_tiles)
|
|
return nil unless loc[:map].to_s == map_name_of(map)
|
|
map.lonacraft_home_room_tiles(loc)
|
|
end
|
|
|
|
#----------------------------------------------------------------------
|
|
# Clearing a room (clear_existing)
|
|
#----------------------------------------------------------------------
|
|
def self.keep_event?(loc, name)
|
|
keep = loc[:keep].is_a?(Array) ? loc[:keep] : []
|
|
keep.include?(name.to_s)
|
|
end
|
|
|
|
# [x, y] a room point event is moved to, or nil (stays where it is)
|
|
def self.point_target(loc, name)
|
|
moves = loc[:move_points].is_a?(Hash) ? loc[:move_points] : {}
|
|
t = moves[name.to_s]
|
|
t.is_a?(Array) ? [t[0].to_i, t[1].to_i] : nil
|
|
end
|
|
|
|
def self.remove_tile?(loc, x, y)
|
|
(loc[:remove_event_tiles] || []).any?{|t| t[0].to_i == x && t[1].to_i == y }
|
|
end
|
|
|
|
# Called on buying / renting. The map data is cleared at each setup
|
|
# (Game_Map#lonacraft_clear_owned_rooms); if Lona is on that map now,
|
|
# it is cleared at once: the override tiles change, a "-point-" event
|
|
# is erased (it stays as a point, moved by :move_points), any other
|
|
# event in the room or on :remove_event_tiles is deleted (with its
|
|
# light) and marked not to come back on a nap (reset_events,
|
|
# 31_Game_Map.rb:359-374).
|
|
def self.clear_existing!(id)
|
|
loc = location(id)
|
|
return nil unless room?(loc)
|
|
map = $game_map
|
|
return nil if map.nil? || loc[:map].to_s != map_name_of(map)
|
|
map.lonacraft_apply_tile_overrides(loc) if map.respond_to?(:lonacraft_apply_tile_overrides)
|
|
tiles = room_tiles(map, id)
|
|
return nil if tiles.nil?
|
|
map.events.values.each{|ev|
|
|
next if ev.nil? || ev.deleted?
|
|
next if ev.respond_to?(:foreign_event) && ev.foreign_event # summoned (furniture, NPC drops)
|
|
in_room = tiles[[ev.x, ev.y]] ? true : false
|
|
next unless in_room || remove_tile?(loc, ev.x, ev.y)
|
|
name = ev.respond_to?(:name) ? ev.name.to_s : ""
|
|
next if keep_event?(loc, name)
|
|
if in_room && name =~ POINT_RE
|
|
ev.erase
|
|
to = point_target(loc, name)
|
|
if to
|
|
ev.moveto(to[0], to[1])
|
|
map.add_storypoint(name.sub(POINT_RE, ""), to[0], to[1], ev.id) if map.respond_to?(:add_storypoint)
|
|
end
|
|
else
|
|
ev.nappable = false
|
|
ev.delete
|
|
end
|
|
}
|
|
map.refresh if map.respond_to?(:refresh)
|
|
nil
|
|
rescue => e
|
|
p "LonaCraft Homes clear error #{e.class} #{e.message}"
|
|
nil
|
|
end
|
|
|
|
#----------------------------------------------------------------------
|
|
# Doors (houses)
|
|
#----------------------------------------------------------------------
|
|
def self.door_event_name(loc)
|
|
"LonaCraftHomeDoor_#{loc[:id]}"
|
|
end
|
|
|
|
def self.doors_on(map_name)
|
|
return [] unless enabled?
|
|
LOCATIONS.select{|loc| loc[:door].is_a?(Array) && loc[:door][0].to_s == map_name.to_s && @keys[loc[:id]] }
|
|
end
|
|
|
|
# RPG::Event for the door of +loc+. +point+: a world-map point (below
|
|
# characters, walk-through) instead of a door standing in a wall.
|
|
def self.build_door_event(loc, point)
|
|
map_name, x, y, sprite = loc[:door]
|
|
sprite = [] unless sprite.is_a?(Array)
|
|
ev = RPG::Event.new(x.to_i, y.to_i)
|
|
ev.name = door_event_name(loc)
|
|
page = RPG::Event::Page.new
|
|
page.graphic.tile_id = 0
|
|
page.graphic.character_name = sprite[0].to_s
|
|
page.graphic.character_index = sprite[1].to_i
|
|
page.graphic.direction = sprite[2].nil? ? 2 : sprite[2].to_i
|
|
page.graphic.pattern = sprite[3].to_i
|
|
page.move_type = 0
|
|
page.walk_anime = false
|
|
page.step_anime = false
|
|
page.direction_fix = true
|
|
page.through = point ? true : false
|
|
page.priority_type = point ? 0 : 1
|
|
page.trigger = 0
|
|
page.list = [
|
|
EvLib.NewEventCMD("lonacraft_home_door(#{loc[:id].to_s.inspect}) if respond_to?(:lonacraft_home_door)"),
|
|
RPG::EventCommand.new(0, 0, [])
|
|
]
|
|
ev.pages = [page]
|
|
ev
|
|
end
|
|
|
|
#----------------------------------------------------------------------
|
|
# Script redirects (sellers, nap gates)
|
|
#----------------------------------------------------------------------
|
|
def self.wrapper_script(game_script)
|
|
LonaCraft.resource("HCGframes/#{File.basename(game_script.to_s)}")
|
|
end
|
|
|
|
# Script +game_script+ ran before LonaCraft took it over.
|
|
def self.previous_script(game_script)
|
|
@previous[game_script.to_s] || game_script.to_s
|
|
end
|
|
|
|
def self.redirect(game_script)
|
|
mine = wrapper_script(game_script)
|
|
unless File.exist?(mine)
|
|
p "LonaCraft Homes: missing #{mine}, #{game_script} left alone"
|
|
return
|
|
end
|
|
current = $mod_load_script.fetch(game_script, game_script)
|
|
@previous[game_script] = current unless current == mine
|
|
$mod_load_script[game_script] = mine
|
|
end
|
|
|
|
def self.install_redirects
|
|
return unless enabled?
|
|
return if $mod_load_script.nil?
|
|
SELLERS.each{|seller, row|
|
|
# Don't wrap NoerHome's bank: the separate menu hook below
|
|
# integrates all three houses while keeping its purchase handler.
|
|
next if seller == "NoerBankMaani" && noerhome_active?
|
|
redirect(row[0])
|
|
}
|
|
LOCATIONS.each{|loc| redirect(loc[:nap_script]) if loc[:nap_script] }
|
|
rescue => e
|
|
p "LonaCraft Homes redirect error #{e.class} #{e.message}"
|
|
end
|
|
|
|
def self.seller_script(seller)
|
|
row = SELLERS[seller.to_s]
|
|
row ? row[0] : nil
|
|
end
|
|
|
|
# Ids of the places +seller+ offers right now (not owned / not rented, usable).
|
|
def self.offers_for(seller)
|
|
return [] unless enabled?
|
|
LOCATIONS.select{|loc|
|
|
loc[:seller].to_s == seller.to_s && !owned?(loc[:id]) && available?(loc)
|
|
}.map{|loc| loc[:id] }
|
|
end
|
|
|
|
def self.clean_label(label)
|
|
label.to_s.gsub(/[,\[\]\r\n]/, "")
|
|
end
|
|
|
|
# Other parts add lines to a seller's menu: the block returns
|
|
# [[label, proc], ...]; a picked line calls proc.call(interpreter)
|
|
def self.add_menu_provider(seller, &blk)
|
|
(@providers[seller.to_s] ||= []) << blk if blk
|
|
end
|
|
|
|
def self.provider_entries(seller)
|
|
out = []
|
|
(@providers[seller.to_s] || []).each{|blk|
|
|
begin
|
|
Array(blk.call).each{|label, act| out << [clean_label(label), act, nil] if act.is_a?(Proc) }
|
|
rescue => e
|
|
p "LonaCraft Homes menu provider error #{e.class} #{e.message}"
|
|
end
|
|
}
|
|
out
|
|
end
|
|
|
|
# The seller's extra menu lines: [[label, action, id], ...];
|
|
# action :buy, :rent, :status or :collect, or a Proc (add_menu_provider).
|
|
def self.menu_entries_for(seller)
|
|
return [] unless enabled?
|
|
out = []
|
|
LOCATIONS.each{|loc|
|
|
next unless loc[:seller].to_s == seller.to_s && available?(loc)
|
|
id = loc[:id]
|
|
price = loc[:price].to_i
|
|
if rent?(loc)
|
|
per_week = "#{price} #{text("#{id}/coin_week")}"
|
|
if rented?(id)
|
|
out << [clean_label("#{text("#{id}/extend_opt")} #{per_week}"), :rent, id]
|
|
out << [clean_label(text("#{id}/status_opt")), :status, id]
|
|
else
|
|
out << [clean_label("#{text("#{id}/rent_opt")} #{per_week}"), :rent, id]
|
|
end
|
|
out << [clean_label(text("common/collect_opt")), :collect, id] unless stored(id).empty?
|
|
elsif !owned?(id)
|
|
out << [clean_label("#{text("#{id}/buy_opt")} #{price} #{text("common/gold")}"), :buy, id]
|
|
end
|
|
}
|
|
out
|
|
end
|
|
|
|
# +dialog+ with one more \optB entry per label, and the number of
|
|
# entries it had: [new dialog, count]. nil when it has no \optB list or
|
|
# the list lacks +marker+ (the text of the seller's marker option).
|
|
def self.extend_menu(dialog, labels, marker)
|
|
return nil unless dialog.is_a?(String) && labels.is_a?(Array) && !labels.empty?
|
|
start = dialog.index("\\optB[")
|
|
return nil if start.nil?
|
|
close = dialog.rindex("]")
|
|
return nil if close.nil? || close < start
|
|
inner = dialog[(start + 6)...close]
|
|
entries = inner.split(",").reject{|s| s.strip.empty? }
|
|
return nil if marker && !marker.empty? && !entries.include?(marker)
|
|
add = labels.map{|label| "#{label}," }.join
|
|
sep = (inner.empty? || inner[-1, 1] == ",") ? "" : ","
|
|
[dialog[0...close] + sep + add + dialog[close..-1], entries.length]
|
|
end
|
|
end
|
|
end
|
|
|
|
LonaCraft::Homes.install_redirects
|
|
|
|
#==============================================================================
|
|
# DataManager: register the house maps after every other map list is built.
|
|
#==============================================================================
|
|
module DataManager
|
|
unless respond_to?(:load_mod_database_lonacraft_homes)
|
|
self.singleton_class.send(:alias_method, :load_mod_database_lonacraft_homes, :load_mod_database)
|
|
def self.load_mod_database
|
|
load_mod_database_lonacraft_homes
|
|
LonaCraft::Homes.register_maps
|
|
end
|
|
end
|
|
end
|
|
|
|
#==============================================================================
|
|
# Game_Date: rent may run out whenever the date moves (a nap shifts it,
|
|
# 70_Game_Map_DayNightAndOvermap.rb:14).
|
|
#==============================================================================
|
|
class Game_Date
|
|
[:shift, :addDays, :oneDayForward].each{|meth|
|
|
old = "#{meth}_lonacraft_homes".to_sym
|
|
next unless method_defined?(meth)
|
|
next if method_defined?(old)
|
|
alias_method old, meth
|
|
define_method(meth){|*args, **kwargs, &block|
|
|
result = kwargs.empty? ? send(old, *args, &block) : send(old, *args, **kwargs, &block)
|
|
begin
|
|
LonaCraft::Homes.check_rent_expiry if $game_date.equal?(self)
|
|
rescue => e
|
|
p "LonaCraft Homes date hook error #{e.class} #{e.message}"
|
|
end
|
|
result
|
|
}
|
|
}
|
|
end
|
|
|
|
#==============================================================================
|
|
# Game_Party: inn keys while Lona sleeps in her rented room. Only while
|
|
# Homes.nap_keys_active is set (lonacraft_home_nap, for the length of the
|
|
# inn's nap script): has_item? of a room key is true (NoerTavern_Nap.rb:117,
|
|
# 125, 129) and lose_item of one takes nothing (:130). Otherwise untouched.
|
|
#==============================================================================
|
|
class Game_Party
|
|
unless method_defined?(:has_item_lonacraft_homes?)
|
|
alias_method :has_item_lonacraft_homes?, :has_item?
|
|
def has_item?(item, *args)
|
|
begin
|
|
return true if LonaCraft::Homes.nap_keys_active && LonaCraft::Homes.nap_key?(item)
|
|
rescue => e
|
|
p "LonaCraft Homes key check error #{e.class} #{e.message}"
|
|
end
|
|
has_item_lonacraft_homes?(item, *args)
|
|
end
|
|
end
|
|
|
|
unless method_defined?(:lose_item_lonacraft_homes)
|
|
alias_method :lose_item_lonacraft_homes, :lose_item
|
|
def lose_item(item, *args)
|
|
begin
|
|
return nil if LonaCraft::Homes.nap_keys_active && LonaCraft::Homes.nap_key?(item)
|
|
rescue => e
|
|
p "LonaCraft Homes key keep error #{e.class} #{e.message}"
|
|
end
|
|
lose_item_lonacraft_homes(item, *args)
|
|
end
|
|
end
|
|
end
|
|
|
|
#==============================================================================
|
|
# Scene_Map: queued home popups (rent ran out).
|
|
#==============================================================================
|
|
class Scene_Map
|
|
unless method_defined?(:update_lonacraft_homes)
|
|
alias_method :update_lonacraft_homes, :update
|
|
def update
|
|
update_lonacraft_homes
|
|
LonaCraft::Homes.flush_notices
|
|
end
|
|
end
|
|
end
|
|
|
|
#==============================================================================
|
|
# Window_ChoiceList: game draw fix (LonaCraft alias). refresh draws every
|
|
# choice dim (Window_Selectable#refresh -> draw_all_items,
|
|
# 54_Window_Selectable.rb:406-407, 436-438), then draw_selected_item
|
|
# (80_Window_ChoiceList.rb:183-189) draws "> choice <" over the selected one
|
|
# without clearing its row. Short choices hide the dim copy exactly; once
|
|
# "> choice <" is wider than the text rect (608 px) draw_text squeezes it and
|
|
# the dim copy shows through. Clearing the row first removes the copy and
|
|
# changes nothing else.
|
|
#==============================================================================
|
|
class Window_ChoiceList
|
|
if method_defined?(:draw_selected_item) && !method_defined?(:draw_selected_item_lonacraft_homes)
|
|
alias_method :draw_selected_item_lonacraft_homes, :draw_selected_item
|
|
def draw_selected_item(*args)
|
|
begin
|
|
contents.clear_rect(item_rect(self.index)) if self.index >= 0 && contents && !contents.disposed?
|
|
rescue => e
|
|
p "LonaCraft choice draw fix error #{e.class} #{e.message}"
|
|
end
|
|
draw_selected_item_lonacraft_homes(*args)
|
|
end
|
|
end
|
|
end
|
|
|
|
#==============================================================================
|
|
# Game_Map: house doors, room tiles and clearing, map number -> house file.
|
|
#==============================================================================
|
|
class Game_Map
|
|
# {[x, y] => true}, cached until the next setup of this map.
|
|
def lonacraft_home_room_tiles(loc)
|
|
@lonacraft_home_rooms = {} unless @lonacraft_home_rooms.is_a?(Hash)
|
|
id = loc[:id].to_s
|
|
@lonacraft_home_rooms[id] ||= LonaCraft::Homes.flood_room(@map.data, tileset.flags, width, height, loc)
|
|
@lonacraft_home_rooms[id]
|
|
end
|
|
|
|
# House floor ({[x, y] => true}), cached until the next setup.
|
|
def lonacraft_home_floor_tiles(loc)
|
|
@lonacraft_home_rooms = {} unless @lonacraft_home_rooms.is_a?(Hash)
|
|
key = "floor_#{loc[:id]}"
|
|
unless @lonacraft_home_rooms[key]
|
|
seed = loc[:floor_seed]
|
|
seed = [loc[:interior][2], loc[:interior][3]] if !seed.is_a?(Array) && loc[:interior].is_a?(Array)
|
|
spec = {:room_seed => seed, :room_bounds => loc[:floor_bounds], :door_tiles => loc[:floor_door_tiles] || []}
|
|
@lonacraft_home_rooms[key] = LonaCraft::Homes.flood_room(@map.data, tileset.flags, width, height, spec)
|
|
end
|
|
@lonacraft_home_rooms[key]
|
|
end
|
|
|
|
# Wall tiles above +floor+ (see Homes.wall_tiles), cached until the next setup.
|
|
def lonacraft_home_wall_tiles(loc, floor)
|
|
@lonacraft_home_rooms = {} unless @lonacraft_home_rooms.is_a?(Hash)
|
|
key = "wall_#{loc[:id]}"
|
|
return @lonacraft_home_rooms[key] if @lonacraft_home_rooms[key]
|
|
homes = LonaCraft::Homes
|
|
windows = {}
|
|
(loc[:window_tiles] || []).each{|t| windows[[t[0].to_i, t[1].to_i]] = true }
|
|
flags = tileset.flags
|
|
walls = {}
|
|
floor.each_key{|t|
|
|
x = t[0]
|
|
y = t[1] - 1
|
|
k = [x, y]
|
|
next if floor[k] || windows[k] || walls[k]
|
|
next if [2, 4, 6, 8].any?{|d| homes.layer_pass?(@map.data, flags, width, height, x, y, d) }
|
|
walls[k] = true
|
|
}
|
|
@lonacraft_home_rooms[key] = walls
|
|
end
|
|
|
|
# :tile_overrides: each tile takes all four layers of its reference tile
|
|
# (the loaded @map only). Works the room out again afterwards.
|
|
def lonacraft_apply_tile_overrides(loc)
|
|
list = loc[:tile_overrides]
|
|
return unless list.is_a?(Array) && !list.empty?
|
|
changes = []
|
|
list.each{|o|
|
|
x, y, rx, ry = o.map{|v| v.to_i }
|
|
next unless valid?(x, y) && valid?(rx, ry)
|
|
changes << [x, y, [0, 1, 2, 3].map{|z| @map.data[rx, ry, z] }]
|
|
}
|
|
changes.each{|x, y, layers| [0, 1, 2, 3].each{|z| @map.data[x, y, z] = layers[z] } }
|
|
if @lonacraft_home_rooms.is_a?(Hash)
|
|
@lonacraft_home_rooms.delete(loc[:id].to_s)
|
|
@lonacraft_home_rooms.delete("wall_#{loc[:id]}")
|
|
end
|
|
end
|
|
|
|
# Owned rooms of this map: override tiles, their events go and decor
|
|
# tiles become floor (in the loaded @map only), before setup_events
|
|
# builds the events.
|
|
def lonacraft_clear_owned_rooms
|
|
homes = LonaCraft::Homes
|
|
homes.owned_rooms_on(self).each{|loc|
|
|
next unless loc[:clear_existing]
|
|
lonacraft_apply_tile_overrides(loc)
|
|
tiles = lonacraft_home_room_tiles(loc)
|
|
@map.events.keys.each{|i|
|
|
ev = @map.events[i]
|
|
next if ev.nil?
|
|
in_room = tiles[[ev.x, ev.y]] ? true : false
|
|
next unless in_room || homes.remove_tile?(loc, ev.x, ev.y)
|
|
next if homes.keep_event?(loc, ev.name)
|
|
if in_room && ev.name.to_s =~ LonaCraft::Homes::POINT_RE
|
|
# looked up by name (WakeUp: 34_Functions_ChangeMap.rb:74,
|
|
# SexPoint: 28_Functions_Chcg_Events.rb:994-1005): keep the
|
|
# point, drop its picture and commands
|
|
page = RPG::Event::Page.new
|
|
page.graphic.character_name = ""
|
|
page.through = true
|
|
page.priority_type = 0
|
|
page.trigger = 0
|
|
page.list = [RPG::EventCommand.new(0, 0, [])]
|
|
ev.pages = [page]
|
|
# moved out of the room when :move_points says so; storypoints
|
|
# are read from @map.events after this (31_Game_Map.rb:197, 254-264)
|
|
to = homes.point_target(loc, ev.name)
|
|
if to
|
|
ev.x = to[0]
|
|
ev.y = to[1]
|
|
end
|
|
else
|
|
@map.events.delete(i)
|
|
@preload_EventHash.delete(ev.name) if @preload_EventHash.is_a?(Hash) && @preload_EventHash[ev.name].equal?(ev)
|
|
# a nap keeps the live events (reset_events would rebuild
|
|
# this one from the map data, which no longer has it)
|
|
old = @events.is_a?(Hash) ? @events[i] : nil
|
|
old.nappable = false if old && old.respond_to?(:nappable=)
|
|
end
|
|
}
|
|
ref = loc[:floor_ref]
|
|
next unless ref.is_a?(Array)
|
|
rx = ref[0].to_i
|
|
ry = ref[1].to_i
|
|
next unless valid?(rx, ry)
|
|
layers = loc[:floor_layers].is_a?(Array) ? loc[:floor_layers].map{|z| z.to_i }.select{|z| z >= 0 && z <= 2 } : [0, 1, 2]
|
|
floor = {}
|
|
layers.each{|z| floor[z] = @map.data[rx, ry, z] }
|
|
check = layers.select{|z| z > 0 }
|
|
tiles.each_key{|t|
|
|
x, y = t
|
|
next unless valid?(x, y)
|
|
next unless check.any?{|z| @map.data[x, y, z] != floor[z] }
|
|
layers.each{|z| @map.data[x, y, z] = floor[z] }
|
|
}
|
|
}
|
|
end
|
|
|
|
# Adds the house doors of this map to @map.events before setup_events
|
|
# builds them (and a nap rebuilds them the same way), as 90_Furniture.rb does.
|
|
def lonacraft_inject_home_doors
|
|
homes = LonaCraft::Homes
|
|
doors = homes.doors_on(@name)
|
|
return if doors.empty?
|
|
point = Note.get_data(@map.note.to_s)["isOverMap"] == "true"
|
|
doors.each{|loc|
|
|
name = homes.door_event_name(loc)
|
|
next if @map.events.values.any?{|e| e && e.name == name } # already there
|
|
x = loc[:door][1].to_i
|
|
y = loc[:door][2].to_i
|
|
if @map.events.values.any?{|e| e && e.x == x && e.y == y }
|
|
p "LonaCraft Homes: door of #{loc[:id]} on #{@name} (#{x},#{y}) skipped, tile has an event"
|
|
next
|
|
end
|
|
ev = homes.build_door_event(loc, point)
|
|
new_id = @map.events.keys.max
|
|
new_id = new_id.nil? ? 1 : new_id + 1
|
|
ev.id = new_id
|
|
@map.events[new_id] = ev
|
|
@preload_EventHash[name] = ev if @preload_EventHash.is_a?(Hash)
|
|
}
|
|
end
|
|
|
|
unless method_defined?(:setup_event_hack_lonacraft_homes)
|
|
alias_method :setup_event_hack_lonacraft_homes, :setup_event_hack
|
|
def setup_event_hack
|
|
setup_event_hack_lonacraft_homes
|
|
@lonacraft_home_rooms = {} # new map data: work the rooms out again
|
|
return unless LonaCraft::Homes.enabled?
|
|
LonaCraft::Homes.check_rent_expiry
|
|
begin
|
|
lonacraft_clear_owned_rooms
|
|
rescue => e
|
|
p "LonaCraft Homes room clear error #{e.class} #{e.message}"
|
|
end
|
|
begin
|
|
lonacraft_inject_home_doors
|
|
rescue => e
|
|
p "LonaCraft Homes door error #{e.class} #{e.message}"
|
|
end
|
|
end
|
|
end
|
|
|
|
unless method_defined?(:setup_lonacraft_homes)
|
|
alias_method :setup_lonacraft_homes, :setup
|
|
def setup(map_id)
|
|
begin
|
|
LonaCraft::Homes.sync_cloud_homes!
|
|
rescue StandardError
|
|
end
|
|
setup_lonacraft_homes(LonaCraft::Homes.setup_key(map_id))
|
|
end
|
|
end
|
|
end
|
|
|
|
#==============================================================================
|
|
# Game_Interpreter: the door, the seller menus, buying, renting, the nap gate.
|
|
#==============================================================================
|
|
class Game_Interpreter
|
|
# The command of every house door.
|
|
def lonacraft_home_door(id)
|
|
homes = LonaCraft::Homes
|
|
loc = homes.location(id)
|
|
return if loc.nil? || !homes.enabled?
|
|
$game_portraits.lprt.hide
|
|
if homes.owned?(id)
|
|
call_msg(homes.text_key("#{loc[:id]}/enter"))
|
|
pick = $game_temp.choice
|
|
$game_temp.choice = -1
|
|
if pick == 1
|
|
if $game_player.cannot_change_map
|
|
SndLib.sys_buzzer
|
|
else
|
|
$game_player.direction = 8
|
|
SndLib.sys_buzzer unless homes.enter(id, self)
|
|
end
|
|
end
|
|
else
|
|
call_msg(homes.text_key("#{loc[:id]}/locked"))
|
|
end
|
|
$game_portraits.lprt.hide
|
|
$game_portraits.rprt.hide
|
|
$game_temp.choice = -1
|
|
end
|
|
|
|
# Run by HCGframes/<seller script name> in place of the seller's script.
|
|
def lonacraft_home_seller(seller)
|
|
homes = LonaCraft::Homes
|
|
entries = []
|
|
begin
|
|
homes.check_rent_expiry
|
|
entries = homes.menu_entries_for(seller) + homes.provider_entries(seller)
|
|
rescue => e
|
|
p "LonaCraft Homes offers error #{e.class} #{e.message}"
|
|
entries = []
|
|
end
|
|
@lonacraft_home_offers = nil
|
|
unless entries.empty?
|
|
row = LonaCraft::Homes::SELLERS[seller.to_s]
|
|
marker = row && row[1] ? $game_text[row[1]].to_s : ""
|
|
@lonacraft_home_offers = [entries, marker]
|
|
end
|
|
begin
|
|
lonacraft_run_previous_script(homes.seller_script(seller))
|
|
ensure
|
|
@lonacraft_home_offers = nil
|
|
end
|
|
end
|
|
|
|
# Run by HCGframes/<nap script name> in place of an inn map's nap script.
|
|
# The inn's own script always runs (night visitors, the paid-room meal,
|
|
# bath and full restore, handleNap). Inside a rented room its key checks
|
|
# see the room's :nap_keys as held and its lose_item of a key does
|
|
# nothing (Game_Party aliases below); anywhere else it runs unchanged.
|
|
def lonacraft_home_nap(game_script)
|
|
room = nil
|
|
begin
|
|
room = LonaCraft::Homes.room_at_player
|
|
room = nil if room && !room[:nap_keys].is_a?(Array)
|
|
rescue => e
|
|
p "LonaCraft Homes nap check error #{e.class} #{e.message}"
|
|
room = nil
|
|
end
|
|
return lonacraft_run_previous_script(game_script) if room.nil?
|
|
LonaCraft::Homes.nap_keys_active = room
|
|
begin
|
|
lonacraft_run_previous_script(game_script)
|
|
ensure
|
|
LonaCraft::Homes.nap_keys_active = nil
|
|
end
|
|
end
|
|
|
|
# The script that ran before LonaCraft; the redirect is lifted for the
|
|
# call so the game path does not loop back here (as 20_Station.rb
|
|
# lonacraft_run_original_pot).
|
|
def lonacraft_run_previous_script(game_script)
|
|
return if game_script.nil?
|
|
homes = LonaCraft::Homes
|
|
mine = $mod_load_script[game_script]
|
|
$mod_load_script.delete(game_script) if mine == homes.wrapper_script(game_script)
|
|
begin
|
|
load_script(homes.previous_script(game_script))
|
|
ensure
|
|
$mod_load_script[game_script] = mine if mine
|
|
end
|
|
end
|
|
|
|
def lonacraft_home_purchase(id)
|
|
homes = LonaCraft::Homes
|
|
case homes.buy(id, self)
|
|
when :ok
|
|
call_msg(homes.text_key("#{id}/bought"))
|
|
when :no_gold
|
|
SndLib.sys_buzzer
|
|
call_msg(homes.text_key("common/no_gold"))
|
|
when :owned
|
|
call_msg(homes.text_key("common/owned"))
|
|
end
|
|
end
|
|
|
|
# Rent or extend: how many weeks, then pay.
|
|
def lonacraft_home_rent(id)
|
|
homes = LonaCraft::Homes
|
|
was = homes.rented?(id)
|
|
$game_temp.choice = -1
|
|
own = "#{id}/rent_weeks" # a room's own price line, else Noer's common one
|
|
key = homes.text_key(own)
|
|
have = $game_text[key].to_s
|
|
call_msg(have.empty? || have == key ? homes.text_key("common/rent_weeks") : key)
|
|
pick = $game_temp.choice
|
|
$game_temp.choice = -1
|
|
weeks = pick.is_a?(Integer) && pick >= 0 ? LonaCraft::Homes::RENT_WEEKS[pick] : nil
|
|
return if weeks.nil?
|
|
case homes.pay_rent(id, weeks, self)
|
|
when :ok
|
|
call_msg(homes.text_key("#{id}/#{was ? "extended" : "rented"}"))
|
|
when :no_coins
|
|
SndLib.sys_buzzer
|
|
call_msg(homes.text_key("#{id}/no_coins"))
|
|
end
|
|
end
|
|
|
|
def lonacraft_home_status(id)
|
|
homes = LonaCraft::Homes
|
|
$story_stats["HiddenOPT0"] = homes.rent_days_left(id)
|
|
call_msg(homes.text_key("#{id}/status"))
|
|
$story_stats["HiddenOPT0"] = 0
|
|
end
|
|
|
|
def lonacraft_home_collect(id)
|
|
homes = LonaCraft::Homes
|
|
n = homes.collect_stored(id)
|
|
if n > 0
|
|
SndLib.sound_equip_armor
|
|
call_msg(homes.text_key("common/collected"))
|
|
else
|
|
call_msg(homes.text_key("common/nothing_stored"))
|
|
end
|
|
end
|
|
|
|
def lonacraft_home_action(entry)
|
|
label, action, id = entry
|
|
return action.call(self) if action.is_a?(Proc) # add_menu_provider lines
|
|
case action
|
|
when :buy then lonacraft_home_purchase(id)
|
|
when :rent then lonacraft_home_rent(id)
|
|
when :status then lonacraft_home_status(id)
|
|
when :collect then lonacraft_home_collect(id)
|
|
end
|
|
end
|
|
|
|
# While home lines are pending: if +text+ is the seller's menu, show it
|
|
# with the lines added (the block shows it) and handle a pick of one of
|
|
# them. Returns true when the menu was shown here.
|
|
def lonacraft_home_menu(text)
|
|
pending = @lonacraft_home_offers
|
|
return false if pending.nil?
|
|
entries, marker = pending
|
|
menu = nil
|
|
begin
|
|
menu = LonaCraft::Homes.extend_menu(text, entries.map{|e| e[0] }, marker)
|
|
rescue => e
|
|
p "LonaCraft Homes menu error #{e.class} #{e.message}"
|
|
menu = nil
|
|
end
|
|
return false if menu.nil?
|
|
@lonacraft_home_offers = nil # only the first such menu
|
|
yield menu[0]
|
|
count = menu[1]
|
|
pick = $game_temp.choice
|
|
if pick.is_a?(Integer) && pick >= count && pick < count + entries.length
|
|
$game_temp.choice = -1
|
|
begin
|
|
lonacraft_home_action(entries[pick - count])
|
|
rescue => e
|
|
p "LonaCraft Homes menu action error #{e.class} #{e.message}"
|
|
end
|
|
$game_temp.choice = -1
|
|
end
|
|
true
|
|
end
|
|
|
|
# Maani: show_npc_info(char, extra_info, "\\optB[...]") (NoerBankMaani.rb:22)
|
|
if method_defined?(:show_npc_info) && !method_defined?(:show_npc_info_lonacraft_homes)
|
|
alias_method :show_npc_info_lonacraft_homes, :show_npc_info
|
|
def show_npc_info(*args)
|
|
return show_npc_info_lonacraft_homes(*args) if @lonacraft_home_offers.nil? || args.length < 3
|
|
result = nil
|
|
done = lonacraft_home_menu(args[2]){|text|
|
|
new_args = args.dup
|
|
new_args[2] = text
|
|
result = show_npc_info_lonacraft_homes(*new_args)
|
|
}
|
|
return result if done
|
|
show_npc_info_lonacraft_homes(*args)
|
|
end
|
|
end
|
|
|
|
# Boss Mama: call_msg("\\optB[...]") (NoerTavernWaifu.rb:214)
|
|
if method_defined?(:call_msg) && !method_defined?(:call_msg_lonacraft_homes)
|
|
alias_method :call_msg_lonacraft_homes, :call_msg
|
|
def call_msg(*args)
|
|
return call_msg_lonacraft_homes(*args) if @lonacraft_home_offers.nil? || args.empty?
|
|
result = nil
|
|
msg = args[0]
|
|
# R16: a keeper whose menu is a text key (Fish Town,
|
|
# FishTownInnKeeper.rb:12): resolve it, extend the \optB in its text and
|
|
# show that through a runtime key (the text holds "]", so it cannot go
|
|
# into call_msg's \t[...] itself)
|
|
if msg.is_a?(String) && !msg.include?("\\optB[") && msg =~ /\A[^\s\\\[\]]+:[^\s\\\[\]]+\z/
|
|
full = $game_text[msg].to_s
|
|
if full != msg && full.include?("\\optB[") && defined?(LonaCraft::RuntimeText)
|
|
done = lonacraft_home_menu(full){|text|
|
|
new_args = args.dup
|
|
new_args[0] = LonaCraft::RuntimeText.key("Homes", "rt_keeper_menu", text)
|
|
result = call_msg_lonacraft_homes(*new_args)
|
|
}
|
|
return result if done
|
|
end
|
|
return call_msg_lonacraft_homes(*args)
|
|
end
|
|
done = lonacraft_home_menu(msg){|text|
|
|
new_args = args.dup
|
|
new_args[0] = text
|
|
result = call_msg_lonacraft_homes(*new_args)
|
|
}
|
|
return result if done
|
|
call_msg_lonacraft_homes(*args)
|
|
end
|
|
end
|
|
end
|