mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-05-28 06:51:54 +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)
|
||||
@rpc("any_peer")
|
||||
func startMultiplayerGame():
|
||||
if multiplayer.is_server():
|
||||
for i in getPlayerNames():
|
||||
EntityBase.generatePlayer(i)
|
||||
Wave.next()
|
||||
UIState.closeCurrentPanel()
|
||||
MultiplayerState.playerName = playerNameInput.text
|
||||
for i in getPlayerNames():
|
||||
EntityBase.generatePlayer(i)
|
||||
Wave.next()
|
||||
UIState.closeCurrentPanel()
|
||||
|
||||
func _ready():
|
||||
historyStack = Composables.useHistoryStack(playerNameInput)
|
||||
|
||||
@@ -169,13 +169,16 @@ func _physics_process(_delta: float) -> void:
|
||||
else:
|
||||
velocity = Vector2.ZERO
|
||||
if (isPlayer() or is_instance_valid(currentFocusedBoss)) and not charginup and canRunAi:
|
||||
ai()
|
||||
if isPlayer():
|
||||
if MultiplayerState.playerName == displayName:
|
||||
ai()
|
||||
else:
|
||||
ai()
|
||||
elif isSummon():
|
||||
ai()
|
||||
move_and_slide()
|
||||
storeEnergy(randf_range(0.01, 0.05 + fields.get(FieldStore.Entity.ENERGY_REGENERATION) - 1), true)
|
||||
trailParticle.emitting = trailing
|
||||
rpc("syncPosition", displayName, position)
|
||||
|
||||
# 通用方法
|
||||
func rebuildWeaponIcons():
|
||||
@@ -394,21 +397,6 @@ func summon(who: PackedScene, syncFields: bool = true, lockValue: bool = true) -
|
||||
get_parent().add_child(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:
|
||||
return hurtbox.get_node("hitbox").global_position
|
||||
|
||||
@@ -21,6 +21,7 @@ static var stateColorMap = {
|
||||
}
|
||||
|
||||
static var state: ConnectionState = ConnectionState.DISCONNECTED
|
||||
static var playerName: String
|
||||
|
||||
static var maxPlayer: int = 10
|
||||
|
||||
|
||||
Reference in New Issue
Block a user