diff options
| author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-03-18 22:24:38 +0100 |
|---|---|---|
| committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2013-03-25 20:32:36 +0100 |
| commit | 7aee56f062989c8901322a09b2da40bb028eb222 (patch) | |
| tree | 2c3712c3926121d35b0ef569e1eeed8f42e34b32 /src/game-server/commandhandler.cpp | |
| parent | 8ebd7ef2c200009e6d22b2cfaa3dd0d849155db6 (diff) | |
| download | manaserv-7aee56f062989c8901322a09b2da40bb028eb222.tar.gz manaserv-7aee56f062989c8901322a09b2da40bb028eb222.tar.xz manaserv-7aee56f062989c8901322a09b2da40bb028eb222.zip | |
Changed Item to a component of Actor
Items also have positions, so the ItemComponent only makes sense as part of
an Actor. Later on it will probably be part of an entity that also has an
ActorComponent.
Since it was annoying to update all the places where items were created,
I've introduced a function for this.
The component types are now prefixed with "CT_" because I wanted to introduce
an 'Item' namespace which would otherwise be conflicting. The component types
enum isn't used much in the code so it can look a bit ugly.
Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src/game-server/commandhandler.cpp')
| -rw-r--r-- | src/game-server/commandhandler.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index 6de2224..ad6a1bc 100644 --- a/src/game-server/commandhandler.cpp +++ b/src/game-server/commandhandler.cpp @@ -568,11 +568,11 @@ static void handleItem(Character *player, std::string &args) static void handleDrop(Character *player, std::string &args) { ItemClass *ic; - int value = 0; + int amount = 0; // get arguments std::string itemclass = getArgument(args); - std::string valuestr = getArgument(args); + std::string amountstr = getArgument(args); // check all arguments are there if (itemclass.empty()) @@ -598,26 +598,26 @@ static void handleDrop(Character *player, std::string &args) return; } - //identify the amount - if (valuestr.empty()) + // identify the amount + if (amountstr.empty()) { - value = 1; + amount = 1; } - else if (utils::isNumeric(valuestr)) + else if (utils::isNumeric(amountstr)) { - value = utils::stringToInt(valuestr); + amount = utils::stringToInt(amountstr); } // check for valid amount - if (value <= 0) + if (amount <= 0) { say("Invalid number of items", player); return; } - // create the integer and put it on the map - Item *item = new Item(ic, value); - item->setMap(player->getMap()); - item->setPosition(player->getPosition()); + Entity *item = Item::create(player->getMap(), + player->getPosition(), + ic, amount); + GameState::insertOrDelete(item); // log transaction |
