Projectiles+

This commit is contained in:
dingo
2026-01-18 20:45:48 -05:00
parent 32fb57fa75
commit 718a8ecb3b
14 changed files with 455 additions and 19 deletions
+51 -2
View File
@@ -21,6 +21,10 @@ signal recipe_discovered(recipe: Dictionary)
signal stash_updated(stash_data: Dictionary)
signal stash_result(result: Dictionary)
signal dungeon_tiles_updated(tiles: Array)
signal projectile_spawned(projectile_data: Dictionary)
signal projectile_hit(hit_data: Dictionary)
signal projectile_expired(expired_data: Dictionary)
signal damage_number(damage_data: Dictionary)
# Use constants instead of enum to avoid type issues
const STATE_AUTH = 0
@@ -175,6 +179,14 @@ func _on_message_received(opcode: int, data: Dictionary):
_handle_stash_state(data)
OpCodes.STASH_RESULT:
_handle_stash_result(data)
OpCodes.EVENT_PROJECTILE_SPAWNED:
_handle_projectile_spawned(data)
OpCodes.EVENT_PROJECTILE_HIT:
_handle_projectile_hit(data)
OpCodes.EVENT_PROJECTILE_EXPIRED:
_handle_projectile_expired(data)
OpCodes.EVENT_DAMAGE_NUMBER:
_handle_damage_number(data)
_:
print("[GameState] Unhandled opcode: ", opcode)
@@ -398,7 +410,25 @@ func _handle_dungeon_state(data: Dictionary):
for lc in lchests:
var lcid = lc.get("id", lc.get("Id"))
loot_chests[lcid] = lc
# Parse events (damage, deaths, projectile hits/expires)
var events = data.get("events")
if events:
# Handle damage events - spawn floating damage numbers
var damage_events = events.get("damage", [])
for dmg_event in damage_events:
damage_number.emit(dmg_event)
# Handle projectile hit events - remove projectile from client
var projectile_hits = events.get("projectileHits", [])
for hit_event in projectile_hits:
projectile_hit.emit(hit_event)
# Handle projectile expired events - remove projectile from client
var proj_expired = events.get("projectileExpired", [])
for expire_event in proj_expired:
projectile_expired.emit(expire_event)
dungeon_state_updated.emit()
func _handle_inventory_state(data: Dictionary):
@@ -491,6 +521,9 @@ func send_move(dx: float, dy: float, aim_angle: float):
func send_attack(aim_angle: float):
Network.send_message(OpCodes.INPUT_ATTACK, {"AimAngle": aim_angle})
func send_fire_projectile(direction_x: float, direction_y: float):
Network.send_message(OpCodes.INPUT_FIRE_PROJECTILE, {"DirectionX": direction_x, "DirectionY": direction_y})
func send_enter_dungeon(tier: int):
Network.send_message(OpCodes.DUNGEON_ENTER, {"Tier": tier})
@@ -731,5 +764,21 @@ func _handle_tile_update(data: Dictionary):
if not found:
dungeon.visual_tiles.tiles.append(tile)
dungeon_tiles_updated.emit(tiles)
func _handle_projectile_spawned(data: Dictionary):
print("[GameState] Projectile spawned: ", data.get("id", -1))
projectile_spawned.emit(data)
func _handle_projectile_hit(data: Dictionary):
print("[GameState] Projectile hit: ", data)
projectile_hit.emit(data)
func _handle_projectile_expired(data: Dictionary):
print("[GameState] Projectile expired: ", data.get("id", -1))
projectile_expired.emit(data)
func _handle_damage_number(data: Dictionary):
# Emit damage number for floating damage text
damage_number.emit(data)
+1 -1
View File
@@ -188,7 +188,7 @@ func _handle_received_data(packet: PackedByteArray):
var message = json.data
var opcode: int = message.get("opCode", message.get("OpCode", 0))
print("[Network] OpCode Recieved: ", opcode)
# Decode payload
var payload_data = message.get("payload", message.get("Payload", null))
var decoded_data = {}
+15
View File
@@ -205,6 +205,9 @@ const INPUT_CHEST = 403
## Client -> Server: Use portal
const INPUT_PORTAL = 404
## Client -> Server: Fire projectile (bow, crossbow, throwable)
const INPUT_FIRE_PROJECTILE = 405
# ===== Escape / Portal (450-459) =====
## Client -> Server: Start escape channel (return to hub)
@@ -236,6 +239,18 @@ const EVENT_LEVELUP = 502
## Server -> Client: Loot obtained
const EVENT_LOOT = 503
## Server -> Client: Projectile spawned in dungeon
const EVENT_PROJECTILE_SPAWNED = 504
## Server -> Client: Projectile hit target (mob/player)
const EVENT_PROJECTILE_HIT = 505
## Server -> Client: Projectile expired (max range or wall collision)
const EVENT_PROJECTILE_EXPIRED = 506
## Server -> Client: Damage number for floating text
const EVENT_DAMAGE_NUMBER = 507
# ===== Server Broadcasts (600-609) =====
## Server -> All Clients: Server-wide broadcast message