Browse Source

add effects

igorbat99 6 years ago
parent
commit
d3846026aa

+ 10 - 23
include/effects/effect.h

@@ -30,40 +30,27 @@ public:
     //---------------------------------------------//
     //----------------GUI section------------------//
     //---------------------------------------------//
-
-    QString getUnitId() const;
-    QString getUnitName() const;
-    QString getUnitDescr() const;
-    QString getUnitBaseClassId() const;
-    std::vector<QString> getUnitTraits() const;
-    QImage getUnitIcon() const;
+    QString getEffectName() const;
+    QString getEffectDescr() const;
+    QImage getEffectIcon() const;
 
     //---------------------------------------------//
     //-----------Parameters load section-----------//
     //---------------------------------------------//
 
 private:
-    void loadUnitName(QString unit_folder);
-    void loadUnitDescr(QString unit_folder);
-    void loadUnitBaseClass(QString unit_folder);
-    void loadUnitTraits(QString unit_folder);
-    void loadUnitIcon(QString unit_folder);
-    void loadUnitPrevSpecs(QString unit_folder);
-    void loadUnitUpgradeSpecs(QString unit_folder);
+    void loadEffectDescr(QString effect_folder);
+    void loadEffectIcon(QString effect_folder);
 public:
-    virtual void OperateOnCell(Cell*) = 0;
-    virtual void OperateOnUnit(Unit*) = 0;
+    virtual void OperateOnCell(Cell* cell) = 0;
+    virtual void OperateOnUnit(Unit* unit) = 0;
 protected:
     int count_;
     int durability_;
 
     // GUI values
-    QString race_id_;
-    QString unit_id_;
-
-    QString unit_name_;
-    QString unit_descr_;
-    QString base_class_id_;
-    QImage unit_icon_;
+    QString effect_name_;
+    QString effect_descr_;
+    QImage effect_icon_;
 };
 #endif //THE_GAME_EFFECT_H

+ 2 - 1
include/effects/melledamage.h

@@ -9,6 +9,7 @@
 #include "effect\effect.h"
 
 class melledamage : public Effect {
-
+    void OperateOnCell(Cell* cell);
+    void OperateOnUnit(Unit* unit);
 };
 #endif //GAME_CLIENT_MELLEDAMAGE_H

+ 2 - 1
include/effects/selfheal.h

@@ -9,7 +9,8 @@
 #include "effect\effect.h"
 
 class selfheal : public Effect {
-
+    void OperateOnCell(Cell* cell);
+    void OperateOnUnit(Unit* unit);
 };
 
 #endif //GAME_CLIENT_SELFHEAL_H

+ 63 - 0
source/effects/effect.cpp

@@ -1,4 +1,67 @@
 //
 // Created by IgorBat on 21.04.2018.
 //
+#include "abstractfactory.h"
+#include "effects/effect.h"
 
+#include <iostream>
+#include <algorithm>
+#include <cassert>
+#include <string>
+
+#include <QFile>
+#include <QString>
+#include <QTextStream>
+
+Effect::Effect(QString parameters) {
+    QStringList params = parameters.split("|");
+
+    assert(params.size() >= 3);
+
+    effect_name_ = params[0];
+    count_ = params[1].toInt();
+    durability_ = params[2].toInt();
+    QString effect_folder = ":/assets/effects/" + effect_name_ + "/";
+
+    loadEffectDescr(effect_folder);
+    loadEffectIcon(effect_folder);
+}
+
+void Effect::loadUnitDescr(QString effect_folder) {
+    QFile file(effect_folder + "descr.txt");
+    file.open(QIODevice::ReadOnly);
+    QTextStream in(&file);
+    in.setCodec("UTF-8");
+    effect_descr_ = in.readAll();
+}
+
+void Effect::loadUnitIcon(QString effect_folder) {
+    effect_icon_.load(effect_folder + "icon.png");
+}
+
+
+QString Effect::getEffectName() const {
+    return effect_name_;
+}
+
+QString Effect::getEffectDescr() const {
+    return effect_descr_;
+}
+
+QImage Effect::getEffectIcon() const {
+    return effect_icon_;
+}
+
+int Effect::getCount(){
+    return count_;
+}
+void Effect::setCount(int value){
+    count_ = value;
+}
+
+int Effect::getDurability(){
+        return durability_;
+};
+void Effect::setDurability(int value){
+    durability_ = value;
+}

+ 15 - 0
source/effects/melledamage.cpp

@@ -2,3 +2,18 @@
 // Created by IgorBat on 23.04.2018.
 //
 
+#pragma once
+#include <cassert>
+#include "effect\melledamage.h"
+#include "units\unit.h"
+#include <string>
+
+void melledamage::OperateOnCell(Cell* cell){
+    throw std :: string("CAN'T TOUCH THIS")
+}
+
+void melledamage::OperateOnUnit(Unit* unit){
+    double temp = unit.reduceIncomingDamage("p", count_);
+    unit.setHealthPoints(unit.getHealthPoints() - temp);
+    //check_on_death
+}

+ 15 - 0
source/effects/selfheal.cpp

@@ -2,3 +2,18 @@
 // Created by IgorBat on 23.04.2018.
 //
 
+
+#pragma once
+#include <cassert>
+#include "effect\selfdamage.h"
+#include "units\unit.h"
+#include <string>
+
+void melledamage::OperateOnCell(Cell* cell){
+    throw std :: string("CAN'T TOUCH THIS")
+}
+
+void melledamage::OperateOnUnit(Unit* unit){
+    unit.setHealthPoints(unit.getHealthPoints() + count_);
+    //check_on_death
+}