summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2013-09-08 21:50:08 +0200
committerErik Schilling <ablu.erikschilling@googlemail.com>2013-09-08 21:50:08 +0200
commit9c780f3d547e11bc6585033b2bf8c1a233aaf9d9 (patch)
treefde539b8b75bba7195e3d474eaaa8f3a6a6ca750
parent54389afd7ba9fecf0761333185145e968e2453ae (diff)
downloadmanaserv-9c780f3d547e11bc6585033b2bf8c1a233aaf9d9.tar.gz
manaserv-9c780f3d547e11bc6585033b2bf8c1a233aaf9d9.tar.bz2
manaserv-9c780f3d547e11bc6585033b2bf8c1a233aaf9d9.tar.xz
manaserv-9c780f3d547e11bc6585033b2bf8c1a233aaf9d9.zip
Allow to use the name of attributes in @attribute
-rw-r--r--src/game-server/commandhandler.cpp28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp
index 44559a5e..919ce7fc 100644
--- a/src/game-server/commandhandler.cpp
+++ b/src/game-server/commandhandler.cpp
@@ -1070,11 +1070,11 @@ static void handleAttribute(Entity *player, std::string &args)
// get arguments
std::string character = getArgument(args);
- std::string attrstr = getArgument(args);
+ std::string attribute = getArgument(args);
std::string valuestr = getArgument(args);
// check all arguments are there
- if (character.empty() || valuestr.empty() || attrstr.empty())
+ if (character.empty() || valuestr.empty() || attribute.empty())
{
say("Invalid number of arguments given.", player);
say("Usage: @attribute <character> <attribute> <value>", player);
@@ -1098,16 +1098,24 @@ static void handleAttribute(Entity *player, std::string &args)
}
// check they are really integers
- if (!utils::isNumeric(valuestr) || !utils::isNumeric(attrstr))
+ if (!utils::isNumeric(valuestr))
{
say("Invalid argument", player);
return;
}
- // put the attribute into an integer
- int attributeId = utils::stringToInt(attrstr);
+ AttributeInfo *attributeInfo;
+ if (utils::isNumeric(attribute))
+ {
+ const int id = utils::stringToInt(attribute);
+ attributeInfo = attributeManager->getAttributeInfo(id);
+ }
+ else
+ {
+ attributeInfo = attributeManager->getAttributeInfo(attribute);
+ }
- if (attributeId < 0)
+ if (!attributeInfo)
{
say("Invalid Attribute", player);
return;
@@ -1124,20 +1132,18 @@ static void handleAttribute(Entity *player, std::string &args)
auto *beingComponent = other->getComponent<BeingComponent>();
- auto *attribute = attributeManager->getAttributeInfo(attributeId);
-
- if (!attribute)
+ if (!attributeInfo)
{
say("Invalid attribute", player);
return;
}
// change the player's attribute
- beingComponent->setAttribute(*other, attribute, value);
+ beingComponent->setAttribute(*other, attributeInfo, value);
// log transaction
std::stringstream msg;
- msg << "User changed attribute " << attribute->id << " of player "
+ msg << "User changed attribute " << attributeInfo->id << " of player "
<< beingComponent->getName()
<< " to " << value;
int databaseId =