Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
722e5eb5ed |
No files matched your search
@@ -54,7 +54,7 @@
|
|||||||
"player3",
|
"player3",
|
||||||
"player4"
|
"player4"
|
||||||
],
|
],
|
||||||
"networkCompatibility": "battle-zone-lockstep-v5",
|
"networkCompatibility": "battle-zone-lockstep-v7",
|
||||||
"loadingScreen": "resources/w/ui/screen_loading.json"
|
"loadingScreen": "resources/w/ui/screen_loading.json"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -792,7 +792,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"savedAt": "2026-11-10 20:38",
|
"savedAt": "2026-11-10 20:38",
|
||||||
"schemaVersion": 7,
|
"schemaVersion": 9,
|
||||||
"taxiIsCalled": false,
|
"taxiIsCalled": false,
|
||||||
"tutorialJournalScreenOpened": false,
|
"tutorialJournalScreenOpened": false,
|
||||||
"tutorialNeedOpenTaxiScreen": false,
|
"tutorialNeedOpenTaxiScreen": false,
|
||||||
|
|||||||
@@ -827,6 +827,15 @@
|
|||||||
"animationFrame": 0.0,
|
"animationFrame": 0.0,
|
||||||
"attackTargetId": "",
|
"attackTargetId": "",
|
||||||
"attack_cooldown": 0.0,
|
"attack_cooldown": 0.0,
|
||||||
|
"jumpAttackUnlocked": true,
|
||||||
|
"jumpAttackPending": false,
|
||||||
|
"jumpAttackActive": false,
|
||||||
|
"jumpAttackImpactConsumed": false,
|
||||||
|
"jumpAttackCooldownTicks": 0,
|
||||||
|
"jumpAttackAnimationSubframe": 0,
|
||||||
|
"jumpAttackTargetId": "",
|
||||||
|
"jumpAttackStartPosition": [0.0, 0.0, 0.0],
|
||||||
|
"jumpAttackLandingPosition": [0.0, 0.0, 0.0],
|
||||||
"battle_state": 0,
|
"battle_state": 0,
|
||||||
"attack": 0,
|
"attack": 0,
|
||||||
"resetAnim": false,
|
"resetAnim": false,
|
||||||
@@ -873,6 +882,15 @@
|
|||||||
"animationFrame": 0.0,
|
"animationFrame": 0.0,
|
||||||
"attackTargetId": "",
|
"attackTargetId": "",
|
||||||
"attack_cooldown": 0.0,
|
"attack_cooldown": 0.0,
|
||||||
|
"jumpAttackUnlocked": true,
|
||||||
|
"jumpAttackPending": false,
|
||||||
|
"jumpAttackActive": false,
|
||||||
|
"jumpAttackImpactConsumed": false,
|
||||||
|
"jumpAttackCooldownTicks": 0,
|
||||||
|
"jumpAttackAnimationSubframe": 0,
|
||||||
|
"jumpAttackTargetId": "",
|
||||||
|
"jumpAttackStartPosition": [0.0, 0.0, 0.0],
|
||||||
|
"jumpAttackLandingPosition": [0.0, 0.0, 0.0],
|
||||||
"battle_state": 0,
|
"battle_state": 0,
|
||||||
"attack": 0,
|
"attack": 0,
|
||||||
"resetAnim": false,
|
"resetAnim": false,
|
||||||
@@ -919,6 +937,15 @@
|
|||||||
"animationFrame": 0.0,
|
"animationFrame": 0.0,
|
||||||
"attackTargetId": "",
|
"attackTargetId": "",
|
||||||
"attack_cooldown": 0.0,
|
"attack_cooldown": 0.0,
|
||||||
|
"jumpAttackUnlocked": true,
|
||||||
|
"jumpAttackPending": false,
|
||||||
|
"jumpAttackActive": false,
|
||||||
|
"jumpAttackImpactConsumed": false,
|
||||||
|
"jumpAttackCooldownTicks": 0,
|
||||||
|
"jumpAttackAnimationSubframe": 0,
|
||||||
|
"jumpAttackTargetId": "",
|
||||||
|
"jumpAttackStartPosition": [0.0, 0.0, 0.0],
|
||||||
|
"jumpAttackLandingPosition": [0.0, 0.0, 0.0],
|
||||||
"battle_state": 0,
|
"battle_state": 0,
|
||||||
"attack": 0,
|
"attack": 0,
|
||||||
"resetAnim": false,
|
"resetAnim": false,
|
||||||
@@ -965,6 +992,15 @@
|
|||||||
"animationFrame": 0.0,
|
"animationFrame": 0.0,
|
||||||
"attackTargetId": "",
|
"attackTargetId": "",
|
||||||
"attack_cooldown": 0.0,
|
"attack_cooldown": 0.0,
|
||||||
|
"jumpAttackUnlocked": true,
|
||||||
|
"jumpAttackPending": false,
|
||||||
|
"jumpAttackActive": false,
|
||||||
|
"jumpAttackImpactConsumed": false,
|
||||||
|
"jumpAttackCooldownTicks": 0,
|
||||||
|
"jumpAttackAnimationSubframe": 0,
|
||||||
|
"jumpAttackTargetId": "",
|
||||||
|
"jumpAttackStartPosition": [0.0, 0.0, 0.0],
|
||||||
|
"jumpAttackLandingPosition": [0.0, 0.0, 0.0],
|
||||||
"battle_state": 0,
|
"battle_state": 0,
|
||||||
"attack": 0,
|
"attack": 0,
|
||||||
"resetAnim": false,
|
"resetAnim": false,
|
||||||
@@ -1013,7 +1049,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"savedAt": "2026-11-05 17:43",
|
"savedAt": "2026-11-05 17:43",
|
||||||
"schemaVersion": 7,
|
"schemaVersion": 9,
|
||||||
"taxiIsCalled": false,
|
"taxiIsCalled": false,
|
||||||
"tutorialJournalScreenOpened": false,
|
"tutorialJournalScreenOpened": false,
|
||||||
"tutorialNeedOpenTaxiScreen": false,
|
"tutorialNeedOpenTaxiScreen": false,
|
||||||
|
|||||||
@@ -827,6 +827,15 @@
|
|||||||
"animationFrame": 0.0,
|
"animationFrame": 0.0,
|
||||||
"attackTargetId": "",
|
"attackTargetId": "",
|
||||||
"attack_cooldown": 0.0,
|
"attack_cooldown": 0.0,
|
||||||
|
"jumpAttackUnlocked": true,
|
||||||
|
"jumpAttackPending": false,
|
||||||
|
"jumpAttackActive": false,
|
||||||
|
"jumpAttackImpactConsumed": false,
|
||||||
|
"jumpAttackCooldownTicks": 0,
|
||||||
|
"jumpAttackAnimationSubframe": 0,
|
||||||
|
"jumpAttackTargetId": "",
|
||||||
|
"jumpAttackStartPosition": [0.0, 0.0, 0.0],
|
||||||
|
"jumpAttackLandingPosition": [0.0, 0.0, 0.0],
|
||||||
"battle_state": 0,
|
"battle_state": 0,
|
||||||
"attack": 0,
|
"attack": 0,
|
||||||
"resetAnim": false,
|
"resetAnim": false,
|
||||||
@@ -873,6 +882,15 @@
|
|||||||
"animationFrame": 0.0,
|
"animationFrame": 0.0,
|
||||||
"attackTargetId": "",
|
"attackTargetId": "",
|
||||||
"attack_cooldown": 0.0,
|
"attack_cooldown": 0.0,
|
||||||
|
"jumpAttackUnlocked": true,
|
||||||
|
"jumpAttackPending": false,
|
||||||
|
"jumpAttackActive": false,
|
||||||
|
"jumpAttackImpactConsumed": false,
|
||||||
|
"jumpAttackCooldownTicks": 0,
|
||||||
|
"jumpAttackAnimationSubframe": 0,
|
||||||
|
"jumpAttackTargetId": "",
|
||||||
|
"jumpAttackStartPosition": [0.0, 0.0, 0.0],
|
||||||
|
"jumpAttackLandingPosition": [0.0, 0.0, 0.0],
|
||||||
"battle_state": 0,
|
"battle_state": 0,
|
||||||
"attack": 0,
|
"attack": 0,
|
||||||
"resetAnim": false,
|
"resetAnim": false,
|
||||||
@@ -919,6 +937,15 @@
|
|||||||
"animationFrame": 0.0,
|
"animationFrame": 0.0,
|
||||||
"attackTargetId": "",
|
"attackTargetId": "",
|
||||||
"attack_cooldown": 0.0,
|
"attack_cooldown": 0.0,
|
||||||
|
"jumpAttackUnlocked": true,
|
||||||
|
"jumpAttackPending": false,
|
||||||
|
"jumpAttackActive": false,
|
||||||
|
"jumpAttackImpactConsumed": false,
|
||||||
|
"jumpAttackCooldownTicks": 0,
|
||||||
|
"jumpAttackAnimationSubframe": 0,
|
||||||
|
"jumpAttackTargetId": "",
|
||||||
|
"jumpAttackStartPosition": [0.0, 0.0, 0.0],
|
||||||
|
"jumpAttackLandingPosition": [0.0, 0.0, 0.0],
|
||||||
"battle_state": 0,
|
"battle_state": 0,
|
||||||
"attack": 0,
|
"attack": 0,
|
||||||
"resetAnim": false,
|
"resetAnim": false,
|
||||||
@@ -965,6 +992,15 @@
|
|||||||
"animationFrame": 0.0,
|
"animationFrame": 0.0,
|
||||||
"attackTargetId": "",
|
"attackTargetId": "",
|
||||||
"attack_cooldown": 0.0,
|
"attack_cooldown": 0.0,
|
||||||
|
"jumpAttackUnlocked": true,
|
||||||
|
"jumpAttackPending": false,
|
||||||
|
"jumpAttackActive": false,
|
||||||
|
"jumpAttackImpactConsumed": false,
|
||||||
|
"jumpAttackCooldownTicks": 0,
|
||||||
|
"jumpAttackAnimationSubframe": 0,
|
||||||
|
"jumpAttackTargetId": "",
|
||||||
|
"jumpAttackStartPosition": [0.0, 0.0, 0.0],
|
||||||
|
"jumpAttackLandingPosition": [0.0, 0.0, 0.0],
|
||||||
"battle_state": 0,
|
"battle_state": 0,
|
||||||
"attack": 0,
|
"attack": 0,
|
||||||
"resetAnim": false,
|
"resetAnim": false,
|
||||||
@@ -1013,7 +1049,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"savedAt": "2026-11-05 17:43",
|
"savedAt": "2026-11-05 17:43",
|
||||||
"schemaVersion": 7,
|
"schemaVersion": 9,
|
||||||
"taxiIsCalled": false,
|
"taxiIsCalled": false,
|
||||||
"tutorialJournalScreenOpened": false,
|
"tutorialJournalScreenOpened": false,
|
||||||
"tutorialNeedOpenTaxiScreen": false,
|
"tutorialNeedOpenTaxiScreen": false,
|
||||||
|
|||||||
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
+7
-1
@@ -53,7 +53,9 @@ namespace FRG {
|
|||||||
{
|
{
|
||||||
if (value.is_string()) {
|
if (value.is_string()) {
|
||||||
const std::string path = value.get<std::string>();
|
const std::string path = value.get<std::string>();
|
||||||
if (hasExtension(path, ".anim")) animationPaths.insert(path);
|
if (hasExtension(path, ".anim") ||
|
||||||
|
hasExtension(path, ".txt.bin"))
|
||||||
|
animationPaths.insert(path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (value.is_array()) {
|
if (value.is_array()) {
|
||||||
@@ -245,6 +247,10 @@ namespace FRG {
|
|||||||
std::uint64_t hash = 1469598103934665603ull;
|
std::uint64_t hash = 1469598103934665603ull;
|
||||||
hashString(hash, manifest.dump());
|
hashString(hash, manifest.dump());
|
||||||
std::set<std::string> animationPaths;
|
std::set<std::string> animationPaths;
|
||||||
|
animationPaths.insert(
|
||||||
|
"resources/w/gg/new3/gg_attack_jump001_small.txt.bin");
|
||||||
|
animationPaths.insert(
|
||||||
|
"resources/w/gg/new3/gg_attack2_single_001_small.txt.bin");
|
||||||
for (const std::string& path : resourcePaths) {
|
for (const std::string& path : resourcePaths) {
|
||||||
const std::vector<char> bytes =
|
const std::vector<char> bytes =
|
||||||
readCompatibilityResource(path, zipFile);
|
readCompatibilityResource(path, zipFile);
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
namespace FRG {
|
namespace FRG {
|
||||||
|
|
||||||
inline constexpr int kDeterministicSimulationVersion = 1;
|
inline constexpr int kDeterministicSimulationVersion = 3;
|
||||||
|
|
||||||
// One location of a campaign, loaded from resources/config/locations/<name>.json.
|
// One location of a campaign, loaded from resources/config/locations/<name>.json.
|
||||||
// Optional paths may be left empty; Location::setup skips them.
|
// Optional paths may be left empty; Location::setup skips them.
|
||||||
|
|||||||
+38
-1
@@ -79,7 +79,8 @@ std::unique_ptr<Character> Character::createFromState(const CharacterState& st,
|
|||||||
auto loadAnim = [&](AnimationState animState, const std::string& path) {
|
auto loadAnim = [&](AnimationState animState, const std::string& path) {
|
||||||
if (path.empty()) return;
|
if (path.empty()) return;
|
||||||
try {
|
try {
|
||||||
if (path.size() >= 5 && path.substr(path.size() - 5) == ".anim")
|
if ((path.size() >= 5 && path.substr(path.size() - 5) == ".anim") ||
|
||||||
|
(path.size() >= 4 && path.substr(path.size() - 4) == ".bin"))
|
||||||
c->loadBinaryAnimation(animState, path, zip);
|
c->loadBinaryAnimation(animState, path, zip);
|
||||||
else
|
else
|
||||||
c->loadAnimation(animState, path, zip);
|
c->loadAnimation(animState, path, zip);
|
||||||
@@ -189,6 +190,16 @@ void Character::update(int64_t deltaMs, const CharacterUpdateEvents* events) {
|
|||||||
if (hitSparkEmitter.isConfigured()) {
|
if (hitSparkEmitter.isConfigured()) {
|
||||||
hitSparkEmitter.update(static_cast<float>(deltaMs));
|
hitSparkEmitter.update(static_cast<float>(deltaMs));
|
||||||
}
|
}
|
||||||
|
if (jumpAttackBounceActive_) {
|
||||||
|
if (jumpAttackBounceFresh_)
|
||||||
|
jumpAttackBounceFresh_ = false;
|
||||||
|
else
|
||||||
|
jumpAttackBounceElapsedMs_ += static_cast<float>(deltaMs);
|
||||||
|
if (jumpAttackBounceElapsedMs_ >= 220.f) {
|
||||||
|
jumpAttackBounceElapsedMs_ = 0.f;
|
||||||
|
jumpAttackBounceActive_ = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto stateSnapshot = this->stateSnapshot();
|
auto stateSnapshot = this->stateSnapshot();
|
||||||
if (!stateSnapshot) return;
|
if (!stateSnapshot) return;
|
||||||
@@ -311,6 +322,12 @@ bool Character::prepareForDraw(CharacterState& state) {
|
|||||||
if (!snapshot) return false;
|
if (!snapshot) return false;
|
||||||
state = interpolatedState(*snapshot);
|
state = interpolatedState(*snapshot);
|
||||||
if (!state.enabled) return false;
|
if (!state.enabled) return false;
|
||||||
|
if (jumpAttackBounceActive_) {
|
||||||
|
const float phase =
|
||||||
|
(std::min)(1.f, jumpAttackBounceElapsedMs_ / 220.f);
|
||||||
|
state.position.y += static_cast<fp>(
|
||||||
|
std::sin(phase * 3.14159265358979323846f) * 0.08f);
|
||||||
|
}
|
||||||
updateAnimationForRender(state);
|
updateAnimationForRender(state);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -384,6 +401,20 @@ void Character::drawAttachedWeapon(Renderer& renderer, const CharacterState& sta
|
|||||||
renderer.RotateMatrix(Eigen::Matrix3f(currentBone.block<3, 3>(0, 0)));
|
renderer.RotateMatrix(Eigen::Matrix3f(currentBone.block<3, 3>(0, 0)));
|
||||||
renderer.TranslateMatrix(weaponInitialPosition);
|
renderer.TranslateMatrix(weaponInitialPosition);
|
||||||
renderer.RotateMatrix(weaponInitialRotation);
|
renderer.RotateMatrix(weaponInitialRotation);
|
||||||
|
if (state.currentState == AnimationState::ACTION_ATTACK_POWER &&
|
||||||
|
state.animationFrame >= 27.f && state.animationFrame <= 55.f) {
|
||||||
|
const float progress =
|
||||||
|
(state.animationFrame - 27.f) / (55.f - 27.f);
|
||||||
|
const float eased =
|
||||||
|
progress * progress * (3.f - 2.f * progress);
|
||||||
|
// Four reverse turns over the same frame window: 20% slower than the
|
||||||
|
// original five-turn effect while returning to the bound hand pose.
|
||||||
|
//constexpr float kReverseFourTurns = -4.f * 2.f * 3.14159265358979323846f;
|
||||||
|
constexpr float k = 1.f * 2.f * 3.14159265358979323846f;
|
||||||
|
renderer.RotateMatrix(Eigen::AngleAxisf(
|
||||||
|
eased * k,
|
||||||
|
Eigen::Vector3f::UnitZ()).toRotationMatrix());
|
||||||
|
}
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, weaponTexture->getTexID());
|
glBindTexture(GL_TEXTURE_2D, weaponTexture->getTexID());
|
||||||
renderer.DrawVertexRenderStruct(weaponMesh);
|
renderer.DrawVertexRenderStruct(weaponMesh);
|
||||||
@@ -639,6 +670,12 @@ void Character::presentDamage(float hp, float maxHp,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Character::presentJumpAttackBounce() {
|
||||||
|
jumpAttackBounceElapsedMs_ = 0.f;
|
||||||
|
jumpAttackBounceActive_ = true;
|
||||||
|
jumpAttackBounceFresh_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
void Character::prepareHitSparksForDraw(const Eigen::Matrix4f& cameraViewMatrix) {
|
void Character::prepareHitSparksForDraw(const Eigen::Matrix4f& cameraViewMatrix) {
|
||||||
if (!hitSparkEmitter.isConfigured()) return;
|
if (!hitSparkEmitter.isConfigured()) return;
|
||||||
hitSparkEmitter.prepareForDraw(cameraViewMatrix);
|
hitSparkEmitter.prepareForDraw(cameraViewMatrix);
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ public:
|
|||||||
// ---- Damage ----
|
// ---- Damage ----
|
||||||
void presentDamage(float hp, float maxHp, const Vec3fp& attackDirection,
|
void presentDamage(float hp, float maxHp, const Vec3fp& attackDirection,
|
||||||
const std::string& attackerId);
|
const std::string& attackerId);
|
||||||
|
void presentJumpAttackBounce();
|
||||||
|
|
||||||
// ---- Spark setup ----
|
// ---- Spark setup ----
|
||||||
void setupHitSparks(std::shared_ptr<Texture> sparkTexture);
|
void setupHitSparks(std::shared_ptr<Texture> sparkTexture);
|
||||||
@@ -131,6 +132,9 @@ private:
|
|||||||
PresentationSample currentPresentationSample_;
|
PresentationSample currentPresentationSample_;
|
||||||
std::chrono::steady_clock::time_point lastPresentationUpdate_;
|
std::chrono::steady_clock::time_point lastPresentationUpdate_;
|
||||||
bool hasPresentationSample_ = false;
|
bool hasPresentationSample_ = false;
|
||||||
|
float jumpAttackBounceElapsedMs_ = 0.f;
|
||||||
|
bool jumpAttackBounceActive_ = false;
|
||||||
|
bool jumpAttackBounceFresh_ = false;
|
||||||
|
|
||||||
AnimationState resolveActiveState(const CharacterState& state) const;
|
AnimationState resolveActiveState(const CharacterState& state) const;
|
||||||
CharacterState interpolatedState(const CharacterState& state) const;
|
CharacterState interpolatedState(const CharacterState& state) const;
|
||||||
|
|||||||
+250
-21
@@ -10,6 +10,14 @@ namespace {
|
|||||||
constexpr float kPi = 3.14159265358979323846f;
|
constexpr float kPi = 3.14159265358979323846f;
|
||||||
// Tick counts are authoritative and therefore independent of render rate.
|
// Tick counts are authoritative and therefore independent of render rate.
|
||||||
constexpr float ATTACK_COOLDOWN_TIME = 1.6f;
|
constexpr float ATTACK_COOLDOWN_TIME = 1.6f;
|
||||||
|
constexpr int JUMP_ATTACK_COOLDOWN_TICKS = 50;
|
||||||
|
constexpr int JUMP_ATTACK_TAKEOFF_SUBFRAME = 8 * 1000;
|
||||||
|
constexpr int JUMP_ATTACK_IMPACT_SUBFRAME = 21 * 1000;
|
||||||
|
constexpr int ANIMATION_SUBFRAMES_PER_FRAME = 1000;
|
||||||
|
constexpr int JUMP_ATTACK_FRAME_COUNT = 80;
|
||||||
|
constexpr int JUMP_ATTACK_DURATION_MS = 2000;
|
||||||
|
constexpr int POWER_ATTACK_COOLDOWN_TICKS = 5;//100;
|
||||||
|
constexpr int POWER_ATTACK_IMPACT_FRAME = 19;
|
||||||
constexpr float HOME_DRIFT_CHECK_INTERVAL = 5.0f;
|
constexpr float HOME_DRIFT_CHECK_INTERVAL = 5.0f;
|
||||||
const fp HOME_DRIFT_CHECK_INTERVAL_FP = static_cast<fp>(HOME_DRIFT_CHECK_INTERVAL);
|
const fp HOME_DRIFT_CHECK_INTERVAL_FP = static_cast<fp>(HOME_DRIFT_CHECK_INTERVAL);
|
||||||
// An NPC farther than this from its home position (squared) walks back.
|
// An NPC farther than this from its home position (squared) walks back.
|
||||||
@@ -181,6 +189,16 @@ void CharacterState::stopAndRotateToTarget(std::string characterId)
|
|||||||
faceTargetId = std::move(characterId);
|
faceTargetId = std::move(characterId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CharacterState::leaveBattleState()
|
||||||
|
{
|
||||||
|
battle_state = 0;
|
||||||
|
attack = 0;
|
||||||
|
attackTargetId.clear();
|
||||||
|
cancelPendingJumpAttack();
|
||||||
|
powerAttackPending = false;
|
||||||
|
powerAttackTargetId.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void CharacterState::resetPlayerAfterDeath()
|
void CharacterState::resetPlayerAfterDeath()
|
||||||
{
|
{
|
||||||
if (!isPlayer) return;
|
if (!isPlayer) return;
|
||||||
@@ -189,18 +207,66 @@ void CharacterState::resetPlayerAfterDeath()
|
|||||||
showWeapon = false;
|
showWeapon = false;
|
||||||
battle_state = 0;
|
battle_state = 0;
|
||||||
attack = 0;
|
attack = 0;
|
||||||
|
jumpAttackPending = false;
|
||||||
|
jumpAttackActive = false;
|
||||||
|
jumpAttackImpactConsumed = false;
|
||||||
|
jumpAttackAnimationSubframe = 0;
|
||||||
|
jumpAttackTargetId.clear();
|
||||||
|
powerAttackPending = false;
|
||||||
|
powerAttackTargetId.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharacterState::tryAttackCombo()
|
bool CharacterState::tryPowerAttack(const std::string& targetId)
|
||||||
{
|
{
|
||||||
if (static_cast<int>(animationFrame) < 20 ||
|
if (!isPlayer || hp <= 0.f || targetId.empty() ||
|
||||||
(currentState != AnimationState::ACTION_ATTACK &&
|
powerAttackCooldownTicks > 0 || powerAttackPending ||
|
||||||
currentState != AnimationState::ACTION_ATTACK_2)) {
|
jumpAttackActive ||
|
||||||
return;
|
currentState == AnimationState::ACTION_ATTACK_POWER) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
const auto index = static_cast<std::size_t>(currentState);
|
powerAttackPending = true;
|
||||||
animationFrame = index < animationStartFrames.size()
|
powerAttackTargetId = targetId;
|
||||||
? static_cast<float>(animationStartFrames[index]) : 0.f;
|
cancelPendingJumpAttack();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CharacterState::reserveJumpAttack(const std::string& targetId)
|
||||||
|
{
|
||||||
|
if (!isPlayer || !jumpAttackUnlocked || jumpAttackCooldownTicks > 0 ||
|
||||||
|
jumpAttackPending || jumpAttackActive || powerAttackPending ||
|
||||||
|
hp <= 0.f ||
|
||||||
|
battle_state != 0 ||
|
||||||
|
(currentState != AnimationState::STAND &&
|
||||||
|
currentState != AnimationState::WALK) ||
|
||||||
|
targetId.empty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
jumpAttackPending = true;
|
||||||
|
jumpAttackTargetId = targetId;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CharacterState::cancelPendingJumpAttack()
|
||||||
|
{
|
||||||
|
jumpAttackPending = false;
|
||||||
|
if (!jumpAttackActive) jumpAttackTargetId.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CharacterState::beginJumpAttack(const Vec3fp& landingPosition)
|
||||||
|
{
|
||||||
|
jumpAttackPending = false;
|
||||||
|
jumpAttackActive = true;
|
||||||
|
jumpAttackImpactConsumed = false;
|
||||||
|
jumpAttackCooldownTicks = JUMP_ATTACK_COOLDOWN_TICKS;
|
||||||
|
jumpAttackAnimationSubframe = 0;
|
||||||
|
jumpAttackStartPosition = position;
|
||||||
|
jumpAttackLandingPosition = landingPosition;
|
||||||
|
currentState = AnimationState::ACTION_ATTACK_JUMP;
|
||||||
|
animationFrame = 0.f;
|
||||||
|
resetAnim = false;
|
||||||
|
attack = 0;
|
||||||
|
battle_state = 1;
|
||||||
|
stopInPlace();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharacterState::setHp(float newHp) {
|
void CharacterState::setHp(float newHp) {
|
||||||
@@ -223,17 +289,39 @@ CharacterUpdateEvents CharacterState::update(
|
|||||||
{
|
{
|
||||||
CharacterUpdateEvents events;
|
CharacterUpdateEvents events;
|
||||||
if (!enabled) return events;
|
if (!enabled) return events;
|
||||||
|
if (jumpAttackCooldownTicks > 0) --jumpAttackCooldownTicks;
|
||||||
|
if (powerAttackCooldownTicks > 0) --powerAttackCooldownTicks;
|
||||||
|
if (hp <= 0.f && jumpAttackActive) {
|
||||||
|
jumpAttackActive = false;
|
||||||
|
jumpAttackImpactConsumed = false;
|
||||||
|
jumpAttackAnimationSubframe = 0;
|
||||||
|
jumpAttackTargetId.clear();
|
||||||
|
}
|
||||||
|
|
||||||
const CharacterObservation* attackTarget = context.attackTarget;
|
const CharacterObservation* attackTarget = context.attackTarget;
|
||||||
const CharacterObservation* faceTarget = context.faceTarget;
|
const CharacterObservation* faceTarget = context.faceTarget;
|
||||||
if (!attackTarget || attackTarget->hp <= 0.f) {
|
if (jumpAttackActive) {
|
||||||
battle_state = 0;
|
battle_state = 1;
|
||||||
|
attack = 0;
|
||||||
|
} else if (!attackTarget || attackTarget->hp <= 0.f) {
|
||||||
|
// A victorious player keeps the weapon drawn and finishes the current
|
||||||
|
// attack animation. Only an explicit movement/clear command leaves
|
||||||
|
// battle state. NPCs retain their autonomous disengage behavior.
|
||||||
|
if (!isPlayer) battle_state = 0;
|
||||||
attack = 0;
|
attack = 0;
|
||||||
attackTargetId.clear();
|
attackTargetId.clear();
|
||||||
|
cancelPendingJumpAttack();
|
||||||
|
powerAttackPending = false;
|
||||||
|
powerAttackTargetId.clear();
|
||||||
} else {
|
} else {
|
||||||
const fp distanceSquared = (attackTarget->position - position).normSquared();
|
const fp distanceSquared = (attackTarget->position - position).normSquared();
|
||||||
if (distanceSquared >= visibleRange * visibleRange ||
|
const fp combatRange = static_cast<fp>(
|
||||||
distanceSquared >= static_cast<fp>(kAttackRange * kAttackRange)) {
|
jumpAttackPending ? kJumpAttackRange : kAttackRange);
|
||||||
|
const bool outOfCombatRange = jumpAttackPending
|
||||||
|
? distanceSquared > combatRange * combatRange
|
||||||
|
: distanceSquared >= visibleRange * visibleRange ||
|
||||||
|
distanceSquared >= combatRange * combatRange;
|
||||||
|
if (outOfCombatRange) {
|
||||||
// Out of attack range: chase the target.
|
// Out of attack range: chase the target.
|
||||||
if ((attackTarget->position - requestedWalkTarget).normSquared() >
|
if ((attackTarget->position - requestedWalkTarget).normSquared() >
|
||||||
TARGET_REPLAN_THRESHOLD_SQUARED) {
|
TARGET_REPLAN_THRESHOLD_SQUARED) {
|
||||||
@@ -350,7 +438,7 @@ CharacterUpdateEvents CharacterState::update(
|
|||||||
attackTargetId.clear();
|
attackTargetId.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (battle_state == 1 && attackTarget) {
|
else if (battle_state == 1 && attackTarget && !jumpAttackActive) {
|
||||||
targetFacingAngle = fpm::atan2(
|
targetFacingAngle = fpm::atan2(
|
||||||
attackTarget->position.x - position.x, -(attackTarget->position.z - position.z));
|
attackTarget->position.x - position.x, -(attackTarget->position.z - position.z));
|
||||||
|
|
||||||
@@ -358,21 +446,35 @@ CharacterUpdateEvents CharacterState::update(
|
|||||||
currentState = AnimationState::STAND_TO_ACTION;
|
currentState = AnimationState::STAND_TO_ACTION;
|
||||||
resetAnim = true;
|
resetAnim = true;
|
||||||
}
|
}
|
||||||
if (canAttack && attack == 0 && attack_cooldown < 0.f &&
|
if (powerAttackPending &&
|
||||||
|
powerAttackTargetId == attackTargetId &&
|
||||||
|
currentState == AnimationState::ACTION_IDLE) {
|
||||||
|
powerAttackPending = false;
|
||||||
|
powerAttackCooldownTicks = POWER_ATTACK_COOLDOWN_TICKS;
|
||||||
|
currentState = AnimationState::ACTION_ATTACK_POWER;
|
||||||
|
resetAnim = true;
|
||||||
|
attack = 0;
|
||||||
|
}
|
||||||
|
if (canAttack && !powerAttackPending &&
|
||||||
|
currentState != AnimationState::ACTION_ATTACK_POWER &&
|
||||||
|
attack == 0 && attack_cooldown < 0.f &&
|
||||||
currentState == AnimationState::ACTION_IDLE) {
|
currentState == AnimationState::ACTION_IDLE) {
|
||||||
attack = 1;
|
attack = 1;
|
||||||
attack_cooldown = ATTACK_COOLDOWN_TIME;
|
attack_cooldown = ATTACK_COOLDOWN_TIME;
|
||||||
}
|
}
|
||||||
if (canAttack && attack_cooldown >= 0.f)
|
if (canAttack && attack_cooldown >= 0.f)
|
||||||
attack_cooldown -= static_cast<float>(deltaMs) / 1000.f;
|
attack_cooldown -= static_cast<float>(deltaMs) / 1000.f;
|
||||||
if (attack == 1 && currentState == AnimationState::ACTION_IDLE &&
|
if (attack == 1 && !powerAttackPending &&
|
||||||
|
currentState == AnimationState::ACTION_IDLE &&
|
||||||
attackTarget->hp > 0.f) {
|
attackTarget->hp > 0.f) {
|
||||||
currentState = AnimationState::ACTION_ATTACK;
|
currentState = AnimationState::ACTION_ATTACK;
|
||||||
resetAnim = true;
|
resetAnim = true;
|
||||||
}
|
}
|
||||||
} else if (currentState == AnimationState::STAND_TO_ACTION ||
|
} else if (!jumpAttackActive && battle_state == 0 &&
|
||||||
|
(currentState == AnimationState::STAND_TO_ACTION ||
|
||||||
currentState == AnimationState::ACTION_IDLE ||
|
currentState == AnimationState::ACTION_IDLE ||
|
||||||
currentState == AnimationState::ACTION_ATTACK) {
|
currentState == AnimationState::ACTION_ATTACK ||
|
||||||
|
currentState == AnimationState::ACTION_ATTACK_POWER)) {
|
||||||
currentState = AnimationState::ACTION_TO_STAND;
|
currentState = AnimationState::ACTION_TO_STAND;
|
||||||
resetAnim = true;
|
resetAnim = true;
|
||||||
}
|
}
|
||||||
@@ -402,6 +504,71 @@ CharacterUpdateEvents CharacterState::update(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (jumpAttackActive) {
|
||||||
|
const int previousSubframe = jumpAttackAnimationSubframe;
|
||||||
|
jumpAttackAnimationSubframe += static_cast<int>(
|
||||||
|
deltaMs * JUMP_ATTACK_FRAME_COUNT *
|
||||||
|
ANIMATION_SUBFRAMES_PER_FRAME / JUMP_ATTACK_DURATION_MS);
|
||||||
|
animationFrame =
|
||||||
|
static_cast<float>(jumpAttackAnimationSubframe) /
|
||||||
|
static_cast<float>(ANIMATION_SUBFRAMES_PER_FRAME);
|
||||||
|
|
||||||
|
if (jumpAttackAnimationSubframe > JUMP_ATTACK_TAKEOFF_SUBFRAME) {
|
||||||
|
const int travelSubframes =
|
||||||
|
JUMP_ATTACK_IMPACT_SUBFRAME - JUMP_ATTACK_TAKEOFF_SUBFRAME;
|
||||||
|
const int elapsed = (std::min)(
|
||||||
|
travelSubframes,
|
||||||
|
jumpAttackAnimationSubframe - JUMP_ATTACK_TAKEOFF_SUBFRAME);
|
||||||
|
const fp progress = static_cast<fp>(elapsed) /
|
||||||
|
static_cast<fp>(travelSubframes);
|
||||||
|
position = jumpAttackStartPosition +
|
||||||
|
(jumpAttackLandingPosition - jumpAttackStartPosition) * progress;
|
||||||
|
position.y = jumpAttackLandingPosition.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!jumpAttackImpactConsumed &&
|
||||||
|
previousSubframe < JUMP_ATTACK_IMPACT_SUBFRAME &&
|
||||||
|
jumpAttackAnimationSubframe >= JUMP_ATTACK_IMPACT_SUBFRAME) {
|
||||||
|
position = jumpAttackLandingPosition;
|
||||||
|
jumpAttackImpactConsumed = true;
|
||||||
|
events.attackImpact = true;
|
||||||
|
events.jumpAttackImpact = true;
|
||||||
|
events.attackDamage = 20.f;
|
||||||
|
events.attackTargetId = jumpAttackTargetId;
|
||||||
|
if (attackTarget) {
|
||||||
|
events.attackDirection = attackTarget->position - position;
|
||||||
|
events.attackDirection.y = fp(0);
|
||||||
|
const fp lengthSquared = events.attackDirection.normSquared();
|
||||||
|
if (lengthSquared > static_cast<fp>(0.001f))
|
||||||
|
events.attackDirection =
|
||||||
|
events.attackDirection / fpm::sqrt(lengthSquared);
|
||||||
|
else
|
||||||
|
events.attackDirection = Vec3fp{};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto jumpIndex =
|
||||||
|
static_cast<std::size_t>(AnimationState::ACTION_ATTACK_JUMP);
|
||||||
|
const int jumpFrameCount = jumpIndex < animationFrameCounts.size()
|
||||||
|
? animationFrameCounts[jumpIndex] : 80;
|
||||||
|
if (jumpAttackAnimationSubframe >=
|
||||||
|
((std::max)(1, jumpFrameCount) - 1) *
|
||||||
|
ANIMATION_SUBFRAMES_PER_FRAME) {
|
||||||
|
position = jumpAttackLandingPosition;
|
||||||
|
jumpAttackActive = false;
|
||||||
|
jumpAttackImpactConsumed = false;
|
||||||
|
jumpAttackAnimationSubframe = 0;
|
||||||
|
jumpAttackTargetId.clear();
|
||||||
|
currentState = AnimationState::ACTION_IDLE;
|
||||||
|
const auto idleIndex =
|
||||||
|
static_cast<std::size_t>(AnimationState::ACTION_IDLE);
|
||||||
|
animationFrame = idleIndex < animationStartFrames.size()
|
||||||
|
? static_cast<float>(animationStartFrames[idleIndex]) : 0.f;
|
||||||
|
}
|
||||||
|
showWeapon = true;
|
||||||
|
return events;
|
||||||
|
}
|
||||||
|
|
||||||
if (resetAnim) {
|
if (resetAnim) {
|
||||||
resetAnim = false;
|
resetAnim = false;
|
||||||
const auto index = static_cast<std::size_t>(currentState);
|
const auto index = static_cast<std::size_t>(currentState);
|
||||||
@@ -416,10 +583,10 @@ CharacterUpdateEvents CharacterState::update(
|
|||||||
animationFrame += static_cast<float>(deltaMs) / 24.f * playbackRate;
|
animationFrame += static_cast<float>(deltaMs) / 24.f * playbackRate;
|
||||||
|
|
||||||
if (previousFrame < 19 && static_cast<int>(animationFrame) >= 19 &&
|
if (previousFrame < 19 && static_cast<int>(animationFrame) >= 19 &&
|
||||||
(currentState == AnimationState::ACTION_ATTACK ||
|
currentState == AnimationState::ACTION_ATTACK &&
|
||||||
currentState == AnimationState::ACTION_ATTACK_2) &&
|
|
||||||
attackTarget) {
|
attackTarget) {
|
||||||
events.attackImpact = true;
|
events.attackImpact = true;
|
||||||
|
events.attackDamage = 10.f;
|
||||||
events.attackTargetId = attackTargetId;
|
events.attackTargetId = attackTargetId;
|
||||||
events.attackDirection = attackTarget->position - position;
|
events.attackDirection = attackTarget->position - position;
|
||||||
events.attackDirection.y = static_cast<fp>(0.f);
|
events.attackDirection.y = static_cast<fp>(0.f);
|
||||||
@@ -436,11 +603,29 @@ CharacterUpdateEvents CharacterState::update(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (previousFrame < POWER_ATTACK_IMPACT_FRAME &&
|
||||||
|
static_cast<int>(animationFrame) >= POWER_ATTACK_IMPACT_FRAME &&
|
||||||
|
currentState == AnimationState::ACTION_ATTACK_POWER &&
|
||||||
|
attackTarget) {
|
||||||
|
events.attackImpact = true;
|
||||||
|
events.powerAttackImpact = true;
|
||||||
|
events.attackDamage = 30.f;
|
||||||
|
events.attackTargetId = attackTargetId;
|
||||||
|
events.attackDirection = attackTarget->position - position;
|
||||||
|
events.attackDirection.y = fp(0);
|
||||||
|
const fp lengthSquared = events.attackDirection.normSquared();
|
||||||
|
if (lengthSquared > static_cast<fp>(0.001f))
|
||||||
|
events.attackDirection =
|
||||||
|
events.attackDirection / fpm::sqrt(lengthSquared);
|
||||||
|
else
|
||||||
|
events.attackDirection = Vec3fp{};
|
||||||
|
}
|
||||||
|
|
||||||
showWeapon =
|
showWeapon =
|
||||||
(static_cast<int>(animationFrame) >= 20 && currentState == AnimationState::STAND_TO_ACTION) ||
|
(static_cast<int>(animationFrame) >= 20 && currentState == AnimationState::STAND_TO_ACTION) ||
|
||||||
(static_cast<int>(animationFrame) <= 32 && currentState == AnimationState::ACTION_TO_STAND) ||
|
(static_cast<int>(animationFrame) <= 32 && currentState == AnimationState::ACTION_TO_STAND) ||
|
||||||
currentState == AnimationState::ACTION_ATTACK_2 ||
|
|
||||||
currentState == AnimationState::ACTION_ATTACK ||
|
currentState == AnimationState::ACTION_ATTACK ||
|
||||||
|
currentState == AnimationState::ACTION_ATTACK_POWER ||
|
||||||
currentState == AnimationState::ACTION_IDLE;
|
currentState == AnimationState::ACTION_IDLE;
|
||||||
|
|
||||||
const int frameCount = animationIndex < animationFrameCounts.size()
|
const int frameCount = animationIndex < animationFrameCounts.size()
|
||||||
@@ -451,7 +636,7 @@ CharacterUpdateEvents CharacterState::update(
|
|||||||
else if (currentState == AnimationState::ACTION_TO_STAND)
|
else if (currentState == AnimationState::ACTION_TO_STAND)
|
||||||
currentState = AnimationState::STAND;
|
currentState = AnimationState::STAND;
|
||||||
else if (currentState == AnimationState::ACTION_ATTACK ||
|
else if (currentState == AnimationState::ACTION_ATTACK ||
|
||||||
currentState == AnimationState::ACTION_ATTACK_2) {
|
currentState == AnimationState::ACTION_ATTACK_POWER) {
|
||||||
currentState = AnimationState::ACTION_IDLE;
|
currentState = AnimationState::ACTION_IDLE;
|
||||||
attack = 0;
|
attack = 0;
|
||||||
} else if (currentState == AnimationState::ACTION_TO_DEATH) {
|
} else if (currentState == AnimationState::ACTION_TO_DEATH) {
|
||||||
@@ -478,6 +663,24 @@ void CharacterState::save(nlohmann::json& out) const
|
|||||||
out["resetAnim"] = resetAnim;
|
out["resetAnim"] = resetAnim;
|
||||||
out["currentState"] = static_cast<int>(currentState);
|
out["currentState"] = static_cast<int>(currentState);
|
||||||
out["attack_cooldown"] = attack_cooldown;
|
out["attack_cooldown"] = attack_cooldown;
|
||||||
|
out["jumpAttackUnlocked"] = jumpAttackUnlocked;
|
||||||
|
out["jumpAttackPending"] = jumpAttackPending;
|
||||||
|
out["jumpAttackActive"] = jumpAttackActive;
|
||||||
|
out["jumpAttackImpactConsumed"] = jumpAttackImpactConsumed;
|
||||||
|
out["jumpAttackCooldownTicks"] = jumpAttackCooldownTicks;
|
||||||
|
out["jumpAttackAnimationSubframe"] = jumpAttackAnimationSubframe;
|
||||||
|
out["jumpAttackTargetId"] = jumpAttackTargetId;
|
||||||
|
out["jumpAttackStartPosition"] = {
|
||||||
|
static_cast<double>(jumpAttackStartPosition.x),
|
||||||
|
static_cast<double>(jumpAttackStartPosition.y),
|
||||||
|
static_cast<double>(jumpAttackStartPosition.z) };
|
||||||
|
out["jumpAttackLandingPosition"] = {
|
||||||
|
static_cast<double>(jumpAttackLandingPosition.x),
|
||||||
|
static_cast<double>(jumpAttackLandingPosition.y),
|
||||||
|
static_cast<double>(jumpAttackLandingPosition.z) };
|
||||||
|
out["powerAttackPending"] = powerAttackPending;
|
||||||
|
out["powerAttackCooldownTicks"] = powerAttackCooldownTicks;
|
||||||
|
out["powerAttackTargetId"] = powerAttackTargetId;
|
||||||
out["showWeapon"] = showWeapon;
|
out["showWeapon"] = showWeapon;
|
||||||
out["attackTargetId"] = attackTargetId;
|
out["attackTargetId"] = attackTargetId;
|
||||||
out["faceTargetId"] = faceTargetId;
|
out["faceTargetId"] = faceTargetId;
|
||||||
@@ -527,6 +730,32 @@ void CharacterState::load(const nlohmann::json& in)
|
|||||||
resetAnim = in.at("resetAnim").get<bool>();
|
resetAnim = in.at("resetAnim").get<bool>();
|
||||||
currentState = static_cast<AnimationState>(in.value("currentState", static_cast<int>(currentState)));
|
currentState = static_cast<AnimationState>(in.value("currentState", static_cast<int>(currentState)));
|
||||||
attack_cooldown = in.value("attack_cooldown", attack_cooldown);
|
attack_cooldown = in.value("attack_cooldown", attack_cooldown);
|
||||||
|
jumpAttackUnlocked =
|
||||||
|
in.value("jumpAttackUnlocked", jumpAttackUnlocked);
|
||||||
|
jumpAttackPending =
|
||||||
|
in.value("jumpAttackPending", jumpAttackPending);
|
||||||
|
jumpAttackActive =
|
||||||
|
in.value("jumpAttackActive", jumpAttackActive);
|
||||||
|
jumpAttackImpactConsumed =
|
||||||
|
in.value("jumpAttackImpactConsumed", jumpAttackImpactConsumed);
|
||||||
|
jumpAttackCooldownTicks =
|
||||||
|
in.value("jumpAttackCooldownTicks", jumpAttackCooldownTicks);
|
||||||
|
jumpAttackAnimationSubframe =
|
||||||
|
in.value("jumpAttackAnimationSubframe", jumpAttackAnimationSubframe);
|
||||||
|
jumpAttackTargetId =
|
||||||
|
in.value("jumpAttackTargetId", jumpAttackTargetId);
|
||||||
|
if (in.contains("jumpAttackStartPosition"))
|
||||||
|
jumpAttackStartPosition = readVec3fp(
|
||||||
|
in["jumpAttackStartPosition"], jumpAttackStartPosition);
|
||||||
|
if (in.contains("jumpAttackLandingPosition"))
|
||||||
|
jumpAttackLandingPosition = readVec3fp(
|
||||||
|
in["jumpAttackLandingPosition"], jumpAttackLandingPosition);
|
||||||
|
powerAttackPending =
|
||||||
|
in.value("powerAttackPending", powerAttackPending);
|
||||||
|
powerAttackCooldownTicks =
|
||||||
|
in.value("powerAttackCooldownTicks", powerAttackCooldownTicks);
|
||||||
|
powerAttackTargetId =
|
||||||
|
in.value("powerAttackTargetId", powerAttackTargetId);
|
||||||
showWeapon = in.value("showWeapon", showWeapon);
|
showWeapon = in.value("showWeapon", showWeapon);
|
||||||
attackTargetId = in.value("attackTargetId", attackTargetId);
|
attackTargetId = in.value("attackTargetId", attackTargetId);
|
||||||
faceTargetId = in.value("faceTargetId", faceTargetId);
|
faceTargetId = in.value("faceTargetId", faceTargetId);
|
||||||
|
|||||||
+35
-10
@@ -16,6 +16,7 @@ namespace FRG {
|
|||||||
constexpr float VISIBLE_RANGE = 6.f;
|
constexpr float VISIBLE_RANGE = 6.f;
|
||||||
// Distance at which a character starts attacking its target.
|
// Distance at which a character starts attacking its target.
|
||||||
constexpr float kAttackRange = 1.25f;
|
constexpr float kAttackRange = 1.25f;
|
||||||
|
constexpr float kJumpAttackRange = 5.0f;
|
||||||
// How close the player must be to a peaceful NPC to start a conversation.
|
// How close the player must be to a peaceful NPC to start a conversation.
|
||||||
constexpr float kNpcTalkDistance = 1.35f;
|
constexpr float kNpcTalkDistance = 1.35f;
|
||||||
|
|
||||||
@@ -29,11 +30,12 @@ enum class AnimationState {
|
|||||||
WALK = 1,
|
WALK = 1,
|
||||||
STAND_TO_ACTION = 2,
|
STAND_TO_ACTION = 2,
|
||||||
ACTION_ATTACK = 3,
|
ACTION_ATTACK = 3,
|
||||||
ACTION_ATTACK_2 = 4,
|
ACTION_IDLE = 4,
|
||||||
ACTION_IDLE = 5,
|
ACTION_TO_STAND = 5,
|
||||||
ACTION_TO_STAND = 6,
|
ACTION_TO_DEATH = 6,
|
||||||
ACTION_TO_DEATH = 7,
|
DEATH_IDLE = 7,
|
||||||
DEATH_IDLE = 8,
|
ACTION_ATTACK_JUMP = 8,
|
||||||
|
ACTION_ATTACK_POWER = 9,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -83,6 +85,22 @@ public:
|
|||||||
AnimationState currentState = AnimationState::STAND;
|
AnimationState currentState = AnimationState::STAND;
|
||||||
float attack_cooldown = 0.f;
|
float attack_cooldown = 0.f;
|
||||||
|
|
||||||
|
// Jump attack is selected by an ordinary hostile-target command, but all
|
||||||
|
// timing and movement are authoritative simulation state.
|
||||||
|
bool jumpAttackUnlocked = false;
|
||||||
|
bool jumpAttackPending = false;
|
||||||
|
bool jumpAttackActive = false;
|
||||||
|
bool jumpAttackImpactConsumed = false;
|
||||||
|
int jumpAttackCooldownTicks = 0;
|
||||||
|
int jumpAttackAnimationSubframe = 0; // 1000 units per animation frame.
|
||||||
|
std::string jumpAttackTargetId;
|
||||||
|
Vec3fp jumpAttackStartPosition;
|
||||||
|
Vec3fp jumpAttackLandingPosition;
|
||||||
|
|
||||||
|
bool powerAttackPending = false;
|
||||||
|
int powerAttackCooldownTicks = 0;
|
||||||
|
std::string powerAttackTargetId;
|
||||||
|
|
||||||
// Weapon visibility toggle (changes during animation)
|
// Weapon visibility toggle (changes during animation)
|
||||||
bool showWeapon = true;
|
bool showWeapon = true;
|
||||||
|
|
||||||
@@ -99,11 +117,11 @@ public:
|
|||||||
// Frame counts are immutable metadata copied from loaded clips during
|
// Frame counts are immutable metadata copied from loaded clips during
|
||||||
// character construction. Simulation advances animationFrame itself.
|
// character construction. Simulation advances animationFrame itself.
|
||||||
float animationFrame = 0.0f;
|
float animationFrame = 0.0f;
|
||||||
std::array<int, 9> animationStartFrames = {{0, 0, 0, 0, 0, 0, 0, 0, 0}};
|
std::array<int, 10> animationStartFrames = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
|
||||||
std::array<int, 9> animationFrameCounts = {{1, 1, 1, 1, 1, 1, 1, 1, 1}};
|
std::array<int, 10> animationFrameCounts = {{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}};
|
||||||
std::array<float, 9> animationPlaybackRates = {{
|
std::array<float, 10> animationPlaybackRates = {{
|
||||||
1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
|
1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
|
||||||
1.0f, 1.0f, 1.0f, 1.0f}};
|
1.0f, 1.0f, 1.0f, 1.0f, 1.0f}};
|
||||||
|
|
||||||
// --- Movement / visual parameters ---
|
// --- Movement / visual parameters ---
|
||||||
fp walkSpeed = static_cast<fp>(3.0f);
|
fp walkSpeed = static_cast<fp>(3.0f);
|
||||||
@@ -157,8 +175,12 @@ public:
|
|||||||
const LocationNetworkState& location);
|
const LocationNetworkState& location);
|
||||||
void forceReplan(const LocationNetworkState& location);
|
void forceReplan(const LocationNetworkState& location);
|
||||||
void stopAndRotateToTarget(std::string characterId);
|
void stopAndRotateToTarget(std::string characterId);
|
||||||
|
void leaveBattleState();
|
||||||
void resetPlayerAfterDeath();
|
void resetPlayerAfterDeath();
|
||||||
void tryAttackCombo();
|
bool tryPowerAttack(const std::string& targetId);
|
||||||
|
bool reserveJumpAttack(const std::string& targetId);
|
||||||
|
void cancelPendingJumpAttack();
|
||||||
|
void beginJumpAttack(const Vec3fp& landingPosition);
|
||||||
void setHp(float newHp);
|
void setHp(float newHp);
|
||||||
CharacterUpdateEvents update(std::int64_t deltaMs, const CharacterUpdateContext& context);
|
CharacterUpdateEvents update(std::int64_t deltaMs, const CharacterUpdateContext& context);
|
||||||
void setAnimationMetadata(AnimationState state, int startFrame, int frameCount);
|
void setAnimationMetadata(AnimationState state, int startFrame, int frameCount);
|
||||||
@@ -189,6 +211,8 @@ struct CharacterUpdateContext {
|
|||||||
|
|
||||||
struct CharacterUpdateEvents {
|
struct CharacterUpdateEvents {
|
||||||
bool attackImpact = false;
|
bool attackImpact = false;
|
||||||
|
bool jumpAttackImpact = false;
|
||||||
|
bool powerAttackImpact = false;
|
||||||
bool deathAnimationComplete = false;
|
bool deathAnimationComplete = false;
|
||||||
bool navigationRequested = false;
|
bool navigationRequested = false;
|
||||||
bool forceNavigationReplan = false;
|
bool forceNavigationReplan = false;
|
||||||
@@ -197,6 +221,7 @@ struct CharacterUpdateEvents {
|
|||||||
std::string arrivedCallbackName;
|
std::string arrivedCallbackName;
|
||||||
std::string attackTargetId;
|
std::string attackTargetId;
|
||||||
Vec3fp attackDirection;
|
Vec3fp attackDirection;
|
||||||
|
float attackDamage = 10.f;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace FRG
|
} // namespace FRG
|
||||||
+1
-1
@@ -33,7 +33,7 @@ struct StoredChatMessage {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct GameState : public ISaveable {
|
struct GameState : public ISaveable {
|
||||||
static constexpr int kSchemaVersion = 7;
|
static constexpr int kSchemaVersion = 9;
|
||||||
|
|
||||||
// --- World ---
|
// --- World ---
|
||||||
// Campaign being played (see CampaignRegistry).
|
// Campaign being played (see CampaignRegistry).
|
||||||
|
|||||||
+30
-13
@@ -130,10 +130,12 @@ namespace FRG
|
|||||||
ResetCharacterAfterDeathCommand{locationId_, character.entityId()});
|
ResetCharacterAfterDeathCommand{locationId_, character.entityId()});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Location::tryCharacterAttackCombo(Character& character)
|
void Location::tryCharacterPowerAttack(
|
||||||
|
Character& character, const std::string& targetId)
|
||||||
{
|
{
|
||||||
gameServer_.submit(
|
gameServer_.submit(
|
||||||
TryCharacterAttackComboCommand{locationId_, character.entityId()});
|
TryCharacterPowerAttackCommand{
|
||||||
|
locationId_, character.entityId(), targetId});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Location::setCharacterHp(Character& character, float hp)
|
void Location::setCharacterHp(Character& character, float hp)
|
||||||
@@ -496,17 +498,22 @@ namespace FRG
|
|||||||
player->loadBinaryAnimation(AnimationState::STAND_TO_ACTION, "resources/w/gg/new2/gg_stand_to_action001_small.anim", CONST_ZIP_FILE);
|
player->loadBinaryAnimation(AnimationState::STAND_TO_ACTION, "resources/w/gg/new2/gg_stand_to_action001_small.anim", CONST_ZIP_FILE);
|
||||||
|
|
||||||
player->loadBinaryAnimation(AnimationState::ACTION_ATTACK, "resources/w/gg/new2/gg_action_chop001_small.anim", CONST_ZIP_FILE);
|
player->loadBinaryAnimation(AnimationState::ACTION_ATTACK, "resources/w/gg/new2/gg_action_chop001_small.anim", CONST_ZIP_FILE);
|
||||||
player->loadBinaryAnimation(AnimationState::ACTION_ATTACK_2, "resources/w/gg/new2/gg_action_stab001_small.anim", CONST_ZIP_FILE);
|
|
||||||
player->loadBinaryAnimation(AnimationState::ACTION_IDLE, "resources/w/gg/new2/gg_action_idle002_small.anim", CONST_ZIP_FILE);
|
player->loadBinaryAnimation(AnimationState::ACTION_IDLE, "resources/w/gg/new2/gg_action_idle002_small.anim", CONST_ZIP_FILE);
|
||||||
player->loadBinaryAnimation(AnimationState::ACTION_TO_STAND, "resources/w/gg/new2/gg_action_to_stand001_small.anim", CONST_ZIP_FILE);
|
player->loadBinaryAnimation(AnimationState::ACTION_TO_STAND, "resources/w/gg/new2/gg_action_to_stand001_small.anim", CONST_ZIP_FILE);
|
||||||
player->loadBinaryAnimation(AnimationState::ACTION_TO_DEATH, "resources/w/gg/new2/gg_die001_small.anim", CONST_ZIP_FILE);
|
player->loadBinaryAnimation(AnimationState::ACTION_TO_DEATH, "resources/w/gg/new2/gg_die001_small.anim", CONST_ZIP_FILE);
|
||||||
player->loadBinaryAnimation(AnimationState::DEATH_IDLE, "resources/w/gg/new2/gg_die_idle001_small.anim", CONST_ZIP_FILE);
|
player->loadBinaryAnimation(AnimationState::DEATH_IDLE, "resources/w/gg/new2/gg_die_idle001_small.anim", CONST_ZIP_FILE);
|
||||||
|
player->loadBinaryAnimation(AnimationState::ACTION_ATTACK_JUMP, "resources/w/gg/new3/gg_attack_jump001_small.txt.bin", CONST_ZIP_FILE);
|
||||||
|
player->loadBinaryAnimation(AnimationState::ACTION_ATTACK_POWER, "resources/w/gg/new3/gg_attack2_single_001_small.txt.bin", CONST_ZIP_FILE);
|
||||||
|
|
||||||
|
|
||||||
player->weaponTexture = renderer.textureManager.LoadFromPng("resources/w/gg/Props.png", CONST_ZIP_FILE);
|
|
||||||
player->weaponMesh.data = LoadModelFromBinFile("resources/w/gg/knife002.txt.bin", CONST_ZIP_FILE);
|
//player->weaponTexture = renderer.textureManager.LoadFromPng("resources/w/gg/Props.png", CONST_ZIP_FILE);
|
||||||
|
//player->weaponMesh.data = LoadModelFromBinFile("resources/w/gg/knife002.txt.bin", CONST_ZIP_FILE);
|
||||||
|
player->weaponTexture = renderer.textureManager.LoadFromPng("resources/w/gg/Sickle.png", CONST_ZIP_FILE);
|
||||||
|
player->weaponMesh.data = LoadModelFromBinFile("resources/w/gg/sickle002.txt.bin", CONST_ZIP_FILE);
|
||||||
player->weaponMesh.data.Move(Vector3f(0, -0.3, 0));
|
player->weaponMesh.data.Move(Vector3f(0, -0.3, 0));
|
||||||
player->weaponMesh.data.Scale(0.2f);
|
player->weaponMesh.data.Scale(0.2f);
|
||||||
|
//player->weaponMesh.data.Scale(0.8f);
|
||||||
player->weaponMesh.RefreshVBO();
|
player->weaponMesh.RefreshVBO();
|
||||||
player->weaponAttachBoneName = "RightHand";
|
player->weaponAttachBoneName = "RightHand";
|
||||||
player->weaponInitialRotation = Eigen::AngleAxisf(-M_PI * 0.5, Eigen::Vector3f::UnitZ()).toRotationMatrix();
|
player->weaponInitialRotation = Eigen::AngleAxisf(-M_PI * 0.5, Eigen::Vector3f::UnitZ()).toRotationMatrix();
|
||||||
@@ -1647,9 +1654,12 @@ namespace FRG
|
|||||||
}
|
}
|
||||||
for (const CharacterDamageEvent& event : events.damage) {
|
for (const CharacterDamageEvent& event : events.damage) {
|
||||||
Character* target = findRuntimeCharacter(event.targetId);
|
Character* target = findRuntimeCharacter(event.targetId);
|
||||||
if (target)
|
if (target) {
|
||||||
target->presentDamage(
|
target->presentDamage(
|
||||||
event.hp, event.maxHp, event.direction, event.attackerId);
|
event.hp, event.maxHp, event.direction, event.attackerId);
|
||||||
|
if (event.jumpAttack || event.powerAttack)
|
||||||
|
target->presentJumpAttackBounce();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto eventFor = [&](const std::string& id) -> const CharacterUpdateEvents* {
|
auto eventFor = [&](const std::string& id) -> const CharacterUpdateEvents* {
|
||||||
@@ -1754,8 +1764,6 @@ namespace FRG
|
|||||||
if (!playerState || !playerState->enabled) return;
|
if (!playerState || !playerState->enabled) return;
|
||||||
auto locationState = stateSnapshot();
|
auto locationState = stateSnapshot();
|
||||||
if (!locationState) return;
|
if (!locationState) return;
|
||||||
const std::string lastPlayerAttackTarget = playerState->attackTargetId;
|
|
||||||
|
|
||||||
clearCharacterAttackTarget(*player);
|
clearCharacterAttackTarget(*player);
|
||||||
|
|
||||||
// Unproject click to ground plane for walk target
|
// Unproject click to ground plane for walk target
|
||||||
@@ -1818,6 +1826,7 @@ namespace FRG
|
|||||||
// First check if we clicked on interactive object
|
// First check if we clicked on interactive object
|
||||||
InteractiveObject* clickedObject = raycastInteractiveObjects(camPos, rayDir);
|
InteractiveObject* clickedObject = raycastInteractiveObjects(camPos, rayDir);
|
||||||
if (clickedObject && player && clickedObject->state.isActive) {
|
if (clickedObject && player && clickedObject->state.isActive) {
|
||||||
|
hasLastHostileTap_ = false;
|
||||||
//logger() << "[CLICK] *** SUCCESS: Clicked on interactive object: " << clickedObject->loadedObject.name << " ***" << std::endl;
|
//logger() << "[CLICK] *** SUCCESS: Clicked on interactive object: " << clickedObject->loadedObject.name << " ***" << std::endl;
|
||||||
|
|
||||||
gameServer_.submit(SetLocationTargetsCommand{
|
gameServer_.submit(SetLocationTargetsCommand{
|
||||||
@@ -1855,12 +1864,18 @@ namespace FRG
|
|||||||
//logger() << "Raycast npc step 3" << std::endl;
|
//logger() << "Raycast npc step 3" << std::endl;
|
||||||
//logger() << "npcIndex=" << npcIndex << std::endl;
|
//logger() << "npcIndex=" << npcIndex << std::endl;
|
||||||
// Hostile NPC: combat logic walks the player toward the stable target ID.
|
// Hostile NPC: combat logic walks the player toward the stable target ID.
|
||||||
if (lastPlayerAttackTarget == clickedNpc->entityId())
|
|
||||||
{
|
|
||||||
//logger() << "Raycast npc step 4" << std::endl;
|
|
||||||
tryCharacterAttackCombo(*player);
|
|
||||||
}
|
|
||||||
const std::string targetId = clickedNpc->entityId();
|
const std::string targetId = clickedNpc->entityId();
|
||||||
|
const auto now = std::chrono::steady_clock::now();
|
||||||
|
const bool isDoubleTap =
|
||||||
|
hasLastHostileTap_ &&
|
||||||
|
lastHostileTapTargetId_ == targetId &&
|
||||||
|
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
|
now - lastHostileTapTime_).count() <= 350;
|
||||||
|
lastHostileTapTargetId_ = targetId;
|
||||||
|
lastHostileTapTime_ = now;
|
||||||
|
hasLastHostileTap_ = !isDoubleTap;
|
||||||
|
if (isDoubleTap)
|
||||||
|
tryCharacterPowerAttack(*player, targetId);
|
||||||
gameServer_.submit(SetLocationTargetsCommand{
|
gameServer_.submit(SetLocationTargetsCommand{
|
||||||
locationId_, std::string(), std::string(), std::string()});
|
locationId_, std::string(), std::string(), std::string()});
|
||||||
|
|
||||||
@@ -1883,6 +1898,7 @@ namespace FRG
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
hasLastHostileTap_ = false;
|
||||||
// Peaceful NPC: walk to them, fire on_npc_interact when within talk distance.
|
// Peaceful NPC: walk to them, fire on_npc_interact when within talk distance.
|
||||||
clearCharacterAttackTarget(*player);
|
clearCharacterAttackTarget(*player);
|
||||||
|
|
||||||
@@ -1914,6 +1930,7 @@ namespace FRG
|
|||||||
|
|
||||||
}
|
}
|
||||||
else if (rayDir.y() < -0.001f && player) {
|
else if (rayDir.y() < -0.001f && player) {
|
||||||
|
hasLastHostileTap_ = false;
|
||||||
// Unproject click to ground plane for walk target / teleport detection
|
// Unproject click to ground plane for walk target / teleport detection
|
||||||
float t = -camPos.y() / rayDir.y();
|
float t = -camPos.y() / rayDir.y();
|
||||||
Eigen::Vector3f hit = camPos + rayDir * t;
|
Eigen::Vector3f hit = camPos + rayDir * t;
|
||||||
|
|||||||
+5
-1
@@ -172,7 +172,8 @@ namespace FRG
|
|||||||
void stopCharacter(Character& character);
|
void stopCharacter(Character& character);
|
||||||
void faceCharacter(Character& character, std::string targetId);
|
void faceCharacter(Character& character, std::string targetId);
|
||||||
void resetCharacterAfterDeath(Character& character);
|
void resetCharacterAfterDeath(Character& character);
|
||||||
void tryCharacterAttackCombo(Character& character);
|
void tryCharacterPowerAttack(
|
||||||
|
Character& character, const std::string& targetId);
|
||||||
void setCharacterHp(Character& character, float hp);
|
void setCharacterHp(Character& character, float hp);
|
||||||
void refillCharacterHp(Character& character);
|
void refillCharacterHp(Character& character);
|
||||||
bool hasInventoryItem(const std::string& itemId) const;
|
bool hasInventoryItem(const std::string& itemId) const;
|
||||||
@@ -263,6 +264,9 @@ namespace FRG
|
|||||||
NpcCarPresentationSample currentNpcCarPresentation_;
|
NpcCarPresentationSample currentNpcCarPresentation_;
|
||||||
std::chrono::steady_clock::time_point lastNpcCarPresentationUpdate_;
|
std::chrono::steady_clock::time_point lastNpcCarPresentationUpdate_;
|
||||||
bool hasNpcCarPresentationSample_ = false;
|
bool hasNpcCarPresentationSample_ = false;
|
||||||
|
std::string lastHostileTapTargetId_;
|
||||||
|
std::chrono::steady_clock::time_point lastHostileTapTime_;
|
||||||
|
bool hasLastHostileTap_ = false;
|
||||||
|
|
||||||
void captureNpcCarPresentation(const NpcCar& car);
|
void captureNpcCarPresentation(const NpcCar& car);
|
||||||
NpcCarPresentationSample interpolatedNpcCarPresentation(const NpcCar& car) const;
|
NpcCarPresentationSample interpolatedNpcCarPresentation(const NpcCar& car) const;
|
||||||
|
|||||||
+142
-3
@@ -421,6 +421,131 @@ LocationSimulationEvents LocationGameState::update(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resolve pending player jump attacks from tick-start state. Candidate
|
||||||
|
// ordering and all collision tests are fixed so every lockstep replica
|
||||||
|
// freezes exactly the same landing point.
|
||||||
|
const PathFinder* jumpNavMesh = nullptr;
|
||||||
|
if (location && location->activeNavigationIndex >= 0 &&
|
||||||
|
location->activeNavigationIndex <
|
||||||
|
static_cast<int>(location->navigationMaps.size())) {
|
||||||
|
jumpNavMesh =
|
||||||
|
&location->navigationMaps[location->activeNavigationIndex];
|
||||||
|
}
|
||||||
|
for (const Entry& sourceEntry : allChars) {
|
||||||
|
CharacterState& source = *sourceEntry.state;
|
||||||
|
if (!source.jumpAttackPending) continue;
|
||||||
|
|
||||||
|
CharacterState* target =
|
||||||
|
findCharacter(source.jumpAttackTargetId, players);
|
||||||
|
if (!target || !target->enabled || target->hp <= 0.f ||
|
||||||
|
source.attackTargetId != source.jumpAttackTargetId) {
|
||||||
|
source.cancelPendingJumpAttack();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec3fp sourceToTarget = target->position - source.position;
|
||||||
|
sourceToTarget.y = fp(0);
|
||||||
|
const fp distanceSquared = sourceToTarget.normSquared();
|
||||||
|
const fp normalRange = static_cast<fp>(kAttackRange);
|
||||||
|
const fp jumpRange = static_cast<fp>(kJumpAttackRange);
|
||||||
|
if (distanceSquared <= normalRange * normalRange) {
|
||||||
|
source.cancelPendingJumpAttack();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (distanceSquared > jumpRange * jumpRange ||
|
||||||
|
source.currentState != AnimationState::ACTION_IDLE) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!jumpNavMesh || !jumpNavMesh->isWalkable(source.position)) {
|
||||||
|
source.cancelPendingJumpAttack();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fp distance = fpm::sqrt(distanceSquared);
|
||||||
|
const Vec2fp targetToSource(
|
||||||
|
-sourceToTarget.x / distance, -sourceToTarget.z / distance);
|
||||||
|
const fp diagonal = static_cast<fp>(0.7071067811865475f);
|
||||||
|
const std::array<Vec2fp, 6> directions = {{
|
||||||
|
targetToSource,
|
||||||
|
Vec2fp((targetToSource.x - targetToSource.y) * diagonal,
|
||||||
|
(targetToSource.x + targetToSource.y) * diagonal),
|
||||||
|
Vec2fp((targetToSource.x + targetToSource.y) * diagonal,
|
||||||
|
(-targetToSource.x + targetToSource.y) * diagonal),
|
||||||
|
Vec2fp(-targetToSource.y, targetToSource.x),
|
||||||
|
Vec2fp(targetToSource.y, -targetToSource.x),
|
||||||
|
Vec2fp(-targetToSource.x, -targetToSource.y)
|
||||||
|
}};
|
||||||
|
const fp standOff =
|
||||||
|
source.collisionRadius + target->collisionRadius +
|
||||||
|
static_cast<fp>(0.08f);
|
||||||
|
|
||||||
|
bool foundLanding = false;
|
||||||
|
Vec3fp landing;
|
||||||
|
for (const Vec2fp& direction : directions) {
|
||||||
|
Vec3fp candidate(
|
||||||
|
target->position.x + direction.x * standOff,
|
||||||
|
jumpNavMesh->getFloorY(),
|
||||||
|
target->position.z + direction.y * standOff);
|
||||||
|
if (!jumpNavMesh->isWalkable(candidate)) continue;
|
||||||
|
const PathFinder::PathResult path =
|
||||||
|
jumpNavMesh->findPathResult(source.position, candidate);
|
||||||
|
if (!path.reachedGoal() || path.waypoints.size() > 2) continue;
|
||||||
|
|
||||||
|
bool blocked = false;
|
||||||
|
const Vec2fp segmentStart(source.position.x, source.position.z);
|
||||||
|
const Vec2fp segmentEnd(candidate.x, candidate.z);
|
||||||
|
const Vec2fp segment = segmentEnd - segmentStart;
|
||||||
|
const fp segmentLengthSquared = segment.lengthSq();
|
||||||
|
for (const Entry& otherEntry : allChars) {
|
||||||
|
if (otherEntry.id == sourceEntry.id) continue;
|
||||||
|
const CharacterState& other = *otherEntry.state;
|
||||||
|
if (!other.enabled || other.hp <= 0.f) continue;
|
||||||
|
|
||||||
|
const fp landingClearance =
|
||||||
|
source.collisionRadius + other.collisionRadius;
|
||||||
|
std::array<Vec2fp, 2> occupiedPositions = {{
|
||||||
|
Vec2fp(other.position.x, other.position.z),
|
||||||
|
Vec2fp(
|
||||||
|
other.jumpAttackLandingPosition.x,
|
||||||
|
other.jumpAttackLandingPosition.z)
|
||||||
|
}};
|
||||||
|
const int occupiedCount = other.jumpAttackActive ? 2 : 1;
|
||||||
|
for (int occupied = 0; occupied < occupiedCount; ++occupied) {
|
||||||
|
const Vec2fp& otherPosition =
|
||||||
|
occupiedPositions[occupied];
|
||||||
|
if ((otherPosition - segmentEnd).lengthSq() <=
|
||||||
|
landingClearance * landingClearance) {
|
||||||
|
blocked = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (segmentLengthSquared <= fp(0)) continue;
|
||||||
|
fp projection =
|
||||||
|
(otherPosition - segmentStart).dot(segment) /
|
||||||
|
segmentLengthSquared;
|
||||||
|
projection =
|
||||||
|
(std::max)(fp(0), (std::min)(fp(1), projection));
|
||||||
|
const Vec2fp closest =
|
||||||
|
segmentStart + segment * projection;
|
||||||
|
if ((otherPosition - closest).lengthSq() <=
|
||||||
|
landingClearance * landingClearance) {
|
||||||
|
blocked = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (blocked) break;
|
||||||
|
}
|
||||||
|
if (blocked) continue;
|
||||||
|
landing = candidate;
|
||||||
|
foundLanding = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (foundLanding)
|
||||||
|
source.beginJumpAttack(landing);
|
||||||
|
else
|
||||||
|
source.cancelPendingJumpAttack();
|
||||||
|
}
|
||||||
|
|
||||||
// 2. ФАЗА 1: Обновляем логику каждого персонажа (вычисляется preferredVelocity)
|
// 2. ФАЗА 1: Обновляем логику каждого персонажа (вычисляется preferredVelocity)
|
||||||
for (auto& entry : allChars) {
|
for (auto& entry : allChars) {
|
||||||
CharacterUpdateContext context;
|
CharacterUpdateContext context;
|
||||||
@@ -474,6 +599,10 @@ LocationSimulationEvents LocationGameState::update(
|
|||||||
// 4. ФАЗА 3: Записываем новые позиции, скорости и обновляем анимацию/поворот
|
// 4. ФАЗА 3: Записываем новые позиции, скорости и обновляем анимацию/поворот
|
||||||
for (const auto& agent : orcaAgents) {
|
for (const auto& agent : orcaAgents) {
|
||||||
CharacterState* st = agent.state;
|
CharacterState* st = agent.state;
|
||||||
|
if (st->jumpAttackActive) {
|
||||||
|
st->velocity = Vec2fp(fp(0), fp(0));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const Vec2fp oldPos(st->position.x, st->position.z);
|
const Vec2fp oldPos(st->position.x, st->position.z);
|
||||||
const Vec2fp displacement = agent.pos - oldPos;
|
const Vec2fp displacement = agent.pos - oldPos;
|
||||||
const fp movedDistSq = displacement.lengthSq();
|
const fp movedDistSq = displacement.lengthSq();
|
||||||
@@ -510,14 +639,24 @@ LocationSimulationEvents LocationGameState::update(
|
|||||||
if (!source.events.attackImpact) continue;
|
if (!source.events.attackImpact) continue;
|
||||||
CharacterState* target = findCharacter(source.events.attackTargetId, players);
|
CharacterState* target = findCharacter(source.events.attackTargetId, players);
|
||||||
if (!target || !target->enabled || target->hp <= 0.f) continue;
|
if (!target || !target->enabled || target->hp <= 0.f) continue;
|
||||||
constexpr float damage = 10.f;
|
if (source.events.jumpAttackImpact) {
|
||||||
target->setHp(target->hp - damage);
|
const CharacterState* attacker =
|
||||||
|
findCharacter(source.characterId, players);
|
||||||
|
if (!attacker) continue;
|
||||||
|
Vec3fp separation = target->position - attacker->position;
|
||||||
|
separation.y = fp(0);
|
||||||
|
const fp hitRange = static_cast<fp>(kAttackRange);
|
||||||
|
if (separation.normSquared() > hitRange * hitRange) continue;
|
||||||
|
}
|
||||||
|
target->setHp(target->hp - source.events.attackDamage);
|
||||||
result.damage.push_back({
|
result.damage.push_back({
|
||||||
source.events.attackTargetId,
|
source.events.attackTargetId,
|
||||||
source.characterId,
|
source.characterId,
|
||||||
target->hp,
|
target->hp,
|
||||||
target->initialHp,
|
target->initialHp,
|
||||||
source.events.attackDirection });
|
source.events.attackDirection,
|
||||||
|
source.events.jumpAttackImpact,
|
||||||
|
source.events.powerAttackImpact });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ struct CharacterDamageEvent {
|
|||||||
float hp = 0.f;
|
float hp = 0.f;
|
||||||
float maxHp = 0.f;
|
float maxHp = 0.f;
|
||||||
Vec3fp direction;
|
Vec3fp direction;
|
||||||
|
bool jumpAttack = false;
|
||||||
|
bool powerAttack = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct InteractiveObjectSimulationEvent {
|
struct InteractiveObjectSimulationEvent {
|
||||||
|
|||||||
@@ -234,7 +234,10 @@ void loadCharacterAnimationMetadata(
|
|||||||
CharacterState& state, const std::string& zipFile)
|
CharacterState& state, const std::string& zipFile)
|
||||||
{
|
{
|
||||||
for (const auto& [animation, path] : state.creationInfo.animationPaths) {
|
for (const auto& [animation, path] : state.creationInfo.animationPaths) {
|
||||||
if (path.size() < 5 || path.substr(path.size() - 5) != ".anim")
|
const bool binary =
|
||||||
|
(path.size() >= 5 && path.substr(path.size() - 5) == ".anim") ||
|
||||||
|
(path.size() >= 4 && path.substr(path.size() - 4) == ".bin");
|
||||||
|
if (!binary)
|
||||||
continue;
|
continue;
|
||||||
try {
|
try {
|
||||||
const auto [startFrame, frameCount] =
|
const auto [startFrame, frameCount] =
|
||||||
|
|||||||
@@ -193,9 +193,10 @@ struct ResetCharacterAfterDeathCommand {
|
|||||||
std::string locationId;
|
std::string locationId;
|
||||||
std::string characterId;
|
std::string characterId;
|
||||||
};
|
};
|
||||||
struct TryCharacterAttackComboCommand {
|
struct TryCharacterPowerAttackCommand {
|
||||||
std::string locationId;
|
std::string locationId;
|
||||||
std::string characterId;
|
std::string characterId;
|
||||||
|
std::string targetId;
|
||||||
};
|
};
|
||||||
struct SetCharacterHealthCommand {
|
struct SetCharacterHealthCommand {
|
||||||
std::string locationId;
|
std::string locationId;
|
||||||
@@ -266,7 +267,7 @@ using GameCommand = std::variant<
|
|||||||
FaceCharacterCommand,
|
FaceCharacterCommand,
|
||||||
ReplanCharacterCommand,
|
ReplanCharacterCommand,
|
||||||
ResetCharacterAfterDeathCommand,
|
ResetCharacterAfterDeathCommand,
|
||||||
TryCharacterAttackComboCommand,
|
TryCharacterPowerAttackCommand,
|
||||||
SetCharacterHealthCommand,
|
SetCharacterHealthCommand,
|
||||||
SetCharacterAnimationMetadataCommand,
|
SetCharacterAnimationMetadataCommand,
|
||||||
DamageCharacterCommand,
|
DamageCharacterCommand,
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ void configurePlayerAnimations(
|
|||||||
"resources/w/gg/new2/gg_stand_to_action001_small.anim"},
|
"resources/w/gg/new2/gg_stand_to_action001_small.anim"},
|
||||||
{AnimationState::ACTION_ATTACK,
|
{AnimationState::ACTION_ATTACK,
|
||||||
"resources/w/gg/new2/gg_action_chop001_small.anim"},
|
"resources/w/gg/new2/gg_action_chop001_small.anim"},
|
||||||
{AnimationState::ACTION_ATTACK_2,
|
|
||||||
"resources/w/gg/new2/gg_action_stab001_small.anim"},
|
|
||||||
{AnimationState::ACTION_IDLE,
|
{AnimationState::ACTION_IDLE,
|
||||||
"resources/w/gg/new2/gg_action_idle002_small.anim"},
|
"resources/w/gg/new2/gg_action_idle002_small.anim"},
|
||||||
{AnimationState::ACTION_TO_STAND,
|
{AnimationState::ACTION_TO_STAND,
|
||||||
@@ -33,8 +31,17 @@ void configurePlayerAnimations(
|
|||||||
{AnimationState::ACTION_TO_DEATH,
|
{AnimationState::ACTION_TO_DEATH,
|
||||||
"resources/w/gg/new2/gg_die001_small.anim"},
|
"resources/w/gg/new2/gg_die001_small.anim"},
|
||||||
{AnimationState::DEATH_IDLE,
|
{AnimationState::DEATH_IDLE,
|
||||||
"resources/w/gg/new2/gg_die_idle001_small.anim"}};
|
"resources/w/gg/new2/gg_die_idle001_small.anim"},
|
||||||
|
{AnimationState::ACTION_ATTACK_JUMP,
|
||||||
|
"resources/w/gg/new3/gg_attack_jump001_small.txt.bin"},
|
||||||
|
{AnimationState::ACTION_ATTACK_POWER,
|
||||||
|
"resources/w/gg/new3/gg_attack2_single_001_small.txt.bin"}};
|
||||||
loadCharacterAnimationMetadata(player, zipFile);
|
loadCharacterAnimationMetadata(player, zipFile);
|
||||||
|
// Gameplay timing is authored against the documented 80-frame clip.
|
||||||
|
player.setAnimationMetadata(
|
||||||
|
AnimationState::ACTION_ATTACK_JUMP, 0, 80);
|
||||||
|
player.setAnimationMetadata(
|
||||||
|
AnimationState::ACTION_ATTACK_POWER, 0, 79);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -403,7 +410,10 @@ void InternalGameServer::submit(const GameCommand& command)
|
|||||||
} else if constexpr (std::is_same_v<T, SetCharacterTargetCommand>) {
|
} else if constexpr (std::is_same_v<T, SetCharacterTargetCommand>) {
|
||||||
CharacterState* character =
|
CharacterState* character =
|
||||||
state_.findCharacter(value.locationId, value.characterId);
|
state_.findCharacter(value.locationId, value.characterId);
|
||||||
if (character) character->attackTargetId = value.targetId;
|
if (character) {
|
||||||
|
character->reserveJumpAttack(value.targetId);
|
||||||
|
character->attackTargetId = value.targetId;
|
||||||
|
}
|
||||||
} else if constexpr (std::is_same_v<T, SetCharacterFaceTargetCommand>) {
|
} else if constexpr (std::is_same_v<T, SetCharacterFaceTargetCommand>) {
|
||||||
CharacterState* character =
|
CharacterState* character =
|
||||||
state_.findCharacter(value.locationId, value.characterId);
|
state_.findCharacter(value.locationId, value.characterId);
|
||||||
@@ -420,17 +430,30 @@ void InternalGameServer::submit(const GameCommand& command)
|
|||||||
character->faceTargetId.clear();
|
character->faceTargetId.clear();
|
||||||
character->attackTargetId.clear();
|
character->attackTargetId.clear();
|
||||||
character->battle_state = 0;
|
character->battle_state = 0;
|
||||||
|
character->cancelPendingJumpAttack();
|
||||||
|
character->jumpAttackActive = false;
|
||||||
|
character->jumpAttackImpactConsumed = false;
|
||||||
|
character->jumpAttackAnimationSubframe = 0;
|
||||||
|
character->jumpAttackTargetId.clear();
|
||||||
|
character->powerAttackPending = false;
|
||||||
|
character->powerAttackTargetId.clear();
|
||||||
}
|
}
|
||||||
} else if constexpr (std::is_same_v<T, ClearCharacterAttackTargetCommand>) {
|
} else if constexpr (std::is_same_v<T, ClearCharacterAttackTargetCommand>) {
|
||||||
CharacterState* character =
|
CharacterState* character =
|
||||||
state_.findCharacter(value.locationId, value.characterId);
|
state_.findCharacter(value.locationId, value.characterId);
|
||||||
if (character) character->attackTargetId.clear();
|
if (character) {
|
||||||
|
character->leaveBattleState();
|
||||||
|
}
|
||||||
} else if constexpr (std::is_same_v<T, SetCharacterDestinationCommand>) {
|
} else if constexpr (std::is_same_v<T, SetCharacterDestinationCommand>) {
|
||||||
auto location = state_.locations.find(value.locationId);
|
auto location = state_.locations.find(value.locationId);
|
||||||
if (location != state_.locations.end())
|
if (location != state_.locations.end()) {
|
||||||
|
CharacterState* character =
|
||||||
|
state_.findCharacter(value.locationId, value.characterId);
|
||||||
|
if (character) character->leaveBattleState();
|
||||||
location->second.setCharacterDestination(
|
location->second.setCharacterDestination(
|
||||||
value.characterId, value.target, value.callbackName,
|
value.characterId, value.target, value.callbackName,
|
||||||
state_.players);
|
state_.players);
|
||||||
|
}
|
||||||
} else if constexpr (std::is_same_v<T, StopCharacterCommand>) {
|
} else if constexpr (std::is_same_v<T, StopCharacterCommand>) {
|
||||||
CharacterState* character =
|
CharacterState* character =
|
||||||
state_.findCharacter(value.locationId, value.characterId);
|
state_.findCharacter(value.locationId, value.characterId);
|
||||||
@@ -449,10 +472,10 @@ void InternalGameServer::submit(const GameCommand& command)
|
|||||||
CharacterState* character =
|
CharacterState* character =
|
||||||
state_.findCharacter(value.locationId, value.characterId);
|
state_.findCharacter(value.locationId, value.characterId);
|
||||||
if (character) character->resetPlayerAfterDeath();
|
if (character) character->resetPlayerAfterDeath();
|
||||||
} else if constexpr (std::is_same_v<T, TryCharacterAttackComboCommand>) {
|
} else if constexpr (std::is_same_v<T, TryCharacterPowerAttackCommand>) {
|
||||||
CharacterState* character =
|
CharacterState* character =
|
||||||
state_.findCharacter(value.locationId, value.characterId);
|
state_.findCharacter(value.locationId, value.characterId);
|
||||||
if (character) character->tryAttackCombo();
|
if (character) character->tryPowerAttack(value.targetId);
|
||||||
} else if constexpr (std::is_same_v<T, SetCharacterHealthCommand>) {
|
} else if constexpr (std::is_same_v<T, SetCharacterHealthCommand>) {
|
||||||
CharacterState* character =
|
CharacterState* character =
|
||||||
state_.findCharacter(value.locationId, value.characterId);
|
state_.findCharacter(value.locationId, value.characterId);
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ inline void applyScheduledCommand(
|
|||||||
} else if (command.action == "clear_attack_target") {
|
} else if (command.action == "clear_attack_target") {
|
||||||
server.submit(ClearCharacterAttackTargetCommand{
|
server.submit(ClearCharacterAttackTargetCommand{
|
||||||
locationId, command.playerId});
|
locationId, command.playerId});
|
||||||
} else if (command.action == "try_attack_combo") {
|
} else if (command.action == "try_power_attack") {
|
||||||
server.submit(TryCharacterAttackComboCommand{
|
server.submit(TryCharacterPowerAttackCommand{
|
||||||
locationId, command.playerId});
|
locationId, command.playerId, command.targetId});
|
||||||
}
|
}
|
||||||
}, scheduled);
|
}, scheduled);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,12 +142,13 @@ bool validCharacterAction(
|
|||||||
{
|
{
|
||||||
if (action != "set_target" &&
|
if (action != "set_target" &&
|
||||||
action != "clear_attack_target" &&
|
action != "clear_attack_target" &&
|
||||||
action != "try_attack_combo") {
|
action != "try_power_attack") {
|
||||||
error = "unsupported character action";
|
error = "unsupported character action";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (action == "set_target" && targetId.empty()) {
|
if ((action == "set_target" || action == "try_power_attack") &&
|
||||||
error = "set_target requires a targetId";
|
targetId.empty()) {
|
||||||
|
error = action + " requires a targetId";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (action != "set_target" && !targetId.empty()) {
|
if (action != "set_target" && !targetId.empty()) {
|
||||||
@@ -296,7 +297,7 @@ bool isOrderCommand(const ScheduledCommand& command, const std::string& playerId
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Within one tick only the player's last order (destination, set_target or
|
// Within one tick only the player's last order (destination, set_target or
|
||||||
// clear_attack_target) survives; combos and presence commands are untouched.
|
// clear_attack_target) survives; abilities and presence commands are untouched.
|
||||||
void dropSupersededOrders(
|
void dropSupersededOrders(
|
||||||
std::vector<ScheduledCommand>& commands, const std::string& playerId)
|
std::vector<ScheduledCommand>& commands, const std::string& playerId)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -513,9 +513,11 @@ void WebsocketGameClient::submit(const GameCommand& command)
|
|||||||
} else if (std::holds_alternative<ClearCharacterAttackTargetCommand>(command)) {
|
} else if (std::holds_alternative<ClearCharacterAttackTargetCommand>(command)) {
|
||||||
impl_->send(signInputMessage(makeCharacterActionInputMessage(
|
impl_->send(signInputMessage(makeCharacterActionInputMessage(
|
||||||
{nextClientSequence_++, "clear_attack_target", {}}), sessionSecret_));
|
{nextClientSequence_++, "clear_attack_target", {}}), sessionSecret_));
|
||||||
} else if (std::holds_alternative<TryCharacterAttackComboCommand>(command)) {
|
} else if (const auto* powerAttack =
|
||||||
|
std::get_if<TryCharacterPowerAttackCommand>(&command)) {
|
||||||
impl_->send(signInputMessage(makeCharacterActionInputMessage(
|
impl_->send(signInputMessage(makeCharacterActionInputMessage(
|
||||||
{nextClientSequence_++, "try_attack_combo", {}}), sessionSecret_));
|
{nextClientSequence_++, "try_power_attack",
|
||||||
|
powerAttack->targetId}), sessionSecret_));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user