2011-08-28 15:17:58 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2011-08-15 16:11:24 +02:00
|
|
|
#include "item.h"
|
2011-08-31 17:03:33 +02:00
|
|
|
#include "thingstype.h"
|
2011-08-15 21:15:49 +02:00
|
|
|
#include "spritemanager.h"
|
2011-08-15 16:11:24 +02:00
|
|
|
#include "thing.h"
|
2011-12-01 23:25:32 +01:00
|
|
|
#include <framework/core/clock.h>
|
2011-12-27 03:18:15 +01:00
|
|
|
#include <framework/core/eventdispatcher.h>
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2011-08-31 22:22:57 +02:00
|
|
|
Item::Item() : Thing()
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2011-11-08 02:44:30 +01:00
|
|
|
m_data = 0;
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2011-11-08 02:44:30 +01:00
|
|
|
void Item::draw(const Point& p)
|
2011-08-28 21:51:34 +02:00
|
|
|
{
|
2011-12-02 03:29:05 +01:00
|
|
|
if(m_type->dimensions[ThingType::AnimationPhases] > 1)
|
|
|
|
m_animation = (g_clock.ticks() % (TICKS_PER_FRAME * m_type->dimensions[ThingType::AnimationPhases])) / TICKS_PER_FRAME;
|
2011-08-28 21:51:34 +02:00
|
|
|
|
2011-12-02 03:29:05 +01:00
|
|
|
for(int b = 0; b < m_type->dimensions[ThingType::Layers]; b++)
|
2011-11-08 02:44:30 +01:00
|
|
|
internalDraw(p, b);
|
2011-08-28 21:51:34 +02:00
|
|
|
}
|
|
|
|
|
2011-11-13 09:46:19 +01:00
|
|
|
void Item::setPosition(const Position& position)
|
2011-08-28 21:47:23 +02:00
|
|
|
{
|
2011-12-02 03:29:05 +01:00
|
|
|
if(m_type->properties[ThingType::IsGround]) {
|
|
|
|
m_xPattern = position.x % m_type->dimensions[ThingType::PatternX];
|
|
|
|
m_yPattern = position.y % m_type->dimensions[ThingType::PatternY];
|
|
|
|
m_zPattern = position.z % m_type->dimensions[ThingType::PatternZ];
|
2011-08-25 15:30:46 +02:00
|
|
|
}
|
2011-11-13 09:46:19 +01:00
|
|
|
|
|
|
|
Thing::setPosition(position);
|
2011-08-28 21:47:23 +02:00
|
|
|
}
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2011-11-13 09:46:19 +01:00
|
|
|
void Item::setData(int data)
|
2011-08-28 21:47:23 +02:00
|
|
|
{
|
2011-12-02 03:29:05 +01:00
|
|
|
if(m_type->properties[ThingType::IsStackable] && m_type->dimensions[ThingType::PatternX] == 4 && m_type->dimensions[ThingType::PatternY] == 2) {
|
2011-11-13 09:46:19 +01:00
|
|
|
if(data < 5) {
|
|
|
|
m_xPattern = data-1;
|
2011-08-31 15:58:01 +02:00
|
|
|
m_yPattern = 0;
|
2011-08-24 05:58:23 +02:00
|
|
|
}
|
2011-11-13 09:46:19 +01:00
|
|
|
else if(data < 10) {
|
2011-08-31 15:58:01 +02:00
|
|
|
m_xPattern = 0;
|
|
|
|
m_yPattern = 1;
|
2011-08-24 05:58:23 +02:00
|
|
|
}
|
2011-11-13 09:46:19 +01:00
|
|
|
else if(data < 25) {
|
2011-08-31 15:58:01 +02:00
|
|
|
m_xPattern = 1;
|
|
|
|
m_yPattern = 1;
|
2011-08-24 05:58:23 +02:00
|
|
|
}
|
2011-11-13 09:46:19 +01:00
|
|
|
else if(data < 50) {
|
2011-08-31 15:58:01 +02:00
|
|
|
m_xPattern = 2;
|
|
|
|
m_yPattern = 1;
|
2011-08-24 05:58:23 +02:00
|
|
|
}
|
2011-11-13 09:46:19 +01:00
|
|
|
else if(data <= 100) {
|
2011-08-31 15:58:01 +02:00
|
|
|
m_xPattern = 3;
|
|
|
|
m_yPattern = 1;
|
2011-08-24 05:58:23 +02:00
|
|
|
}
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
2011-12-02 03:29:05 +01:00
|
|
|
else if(m_type->properties[ThingType::IsHangable]) {
|
|
|
|
if(m_type->properties[ThingType::HookSouth]) {
|
|
|
|
m_xPattern = m_type->dimensions[ThingType::PatternX] >= 2 ? 1 : 0;
|
2011-11-08 02:44:30 +01:00
|
|
|
}
|
2011-12-02 03:29:05 +01:00
|
|
|
else if(m_type->properties[ThingType::HookEast]) {
|
|
|
|
m_xPattern = m_type->dimensions[ThingType::PatternX] >= 3 ? 2 : 0;
|
2011-11-08 02:44:30 +01:00
|
|
|
}
|
|
|
|
}
|
2011-12-02 03:29:05 +01:00
|
|
|
else if(m_type->properties[ThingType::IsFluid] || m_type->properties[ThingType::IsFluidContainer]) {
|
2011-11-30 19:59:36 +01:00
|
|
|
int color = 0;
|
|
|
|
// TODO: find out what the heck does it mean 4, 7, 12, 13, 14, 16, 17. options are already there
|
2011-11-13 09:46:19 +01:00
|
|
|
switch(data) {
|
2011-11-08 02:44:30 +01:00
|
|
|
case 0:
|
2011-11-30 19:59:36 +01:00
|
|
|
color = 0;
|
2011-11-08 02:44:30 +01:00
|
|
|
break;
|
2011-11-30 19:59:36 +01:00
|
|
|
case Otc::FluidWater:
|
|
|
|
color = Otc::FluidBlue;
|
2011-11-08 02:44:30 +01:00
|
|
|
break;
|
2011-11-30 19:59:36 +01:00
|
|
|
case Otc::FluidMana:
|
|
|
|
color = Otc::FluidPurple;
|
2011-11-08 02:44:30 +01:00
|
|
|
break;
|
2011-11-30 19:59:36 +01:00
|
|
|
case Otc::FluidBeer:
|
|
|
|
color = Otc::FluidBrown;
|
2011-11-08 02:44:30 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
2011-11-30 19:59:36 +01:00
|
|
|
color = Otc::FluidBrown; // oil, mud, mead, rum, tea
|
2011-11-08 02:44:30 +01:00
|
|
|
break;
|
2011-11-30 19:59:36 +01:00
|
|
|
case Otc::FluidBlood:
|
|
|
|
color = Otc::FluidRed;
|
2011-11-08 02:44:30 +01:00
|
|
|
break;
|
2011-11-30 19:59:36 +01:00
|
|
|
case Otc::FluidSlime:
|
|
|
|
color = Otc::FluidGreen;
|
2011-11-08 02:44:30 +01:00
|
|
|
break;
|
|
|
|
case 7:
|
2011-11-30 19:59:36 +01:00
|
|
|
color = Otc::FluidBrown; // oil, mud, mead, rum, tea
|
2011-11-08 02:44:30 +01:00
|
|
|
break;
|
2011-11-30 19:59:36 +01:00
|
|
|
case Otc::FluidLemonade:
|
|
|
|
color = Otc::FluidYellow;
|
2011-11-08 02:44:30 +01:00
|
|
|
break;
|
2011-11-30 19:59:36 +01:00
|
|
|
case Otc::FluidMilk:
|
|
|
|
color = Otc::FluidWhite;
|
2011-11-08 02:44:30 +01:00
|
|
|
break;
|
2011-11-30 19:59:36 +01:00
|
|
|
case Otc::FluidWine:
|
|
|
|
color = Otc::FluidPurple;
|
2011-11-08 02:44:30 +01:00
|
|
|
break;
|
2011-11-30 19:59:36 +01:00
|
|
|
case Otc::FluidHealth:
|
|
|
|
color = Otc::FluidRed;
|
2011-11-08 02:44:30 +01:00
|
|
|
break;
|
|
|
|
case 12:
|
2011-11-30 19:59:36 +01:00
|
|
|
color = Otc::FluidYellow; // urine, fruit juice
|
2011-11-08 02:44:30 +01:00
|
|
|
break;
|
|
|
|
case 13:
|
2011-11-30 19:59:36 +01:00
|
|
|
color = Otc::FluidBrown; // oil, mud, mead, rum, tea
|
2011-11-08 02:44:30 +01:00
|
|
|
break;
|
|
|
|
case 14:
|
2011-11-30 19:59:36 +01:00
|
|
|
color = Otc::FluidYellow; // urine, fruit juice
|
2011-11-08 02:44:30 +01:00
|
|
|
break;
|
2011-11-30 19:59:36 +01:00
|
|
|
case Otc::FluidCoconutMilk:
|
|
|
|
color = Otc::FluidWhite;
|
2011-11-08 02:44:30 +01:00
|
|
|
break;
|
|
|
|
case 16:
|
2011-11-30 19:59:36 +01:00
|
|
|
color = Otc::FluidBrown; // oil, mud, mead, rum, tea
|
2011-11-08 02:44:30 +01:00
|
|
|
break;
|
|
|
|
case 17:
|
2011-11-30 19:59:36 +01:00
|
|
|
color = Otc::FluidBrown; // oil, mud, mead, rum, tea
|
2011-11-08 02:44:30 +01:00
|
|
|
break;
|
|
|
|
default:
|
2011-11-30 19:59:36 +01:00
|
|
|
color = 1;
|
2011-11-08 02:44:30 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-02 03:29:05 +01:00
|
|
|
m_xPattern = (color % 4) % m_type->dimensions[ThingType::PatternX];
|
|
|
|
m_yPattern = (color / 4) % m_type->dimensions[ThingType::PatternY];
|
2011-11-08 02:44:30 +01:00
|
|
|
}
|
2011-11-13 09:46:19 +01:00
|
|
|
|
|
|
|
m_data = data;
|
|
|
|
}
|
|
|
|
|
2011-12-02 03:29:05 +01:00
|
|
|
ThingType *Item::getType()
|
2011-11-13 09:46:19 +01:00
|
|
|
{
|
|
|
|
return g_thingsType.getThingType(m_id, ThingsType::Item);
|
2011-08-28 21:47:23 +02:00
|
|
|
}
|