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 ***************************************************************************/
21 #include "EditorPlaying.h"
22 #include "EditorMovement.h"
26 #include "StringUtilities.h"
28 #include "Character.h"
29 #include "PCharacter.h"
30 #include "PCharacterManager.h"
32 #include "ChunkManager.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
[] = {
51 B("delete", deleteCharacter
),
52 B("go", startMovement
),
54 B("quit", quitEditor
),
56 B("score", showScore
),
59 EditorPlaying::EditorPlaying(UBSocket
* sock
, mud::PCharacterPtr character
) :
61 m_commands(commands
, array_size(commands
)),
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");
73 m_char
->OnSend(String::Get()->box(m_commands
.getCommandsVector(), "Playing"));
76 EditorPlaying::~EditorPlaying(void)
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
);
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
);
96 act
->Run(this, argument
);
99 void EditorPlaying::listCommands(const std::string
& argument
)
101 m_char
->OnSend(String::Get()->box(m_commands
.getCommandsVector(), "Playing"));
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");
113 printf("Deleting PCharacter %s.\n", m_char
->getName().c_str());
115 m_char
->OnSend("Goodbye.\n");
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");
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
)
156 m_sock
->SetEditor(new EditorMovement(m_sock
, m_char
));
160 m_sock
->SetEditor(new EditorMovement(m_sock
, m_char
, argument
));