Mana
Loading...
Searching...
No Matches
itemhandler.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
23
24#include "actorspritemanager.h"
25
28
29namespace ManaServ {
30
32{
33 static const uint16_t _messages[] = {
36 0
37 };
38 handledMessages = _messages;
39}
40
42{
43 switch (msg.getId())
44 {
46 case GPMSG_ITEMS:
47 {
48 while (msg.getUnreadLength())
49 {
50 int itemId = msg.readInt16();
51 int x = msg.readInt16();
52 int y = msg.readInt16();
53 int id = (x << 16) | y; // dummy id
54
55 if (itemId)
56 {
57 actorSpriteManager->createItem(id, itemId, Vector(x, y));
58 }
59 else if (FloorItem *item = actorSpriteManager->findItem(id))
60 {
62 }
63 }
64 } break;
65 }
66}
67
68} // namespace ManaServ
ActorSpriteManager * actorSpriteManager
Definition game.cpp:110
FloorItem * findItem(int id) const
Returns a specific FloorItem, by id.
void destroyActor(ActorSprite *actor)
Immediately destroys the given actor.
FloorItem * createItem(int id, int itemId, const Vector &position)
Create a FloorItem and add it to the list of ActorSprites.
An item lying on the floor.
Definition flooritem.h:32
void handleMessage(MessageIn &msg) override
Used for parsing an incoming message from manaserv.
Definition messagein.h:37
uint16_t readInt16()
Reads an unsigned 16-bit integer from the message.
Definition messagein.cpp:58
unsigned int getUnreadLength() const
Returns the length of unread data.
Definition messagein.h:54
uint16_t getId() const
Returns the message ID.
Definition messagein.h:44
const uint16_t * handledMessages
Vector class.
Definition vector.h:33