LastMUD/internal/game/logic/world/player.go

30 lines
918 B
Go
Raw Normal View History

package world
import (
"code.haedhutner.dev/mvv/LastMUD/internal/ecs"
"code.haedhutner.dev/mvv/LastMUD/internal/game/data"
"github.com/google/uuid"
)
func CreateJoiningPlayer(world *ecs.World, connectionId uuid.UUID) (entity ecs.Entity) {
entity = ecs.NewEntity()
ecs.SetComponent(world, entity, data.ConnectionIdComponent{ConnectionId: connectionId})
ecs.SetComponent(world, entity, data.PlayerStateComponent{State: data.PlayerStateJoining})
ecs.SetComponent(world, entity, data.NameComponent{Name: connectionId.String()})
ecs.SetComponent(world, entity, data.IsPlayerComponent{})
2025-06-29 18:21:22 +03:00
ecs.SetComponent(world, entity, data.InputBufferComponent{InputBuffer: ""})
return
}
2025-06-29 18:21:22 +03:00
func SendMessageToPlayer(world *ecs.World, player ecs.Entity, message string) {
connId, ok := ecs.GetComponent[data.ConnectionIdComponent](world, player)
if !ok {
return
}
CreateGameOutput(world, connId.ConnectionId, message)
}