535 lines
27 KiB
C++
535 lines
27 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
|
|
#pragma once
|
|
#include "Animation.h"
|
|
#include "State.h"
|
|
#include "Buff.h"
|
|
#include "olcUTIL_Animate2D.h"
|
|
#include "DEFINES.h"
|
|
#include "Attributable.h"
|
|
#include "safemap.h"
|
|
#include "Pathfinding.h"
|
|
#include "GameEvent.h"
|
|
#include "TMXParser.h"
|
|
#include "MonsterData.h"
|
|
#include "Direction.h"
|
|
#include "HurtDamageInfo.h"
|
|
#include "Oscillator.h"
|
|
#include"MonsterStrategyHelpers.h"
|
|
#include"Entity.h"
|
|
|
|
INCLUDE_ITEM_DATA
|
|
INCLUDE_MONSTER_DATA
|
|
|
|
struct DamageNumber;
|
|
class AiL;
|
|
|
|
enum class Attribute;
|
|
|
|
class GameEvent;
|
|
|
|
class Entity;
|
|
|
|
class DeathSpawnInfo{
|
|
std::string monsterSpawnName;
|
|
uint8_t spawnAmt;
|
|
vf2d spawnLocOffset;
|
|
public:
|
|
DeathSpawnInfo(const std::string_view monsterName,const uint8_t spawnAmt,const vf2d spawnOffset={});
|
|
void Spawn(const vf2d monsterDeathPos,const bool onUpperLevel);
|
|
};
|
|
class Monster:public IAttributable{
|
|
friend struct STRATEGY;
|
|
friend class AiL;
|
|
friend class InventoryCreator;
|
|
friend class DeathSpawnInfo;
|
|
friend struct MonsterData;
|
|
friend const bool Entity::IsBoss()const;
|
|
friend class Entity;
|
|
public:
|
|
enum MonsterStrategy{
|
|
RUN_TOWARDS,
|
|
SHOOT_AFAR,
|
|
TURRET,
|
|
SLIMEKING,
|
|
RUN_AWAY,
|
|
FROG,
|
|
WOLF,
|
|
BEAR,
|
|
URSULE,
|
|
NPC,
|
|
BOAR,
|
|
GOBLIN_DAGGER,
|
|
GOBLIN_BOW,
|
|
GOBLIN_BOAR_RIDER,
|
|
GOBLIN_BOMB,
|
|
HAWK,
|
|
STONE_ELEMENTAL,
|
|
ZEPHY,
|
|
MAJOR_HAWK,
|
|
DONOTHING,
|
|
STONE_GOLEM,
|
|
BREAKING_PILLAR,
|
|
PIRATE_MARAUDER,
|
|
PIRATE_CAPTAIN,
|
|
SEAGULL,
|
|
SANDWORM,
|
|
PIRATE_BUCCANEER,
|
|
PARROT,
|
|
CRAB,
|
|
GIANT_CRAB,
|
|
GIANT_OCTOPUS,
|
|
OCTOPUS_ARM,
|
|
GHOST_OF_PIRATE_CAPTAIN,
|
|
PIRATES_TREASURE,
|
|
PIRATES_COIN,
|
|
SKELETON_BARBARIAN,
|
|
_RUN_RIGHT,
|
|
SKELETON_CAPTAIN,
|
|
SKELETON_CAPTAIN_FLAG,
|
|
SKELETON_MAGE,
|
|
SPIDER,
|
|
WARRIORTHIEF,
|
|
////////////////////////////////////
|
|
////////////////////////////////////
|
|
////////////////////////////////////
|
|
////////////////////////////////////
|
|
////////////////////////////////////
|
|
////////////////////////////////////
|
|
////////////////////////////////////
|
|
////////////////////////////////////
|
|
END_ENUM //THIS SHOULD ALWAYS BE THE LAST ITEM
|
|
};
|
|
struct StrategyFunction{
|
|
std::string name;
|
|
std::function<void(Monster&,float,std::string)>function;
|
|
};
|
|
struct STRATEGY{
|
|
static safeunorderedmap<MonsterStrategy,StrategyFunction>monsterStrategies;
|
|
static std::string ERR;
|
|
static int _GetInt(Monster&m,const std::string¶m,const std::string&strategy,int index=0);
|
|
static float _GetFloat(Monster&m,const std::string¶m,const std::string&strategy,int index=0);
|
|
static bool _GetBool(Monster&m,const std::string¶m,const std::string&strategy,int index=0);
|
|
static Pixel _GetPixel(Monster&m,const std::string¶m,const std::string&strategy,int index=0);
|
|
//Converts unit distances to pixels. (Every 100 units = 24 pixels)
|
|
static float _GetPixels(Monster&m,const std::string¶m,const std::string&strategy,int index=0);
|
|
static olc::vf2d _GetVec(Monster&m,const std::string¶m,const std::string&strategy,int index=0);
|
|
static const std::string&_GetString(Monster&m,const std::string¶m,const std::string&strategy,int index=0);
|
|
static const datafile&_Get(Monster&m,const std::string¶m,const std::string&strategy);
|
|
static void RUN_TOWARDS(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void SHOOT_AFAR(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void TURRET(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void SLIMEKING(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void RUN_AWAY(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void FROG(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void WOLF(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void BEAR(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void URSULE(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void NPC(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void BOAR(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void GOBLIN_DAGGER(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void GOBLIN_BOW(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void GOBLIN_BOAR_RIDER(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void GOBLIN_BOMB(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void HAWK(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void STONE_ELEMENTAL(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void ZEPHY(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void MAJOR_HAWK(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void DONOTHING(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void STONE_GOLEM(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void BREAKING_PILLAR(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void PIRATE_MARAUDER(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void PIRATE_CAPTAIN(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void SEAGULL(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void SANDWORM(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void PIRATE_BUCCANEER(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void PARROT(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void CRAB(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void GIANT_CRAB(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void GIANT_OCTOPUS(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void OCTOPUS_ARM(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void GHOST_OF_PIRATE_CAPTAIN(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void PIRATES_TREASURE(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void PIRATES_COIN(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void SKELETON_BARBARIAN(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void _RUN_RIGHT(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void SKELETON_CAPTAIN(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void SKELETON_CAPTAIN_FLAG(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void SKELETON_MAGE(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void SPIDER(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
static void WARRIORTHIEF(Monster&m,float fElapsedTime,const std::string&strategy);
|
|
};
|
|
void RunStrategy(const MonsterStrategy&strategy);
|
|
|
|
private:
|
|
static safeunorderedmap<std::string,MonsterStrategy>stringToStrategyMap;
|
|
public:
|
|
Monster()=delete;
|
|
Monster(vf2d pos,MonsterData data,bool upperLevel=false,bool bossMob=false);
|
|
const vf2d&GetPos()const;
|
|
const int GetHealth()const;
|
|
const int GetMaxHealth()const;
|
|
const int GetMana()const;
|
|
int GetAttack()const;
|
|
//This function returns the multiplier for the movespd from the base spd. So 100 movespd is 1.0.
|
|
float GetMoveSpdMult()const;
|
|
//Obtains the size multiplier (from 0.f-1.f).
|
|
float GetSizeMult()const;
|
|
Animate2D::Frame GetFrame()const;
|
|
const std::optional<const Animate2D::Frame>GetMountedFrame()const;
|
|
void Update(const float fElapsedTime);
|
|
//Returns true when damage is actually dealt. Provide whether or not the attack is on the upper level or not. Monsters must be on the same level to get hit by it. (there is a death check and level check here.)
|
|
//If you need to hurt multiple enemies try AiL::HurtEnemies()
|
|
bool Hurt(HurtDamageInfo damageData);
|
|
//Returns true when damage is actually dealt. Provide whether or not the attack is on the upper level or not. Monsters must be on the same level to get hit by it. (there is a death check and level check here.)
|
|
//If you need to hurt multiple enemies try AiL::HurtEnemies()
|
|
bool Hurt(int damage,bool onUpperLevel,float z,HurtFlag::HurtFlag hurtFlags=HurtFlag::NONE);
|
|
const bool IsAlive()const;
|
|
const vf2d&GetTargetPos()const;
|
|
Direction GetFacingDirection()const;
|
|
//Will make the monster face in the correct direction relative to a given target point to look at.
|
|
void UpdateFacingDirection(vf2d facingTargetPoint);
|
|
void UpdateFacingDirection(Direction newFacingDir);
|
|
void Draw()const;
|
|
void DrawReflection(float drawRatioX,float multiplierX);
|
|
void Collision(Player*p);
|
|
void Collision(Monster&p);
|
|
void Collision();
|
|
void SetVelocity(vf2d vel);
|
|
void AddAddedVelocity(vf2d vel); //NOTE: If a monster is trying to set its velocity internally, use SetVelocity() instead. This function is for external sources affecting this monster's velocity.
|
|
//Returns false if the monster could not be moved to the requested location due to collision.
|
|
bool SetPos(vf2d pos);
|
|
//Returns false if the monster could not be moved to the requested location due to collision.
|
|
bool SetX(float x);
|
|
//Returns false if the monster could not be moved to the requested location due to collision.
|
|
bool SetY(float y);
|
|
void PerformJumpAnimation();
|
|
void PerformShootAnimation();
|
|
void PerformIdleAnimation();
|
|
void PerformJumpAnimation(const Direction facingDir);
|
|
void PerformShootAnimation(const Direction facingDir);
|
|
void PerformIdleAnimation(const Direction facingDir);
|
|
void PerformNPCDownAnimation();
|
|
void PerformNPCUpAnimation();
|
|
void PerformNPCLeftAnimation();
|
|
void PerformNPCRightAnimation();
|
|
void PerformAnimation(const std::string_view animationName);
|
|
void PerformAnimation(const std::string_view animationName,const Direction facingDir); //Performs an animation, optionally changes the facing direction of this monster.
|
|
void PerformAnimation(const std::string_view animationName,const vf2d targetFacingDir); //Faces a target vector while performing an animation.
|
|
const Animate2D::FrameSequence&GetCurrentAnimation()const;
|
|
const Animate2D::FrameSequence&GetAnimation(const std::string_view animationName)const;
|
|
const bool OnUpperLevel()const;
|
|
void Moved();
|
|
//Returns false if a path could not be found.
|
|
bool StartPathfinding(float pathingTime);
|
|
void PathAroundBehavior(float fElapsedTime);
|
|
Buff&AddBuff(BuffType type,float duration,float intensity);
|
|
//NOTE: If adding a % increase stat, please use the percentage version! 100% = 1!!
|
|
Buff&AddBuff(BuffType type,float duration,float intensity,std::set<ItemAttribute>attr);
|
|
//NOTE: If adding a % increase stat, please use the percentage version! 100% = 1!!
|
|
Buff&AddBuff(BuffType type,float duration,float intensity,std::set<std::string>attr);
|
|
Buff&AddBuff(BuffType type,float duration,float intensity,Buff::MonsterBuffExpireCallbackFunction expireCallback);
|
|
Buff&AddBuff(BuffRestorationType type,BuffOverTimeType::BuffOverTimeType overTimeType,float duration,float intensity,float timeBetweenTicks);
|
|
Buff&AddBuff(BuffRestorationType type,BuffOverTimeType::BuffOverTimeType overTimeType,float duration,float intensity,float timeBetweenTicks,Buff::MonsterBuffExpireCallbackFunction expireCallback);
|
|
Buff&AddBuff(BuffType type,BuffRestorationType restorationType,BuffOverTimeType::BuffOverTimeType overTimeType,float duration,float intensity,float timeBetweenTicks);
|
|
Buff&AddBuff(BuffType type,BuffRestorationType restorationType,BuffOverTimeType::BuffOverTimeType overTimeType,float duration,float intensity,float timeBetweenTicks,Buff::MonsterBuffExpireCallbackFunction expireCallback);
|
|
Buff&GetOrAddBuff(BuffType buff,std::pair<BuffDuration,BuffIntensity>newBuff);
|
|
const bool HasBuff(BuffType buff)const;
|
|
const std::optional<Buff>GetBuff(BuffType buff)const;
|
|
const std::vector<Buff>GetBuffs(BuffType buff)const;
|
|
const std::vector<Buff>GetBuffs(std::vector<BuffType>buffs)const;
|
|
//Removes all buffs of a given type.
|
|
void RemoveBuff(BuffType type);
|
|
State::State GetState();
|
|
void SetState(State::State newState);
|
|
static void InitializeStrategies();
|
|
const bool HasIframes()const;
|
|
void ApplyIframes(const float iframeTime);
|
|
//NOTE: Will directly override the iframe timer for the player, as opposed to _ApplyIframes which actually keeps the longest current iframe time.
|
|
void _SetIframes(const float iframeTime);
|
|
const float GetZ()const;
|
|
void SetZ(float z);
|
|
const std::function<void(Monster&,float,std::string)>&GetStrategyFunc()const;
|
|
void SetSize(float newSize,bool immediate=true);
|
|
geom2d::circle<float>BulletCollisionHitbox();
|
|
void SetStrategyDrawFunction(std::function<void(AiL*game,Monster&monster,const std::string&strategy)>func);
|
|
void SetStrategyDrawOverlayFunction(std::function<void(AiL*game,Monster&monster,const std::string&strategy)>func);
|
|
std::function<void(AiL*,Monster&,const std::string&)>strategyDraw=[](AiL*pge,Monster&m,const std::string&strategy){};
|
|
std::function<void(AiL*,Monster&,const std::string&)>strategyDrawOverlay=[](AiL*pge,Monster&m,const std::string&strategy){};
|
|
const ItemAttributable&GetStats()const;
|
|
const EventName&GetHurtSound();
|
|
const EventName&GetDeathSound();
|
|
const EventName&GetWalkSound();
|
|
void Knockback(const vf2d&vel);
|
|
void ProximityKnockback(const vf2d centerPoint,const float knockbackFactor);
|
|
//Knockup the player for duration amount of seconds.
|
|
void Knockup(float duration);
|
|
const bool AttackAvoided(const float attackZ)const;
|
|
const std::string&GetName()const;
|
|
//Rotates this enemy's sprite towards a given location. Also flips it to face the correct direction.
|
|
void RotateTowardsPos(const vf2d&targetPos);
|
|
const float GetDamageReductionFromBuffs()const;
|
|
const float GetCollisionDamage()const;
|
|
const bool IsNPC()const;
|
|
const bool HasLineOfSight(vf2d targetPos)const;
|
|
const float GetDistanceFrom(vf2d target)const;
|
|
const Direction GetFacingDirectionToTarget(vf2d target)const;
|
|
const bool HasFourWaySprites()const;
|
|
const bool HasMountedMonster()const;
|
|
const bool IgnoresTerrainCollision()const;
|
|
const float TimeSpentAlive()const;
|
|
const bool Immovable()const;
|
|
const bool IsSolid()const;
|
|
const bool Invulnerable()const;
|
|
//If an object has a lifetime set, returns it.
|
|
const std::optional<float>GetLifetime()const;
|
|
const std::optional<float>GetTotalLifetime()const;
|
|
void SetLifetime(const float lifetime);
|
|
//If an object has a collision radius, returns it.
|
|
const float GetCollisionRadius()const;
|
|
const bool IsDead()const;
|
|
const std::string_view GetDisplayName()const;
|
|
const bool HasArrowIndicator()const;
|
|
const bool ReachedTargetPos(const float maxDistanceFromTarget=4.f)const;
|
|
const float GetHealthRatio()const;
|
|
const bool _DealTrueDamage(const uint32_t damageAmt,HurtFlag::HurtFlag hurtFlags=HurtFlag::NONE);
|
|
void Heal(const int healAmt,const bool displayDamageNumber=false);
|
|
const float GetModdedStatBonuses(std::string_view stat)const;
|
|
//The collision rectangle is only used currently for determining the safe spots for the stone golem boss fight.
|
|
const std::optional<geom2d::rect<float>>&GetRectangleCollision()const;
|
|
const uint8_t GetMarkStacks()const; //Number of Trapper marks on this target.
|
|
const uint8_t GetSpecialMarkStacks()const; //Number of Trapper marks on this target.
|
|
void TriggerMark(); //Deals no damage, but causes a mark proc to occur.
|
|
void ApplyMark(float time,uint8_t stackCount); //Adds stackCount mark stacks to the target, refreshing the buff to time time.
|
|
void ApplySpecialMark(float time,uint8_t stackCount); //Adds stackCount special mark stacks to the target, refreshing the buff to time time.
|
|
//Gets the nearest target that can be immediately targeted
|
|
static std::optional<std::weak_ptr<Monster>>GetNearestMonster(const vf2d point,const float maxDistance,const bool onUpperLevel,const float z,const std::optional<std::weak_ptr<Monster>>excludedTarget={});
|
|
const bool InUndamageableState(const bool onUpperLevel,const float z)const;
|
|
const bool CanMove()const;
|
|
const std::weak_ptr<Monster>GetWeakPointer()const;
|
|
void ApplyDot(float duration,int damage,float timeBetweenTicks,Buff::MonsterBuffExpireCallbackFunction expireCallbackFunc=[](std::weak_ptr<Monster>m,Buff&b){});
|
|
void ApplyDot(float duration,int damage,float timeBetweenTicks,BuffType identifierType,Buff::MonsterBuffExpireCallbackFunction expireCallbackFunc=[](std::weak_ptr<Monster>m,Buff&b){});
|
|
const float GetDamageAmplificationMult(const bool backstabOccurred)const;
|
|
std::optional<Buff>EditBuff(BuffType buff);
|
|
Buff&EditBuff(BuffType buff,size_t buffInd);
|
|
std::vector<std::reference_wrapper<Buff>>EditBuffs(BuffType buff);
|
|
const bool IsBackstabAttack()const;
|
|
void Stun(const float stunDuration);
|
|
const float&GetRemainingStunDuration()const;
|
|
const bool FadeoutWhenStandingBehind()const;
|
|
const bool FaceTarget()const;
|
|
void ResetCurseOfDeathDamage();
|
|
void MoveForward(const vf2d&moveForwardVec,const float fElapsedTime); //Moves the monster forward in given cartesian vector direction (will be auto-normalized) applying speeed boosts and other proper movement requirements as if you wanted to move on a frame-by-frame basis.
|
|
void SetPhase(const std::string&strategyName,int phase);
|
|
const int GetPhase(const std::string&strategyName);
|
|
const float GetOriginalCollisionRadius()const;
|
|
void SetCollisionRadius(const float collisionRadius);
|
|
const MonsterStrategy&GetStrategy()const;
|
|
const std::string&GetStrategyName()const;
|
|
const std::vector<MonsterAbilityData>&GetAbilities()const;
|
|
const float GetMPRecovery()const;
|
|
void CastAbility(const MonsterAbilityData&data,const vf2d pos={});
|
|
void SetTransparency(uint8_t alpha);
|
|
uint8_t GetTransparency()const;
|
|
void Spin(float duration,float spinSpd);
|
|
private:
|
|
//NOTE: Marking a monster for deletion does not trigger any death events. It just simply removes the monster from the field!!
|
|
// The way this works is that monsters marked for deletion will cause the monster update loop to detect there's at least one or more monsters that must be deleted and will call erase_if on the list at the end of the iteration loop.
|
|
void MarkForDeletion();
|
|
std::string name;
|
|
vf2d pos;
|
|
vf2d vel={0,0};
|
|
float friction=400;
|
|
vf2d target{};
|
|
float targetAcquireTimer=0;
|
|
vf2d spawnPos;
|
|
int hp{0};
|
|
#ifdef UNIT_TESTING
|
|
public:
|
|
#endif
|
|
int mp{0};
|
|
float mpRemainder{0.f};
|
|
#ifdef UNIT_TESTING
|
|
private:
|
|
#endif
|
|
ItemAttributable stats;
|
|
float size;
|
|
float attackCooldownTimer=0;
|
|
float queueShotTimer=0;
|
|
float z=0;
|
|
float iframe_timer=0;
|
|
Direction facingDirection;
|
|
#ifdef UNIT_TESTING
|
|
public:
|
|
#endif
|
|
std::string strategy;
|
|
#ifdef UNIT_TESTING
|
|
private:
|
|
#endif
|
|
State::State state=State::NORMAL;
|
|
std::string overlaySprite="";
|
|
uint8_t overlaySpriteTransparency=0U;
|
|
Animate2D::Animation<std::string>animation;
|
|
Animate2D::AnimationState internal_animState;
|
|
std::optional<Animate2D::Animation<std::string>>mounted_animation;
|
|
Animate2D::AnimationState internal_mounted_animState;
|
|
float randomFrameOffset=0.f;
|
|
float deathTimer=0.f;
|
|
float monsterHurtSoundCooldown=0.f;
|
|
float monsterWalkSoundTimer;
|
|
float abilityAndManaTickTimer{0.f};
|
|
std::vector<Buff>buffList;
|
|
std::string GetDeathAnimationName();
|
|
float lastHitPlayer=0.0f;
|
|
bool canMove=true; //Set to false when stuck due to collisions.
|
|
bool upperLevel=false;
|
|
vf2d pathTarget={};
|
|
Pathfinding::sSpline path;
|
|
float pathIndex=0;
|
|
float lastHitTimer=0;
|
|
float lastDotTimer=0;
|
|
float spriteRot=0;
|
|
std::shared_ptr<DamageNumber>damageNumberPtr;
|
|
std::shared_ptr<DamageNumber>dotNumberPtr;
|
|
std::unordered_map<StrategyName,int>phase{}; //NOTE: THIS SHOULD NOT BE MODIFIED DIRECTLY!!! Use SetPhase(), GetPhase() / PHASE() SETPHASE() macros!
|
|
#ifdef UNIT_TESTING
|
|
public:
|
|
#endif
|
|
bool diesNormally=true; //If set to false, the monster death is handled in a special way. Set it to true when it's time to die.
|
|
#ifdef UNIT_TESTING
|
|
private:
|
|
#endif
|
|
float targetSize=0;
|
|
bool isBoss=false;
|
|
void OnDeath();
|
|
bool hasStrategyDeathFunction=false;
|
|
NPCData npcData;
|
|
float lastPathfindingCooldown=0.f;
|
|
std::function<bool(GameEvent&,Monster&,const std::string&)>strategyDeathFunc{};
|
|
std::function<void(const HurtDamageInfo damageInfo,Monster&,const std::string&)>strategyOnHitFunc{};
|
|
//Sets the strategy death function that runs when a monster dies.
|
|
// The function should return false to indicate the event is over. If the event should keep running, return true.
|
|
void SetStrategyDeathFunction(std::function<bool(GameEvent&event,Monster&monster,const StrategyName&strategyName)>func);
|
|
// The function is called immediately after taking damage. Note the damage has already gone through, and the damage data contains the final damage that was received after all damage reductions were applied. It cannot be modified.
|
|
void SetStrategyOnHitFunction(std::function<void(const HurtDamageInfo damageData,Monster&monster,const StrategyName&strategyName)>func);
|
|
//If you are trying to change a Get() stat, use the STAT_UP buff (and the optional argument) to supply an attribute you want to apply.
|
|
const ItemAttribute&GetBonusStat(std::string_view attr)const;
|
|
//Returns false if the monster could not be moved to the requested location due to collision.
|
|
//If monsterInvoked is true, this means the monster was the one that instantiated this input, and it's not an extra movement done via collision.
|
|
//Set monsterInvoked to false when you don't want a movement loop due to collisions.
|
|
//Typical usage is monsterInvoked is true on first call, and monsterInvoked is false on all subsequent chained calls.
|
|
bool _SetX(float x,const bool monsterInvoked=true);
|
|
//Returns false if the monster could not be moved to the requested location due to collision.
|
|
//If monsterInvoked is true, this means the monster was the one that instantiated this input, and it's not an extra movement done via collision.
|
|
//Set monsterInvoked to false when you don't want a movement loop due to collisions.
|
|
//Typical usage is monsterInvoked is true on first call, and monsterInvoked is false on all subsequent chained calls.
|
|
bool _SetY(float y,const bool monsterInvoked=true);
|
|
float knockUpTimer=0.f;
|
|
float totalKnockupTime=0.f;
|
|
float knockUpZAmt=0.f;
|
|
//Spawns the drops a monster would drop as if they were defeated. Returns what items were dropped and their amounts.
|
|
std::map<ItemInfo*,uint16_t>SpawnDrops();
|
|
float prevFacingDirectionAngle=PI; //Keeps track of the angle of the previous target to ensure four-way sprite facing changes don't happen too early or spastically.
|
|
float lastFacingDirectionChange=0.f; //How much time has passed since the last facing direction change. Used to ensure another facing direction change doesn't happen too quickly. Probably allowing one every quarter second is good enough.
|
|
std::vector<DeathSpawnInfo>deathData; //Data that contains further actions and information when this monster dies. Mostly used to spawn sub-monsters from a defeated monster.
|
|
vf2d mountedSprOffset{};
|
|
float timeSpentAlive{0.f};
|
|
std::optional<float>lifetime{};
|
|
float fadeTimer{0.f};
|
|
bool markedForDeletion{false}; //DO NOT MODIFY DIRECTLY. Use MarkForDeletion() if this monster needs to be marked. NOTE: Marking a monster for deletion does not trigger any death events. It just simply removes the monster from the field!!
|
|
float solidFadeTimer{0.f};
|
|
bool _Hurt(int damage,bool onUpperLevel,float z,const TrueDamageFlag damageRule,HurtFlag::HurtFlag hurtFlags);
|
|
void RemoveMarkStack();
|
|
void RemoveSpecialMarkStack();
|
|
float markApplicationTimer{}; //Used for animations involving the mark being applied to the target.
|
|
float specialMarkApplicationTimer{}; //Used for animations involving the mark being applied to the target.
|
|
void SetWeakPointer(std::shared_ptr<Monster>&sharedMonsterPtr);
|
|
std::weak_ptr<Monster>weakPtr;
|
|
void LongLastingMarkEffect(float&out_markDuration); //Modifies a given duration.
|
|
float stunTimer{};
|
|
int accumulatedCurseOfDeathDamage{};
|
|
vf2d addedVel{};
|
|
std::weak_ptr<Monster>attachedTarget; //A monster attached to another monster can then use this to alter behaviors based on the state of that other monster.
|
|
float unconsciousTimer{};
|
|
#ifdef UNIT_TESTING
|
|
public:
|
|
#endif
|
|
const bool IsUnconscious()const;
|
|
float blockTimer{};
|
|
#ifdef UNIT_TESTING
|
|
private:
|
|
#endif
|
|
const float UnconsciousTime()const;
|
|
bool manualIgnoreTerrain{false}; //A manual flag that can be toggled on to dynamically make this monster ignore terrain collision.
|
|
float collisionRadius{}; //The collision radius can be modified, it's just set initially to the monster database entry.
|
|
//Ignores collision checking and sets the monster at the given position.
|
|
void ForceSetPos(vf2d pos);
|
|
Renderable afterImage;
|
|
void SetupAfterImage();
|
|
float removeLineTimer{};
|
|
const float TIME_BETWEEN_LINE_REMOVALS{0.025f};
|
|
uint8_t scanLine{24};
|
|
vf2d afterImagePos{};
|
|
Oscillator<float>floatOscillator{0.f,8.f,0.5f};
|
|
bool arrowIndicator{false};
|
|
const float GetHastePct()const;
|
|
std::optional<CastInfo>currentCast;
|
|
void PerformSpell(const CastInfo&castData);
|
|
bool bumpedIntoTerrain=false; //Gets set to true before a strategy executes if the monster runs into some terrain on this frame.
|
|
bool attackedByPlayer=false; //Gets set to true before a strategy executes if the monster has been attacked by the player.
|
|
uint8_t transparency{255U};
|
|
};
|
|
|
|
struct MonsterSpawner{
|
|
private:
|
|
vf2d pos;
|
|
vf2d range;
|
|
std::vector<std::pair<std::string,vf2d>>monsters;
|
|
bool triggered=false;
|
|
bool upperLevel=false;
|
|
std::string bossNameDisplay="";
|
|
public:
|
|
MonsterSpawner();
|
|
//For the monster list, the second pair item is the position relative to the spawner to spawn the monster.
|
|
MonsterSpawner(vf2d pos,vf2d range,std::vector<std::pair<std::string,vf2d>>MONSTER_LIST,bool upperLevel=false,std::string bossNameDisplay="");
|
|
bool SpawnTriggered();
|
|
vf2d GetRange();
|
|
vf2d GetPos();
|
|
bool DoesUpperLevelSpawning();
|
|
void SetTriggered(bool trigger,bool spawnMonsters=true);
|
|
}; |