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/entity.h

168 lines
6.0 KiB

#ifndef ENTITY_H
#define ENTITY_H
#include "pixelGameEngine.h"
#include "object.h"
extern std::vector<Item*>PARTY_INVENTORY;
using namespace olc;
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;
std::map<Property,int> statusEffects;
int selectedTarget = NO_TARGET;
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 = DEFAULT_CHANNELPOS; //Where our channel is happening.
std::vector<Item*> inventory; //Used mostly for enemy spoils.
std::array<Item*,3> equipment = {nullptr,nullptr,nullptr}; //Equipment this character is using.
bool isPlayer=false; //Whether or not this is a player entity.
//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){
isPlayer=true;
}
//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;
}
Property GetPrimaryStatusEffect() {
for (std::map<Property,int>::iterator it = statusEffects.begin();it!=statusEffects.end();++it) {
if (it->second!=0) {
return it->first;
}
}
return Property::NONE;
}
//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;
}
void RemoveItem(int index) {
if (isPlayer) {
PARTY_INVENTORY.erase(PARTY_INVENTORY.begin()+index);
} else {
inventory.erase(inventory.begin()+index);
}
}
//If index is -1, the item is inserted at the end of the list. Otherwise it's going to overwrite a certain slot. Be certain you swap the item before doing this!
void RemoveEquip(EquipSlot::Equip slot,int index=-1) {
Item*CurrentEquip=equipment[slot];
if (CurrentEquip==nullptr) {
return;
}
if (isPlayer) {
if (index==-1) {
PARTY_INVENTORY.push_back(CurrentEquip);
} else {
PARTY_INVENTORY[index]=CurrentEquip;
}
equipment[slot]=nullptr;
} else {
if (index==-1) {
inventory.push_back(CurrentEquip);
} else {
inventory[index]=CurrentEquip;
}
equipment[slot]=nullptr;
}
}
//Will automatically swap items with current equipment so no need to call remove first.
void EquipItem(int index) {
Item*equip=nullptr;
if (isPlayer) {
equip=PARTY_INVENTORY[index];
} else {
equip=inventory[index];
}
if (equip==nullptr) {
return;
}
if (equip->stats.equip==EquipSlot::NONE) {
printf("Cannot equip %s! Does not have a valid Equip slot!\n",equip->name.c_str());
return;
}
Item*CurrentEquip=equipment[equip->stats.equip];
if (CurrentEquip==nullptr) {
if (isPlayer) {
PARTY_INVENTORY.erase(PARTY_INVENTORY.begin()+index);
} else {
inventory.erase(inventory.begin()+index);
}
} else {
RemoveEquip(CurrentEquip->stats.equip,index);
}
equipment[equip->stats.equip]=equip;
}
};
#endif