mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-31 00:15:54 -04:00
162 lines
5.3 KiB
Plaintext
162 lines
5.3 KiB
Plaintext
/**
|
|
* Title: library.fs_quests_cc.scriptlib
|
|
* Description: Utility functions for the fs village phase 2 and 3 community crafting quests
|
|
*/
|
|
|
|
/***** INCLUDES ********************************************************/
|
|
|
|
include library.community_crafting;
|
|
include library.fs_dyn_village;
|
|
include library.fs_quests;
|
|
include library.quests;
|
|
|
|
|
|
/***** CONSTANTS *******************************************************/
|
|
|
|
const java.text.NumberFormat floatFormat = new java.text.DecimalFormat("###0.00%");
|
|
|
|
const string SCRIPTVAR_CRAFTING_TRACKER = fs_dyn_village.OBJVAR_MY_MASTER_OBJECT;
|
|
const string SCRIPTVAR_VILLAGE_PHASE = "community_crafting.village_phase";
|
|
const string SCRIPTVAR_TRACKING_QUALITY = "community_crafting.quality";
|
|
const string SCRIPTVAR_TRACKING_QUANTITY = "community_crafting.quantity";
|
|
const string SCRIPTVAR_TRACKING_SLOTS = "community_crafting.slots";
|
|
const string SCRIPTVAR_TRACKING_NUM_SLOTS = "community_crafting.numSlots";
|
|
const string SCRIPTVAR_MIN_INGREDIENTS = "community_crafting.minIngredients";
|
|
|
|
const string_id SID_RANKINGS_TITLE = new string_id("crafting", "player_rankings");
|
|
const string_id SID_ATTRIBUTES_TITLE = new string_id("crafting", "project_attributes");
|
|
const string_id SID_NO_PLAYERS = new string_id("crafting", "no_players");
|
|
const string_id SID_ATTRIBUTES_PROMPT = new string_id("crafting", "attributes_prompt");
|
|
const string_id SID_QUALITY_PROMPT = new string_id("crafting", "quality_prompt");
|
|
const string_id SID_QUALITY_PROMPT_LIMITED = new string_id("crafting", "quality_prompt_limited");
|
|
const string_id SID_QUANTITY_PROMPT = new string_id("crafting", "quantity_prompt");
|
|
const string_id SID_QUANTITY_PROMPT_LIMITED = new string_id("crafting", "quantity_prompt_limited");
|
|
|
|
|
|
/***** FUNCTIONS *******************************************************/
|
|
|
|
boolean testCommunityCraftingEnabled (obj_id npc, int phase)
|
|
{
|
|
if (utils.getIntScriptVar(npc, SCRIPTVAR_VILLAGE_PHASE) != phase)
|
|
return false;
|
|
|
|
obj_id craftingTracker = utils.getObjIdScriptVar(npc, SCRIPTVAR_CRAFTING_TRACKER);
|
|
if (isIdValid(craftingTracker))
|
|
{
|
|
return community_crafting.isSessionActive(craftingTracker);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Displays the community crafting quest project attributes to a player.
|
|
*/
|
|
void showPlayerProjectAttribs(obj_id npc, obj_id player, int phase)
|
|
{
|
|
if (testCommunityCraftingEnabled(npc, phase))
|
|
{
|
|
obj_id craftingTracker = utils.getObjIdScriptVar(npc, SCRIPTVAR_CRAFTING_TRACKER);
|
|
if (!isIdValid(craftingTracker))
|
|
return;
|
|
|
|
Vector names = new Vector();
|
|
Vector values = new Vector();
|
|
if (!community_crafting.getProjectAttributes(craftingTracker, names, values))
|
|
return;
|
|
|
|
string[] attributes = new string[names.size()];
|
|
for (int i = 0; i < attributes.length; ++i)
|
|
{
|
|
// format the values to a percent-type display
|
|
double f = ((Float)(values.get(i))).doubleValue();
|
|
values.set(i, floatFormat.format(f / 1000.0));
|
|
attributes[i] = "@" + names.get(i) + " \\>200" + values.get(i);
|
|
}
|
|
|
|
int pid = sui.listbox(player, "@" + SID_ATTRIBUTES_PROMPT, "@" + SID_ATTRIBUTES_TITLE, sui.OK_ONLY, attributes);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Displays the community crafting quest project player rankings to a player.
|
|
*/
|
|
void showPlayerProjectStats(obj_id npc, obj_id player, int slot, boolean quality, int phase)
|
|
{
|
|
if (testCommunityCraftingEnabled(npc, phase))
|
|
{
|
|
obj_id craftingTracker = utils.getObjIdScriptVar(npc, SCRIPTVAR_CRAFTING_TRACKER);
|
|
if (!isIdValid(craftingTracker))
|
|
return;
|
|
|
|
string_id prompt = SID_QUANTITY_PROMPT;
|
|
Vector playerIds = new Vector();
|
|
Vector playerNames = new Vector();
|
|
Vector values = new Vector();
|
|
if (!community_crafting.getPlayerRanking(craftingTracker, playerIds, playerNames, values, !quality, slot))
|
|
{
|
|
return;
|
|
}
|
|
if (quality)
|
|
{
|
|
prompt = SID_QUALITY_PROMPT;
|
|
for (int i = 0; i < values.size(); ++i)
|
|
{
|
|
// format the values to a percent-type display
|
|
double f = ((Float)(values.get(i))).doubleValue();
|
|
values.set(i, floatFormat.format(f / 100.0));
|
|
}
|
|
}
|
|
|
|
// if the number of players is greater than the sui limit (currently 50), we will only show
|
|
// the top 49 players plus the player asking for the stats
|
|
Vector rankings = new Vector();
|
|
boolean skippingPlayers = false;
|
|
boolean addedPlayer = false;
|
|
int count = 0;
|
|
for (int i = 0; i < playerIds.size() && count < sui.MAX_ARRAY_SIZE; ++i)
|
|
{
|
|
if (isIdValid((obj_id)(playerIds.get(i))))
|
|
{
|
|
if (playerIds.get(i) == player)
|
|
{
|
|
// highlight the player who's requesting the list
|
|
rankings.add(
|
|
"\\#pcontrast1 " +
|
|
getPlayerName((obj_id)(playerIds.get(i))) +
|
|
"\\>200" +
|
|
values.get(i) +
|
|
"\\#."
|
|
);
|
|
++count;
|
|
addedPlayer = true;
|
|
}
|
|
else if ((addedPlayer && count < sui.MAX_ARRAY_SIZE) || (!addedPlayer && count < sui.MAX_ARRAY_SIZE - 1))
|
|
{
|
|
rankings.add(
|
|
getPlayerName((obj_id)(playerIds.get(i))) +
|
|
"\\>200" +
|
|
values.get(i)
|
|
);
|
|
++count;
|
|
}
|
|
else
|
|
skippingPlayers = true;
|
|
}
|
|
}
|
|
if (rankings.size() == 0)
|
|
rankings.add("@" + SID_NO_PLAYERS);
|
|
if ( skippingPlayers )
|
|
{
|
|
if ( prompt == SID_QUANTITY_PROMPT )
|
|
prompt = SID_QUANTITY_PROMPT_LIMITED;
|
|
else
|
|
prompt = SID_QUALITY_PROMPT_LIMITED;
|
|
}
|
|
|
|
int pid = sui.listbox(player, "@" + prompt, "@" + SID_RANKINGS_TITLE, sui.OK_ONLY, rankings);
|
|
}
|
|
}
|
|
|
|
|
|
|