Always have ActorReference string on optional arrays instantiated

This commit is contained in:
Gustas
2023-06-11 22:38:12 +03:00
committed by Matthias Mailänder
parent ed395c8ace
commit 99226c3df5

View File

@@ -9,6 +9,7 @@
*/ */
#endregion #endregion
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Primitives; using OpenRA.Primitives;
@@ -29,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits
[ActorReference] [ActorReference]
[Desc("Actors to spawn on sell. Be sure to use lowercase.")] [Desc("Actors to spawn on sell. Be sure to use lowercase.")]
public readonly string[] GuaranteedActorTypes = null; public readonly string[] GuaranteedActorTypes = Array.Empty<string>();
[Desc("Spawns actors only if the selling player's faction is in this list. " + [Desc("Spawns actors only if the selling player's faction is in this list. " +
"Leave empty to allow all factions by default.")] "Leave empty to allow all factions by default.")]
@@ -80,18 +81,18 @@ namespace OpenRA.Mods.Common.Traits
if (eligibleLocations.Count == 0) if (eligibleLocations.Count == 0)
return; return;
var guaranteedActorTypes = Info.GuaranteedActorTypes?.Select(a => if (Info.GuaranteedActorTypes.Length > 0)
{ {
var av = self.World.Map.Rules.Actors[a].TraitInfoOrDefault<ValuedInfo>(); var guaranteedActorTypes = Info.GuaranteedActorTypes.Select(a =>
return new
{ {
Name = a, var av = self.World.Map.Rules.Actors[a].TraitInfoOrDefault<ValuedInfo>();
Cost = av?.Cost ?? 0 return new
}; {
}).ToList(); Name = a,
Cost = av?.Cost ?? 0
};
}).ToList();
if (guaranteedActorTypes != null)
{
while (eligibleLocations.Count > 0 && guaranteedActorTypes.Count > 0) while (eligibleLocations.Count > 0 && guaranteedActorTypes.Count > 0)
{ {
var at = guaranteedActorTypes.Random(self.World.SharedRandom); var at = guaranteedActorTypes.Random(self.World.SharedRandom);
@@ -107,10 +108,10 @@ namespace OpenRA.Mods.Common.Traits
new OwnerInit(self.Owner), new OwnerInit(self.Owner),
})); }));
} }
}
if (eligibleLocations.Count == 0) if (eligibleLocations.Count == 0)
return; return;
}
var actorTypes = Info.ActorTypes.Select(a => var actorTypes = Info.ActorTypes.Select(a =>
{ {