Skip to content
Permalink
Browse files

Merged PR 479: Merge 175_locks to master

Related work items: #586, #175
  • Loading branch information...
realms-mud committed Apr 4, 2019
1 parent ab84859 commit dbf324f817374701296438ffbb9311dccd6cd971
@@ -390,13 +390,23 @@ public nomask string parseTemplate(string template, string perspective,

/////////////////////////////////////////////////////////////////////////////
public nomask varargs void displayMessage(string message, object initiator,
object target, string textClass, string type)
object target, string textClass, string type, int checkVisibility,
object location, int suppressInitiator)
{
if (environment(initiator))
{
object *characters = filter(all_inventory(environment(initiator)),
if (!objectp(location))
{
location = environment(initiator);
}
object *characters = filter(all_inventory(location),
(: $1->isRealizationOfLiving() :));

if (suppressInitiator)
{
characters -= ({ initiator });
}

foreach(object person in characters)
{
if (person && objectp(person))
@@ -422,9 +432,13 @@ public nomask varargs void displayMessage(string message, object initiator,
object configuration =
load_object("/lib/dictionaries/configurationDictionary.c");

tell_object(person, configuration->decorate(
format(parsedMessage, 78),
textClass, type, person->colorConfiguration()));
if (!checkVisibility ||
(checkVisibility && person->canSee()))
{
tell_object(person, configuration->decorate(
format(parsedMessage, 78),
textClass, type, person->colorConfiguration()));
}
}
}
}
@@ -515,3 +515,51 @@ public nomask void reset(int arg)
advanceTime();
}
}

/////////////////////////////////////////////////////////////////////////////
public nomask int isValidKey(string key)
{
int ret = stringp(key);
if (ret)
{
if (file_size(key) > 0)
{
object keyObj = load_object(key);
ret = member(inherit_list(keyObj), "lib/items/key.c") > -1;

if (!ret)
{
raise_error(sprintf("ERROR in environment: '%s' is not a "
"valid key object.\n", key));
}
}
else
{
raise_error(sprintf("ERROR in environment: '%s' is not a "
"valid file.\n", key));
}
}
return ret;
}

/////////////////////////////////////////////////////////////////////////////
public nomask object getDoor(string door)
{
object ret = 0;
if (file_size(door) > 0)
{
ret = clone_object(door);

if (member(inherit_list(ret), "lib/environment/doors/baseDoor.c") < 0)
{
raise_error(sprintf("ERROR in environment.c: '%s' is not a "
"valid door object.\n", door));
}
}
else
{
raise_error(sprintf("ERROR in environment.c: '%s' is not a "
"valid file.\n", door));
}
return ret;
}
@@ -151,6 +151,16 @@ addBuilding("/lib/environment/shops/wainwright.c", "north", "/players/maeglin/sp
The pre-fabricated buildings can be found in: `/lib/environment/buildings`. All custom buildings
must inherit from `/lib/environment/buildings/baseBuilding.c`.

If the building you wish to add has a door that should open/close and potentially lock, there is a special
method for adding a building of this nature.

`varargs void addBuildingWithDoor(string building, mixed location, string path, string door, string key, string state);`

This is identical to the `addBuilding` method with the notable addition of two new parameters: door and key. The door
parameter is a string that is the file path to the door environmental element that will be used to describe the door. This must inherit
`/lib/environment/doors/baseDoor.c`. The (optional) key parameter is the file path to the key object that can lock/unlock the door. This key must inherit
`/lib/items/key.c`.

###### Other Features and Static Items
In addition to buildings, you can also add other features or static items.

@@ -231,6 +241,12 @@ varargs void addExit(string direction, string path, string state);
```
TBD

```
varargs void addExitWithDoor(string direction, string path, string door,
string key, string state);
```
TBD

#### Regions
```
void setCoordinates(string region, int x, int y);
@@ -0,0 +1,242 @@
//*****************************************************************************
// Copyright (c) 2019 - Allen Cummings, RealmsMUD, All rights reserved. See
// the accompanying LICENSE file for details.
//*****************************************************************************
inherit "/lib/environment/environmentalElement.c";

private string Key = 0;
private int isCurrentlyLocked = 0;
private int wasManipulated = 0;
private mapping whenLocked = ([]);
private int pickLockLevel = 5;

private object messageParser = load_object("/lib/core/messageParser.c");

/////////////////////////////////////////////////////////////////////////////
public string Type()
{
return "door";
}

/////////////////////////////////////////////////////////////////////////////
public nomask varargs void setKey(string key, int startUnlocked)
{
if (environmentDictionary()->isValidKey(key))
{
Key = key;
isCurrentlyLocked = !startUnlocked;
}
}

/////////////////////////////////////////////////////////////////////////////
public nomask void setPickLockLevel(int level)
{
pickLockLevel = level;
}

/////////////////////////////////////////////////////////////////////////////
private nomask varargs mapping setLockedBySeason(string season)
{
mapping data = ([]);
if (environmentDictionary()->isValidSeason(season))
{
data[season] = 1;
}
else
{
foreach(string item in environmentDictionary()->seasons())
{
data[item] = 1;
}
}
return data;
}

/////////////////////////////////////////////////////////////////////////////
private nomask varargs mapping setLockedTime(string period, string season)
{
mapping data = ([]);
if (environmentDictionary()->isValidTimeOfDay(period))
{
data[period] = setLockedBySeason(season);
}
else
{
foreach(string timeOfDay in environmentDictionary()->timesOfDay())
{
data[timeOfDay] = setLockedBySeason(season);
}
}
return data;
}

/////////////////////////////////////////////////////////////////////////////
public nomask varargs void setWhenLockActive(string state, string period,
string season)
{
string *states = ({});
if (state && (state != ""))
{
states = ({ state });
}
else
{
states = states();

if (!sizeof(states))
{
states = ({ "default" });
}
}

if (sizeof(states))
{
foreach(string stateItem in states)
{
whenLocked[stateItem] = setLockedTime(period, season);
}
}
}

/////////////////////////////////////////////////////////////////////////////
public nomask varargs int isLocked()
{
int ret = isCurrentlyLocked;

string timeOfDay = environmentDictionary()->timeOfDay();
string season = environmentDictionary()->season();

if (!wasManipulated && member(whenLocked, State) &&
member(whenLocked[State], timeOfDay) &&
member(whenLocked[State][timeOfDay], season))
{
ret = whenLocked[State][timeOfDay][season];
}

return ret;
}

/////////////////////////////////////////////////////////////////////////////
public nomask void lock(object initiator)
{
if (objectp(initiator))
{
object messageParser = load_object("/lib/core/messageParser.c");

string message = message = "##InitiatorName## ##Infinitive::try## to "
"lock an already-locked door.";

if (!stringp(Key))
{
message = "##InitiatorName## ##Infinitive::try## to lock the door "
"but ##Infinitive::notice## that it has no lock.";
}
else if (!present_clone(Key, initiator))
{
message = "##InitiatorName## ##Infinitive::try## to lock the door "
"but ##Infinitive::do## not have the key.";
}
else if (!isLocked())
{
isCurrentlyLocked = 1;
wasManipulated = 1;
message = "##InitiatorName## ##Infinitive::lock## the door.";
}
messageParser->displayMessage(message, initiator, 0, "description",
"environment");
}
}

/////////////////////////////////////////////////////////////////////////////
public nomask void unlock(object initiator)
{
if (objectp(initiator))
{
string message = message = "##InitiatorName## ##Infinitive::try## to "
"unlock an already-unlocked door.";

if (!stringp(Key))
{
message = "##InitiatorName## ##Infinitive::try## to unlock the door "
"but ##Infinitive::notice## that it has no lock.";
}
else if (!present_clone(Key, initiator))
{
message = "##InitiatorName## ##Infinitive::try## to unlock the door "
"but ##Infinitive::do## not have the key.";
}
else if (isLocked())
{
isCurrentlyLocked = 0;
wasManipulated = 1;
message = "##InitiatorName## ##Infinitive::unlock## the door.";
}
messageParser->displayMessage(message, initiator, 0, "description",
"environment");
}
}

/////////////////////////////////////////////////////////////////////////////
public void displayLockedMessage(object initiator)
{
messageParser->displayMessage("##InitiatorName## ##Infinitive::try## "
"to go through the door, but it is locked.", initiator, 0,
"description", "environment", 1);
}

/////////////////////////////////////////////////////////////////////////////
public void displayMoveMessage(object initiator, string direction)
{
messageParser->displayMessage(sprintf("##InitiatorName## "
"##Infinitive::go## through the door to the %s.", direction),
initiator, 0, "description", "environment", 1);
}

/////////////////////////////////////////////////////////////////////////////
public void displayCloseMessage(object initiator, object originalLocation)
{
messageParser->displayMessage("The door closes.",
initiator, 0, "description", "environment", 1, originalLocation);
}

/////////////////////////////////////////////////////////////////////////////
public void displayOpenMessage(object initiator)
{
messageParser->displayMessage("The door opens and ##InitiatorName## "
"##Infinitive::enter##.",
initiator, 0, "description", "environment", 1, 0, 1);
}

/////////////////////////////////////////////////////////////////////////////
public nomask void pickLock(object initiator)
{
if (objectp(initiator))
{
string message = message = "##InitiatorName## ##Infinitive::try## to "
"pick the lock of an already-unlocked door.";

if (isLocked(State))
{
if (initiator->getSkill("open lock") < pickLockLevel)
{
message = "##InitiatorName## ##Infinitive::try## to pick the door's "
"lock but ##Infinitive::fail##.";
}
else
{
isCurrentlyLocked = 0;
wasManipulated = 1;
message = "##InitiatorName## ##Infinitive::pick## the lock on the door.";
}
}

messageParser->displayMessage(message, initiator, 0, "description",
"environment");
}
}

/////////////////////////////////////////////////////////////////////////////
public nomask void damageDoor(object initiator)
{

}
@@ -0,0 +1,13 @@
//*****************************************************************************
// Copyright (c) 2019 - Allen Cummings, RealmsMUD, All rights reserved. See
// the accompanying LICENSE file for details.
//*****************************************************************************
inherit "/lib/environment/doors/baseDoor.c";

/////////////////////////////////////////////////////////////////////////////
public void Setup()
{
Name("generic door");

addDescriptionTemplate("a door");
}
Oops, something went wrong.

0 comments on commit dbf324f

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