public void Undo(Mapcache mapcache) { for (int index = _commands.Count - 1; index >= 0; index--) { _commands[index].Undo(mapcache); } }
public void Undo(Mapcache mapcache) { if (_conflictMap == null) { mapcache.Maps.Remove(_map); } else { mapcache.Maps[mapcache.GetMapIndex(_name)] = _conflictMap; } }
public static void Destroy() { // Clear and dispose all objects if (Objects != null) { Objects.Clear(true); Objects = null; } // Maps Mapcache.Destroy(); }
public void Execute(Mapcache mapcache) { _setupMap(); int index = mapcache.GetMapIndex(_name); if (index > -1) { _conflictMap = mapcache.Maps[index]; mapcache.Maps[index] = _map; } else { mapcache.Maps.Add(_map); } }
public void Execute(Mapcache mapcache) { if (_executeCommandsOnStore) { if (_firstTimeExecuted) { _firstTimeExecuted = false; return; } } for (int index = 0; index < _commands.Count; index++) { var command = _commands[index]; try { command.Execute(mapcache); } catch (AbstractCommandException) { _commands.RemoveAt(index); index--; } } }
public static void Load() { if (Loaded == true || Loading == true) { return; } Loading = true; // Trigger events for scripts Events.Call("worldLoadStart"); // Our object manager for world objects (spawned objects) Objects = new WorldObjectManager(); // Delegate for Send() Method //mForeachInRangeCallback = new ForeachInRangeVoidDelegate(SendSub); mAddQueue = new Queue <WorldObject>(); mDelQueue = new Queue <WorldObject>(); // Load globals from config, initialize packets ect ServerConsole.InfoLine("Initialize game symantics..."); Global.Initialize(); PathHelper.Initialize(); // Real database loading ServerConsole.InfoLine("Begin World loading..."); DataTable table = null; Stopwatch watchAll = Stopwatch.StartNew(); Stopwatch watch = Stopwatch.StartNew(); //------------- loading start ------------- #region Mapcache ServerConsole.Info("\t# loading Maps from mapcache..."); watch.Reset(); watch.Start(); Mapcache.Initialize(); watch.Stop(); ServerConsole.WriteLine(EConsoleColor.Status, " done (" + Mapcache.Maps.Count + " Maps in " + watch.ElapsedMilliseconds + "ms)"); #endregion // Loading other shit // o.o //------------- loading end ------------- // Trigger event for scripts Events.Call("worldLoadFinish"); Loading = false; Loaded = true; ProcessSafetyQueues(); // TODO: Initialize save timer ServerConsole.InfoLine("Finished World loading! Needed {0:F2} sec", watchAll.Elapsed.TotalSeconds); watch.Stop(); watch = null; watchAll.Stop(); watchAll = null; }
public void Undo(Mapcache mapcache) { mapcache.Maps.Insert(_index, _conflict); }
public void Execute(Mapcache mapcache) { _index = mapcache.GetMapIndex(_name); _conflict = mapcache.Maps[_index]; mapcache.Maps.RemoveAt(_index); }
public CommandsHolder(Mapcache mapcache) { _mapcache = mapcache; }
public MapcacheGroupCommand(Mapcache mapcache, bool executeCommandsOnStore = false) { _mapcache = mapcache; _executeCommandsOnStore = executeCommandsOnStore; }
protected override bool LoadFromDatabase(DataRow row) { // Load serials base.Serial = new DatabaseID(row.Field <uint>("charID"), EDatabaseType.Char); if (row.Field <uint>("partyID") > 0) { PartyID = new WorldID(row.Field <uint>("partyID"), EDatabaseType.Party); } if (row.Field <uint>("guildID") > 0) { GuildID = new WorldID(row.Field <uint>("guildID"), EDatabaseType.Guild); } if (row.Field <uint>("petID") > 0) { PetID = new WorldID(row.Field <uint>("petID"), EDatabaseType.Pet); } if (row.Field <uint>("homunID") > 0) { HomID = new WorldID(row.Field <uint>("homunID"), EDatabaseType.Homunculus); } if (row.Field <uint>("partnerID") > 0) { PartnerID = new WorldID(row.Field <uint>("partnerID"), EDatabaseType.Char); } if (row.Field <uint>("fatherID") > 0) { FatherID = new WorldID(row.Field <uint>("fatherID"), EDatabaseType.Char); } if (row.Field <uint>("motherID") > 0) { MotherID = new WorldID(row.Field <uint>("motherID"), EDatabaseType.Char); } if (row.Field <uint>("childID") > 0) { ChildrenID = new WorldID(row.Field <uint>("childID"), EDatabaseType.Char); } if (row.Field <uint>("childID") > 0) { MercenaryID = new WorldID(row.Field <uint>("mercID"), EDatabaseType.Mercenary); } Name = row.Field <string>("name"); LevelBase = row.Field <ushort>("levelBase"); LevelJob = row.Field <ushort>("levelJob"); // TODO: rework all datatypes.. Str = (short)row.Field <ushort>("str"); Agi = (short)row.Field <ushort>("agi"); Vit = (short)row.Field <ushort>("vit"); Int = (short)row.Field <ushort>("int"); Dex = (short)row.Field <ushort>("dex"); Luk = (short)row.Field <ushort>("luk"); Slot = (byte)row.Field <short>("slot"); //Sex = (EAccountSex)row.Field<int>("sex"); ExpBase = (uint)row.Field <ulong>("expBase"); ExpJob = (uint)row.Field <ulong>("expJob"); Zeny = (int)row.Field <uint>("zeny"); Class = (EClientClass)row.Field <ushort>("class"); StatusPoints = row.Field <uint>("statusPoint"); SkillPoints = row.Field <uint>("skillPoint"); HP = (int)row.Field <uint>("hp"); HPMax = (int)row.Field <uint>("hpMax"); SP = (int)row.Field <uint>("sp"); SPMax = (int)row.Field <uint>("spMax"); Option = (EStatusOption)row.Field <int>("option"); Manner = row.Field <short>("manner"); Karma = (byte)row.Field <sbyte>("karma"); HairStyle = row.Field <byte>("hair"); HairColor = (short)row.Field <ushort>("hairColor"); ClothColor = (short)row.Field <ushort>("clothesColor"); IsOnline = (row.Field <sbyte>("isOnline") > 0? true : false); Fame = (int)row.Field <uint>("fame"); // Mercenary Guilds Rank /* * int arch_faith, arch_calls; * int spear_faith, spear_calls; * int sword_faith, sword_calls; */ Weapon = (EWeaponType)row.Field <ushort>("weapon"); Shield = (short)row.Field <ushort>("shield"); HeadTop = (short)row.Field <ushort>("headTop"); HeadMid = (short)row.Field <ushort>("headMid"); HeadBottom = (short)row.Field <ushort>("headBottom"); Rename = (short)row.Field <ushort>("rename"); // Load locations Location = new Location(Mapcache.GetID(row.Field <string>("lastMap")), row.Field <ushort>("lastX"), row.Field <ushort>("lastY")); SavePoint = new Location(Mapcache.GetID(row.Field <string>("saveMap")), row.Field <ushort>("saveX"), row.Field <ushort>("saveY")); // Other crap DeleteDate = row.FieldDateTime("deleteDate"); return(true); }
public static void Load() { if (Loaded == true || Loading == true) { return; } Loading = true; // Trigger events for scripts Events.InvokeWorldLoadStart(); // Our object manager for databsae objects Database = new DatabaseObjectManager(); // Our object manager for world objects (spawned objects) Objects = new WorldObjectManager(); // Delegate for Send() Method mForeachInRangeCallback = new ForeachInRangeVoidDelegate(SendSub); mAddQueue = new Queue <DatabaseObject>(); mDelQueue = new Queue <DatabaseObject>(); // Load globals from config, initialize packets ect ServerConsole.InfoLine("Initialize game symantics..."); Global.Initialize(); WorldObjectStatus.Initialize(); ChatHelper.Initialize(); PlayerCommandHelper.Initialize(); PathHelper.Initialize(); SkillTree.Initialize(); FameListHelper.Initialize(); CharacterJobBonus.Initialize(); CharacterJobModifer.Initialize(); // Real database loading ServerConsole.InfoLine("Begin World loading..."); DataTable table = null; Stopwatch watchAll = Stopwatch.StartNew(); Stopwatch watch = Stopwatch.StartNew(); //------------- loading start ------------- #region Mapcache ServerConsole.Info("\t# loading Maps from mapcache..."); watch.Reset(); watch.Start(); Mapcache.Initialize(); watch.Stop(); ServerConsole.WriteLine(EConsoleColor.Status, " done (" + Mapcache.Maps.Count + " Maps in " + watch.ElapsedMilliseconds + "ms)"); #endregion #region Items ServerConsole.Info("\t# loading Items..."); watch.Reset(); watch.Start(); table = Core.Database.Query("SELECT * FROM dbitem"); table.TableName = "ItemDB Table"; if (table == null || table.Rows.Count == 0) { if (Core.Database.LastError != null) { ServerConsole.ErrorLine("failed to load Item Database!"); ServerConsole.WriteLine(Core.Database.LastError.ToString()); } } else { ItemDatabaseData item; for (int i = 0; i < table.Rows.Count; i++) { item = ItemDatabaseData.Load(table.Rows[i]); if (item == null) { ServerConsole.WarningLine("Failed to load item {0}: #{1} {2}", i, table.Rows[i].Field <int>("itemID"), table.Rows[i].Field <string>("nameEnglish")); continue; } Database.Add(item); //ServerConsole.DebugLine("\tLoad: #{0} {1}", item.NameID.ToString().PadLeft(5), item.Name); } } watch.Stop(); ServerConsole.WriteLine(EConsoleColor.Status, " done (" + Database.Items.Count + " Items in " + watch.ElapsedMilliseconds + "ms)"); #endregion #region Monster ServerConsole.Info("\t# loading Mobs..."); watch.Reset(); watch.Start(); table = Core.Database.Query("SELECT * FROM dbmob"); table.TableName = "MobDB Table"; if (table == null || table.Rows.Count == 0) { if (Core.Database.LastError != null) { ServerConsole.ErrorLine("failed to load Monster Database!"); ServerConsole.WriteLine(Core.Database.LastError.ToString()); } } else { MonsterDatabaseData mob; for (int i = 0; i < table.Rows.Count; i++) { mob = MonsterDatabaseData.Load(table.Rows[i]); if (mob == null) { ServerConsole.WarningLine("Failed to load mob {0}: #{1} {2}", i, table.Rows[i].Field <int>("mobID"), table.Rows[i].Field <string>("nameInter")); continue; } Database.Add(mob); //ServerConsole.DebugLine("\tLoad: #{0} {1} ({2} drops, {3} skills)", mob.ID.ToString().PadLeft(5), mob.NameInter, mob.Drops.Count, mob.Skills.Count); } } watch.Stop(); ServerConsole.WriteLine(EConsoleColor.Status, " done (" + Database.Monster.Count + " Mobs in " + watch.ElapsedMilliseconds + "ms)"); ServerConsole.Info("\t# loading Mob Skills..."); watch.Reset(); watch.Start(); table = Core.Database.Query("SELECT * FROM dbmob_skill ORDER BY mobID ASC"); table.TableName = "MobDB Skill Table"; if (table == null || table.Rows.Count == 0) { if (Core.Database.LastError != null) { ServerConsole.ErrorLine("failed to load Mob Skill Database!"); ServerConsole.WriteLine(Core.Database.LastError.ToString()); } } else { MonsterSkill mobSkill; for (int i = 0; i < table.Rows.Count; i++) { mobSkill = MonsterSkill.Load(table.Rows[i]); if (mobSkill == null) { throw new Exception(string.Format("Failed to load mob skill #{0}: {1}", table.Rows[i].Field <int>("mobID"), table.Rows[i].Field <string>("info"))); } (Database[EDatabaseType.Mob, mobSkill.MobID] as MonsterDatabaseData).Skills.Add(mobSkill); //ServerConsole.DebugLine("\tLoad: #{0} {1} ({2} level)", skill.ID.ToString().PadLeft(5), skill.Name, skill.Level.Count); } } watch.Stop(); ServerConsole.WriteLine(EConsoleColor.Status, " done in " + watch.ElapsedMilliseconds + "ms"); ServerConsole.Info("\t# loading Mob Drops..."); watch.Reset(); watch.Start(); table = Core.Database.Query("SELECT * FROM dbmob_drop ORDER BY mobID ASC"); table.TableName = "MobDB Drop Table"; if (table == null || table.Rows.Count == 0) { if (Core.Database.LastError != null) { ServerConsole.ErrorLine("failed to load Mob Drop Database!"); ServerConsole.WriteLine(Core.Database.LastError.ToString()); } } else { MonsterDrop drop; for (int i = 0; i < table.Rows.Count; i++) { drop = MonsterDrop.Load(table.Rows[i]); (Database[EDatabaseType.Mob, drop.MobID] as MonsterDatabaseData).Drops.Add(drop); //ServerConsole.DebugLine("\tLoad: #{0} {1} ({2} level)", skill.ID.ToString().PadLeft(5), skill.Name, skill.Level.Count); } } watch.Stop(); ServerConsole.WriteLine(EConsoleColor.Status, " done in " + watch.ElapsedMilliseconds + "ms"); #endregion #region General Skills ServerConsole.Info("\t# loading Skills..."); watch.Reset(); watch.Start(); table = Core.Database.Query("SELECT * FROM dbskill"); table.TableName = "SkillDB Table"; if (table == null || table.Rows.Count == 0) { if (Core.Database.LastError != null) { ServerConsole.ErrorLine("failed to load Skill Database!"); ServerConsole.WriteLine(Core.Database.LastError.ToString()); } } else { SkillDatabaseData skill; for (int i = 0; i < table.Rows.Count; i++) { skill = SkillDatabaseData.Load(table.Rows[i]); if (skill == null) { ServerConsole.WarningLine("Failed to load skill {0}: #{1} {2}", i, table.Rows[i].Field <int>("skillID"), table.Rows[i].Field <string>("name")); continue; } Database.Add(skill.Index, skill); //ServerConsole.DebugLine("\tLoad: #{0} {1} ({2} level)", skill.ID.ToString().PadLeft(5), skill.Name, skill.Level.Count); } } watch.Stop(); ServerConsole.WriteLine(EConsoleColor.Status, " done (" + Database.Skill.Count + " Skills in " + watch.ElapsedMilliseconds + "ms)"); #endregion // Loading other shit // o.o //------------- loading end ------------- // Trigger event for scripts Events.InvokeWorldLoadFinish(); Loading = false; Loaded = true; ProcessSafetyQueues(); // TODO: Initialize save timer ServerConsole.InfoLine("Finished World loading! Needed {0:F2} sec", watchAll.Elapsed.TotalSeconds); watch.Stop(); watch = null; watchAll.Stop(); watchAll = null; }
public static ECharacterCreationResult Create(Account account, string name, byte slot, byte str, byte agi, byte vit, byte int_, byte dex, byte luk, short hairColor, short hairStyle, out Character newChar) { newChar = null; if (name.Length > 24) { name = name.Substring(0, 24); } //name = name.Replace('\032', ' ').Replace('\t', ' ').Replace('\x0A', ' ').Replace('\x0D', ' '); if ( (slot >= Global.MAX_SLOTS) || (str + agi + vit + int_ + dex + luk != 6 * 5) || (str < 1 || str > 9 || agi < 1 || agi > 9 || vit < 1 || vit > 9 || int_ < 1 || int_ > 9 || dex < 1 || dex > 9 || luk < 1 || luk > 9) || (str + int_ != 10 || agi + luk != 10 || vit + dex != 10) ) { return(ECharacterCreationResult.CharCreationDenied); // invalid input } // Check for max character count on this account if (account.Chars.Count >= Global.MAX_SLOTS) { return(ECharacterCreationResult.CharCreationDenied); // character account limit exceeded } // Check for existing char with this name if (Core.Database.Query("SELECT charID FROM `char` WHERE `name` = '{0}'", name.MysqlEscape()).Rows.Count > 0) { return(ECharacterCreationResult.CharnameAlreadyExists); } // Check for existing char on this slot foreach (Character tmpChar in account.Chars.Values) { if (tmpChar.Status.Slot == slot) { return(ECharacterCreationResult.CharCreationDenied); } } // TODO: this has to be in CharacterDatabaseStatus, nor? // CharacterDatabaseData represents the character in the character server // so.. newChar = new Character(DatabaseID.Zero, false); newChar.Parent = account; newChar.Status.Name = name; newChar.Status.Slot = slot; newChar.Status.Zeny = Config.StartZeny; newChar.Status.Str = str; newChar.Status.Agi = agi; newChar.Status.Dex = dex; newChar.Status.Vit = vit; newChar.Status.Int = int_; newChar.Status.Luk = luk; newChar.Status.HPMax = newChar.Status.HP = (40 * (100 + vit) / 100); newChar.Status.SPMax = newChar.Status.SP = (11 * (100 + int_) / 100); newChar.Status.HairStyle = hairStyle; newChar.Status.HairColor = hairColor; newChar.Status.SavePoint = new Location(Mapcache.GetID(Config.StartMap), Config.StartMapX, Config.StartMapY); newChar.Status.Location = new Location(newChar.Status.SavePoint.Map.ID, newChar.Status.SavePoint.Point.X, newChar.Status.SavePoint.Point.Y); // Save it CharacterDatabaseData status = newChar.Status; string query = string.Format( "INSERT INTO `char` (" + "`accountID`, `slot`, `name`, `zeny`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hpMax`, `hp`," + "`spMax`, `sp`, `hair`, `hairColor`, `lastMap`, `lastX`, `lastY`, `saveMap`, `saveX`, `saveY`" + ") VALUES (" + "{0}, {1}, '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}'," + "'{12}', '{13}', '{14}', '{15}', '{16}', '{17}', '{18}', '{19}', '{20}', '{21}'" + ")" , account.WorldID.ID, slot, name.MysqlEscape(), status.Zeny, status.Str, status.Agi, status.Vit, status.Int, status.Dex, status.Luk, status.HPMax, status.HP, status.SPMax, status.SP, status.HairStyle, status.HairColor, status.Location.Map, status.Location.Point.X, status.Location.Point.Y, status.SavePoint.Map, status.SavePoint.Point.X, status.SavePoint.Point.X ); Core.Database.Query(query); uint charID = (uint)Core.Database.GetLastInsertID(); if (charID == 0) { // Failed to add character? return(ECharacterCreationResult.CharCreationDenied); } // save Serial/CharID newChar.UpdateDatabaseID(charID, EDatabaseType.Char); newChar.WorldID = new WorldID(charID, EDatabaseType.Char); // Add it to account dictionary account.Chars.Add(newChar.WorldID, newChar); return(ECharacterCreationResult.Success); }