Advertisement
SSTrihan

HorrorVale - Map update

Apr 6th, 2024
754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.37 KB | Source Code | 0 0
  1. #-------------------------------------------------------------------------------
  2. # Don't remove this header!
  3. #-------------------------------------------------------------------------------
  4. # Custom Map System Script
  5. # by Trihan
  6. #
  7. # Version : 1.2
  8. #
  9. # This script is commissioned by Batworks Software.
  10. #-------------------------------------------------------------------------------
  11.  
  12. #-------------------------------------------------------------------------------
  13. # Version History
  14. #-------------------------------------------------------------------------------
  15. # 1.2 - Added icons for fast travel, party swap, shop and save coffins
  16. # 1.1 - Map name window position will now change if cursor overlaps it.
  17. # 1.0 - Initial script.
  18. #-------------------------------------------------------------------------------
  19.  
  20. #-------------------------------------------------------------------------------
  21. # All pictures are located in the Graphics/Maps folder.
  22. #
  23. # To call the map scene, use the following script call
  24. #
  25. #     SceneManager.call(Scene_MapSystem)
  26. #
  27. # This script runs mostly automatically. All you need to configure is the
  28. # graphic and offset for the cursor, the graphic for the player marker, and
  29. # the regex pattern to use for map filenames.
  30. #
  31. # The filename by default needs to meet the following pattern:
  32. # AreaXMap + name of map + _markerx_markery
  33. #
  34. # For example, Area1MapAbandonedShack_141_198.png
  35. # This will mark the map as belonging to area 1, connect it to the map named
  36. # AbandonedShack, and display the marker at (141, 198) on the screen.
  37. #
  38. # If you change the regex pattern, please ensure that (\d+) still appears in
  39. # it somewhere, otherwise the script won't be able to determine areas.
  40. #-------------------------------------------------------------------------------
  41. module TLBMapSystem
  42. #-------------------------------------------------------------------------------
  43. #  Config
  44.  
  45.    CursorIcon = "fingerpointer"
  46.    PlayerMarker = "alicemarker"
  47.    FastTravelMarker = "bellmarker"
  48.    PartySwapMarker = "laylamarker"
  49.    PartySwapSwitch = 506
  50.    ShopMarker = "jiangicon"
  51.    RedCoffinMarker = "coffinmarkerred"
  52.    OrangeCoffinMarker = "coffinmarkerorange"
  53.    BlackCoffinMarker = "coffinmarkerblack"
  54.    CursorXOffset = 5
  55.    CursorYOffset = 0
  56.    IconXOffset = 10
  57.    IconYOffset = 10
  58.    MapRegex = /Area(\d+)Map.*/
  59.  
  60. #  ** End Config **
  61. #
  62. # WARNING: Editing anything beyond this point may result in the script no
  63. # longer functioning as intended.
  64. #-------------------------------------------------------------------------------
  65. end
  66.  
  67. module Cache; def self.maps(filename); load_bitmap("Graphics/Maps/", filename); end; end
  68.  
  69. class Game_System
  70.   attr_accessor :mapdata
  71.  
  72.   alias :tlb_mapsystem_initialize :initialize
  73.   def initialize
  74.     tlb_mapsystem_initialize
  75.     create_map_data
  76.   end
  77.  
  78.   def create_map_data
  79.     @mapdata = {}
  80.     regexpattern = TLBMapSystem::MapRegex
  81.     files = Dir.entries("Graphics/Maps")
  82.       .select { |file| file =~ regexpattern }
  83.       .map { |file| File.basename(file, ".png") }
  84.     areas = []
  85.     files.each { |file|
  86.       area = file.scan(regexpattern)
  87.       if area.size > 0 && !areas.include?(area[0][0])
  88.         areas.push(area[0][0])
  89.       end
  90.     }
  91.     areas.each { |area|
  92.       regexpattern = Regexp.new("Area#{area}Map(.*)")
  93.       @mapdata[area] = files
  94.         .select { |file| file =~ regexpattern }
  95.         .map { |file|
  96.           data = file.scan(regexpattern)[0][0].split("_")
  97.           {
  98.             :name => data[0],
  99.             :filename => file,
  100.             :cursor_x => data[1].to_i,
  101.             :cursor_y => data[2].to_i,
  102.             :visited => false
  103.           }
  104.         }
  105.     }
  106.   end
  107.  
  108.   def get_visited_maps(area)
  109.     if @mapdata[area]
  110.       @mapdata[area].select { |map| map[:visited] }
  111.     else
  112.       []
  113.     end
  114.   end
  115.  
  116.   def visit_map(area, mapname)
  117.     map = @mapdata[area].select { |map| map[:name] == mapname }
  118.     if map.size > 0
  119.       map[0][:visited] = true
  120.     end
  121.   end
  122. end
  123.  
  124. class Game_Map
  125.   alias :tlb_mapsystem_setup :setup
  126.   def setup(map_id)
  127.     tlb_mapsystem_setup(map_id)
  128.     mapname = $data_mapinfos[map_id].name
  129.     area = get_current_area
  130.     if area
  131.       $game_system.visit_map(area, mapname)
  132.     end
  133.   end
  134.  
  135.   def get_current_area
  136.     area = self.note.scan(/<area: ?(\d+)/)
  137.     if area.size > 0
  138.       return area[0][0]
  139.     else
  140.       return nil
  141.     end
  142.   end
  143.  
  144.   def get_map(mapname)
  145.     area = get_current_area
  146.     if area
  147.       map = $game_system.mapdata[area].select { |map| map[:name] == mapname }
  148.       if map
  149.         map[0]
  150.       else
  151.         nil
  152.       end
  153.     end
  154.   end
  155.  
  156.   def get_current_map
  157.     mapname = $data_mapinfos[@map_id].name
  158.     get_map(mapname)
  159.   end
  160.  
  161.   def get_directional_map(start_map, direction)
  162.     map_match = $data_mapinfos.select{|key, value| value.name == start_map[:name]}.keys
  163.     if map_match
  164.       map_id = map_match.first
  165.       map = nil
  166.       if map_id
  167.         mapfile = load_data(sprintf("Data/Map%03d.rvdata2", map_id))
  168.         case direction
  169.         when 2
  170.           map = mapfile.note.scan(/<south: ?(.*)>/)
  171.         when 4
  172.           map = mapfile.note.scan(/<west: ?(.*)>/)
  173.         when 6
  174.           map = mapfile.note.scan(/<east: ?(.*)>/)
  175.         when 8
  176.           map = mapfile.note.scan(/<north: ?(.*)>/)
  177.         else
  178.           map = nil
  179.         end
  180.         if map && map.size > 0
  181.           map_strings = map[0][0].split("/")
  182.           map_strings.each{|string|
  183.             map_obj = get_map(string)
  184.             if map_obj[:visited]
  185.               return map_obj
  186.             end
  187.           }
  188.         else
  189.           nil
  190.         end
  191.       end
  192.     end
  193.     nil
  194.   end
  195.  
  196.   def get_south_map(start_map)
  197.     get_directional_map(start_map, 2)
  198.   end
  199.  
  200.   def get_west_map(start_map)
  201.     get_directional_map(start_map, 4)
  202.   end
  203.  
  204.   def get_east_map(start_map)
  205.     get_directional_map(start_map, 6)
  206.   end
  207.  
  208.   def get_north_map(start_map)
  209.     get_directional_map(start_map, 8)
  210.   end
  211. end
  212.  
  213. class Window_MapLabel < Window_Base
  214.   def initialize
  215.     super(0, 0, Graphics.width, 120)
  216.     @text = ""
  217.     refresh
  218.   end
  219.  
  220.   def set_text(text)
  221.     @text = text
  222.     refresh
  223.   end
  224.  
  225.   def refresh
  226.     create_contents
  227.     draw_text(0, 0, 32, line_height, @text)
  228.   end
  229. end
  230.  
  231. class Window_Mystery < Window_Base
  232.   def initialize
  233.     super(0, 0, 100, fitting_height(1))
  234.     self.width = text_size("???").width + standard_padding * 2
  235.     create_contents
  236.     self.x = Graphics.width / 2 - self.width / 2
  237.     self.y = Graphics.height / 2 - self.height / 2
  238.     self.opacity = 0
  239.     draw_text(0, 0, 32, line_height, "???")
  240.   end
  241. end
  242.  
  243. class Scene_MapSystem < Scene_Base
  244.   def start
  245.     super
  246.     create_background
  247.     create_map
  248.     @current_map = $game_map.get_current_map
  249.     @selected_map = $game_map.get_current_map
  250.     create_player_marker
  251.     create_pointer
  252.     create_label_window
  253.     create_mystery_window
  254.   end
  255.  
  256.   def terminate
  257.     super
  258.     dispose_background
  259.     dispose_map
  260.     dispose_player_marker
  261.     dispose_pointer
  262.   end
  263.  
  264.   def update
  265.     super
  266.   end
  267.  
  268.   def create_background
  269.     @sprite = Sprite.new
  270.     @sprite.bitmap = Cache.maps("Mapbackground")
  271.     center_sprite(@sprite)
  272.   end
  273.  
  274.   def create_map
  275.     @map_icons = []
  276.     maps = $game_system.get_visited_maps($game_map.get_current_area)
  277.     if maps.size > 0
  278.       @area_sprites = []
  279.       maps.each { |map|
  280.         map_match = $data_mapinfos.select{|key, value| value.name == map[:name]}.keys
  281.         if map_match
  282.           map_id = map_match.first
  283.           if map_id
  284.             mapfile = load_data(sprintf("Data/Map%03d.rvdata2", map_id))
  285.             fasttravel = mapfile.note.scan(/<fasttravel: ?(\d+)>/)
  286.             partyswap = mapfile.note.scan(/<partyswap>/)
  287.             shop = mapfile.note.scan(/<shop>/)
  288.             save = mapfile.note.scan(/<save: ?(\d)>/)
  289.             if fasttravel && fasttravel.size > 0
  290.               switch_id = fasttravel[0][0].to_i
  291.               if $game_switches[switch_id]
  292.                 sprite = Sprite.new
  293.                 sprite.bitmap = Cache.maps(TLBMapSystem::FastTravelMarker)
  294.                 sprite.x = map[:cursor_x] - TLBMapSystem::IconXOffset
  295.                 sprite.y = map[:cursor_y] - TLBMapSystem::IconYOffset
  296.                 sprite.z += 100
  297.                 @map_icons.push(sprite)
  298.               end
  299.             end
  300.             if partyswap && partyswap.size > 0
  301.               switch_id = TLBMapSystem::PartySwapSwitch
  302.               if $game_switches[switch_id]
  303.                 sprite = Sprite.new
  304.                 sprite.bitmap = Cache.maps(TLBMapSystem::PartySwapMarker)
  305.                 sprite.x = map[:cursor_x] + TLBMapSystem::IconXOffset
  306.                 sprite.y = map[:cursor_y] - TLBMapSystem::IconYOffset
  307.                 sprite.z += 100
  308.                 @map_icons.push(sprite)
  309.               end
  310.             end
  311.             if shop && shop.size > 0
  312.               sprite = Sprite.new
  313.               sprite.bitmap = Cache.maps(TLBMapSystem::ShopMarker)
  314.               sprite.x = map[:cursor_x] - TLBMapSystem::IconXOffset
  315.               sprite.y = map[:cursor_y] + TLBMapSystem::IconYOffset
  316.               sprite.z += 100
  317.               @map_icons.push(sprite)
  318.             end
  319.             if save && save.size > 0
  320.               save_type = save[0][0].to_i
  321.               case save_type
  322.               when 1
  323.                 bitmap = Cache.maps(TLBMapSystem::RedCoffinMarker)
  324.               when 2
  325.                 bitmap = Cache.maps(TLBMapSystem::OrangeCoffinMarker)
  326.               when 3
  327.                 bitmap = Cache.maps(TLBMapSystem::BlackCoffinMarker)
  328.               else
  329.                 bitmap = Cache.maps(TLBMapSystem::RedCoffinMarker)
  330.               end
  331.               sprite = Sprite.new
  332.               sprite.bitmap = bitmap
  333.               sprite.x = map[:cursor_x] + TLBMapSystem::IconXOffset
  334.               sprite.y = map[:cursor_y] + TLBMapSystem::IconYOffset
  335.               sprite.z += 100
  336.               @map_icons.push(sprite)
  337.             end
  338.           end
  339.         end
  340.         sprite = Sprite.new
  341.         sprite.bitmap = Cache.maps(map[:filename])
  342.         center_sprite(sprite)
  343.         @area_sprites.push(sprite)
  344.       }
  345.     end
  346.   end
  347.  
  348.   def create_player_marker
  349.     @player_marker_sprite = Sprite.new
  350.     @player_marker_sprite.bitmap = Cache.maps(TLBMapSystem::PlayerMarker)
  351.     if @current_map
  352.       x = @current_map[:cursor_x]
  353.       y = @current_map[:cursor_y]
  354.       @player_marker_sprite.x = x if x
  355.       @player_marker_sprite.y = y if y
  356.       @player_marker_sprite.z += 100
  357.     end
  358.   end
  359.  
  360.   def create_pointer
  361.     @pointer_sprite = Sprite.new
  362.     @pointer_sprite.bitmap = Cache.menus(TLBMapSystem::CursorIcon)
  363.     if @selected_map
  364.       x = @selected_map[:cursor_x] + TLBMapSystem::CursorXOffset
  365.       y = @selected_map[:cursor_y] + TLBMapSystem::CursorYOffset
  366.       @pointer_sprite.x = x if x
  367.       @pointer_sprite.y = y if y
  368.       @pointer_sprite.z += 200
  369.     end
  370.   end
  371.  
  372.   def create_label_window
  373.     @label_window = Window_MapLabel.new
  374.     if @selected_map
  375.       refresh_label
  376.     end
  377.   end
  378.  
  379.   def create_mystery_window
  380.     @mystery_window = Window_Mystery.new
  381.     if @area_sprites && @area_sprites.size > 0
  382.       @mystery_window.hide
  383.     end
  384.   end
  385.  
  386.   def refresh_label
  387.     map_text = @selected_map[:name]
  388.     @label_window.set_text(map_text)
  389.     if @pointer_sprite.y < @label_window.height
  390.       @label_window.y = Graphics.height - @label_window.height
  391.     else
  392.       @label_window.y = 0
  393.     end
  394.   end
  395.  
  396.   def update
  397.     super
  398.     if Input.trigger?(:B)
  399.       return_scene
  400.     end
  401.     if @area_sprites && @area_sprites.size > 0
  402.       if Input.trigger?(:DOWN)
  403.         map = $game_map.get_south_map(@selected_map)
  404.       end
  405.       if Input.trigger?(:LEFT)
  406.         map = $game_map.get_west_map(@selected_map)
  407.       end
  408.       if Input.trigger?(:RIGHT)
  409.         map = $game_map.get_east_map(@selected_map)
  410.       end
  411.       if Input.trigger?(:UP)
  412.         map = $game_map.get_north_map(@selected_map)
  413.       end
  414.     end
  415.     if map
  416.       x = map[:cursor_x] + TLBMapSystem::CursorXOffset
  417.       y = map[:cursor_y] + TLBMapSystem::CursorYOffset
  418.       @pointer_sprite.x = x if x
  419.       @pointer_sprite.y = y if y
  420.       @selected_map = map
  421.       refresh_label
  422.     end
  423.     if Graphics.frame_count % 60 == 0 && @area_sprites
  424.       current_sprite = @area_sprites.select { |sprite| sprite.bitmap == Cache.maps(@current_map[:filename]) }
  425.       if current_sprite
  426.         current_sprite[0].flash(Color.new(255, 255, 255, 255), 60)
  427.       end
  428.     end
  429.     if @area_sprites
  430.       @area_sprites.each {|sprite| sprite.update }
  431.     end
  432.   end
  433.  
  434.   def dispose_background
  435.     @sprite.bitmap.dispose
  436.     @sprite.dispose
  437.   end
  438.  
  439.   def dispose_map
  440.     if @area_sprites
  441.       @area_sprites.each { |sprite|
  442.         sprite.bitmap.dispose
  443.         sprite.dispose
  444.       }
  445.     end
  446.     if @map_icons
  447.       @map_icons.each { |sprite|
  448.         sprite.bitmap.dispose
  449.         sprite.dispose
  450.       }
  451.     end
  452.   end
  453.  
  454.   def dispose_player_marker
  455.     @player_marker_sprite.bitmap.dispose
  456.     @player_marker_sprite.dispose
  457.   end
  458.  
  459.   def dispose_pointer
  460.     @pointer_sprite.bitmap.dispose
  461.     @pointer_sprite.dispose
  462.   end
  463.  
  464.   def center_sprite(sprite)
  465.     sprite.ox = sprite.bitmap.width / 2
  466.     sprite.oy = sprite.bitmap.height / 2
  467.     sprite.x = Graphics.width / 2
  468.     sprite.y = Graphics.height / 2
  469.   end
  470. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement