TheoAllen

AMA - fast travel

Apr 4th, 2013
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 12.32 KB | None | 0 0
  1. =begin
  2.   ALUMNEA MAGIC ACADEMY - Fast Travel
  3.   Ver 0.7
  4.   (written in informal indonesian language)
  5.  
  6.   =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  7.   Term of Service :
  8.   Script ini pada aslinya ga w bikin buat disebar. tapi buat ojekan pribadi gw
  9.   Jadi w minta maap kalo rada ribet makenya ato keterangannya g jelas. Yg jelas
  10.   gw g ngelayani support kalo ada apa-apa buat script ini.
  11.  
  12.   u boleh ngedit ato minta editin scripter lain. u boleh ngeredistribusi script
  13.   ini dengan versi editan u sendiri. Cuman gw minta satu syarat. Credit gw!
  14.   TheoAllen!
  15.  
  16.   Komersil? boleh. Tapi u urus aja sendiri script gw kalo misalnya ada masalah
  17.   ato g sreg :v
  18.   =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  19.  
  20.   Cara Penggunaan :
  21.   AMA.new_map(a,b,c,d,e)
  22.   a = Nama Tujuan ntar (buat ditampilin)
  23.   b = Nama file yg jadi snapshot
  24.   c = id peta yg jadi tujuan teleport
  25.   d = posisi x transfer
  26.   e = posisi y pas transfer
  27.  
  28.   AMA.set_map(a,b,c) >> Ngemasukin current map ke list map transferable
  29.   a = File snapshot
  30.   b = posisi x
  31.   c = posisi y
  32.  
  33.   AMA.clear_map
  34.   buat ngebersihin transferable map yg disimpen
  35.  
  36.   Untuk manggil Scene fast travel. Tulis :
  37.   "SceneManager.call(Scene_Travel)"
  38.   Panggil via script call. Ato terserah u sisipin dimana dalam script
  39.   (kalo u ngerti scripting :v)
  40.  
  41. =end
  42.  
  43. module AMA
  44.   # ============== Config ====================
  45.   module TRAVEL
  46.    
  47.     # Pengaturan Window Title
  48.     TITLE_WIDTH   = "Graphics.width"    
  49.     TITLE_HEIGHT  = "line_height + standard_padding*2"
  50.     TITLE_X       = "0"                
  51.    
  52.     # Vokab ~
  53.     TITLE       = "~ Fast Travel ~"
  54.     CURRENT_MAP = "Current Map :"
  55.    
  56.   end
  57.   # ============== End of config =============
  58.  
  59.   def self.new_map(name,file,id,x,y)
  60.     new_map = Game_MapList.new(name,id,file,x,y)
  61.     $game_maplist.push(new_map)
  62.   end
  63.  
  64.   def self.set_map(file,x,y)
  65.     map = $game_map
  66.     name = map.display_name
  67.     id = map.map_id
  68.     new_map = Game_MapList(name,id,file,x,y)
  69.     $game_maplist.push(new_map)
  70.   end
  71.  
  72.   def self.clear_map
  73.     $game_maplist.clear
  74.   end
  75.  
  76. end
  77.  
  78. =begin
  79.  
  80.   Game_Maplist = Buat nyatet dan ngelist map2 mana aja yg transferable
  81.   Game_Maplist beda dengan Game_Map ato $data_mapinfos
  82.  
  83. =end
  84.  
  85. class Game_MapList
  86.   attr_accessor :name         # Nama map (Spesifikasikan sendiri)
  87.   attr_accessor :id           # ID map tujuan buat transfer
  88.   attr_accessor :x            # Posisi x saat transfer
  89.   attr_accessor :y            # Posisi y saat transfer
  90.   attr_writer :complete_flag  # Tanda kalo map udah komplet diexplore
  91.   attr_reader :nth            # Maplist ke-n. Otomatis nambah.
  92.   attr_reader :file           # Nama file snapshot
  93.  
  94.   @@count = 0     # Static variable ~
  95.  
  96.   def initialize(name,id,file,x,y)
  97.     @name = name
  98.     @id = id
  99.     @file = file
  100.     @complete_flag = false
  101.     @x = x
  102.     @y = y
  103.     @@count += 1
  104.     @nth = @@count
  105.   end
  106.  
  107.   def complete?
  108.     @complete_flag
  109.   end
  110.  
  111. end
  112.  
  113. class Game_Map
  114.  
  115.   # buat lu yg mo ngembangin script ini
  116.   def travel?
  117.     @map.note.include?("<travel>")
  118.   end
  119.  
  120.   def no_travel?
  121.     @map.note.include?("<no travel>")
  122.   end
  123.  
  124. end
  125.  
  126. module DataManager
  127.  
  128.   class << self
  129.     alias fast_travel_db load_database   # Aliasing load database
  130.   end
  131.  
  132.   def self.load_database
  133.     fast_travel_db
  134.     make_maplist_obj
  135.   end
  136.  
  137.   def self.make_maplist_obj
  138.     $game_maplist = []      # Bikin object array buat nampung object2 maplist
  139.   end
  140.  
  141.   def self.make_save_contents
  142.     contents = {}
  143.     contents[:system]        = $game_system
  144.     contents[:timer]         = $game_timer
  145.     contents[:message]       = $game_message
  146.     contents[:switches]      = $game_switches
  147.     contents[:variables]     = $game_variables
  148.     contents[:self_switches] = $game_self_switches
  149.     contents[:actors]        = $game_actors
  150.     contents[:party]         = $game_party
  151.     contents[:troop]         = $game_troop
  152.     contents[:map]           = $game_map
  153.     contents[:player]        = $game_player
  154.     contents[:maplist]       = $game_maplist
  155.     contents
  156.   end
  157.  
  158.   def self.extract_save_contents(contents)
  159.     $game_system        = contents[:system]
  160.     $game_timer         = contents[:timer]
  161.     $game_message       = contents[:message]
  162.     $game_switches      = contents[:switches]
  163.     $game_variables     = contents[:variables]
  164.     $game_self_switches = contents[:self_switches]
  165.     $game_actors        = contents[:actors]
  166.     $game_party         = contents[:party]
  167.     $game_troop         = contents[:troop]
  168.     $game_map           = contents[:map]
  169.     $game_player        = contents[:player]
  170.     $game_maplist       = contents[:maplist]
  171.   end
  172.  
  173. end
  174.  
  175. =begin
  176.  
  177.   Class ini buat nampilin window judul diatas. Panjang window ini berpengaruh
  178.   ke window lain.
  179.  
  180. =end
  181.  
  182. class Window_TravelTitle < Window_Base
  183.  
  184.   def initialize
  185.     super(0,0,window_width,window_height)
  186.     update_placement
  187.     refresh
  188.   end
  189.  
  190.   def window_width
  191.     eval(AMA::TRAVEL::TITLE_WIDTH)
  192.   end
  193.  
  194.   def window_height
  195.     eval(AMA::TRAVEL::TITLE_HEIGHT)
  196.   end
  197.  
  198.   def update_placement
  199.     self.x = eval(AMA::TRAVEL::TITLE_X)
  200.   end
  201.  
  202.   def refresh
  203.     contents.clear
  204.     draw_text(0,0,contents.width,line_height,AMA::TRAVEL::TITLE,1)
  205.   end
  206.  
  207. end
  208.  
  209. =begin
  210.  
  211.   Class ini buat nampilin map sekarang. Letaknya ada di paling bawah
  212.  
  213. =end
  214.  
  215. class Window_CurrentMap < Window_Base
  216.  
  217.   def initialize
  218.     super(0,0,window_width,window_height)
  219.     update_placement
  220.     refresh
  221.   end
  222.  
  223.   def window_width
  224.     return eval(AMA::TRAVEL::TITLE_WIDTH)
  225.   end
  226.  
  227.   def window_height
  228.     return eval(AMA::TRAVEL::TITLE_HEIGHT)
  229.   end
  230.  
  231.   def update_placement
  232.     self.x = (Graphics.width - window_width) / 2
  233.     self.y = Graphics.height - self.window_height
  234.   end
  235.  
  236.   def refresh
  237.     contents.clear
  238.     draw_current_map
  239.   end
  240.  
  241.   def draw_current_map
  242.     change_color(system_color)
  243.     draw_text(0,0,contents.width,line_height,AMA::TRAVEL::CURRENT_MAP)
  244.     change_color(normal_color)
  245.     draw_text(0,0,contents.width,line_height,$game_map.display_name,2)
  246.   end
  247.  
  248. end
  249.  
  250. =begin
  251.  
  252.   Class ini buat nampilin list-list map yg bisa transfer. Class ini ngerefers
  253.   ke $game_maplist. Kalo mau nambahin list map u harus ngemasukin map lewat
  254.   modul AMA.new_map. Penjelasan dah ada di section sbelumnya
  255.  
  256. =end
  257. class Window_Maplist < Window_Selectable
  258.   # ----------------------------------------------------------
  259.   # Inisialisasi ~
  260.   # ----------------------------------------------------------
  261.   def initialize(x,y,width,height)
  262.     super(x,y,width,height)
  263.     @width = width
  264.     @height = height
  265.     @data = []
  266.     refresh
  267.   end
  268.   # ----------------------------------------------------------
  269.   # Lebar window ~
  270.   # ----------------------------------------------------------
  271.   def window_width
  272.     @width
  273.   end
  274.   # ----------------------------------------------------------
  275.   # Tinggi window ~
  276.   # ----------------------------------------------------------
  277.   def window_height
  278.     @height
  279.   end
  280.   # ----------------------------------------------------------
  281.   # Kolom maksimum ~
  282.   # ----------------------------------------------------------
  283.   def col_max
  284.     return 1
  285.   end
  286.   # ----------------------------------------------------------
  287.   # Jumlah item maksimum. 1 jika data ngga ada
  288.   # ----------------------------------------------------------
  289.   def item_max
  290.     @data ? @data.size : 1
  291.   end
  292.   # ----------------------------------------------------------
  293.   # Buat ndapetin item / data yg lagi dipilih
  294.   # ----------------------------------------------------------
  295.   def item
  296.     @data && index >= 0 ? @data[index] : nil
  297.   end
  298.   # ----------------------------------------------------------
  299.   # Refresh window
  300.   # ----------------------------------------------------------
  301.   def refresh
  302.     make_item_list
  303.     create_contents
  304.     draw_all_items
  305.   end
  306.   # ----------------------------------------------------------
  307.   # Data diambil dari Game_Maplist
  308.   # ----------------------------------------------------------
  309.   def make_item_list
  310.     @data = $game_maplist
  311.   end
  312.   # ----------------------------------------------------------
  313.   # Metode ngedraw item / data
  314.   # ----------------------------------------------------------
  315.   def draw_item(index)
  316.     map = @data[index]        # permisalan
  317.     if map                    # kalo datanya ada ~>
  318.       rect = item_rect(index) # Pesen tempat
  319.       rect.width -= 4         # Lebar dikecilin dikit
  320.       draw_map_name(map,rect) # Ngedraw nama peta
  321.     end
  322.   end
  323.   # ----------------------------------------------------------
  324.   # Metode ngedraw nama peta
  325.   # (%03d,number) >> regular expression yg ntar jadinya :
  326.   # - 001 >> kalo number = 1
  327.   # - 099 >> kalo number = 99
  328.   # ----------------------------------------------------------
  329.   def draw_map_name(map,rect)
  330.     name = map.name           # ngambil nama peta
  331.     number = map.nth          # ngambil nomor peta
  332.     text = sprintf("%03d:%s",number,name) # bikin format nama peta
  333.     change_color(power_up_color) if map.complete?
  334.     draw_text(rect,text)      # nulis nama peta berdasar format ^
  335.     reset_font_settings
  336.   end
  337.   # ----------------------------------------------------------
  338.   # Update help. Help window refers ke Window_Mapinfo
  339.   # ----------------------------------------------------------
  340.   def update_help
  341.     @help_window.set_item(item) if @help_window
  342.   end
  343.  
  344. end
  345. =begin
  346.  
  347.   class ini buat window yg nampilin info map
  348.  
  349. =end
  350. class Window_Mapinfo < Window_Base
  351.  
  352.   def initialize(x,y,width,height)
  353.     super(x,y,width,height)
  354.     @width = width
  355.     @height = height
  356.     @map =  nil
  357.     refresh
  358.   end
  359.  
  360.   def window_height
  361.     @height
  362.   end
  363.  
  364.   def window_width
  365.     @width
  366.   end
  367.  
  368.   def refresh
  369.     contents.clear
  370.     draw_map_infos
  371.   end
  372.  
  373.   def draw_map_infos
  374.     change_color(system_color)
  375.     draw_text(0,0,contents.width,line_height,"Map Infos :",1)
  376.     draw_contents if @map
  377.   end
  378.  
  379.   def draw_contents
  380.     draw_map_name
  381.     draw_map_snapshot(0, line_height*4)
  382.   end
  383.  
  384.   def draw_map_name
  385.     change_color(system_color)
  386.     pos = line_height
  387.     width = contents.width
  388.     draw_text(0,pos,width,pos,"Name :")
  389.     change_color(normal_color)
  390.     draw_text(0,pos+line_height,width,pos,@map.name)
  391.     change_color(system_color)
  392.     width = window_width
  393.     draw_text(0,pos+(line_height*2),width,pos,"Snapshot :")
  394.   end
  395.  
  396.   def set_item(item)
  397.     @map = item
  398.     refresh
  399.   end
  400.  
  401.   def draw_map_snapshot(x, y, enabled = true)
  402.     bitmap = Cache.system(@map.file)
  403.     rect = Rect.new(0,0, 300, 300)
  404.     contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
  405.   end
  406.  
  407. end
  408. =begin
  409.  
  410.   Custom scene class buat travel
  411.  
  412. =end
  413. class Scene_Travel < Scene_MenuBase
  414.  
  415.   def start
  416.     super
  417.     create_title_window
  418.     create_current_map_window
  419.     create_maplist_window
  420.     create_mapinfo_window
  421.   end
  422.  
  423.   def create_title_window
  424.     @title_window = Window_TravelTitle.new
  425.     @title_window.viewport = @viewport
  426.   end
  427.  
  428.   def create_current_map_window
  429.     @current_map_window = Window_CurrentMap.new
  430.     @current_map_window.viewport = @viewport
  431.   end
  432.  
  433.   def create_mapinfo_window
  434.     wx = @maplist_window.window_width
  435.     wy = @title_window.window_height
  436.     ww = @title_window.window_width / 2
  437.     p ww
  438.     wh = Graphics.height - @title_window.window_height*2
  439.     @mapinfo_window = Window_Mapinfo.new(wx,wy,ww,wh)
  440.     @mapinfo_window.viewport = @viewport
  441.     @maplist_window.help_window = @mapinfo_window
  442.   end
  443.  
  444.   def create_maplist_window
  445.     wx = @title_window.x
  446.     wy = @title_window.window_height
  447.     ww = @title_window.window_width / 2
  448.     wh = Graphics.height - @title_window.window_height*2
  449.     @maplist_window = Window_Maplist.new(wx,wy,ww,wh)
  450.     @maplist_window.viewport = @viewport
  451.     @maplist_window.set_handler(:ok, method(:on_item_ok))
  452.     @maplist_window.set_handler(:cancel, method(:return_scene))
  453.     @maplist_window.activate
  454.     @maplist_window.select(0)
  455.   end
  456.  
  457.   def on_item_ok
  458.     map = @maplist_window.item
  459.     $game_player.reserve_transfer(map.id,map.x,map.y)
  460.     Audio.se_play("Audio/SE/Move",80)
  461.     SceneManager.call_map
  462.   end
  463.  
  464. end
  465.  
  466. module SceneManager
  467.  
  468.   def self.call_map
  469.     @scene = Scene_Map.new
  470.     clear
  471.   end
  472.  
  473. end
Advertisement
Add Comment
Please, Sign In to add comment