Beispiel #1
0
        public void Run(Action <string> emitError, Action <string> emitWarning, ModData modData, Map map)
        {
            var playerNames = new MapPlayers(map.PlayerDefinitions).Players.Values
                              .Select(p => p.Name)
                              .ToHashSet();

            // Check for actors that require specific owners
            var actorsWithRequiredOwner = map.Rules.Actors
                                          .Where(a => a.Value.HasTraitInfo <RequiresSpecificOwnersInfo>())
                                          .ToDictionary(a => a.Key, a => a.Value.TraitInfo <RequiresSpecificOwnersInfo>());

            foreach (var kv in map.ActorDefinitions)
            {
                var actorReference = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
                var ownerInit      = actorReference.GetOrDefault <OwnerInit>();
                if (ownerInit == null)
                {
                    emitError("Actor {0} is not owned by any player.".F(kv.Key));
                }
                else
                {
                    var ownerName = ownerInit.InternalName;
                    if (!playerNames.Contains(ownerName))
                    {
                        emitError("Actor {0} is owned by unknown player {1}.".F(kv.Key, ownerName));
                    }

                    if (actorsWithRequiredOwner.TryGetValue(kv.Value.Value, out var info))
                    {
                        if (!info.ValidOwnerNames.Contains(ownerName))
                        {
                            emitError("Actor {0} owner {1} is not one of ValidOwnerNames: {2}".F(kv.Key, ownerName, info.ValidOwnerNames.JoinWith(", ")));
                        }
                    }
                }
            }
        }