summaryrefslogtreecommitdiffstats
path: root/sigbattle/TeamMember.h
blob: 4a4c9aadf928973941a7e43ca27ceac8b6ff9934 (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
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
/*
 * 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/>.
 */

#ifndef SIGBATTLE_TEAMMEMBER
#define SIGBATTLE_TEAMMEMBER

// Sigbattle includes
#include "Global.h"

// Sigscript includes
#include "../sigscript/Config.h"

// Sigmod includes
#include "../sigmod/Global.h"

// Qt includes
#include <QtCore/QFuture>
#include <QtCore/QList>
#include <QtCore/QMap>
#include <QtCore/QMultiMap>
#include <QtCore/QObject>
#include <QtCore/QPair>
#include <QtCore/QString>
#include <QtCore/QUuid>

// Forward declarations
namespace Sigscript
{
class AbilityWrapper;
class ItemWrapper;
class MoveWrapper;
class NatureWrapper;
class MapTrainerTeamMemberWrapper;
class SigmodWrapper;
class SpeciesWrapper;
class StatusWrapper;
}
namespace Kross
{
class Action;
}

namespace Sigbattle
{
class Arena;
class Containment;

class SIGBATTLE_EXPORT TeamMember : public Sigscript::Config
{
    Q_OBJECT
    
    public:
        enum Gender
        {
            Male = 0,
            Female = 1,
            Genderless = 2
        };
        
        enum ActionType
        {
            Attack = 0,
            Item = 1,
            Switch = 2,
            Run = 3,
            Skip = 4,
            Timeout = 5,
            Invalid = 6
        };
        
        typedef QList<QUuid> Targets;
        typedef QPair<QVariant, Targets> ActionData;
        typedef QPair<ActionType, ActionData> Action;
        typedef QPair<TeamMember*, QFuture<TeamMember::Action> > RequestedAction;
        
        TeamMember(const int speciesId, const QString& name, const int level, Containment* containment, const bool suppressItems = false);
        TeamMember(Sigscript::MapTrainerTeamMemberWrapper* teamMember, Containment* containment);
        
        Containment* containment() const;
        
        QUuid id() const;
        
        QString name() const;
        long long currentHp() const;
        Sigscript::SpeciesWrapper* species() const;
        int level() const;
        Gender gender() const;
        long long levelExperience() const;
        int baseStat(const Sigmod::Stat stat) const;
        long long statExperience(const Sigmod::Stat stat) const;
        int dv(const Sigmod::Stat stat) const;
        long long statValue(const Sigmod::Stat stat, const long long exp = -1) const;
        long long calcExp(int level = -1) const;
        
        bool canLearnMove(Sigscript::MoveWrapper* move) const;
        
        long long timer() const;
        
        Sigscript::SigmodWrapper* sigmod() const;
    public slots:
        void boostLevels(const int levels);
        
        void evolveInto(Sigscript::SpeciesWrapper* newSpecies);
        
        void setName(const QString& name);
        void cureStatus(Sigscript::StatusWrapper* status);
        void giveStatus(Sigscript::StatusWrapper* status);
        void giveLevelExp(const int exp);
        void giveStatExp(const Sigmod::Stat stat, const int exp);
        void takeItem(Sigscript::ItemWrapper* item);
        void giveItem(Sigscript::ItemWrapper* item);
        void forgetMove(Sigscript::MoveWrapper* move);
        void teachMove(Sigscript::MoveWrapper* move);
        
        Action requestAction();
        Action latestAction() const;
        
        void makeActive(Arena* arena);
        void leaveArena();
        
        void advanceTimer(const long long jump);
        
        virtual void writeBack();
    signals:
        void speciesChanged(Sigscript::SpeciesWrapper* species);
        
        void evolveStart();
        void evolveEnd();
        
        void nameChanged(const QString& oldName, const QString& newName);
        
        void statusCured(Sigscript::StatusWrapper* status);
        void statusInflicted(Sigscript::StatusWrapper* status);
        
        void expGained(const int exp);
        void levelAboutToGrow();
        void levelGrown(const int newLevel);
        
        void statChanged(const Sigmod::Stat stat, const int value);
        void effortFull(const int stat);
        void totalEffortFull();
        
        void itemTaken(Sigscript::ItemWrapper* item);
        void itemGiven(Sigscript::ItemWrapper* item);
        
        void moveForgotten(Sigscript::MoveWrapper* move);
        void moveLearned(Sigscript::MoveWrapper* move);
        void movesFull(Sigscript::MoveWrapper* move);
        void unlearnableMove(Sigscript::MoveWrapper* move);
        
        void knockedOut();
    protected:
        bool checkWeight(const Sigscript::ItemWrapper* item);
        
        Containment* m_containment;
        
        const QUuid m_id;
        
        QString m_name;
        long long m_currentHp;
        Sigscript::SpeciesWrapper* m_species;
        Gender m_gender;
        long long m_levelExp;
        int m_level;
        long long m_statExp[Sigmod::ST_SpecialDefense - Sigmod::ST_HP + 1];
        int m_dv[Sigmod::ST_SpecialDefense - Sigmod::ST_HP + 1];
        QMultiMap<Sigscript::StatusWrapper*, Kross::Action*> m_status;
        QMap<Sigscript::AbilityWrapper*, Kross::Action*> m_abilities;
        QList<Sigscript::ItemWrapper*> m_items;
        QList<Sigscript::MoveWrapper*> m_moves;
        QList<Sigscript::NatureWrapper*> m_natures;
        
        long long m_timer;
        Action m_lastAction;
        
        QList<Kross::Action*> m_abilityBattleScripts;
        QList<Kross::Action*> m_statusBattleScripts;
    protected slots:
        void setSpecies(Sigscript::SpeciesWrapper* species);
        void setLevel(const int level);
    private:
        void makeConnections();
        
        void initAbility(Sigscript::AbilityWrapper* ability);
        
        void initItems();
        void initAbilities(const QList<Sigscript::AbilityWrapper*>& initial = QList<Sigscript::AbilityWrapper*>());
        void initMoves(const QList<Sigscript::MoveWrapper*>& initial = QList<Sigscript::MoveWrapper*>());
        void initNatures(const QList<Sigscript::NatureWrapper*>& initial = QList<Sigscript::NatureWrapper*>());
        void initStats();
    private slots:
        void levelGrown();
};

SIGBATTLE_EXPORT int actionPriority(TeamMember* teamMember, const TeamMember::Action& action);

}
Q_DECLARE_METATYPE(Sigbattle::TeamMember*)
Q_DECLARE_METATYPE(Sigbattle::TeamMember::Gender)
Q_DECLARE_METATYPE(Sigbattle::TeamMember::ActionType)
Q_DECLARE_METATYPE(Sigbattle::TeamMember::Targets)
Q_DECLARE_METATYPE(Sigbattle::TeamMember::ActionData)
Q_DECLARE_METATYPE(Sigbattle::TeamMember::Action)
Q_DECLARE_METATYPE(Sigbattle::TeamMember::RequestedAction)

#endif