Traveller/scripts/map/slotsMatcher/RoomSlotsMatcher.cs

89 lines
2.6 KiB
C#
Raw Normal View History

2024-04-28 13:55:19 +00:00
using System.Threading.Tasks;
using ColdMint.scripts.map.dateBean;
using ColdMint.scripts.map.interfaces;
using ColdMint.scripts.map.room;
2024-04-28 13:55:19 +00:00
namespace ColdMint.scripts.map.slotsMatcher;
public class RoomSlotsMatcher : IRoomSlotsMatcher
{
private RoomSlot? _lastMatchedMainSlot;
private RoomSlot? _lastMatchedMinorSlot;
2024-04-28 13:55:19 +00:00
public Task<bool> IsMatch(Room? mainRoom, Room newRoom)
2024-04-28 13:55:19 +00:00
{
if (mainRoom == null)
2024-04-28 13:55:19 +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;
}
foreach (var newRoomSlot in newRoomSlots)
2024-04-28 13:55:19 +00:00
{
if (newRoomSlot == null)
{
continue;
}
2024-04-28 13:55:19 +00:00
if (newRoomSlot.Matched)
{
//如果已经匹配过了,就不再匹配
continue;
}
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;
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;
return Task.FromResult(true);
2024-04-28 13:55:19 +00:00
}
}
return Task.FromResult(false);
2024-04-28 13:55:19 +00:00
}
public RoomSlot? LastMatchedMainSlot => _lastMatchedMainSlot;
public RoomSlot? LastMatchedMinorSlot => _lastMatchedMinorSlot;
2024-04-28 13:55:19 +00:00
}