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 ***************************************************************************/
27 #include "StringUtilities.h"
28 #include "FieldImpls.h"
29 #include "TableImpls.h"
31 #include "Character.h"
33 #include "RaceManager.h"
36 #include "ChunkManager.h"
37 #include "AreaManager.h"
42 Character::Character(SavableManagerPtr character
) :
43 m_character(character
)
48 Character::~Character(void)
53 value_type
Character::getID() const
55 return m_character
->getValue(db::TableImpls::Get()->ENTITIES
->ENTITYID
)->getIntegerValue();
58 const std::string
& Character::getName() const
60 return m_character
->getValue(db::TableImpls::Get()->ENTITIES
->NAME
)->getStringValue();
63 const std::string
& Character::getDescription() const
65 return m_character
->getValue(db::TableImpls::Get()->ENTITIES
->DESCRIPTION
)->getStringValue();
68 value_type
Character::getRace() const
70 return m_character
->getValue(db::TableImpls::Get()->ENTITIES
->FKRACES
)->getIntegerValue();
73 value_type
Character::getChunk() const
75 return m_character
->getValue(db::TableImpls::Get()->ENTITIES
->FKCHUNKS
)->getIntegerValue();
82 void Character::setName(const std::string
& name
)
85 ValuePtr
value(new FieldValue(db::TableImpls::Get()->ENTITIES
->NAME
, name
));
86 m_character
->setValue(value
);
90 void Character::setDescription(const std::string
& description
)
93 ValuePtr
value(new FieldValue(db::TableImpls::Get()->ENTITIES
->DESCRIPTION
, description
));
94 m_character
->setValue(value
);
98 void Character::setRace(value_type race
)
101 ValuePtr
value(new FieldValue(db::TableImpls::Get()->ENTITIES
->FKRACES
, race
));
102 m_character
->setValue(value
);
106 void Character::setChunk(value_type chunk
)
109 ValuePtr
value(new FieldValue(db::TableImpls::Get()->ENTITIES
->FKCHUNKS
, chunk
));
110 m_character
->setValue(value
);
119 void mud::Character::MoveToChunk(value_type chunkid
)
121 mud::ChunkPtr inchunk
= mud::Managers::Get()->Chunk
->GetByKey(getChunk());
122 mud::ChunkPtr tochunk
= mud::Managers::Get()->Chunk
->GetByKey(chunkid
);
124 value_type id
= getID();
127 inchunk
->removeCharacter(id
);
128 tochunk
->addCharacter(id
);
134 void Character::OnSend(const std::string
& msg
)
140 void Character::OnSendf(const char* format
, ...)
143 va_start(args
, format
);
144 OnSend(Global::Get()->sprint(args
, format
));
157 void Character::OnLook(const std::string
& msg
)
161 long chunkid
= getChunk();
162 mud::ChunkPtr chunk
= mud::Managers::Get()->Chunk
->GetByKey(chunkid
);
164 OnSend(chunk
->toString());
166 Characters chars = room->getCharacters();
167 for(Characters::iterator it = chars.begin(); it != chars.end(); it++)
169 OnSendf("(%s) %s.\n", (*it)->getName().c_str(), (*it)->getDescription().c_str());
175 catch (RowNotFoundException
& e
)
177 Global::Get()->bug(e
.what());
182 void Character::OnScore(const std::string
& msg
)
184 OnSend(m_character
->toString());
188 void Character::OnSay(const std::string
& msg
)
192 OnSend("Say what?\n");
198 long chunkid
= getChunk();
199 ChunkPtr chunk
= mud::Managers::Get()->Chunk
->GetByKey(chunkid
);
201 std::string line
= getName();
202 line
.append(" says '");
209 catch (RowNotFoundException
& e
)
211 Global::Get()->bug(e
.what());
220 void Character::Delete()
223 m_character
->erase();
227 void Character::Save()
234 void Character::Discard()
237 m_character
->discard();
241 bool Character::Exists()
243 return m_character
->exists();
246 SavableManagerPtr
Character::getManager() const
251 TableImplPtr
Character::getTable() const
253 return m_character
->getTable();