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.
137 lines
5.7 KiB
137 lines
5.7 KiB
#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 "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{
|
|
INITIALIZE_PERCEPTION,
|
|
MOVE,
|
|
LOCKON,
|
|
WINDUP,
|
|
};
|
|
#pragma endregion
|
|
|
|
switch(PHASE()){
|
|
case INITIALIZE_PERCEPTION:{
|
|
m.F(A::PERCEPTION_LEVEL)=ConfigFloat("Starting Perception Level");
|
|
SETPHASE(MOVE);
|
|
}break;
|
|
case MOVE:{
|
|
m.F(A::ATTACK_COOLDOWN)+=fElapsedTime;
|
|
|
|
float distToPlayer=m.GetDistanceFrom(game->GetPlayer()->GetPos());
|
|
|
|
const bool outsideMaxShootingRange=distToPlayer>=ConfigPixelsArr("Stand Still and Shoot Range",1);
|
|
|
|
auto PrepareToShoot=[&](){
|
|
SETPHASE(LOCKON);
|
|
m.F(A::SHOOT_TIMER)=ConfigFloat("Attack Windup Time");
|
|
|
|
m.PerformAnimation("SHOOT",m.GetFacingDirectionToTarget(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
|
|
if(m.F(A::ATTACK_COOLDOWN)>=ConfigFloat("Attack Reload Time")/2.f){ //Only the stand still and shoot range remains, which is twice as fast...
|
|
PrepareToShoot();
|
|
}
|
|
}break;
|
|
case LOCKON:{
|
|
m.F(A::SHOOT_TIMER)-=fElapsedTime;
|
|
m.UpdateFacingDirection(game->GetPlayer()->GetPos());
|
|
if(m.F(A::SHOOT_TIMER)<=ConfigFloat("Bow Steadying Time")){
|
|
geom2d::line pointTowardsPlayer(m.GetPos(),game->GetPlayer()->GetPos());
|
|
vf2d extendedLine=pointTowardsPlayer.upoint(1.1f);
|
|
m.V(A::EXTENDED_LINE)=extendedLine;
|
|
Arrow tempArrow{m.GetPos(),extendedLine,pointTowardsPlayer.vector().norm()*ConfigFloat("Arrow Spd"),"goblin_arrow.png",ConfigFloat("Arrow Hitbox Radius"),m.GetAttack(),m.OnUpperLevel()};
|
|
m.V(A::FIRE_VELOCITY)=tempArrow.PointToBestTargetPath(m.F(A::PERCEPTION_LEVEL));
|
|
SETPHASE(WINDUP);
|
|
}
|
|
}break;
|
|
case WINDUP:{
|
|
m.F(A::SHOOT_TIMER)-=fElapsedTime;
|
|
if(m.F(A::SHOOT_TIMER)<=0){
|
|
m.F(A::ATTACK_COOLDOWN)=0.f;
|
|
CreateBullet(Arrow)(m.GetPos(),m.V(A::EXTENDED_LINE),m.V(A::FIRE_VELOCITY),"goblin_arrow.png",ConfigFloat("Arrow Hitbox Radius"),m.GetAttack(),m.OnUpperLevel())EndBullet;
|
|
m.F(A::PERCEPTION_LEVEL)=std::min(ConfigFloat("Maximum Perception Level"),m.F(A::PERCEPTION_LEVEL)+ConfigFloat("Perception Level Increase"));
|
|
m.PerformAnimation("IDLE",m.GetFacingDirectionToTarget(game->GetPlayer()->GetPos()));
|
|
SETPHASE(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;
|
|
}
|
|
} |