1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
//includes, librarys, namespace
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <string>
using namespace std;
//character definition, characters, chars, char, player, npc, enemy
//#1
//line1: if it can be attacked it counts as a character
struct character
{
//#2
//line1: the combat system works like this the attack has a (*agility*25)%c chance of hitting making the max agility lvl 4. then if it hits the damage is
//line2: see comment #5"(attack lvl give or take a 3rd) - (defence lvl give or take a third)"
int defence;
int attack;
int agility;
int gold;
int lvl;
int xp;
int health;
string name;
};
//drops, drop, xp, eperience, gold, rewards
//#3
//line1: determines how much xp and hw much gold the enemy drops if killed
struct drop
{
int gold;
int xp;
};
//combat, fight, kill, die, win, death
drop get_damage(character attacker, character defender)
{
//#4
//line1: makes sure the attacker hits before continuing
srand(time(0));
if (rand() % 100 > attacker.agility * 25)
{
//#5
//line1: gets the numbers referenced in comment #2 line2
//line2: dont look to hard at the rest unless you have to or your eyes may bleed
//the
int def_ofset_down = defender.defence - (defender.defence / 3);
int att_ofset_down = attacker.attack - (attacker.attack / 3);
int def_ofset_up = defender.defence + (defender.defence / 3);
int att_ofset_up = attacker.attack + (attacker.attack / 3);
//rest
srand(time(0));
if(rand() % 150 > attacker.agility * 10)
{
//#6
//line1: see comment #1 line1 for explaination on how combat works
double hit = rand() % (att_ofset_up - att_ofset_down - 1) + att_ofset_down + 1;
double sponge = rand() % (def_ofset_up - def_ofset_down - 1) + def_ofset_down + 1;
int damage = hit - sponge;
defender.health = defender.health - damage;
cout << attacker.name << " hits " << defender.name << " for " << damage << " damage" << endl;
cout << defender.name << " has " << defender.health << " health left" << endl;
}
else
{
cout << attacker.name << " attacks " << defender.name << " but " << defender.name << " deflects it" << endl;
}
}
}
|