/// <summary> /// Teleport the player to the designated coordinates. /// </summary> /// <param name="player"></param> /// <param name="destination"></param> protected void OnTeleport(GamePlayer player, Teleport destination) { if (player.InCombat == false && GameRelic.IsPlayerCarryingRelic(player) == false) { player.LeaveHouse(); GameLocation currentLocation = new GameLocation("TeleportStart", player.CurrentRegionID, player.X, player.Y, player.Z); player.MoveTo((ushort)destination.RegionID, destination.X, destination.Y, destination.Z, (ushort)destination.Heading); GameServer.ServerRules.OnPlayerTeleport(player, currentLocation, destination); } }
/// <summary> /// Loads elements relating to the given instance keyname from the database and populates the instance. /// </summary> /// <param name="instanceName"></param> public virtual void LoadFromDatabase(string instanceName) { var objects = GameServer.Database.SelectObjects<DBInstanceXElement>("`InstanceID` = '" + instanceName + "'"); if (objects.Count == 0) return; int count = 0; //Now we have a list of DBElements, lets create the various entries //associated with them and populate the instance. foreach (DBInstanceXElement entry in objects) { if (entry == null) continue; //an odd error, but experience knows best. GameObject obj = null; string theType = "DOL.GS.GameNPC"; //Switch the classtype to see what we are making. switch (entry.ClassType) { case "entrance": { //create the entrance, then move to the next. m_entranceLocation = new GameLocation(instanceName + "entranceRegion" + ID, ID, entry.X, entry.Y, entry.Z, entry.Heading); //move to the next entry, nothing more to do here... continue; } case "region": continue; //This is used to save the regionID as NPCTemplate. case "DOL.GS.GameNPC": break; default: theType = entry.ClassType; break; } //Now we have the classtype to create, create it thus! ArrayList asms = new ArrayList(); asms.Add(typeof(GameServer).Assembly); asms.AddRange(ScriptMgr.Scripts); //This is required to ensure we check scripts for the space aswell, such as quests! foreach (Assembly asm in asms) { obj = (GameObject)(asm.CreateInstance(theType, false)); if (obj != null) break; } if (obj == null) continue; //We now have an object that isnt null. Lets place it at the location, in this region. obj.X = entry.X; obj.Y = entry.Y; obj.Z = entry.Z; obj.Heading = entry.Heading; obj.CurrentRegionID = ID; //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 && !Util.IsEmpty(entry.NPCTemplate, true)) { var listTemplate = entry.NPCTemplate.SplitCSV(true); int template = 0; if (int.TryParse(listTemplate[Util.Random(listTemplate.Count-1)], out template) && template > 0) { INpcTemplate npcTemplate = NpcTemplateMgr.GetTemplate(template); //we only want to load the template if one actually exists, or there could be trouble! if (npcTemplate != null) { ((GameNPC)obj).LoadTemplate(npcTemplate); } } } //Finally, add it to the world! obj.AddToWorld(); //Keep track of numbers. count++; } log.Info("Successfully loaded a db entry to " + Description + " - Region ID " + ID + ". Loaded Entities: " + count); }
/// <summary> /// Move this object to a GameLocation /// </summary> /// <param name="loc"></param> /// <returns></returns> public virtual bool MoveTo(GameLocation loc) { return MoveTo(loc.RegionID, loc.X, loc.Y, loc.Z, loc.Heading); }
/// <summary> /// Should be called whenever a player teleports to a new location /// </summary> /// <param name="player"></param> /// <param name="source"></param> /// <param name="destination"></param> public override void OnPlayerTeleport(GamePlayer player, GameLocation source, Teleport destination) { // Since region change already starts an immunity timer we only want to do this if a player // is teleporting within the same region if (source.RegionID == destination.RegionID) { StartImmunityTimer(player, ServerProperties.Properties.TIMER_PVP_TELEPORT * 1000); } }
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; }
public static int GetDistance( int r1, int x1, int y1, int z1, int r2, int x2, int y2, int z2 ) { GameLocation loc1 = new GameLocation( "loc1", (ushort)r1, x1, y1, z1 ); GameLocation loc2 = new GameLocation( "loc2", (ushort)r2, x2, y2, z2 ); return loc1.GetDistance( loc2 ); }