package maps

import (
	"blazing/logic/service"
	"blazing/logic/service/space"
)

type LeaveMapOutboundInfo struct {
	// 米米号
	UserID uint32 `struc:"uint32" fieldDesc:"米米号" json:"user_id"`
}

type LeaveMapInboundInfo struct {
	Head service.TomeeHeader `cmd:"2002" struc:"[0]pad"` //切换地图
}

func (t *LeaveMapInboundInfo) Broadcast(mapid uint32, o LeaveMapOutboundInfo) {

	space.GetSpace(mapid).Range(func(playerID uint32, player service.PlayerI) bool {
		t.Head.Result = 0

		player.SendPack(t.Head.Pack(&o))
		return true
	})
}

func LeaveMap(c service.PlayerI) {
	t := service.NewTomeeHeader(2002, c.ID())

	space.GetSpace(c.MapID()).Range(func(playerID uint32, player service.PlayerI) bool {

		player.SendPack(t.Pack(&LeaveMapOutboundInfo{UserID: c.ID()}))
		return true
	})
	space.GetSpace(c.MapID()).Delete(c.ID())
}
