|
|
|
@ -154,7 +154,7 @@ State Player::GetState(){ |
|
|
|
|
|
|
|
|
|
void Player::Update(float fElapsedTime){ |
|
|
|
|
Ability&rightClickAbility=GetRightClickAbility(), |
|
|
|
|
&ability1=GetAbility1(), |
|
|
|
|
&ability=GetAbility1(), |
|
|
|
|
&ability2=GetAbility2(), |
|
|
|
|
&ability3=GetAbility3(), |
|
|
|
|
&ability4=GetAbility4(); |
|
|
|
@ -256,7 +256,7 @@ void Player::Update(float fElapsedTime){ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
rightClickAbility.cooldown=std::max(0.f,rightClickAbility.cooldown-fElapsedTime); |
|
|
|
|
ability1.cooldown=std::max(0.f,ability1.cooldown-fElapsedTime); |
|
|
|
|
ability.cooldown=std::max(0.f,ability.cooldown-fElapsedTime); |
|
|
|
|
ability2.cooldown=std::max(0.f,ability2.cooldown-fElapsedTime); |
|
|
|
|
ability3.cooldown=std::max(0.f,ability3.cooldown-fElapsedTime); |
|
|
|
|
for(Monster&m:MONSTER_LIST){ |
|
|
|
@ -291,41 +291,44 @@ void Player::Update(float fElapsedTime){ |
|
|
|
|
if(attack_cooldown_timer==0&&game->GetMouse(0).bHeld){ |
|
|
|
|
AutoAttack(); |
|
|
|
|
} |
|
|
|
|
if(ability1.cooldown==0&&GetMana()>=ability1.manaCost&&game->GetKey(SHIFT).bHeld){ |
|
|
|
|
if(ability1.action()){ |
|
|
|
|
ability1.cooldown=ability1.COOLDOWN_TIME; |
|
|
|
|
mana-=ability1.manaCost; |
|
|
|
|
} |
|
|
|
|
} else
|
|
|
|
|
if(ability1.cooldown==0&&GetMana()<ability1.manaCost&&game->GetKey(SHIFT).bPressed){ |
|
|
|
|
notEnoughManaDisplay={ability1.name,1}; |
|
|
|
|
} |
|
|
|
|
if(ability2.cooldown==0&&GetMana()>=ability2.manaCost&&game->GetKey(SPACE).bPressed){ |
|
|
|
|
if(ability2.action()){ |
|
|
|
|
ability2.cooldown=ability2.COOLDOWN_TIME; |
|
|
|
|
mana-=ability2.manaCost; |
|
|
|
|
} |
|
|
|
|
} else
|
|
|
|
|
if(ability2.cooldown==0&&GetMana()<ability2.manaCost&&game->GetKey(SPACE).bPressed){ |
|
|
|
|
notEnoughManaDisplay={ability2.name,1}; |
|
|
|
|
} |
|
|
|
|
if(ability3.cooldown==0&&GetMana()>=ability3.manaCost&&game->GetKey(CTRL).bPressed){ |
|
|
|
|
if(ability3.action()){ |
|
|
|
|
ability3.cooldown=ability3.COOLDOWN_TIME; |
|
|
|
|
mana-=ability3.manaCost; |
|
|
|
|
} |
|
|
|
|
} else
|
|
|
|
|
if(ability3.cooldown==0&&GetMana()<ability3.manaCost&&game->GetKey(CTRL).bPressed){ |
|
|
|
|
notEnoughManaDisplay={ability3.name,1}; |
|
|
|
|
} |
|
|
|
|
if(rightClickAbility.cooldown==0&&GetMana()>=rightClickAbility.manaCost&&game->GetMouse(1).bHeld){ |
|
|
|
|
if(rightClickAbility.action()){ |
|
|
|
|
rightClickAbility.cooldown=rightClickAbility.COOLDOWN_TIME; |
|
|
|
|
mana-=rightClickAbility.manaCost; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto AllowedToCast=[&](Ability&ability){return !ability.precastInfo.precastTargetingRequired||ability.precastInfo.precastTargetingRequired&&GetState()==State::PREP_CAST;}; |
|
|
|
|
auto CheckAndPerformAbility=[&](Ability&ability,HWButton key){ |
|
|
|
|
if(ability.cooldown==0&&GetMana()>=ability.manaCost){ |
|
|
|
|
if(key.bPressed||key.bReleased&&&ability==castPrepAbility&&GetState()==State::PREP_CAST){ |
|
|
|
|
if(AllowedToCast(ability)&&ability.action()){ |
|
|
|
|
ability.cooldown=ability.COOLDOWN_TIME; |
|
|
|
|
mana-=ability.manaCost; |
|
|
|
|
}else |
|
|
|
|
if(ability.precastInfo.precastTargetingRequired&&GetState()!=State::PREP_CAST){ |
|
|
|
|
PrepareCast(ability); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else
|
|
|
|
|
if(ability.cooldown==0&&GetMana()<ability.manaCost&&key.bPressed){ |
|
|
|
|
notEnoughManaDisplay={ability.name,1}; |
|
|
|
|
} |
|
|
|
|
} else
|
|
|
|
|
if(rightClickAbility.cooldown==0&&GetMana()<rightClickAbility.manaCost&&game->GetMouse(1).bPressed){ |
|
|
|
|
notEnoughManaDisplay={rightClickAbility.name,1}; |
|
|
|
|
}; |
|
|
|
|
CheckAndPerformAbility(GetAbility1(),game->GetKey(SHIFT)); |
|
|
|
|
CheckAndPerformAbility(GetAbility2(),game->GetKey(SPACE)); |
|
|
|
|
CheckAndPerformAbility(GetAbility3(),game->GetKey(CTRL)); |
|
|
|
|
CheckAndPerformAbility(GetAbility4(),game->GetKey(R)); |
|
|
|
|
CheckAndPerformAbility(GetRightClickAbility(),game->GetMouse(1)); |
|
|
|
|
|
|
|
|
|
if(GetState()==State::PREP_CAST){ |
|
|
|
|
#define CheckAbilityKeyReleasedAndCastSpell(ability,input) \ |
|
|
|
|
if(&ability==castPrepAbility&&input.bReleased){CastSpell(ability);} |
|
|
|
|
|
|
|
|
|
CheckAbilityKeyReleasedAndCastSpell(rightClickAbility,game->GetMouse(1)) |
|
|
|
|
else |
|
|
|
|
CheckAbilityKeyReleasedAndCastSpell(ability,game->GetKey(SHIFT)) |
|
|
|
|
else |
|
|
|
|
CheckAbilityKeyReleasedAndCastSpell(ability2,game->GetKey(SPACE)) |
|
|
|
|
else |
|
|
|
|
CheckAbilityKeyReleasedAndCastSpell(ability3,game->GetKey(CTRL)) |
|
|
|
|
else |
|
|
|
|
CheckAbilityKeyReleasedAndCastSpell(ability4,game->GetKey(R)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
switch(GetState()){ |
|
|
|
@ -481,8 +484,9 @@ std::vector<Buff>Player::GetBuffs(BuffType buff){ |
|
|
|
|
return filteredBuffs; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Player::CastSpell(std::string name,float castTotalTime){ |
|
|
|
|
castInfo={name,castTotalTime,castTotalTime}; |
|
|
|
|
void Player::CastSpell(Ability&ability){ |
|
|
|
|
castInfo={ability.name,ability.precastInfo.castTime,ability.precastInfo.castTime}; |
|
|
|
|
SetState(State::NORMAL); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CastInfo&Player::GetCastInfo(){ |
|
|
|
@ -493,3 +497,8 @@ bool Player::CanPathfindTo(vf2d pos,vf2d targetPos,float range){ |
|
|
|
|
std::vector<vf2d>pathing=game->pathfinder.Solve_AStar(pos,targetPos,8,upperLevel); |
|
|
|
|
return pathing.size()>0&&pathing.size()<8;//We'll say 7 tiles or less is close enough to 650 range. Have a little bit of wiggle room.
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Player::PrepareCast(Ability&ability){ |
|
|
|
|
castPrepAbility=&ability; |
|
|
|
|
SetState(State::PREP_CAST); |
|
|
|
|
} |