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

223 lines
6.7 KiB
Plaintext

// Modified by Zunath
#include "fus_include"
const string RESPONSE_PAGE = "fus_menu_responses";
const string PAGE_MAIN = "main_page";
const string PAGE_UPGRADE = "fus_upgrade_page";
void MainPageInit();
void MainPageSelect();
void UpgradePageInit();
void UpgradePageSelect();
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( );
if( sPage == PAGE_UPGRADE ) UpgradePageInit( );
dlgSetActiveResponseList( RESPONSE_PAGE );
}
// Handles any selection.
void OnSelection( string sPage )
{
if ( sPage == PAGE_MAIN ) MainPageSelect( );
if ( sPage == PAGE_UPGRADE ) UpgradePageSelect( );
}
void OnReset( string sPage )
{
dlgChangePage( PAGE_MAIN );
dlgResetPageNumber( );
}
void OnAbort( string sPage )
{
object oPC = dlgGetSpeakingPC();
object oFirearm = GetLocalObject(oPC, FUS_FIREARM_OBJECT);
DeleteList( RESPONSE_PAGE, oPC );
FUS_ClearTemporaryVariables(oPC);
SetItemCursedFlag(oFirearm, FALSE);
}
void OnEnd( string sPage )
{
object oPC = dlgGetSpeakingPC();
object oFirearm = GetLocalObject(oPC, FUS_FIREARM_OBJECT);
DeleteList( RESPONSE_PAGE, oPC );
FUS_ClearTemporaryVariables(oPC);
SetItemCursedFlag(oFirearm, FALSE);
}
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);
object oFirearm = GetLocalObject(oPC, FUS_FIREARM_OBJECT);
string sResref = GetResRef(oFirearm);
dlgSetPrompt("Firearm Upgrade Workbench\n\n" + ColorTokenGreen() + "Please select an upgrade to make..." + ColorTokenEnd());
// I'm no SQL expert so there's probably a better way to do this.
int iCurUpgradeType = 1;
string sSQL = "SELECT MAX(Level) FROM " + FUS_MYSQL_PREFIX + sResref + " WHERE UpgradeType=" + IntToString(iCurUpgradeType);
for(iCurUpgradeType = 2; iCurUpgradeType <= FUS_NUMBER_OF_UPGRADE_CATEGORIES; iCurUpgradeType++)
{
sSQL += " UNION ALL SELECT MAX(Level) FROM " + FUS_MYSQL_PREFIX + sResref + " WHERE UpgradeType=" + IntToString(iCurUpgradeType);
}
SQLExecDirect(sSQL);
SQLFetch();
if(StringToInt(SQLGetData(1)) > 0)
dlgAddResponseAction(RESPONSE_PAGE, "Upgrade: Firepower");
SQLFetch();
if(StringToInt(SQLGetData(1)) > 0)
dlgAddResponseAction(RESPONSE_PAGE, "Upgrade: Magazine Size");
SQLFetch();
if(StringToInt(SQLGetData(1)) > 0)
dlgAddResponseAction(RESPONSE_PAGE, "Upgrade: Reload Speed");
SQLFetch();
if(StringToInt(SQLGetData(1)) > 0)
dlgAddResponseAction(RESPONSE_PAGE, "Upgrade: Ammo Types");
SQLFetch();
if(StringToInt(SQLGetData(1)) > 0)
dlgAddResponseAction(RESPONSE_PAGE, "Upgrade: Firing Modes");
SQLFetch();
if(StringToInt(SQLGetData(1)) > 0)
dlgAddResponseAction(RESPONSE_PAGE, "Upgrade: Critical Rate");
dlgDeactivateResetResponse();
dlgActivateEndResponse( "End" );
}
void MainPageSelect( )
{
object oPC = dlgGetSpeakingPC();
object oDatabase = GetItemPossessedBy(oPC, PC_DATABASE);
if(dlgIsSelectionEqualToName("Upgrade: Firepower"))
{
dlgSetPlayerDataInt(FUS_CHAT_NODE_ID, FUS_UPGRADE_TYPE_FIREPOWER);
}
else if(dlgIsSelectionEqualToName("Upgrade: Magazine Size"))
{
dlgSetPlayerDataInt(FUS_CHAT_NODE_ID, FUS_UPGRADE_TYPE_MAGAZINE_SIZE);
}
else if(dlgIsSelectionEqualToName("Upgrade: Reload Speed"))
{
dlgSetPlayerDataInt(FUS_CHAT_NODE_ID, FUS_UPGRADE_TYPE_RELOAD_SPEED);
}
else if(dlgIsSelectionEqualToName("Upgrade: Ammo Types"))
{
dlgSetPlayerDataInt(FUS_CHAT_NODE_ID, FUS_UPGRADE_TYPE_AMMO_TYPE);
}
else if(dlgIsSelectionEqualToName("Upgrade: Firing Modes"))
{
dlgSetPlayerDataInt(FUS_CHAT_NODE_ID, FUS_UPGRADE_TYPE_FIRING_MODES);
}
else if(dlgIsSelectionEqualToName("Upgrade: Critical Rate"))
{
dlgSetPlayerDataInt(FUS_CHAT_NODE_ID, FUS_UPGRADE_TYPE_CRITICAL_RATING);
}
dlgChangePage(PAGE_UPGRADE);
}
void UpgradePageInit()
{
object oPC = dlgGetSpeakingPC();
object oFirearm = GetLocalObject(oPC, FUS_FIREARM_OBJECT);
int iUpgradeID = dlgGetPlayerDataInt(FUS_CHAT_NODE_ID);
dlgSetPrompt(FUS_CreateUpgradePageHeader(oPC, iUpgradeID));
struct FUS_UpgradeInfoStruct stUpgradeInfo = FUS_GetUpgradeInformation(oFirearm, iUpgradeID);
int iGold = GetGold(oPC);
// Player must meet the gold requirement in order to see this option.
// Also must not be at the maximum upgrade level
if(iGold >= stUpgradeInfo.iGoldCost && stUpgradeInfo.iUpgradeLevel < stUpgradeInfo.iMaxLevel)
{
// Display confirmation message or the initial message, depending on how many times the PC has selected this option.
if(GetLocalInt(oPC, FUS_CHAT_UPGRADE_CONFIRMATION))
{
dlgAddResponseAction(RESPONSE_PAGE, "CONFIRM PURCHASE (" + IntToString(stUpgradeInfo.iGoldCost) + " GP)");
}
else
{
dlgAddResponseAction(RESPONSE_PAGE, "Purchase Upgrade (" + IntToString(stUpgradeInfo.iGoldCost) + " GP)");
}
}
dlgAddResponseAction(RESPONSE_PAGE, "Back", ColorTokenBlue());
}
void UpgradePageSelect()
{
object oPC = dlgGetSpeakingPC();
object oFirearm = GetLocalObject(oPC, FUS_FIREARM_OBJECT);
int iUpgradeID = dlgGetPlayerDataInt(FUS_CHAT_NODE_ID);
struct FUS_UpgradeInfoStruct stUpgradeInfo = FUS_GetUpgradeInformation(oFirearm, iUpgradeID);
int iGold = GetGold(oPC);
// Return to main menu
if(dlgIsSelectionEqualToName("Back"))
{
DeleteLocalInt(oPC, FUS_CHAT_UPGRADE_CONFIRMATION);
dlgChangePage(PAGE_MAIN);
return;
}
// Just in case the PC dropped his or her gold on the ground while using the conversation menu,
// we need to check and make sure they still have enough gold before continuing on.
if(iGold < stUpgradeInfo.iGoldCost)
{
SendMessageToPC(oPC, ColorTokenRed() + "You do not have enough money to make that purchase" + ColorTokenEnd());
return;
}
// Initial Purchase
if(!GetLocalInt(oPC, FUS_CHAT_UPGRADE_CONFIRMATION))
{
SetLocalInt(oPC, FUS_CHAT_UPGRADE_CONFIRMATION, TRUE);
}
// Confirmation of purchase
else
{
FUS_DoUpgrade(oPC, iUpgradeID, stUpgradeInfo);
DeleteLocalInt(oPC, FUS_CHAT_UPGRADE_CONFIRMATION);
}
}