-
-
Notifications
You must be signed in to change notification settings - Fork 544
/
game.h
644 lines (519 loc) · 26.6 KB
/
game.h
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
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
/**
* The Forgotten Server - a free and open-source MMORPG server emulator
* Copyright (C) 2019 Mark Samman <mark.samman@gmail.com>
*
* 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
* (at your option) 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef SRC_GAME_GAME_H_
#define SRC_GAME_GAME_H_
#include <unordered_set>
#include "creatures/players/account/account.hpp"
#include "creatures/combat/combat.h"
#include "items/containers/container.h"
#include "game/gamestore.h"
#include "creatures/players/grouping/groups.h"
#include "io/iobestiary.h"
#include "items/item.h"
#include "map/map.h"
#include "creatures/npcs/npc.h"
#include "movement/position.h"
#include "creatures/players/player.h"
#include "lua/creature/raids.h"
#include "creatures/players/grouping/team_finder.hpp"
#include "utils/wildcardtree.h"
#include "items/items_classification.hpp"
class ServiceManager;
class Creature;
class Monster;
class Npc;
class CombatInfo;
class Charm;
class ItemClassification;
static constexpr int32_t EVENT_LIGHTINTERVAL_MS = 10000;
class Game
{
public:
Game();
~Game();
// Singleton - ensures we don't accidentally copy it.
Game(const Game&) = delete;
Game& operator=(const Game&) = delete;
void loadBoostedCreature();
void start(ServiceManager* manager);
void forceRemoveCondition(uint32_t creatureId, ConditionType_t type, ConditionId_t conditionId);
/**
* Load the main map
* \param filename Is the map custom name (Example: "map".otbm, not is necessary add extension .otbm)
* \returns true if the custom map was loaded successfully
*/
bool loadMainMap(const std::string& filename);
/**
* Load the custom map
* \param filename Is the map custom name (Example: "map".otbm, not is necessary add extension .otbm)
* \returns true if the custom map was loaded successfully
*/
bool loadCustomMap(const std::string& filename);
void loadMap(const std::string& path);
void getMapDimensions(uint32_t& width, uint32_t& height) const {
width = map.width;
height = map.height;
}
void setWorldType(WorldType_t type);
WorldType_t getWorldType() const {
return worldType;
}
std::map<uint32_t, TeamFinder*> getTeamFinderList() const {
return teamFinderMap;
}
void registerTeamFinderAssemble(uint32_t leaderGuid, TeamFinder* teamFinder) {
teamFinderMap[leaderGuid] = teamFinder;
}
void removeTeamFinderListed(uint32_t leaderGuid) {
teamFinderMap.erase(leaderGuid);
}
// Event schedule xml load
bool loadScheduleEventFromXml();
Cylinder* internalGetCylinder(Player* player, const Position& pos) const;
Thing* internalGetThing(Player* player, const Position& pos, int32_t index,
uint32_t spriteId, StackPosType_t type) const;
static void internalGetPosition(Item* item, Position& pos, uint8_t& stackpos);
static std::string getTradeErrorDescription(ReturnValue ret, Item* item);
Creature* getCreatureByID(uint32_t id);
Monster* getMonsterByID(uint32_t id);
Npc* getNpcByID(uint32_t id);
Player* getPlayerByID(uint32_t id);
Creature* getCreatureByName(const std::string& s);
Npc* getNpcByName(const std::string& s);
Player* getPlayerByName(const std::string& s);
Player* getPlayerByGUID(const uint32_t& guid);
ReturnValue getPlayerByNameWildcard(const std::string& s, Player*& player);
Player* getPlayerByAccount(uint32_t acc);
bool internalPlaceCreature(Creature* creature, const Position& pos, bool extendedPos = false, bool forced = false, bool creatureCheck = false);
bool placeCreature(Creature* creature, const Position& pos, bool extendedPos = false, bool force = false);
bool removeCreature(Creature* creature, bool isLogout = true);
void executeDeath(uint32_t creatureId);
void addCreatureCheck(Creature* creature);
static void removeCreatureCheck(Creature* creature);
size_t getPlayersOnline() const {
return players.size();
}
size_t getMonstersOnline() const {
return monsters.size();
}
size_t getNpcsOnline() const {
return npcs.size();
}
uint32_t getPlayersRecord() const {
return playersRecord;
}
uint16_t getItemsPriceCount() const {
return itemsSaleCount;
}
void addItemsClassification(ItemClassification* itemsClassification) {
itemsClassifications.push_back(itemsClassification);
}
ItemClassification* getItemsClassification(uint8_t id, bool create) {
auto it = std::find_if(itemsClassifications.begin(), itemsClassifications.end(), [id](ItemClassification* it) {
return it->id == id;
});
if (it != itemsClassifications.end()) {
return *it;
} else if (create) {
ItemClassification* itemClassification = new ItemClassification(id);
addItemsClassification(itemClassification);
return itemClassification;
}
return nullptr;
}
LightInfo getWorldLightInfo() const;
bool gameIsDay();
ReturnValue internalMoveCreature(Creature* creature,
Direction direction, uint32_t flags = 0);
ReturnValue internalMoveCreature(Creature& creature,
Tile& toTile, uint32_t flags = 0);
ReturnValue internalMoveItem(Cylinder* fromCylinder, Cylinder* toCylinder,
int32_t index, Item* item, uint32_t count,
Item** internalMoveItem, uint32_t flags = 0,
Creature* actor = nullptr,
Item* tradeItem = nullptr);
ReturnValue internalAddItem(Cylinder* toCylinder, Item* item,
int32_t index = INDEX_WHEREEVER,
uint32_t flags = 0, bool test = false);
ReturnValue internalAddItem(Cylinder* toCylinder, Item* item, int32_t index,
uint32_t flags, bool test, uint32_t& remainderCount);
ReturnValue internalRemoveItem(Item* item, int32_t count = -1,
bool test = false, uint32_t flags = 0);
ReturnValue internalPlayerAddItem(Player* player, Item* item,
bool dropOnMap = true,
Slots_t slot = CONST_SLOT_WHEREEVER);
Item* findItemOfType(Cylinder* cylinder, uint16_t itemId,
bool depthSearch = true, int32_t subType = -1) const;
bool removeMoney(Cylinder* cylinder, uint64_t money,
uint32_t flags = 0, bool useBank = false);
void addMoney(Cylinder* cylinder, uint64_t money, uint32_t flags = 0);
Item* transformItem(Item* item, uint16_t newId, int32_t newCount = -1);
ReturnValue internalTeleport(Thing* thing, const Position& newPos,
bool pushMove = true, uint32_t flags = 0);
bool internalCreatureTurn(Creature* creature, Direction dir);
bool internalCreatureSay(Creature* creature, SpeakClasses type,
const std::string& text,
bool ghostMode,
SpectatorHashSet* spectatorsPtr = nullptr,
const Position* pos = nullptr);
void internalQuickLootCorpse(Player* player, Container* corpse);
ReturnValue internalQuickLootItem(Player* player, Item* item,
ObjectCategory_t category = OBJECTCATEGORY_DEFAULT);
ObjectCategory_t getObjectCategory(const Item* item);
void loadPlayersRecord();
void checkPlayersRecord();
void sendGuildMotd(uint32_t playerId);
void kickPlayer(uint32_t playerId, bool displayEffect);
void playerReportBug(uint32_t playerId, const std::string& message,
const Position& position, uint8_t category);
void playerDebugAssert(uint32_t playerId, const std::string& assertLine,
const std::string& date, const std::string& description,
const std::string& comment);
void playerNpcGreet(uint32_t playerId, uint32_t npcId);
void playerAnswerModalWindow(uint32_t playerId, uint32_t modalWindowId,
uint8_t button, uint8_t choice);
void playerReportRuleViolationReport(uint32_t playerId,
const std::string& targetName,
uint8_t reportType, uint8_t reportReason,
const std::string& comment,
const std::string& translation);
void playerCyclopediaCharacterInfo(Player* player, uint32_t characterID, CyclopediaCharacterInfoType_t characterInfoType, uint16_t entriesPerPage, uint16_t page);
void playerHighscores(Player* player, HighscoreType_t type, uint8_t category, uint32_t vocation, const std::string& worldName, uint16_t page, uint8_t entriesPerPage);
void playerTournamentLeaderboard(uint32_t playerId, uint8_t leaderboardType);
void updatePlayerSaleItems(uint32_t playerId);
bool internalStartTrade(Player* player, Player* partner, Item* tradeItem);
void internalCloseTrade(Player* player);
bool playerBroadcastMessage(Player* player, const std::string& text) const;
void broadcastMessage(const std::string& text, MessageClasses type) const;
//Implementation of player invoked events
void playerTeleport(uint32_t playerId, const Position& pos);
void playerMoveThing(uint32_t playerId, const Position& fromPos, uint16_t spriteId, uint8_t fromStackPos,
const Position& toPos, uint8_t count);
void playerMoveCreatureByID(uint32_t playerId, uint32_t movingCreatureId, const Position& movingCreatureOrigPos, const Position& toPos);
void playerMoveCreature(Player* playerId, Creature* movingCreature, const Position& movingCreatureOrigPos, Tile* toTile);
void playerMoveItemByPlayerID(uint32_t playerId, const Position& fromPos, uint16_t spriteId, uint8_t fromStackPos, const Position& toPos, uint8_t count);
void playerMoveItem(Player* player, const Position& fromPos,
uint16_t spriteId, uint8_t fromStackPos, const Position& toPos, uint8_t count, Item* item, Cylinder* toCylinder);
void playerEquipItem(uint32_t playerId, uint16_t spriteId);
void playerMove(uint32_t playerId, Direction direction);
void playerCreatePrivateChannel(uint32_t playerId);
void playerChannelInvite(uint32_t playerId, const std::string& name);
void playerChannelExclude(uint32_t playerId, const std::string& name);
void playerRequestChannels(uint32_t playerId);
void playerOpenChannel(uint32_t playerId, uint16_t channelId);
void playerCloseChannel(uint32_t playerId, uint16_t channelId);
void playerOpenPrivateChannel(uint32_t playerId, std::string& receiver);
void playerStowItem(uint32_t playerId, const Position& pos, uint16_t spriteId, uint8_t stackpos, uint8_t count, bool allItems);
void playerStashWithdraw(uint32_t playerId, uint16_t spriteId, uint32_t count, uint8_t stackpos);
void playerCloseNpcChannel(uint32_t playerId);
void playerReceivePing(uint32_t playerId);
void playerReceivePingBack(uint32_t playerId);
void playerAutoWalk(uint32_t playerId, const std::forward_list<Direction>& listDir);
void playerStopAutoWalk(uint32_t playerId);
void playerUseItemEx(uint32_t playerId, const Position& fromPos, uint8_t fromStackPos,
uint16_t fromSpriteId, const Position& toPos, uint8_t toStackPos, uint16_t toSpriteId);
void playerUseItem(uint32_t playerId, const Position& pos, uint8_t stackPos, uint8_t index, uint16_t spriteId);
void playerUseWithCreature(uint32_t playerId, const Position& fromPos, uint8_t fromStackPos, uint32_t creatureId, uint16_t spriteId);
void playerCloseContainer(uint32_t playerId, uint8_t cid);
void playerMoveUpContainer(uint32_t playerId, uint8_t cid);
void playerUpdateContainer(uint32_t playerId, uint8_t cid);
void playerRotateItem(uint32_t playerId, const Position& pos, uint8_t stackPos, const uint16_t spriteId);
void playerConfigureShowOffSocket(uint32_t playerId, const Position& pos, uint8_t stackPos, const uint16_t spriteId);
void playerSetShowOffSocket(uint32_t playerId, Outfit_t& outfit, const Position& pos, uint8_t stackPos, const uint16_t spriteId, uint8_t podiumVisible, uint8_t direction);
void playerWrapableItem(uint32_t playerId, const Position& pos, uint8_t stackPos, const uint16_t spriteId);
void playerWriteItem(uint32_t playerId, uint32_t windowTextId, const std::string& text);
void playerBrowseField(uint32_t playerId, const Position& pos);
void playerSeekInContainer(uint32_t playerId, uint8_t containerId, uint16_t index);
void playerUpdateHouseWindow(uint32_t playerId, uint8_t listId, uint32_t windowTextId, const std::string& text);
void playerRequestTrade(uint32_t playerId, const Position& pos, uint8_t stackPos,
uint32_t tradePlayerId, uint16_t spriteId);
void playerAcceptTrade(uint32_t playerId);
void playerLookInTrade(uint32_t playerId, bool lookAtCounterOffer, uint8_t index);
void playerBuyItem(uint32_t playerId, uint16_t spriteId, uint8_t count, uint8_t amount,
bool ignoreCap = false, bool inBackpacks = false);
void playerSellItem(uint32_t playerId, uint16_t spriteId, uint8_t count,
uint8_t amount, bool ignoreEquipped = false);
void playerCloseShop(uint32_t playerId);
void playerLookInShop(uint32_t playerId, uint16_t spriteId, uint8_t count);
void playerCloseTrade(uint32_t playerId);
void playerSetAttackedCreature(uint32_t playerId, uint32_t creatureId);
void playerFollowCreature(uint32_t playerId, uint32_t creatureId);
void playerCancelAttackAndFollow(uint32_t playerId);
void playerSetFightModes(uint32_t playerId, FightMode_t fightMode, bool chaseMode, bool secureMode);
void playerLookAt(uint32_t playerId, const Position& pos, uint8_t stackPos);
void playerLookInBattleList(uint32_t playerId, uint32_t creatureId);
void playerQuickLoot(uint32_t playerId, const Position& pos, uint16_t spriteId, uint8_t stackPos,
Item* defaultItem = nullptr, bool lootAllCorpses = false, bool autoLoot = false);
void playerLootAllCorpses(Player* player, const Position& pos, bool lootAllCorpses);
void playerSetLootContainer(uint32_t playerId, ObjectCategory_t category,
const Position& pos, uint16_t spriteId, uint8_t stackPos);
void playerClearLootContainer(uint32_t playerId, ObjectCategory_t category);;
void playerOpenLootContainer(uint32_t playerId, ObjectCategory_t category);
void playerSetQuickLootFallback(uint32_t playerId, bool fallback);
void playerQuickLootBlackWhitelist(uint32_t playerId,
QuickLootFilter_t filter, std::vector<uint16_t> clientIds);
void playerRequestLockFind(uint32_t playerId);
void playerRequestAddVip(uint32_t playerId, const std::string& name);
void playerRequestRemoveVip(uint32_t playerId, uint32_t guid);
void playerRequestEditVip(uint32_t playerId, uint32_t guid, const std::string& description, uint32_t icon, bool notify);
void playerApplyImbuement(uint32_t playerId, uint32_t imbuementid, uint8_t slot, bool protectionCharm);
void playerClearImbuement(uint32_t playerid, uint8_t slot);
void playerCloseImbuementWindow(uint32_t playerid);
void playerTurn(uint32_t playerId, Direction dir);
void playerRequestOutfit(uint32_t playerId);
void playerShowQuestLog(uint32_t playerId);
void playerShowQuestLine(uint32_t playerId, uint16_t questId);
void playerSay(uint32_t playerId, uint16_t channelId, SpeakClasses type,
const std::string& receiver, const std::string& text);
void playerChangeOutfit(uint32_t playerId, Outfit_t outfit);
void playerInviteToParty(uint32_t playerId, uint32_t invitedId);
void playerJoinParty(uint32_t playerId, uint32_t leaderId);
void playerRevokePartyInvitation(uint32_t playerId, uint32_t invitedId);
void playerPassPartyLeadership(uint32_t playerId, uint32_t newLeaderId);
void playerLeaveParty(uint32_t playerId);
void playerEnableSharedPartyExperience(uint32_t playerId, bool sharedExpActive);
void playerToggleMount(uint32_t playerId, bool mount);
void playerLeaveMarket(uint32_t playerId);
void playerBrowseMarket(uint32_t playerId, uint16_t spriteId);
void playerBrowseMarketOwnOffers(uint32_t playerId);
void playerBrowseMarketOwnHistory(uint32_t playerId);
void playerCreateMarketOffer(uint32_t playerId, uint8_t type, uint16_t spriteId, uint16_t amount, uint32_t price, bool anonymous);
void playerCancelMarketOffer(uint32_t playerId, uint32_t timestamp, uint16_t counter);
void playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16_t counter, uint16_t amount);
void playerStoreOpen(uint32_t playerId, uint8_t serviceType);
void playerShowStoreCategoryOffers(uint32_t playerId, StoreCategory* category);
void playerBuyStoreOffer(uint32_t playerId, uint32_t offerId, uint8_t productType, const std::string& additionalInfo="");
void playerCoinTransfer(uint32_t playerId, const std::string& receiverName, uint32_t amount);
void playerStoreTransactionHistory(uint32_t playerId, uint32_t page);
void parsePlayerExtendedOpcode(uint32_t playerId, uint8_t opcode, const std::string& buffer);
std::forward_list<Item*> getMarketItemList(uint16_t wareId, uint16_t sufficientCount, DepotLocker* depotLocker);
static void updatePremium(account::Account& account);
void cleanup();
void shutdown();
void dieSafely(std::string errorMsg);
void ReleaseCreature(Creature* creature);
void ReleaseItem(Item* item);
void addBestiaryList(uint16_t raceid, std::string name);
const std::map<uint16_t, std::string>& getBestiaryList() const { return BestiaryList; }
void setBoostedName(std::string name) {
boostedCreature = name;
}
std::string getBoostedMonsterName() const {
return boostedCreature;
}
void onPressHotkeyEquip(uint32_t playerId, uint16_t spriteid);
bool canThrowObjectTo(const Position& fromPos, const Position& toPos, bool checkLineOfSight = true,
int32_t rangex = Map::maxClientViewportX, int32_t rangey = Map::maxClientViewportY) const;
bool isSightClear(const Position& fromPos, const Position& toPos, bool sameFloor) const;
void changeSpeed(Creature* creature, int32_t varSpeedDelta);
void internalCreatureChangeOutfit(Creature* creature, const Outfit_t& oufit);
void internalCreatureChangeVisible(Creature* creature, bool visible);
void changeLight(const Creature* creature);
void updateCreatureIcon(const Creature* creature);
void updateCreatureSkull(const Creature* player);
void updatePlayerShield(Player* player);
void updateCreatureType(Creature* creature);
void updateCreatureWalkthrough(const Creature* creature);
GameState_t getGameState() const;
void setGameState(GameState_t newState);
void saveGameState();
// Events
void checkCreatureWalk(uint32_t creatureId);
void updateCreatureWalk(uint32_t creatureId);
void checkCreatureAttack(uint32_t creatureId);
void checkCreatures(size_t index);
void checkLight();
bool combatBlockHit(CombatDamage& damage, Creature* attacker, Creature* target, bool checkDefense, bool checkArmor, bool field);
void combatGetTypeInfo(CombatType_t combatType, Creature* target, TextColor_t& color, uint8_t& effect);
bool combatChangeHealth(Creature* attacker, Creature* target, CombatDamage& damage, bool isEvent = false);
bool combatChangeMana(Creature* attacker, Creature* target, CombatDamage& damage);
// Animation help functions
void addCreatureHealth(const Creature* target);
static void addCreatureHealth(const SpectatorHashSet& spectators, const Creature* target);
void addPlayerMana(const Player* target);
void addPlayerVocation(const Player* target);
void addMagicEffect(const Position& pos, uint8_t effect);
static void addMagicEffect(const SpectatorHashSet& spectators, const Position& pos, uint8_t effect);
void addDistanceEffect(const Position& fromPos, const Position& toPos, uint8_t effect);
static void addDistanceEffect(const SpectatorHashSet& spectators, const Position& fromPos, const Position& toPos, uint8_t effect);
int32_t getLightHour() const {
return lightHour;
}
bool loadItemsPrice();
void loadMotdNum();
void saveMotdNum() const;
const std::string& getMotdHash() const { return motdHash; }
uint32_t getMotdNum() const { return motdNum; }
void incrementMotdNum() { motdNum++; }
void sendOfflineTrainingDialog(Player* player);
const std::map<uint16_t, uint32_t>& getItemsPrice() const { return itemsPriceMap; }
const std::unordered_map<uint32_t, Player*>& getPlayers() const { return players; }
const std::map<uint32_t, Npc*>& getNpcs() const { return npcs; }
const std::vector<ItemClassification*>& getItemsClassifications() const { return itemsClassifications; }
void addPlayer(Player* player);
void removePlayer(Player* player);
void addNpc(Npc* npc);
void removeNpc(Npc* npc);
void addMonster(Monster* npc);
void removeMonster(Monster* npc);
Guild* getGuild(uint32_t id) const;
void addGuild(Guild* guild);
void removeGuild(uint32_t guildId);
void decreaseBrowseFieldRef(const Position& pos);
std::unordered_map<Tile*, Container*> browseFields;
void internalRemoveItems(std::vector<Item*> itemList, uint32_t amount, bool stackable);
BedItem* getBedBySleeper(uint32_t guid) const;
void setBedSleeper(BedItem* bed, uint32_t guid);
void removeBedSleeper(uint32_t guid);
Item* getUniqueItem(uint16_t uniqueId);
bool addUniqueItem(uint16_t uniqueId, Item* item);
void removeUniqueItem(uint16_t uniqueId);
bool reload(ReloadTypes_t reloadType);
bool itemidHasMoveevent(uint32_t itemid);
bool hasEffect(uint8_t effectId);
bool hasDistanceEffect(uint8_t effectId);
Groups groups;
Map map;
Mounts mounts;
Raids raids;
GameStore gameStore;
std::unordered_set<Tile*> getTilesToClean() const {
return tilesToClean;
}
void addTileToClean(Tile* tile) {
tilesToClean.emplace(tile);
}
void removeTileToClean(Tile* tile) {
tilesToClean.erase(tile);
}
void clearTilesToClean() {
tilesToClean.clear();
}
// Event schedule
uint16_t getExpSchedule() const {
return expSchedule;
}
void setExpSchedule(uint16_t exprate) {
expSchedule = (expSchedule * exprate)/100;
}
uint16_t getLootSchedule() const {
return lootSchedule;
}
void setLootSchedule(uint16_t lootrate) {
lootSchedule = (lootSchedule * lootrate)/100;
}
uint32_t getSpawnMonsterSchedule() const {
return spawnMonsterSchedule;
}
void setSpawnMonsterSchedule(uint32_t spawnrate) {
spawnMonsterSchedule = (spawnMonsterSchedule * spawnrate)/100;
}
uint16_t getSkillSchedule() const {
return skillSchedule;
}
void setSkillSchedule(uint16_t skillrate) {
skillSchedule = (skillSchedule * skillrate)/100;
}
void playerInspectItem(Player* player, const Position& pos);
void playerInspectItem(Player* player, uint16_t itemId, uint8_t itemCount, bool cyclopedia);
void addCharmRune(Charm* charm)
{
CharmList.push_back(charm);
CharmList.shrink_to_fit();
}
std::vector<Charm*> getCharmList() {
return CharmList;
}
void increasePlayerActiveImbuements(uint32_t playerId) {
setPlayerActiveImbuements(playerId, playersActiveImbuements[playerId] + 1);
}
void decreasePlayerActiveImbuements(uint32_t playerId) {
setPlayerActiveImbuements(playerId, playersActiveImbuements[playerId] - 1);
}
void setPlayerActiveImbuements(uint32_t playerId, uint8_t value) {
if (value <= 0) {
playersActiveImbuements.erase(playerId);
return;
}
playersActiveImbuements[playerId] = std::min<uint8_t>(255, value);
}
uint8_t getPlayerActiveImbuements(uint32_t playerId) {
return playersActiveImbuements[playerId];
}
private:
void checkImbuements();
bool playerSaySpell(Player* player, SpeakClasses type, const std::string& text);
void playerWhisper(Player* player, const std::string& text);
bool playerYell(Player* player, const std::string& text);
bool playerSpeakTo(Player* player, SpeakClasses type, const std::string& receiver, const std::string& text);
void playerSpeakToNpc(Player* player, const std::string& text);
std::unordered_map<uint32_t, Player*> players;
std::unordered_map<uint32_t, uint8_t> playersActiveImbuements;
std::unordered_map<std::string, Player*> mappedPlayerNames;
std::unordered_map<uint32_t, Guild*> guilds;
std::unordered_map<uint16_t, Item*> uniqueItems;
std::map<uint32_t, uint32_t> stages;
std::map<uint16_t, std::string> BestiaryList;
std::string boostedCreature = "";
std::vector<Charm*> CharmList;
std::vector<Creature*> ToReleaseCreatures;
std::vector<Creature*> checkCreatureLists[EVENT_CREATURECOUNT];
std::vector<Item*> ToReleaseItems;
size_t lastBucket = 0;
size_t lastImbuedBucket = 0;
WildcardTreeNode wildcardTree { false };
std::map<uint32_t, Npc*> npcs;
std::map<uint32_t, Monster*> monsters;
std::map<uint32_t, TeamFinder*> teamFinderMap; // [leaderGUID] = TeamFinder*
//list of items that are in trading state, mapped to the player
std::map<Item*, uint32_t> tradeItems;
std::map<uint32_t, BedItem*> bedSleepersMap;
std::unordered_set<Tile*> tilesToClean;
ModalWindow offlineTrainingWindow { std::numeric_limits<uint32_t>::max(), "Choose a Skill", "Please choose a skill:" };
static constexpr int32_t DAY_LENGTH_SECONDS = 3600;
static constexpr int32_t LIGHT_DAY_LENGTH = 1440;
static constexpr int32_t LIGHT_LEVEL_DAY = 250;
static constexpr int32_t LIGHT_LEVEL_NIGHT = 40;
static constexpr int32_t SUNSET = 1050;
static constexpr int32_t SUNRISE = 360;
bool isDay = false;
bool browseField = false;
GameState_t gameState = GAME_STATE_NORMAL;
WorldType_t worldType = WORLD_TYPE_PVP;
// Event schedule
uint16_t expSchedule = 100;
uint16_t lootSchedule = 100;
uint16_t skillSchedule = 100;
uint32_t spawnMonsterSchedule = 100;
LightState_t lightState = LIGHT_STATE_DAY;
LightState_t currentLightState = lightState;
uint8_t lightLevel = LIGHT_LEVEL_DAY;
int32_t lightHour = SUNRISE + (SUNSET - SUNRISE) / 2;
// (1440 total light of tibian day)/(3600 real seconds each tibian day) * 10 seconds event interval
int32_t lightHourDelta = (LIGHT_DAY_LENGTH * (EVENT_LIGHTINTERVAL_MS/1000)) / DAY_LENGTH_SECONDS;
ServiceManager* serviceManager = nullptr;
void updatePlayersRecord() const;
uint32_t playersRecord = 0;
std::string motdHash;
uint32_t motdNum = 0;
std::map<uint16_t, uint32_t> itemsPriceMap;
uint16_t itemsSaleCount;
std::vector<ItemClassification*> itemsClassifications;
};
#endif // SRC_GAME_GAME_H_