Jaysyn904 f82740bbbd Initial commit
Initial commit
2024-02-22 13:22:03 -05:00

484 lines
15 KiB
Plaintext

// Modified by Zunath
#include "rhs_include"
#include "zzdlg_main_inc"
const string RESPONSE_PAGE = "rhs_buy_menu_responses";
const string PAGE_MAIN = "main_page";
const string PAGE_PREVIEW_HOUSE = "preview_house_page";
const string PAGE_PREVIEW_HOUSE_CONFIRM = "preview_house_confirm_page";
const string PAGE_RENT_HOUSE = "rent_house_page";
const string PAGE_RENT_HOUSE_CONFIRM = "rent_house_confirm_page";
const string PAGE_SELL_ALL_FURNITURE = "sell_all_furniture_page";
const string PAGE_SELL_ALL_FURNITURE_CONFIRM = "sell_all_furniture_confirm_page";
const string PAGE_MOVE_OUT = "move_out_page";
const string PAGE_MOVE_OUT_CONFIRM = "move_out_confirm_page";
/////////////////////////
// TEMPORARY VARIABLES //
/////////////////////////
// Tracks the name of the house selected for previewing
const string RHS_TEMP_PAGE_HOUSE_TYPE_SELECTED = "RHS_TEMP_PAGE_HOUSE_TYPE_SELECTED";
// Tracks the resref of the house selected for previewing
const string RHS_TEMP_PAGE_HOUSE_TYPE_RESREF = "RHS_TEMP_PAGE_HOUSE_TYPE_RESREF";
// Tracks the rent cost of the house selected for renting
const string RHS_TEMP_PAGE_HOUSE_TYPE_RENT_COST = "RHS_TEMP_PAGE_HOUSE_TYPE_RENT_COST";
// Tracks the amount of money player will receive for selling all of his/her furniture
const string RHS_TEMP_PAGE_FURNITURE_SALE_AMOUNT = "RHS_TEMP_PAGE_FURNITURE_SALE_AMOUNT";
void ClearTemporaryVariables()
{
object oPC = dlgGetSpeakingPC();
DeleteLocalString(oPC, RHS_TEMP_PAGE_HOUSE_TYPE_SELECTED);
DeleteLocalString(oPC, RHS_TEMP_PAGE_HOUSE_TYPE_RESREF);
DeleteLocalInt(oPC, RHS_TEMP_PAGE_HOUSE_TYPE_RENT_COST);
DeleteLocalInt(oPC, RHS_TEMP_PAGE_FURNITURE_SALE_AMOUNT);
}
// Creates the response choices for all house types the landlord is authorized to rent out.
void CreateHouseSelections();
void CreateHouseSelections()
{
object oNPC = OBJECT_SELF;
string sSQL;
int iIndex = 1;
int iCurrentHouse = GetLocalArrayInt(oNPC, RHS_LANDLORD_HOUSES_AVAILABLE_ARRAY, iIndex);
string sHouses = IntToString(iCurrentHouse);
int bFoundHouse = FALSE;
while(iCurrentHouse > 0)
{
bFoundHouse = TRUE;
sHouses += " OR ID=" + IntToString(iCurrentHouse);
iIndex++;
iCurrentHouse = GetLocalArrayInt(oNPC, RHS_LANDLORD_HOUSES_AVAILABLE_ARRAY, iIndex);
}
if(bFoundHouse)
{
sSQL = "SELECT Name FROM " + RHS_SCHEMA + "." + RHS_TABLE_HOUSE_TYPES + " WHERE ID=" + sHouses + ";";
SQLExecDirect(sSQL);
while(SQLFetch() == SQL_SUCCESS)
{
dlgAddResponseAction(RESPONSE_PAGE, SQLDecodeSpecialChars(SQLGetData(1)));
}
}
}
// Creates the header for the 'Preview House' and 'Rent House' events.
// Returns the rent price.
int CreatePreviewHeader();
int CreatePreviewHeader()
{
object oPC = dlgGetSpeakingPC();
string sHouseType = GetLocalString(oPC, RHS_TEMP_PAGE_HOUSE_TYPE_SELECTED);
string sMessage = ColorTokenGreen() + RHS_HOUSE_TERM_PROPER + " Menu\n\n" + ColorTokenEnd();
string sResref;
int iRent;
// Grab rent and resref information from database
string sSQL = "SELECT Resref, Rent FROM " + RHS_SCHEMA + "." + RHS_TABLE_HOUSE_TYPES + " WHERE Name='" + SQLEncodeSpecialChars(sHouseType) + "';";
SQLExecDirect(sSQL);
while(SQLFetch() == SQL_SUCCESS)
{
sResref = SQLGetData(1);
iRent = StringToInt(SQLGetData(2));
}
sMessage += ColorTokenGreen() + "House Type: " + ColorTokenEnd() + sHouseType + "\n";
sMessage += ColorTokenGreen() + "Rent: " + ColorTokenEnd() + IntToString(iRent) + " GP due every " + IntToString(RHS_RENT_LENGTH) + " days\n";
dlgSetPrompt(sMessage);
// Store resref for later use
SetLocalString(oPC, RHS_TEMP_PAGE_HOUSE_TYPE_RESREF, sResref);
return iRent;
}
// Prototypes
void MainPageInit();
void MainPageSelect();
void PreviewHouseInit();
void PreviewHouseSelect();
void RentHouseInit();
void RentHouseSelect();
void SellAllFurnitureInit();
void SellAllFurnitureSelect();
void MoveOutInit();
void MoveOutSelect();
void PreviewHouseConfirmInit();
void PreviewHouseConfirmSelect();
void RentHouseConfirmInit();
void RentHouseConfirmSelect();
void SellAllFurnitureConfirmInit();
void SellAllFurnitureConfirmSelect();
void MoveOutConfirmInit();
void MoveOutConfirmSelect();
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_PREVIEW_HOUSE) PreviewHouseInit();
else if(sPage == PAGE_RENT_HOUSE) RentHouseInit();
else if(sPage == PAGE_SELL_ALL_FURNITURE) SellAllFurnitureInit();
else if(sPage == PAGE_MOVE_OUT) MoveOutInit();
else if(sPage == PAGE_PREVIEW_HOUSE_CONFIRM) PreviewHouseConfirmInit();
else if(sPage == PAGE_RENT_HOUSE_CONFIRM) RentHouseConfirmInit();
else if(sPage == PAGE_SELL_ALL_FURNITURE_CONFIRM) SellAllFurnitureConfirmInit();
else if(sPage == PAGE_MOVE_OUT_CONFIRM) MoveOutConfirmInit();
dlgSetActiveResponseList( RESPONSE_PAGE );
}
// Handles any selection.
void OnSelection( string sPage )
{
if ( sPage == PAGE_MAIN ) MainPageSelect( );
else if(sPage == PAGE_PREVIEW_HOUSE) PreviewHouseSelect();
else if(sPage == PAGE_RENT_HOUSE) RentHouseSelect();
else if(sPage == PAGE_SELL_ALL_FURNITURE) SellAllFurnitureSelect();
else if(sPage == PAGE_MOVE_OUT) MoveOutSelect();
else if(sPage == PAGE_PREVIEW_HOUSE_CONFIRM) PreviewHouseConfirmSelect();
else if(sPage == PAGE_RENT_HOUSE_CONFIRM) RentHouseConfirmSelect();
else if(sPage == PAGE_SELL_ALL_FURNITURE_CONFIRM) SellAllFurnitureConfirmSelect();
else if(sPage == PAGE_MOVE_OUT_CONFIRM) MoveOutConfirmSelect();
}
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, "Preview " + RHS_HOUSE_TERM_PROPER);
dlgAddResponseAction(RESPONSE_PAGE, "Rent " + RHS_HOUSE_TERM_PROPER);
}
else
{
sPrompt += "What would you like to do?";
dlgAddResponseAction(RESPONSE_PAGE, "Preview " + RHS_HOUSE_TERM_PROPER);
dlgAddResponseAction(RESPONSE_PAGE, "Sell All Furniture");
dlgAddResponseAction(RESPONSE_PAGE, "Move Out");
}
dlgSetPrompt(sPrompt);
dlgDeactivateResetResponse();
dlgActivateEndResponse( "End" );
}
void MainPageSelect( )
{
object oPC = dlgGetSpeakingPC();
object oDatabase = GetItemPossessedBy(oPC, PC_DATABASE);
if(dlgIsSelectionEqualToName("Sell All Furniture"))
{
dlgChangePage(PAGE_SELL_ALL_FURNITURE);
}
else if(dlgIsSelectionEqualToName("Move Out"))
{
dlgChangePage(PAGE_MOVE_OUT);
}
else if(dlgIsSelectionEqualToName("Preview " + RHS_HOUSE_TERM_PROPER))
{
dlgChangePage(PAGE_PREVIEW_HOUSE);
}
else if(dlgIsSelectionEqualToName("Rent " + RHS_HOUSE_TERM_PROPER))
{
dlgChangePage(PAGE_RENT_HOUSE);
}
}
void PreviewHouseInit()
{
string sMessage = ColorTokenGreen() + RHS_HOUSE_TERM_PROPER + " Menu\n\n" + ColorTokenEnd();
sMessage += "You can preview the layout of a " + RHS_HOUSE_TERM_LOWER + " before you decide to rent it.\n\n";
sMessage += "Please select a " + RHS_HOUSE_TERM_LOWER + " layout to preview.\n";
dlgSetPrompt(sMessage);
CreateHouseSelections();
dlgActivateResetResponse("Back", ColorTokenBlue());
}
void PreviewHouseSelect()
{
object oPC = dlgGetSpeakingPC();
string sHouseTypeSelected = dlgGetSelectionName();
SetLocalString(oPC, RHS_TEMP_PAGE_HOUSE_TYPE_SELECTED, sHouseTypeSelected);
dlgChangePage(PAGE_PREVIEW_HOUSE_CONFIRM);
}
void RentHouseInit()
{
string sMessage = ColorTokenGreen() + RHS_HOUSE_TERM_PROPER + " Menu\n\n" + ColorTokenEnd();
sMessage += "Which " + RHS_HOUSE_TERM_LOWER + " would you like to start renting?\n";
dlgSetPrompt(sMessage);
CreateHouseSelections();
dlgActivateResetResponse("Back", ColorTokenBlue());
}
void RentHouseSelect()
{
object oPC = dlgGetSpeakingPC();
string sHouseTypeSelected = dlgGetSelectionName();
SetLocalString(oPC, RHS_TEMP_PAGE_HOUSE_TYPE_SELECTED, sHouseTypeSelected);
dlgChangePage(PAGE_RENT_HOUSE_CONFIRM);
}
void SellAllFurnitureInit()
{
object oPC = dlgGetSpeakingPC();
float fPercentage = RHS_FURNITURE_SELL_BACK_PERCENTAGE * 100.0;
int iSellBackAmount = RHS_CalculateTotalFurnitureValue(oPC);
string sMessage = ColorTokenGreen() + RHS_HOUSE_TERM_PROPER + " Menu\n\n" + ColorTokenEnd();
sMessage += "Furniture can be sold back at " + FloatToString(fPercentage, 3, 2) + "% of retail value.\n\n";
sMessage += "You will receive " + IntToString(iSellBackAmount) + " GP if you sell all of the furniture in your " + RHS_HOUSE_TERM_LOWER + " back to the store.\n\n";
sMessage += ColorTokenRed() + "Warning:" + ColorTokenEnd() + " This action cannot be be undone! Are you sure you want to sell all of the furniture in your " + RHS_HOUSE_TERM_LOWER + "?\n";
dlgSetPrompt(sMessage);
dlgAddResponseAction(RESPONSE_PAGE, "Sell All Furniture");
dlgActivateResetResponse("Back", ColorTokenBlue());
}
void SellAllFurnitureSelect()
{
if(dlgIsSelectionEqualToName("Sell All Furniture"))
{
dlgChangePage(PAGE_SELL_ALL_FURNITURE_CONFIRM);
}
}
void MoveOutInit()
{
object oPC = dlgGetSpeakingPC();
// Convert sell back price to percentage
float fPercentage = RHS_FURNITURE_SELL_BACK_PERCENTAGE * 100.0;
// Calculate sell back amount
int iSellBackAmount = RHS_CalculateTotalFurnitureValue(oPC);
// Store the sell back amount for later use
SetLocalInt(oPC, RHS_TEMP_PAGE_FURNITURE_SALE_AMOUNT, iSellBackAmount);
string sMessage = ColorTokenGreen() + RHS_HOUSE_TERM_PROPER + " Menu\n\n" + ColorTokenEnd();
sMessage += "You can move out of your " + RHS_HOUSE_TERM_LOWER + " here. If you choose to move out, all of the furniture in your " + RHS_HOUSE_TERM_LOWER + " will be sold at " + FloatToString(fPercentage, 3, 2) + "% of retail price.\n\n";
sMessage += "If you choose to move out you will receive a total of " + IntToString(iSellBackAmount) + " GP.\n\n";
sMessage += ColorTokenRed() + "Warning: " + ColorTokenEnd() + "Your list of friends, trustees and lease will also be reset!\n";
dlgSetPrompt(sMessage);
dlgAddResponseAction(RESPONSE_PAGE, "Move out of my " + RHS_HOUSE_TERM_LOWER);
dlgActivateResetResponse("Back", ColorTokenBlue());
}
void MoveOutSelect()
{
if(dlgIsSelectionEqualToName("Move out of my " + RHS_HOUSE_TERM_LOWER))
{
dlgChangePage(PAGE_MOVE_OUT_CONFIRM);
}
}
// Preview House Confirmation Page
void PreviewHouseConfirmInit()
{
CreatePreviewHeader();
dlgAddResponseAction(RESPONSE_PAGE, "Preview " + RHS_HOUSE_TERM_PROPER);
dlgAddResponseAction(RESPONSE_PAGE, "Back", ColorTokenBlue());
dlgDeactivateResetResponse();
}
void PreviewHouseConfirmSelect()
{
object oPC = dlgGetSpeakingPC();
string sHouseName = GetLocalString(oPC, RHS_TEMP_PAGE_HOUSE_TYPE_SELECTED);
if(dlgIsSelectionEqualToName("Back"))
{
ClearTemporaryVariables();
dlgChangePage(PAGE_PREVIEW_HOUSE);
}
else if(dlgIsSelectionEqualToName("Preview " + RHS_HOUSE_TERM_PROPER))
{
int iHouseType = StringToInt(GetMySQLDataKeyString(RHS_TABLE_HOUSE_TYPES, "ID", sHouseName, "Name", RHS_SCHEMA));
sHouseName = "(PREVIEW) " + sHouseName;
RHS_PreviewHouse(oPC, iHouseType, sHouseName);
}
}
// Rent House Confirmation Page
void RentHouseConfirmInit()
{
object oPC = dlgGetSpeakingPC();
int iRent = CreatePreviewHeader();
int iGold = GetGold(oPC);
// Only display if PC has enough money to rent the place
if(iGold >= iRent)
{
SetLocalInt(oPC, RHS_TEMP_PAGE_HOUSE_TYPE_RENT_COST, iRent);
dlgAddResponseAction(RESPONSE_PAGE, "Rent " + RHS_HOUSE_TERM_PROPER + " (" + IntToString(iRent) + " GP)");
}
dlgAddResponseAction(RESPONSE_PAGE, "Back", ColorTokenBlue());
dlgDeactivateResetResponse();
}
void RentHouseConfirmSelect()
{
// Return to house type selection menu
if(dlgIsSelectionEqualToName("Back"))
{
ClearTemporaryVariables();
dlgChangePage(PAGE_MAIN);
}
// Chose to rent the house - set PC up with all necessary variables and add database tables
else
{
object oPC = dlgGetSpeakingPC();
object oDatabase = GetItemPossessedBy(oPC, PC_DATABASE);
int iGold = GetGold(oPC);
int iRent = GetLocalInt(oPC, RHS_TEMP_PAGE_HOUSE_TYPE_RENT_COST);
string sHouseType = GetLocalString(oPC, RHS_TEMP_PAGE_HOUSE_TYPE_SELECTED);
// Not enough cash
if(iRent > iGold)
{
FloatingTextStringOnCreature(ColorTokenRed() + "You do not have enough money to make that purchase." + ColorTokenEnd(), oPC, FALSE);
return;
}
// Remove money
AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));
int iHouseType = StringToInt(GetMySQLDataKeyString(RHS_TABLE_HOUSE_TYPES, "ID", sHouseType, "Name", RHS_SCHEMA));
// Add tables to database and set PC up to use the house
RHS_SetPlayerHouse(oPC, iHouseType);
// Return to main menu
dlgChangePage(PAGE_MAIN);
}
}
// Sell All Furniture Confirmation Page
void SellAllFurnitureConfirmInit()
{
dlgAddResponseAction(RESPONSE_PAGE, "CONFIRM SELL ALL FURNITURE");
dlgAddResponseAction(RESPONSE_PAGE, "Back", ColorTokenBlue());
dlgDeactivateResetResponse();
}
void SellAllFurnitureConfirmSelect()
{
if(dlgIsSelectionEqualToName("Back"))
{
ClearTemporaryVariables();
dlgChangePage(PAGE_MAIN);
}
else if(dlgIsSelectionEqualToName("CONFIRM SELL ALL FURNITURE"))
{
object oPC = dlgGetSpeakingPC();
RHS_SellAllFurniture(oPC);
ClearTemporaryVariables();
dlgChangePage(PAGE_MAIN);
}
}
// Move Out Confirmation Page
void MoveOutConfirmInit()
{
dlgAddResponseAction(RESPONSE_PAGE, "CONFIRM MOVE OUT");
dlgAddResponseAction(RESPONSE_PAGE, "Back", ColorTokenBlue());
dlgDeactivateResetResponse();
}
void MoveOutConfirmSelect()
{
object oPC = dlgGetSpeakingPC();
if(dlgIsSelectionEqualToName("Back"))
{
ClearTemporaryVariables();
dlgChangePage(PAGE_PREVIEW_HOUSE);
}
else if(dlgIsSelectionEqualToName("CONFIRM MOVE OUT"))
{
int iFurnitureMoney = GetLocalInt(oPC, RHS_TEMP_PAGE_FURNITURE_SALE_AMOUNT);
RHS_RemovePlayerHouse(oPC, iFurnitureMoney);
dlgChangePage(PAGE_MAIN);
}
}