2 Commits 8b2e043f1e ... 41b4a25ca9

Auteur SHA1 Bericht Datum
  igorbat99 41b4a25ca9 did the CanCast? 6 jaren geleden
  igorbat99 df318d51ce att execute 6 jaren geleden

+ 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);
 };
 
 

+ 1 - 1
include/spells/spell.h

@@ -34,7 +34,7 @@ public:
     void setForCell(bool value);
 
     virtual bool canCastToCell(Cell* destination, Cell* from);
-
+    bool isNeirbor(Cell* destination, Cell* from);
     virtual void CastSpell(Cell* from, Cell* where, Unit* who, Unit* whom) = 0;
 
     QString getSpellName() const;

+ 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

+ 7 - 3
source/effects/meleedamage.cpp

@@ -16,7 +16,11 @@ void MeleeDamage::OperateOnUnitToCell(Unit* who, Cell* where){
 }
 
 void MeleeDamage::OperateOnUnit(Unit* unit){
-    //int temp = unit -> reduceIncomingDamage("p", count_);
-    //unit ->setHealthPoints(unit -> getHealthPoints() - temp);
-    //check_on_death
+//    unit->setHealthPoints(  unit->getHealthPoints() -
+//                            (count_ - 2.5 * double(count_) * double(unit->getPhysicDefence()) / 100.0));
+}
+
+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);
+}

+ 4 - 0
source/spells/meleedamagespell.cpp

@@ -11,3 +11,7 @@
 void MeleeDamageSpell::CastSpell(Cell* from, Cell* where, Unit* who, Unit* whom){
     effects_[0] -> OperateOnUnit(whom);
 }
+
+bool MeleeDamageSpell::canCastToCell(Cell* destination, Cell* from){
+    return isNeirbor(Cell* destination, Cell* from);
+}

+ 4 - 0
source/spells/selfhealspell.cpp

@@ -12,3 +12,7 @@
 void SelfHealSpell::CastSpell(Cell* from, Cell* where, Unit* who, Unit* whom){
     effects_[0] -> OperateOnUnit(who);
 }
+
+bool SelfHealSpell::canCastToCell(Cell* destination, Cell* from){
+    return isNeirbor(Cell* destination, Cell* from);
+}

+ 4 - 0
source/spells/selfmovespell.cpp

@@ -8,3 +8,7 @@
 void SelfMoveSpell::CastSpell(Cell* from, Cell* where, Unit* who, Unit* whom){
     effects_[0] -> OperateOnUnitToCell(who, where);
 }
+
+bool SelfMoveSpell::canCastToCell(Cell* destination, Cell* from){
+    return isNeirbor(Cell* destination, Cell* from);
+}

+ 19 - 7
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 {
@@ -69,7 +76,12 @@ bool Spell::getForCell(){
 void Spell::setForCell(bool value){
     forCell_ = value;
 }
-bool Spell::canCastToCell(Cell* destination, Cell* from){
-    //if(from -> lenOfActualPath(destination) == 1) return true;
-    return false;
+
+bool Spell::isNeirbor(Cell* destination, Cell* from){
+    return from -> getleft() == destination ||
+           from -> getleftDown() == destination ||
+           from -> getleftUp() == destination ||
+           from -> getright() == destination ||
+           from -> getrightDown() == destination ||
+           from -> getrightUp() == destination;
 }