Mob fixes.
This commit is contained in:
@@ -300,6 +300,16 @@ func _handle_dungeon_enter(data: Dictionary):
|
|||||||
var pid = p.get("id", p.get("Id"))
|
var pid = p.get("id", p.get("Id"))
|
||||||
portals[pid] = p
|
portals[pid] = p
|
||||||
|
|
||||||
|
# Parse mob catalog if included in the dungeon-enter response
|
||||||
|
var catalog = data.get("mobCatalog", data.get("MobCatalog", []))
|
||||||
|
if catalog is Array and catalog.size() > 0:
|
||||||
|
for entry in catalog:
|
||||||
|
var cid = entry.get("id", entry.get("Id"))
|
||||||
|
if cid != null:
|
||||||
|
mob_catalog[cid] = entry
|
||||||
|
print("[GameState] Mob catalog from enter: %d entries" % catalog.size())
|
||||||
|
_prefetch_mob_textures_from_list(catalog)
|
||||||
|
|
||||||
# Prefetch mob textures early on web (mobs list is included in enter payload)
|
# Prefetch mob textures early on web (mobs list is included in enter payload)
|
||||||
var mobs_list = data.get("mobs", data.get("Mobs", []))
|
var mobs_list = data.get("mobs", data.get("Mobs", []))
|
||||||
_prefetch_mob_textures_from_list(mobs_list)
|
_prefetch_mob_textures_from_list(mobs_list)
|
||||||
|
|||||||
@@ -641,12 +641,7 @@ func _update_mob_entities():
|
|||||||
mob_dead = hp <= 0
|
mob_dead = hp <= 0
|
||||||
var was_dead = entity_node.get_meta("is_dead", false)
|
var was_dead = entity_node.get_meta("is_dead", false)
|
||||||
|
|
||||||
if mob_dead and not was_dead:
|
if not mob_dead and was_dead:
|
||||||
# Alive → dead transition
|
|
||||||
entity_node.set_meta("is_dead", true)
|
|
||||||
if entity_node.has_method("play_death_animation"):
|
|
||||||
entity_node.play_death_animation()
|
|
||||||
elif not mob_dead and was_dead:
|
|
||||||
# Dead → alive transition (respawn / reused ID) — reset stale state
|
# Dead → alive transition (respawn / reused ID) — reset stale state
|
||||||
entity_node.set_meta("is_dead", false)
|
entity_node.set_meta("is_dead", false)
|
||||||
if entity_node.has_method("reset_state"):
|
if entity_node.has_method("reset_state"):
|
||||||
@@ -656,9 +651,16 @@ func _update_mob_entities():
|
|||||||
var has_loot = mob.get("hasLoot", mob.get("HasLoot", false))
|
var has_loot = mob.get("hasLoot", mob.get("HasLoot", false))
|
||||||
entity_node.set_meta("has_loot", has_loot)
|
entity_node.set_meta("has_loot", has_loot)
|
||||||
|
|
||||||
|
# Update visual data BEFORE death transition so play_death_animation() has final say
|
||||||
if entity_node.has_method("update_data"):
|
if entity_node.has_method("update_data"):
|
||||||
entity_node.update_data(mob)
|
entity_node.update_data(mob)
|
||||||
|
|
||||||
|
if mob_dead and not was_dead:
|
||||||
|
# Alive → dead transition — called AFTER update_data so it overrides animation
|
||||||
|
entity_node.set_meta("is_dead", true)
|
||||||
|
if entity_node.has_method("play_death_animation"):
|
||||||
|
entity_node.play_death_animation()
|
||||||
|
|
||||||
# Remove entity nodes that are no longer tracked at all
|
# Remove entity nodes that are no longer tracked at all
|
||||||
for child in mobs_container.get_children():
|
for child in mobs_container.get_children():
|
||||||
if child.has_meta("entity_id"):
|
if child.has_meta("entity_id"):
|
||||||
|
|||||||
@@ -153,14 +153,31 @@ func update_data(data: Dictionary):
|
|||||||
_apply_tint(tint)
|
_apply_tint(tint)
|
||||||
_initialized = true
|
_initialized = true
|
||||||
|
|
||||||
# Resolve animation — prefer server-authoritative currentAnimation, fall back to state
|
# Resolve animation — prefer server-authoritative currentAnimation, fall back to state.
|
||||||
|
# If dungeon_manager already triggered play_death_animation() this tick (setting
|
||||||
|
# _current_state = "dead"), don't let a stale currentAnimation override it — unless
|
||||||
|
# the server explicitly says the mob is alive via a non-dead animation.
|
||||||
var current_anim = data.get("currentAnimation", data.get("CurrentAnimation", null))
|
var current_anim = data.get("currentAnimation", data.get("CurrentAnimation", null))
|
||||||
var rotation = data.get("rotation", data.get("Rotation", 0.0))
|
var rotation = data.get("rotation", data.get("Rotation", 0.0))
|
||||||
|
|
||||||
if current_anim != null and current_anim is String and not current_anim.is_empty():
|
if current_anim != null and current_anim is String and not current_anim.is_empty():
|
||||||
# Server says exactly what animation to play — always apply, even if currently "dead"
|
var anim_lower = current_anim.to_lower()
|
||||||
var animation_state := _state_to_animation(current_anim)
|
# Map through STATE_TO_ANIMATION if it's a known state name; otherwise use as-is
|
||||||
_update_animation_state(animation_state, rotation)
|
var animation_state: String
|
||||||
|
if STATE_TO_ANIMATION.has(anim_lower):
|
||||||
|
animation_state = STATE_TO_ANIMATION[anim_lower]
|
||||||
|
else:
|
||||||
|
animation_state = anim_lower
|
||||||
|
|
||||||
|
if animation_state == "dead":
|
||||||
|
# Server confirms death — apply death animation
|
||||||
|
_update_animation_state(animation_state, rotation)
|
||||||
|
elif _current_state == "dead":
|
||||||
|
# Server says non-dead but we're locally dead — server override, mob is alive
|
||||||
|
_update_animation_state(animation_state, rotation)
|
||||||
|
else:
|
||||||
|
# Normal case: apply server animation
|
||||||
|
_update_animation_state(animation_state, rotation)
|
||||||
elif _current_state != "dead":
|
elif _current_state != "dead":
|
||||||
# Legacy path: use state field, but still skip if locally dead (no server override)
|
# Legacy path: use state field, but still skip if locally dead (no server override)
|
||||||
var raw_state = data.get("state", data.get("State", "idle")).to_lower()
|
var raw_state = data.get("state", data.get("State", "idle")).to_lower()
|
||||||
@@ -525,14 +542,15 @@ func _play_animation(state: String, direction: String):
|
|||||||
|
|
||||||
# Only log and play if animation changed
|
# Only log and play if animation changed
|
||||||
if anim_name != _last_animation:
|
if anim_name != _last_animation:
|
||||||
#print("[MobVisual] Playing animation: %s (state=%s, dir=%s)" % [anim_name, state, direction])
|
|
||||||
_last_animation = anim_name
|
_last_animation = anim_name
|
||||||
_animated_sprite.play(anim_name)
|
_animated_sprite.play(anim_name)
|
||||||
|
|
||||||
# Handle flipping
|
# Handle horizontal flipping when playing opposite direction's animation.
|
||||||
# For left direction without a dedicated left animation, flip the right one
|
# If facing right but playing a _left animation (or vice versa), flip.
|
||||||
if direction == "left" and not frames.has_animation("%s_left" % state):
|
if direction == "right" and anim_name.ends_with("_left"):
|
||||||
should_flip_x = not should_flip_x # Toggle flip
|
should_flip_x = not should_flip_x
|
||||||
|
elif direction == "left" and anim_name.ends_with("_right"):
|
||||||
|
should_flip_x = not should_flip_x
|
||||||
|
|
||||||
_animated_sprite.flip_h = should_flip_x
|
_animated_sprite.flip_h = should_flip_x
|
||||||
_animated_sprite.flip_v = should_flip_y
|
_animated_sprite.flip_v = should_flip_y
|
||||||
|
|||||||
Reference in New Issue
Block a user