S3-01 + S3-02
This commit is contained in:
@@ -0,0 +1,188 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace GeometryTD.Definition
|
||||
{
|
||||
public enum CombatParticipantTowerValidationFailureReason
|
||||
{
|
||||
None = 0,
|
||||
TowerMissing = 1,
|
||||
MissingMuzzleComponent = 2,
|
||||
MissingBearingComponent = 3,
|
||||
MissingBaseComponent = 4
|
||||
}
|
||||
|
||||
public sealed class CombatParticipantTowerValidationResult
|
||||
{
|
||||
public long TowerInstanceId { get; set; }
|
||||
|
||||
public bool IsValid => FailureReason == CombatParticipantTowerValidationFailureReason.None;
|
||||
|
||||
public CombatParticipantTowerValidationFailureReason FailureReason { get; set; }
|
||||
|
||||
public TowerItemData Tower { get; set; }
|
||||
}
|
||||
|
||||
public sealed class CombatParticipantTowerValidationSummary
|
||||
{
|
||||
public IReadOnlyList<TowerItemData> ValidTowers { get; set; } = System.Array.Empty<TowerItemData>();
|
||||
|
||||
public IReadOnlyList<CombatParticipantTowerValidationResult> InvalidResults { get; set; } =
|
||||
System.Array.Empty<CombatParticipantTowerValidationResult>();
|
||||
|
||||
public bool HasAnyValidParticipantTower => ValidTowers != null && ValidTowers.Count > 0;
|
||||
}
|
||||
|
||||
public static class CombatParticipantTowerValidationService
|
||||
{
|
||||
public static CombatParticipantTowerValidationResult ValidateTower(
|
||||
BackpackInventoryData inventory,
|
||||
long towerInstanceId)
|
||||
{
|
||||
if (!TryGetTowerById(inventory, towerInstanceId, out TowerItemData tower))
|
||||
{
|
||||
return new CombatParticipantTowerValidationResult
|
||||
{
|
||||
TowerInstanceId = towerInstanceId,
|
||||
FailureReason = CombatParticipantTowerValidationFailureReason.TowerMissing
|
||||
};
|
||||
}
|
||||
|
||||
return ValidateTower(inventory, tower);
|
||||
}
|
||||
|
||||
public static CombatParticipantTowerValidationResult ValidateTower(
|
||||
BackpackInventoryData inventory,
|
||||
TowerItemData tower)
|
||||
{
|
||||
if (tower == null || tower.InstanceId <= 0)
|
||||
{
|
||||
return new CombatParticipantTowerValidationResult
|
||||
{
|
||||
TowerInstanceId = tower != null ? tower.InstanceId : 0,
|
||||
Tower = tower,
|
||||
FailureReason = CombatParticipantTowerValidationFailureReason.TowerMissing
|
||||
};
|
||||
}
|
||||
|
||||
if (!HasComponent(inventory?.MuzzleComponents, tower.MuzzleComponentInstanceId))
|
||||
{
|
||||
return new CombatParticipantTowerValidationResult
|
||||
{
|
||||
TowerInstanceId = tower.InstanceId,
|
||||
Tower = tower,
|
||||
FailureReason = CombatParticipantTowerValidationFailureReason.MissingMuzzleComponent
|
||||
};
|
||||
}
|
||||
|
||||
if (!HasComponent(inventory?.BearingComponents, tower.BearingComponentInstanceId))
|
||||
{
|
||||
return new CombatParticipantTowerValidationResult
|
||||
{
|
||||
TowerInstanceId = tower.InstanceId,
|
||||
Tower = tower,
|
||||
FailureReason = CombatParticipantTowerValidationFailureReason.MissingBearingComponent
|
||||
};
|
||||
}
|
||||
|
||||
if (!HasComponent(inventory?.BaseComponents, tower.BaseComponentInstanceId))
|
||||
{
|
||||
return new CombatParticipantTowerValidationResult
|
||||
{
|
||||
TowerInstanceId = tower.InstanceId,
|
||||
Tower = tower,
|
||||
FailureReason = CombatParticipantTowerValidationFailureReason.MissingBaseComponent
|
||||
};
|
||||
}
|
||||
|
||||
return new CombatParticipantTowerValidationResult
|
||||
{
|
||||
TowerInstanceId = tower.InstanceId,
|
||||
Tower = tower,
|
||||
FailureReason = CombatParticipantTowerValidationFailureReason.None
|
||||
};
|
||||
}
|
||||
|
||||
public static CombatParticipantTowerValidationSummary ValidateParticipantTowers(BackpackInventoryData inventory)
|
||||
{
|
||||
List<TowerItemData> validTowers = new List<TowerItemData>();
|
||||
List<CombatParticipantTowerValidationResult> invalidResults =
|
||||
new List<CombatParticipantTowerValidationResult>();
|
||||
HashSet<long> processedTowerIds = new HashSet<long>();
|
||||
|
||||
if (inventory?.ParticipantTowerInstanceIds == null || inventory.ParticipantTowerInstanceIds.Count <= 0)
|
||||
{
|
||||
return new CombatParticipantTowerValidationSummary
|
||||
{
|
||||
ValidTowers = validTowers,
|
||||
InvalidResults = invalidResults
|
||||
};
|
||||
}
|
||||
|
||||
for (int i = 0; i < inventory.ParticipantTowerInstanceIds.Count; i++)
|
||||
{
|
||||
long towerInstanceId = inventory.ParticipantTowerInstanceIds[i];
|
||||
if (towerInstanceId <= 0 || !processedTowerIds.Add(towerInstanceId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
CombatParticipantTowerValidationResult result = ValidateTower(inventory, towerInstanceId);
|
||||
if (result.IsValid)
|
||||
{
|
||||
validTowers.Add(result.Tower);
|
||||
}
|
||||
else
|
||||
{
|
||||
invalidResults.Add(result);
|
||||
}
|
||||
}
|
||||
|
||||
return new CombatParticipantTowerValidationSummary
|
||||
{
|
||||
ValidTowers = validTowers,
|
||||
InvalidResults = invalidResults
|
||||
};
|
||||
}
|
||||
|
||||
private static bool TryGetTowerById(BackpackInventoryData inventory, long towerInstanceId, out TowerItemData tower)
|
||||
{
|
||||
tower = null;
|
||||
if (inventory?.Towers == null || towerInstanceId <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < inventory.Towers.Count; i++)
|
||||
{
|
||||
TowerItemData candidate = inventory.Towers[i];
|
||||
if (candidate != null && candidate.InstanceId == towerInstanceId)
|
||||
{
|
||||
tower = candidate;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool HasComponent<TComponent>(IReadOnlyList<TComponent> components, long componentInstanceId)
|
||||
where TComponent : TowerCompItemData
|
||||
{
|
||||
if (components == null || componentInstanceId <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < components.Count; i++)
|
||||
{
|
||||
TComponent component = components[i];
|
||||
if (component != null && component.InstanceId == componentInstanceId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a8f51ad44094d59af6618736cd6a0d3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace GeometryTD.Definition
|
||||
{
|
||||
public enum ParticipantTowerAssignFailureReason
|
||||
{
|
||||
None = 0,
|
||||
TowerMissing = 1,
|
||||
InvalidTower = 2,
|
||||
AlreadyAssigned = 3,
|
||||
ParticipantAreaFull = 4
|
||||
}
|
||||
|
||||
public sealed class ParticipantTowerAssignResult
|
||||
{
|
||||
public long TowerInstanceId { get; set; }
|
||||
|
||||
public bool IsSuccess => FailureReason == ParticipantTowerAssignFailureReason.None;
|
||||
|
||||
public ParticipantTowerAssignFailureReason FailureReason { get; set; }
|
||||
|
||||
public CombatParticipantTowerValidationFailureReason ValidationFailureReason { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00c667d942b94e23a4933fda5c5eaf8e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user