|
|
|
#pragma region License
|
|
|
|
/*
|
|
|
|
License (OLC-3)
|
|
|
|
~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Copyright 2024 Joshua 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 "Monster.h"
|
|
|
|
#include "AdventuresInLestoria.h"
|
|
|
|
#include "MonsterStrategyHelpers.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "BulletTypes.h"
|
|
|
|
#include "SoundEffect.h"
|
|
|
|
|
|
|
|
INCLUDE_game
|
|
|
|
INCLUDE_BULLET_LIST
|
|
|
|
|
|
|
|
using A=Attribute;
|
|
|
|
|
|
|
|
void Monster::STRATEGY::WOLF(Monster&m,float fElapsedTime,std::string strategy){
|
|
|
|
switch(PHASE()){
|
|
|
|
case 0:{ //Run towards the player.
|
|
|
|
float distToPlayer=geom2d::line<float>(game->GetPlayer()->GetPos(),m.GetPos()).length();
|
|
|
|
if(distToPlayer<=ConfigFloat("Lockon Range")/100*24.f){
|
|
|
|
SETPHASE(1);
|
|
|
|
m.V(A::LOCKON_POS)=geom2d::line<float>(m.GetPos(),game->GetPlayer()->GetPos()).upoint(1.2f);
|
|
|
|
m.AddBuff(BuffType::LOCKON_SPEEDBOOST,INFINITE,ConfigFloat("Lockon Speed Boost")/100);
|
|
|
|
m.F(A::TARGET_TIMER)=5.0f;
|
|
|
|
}
|
|
|
|
m.target=game->GetPlayer()->GetPos();
|
|
|
|
RUN_TOWARDS(m,fElapsedTime,"Run Towards");
|
|
|
|
}break;
|
|
|
|
case 1:{ //Charge the player.
|
|
|
|
m.F(A::TARGET_TIMER)=std::max(0.f,m.F(A::TARGET_TIMER)-fElapsedTime);
|
|
|
|
float distToTarget=geom2d::line<float>(m.GetPos(),m.V(A::LOCKON_POS)).length();
|
|
|
|
if(distToTarget<=12.f||m.F(A::TARGET_TIMER)==0.f){
|
|
|
|
SETPHASE(2);
|
|
|
|
m.F(A::RECOVERY_TIME)=ConfigFloat("Charge Recovery Time");
|
|
|
|
m.PerformIdleAnimation();
|
|
|
|
}else{
|
|
|
|
m.target=m.V(A::LOCKON_POS);
|
|
|
|
RUN_TOWARDS(m,fElapsedTime,"Run Towards");
|
|
|
|
}
|
|
|
|
}break;
|
|
|
|
case 2:{ //Recovery period after charging.
|
|
|
|
m.F(A::RECOVERY_TIME)=std::max(0.f,m.F(A::RECOVERY_TIME)-fElapsedTime);
|
|
|
|
if(m.F(A::RECOVERY_TIME)==0.f){
|
|
|
|
m.RemoveBuff(BuffType::LOCKON_SPEEDBOOST);
|
|
|
|
m.AddBuff(BuffType::SPEEDBOOST,ConfigFloatArr("Disengage Speed Boost",1),ConfigFloatArr("Disengage Speed Boost",0)/100);
|
|
|
|
std::vector<vf2d>disengagePoints;
|
|
|
|
for(float angle=0.f;angle<360.f;angle+=22.5f){
|
|
|
|
float range=50;
|
|
|
|
vf2d checkLoc=vf2d{0,util::degToRad(angle)}.cart();
|
|
|
|
while(range<=ConfigFloat("Disengage Range")){
|
|
|
|
checkLoc=game->GetPlayer()->GetPos()+vf2d{range/100*24.f,util::degToRad(angle)}.cart();
|
|
|
|
if(game->GetTileCollision(game->GetCurrentMapName(),checkLoc,m.OnUpperLevel())!=game->NO_COLLISION){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
range+=50;
|
|
|
|
}
|
|
|
|
disengagePoints.push_back(checkLoc);
|
|
|
|
}
|
|
|
|
m.path.Initialize(disengagePoints);
|
|
|
|
if(disengagePoints.size()!=16)ERR(std::format("Disengage Points size was not equal to 16! Size: {}",disengagePoints.size()));
|
|
|
|
if(m.path.points.size()!=16)ERR(std::format("Path Points size was not equal to 16! Size: {}",m.path.points.size()));
|
|
|
|
m.I(A::PATH_DIR)=util::random()%2;
|
|
|
|
if(m.I(A::PATH_DIR)==0)m.I(A::PATH_DIR)=-1;
|
|
|
|
m.pathIndex=util::random()%disengagePoints.size();
|
|
|
|
SETPHASE(3);
|
|
|
|
m.F(A::RUN_AWAY_TIMER)=ConfigFloat("Disengage Duration");
|
|
|
|
m.PerformJumpAnimation();
|
|
|
|
}
|
|
|
|
}break;
|
|
|
|
case 3:{ //Disengage.
|
|
|
|
m.F(A::RUN_AWAY_TIMER)=std::max(0.f,m.F(A::RUN_AWAY_TIMER)-fElapsedTime);
|
|
|
|
m.pathIndex+=m.I(A::PATH_DIR)*fElapsedTime*1.25f;
|
|
|
|
m.pathIndex=fmod(m.pathIndex,m.path.points.size());
|
|
|
|
if(m.pathIndex<0){ //When the modulus is negative, adding the total number of elements gets us to the correct index.
|
|
|
|
m.pathIndex=m.pathIndex+m.path.points.size();
|
|
|
|
}
|
|
|
|
if(m.F(A::RUN_AWAY_TIMER)==0.f){
|
|
|
|
SETPHASE(0);
|
|
|
|
}
|
|
|
|
m.target=m.path.GetSplinePoint(m.pathIndex).pos;
|
|
|
|
geom2d::line<float>moveTowardsLine=geom2d::line(m.pos,m.path.GetSplinePoint(m.pathIndex).pos);
|
|
|
|
|
|
|
|
if(moveTowardsLine.length()>1.f){
|
|
|
|
m.UpdateFacingDirection(moveTowardsLine.end);
|
|
|
|
m.SetPos(m.pos+moveTowardsLine.vector().norm()*100*fElapsedTime*m.GetMoveSpdMult());
|
|
|
|
}
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
}
|