diff --git a/src/Character.cpp b/src/Character.cpp index ca3b04b..d082f2e 100644 --- a/src/Character.cpp +++ b/src/Character.cpp @@ -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(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; diff --git a/src/Character.h b/src/Character.h index f7dd281..f05e1de 100644 --- a/src/Character.h +++ b/src/Character.h @@ -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); diff --git a/src/Game.cpp b/src/Game.cpp index b4fee37..136fa06 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -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; } diff --git a/src/Location.cpp b/src/Location.cpp index ed6c34c..1cc4220 100644 --- a/src/Location.cpp +++ b/src/Location.cpp @@ -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;