/
goto.c
57 lines (53 loc) · 1.84 KB
/
goto.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//*****************************************************************************
// Copyright (c) 2018 - Allen Cummings, RealmsMUD, All rights reserved. See
// the accompanying LICENSE file for details.
//*****************************************************************************
inherit "/lib/commands/baseCommand.c";
/////////////////////////////////////////////////////////////////////////////
public nomask void reset(int arg)
{
if (!arg)
{
addCommandTemplate("goto ##Target##");
}
}
/////////////////////////////////////////////////////////////////////////////
public nomask int execute(string command, object initiator)
{
int ret = 0;
if (canExecuteCommand(command) && initiator->hasExecuteAccess("goto"))
{
string targetString = getTargetString(initiator, command);
object target = find_player(targetString) ||
find_living(targetString);
object destination = 0;
if (target)
{
destination = environment(target) || target;
}
else if(file_size(targetString) > 0)
{
destination = load_object(targetString);
}
else if (file_size(sprintf("%s/%s", initiator->pwd(),
targetString)) > 0)
{
destination = load_object(sprintf("%s/%s", initiator->pwd(),
targetString));
}
if(destination)
{
ret = 1;
displayMessage(sprintf("##InitiatorName## %s\n",
initiator->MagicalMessageOut()), initiator);
move_object(initiator, destination);
displayMessage(sprintf("##InitiatorName## %s\n",
initiator->MagicalMessageIn()), initiator);
}
else
{
notify_fail(sprintf("Could not go to '%s'.\n", targetString));
}
}
return ret;
}