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"
39 #include "CharacterManager.h"
43 Character::Character(SavableManagerPtr character
) :
44 m_character(character
)
49 Character::~Character(void)
54 value_type
Character::getID() const
56 return m_character
->getValue(db::TableImpls::Get()->ENTITIES
->ENTITYID
)->getIntegerValue();
59 const std::string
& Character::getName() const
61 return m_character
->getValue(db::TableImpls::Get()->ENTITIES
->NAME
)->getStringValue();
64 const std::string
& Character::getDescription() const
66 return m_character
->getValue(db::TableImpls::Get()->ENTITIES
->DESCRIPTION
)->getStringValue();
69 value_type
Character::getRace() const
71 return m_character
->getValue(db::TableImpls::Get()->ENTITIES
->FKRACES
)->getIntegerValue();
74 value_type
Character::getChunk() const
76 return m_character
->getValue(db::TableImpls::Get()->ENTITIES
->FKCHUNKS
)->getIntegerValue();
83 void Character::setName(const std::string
& name
)
86 ValuePtr
value(new FieldValue(db::TableImpls::Get()->ENTITIES
->NAME
, name
));
87 m_character
->setValue(value
);
91 void Character::setDescription(const std::string
& description
)
94 ValuePtr
value(new FieldValue(db::TableImpls::Get()->ENTITIES
->DESCRIPTION
, description
));
95 m_character
->setValue(value
);
99 void Character::setRace(value_type race
)
102 ValuePtr
value(new FieldValue(db::TableImpls::Get()->ENTITIES
->FKRACES
, race
));
103 m_character
->setValue(value
);
107 void Character::setChunk(value_type chunk
)
110 ValuePtr
value(new FieldValue(db::TableImpls::Get()->ENTITIES
->FKCHUNKS
, chunk
));
111 m_character
->setValue(value
);
120 void mud::Character::MoveToChunk(value_type chunkid
)
122 mud::ChunkPtr inchunk
= mud::Managers::Get()->Chunk
->GetByKey(getChunk());
123 mud::ChunkPtr tochunk
= mud::Managers::Get()->Chunk
->GetByKey(chunkid
);
125 value_type id
= getID();
127 inchunk
->removeCharacter(id
);
129 tochunk
->addCharacter(id
);
135 void Character::OnSend(const std::string
& msg
)
141 void Character::OnSendf(const char* format
, ...)
144 va_start(args
, format
);
145 OnSend(Global::Get()->sprint(args
, format
));
158 void Character::OnLook(const std::string
& msg
)
160 long chunkid
= getChunk();
161 mud::ChunkPtr chunk
= mud::Managers::Get()->Chunk
->GetByKey(chunkid
);
163 OnSend(chunk
->toString());
165 for(value_types::const_iterator it
= chunk
->begin(); it
!= chunk
->end(); it
++)
167 value_type characterid
= *it
;
169 CharacterPtr pch
= mud::Managers::Get()->Character
->GetByKey(characterid
);
172 OnSendf("(%s) %s.\n", pch
->getName().c_str(), pch
->getDescription().c_str());
178 void Character::OnScore(const std::string
& msg
)
180 OnSend(m_character
->toString());
184 void Character::OnSay(const std::string
& msg
)
188 OnSend("Say what?\n");
192 long chunkid
= getChunk();
193 ChunkPtr chunk
= mud::Managers::Get()->Chunk
->GetByKey(chunkid
);
195 std::string line
= getName();
196 line
.append(" says '");
208 void Character::Delete()
211 m_character
->erase();
215 void Character::Save()
222 void Character::Discard()
225 m_character
->discard();
229 bool Character::Exists()
231 return m_character
->exists();
234 SavableManagerPtr
Character::getManager() const
239 TableImplPtr
Character::getTable() const
241 return m_character
->getTable();