Bläddra i källkod

Done: basic spell/skill model. TODO: Spell:traits

igorbat99 6 år sedan
förälder
incheckning
fd5ce3aaaa

+ 2 - 1
assets/effects/effects.txt

@@ -1 +1,2 @@
-Effect of instance heal to Unit.
+melledamage
+selfheal

+ 2 - 0
assets/skills/melledamage/traits.txt

@@ -1,2 +1,4 @@
 1
+1
+0
 melledamage|10|0

+ 2 - 0
assets/skills/selfheal/traits.txt

@@ -1,2 +1,4 @@
 1
+1
+0
 selfheal|5|0

+ 2 - 10
include/skills/melledamage.h

@@ -6,18 +6,10 @@
 #define GAME_CLIENT_MELLEDAMAGE_H
 #pragma once
 #include <cassert>
-#include "effect\effect.h"
+#include "skills\spell.h"
 
 class melledamage : public Effect {
-    Mage() = delete;
-    Mage(std::string id);
-    ~Mage();
-
-    bool canAttackForDistance(int distance);
-
-    bool canAttackToCell(Cell* destination);
-
-    bool canAttackUnit(Unit* target);
+    void CastSpell(Cell* from, Cell* where, Unit* who, Unit* whom);
 };
 
 #endif //GAME_CLIENT_MELLEDAMAGE_H

+ 6 - 13
include/skills/selfheal.h

@@ -2,22 +2,15 @@
 // Created by IgorBat on 23.04.2018.
 //
 
-#ifndef GAME_CLIENT_MELLEDAMAGE_H
-#define GAME_CLIENT_MELLEDAMAGE_H
+#ifndef GAME_CLIENT_SELFHEAL_H
+#define GAME_CLIENT_SELFHEAL_H
 #pragma once
 #include <cassert>
-#include "effect\effect.h"
+#include "skills\spell.h"
 
-class melledamage : public Effect {
-    Mage() = delete;
-    Mage(std::string id);
-    ~Mage();
+class selfheal : public Spell {
+    void CastSpell(Cell* from, Cell* where, Unit* who, Unit* whom);
 
-    bool canAttackForDistance(int distance);
-
-    bool canAttackToCell(Cell* destination);
-
-    bool canAttackUnit(Unit* target);
 };
 
-#endif //GAME_CLIENT_MELLEDAMAGE_H
+#endif //GAME_CLIENT_SELFHEAL_H

+ 27 - 11
include/skills/spell.h

@@ -18,20 +18,18 @@ class Unit{
 class Cell{
     std :: list <Effect> effectsOnCell;
 };
-class Spell {
+class Spell : public QObject {
+    Q_OBJECT
 
 protected:
     std :: list <Effect> effects_;
-
 private:
     int distance_;
     bool forCell_;
 public:
-    Spell() = delete;
-    Spell(std::string path) {
+    explicit Spell(QString parameters);
 
-    }
-    virtual ~Spell() = delete;
+    virtual ~Spell() {}
 
     int getDistance();
     void setDistance(int value);
@@ -39,14 +37,32 @@ public:
     bool getForCell();
     void setForCell(bool value);
 
-    //int lenOfSmallestPath(Cell* destination);
+    virtual bool canCastToCell(Cell* destination, Cell* from);
+
+    virtual void CastSpell(Cell* from, Cell* where, Unit* who, Unit* whom) = 0;
 
-    virtual bool canCastForDistance(int distance);
+    int getDistance();
+    void setDistance(int Value);
 
-    virtual bool canCastToCell(Cell* destination);
+    bool getForCell();
+    void setForCell(bool Value);
 
-    virtual void castToCell(Cell* destination);
+    QString getSpellName() const;
+    QString getSpellDescr() const;
+    QImage getSpellIcon() const;
+
+    //---------------------------------------------//
+    //-----------Parameters load section-----------//
+    //---------------------------------------------//
+
+private:
+    void loadSpellTraits(QString spell_folder);
+    void loadSpellDescr(QString spell_folder);
+    void loadSpellIcon(QString spell_folder);
 
-    void CastSpell(Cell* from, Cell* where, Unit* who, Unit* whom);
+    // GUI values
+    QString spell_name_;
+    QString spell_descr_;
+    QImage spell_icon_;
 };
 #endif //THE_GAME_SPELL_H

+ 4 - 4
source/effects/effect.cpp

@@ -19,15 +19,15 @@ Effect::Effect(QString parameters) {
     assert(params.size() >= 3);
 
     effect_name_ = params[0];
-    count_ = params[1].toInt();
-    durability_ = params[2].toInt();
+    setCount(params[1].toInt());
+    setDurability(params[2].toInt());
     QString effect_folder = ":/assets/effects/" + effect_name_ + "/";
 
     loadEffectDescr(effect_folder);
     loadEffectIcon(effect_folder);
 }
 
-void Effect::loadUnitDescr(QString effect_folder) {
+void Effect::loadEffectDescr(QString effect_folder) {
     QFile file(effect_folder + "descr.txt");
     file.open(QIODevice::ReadOnly);
     QTextStream in(&file);
@@ -35,7 +35,7 @@ void Effect::loadUnitDescr(QString effect_folder) {
     effect_descr_ = in.readAll();
 }
 
-void Effect::loadUnitIcon(QString effect_folder) {
+void Effect::loadEffectIcon(QString effect_folder) {
     effect_icon_.load(effect_folder + "icon.png");
 }
 

+ 2 - 2
source/effects/melledamage.cpp

@@ -13,7 +13,7 @@ void melledamage::OperateOnCell(Cell* cell){
 }
 
 void melledamage::OperateOnUnit(Unit* unit){
-    double temp = unit.reduceIncomingDamage("p", count_);
-    unit.setHealthPoints(unit.getHealthPoints() - temp);
+    int temp = unit -> reduceIncomingDamage("p", count_);
+    unit ->setHealthPoints(unit -> getHealthPoints() - temp);
     //check_on_death
 }

+ 3 - 0
source/skills/melledamage.cpp

@@ -2,3 +2,6 @@
 // Created by IgorBat on 23.04.2018.
 //
 
+void melledamage::CastSpell(Cell* from, Cell* where, Unit* who, Unit* whom){
+    effects_[0] -> OperateOnUnit(whom);
+}

+ 3 - 0
source/skills/selfheal.cpp

@@ -2,3 +2,6 @@
 // Created by IgorBat on 23.04.2018.
 //
 
+void selfheal::CastSpell(Cell* from, Cell* where, Unit* who, Unit* whom){
+    effects_[0] -> OperateOnUnit(who);
+}

+ 71 - 0
source/skills/spell.cpp

@@ -2,3 +2,74 @@
 // Created by IgorBat on 21.04.2018.
 //
 
+#include "abstractfactory.h"
+#include "skills/spell.h"
+
+#include <iostream>
+#include <algorithm>
+#include <cassert>
+#include <string>
+
+#include <QFile>
+#include <QString>
+#include <QTextStream>
+
+Spell::Spell(QString parameters) {
+    QStringList params = parameters.split("\n");
+    assert(params.size() >= 1);
+    spell_name_ = param[0];
+    QString spell_folder = ":/assets/skills/" + spell_name_ + "/";
+
+    loadSpellDescr(spell_folder);
+    loadSpellIcon(spell_folder);
+    loadSpellTraits(spell_folder);
+}
+
+void Spell::loadSpellDescr(QString spell_folder) {
+    QFile file(spell_folder + "descr.txt");
+    file.open(QIODevice::ReadOnly);
+    QTextStream in(&file);
+    in.setCodec("UTF-8");
+    spell_descr_ = in.readAll();
+}
+
+void Spell::loadSpellIcon(QString spell_folder) {
+    spell_icon_.load(spell_folder + "icon.png");
+}
+
+void Spell::loadSpellTraits(QString spell_folder) {
+    /*
+     * you can do it by yourself, i need to sleep
+     */
+
+}
+
+QString Spell::getSpellName() const {
+    return spell_name_;
+}
+
+QString Spell::getSpellDescr() const {
+    return spell_descr_;
+}
+
+QImage Spell::getSpellIcon() const {
+    return spell_icon_;
+}
+
+int Spell::getDistance(){
+    return distance_;
+}
+void setDistance(int value){
+    distance_ = value;
+}
+
+bool getForCell(){
+    return forCell_;
+}
+void setForCell(bool value){
+    forCell_ = value;
+}
+bool Spell::canCastToCell(Cell* destination, Cell* from){
+    if(from -> lenOfActualPath(destination) == 1) return true;
+    return false;
+}