1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
|
/*
* The ManaPlus Client
* Copyright (C) 2009 The Mana World Development Team
* Copyright (C) 2009-2010 Andrei Karas
* Copyright (C) 2011-2013 The ManaPlus developers
*
* This file is part of The ManaPlus Client.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gui/killstats.h"
#include "gui/widgets/button.h"
#include "gui/widgets/label.h"
#include "gui/widgets/layout.h"
#include "gui/widgets/chattab.h"
#include "actorspritemanager.h"
#include "game.h"
#include "localplayer.h"
#include "playerinfo.h"
#include "utils/gettext.h"
#include <math.h>
#include "debug.h"
KillStats::KillStats():
Window(_("Kill stats"), false, nullptr, "killstats.xml"),
gcn::ActionListener(),
mKillCounter(0),
mExpCounter(0),
mKillTCounter(0),
mExpTCounter(0),
mKillTimer(0),
mResetButton(new Button(this, _("Reset stats"), "reset", this)),
mTimerButton(new Button(this, _("Reset timer"), "timer", this)),
mLine4(new Label(this, strprintf(_("Kills: %s, total exp: %s"),
"?", "?"))),
mLine5(new Label(this, strprintf(_("Avg Exp: %s"), "?"))),
mLine6(new Label(this, strprintf(_("No. of avg mob to next level: %s"),
"?"))),
mLine7(new Label(this, strprintf(_("Kills/Min: %s, Exp/Min: %s"),
"?", "?"))),
mExpSpeed1Label(new Label(this, strprintf(ngettext(
"Exp speed per %d min: %s", "Exp speed per %d min: %s", 1), 1, "?"))),
mExpTime1Label(new Label(this, strprintf(ngettext(
"Time for next level per %d min: %s",
"Time for next level per %d min: %s", 1), 1, "?"))),
mExpSpeed5Label(new Label(this, strprintf(ngettext(
"Exp speed per %d min: %s", "Exp speed per %d min: %s", 5), 5, "?"))),
mExpTime5Label(new Label(this, strprintf(ngettext(
"Time for next level per %d min: %s",
"Time for next level per %d min: %s", 5), 5, "?"))),
mExpSpeed15Label(new Label(this, strprintf(ngettext(
"Exp speed per %d min: %s", "Exp speed per %d min: %s", 15),
15, "?"))),
mExpTime15Label(new Label(this, strprintf(ngettext(
"Time for next level per %d min: %s",
"Time for next level per %d min: %s", 15), 15, "?"))),
mLastKillExpLabel(new Label(this, strprintf("%s ?", _("Last kill exp:")))),
mTimeBeforeJackoLabel(new Label(this, strprintf(
"%s ?", _("Time before jacko spawn:")))),
m1minExpTime(0),
m1minExpNum(0),
m1minSpeed(0),
m5minExpTime(0),
m5minExpNum(0),
m5minSpeed(0),
m15minExpTime(0),
m15minExpNum(0),
m15minSpeed(0),
mJackoSpawnTime(0),
mValidateJackoTime(0),
mJackoId(0),
mIsJackoAlive(false),
mIsJackoMustSpawn(true),
mIsJackoSpawnTimeUnknown(true)
{
setWindowName("Kill stats");
setCloseButton(true);
setResizable(true);
setSaveVisible(true);
setStickyButtonLock(true);
setDefaultSize(250, 250, 350, 300);
listen(CHANNEL_ATTRIBUTES);
const int xp(PlayerInfo::getAttribute(PlayerInfo::EXP));
int xpNextLevel(PlayerInfo::getAttribute(PlayerInfo::EXP_NEEDED));
if (!xpNextLevel)
xpNextLevel = 1;
mLine1 = new Label(this, strprintf(_("Level: %d at %f%%"),
player_node->getLevel(), static_cast<double>(xp)
/ static_cast<double>(xpNextLevel) * 100.0));
mLine2 = new Label(this, strprintf(_("Exp: %d/%d Left: %d"),
xp, xpNextLevel, xpNextLevel - xp));
mLine3 = new Label(this, strprintf(_("1%% = %d exp, avg mob for 1%%: %s"),
xpNextLevel / 100, "?"));
place(0, 0, mLine1, 6).setPadding(0);
place(0, 1, mLine2, 6).setPadding(0);
place(0, 2, mLine3, 6).setPadding(0);
place(0, 3, mLine4, 6).setPadding(0);
place(0, 4, mLine5, 6).setPadding(0);
place(0, 5, mLine6, 6).setPadding(0);
place(0, 6, mLine7, 6).setPadding(0);
place(0, 7, mLastKillExpLabel, 6).setPadding(0);
place(0, 8, mTimeBeforeJackoLabel, 6).setPadding(0);
place(0, 9, mExpSpeed1Label, 6).setPadding(0);
place(0, 10, mExpTime1Label, 6).setPadding(0);
place(0, 11, mExpSpeed5Label, 6).setPadding(0);
place(0, 12, mExpTime5Label, 6).setPadding(0);
place(0, 13, mExpSpeed15Label, 6).setPadding(0);
place(0, 14, mExpTime15Label, 6).setPadding(0);
place(5, 13, mTimerButton).setPadding(0);
place(5, 14, mResetButton).setPadding(0);
loadWindowState();
enableVisibleSound(true);
}
KillStats::~KillStats()
{
}
void KillStats::action(const gcn::ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "reset")
{
mKillCounter = 0;
mExpCounter = 0;
mLine3->setCaption(strprintf("1%% = %d exp, avg mob for 1%%: %s",
PlayerInfo::getAttribute(PlayerInfo::EXP_NEEDED) / 100, "?"));
mLine4->setCaption(strprintf(_("Kills: %s, total exp: %s"), "?", "?"));
mLine5->setCaption(strprintf(_("Avg Exp: %s"), "?"));
mLine6->setCaption(strprintf(
_("No. of avg mob to next level: %s"), "?"));
resetTimes();
}
else if (eventId == "timer")
{
mKillTimer = 0;
mKillTCounter = 0;
mExpTCounter = 0;
mLine7->setCaption(strprintf(
_("Kills/Min: %s, Exp/Min: %s"), "?", "?"));
resetTimes();
}
}
void KillStats::resetTimes()
{
m1minExpTime = 0;
m1minExpNum = 0;
m1minSpeed = 0;
m5minExpTime = 0;
m5minExpNum = 0;
m5minSpeed = 0;
m15minExpTime = 0;
m15minExpNum = 0;
m15minSpeed = 0;
}
void KillStats::gainXp(int xp)
{
if (xp == PlayerInfo::getAttribute(PlayerInfo::EXP_NEEDED))
xp = 0;
else if (!xp)
return;
mKillCounter++;
mKillTCounter++;
mExpCounter = mExpCounter + xp;
mExpTCounter = mExpTCounter + xp;
if (!mKillCounter)
mKillCounter = 1;
const float AvgExp = static_cast<float>(mExpCounter / mKillCounter);
int xpNextLevel(PlayerInfo::getAttribute(PlayerInfo::EXP_NEEDED));
if (mKillTimer == 0)
mKillTimer = cur_time;
if (!xpNextLevel)
xpNextLevel = 1;
double timeDiff = difftime(cur_time, mKillTimer) / 60;
if (timeDiff <= 0.001)
timeDiff = 1;
mLine1->setCaption(strprintf(_("Level: %d at %f%%"),
player_node->getLevel(), static_cast<double>(
PlayerInfo::getAttribute(PlayerInfo::EXP)) / static_cast<double>(
xpNextLevel) * 100.0));
mLine2->setCaption(strprintf(_("Exp: %d/%d Left: %d"),
PlayerInfo::getAttribute(PlayerInfo::EXP), xpNextLevel,
xpNextLevel - PlayerInfo::getAttribute(PlayerInfo::EXP)));
if (AvgExp >= 0.001f && AvgExp <= 0.001f)
{
mLine3->setCaption(strprintf(_("1%% = %d exp, avg mob for 1%%: %s"),
xpNextLevel / 100, "?"));
mLine5->setCaption(strprintf(_("Avg Exp: %s"),
toString(AvgExp).c_str()));
mLine6->setCaption(strprintf(
_("No. of avg mob to next level: %s"), "?"));
}
else
{
mLine3->setCaption(strprintf(_("1%% = %d exp, avg mob for 1%%: %s"),
xpNextLevel / 100, toString((static_cast<float>(
xpNextLevel) / 100) / AvgExp).c_str()));
mLine5->setCaption(strprintf(_("Avg Exp: %s"),
toString(AvgExp).c_str()));
mLine6->setCaption(strprintf(_("No. of avg mob to next level: %s"),
toString(static_cast<float>(xpNextLevel
- PlayerInfo::getAttribute(PlayerInfo::EXP)) / AvgExp).c_str()));
}
mLine4->setCaption(strprintf(_("Kills: %s, total exp: %s"),
toString(mKillCounter).c_str(), toString(mExpCounter).c_str()));
mLine7->setCaption(strprintf(_("Kills/Min: %s, Exp/Min: %s"),
toString(mKillTCounter / timeDiff).c_str(),
toString(mExpTCounter / timeDiff).c_str()));
mLastKillExpLabel->setCaption(strprintf("%s %d", _("Last kill exp:"), xp));
recalcStats();
update();
}
void KillStats::recalcStats()
{
BLOCK_START("KillStats::recalcStats")
const int curTime = cur_time;
// Need Update Exp Counter
if (curTime - m1minExpTime > 60)
{
const int newExp = PlayerInfo::getAttribute(PlayerInfo::EXP);
if (m1minExpTime != 0)
m1minSpeed = newExp - m1minExpNum;
else
m1minSpeed = 0;
m1minExpTime = curTime;
m1minExpNum = newExp;
}
if (curTime - m5minExpTime > 60*5)
{
const int newExp = PlayerInfo::getAttribute(PlayerInfo::EXP);
if (m5minExpTime != 0)
m5minSpeed = newExp - m5minExpNum;
else
m5minSpeed = 0;
m5minExpTime = curTime;
m5minExpNum = newExp;
}
if (curTime - m15minExpTime > 60*15)
{
const int newExp = PlayerInfo::getAttribute(PlayerInfo::EXP);
if (m15minExpTime != 0)
m15minSpeed = newExp - m15minExpNum;
else
m15minSpeed = 0;
m15minExpTime = curTime;
m15minExpNum = newExp;
}
validateJacko();
BLOCK_END("KillStats::recalcStats")
}
void KillStats::update()
{
BLOCK_START("KillStats::update")
mExpSpeed1Label->setCaption(strprintf(ngettext("Exp speed per %d min: %s",
"Exp speed per %d min: %s", 1), 1, toString(m1minSpeed).c_str()));
if (m1minSpeed != 0)
{
mExpTime1Label->setCaption(strprintf(_(" Time for next level: %s"),
toString(static_cast<float>((PlayerInfo::getAttribute(
PlayerInfo::EXP_NEEDED) - PlayerInfo::getAttribute(
PlayerInfo::EXP)) / m1minSpeed)).c_str()));
}
else
{
mExpTime1Label->setCaption(strprintf(
_(" Time for next level: %s"), "?"));
}
mExpTime1Label->adjustSize();
mExpSpeed5Label->setCaption(strprintf(ngettext("Exp speed per %d min: %s",
"Exp speed per %d min: %s", 5), 5, toString(m5minSpeed / 5).c_str()));
mExpSpeed5Label->adjustSize();
if (m5minSpeed != 0)
{
mExpTime5Label->setCaption(strprintf(_(" Time for next level: %s"),
toString(static_cast<float>((PlayerInfo::getAttribute(
PlayerInfo::EXP_NEEDED) - PlayerInfo::getAttribute(
PlayerInfo::EXP)) / m5minSpeed * 5)).c_str()));
}
else
{
mExpTime5Label->setCaption(strprintf(
_(" Time for next level: %s"), "?"));
}
mExpTime5Label->adjustSize();
mExpSpeed15Label->setCaption(strprintf(ngettext("Exp speed per %d min: %s",
"Exp speed per %d min: %s", 15), 15, toString(
m15minSpeed / 15).c_str()));
mExpSpeed15Label->adjustSize();
if (m15minSpeed != 0)
{
mExpTime15Label->setCaption(strprintf(_(" Time for next level: %s"),
toString(static_cast<float>((PlayerInfo::getAttribute(
PlayerInfo::EXP_NEEDED) - PlayerInfo::getAttribute(
PlayerInfo::EXP)) / m15minSpeed * 15)).c_str()));
}
else
{
mExpTime15Label->setCaption(strprintf(
_(" Time for next level: %s"), "?"));
}
validateJacko();
updateJackoLabel();
BLOCK_END("KillStats::update")
}
void KillStats::draw(gcn::Graphics *g)
{
// update();
Window::draw(g);
}
void KillStats::updateJackoLabel()
{
if (mIsJackoAlive)
{
mTimeBeforeJackoLabel->setCaption(strprintf("%s jacko alive",
_("Time before jacko spawn:")));
}
else if (mIsJackoSpawnTimeUnknown && mJackoSpawnTime != 0)
{
// TRANSLATORS: Example: Time before jacko spawn: 10?
mTimeBeforeJackoLabel->setCaption(strprintf(
_("%s %d?"), _("Time before jacko spawn:"),
mJackoSpawnTime - cur_time));
}
else if (mIsJackoMustSpawn)
{
mTimeBeforeJackoLabel->setCaption(strprintf("%s %s",
_("Time before jacko spawn:"), _("jacko spawning")));
}
else
{
mTimeBeforeJackoLabel->setCaption(strprintf("%s %d",
_("Time before jacko spawn:"), mJackoSpawnTime - cur_time));
}
}
void KillStats::jackoDead(const int id)
{
if (id == mJackoId && mIsJackoAlive)
{
mIsJackoAlive = false;
mJackoSpawnTime = cur_time + 60*4;
mIsJackoSpawnTimeUnknown = false;
updateJackoLabel();
}
}
void KillStats::jackoAlive(const int id)
{
if (!mIsJackoAlive)
{
mJackoId = id;
mIsJackoAlive = true;
mIsJackoMustSpawn = false;
mJackoSpawnTime = 0;
mIsJackoSpawnTimeUnknown = false;
updateJackoLabel();
}
}
void KillStats::validateJacko()
{
if (!actorSpriteManager || !player_node)
return;
const Map *const currentMap = Game::instance()->getCurrentMap();
if (currentMap)
{
if (currentMap->getProperty("_realfilename") == "018-1"
|| currentMap->getProperty("_realfilename") == "maps/018-1.tmx")
{
if (player_node->getTileX() >= 167
&& player_node->getTileX() <= 175
&& player_node->getTileY() >= 21
&& player_node->getTileY() <= 46)
{
const Being *const dstBeing
= actorSpriteManager->findBeingByName(
"Jack O", Being::MONSTER);
if (mIsJackoAlive && !dstBeing)
{
mIsJackoAlive = false;
mJackoSpawnTime = cur_time + 60*4;
mIsJackoSpawnTimeUnknown = true;
}
}
}
if (!mIsJackoAlive && cur_time > mJackoSpawnTime + 15)
mIsJackoMustSpawn = true;
}
}
void KillStats::processEvent(Channels channel A_UNUSED,
const DepricatedEvent &event)
{
if (event.getName() == EVENT_UPDATEATTRIBUTE)
{
const int id = event.getInt("id");
if (id == PlayerInfo::EXP || id == PlayerInfo::EXP_NEEDED)
{
gainXp(event.getInt("newValue") - event.getInt("oldValue"));
// update();
}
else if (id == PlayerInfo::LEVEL)
{
mKillCounter = 0;
mKillTCounter = 0;
mExpCounter = 0;
mExpTCounter = 0;
mLine3->setCaption(strprintf("1%% = %d exp, avg mob for 1%%: %s",
PlayerInfo::getAttribute(PlayerInfo::EXP_NEEDED) / 100, "?"));
mLine4->setCaption(strprintf(_(
"Kills: %s, total exp: %s"), "?", "?"));
mLine5->setCaption(strprintf(_("Avg Exp: %s"), "?"));
mLine6->setCaption(strprintf(
_("No. of avg mob to next level: %s"), "?"));
mLine7->setCaption(strprintf(
_("Kills/Min: %s, Exp/Min: %s"), "?", "?"));
resetTimes();
}
}
}
|