# ifndef ENCOUNTERS_H
# define ENCOUNTERS_H
# include "pixelGameEngine.h"
using namespace olc ;
# include "defines.h"
# include "object.h"
# include "battle.h"
# include "item.h"
extern std : : vector < Item * > PARTY_INVENTORY ;
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 = 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 ;
}
//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 ( int 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 ;
}
} ;
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