forked from otland/forgottenserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
housetile.cpp
129 lines (108 loc) · 3.28 KB
/
housetile.cpp
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
// Copyright 2023 The Forgotten Server Authors. All rights reserved.
// Use of this source code is governed by the GPL-2.0 License that can be found in the LICENSE file.
#include "otpch.h"
#include "housetile.h"
#include "configmanager.h"
#include "game.h"
#include "house.h"
extern Game g_game;
extern ConfigManager g_config;
HouseTile::HouseTile(int32_t x, int32_t y, int32_t z, House* house) : DynamicTile(x, y, z), house(house) {}
void HouseTile::addThing(int32_t index, Thing* thing)
{
Tile::addThing(index, thing);
if (!thing->getParent()) {
return;
}
if (Item* item = thing->getItem()) {
updateHouse(item);
}
}
void HouseTile::internalAddThing(uint32_t index, Thing* thing)
{
Tile::internalAddThing(index, thing);
if (!thing->getParent()) {
return;
}
if (Item* item = thing->getItem()) {
updateHouse(item);
}
}
void HouseTile::updateHouse(Item* item)
{
if (item->getParent() != this) {
return;
}
Door* door = item->getDoor();
if (door) {
if (door->getDoorId() != 0) {
house->addDoor(door);
}
} else {
BedItem* bed = item->getBed();
if (bed) {
house->addBed(bed);
}
}
}
ReturnValue HouseTile::queryAdd(int32_t index, const Thing& thing, uint32_t count, uint32_t flags,
Creature* actor /* = nullptr*/) const
{
if (const Creature* creature = thing.getCreature()) {
if (const Player* player = creature->getPlayer()) {
if (!house->isInvited(player)) {
return RETURNVALUE_PLAYERISNOTINVITED;
}
} else {
return RETURNVALUE_NOTPOSSIBLE;
}
} else if (const Item* item = thing.getItem()) {
if (item->isStoreItem() && !item->hasAttribute(ITEM_ATTRIBUTE_WRAPID)) {
return RETURNVALUE_ITEMCANNOTBEMOVEDTHERE;
}
if (actor && g_config.getBoolean(ConfigManager::ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) {
if (!house->isInvited(actor->getPlayer())) {
return RETURNVALUE_PLAYERISNOTINVITED;
}
}
}
return Tile::queryAdd(index, thing, count, flags, actor);
}
Tile* HouseTile::queryDestination(int32_t& index, const Thing& thing, Item** destItem, uint32_t& flags)
{
if (const Creature* creature = thing.getCreature()) {
if (const Player* player = creature->getPlayer()) {
if (!house->isInvited(player)) {
const Position& entryPos = house->getEntryPosition();
Tile* destTile = g_game.map.getTile(entryPos);
if (!destTile) {
std::cout << "Error: [HouseTile::queryDestination] House entry not correct"
<< " - Name: " << house->getName() << " - House id: " << house->getId()
<< " - Tile not found: " << entryPos << std::endl;
destTile = g_game.map.getTile(player->getTemplePosition());
if (!destTile) {
destTile = &(Tile::nullptr_tile);
}
}
index = -1;
*destItem = nullptr;
return destTile;
}
}
}
return Tile::queryDestination(index, thing, destItem, flags);
}
ReturnValue HouseTile::queryRemove(const Thing& thing, uint32_t count, uint32_t flags,
Creature* actor /*= nullptr*/) const
{
const Item* item = thing.getItem();
if (!item) {
return RETURNVALUE_NOTPOSSIBLE;
}
if (actor && g_config.getBoolean(ConfigManager::ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) {
if (!house->isInvited(actor->getPlayer())) {
return RETURNVALUE_PLAYERISNOTINVITED;
}
}
return Tile::queryRemove(thing, count, flags);
}