176 lines
5.1 KiB
C++
176 lines
5.1 KiB
C++
#pragma region License
|
|
/*
|
|
License (OLC-3)
|
|
~~~~~~~~~~~~~~~
|
|
|
|
Copyright 2026 Amy Sigona <sigonasr2@gmail.com>
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
are permitted provided that the following conditions are met:
|
|
|
|
1. Redistributions or derivations of source code must retain the above copyright
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions or derivative works in binary form must reproduce the above
|
|
copyright notice. This list of conditions and the following disclaimer must be
|
|
reproduced in the documentation and/or other materials provided with the distribution.
|
|
|
|
3. Neither the name of the copyright holder nor the names of its contributors may
|
|
be used to endorse or promote products derived from this software without specific
|
|
prior written permission.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
|
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
|
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
SUCH DAMAGE.
|
|
|
|
Portions of this software are copyright © 2024 The FreeType
|
|
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
|
|
All rights reserved.
|
|
*/
|
|
#pragma endregion
|
|
|
|
#include "Entity.h"
|
|
#include "Player.h"
|
|
#include "MonsterStrategyHelpers.h"
|
|
|
|
#define is(type) std::holds_alternative<type>(this->entity)
|
|
#define get(type) std::get<type>(this->entity)
|
|
|
|
#define CallClassFunc(func) \
|
|
if(is(Player*))return get(Player*)->func; \
|
|
if(is(Monster*))return get(Monster*)->func; \
|
|
ERR("Entity is not a valid type! THIS SHOULD NOT BE HAPPENING!");
|
|
|
|
Entity::Entity(Player*player):entity(player){}
|
|
Entity::Entity(Monster*monster):entity(monster){}
|
|
Entity::Entity(const std::variant<Monster*,Player*>ent):entity(ent){}
|
|
|
|
const vf2d Entity::GetPos()const{
|
|
CallClassFunc(GetPos());
|
|
}
|
|
|
|
void Entity::ApplyIframes(const float iframeTime){
|
|
CallClassFunc(ApplyIframes(iframeTime));
|
|
}
|
|
|
|
Buff&Entity::GetOrAddBuff(BuffType buffType,std::pair<BuffDuration,BuffIntensity>newBuff){
|
|
CallClassFunc(GetOrAddBuff(buffType,newBuff));
|
|
}
|
|
|
|
const std::optional<Buff>Entity::GetBuff(BuffType buff)const{
|
|
CallClassFunc(GetBuff(buff));
|
|
}
|
|
|
|
const float Entity::GetDistanceFrom(vf2d target)const{
|
|
CallClassFunc(GetDistanceFrom(target));
|
|
}
|
|
|
|
bool Entity::Hurt(int damage,bool onUpperLevel,float z,HurtFlag::HurtFlag hurtFlags){
|
|
CallClassFunc(Hurt(damage,onUpperLevel,z,hurtFlags));
|
|
}
|
|
|
|
std::optional<Buff>Entity::EditBuff(BuffType buff){
|
|
CallClassFunc(EditBuff(buff));
|
|
}
|
|
|
|
|
|
const bool Entity::IsSkeletonMage()const{
|
|
if(is(Player*)){return false;}
|
|
else if(is(Monster*)){return get(Monster*)->GetStrategy()==Monster::MonsterStrategy::SKELETON_MAGE;}
|
|
ERR("Entity is not a valid type! THIS SHOULD NOT BE HAPPENING!");
|
|
std::unreachable();
|
|
};
|
|
|
|
const bool Entity::IsBoss()const{
|
|
if(is(Player*)){return false;}
|
|
else if(is(Monster*)){return get(Monster*)->isBoss;}
|
|
ERR("Entity is not a valid type! THIS SHOULD NOT BE HAPPENING!");
|
|
std::unreachable();
|
|
};
|
|
|
|
const std::vector<Buff>Entity::GetBuffs(BuffType buff)const{
|
|
CallClassFunc(GetBuffs(buff));
|
|
}
|
|
|
|
const bool Entity::OnUpperLevel()const{
|
|
CallClassFunc(OnUpperLevel());
|
|
}
|
|
|
|
Player*const Entity::ToPlayer()const{
|
|
return get(Player*);
|
|
}
|
|
Monster*const Entity::ToMonster()const{
|
|
return get(Monster*);
|
|
}
|
|
|
|
const float Entity::GetMoveSpdMult()const{
|
|
CallClassFunc(GetMoveSpdMult());
|
|
}
|
|
|
|
const int Entity::GetAttack()const{
|
|
CallClassFunc(GetAttack());
|
|
}
|
|
|
|
const FriendlyType Entity::IsFriendly()const{
|
|
if(is(Player*))return FRIENDLY;
|
|
return NON_FRIENDLY;
|
|
}
|
|
|
|
const float Entity::GetSizeMult()const{
|
|
CallClassFunc(GetSizeMult());
|
|
}
|
|
|
|
const bool Entity::CanMove()const{
|
|
CallClassFunc(CanMove());
|
|
}
|
|
|
|
const bool Entity::HasEnchant(const std::string&enchant)const{
|
|
if(is(Player*))return get(Player*)->HasEnchant(enchant);
|
|
return false;
|
|
}
|
|
|
|
float&Entity::GetBlockTimer()const{
|
|
CallClassFunc(blockTimer);
|
|
}
|
|
|
|
Buff&Entity::AddBuff(BuffType type,float duration,float intensity){
|
|
CallClassFunc(AddBuff(type,duration,intensity));
|
|
}
|
|
|
|
Buff&Entity::AddBuff(BuffType type,float duration,float intensity,std::set<std::string>attr){
|
|
CallClassFunc(AddBuff(type,duration,intensity,attr));
|
|
}
|
|
|
|
void Entity::ForPlayer(std::function<void(Player&p)>func){
|
|
if(is(Player*))func(*get(Player*));
|
|
}
|
|
void Entity::ForMonster(std::function<void(Monster&p)>func){
|
|
if(is(Monster*))func(*get(Monster*));
|
|
}
|
|
|
|
const float Entity::GetZ()const{
|
|
CallClassFunc(GetZ());
|
|
}
|
|
|
|
void Entity::Spin(float duration,float spinSpd){
|
|
CallClassFunc(Spin(duration,spinSpd));
|
|
}
|
|
|
|
void Entity::Knockback(vf2d vel){
|
|
CallClassFunc(Knockback(vel));
|
|
}
|
|
|
|
Direction Entity::GetFacingDirection()const{
|
|
CallClassFunc(GetFacingDirection());
|
|
}
|
|
|
|
void Entity::SetVelocity(vf2d vel){
|
|
CallClassFunc(SetVelocity(vel));
|
|
} |