Ejemplo n.º 1
0
        public static void EventSink_Login(LoginEventArgs args)
        {
            Setup set = new Setup();

            NetState     ns = args.Mobile.NetState;
            PlayerMobile pm = args.Mobile as PlayerMobile;

            if (PlayerInfo.ContainsKey(Convert.ToInt32(pm.Serial)))//Loaded
            {
                InfoList info = PlayerInfo[Convert.ToInt32(pm.Serial)];

                if (pm.Level > info.Level | pm.KillExp > info.KillExp)//Login-Logout-Login Saftey:
                {
                    return;
                }

                pm.Level      = info.Level;
                pm.LevelCap   = info.LevelCap;
                pm.KillExp    = info.KillExp;
                pm.AccKillExp = info.AccKillExp;
                pm.LevelAt    = info.LevelAt;
                pm.AccLevelAt = info.AccLevelAt;
            }
            else//Newbie
            {
                pm.Level      = 1;
                pm.LevelCap   = set.StartingLevelCap;
                pm.KillExp    = 0;
                pm.AccKillExp = 0;
                pm.LevelAt    = set.NextLevelAt;
                pm.AccLevelAt = set.NextLevelAt;

                PlayerInfo.Add(Convert.ToInt32(pm.Serial),
                               new InfoList(pm.Level, pm.LevelCap, pm.KillExp, pm.AccKillExp, pm.LevelAt, pm.AccLevelAt));
            }
        }
Ejemplo n.º 2
0
        public static void EventSink_Save(WorldSaveEventArgs args)
        {
            ConsoleColor col = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.DarkGreen;

            Console.WriteLine();
            Console.Write("Level System: Saving... ");
            Setup    set   = new Setup();
            DateTime Start = DateTime.Now;

            if (!Directory.Exists(FilePath))
            {
                Directory.CreateDirectory(FilePath);
            }

            if (File.Exists(FilePath + FileName))
            {
                File.Delete(FilePath + FileName);
            }

            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent      = true;
            settings.IndentChars = "	";

            XmlWriter writer = XmlWriter.Create(FilePath + FileName, settings);

            writer.WriteStartElement("Info");

            string ID;

            foreach (Mobile mob in World.Mobiles.Values)
            {
                if (mob is PlayerMobile)
                {
                    PlayerMobile pm = mob as PlayerMobile;

                    if (PlayerInfo.ContainsKey(Convert.ToInt32(pm.Serial)))
                    {
                        InfoList info = PlayerInfo[Convert.ToInt32(pm.Serial)];

                        ID = Convert.ToString(Convert.ToInt32(pm.Serial));
                        writer.WriteStartElement("ID");
                        writer.WriteStartAttribute("", "Serial", "");
                        writer.WriteString(ID);
                        writer.WriteEndAttribute();

                        if (info.Level > pm.Level && pm.Level == 0 || info.KillExp > pm.KillExp && pm.KillExp == 0)
                        {   //Login-Save-Restart-No Login-Save Saftey
                            SystemInfo.SaveValue("Level", info.Level, 0, writer);
                            SystemInfo.SaveValue("LevelCap", info.LevelCap, 0, writer);
                            SystemInfo.SaveValue("KillExp", info.KillExp, 1, writer);
                            SystemInfo.SaveValue("AccKillExp", info.AccKillExp, 1, writer);
                            SystemInfo.SaveValue("LevelAt", info.LevelAt, 0, writer);
                            SystemInfo.SaveValue("AccLevelAt", info.LevelAt, 0, writer);
                        }
                        else
                        {
                            SystemInfo.SaveValue("Level", pm.Level, 0, writer);
                            SystemInfo.SaveValue("LevelCap", pm.LevelCap, 0, writer);
                            SystemInfo.SaveValue("KillExp", pm.KillExp, 1, writer);
                            SystemInfo.SaveValue("AccKillExp", pm.AccKillExp, 1, writer);
                            SystemInfo.SaveValue("LevelAt", pm.LevelAt, 0, writer);
                            SystemInfo.SaveValue("AccLevelAt", pm.LevelAt, 0, writer);
                        }

                        writer.WriteEndElement();
                    }
                }
            }

            writer.WriteEndElement();
            writer.Close();

            if (set.TimeSave)
            {
                Console.WriteLine("Done! ({0:F1} seconds)", (DateTime.Now - Start).TotalSeconds);
            }
            else
            {
                Console.WriteLine("Done!");
            }

            Console.ForegroundColor = col;
            LoadPlayers(true);
        }