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
71 lines (62 sloc) 1.64 KB
#include "../include/Ability.hpp"
#include "../include/Effect.hpp"
#include <iostream>
Ability::Ability(int _id)
{
string filename = "Database/Game_Database.sqlite";
try
{
sqlite::sqlite db(filename);
auto cur = db.get_statement();
cur->set_sql("SELECT * FROM Abilities WHERE Ability_ID = ?;");
cur->prepare();
cur->bind(1, _id);
while(cur->step())
{
Ability_Name = cur->get_text(1);
Ability_Description = cur->get_text(2);
Damage_Max = cur->get_int(3);
Damage_Min = cur->get_int(4);
Heal_Max = cur->get_int(5);
Heal_Min = cur->get_int(6);
Mana_Cost = cur->get_int(7);
Stamina_Cost = cur->get_int(8);
}
cur->reset();
cur->set_sql("SELECT Effect_ID FROM Ability_Effects WHERE Ability_ID = ?;");
cur->prepare();
cur->bind(1, _id);
while(cur->step())
{
effect_ids.emplace_back(cur->get_int(0));
}
}
catch(sqlite::exception e)
{
cerr << e.what() << endl;
}
for(int i=0; i<effect_ids.size(); ++i)
{
Effect ability_effect(effect_ids[i]);
effects.push_back(ability_effect);
}
}
int Ability::GetDamage()
{
srand((int) time(0));
return (rand() % Damage_Max - Damage_Min) + Damage_Min + 1;
}
int Ability::GetHealing()
{
srand((int time(0));
return (rand() % Heal_Max - Heal_Min) + Heal_Min + 1;
}
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;
}