using Fantasy;
using Fantasy.Async;
using Fantasy.Network.Interface;

namespace NB.Map;

public class C2Map_RolePropertyChangeHandler : Route<MapUnit, C2Map_RolePropertyChange>
{
    protected override async FTask Run(MapUnit entity, C2Map_RolePropertyChange message)
    {
        var roomManageComponent = entity.Scene.GetComponent<RoomManageComponent>();
        var roomId = entity.RoomId;
        var room = roomManageComponent.Get(roomId);
        if (room == null)
        {
            return;
        }

        var notifyMessage = new Map2C_RolePropertyChangeNotify()
        {
            Id = entity.Id,
            Propertys = message.Propertys,
        };


        foreach (var (_, unit) in room.Units)
        {
            if (unit.Id == entity.Id) continue;
            entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.GateRouteId, notifyMessage);
        }

        await FTask.CompletedTask;
    }
}