Well don't that own? Sorted all the #include's.
[UnsignedByte.git] / src / Core / Editors / EditorPlaying.cpp
blob1f74268966ffbb19abee4b757be21ec6338ddd39
1 /***************************************************************************
2 * Copyright (C) 2008 by Sverre Rabbelier *
3 * sverre@rabbelier.nl *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
21 #include "Account.h"
22 #include "Array.h"
23 #include "Assert.h"
24 #include "Character.h"
25 #include "Chunk.h"
26 #include "ChunkManager.h"
27 #include "EditorMovement.h"
28 #include "EditorPlaying.h"
29 #include "Managers.h"
30 #include "PCharacter.h"
31 #include "PCharacterManager.h"
32 #include "StringUtilities.h"
33 #include "UBSocket.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[] = {
52 B("?", listCommands),
53 B("delete", deleteCharacter),
54 B("exits", listExits),
55 B("glance", listCharacters),
56 B("go", startMovement),
57 B("look", look),
58 B("quit", quitEditor),
59 B("say", say),
60 B("score", showScore),
63 EditorPlaying::EditorPlaying(UBSocket* sock, mud::PCharacterPtr character) :
64 Editor(sock),
65 m_commands(commands, array_size(commands)),
66 m_char(character)
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");
75 inchunk->Send(msg);
77 m_char->OnSend(String::Get()->box(m_commands.getCommandsVector(), "Playing"));
80 EditorPlaying::~EditorPlaying(void)
82 m_char->Save();
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);
89 if(act)
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);
99 Assert(act);
100 act->Run(this, argument);
103 void EditorPlaying::listCommands(const std::string& argument)
105 m_char->OnSend(String::Get()->box(m_commands.getCommandsVector(), "Playing"));
106 return;
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");
114 return;
117 printf("Deleting PCharacter %s.\n", m_char->getName().c_str());
119 m_char->OnSend("Goodbye.\n");
120 m_sock->PopEditor();
121 m_char->Delete();
122 return;
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");
150 chunk->Send(msg);
153 m_sock->PopEditor();
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)
168 if(!argument.size())
170 m_sock->SetEditor(new EditorMovement(m_sock, m_char));
171 return;
174 m_sock->SetEditor(new EditorMovement(m_sock, m_char, argument));
175 return;