summaryrefslogtreecommitdiffstats
path: root/pokemod/Item.cpp
blob: ddba2d68fc898a3f78db8760813cd501a3fdc703 (plain)
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
/*
 * Copyright 2007-2008 Ben Boeckel <MathStuf@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 3 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, see <http://www.gnu.org/licenses/>.
 */

// Header include
#include "Item.h"

// Pokemod includes
#include "Pokemod.h"
#include "Rules.h"

// Qt includes
#include <QSet>

Item::Item(const Item& item) :
        Object("Item", item.parent(), item.id())
{
    *this = item;
}

Item::Item(const Pokemod* parent, const int id) :
        Object("Item", parent, id),
        m_name(""),
        m_sellable(false),
        m_type(INT_MAX),
        m_price(0),
        m_description(""),
        m_script("", "")
{
}

Item::Item(const Item& item, const Pokemod* parent, const int id) :
        Object("Item", parent, id)
{
    *this = item;
}

Item::Item(const QDomElement& xml, const Pokemod* parent, const int id) :
        Object("Item", parent, id)
{
    load(xml, id);
}

Item::~Item()
{
}

void Item::validate()
{
    if (m_name.isEmpty())
        emit(error("Name is empty"));
    TEST(setType, type);
    TEST(setPrice, price);
}

void Item::load(const QDomElement& xml, int id)
{
    LOAD_ID();
    LOAD(QString, name);
    LOAD(bool, sellable);
    LOAD(int, type);
    LOAD(int, price);
    LOAD(QString, description);
    LOAD(Script, script);
}

QDomElement Item::save() const
{
    SAVE_CREATE();
    SAVE(QString, name);
    SAVE(bool, sellable);
    SAVE(int, type);
    SAVE(int, price);
    SAVE(QString, description);
    SAVE(Script, script);
    return xml;
}

void Item::setName(const QString& name)
{
    CHECK(name);
}

void Item::setSellable(const bool sellable)
{
    CHECK(sellable);
}

void Item::setType(const int type)
{
    if (static_cast<const Pokemod*>(pokemod())->itemTypeIndex(type) == INT_MAX)
    {
        emit(error(bounds("type")));
        return;
    }
    CHECK(type);
}

void Item::setPrice(const int price)
{
    if (static_cast<const Pokemod*>(pokemod())->rules()->maxMoney() < price)
    {
        emit(error(bounds("price")));
        return;
    }
    CHECK(price);
}

void Item::setDescription(const QString& description)
{
    CHECK(description);
}

void Item::setScript(const Script& script)
{
    CHECK(script);
}

QString Item::name() const
{
    return m_name;
}

bool Item::sellable() const
{
    return m_sellable;
}

int Item::type() const
{
    return m_type;
}

int Item::price() const
{
    return m_price;
}

QString Item::description() const
{
    return m_description;
}

Script Item::script() const
{
    return m_script;
}

Item& Item::operator=(const Item& rhs)
{
    if (this == &rhs)
        return *this;
    COPY(name);
    COPY(sellable);
    COPY(type);
    COPY(price);
    COPY(description);
    COPY(script);
    return *this;
}