diff --git a/Adventures in Lestoria/Adventures in Lestoria.vcxproj b/Adventures in Lestoria/Adventures in Lestoria.vcxproj index 3e602540..ed89c350 100644 --- a/Adventures in Lestoria/Adventures in Lestoria.vcxproj +++ b/Adventures in Lestoria/Adventures in Lestoria.vcxproj @@ -309,6 +309,10 @@ + + + + @@ -700,6 +704,7 @@ + diff --git a/Adventures in Lestoria/Boar.cpp b/Adventures in Lestoria/Boar.cpp index 41615fce..295ddd6a 100644 --- a/Adventures in Lestoria/Boar.cpp +++ b/Adventures in Lestoria/Boar.cpp @@ -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(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"); diff --git a/Adventures in Lestoria/Direction.h b/Adventures in Lestoria/Direction.h new file mode 100644 index 00000000..c6c3d4c8 --- /dev/null +++ b/Adventures in Lestoria/Direction.h @@ -0,0 +1,45 @@ +#pragma region License +/* +License (OLC-3) +~~~~~~~~~~~~~~~ + +Copyright 2024 Joshua Sigona + +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 +}; \ No newline at end of file diff --git a/Adventures in Lestoria/Goblin_Dagger.cpp b/Adventures in Lestoria/Goblin_Dagger.cpp new file mode 100644 index 00000000..84eeb055 --- /dev/null +++ b/Adventures in Lestoria/Goblin_Dagger.cpp @@ -0,0 +1,123 @@ +#pragma region License +/* +License (OLC-3) +~~~~~~~~~~~~~~~ + +Copyright 2024 Joshua Sigona + +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; + } +} \ No newline at end of file diff --git a/Adventures in Lestoria/Monster.cpp b/Adventures in Lestoria/Monster.cpp index 264833ce..04a8a252 100644 --- a/Adventures in Lestoria/Monster.cpp +++ b/Adventures in Lestoria/Monster.cpp @@ -871,4 +871,19 @@ const bool Monster::HasLineOfSight(vf2d targetPos)const{ losLineMarker+=game->GetCurrentMapData().TileSize.x/2.f; } return hasLoS; +} + +const float Monster::GetDistanceFrom(vf2d target)const{ + return geom2d::line(GetPos(),target).length(); +} + +const Direction Monster::GetFacingDirectionToTarget(vf2d target)const{ + float targetDirection=util::angleTo(GetPos(),target); + LOG(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)); } \ No newline at end of file diff --git a/Adventures in Lestoria/Monster.h b/Adventures in Lestoria/Monster.h index 6e5b05a2..84c89ff9 100644 --- a/Adventures in Lestoria/Monster.h +++ b/Adventures in Lestoria/Monster.h @@ -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. diff --git a/Adventures in Lestoria/MonsterAttribute.h b/Adventures in Lestoria/MonsterAttribute.h index dd91afc2..4bb674aa 100644 --- a/Adventures in Lestoria/MonsterAttribute.h +++ b/Adventures in Lestoria/MonsterAttribute.h @@ -107,4 +107,5 @@ enum class Attribute{ LAST_JUMP_TIMER, INITIALIZED, JUMP_MOVE_TO_TARGET_TIMER, + ATTACK_TYPE, }; \ No newline at end of file diff --git a/Adventures in Lestoria/RUN_STRATEGY.cpp b/Adventures in Lestoria/RUN_STRATEGY.cpp index 6eb23c36..f361fd89 100644 --- a/Adventures in Lestoria/RUN_STRATEGY.cpp +++ b/Adventures in Lestoria/RUN_STRATEGY.cpp @@ -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(); } diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index d70bd58f..013bcfe2 100644 --- a/Adventures in Lestoria/Version.h +++ b/Adventures in Lestoria/Version.h @@ -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 diff --git a/Adventures in Lestoria/assets/Campaigns/2_1.tmx b/Adventures in Lestoria/assets/Campaigns/2_1.tmx index 509003e0..7cf5f3ac 100644 --- a/Adventures in Lestoria/assets/Campaigns/2_1.tmx +++ b/Adventures in Lestoria/assets/Campaigns/2_1.tmx @@ -1,5 +1,5 @@ - + @@ -1886,5 +1886,10 @@ + + + + + diff --git a/Adventures in Lestoria/assets/config/MonsterStrategies.txt b/Adventures in Lestoria/assets/config/MonsterStrategies.txt index f2fa8010..86d96aa0 100644 --- a/Adventures in Lestoria/assets/config/MonsterStrategies.txt +++ b/Adventures in Lestoria/assets/config/MonsterStrategies.txt @@ -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 + } } \ No newline at end of file diff --git a/Adventures in Lestoria/assets/config/Monsters.txt b/Adventures in Lestoria/assets/config/Monsters.txt index 544f0547..19c2dcb8 100644 --- a/Adventures in Lestoria/assets/config/Monsters.txt +++ b/Adventures in Lestoria/assets/config/Monsters.txt @@ -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) { diff --git a/Adventures in Lestoria/assets/monsters/Goblin (Dagger).png b/Adventures in Lestoria/assets/monsters/Goblin (Dagger).png index 61f73e58..17645ac4 100644 Binary files a/Adventures in Lestoria/assets/monsters/Goblin (Dagger).png and b/Adventures in Lestoria/assets/monsters/Goblin (Dagger).png differ diff --git a/Adventures in Lestoria/assets/monsters/Goblin (Dagger).xcf b/Adventures in Lestoria/assets/monsters/Goblin (Dagger).xcf new file mode 100644 index 00000000..173155ef Binary files /dev/null and b/Adventures in Lestoria/assets/monsters/Goblin (Dagger).xcf differ diff --git a/x64/Release/Adventures in Lestoria.exe b/x64/Release/Adventures in Lestoria.exe index 3f970ea2..45118e21 100644 Binary files a/x64/Release/Adventures in Lestoria.exe and b/x64/Release/Adventures in Lestoria.exe differ