Exemplo n.º 1
0
        private void InitCharacters(Submarine submarine)
        {
            characters.Clear();
            characterItems.Clear();

            if (characterConfig == null)
            {
                return;
            }

            foreach (XElement element in characterConfig.Elements())
            {
                if (GameMain.NetworkMember == null && element.GetAttributeBool("multiplayeronly", false))
                {
                    continue;
                }

                int defaultCount = element.GetAttributeInt("count", -1);
                if (defaultCount < 0)
                {
                    defaultCount = element.GetAttributeInt("amount", 1);
                }
                int min   = Math.Min(element.GetAttributeInt("min", defaultCount), 255);
                int max   = Math.Min(Math.Max(min, element.GetAttributeInt("max", defaultCount)), 255);
                int count = Rand.Range(min, max + 1);

                if (element.Attribute("identifier") != null && element.Attribute("from") != null)
                {
                    string      characterIdentifier = element.GetAttributeString("identifier", "");
                    string      characterFrom       = element.GetAttributeString("from", "");
                    HumanPrefab humanPrefab         = NPCSet.Get(characterFrom, characterIdentifier);
                    if (humanPrefab == null)
                    {
                        DebugConsole.ThrowError("Couldn't spawn a character for abandoned outpost mission: character prefab \"" + characterIdentifier + "\" not found");
                        continue;
                    }
                    for (int i = 0; i < count; i++)
                    {
                        LoadHuman(humanPrefab, element, submarine);
                    }
                }
                else
                {
                    string speciesName     = element.GetAttributeString("character", element.GetAttributeString("identifier", ""));
                    var    characterPrefab = CharacterPrefab.FindBySpeciesName(speciesName);
                    if (characterPrefab == null)
                    {
                        DebugConsole.ThrowError("Couldn't spawn a character for abandoned outpost mission: character prefab \"" + speciesName + "\" not found");
                        continue;
                    }
                    for (int i = 0; i < count; i++)
                    {
                        LoadMonster(characterPrefab, element, submarine);
                    }
                }
            }
        }
        protected OutpostGenerationParams(XElement element, string filePath)
        {
            Identifier             = element.GetAttributeString("identifier", "");
            Name                   = element.GetAttributeString("name", Identifier);
            allowedLocationTypes   = element.GetAttributeStringArray("allowedlocationtypes", Array.Empty <string>()).ToList();
            SerializableProperties = SerializableProperty.DeserializeProperties(this, element);

            if (element == null)
            {
                return;
            }
            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "modulecount":
                    string moduleFlag = (subElement.GetAttributeString("flag", null) ?? subElement.GetAttributeString("moduletype", "")).ToLowerInvariant();
                    moduleCounts[moduleFlag] = subElement.GetAttributeInt("count", 0);
                    break;

                case "npcs":
                    humanPrefabLists.Add(new List <HumanPrefab>());
                    foreach (XElement npcElement in subElement.Elements())
                    {
                        string from = npcElement.GetAttributeString("from", string.Empty);

                        // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                        if (!string.IsNullOrWhiteSpace(from))
                        {
                            HumanPrefab prefab = NPCSet.Get(from, npcElement.GetAttributeString("identifier", string.Empty));
                            if (prefab != null)
                            {
                                humanPrefabLists.Last().Add(prefab);
                            }
                        }
                        else
                        {
                            humanPrefabLists.Last().Add(new HumanPrefab(npcElement, filePath));
                        }
                    }
                    break;
                }
            }
        }
Exemplo n.º 3
0
        // putting these here since both escort and pirate missions need them. could be tucked away into another class that they can inherit from (or use composition)
        protected HumanPrefab GetHumanPrefabFromElement(XElement element)
        {
            if (element.Attribute("name") != null)
            {
                DebugConsole.ThrowError("Error in mission \"" + Name + "\" - use character identifiers instead of names to configure the characters.");

                return(null);
            }

            string      characterIdentifier = element.GetAttributeString("identifier", "");
            string      characterFrom       = element.GetAttributeString("from", "");
            HumanPrefab humanPrefab         = NPCSet.Get(characterFrom, characterIdentifier);

            if (humanPrefab == null)
            {
                DebugConsole.ThrowError("Couldn't spawn character for mission: character prefab \"" + characterIdentifier + "\" not found");
                return(null);
            }

            return(humanPrefab);
        }