The open source repository for the action RPG game in development by Sig Productions titled 'Adventures in Lestoria'!
https://forums.lestoria.net
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.
233 lines
7.9 KiB
233 lines
7.9 KiB
1 year ago
|
#pragma region License
|
||
1 year ago
|
/*
|
||
|
License (OLC-3)
|
||
|
~~~~~~~~~~~~~~~
|
||
|
|
||
11 months ago
|
Copyright 2024 Joshua Sigona <sigonasr2@gmail.com>
|
||
1 year ago
|
|
||
|
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.
|
||
1 year ago
|
|
||
|
Portions of this software are copyright © 2023 The FreeType
|
||
|
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
|
||
|
All rights reserved.
|
||
1 year ago
|
*/
|
||
1 year ago
|
#pragma endregion
|
||
2 years ago
|
#pragma once
|
||
2 years ago
|
#include "olcPixelGameEngine.h"
|
||
2 years ago
|
#include "Animation.h"
|
||
2 years ago
|
#include "State.h"
|
||
1 year ago
|
#include "Buff.h"
|
||
2 years ago
|
#include "olcUTIL_Animate2D.h"
|
||
1 year ago
|
#include "DEFINES.h"
|
||
1 year ago
|
#include "Attributable.h"
|
||
1 year ago
|
#include "Item.h"
|
||
|
#include "safemap.h"
|
||
1 year ago
|
|
||
1 year ago
|
INCLUDE_ITEM_DATA
|
||
|
|
||
1 year ago
|
struct DamageNumber;
|
||
1 year ago
|
struct Player;
|
||
11 months ago
|
class AiL;
|
||
1 year ago
|
|
||
1 year ago
|
enum class Attribute;
|
||
|
|
||
1 year ago
|
enum MonsterAnimation{
|
||
|
IDLE,
|
||
|
JUMP,
|
||
|
SHOOT,
|
||
|
DEATH
|
||
2 years ago
|
};
|
||
|
|
||
1 year ago
|
struct MonsterDropData{
|
||
|
ItemInfo*item;
|
||
|
float dropChance;
|
||
|
int minQty=1;
|
||
|
int maxQty=1;
|
||
|
MonsterDropData(std::string itemName,float dropChance,int minQty=1,int maxQty=1)
|
||
1 year ago
|
:item(&ITEM_DATA.at(itemName)),dropChance(dropChance),minQty(minQty),maxQty(maxQty){}
|
||
1 year ago
|
};
|
||
|
|
||
2 years ago
|
struct MonsterData{
|
||
|
private:
|
||
1 year ago
|
std::string name;
|
||
2 years ago
|
int hp;
|
||
|
int atk;
|
||
12 months ago
|
uint32_t xp;
|
||
2 years ago
|
float moveSpd;//1.0=100%
|
||
|
float size;
|
||
1 year ago
|
std::vector<std::string> animations;
|
||
12 months ago
|
std::string strategy;
|
||
2 years ago
|
int collisionDmg;
|
||
1 year ago
|
std::string jumpAnimation="WARRIOR_IDLE_S";
|
||
|
std::string shootAnimation="WARRIOR_IDLE_S";
|
||
|
std::string deathAnimation="WARRIOR_IDLE_S";
|
||
1 year ago
|
std::vector<MonsterDropData> dropData;
|
||
2 years ago
|
public:
|
||
2 years ago
|
MonsterData();
|
||
12 months ago
|
MonsterData(std::string name,int hp,int atk,const uint32_t xp,std::vector<std::string>animations,std::vector<MonsterDropData>drops,float moveSpd=1.0f,float size=1.0f,std::string strategy="Run Towards",int collisionDmg=0);
|
||
2 years ago
|
int GetHealth();
|
||
|
int GetAttack();
|
||
12 months ago
|
const uint32_t GetXP()const;
|
||
2 years ago
|
float GetMoveSpdMult();
|
||
|
float GetSizeMult();
|
||
12 months ago
|
std::string GetAIStrategy();
|
||
2 years ago
|
int GetCollisionDmg();
|
||
1 year ago
|
std::string GetIdleAnimation();
|
||
1 year ago
|
std::string GetJumpAnimation();
|
||
|
std::string GetShootAnimation();
|
||
|
std::string GetDeathAnimation();
|
||
|
std::vector<std::string>GetAnimations(){
|
||
2 years ago
|
return animations;
|
||
|
}
|
||
1 year ago
|
const std::vector<MonsterDropData>&GetDropData();
|
||
1 year ago
|
std::string GetDisplayName();
|
||
1 year ago
|
static void InitializeMonsterData();
|
||
12 months ago
|
static std::map<std::string,Renderable*>imgs;
|
||
2 years ago
|
};
|
||
|
|
||
1 year ago
|
|
||
1 year ago
|
struct Monster:IAttributable{
|
||
1 year ago
|
friend struct STRATEGY;
|
||
1 year ago
|
public:
|
||
1 year ago
|
Monster()=delete;
|
||
1 year ago
|
Monster(vf2d pos,MonsterData data,bool upperLevel=false,bool bossMob=false);
|
||
2 years ago
|
vf2d&GetPos();
|
||
|
int GetHealth();
|
||
|
int GetAttack();
|
||
|
float GetMoveSpdMult();
|
||
|
float GetSizeMult();
|
||
2 years ago
|
Animate2D::Frame GetFrame();
|
||
1 year ago
|
void UpdateAnimation(std::string state);
|
||
2 years ago
|
bool Update(float fElapsedTime);
|
||
1 year ago
|
//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.)
|
||
11 months ago
|
//If you need to hurt multiple enemies try AiL::HurtEnemies()
|
||
1 year ago
|
bool Hurt(int damage,bool onUpperLevel,float z);
|
||
2 years ago
|
bool IsAlive();
|
||
2 years ago
|
vf2d&GetTargetPos();
|
||
|
Key GetFacingDirection();
|
||
|
void Draw();
|
||
1 year ago
|
void DrawReflection(float drawRatioX,float multiplierX);
|
||
1 year ago
|
void Collision(Player*p);
|
||
2 years ago
|
void Collision(Monster&p);
|
||
|
void Collision();
|
||
|
void SetVelocity(vf2d vel);
|
||
1 year ago
|
//Returns false if the monster could not be moved to the requested location due to collision.
|
||
1 year ago
|
bool SetPos(vf2d pos);
|
||
1 year ago
|
//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);
|
||
2 years ago
|
void PerformJumpAnimation();
|
||
2 years ago
|
void PerformShootAnimation();
|
||
1 year ago
|
void PerformIdleAnimation();
|
||
1 year ago
|
bool OnUpperLevel();
|
||
1 year ago
|
void Moved();
|
||
1 year ago
|
void StartPathfinding(float pathingTime);
|
||
|
void PathAroundBehavior(float fElapsedTime);
|
||
2 years ago
|
void AddBuff(BuffType type,float duration,float intensity);
|
||
|
std::vector<Buff>GetBuffs(BuffType buff);
|
||
1 year ago
|
State::State GetState();
|
||
|
void SetState(State::State newState);
|
||
1 year ago
|
static void InitializeStrategies();
|
||
1 year ago
|
bool HasIframes();
|
||
1 year ago
|
float GetZ();
|
||
1 year ago
|
void SetZ(float z);
|
||
12 months ago
|
const std::function<void(Monster&,float,std::string)>&GetStrategy()const;
|
||
1 year ago
|
void SetSize(float newSize,bool immediate=true);
|
||
11 months ago
|
void SetStrategyDrawFunction(std::function<void(AiL*)>func);
|
||
|
std::function<void(AiL*)>strategyDraw=[](AiL*pge){};
|
||
12 months ago
|
const ItemAttributable&GetStats()const;
|
||
|
private:
|
||
|
std::string name;
|
||
|
vf2d pos;
|
||
|
vf2d vel={0,0};
|
||
|
float friction=400;
|
||
|
vf2d target={0,0};
|
||
|
float targetAcquireTimer=0;
|
||
12 months ago
|
int hp;
|
||
12 months ago
|
ItemAttributable stats;
|
||
|
float size;
|
||
|
float attackCooldownTimer=0;
|
||
|
float queueShotTimer=0;
|
||
|
float z=0;
|
||
|
float iframe_timer=0;
|
||
|
Key facingDirection=DOWN;
|
||
|
std::string strategy;
|
||
|
State::State state=State::NORMAL;
|
||
|
Animate2D::Animation<std::string>animation;
|
||
|
Animate2D::AnimationState internal_animState;
|
||
|
float randomFrameOffset=0.f;
|
||
|
float deathTimer=0.f;
|
||
|
std::vector<Buff>buffList;
|
||
|
std::string GetDeathAnimationName();
|
||
|
bool hasHitPlayer=false;
|
||
|
bool canMove=true; //Set to false when stuck due to collisions.
|
||
|
bool upperLevel=false;
|
||
|
vf2d pathTarget={};
|
||
|
std::vector<vf2d>path;
|
||
|
int pathIndex=0;
|
||
|
float lastHitTimer=0;
|
||
|
std::shared_ptr<DamageNumber>damageNumberPtr;
|
||
|
int phase=0;
|
||
|
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.
|
||
|
float targetSize=0;
|
||
|
bool isBoss=false;
|
||
|
void OnDeath();
|
||
|
ItemAttribute&Get(std::string_view attr);
|
||
|
|
||
1 year ago
|
private:
|
||
1 year ago
|
struct STRATEGY{
|
||
12 months ago
|
static int _GetInt(Monster&m,std::string param,std::string strategy,int index=0);
|
||
|
static float _GetFloat(Monster&m,std::string param,std::string strategy,int index=0);
|
||
|
static std::string _GetString(Monster&m,std::string param,std::string strategy,int index=0);
|
||
1 year ago
|
static void RUN_STRATEGY(Monster&m,float fElapsedTime);
|
||
12 months ago
|
static void RUN_TOWARDS(Monster&m,float fElapsedTime,std::string strategy);
|
||
|
static void SHOOT_AFAR(Monster&m,float fElapsedTime,std::string strategy);
|
||
|
static void TURRET(Monster&m,float fElapsedTime,std::string strategy);
|
||
|
static void SLIMEKING(Monster&m,float fElapsedTime,std::string strategy);
|
||
|
static void RUN_AWAY(Monster&m,float fElapsedTime,std::string strategy);
|
||
1 year ago
|
};
|
||
2 years ago
|
};
|
||
|
|
||
|
struct MonsterSpawner{
|
||
2 years ago
|
private:
|
||
2 years ago
|
vf2d pos;
|
||
1 year ago
|
vf2d range;
|
||
12 months ago
|
std::vector<std::pair<std::string,vf2d>>monsters;
|
||
2 years ago
|
bool triggered=false;
|
||
1 year ago
|
bool upperLevel=false;
|
||
1 year ago
|
std::string bossNameDisplay="";
|
||
2 years ago
|
public:
|
||
|
MonsterSpawner();
|
||
2 years ago
|
//For the monster list, the second pair item is the position relative to the spawner to spawn the monster.
|
||
12 months ago
|
MonsterSpawner(vf2d pos,vf2d range,std::vector<std::pair<std::string,vf2d>>MONSTER_LIST,bool upperLevel=false,std::string bossNameDisplay="");
|
||
2 years ago
|
bool SpawnTriggered();
|
||
1 year ago
|
vf2d GetRange();
|
||
2 years ago
|
vf2d GetPos();
|
||
1 year ago
|
bool DoesUpperLevelSpawning();
|
||
2 years ago
|
void SetTriggered(bool trigger,bool spawnMonsters=true);
|
||
1 year ago
|
friend std::ostream&operator<<(std::ostream&os,MonsterSpawner&rhs);
|
||
2 years ago
|
};
|