GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/mercenaryrecv.cpp Lines: 1 104 1.0 %
Date: 2018-06-18 21:15:20 Branches: 0 98 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2018  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "net/eathena/mercenaryrecv.h"
22
23
#include "actormanager.h"
24
#include "notifymanager.h"
25
26
#include "being/localplayer.h"
27
#include "being/mercenaryinfo.h"
28
#include "being/playerinfo.h"
29
30
#include "enums/resources/notifytypes.h"
31
32
#include "gui/windows/skilldialog.h"
33
34
#include "net/messagein.h"
35
36
#include "net/eathena/sp.h"
37
38
#include "utils/checkutils.h"
39
40
#include "debug.h"
41
42
namespace EAthena
43
{
44
45
#define setMercStat(sp, stat) \
46
        case sp: \
47
            PlayerInfo::setStatBase(stat, \
48
                val, \
49
                Notify_true); \
50
            break;
51
52
void MercenaryRecv::processMercenaryUpdate(Net::MessageIn &msg)
53
{
54
    const int sp = msg.readInt16("type");
55
    const int val = msg.readInt32("value");
56
    switch (sp)
57
    {
58
        setMercStat(Sp::ATK1, Attributes::MERC_ATK);
59
        setMercStat(Sp::MATK1, Attributes::MERC_MATK);
60
        setMercStat(Sp::HIT, Attributes::MERC_HIT);
61
        setMercStat(Sp::CRITICAL, Attributes::MERC_CRIT);
62
        setMercStat(Sp::DEF1, Attributes::MERC_DEF);
63
        setMercStat(Sp::MDEF1, Attributes::MERC_MDEF);
64
        setMercStat(Sp::MERCFLEE, Attributes::MERC_FLEE);
65
        setMercStat(Sp::ASPD, Attributes::MERC_ATTACK_DELAY);
66
        setMercStat(Sp::HP, Attributes::MERC_HP);
67
        setMercStat(Sp::MAXHP, Attributes::MERC_MAX_HP);
68
        setMercStat(Sp::SP, Attributes::MERC_MP);
69
        setMercStat(Sp::MAXSP, Attributes::MERC_MAX_MP);
70
        setMercStat(Sp::MERCKILLS, Attributes::MERC_KILLS);
71
        setMercStat(Sp::MERCFAITH, Attributes::MERC_FAITH);
72
        default:
73
            reportAlways("Unknown mercenary stat %d",
74
                sp);
75
            break;
76
    }
77
}
78
79
void MercenaryRecv::processMercenaryInfo(Net::MessageIn &msg)
80
{
81
    if (actorManager == nullptr)
82
        return;
83
    // +++ need create if need mercenary being and update stats
84
    Being *const dstBeing = actorManager->findBeing(
85
        msg.readBeingId("being id"));
86
    PlayerInfo::setStatBase(Attributes::MERC_ATK,
87
        msg.readInt16("atk"),
88
        Notify_true);
89
    PlayerInfo::setStatBase(Attributes::MERC_MATK,
90
        msg.readInt16("matk"),
91
        Notify_true);
92
    PlayerInfo::setStatBase(Attributes::MERC_HIT,
93
        msg.readInt16("hit"),
94
        Notify_true);
95
    PlayerInfo::setStatBase(Attributes::MERC_CRIT,
96
        msg.readInt16("crit/10"),
97
        Notify_true);
98
    PlayerInfo::setStatBase(Attributes::MERC_DEF,
99
        msg.readInt16("def"),
100
        Notify_true);
101
    PlayerInfo::setStatBase(Attributes::MERC_MDEF,
102
        msg.readInt16("mdef"),
103
        Notify_true);
104
    PlayerInfo::setStatBase(Attributes::MERC_FLEE,
105
        msg.readInt16("flee"),
106
        Notify_true);
107
    PlayerInfo::setStatBase(Attributes::MERC_ATTACK_DELAY,
108
        msg.readInt16("attack speed"),
109
        Notify_true);
110
    const std::string name = msg.readString(24, "name");
111
    const int level = msg.readInt16("level");
112
    PlayerInfo::setStatBase(Attributes::MERC_LEVEL,
113
        level,
114
        Notify_true);
115
    PlayerInfo::setStatBase(Attributes::MERC_HP,
116
        msg.readInt32("hp"),
117
        Notify_true);
118
    PlayerInfo::setStatBase(Attributes::MERC_MAX_HP,
119
        msg.readInt32("max hp"),
120
        Notify_true);
121
    PlayerInfo::setStatBase(Attributes::MERC_MP,
122
        msg.readInt32("sp"),
123
        Notify_true);
124
    PlayerInfo::setStatBase(Attributes::MERC_MAX_MP,
125
        msg.readInt32("max sp"),
126
        Notify_true);
127
    PlayerInfo::setStatBase(Attributes::MERC_EXPIRE,
128
        msg.readInt32("expire time"),
129
        Notify_true);
130
    PlayerInfo::setStatBase(Attributes::MERC_FAITH,
131
        msg.readInt16("faith"),
132
        Notify_true);
133
    PlayerInfo::setStatBase(Attributes::MERC_CALLS,
134
        msg.readInt32("calls"),
135
        Notify_true);
136
    PlayerInfo::setStatBase(Attributes::MERC_KILLS,
137
        msg.readInt32("kills"),
138
        Notify_true);
139
    const int range = msg.readInt16("attack range");
140
    PlayerInfo::setStatBase(Attributes::MERC_ATTACK_RANGE,
141
        range,
142
        Notify_true);
143
    PlayerInfo::updateAttrs();
144
145
    if ((dstBeing != nullptr) && (localPlayer != nullptr))
146
    {
147
        MercenaryInfo *const mercenary = new MercenaryInfo;
148
        mercenary->id = dstBeing->getId();
149
        mercenary->name = name;
150
        mercenary->level = level;
151
        mercenary->range = range;
152
        PlayerInfo::setMercenary(mercenary);
153
        PlayerInfo::setMercenaryBeing(dstBeing);
154
    }
155
}
156
157
void MercenaryRecv::processMercenarySkills(Net::MessageIn &msg)
158
{
159
    if (skillDialog != nullptr)
160
        skillDialog->hideSkills(SkillOwner::Mercenary);
161
    const int count = (msg.readInt16("len") - 4) / 37;
162
    for (int f = 0; f < count; f ++)
163
    {
164
        const int skillId = msg.readInt16("skill id");
165
        const SkillType::SkillType inf = static_cast<SkillType::SkillType>(
166
            msg.readInt32("inf"));
167
        const int level = msg.readInt16("skill level");
168
        const int sp = msg.readInt16("sp");
169
        const int range = msg.readInt16("range");
170
        const std::string name = msg.readString(24, "skill name");
171
        const Modifiable up = fromBool(msg.readUInt8("up flag"), Modifiable);
172
        PlayerInfo::setSkillLevel(skillId, level);
173
        if (skillDialog != nullptr)
174
        {
175
            if (!skillDialog->updateSkill(skillId, range, up, inf, sp))
176
            {
177
                skillDialog->addSkill(SkillOwner::Mercenary,
178
                    skillId, name, level, range, up, inf, sp);
179
            }
180
        }
181
    }
182
    if (skillDialog != nullptr)
183
        skillDialog->updateModels();
184
}
185
186
void MercenaryRecv::handleMercenaryMessage(const int cmd)
187
{
188
    PlayerInfo::setMercenary(nullptr);
189
    if (skillDialog != nullptr)
190
    {
191
        skillDialog->hideSkills(SkillOwner::Mercenary);
192
        skillDialog->updateModels();
193
    }
194
195
    switch (cmd)
196
    {
197
        case 0:
198
            NotifyManager::notify(NotifyTypes::MERCENARY_EXPIRED);
199
            break;
200
        case 1:
201
            NotifyManager::notify(NotifyTypes::MERCENARY_KILLED);
202
            break;
203
        case 2:
204
            NotifyManager::notify(NotifyTypes::MERCENARY_FIRED);
205
            break;
206
        case 3:
207
            NotifyManager::notify(NotifyTypes::MERCENARY_RUN);
208
            break;
209
        default:
210
            NotifyManager::notify(NotifyTypes::MERCENARY_UNKNOWN);
211
            break;
212
    }
213
}
214
215
4
}  // namespace EAthena