2024-04-28 13:55:19 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using ColdMint.scripts.map.dateBean;
|
|
|
|
|
using ColdMint.scripts.map.interfaces;
|
|
|
|
|
|
|
|
|
|
namespace ColdMint.scripts.map.slotsMatcher;
|
|
|
|
|
|
|
|
|
|
public class RoomSlotsMatcher : IRoomSlotsMatcher
|
|
|
|
|
{
|
2024-05-08 10:22:04 +00:00
|
|
|
|
private RoomSlot? _lastMatchedMainSlot;
|
|
|
|
|
private RoomSlot? _lastMatchedMinorSlot;
|
2024-04-28 13:55:19 +00:00
|
|
|
|
|
2024-05-08 10:22:04 +00:00
|
|
|
|
public Task<bool> IsMatch(IRoom? mainRoom, IRoom newRoom)
|
2024-04-28 13:55:19 +00:00
|
|
|
|
{
|
2024-05-08 10:22:04 +00:00
|
|
|
|
if (mainRoom == null)
|
2024-04-28 13:55:19 +00:00
|
|
|
|
{
|
2024-05-08 10:22:04 +00:00
|
|
|
|
return Task.FromResult(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var roomSlots = mainRoom.RoomSlots;
|
|
|
|
|
if (roomSlots == null)
|
|
|
|
|
{
|
|
|
|
|
return Task.FromResult(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var newRoomSlots = newRoom.RoomSlots;
|
|
|
|
|
if (newRoomSlots == null)
|
|
|
|
|
{
|
|
|
|
|
return Task.FromResult(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var mainRoomSlot in roomSlots)
|
|
|
|
|
{
|
|
|
|
|
if (mainRoomSlot == null || mainRoomSlot.Matched)
|
2024-04-28 13:55:19 +00:00
|
|
|
|
{
|
|
|
|
|
//如果已经匹配过了,就不再匹配
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-08 10:22:04 +00:00
|
|
|
|
foreach (var newRoomSlot in newRoomSlots)
|
2024-04-28 13:55:19 +00:00
|
|
|
|
{
|
2024-05-08 10:22:04 +00:00
|
|
|
|
if (newRoomSlot == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-28 13:55:19 +00:00
|
|
|
|
if (newRoomSlot.Matched)
|
|
|
|
|
{
|
|
|
|
|
//如果已经匹配过了,就不再匹配
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-05-08 10:22:04 +00:00
|
|
|
|
|
2024-04-28 13:55:19 +00:00
|
|
|
|
if (mainRoomSlot.IsHorizontal != newRoomSlot.IsHorizontal)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mainRoomSlot.Length != newRoomSlot.Length)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var distanceToMidpointOfRoom = mainRoomSlot.DistanceToMidpointOfRoom;
|
|
|
|
|
var newDistanceToMidpointOfRoom = newRoomSlot.DistanceToMidpointOfRoom;
|
2024-05-08 10:22:04 +00:00
|
|
|
|
if (distanceToMidpointOfRoom == null || newDistanceToMidpointOfRoom == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-28 13:55:19 +00:00
|
|
|
|
if (distanceToMidpointOfRoom[0] == newDistanceToMidpointOfRoom[0] &&
|
|
|
|
|
distanceToMidpointOfRoom[1] == newDistanceToMidpointOfRoom[1])
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mainRoomSlot.Matched = true;
|
|
|
|
|
newRoomSlot.Matched = true;
|
|
|
|
|
_lastMatchedMainSlot = mainRoomSlot;
|
|
|
|
|
_lastMatchedMinorSlot = newRoomSlot;
|
2024-05-08 10:22:04 +00:00
|
|
|
|
return Task.FromResult(true);
|
2024-04-28 13:55:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-08 10:22:04 +00:00
|
|
|
|
return Task.FromResult(false);
|
2024-04-28 13:55:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-08 10:22:04 +00:00
|
|
|
|
public RoomSlot? LastMatchedMainSlot => _lastMatchedMainSlot;
|
|
|
|
|
public RoomSlot? LastMatchedMinorSlot => _lastMatchedMinorSlot;
|
2024-04-28 13:55:19 +00:00
|
|
|
|
}
|