S5-01 + S5-02 + S5-03
This commit is contained in:
@@ -8,7 +8,10 @@ namespace GeometryTD.Definition
|
||||
TowerMissing = 1,
|
||||
MissingMuzzleComponent = 2,
|
||||
MissingBearingComponent = 3,
|
||||
MissingBaseComponent = 4
|
||||
MissingBaseComponent = 4,
|
||||
BrokenMuzzleComponent = 5,
|
||||
BrokenBearingComponent = 6,
|
||||
BrokenBaseComponent = 7
|
||||
}
|
||||
|
||||
public sealed class CombatParticipantTowerValidationResult
|
||||
@@ -64,7 +67,7 @@ namespace GeometryTD.Definition
|
||||
};
|
||||
}
|
||||
|
||||
if (!HasComponent(inventory?.MuzzleComponents, tower.MuzzleComponentInstanceId))
|
||||
if (!TryGetComponentById(inventory?.MuzzleComponents, tower.MuzzleComponentInstanceId, out MuzzleCompItemData muzzleComponent))
|
||||
{
|
||||
return new CombatParticipantTowerValidationResult
|
||||
{
|
||||
@@ -74,7 +77,17 @@ namespace GeometryTD.Definition
|
||||
};
|
||||
}
|
||||
|
||||
if (!HasComponent(inventory?.BearingComponents, tower.BearingComponentInstanceId))
|
||||
if (muzzleComponent.Endurance <= 0f)
|
||||
{
|
||||
return new CombatParticipantTowerValidationResult
|
||||
{
|
||||
TowerInstanceId = tower.InstanceId,
|
||||
Tower = tower,
|
||||
FailureReason = CombatParticipantTowerValidationFailureReason.BrokenMuzzleComponent
|
||||
};
|
||||
}
|
||||
|
||||
if (!TryGetComponentById(inventory?.BearingComponents, tower.BearingComponentInstanceId, out BearingCompItemData bearingComponent))
|
||||
{
|
||||
return new CombatParticipantTowerValidationResult
|
||||
{
|
||||
@@ -84,7 +97,17 @@ namespace GeometryTD.Definition
|
||||
};
|
||||
}
|
||||
|
||||
if (!HasComponent(inventory?.BaseComponents, tower.BaseComponentInstanceId))
|
||||
if (bearingComponent.Endurance <= 0f)
|
||||
{
|
||||
return new CombatParticipantTowerValidationResult
|
||||
{
|
||||
TowerInstanceId = tower.InstanceId,
|
||||
Tower = tower,
|
||||
FailureReason = CombatParticipantTowerValidationFailureReason.BrokenBearingComponent
|
||||
};
|
||||
}
|
||||
|
||||
if (!TryGetComponentById(inventory?.BaseComponents, tower.BaseComponentInstanceId, out BaseCompItemData baseComponent))
|
||||
{
|
||||
return new CombatParticipantTowerValidationResult
|
||||
{
|
||||
@@ -94,6 +117,16 @@ namespace GeometryTD.Definition
|
||||
};
|
||||
}
|
||||
|
||||
if (baseComponent.Endurance <= 0f)
|
||||
{
|
||||
return new CombatParticipantTowerValidationResult
|
||||
{
|
||||
TowerInstanceId = tower.InstanceId,
|
||||
Tower = tower,
|
||||
FailureReason = CombatParticipantTowerValidationFailureReason.BrokenBaseComponent
|
||||
};
|
||||
}
|
||||
|
||||
return new CombatParticipantTowerValidationResult
|
||||
{
|
||||
TowerInstanceId = tower.InstanceId,
|
||||
@@ -165,9 +198,13 @@ namespace GeometryTD.Definition
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool HasComponent<TComponent>(IReadOnlyList<TComponent> components, long componentInstanceId)
|
||||
private static bool TryGetComponentById<TComponent>(
|
||||
IReadOnlyList<TComponent> components,
|
||||
long componentInstanceId,
|
||||
out TComponent resolvedComponent)
|
||||
where TComponent : TowerCompItemData
|
||||
{
|
||||
resolvedComponent = null;
|
||||
if (components == null || componentInstanceId <= 0)
|
||||
{
|
||||
return false;
|
||||
@@ -178,6 +215,7 @@ namespace GeometryTD.Definition
|
||||
TComponent component = components[i];
|
||||
if (component != null && component.InstanceId == componentInstanceId)
|
||||
{
|
||||
resolvedComponent = component;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user