#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 "Class.h" #include "DEFINES.h" #include "Player.h" #include "Effect.h" #include "AdventuresInLestoria.h" #include "BulletTypes.h" #include "util.h" #include "config.h" #include "SoundEffect.h" INCLUDE_MONSTER_LIST INCLUDE_BULLET_LIST INCLUDE_game void Ranger::Initialize(){ READFROMCONFIG(Ranger,RANGER); Ranger::idle_n="RANGER_IDLE_N"; Ranger::idle_e="RANGER_IDLE_E"; Ranger::idle_s="RANGER_IDLE_S"; Ranger::idle_w="RANGER_IDLE_W"; Ranger::walk_n="RANGER_WALK_N"; Ranger::walk_e="RANGER_WALK_E"; Ranger::walk_s="RANGER_WALK_S"; Ranger::walk_w="RANGER_WALK_W"; } SETUP_CLASS(Ranger) void Ranger::OnUpdate(float fElapsedTime){ } bool Ranger::AutoAttack(){ geom2d::line pointTowardsCursor(GetPos(),GetWorldAimingLocation()); vf2d extendedLine=pointTowardsCursor.upoint(1.1f); float angleToCursor=atan2(extendedLine.y-GetPos().y,extendedLine.x-GetPos().x); attack_cooldown_timer=ARROW_ATTACK_COOLDOWN-GetAttackRecoveryRateReduction(); CreateBullet(Arrow)(GetPos(),extendedLine,vf2d{cos(angleToCursor)*"Ranger.Auto Attack.ArrowSpd"_F,float(sin(angleToCursor)*"Ranger.Auto Attack.ArrowSpd"_F-PI/8*"Ranger.Auto Attack.ArrowSpd"_F)}+movementVelocity/1.5f,"Ranger.Auto Attack.Radius"_F,int(GetAttack()*"Ranger.Auto Attack.DamageMult"_F),OnUpperLevel(),true)EndBullet; BULLET_LIST.back()->SetIsPlayerAutoAttackProjectile(); SetState(State::SHOOT_ARROW); SetAnimationBasedOnTargetingDirection(angleToCursor); SoundEffect::PlaySFX("Ranger.Auto Attack.Sound"_S,SoundEffect::CENTERED); return true; } void Ranger::InitializeClassAbilities(){ #pragma region Ranger Right-click Ability (Retreat) Ranger::rightClickAbility.action= [](Player*p,vf2d pos={}){ geom2d::line mouseDir{p->GetWorldAimingLocation(Player::USE_WALK_DIR),p->GetPos()}; float velocity=(0.5f*-p->friction*p->RETREAT_TIME*p->RETREAT_TIME-p->RETREAT_DISTANCE)/-p->RETREAT_TIME; //Derived from kinetic motion formula. p->SetVelocity(mouseDir.vector().norm()*velocity); p->retreatTimer=p->RETREAT_TIME; p->iframe_time=p->RETREAT_TIME; p->ghostPositions.push_back(p->GetPos()+vf2d{0,-p->GetZ()}); p->ghostFrameTimer=p->RETREAT_GHOST_FRAME_DELAY; p->ghostRemoveTimer=p->RETREAT_GHOST_FRAMES*p->RETREAT_GHOST_FRAME_DELAY; float angleToCursor=atan2(p->GetWorldAimingLocation(Player::USE_WALK_DIR).y-p->GetPos().y,p->GetWorldAimingLocation(Player::USE_WALK_DIR).x-p->GetPos().x); p->SetAnimationBasedOnTargetingDirection(angleToCursor); p->SetState(State::RETREAT); SoundEffect::PlaySFX("Ranger.Right Click Ability.Sound"_S,SoundEffect::CENTERED); return true; }; #pragma endregion #pragma region Ranger Ability 1 (Rapid Fire) Ranger::ability1.action= [](Player*p,vf2d pos={}){ p->remainingRapidFireShots=p->RAPID_FIRE_SHOOT_AMOUNT; p->rapidFireTimer=p->RAPID_FIRE_SHOOT_DELAY; if("Ranger.Ability 1.IsAnimationLocked"_I){ p->SetState(State::ANIMATION_LOCK); } SoundEffect::PlaySFX("Ranger.Ability 1.Sound"_S,SoundEffect::CENTERED); return true; }; #pragma endregion #pragma region Ranger Ability 2 (Charged Shot) Ranger::ability2.action= [](Player*p,vf2d pos={}){ vf2d arrowVelocity=util::pointTo(p->GetPos(),p->GetWorldAimingLocation()); BULLET_LIST.push_back(std::make_unique(p->GetPos(),arrowVelocity*"Ranger.Ability 2.Speed"_F,12*"Ranger.Ability 2.Radius"_F/100,p->GetAttack()*"Ranger.Ability 2.DamageMult"_F,p->OnUpperLevel(),true)); p->SetState(State::SHOOT_ARROW); p->rangerShootAnimationTimer=0.3f; p->SetAnimationBasedOnTargetingDirection(atan2(arrowVelocity.y,arrowVelocity.x)); game->SetupWorldShake("Ranger.Ability 2.WorldShakeTime"_F); p->Knockback(-1.f*arrowVelocity.norm()*"Ranger.Ability 2.Knockback"_F); SoundEffect::PlaySFX("Ranger.Ability 2.Sound"_S,SoundEffect::CENTERED); return true; }; #pragma endregion #pragma region Ranger Ability 3 (Multi Shot) Ranger::ability3.action= [](Player*p,vf2d pos={}){ geom2d::line pointTowardsCursor=geom2d::line(p->GetPos(),p->GetWorldAimingLocation()); float shootingDist=pointTowardsCursor.length(); vf2d shootingDirMiddle=pointTowardsCursor.vector(); float shootingAngle=atan2(shootingDirMiddle.y,shootingDirMiddle.x); int arrowCount="Ranger.Ability 3.ArrowCount"_I%2==0?"Ranger.Ability 3.ArrowCount"_I+1:"Ranger.Ability 3.ArrowCount"_I; for(int i=0;iGetPos(),p->GetPos()+vf2d{cos(newAngle),sin(newAngle)}*shootingDist); vf2d extendedLine=pointTowardsCursor.upoint(1.1f); BULLET_LIST.push_back(std::make_unique(Arrow(p->GetPos(),extendedLine,vf2d{cos(newAngle)*"Ranger.Ability 3.ArrowSpd"_F,float(sin(newAngle)*"Ranger.Ability 3.ArrowSpd"_F-PI/8*"Ranger.Ability 3.ArrowSpd"_F)}+p->movementVelocity,12*"Ranger.Ability 3.ArrowRadius"_F/100,int(p->GetAttack()*"Ranger.Ability 3.DamageMult"_F),p->OnUpperLevel(),true))); } p->rangerShootAnimationTimer=0.3f; p->SetState(State::SHOOT_ARROW); p->SetAnimationBasedOnTargetingDirection(shootingAngle); SoundEffect::PlaySFX("Ranger.Ability 3.Sound"_S,SoundEffect::CENTERED); return true; }; #pragma endregion }