Improving the battle, fixing bugs

This commit is contained in:
Vladislav Khorev 2026-07-12 18:35:46 +03:00
parent 92929118d5
commit 33c2b313af
4 changed files with 36 additions and 1 deletions

View File

@ -487,6 +487,9 @@ void Character::draw(Renderer& renderer) {
hitSparkEmitter.draw(renderer, 1.0f, Environment::width, Environment::height, false);
}
renderer.RenderUniform1f("uAlpha", 1.0f);
glDisable(GL_BLEND);
if (!state.enabled) return;
if (state.useGpuSkinning) {
@ -609,6 +612,22 @@ bool Character::prepareGpuSkinning() {
return true;
}
void Character::tryAttackCombo()
{
std::cout << "Try Attack Combo" << std::endl;
auto it = animations.find(state.currentState);
if (it == animations.end()) return;
auto& anim = it->second;
if (static_cast<int>(anim.currentFrame) >= 20 &&
(state.currentState == AnimationState::ACTION_ATTACK ||
state.currentState == AnimationState::ACTION_ATTACK_2)) {
std::cout << "Try Attack Combo Success" << std::endl;
anim.currentFrame = anim.model.startingFrame;
}
}
void Character::drawAttachedWeapon(Renderer& renderer) {
if (!state.showWeapon) return;
if (weaponMesh.data.PositionData.size() == 0 || !weaponTexture) return;

View File

@ -65,6 +65,8 @@ public:
// ---- Reset ----
void resetPlayerAfterDeath();
void tryAttackCombo();
// ---- Damage ----
void applyDamage(float damageAmount, const Eigen::Vector3f& attackDirection = Eigen::Vector3f::Zero(), int attackerIndex = CharacterState::kNoTarget);

View File

@ -758,7 +758,9 @@ namespace ZL
((loc->player->state.attackTargetIndex >= 0) &&
(loc->npcs[loc->player->state.attackTargetIndex]->state.hp <= 0)))
&&
loc->player->isMoving() == false) {
loc->player->isMoving() == false
&&
loc->player->getHp() > 0) {
loc->player->state.attackTargetIndex = attackerIndex;
}

View File

@ -1661,6 +1661,8 @@ namespace ZL
return;
}
int lastPlayerAttackTarget = player->state.attackTargetIndex;
player->state.attackTargetIndex = CharacterState::kNoTarget;
// Unproject click to ground plane (y=0) for Viola's walk target
@ -1723,6 +1725,7 @@ namespace ZL
}
else {
//std::cout << "Raycast npc step 1" << std::endl;
// Check if we clicked on an NPC
Character* clickedNpc = raycastNpcs(camPos, rayDir);
if (clickedNpc && player) {
@ -1735,11 +1738,20 @@ namespace ZL
}
}
if (npcIndex != -1) {
//std::cout << "Raycast npc step 2" << std::endl;
state.targetInteractiveObjectIndex = -1;
state.targetTeleportZoneIndex = -1;
if (clickedNpc->state.canAttack) {
//std::cout << "Raycast npc step 3" << std::endl;
//std::cout << "player->state.attackTargetIndex=" << player->state.attackTargetIndex << std::endl;
//std::cout << "npcIndex=" << npcIndex << std::endl;
// Hostile NPC: combat logic walks the player in via attackTargetIndex.
if (lastPlayerAttackTarget == npcIndex)
{
//std::cout << "Raycast npc step 4" << std::endl;
player->tryAttackCombo();
}
player->state.attackTargetIndex = npcIndex;
state.targetInteractNpcIndex = -1;