1 /***************************************************************************
2 * Copyright (C) 2008 by Sverre Rabbelier *
3 * sverre@rabbelier.nl *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
24 #include "Character.h"
26 #include "ChunkManager.h"
27 #include "EditorMovement.h"
28 #include "EditorPlaying.h"
30 #include "PCharacter.h"
31 #include "PCharacterManager.h"
32 #include "StringUtilities.h"
35 using mud::PCharacter
;
37 typedef EditorPlaying E
;
38 typedef CommandObject
<E
> O
;
39 typedef CommandBinding
<E
> B
;
41 static O
listCharacters("Characters",&E::listCharacters
);
42 static O
listCommands( "Commands", &E::listCommands
);
43 static O
listExits( "Exits", &E::listExits
);
44 static O
showScore( "Score", &E::showScore
);
45 static O
look( "Look", &E::look
);
46 static O
say( "Say", &E::say
);
47 static O
startMovement( "Movement", &E::startMovement
);
48 static O
deleteCharacter("Delete", &E::deleteCharacter
);
49 static O
quitEditor( "Quit", &E::quitEditor
);
51 static const B commands
[] = {
53 B("delete", deleteCharacter
),
54 B("exits", listExits
),
55 B("glance", listCharacters
),
56 B("go", startMovement
),
58 B("quit", quitEditor
),
60 B("score", showScore
),
63 EditorPlaying::EditorPlaying(UBSocket
* sock
, mud::PCharacterPtr character
) :
65 m_commands(commands
, array_size(commands
)),
68 long chunkid
= m_char
->getChunk();
69 mud::ChunkPtr inchunk
= mud::Managers::Get()->Chunk
->GetByKey(chunkid
);
70 inchunk
->addCharacter(m_char
->getID());
72 std::string msg
= m_char
->getName();
73 msg
.append(" enters the realm.\n");
77 m_char
->OnSend(String::Get()->box(m_commands
.getCommandsVector(), "Playing"));
80 EditorPlaying::~EditorPlaying(void)
83 mud::PCharacterManager::Get()->UnloadByKey(m_char
->getID());
86 std::string
EditorPlaying::lookup(const std::string
& action
)
88 const PlayingCommand
* act
= m_commands
.getObject(action
);
90 return act
->getName();
92 return Global::Get()->EmptyString
;
95 void EditorPlaying::dispatch(const std::string
& action
, const std::string
& argument
)
97 const PlayingCommand
* act
= m_commands
.getObject(action
);
100 act
->Run(this, argument
);
103 void EditorPlaying::listCommands(const std::string
& argument
)
105 m_char
->OnSend(String::Get()->box(m_commands
.getCommandsVector(), "Playing"));
109 void EditorPlaying::deleteCharacter(const std::string
& argument
)
111 if(argument
.compare("confirm"))
113 m_char
->OnSend("If you really want to delete, please type 'delete confirm'.\n");
117 printf("Deleting PCharacter %s.\n", m_char
->getName().c_str());
119 m_char
->OnSend("Goodbye.\n");
125 void EditorPlaying::look(const std::string
& argument
)
127 m_char
->OnLook(argument
);
130 void EditorPlaying::listExits(const std::string
& argument
)
132 m_char
->OnExits(argument
);
135 void EditorPlaying::listCharacters(const std::string
& argument
)
137 m_char
->OnCharactersInRoom(argument
);
140 void EditorPlaying::quitEditor(const std::string
& argument
)
142 m_char
->OnSend("Thank you for visiting.\n");
144 value_type chunkid
= m_char
->getChunk();
145 mud::ChunkPtr chunk
= mud::Managers::Get()->Chunk
->GetByKey(chunkid
);
147 std::string msg
= m_char
->getName();
148 msg
.append(" fades from the realm.\n");
156 void EditorPlaying::showScore(const std::string
& argument
)
158 m_char
->OnScore(argument
);
161 void EditorPlaying::say(const std::string
& argument
)
163 m_char
->OnSay(argument
);
166 void EditorPlaying::startMovement(const std::string
& argument
)
170 m_sock
->SetEditor(new EditorMovement(m_sock
, m_char
));
174 m_sock
->SetEditor(new EditorMovement(m_sock
, m_char
, argument
));