소스 검색

att execute

igorbat99 6 년 전
부모
커밋
df318d51ce

+ 2 - 1
client.pro

@@ -163,7 +163,8 @@ HEADERS +=                                      \
     ui/dialog_form/dialogform.h                 \
     ui/about_us/aboutus.h \
     include/effects/selfmove.h \
-    include/spells/selfmovespell.h
+    include/spells/selfmovespell.h \
+    include/spellsmanager.h
 
 FORMS +=                                        \
     ui/hotseat_game/hotseatgame.ui              \

+ 6 - 0
include/effects/effect.h

@@ -21,6 +21,11 @@ class Effect : public QObject {
     Q_OBJECT
 
 public:
+    enum TypeOfTrigger{
+        InCome = 1,
+        AfterAction = 2,
+        AfterEndTurn = 3
+    };
     explicit Effect(QString parameters);
 
     virtual ~Effect() {}
@@ -49,6 +54,7 @@ public:
     virtual void OperateOnCell(Cell* cell) = 0;
     virtual void OperateOnUnit(Unit* unit) = 0;
     virtual void OperateOnUnitToCell(Unit* who, Cell* where) = 0;
+    virtual void Execute(Cell* from, Cell* where, Unit* who, Unit* whom, TypeOfTrigger Type) = 0;
 protected:
     int count_;
     int durability_;

+ 1 - 0
include/effects/meleedamage.h

@@ -12,5 +12,6 @@ class MeleeDamage : public Effect {
     void OperateOnCell(Cell* cell);
     void OperateOnUnit(Unit* unit);
     void OperateOnUnitToCell(Unit* who, Cell* where);
+    void Execute(Cell* from, Cell* where, Unit* who, Unit* whom, TypeOfTrigger Type);
 };
 #endif //GAME_CLIENT_MELEEDAMAGE_H

+ 1 - 0
include/effects/selfheal.h

@@ -12,6 +12,7 @@ class SelfHeal : public Effect {
     void OperateOnCell(Cell* cell);
     void OperateOnUnit(Unit* unit);
     void OperateOnUnitToCell(Unit* who, Cell* where);
+    void Execute(Cell* from, Cell* where, Unit* who, Unit* whom, TypeOfTrigger Type);
 };
 
 #endif //GAME_CLIENT_SELFHEAL_H

+ 1 - 0
include/effects/selfmove.h

@@ -7,6 +7,7 @@ class SelfMove : public Effect {
     void OperateOnUnitAndCell(Unit* who, Cell* where);
     void OperateOnCell(Cell* cell);
     void OperateOnUnit(Unit* unit);
+    void Execute(Cell* from, Cell* where, Unit* who, Unit* whom, TypeOfTrigger Type);
 };
 
 

+ 33 - 0
include/spellsmanager.h

@@ -0,0 +1,33 @@
+#ifndef SPELLSMANAGER_H
+#define SPELLSMANAGER_H
+/*#include <QObject>
+#include <QString>
+#include <QImage>
+
+#include <vector>
+
+#include "abstractfactory.h"
+#include "effects/effect.h"
+#include "spells/spell.h"
+
+class SpellManager : public QObject
+{
+    Q_OBJECT
+public:
+    //explicit Race(QString race_name, QObject *parent = nullptr);
+
+    std::shared_ptr<Spell> createSpell(QString spell_name);
+
+    const std::vector<QString> &getAvailableUnitsList();
+    const std::vector<std::shared_ptr<Unit>> &getAllUnitsList();
+
+private:
+    QString race_id_;
+    QString race_name_;
+    QImage race_icon_;
+    QString race_descr_;
+    ObjectFactory<Unit, QString> spells_factory_;
+    std::vector<QString> available_spells_list_;
+    std::vector<std::shared_ptr<Unit>> all_spells_list_;
+}*/
+#endif // SPELLSMANAGER_H

+ 5 - 0
source/effects/meleedamage.cpp

@@ -20,3 +20,8 @@ void MeleeDamage::OperateOnUnit(Unit* unit){
     //unit ->setHealthPoints(unit -> getHealthPoints() - temp);
     //check_on_death
 }
+
+void MeleeDamage::Execute(Cell* from, Cell* where, Unit* who, Unit* whom, TypeOfTrigger Type){
+    if(Type == 1)
+        OperateOnUnit(whom);
+}

+ 6 - 0
source/effects/selfheal.cpp

@@ -19,3 +19,9 @@ void SelfHeal::OperateOnUnit(Unit* unit){
 void SelfHeal::OperateOnUnitToCell(Unit* who, Cell* where){
     throw std :: string("CAN'T TOUCH THIS");
 }
+
+void SelfHeal::Execute(Cell* from, Cell* where, Unit* who, Unit* whom, TypeOfTrigger Type){
+    if(Type == 1)
+        OperateOnUnit(who);
+}
+

+ 5 - 0
source/effects/selfmove.cpp

@@ -15,3 +15,8 @@ void SelfMove::OperateOnUnit(Unit* unit){
 void SelfMove::OperateOnUnitAndCell(Unit* unit, Cell* cell){
     unit->setLocation(cell);
 }
+
+void SelfMove::Execute(Cell* from, Cell* where, Unit* who, Unit* whom, TypeOfTrigger Type){
+    if(Type == 1)
+        OperateOnUnitAndCell(who, where);
+}

+ 11 - 4
source/spells/spell.cpp

@@ -38,10 +38,17 @@ void Spell::loadSpellIcon(QString spell_folder) {
 }
 
 void Spell::loadSpellTraits(QString spell_folder) {
-    /*
-     * you can do it by yourself, i need to sleep
-     */
-
+    QFile file(spell_folder + "traits.txt");
+    file.open(QIODevice::ReadOnly);
+    QTextStream in(&file);
+    in.setCodec("UTF-8");
+    QString traits_containts = in.readAll();
+    QStringList params = traits_containts.split("\n");
+    assert(params.size() >= 1);
+    size_t countEffects = params[0].toInt();
+    for (size_t i = 1; i <= countEffects; ++i){
+        effects_.push_back(new Effect(params[i]));
+    }
 }
 
 QString Spell::getSpellName() const {