You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SeasonI/encounters.h

127 lines
4.1 KiB

#ifndef ENCOUNTERS_H
#define ENCOUNTERS_H
#include "pixelGameEngine.h"
using namespace olc;
#include "defines.h"
#include "object.h"
#include "battle.h"
#include "item.h"
namespace encounter{
enum{
ENCOUNTER_1,
ENCOUNTER_2,
ENCOUNTER_3,
ENCOUNTER_4,
};
}
class Entity{
private:
int HP=0;
int targetHP=0;
int PP=0;
int targetPP=0;
public:
int maxHP=0;
int maxPP=0;
std::array<int,4>resistances={0,0,0,0};
int speed=0;
int baseAtk=0;
int damageReduction=0; //A percentage of how much damage to reduce.
bool smart=false;
bool dumb=false;
int atb=0; //When this value reaches 1000, it's this entity's turn.
Object* obj;
std::vector<Battle::Move*> moveSet;
int selectedTarget = 0;
Battle::Move*selectedMove = nullptr; //The index of the selected move.
int channelTimeRemaining = 0; //The amount of channel time left until move can be performed.
vd2d channelPos = {0,0}; //Where our channel is happening.
std::vector<Item*> inventory; //Used mostly for enemy spoils.
std::array<Item*,3> equipment; //Equipment this character is using.
//Used for initializing players.
Entity(int HP,int maxHP,int PP,int maxPP,int baseAtk,std::array<int,4>resistances,int speed,std::vector<Battle::Move*>moveSet,std::vector<Item*>items={},std::array<Item*,3>equipment={},int damageReduction=0,bool smart=false,bool dumb=false)
:Entity(nullptr,HP,maxHP,PP,maxPP,baseAtk,resistances,speed,moveSet,items,equipment,damageReduction,smart,dumb){}
//Use this for initializing enemies as it lets you specify an object.
Entity(Object*obj,int HP,int maxHP,int PP,int maxPP,int baseAtk,std::array<int,4>resistances,int speed,std::vector<Battle::Move*>moveSet,std::vector<Item*>items={},std::array<Item*,3>equipment={},int damageReduction=0,bool smart=false,bool dumb=false)
:obj(obj),HP(HP),maxHP(maxHP),PP(PP),maxPP(maxPP),baseAtk(baseAtk),speed(speed),equipment(equipment),moveSet(moveSet),damageReduction(damageReduction),inventory(items),smart(smart),dumb(dumb){
for (int i=0;i<4;i++) {
this->resistances[i]=resistances[i];
}
this->targetHP=HP;
this->targetPP=PP;
}
//Get the HP that the rolling counter is moving towards.
int GetTargetHP() {
return targetHP;
}
//Gets the current actual health of the target.
int GetHP() {
return HP;
}
//Get the PP that the rolling counter is moving towards.
int GetTargetPP() {
return targetPP;
}
//Gets the current actual pp of the target.
int GetPP() {
return PP;
}
//Sets the rolling counter target to this health value.
void SetTargetHP(int hp) {
targetHP=hp;
}
//Sets the rolling counter target to this pp value.
void SetTargetPP(int pp) {
targetPP=pp;
}
//Subtracts from the rolling counter target from this health value.
void SubtractHP(int hp) {
targetHP-=hp;
}
//Adds to the rolling counter target from this health value.
void AddHP(int hp) {
targetHP=std::clamp(targetHP+hp,0,maxHP);
}
//Subtracts from the rolling counter target from this pp value.
void SubtractPP(int pp) {
targetPP=std::clamp(targetPP-pp,0,maxPP);
}
//Adds to the rolling counter target from this pp value.
void AddPP(int pp) {
targetPP=std::clamp(targetPP+pp,0,maxPP);
}
//THIS IS FOR SPECIAL USE CASES ONLY! Normally you want to touch the rolling counter amount instead using SetTargetHP()!
void _SetDirectHP(int hp) {
HP=hp;
}
//THIS IS FOR SPECIAL USE CASES ONLY! Normally you want to touch the rolling counter amount instead using SetTargetPP()!
void _SetDirectPP(int pp) {
PP=pp;
}
};
class Encounter{
public:
vd2d pos;
int chance; //Chance of the encounter existing.
std::vector<Entity*>objs;
std::array<vd2d,4> playerPos;
int id;
Encounter(int id,vd2d pos,std::array<vd2d,4> playerPos,std::vector<Entity*>objs,int chance=25)
:id(id),pos(pos),objs(objs),chance(chance),playerPos(playerPos){}
bool IsEncounterAlive() {
for (int i=0;i<objs.size();i++) {
if (objs[i]->GetHP()>0) {
return true;
}
}
return false;
}
bool IsInRange(vd2d pos) {
vd2d diff=pos-this->pos;
return diff.x>=0&&diff.x<=WIDTH&&diff.y>=0&&diff.y<=HEIGHT;
}
};
#endif