public override bool SayReceive(GameLiving source, string str) { if (!base.SayReceive(source, str)) { return(false); } string[] split = str.Split(' '); switch (split[0]) { case "create": ushort id = 286; if (split.Length > 1) { try { id = ushort.Parse(split[1]); } catch { } } m_instance = (Instance)WorldMgr.CreateInstance(id, typeof(Instance)); if (m_instance != null) { Say("Success, instance created."); } else { Say("Instance creation found errors."); } // Try and load a template from the db... if (split.Length > 2) { string load = split[2]; Say("Trying to load instance '" + load + "' template from DB"); m_instance.LoadFromDatabase(load); } break; case "test": if (m_instance == null) { Say("Instance is currently null."); } else { int x = 32361; int y = 31744; int z = 16003; ushort heading = 1075; if (m_instance.InstanceEntranceLocation != null) { x = m_instance.InstanceEntranceLocation.X; y = m_instance.InstanceEntranceLocation.Y; z = m_instance.InstanceEntranceLocation.Z; heading = m_instance.InstanceEntranceLocation.Heading; } // save current position so player can use /instance exit GameLocation saveLocation = new GameLocation(source.Name + "_exit", source.CurrentRegionID, source.X, source.Y, source.Z); source.TempProperties.setProperty(saveLocation.Name, saveLocation); Say("Instance ID " + m_instance.ID + ", Skin: " + m_instance.Skin + ", with " + m_instance.Zones.Count + " zones inside the region."); if (!source.MoveTo(m_instance.ID, x, y, z, heading)) { Say("Source could not be moved to instance entrance; MoveTo returned false. Now trying to move to current location inside the instance."); if (!source.MoveTo(m_instance.ID, source.X, source.Y, source.Z, source.Heading)) { Say("Sorry, that failed as well."); } } } break; } return(true); }
/// <summary> /// Decides whether player can jump to the target point. /// All messages with reasons must be sent here. /// Can change destination too. /// </summary> /// <param name="targetPoint">The jump destination</param> /// <param name="player">The jumping player</param> /// <returns>True if allowed</returns> public bool IsAllowedToJump(ZonePoint targetPoint, GamePlayer player) { //Handles zoning INTO an instance. GameLocation loc = null; AdventureWingInstance previousInstance = null; // Do we have a group ? if (player.Group != null) { //Check if there is an instance dedicated to this group foreach (Region region in WorldMgr.GetAllRegions()) { if (region is AdventureWingInstance && ((AdventureWingInstance)region).Group != null && ((AdventureWingInstance)region).Group == player.Group) { // Our group has an instance ! previousInstance = (AdventureWingInstance)region; break; } else if (region is AdventureWingInstance && ((AdventureWingInstance)region).Player != null && ((AdventureWingInstance)region).Player == player.Group.Leader) { // Our leader has an instance ! previousInstance = (AdventureWingInstance)region; previousInstance.Group = player.Group; break; } } } else { // I am solo ! //Check if there is an instance dedicated to me foreach (Region region in WorldMgr.GetAllRegions()) { if (region is AdventureWingInstance && ((AdventureWingInstance)region).Player != null && ((AdventureWingInstance)region).Player == player) { // I have an Instance ! previousInstance = (AdventureWingInstance)region; previousInstance.Group = player.Group; break; } } } if (previousInstance != null) { // We should check if we can go in ! if (previousInstance.Skin != targetPoint.TargetRegion) { //we're trying to enter in an other instance and we still have one ! //check if previous one is empty if (previousInstance.NumPlayers > 0) { //We can't jump ! player.Out.SendMessage("You have another instance (" + previousInstance.Description + ") running with people in it !", eChatType.CT_System, eChatLoc.CL_SystemWindow); return(false); } else { log.Warn("Player : " + player.Name + " requested new Instance, destroying instance " + previousInstance.Description + ", ID: " + previousInstance.ID + ", type=" + previousInstance.GetType().ToString() + "."); WorldMgr.RemoveInstance(previousInstance); previousInstance = null; } } } if (previousInstance == null) { // I have no instance to go to, create one ! previousInstance = (AdventureWingInstance)WorldMgr.CreateInstance(targetPoint.TargetRegion, typeof(AdventureWingInstance)); if (targetPoint.SourceRegion != 0 && targetPoint.SourceRegion == player.CurrentRegionID) { //source loc seems legit... previousInstance.SourceEntrance = new GameLocation("source", targetPoint.SourceRegion, targetPoint.SourceX, targetPoint.SourceY, targetPoint.SourceZ); } if (player.Group != null) { previousInstance.Group = player.Group; previousInstance.Player = player.Group.Leader; } else { previousInstance.Group = null; previousInstance.Player = player; } //get region data long mobs = 0; long merchants = 0; long items = 0; long bindpoints = 0; previousInstance.LoadFromDatabase(previousInstance.RegionData.Mobs, ref mobs, ref merchants, ref items, ref bindpoints); if (log.IsInfoEnabled) { log.Info("Total Mobs: " + mobs); log.Info("Total Merchants: " + merchants); log.Info("Total Items: " + items); } //Attach Loot Generator LootMgr.RegisterLootGenerator(new LootGeneratorAurulite(), null, null, null, previousInstance.ID); // Player created new instance // Destroy all other instance that should be... List <Region> to_delete = new List <Region>(); foreach (Region region in WorldMgr.GetAllRegions()) { if (region is AdventureWingInstance && (AdventureWingInstance)region != previousInstance) { AdventureWingInstance to_clean = (AdventureWingInstance)region; // Won't clean up populated Instance if (to_clean.NumPlayers == 0) { if (to_clean.Group != null && player.Group != null && to_clean.Group == player.Group) { // Got another instance for the same group... Destroy it ! to_delete.Add(to_clean); } else if (to_clean.Player != null && (to_clean.Player == player || (player.Group != null && player.Group.Leader == to_clean.Player))) { // Got another instance for the same player... Destroy it ! to_delete.Add(to_clean); } else if (to_clean.Group == null && to_clean.Player == null) { //nobody owns this instance anymore to_delete.Add(to_clean); } } } } //enumerate to_delete foreach (Region region in to_delete) { log.Warn("Player : " + player.Name + " has provoked an instance cleanup - " + region.Description + ", ID: " + region.ID + ", type=" + region.GetType().ToString() + "."); WorldMgr.RemoveInstance((BaseInstance)region); } } //get loc of instance if (previousInstance != null) { loc = new GameLocation(previousInstance.Description + " (instance)", previousInstance.ID, targetPoint.TargetX, targetPoint.TargetY, targetPoint.TargetZ, targetPoint.TargetHeading); } if (loc != null) { // Move Player, changing target destination is failing !! player.MoveTo(loc); return(false); } player.Out.SendMessage("Something went Wrong when creating Instance !", eChatType.CT_System, eChatLoc.CL_SystemWindow); return(false); }
public void OnCommand(GameClient client, string[] args) { if (client.Player == null) { return; } GamePlayer player = client.Player; string key = GetInstanceKey(player); if (args.Length < 2) { if (key != "") { SendMessage(client, "Current instance key is " + key); } DisplaySyntax(client); return; } if (key == "" && args[1] != "key") { SendMessage(client, "You must first assign an instance to work with using /instance key <ID>."); return; } switch (args[1].ToLower()) { #region SetInstanceID case "key": string newKey = string.Join(" ", args, 2, args.Length - 2); client.Player.TempProperties.setProperty(INSTANCE_KEY, newKey); SendMessage(client, "Instance key set to " + newKey); break; #endregion #region Create Entry case "entry": { try { if (args.Length < 3) { DisplaySyntax(client); return; } //Create the database entry... DBInstanceXElement element = new DBInstanceXElement(); element.Heading = client.Player.Heading; element.X = (int)client.Player.Position.X; element.Y = (int)client.Player.Position.Y; element.Z = (int)client.Player.Position.Z; element.InstanceID = key; element.ClassType = args[2]; int npctemplate = 0; try { npctemplate = int.Parse(args[3]); } catch { } element.NPCTemplate = npctemplate.ToString(); if (npctemplate > 0) { // reload all templates to grab any new ones NpcTemplateMgr.Reload(); } //Save the element to database! GameServer.Database.AddObject(element); GameServer.Database.SaveObject(element); //Dinberg: place a marker at this spot! string theType = args[2]; SendMessage(client, "Created an element here! Use your memory for now, I sure as hell dont have anything else to show you where it is ^^"); //Only create ones that have namespaces (signified by '.') if (theType.Contains(".")) { SendMessage(client, "theType suspected to be a ClassType - attempting to invoke a marker of this class."); GameObject obj = null; //Now we have the classtype to create, create it thus! //This is required to ensure we check scripts for the space aswell, such as quests! foreach (Assembly asm in ScriptMgr.GameServerScripts) { obj = (GameObject)(asm.CreateInstance(theType, false)); if (obj != null) { break; } } if (args.Length == 4) { int templateID = 0; try { templateID = int.Parse(args[3]); } catch { } //If its an npc, load from the npc template about now. //By default, we ignore npctemplate if its set to 0. if ((GameNPC)obj != null && templateID != 0) { INpcTemplate npcTemplate = NpcTemplateMgr.GetTemplate(templateID); //we only want to load the template if one actually exists, or there could be trouble! if (npcTemplate != null) { ((GameNPC)obj).LoadTemplate(npcTemplate); } } } //Add to world... obj.Name = element.ObjectId.Substring(0, 18); obj.GuildName = element.ObjectId.Substring(18); obj.Position = new Vector3(element.X, element.Y, element.Z); obj.Heading = element.Heading; obj.CurrentRegion = client.Player.CurrentRegion; // now make sure model is visible if (obj is GameNPC && obj.Model == 0) { obj.Model = 408; // red ball } else if (obj is GameStaticItem && obj.Model == 0) { obj.Model = 100; // bag } if (!obj.AddToWorld()) { client.Out.SendMessage("Error: Object not added to world correctly!", eChatType.CT_Important, eChatLoc.CL_SystemWindow); } else { client.Out.SendMessage("Object added!", eChatType.CT_Say, eChatLoc.CL_SystemWindow); } } } catch (Exception ex) { client.Out.SendMessage("An Exception has occurred when trying to add object, review server error logs! Exception: " + ex.Message, eChatType.CT_Important, eChatLoc.CL_SystemWindow); log.Error("Instance Entry Error", ex); } } break; #endregion #region remove case "remove": { GameObject obj = client.Player.TargetObject; if (obj == null) { return; } string ObjectId = obj.Name + obj.GuildName; DataObject o = GameServer.Database.FindObjectByKey <DBInstanceXElement>(ObjectId); if (o == null) { client.Out.SendMessage("Could not find the entry in the database! <key=" + ObjectId + ">", eChatType.CT_Say, eChatLoc.CL_SystemWindow); return; } GameServer.Database.DeleteObject(o); client.Out.SendMessage("Object removed!", eChatType.CT_Say, eChatLoc.CL_SystemWindow); //Remove object... obj.RemoveFromWorld(); obj.Delete(); obj.DeleteFromDatabase(); } break; #endregion #region create case "create": { if (player.CurrentRegion.IsInstance) { SendMessage(client, "You are already in an instance, use /instance exit to get out."); return; } try { if (args.Length < 3) { throw new Exception("You need to provide a skin id. A skin is the ID of the region you want this instance to look like."); } Instance newInstance = player.TempProperties.getProperty <object>(key, null) as Instance; if (newInstance != null) { throw new Exception("You already have an instance '" + key + "' created, please close it before creating another."); } ushort skinID = Convert.ToUInt16(args[2]); newInstance = (Instance)WorldMgr.CreateInstance(skinID, typeof(Instance)); if (newInstance == null) { SendMessage(client, "Instance creation failed."); } else { SendMessage(client, "Instance created, now loading elements for instance '" + key + "' from the DB."); newInstance.LoadFromDatabase(key); player.TempProperties.setProperty(key, newInstance); } } catch (Exception ex) { SendMessage(client, ex.Message); return; } } break; #endregion #region close case "close": { Instance newInstance = player.TempProperties.getProperty <object>(key, null) as Instance; if (newInstance == null) { SendMessage(client, "Can't find an instance to delete."); } else { player.TempProperties.removeProperty(key); newInstance.DestroyWhenEmpty = true; if (newInstance.NumPlayers == 0) { SendMessage(client, "Instance closed."); } else { SendMessage(client, "Instance will close once all players leave."); } } } break; #endregion #region test case "test": { if (player.CurrentRegion.IsInstance) { SendMessage(client, "You are already in an instance, use /instance exit to get out."); return; } Instance newInstance = player.TempProperties.getProperty <object>(key, null) as Instance; if (newInstance == null) { SendMessage(client, "Can't find an instance to test, you will need to create one first."); } else { // start with some generic coordinates that seem to work well in many instance zones var pos = new Vector3(32361, 31744, 16003); ushort heading = 1075; // If you're having trouble zoning into an instance then try adding an entrance element so it can be used here if (newInstance.InstanceEntranceLocation != null) { pos = newInstance.InstanceEntranceLocation.Position; heading = newInstance.InstanceEntranceLocation.Heading; } // save current position for use with /instance exit GameLocation saveLocation = new GameLocation(player.Name + "_exit", player.CurrentRegionID, player.Position, player.Heading); player.TempProperties.setProperty(saveLocation.Name, saveLocation); bool success = true; if (!player.MoveTo(newInstance.ID, pos, heading)) { SendMessage(client, "MoveTo to entrance failed, now trying to move to current location inside the instance."); if (!player.MoveTo(newInstance.ID, player.Position, player.Heading)) { SendMessage(client, "That failed as well. Either add an entrance to this instance or move in the world to a corresponding instance location."); success = false; } } if (success) { SendMessage(client, "Welcome to Instance ID " + newInstance.ID + ", Skin: " + newInstance.Skin + ", with " + newInstance.Zones.Count + " zones and " + newInstance.Objects.Length + " objects inside the region!"); SendMessage(client, "Use '/instance exit' to leave if you get stuck."); } } } break; #endregion #region exit case "exit": { if (!player.CurrentRegion.IsInstance) { SendMessage(client, "You need to be in an instance to use this command."); return; } GameLocation saveLocation = player.TempProperties.getProperty <object>(player.Name + "_exit", null) as GameLocation; if (saveLocation == null) { ushort sourceRegion = (player.CurrentRegion as BaseInstance).Skin; if (!player.MoveTo(sourceRegion, player.Position, player.Heading)) { player.MoveToBind(); } } else { player.MoveTo(saveLocation.RegionID, saveLocation.Position, saveLocation.Heading); } } break; #endregion } return; }
public TaskDungeonMission(object owner, eDungeonType dungeonType = eDungeonType.Ranged) : base(owner) { log.Info("INFO: Successfully entered TaskDungeonMission!"); GamePlayer player = owner as GamePlayer; if (owner is Group) { player = (owner as Group).Leader; //Assign the mission to the group. (owner as Group).Mission = this; } if (player == null) { return; } //check level range and get region id from it ushort rid = GetRegionFromLevel(player.Level, player.Realm, dungeonType); TaskDungeonInstance instance = (TaskDungeonInstance)WorldMgr.CreateInstance(rid, typeof(TaskDungeonInstance)); m_taskRegion = instance; instance.Mission = this; //Dinberg: I've removed instance level, and have commented this out so it compiles. //I dont have time to implement the rest right now, //m_taskRegion.InstanceLevel = GetLevelFromPlayer(player); //Infact, this clearly isnt in use. I'll fix it to use the new instance system, and then itll work. //Do that later this week ^^. //Lets load the region from the InstanceXElementDB! //First we get the instance keyname. string keyname = "TaskDungeon" + rid + ".1"; //TODO; variations, eg .2, .3 etc. instance.LoadFromDatabase(keyname); //Now, search for the boss and possible targets in the instance! foreach (GameNPC npc in instance.Objects) { if (npc == null) { continue; } if (npc.Name.ToLower() != npc.Name) { if (m_bossName == "") { m_bossName = npc.Name; //Some instances have multiple bosses, eg Gregorian - why break? } else if (Util.Chance(50)) { m_bossName = npc.Name; } } //else what if we aren't looking at a boss, but a normal mob? else if (Util.Chance(20) || m_targetName == "") { m_targetName = npc.Name; } } int specificCount = 0; //Draw the mission type before we do anymore counting... if (Util.Chance(40) && m_bossName != "") { m_missionType = eTDMissionType.Boss; } else if (Util.Chance(20) && m_targetName != "") { m_missionType = eTDMissionType.Specific; } else { m_missionType = eTDMissionType.Clear; } //Now, count if we need to. if (m_missionType != eTDMissionType.Boss) { foreach (GameNPC entry in instance.Objects) { if (entry == null) { continue; } //Now, if we want all mobs, get all mobs... if (m_missionType == eTDMissionType.Clear) { specificCount++; } else if (entry.Name == m_targetName) { //only count target mobs for specific dungeons. specificCount++; } } } //append the count to the total! m_total = specificCount; //Set the mission description again if owner is group, otherwise //mission description is always "Clear" before entering the dungeon. if (owner is Group) { UpdateMission(); } m_mobIsAlive = new bool[m_total]; for (int i = 0; i < m_total; i++) { m_mobIsAlive[i] = true; } }