mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-07 13:45:42 +12:00
add npc wandering to db, and add %GOTO NPC
This commit is contained in:
parent
e32dabb1b4
commit
bdebe4d84a
4 changed files with 282 additions and 36 deletions
|
@ -258,6 +258,7 @@ namespace HISP.Game.Chat
|
|||
{
|
||||
user.Teleport(waypnt.PosX, waypnt.PosY);
|
||||
teleported = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!teleported)
|
||||
|
@ -268,7 +269,33 @@ namespace HISP.Game.Chat
|
|||
return false;
|
||||
}
|
||||
}
|
||||
if(args[0].Contains(","))
|
||||
else if(args[0] == "NPC")
|
||||
{
|
||||
if (args.Length < 2)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
string npcName = string.Join(" ", args, 1, args.Length - 1);
|
||||
bool teleported = false;
|
||||
foreach (Npc.NpcEntry npc in Npc.NpcList)
|
||||
{
|
||||
if (npc.Name.ToLower().StartsWith(npcName.ToLower()))
|
||||
{
|
||||
user.Teleport(npc.X, npc.Y);
|
||||
teleported = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!teleported)
|
||||
return false;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if(args[0].Contains(","))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -282,6 +309,10 @@ namespace HISP.Game.Chat
|
|||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -25,14 +25,75 @@ namespace HISP.Game
|
|||
}
|
||||
public class NpcEntry
|
||||
{
|
||||
public int Id;
|
||||
public NpcEntry(int npcId, int posX, int posY, bool npcMoves, int udlrStartX=0, int udlrStartY=0)
|
||||
{
|
||||
id = npcId;
|
||||
x = posX;
|
||||
y = posY;
|
||||
Moves = npcMoves;
|
||||
|
||||
UDLRStartX = udlrStartX;
|
||||
UDLRStartY = udlrStartY;
|
||||
|
||||
if(Moves)
|
||||
{
|
||||
if(Database.HasNpcPos(id))
|
||||
{
|
||||
udlrScriptPos = Database.GetNpcUdlrPointer(npcId);
|
||||
x = Database.GetNpcPosX(npcId);
|
||||
y = Database.GetNpcPosY(npcId);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(udlrStartX != 0 && udlrStartY != 0)
|
||||
{
|
||||
x = udlrStartX;
|
||||
y = udlrStartY;
|
||||
}
|
||||
udlrScriptPos = 0;
|
||||
Database.AddNpcPos(npcId, x, Y, udlrScriptPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
private int id;
|
||||
public string Name;
|
||||
public string AdminDescription;
|
||||
public string ShortDescription;
|
||||
public string LongDescription;
|
||||
public bool Moves;
|
||||
public int X;
|
||||
public int Y;
|
||||
private int x;
|
||||
private int y;
|
||||
public int Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return id;
|
||||
}
|
||||
}
|
||||
public int X
|
||||
{
|
||||
get
|
||||
{
|
||||
return x;
|
||||
}
|
||||
set
|
||||
{
|
||||
Database.SetNpcX(id, value);
|
||||
x = value;
|
||||
}
|
||||
}
|
||||
public int Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return y;
|
||||
}
|
||||
set
|
||||
{
|
||||
Database.SetNpcY(id, value);
|
||||
y = value;
|
||||
}
|
||||
}
|
||||
public string StayOn;
|
||||
public int RequiresQuestIdCompleted;
|
||||
public int RequiresQuestIdNotCompleted;
|
||||
|
@ -45,6 +106,18 @@ namespace HISP.Game
|
|||
|
||||
private int udlrScriptPos = 0;
|
||||
|
||||
public int UdlrScriptPos
|
||||
{
|
||||
get
|
||||
{
|
||||
return udlrScriptPos;
|
||||
}
|
||||
set
|
||||
{
|
||||
Database.SetNpcUdlrPointer(Id, value);
|
||||
udlrScriptPos = value;
|
||||
}
|
||||
}
|
||||
private bool canNpcBeHere(int x, int y)
|
||||
{
|
||||
// Horses cannot be in towns.
|
||||
|
@ -101,33 +174,30 @@ namespace HISP.Game
|
|||
}
|
||||
else // Is Scripted.
|
||||
{
|
||||
if (GameServer.GetUsersAt(this.X, this.Y, true, true).Length > 0)
|
||||
return;
|
||||
|
||||
X = UDLRStartX;
|
||||
Y = UDLRStartY;
|
||||
for(int i = 0; i < udlrScriptPos; i++)
|
||||
if (UdlrScriptPos + 1 >= UDLRScript.Length)
|
||||
UdlrScriptPos = 0;
|
||||
else
|
||||
UdlrScriptPos++;
|
||||
|
||||
switch (UDLRScript.ToLower()[UdlrScriptPos])
|
||||
{
|
||||
|
||||
switch (UDLRScript.ToLower()[i])
|
||||
{
|
||||
case 'u':
|
||||
Y++;
|
||||
break;
|
||||
case 'd':
|
||||
Y--;
|
||||
break;
|
||||
case 'l':
|
||||
X--;
|
||||
break;
|
||||
case 'r':
|
||||
X++;
|
||||
break;
|
||||
}
|
||||
case 'u':
|
||||
Y++;
|
||||
break;
|
||||
case 'd':
|
||||
Y--;
|
||||
break;
|
||||
case 'l':
|
||||
X--;
|
||||
break;
|
||||
case 'r':
|
||||
X++;
|
||||
break;
|
||||
}
|
||||
|
||||
udlrScriptPos++;
|
||||
|
||||
if (udlrScriptPos > UDLRScript.Length)
|
||||
udlrScriptPos = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ namespace HISP.Server
|
|||
string AbuseReorts = "CREATE TABLE AbuseReports(ReportCreator TEXT(1028), Reporting TEXT(1028), ReportReason TEXT(1028))";
|
||||
string Leaderboards = "CREATE TABLE Leaderboards(playerId INT, minigame TEXT(128), wins INT, looses INT, timesplayed INT, score INT, type TEXT(128))";
|
||||
string NpcStartPoint = "CREATE TABLE NpcStartPoint(playerId INT, npcId INT, chatpointId INT)";
|
||||
string NpcPos = "CREATE TABLE NpcPos(npcId INT, X INT, Y INT, UdlrPointer INT)";
|
||||
string PoetryRooms = "CREATE TABLE PoetryRooms(poetId INT, X INT, Y INT, roomId INT)";
|
||||
string SavedDrawings = "CREATE TABLE SavedDrawings(playerId INT, Drawing1 TEXT(65535), Drawing2 TEXT(65535), Drawing3 TEXT(65535))";
|
||||
string DrawingRooms = "CREATE TABLE DrawingRooms(roomId INT, Drawing TEXT(65535))";
|
||||
|
@ -49,6 +50,19 @@ namespace HISP.Server
|
|||
string RiddlesComplete = "CREATE TABLE RiddlesComplete(playerId INT, riddleId INT, solved TEXT(1028))";
|
||||
string DeleteOnlineUsers = "DELETE FROM OnlineUsers";
|
||||
|
||||
try
|
||||
{
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
sqlCommand.CommandText = NpcPos;
|
||||
sqlCommand.ExecuteNonQuery();
|
||||
sqlCommand.Dispose();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.WarnPrint(e.Message);
|
||||
};
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
|
@ -3520,6 +3534,128 @@ namespace HISP.Server
|
|||
return total >= 1;
|
||||
}
|
||||
}
|
||||
public static bool HasNpcPos(int npcId)
|
||||
{
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
db.Open();
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
|
||||
sqlCommand.CommandText = "SELECT COUNT(1) FROM NpcPos WHERE npcId=@npcId";
|
||||
sqlCommand.Parameters.AddWithValue("@npcId", npcId);
|
||||
sqlCommand.Prepare();
|
||||
int total = Convert.ToInt32(sqlCommand.ExecuteScalar());
|
||||
sqlCommand.Dispose();
|
||||
return total >= 1;
|
||||
}
|
||||
}
|
||||
public static void SetNpcY(int npcId, int x)
|
||||
{
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
db.Open();
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
|
||||
sqlCommand.CommandText = "UPDATE NpcPos SET Y=@yPos WHERE npcId=@npcId";
|
||||
sqlCommand.Parameters.AddWithValue("@yPos", x);
|
||||
sqlCommand.Parameters.AddWithValue("@npcId", npcId);
|
||||
sqlCommand.Prepare();
|
||||
sqlCommand.ExecuteNonQuery();
|
||||
sqlCommand.Dispose();
|
||||
}
|
||||
}
|
||||
public static void SetNpcX(int npcId, int x)
|
||||
{
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
db.Open();
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
|
||||
sqlCommand.CommandText = "UPDATE NpcPos SET X=@xPos WHERE npcId=@npcId";
|
||||
sqlCommand.Parameters.AddWithValue("@xPos", x);
|
||||
sqlCommand.Parameters.AddWithValue("@npcId", npcId);
|
||||
sqlCommand.Prepare();
|
||||
sqlCommand.ExecuteNonQuery();
|
||||
sqlCommand.Dispose();
|
||||
}
|
||||
}
|
||||
public static void SetNpcUdlrPointer(int npcId, int udlr)
|
||||
{
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
db.Open();
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
|
||||
sqlCommand.CommandText = "UPDATE NpcPos SET UdlrPointer=@udlr WHERE npcId=@npcId";
|
||||
sqlCommand.Parameters.AddWithValue("@udlr", udlr);
|
||||
sqlCommand.Parameters.AddWithValue("@npcId", npcId);
|
||||
sqlCommand.Prepare();
|
||||
sqlCommand.ExecuteNonQuery();
|
||||
sqlCommand.Dispose();
|
||||
}
|
||||
}
|
||||
public static int GetNpcUdlrPointer(int npcId)
|
||||
{
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
db.Open();
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
|
||||
sqlCommand.CommandText = "SELECT UdlrPointer FROM NpcPos WHERE npcId=@npcId";
|
||||
sqlCommand.Parameters.AddWithValue("@npcId", npcId);
|
||||
sqlCommand.Prepare();
|
||||
int udlrPointer = Convert.ToInt32(sqlCommand.ExecuteScalar());
|
||||
sqlCommand.Dispose();
|
||||
return udlrPointer;
|
||||
}
|
||||
}
|
||||
public static int GetNpcPosY(int npcId)
|
||||
{
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
db.Open();
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
|
||||
sqlCommand.CommandText = "SELECT y FROM NpcPos WHERE npcId=@npcId";
|
||||
sqlCommand.Parameters.AddWithValue("@npcId", npcId);
|
||||
sqlCommand.Prepare();
|
||||
int y = Convert.ToInt32(sqlCommand.ExecuteScalar());
|
||||
sqlCommand.Dispose();
|
||||
return y;
|
||||
}
|
||||
}
|
||||
public static int GetNpcPosX(int npcId)
|
||||
{
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
db.Open();
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
|
||||
sqlCommand.CommandText = "SELECT X FROM NpcPos WHERE npcId=@npcId";
|
||||
sqlCommand.Parameters.AddWithValue("@npcId", npcId);
|
||||
sqlCommand.Prepare();
|
||||
int x = Convert.ToInt32(sqlCommand.ExecuteScalar());
|
||||
sqlCommand.Dispose();
|
||||
return x;
|
||||
}
|
||||
}
|
||||
public static void AddNpcPos(int npcId, int X, int Y, int udlrPointer)
|
||||
{
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
db.Open();
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
|
||||
sqlCommand.CommandText = "INSERT INTO NpcPos VALUES(@npcId, @xPos, @yPos, @udlr)";
|
||||
sqlCommand.Parameters.AddWithValue("@npcId", npcId);
|
||||
sqlCommand.Parameters.AddWithValue("@xPos", X);
|
||||
sqlCommand.Parameters.AddWithValue("@yPos", Y);
|
||||
sqlCommand.Parameters.AddWithValue("@udlr", udlrPointer);
|
||||
sqlCommand.Prepare();
|
||||
sqlCommand.ExecuteNonQuery();
|
||||
sqlCommand.Dispose();
|
||||
}
|
||||
}
|
||||
public static void AddNpcStartPoint(int playerId, int npcId, int startChatpoint)
|
||||
{
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
|
|
|
@ -244,15 +244,27 @@ namespace HISP.Server
|
|||
int totalNpcs = gameData.npc_list.Count;
|
||||
for(int i = 0; i < totalNpcs; i++)
|
||||
{
|
||||
Npc.NpcEntry npcEntry = new Npc.NpcEntry();
|
||||
npcEntry.Id = gameData.npc_list[i].id;
|
||||
int id = gameData.npc_list[i].id;
|
||||
int x = gameData.npc_list[i].x;
|
||||
int y = gameData.npc_list[i].y;
|
||||
bool moves = gameData.npc_list[i].moves;
|
||||
|
||||
int udlrStartX = 0;
|
||||
int udlrStartY = 0;
|
||||
|
||||
if (gameData.npc_list[i].udlr_start_x != null)
|
||||
udlrStartX = gameData.npc_list[i].udlr_start_x;
|
||||
if (gameData.npc_list[i].udlr_start_y != null)
|
||||
udlrStartY = gameData.npc_list[i].udlr_start_y;
|
||||
|
||||
Npc.NpcEntry npcEntry = new Npc.NpcEntry(id, x, y, moves, udlrStartX, udlrStartY);
|
||||
|
||||
npcEntry.Name = gameData.npc_list[i].name;
|
||||
npcEntry.AdminDescription = gameData.npc_list[i].admin_description;
|
||||
npcEntry.ShortDescription = gameData.npc_list[i].short_description;
|
||||
npcEntry.LongDescription = gameData.npc_list[i].long_description;
|
||||
npcEntry.Moves = gameData.npc_list[i].moves;
|
||||
npcEntry.X = gameData.npc_list[i].x;
|
||||
npcEntry.Y = gameData.npc_list[i].y;
|
||||
|
||||
|
||||
if (gameData.npc_list[i].stay_on != null)
|
||||
npcEntry.StayOn = gameData.npc_list[i].stay_on;
|
||||
if (gameData.npc_list[i].requires_questid_completed != null)
|
||||
|
@ -261,10 +273,7 @@ namespace HISP.Server
|
|||
npcEntry.RequiresQuestIdNotCompleted = gameData.npc_list[i].requires_questid_not_completed;
|
||||
if (gameData.npc_list[i].udlr_script != null)
|
||||
npcEntry.UDLRScript = gameData.npc_list[i].udlr_script;
|
||||
if (gameData.npc_list[i].udlr_start_x != null)
|
||||
npcEntry.UDLRStartX = gameData.npc_list[i].udlr_start_x;
|
||||
if (gameData.npc_list[i].udlr_start_y != null)
|
||||
npcEntry.UDLRStartY = gameData.npc_list[i].udlr_start_y;
|
||||
|
||||
npcEntry.AdminOnly = gameData.npc_list[i].admin_only;
|
||||
npcEntry.LibarySearchable = gameData.npc_list[i].libary_searchable;
|
||||
npcEntry.IconId = gameData.npc_list[i].icon_id;
|
||||
|
|
Loading…
Add table
Reference in a new issue