Added a way to reset a zone and reload the NPC list.

This commit is contained in:
Filip Maj 2016-01-24 03:10:17 -05:00
parent f1025f89d3
commit e043be5ca4
3 changed files with 122 additions and 12 deletions

View file

@ -186,6 +186,72 @@ namespace FFXIVClassic_Map_Server
Log.info(String.Format("Loaded {0} npc(s).", count));
}
public void LoadNPCs(uint zoneId)
{
int count = 0;
using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD)))
{
try
{
conn.Open();
string query = @"
SELECT
id,
name,
zoneId,
actorTemplateId,
positionX,
positionY,
positionZ,
rotation,
actorState,
animationId,
actorClassName,
eventConditions
FROM server_npclist
WHERE zoneId = @zoneId
";
MySqlCommand cmd = new MySqlCommand(query, conn);
cmd.Parameters.AddWithValue("@zoneId", zoneId);
using (MySqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
Npc npc = new Npc(reader.GetUInt32(0), reader.GetString(1), reader.GetUInt32(2), reader.GetUInt32(3), reader.GetFloat(4), reader.GetFloat(5), reader.GetFloat(6), reader.GetFloat(7), reader.GetUInt16(8), reader.GetUInt32(9), reader.GetString(10));
if (!reader.IsDBNull(11))
{
string eventConditions = reader.GetString(11);
npc.loadEventConditions(eventConditions);
}
if (!zoneList.ContainsKey(npc.zoneId))
continue;
Zone zone = zoneList[npc.zoneId];
if (zone == null)
continue;
npc.zone = zone;
zone.addActorToZone(npc);
count++;
}
}
}
catch (MySqlException e)
{ Console.WriteLine(e); }
finally
{
conn.Dispose();
}
}
Log.info(String.Format("Loaded {0} npc(s).", count));
}
//Moves the actor to the new zone if exists. No packets are sent nor position changed.
public void DoSeamlessZoneChange(Player player, uint destinationZoneId)
{
@ -273,6 +339,17 @@ namespace FFXIVClassic_Map_Server
player.sendZoneInPackets(this, 0x1);
}
public void reloadZone(uint zoneId)
{
if (!zoneList.ContainsKey(zoneId))
return;
Zone zone = zoneList[zoneId];
zone.clear();
LoadNPCs(zone.actorId);
}
public Player GetPCInWorld(string name)
{
foreach (Zone zone in zoneList.Values)