Advertisement
Guest User

Vorspire

a guest
Jul 7th, 2009
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.09 KB | None | 0 0
  1. #define RUNUO_2 //Comment this out to enable RunUO 1.0 Mode
  2.  
  3. using System;
  4. using System.IO;
  5. using System.Collections;
  6.  
  7. #if(RUNUO_2)
  8. using System.Collections.Generic;
  9. #endif
  10.  
  11. using Server;
  12. using Server.Mobiles;
  13. using Server.Network;
  14.  
  15. namespace Server.Touring
  16. {
  17.     public delegate void DestinationChangedEventHandler(DestinationChangedEventArgs e);
  18.  
  19.     public static partial class Tour
  20.     {
  21.         public static void Initialize()
  22.         {
  23.             DestinationConfig.Init();
  24.             CheckGuideIntegrity();
  25.  
  26.             EventSink.Logout += new LogoutEventHandler(OnLogout);
  27.             EventSink.Disconnected += new DisconnectedEventHandler(OnDisconnect);
  28.             EventSink.ServerStarted += new ServerStartedEventHandler(OnLoad);
  29.             EventSink.WorldSave += new WorldSaveEventHandler(OnSave);
  30.         }
  31.  
  32.         private static void OnLoad()
  33.         {
  34.             /*string path = "\\Saves\\Touring\\";
  35.             string fileName = "guides.bin";
  36.  
  37.             if (!Directory.Exists(path))
  38.                 Directory.CreateDirectory(path);
  39.  
  40.             if (!File.Exists(path + fileName))
  41.                 File.Create(path + fileName).Close();
  42.  
  43.             FileStream stream = File.OpenRead(path + fileName);
  44.  
  45.             if(stream.Length > 0)
  46.             {
  47.                 using (BinaryFileReader reader = new BinaryFileReader(new BinaryReader(stream)))
  48.                 {
  49.                     int count = reader.ReadInt();
  50.  
  51.                     for(int i = 0; i < count; i++)
  52.                     {
  53.                         int destID = reader.ReadInt();
  54.                         TourGuide guide = (TourGuide)reader.ReadMobile();
  55.  
  56.                         if (guide != null && !guide.Deleted && m_Destinations[destID] != null)
  57.                         {
  58.                             Destination dest = m_Destinations[destID];
  59.  
  60.                             m_GuideLocations.Add(dest, guide);
  61.                         }
  62.                     }
  63.  
  64.                     reader.Close();
  65.                 }
  66.             }
  67.  
  68.             stream.Close();*/
  69.         }
  70.  
  71.         private static void OnSave(WorldSaveEventArgs e)
  72.         {
  73.             /*string path = "\\Saves\\Touring\\";
  74.             string fileName = "guides.bin";
  75.  
  76.             if (!Directory.Exists(path))
  77.                 Directory.CreateDirectory(path);
  78.  
  79.             if (File.Exists(path + fileName))
  80.                 File.Delete(path + fileName);
  81.  
  82.             if (!File.Exists(path + fileName))
  83.                 File.Create(path + fileName).Close();
  84.  
  85.             FileStream stream = File.OpenWrite(path + fileName);
  86.  
  87.             using (BinaryFileWriter writer = new BinaryFileWriter(stream, true))
  88.             {
  89.                 writer.Write(m_GuideLocations.Count);
  90.  
  91.                 for (int i = 0; i < m_GuideLocations.Count; i++)
  92.                 {
  93.                     for (int destID = 0; destID < m_Destinations.Count; destID++)
  94.                     {
  95.                         if (m_Destinations[destID] != null)
  96.                         {
  97.                             Destination test = (Destination)m_Destinations[destID];
  98.  
  99.                             if (m_GuideLocations.ContainsKey(test))
  100.                             {
  101.                                 writer.Write(destID);
  102.                                 writer.Write((Mobile)m_GuideLocations[destID]);
  103.                                 break;
  104.                             }
  105.                         }
  106.                     }
  107.                 }
  108.  
  109.                 writer.Close();
  110.             }
  111.  
  112.             stream.Close();*/
  113.         }
  114.  
  115.         public static void CheckGuideIntegrity()
  116.         {
  117. #if(RUNUO_2)
  118.             List<Destination> toRemove = new List<Destination>();
  119. #else
  120.             ArrayList toRemove = new ArrayList();
  121. #endif
  122.  
  123. #if(RUNUO_2)
  124.             foreach (KeyValuePair<Destination, TourGuide> kvp in m_GuideLocations)
  125.             {
  126.                 Destination dest = kvp.Key;
  127.                 TourGuide guide = kvp.Value;
  128.  
  129.                 if (guide == null || guide.Deleted || !TourConfig.UseTourGuide)
  130.                     toRemove.Add(dest);
  131.             }
  132. #else
  133.             foreach(Destination dest in m_GuideLocations.Keys)
  134.             {
  135.                 TourGuide guide = (TourGuide)m_GuideLocations[dest];
  136.  
  137.                 if (guide == null || guide.Deleted || !TourConfig.UseTourGuide)
  138.                     toRemove.Add(dest);
  139.             }
  140. #endif
  141.  
  142.             foreach (Destination xDest in toRemove)
  143.             {
  144.                 if (m_GuideLocations.ContainsKey(xDest))
  145.                 {
  146.                     TourGuide guide = (TourGuide)m_GuideLocations[xDest];
  147.  
  148.                     if (guide != null && !guide.Deleted)
  149.                         guide.Delete();
  150.  
  151.                     m_GuideLocations.Remove(xDest);
  152.                 }
  153.             }
  154.         }
  155.  
  156.         public static void AddDestination(Map map, Point3D location, string name, string description, TimeSpan delay)
  157.         {
  158.             Destination dest = new Destination(map, location, name, description, delay);
  159.  
  160.             if (dest.IsValid())
  161.             {
  162.                 m_Destinations.Add(dest);
  163.  
  164.                 if (TourConfig.UseTourGuide)
  165.                 {
  166.                     TourGuide guide = new TourGuide(dest);
  167.  
  168.                     if (guide != null && !guide.Deleted)
  169.                         m_GuideLocations.Add(dest, guide);
  170.                 }
  171.             }
  172.         }
  173.  
  174.         private static void OnLogout(LogoutEventArgs e)
  175.         {
  176.             if (e.Mobile == null || e.Mobile.Deleted)
  177.                 return;
  178.  
  179.             Tour.Finish(e.Mobile);
  180.         }
  181.  
  182.         private static void OnDisconnect(DisconnectedEventArgs e)
  183.         {
  184.             if (e.Mobile == null || e.Mobile.Deleted)
  185.                 return;
  186.  
  187.             Tour.Finish(e.Mobile);
  188.         }
  189.  
  190.         public static event DestinationChangedEventHandler
  191.             DestinationChanged = new DestinationChangedEventHandler(OnDestinationChanged);
  192.  
  193.         public static void DestinationChangedInvoke(DestinationChangedEventArgs e)
  194.         {
  195.             try { DestinationChanged.Invoke(e); }
  196.             catch { }
  197.         }
  198.  
  199.         private static void OnDestinationChanged(DestinationChangedEventArgs e)
  200.         {
  201.             if (e.Mobile == null || e.Mobile.Deleted)
  202.                 return;
  203.  
  204.             if (m_Stages.ContainsKey(e.Mobile))
  205.             {
  206.                 int curStage = (int)m_Stages[e.Mobile];
  207.                 Destination curDest = e.Destination;
  208.  
  209.                 if (curDest.IsValid())
  210.                 {
  211.                     if (TourConfig.UseTourGuide)
  212.                     {
  213.                         TourGuide guide = FindTourGuide(curDest);
  214.  
  215.                         if (guide != null && !guide.Deleted)
  216.                         {
  217.                             guide.ShowTo(e.Mobile);
  218.                             guide.SayTo(e.Mobile, String.Format("Welcome to {0}!", e.Destination.Name));
  219.                             guide.SayTo(e.Mobile, String.Format("{0}", e.Destination.Description));
  220.                         }
  221.                         else
  222.                         {
  223.                             e.Mobile.SendMessage(0x55, String.Format("Welcome to {0}! {1}", e.Destination.Description));
  224.                         }
  225.                     }
  226.                     else
  227.                     {
  228.                         e.Mobile.SendMessage(0x55, String.Format("Welcome to {0}! {1}", e.Destination.Description));
  229.                     }
  230.  
  231.                     Timer.DelayCall(e.Destination.Delay, new TimerStateCallback(NextDestination), new object[] { e.Mobile });
  232.                 }
  233.             }
  234.         }
  235.  
  236.  
  237.     }
  238.  
  239.     public sealed class DestinationChangedEventArgs : EventArgs
  240.     {
  241.         private Destination m_Destination;
  242.         private Mobile m_Mobile;
  243.  
  244.         public Destination Destination { get { return m_Destination; } }
  245.         public Mobile Mobile { get { return m_Mobile; } }
  246.  
  247.         public DestinationChangedEventArgs(Destination destination, Mobile m)
  248.         {
  249.             m_Destination = destination;
  250.             m_Mobile = m;
  251.         }
  252.     }
  253. }
  254.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement