1504 lines
65 KiB
Ruby
1504 lines
65 KiB
Ruby
# NoerHome decor grid editor.
|
||
# Opens from the cat decor menu and stores exact item positions in the DB blob.
|
||
|
||
return if defined?($noerhome_decor_grid_editor_loaded) && $noerhome_decor_grid_editor_loaded
|
||
$noerhome_decor_grid_editor_loaded = true
|
||
|
||
if defined?(NoerHomeDecor)
|
||
module NoerHomeDecor
|
||
PLACEMENT_PREFIX = "v2|" unless const_defined?(:PLACEMENT_PREFIX)
|
||
BASE_CLEAR_ID = "__base_clear" unless const_defined?(:BASE_CLEAR_ID)
|
||
TILE_ID_A5 = 1536 unless const_defined?(:TILE_ID_A5)
|
||
SMALL_COPPER = 1 unless const_defined?(:SMALL_COPPER)
|
||
MEDIUM_COPPER = 10 * SMALL_COPPER unless const_defined?(:MEDIUM_COPPER)
|
||
GOLD_COPPER = 10 * MEDIUM_COPPER unless const_defined?(:GOLD_COPPER)
|
||
COIN_SPECS = [
|
||
["ItemCoin1", 50, SMALL_COPPER],
|
||
["ItemCoin2", 51, MEDIUM_COPPER],
|
||
["ItemCoin3", 52, GOLD_COPPER]
|
||
] unless const_defined?(:COIN_SPECS)
|
||
PRICE_FLOOR = 10 * SMALL_COPPER unless const_defined?(:PRICE_FLOOR)
|
||
PRICE_STATIC = 1 * MEDIUM_COPPER unless const_defined?(:PRICE_STATIC)
|
||
PRICE_INTERACTIVE = 5 * MEDIUM_COPPER unless const_defined?(:PRICE_INTERACTIVE)
|
||
PALACE_PRICE_MULTIPLIER = 3 unless const_defined?(:PALACE_PRICE_MULTIPLIER)
|
||
|
||
EXTRA_GRID_ITEMS = [
|
||
{ :id => "floor_wood", :title => "Деревянный пол", :path => "Graphics/Tilesets/Inside_A5.png", :rect => [0, 96, 32, 32], :tile_id => 1560, :x => 8, :y => 10, :z => 1, :floor => true, :layer => "floor", :solid => false, :footprint => [1, 1], :price => PRICE_FLOOR },
|
||
{ :id => "floor_stone", :title => "Каменный пол", :path => "Graphics/Tilesets/Inside_A5.png", :rect => [32, 32, 32, 32], :tile_id => 1545, :x => 8, :y => 10, :z => 1, :floor => true, :layer => "floor", :solid => false, :footprint => [1, 1], :price => PRICE_FLOOR },
|
||
{ :id => "floor_tile", :title => "Плиточный пол", :path => "Graphics/Tilesets/Inside_A5.png", :rect => [64, 128, 32, 32], :tile_id => 1570, :x => 8, :y => 10, :z => 1, :floor => true, :layer => "floor", :solid => false, :footprint => [1, 1], :price => PRICE_FLOOR },
|
||
{ :id => "floor_poor_wood", :title => "Старый деревянный пол", :path => "Graphics/Tilesets/Inside_POOR_A5.png", :rect => [0, 96, 32, 32], :tile_id => 1560, :x => 8, :y => 10, :z => 1, :floor => true, :layer => "floor", :solid => false, :footprint => [1, 1], :price => PRICE_FLOOR },
|
||
{ :id => "floor_poor_stone", :title => "Грубый каменный пол", :path => "Graphics/Tilesets/Inside_POOR_A5.png", :rect => [32, 32, 32, 32], :tile_id => 1545, :x => 8, :y => 10, :z => 1, :floor => true, :layer => "floor", :solid => false, :footprint => [1, 1], :price => PRICE_FLOOR },
|
||
{ :id => "floor_dark_wood", :title => "Тёмный деревянный пол", :path => "Graphics/Tilesets/TileA5_interior.png", :rect => [0, 0, 32, 32], :tile_id => 1536, :x => 8, :y => 10, :z => 1, :floor => true, :layer => "floor", :solid => false, :footprint => [1, 1], :price => PRICE_FLOOR },
|
||
{ :id => "floor_wide_planks", :title => "Широкие доски", :path => "Graphics/Tilesets/TileA5_interior.png", :rect => [96, 0, 32, 32], :tile_id => 1539, :x => 8, :y => 10, :z => 1, :floor => true, :layer => "floor", :solid => false, :footprint => [1, 1], :price => PRICE_FLOOR },
|
||
{ :id => "floor_gray_stone", :title => "Серый каменный пол", :path => "Graphics/Tilesets/TileA5_interior.png", :rect => [32, 128, 32, 32], :tile_id => 1569, :x => 8, :y => 10, :z => 1, :floor => true, :layer => "floor", :solid => false, :footprint => [1, 1], :price => PRICE_FLOOR },
|
||
{ :id => "floor_palace_mosaic", :title => "Дворцовая мозаика", :path => "Graphics/Tilesets/TileA5_interior.png", :rect => [96, 160, 32, 32], :tile_id => 1579, :x => 8, :y => 10, :z => 1, :floor => true, :layer => "floor", :solid => false, :footprint => [1, 1], :palace => true, :price => PRICE_FLOOR * PALACE_PRICE_MULTIPLIER },
|
||
{ :id => "floor_palace_gold", :title => "Дворцовый золотой пол", :path => "Graphics/Tilesets/TileA5_interior.png", :rect => [0, 320, 32, 32], :tile_id => 1616, :x => 8, :y => 10, :z => 1, :floor => true, :layer => "floor", :solid => false, :footprint => [1, 1], :palace => true, :price => PRICE_FLOOR * PALACE_PRICE_MULTIPLIER },
|
||
{ :id => "floor_palace_red", :title => "Дворцовый красный настил", :path => "Graphics/Tilesets/TileA5_interior.png", :rect => [0, 352, 32, 32], :tile_id => 1624, :x => 8, :y => 10, :z => 1, :floor => true, :layer => "floor", :solid => false, :footprint => [1, 1], :palace => true, :price => PRICE_FLOOR * PALACE_PRICE_MULTIPLIER },
|
||
|
||
{ :id => "bed_red", :title => "Красная кровать", :path => "Graphics/Tilesets/Inside_B.png", :rect => [0, 256, 64, 64], :x => 8, :y => 8, :z => 80, :solid => true, :footprint => [2, 2], :z_offset => 2, :layer => "object", :action => "sleep", :price => PRICE_INTERACTIVE },
|
||
{ :id => "bed_green", :title => "Зелёная кровать", :path => "Graphics/Tilesets/Inside_B.png", :rect => [64, 256, 64, 64], :x => 8, :y => 8, :z => 80, :solid => true, :footprint => [2, 2], :z_offset => 2, :layer => "object", :action => "sleep", :price => PRICE_INTERACTIVE },
|
||
{ :id => "bed_white", :title => "Белая кровать", :path => "Graphics/Tilesets/Inside_B.png", :rect => [128, 256, 64, 64], :x => 8, :y => 8, :z => 80, :solid => true, :footprint => [2, 2], :z_offset => 2, :layer => "object", :action => "sleep", :price => PRICE_INTERACTIVE },
|
||
{ :id => "bed_rough", :title => "Простая кровать", :path => "Graphics/Tilesets/Inside_B.png", :rect => [192, 256, 64, 64], :x => 8, :y => 8, :z => 80, :solid => true, :footprint => [2, 2], :z_offset => 2, :layer => "object", :action => "sleep", :price => PRICE_INTERACTIVE },
|
||
{ :id => "bed_palace_red", :title => "Дворцовая красная кровать", :path => "Graphics/Tilesets/RoyalTileset-TileB.png", :rect => [256, 320, 96, 64], :x => 8, :y => 8, :z => 80, :solid => true, :footprint => [3, 2], :z_offset => 2, :layer => "object", :action => "sleep", :palace => true, :price => PRICE_INTERACTIVE * PALACE_PRICE_MULTIPLIER },
|
||
{ :id => "bed_palace_green", :title => "Дворцовая зелёная кровать", :path => "Graphics/Tilesets/RoyalTileset-TileB.png", :rect => [256, 384, 96, 64], :x => 8, :y => 8, :z => 80, :solid => true, :footprint => [3, 2], :z_offset => 2, :layer => "object", :action => "sleep", :palace => true, :price => PRICE_INTERACTIVE * PALACE_PRICE_MULTIPLIER },
|
||
|
||
{ :id => "chest_wood", :title => "Деревянный сундук", :path => "Graphics/Characters/$Chest.png", :rect => [64, 0, 32, 32], :x => 16, :y => 8, :z => 80, :solid => true, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "storage", :price => PRICE_INTERACTIVE },
|
||
{ :id => "chest_red", :title => "Красный сундук", :path => "Graphics/Characters/$Chest.png", :rect => [0, 0, 32, 32], :x => 16, :y => 8, :z => 80, :solid => true, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "storage", :price => PRICE_INTERACTIVE },
|
||
{ :id => "chest_gold", :title => "Золотой сундук", :path => "Graphics/Characters/$Chest.png", :rect => [32, 0, 32, 32], :x => 16, :y => 8, :z => 80, :solid => true, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "storage", :palace => true, :price => PRICE_INTERACTIVE * PALACE_PRICE_MULTIPLIER },
|
||
{ :id => "chest_iron", :title => "Железный сундук", :path => "Graphics/Characters/!$_chest_1.png", :rect => [0, 0, 32, 32], :x => 16, :y => 8, :z => 80, :solid => true, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "storage", :price => PRICE_INTERACTIVE },
|
||
{ :id => "chest_large", :title => "Большой сундук", :path => "Graphics/Characters/!$_chest_5.png", :rect => [0, 0, 32, 48], :x => 16, :y => 8, :z => 80, :solid => true, :footprint => [1, 2], :z_offset => 2, :layer => "object", :action => "storage", :price => PRICE_INTERACTIVE },
|
||
{ :id => "chest_palace", :title => "Дворцовый сундук", :path => "Graphics/Tilesets/RoyalTileset-TileB.png", :rect => [160, 448, 32, 32], :x => 16, :y => 8, :z => 80, :solid => true, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "storage", :palace => true, :price => PRICE_INTERACTIVE * PALACE_PRICE_MULTIPLIER },
|
||
|
||
{ :id => "table_round", :title => "Круглый стол", :path => "Graphics/Characters/NoerTransHouse/CenTable.png", :rect => [0, 0, 81, 75], :x => 12, :y => 9, :z => 80, :solid => true, :footprint => [3, 3], :z_offset => 2, :layer => "object", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "table_large_round", :title => "Большой круглый стол", :path => "Graphics/Characters/!_Z_SYB_RoundTable.png", :rect => [0, 0, 162, 146], :x => 12, :y => 9, :z => 80, :solid => true, :footprint => [5, 5], :z_offset => 2, :layer => "object", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "table_palace_fruit", :title => "Дворцовый стол с фруктами", :path => "Graphics/Tilesets/RoyalTileset-TileB.png", :rect => [384, 256, 32, 32], :x => 12, :y => 9, :z => 80, :solid => true, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "none", :palace => true, :price => PRICE_STATIC * PALACE_PRICE_MULTIPLIER },
|
||
{ :id => "table_palace_gold", :title => "Дворцовый золотой столик", :path => "Graphics/Tilesets/RoyalTileset-TileB.png", :rect => [416, 256, 32, 32], :x => 12, :y => 9, :z => 80, :solid => true, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "none", :palace => true, :price => PRICE_STATIC * PALACE_PRICE_MULTIPLIER },
|
||
{ :id => "counter_palace_goods", :title => "Дворцовая стойка с посудой", :path => "Graphics/Tilesets/RoyalTileset-TileC.png", :rect => [288, 64, 64, 32], :x => 12, :y => 9, :z => 80, :solid => true, :footprint => [2, 1], :z_offset => 2, :layer => "object", :action => "none", :palace => true, :price => PRICE_STATIC * PALACE_PRICE_MULTIPLIER },
|
||
{ :id => "table_palace_long", :title => "Дворцовая длинная стойка", :path => "Graphics/Tilesets/RoyalTileset-TileC.png", :rect => [352, 64, 96, 32], :x => 12, :y => 9, :z => 80, :solid => true, :footprint => [3, 1], :z_offset => 2, :layer => "object", :action => "none", :palace => true, :price => PRICE_STATIC * PALACE_PRICE_MULTIPLIER },
|
||
|
||
{ :id => "chair_red", :title => "Красный стул", :path => "Graphics/Characters/!_clutter2.png", :rect => [192, 32, 32, 32], :x => 14, :y => 9, :z => 80, :solid => true, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "chair_wood", :title => "Деревянный стул", :path => "Graphics/Characters/!_clutter2.png", :rect => [96, 32, 32, 32], :x => 14, :y => 9, :z => 80, :solid => true, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "chair_palace_red", :title => "Дворцовое красное кресло", :path => "Graphics/Tilesets/RoyalTileset-TileB.png", :rect => [384, 320, 32, 32], :x => 14, :y => 9, :z => 80, :solid => true, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "none", :palace => true, :price => PRICE_STATIC * PALACE_PRICE_MULTIPLIER },
|
||
{ :id => "chair_palace_red_front", :title => "Дворцовое красное кресло 2", :path => "Graphics/Tilesets/RoyalTileset-TileB.png", :rect => [384, 352, 32, 32], :x => 14, :y => 9, :z => 80, :solid => true, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "none", :palace => true, :price => PRICE_STATIC * PALACE_PRICE_MULTIPLIER },
|
||
{ :id => "chair_palace_gold", :title => "Дворцовое золотое кресло", :path => "Graphics/Tilesets/RoyalTileset-TileB.png", :rect => [448, 384, 32, 32], :x => 14, :y => 9, :z => 80, :solid => true, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "none", :palace => true, :price => PRICE_STATIC * PALACE_PRICE_MULTIPLIER },
|
||
{ :id => "chair_palace_gold_front", :title => "Дворцовое золотое кресло 2", :path => "Graphics/Tilesets/RoyalTileset-TileB.png", :rect => [448, 416, 32, 32], :x => 14, :y => 9, :z => 80, :solid => true, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "none", :palace => true, :price => PRICE_STATIC * PALACE_PRICE_MULTIPLIER },
|
||
|
||
{ :id => "fireplace_stone", :title => "Каменный камин", :path => "Graphics/Characters/!$_fireplace2.png", :rect => [0, 0, 64, 128], :x => 18, :y => 8, :z => 80, :solid => true, :footprint => [2, 4], :z_offset => 2, :layer => "object", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "fireplace_palace", :title => "Дворцовый камин", :path => "Graphics/Tilesets/RoyalTileset-TileB.png", :rect => [288, 32, 64, 96], :x => 18, :y => 8, :z => 80, :solid => true, :footprint => [2, 3], :z_offset => 2, :layer => "object", :action => "none", :palace => true, :price => PRICE_STATIC * PALACE_PRICE_MULTIPLIER },
|
||
{ :id => "candles_large", :title => "Большие свечи", :path => "Graphics/Characters/!_Z_CandlesLarge.png", :rect => [0, 0, 32, 32], :x => 10, :y => 9, :z => 80, :solid => false, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "candles_large_2", :title => "Большие свечи 2", :path => "Graphics/Characters/!_Z_CandlesLarge.png", :rect => [32, 0, 32, 32], :x => 10, :y => 9, :z => 80, :solid => false, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "candles_large_3", :title => "Большие свечи 3", :path => "Graphics/Characters/!_Z_CandlesLarge.png", :rect => [64, 0, 32, 32], :x => 10, :y => 9, :z => 80, :solid => false, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "shelf_food", :title => "Полка с припасами", :path => "Graphics/Tilesets/Inside_B.png", :rect => [64, 192, 96, 64], :x => 10, :y => 7, :z => 80, :solid => true, :footprint => [3, 2], :z_offset => 2, :layer => "object", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "shelf_books", :title => "Книжная полка", :path => "Graphics/Tilesets/Inside_B.png", :rect => [128, 192, 96, 64], :x => 10, :y => 7, :z => 80, :solid => true, :footprint => [3, 2], :z_offset => 2, :layer => "object", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "vase_clay", :title => "Глиняный горшок", :path => "Graphics/Tilesets/Inside_B.png", :rect => [256, 288, 32, 32], :x => 10, :y => 9, :z => 80, :solid => true, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "pot_lidded", :title => "Горшок с крышкой", :path => "Graphics/Tilesets/Inside_B.png", :rect => [288, 288, 32, 32], :x => 10, :y => 9, :z => 80, :solid => true, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "basket_gold", :title => "Плетёная корзина", :path => "Graphics/Tilesets/Inside_B.png", :rect => [256, 320, 32, 32], :x => 10, :y => 9, :z => 80, :solid => true, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "barrels", :title => "Деревянная бочка", :path => "Graphics/Tilesets/Inside_B.png", :rect => [288, 320, 32, 32], :x => 10, :y => 9, :z => 80, :solid => true, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "crate_small", :title => "Малый ящик", :path => "Graphics/Tilesets/Inside_B.png", :rect => [416, 288, 32, 32], :x => 10, :y => 9, :z => 80, :solid => true, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "crates", :title => "Деревянный ящик", :path => "Graphics/Tilesets/Inside_B.png", :rect => [448, 288, 32, 32], :x => 10, :y => 9, :z => 80, :solid => true, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "column_square", :title => "Квадратная колонна", :path => "Graphics/Tilesets/Inside_B.png", :rect => [320, 288, 32, 64], :x => 10, :y => 8, :z => 80, :solid => true, :footprint => [1, 2], :z_offset => 2, :layer => "object", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "column_round", :title => "Круглая колонна", :path => "Graphics/Tilesets/Inside_B.png", :rect => [384, 288, 32, 64], :x => 10, :y => 8, :z => 80, :solid => true, :footprint => [1, 2], :z_offset => 2, :layer => "object", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "statue_knight", :title => "Дворцовая статуя", :path => "Graphics/Tilesets/RoyalTileset-TileB.png", :rect => [352, 96, 32, 96], :x => 10, :y => 7, :z => 80, :solid => true, :footprint => [1, 3], :z_offset => 2, :layer => "object", :action => "none", :palace => true, :price => PRICE_STATIC * PALACE_PRICE_MULTIPLIER },
|
||
{ :id => "fountain_palace", :title => "Дворцовый фонтан", :path => "Graphics/Characters/!$_fountain.png", :rect => [0, 0, 96, 112], :x => 10, :y => 7, :z => 80, :solid => true, :footprint => [3, 4], :z_offset => 2, :layer => "object", :action => "none", :palace => true, :price => PRICE_STATIC * PALACE_PRICE_MULTIPLIER },
|
||
|
||
{ :id => "wall_stone", :title => "Каменная стена", :path => "Graphics/Tilesets/Inside_B.png", :rect => [192, 0, 32, 32], :x => 7, :y => 5, :z => 40, :solid => true, :footprint => [1, 1], :z_offset => 0, :layer => "wall", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "wall_plaster", :title => "Светлая стена", :path => "Graphics/Tilesets/Inside_B.png", :rect => [96, 0, 32, 32], :x => 7, :y => 5, :z => 40, :solid => true, :footprint => [1, 1], :z_offset => 0, :layer => "wall", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "wall_curtain_dark", :title => "Тёмная занавеска", :path => "Graphics/Tilesets/Inside_B.png", :rect => [256, 0, 32, 64], :x => 7, :y => 5, :z => 40, :solid => false, :footprint => [1, 2], :z_offset => 0, :layer => "wall", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "wall_curtain_torn", :title => "Рваная занавеска", :path => "Graphics/Tilesets/Inside_B.png", :rect => [288, 0, 32, 64], :x => 7, :y => 5, :z => 40, :solid => false, :footprint => [1, 2], :z_offset => 0, :layer => "wall", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "wall_banner_red", :title => "Стена с красным флагом", :path => "Graphics/Tilesets/Inside_B.png", :rect => [416, 0, 32, 64], :x => 7, :y => 5, :z => 40, :solid => false, :footprint => [1, 2], :z_offset => 0, :layer => "wall", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "wall_palace_gray", :title => "Дворцовая каменная стена", :path => "Graphics/Tilesets/RoyalTileset-TileB.png", :rect => [192, 0, 32, 32], :x => 7, :y => 5, :z => 40, :solid => true, :footprint => [1, 1], :z_offset => 0, :layer => "wall", :action => "none", :palace => true, :price => PRICE_STATIC * PALACE_PRICE_MULTIPLIER },
|
||
{ :id => "wall_palace_trim", :title => "Дворцовый верх стены", :path => "Graphics/Tilesets/RoyalTileset-TileB.png", :rect => [256, 0, 32, 32], :x => 7, :y => 5, :z => 40, :solid => true, :footprint => [1, 1], :z_offset => 0, :layer => "wall", :action => "none", :palace => true, :price => PRICE_STATIC * PALACE_PRICE_MULTIPLIER },
|
||
{ :id => "wall_palace_window", :title => "Дворцовый витраж", :path => "Graphics/Tilesets/RoyalTileset-TileB.png", :rect => [288, 96, 32, 64], :x => 7, :y => 5, :z => 40, :solid => false, :footprint => [1, 2], :z_offset => 0, :layer => "wall", :action => "none", :palace => true, :price => PRICE_STATIC * PALACE_PRICE_MULTIPLIER },
|
||
{ :id => "wall_palace_curtain", :title => "Дворцовый витраж с занавеской", :path => "Graphics/Tilesets/RoyalTileset-TileB.png", :rect => [320, 96, 32, 64], :x => 7, :y => 5, :z => 40, :solid => false, :footprint => [1, 2], :z_offset => 0, :layer => "wall", :action => "none", :palace => true, :price => PRICE_STATIC * PALACE_PRICE_MULTIPLIER },
|
||
{ :id => "painting_landscape", :title => "Картина", :path => "Graphics/Tilesets/Inside_B.png", :rect => [384, 96, 64, 32], :x => 7, :y => 5, :z => 40, :solid => false, :footprint => [2, 1], :z_offset => 0, :layer => "wall", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "painting_small", :title => "Малая картина", :path => "Graphics/Tilesets/Inside_B.png", :rect => [448, 96, 32, 32], :x => 7, :y => 5, :z => 40, :solid => false, :footprint => [1, 1], :z_offset => 0, :layer => "wall", :action => "none", :price => PRICE_STATIC },
|
||
{ :id => "painting_palace", :title => "Дворцовая картина", :path => "Graphics/Tilesets/RoyalTileset-TileB.png", :rect => [352, 0, 32, 32], :x => 7, :y => 5, :z => 40, :solid => false, :footprint => [1, 1], :z_offset => 0, :layer => "wall", :action => "none", :palace => true, :price => PRICE_STATIC * PALACE_PRICE_MULTIPLIER }
|
||
] unless const_defined?(:EXTRA_GRID_ITEMS)
|
||
GRID_ITEM_PATCHES = {
|
||
"bed" => { :title => "Кровать", :rect => [0, 0, 64, 64], :solid => true, :footprint => [2, 2], :z_offset => 2, :layer => "object", :action => "sleep", :price => PRICE_INTERACTIVE },
|
||
"table" => { :title => "Стол", :rect => [0, 0, 160, 128], :solid => true, :footprint => [5, 4], :z_offset => 2, :layer => "object", :action => "none", :price => PRICE_STATIC },
|
||
"chair" => { :title => "Стул", :rect => [0, 0, 30, 20], :solid => true, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "none", :price => PRICE_STATIC },
|
||
"chest" => { :title => "Сундук", :rect => [0, 0, 32, 32], :solid => true, :footprint => [1, 1], :z_offset => 2, :layer => "object", :action => "storage", :price => PRICE_INTERACTIVE },
|
||
"fireplace" => { :title => "Камин", :rect => [0, 0, 64, 128], :solid => true, :footprint => [2, 4], :z_offset => 2, :layer => "object", :action => "none", :price => PRICE_STATIC },
|
||
"wall_wood" => { :title => "Деревянная стена", :rect => [32, 0, 32, 32], :solid => true, :footprint => [1, 1], :z_offset => 0, :layer => "wall", :action => "none", :price => PRICE_STATIC },
|
||
"wall_poor" => { :title => "Бедная стена", :rect => [32, 0, 32, 32], :solid => true, :footprint => [1, 1], :z_offset => 0, :layer => "wall", :action => "none", :price => PRICE_STATIC }
|
||
} unless const_defined?(:GRID_ITEM_PATCHES)
|
||
class << self
|
||
def install_grid_items
|
||
return if @grid_items_installed
|
||
@grid_items_installed = true
|
||
GRID_ITEM_PATCHES.each do |id, attrs|
|
||
item = ITEMS.find { |row| row[:id].to_s == id.to_s }
|
||
next unless item
|
||
attrs.each { |key, value| item[key] = value }
|
||
end
|
||
EXTRA_GRID_ITEMS.each do |extra|
|
||
next if ITEMS.any? { |row| row[:id].to_s == extra[:id].to_s }
|
||
ITEMS << extra
|
||
end
|
||
unless ITEMS.any? { |row| row[:id].to_s == BASE_CLEAR_ID }
|
||
ITEMS << { :id => BASE_CLEAR_ID, :title => "Скрытая очистка карты", :hidden => true, :solid => false, :footprint => [1, 1], :layer => "clear", :action => "none", :price => 0 }
|
||
end
|
||
ITEMS.each do |item|
|
||
next if base_clear_item?(item)
|
||
item[:price] = default_item_price(item) unless item.has_key?(:price)
|
||
item[:title] = item[:id].to_s if item[:title].to_s.strip == ""
|
||
end
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def item_by_id(id)
|
||
install_grid_items
|
||
ITEMS.find { |item| item[:id].to_s == id.to_s }
|
||
rescue
|
||
nil
|
||
end
|
||
|
||
def legacy_enabled_ids(blob = nil)
|
||
text = blob.nil? ? NoerHomeEstate.decor_blob.to_s : blob.to_s
|
||
text.split(",").map { |v| v.strip }.reject { |v| v == "" }.uniq
|
||
rescue
|
||
[]
|
||
end
|
||
|
||
def placements
|
||
install_grid_items
|
||
blob = NoerHomeEstate.decor_blob.to_s
|
||
rows = []
|
||
|
||
if blob.start_with?(PLACEMENT_PREFIX)
|
||
blob[PLACEMENT_PREFIX.length..-1].to_s.split("|").each do |entry|
|
||
parts = entry.split(",", 3)
|
||
next unless parts.length >= 3
|
||
item = item_by_id(parts[0])
|
||
next unless item
|
||
rows << { :id => item[:id].to_s, :x => parts[1].to_i, :y => parts[2].to_i }
|
||
end
|
||
else
|
||
legacy_enabled_ids(blob).each do |id|
|
||
item = item_by_id(id)
|
||
next unless item
|
||
rows << { :id => item[:id].to_s, :x => item[:x].to_i, :y => item[:y].to_i }
|
||
end
|
||
end
|
||
|
||
rows
|
||
rescue
|
||
[]
|
||
end
|
||
|
||
def encode_placements(rows)
|
||
clean = []
|
||
rows.each do |row|
|
||
id = row[:id].to_s
|
||
item = item_by_id(id)
|
||
next unless item
|
||
x = row[:x].to_i
|
||
y = row[:y].to_i
|
||
clean << [id.gsub(/[|,]/, ""), x, y].join(",")
|
||
end
|
||
clean.empty? ? "" : PLACEMENT_PREFIX + clean.join("|")
|
||
rescue
|
||
""
|
||
end
|
||
|
||
def save_placements(rows)
|
||
install_grid_items
|
||
return false unless own_house?
|
||
return false unless NoerHomeEstate.set_decor_blob(encode_placements(rows))
|
||
NoerHomeEstate.sync_to_server(true)
|
||
true
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def interactive_item?(item)
|
||
action = item ? item[:action].to_s : ""
|
||
action == "storage" || action == "sleep"
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def palace_item?(item)
|
||
item && item[:palace] == true
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def default_item_price(item)
|
||
return 0 if base_clear_item?(item)
|
||
base = floor_item?(item) ? PRICE_FLOOR : (interactive_item?(item) ? PRICE_INTERACTIVE : PRICE_STATIC)
|
||
palace_item?(item) ? base * PALACE_PRICE_MULTIPLIER : base
|
||
rescue
|
||
0
|
||
end
|
||
|
||
def item_price(item)
|
||
return 0 unless item
|
||
price = item[:price]
|
||
price.nil? ? default_item_price(item) : [price.to_i, 0].max
|
||
rescue
|
||
0
|
||
end
|
||
|
||
def placement_price(row)
|
||
item_price(item_by_id(row[:id]))
|
||
rescue
|
||
0
|
||
end
|
||
|
||
def rows_price(rows)
|
||
rows.to_a.inject(0) { |sum, row| sum + placement_price(row) }
|
||
rescue
|
||
0
|
||
end
|
||
|
||
def coin_item(name, fallback_id)
|
||
begin
|
||
if defined?($data_ItemName) && $data_ItemName
|
||
item = $data_ItemName[name.to_s]
|
||
return item if item
|
||
end
|
||
rescue
|
||
end
|
||
begin
|
||
return $data_items[fallback_id.to_i] if defined?($data_items) && $data_items
|
||
rescue
|
||
end
|
||
nil
|
||
end
|
||
|
||
def coin_inventory
|
||
COIN_SPECS.map do |name, fallback_id, value|
|
||
[coin_item(name, fallback_id), value.to_i]
|
||
end
|
||
rescue
|
||
[]
|
||
end
|
||
|
||
def coin_counts
|
||
return [] unless defined?($game_party) && $game_party
|
||
coin_inventory.map do |item, value|
|
||
count = item ? $game_party.item_number(item).to_i : 0
|
||
[item, value, count]
|
||
end
|
||
rescue
|
||
[]
|
||
end
|
||
|
||
def wallet_amount
|
||
coin_counts.inject(0) do |sum, row|
|
||
item, value, count = row
|
||
item ? sum + value.to_i * count.to_i : sum
|
||
end
|
||
rescue
|
||
0
|
||
end
|
||
|
||
def apply_coin_counts(snapshot, desired)
|
||
return false unless defined?($game_party) && $game_party
|
||
return false unless snapshot.length == desired.length
|
||
return false if snapshot.any? { |row| row[0].nil? }
|
||
|
||
snapshot.each_with_index do |row, index|
|
||
item = row[0]
|
||
current = row[2].to_i
|
||
target = [desired[index].to_i, 0].max
|
||
delta = target - current
|
||
$game_party.gain_item(item, delta) if delta != 0
|
||
end
|
||
|
||
valid = snapshot.each_with_index.all? do |row, index|
|
||
$game_party.item_number(row[0]).to_i == [desired[index].to_i, 0].max
|
||
end
|
||
return true if valid
|
||
|
||
snapshot.each do |row|
|
||
item = row[0]
|
||
original = row[2].to_i
|
||
now = $game_party.item_number(item).to_i
|
||
$game_party.gain_item(item, original - now) if now != original
|
||
end
|
||
false
|
||
rescue
|
||
begin
|
||
snapshot.each do |row|
|
||
next unless row && row[0]
|
||
original = row[2].to_i
|
||
now = $game_party.item_number(row[0]).to_i
|
||
$game_party.gain_item(row[0], original - now) if now != original
|
||
end
|
||
rescue
|
||
end
|
||
false
|
||
end
|
||
|
||
def spend_coins(amount)
|
||
cost = amount.to_i
|
||
return true if cost <= 0
|
||
snapshot = coin_counts
|
||
return false if snapshot.empty? || snapshot.any? { |row| row[0].nil? }
|
||
return false if wallet_amount < cost
|
||
|
||
desired = snapshot.map { |row| row[2].to_i }
|
||
remaining = cost
|
||
|
||
snapshot.each_with_index do |row, index|
|
||
value = row[1].to_i
|
||
next if value <= 0
|
||
use = [desired[index], remaining / value].min
|
||
desired[index] -= use
|
||
remaining -= use * value
|
||
end
|
||
|
||
if remaining > 0
|
||
break_index = nil
|
||
snapshot.each_with_index do |row, index|
|
||
if row[1].to_i > remaining && desired[index] > 0
|
||
break_index = index
|
||
break
|
||
end
|
||
end
|
||
return false if break_index.nil?
|
||
|
||
broken_value = snapshot[break_index][1].to_i
|
||
desired[break_index] -= 1
|
||
change = broken_value - remaining
|
||
remaining = 0
|
||
|
||
(break_index - 1).downto(0) do |index|
|
||
value = snapshot[index][1].to_i
|
||
next if value <= 0
|
||
add = change / value
|
||
desired[index] += add
|
||
change -= add * value
|
||
end
|
||
return false if change != 0
|
||
end
|
||
|
||
apply_coin_counts(snapshot, desired)
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def refund_coins(amount)
|
||
refund = amount.to_i
|
||
return true if refund <= 0
|
||
snapshot = coin_counts
|
||
return false if snapshot.empty? || snapshot.any? { |row| row[0].nil? }
|
||
|
||
desired = snapshot.map { |row| row[2].to_i }
|
||
remaining = refund
|
||
(snapshot.length - 1).downto(0) do |index|
|
||
value = snapshot[index][1].to_i
|
||
next if value <= 0
|
||
add = remaining / value
|
||
desired[index] += add
|
||
remaining -= add * value
|
||
end
|
||
return false if remaining != 0
|
||
|
||
apply_coin_counts(snapshot, desired)
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def plural_ru(number, one, few, many)
|
||
n = number.to_i.abs % 100
|
||
n1 = n % 10
|
||
return many if n >= 11 && n <= 14
|
||
return one if n1 == 1
|
||
return few if n1 >= 2 && n1 <= 4
|
||
many
|
||
rescue
|
||
many
|
||
end
|
||
|
||
def price_label(amount, prefer_small = false)
|
||
value = amount.to_i
|
||
return "бесплатно" if value <= 0
|
||
if prefer_small || value < MEDIUM_COPPER || value % MEDIUM_COPPER != 0
|
||
"#{value} #{plural_ru(value, "малый медяк", "малых медяка", "малых медяков")}"
|
||
else
|
||
medium = value / MEDIUM_COPPER
|
||
"#{medium} #{plural_ru(medium, "средний медяк", "средних медяка", "средних медяков")}"
|
||
end
|
||
rescue
|
||
amount.to_i.to_s
|
||
end
|
||
|
||
def price_label_for(item)
|
||
price_label(item_price(item), floor_item?(item))
|
||
rescue
|
||
"бесплатно"
|
||
end
|
||
|
||
def sync_money_change(reason)
|
||
return true unless defined?(MPCloudOnlySave)
|
||
tag = reason.to_s == "" ? "home_decor_money" : reason.to_s
|
||
if MPCloudOnlySave.respond_to?(:send_tracked_now)
|
||
MPCloudOnlySave.send_tracked_now(tag, true) || (MPCloudOnlySave.request(tag, 1) if MPCloudOnlySave.respond_to?(:request))
|
||
elsif MPCloudOnlySave.respond_to?(:request)
|
||
MPCloudOnlySave.request(tag, 1)
|
||
end
|
||
true
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def apply_price_delta(delta, reason = "home_decor_money", prefer_small = false)
|
||
change = delta.to_i
|
||
return true if change == 0
|
||
return false unless defined?($game_party) && $game_party
|
||
if change > 0
|
||
balance = wallet_amount
|
||
if balance < change
|
||
notify("Не хватает денег. Нужно: #{price_label(change, prefer_small)}. У тебя: #{price_label(balance)}.")
|
||
return false
|
||
end
|
||
return false unless spend_coins(change)
|
||
else
|
||
return false unless refund_coins(-change)
|
||
end
|
||
sync_money_change(reason)
|
||
true
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def last_refund_amount
|
||
(@last_refund_amount || 0).to_i
|
||
rescue
|
||
0
|
||
end
|
||
|
||
def floor_item?(item)
|
||
item && (item[:floor] == true || item[:layer].to_s == "floor")
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def solid_item?(item)
|
||
item && !floor_item?(item) && !base_clear_item?(item) && item[:solid] != false
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def base_clear_item?(item_or_id)
|
||
id = item_or_id.is_a?(Hash) ? item_or_id[:id] : item_or_id
|
||
id.to_s == BASE_CLEAR_ID
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def floor_tile_id_for(item)
|
||
return 0 unless item
|
||
return item[:tile_id].to_i if item[:tile_id].to_i > 0
|
||
rect = item[:rect]
|
||
return 0 unless rect.is_a?(Array) && rect.length >= 2
|
||
TILE_ID_A5 + (rect[1].to_i / 32) * 8 + (rect[0].to_i / 32)
|
||
rescue
|
||
0
|
||
end
|
||
|
||
def footprint_for(item)
|
||
fp = item ? item[:footprint] : nil
|
||
return [[fp[0].to_i, 1].max, [fp[1].to_i, 1].max] if fp.is_a?(Array) && fp.length >= 2
|
||
rect = item ? item[:rect] : nil
|
||
if rect.is_a?(Array) && rect.length >= 4
|
||
return [[(rect[2].to_i + 31) / 32, 1].max, [(rect[3].to_i + 31) / 32, 1].max]
|
||
end
|
||
[1, 1]
|
||
rescue
|
||
[1, 1]
|
||
end
|
||
|
||
def row_footprint_cells(row)
|
||
item = item_by_id(row[:id])
|
||
return [] unless item
|
||
w, h = footprint_for(item)
|
||
sx = row[:x].to_i
|
||
sy = row[:y].to_i
|
||
cells = []
|
||
h.times do |dy|
|
||
w.times do |dx|
|
||
cells << [sx + dx, sy + dy]
|
||
end
|
||
end
|
||
cells
|
||
rescue
|
||
[]
|
||
end
|
||
|
||
def row_covers_tile?(row, x, y)
|
||
row_footprint_cells(row).any? { |cell| cell[0] == x.to_i && cell[1] == y.to_i }
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def row_intersects_area?(row, x, y, w, h)
|
||
x1 = x.to_i
|
||
y1 = y.to_i
|
||
x2 = x1 + [w.to_i, 1].max - 1
|
||
y2 = y1 + [h.to_i, 1].max - 1
|
||
row_footprint_cells(row).any? { |cell| cell[0] >= x1 && cell[0] <= x2 && cell[1] >= y1 && cell[1] <= y2 }
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def placement_at(x, y, solids_only = false)
|
||
placements.find do |row|
|
||
item = item_by_id(row[:id])
|
||
item && File.file?(item[:path].to_s) && (!solids_only || solid_item?(item)) && row_covers_tile?(row, x, y)
|
||
end
|
||
rescue
|
||
nil
|
||
end
|
||
|
||
def top_placement_in_rows(rows, x, y, include_floor = true, actions_only = false)
|
||
matches = rows.select do |row|
|
||
item = item_by_id(row[:id])
|
||
next false unless item && File.file?(item[:path].to_s)
|
||
next false if !include_floor && floor_item?(item)
|
||
action = item[:action].to_s
|
||
next false if actions_only && (action == "" || action == "none")
|
||
row_covers_tile?(row, x, y)
|
||
end
|
||
matches.sort_by do |row|
|
||
item = item_by_id(row[:id])
|
||
[floor_item?(item) ? 0 : 1, render_z_for(row, item)]
|
||
end.last
|
||
rescue
|
||
nil
|
||
end
|
||
|
||
def top_placement_at(x, y, include_floor = true, actions_only = false)
|
||
top_placement_in_rows(placements, x, y, include_floor, actions_only)
|
||
rescue
|
||
nil
|
||
end
|
||
|
||
def blocked_tile?(x, y)
|
||
house_visible? && !!placement_at(x, y, true)
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def render_z_for(row, item)
|
||
return item[:z].to_i if floor_item?(item)
|
||
fp = footprint_for(item)
|
||
base_y = row[:y].to_i + fp[1] - 1
|
||
10 + base_y * 3 + (item[:z_offset] || 2).to_i
|
||
rescue
|
||
80
|
||
end
|
||
|
||
def floor_cell_clear?(x, y)
|
||
tx = x.to_i
|
||
ty = y.to_i
|
||
return false unless defined?($game_map) && $game_map
|
||
$game_map.valid?(tx, ty)
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def base_clear_at?(x, y, rows = nil)
|
||
tx = x.to_i
|
||
ty = y.to_i
|
||
(rows || placements).any? { |row| base_clear_item?(row[:id]) && row[:x].to_i == tx && row[:y].to_i == ty }
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def base_tile_present_at?(x, y)
|
||
tx = x.to_i
|
||
ty = y.to_i
|
||
return false unless defined?($game_map) && $game_map
|
||
return false unless $game_map.valid?(tx, ty)
|
||
data = ($game_map.data rescue nil)
|
||
data && (data[tx, ty, 1].to_i > 0 || data[tx, ty, 2].to_i > 0)
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def can_clear_base_at?(x, y)
|
||
tx = x.to_i
|
||
ty = y.to_i
|
||
return false unless defined?($game_map) && $game_map
|
||
return false unless $game_map.valid?(tx, ty)
|
||
return true if base_tile_present_at?(tx, ty)
|
||
events = ($game_map.events_xy_nt(tx, ty) rescue [])
|
||
events && events.any? { |event| clearable_base_event?(event) }
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def base_clear_cells_for(x, y)
|
||
tx = x.to_i
|
||
ty = y.to_i
|
||
return [[tx, ty]] unless base_tile_present_at?(tx, ty)
|
||
visited = {}
|
||
pending = [[tx, ty]]
|
||
cells = []
|
||
while !pending.empty? && cells.length < 24
|
||
cx, cy = pending.shift
|
||
key = [cx, cy]
|
||
next if visited[key]
|
||
visited[key] = true
|
||
next unless base_tile_present_at?(cx, cy)
|
||
cells << [cx, cy]
|
||
[[1, 0], [-1, 0], [0, 1], [0, -1]].each do |step|
|
||
nx = cx + step[0]
|
||
ny = cy + step[1]
|
||
next if (nx - tx).abs > 5 || (ny - ty).abs > 5
|
||
pending << [nx, ny]
|
||
end
|
||
end
|
||
cells.empty? ? [[tx, ty]] : cells
|
||
rescue
|
||
[[x.to_i, y.to_i]]
|
||
end
|
||
|
||
def clear_base_tile(x, y)
|
||
tx = x.to_i
|
||
ty = y.to_i
|
||
rows = placements
|
||
added = false
|
||
base_clear_cells_for(tx, ty).each do |cell|
|
||
cx = cell[0].to_i
|
||
cy = cell[1].to_i
|
||
next if base_clear_at?(cx, cy, rows)
|
||
next unless can_clear_base_at?(cx, cy)
|
||
rows << { :id => BASE_CLEAR_ID, :x => cx, :y => cy }
|
||
added = true
|
||
end
|
||
return false unless added
|
||
save_placements(rows)
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def map_override_signature(rows)
|
||
rows.select do |row|
|
||
item = item_by_id(row[:id])
|
||
floor_item?(item) || base_clear_item?(item)
|
||
end.map { |row| [row[:id].to_s, row[:x].to_i, row[:y].to_i].join(":") }.sort.join(";")
|
||
rescue
|
||
""
|
||
end
|
||
|
||
def remember_original_tile(data, x, y, z)
|
||
@map_override_originals ||= {}
|
||
key = [x.to_i, y.to_i, z.to_i]
|
||
@map_override_originals[key] = data[x.to_i, y.to_i, z.to_i] unless @map_override_originals.has_key?(key)
|
||
rescue
|
||
nil
|
||
end
|
||
|
||
def base_events_at(x, y)
|
||
tx = x.to_i
|
||
ty = y.to_i
|
||
if $game_map.respond_to?(:events_xy)
|
||
return ($game_map.events_xy(tx, ty) rescue [])
|
||
end
|
||
events = ($game_map.events.values rescue [])
|
||
events.select { |event| (event.x rescue nil) == tx && (event.y rescue nil) == ty }
|
||
rescue
|
||
[]
|
||
end
|
||
|
||
def clearable_base_event?(event)
|
||
return false unless event
|
||
return false if (event.deleted? rescue false) || (event.erased rescue false)
|
||
name = ((event.event.name rescue "") || "").downcase
|
||
guarded = ["door", "exit", "enter", "transfer", "warp", "menu", "cat", "noer", "home"]
|
||
return false if guarded.any? { |token| name.include?(token) }
|
||
list = (event.list rescue nil)
|
||
return true if list.nil? || list.empty?
|
||
active_codes = list.map { |cmd| (cmd.code rescue 0).to_i }.select { |code| code > 0 && code != 108 && code != 408 }
|
||
active_codes.empty?
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def remember_event_state(event)
|
||
return unless event
|
||
@map_override_event_originals ||= {}
|
||
key = event.object_id
|
||
return if @map_override_event_originals.has_key?(key)
|
||
@map_override_event_originals[key] = {
|
||
:event => event,
|
||
:transparent => (event.transparent rescue nil),
|
||
:through => (event.through rescue nil)
|
||
}
|
||
rescue
|
||
nil
|
||
end
|
||
|
||
def hide_base_events_at(x, y)
|
||
base_events_at(x, y).each do |event|
|
||
next unless clearable_base_event?(event)
|
||
remember_event_state(event)
|
||
event.transparent = true if event.respond_to?(:transparent=)
|
||
event.through = true if event.respond_to?(:through=)
|
||
end
|
||
true
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def restore_map_overrides
|
||
if @map_override_data && @map_override_originals
|
||
@map_override_originals.each do |key, value|
|
||
x, y, z = key
|
||
@map_override_data[x, y, z] = value
|
||
end
|
||
end
|
||
if @map_override_event_originals
|
||
@map_override_event_originals.each_value do |state|
|
||
event = state[:event]
|
||
next unless event
|
||
event.transparent = state[:transparent] if !state[:transparent].nil? && event.respond_to?(:transparent=)
|
||
event.through = state[:through] if !state[:through].nil? && event.respond_to?(:through=)
|
||
end
|
||
end
|
||
@map_override_originals = nil
|
||
@map_override_event_originals = nil
|
||
@map_override_data = nil
|
||
@map_override_signature = nil
|
||
true
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def apply_map_overrides(rows = nil)
|
||
return restore_map_overrides unless house_visible?
|
||
rows ||= placements
|
||
data = ($game_map.data rescue nil)
|
||
return false unless data
|
||
signature = map_override_signature(rows)
|
||
if @map_override_signature == signature && @map_override_data.equal?(data)
|
||
rows.each do |row|
|
||
item = item_by_id(row[:id])
|
||
hide_base_events_at(row[:x], row[:y]) if base_clear_item?(item)
|
||
end
|
||
return true
|
||
end
|
||
|
||
restore_map_overrides
|
||
@map_override_data = data
|
||
@map_override_originals = {}
|
||
@map_override_event_originals = {}
|
||
rows.each do |row|
|
||
item = item_by_id(row[:id])
|
||
next unless item
|
||
x = row[:x].to_i
|
||
y = row[:y].to_i
|
||
next unless $game_map.valid?(x, y)
|
||
if base_clear_item?(item)
|
||
[1, 2].each do |z|
|
||
remember_original_tile(data, x, y, z)
|
||
data[x, y, z] = 0
|
||
end
|
||
hide_base_events_at(x, y)
|
||
elsif floor_item?(item)
|
||
tile_id = floor_tile_id_for(item)
|
||
next unless tile_id > 0
|
||
remember_original_tile(data, x, y, 0)
|
||
data[x, y, 0] = tile_id
|
||
end
|
||
end
|
||
@map_override_signature = signature
|
||
true
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def enabled_ids
|
||
placements.map { |row| row[:id].to_s }.uniq
|
||
rescue
|
||
[]
|
||
end
|
||
|
||
def save_rows_with_price(new_rows, reason = "home_decor_legacy_save")
|
||
install_grid_items
|
||
return false unless own_house?
|
||
old_rows = placements
|
||
delta = rows_price(new_rows) - rows_price(old_rows)
|
||
return false if delta > 0 && !apply_price_delta(delta, reason)
|
||
unless save_placements(new_rows)
|
||
apply_price_delta(-delta, "#{reason}_rollback") if delta > 0
|
||
return false
|
||
end
|
||
apply_price_delta(delta, "#{reason}_refund") if delta < 0
|
||
true
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def save_ids(ids)
|
||
install_grid_items
|
||
return false unless own_house?
|
||
clean = ids.to_a.map { |v| v.to_s }.select { |id| item_by_id(id) }.uniq
|
||
new_rows = clean.map do |id|
|
||
item = item_by_id(id)
|
||
{ :id => item[:id].to_s, :x => item[:x].to_i, :y => item[:y].to_i }
|
||
end
|
||
save_rows_with_price(new_rows, "home_decor_legacy_save")
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def toggle(id)
|
||
install_grid_items
|
||
return false unless own_house?
|
||
item = item_by_id(id)
|
||
return false unless item
|
||
removed = false
|
||
new_rows = []
|
||
placements.each do |row|
|
||
if !removed && row[:id].to_s == item[:id].to_s
|
||
removed = true
|
||
next
|
||
end
|
||
new_rows << row
|
||
end
|
||
unless removed
|
||
new_rows << { :id => item[:id].to_s, :x => item[:x].to_i, :y => item[:y].to_i }
|
||
end
|
||
save_rows_with_price(new_rows, "home_decor_legacy_toggle")
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def active_items
|
||
install_grid_items
|
||
rows = placements
|
||
apply_map_overrides(rows)
|
||
rows.map do |row|
|
||
item = item_by_id(row[:id])
|
||
next nil unless item && File.file?(item[:path].to_s)
|
||
next nil if floor_item?(item) || base_clear_item?(item) || item[:hidden]
|
||
placed = item.dup
|
||
placed[:x] = row[:x].to_i
|
||
placed[:y] = row[:y].to_i
|
||
placed[:z] = render_z_for(row, item)
|
||
placed
|
||
end.compact.sort_by { |item| [item[:z].to_i, floor_item?(item) ? 0 : 1] }
|
||
rescue
|
||
[]
|
||
end
|
||
def reset_placements
|
||
install_grid_items
|
||
return false unless own_house?
|
||
rows = placements
|
||
refund = rows_price(rows)
|
||
@last_refund_amount = 0
|
||
NoerHomeEstate.set_decor_blob("")
|
||
NoerHomeEstate.sync_to_server(true)
|
||
restore_map_overrides
|
||
if refund > 0 && apply_price_delta(-refund, "home_decor_reset_refund")
|
||
@last_refund_amount = refund
|
||
end
|
||
true
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def storage_box_id
|
||
if defined?(System_Settings) && System_Settings.const_defined?(:STORAGE_NOERHOME)
|
||
return System_Settings::STORAGE_NOERHOME.to_i
|
||
end
|
||
if defined?(System_Settings) && System_Settings.const_defined?(:STORAGE_BANK)
|
||
return System_Settings::STORAGE_BANK.to_i
|
||
end
|
||
65533
|
||
rescue
|
||
65533
|
||
end
|
||
|
||
def notify(text)
|
||
NoerHomeEstate.notify(text) if defined?(NoerHomeEstate)
|
||
rescue
|
||
end
|
||
|
||
def front_action_row
|
||
return nil unless own_house?
|
||
fx = $game_map.round_x_with_direction($game_player.x, $game_player.direction)
|
||
fy = $game_map.round_y_with_direction($game_player.y, $game_player.direction)
|
||
top_placement_at(fx, fy, false, true) || top_placement_at($game_player.x, $game_player.y, false, true)
|
||
rescue
|
||
nil
|
||
end
|
||
|
||
def request_action(row)
|
||
return false if @action_fiber && @action_fiber.alive?
|
||
id = row[:id].to_s
|
||
@action_fiber = Fiber.new { Game_Interpreter.new.noerhome_decor_use_item(id) }
|
||
update_action_fiber
|
||
true
|
||
rescue
|
||
@action_fiber = nil
|
||
false
|
||
end
|
||
|
||
def update_action_fiber
|
||
return if @action_fiber.nil?
|
||
if @action_fiber.alive?
|
||
@action_fiber.resume
|
||
else
|
||
@action_fiber = nil
|
||
end
|
||
rescue FiberError
|
||
@action_fiber = nil
|
||
rescue
|
||
@action_fiber = nil
|
||
end
|
||
|
||
def handle_action
|
||
return false unless own_house?
|
||
return false if defined?(NoerHomeDecorEditor) && NoerHomeDecorEditor.active?
|
||
row = front_action_row
|
||
return false unless row
|
||
request_action(row)
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def open_storage
|
||
return false unless own_house?
|
||
box_id = storage_box_id
|
||
klass = nil
|
||
begin
|
||
if defined?(System_Settings) && System_Settings.const_defined?(:STORAGE_BANK) && box_id == System_Settings::STORAGE_BANK.to_i && defined?(Scene_BankStorage)
|
||
klass = Scene_BankStorage
|
||
elsif defined?(Scene_NoerHomeStorage)
|
||
klass = Scene_NoerHomeStorage
|
||
elsif defined?(Scene_ItemStorage)
|
||
klass = Scene_ItemStorage
|
||
end
|
||
rescue
|
||
klass = defined?(Scene_ItemStorage) ? Scene_ItemStorage : nil
|
||
end
|
||
return false unless klass && defined?(SceneManager)
|
||
SceneManager.goto(klass)
|
||
SceneManager.scene.prepare(box_id) if SceneManager.scene && SceneManager.scene.respond_to?(:prepare)
|
||
true
|
||
rescue
|
||
notify("Сундук сейчас недоступен.")
|
||
false
|
||
end
|
||
|
||
end
|
||
end
|
||
|
||
module NoerHomeDecorEditor
|
||
module_function
|
||
|
||
HUD_HEIGHT = 64
|
||
|
||
def active?
|
||
@active == true
|
||
end
|
||
|
||
def palette
|
||
NoerHomeDecor.install_grid_items
|
||
NoerHomeDecor::ITEMS.select { |item| !item[:hidden] && File.file?(item[:path].to_s) }
|
||
rescue
|
||
[]
|
||
end
|
||
|
||
def selected_item
|
||
list = palette
|
||
return nil if list.empty?
|
||
@index ||= 0
|
||
@index = [[@index, 0].max, list.length - 1].min
|
||
list[@index]
|
||
end
|
||
|
||
def start
|
||
return false unless NoerHomeDecor.own_house?
|
||
@active = true
|
||
@index ||= 0
|
||
@cursor_x = ($game_player.x rescue 8)
|
||
@cursor_y = ($game_player.y rescue 8)
|
||
@last_hud_signature = nil
|
||
@last_preview_signature = nil
|
||
create_sprites
|
||
refresh_hud(true)
|
||
refresh_preview(true)
|
||
play_ok
|
||
true
|
||
rescue
|
||
@active = false
|
||
false
|
||
end
|
||
|
||
def start_at(x, y)
|
||
ok = start
|
||
set_cursor_tile(x, y, false) if ok
|
||
ok
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def stop
|
||
return unless active?
|
||
dispose_sprites
|
||
@active = false
|
||
play_cancel
|
||
true
|
||
rescue
|
||
@active = false
|
||
false
|
||
end
|
||
|
||
def update
|
||
return unless active?
|
||
create_sprites
|
||
update_mouse
|
||
update_keyboard
|
||
update_sprite_positions
|
||
refresh_hud(false)
|
||
refresh_preview(false)
|
||
rescue
|
||
stop
|
||
end
|
||
|
||
def update_keyboard
|
||
if input_trigger?(:B, :ESCAPE)
|
||
stop
|
||
return
|
||
end
|
||
|
||
if input_trigger?(:L, :LETTER_Q)
|
||
change_item(-1)
|
||
elsif input_trigger?(:R, :LETTER_E)
|
||
change_item(1)
|
||
end
|
||
|
||
if input_repeat?(:LEFT)
|
||
move_cursor(-1, 0)
|
||
elsif input_repeat?(:RIGHT)
|
||
move_cursor(1, 0)
|
||
elsif input_repeat?(:UP)
|
||
move_cursor(0, -1)
|
||
elsif input_repeat?(:DOWN)
|
||
move_cursor(0, 1)
|
||
end
|
||
|
||
place_current if input_trigger?(:C, :ENTER, :RETURN)
|
||
erase_current if input_trigger?(:DELETE)
|
||
end
|
||
|
||
def update_mouse
|
||
return unless defined?(Mouse) && Mouse.usable?
|
||
xy = Mouse.GetMouseXY rescue nil
|
||
return unless xy && xy[0] && xy[1]
|
||
set_cursor_tile(mouse_to_tile_x(xy[0]), mouse_to_tile_y(xy[1]), false)
|
||
place_current if input_trigger?(:MZ_LINK)
|
||
erase_current if input_trigger?(:MX_LINK)
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def change_item(delta)
|
||
list = palette
|
||
return if list.empty?
|
||
@index = ((@index || 0) + delta) % list.length
|
||
@last_hud_signature = nil
|
||
@last_preview_signature = nil
|
||
play_cursor
|
||
end
|
||
|
||
def move_cursor(dx, dy)
|
||
set_cursor_tile((@cursor_x || 0) + dx, (@cursor_y || 0) + dy)
|
||
end
|
||
|
||
def set_cursor_tile(x, y, sound = true)
|
||
max_x = [($game_map.width rescue 1) - 1, 0].max
|
||
max_y = [($game_map.height rescue 1) - 1, 0].max
|
||
new_x = [[x.to_i, 0].max, max_x].min
|
||
new_y = [[y.to_i, 0].max, max_y].min
|
||
return if @cursor_x == new_x && @cursor_y == new_y
|
||
@cursor_x = new_x
|
||
@cursor_y = new_y
|
||
@last_hud_signature = nil
|
||
play_cursor if sound
|
||
end
|
||
|
||
def mouse_to_tile_x(screen_x)
|
||
(($game_map.display_x rescue 0) + screen_x.to_f / 32.0).floor
|
||
end
|
||
|
||
def mouse_to_tile_y(screen_y)
|
||
(($game_map.display_y rescue 0) + screen_y.to_f / 32.0).floor
|
||
end
|
||
|
||
def place_current
|
||
item = selected_item
|
||
return play_buzzer unless item
|
||
return play_buzzer unless can_place_item?(item, @cursor_x, @cursor_y)
|
||
rows = NoerHomeDecor.placements
|
||
new_rows = rows_without_conflicts(rows, item, @cursor_x, @cursor_y)
|
||
removed_rows = rows.reject { |row| new_rows.include?(row) }
|
||
price_delta = NoerHomeDecor.item_price(item) - NoerHomeDecor.rows_price(removed_rows)
|
||
return play_buzzer if price_delta > 0 && !NoerHomeDecor.apply_price_delta(price_delta, "home_decor_place", NoerHomeDecor.floor_item?(item))
|
||
new_rows << { :id => item[:id].to_s, :x => @cursor_x.to_i, :y => @cursor_y.to_i }
|
||
unless NoerHomeDecor.save_placements(new_rows)
|
||
NoerHomeDecor.apply_price_delta(-price_delta, "home_decor_place_rollback") if price_delta > 0
|
||
return play_buzzer
|
||
end
|
||
NoerHomeDecor.apply_price_delta(price_delta, "home_decor_place_refund") if price_delta < 0
|
||
@last_hud_signature = nil
|
||
play_ok
|
||
rescue
|
||
play_buzzer
|
||
end
|
||
|
||
def erase_current
|
||
rows = NoerHomeDecor.placements
|
||
target = NoerHomeDecor.top_placement_in_rows(rows, @cursor_x, @cursor_y, true, false)
|
||
if target
|
||
refund = NoerHomeDecor.placement_price(target)
|
||
rows.delete(target)
|
||
return play_buzzer unless NoerHomeDecor.save_placements(rows)
|
||
NoerHomeDecor.apply_price_delta(-refund, "home_decor_dismantle_refund") if refund > 0
|
||
@last_hud_signature = nil
|
||
return play_cancel
|
||
end
|
||
if NoerHomeDecor.clear_base_tile(@cursor_x, @cursor_y)
|
||
@last_hud_signature = nil
|
||
return play_cancel
|
||
end
|
||
play_buzzer
|
||
rescue
|
||
play_buzzer
|
||
end
|
||
|
||
def rows_without_conflicts(rows, item, x, y)
|
||
if NoerHomeDecor.floor_item?(item)
|
||
rows.reject do |row|
|
||
other = NoerHomeDecor.item_by_id(row[:id])
|
||
NoerHomeDecor.floor_item?(other) && row[:x].to_i == x.to_i && row[:y].to_i == y.to_i
|
||
end
|
||
else
|
||
w, h = NoerHomeDecor.footprint_for(item)
|
||
rows.reject do |row|
|
||
other = NoerHomeDecor.item_by_id(row[:id])
|
||
next false unless other && !NoerHomeDecor.floor_item?(other) && !NoerHomeDecor.base_clear_item?(other)
|
||
if NoerHomeDecor.solid_item?(item)
|
||
NoerHomeDecor.row_intersects_area?(row, x, y, w, h)
|
||
else
|
||
row[:id].to_s == item[:id].to_s && row[:x].to_i == x.to_i && row[:y].to_i == y.to_i
|
||
end
|
||
end
|
||
end
|
||
rescue
|
||
rows
|
||
end
|
||
|
||
def can_place_item?(item, x, y)
|
||
return can_place_floor?(x, y) if NoerHomeDecor.floor_item?(item)
|
||
return false unless $game_map.valid?(x.to_i, y.to_i)
|
||
return true unless NoerHomeDecor.solid_item?(item)
|
||
w, h = NoerHomeDecor.footprint_for(item)
|
||
h.times do |dy|
|
||
w.times do |dx|
|
||
tx = x.to_i + dx
|
||
ty = y.to_i + dy
|
||
return false unless $game_map.valid?(tx, ty)
|
||
return false if (($game_player.x == tx && $game_player.y == ty) rescue false)
|
||
unless NoerHomeDecor.base_clear_at?(tx, ty)
|
||
events = ($game_map.events_xy_nt(tx, ty) rescue [])
|
||
return false if events && !events.empty?
|
||
end
|
||
end
|
||
end
|
||
true
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def can_place_floor?(x, y)
|
||
tx = x.to_i
|
||
ty = y.to_i
|
||
NoerHomeDecor.floor_cell_clear?(tx, ty)
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def create_sprites
|
||
create_cursor_sprite unless @cursor_sprite && !@cursor_sprite.disposed?
|
||
create_hud_sprite unless @hud_sprite && !@hud_sprite.disposed?
|
||
create_preview_sprite unless @preview_sprite && !@preview_sprite.disposed?
|
||
end
|
||
|
||
def create_cursor_sprite
|
||
@cursor_sprite = Sprite.new
|
||
@cursor_sprite.bitmap = Bitmap.new(32, 32)
|
||
c1 = Color.new(255, 230, 80, 230)
|
||
c2 = Color.new(20, 20, 20, 180)
|
||
@cursor_sprite.bitmap.fill_rect(0, 0, 32, 2, c1)
|
||
@cursor_sprite.bitmap.fill_rect(0, 30, 32, 2, c1)
|
||
@cursor_sprite.bitmap.fill_rect(0, 0, 2, 32, c1)
|
||
@cursor_sprite.bitmap.fill_rect(30, 0, 2, 32, c1)
|
||
@cursor_sprite.bitmap.fill_rect(3, 3, 26, 1, c2)
|
||
@cursor_sprite.bitmap.fill_rect(3, 28, 26, 1, c2)
|
||
@cursor_sprite.bitmap.fill_rect(3, 3, 1, 26, c2)
|
||
@cursor_sprite.bitmap.fill_rect(28, 3, 1, 26, c2)
|
||
@cursor_sprite.z = 9999
|
||
end
|
||
|
||
def create_hud_sprite
|
||
@hud_sprite = Sprite.new
|
||
@hud_sprite.bitmap = Bitmap.new(Graphics.width, HUD_HEIGHT)
|
||
@hud_sprite.x = 0
|
||
@hud_sprite.y = Graphics.height - HUD_HEIGHT
|
||
@hud_sprite.z = 10000
|
||
end
|
||
|
||
def create_preview_sprite
|
||
@preview_sprite = Sprite.new
|
||
@preview_sprite.opacity = 255
|
||
@preview_sprite.z = 9998
|
||
end
|
||
|
||
def dispose_sprites
|
||
dispose_sprite(@cursor_sprite)
|
||
dispose_sprite(@hud_sprite)
|
||
dispose_preview
|
||
@cursor_sprite = nil
|
||
@hud_sprite = nil
|
||
@preview_sprite = nil
|
||
@last_hud_signature = nil
|
||
@last_preview_signature = nil
|
||
end
|
||
|
||
def dispose_sprite(sprite)
|
||
return unless sprite
|
||
sprite.bitmap.dispose if sprite.bitmap && !sprite.bitmap.disposed?
|
||
sprite.dispose unless sprite.disposed?
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def dispose_preview
|
||
return unless @preview_sprite
|
||
@preview_sprite.bitmap.dispose if @preview_sprite.bitmap && !@preview_sprite.bitmap.disposed?
|
||
@preview_sprite.dispose unless @preview_sprite.disposed?
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def update_sprite_positions
|
||
sx = (($game_map.adjust_x(@cursor_x) rescue @cursor_x) * 32).to_i
|
||
sy = (($game_map.adjust_y(@cursor_y) rescue @cursor_y) * 32).to_i
|
||
@cursor_sprite.x = sx if @cursor_sprite
|
||
@cursor_sprite.y = sy if @cursor_sprite
|
||
@preview_sprite.x = sx if @preview_sprite
|
||
@preview_sprite.y = sy if @preview_sprite
|
||
end
|
||
|
||
def refresh_hud(force)
|
||
item = selected_item
|
||
count = NoerHomeDecor.placements.length
|
||
money = NoerHomeDecor.wallet_amount
|
||
signature = [@cursor_x, @cursor_y, @index, count, money, Graphics.width].join(":")
|
||
return if !force && @last_hud_signature == signature
|
||
@last_hud_signature = signature
|
||
|
||
bmp = @hud_sprite.bitmap
|
||
bmp.clear
|
||
bmp.fill_rect(0, 0, bmp.width, bmp.height, Color.new(0, 0, 0, 160))
|
||
bmp.font.size = 18
|
||
bmp.font.color = Color.new(255, 255, 255)
|
||
title = item ? item[:title].to_s : "нет"
|
||
price = item ? NoerHomeDecor.price_label_for(item) : "-"
|
||
money_text = NoerHomeDecor.price_label(money)
|
||
bmp.draw_text(12, 6, bmp.width - 24, 24, "Обустройство: #{title} Цена: #{price} Деньги: #{money_text}")
|
||
bmp.font.size = 14
|
||
bmp.font.color = Color.new(220, 220, 220)
|
||
bmp.draw_text(12, 34, bmp.width - 24, 22, "Клетка #{@cursor_x}, #{@cursor_y} Q/E выбор Enter/ЛКМ поставить Del/ПКМ демонтировать Esc выход")
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def refresh_preview(force)
|
||
item = selected_item
|
||
signature = item ? [item[:id], item[:path], item[:rect]].join(":") : "none"
|
||
return if !force && @last_preview_signature == signature
|
||
@last_preview_signature = signature
|
||
|
||
@preview_sprite.bitmap.dispose if @preview_sprite.bitmap && !@preview_sprite.bitmap.disposed?
|
||
@preview_sprite.bitmap = nil
|
||
return unless item && File.file?(item[:path].to_s)
|
||
|
||
@preview_sprite.bitmap = Bitmap.new(item[:path].to_s)
|
||
if item[:rect]
|
||
rect = item[:rect]
|
||
@preview_sprite.src_rect.set(rect[0].to_i, rect[1].to_i, rect[2].to_i, rect[3].to_i)
|
||
else
|
||
@preview_sprite.src_rect.set(0, 0, @preview_sprite.bitmap.width, @preview_sprite.bitmap.height)
|
||
end
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def input_trigger?(*keys)
|
||
keys.any? { |key| Input.trigger?(key) rescue false }
|
||
end
|
||
|
||
def input_repeat?(*keys)
|
||
keys.any? { |key| Input.repeat?(key) rescue false }
|
||
end
|
||
|
||
def play_cursor
|
||
SndLib.play_cursor if defined?(SndLib)
|
||
rescue
|
||
nil
|
||
end
|
||
|
||
def play_ok
|
||
SndLib.sound_QuickDialog if defined?(SndLib)
|
||
rescue
|
||
nil
|
||
end
|
||
|
||
def play_cancel
|
||
SndLib.sys_cancel if defined?(SndLib)
|
||
rescue
|
||
nil
|
||
end
|
||
|
||
def play_buzzer
|
||
SndLib.sys_buzzer if defined?(SndLib)
|
||
rescue
|
||
nil
|
||
end
|
||
end
|
||
|
||
if defined?(Game_Interpreter)
|
||
class Game_Interpreter
|
||
def noerhome_decor_menu(_target = nil)
|
||
unless NoerHomeDecor.own_house?
|
||
NoerHomeEstate.notify("Обустройство доступно только внутри своего дома.")
|
||
return false
|
||
end
|
||
if respond_to?(:noerhome_pick_rows)
|
||
rows = [["Открыть редактор", "edit"], ["Сбросить обустройство", "reset"], ["Отмена", "cancel"]]
|
||
picked = noerhome_pick_rows(rows)
|
||
case picked
|
||
when "edit"
|
||
NoerHomeDecorEditor.start
|
||
when "reset"
|
||
noerhome_decor_reset_confirm
|
||
end
|
||
else
|
||
NoerHomeDecorEditor.start
|
||
end
|
||
false
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def noerhome_decor_reset_confirm
|
||
if respond_to?(:noerhome_pick_rows)
|
||
picked = noerhome_pick_rows([["Да, сбросить всё и вернуть деньги", "yes"], ["Отмена", "cancel"]])
|
||
return false unless picked == "yes"
|
||
end
|
||
ok = NoerHomeDecor.reset_placements
|
||
if defined?(NoerHomeEstate)
|
||
refund = NoerHomeDecor.last_refund_amount
|
||
text = if ok && refund > 0
|
||
"Обустройство сброшено. Возвращено: #{NoerHomeDecor.price_label(refund)}."
|
||
elsif ok
|
||
"Обустройство сброшено."
|
||
else
|
||
"Не удалось сбросить обустройство."
|
||
end
|
||
NoerHomeEstate.notify(text)
|
||
end
|
||
ok
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def noerhome_decor_use_item(id)
|
||
item = NoerHomeDecor.item_by_id(id)
|
||
case item ? item[:action].to_s : id.to_s
|
||
when "storage"
|
||
NoerHomeDecor.open_storage
|
||
when "sleep"
|
||
noerhome_decor_sleep
|
||
else
|
||
false
|
||
end
|
||
rescue
|
||
false
|
||
end
|
||
|
||
def noerhome_decor_sleep
|
||
unless NoerHomeDecor.own_house?
|
||
NoerHomeEstate.notify("Спать можно только в своем доме.") if defined?(NoerHomeEstate)
|
||
return false
|
||
end
|
||
map_key = ($game_map.map_id_rec rescue ($game_map.map_id rescue 0))
|
||
if respond_to?(:handleNap)
|
||
handleNap(:normal, map_key)
|
||
NoerHomeEstate.sync_to_server(true) if defined?(NoerHomeEstate)
|
||
if defined?(MPCloudOnlySave)
|
||
if MPCloudOnlySave.respond_to?(:send_tracked_now)
|
||
MPCloudOnlySave.send_tracked_now("home_bed_sleep", true) || MPCloudOnlySave.request("home_bed_sleep", 1)
|
||
elsif MPCloudOnlySave.respond_to?(:request)
|
||
MPCloudOnlySave.request("home_bed_sleep", 1)
|
||
end
|
||
end
|
||
true
|
||
else
|
||
NoerHomeEstate.notify("Сон сейчас недоступен.") if defined?(NoerHomeEstate)
|
||
false
|
||
end
|
||
rescue
|
||
NoerHomeEstate.notify("Сон сейчас недоступен.") if defined?(NoerHomeEstate)
|
||
false
|
||
end
|
||
end
|
||
end
|
||
|
||
if defined?(Game_Player)
|
||
class Game_Player
|
||
unless method_defined?(:noerhome_decor_actions_check_action_event_without_grid)
|
||
alias noerhome_decor_actions_check_action_event_without_grid check_action_event
|
||
end
|
||
|
||
def check_action_event(chkItemsPick = false)
|
||
result = noerhome_decor_actions_check_action_event_without_grid(chkItemsPick)
|
||
return true if result
|
||
return true if defined?(NoerHomeDecor) && NoerHomeDecor.respond_to?(:handle_action) && NoerHomeDecor.handle_action
|
||
result
|
||
end
|
||
end
|
||
end
|
||
|
||
if defined?(Game_Map)
|
||
class Game_Map
|
||
unless method_defined?(:noerhome_decor_grid_passable_without_decor)
|
||
alias noerhome_decor_grid_passable_without_decor passable?
|
||
end
|
||
|
||
def passable?(x, y, d)
|
||
begin
|
||
if defined?(NoerHomeDecor) && NoerHomeDecor.respond_to?(:blocked_tile?)
|
||
tx = round_x_with_direction(x, d)
|
||
ty = round_y_with_direction(y, d)
|
||
return false if NoerHomeDecor.blocked_tile?(tx, ty)
|
||
end
|
||
rescue
|
||
end
|
||
noerhome_decor_grid_passable_without_decor(x, y, d)
|
||
end
|
||
end
|
||
end
|
||
|
||
if defined?(Scene_Map)
|
||
class Scene_Map
|
||
alias noerhome_decor_editor_update_without_editor update
|
||
def update(*args)
|
||
noerhome_decor_editor_update_without_editor(*args)
|
||
NoerHomeDecor.apply_map_overrides if defined?(NoerHomeDecor) && NoerHomeDecor.respond_to?(:apply_map_overrides)
|
||
NoerHomeDecor.update_action_fiber if defined?(NoerHomeDecor) && NoerHomeDecor.respond_to?(:update_action_fiber)
|
||
NoerHomeDecorEditor.update if defined?(NoerHomeDecorEditor) && NoerHomeDecorEditor.active?
|
||
end
|
||
|
||
alias noerhome_decor_editor_terminate_without_editor terminate
|
||
def terminate(*args)
|
||
NoerHomeDecorEditor.stop if defined?(NoerHomeDecorEditor) && NoerHomeDecorEditor.active?
|
||
NoerHomeDecor.restore_map_overrides if defined?(NoerHomeDecor) && NoerHomeDecor.respond_to?(:restore_map_overrides)
|
||
noerhome_decor_editor_terminate_without_editor(*args)
|
||
end
|
||
end
|
||
end
|
||
end
|