Chunk is purely a wrapper class, any 'state variables', like 'characters in room...
[UnsignedByte.git] / src / Core / Editors / EditorPlaying.cpp
blob9e7a3686730779af76b3a888321483a0ab68de52
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 "EditorPlaying.h"
22 #include "EditorMovement.h"
23 #include "UBSocket.h"
24 #include "Array.h"
25 #include "Assert.h"
26 #include "StringUtilities.h"
27 #include "Account.h"
28 #include "Character.h"
29 #include "PCharacter.h"
30 #include "PCharacterManager.h"
31 #include "Chunk.h"
32 #include "ChunkManager.h"
33 #include "Managers.h"
35 using mud::PCharacter;
37 typedef EditorPlaying E;
38 typedef CommandObject<E> O;
39 typedef CommandBinding<E> B;
41 static O listCommands("Commands",&E::listCommands);
42 static O showScore( "Score", &E::showScore);
43 static O look( "Look", &E::look);
44 static O say( "Say", &E::say);
45 static O startMovement("Movement", &E::startMovement);
46 static O deleteCharacter("Delete",&E::deleteCharacter);
47 static O quitEditor("Quit", &E::quitEditor);
49 static const B commands[] = {
50 B("?", listCommands),
51 B("delete", deleteCharacter),
52 B("go", startMovement),
53 B("look", look),
54 B("quit", quitEditor),
55 B("say", say),
56 B("score", showScore),
59 EditorPlaying::EditorPlaying(UBSocket* sock, mud::PCharacterPtr character) :
60 Editor(sock),
61 m_commands(commands, array_size(commands)),
62 m_char(character)
64 long chunkid = m_char->getChunk();
65 mud::ChunkPtr inchunk = mud::Managers::Get()->Chunk->GetByKey(chunkid);
66 inchunk->addCharacter(m_char->getID());
68 std::string msg = m_char->getName();
69 msg.append(" enters the realm.\n");
71 inchunk->Send(msg);
73 m_char->OnSend(String::Get()->box(m_commands.getCommandsVector(), "Playing"));
76 EditorPlaying::~EditorPlaying(void)
78 m_char->Save();
79 mud::PCharacterManager::Get()->UnloadByKey(m_char->getID());
82 std::string EditorPlaying::lookup(const std::string& action)
84 const PlayingCommand* act = m_commands.getObject(action);
85 if(act)
86 return act->getName();
88 return Global::Get()->EmptyString;
91 void EditorPlaying::dispatch(const std::string& action, const std::string& argument)
93 const PlayingCommand* act = m_commands.getObject(action);
95 Assert(act);
96 act->Run(this, argument);
99 void EditorPlaying::listCommands(const std::string& argument)
101 m_char->OnSend(String::Get()->box(m_commands.getCommandsVector(), "Playing"));
102 return;
105 void EditorPlaying::deleteCharacter(const std::string& argument)
107 if(argument.compare("confirm"))
109 m_char->OnSend("If you really want to delete, please type 'delete confirm'.\n");
110 return;
113 printf("Deleting PCharacter %s.\n", m_char->getName().c_str());
115 m_char->OnSend("Goodbye.\n");
116 m_sock->PopEditor();
117 m_char->Delete();
118 return;
121 void EditorPlaying::look(const std::string& argument)
123 m_char->OnLook(argument);
126 void EditorPlaying::quitEditor(const std::string& argument)
128 m_char->OnSend("Thank you for visiting.\n");
130 value_type chunkid = m_char->getChunk();
131 mud::ChunkPtr chunk = mud::Managers::Get()->Chunk->GetByKey(chunkid);
133 std::string msg = m_char->getName();
134 msg.append(" fades from the realm.\n");
136 chunk->Send(msg);
139 m_sock->PopEditor();
142 void EditorPlaying::showScore(const std::string& argument)
144 m_char->OnScore(argument);
147 void EditorPlaying::say(const std::string& argument)
149 m_char->OnSay(argument);
152 void EditorPlaying::startMovement(const std::string& argument)
154 if(!argument.size())
156 m_sock->SetEditor(new EditorMovement(m_sock, m_char));
157 return;
160 m_sock->SetEditor(new EditorMovement(m_sock, m_char, argument));
161 return;