REO-EE/_module/nss/rhs_house_menu.nss
Jaysyn904 f82740bbbd Initial commit
Initial commit
2024-02-22 13:22:03 -05:00

516 lines
17 KiB
Plaintext

// Modified by Zunath
#include "rhs_include"
#include "zzdlg_main_inc"
const string RESPONSE_PAGE = "rhs_house_menu_responses";
const string PAGE_MAIN = "main_page";
const string PAGE_ENTER_FRIEND_HOUSE = "enter_friend_house_page";
const string PAGE_ENTER_PUBLIC_HOUSE = "enter_public_house_page";
const string PAGE_PAY_RENT = "pay_rent_page";
const string PAGE_MANAGE_FRIENDS = "manage_friends_page";
const string PAGE_MANAGE_PRIVACY = "manage_privacy_page";
const string PAGE_CHANGE_HOUSE_NAME = "change_house_name_page";
/////////////////////////
// TEMPORARY VARIABLES //
/////////////////////////
// Tracks the amount of money rent costs
const string PAGE_TEMP_RENT_COST = "PAGE_TEMP_RENT_COST";
void ClearTemporaryVariables()
{
object oPC = dlgGetSpeakingPC();
DeleteLocalInt(oPC, RHS_PAGE_TEMP_LISTENING);
DeleteLocalInt(oPC, PAGE_TEMP_RENT_COST);
DeleteLocalString(oPC, RHS_PAGE_TEMP_NEW_HOUSE_NAME);
}
// Prototypes
void MainPageInit();
void MainPageSelect();
void EnterFriendHouseInit();
void EnterFriendHouseSelect();
void EnterPublicHouseInit();
void EnterPublicHouseSelect();
void PayRentInit();
void PayRentSelect();
void ManageFriendsInit();
void ManageFriendsSelect();
void ManagePrivacyInit();
void ManagePrivacySelect();
void ChangeHouseNameInit();
void ChangeHouseNameSelect();
void OnInit()
{
dlgChangeLabelNext("Next page");
dlgChangeLabelPrevious("Previous page");
dlgChangePage(PAGE_MAIN);
dlgActivatePreservePageNumberOnSelection();
dlgActivateResetResponse();
}
// Create the page
void OnPageInit( string sPage )
{
DeleteList( RESPONSE_PAGE, dlgGetSpeakingPC() );
if( sPage == PAGE_MAIN ) MainPageInit( );
else if(sPage == PAGE_ENTER_FRIEND_HOUSE) EnterFriendHouseInit();
else if(sPage == PAGE_ENTER_PUBLIC_HOUSE) EnterPublicHouseInit();
else if(sPage == PAGE_PAY_RENT) PayRentInit();
else if(sPage == PAGE_MANAGE_FRIENDS) ManageFriendsInit();
else if(sPage == PAGE_MANAGE_PRIVACY) ManagePrivacyInit();
else if(sPage == PAGE_CHANGE_HOUSE_NAME) ChangeHouseNameInit();
dlgSetActiveResponseList( RESPONSE_PAGE );
}
// Handles any selection.
void OnSelection( string sPage )
{
if ( sPage == PAGE_MAIN ) MainPageSelect( );
else if(sPage == PAGE_ENTER_FRIEND_HOUSE) EnterFriendHouseSelect();
else if(sPage == PAGE_ENTER_PUBLIC_HOUSE) EnterPublicHouseSelect();
else if(sPage == PAGE_PAY_RENT) PayRentSelect();
else if(sPage == PAGE_MANAGE_FRIENDS) ManageFriendsSelect();
else if(sPage == PAGE_MANAGE_PRIVACY) ManagePrivacySelect();
else if(sPage == PAGE_CHANGE_HOUSE_NAME) ChangeHouseNameSelect();
}
void OnReset( string sPage )
{
ClearTemporaryVariables();
dlgChangePage( PAGE_MAIN );
dlgResetPageNumber( );
}
void OnAbort( string sPage )
{
ClearTemporaryVariables();
DeleteList( RESPONSE_PAGE, dlgGetSpeakingPC() );
}
void OnEnd( string sPage )
{
ClearTemporaryVariables();
DeleteList( RESPONSE_PAGE, dlgGetSpeakingPC() );
}
void OnContinue( string sPage, int iContinuePage )
{
}
// Message handler
void main()
{
dlgOnMessage();
}
// Specific scripting starts here
// MAIN PAGE START
void MainPageInit( )
{
object oPC = dlgGetSpeakingPC();
object oDatabase = GetItemPossessedBy(oPC, PC_DATABASE);
int iPCID = GetLocalInt(oDatabase, PC_ID_NUMBER);
int bHouseRented = GetLocalInt(oDatabase, RHS_PLAYER_HOUSE_RENTED);
string sPrompt = ColorTokenGreen() + RHS_HOUSE_TERM_PROPER + " Menu\n\n" + ColorTokenEnd();
// PC doesn't have a house currently
if(!bHouseRented)
{
sPrompt += "You do not currently have a " + RHS_HOUSE_TERM_LOWER + " rented.";
dlgAddResponseAction(RESPONSE_PAGE, "Enter a Public " + RHS_HOUSE_TERM_PROPER);
}
else
{
string sDate = GetMySQLData(RHS_TABLE_HOUSES, "Accessible_Until", iPCID, "Player_ID", RHS_SCHEMA);
sPrompt += ColorTokenGreen() + "Rent Due: " + ColorTokenEnd() + sDate + "\n\n";;
sPrompt += "What would you like to do?";
dlgAddResponseAction(RESPONSE_PAGE, "Enter Your " + RHS_HOUSE_TERM_PROPER);
//dlgAddResponseAction(RESPONSE_PAGE, "Enter a Friend's " + RHS_HOUSE_TERM_PROPER);
dlgAddResponseAction(RESPONSE_PAGE, "Enter a Public " + RHS_HOUSE_TERM_PROPER);
dlgAddResponseAction(RESPONSE_PAGE, "Pay Rent");
//dlgAddResponseAction(RESPONSE_PAGE, "Manage Friends");
dlgAddResponseAction(RESPONSE_PAGE, "Manage Privacy");
dlgAddResponseAction(RESPONSE_PAGE, "Change " + RHS_HOUSE_TERM_PROPER + " Name");
}
dlgSetPrompt(sPrompt);
dlgDeactivateResetResponse();
dlgActivateEndResponse( "End" );
}
void MainPageSelect( )
{
object oPC = dlgGetSpeakingPC();
object oDatabase = GetItemPossessedBy(oPC, PC_DATABASE);
// Enter Your House
if(dlgIsSelectionEqualToName("Enter Your " + RHS_HOUSE_TERM_PROPER))
{
int bRentPaid = RHS_IsRentPaid(oPC);
// Check if rent is paid - if it is, fire RHS_EnterHouse.
if(bRentPaid)
{
RHS_EnterHouse(oPC, oPC);
}
else
{
FloatingTextStringOnCreature(ColorTokenRed() + "You must pay your rent before you can enter your " + RHS_HOUSE_TERM_LOWER + "." + ColorTokenEnd(), oPC, FALSE);
}
dlgEndDialog();
}
// Enter a Friend's House
else if(dlgIsSelectionEqualToName("Enter a Friend's " + RHS_HOUSE_TERM_PROPER))
{
dlgChangePage(PAGE_ENTER_FRIEND_HOUSE);
}
// Enter a Public House
else if(dlgIsSelectionEqualToName("Enter a Public " + RHS_HOUSE_TERM_PROPER))
{
dlgChangePage(PAGE_ENTER_PUBLIC_HOUSE);
}
// Pay Rent
else if(dlgIsSelectionEqualToName("Pay Rent"))
{
dlgChangePage(PAGE_PAY_RENT);
}
// Manage Friends
else if(dlgIsSelectionEqualToName("Manage Friends"))
{
dlgChangePage(PAGE_MANAGE_FRIENDS);
}
// Manage Privacy
else if(dlgIsSelectionEqualToName("Manage Privacy"))
{
dlgChangePage(PAGE_MANAGE_PRIVACY);
}
// Change House Name
else if(dlgIsSelectionEqualToName("Change " + RHS_HOUSE_TERM_PROPER + " Name"))
{
dlgChangePage(PAGE_CHANGE_HOUSE_NAME);
}
}
void EnterFriendHouseInit()
{
object oPC = dlgGetSpeakingPC();
object oDatabase = GetItemPossessedBy(oPC, PC_DATABASE);
string sSQL = "SELECT";
dlgActivateResetResponse("Back", ColorTokenBlue());
}
void EnterFriendHouseSelect()
{
}
void EnterPublicHouseInit()
{
object oPC = dlgGetSpeakingPC();
dlgSetPrompt(ColorTokenGreen() + RHS_HOUSE_TERM_PROPER + " Menu\n\n" + ColorTokenEnd() + "Please select a " + RHS_HOUSE_TERM_LOWER + " you wish to enter.");
// Display all people's houses that are set to public entry and are accessible (I.E: Rent has been paid)
string sSQL = "SELECT Player_ID, House_Name FROM " + RHS_SCHEMA + "." + RHS_TABLE_HOUSES + " WHERE Publicity='P' AND UNIX_TIMESTAMP(Accessible_Until) > UNIX_TIMESTAMP();";
SQLExecDirect(sSQL);
while(SQLFetch() == SQL_SUCCESS)
{
string sPCID = SQLGetData(1);
string sHouseName = SQLDecodeSpecialChars(SQLGetData(2));
dlgAddResponseAction(RESPONSE_PAGE, "(" + sPCID + ") " + sHouseName);
}
dlgActivateResetResponse("Back", ColorTokenBlue());
}
void EnterPublicHouseSelect()
{
object oPC = dlgGetSpeakingPC();
string sSelection = dlgGetSelectionName();
int iOwnerID;
// Find the owner's ID number, starting from the right
string sOwnerID = GetStringLeft(sSelection, 1);
int iCurChar;
int iLength = GetStringLength(sSelection);
for(iCurChar = 0; iCurChar < iLength; iCurChar++)
{
string sCharacter = GetSubString(sSelection, iCurChar, 1);
if(sCharacter == ")")
break;
else
{
sOwnerID += sCharacter;
}
}
// Knock off the parenthases from sOwnerID
sOwnerID = GetSubString(sOwnerID, 2, GetStringLength(sOwnerID));
iOwnerID = StringToInt(sOwnerID);
// Check if rent is paid once more to be safe
if(!RHS_IsRentPaid(OBJECT_INVALID, iOwnerID))
{
FloatingTextStringOnCreature(ColorTokenRed() + "The owner of that " + RHS_HOUSE_TERM_LOWER + " has not paid his or her rent.", oPC, FALSE);
}
else
{
// We've got the owner ID number now. Port player into his/her house
RHS_EnterHouse(oPC, OBJECT_INVALID, iOwnerID);
dlgEndDialog();
}
}
void PayRentInit()
{
object oPC = dlgGetSpeakingPC();
object oDatabase = GetItemPossessedBy(oPC, PC_DATABASE);
int iPCID = GetLocalInt(oDatabase, PC_ID_NUMBER);
string sMessage = ColorTokenGreen() + RHS_HOUSE_TERM_PROPER + " Menu\n\n" + ColorTokenEnd();
int iRent;
string sDate;
int iGold = GetGold(oPC);
string sSQL = "SELECT Rent, Accessible_Until FROM " + RHS_SCHEMA + "." + RHS_TABLE_HOUSES + ", " + RHS_SCHEMA + "." + RHS_TABLE_HOUSE_TYPES + " WHERE Player_ID=" + IntToString(iPCID) + ";";
SQLExecDirect(sSQL);
while(SQLFetch() == SQL_SUCCESS)
{
iRent = StringToInt(SQLGetData(1));
sDate = SQLGetData(2);
}
sMessage += ColorTokenGreen() + "Rent Cost: " + ColorTokenEnd() + IntToString(iRent) + " GP Per Week \n";
sMessage += ColorTokenGreen() + "Rent Due: " + ColorTokenEnd() + sDate + "\n\n";
sMessage += "You may pay your rent in advance. Each purchase you make extends the date by " + IntToString(RHS_RENT_LENGTH) + " or " + IntToString(RHS_RENT_LENGTH * 4) + " days.\n\n";
sMessage += ColorTokenRed() + "Warning: " + ColorTokenEnd() + "Rent is non-refundable. If you move out of your " + RHS_HOUSE_TERM_LOWER + " with time remaining you will lose the time you purchased!\n";
dlgSetPrompt(sMessage);
// Safety check
if(iRent > 0)
{
SetLocalInt(oPC, PAGE_TEMP_RENT_COST, iRent);
// 1 Week
if(iGold >= iRent)
{
dlgAddResponseAction(RESPONSE_PAGE, "Extend Lease By 1 Week (" + IntToString(iRent) + " GP)");
}
// 4 Weeks
if(iGold >= iRent * 4)
{
dlgAddResponseAction(RESPONSE_PAGE, "Extend Lease By 4 Weeks (" + IntToString(iRent * 4) + " GP)");
}
}
dlgActivateResetResponse("Back", ColorTokenBlue());
}
void PayRentSelect()
{
object oPC = dlgGetSpeakingPC();
int iRent = GetLocalInt(oPC, PAGE_TEMP_RENT_COST);
int iGold = GetGold(oPC);
int iNumberOfIncreases = 1;
string sSelection = dlgGetSelectionName();
if(GetStringLeft(sSelection, 23) == "Extend Lease By 4 Weeks")
{
iNumberOfIncreases = 4;
}
// Not enough money
if(iRent * iNumberOfIncreases > iGold)
{
FloatingTextStringOnCreature(ColorTokenRed() + "You do not have enough money to make that purchase." + ColorTokenEnd(), oPC, FALSE);
return;
}
// Got enough - make the extension
AssignCommand(oPC, TakeGoldFromCreature(iRent * iNumberOfIncreases, oPC, TRUE));
RHS_ExtendHouseRent(oPC, RHS_RENT_LENGTH * iNumberOfIncreases);
}
void ManageFriendsInit()
{
dlgActivateResetResponse("Back", ColorTokenBlue());
}
void ManageFriendsSelect()
{
}
void ManagePrivacyInit()
{
object oPC = dlgGetSpeakingPC();
object oDatabase = GetItemPossessedBy(oPC, PC_DATABASE);
int iPCID = GetLocalInt(oDatabase, PC_ID_NUMBER);
string sMessage = ColorTokenGreen() + RHS_HOUSE_TERM_PROPER + " Menu\n\n" + ColorTokenEnd();
string sPrivacyCode = GetMySQLData(RHS_TABLE_HOUSES, "Publicity", iPCID, "Player_ID", RHS_SCHEMA);
string sPrivacy;
// Convert privacy type to the full meaning
if(sPrivacyCode == "P")
sPrivacy = "Public";
else if(sPrivacyCode == "F")
sPrivacy = "Friends Only";
else if(sPrivacyCode == "T")
sPrivacy = "Trustees Only";
else
sPrivacy = "Private";
sMessage += ColorTokenGreen() + "Privacy Setting: " + ColorTokenEnd() + sPrivacy + "\n\n";
sMessage += "You can modify your privacy settings here. This controls who has access to your " + RHS_HOUSE_TERM_LOWER + ".\n\n";
sMessage += ColorTokenYellow() + "'Private'" + ColorTokenEnd() + " means only you, the owner, will be able to enter.\n";
sMessage += ColorTokenYellow() + "'Friends Only'" + ColorTokenEnd() + " means only those you designate as your friends and/or trustees may enter.\n";
sMessage += ColorTokenYellow() + "'Trustees Only'" + ColorTokenEnd() + " means only those you designate as trustees may enter.\n";
sMessage += ColorTokenYellow() + "'Public'" + ColorTokenEnd() + " means everyone may enter.\n";
dlgSetPrompt(sMessage);
if(sPrivacyCode != "O")
dlgAddResponseAction(RESPONSE_PAGE, "Change Privacy Setting to 'Private'");
// Friends and Trustee settings disabled until the friend management portion of the system is complete
/*
if(sPrivacyCode != "F")
dlgAddResponseAction(RESPONSE_PAGE, "Change Privacy Setting to 'Friends Only'");
if(sPrivacyCode != "T")
dlgAddResponseAction(RESPONSE_PAGE, "Change Privacy Setting to 'Trustees Only'");
*/
if(sPrivacyCode != "P")
dlgAddResponseAction(RESPONSE_PAGE, "Change Privacy Setting to 'Public'");
dlgActivateResetResponse("Back", ColorTokenBlue());
}
void ManagePrivacySelect()
{
object oPC = dlgGetSpeakingPC();
object oDatabase = GetItemPossessedBy(oPC, PC_DATABASE);
int iPCID = GetLocalInt(oDatabase, PC_ID_NUMBER);
if(dlgIsSelectionEqualToName("Change Privacy Setting to 'Private'"))
{
SetMySQLData(RHS_TABLE_HOUSES, "Publicity", iPCID, "O", "Player_ID", RHS_SCHEMA);
}
else if(dlgIsSelectionEqualToName("Change Privacy Setting to 'Friends Only'"))
{
SetMySQLData(RHS_TABLE_HOUSES, "Publicity", iPCID, "F", "Player_ID", RHS_SCHEMA);
}
else if(dlgIsSelectionEqualToName("Change Privacy Setting to 'Trustees Only'"))
{
SetMySQLData(RHS_TABLE_HOUSES, "Publicity", iPCID, "T", "Player_ID", RHS_SCHEMA);
}
else if(dlgIsSelectionEqualToName("Change Privacy Setting to 'Public'"))
{
SetMySQLData(RHS_TABLE_HOUSES, "Publicity", iPCID, "P", "Player_ID", RHS_SCHEMA);
}
}
void ChangeHouseNameInit()
{
object oPC = dlgGetSpeakingPC();
object oDatabase = GetItemPossessedBy(oPC, PC_DATABASE);
int iPCID = GetLocalInt(oDatabase, PC_ID_NUMBER);
string sMessage = ColorTokenGreen() + RHS_HOUSE_TERM_PROPER + " Menu\n\n" + ColorTokenEnd();
int bListening = GetLocalInt(oPC, RHS_PAGE_TEMP_LISTENING);
string sHouseName;
string sSQL = "SELECT House_Name FROM " + RHS_SCHEMA + "." + RHS_TABLE_HOUSES + " WHERE Player_ID=" + IntToString(iPCID) + ";";
SQLExecDirect(sSQL);
while(SQLFetch() == SQL_SUCCESS)
{
sHouseName = SQLDecodeSpecialChars(SQLGetData(1));
}
// House name wasn't put in for some reason - set to default
if(sHouseName == "")
{
sHouseName = GetName(oPC) + "'s " + RHS_HOUSE_TERM_PROPER;
}
sMessage += ColorTokenGreen() + "Current " + RHS_HOUSE_TERM_PROPER + " Name: " + ColorTokenEnd() + sHouseName + "\n\n";
// Is the system listening for PC's text input?
if(bListening)
{
dlgAddResponseAction(RESPONSE_PAGE, "Finish Entering New " + RHS_HOUSE_TERM_PROPER + " Name");
}
// Not listening - add the option to listen
else
{
dlgAddResponseAction(RESPONSE_PAGE, "Enter New " + RHS_HOUSE_TERM_PROPER + " Name");
}
sMessage += "You can change the name of your " + RHS_HOUSE_TERM_LOWER + " here. This will display as the name of the area and it will display in searches made for public " + RHS_HOUSE_TERM_LOWER_PLURAL + ".";
dlgSetPrompt(sMessage);
dlgActivateResetResponse("Back", ColorTokenBlue());
}
void ChangeHouseNameSelect()
{
object oPC = dlgGetSpeakingPC();
object oDatabase = GetItemPossessedBy(oPC, PC_DATABASE);
int iPCID = GetLocalInt(oDatabase, PC_ID_NUMBER);
if(dlgIsSelectionEqualToName("Enter New " + RHS_HOUSE_TERM_PROPER + " Name"))
{
SetLocalInt(oPC, RHS_PAGE_TEMP_LISTENING, TRUE);
FloatingTextStringOnCreature(ColorTokenGreen() + "Please type in the name you wish to call your " + RHS_HOUSE_TERM_LOWER + " and press enter." + ColorTokenEnd(), oPC, FALSE);
}
else if(dlgIsSelectionEqualToName("Finish Entering New " + RHS_HOUSE_TERM_PROPER + " Name"))
{
string sNewName = GetLocalString(oPC, RHS_PAGE_TEMP_NEW_HOUSE_NAME);
int iLength = GetStringLength(sNewName);
// Put in too many characters
if(iLength > RHS_MAX_HOUSE_NAME_LENGTH)
{
FloatingTextStringOnCreature(ColorTokenRed() + "ERROR: " + RHS_HOUSE_TERM_PROPER + " names cannot be longer than " + IntToString(RHS_MAX_HOUSE_NAME_LENGTH) + " characters." + ColorTokenEnd(), oPC, FALSE);
return;
}
else if(iLength < RHS_MIN_HOUSE_NAME_LENGTH && iLength > 0)
{
FloatingTextStringOnCreature(ColorTokenRed() + "ERROR: " + RHS_HOUSE_TERM_PROPER + " names cannot be shorter than " + IntToString(RHS_MIN_HOUSE_NAME_LENGTH) + " characters." + ColorTokenEnd(), oPC, FALSE);
return;
}
// Default to Player Name's House under any of these conditions
else if(sNewName == "")
{
sNewName = GetName(oPC) + "'s " + RHS_HOUSE_TERM_PROPER;
ClearTemporaryVariables();
}
// Encode the name
sNewName = SQLEncodeSpecialChars(sNewName);
// Update the database
SetMySQLData(RHS_SCHEMA + "." + RHS_TABLE_HOUSES, "House_Name", iPCID, sNewName, "Player_ID");
}
}