Skip to content
Permalink
Browse files

Merged PR 537: Merge 612_worker_assignment to master

Related work items: #612
  • Loading branch information...
realms-mud committed Jul 11, 2019
1 parent 2e64d18 commit abd917e81a43f2f4b25c3b9b3a812e38f40f0d8b
@@ -72,3 +72,27 @@ public nomask object getHenchmanFromData(mapping data, object user)

return ret;
}

/////////////////////////////////////////////////////////////////////////////
public nomask string getBenefits(object henchman, string type)
{
return "";
}

/////////////////////////////////////////////////////////////////////////////
public nomask string getBenefitLevel(object henchman, string type)
{
string traits = implode(henchman->Traits(type), "");
string santizedType = regreplace(type, " .*", "", 1);
string ret = "low end worker";

if (sizeof(regexp(({ traits }), "master-" + santizedType)))
{
ret = "elite worker";
}
else if (sizeof(regexp(({ traits }), "journeyman-" + santizedType)))
{
ret = "average worker";
}
return ret;
}
@@ -78,12 +78,45 @@ public nomask string getComponentWorkerInfo(object user, mapping componentData)

/////////////////////////////////////////////////////////////////////////////
public nomask string getWorkersOfType(object user, string type,
string location)
string location, int quantity, mapping currentSelections)
{
string ret = "\n";
string colorConfiguration = user->colorConfiguration();
string charset = user->charsetConfiguration();

return "";
if (quantity == sizeof(currentSelections))
{
ret += configuration->decorate(
sprintf("All required %s have been assigned.\nSelect 'Confirm "
"Selections' to continue.\n", pluralizeValue(type, 1)),
"selected", "player domains", colorConfiguration);
}
else
{
ret += configuration->decorate(
sprintf("%s selected: %d of %d.\n", pluralizeValue(type),
sizeof(currentSelections), quantity),
"selected", "player domains", colorConfiguration);
}

if (sizeof(currentSelections))
{
foreach(string entry in m_indices(currentSelections))
{
string details = currentSelections[entry]["benefits"];
ret += " " +
configuration->decorate(
sprintf("%-25s", (sizeof(entry) > 25) ?
entry[0..21] + "..." : entry),
currentSelections[entry]["level"], "player domains",
colorConfiguration) +
configuration->decorate(
sprintf("Benefits: %-40s\n", (sizeof(details) > 4000) ?
details[0..36] + "..." : details),
"heading", "player domains", colorConfiguration);
}
}
return ret;
}

/////////////////////////////////////////////////////////////////////////////
@@ -51,8 +51,6 @@ public nomask void reset(int arg)
/////////////////////////////////////////////////////////////////////////////
protected nomask void setUpUserForSelection()
{
object dictionary = load_object("/lib/dictionaries/domainDictionary.c");

if (dictionary && WorkerType)
{
Description = "Assign Workers:\n" +
@@ -62,7 +60,8 @@ protected nomask void setUpUserForSelection()
dictionary->pluralizeValue(WorkerType, 1),
dictionary->getLocationDisplayName(Location)), 78),
"description", "selector", colorConfiguration) +
dictionary->getWorkersOfType(User, WorkerType, Location);
dictionary->getWorkersOfType(User, WorkerType, Location,
QuantityNeeded, Selections);

Data = dictionary->getWorkersByTypeMenu(User, Location, WorkerType,
(QuantityNeeded - sizeof(Selections)) != 0);
@@ -104,8 +103,11 @@ protected nomask string displayDetails(string choice)
/////////////////////////////////////////////////////////////////////////////
protected string choiceFormatter(string choice)
{
string choiceColor = member(Data[choice], "is disabled") &&
Data[choice]["is disabled"] ? "choice disabled" : "choice enabled";
string choiceColor = ((member(Data[choice], "is disabled") &&
Data[choice]["is disabled"]) || ((QuantityNeeded == sizeof(Selections)) &&
member(Data[choice], "data") &&
!member(Selections, Data[choice]["type"]))) ?
"choice disabled" : "choice enabled";

return sprintf("[%s]%s - %s%s%s",
configuration->decorate("%s", "number", "selector", colorConfiguration),
@@ -132,11 +134,15 @@ protected nomask int processSelection(string selection)
}
else if (!Data[selection]["is disabled"])
{
if (!member(Selections, Data[selection]["type"]))
if (!member(Selections, Data[selection]["type"]) &&
(QuantityNeeded > sizeof(Selections)))
{
Selections[Data[selection]["type"]] =
Data[selection]["data"];

object worker = Data[selection]["data"];
Selections[Data[selection]["type"]] = ([
"object": worker,
"benefits": dictionary->getBenefits(worker, WorkerType),
"level": dictionary->getBenefitLevel(worker, WorkerType)
]);
}
else
{
@@ -6,48 +6,6 @@ inherit "/lib/tests/framework/testFixture.c";

object Player;
object Selector;
object Location;

/////////////////////////////////////////////////////////////////////////////
void Init()
{
ignoreList += ({ "SetupHenchmen" });
}

/////////////////////////////////////////////////////////////////////////////
void SetupHenchmen()
{
Player->addHenchman("argalach castle", ([
"name": "Tirian",
"house": "Arthellyn",
"gender": "male",
"type": "architect",
"persona": "swordsman",
"level": 12,
"activity": "idle"
]));

Player->addHenchman("argalach castle", ([
"name": "Beren",
"house": "Marannuminas",
"gender": "male",
"type": "architect",
"persona": "swordsman",
"level": 10,
"activity": "building"
]));

Player->addHenchman("argalach castle", ([
"name": "Derek",
"house": "Evendim",
"gender": "male",
"type": "craftsman",
"traits": ({ "lib/instances/traits/domains/journeyman-carpenter.c" }),
"persona": "swordsman",
"level": 10,
"activity": "building"
]));
}

/////////////////////////////////////////////////////////////////////////////
void Setup()
@@ -56,17 +14,13 @@ void Setup()
Selector->setLocation("argalach castle");
Selector->setConstructionData((["type":"keep", "name" : "stone keep"]));

Location = load_object("/lib/dictionaries/domains/rooms/keep-1x1.c");

Player = clone_object("/lib/tests/support/services/mockPlayer.c");
Player->Name("bob");
Player->addCommands();
Player->colorConfiguration("none");
Player->charsetConfiguration("ascii");
Player->addPlayerHolding("argalach castle");

Location->enterEnvironment(Player);

move_object(Selector, Player);
}

@@ -75,7 +29,6 @@ void CleanUp()
{
destruct(Selector);
destruct(Player);
destruct(Location);
}

/////////////////////////////////////////////////////////////////////////////
@@ -497,74 +450,16 @@ void CorrectlyDisplaysWorkerMenu()
/////////////////////////////////////////////////////////////////////////////
void CorrectlyDisplaysWorkerSelectionMenu()
{
SetupHenchmen();
Player->colorConfiguration("none");

Selector->initiateSelector(Player);
command("4", Player);
command("2", Player);

ExpectEq("Building Projects - Assign Workers:\n"
"From this menu, you can select the architects who will be executing your\n"
"project in your holdings at Argalach Castle.\n"
"\n"
"[1] - Beren Marannuminas busy [2] - Tirian Arthellyn \n"
"[3] - Confirm Selections N/A [4] - Exit Building Menu \n"
"You must select a number from 1 to 4.\n"
"Type 'exit' if you do not wish to make a selection at this time.\n"
"For details on a given choice, type 'describe X' (or '? X') where\n"
"X is the option about which you would like further details.\n"
"You have 1 worker left to assign.\n",
Player->caughtMessage());
}

/////////////////////////////////////////////////////////////////////////////
void SelectingWorkerActsAsToggle()
{
SetupHenchmen();
Player->colorConfiguration("none");

Selector->initiateSelector(Player);
command("4", Player);
command("2", Player);

ExpectEq("Building Projects - Assign Workers:\n"
"From this menu, you can select the architects who will be executing your\n"
"project in your holdings at Argalach Castle.\n"
"\n"
"[1] - Beren Marannuminas busy [2] - Tirian Arthellyn \n"
"[3] - Confirm Selections N/A [4] - Exit Building Menu \n"
"You must select a number from 1 to 4.\n"
"Type 'exit' if you do not wish to make a selection at this time.\n"
"For details on a given choice, type 'describe X' (or '? X') where\n"
"X is the option about which you would like further details.\n"
"You have 1 worker left to assign.\n",
Player->caughtMessage());

command("2", Player);

ExpectEq("Building Projects - Assign Workers:\n"
"From this menu, you can select the architects who will be executing your\n"
"project in your holdings at Argalach Castle.\n"
"\n"
"[1] - Beren Marannuminas busy [2] - Tirian Arthellyn (*) \n"
"[3] - Confirm Selections [4] - Exit Building Menu \n"
"You must select a number from 1 to 4.\n"
"Type 'exit' if you do not wish to make a selection at this time.\n"
"For details on a given choice, type 'describe X' (or '? X') where\n"
"X is the option about which you would like further details.\n"
"You have 0 workers left to assign.\n",
Player->caughtMessage());

command("2", Player);

ExpectEq("Building Projects - Assign Workers:\n"
"From this menu, you can select the architects who will be executing your\n"
"project in your holdings at Argalach Castle.\n"
"\n"
"[1] - Beren Marannuminas busy [2] - Tirian Arthellyn \n"
"[3] - Confirm Selections N/A [4] - Exit Building Menu \n"
"You must select a number from 1 to 4.\n"
"\nArchitects selected: 0 of 1.\n\n"
"[1] - Confirm Selections N/A [2] - Exit Building Menu \n"
"You must select a number from 1 to 2.\n"
"Type 'exit' if you do not wish to make a selection at this time.\n"
"For details on a given choice, type 'describe X' (or '? X') where\n"
"X is the option about which you would like further details.\n"

0 comments on commit abd917e

Please sign in to comment.
You can’t perform that action at this time.