mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-07-08 19:17:05 +08:00
feat(多人游戏): 添加玩家名称存储并优化多人游戏逻辑
在MultiplayerState中添加playerName静态变量用于存储玩家名称 修改Starter.gd中的startMultiplayerGame方法,保存玩家名称到MultiplayerState 优化EntityBase.gd的AI逻辑,仅当玩家名称匹配时才执行AI 移除不再需要的多人游戏同步方法
This commit is contained in:
@@ -53,11 +53,11 @@ func rebuildAllPlayers(playerNames: Array[String]):
|
|||||||
addPlayerName(i)
|
addPlayerName(i)
|
||||||
@rpc("any_peer")
|
@rpc("any_peer")
|
||||||
func startMultiplayerGame():
|
func startMultiplayerGame():
|
||||||
if multiplayer.is_server():
|
MultiplayerState.playerName = playerNameInput.text
|
||||||
for i in getPlayerNames():
|
for i in getPlayerNames():
|
||||||
EntityBase.generatePlayer(i)
|
EntityBase.generatePlayer(i)
|
||||||
Wave.next()
|
Wave.next()
|
||||||
UIState.closeCurrentPanel()
|
UIState.closeCurrentPanel()
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
historyStack = Composables.useHistoryStack(playerNameInput)
|
historyStack = Composables.useHistoryStack(playerNameInput)
|
||||||
|
|||||||
@@ -169,13 +169,16 @@ func _physics_process(_delta: float) -> void:
|
|||||||
else:
|
else:
|
||||||
velocity = Vector2.ZERO
|
velocity = Vector2.ZERO
|
||||||
if (isPlayer() or is_instance_valid(currentFocusedBoss)) and not charginup and canRunAi:
|
if (isPlayer() or is_instance_valid(currentFocusedBoss)) and not charginup and canRunAi:
|
||||||
ai()
|
if isPlayer():
|
||||||
|
if MultiplayerState.playerName == displayName:
|
||||||
|
ai()
|
||||||
|
else:
|
||||||
|
ai()
|
||||||
elif isSummon():
|
elif isSummon():
|
||||||
ai()
|
ai()
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
storeEnergy(randf_range(0.01, 0.05 + fields.get(FieldStore.Entity.ENERGY_REGENERATION) - 1), true)
|
storeEnergy(randf_range(0.01, 0.05 + fields.get(FieldStore.Entity.ENERGY_REGENERATION) - 1), true)
|
||||||
trailParticle.emitting = trailing
|
trailParticle.emitting = trailing
|
||||||
rpc("syncPosition", displayName, position)
|
|
||||||
|
|
||||||
# 通用方法
|
# 通用方法
|
||||||
func rebuildWeaponIcons():
|
func rebuildWeaponIcons():
|
||||||
@@ -394,21 +397,6 @@ func summon(who: PackedScene, syncFields: bool = true, lockValue: bool = true) -
|
|||||||
get_parent().add_child(instance)
|
get_parent().add_child(instance)
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
# 多人游戏数据同步
|
|
||||||
@rpc("any_peer")
|
|
||||||
func syncPosition(player: String, newPosition: Vector2):
|
|
||||||
if player == displayName:
|
|
||||||
position = newPosition
|
|
||||||
@rpc("any_peer")
|
|
||||||
func syncHealth(player: String, newHealth: float):
|
|
||||||
if player == displayName:
|
|
||||||
health = newHealth
|
|
||||||
healthChanged.emit(health)
|
|
||||||
@rpc("any_peer")
|
|
||||||
func syncAttack(player: String, index: int):
|
|
||||||
if player == displayName:
|
|
||||||
tryAttack(index)
|
|
||||||
|
|
||||||
# 关于追踪
|
# 关于追踪
|
||||||
func getTrackingAnchor() -> Vector2:
|
func getTrackingAnchor() -> Vector2:
|
||||||
return hurtbox.get_node("hitbox").global_position
|
return hurtbox.get_node("hitbox").global_position
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ static var stateColorMap = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static var state: ConnectionState = ConnectionState.DISCONNECTED
|
static var state: ConnectionState = ConnectionState.DISCONNECTED
|
||||||
|
static var playerName: String
|
||||||
|
|
||||||
static var maxPlayer: int = 10
|
static var maxPlayer: int = 10
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user