Skip to content
Permalink
12d06b305d
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
114 lines (101 sloc) 2.7 KB
#include "../include/Hero.hpp"
#include "../include/Ability.hpp"
#include <iostream>
using namespace std;
Hero::Hero(int _id)
{
string filename = "Database/Game_Database.sqlite";
try
{
sqlite::sqlite db(filename);
auto cur = db.get_statement();
cur->set_sql("SELECT * FROM Heroes WHERE Hero_ID = ?;");
cur->prepare();
cur->bind(1, _id);
while(cur->step())
{
Hero_Name = cur->get_text(1);
Hero_Description = cur->get_text(2);
HP = cur->get_int(3);
MP = cur->get_int(4);
SP = cur->get_int(5);
SPD = cur->get_int(6);
DEF = cur->get_int(7);
}
cur->reset();
cur->set_sql("SELECT Ability_ID FROM Hero_Abilities WHERE Hero_ID = ?;");
cur->prepare();
cur->bind(1, _id);
while(cur->step())
{
ability_ids.emplace_back(cur->get_int(0));
}
}
catch(sqlite::exception e)
{
cerr << e.what() << endl;
}
for(int i=0; i<ability_ids.size(); ++i)
{
Ability hero_ability(ability_ids[i]);
abilities.push_back(hero_ability);
}
/**tuple<string, int> Hero_details = make_tuple(Hero_Name, Hero_Description, HP, MP, SP, SPD, DEF);
for(int i=0; i<tuple_size<decltype(Hero_details)>; ++i)
{
cout << get<i>(Hero_details) << endl;
}**/
}
int Hero::GetHP() {return HP;}
int Hero::GetSP() {return SP;}
int Hero::GetMP() {return MP;}
int Hero::GetSPD() {return SPD;}
int Hero::GetDEF() {return DEF;}
void Hero::DealDMG(int dmg) {HP = dmg * ((100-DEF)/100);}
void Hero::TakeSP(int amount)
{
SP -= amount;
if(SP < 0) SP = 0;
}
void Hero::TakeMP(int amount)
{
MP -= amount;
if(MP < 0) MP = 0;
}
void Hero::SetSPD(int speed) {SPD = speed;}
void Hero::SetDEF(int defence) {DEF = defence;}
ostream& operator<<( ostream& os, const Hero& hero )
{
os << "Details of " << hero.Hero_Name << ":\n"
<< "HP: " << hero.HP << "\n"
<< "SP: " << hero.SP << "\n"
<< "MP: " << hero.MP << "\n"
<< "SPD: " << hero.SPD << "\n"
<< "DEF: " << hero.DEF << "\n";
os << "Able to use:\n";
os << "I don't know what I'm doing." << endl;
return os;
}
/**
ostream& operator<<( ostream& os, const Ability& ability )
{
os << ability.Ability_Name << ":\n"
<< "Deals " << ability.Damage_Min << "-" << ability.Damage_Max << " damage\n"
<< "Heals for " << ability.Heal_Min << "-" << ability.Heal_Max << " points\n"
<< "Costs " << ability.Mana_Cost << " mana and " << ability.Stamina_Cost << " stamina\n"
<< "Have the following effects:\n";
return os;
}
ostream& operator<<( ostream& os, const Effect& effect )
{
os << effect.Effect_Name << "affects the " << effect.Target_Stat << " of the targeted hero for "
<< effect.Duration << " turns and have an impact of " << effect.Impact << "." << endl;
return os;
}
**/
int main()
{
Hero Natalie(1);
cout << Natalie << endl;
//Ability_Effects(1);
}