Mana
Loading...
Searching...
No Matches
effecthandler.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#include "effectmanager.h"
26#include "localplayer.h"
27#include "log.h"
28
29#include "gui/viewport.h"
30
33
34namespace ManaServ {
35
37{
38 static const uint16_t _messages[] = {
43 0
44 };
45 handledMessages = _messages;
46}
47
49{
50 switch (msg.getId())
51 {
54 break;
57 break;
60 break;
61 case GPMSG_SHAKE:
62 handleShake(msg);
63 break;
64 default:
65 break;
66 }
67}
68
70{
71 int id = msg.readInt16();
72 uint16_t x = msg.readInt16();
73 uint16_t y = msg.readInt16();
74 effectManager->trigger(id, x, y);
75}
76
78{
79 int eid = msg.readInt16();
80 int bid = msg.readInt16();
82 if (b)
83 effectManager->trigger(eid, b);
84 else
85 Log::warn("CreateEffect called for unknown being #%d", bid);
86}
87
89{
90 const std::string &text = msg.readString();
91 if (local_player)
93}
94
96{
97 int16_t intensityX = 0;
98 int16_t intensityY = 0;
99 float decay;
100 int duration;
101
102 switch (msg.getUnreadLength())
103 {
104 case 4:
105 intensityX = msg.readInt16();
106 intensityY = msg.readInt16();
107 viewport->shakeScreen(intensityX, intensityY);
108 break;
109 case 6:
110 intensityX = msg.readInt16();
111 intensityY = msg.readInt16();
112 decay = msg.readInt16() / 10000.0f;
113 viewport->shakeScreen(intensityX, intensityY, decay);
114 break;
115 case 8:
116 intensityX = msg.readInt16();
117 intensityY = msg.readInt16();
118 decay = msg.readInt16() / 10000.0f;
119 duration = msg.readInt16();
120 viewport->shakeScreen(intensityX, intensityY, decay, duration);
121 break;
122 default:
123 Log::warn("Received GPMSG_SHAKE message with unexpected length of %d bytes", msg.getUnreadLength());
124 }
125}
126
127} // namespace ManaServ
ActorSpriteManager * actorSpriteManager
Definition game.cpp:110
Being * findBeing(int id) const
Returns a specific Being, by id;.
Definition being.h:65
bool trigger(int id, Being *being, int rotation=0)
Triggers a effect with the id, at the specified being, and with the given rotation in degree: 0° = Do...
void addMessageToQueue(const std::string &message, int color=UserPalette::EXP_INFO)
void handleShake(MessageIn &msg)
void handleCreateEffectBeing(MessageIn &msg)
void handleCreateEffectPos(MessageIn &msg)
void handleCreateTextParticle(MessageIn &msg)
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
std::string readString(int length=-1)
Reads a string.
Definition messagein.cpp:92
uint16_t getId() const
Returns the message ID.
Definition messagein.h:44
const uint16_t * handledMessages
void shakeScreen(int intensity)
Makes the screen shake in a random direction.
Definition viewport.cpp:243
EffectManager * effectManager
Definition game.cpp:114
Viewport * viewport
Viewport on the map.
Definition game.cpp:115
LocalPlayer * local_player
void warn(const char *log_text,...) LOG_PRINTF_ATTR