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.
AdventuresInLestoria/Adventures in Lestoria/StoneGolem.cpp

345 lines
20 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 <EFBFBD> 2024 The FreeType
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
All rights reserved.
*/
#pragma endregion
#include "Monster.h"
#include "MonsterStrategyHelpers.h"
#include "AdventuresInLestoria.h"
#include "DEFINES.h"
#include "util.h"
#include "BulletTypes.h"
#include "SoundEffect.h"
#include "StageMaskPolygon.h"
#include "ExpandingRing.h"
#include <ranges>
INCLUDE_game
INCLUDE_MONSTER_LIST
using A=Attribute;
void Monster::STRATEGY::STONE_GOLEM(Monster&m,float fElapsedTime,std::string strategy){
enum PhaseName{
INITIALIZE,
BEAR_ATTACK,
SPAWN_PILLAR_PREPARE,
RESPAWN_PILLAR_PREPARE,
SPAWN_PILLAR_CAST,
RESPAWN_PILLAR_CAST,
STANDARD,
STONE_THROW_CAST,
STONE_THROW_FINISH_ANIMATION,
SHOCKWAVE,
FIX_SAFE_AREAS,
DOUBLE_ROCK_TOSS,
STONE_RAIN,
};
const auto PrepareSafeAreas=[&](){
m.VEC(A::STAGE_POLYGONS).clear();
std::for_each(MONSTER_LIST.begin(),MONSTER_LIST.end(),[&](const std::shared_ptr<Monster>&monsterPtr){
if(monsterPtr->GetName()!="Stone Golem Pillar"&&monsterPtr->GetName()!="Breaking Stone Golem Pillar"){
return;
}
const Monster&pillar=*monsterPtr;
if(geom2d::overlaps(geom2d::circle<float>{m.GetPos(),m.GetCollisionRadius()},geom2d::circle<float>{pillar.GetPos(),pillar.GetCollisionRadius()}))return;
#pragma region Solve for Safe Quad
//First draw 4 lines to the corners.
const geom2d::rect<float>&collisionRect{pillar.GetRectangleCollision().value()};
const vf2d upperLeftCorner{pillar.GetPos()+collisionRect.pos*pillar.GetSizeMult()};
const vf2d upperRightCorner{pillar.GetPos()+(collisionRect.pos+vf2d{collisionRect.size.x,0.f})*pillar.GetSizeMult()};
const vf2d lowerLeftCorner{pillar.GetPos()+(collisionRect.pos+vf2d{collisionRect.size.y,0.f})*pillar.GetSizeMult()};
const vf2d lowerRightCorner{pillar.GetPos()+(collisionRect.pos+collisionRect.size)*pillar.GetSizeMult()};
const std::vector<vf2d>corners{upperLeftCorner,upperRightCorner,lowerLeftCorner,lowerRightCorner};
using AngleDiff=float;
using Corner=vf2d;
std::pair<AngleDiff,Corner>largestCorner{};
std::pair<AngleDiff,Corner>smallestCorner{};
float angleToMiddle{geom2d::line<float>{m.GetPos(),pillar.GetPos()}.vector().polar().y};
std::for_each(corners.begin(),corners.end(),[&](const vf2d&corner){
float angleToCorner{geom2d::line<float>{m.GetPos(),corner}.vector().polar().y};
AngleDiff diff{util::angle_difference(angleToCorner,angleToMiddle)};
if(largestCorner.first<diff)largestCorner={diff,corner};
if(smallestCorner.first>diff)smallestCorner={diff,corner};
});
const vf2d extendedLargestCornerPoint{geom2d::line<float>{m.GetPos(),largestCorner.second}.rpoint((100000.f))};
const vf2d extendedSmallestCornerPoint{geom2d::line<float>{m.GetPos(),smallestCorner.second}.rpoint((100000.f))};
#pragma endregion
m.VEC(A::STAGE_POLYGONS).emplace_back(StageMaskPolygon{{largestCorner.second,extendedLargestCornerPoint,extendedSmallestCornerPoint,smallestCorner.second},"safeIndicatorGradient.png",angleToMiddle,PixelLerp(Pixel{uint32_t(m.I(A::SHOCKWAVE_COLOR))},BLACK,sin(geom2d::pi*game->GetRunTime()*2))});
});
m.SetStrategyDrawFunction([](AiL*game,Monster&m,const std::string&strategyName){
std::for_each(m.VEC(A::STAGE_POLYGONS).begin(),m.VEC(A::STAGE_POLYGONS).end(),[&](std::any&data){
StageMaskPolygon&polygon{std::any_cast<StageMaskPolygon&>(data)};
Pixel newCol{PixelLerp(Pixel{uint32_t(m.I(A::SHOCKWAVE_COLOR))},BLACK,sin(geom2d::pi*game->GetRunTime()*2)/2.f+0.5f)};
newCol.a=util::lerp(Pixel{uint32_t(m.I(A::SHOCKWAVE_COLOR))}.a,0.f,sin(geom2d::pi*game->GetRunTime()*2)/2.f+0.5f);
polygon.SetBlendColor(newCol);
polygon.Draw();
});
});
};
#pragma region Respawn Pillar Actions
switch(m.I(A::RESPAWN_PHASE)){
case RESPAWN_PILLAR_PREPARE:{
m.F(A::RESPAWN_RECOVERY_TIME)-=fElapsedTime;
if(m.F(A::RESPAWN_RECOVERY_TIME)<=0.f){
m.V(A::RESPAWN_LOCKON_POS)=game->GetPlayer()->GetPos();
m.SIZET(A::RESPAWN_LOOPING_SOUND_ID)=SoundEffect::PlayLoopingSFX("Rock Toss Cast",m.GetPos());
game->AddEffect(std::make_unique<SpellCircle>(m.V(A::RESPAWN_LOCKON_POS),ConfigFloat("Pillar Respawns.Cast Time"),"range_indicator.png","spell_insignia.png",m.OnUpperLevel(),vf2d{1.f,1.f}*(MONSTER_DATA.at("Stone Golem Pillar").GetCollisionRadius()*MONSTER_DATA.at("Stone Golem Pillar").GetSizeMult()/12.f)*1.25f,0.3f,vf2d{},ConfigPixel("Pillar Respawns.Spell Circle Color"),util::random(2*PI),util::degToRad(ConfigFloat("Pillar Respawns.Spell Circle Rotation Spd")),false,vf2d{1.f,1.f}*(MONSTER_DATA.at("Stone Golem Pillar").GetCollisionRadius()*MONSTER_DATA.at("Stone Golem Pillar").GetSizeMult()/12.f)*0.9f,0.3f,vf2d{},ConfigPixel("Pillar Respawns.Spell Insignia Color"),util::random(2*PI),util::degToRad(ConfigFloat("Pillar Respawns.Spell Insignia Rotation Spd"))),true);
m.F(A::RESPAWN_CASTING_TIMER)=ConfigFloat("Pillar Respawns.Cast Time");
m.I(A::RESPAWN_PHASE)=RESPAWN_PILLAR_CAST;
}
}break;
case RESPAWN_PILLAR_CAST:{
m.F(A::RESPAWN_CASTING_TIMER)-=fElapsedTime;
if(m.F(A::RESPAWN_CASTING_TIMER)<=0.f){
SoundEffect::StopLoopingSFX(m.SIZET(A::RESPAWN_LOOPING_SOUND_ID));
SoundEffect::PlaySFX("Pillar Rise",m.V(A::RESPAWN_LOCKON_POS));
if(m.I(A::BAD_PILLAR_SPAWN_COUNT)>0&&
(util::random_range(0,1)<0.5f||m.I(A::RESPAWN_PATTERN_REPEAT_COUNT)<=m.I(A::BAD_PILLAR_SPAWN_COUNT))){
Monster&badPillar{game->SpawnMonster(m.V(A::RESPAWN_LOCKON_POS),MONSTER_DATA.at("Breaking Stone Golem Pillar"),m.OnUpperLevel())};
game->Hurt(m.V(A::RESPAWN_LOCKON_POS),MONSTER_DATA.at("Breaking Stone Golem Pillar").GetCollisionRadius()*MONSTER_DATA.at("Breaking Stone Golem Pillar").GetSizeMult(),MONSTER_DATA.at("Breaking Stone Golem Pillar").GetAttack(),m.OnUpperLevel(),0.f,HurtType::PLAYER);
badPillar._DealTrueDamage(badPillar.GetMaxHealth()-1U); //Force the health to be 1.
m.I(A::BAD_PILLAR_SPAWN_COUNT)--;
}else{
game->Hurt(m.V(A::RESPAWN_LOCKON_POS),MONSTER_DATA.at("Stone Golem Pillar").GetCollisionRadius()*MONSTER_DATA.at("Stone Golem Pillar").GetSizeMult(),MONSTER_DATA.at("Stone Golem Pillar").GetAttack(),m.OnUpperLevel(),0.f,HurtType::PLAYER);
game->SpawnMonster(m.V(A::RESPAWN_LOCKON_POS),MONSTER_DATA.at("Stone Golem Pillar"),m.OnUpperLevel());
}
m.I(A::RESPAWN_PATTERN_REPEAT_COUNT)--;
if(m.I(A::RESPAWN_PATTERN_REPEAT_COUNT)<=0){
m.I(A::RESPAWN_PHASE)=STANDARD;
}else{
m.F(A::RESPAWN_RECOVERY_TIME)=ConfigFloat("Pillar Respawns.Cast Delay Time");
m.I(A::RESPAWN_PHASE)=RESPAWN_PILLAR_PREPARE;
}
}
}break;
}
#pragma endregion
switch(m.phase){
case INITIALIZE:{
m.F(A::RECOVERY_TIME)=ConfigFloat("Beginning Phase.Pillar Cast Delay Time");
m.I(A::PATTERN_REPEAT_COUNT)=ConfigInt("Beginning Phase.Repeat Count");
m.F(A::HEALTH_PCT_PHASE)=1.f;
m.F(A::NEXT_HEALTH_PCT_PILLAR_PHASE)=ConfigFloat("Pillar Respawns.Start HP Threshold")/100.f;
m.I(A::SHOCKWAVE_COLOR)=ConfigPixel("Shockwave.Danger Area Color").n;
m.phase=SPAWN_PILLAR_PREPARE;
if(ConfigIntArr("Pillar Respawns.Respawn Count",0)<ConfigIntArr("Pillar Respawns.Respawn Count",1))ERR(std::format("WARNING! {} Stone golem pillars were declared damaged when only {} will spawn. Please make sure the number is the same or equal to the total spawned pillars! (\"Pillar Respawns.Respawn Count\" strategy property)",ConfigIntArr("Pillar Respawns.Respawn Count",1),ConfigIntArr("Pillar Respawns.Respawn Count",0)));
}break;
case SPAWN_PILLAR_PREPARE:{
m.F(A::RECOVERY_TIME)-=fElapsedTime;
if(m.F(A::RECOVERY_TIME)<=0.f){
m.V(A::LOCKON_POS)=game->GetPlayer()->GetPos();
m.SIZET(A::LOOPING_SOUND_ID)=SoundEffect::PlayLoopingSFX("Rock Toss Cast",m.GetPos());
m.PerformAnimation("CAST",m.GetFacingDirectionToTarget(m.V(A::LOCKON_POS)));
game->AddEffect(std::make_unique<SpellCircle>(m.V(A::LOCKON_POS),ConfigFloat("Beginning Phase.Pillar Cast Time"),"range_indicator.png","spell_insignia.png",m.OnUpperLevel(),vf2d{1.f,1.f}*(MONSTER_DATA.at("Stone Golem Pillar").GetCollisionRadius()*MONSTER_DATA.at("Stone Golem Pillar").GetSizeMult()/12.f)*1.25f,0.3f,vf2d{},ConfigPixel("Beginning Phase.Pillar Spell Circle Color"),util::random(2*PI),util::degToRad(ConfigFloat("Beginning Phase.Pillar Spell Circle Rotation Spd")),false,vf2d{1.f,1.f}*(MONSTER_DATA.at("Stone Golem Pillar").GetCollisionRadius()*MONSTER_DATA.at("Stone Golem Pillar").GetSizeMult()/12.f)*0.9f,0.3f,vf2d{},ConfigPixel("Beginning Phase.Pillar Spell Insignia Color"),util::random(2*PI),util::degToRad(ConfigFloat("Beginning Phase.Pillar Spell Insignia Rotation Spd"))),true);
m.F(A::CASTING_TIMER)=ConfigFloat("Beginning Phase.Pillar Cast Time");
m.phase=SPAWN_PILLAR_CAST;
}
}break;
case SPAWN_PILLAR_CAST:{
m.F(A::CASTING_TIMER)-=fElapsedTime;
if(m.F(A::CASTING_TIMER)<=0.f){
SoundEffect::StopLoopingSFX(m.SIZET(A::LOOPING_SOUND_ID));
SoundEffect::PlaySFX("Pillar Rise",m.V(A::LOCKON_POS));
m.I(A::PATTERN_REPEAT_COUNT)--;
game->SpawnMonster(m.V(A::LOCKON_POS),MONSTER_DATA.at("Stone Golem Pillar"),m.OnUpperLevel());
game->Hurt(m.V(A::LOCKON_POS),MONSTER_DATA.at("Stone Golem Pillar").GetCollisionRadius()*MONSTER_DATA.at("Stone Golem Pillar").GetSizeMult(),MONSTER_DATA.at("Stone Golem Pillar").GetAttack(),m.OnUpperLevel(),0.f,HurtType::PLAYER);
if(m.I(A::PATTERN_REPEAT_COUNT)<=0){
m.phase=STANDARD;
}else{
m.PerformIdleAnimation(m.GetFacingDirectionToTarget(game->GetPlayer()->GetPos()));
m.F(A::RECOVERY_TIME)=ConfigFloat("Beginning Phase.Pillar Cast Delay Time");
m.phase=SPAWN_PILLAR_PREPARE;
}
}
}break;
case STANDARD:{
SoundEffect::StopLoopingSFX(m.SIZET(A::LOOPING_SOUND_ID)); //If we get here, a sound effect should not be playing...
const bool StoneThrowRollSucceeds=util::random(100.f)<=ConfigFloat("Standard Attack.Stone Throw Chance");
if(m.F(A::HEALTH_PCT_PHASE)-m.GetHealthRatio()>=ConfigFloat("Shockwave.Repeating Threshold")/100.f){
m.F(A::HEALTH_PCT_PHASE)-=ConfigFloat("Shockwave.Repeating Threshold")/100.f;
m.F(A::CASTING_TIMER)=ConfigFloat("Shockwave.Cast Time");
m.SIZET(A::PREVIOUS_MONSTER_COUNT)=MONSTER_LIST.size();
m.PerformAnimation("CAST",m.GetFacingDirectionToTarget(game->GetPlayer()->GetPos()));
PrepareSafeAreas();
m.phase=SHOCKWAVE;
break;
}
if(m.F(A::NEXT_HEALTH_PCT_PILLAR_PHASE)>=m.GetHealthRatio()){
m.F(A::NEXT_HEALTH_PCT_PILLAR_PHASE)-=ConfigFloat("Pillar Respawns.Repeating Threshold")/100.f;
m.F(A::RESPAWN_RECOVERY_TIME)=ConfigFloat("Pillar Respawns.Cast Delay Time");
m.I(A::RESPAWN_PATTERN_REPEAT_COUNT)+=ConfigIntArr("Pillar Respawns.Respawn Count",0);
m.I(A::BAD_PILLAR_SPAWN_COUNT)+=ConfigIntArr("Pillar Respawns.Respawn Count",1);
m.I(A::RESPAWN_PHASE)=RESPAWN_PILLAR_PREPARE;
}
if(StoneThrowRollSucceeds){ //The intent is one or the other attack is supposed to happen. We can't do the slam and a throw, rerolling repeatedly each tick is unncessary.
m.phase=STONE_THROW_CAST;
m.V(A::LOCKON_POS)=game->GetPlayer()->GetPos();
m.PerformAnimation("TOSS ROCK CAST");
m.F(A::CASTING_TIMER)=ConfigFloat("Standard Attack.Stone Throw Cast Time");
game->AddEffect(std::make_unique<SpellCircle>(m.V(A::LOCKON_POS),ConfigFloat("Standard Attack.Stone Throw Cast Time"),"range_indicator.png","spell_insignia.png",m.OnUpperLevel(),vf2d{1.f,1.f}*(ConfigPixels("Standard Attack.Stone Radius")/12.f)*1.25f,0.3f,vf2d{},ConfigPixel("Standard Attack.Stone Throw Spell Circle Color"),util::random(2*PI),util::degToRad(ConfigFloat("Standard Attack.Stone Throw Spell Circle Rotation Spd")),false,vf2d{1.f,1.f}*(ConfigPixels("Standard Attack.Stone Radius")/12.f)*0.9f,0.3f,vf2d{},ConfigPixel("Standard Attack.Stone Throw Spell Insignia Color"),util::random(2*PI),util::degToRad(ConfigFloat("Standard Attack.Stone Throw Spell Insignia Rotation Spd"))),true);
//Use acceleration equation to determine how much time it takes for the stone to land based on gravity.
const float stoneTossTime{ConfigFloat("Standard Attack.Stone Throw Time")};
//Physics!! Kinematic equation from https://openstax.org/books/physics/pages/3-2-representing-acceleration-with-equations-and-graphs a=(2d)/(t^2)
const float acc{(2*-ConfigFloat("Standard Attack.Stone Throw Height Offset"))/std::pow(stoneTossTime,2.f)};
m.SIZET(A::LOOPING_SOUND_ID)=SoundEffect::PlayLoopingSFX("Rock Toss Cast",m.GetPos());
CreateBullet(LargeStone)(m.GetPos()+vf2d{0,ConfigFloat("Standard Attack.Stone Throw Height Offset")/2.f},ConfigFloat("Standard Attack.Stone Throw Time"),m.V(A::LOCKON_POS),m.F(A::CASTING_TIMER),ConfigPixels("Standard Attack.Stone Radius"),ConfigFloat("Standard Attack.Stone Throw Height Offset"),acc,ConfigInt("Standard Attack.Stone Damage"),ConfigFloat("Standard Attack.Stone Throw Knockback Factor"),m.OnUpperLevel(),false,INFINITY,false,WHITE,vf2d{1,1}*m.GetSizeMult(),util::random(2*PI))EndBullet;
}else{
m.phase=BEAR_ATTACK;
m.F(A::CHASE_TIMER)=0.f;
}
}break;
case STONE_THROW_CAST:{
m.F(A::CASTING_TIMER)-=fElapsedTime;
if(m.F(A::CASTING_TIMER)<=0.f){
SoundEffect::StopLoopingSFX(m.SIZET(A::LOOPING_SOUND_ID));
m.PerformAnimation("TOSS ROCK");
m.F(A::RECOVERY_TIME)=m.GetCurrentAnimation().GetTotalAnimationDuration();
m.phase=STONE_THROW_FINISH_ANIMATION;
}
}break;
case STONE_THROW_FINISH_ANIMATION:{
m.F(A::RECOVERY_TIME)-=fElapsedTime;
if(m.F(A::RECOVERY_TIME)<=0.f){
m.phase=STANDARD;
}
}break;
case SHOCKWAVE:{
m.F(A::CASTING_TIMER)-=fElapsedTime;
Pixel newCol{PixelLerp(m.I(A::SHOCKWAVE_COLOR),BLACK,sin(geom2d::pi*game->GetRunTime()*2)/2.f+0.5f)};
newCol.a=util::lerp(255.f,210.f,sin(geom2d::pi*game->GetRunTime()*2)/2.f+0.5f);
game->SetWorldColor(newCol);
if(m.SIZET(A::PREVIOUS_MONSTER_COUNT)!=MONSTER_LIST.size()){ //The monster list has changed...Whether it's a pillar getting added or removed, it's important we recalculate safe areas proper.
m.phase=FIX_SAFE_AREAS; //HACK ALERT! Since spawning/removing monsters doesn't immediately occur in the MONSTER_LIST structure, we must defer the safe areas until the next tick and then recalculate them. To do this, we put the monster into another state and pause the shockwave attack for a frame to fix the new spawn areas on the next tick.
m.F(A::SAFE_AREA_WAIT_TIMER)=0.01f;
m.SIZET(A::PREVIOUS_MONSTER_COUNT)=MONSTER_LIST.size();
}
if(m.F(A::CASTING_TIMER)<=0.f){
game->SetupWorldShake(ConfigFloat("Shockwave.Shockwave Screen Shake Time"));
bool playerIsSafe{false};
for(std::any&data:m.VEC(A::STAGE_POLYGONS)){
std::vector<geom2d::triangle<float>>collisionTris{any_cast<StageMaskPolygon>(data).GetCollisionTriangles()};
for(const geom2d::triangle<float>&tri:collisionTris){
if(geom2d::overlaps(game->GetPlayer()->Hitbox(),tri)){
playerIsSafe=true;
goto DoneWithCollisionCheck;
}
}
}
DoneWithCollisionCheck:
if(!playerIsSafe){
game->GetPlayer()->Hurt(ConfigInt("Shockwave.Damage"),m.OnUpperLevel(),m.GetZ());
game->GetPlayer()->Knockback(util::pointTo(m.GetPos(),game->GetPlayer()->GetPos())*ConfigFloat("Shockwave.Knockback Amount"));
}
m.VEC(A::STAGE_POLYGONS).clear();
std::for_each(MONSTER_LIST.begin(),MONSTER_LIST.end(),[&](const std::shared_ptr<Monster>&monsterPtr){
if(monsterPtr->GetName()!="Stone Golem Pillar")return;
monsterPtr->_DealTrueDamage(ConfigInt("Shockwave.Pillar Damage"));
});
SoundEffect::PlaySFX("Shockwave",m.GetPos());
game->AddEffect(std::make_unique<ExpandingRing>(m.GetPos(),ConfigFloat("Shockwave.Shockwave Ring Lifetime"),"finishring.png",m.OnUpperLevel(),vf2d{ConfigFloat("Shockwave.Ring Expand Speed"),ConfigFloat("Shockwave.Ring Expand Speed")},vf2d{1.f,1.f},ConfigFloat("Shockwave.Shockwave Fadeout Time"),vf2d{},ConfigPixel("Shockwave.Shockwave Color")),true);
m.phase=STANDARD;
game->SetWorldColor(WHITE);
}
}break;
case FIX_SAFE_AREAS:{
if(m.F(A::SAFE_AREA_WAIT_TIMER)<=0.f){
PrepareSafeAreas(); //Recalculate safe areas if the shockwave attack is going off.
m.phase=SHOCKWAVE;
}else m.F(A::SAFE_AREA_WAIT_TIMER)-=fElapsedTime;
}break;
case BEAR_ATTACK:{
m.F(A::CHASE_TIMER)+=fElapsedTime;
BEAR(m,fElapsedTime,"Bear");
//Extending the bear script's variables to read the state of it...
const bool SlamHasFinished=m.I(A::ATTACK_COUNT)!=m.I(A::BEAR_STOMP_COUNT); //The bear script uses the internal phase variable to determine the state of things.
if(SlamHasFinished){
m.phase=STANDARD;
m.I(A::ATTACK_COUNT)=m.I(A::BEAR_STOMP_COUNT);
}else
if(m.I(A::PHASE)==0&&m.F(A::CHASE_TIMER)>=ConfigFloat("Max Chase Time")){
m.phase=DOUBLE_ROCK_TOSS;
m.PerformAnimation("RAISE ROCK");
m.I(A::STONE_TOSS_COUNT)=ConfigInt("Stone Rain.Initial Stone Toss Count");
m.F(A::STONE_TOSS_TIMER)=m.GetCurrentAnimation().GetTotalAnimationDuration();
}
}break;
case DOUBLE_ROCK_TOSS:{
m.F(A::STONE_TOSS_TIMER)-=fElapsedTime;
if(m.F(A::STONE_TOSS_TIMER)<=0.f){
m.F(A::STONE_TOSS_TIMER)=ConfigFloat("Stone Rain.Stone Toss Delay");
m.I(A::STONE_TOSS_COUNT)--;
const datafile&throwPos{Config("Stone Rain.Stone Toss Initial Throw Pos")};
game->AddEffect(std::make_unique<RockLaunch>(m.GetPos()+vf2d{util::random_range(throwPos.GetReal(0),throwPos.GetReal(2)),util::random_range(throwPos.GetReal(1),throwPos.GetReal(3))},10.f,"rock.png",ConfigFloat("Stone Rain.Stone Toss Delay"),ConfigFloat("Stone Rain.Stone Toss Rock Size Mult"),0.1f,vf2d{0.f,-ConfigFloat("Stone Rain.Stone Toss Throw Speed")},WHITE,util::random(2*PI),0.f));
if(m.I(A::STONE_TOSS_COUNT)<=0){
m.phase=STONE_RAIN;
m.F(A::BREAK_TIME)=ConfigFloat("Stone Rain.Stone Golem Wait Time");
m.PerformAnimation("CAST");
for(int i:std::ranges::iota_view(0,ConfigInt("Stone Rain.Stone Count"))){
CreateBullet(FallingStone)(game->camera.GetViewPosition()+vf2d{util::random(game->ScreenWidth()),util::random(game->ScreenHeight())},ConfigVec("Stone Rain.Stone Vel"),ConfigFloatArr("Stone Rain.Stone Vel",2),ConfigFloat("Stone Rain.Indicator Time"),ConfigPixels("Stone Rain.Stone Radius"),ConfigInt("Stone Rain.Stone Damage"),m.OnUpperLevel(),false,ConfigFloat("Stone Rain.Stone Knockback Amt"),util::random_range(ConfigFloatArr("Stone Rain.Stone Fall Delay",0),ConfigFloatArr("Stone Rain.Stone Fall Delay",1)),false,ConfigPixel("Stone Rain.Stone Spell Circle Color"),vf2d{ConfigFloat("Stone Rain.Stone Radius")/100.f*2.f,ConfigFloat("Stone Rain.Stone Radius")/100.f*2.f},util::random(2*PI),util::random(2*PI),util::degToRad(ConfigFloat("Stone Rain.Stone Spell Circle Rotation Spd")),ConfigPixel("Stone Rain.Stone Spell Insignia Color"),util::random(2*PI),util::degToRad(ConfigFloat("Stone Rain.Stone Spell Insignia Rotation Spd")))EndBullet;
}
}
}
}break;
case STONE_RAIN:{
m.F(A::BREAK_TIME)-=fElapsedTime;
if(m.F(A::BREAK_TIME)<=0.f){
m.phase=STANDARD;
}
}break;
}
}