added things

added a crafting tool merchant,
added a training hall (not quite working yet)
fixed crafting issues,
exchanged the small cave area
This commit is contained in:
2024-09-01 14:11:15 -04:00
parent 65af23f08d
commit 7030eb2235
335 changed files with 55956 additions and 3946 deletions

View File

@@ -1,7 +1,7 @@
// Name : Avlis Persistence System include
// Purpose : Various APS/NWNX2 related functions
// Authors : Ingmar Stieger, Adam Colon, Josh Simon
// Modified : December 21, 2003
// Modified : January 1st, 2005
// This file is licensed under the terms of the
// GNU GENERAL PUBLIC LICENSE (GPL) Version 2
@@ -10,13 +10,12 @@
/* Return codes */
/************************************/
int SQL_ERROR = 0;
int SQL_SUCCESS = 1;
const int SQL_ERROR = 0;
const int SQL_SUCCESS = 1;
/************************************/
/* Function prototypes */
/************************************/
sqlquery last_sql_query;
// Setup placeholders for ODBC requests and responses
void SQLInit();
@@ -62,33 +61,45 @@ vector APSStringToVector(string sVector);
// Optional parameters:
// iExpiration: Number of days the persistent variable should be kept in database (default: 0=forever)
// sTable: Name of the table where variable should be stored (default: pwdata)
void SetPersistentString(object oObject, string sVarName, string sValue, int iExpiration = 0, string sTable = "pwdata");
void SetPersistentString(object oObject, string sVarName, string sValue, int iExpiration =
0, string sTable = "pwdata");
// Set oObject's persistent integer variable sVarName to iValue
// Optional parameters:
// iExpiration: Number of days the persistent variable should be kept in database (default: 0=forever)
// sTable: Name of the table where variable should be stored (default: pwdata)
void SetPersistentInt(object oObject, string sVarName, int iValue, int iExpiration = 0, string sTable = "pwdata");
void SetPersistentInt(object oObject, string sVarName, int iValue, int iExpiration =
0, string sTable = "pwdata");
// Set oObject's persistent float variable sVarName to fValue
// Optional parameters:
// iExpiration: Number of days the persistent variable should be kept in database (default: 0=forever)
// sTable: Name of the table where variable should be stored (default: pwdata)
void SetPersistentFloat(object oObject, string sVarName, float fValue, int iExpiration = 0, string sTable = "pwdata");
void SetPersistentFloat(object oObject, string sVarName, float fValue, int iExpiration =
0, string sTable = "pwdata");
// Set oObject's persistent location variable sVarName to lLocation
// Optional parameters:
// iExpiration: Number of days the persistent variable should be kept in database (default: 0=forever)
// sTable: Name of the table where variable should be stored (default: pwdata)
// This function converts location to a string for storage in the database.
void SetPersistentLocation(object oObject, string sVarName, location lLocation, int iExpiration = 0, string sTable = "pwdata");
void SetPersistentLocation(object oObject, string sVarName, location lLocation, int iExpiration =
0, string sTable = "pwdata");
// Set oObject's persistent vector variable sVarName to vVector
// Optional parameters:
// iExpiration: Number of days the persistent variable should be kept in database (default: 0=forever)
// sTable: Name of the table where variable should be stored (default: pwdata)
// This function converts vector to a string for storage in the database.
void SetPersistentVector(object oObject, string sVarName, vector vVector, int iExpiration = 0, string sTable = "pwdata");
void SetPersistentVector(object oObject, string sVarName, vector vVector, int iExpiration =
0, string sTable = "pwdata");
// Set oObject's persistent object with sVarName to sValue
// Optional parameters:
// iExpiration: Number of days the persistent variable should be kept in database (default: 0=forever)
// sTable: Name of the table where variable should be stored (default: pwobjdata)
void SetPersistentObject(object oObject, string sVarName, object oObject2, int iExpiration =
0, string sTable = "pwobjdata");
// Get oObject's persistent string variable sVarName
// Optional parameters:
@@ -120,6 +131,12 @@ location GetPersistentLocation(object oObject, string sVarname, string sTable =
// * Return value on error: 0
vector GetPersistentVector(object oObject, string sVarName, string sTable = "pwdata");
// Get oObject's persistent object sVarName
// Optional parameters:
// sTable: Name of the table where object is stored (default: pwobjdata)
// * Return value on error: 0
object GetPersistentObject(object oObject, string sVarName, object oOwner = OBJECT_INVALID, string sTable = "pwobjdata");
// Delete persistent variable sVarName stored on oObject
// Optional parameters:
// sTable: Name of the table where variable is stored (default: pwdata)
@@ -139,22 +156,40 @@ string SQLDecodeSpecialChars(string sString);
void SQLInit()
{
SQLExecDirect("CREATE TABLE IF NOT EXISTS pwdata(player varchar(64), tag varchar(64), name varchar(64), val text, expire int(11), last timestamp NOT NULL DEFAULT DEFAULT_TIMESTAMP, PRIMARY KEY (player,tag,name))");
int i;
// Placeholder for ODBC persistence
string sMemory;
for (i = 0; i < 8; i++) // reserve 8*128 bytes
sMemory +=
"................................................................................................................................";
SetLocalString(GetModule(), "NWNX!ODBC!SPACER", sMemory);
}
void SQLExecDirect(string sSQL)
{
sqlquery sql = SqlPrepareQueryCampaign("db",sSQL);
last_sql_query = sql;
if(GetStringLowerCase(GetStringLeft(sSQL,6)) != "select")
{
SqlStep(sql);
}
SetLocalString(GetModule(), "NWNX!ODBC!EXEC", sSQL);
}
int SQLFetch()
{
return SqlStep(last_sql_query);
string sRow;
object oModule = GetModule();
SetLocalString(oModule, "NWNX!ODBC!FETCH", GetLocalString(oModule, "NWNX!ODBC!SPACER"));
sRow = GetLocalString(oModule, "NWNX!ODBC!FETCH");
if (GetStringLength(sRow) > 0)
{
SetLocalString(oModule, "NWNX_ODBC_CurrentRow", sRow);
return SQL_SUCCESS;
}
else
{
SetLocalString(oModule, "NWNX_ODBC_CurrentRow", "");
return SQL_ERROR;
}
}
// deprecated. use SQLFetch().
@@ -171,7 +206,45 @@ int SQLNextRow()
string SQLGetData(int iCol)
{
return SqlGetString(last_sql_query,iCol-1);
int iPos;
string sResultSet = GetLocalString(GetModule(), "NWNX_ODBC_CurrentRow");
// find column in current row
int iCount = 0;
string sColValue = "";
iPos = FindSubString(sResultSet, "<22>");
if ((iPos == -1) && (iCol == 1))
{
// only one column, return value immediately
sColValue = sResultSet;
}
else if (iPos == -1)
{
// only one column but requested column > 1
sColValue = "";
}
else
{
// loop through columns until found
while (iCount != iCol)
{
iCount++;
if (iCount == iCol)
sColValue = GetStringLeft(sResultSet, iPos);
else
{
sResultSet = GetStringRight(sResultSet, GetStringLength(sResultSet) - iPos - 1);
iPos = FindSubString(sResultSet, "<22>");
}
// special case: last column in row
if (iPos == -1)
iPos = GetStringLength(sResultSet);
}
}
return sColValue;
}
// These functions deal with various data types. Ultimately, all information
@@ -291,7 +364,7 @@ void SetPersistentString(object oObject, string sVarName, string sValue, int iEx
"' AND tag='" + sTag + "' AND name='" + sVarName + "'";
SQLExecDirect(sSQL);
if (SQLFirstRow() == SQL_SUCCESS)
if (SQLFetch() == SQL_SUCCESS)
{
// row exists
sSQL = "UPDATE " + sTable + " SET val='" + sValue +
@@ -331,7 +404,7 @@ string GetPersistentString(object oObject, string sVarName, string sTable = "pwd
"' AND tag='" + sTag + "' AND name='" + sVarName + "'";
SQLExecDirect(sSQL);
if (SQLFirstRow() == SQL_SUCCESS)
if (SQLFetch() == SQL_SUCCESS)
return SQLDecodeSpecialChars(SQLGetData(1));
else
{
@@ -353,7 +426,30 @@ void SetPersistentInt(object oObject, string sVarName, int iValue, int iExpirati
int GetPersistentInt(object oObject, string sVarName, string sTable = "pwdata")
{
return StringToInt(GetPersistentString(oObject, sVarName, sTable));
string sPlayer;
string sTag;
object oModule;
if (GetIsPC(oObject))
{
sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oObject));
sTag = SQLEncodeSpecialChars(GetName(oObject));
}
else
{
sPlayer = "~";
sTag = GetTag(oObject);
}
sVarName = SQLEncodeSpecialChars(sVarName);
string sSQL = "SELECT val FROM " + sTable + " WHERE player='" + sPlayer +
"' AND tag='" + sTag + "' AND name='" + sVarName + "'";
SQLExecDirect(sSQL);
oModule = GetModule();
SetLocalString(oModule, "NWNX!ODBC!FETCH", "-2147483647");
return StringToInt(GetLocalString(oModule, "NWNX!ODBC!FETCH"));
}
void SetPersistentFloat(object oObject, string sVarName, float fValue, int iExpiration =
@@ -364,7 +460,30 @@ void SetPersistentFloat(object oObject, string sVarName, float fValue, int iExpi
float GetPersistentFloat(object oObject, string sVarName, string sTable = "pwdata")
{
return StringToFloat(GetPersistentString(oObject, sVarName, sTable));
string sPlayer;
string sTag;
object oModule;
if (GetIsPC(oObject))
{
sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oObject));
sTag = SQLEncodeSpecialChars(GetName(oObject));
}
else
{
sPlayer = "~";
sTag = GetTag(oObject);
}
sVarName = SQLEncodeSpecialChars(sVarName);
string sSQL = "SELECT val FROM " + sTable + " WHERE player='" + sPlayer +
"' AND tag='" + sTag + "' AND name='" + sVarName + "'";
SQLExecDirect(sSQL);
oModule = GetModule();
SetLocalString(oModule, "NWNX!ODBC!FETCH", "-340282306073709650000000000000000000000.000000000");
return StringToFloat(GetLocalString(oModule, "NWNX!ODBC!FETCH"));
}
void SetPersistentLocation(object oObject, string sVarName, location lLocation, int iExpiration =
@@ -389,6 +508,73 @@ vector GetPersistentVector(object oObject, string sVarName, string sTable = "pwd
return APSStringToVector(GetPersistentString(oObject, sVarName, sTable));
}
void SetPersistentObject(object oOwner, string sVarName, object oObject, int iExpiration =
0, string sTable = "pwobjdata")
{
string sPlayer;
string sTag;
if (GetIsPC(oOwner))
{
sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oOwner));
sTag = SQLEncodeSpecialChars(GetName(oOwner));
}
else
{
sPlayer = "~";
sTag = GetTag(oOwner);
}
sVarName = SQLEncodeSpecialChars(sVarName);
string sSQL = "SELECT player FROM " + sTable + " WHERE player='" + sPlayer +
"' AND tag='" + sTag + "' AND name='" + sVarName + "'";
SQLExecDirect(sSQL);
if (SQLFetch() == SQL_SUCCESS)
{
// row exists
sSQL = "UPDATE " + sTable + " SET val=%s,expire=" + IntToString(iExpiration) +
" WHERE player='" + sPlayer + "' AND tag='" + sTag + "' AND name='" + sVarName + "'";
SetLocalString(GetModule(), "NWNX!ODBC!SETSCORCOSQL", sSQL);
StoreCampaignObject ("NWNX", "-", oObject);
}
else
{
// row doesn't exist
sSQL = "INSERT INTO " + sTable + " (player,tag,name,val,expire) VALUES" +
"('" + sPlayer + "','" + sTag + "','" + sVarName + "',%s," + IntToString(iExpiration) + ")";
SetLocalString(GetModule(), "NWNX!ODBC!SETSCORCOSQL", sSQL);
StoreCampaignObject ("NWNX", "-", oObject);
}
}
object GetPersistentObject(object oObject, string sVarName, object oOwner = OBJECT_INVALID, string sTable = "pwobjdata")
{
string sPlayer;
string sTag;
object oModule;
if (GetIsPC(oObject))
{
sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oObject));
sTag = SQLEncodeSpecialChars(GetName(oObject));
}
else
{
sPlayer = "~";
sTag = GetTag(oObject);
}
sVarName = SQLEncodeSpecialChars(sVarName);
string sSQL = "SELECT val FROM " + sTable + " WHERE player='" + sPlayer +
"' AND tag='" + sTag + "' AND name='" + sVarName + "'";
SetLocalString(GetModule(), "NWNX!ODBC!SETSCORCOSQL", sSQL);
if (!GetIsObjectValid(oOwner))
oOwner = oObject;
return RetrieveCampaignObject ("NWNX", "-", GetLocation(oOwner), oOwner);
}
void DeletePersistentVariable(object oObject, string sVarName, string sTable = "pwdata")
{
string sPlayer;
@@ -456,3 +642,52 @@ string SQLDecodeSpecialChars(string sString)
return sReturn;
}
// Gets the current REAL WORLD time, uses NWNX2
// Year-Month-Day Time
// 1997-12-15 23:50:26
string GetSQLTime();
string GetSQLTime()
{
string sSQL = "SELECT CURRENT_TIME";
SQLExecDirect(sSQL);
if(SQLFetch() == SQL_SUCCESS)
{
return SQLGetData(1);
}
else
{
return "Database error";
}
}
// Gets the current REAL WORLD date, uses NWNX2
string GetSQLDate();
string GetSQLDate()
{
string sSQL = "SELECT CURRENT_DATE";
SQLExecDirect(sSQL);
if(SQLFetch() == SQL_SUCCESS)
{
return SQLGetData(1);
}
else
{
return "Database error";
}
}
// Gets the current REAL WORLD time stamp, uses NWNX2
string GetSQLTimeStamp();
string GetSQLTimeStamp()
{
string sSQL = "SELECT CURRENT_TIMESTAMP";
SQLExecDirect(sSQL);
if(SQLFetch() == SQL_SUCCESS)
{
return SQLGetData(1);
}
else
{
return "Database error";
}
}