219 lines
6.9 KiB
C#
219 lines
6.9 KiB
C#
/*
|
||
* @Author: 白哉
|
||
* @Description:
|
||
* @Date: 2025年09月05日 星期五 15:09:09
|
||
* @Modify:
|
||
*/
|
||
|
||
|
||
using System.Collections.Generic;
|
||
using Logic.CrashSight;
|
||
using MemoryPack;
|
||
using RuntimeData;
|
||
using TH1_Logic.Collect;
|
||
|
||
|
||
namespace TH1_Logic.MatchConfig
|
||
{
|
||
public enum MatchSettlementType
|
||
{
|
||
None = 0,
|
||
Domination = 1,
|
||
Perfect = 2,
|
||
Tutor = 3,
|
||
Story = 4,
|
||
}
|
||
|
||
|
||
[MemoryPackable]
|
||
public partial class MatchSettlementInfo
|
||
{
|
||
public MatchSettlementType SettlementType;
|
||
public bool IsFinished;
|
||
public Dictionary<uint, PlayerSettlementGroup> PlayerSettlements;
|
||
|
||
|
||
[MemoryPackConstructor]
|
||
public MatchSettlementInfo()
|
||
{
|
||
IsFinished = false;
|
||
PlayerSettlements = new Dictionary<uint, PlayerSettlementGroup>();
|
||
}
|
||
|
||
public void Init(MapData map, MapConfig config)
|
||
{
|
||
SettlementType = config.MatchSettlement;
|
||
PlayerSettlements ??= new Dictionary<uint, PlayerSettlementGroup>();
|
||
PlayerSettlements.Clear();
|
||
foreach (var player in map.PlayerMap.PlayerDataList)
|
||
{
|
||
PlayerSettlements[player.Id] = new PlayerSettlementGroup();
|
||
PlayerSettlements[player.Id].Init(config.PlayerSettlements);
|
||
}
|
||
}
|
||
|
||
public bool IsWin(uint id)
|
||
{
|
||
if (!IsFinished) return false;
|
||
var settlementGroup = PlayerSettlements.GetValueOrDefault(id);
|
||
if (settlementGroup == null) return false;
|
||
return settlementGroup.IsWin;
|
||
}
|
||
|
||
public MatchSettlementInfo(MatchSettlementInfo copyData)
|
||
{
|
||
SettlementType = copyData.SettlementType;
|
||
IsFinished = copyData.IsFinished;
|
||
PlayerSettlements = new Dictionary<uint, PlayerSettlementGroup>();
|
||
foreach (var kv in copyData.PlayerSettlements)
|
||
{
|
||
PlayerSettlements[kv.Key] = new PlayerSettlementGroup(kv.Value);
|
||
}
|
||
}
|
||
|
||
public void DeepCopy(MatchSettlementInfo copyData)
|
||
{
|
||
SettlementType = copyData.SettlementType;
|
||
IsFinished = copyData.IsFinished;
|
||
PlayerSettlements ??= new Dictionary<uint, PlayerSettlementGroup>();
|
||
PlayerSettlements.Clear();
|
||
foreach (var kv in copyData.PlayerSettlements)
|
||
{
|
||
PlayerSettlements[kv.Key] = new PlayerSettlementGroup(kv.Value);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
public class MatchSettlementLogicFactory
|
||
{
|
||
private static Dictionary<MatchSettlementType, IMatchSettlement> _logicDict = new Dictionary<MatchSettlementType, IMatchSettlement>()
|
||
{
|
||
{ MatchSettlementType.Domination, new DominationMatchSettlement() },
|
||
{ MatchSettlementType.Perfect, new PerfectMatchSettlement() },
|
||
{ MatchSettlementType.Tutor, new TutorMatchSettlement() },
|
||
{ MatchSettlementType.Story, new StoryMatchSettlement() },
|
||
};
|
||
|
||
public static void RefreshMatchSettlementInfo(MapData map)
|
||
{
|
||
if (!_logicDict.TryGetValue(map.MatchSettlement.SettlementType, out var logic))
|
||
{
|
||
LogSystem.LogError($"RefreshPlayerSettlementInfo Error TaskType:{map.MatchSettlement.SettlementType} No Logic");
|
||
return;
|
||
}
|
||
|
||
foreach (var kv in map.MatchSettlement.PlayerSettlements)
|
||
{
|
||
var player = map.PlayerMap.GetPlayerData(kv.Key);
|
||
if (player == null)
|
||
{
|
||
LogSystem.LogError($"RefreshMatchSettlementInfo Error Player is null");
|
||
continue;
|
||
}
|
||
PlayerSettlementGroup.RefreshPlayerSettlementGroup(map, player, kv.Value);
|
||
}
|
||
logic.Refresh(map, map.MatchSettlement);
|
||
}
|
||
}
|
||
|
||
|
||
public abstract class IMatchSettlement
|
||
{
|
||
public abstract MatchSettlementType GetSettlementType();
|
||
public abstract void Refresh(MapData map, MatchSettlementInfo info);
|
||
}
|
||
|
||
|
||
// DOMINATION 任意玩家结算且为胜,游戏结束 所有非AI玩家结算且均为败,游戏结束
|
||
public class DominationMatchSettlement : IMatchSettlement
|
||
{
|
||
public override MatchSettlementType GetSettlementType()
|
||
{
|
||
return MatchSettlementType.Domination;
|
||
}
|
||
|
||
public override void Refresh(MapData map, MatchSettlementInfo info)
|
||
{
|
||
if (info.IsFinished) return;
|
||
foreach (var kv in info.PlayerSettlements)
|
||
{
|
||
if (kv.Value.IsSettlement && kv.Value.IsWin)
|
||
{
|
||
info.IsFinished = true;
|
||
return;
|
||
}
|
||
}
|
||
foreach (var kv in info.PlayerSettlements)
|
||
{
|
||
if (map.CheckIsAI(kv.Key)) continue;
|
||
if (kv.Value.IsSettlement && !kv.Value.IsWin) continue;
|
||
return;
|
||
}
|
||
info.IsFinished = true;
|
||
}
|
||
}
|
||
|
||
// PERFECT 所有非AI玩家均结算后,游戏结束
|
||
public class PerfectMatchSettlement : IMatchSettlement
|
||
{
|
||
public override MatchSettlementType GetSettlementType()
|
||
{
|
||
return MatchSettlementType.Perfect;
|
||
}
|
||
|
||
public override void Refresh(MapData map, MatchSettlementInfo info)
|
||
{
|
||
if (info.IsFinished) return;
|
||
foreach (var kv in info.PlayerSettlements)
|
||
{
|
||
if (map.CheckIsAI(kv.Key)) continue;
|
||
if (kv.Value.IsSettlement) continue;
|
||
return;
|
||
}
|
||
info.IsFinished = true;
|
||
}
|
||
}
|
||
|
||
// SideTaskConfig 不影响 不参与
|
||
public class TutorMatchSettlement : IMatchSettlement
|
||
{
|
||
public override MatchSettlementType GetSettlementType()
|
||
{
|
||
return MatchSettlementType.Tutor;
|
||
}
|
||
|
||
public override void Refresh(MapData map, MatchSettlementInfo info)
|
||
{
|
||
if (info.IsFinished) return;
|
||
foreach (var kv in info.PlayerSettlements)
|
||
{
|
||
if (map.CheckIsAI(kv.Key)) continue;
|
||
if (kv.Value.IsSettlement) continue;
|
||
return;
|
||
}
|
||
info.IsFinished = true;
|
||
}
|
||
}
|
||
|
||
// TutorTaskConfig 若所有List<Task>完成,当前玩家结算 不参与
|
||
public class StoryMatchSettlement : IMatchSettlement
|
||
{
|
||
public override MatchSettlementType GetSettlementType()
|
||
{
|
||
return MatchSettlementType.Story;
|
||
}
|
||
|
||
public override void Refresh(MapData map, MatchSettlementInfo info)
|
||
{
|
||
if (info.IsFinished) return;
|
||
foreach (var kv in info.PlayerSettlements)
|
||
{
|
||
if (map.CheckIsAI(kv.Key)) continue;
|
||
if (kv.Value.IsSettlement) continue;
|
||
return;
|
||
}
|
||
info.IsFinished = true;
|
||
}
|
||
}
|
||
} |