Goblin Dagger AI basic behaviors implemented. Release Build 9027.

mac-build
sigonasr2 7 months ago
parent 074a53e34f
commit c03f87aefd
  1. 5
      Adventures in Lestoria/Adventures in Lestoria.vcxproj
  2. 2
      Adventures in Lestoria/Boar.cpp
  3. 45
      Adventures in Lestoria/Direction.h
  4. 123
      Adventures in Lestoria/Goblin_Dagger.cpp
  5. 15
      Adventures in Lestoria/Monster.cpp
  6. 4
      Adventures in Lestoria/Monster.h
  7. 1
      Adventures in Lestoria/MonsterAttribute.h
  8. 1
      Adventures in Lestoria/RUN_STRATEGY.cpp
  9. 2
      Adventures in Lestoria/Version.h
  10. 7
      Adventures in Lestoria/assets/Campaigns/2_1.tmx
  11. 11
      Adventures in Lestoria/assets/config/MonsterStrategies.txt
  12. 46
      Adventures in Lestoria/assets/config/Monsters.txt
  13. BIN
      Adventures in Lestoria/assets/monsters/Goblin (Dagger).png
  14. BIN
      Adventures in Lestoria/assets/monsters/Goblin (Dagger).xcf
  15. BIN
      x64/Release/Adventures in Lestoria.exe

@ -309,6 +309,10 @@
<ClInclude Include="AdventuresInLestoria.h" />
<ClInclude Include="DamageNumber.h" />
<ClInclude Include="DEFINES.h" />
<ClInclude Include="Direction.h">
<SubType>
</SubType>
</ClInclude>
<ClInclude Include="discord-files\achievement_manager.h" />
<ClInclude Include="discord-files\activity_manager.h" />
<ClInclude Include="discord-files\application_manager.h" />
@ -700,6 +704,7 @@
</SubType>
</ClCompile>
<ClCompile Include="GameState.cpp" />
<ClCompile Include="Goblin_Dagger.cpp" />
<ClCompile Include="InputHelper.cpp">
<SubType>
</SubType>

@ -59,7 +59,7 @@ void Monster::STRATEGY::BOAR(Monster&m,float fElapsedTime,std::string strategy){
switch(m.phase){
case PhaseName::MOVE:{
float distToPlayer=geom2d::line<float>(m.GetPos(),game->GetPlayer()->GetPos()).length();
float distToPlayer=m.GetDistanceFrom(game->GetPlayer()->GetPos());
if(m.canMove&&distToPlayer>=ConfigInt("Closein Range")/100.f*24){
m.RemoveBuff(BuffType::SELF_INFLICTED_SLOWDOWN);
RUN_TOWARDS(m,fElapsedTime,"Run Towards");

@ -0,0 +1,45 @@
#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
#pragma once
enum class Direction{
NORTH,
EAST,
SOUTH,
WEST
};

@ -0,0 +1,123 @@
#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"
/*
Attack Strategie:
Runs infront of player,
short preparation for attack (~0.3 - 0.5 secs depending what looks better animation wise)
and either slashes with the dagger or stabs with it.
1 sec of idle before loop repeats
*/
INCLUDE_game
INCLUDE_ANIMATION_DATA
using A=Attribute;
void Monster::STRATEGY::GOBLIN_DAGGER(Monster&m,float fElapsedTime,std::string strategy){
enum PhaseName{
MOVE,
WINDUP,
RECOVERY,
};
enum AttackType{
STAB,
SLASH
};
enum class ANIMATION_OFFSET{
STAB_WINDUP_ANIMATION=0,
STAB_ANIMATION=4,
SLASH_WINDUP_ANIMATION=8,
SLASH_ANIMATION=12,
IDLE_ANIMATION=16,
};
auto SetFacingAnimation=[&](ANIMATION_OFFSET animation,vf2d target){
m.PerformOtherAnimation(int(animation)+int(m.GetFacingDirectionToTarget(target)));
};
using enum ANIMATION_OFFSET;
switch(m.phase){
case MOVE:{
float distToPlayer=m.GetDistanceFrom(game->GetPlayer()->GetPos());
if(distToPlayer>ConfigFloat("Attack Spacing")/100.f*24){
RUN_TOWARDS(m,fElapsedTime,"Run Towards");
}else{
m.phase=WINDUP;
m.I(A::ATTACK_TYPE)=STAB; //TODO: Choose randomly between stab or slash.
m.F(A::CASTING_TIMER)=ConfigFloat("Stab Windup Time");
switch(m.I(A::ATTACK_TYPE)){
case STAB:{
SetFacingAnimation(STAB_WINDUP_ANIMATION,game->GetPlayer()->GetPos());
}break;
case SLASH:{
SetFacingAnimation(SLASH_WINDUP_ANIMATION,game->GetPlayer()->GetPos());
}break;
default:ERR(std::format("WARNING! Invalid Attack type {} provided. THIS SHOULD NOT BE HAPPENING!",m.I(A::ATTACK_TYPE)));
}
}
}break;
case WINDUP:{
m.F(A::CASTING_TIMER)-=fElapsedTime;
if(m.F(A::CASTING_TIMER)<=0){
m.phase=RECOVERY;
switch(m.I(A::ATTACK_TYPE)){
case STAB:{
SetFacingAnimation(STAB_ANIMATION,game->GetPlayer()->GetPos());
}break;
case SLASH:{
SetFacingAnimation(SLASH_ANIMATION,game->GetPlayer()->GetPos());
}break;
default:ERR(std::format("WARNING! Invalid Attack type {} provided. THIS SHOULD NOT BE HAPPENING!",m.I(A::ATTACK_TYPE)));
}
m.F(A::CASTING_TIMER)=m.GetCurrentAnimation().GetTotalAnimationDuration();
m.F(A::RECOVERY_TIME)=ConfigFloat("Attack Recovery Time");
}
}break;
case RECOVERY:{
m.F(A::CASTING_TIMER)-=fElapsedTime;
m.F(A::RECOVERY_TIME)-=fElapsedTime;
if(m.F(A::CASTING_TIMER)<=0){SetFacingAnimation(IDLE_ANIMATION,game->GetPlayer()->GetPos());}
if(m.F(A::RECOVERY_TIME)<=0)m.phase=MOVE;
}break;
}
}

@ -872,3 +872,18 @@ const bool Monster::HasLineOfSight(vf2d targetPos)const{
}
return hasLoS;
}
const float Monster::GetDistanceFrom(vf2d target)const{
return geom2d::line<float>(GetPos(),target).length();
}
const Direction Monster::GetFacingDirectionToTarget(vf2d target)const{
float targetDirection=util::angleTo(GetPos(),target);
LOG(targetDirection<<std::endl);
if(targetDirection<=PI/4&&targetDirection>-PI/4)return Direction::EAST;
else if(targetDirection>=3*PI/4||targetDirection<-3*PI/4)return Direction::WEST;
else if(targetDirection<=3*PI/4&&targetDirection>PI/4)return Direction::SOUTH;
else if(targetDirection>=-3*PI/4&&targetDirection<-PI/4)return Direction::NORTH;
ERR(std::format("WARNING! Target direction {} did not result in a proper facing direction!! THIS SHOULD NOT BE HAPPENING!",targetDirection));
}

@ -47,6 +47,7 @@ All rights reserved.
#include "GameEvent.h"
#include "TMXParser.h"
#include "MonsterData.h"
#include "Direction.h"
INCLUDE_ITEM_DATA
@ -147,6 +148,8 @@ public:
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;
private:
std::string name;
vf2d pos;
@ -230,6 +233,7 @@ private:
static void URSULE(Monster&m,float fElapsedTime,std::string strategy);
static void NPC(Monster&m,float fElapsedTime,std::string strategy);
static void BOAR(Monster&m,float fElapsedTime,std::string strategy);
static void GOBLIN_DAGGER(Monster&m,float fElapsedTime,std::string strategy);
};
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.

@ -107,4 +107,5 @@ enum class Attribute{
LAST_JUMP_TIMER,
INITIALIZED,
JUMP_MOVE_TO_TARGET_TIMER,
ATTACK_TYPE,
};

@ -54,6 +54,7 @@ void Monster::InitializeStrategies(){
STRATEGY_DATA.insert("Ursule",Monster::STRATEGY::URSULE);
STRATEGY_DATA.insert("NPC",Monster::STRATEGY::NPC);
STRATEGY_DATA.insert("Boar",Monster::STRATEGY::BOAR);
STRATEGY_DATA.insert("Goblin Dagger",Monster::STRATEGY::GOBLIN_DAGGER);
STRATEGY_DATA.SetInitialized();
}

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 1
#define VERSION_MINOR 2
#define VERSION_PATCH 0
#define VERSION_BUILD 9021
#define VERSION_BUILD 9027
#define stringify(a) stringify_(a)
#define stringify_(a) #a

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.2" class="Map" orientation="orthogonal" renderorder="right-down" width="238" height="369" tilewidth="24" tileheight="24" infinite="0" nextlayerid="7" nextobjectid="16">
<map version="1.10" tiledversion="1.10.2" class="Map" orientation="orthogonal" renderorder="right-down" width="238" height="369" tilewidth="24" tileheight="24" infinite="0" nextlayerid="7" nextobjectid="17">
<properties>
<property name="Backdrop" propertytype="Backdrop" value="None"/>
<property name="Background Music" propertytype="BGM" value="foresty1_1"/>
@ -1886,5 +1886,10 @@
<object id="15" name="Spawn Group 1" type="SpawnGroup" x="4439" y="7869" width="496" height="424">
<ellipse/>
</object>
<object id="16" template="../maps/Monsters/Goblin (Dagger).tx" x="4599" y="8065">
<properties>
<property name="spawner" type="object" value="15"/>
</properties>
</object>
</objectgroup>
</map>

@ -552,4 +552,15 @@ MonsterStrategy
Charge Knockback Amount = 140
}
Goblin Dagger
{
# Distance from player to run to before swinging weapon.
Attack Spacing = 50
# Stab Attack windup time
Stab Windup Time = 0.3s
# Amount of time where nothing happens after an attack.
Attack Recovery Time = 1.0s
}
}

@ -494,7 +494,10 @@ Monsters
XP = 14
Strategy = Run Towards
Strategy = Goblin Dagger
# Wait time override for Run Towards strategy.
WaitTime = 0
#Size of each animation frame
SheetFrameSize = 24,24
@ -515,7 +518,46 @@ Monsters
#Additional custom animations go down below. Start with ANIMATION[0] Order is:
# File name, Frame Count, Frame Speed (s), Frame Cycling (Repeat,OneShot,PingPong,Reverse)
# NOTE: ANIMATION[0] will always be row 5 of an animation sheet, all numbers that follow are each below each other.
# ANIMATION[0] = 1, 0.1, OneShot
# Up Stab Windup
ANIMATION[0] = 1, 0.1, OneShot
# Right Stab Windup
ANIMATION[1] = 1, 0.1, OneShot
# Down Stab Windup
ANIMATION[2] = 1, 0.1, OneShot
# Left Stab Windup
ANIMATION[3] = 1, 0.1, OneShot
# Up Stab
ANIMATION[4] = 2, 0.1, PingPong
# Right Stab
ANIMATION[5] = 2, 0.1, PingPong
# Down Stab
ANIMATION[6] = 2, 0.1, PingPong
# Left Stab
ANIMATION[7] = 2, 0.1, PingPong
# Up Slash Windup
ANIMATION[8] = 1, 0.1, OneShot
# Right Slash Windup
ANIMATION[9] = 1, 0.1, OneShot
# Down Slash Windup
ANIMATION[10] = 1, 0.1, OneShot
# Left Slash Windup
ANIMATION[11] = 1, 0.1, OneShot
# Up Slash
ANIMATION[12] = 2, 0.1, PingPong
# Right Slash
ANIMATION[13] = 2, 0.1, PingPong
# Down Slash
ANIMATION[14] = 2, 0.1, PingPong
# Left Slash
ANIMATION[15] = 2, 0.1, PingPong
# Up Idle
ANIMATION[16] = 1, 0.1, PingPong
# Right Idle
ANIMATION[17] = 1, 0.1, PingPong
# Down Idle
ANIMATION[18] = 1, 0.1, PingPong
# Left Idle
ANIMATION[19] = 1, 0.1, PingPong
}
Goblin (Bow)
{

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Loading…
Cancel
Save