Skip to content
Permalink
master
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
#include <string>
#include "sql.h"
#include <stdlib.h>
#include <vector>
#include <stdio.h>
#include "random.h"
class Quest {
public:
std::string name;
std::string description;
int requirement;
std::string follower_id;
int status;
std::string item;
int gold;
int xp;
std::string query;
int determine_xp() {
int xp;
int min = 50;
int max = 5000;
xp = randomNum(min, max);
return xp;
}
int determine_gold() {
int gold;
int min = 1;
int max = 1000;
gold = randomNum(min, max);
return gold;
}
int determine_requirement() {
int num_of_enemies;
int min = 10;
int max = 50;
num_of_enemies = randomNum(min, max);
return num_of_enemies;
}
/*
make_active()
make complete()
determine description
determine follower_id
determine gold
determine xp
determine item
determine name
populate database with random quests
*/
std::string determine_enemy() {
query = "SELECT Name FROM Enemies ORDER BY RANDOM() LIMIT 1";
std::vector<std::string>results;
results = sql_call(query, false);
std::string enemy = results[0];
return enemy;
}
std::string determine_item() {
query = "SELECT Description FROM Items ORDER BY RANDOM() LIMIT 1";
std::vector<std::string>results;
results = sql_call(query, false);
item = results[1];
return item;
}
std::string determine_quest_test() {
query = "SELECT * FROM Quests";
std::vector<std::string>results;
results = sql_call(query, false);
std::string quest_test = results[0];
return quest_test;
}
void generate_quest() {
std::string enemy = determine_enemy();
//test enemy
//std::cout << "enemy = " << enemy << "\n";
xp = determine_xp();
//test xp
//std::cout << "xp = " << xp << "\n";
gold = determine_gold();
//test gold
//std::cout << "gold = " << gold << "\n";
//requirement is the number of enemies that need to be killed
requirement = determine_requirement();
//test requirement
//std::cout << "Requirement = " << requirement << "\n";
//get item name
item = determine_item();
//test item
//std::cout << "item = " << item << "\n";
//create query to insert into database
name = "Kill " + enemy +"s";
description = "Kill " + std::to_string(requirement) + " " + enemy + " for " + item;
int follower_ID = 0;
status = 1;
query = "INSERT INTO Quests(Name, Description, Requirement, Status, Follower_ID, Item, Gold, XP) VALUES (\"" + name + "\"" + ", \"" + description + "\", " + "\"" + std::to_string(requirement) + "\", " + std::to_string(status) + ", " + std::to_string(follower_ID) + ", \"" + item + "\", " + std::to_string(gold) + ", " + std::to_string(gold) + ")";
//std::cout << query << "\n";
bool a= true;
while (a == true) {
try {
sql_call(query);
a = false;
}
catch (exception e) {
continue;
}
}
//std::string select_call = "SELECT * FROM Quests";
//std::string quest_test = determine_quest_test();
//std::cout << quest_test << "\n";
}
void set_to_complete() {
query = "UPDATE Quests SET Status = 1 WHERE Name = " + '"' + name + "'";
sql_call(query);
}
};