1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2004-2009 The Mana World Development Team |
4 |
|
|
* Copyright (C) 2009-2010 The Mana Developers |
5 |
|
|
* Copyright (C) 2011-2019 The ManaPlus Developers |
6 |
|
|
* Copyright (C) 2019-2021 Andrei Karas |
7 |
|
|
* |
8 |
|
|
* This file is part of The ManaPlus Client. |
9 |
|
|
* |
10 |
|
|
* This program is free software; you can redistribute it and/or modify |
11 |
|
|
* it under the terms of the GNU General Public License as published by |
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
13 |
|
|
* any later version. |
14 |
|
|
* |
15 |
|
|
* This program is distributed in the hope that it will be useful, |
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
|
|
* GNU General Public License for more details. |
19 |
|
|
* |
20 |
|
|
* You should have received a copy of the GNU General Public License |
21 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
#include "being/flooritem.h" |
25 |
|
|
|
26 |
|
|
#include "configuration.h" |
27 |
|
|
|
28 |
|
|
#include "render/graphics.h" |
29 |
|
|
|
30 |
|
|
#include "gui/gui.h" |
31 |
|
|
#include "gui/userpalette.h" |
32 |
|
|
|
33 |
|
|
#include "gui/fonts/font.h" |
34 |
|
|
|
35 |
|
|
#include "resources/iteminfo.h" |
36 |
|
|
|
37 |
|
|
#include "resources/db/itemdb.h" |
38 |
|
|
|
39 |
|
|
#include "resources/map/map.h" |
40 |
|
|
|
41 |
|
|
#ifdef TMWA_SUPPORT |
42 |
|
|
#include "net/net.h" |
43 |
|
|
#endif // TMWA_SUPPORT |
44 |
|
|
#include "net/serverfeatures.h" |
45 |
|
|
|
46 |
|
|
#include "debug.h" |
47 |
|
|
|
48 |
|
|
extern volatile time_t cur_time; |
49 |
|
|
|
50 |
|
|
FloorItem::FloorItem(const BeingId id, |
51 |
|
|
const int itemId, |
52 |
|
|
const int x, const int y, |
53 |
|
|
const ItemTypeT itemType, |
54 |
|
|
const int amount, |
55 |
|
|
const int refine, |
56 |
|
|
const ItemColor color, |
57 |
|
|
const Identified identified, |
58 |
|
|
const Damaged damaged, |
59 |
|
|
const int *const cards) : |
60 |
|
|
ActorSprite(id), |
61 |
|
|
mCards(), |
62 |
|
|
mItemId(itemId), |
63 |
|
|
mX(x), |
64 |
|
|
mY(y), |
65 |
|
|
mDropTime(cur_time), |
66 |
|
|
mAmount(amount), |
67 |
|
|
mRefine(refine), |
68 |
|
|
mHeightPosDiff(0), |
69 |
|
|
mItemType(itemType), |
70 |
|
|
mPickupCount(0), |
71 |
|
|
mCursor(Cursor::CURSOR_PICKUP), |
72 |
|
|
mColor(color), |
73 |
|
|
mIdentified(identified), |
74 |
|
|
mDamaged(damaged), |
75 |
|
|
mShowMsg(true), |
76 |
|
|
mHighlight(config.getBoolValue("floorItemsHighlight")) |
77 |
|
|
{ |
78 |
|
|
setCards(cards, maxCards); |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
void FloorItem::postInit(Map *const map, int subX, int subY) |
82 |
|
|
{ |
83 |
|
|
setMap(map); |
84 |
|
|
const ItemInfo &info = ItemDB::get(mItemId); |
85 |
|
|
if (map != nullptr) |
86 |
|
|
{ |
87 |
|
|
const int maxX = info.getMaxFloorOffsetX(); |
88 |
|
|
const int maxY = info.getMaxFloorOffsetY(); |
89 |
|
|
|
90 |
|
|
if (!serverFeatures->haveExtendedDropsPosition()) |
91 |
|
|
{ |
92 |
|
|
if (subX > maxX) |
93 |
|
|
subX = maxX; |
94 |
|
|
else if (subX < -maxX) |
95 |
|
|
subX = -maxX; |
96 |
|
|
if (subY > maxY) |
97 |
|
|
subY = maxY; |
98 |
|
|
else if (subY < -maxY) |
99 |
|
|
subY = -maxY; |
100 |
|
|
|
101 |
|
|
subX -= 8; |
102 |
|
|
subY -= 8; |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
mHeightPosDiff = map->getHeightOffset(mX, mY) * 16; |
106 |
|
|
mPixelX = mX * map->getTileWidth() |
107 |
|
|
+ subX + mapTileSize / 2; |
108 |
|
|
mPixelY = mY * map->getTileHeight() |
109 |
|
|
+ subY + mapTileSize - mHeightPosDiff; |
110 |
|
|
mPos.x = static_cast<float>(mPixelX); |
111 |
|
|
mPos.y = static_cast<float>(mPixelY); |
112 |
|
|
mYDiff = 31 - mHeightPosDiff; |
113 |
|
|
} |
114 |
|
|
else |
115 |
|
|
{ |
116 |
|
|
mPixelX = 0; |
117 |
|
|
mPixelY = 0; |
118 |
|
|
mPos.x = 0; |
119 |
|
|
mPos.y = 0; |
120 |
|
|
mYDiff = 31; |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
mCursor = info.getPickupCursor(); |
124 |
|
|
setupSpriteDisplay(info.getDisplay(), |
125 |
|
|
ForceDisplay_true, |
126 |
|
|
DisplayType::Floor, |
127 |
|
|
info.getDyeIconColorsString(mColor)); |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
void FloorItem::setCards(const int *const cards, |
131 |
|
|
int sz) |
132 |
|
|
{ |
133 |
|
|
if (sz < 0 || cards == nullptr) |
134 |
|
|
return; |
135 |
|
|
if (sz > maxCards) |
136 |
|
|
sz = maxCards; |
137 |
|
|
for (int f = 0; f < sz; f ++) |
138 |
|
|
mCards[f] = cards[f]; |
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
const ItemInfo &FloorItem::getInfo() const |
142 |
|
|
{ |
143 |
|
|
return ItemDB::get(mItemId); |
144 |
|
|
} |
145 |
|
|
|
146 |
|
|
std::string FloorItem::getName() const |
147 |
|
|
{ |
148 |
|
|
const ItemInfo &info = ItemDB::get(mItemId); |
149 |
|
|
#ifdef TMWA_SUPPORT |
150 |
|
|
if (Net::getNetworkType() == ServerType::TMWATHENA) |
151 |
|
|
{ |
152 |
|
|
return info.getName(); |
153 |
|
|
} |
154 |
|
|
#endif // TMWA_SUPPORT |
155 |
|
|
|
156 |
|
|
return info.getName(mColor); |
157 |
|
|
} |
158 |
|
|
|
159 |
|
|
void FloorItem::draw(Graphics *const graphics, |
160 |
|
|
const int offsetX, const int offsetY) const |
161 |
|
|
{ |
162 |
|
|
if (mMap == nullptr) |
163 |
|
|
return; |
164 |
|
|
|
165 |
|
|
BLOCK_START("FloorItem::draw") |
166 |
|
|
const int x = mX * mMap->getTileWidth() + offsetX; |
167 |
|
|
const int y = mY * mMap->getTileHeight() + offsetY - mHeightPosDiff; |
168 |
|
|
Font *font = nullptr; |
169 |
|
|
|
170 |
|
|
if (mHighlight) |
171 |
|
|
{ |
172 |
|
|
const time_t curTime = cur_time; |
173 |
|
|
font = gui->getFont(); |
174 |
|
|
if (mDropTime < curTime) |
175 |
|
|
{ |
176 |
|
|
const int dx = mapTileSize; |
177 |
|
|
const int dy = mapTileSize; |
178 |
|
|
|
179 |
|
|
if (curTime > mDropTime + 28 && curTime < mDropTime + 50) |
180 |
|
|
{ |
181 |
|
|
graphics->setColor(Color(80, 200, 20, 200)); |
182 |
|
|
graphics->fillRectangle(Rect( |
183 |
|
|
x, y, dx, dy)); |
184 |
|
|
} |
185 |
|
|
else if (curTime > mDropTime + 19 |
186 |
|
|
&& curTime < mDropTime + 28) |
187 |
|
|
{ |
188 |
|
|
graphics->setColor(Color(200, 80, 20, |
189 |
|
|
80 + 10 * CAST_S32(curTime - mDropTime - 18))); |
190 |
|
|
graphics->fillRectangle(Rect( |
191 |
|
|
x, y, dx, dy)); |
192 |
|
|
} |
193 |
|
|
else if (curTime > mDropTime && curTime < mDropTime + 20) |
194 |
|
|
{ |
195 |
|
|
graphics->setColor(Color(20, 20, 255, |
196 |
|
|
7 * CAST_S32(curTime - mDropTime))); |
197 |
|
|
graphics->fillRectangle(Rect(x, y, dx, dy)); |
198 |
|
|
} |
199 |
|
|
} |
200 |
|
|
} |
201 |
|
|
|
202 |
|
|
const int px = getActorX() + offsetX; |
203 |
|
|
const int py = getActorY() + offsetY; |
204 |
|
|
CompoundSprite::drawSimple(graphics, px, py); |
205 |
|
|
|
206 |
|
|
if (mHighlight) |
207 |
|
|
{ |
208 |
|
|
if (font != nullptr && mAmount > 1) |
209 |
|
|
{ |
210 |
|
|
const Color &color = userPalette->getColor( |
211 |
|
|
UserColorId::FLOOR_ITEM_TEXT, |
212 |
|
|
255U); |
213 |
|
|
font->drawString(graphics, |
214 |
|
|
color, color, |
215 |
|
|
toString(mAmount), |
216 |
|
|
x, y); |
217 |
|
|
} |
218 |
|
|
} |
219 |
|
|
BLOCK_END("FloorItem::draw") |
220 |
|
|
} |
221 |
|
|
|
222 |
|
|
int FloorItem::getCard(const int index) const |
223 |
|
|
{ |
224 |
|
|
if (index < 0 || index >= maxCards) |
225 |
|
|
return 0; |
226 |
|
|
return mCards[index]; |
227 |
|
2 |
} |