// Basic Herald system // Basic on DOL script : XMLWebUIGenerator.cs // Modded my Fooljam and Tobz // Date : October 14, 2005 // Official support website : http://www.daocworld.net using System; using System.Reflection; using System.IO; using DOL.Database; using DOL.Database.Attributes; using DOL.Database.Connection; using DOL.Events; using DOL.GS.PacketHandler; using log4net; namespace DOL.GS.Scripts { public class HeraldDBGenerator { /// /// Defines a logger for this class. /// private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); [ScriptLoadedEvent] public static void OnScriptLoaded(DOLEvent e, object sender, EventArgs args) { Start(); } [ScriptUnloadedEvent] public static void OnScriptUnloaded(DOLEvent e, object sender, EventArgs args) { Stop(); } [DataTable(TableName="Herald")] public class Herald : DataObject { private string m_name = "NA"; private string m_lastName = "NA"; private string m_guild = "NA"; private string m_race = "NA"; private string m_class = "NA"; private int m_lvl = 0; private string m_realm = "NA"; private string m_realmPts = "NA"; private string m_RealmTitle = "NA"; private string m_RealmRank = "NA"; private string m_lastPlayed = "NA"; private static bool m_autoSave = true; public override bool AutoSave { get { return m_autoSave; } set { m_autoSave = value; } } [DataElement(AllowDbNull=true)] public string Name { get { return m_name; } set { m_name = value; } } [DataElement(AllowDbNull=true)] public string LastName { get { return m_lastName; } set { m_lastName = value; } } [DataElement(AllowDbNull=true)] public string Guild { get { return m_guild; } set { m_guild = value; } } [DataElement(AllowDbNull=true)] public string Race { get { return m_race; } set { m_race = value; } } [DataElement(AllowDbNull=true)] public string Class { get { return m_class; } set { m_class = value; } } [DataElement(AllowDbNull=true)] public string Realm { get { return m_realm; } set { m_realm = value; } } [DataElement(AllowDbNull=true)] public int Level { get { return m_lvl; } set { m_lvl = value; } } [DataElement(AllowDbNull=true)] public string RealmPoints { get { return m_realmPts; } set { m_realmPts = value; } } [DataElement(AllowDbNull=true)] public string RealmTitle { get { return m_RealmTitle; } set { m_RealmTitle = value; } } [DataElement(AllowDbNull=true)] public string RealmRankTitle { get { return m_RealmRank; } set { m_RealmRank = value; } } [DataElement(AllowDbNull=true)] public string LastPlayed { get { return m_lastPlayed; } set { m_lastPlayed = value; } } } /// /// Holds all realm rank names /// public static readonly string[][] REALM_RANK_NAMES = { new string[] { "realm0" }, // alb new string[] { "Guardian", "Warder", "Myrmidon", "Gryphon Knight", "Eagle Knight", "Phoenix Knight", "Alerion Knight", "Unicorn Knight", "Lion Knight", "Dragon Knight", }, // Mid new string[] { "Skiltvakten", "Isen Vakten", "Flammen Vakten", "Elding Vakten", "Stormur Vakten", "Isen Herra", "Flammen Herra", "Elding Herra", "Stormur Herra", "Einherjar", }, // Hib new string[] { "Savant", "Cosantoir", "Brehon", "Grove Protector", "Raven Ardent", "Silver Hand", "Thunderer", "Gilded Spear", "Tiarna", "Emerald Ridere", }, }; protected static readonly long[] REALMPOINTS_FOR_LEVEL = { 0, // 1L1 1, // 1L1 25, // 1L2 125, // 1L3 350, // 1L4 750, // 1L5 1375, // 1L6 2275, // 1L7 3500, // 1L8 5100, // 1L9 7125, // 2L0 9625, // 2L1 12650, // 2L2 16250, // 2L3 20475, // 2L4 25375, // 2L5 31000, // 2L6 37400, // 2L7 44625, // 2L8 52725, // 2L9 61750, // 3L0 71750, // 3L1 82775, // 3L2 94875, // 3L3 108100, // 3L4 122500, // 3L5 138125, // 3L6 155025, // 3L7 173250, // 3L8 192850, // 3L9 213875, // 4L0 236375, // 4L1 260400, // 4L2 286000, // 4L3 313225, // 4L4 342125, // 4L5 372750, // 4L6 405150, // 4L7 439375, // 4L8 475475, // 4L9 513500, // 5L0 553500, // 5L1 595525, // 5L2 639625, // 5L3 685850, // 5L4 734250, // 5L5 784875, // 5L6 837775, // 5L7 893000, // 5L8 950600, // 5L9 1010625, // 6L0 1073125, // 6L1 1138150, // 6L2 1205750, // 6L3 1275975, // 6L4 1348875, // 6L5 1424500, // 6L6 1502900, // 6L7 1584125, // 6L8 1668225, // 6L9 1755250, // 7L0 1845250, // 7L1 1938275, // 7L2 2034375, // 7L3 2133600, // 7L4 2236000, // 7L5 2341625, // 7L6 2450525, // 7L7 2562750, // 7L8 2678350, // 7L9 2797375, // 8L0 2919875, // 8L1 3045900, // 8L2 3175500, // 8L3 3308725, // 8L4 3445625, // 8L5 3586250, // 8L6 3730650, // 8L7 3878875, // 8L8 4030975, // 8L9 4187000, // 9L0 4347000, // 9L1 4511025, // 9L2 4679125, // 9L3 4851350, // 9L4 5027750, // 9L5 5208375, // 9L6 5393275, // 9L7 5582500, // 9L8 5776100, // 9L9 5974125, // 10L0 6176625, // 10L1 6383650, // 10L2 6595250, // 10L3 6811475, // 10L4 7032375, // 10L5 7258000, // 10L6 7488400, // 10L7 7723625, // 10L8 7963725, // 10L9 8208750, // 11L0 9111713, // 11L1 10114001, // 11L2 11226541, // 11L3 12461460, // 11L4 13832221, // 11L5 15353765, // 11L6 17042680, // 11L7 18917374, // 11L8 20998286, // 11L9 23308097 // 12L0 }; public static string CalculateRealmLevelFromRPs(long realmPoints) { if (realmPoints == 0) return 0; int i = REALMPOINTS_FOR_LEVEL.Length - 1; for (; i > 0; i--) { if (REALMPOINTS_FOR_LEVEL[i] <= realmPoints) break; } if (i > 111) return 111; return i; } public static string GetRealmTitle(long realmPoints, int realm) { if (realm >= REALM_RANK_NAMES.Length) return "unknown realm"; string[] rankNames = REALM_RANK_NAMES[realm]; int rank = CalculateRealmLevelFromRPs(realmPoints) / 10; if (rank >= rankNames.Length) rank = rankNames.Length - 1; return rankNames[rank]; } public static string GetRealmRankTitle(long realmPoints) { int rank = CalculateRealmLevelFromRPs(realmPoints); int firstPart = rank / 10; int secondPart = rank - (firstPart * 10); return firstPart.ToString() + "L" + secondPart.ToString(); } public static void Generate() { try { DataConnection con = new DataConnection(ConnectionType.DATABASE_XML, "."+Path.DirectorySeparatorChar+"herald"); ObjectDatabase db = new ObjectDatabase(con); db.RegisterDataObject(typeof (Herald)); Character[] allChars = (Character[])GameServer.Database.SelectAllObjects(typeof(Character)); foreach(Character singleChar in allChars) { Herald pi = new Herald(); Character plr = singleChar; pi.Name = plr.Name; pi.LastName = plr.LastName; pi.Class = ((eCharacterClass) plr.Class).ToString(); pi.Race = ((eRace) plr.Race).ToString(); pi.Guild = plr.GuildName; pi.Level = plr.Level; pi.Realm = GlobalConstants.RealmToName((eRealm)plr.Realm); pi.RealmPoints = plr.RealmPoints.ToString(); pi.RealmTitle = GetRealmTitle(plr.RealmPoints, plr.Realm); pi.RealmRankTitle = GetRealmRankTitle(plr.RealmPoints); pi.LastPlayed = plr.LastPlayed.ToString(); db.AddNewObject(pi); } db.WriteDatabaseTables(); con = null; db = null; if (log.IsInfoEnabled) log.Info("Herald Generation initialized"); } catch (Exception e) { if (log.IsErrorEnabled) log.Error("Herald Generation: ", e); } } public static void Start() { //Fooljam : Add comments to "Generate();" function if you don't want the Herald files be generated when server starts Generate(); if (log.IsInfoEnabled) log.Info("Herald generation done..."); } public static void Stop() { //Fooljam : Uncomment if you want the Herald be generated when you shut down the server as well. //Generate(); if (log.IsInfoEnabled) log.Info("Herald generation done..."); } } }