Steal cleanup (#24428)

- Fix datafield spelling
- Fix some code oddities
This commit is contained in:
metalgearsloth
2024-01-28 12:10:39 +11:00
committed by GitHub
parent 1e0310ff10
commit b1f9e25c13
4 changed files with 18 additions and 29 deletions

View File

@@ -20,7 +20,7 @@ public sealed partial class StealConditionComponent : Component
/// When enabled, disables generation of this target if there is no entity on the map (disable for objects that can be created mid-round). /// When enabled, disables generation of this target if there is no entity on the map (disable for objects that can be created mid-round).
/// </summary> /// </summary>
[DataField] [DataField]
public bool VerifyMapExistance = true; public bool VerifyMapExistence = true;
/// <summary> /// <summary>
/// If the target may be alive but has died, it will not be counted /// If the target may be alive but has died, it will not be counted

View File

@@ -42,17 +42,8 @@ public sealed class StealConditionSystem : EntitySystem
{ {
List<StealTargetComponent?> targetList = new(); List<StealTargetComponent?> targetList = new();
// cancel if invalid TargetStealName var query = AllEntityQuery<StealTargetComponent>();
var group = _proto.Index<StealTargetGroupPrototype>(condition.Comp.StealGroup); while (query.MoveNext(out var target))
if (group == null)
{
args.Cancelled = true;
Log.Error("StealTargetGroup invalid prototype!");
return;
}
var query = EntityQueryEnumerator<StealTargetComponent>();
while (query.MoveNext(out var uid, out var target))
{ {
if (condition.Comp.StealGroup != target.StealGroup) if (condition.Comp.StealGroup != target.StealGroup)
continue; continue;
@@ -61,17 +52,17 @@ public sealed class StealConditionSystem : EntitySystem
} }
// cancel if the required items do not exist // cancel if the required items do not exist
if (targetList.Count == 0 && condition.Comp.VerifyMapExistance) if (targetList.Count == 0 && condition.Comp.VerifyMapExistence)
{ {
args.Cancelled = true; args.Cancelled = true;
return; return;
} }
//setup condition settings //setup condition settings
var maxSize = condition.Comp.VerifyMapExistance var maxSize = condition.Comp.VerifyMapExistence
? Math.Min(targetList.Count, condition.Comp.MaxCollectionSize) ? Math.Min(targetList.Count, condition.Comp.MaxCollectionSize)
: condition.Comp.MaxCollectionSize; : condition.Comp.MaxCollectionSize;
var minSize = condition.Comp.VerifyMapExistance var minSize = condition.Comp.VerifyMapExistence
? Math.Min(targetList.Count, condition.Comp.MinCollectionSize) ? Math.Min(targetList.Count, condition.Comp.MinCollectionSize)
: condition.Comp.MinCollectionSize; : condition.Comp.MinCollectionSize;
@@ -102,15 +93,13 @@ public sealed class StealConditionSystem : EntitySystem
private float GetProgress(MindComponent mind, StealConditionComponent condition) private float GetProgress(MindComponent mind, StealConditionComponent condition)
{ {
if (!_metaQuery.TryGetComponent(mind.OwnedEntity, out var meta))
return 0;
if (!_containerQuery.TryGetComponent(mind.OwnedEntity, out var currentManager)) if (!_containerQuery.TryGetComponent(mind.OwnedEntity, out var currentManager))
return 0; return 0;
var stack = new Stack<ContainerManagerComponent>(); var stack = new Stack<ContainerManagerComponent>();
var count = 0; var count = 0;
//check pulling object //check pulling object
if (TryComp<SharedPullerComponent>(mind.OwnedEntity, out var pull)) //TO DO: to make the code prettier? don't like the repetition if (TryComp<SharedPullerComponent>(mind.OwnedEntity, out var pull)) //TO DO: to make the code prettier? don't like the repetition
{ {
var pullid = pull.Pulling; var pullid = pull.Pulling;
@@ -147,7 +136,7 @@ public sealed class StealConditionSystem : EntitySystem
} }
} while (stack.TryPop(out currentManager)); } while (stack.TryPop(out currentManager));
var result = (float) count / (float) condition.CollectionSize; var result = count / (float) condition.CollectionSize;
result = Math.Clamp(result, 0, 1); result = Math.Clamp(result, 0, 1);
return result; return result;
} }
@@ -166,7 +155,7 @@ public sealed class StealConditionSystem : EntitySystem
{ {
if (TryComp<MobStateComponent>(entity, out var state)) if (TryComp<MobStateComponent>(entity, out var state))
{ {
if (!_mobState.IsAlive(entity)) if (!_mobState.IsAlive(entity, state))
return false; return false;
} }
} }

View File

@@ -16,7 +16,7 @@
id: BaseThiefStealObjective id: BaseThiefStealObjective
components: components:
- type: StealCondition - type: StealCondition
verifyMapExistance: false verifyMapExistence: false
descriptionText: objective-condition-thief-description descriptionText: objective-condition-thief-description
- type: entity - type: entity
@@ -25,7 +25,7 @@
id: BaseThiefStealCollectionObjective id: BaseThiefStealCollectionObjective
components: components:
- type: StealCondition - type: StealCondition
verifyMapExistance: true verifyMapExistence: true
descriptionText: objective-condition-thief-description descriptionText: objective-condition-thief-description
- type: entity - type: entity
@@ -34,7 +34,7 @@
id: BaseThiefStealStructureObjective id: BaseThiefStealStructureObjective
components: components:
- type: StealCondition - type: StealCondition
verifyMapExistance: true verifyMapExistence: true
descriptionText: objective-condition-thief-description descriptionText: objective-condition-thief-description
- type: Objective - type: Objective
difficulty: 2 # it's hard to hide difficulty: 2 # it's hard to hide
@@ -45,7 +45,7 @@
id: BaseThiefStealAnimalObjective id: BaseThiefStealAnimalObjective
components: components:
- type: StealCondition - type: StealCondition
verifyMapExistance: false verifyMapExistence: false
checkAlive: true checkAlive: true
objectiveNoOwnerText: objective-condition-steal-title-alive-no-owner objectiveNoOwnerText: objective-condition-steal-title-alive-no-owner
descriptionText: objective-condition-thief-animal-description descriptionText: objective-condition-thief-animal-description
@@ -125,7 +125,7 @@
stealGroup: TechnologyDisk stealGroup: TechnologyDisk
minCollectionSize: 5 minCollectionSize: 5
maxCollectionSize: 15 maxCollectionSize: 15
verifyMapExistance: false verifyMapExistence: false
- type: Objective - type: Objective
difficulty: 0.8 difficulty: 0.8
@@ -138,7 +138,7 @@
stealGroup: IDCard stealGroup: IDCard
minCollectionSize: 5 minCollectionSize: 5
maxCollectionSize: 15 maxCollectionSize: 15
verifyMapExistance: false verifyMapExistence: false
- type: Objective - type: Objective
difficulty: 0.7 difficulty: 0.7
@@ -153,7 +153,7 @@
stealGroup: Cannabis stealGroup: Cannabis
minCollectionSize: 20 minCollectionSize: 20
maxCollectionSize: 30 maxCollectionSize: 30
verifyMapExistance: false verifyMapExistence: false
- type: Objective - type: Objective
difficulty: 0.5 difficulty: 0.5
@@ -169,7 +169,7 @@
stealGroup: LAMP stealGroup: LAMP
minCollectionSize: 1 minCollectionSize: 1
maxCollectionSize: 10 maxCollectionSize: 10
verifyMapExistance: true verifyMapExistence: true
- type: Objective - type: Objective
difficulty: 0.5 # just for fun, collectings LAMP on Moth difficulty: 0.5 # just for fun, collectings LAMP on Moth

View File

@@ -27,7 +27,7 @@
id: BaseTraitorStealObjective id: BaseTraitorStealObjective
components: components:
- type: StealCondition - type: StealCondition
verifyMapExistance: false verifyMapExistence: false
- type: Objective - type: Objective
difficulty: 2.75 difficulty: 2.75
- type: ObjectiveLimit - type: ObjectiveLimit