|
|
|
|
#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 <EFBFBD> 2024 The FreeType
|
|
|
|
|
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
|
|
|
|
|
All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
#pragma endregion
|
|
|
|
|
#include "AdventuresInLestoria.h"
|
|
|
|
|
#include "DEFINES.h"
|
|
|
|
|
#include "Monster.h"
|
|
|
|
|
#include "MonsterStrategyHelpers.h"
|
|
|
|
|
#include "BulletTypes.h"
|
|
|
|
|
#include "util.h"
|
|
|
|
|
/*
|
|
|
|
|
Attack Strategie:
|
|
|
|
|
if range > 1000 move to a 850 range.
|
|
|
|
|
if range 1000-700. Stand still and shoot. (reload twice as fast)
|
|
|
|
|
if range between 500 and 700. Shoot and run in random direction while reloading without getting out of the 500 - 700 range
|
|
|
|
|
range < 500 while reloading try to get distance. still shoot if reload finishes
|
|
|
|
|
After every attack: reload takes 2 seconds.
|
|
|
|
|
before shooting takes 1 second.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
INCLUDE_game
|
|
|
|
|
INCLUDE_ANIMATION_DATA
|
|
|
|
|
INCLUDE_BULLET_LIST
|
|
|
|
|
using A=Attribute;
|
|
|
|
|
|
|
|
|
|
void Monster::STRATEGY::GOBLIN_BOW(Monster&m,float fElapsedTime,std::string strategy){
|
|
|
|
|
#pragma region Phase, Animation, and Helper function setup
|
|
|
|
|
enum PhaseName{
|
|
|
|
|
MOVE,
|
|
|
|
|
WINDUP,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum class ANIMATION_OFFSET{
|
|
|
|
|
IDLE_ANIMATION=0,
|
|
|
|
|
SHOOT_ANIMATION=4,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto SetFacingAnimation=[&](ANIMATION_OFFSET animation,vf2d target){
|
|
|
|
|
m.PerformAnimation("");
|
|
|
|
|
};
|
|
|
|
|
auto IsSpriteFlipped=[&](){return m.GetFacingDirection()==RIGHT;};
|
|
|
|
|
#pragma endregion
|
|
|
|
|
|
|
|
|
|
using enum ANIMATION_OFFSET;
|
|
|
|
|
|
|
|
|
|
m.F(A::ATTACK_COOLDOWN)+=fElapsedTime;
|
|
|
|
|
|
|
|
|
|
switch(m.phase){
|
|
|
|
|
case MOVE:{
|
|
|
|
|
float distToPlayer=m.GetDistanceFrom(game->GetPlayer()->GetPos());
|
|
|
|
|
|
|
|
|
|
const bool outsideMaxShootingRange=distToPlayer>=ConfigPixelsArr("Stand Still and Shoot Range",1);
|
|
|
|
|
|
|
|
|
|
auto PrepareToShoot=[&](){
|
|
|
|
|
m.phase=WINDUP;
|
|
|
|
|
m.F(A::SHOOT_TIMER)=ConfigFloat("Attack Windup Time");
|
|
|
|
|
SetFacingAnimation(SHOOT_ANIMATION,game->GetPlayer()->GetPos());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if(outsideMaxShootingRange){
|
|
|
|
|
m.target=game->GetPlayer()->GetPos();
|
|
|
|
|
RUN_TOWARDS(m,fElapsedTime,"Run Towards");
|
|
|
|
|
}else
|
|
|
|
|
if(m.F(A::ATTACK_COOLDOWN)>=ConfigFloat("Attack Reload Time")){
|
|
|
|
|
PrepareToShoot();
|
|
|
|
|
}else
|
|
|
|
|
if(distToPlayer<ConfigPixels("Run Away Range")){
|
|
|
|
|
m.target=geom2d::line<float>(m.GetPos(),game->GetPlayer()->GetPos()).upoint(-1);
|
|
|
|
|
RUN_TOWARDS(m,fElapsedTime,"Run Towards");
|
|
|
|
|
}else
|
|
|
|
|
if(distToPlayer>=ConfigPixelsArr("Random Direction Range",0)&&distToPlayer<ConfigPixelsArr("Random Direction Range",1)){
|
|
|
|
|
#define CW true
|
|
|
|
|
#define CCW false
|
|
|
|
|
//We are going to walk in a circular direction either CW or CCW (determined in windup phase)
|
|
|
|
|
float dirFromPlayer=util::angleTo(game->GetPlayer()->GetPos(),m.GetPos());
|
|
|
|
|
float targetDir=m.B(A::RANDOM_DIRECTION)==CW?dirFromPlayer+PI/4:dirFromPlayer-PI/4;
|
|
|
|
|
m.target=game->GetPlayer()->GetPos()+vf2d{m.F(A::RANDOM_RANGE),targetDir}.cart();
|
|
|
|
|
RUN_TOWARDS(m,fElapsedTime,"Run Towards");
|
|
|
|
|
}else{ //Only the stand still and shoot range remains...
|
|
|
|
|
PrepareToShoot();
|
|
|
|
|
}
|
|
|
|
|
}break;
|
|
|
|
|
case WINDUP:{
|
|
|
|
|
m.F(A::SHOOT_TIMER)-=fElapsedTime;
|
|
|
|
|
if(m.F(A::SHOOT_TIMER)<=0){
|
|
|
|
|
geom2d::line pointTowardsPlayer(m.GetPos(),game->GetPlayer()->GetPos());
|
|
|
|
|
vf2d extendedLine=pointTowardsPlayer.upoint(1.1f);
|
|
|
|
|
CreateBullet(Arrow)(m.GetPos(),extendedLine,pointTowardsPlayer.vector().norm()*ConfigFloat("Arrow Spd"),"goblin_arrow.png",PI/2*ConfigFloat("Arrow Spd"),ConfigFloat("Arrow Hitbox Radius"),m.GetAttack(),m.OnUpperLevel())EndBullet;
|
|
|
|
|
Arrow&arrow=static_cast<Arrow&>(*BULLET_LIST.back());
|
|
|
|
|
arrow.PointToBestTargetPath(0);
|
|
|
|
|
m.phase=MOVE;
|
|
|
|
|
}
|
|
|
|
|
m.B(A::RANDOM_DIRECTION)=util::random()%2;
|
|
|
|
|
m.F(A::RANDOM_RANGE)=util::random_range(ConfigPixelsArr("Random Direction Range",0),ConfigPixelsArr("Random Direction Range",1));
|
|
|
|
|
}break;
|
|
|
|
|
}
|
|
|
|
|
}
|