Ejemplo n.º 1
0
        public LocationTypeChange(string currentType, XElement element)
        {
            ChangeToType     = element.GetAttributeString("type", "");
            Probability      = element.GetAttributeFloat("probability", 1.0f);
            RequiredDuration = element.GetAttributeInt("requiredduration", 0);

            DisallowedAdjacentLocations = element.GetAttributeStringArray("disallowedadjacentlocations", new string[0]).ToList();
            RequiredAdjacentLocations   = element.GetAttributeStringArray("requiredadjacentlocations", new string[0]).ToList();

            Messages = TextManager.GetAll("LocationChange." + currentType + ".ChangeTo." + ChangeToType);
        }
Ejemplo n.º 2
0
        public LocationTypeChange(string currentType, XElement element, bool requireChangeMessages, float defaultProbability = 0.0f)
        {
            CurrentType  = currentType;
            ChangeToType = element.GetAttributeString("type", element.GetAttributeString("to", ""));

            RequireDiscovered = element.GetAttributeBool("requirediscovered", false);

            DisallowedAdjacentLocations = element.GetAttributeStringArray("disallowedadjacentlocations", new string[0]).ToList();
            DisallowedProximity         = Math.Max(element.GetAttributeInt("disallowedproximity", 1), 1);

            RequiredDurationRange = element.GetAttributePoint("requireddurationrange", Point.Zero);

            Probability = element.GetAttributeFloat("probability", defaultProbability);

            CooldownAfterChange = Math.Max(element.GetAttributeInt("cooldownafterchange", 0), 0);

            //backwards compatibility
            if (element.Attribute("requiredlocations") != null)
            {
                Requirements.Add(new Requirement(element, this));
            }

            //backwards compatibility
            if (element.Attribute("requiredduration") != null)
            {
                RequiredDurationRange = new Point(element.GetAttributeInt("requiredduration", 0));
            }

            string messageTag = element.GetAttributeString("messagetag", "LocationChange." + currentType + ".ChangeTo." + ChangeToType);

            Messages = TextManager.GetAll(messageTag);
            if (Messages == null)
            {
                if (requireChangeMessages)
                {
                    DebugConsole.ThrowError("No messages defined for the location type change " + currentType + " -> " + ChangeToType);
                }
                Messages = new List <string>();
            }

            foreach (XElement subElement in element.Elements())
            {
                if (subElement.Name.ToString().Equals("requirement", StringComparison.OrdinalIgnoreCase))
                {
                    Requirements.Add(new Requirement(subElement, this));
                }
            }
        }
Ejemplo n.º 3
0
        public LocationTypeChange(string currentType, XElement element)
        {
            ChangeToType = element.GetAttributeString("type", "");
            Probability  = element.GetAttributeFloat("probability", 1.0f);

            RequireDiscovered = element.GetAttributeBool("requirediscovered", false);

            RequiredLocations                       = element.GetAttributeStringArray("requiredlocations", element.GetAttributeStringArray("requiredadjacentlocations", new string[0])).ToList();
            RequiredProximity                       = Math.Max(element.GetAttributeInt("requiredproximity", 1), 1);
            ProximityProbabilityIncrease            = element.GetAttributeFloat("proximityprobabilityincrease", 0.0f);
            RequiredProximityForProbabilityIncrease = element.GetAttributeInt("requiredproximityforprobabilityincrease", -1);


            if (RequiredProximityForProbabilityIncrease > 0 || ProximityProbabilityIncrease > 0.0f)
            {
                if (!RequiredLocations.Any())
                {
                    DebugConsole.AddWarning(
                        $"Invalid location type change in location type \"{currentType}\". " +
                        "Probability is configured to increase when near some other type of location, but the RequiredLocations attribute is not set.");
                }
                if (Probability >= 1.0f)
                {
                    DebugConsole.AddWarning(
                        $"Invalid location type change in location type \"{currentType}\". " +
                        "Probability is configured to increase when near some other type of location, but the base probability is already 100%");
                }
            }

            DisallowedAdjacentLocations = element.GetAttributeStringArray("disallowedadjacentlocations", new string[0]).ToList();
            DisallowedProximity         = Math.Max(element.GetAttributeInt("disallowedproximity", 1), 1);

            RequiredDurationRange = element.GetAttributePoint("requireddurationrange", Point.Zero);
            //backwards compatibility
            if (element.Attribute("requiredduration") != null)
            {
                RequiredDurationRange = new Point(element.GetAttributeInt("requiredduration", 0));
            }

            string messageTag = element.GetAttributeString("messagetag", "LocationChange." + currentType + ".ChangeTo." + ChangeToType);

            Messages = TextManager.GetAll(messageTag);
            if (Messages == null)
            {
                DebugConsole.ThrowError("No messages defined for the location type change " + currentType + " -> " + ChangeToType);
            }
        }
Ejemplo n.º 4
0
        public LocationTypeChange(string currentType, XElement element)
        {
            ChangeToType     = element.GetAttributeString("type", "");
            Probability      = element.GetAttributeFloat("probability", 1.0f);
            RequiredDuration = element.GetAttributeInt("requiredduration", 0);

            DisallowedAdjacentLocations = element.GetAttributeStringArray("disallowedadjacentlocations", new string[0]).ToList();
            RequiredAdjacentLocations   = element.GetAttributeStringArray("requiredadjacentlocations", new string[0]).ToList();

            string messageTag = element.GetAttributeString("messagetag", "LocationChange." + currentType + ".ChangeTo." + ChangeToType);

            Messages = TextManager.GetAll(messageTag);
            if (Messages == null)
            {
                DebugConsole.ThrowError("No messages defined for the location type change " + currentType + " -> " + ChangeToType);
            }
        }
Ejemplo n.º 5
0
        private LocationType(XElement element)
        {
            Identifier    = element.GetAttributeString("identifier", element.Name.ToString());
            Name          = TextManager.Get("LocationName." + Identifier);
            nameFormats   = TextManager.GetAll("LocationNameFormat." + Identifier);
            UseInMainMenu = element.GetAttributeBool("useinmainmenu", false);

            string nameFile = element.GetAttributeString("namefile", "Content/Map/locationNames.txt");

            try
            {
                names = File.ReadAllLines(nameFile).ToList();
            }
            catch (Exception e)
            {
                DebugConsole.ThrowError("Failed to read name file for location type \"" + Identifier + "\"!", e);
                names = new List <string>()
                {
                    "Name file not found"
                };
            }

            string[] commonnessPerZoneStrs = element.GetAttributeStringArray("commonnessperzone", new string[] { "" });
            foreach (string commonnessPerZoneStr in commonnessPerZoneStrs)
            {
                string[] splitCommonnessPerZone = commonnessPerZoneStr.Split(':');
                if (splitCommonnessPerZone.Length != 2 ||
                    !int.TryParse(splitCommonnessPerZone[0].Trim(), out int zoneIndex) ||
                    !float.TryParse(splitCommonnessPerZone[1].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out float zoneCommonness))
                {
                    DebugConsole.ThrowError("Failed to read commonness values for location type \"" + Identifier + "\" - commonness should be given in the format \"zone0index: zone0commonness, zone1index: zone1commonness\"");
                    break;
                }
                CommonnessPerZone[zoneIndex] = zoneCommonness;
            }

            hireableJobs = new List <Tuple <JobPrefab, float> >();
            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "hireable":
                    string    jobIdentifier = subElement.GetAttributeString("identifier", "");
                    JobPrefab jobPrefab     = null;
                    if (jobIdentifier == "")
                    {
                        DebugConsole.ThrowError("Error in location type \"" + Identifier + "\" - hireable jobs should be configured using identifiers instead of names.");
                        jobIdentifier = subElement.GetAttributeString("name", "");
                        jobPrefab     = JobPrefab.List.Find(jp => jp.Name.ToLowerInvariant() == jobIdentifier.ToLowerInvariant());
                    }
                    else
                    {
                        jobPrefab = JobPrefab.List.Find(jp => jp.Identifier.ToLowerInvariant() == jobIdentifier.ToLowerInvariant());
                    }
                    if (jobPrefab == null)
                    {
                        DebugConsole.ThrowError("Error in  in location type " + Identifier + " - could not find a job with the identifier \"" + jobIdentifier + "\".");
                        continue;
                    }
                    float jobCommonness = subElement.GetAttributeFloat("commonness", 1.0f);
                    totalHireableWeight += jobCommonness;
                    Tuple <JobPrefab, float> hireableJob = new Tuple <JobPrefab, float>(jobPrefab, jobCommonness);
                    hireableJobs.Add(hireableJob);
                    break;

                case "symbol":
                    symbolSprite = new Sprite(subElement);
                    SpriteColor  = subElement.GetAttributeColor("color", Color.White);
                    break;

                case "changeto":
                    CanChangeTo.Add(new LocationTypeChange(Identifier, subElement));
                    break;

                case "portrait":
                    var portrait = new Sprite(subElement, lazyLoad: true);
                    if (portrait != null)
                    {
                        portraits.Add(portrait);
                    }
                    break;
                }
            }
        }
Ejemplo n.º 6
0
        private LocationType(XElement element)
        {
            Identifier = element.GetAttributeString("identifier", element.Name.ToString());
            Name       = TextManager.Get("LocationName." + Identifier, fallBackTag: "unknown");

            BeaconStationChance = element.GetAttributeFloat("beaconstationchance", 0.0f);

            NameFormats   = TextManager.GetAll("LocationNameFormat." + Identifier);
            UseInMainMenu = element.GetAttributeBool("useinmainmenu", false);
            HasOutpost    = element.GetAttributeBool("hasoutpost", true);
            IsEnterable   = element.GetAttributeBool("isenterable", HasOutpost);

            MissionIdentifiers = element.GetAttributeStringArray("missionidentifiers", new string[0]).ToList();
            MissionTags        = element.GetAttributeStringArray("missiontags", new string[0]).ToList();

            HideEntitySubcategories = element.GetAttributeStringArray("hideentitysubcategories", new string[0]).ToList();

            ReplaceInRadiation = element.GetAttributeString(nameof(ReplaceInRadiation).ToLower(), "");

            string teamStr = element.GetAttributeString("outpostteam", "FriendlyNPC");

            Enum.TryParse(teamStr, out OutpostTeam);

            string nameFile = element.GetAttributeString("namefile", "Content/Map/locationNames.txt");

            try
            {
                names = File.ReadAllLines(nameFile).ToList();
            }
            catch (Exception e)
            {
                DebugConsole.ThrowError("Failed to read name file for location type \"" + Identifier + "\"!", e);
                names = new List <string>()
                {
                    "Name file not found"
                };
            }

            string[] commonnessPerZoneStrs = element.GetAttributeStringArray("commonnessperzone", new string[] { "" });
            foreach (string commonnessPerZoneStr in commonnessPerZoneStrs)
            {
                string[] splitCommonnessPerZone = commonnessPerZoneStr.Split(':');
                if (splitCommonnessPerZone.Length != 2 ||
                    !int.TryParse(splitCommonnessPerZone[0].Trim(), out int zoneIndex) ||
                    !float.TryParse(splitCommonnessPerZone[1].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out float zoneCommonness))
                {
                    DebugConsole.ThrowError("Failed to read commonness values for location type \"" + Identifier + "\" - commonness should be given in the format \"zone0index: zone0commonness, zone1index: zone1commonness\"");
                    break;
                }
                CommonnessPerZone[zoneIndex] = zoneCommonness;
            }

            hireableJobs = new List <Tuple <JobPrefab, float> >();
            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "hireable":
                    string    jobIdentifier = subElement.GetAttributeString("identifier", "");
                    JobPrefab jobPrefab     = null;
                    if (jobIdentifier == "")
                    {
                        DebugConsole.ThrowError("Error in location type \"" + Identifier + "\" - hireable jobs should be configured using identifiers instead of names.");
                    }
                    else
                    {
                        jobPrefab = JobPrefab.Get(jobIdentifier.ToLowerInvariant());
                    }
                    if (jobPrefab == null)
                    {
                        DebugConsole.ThrowError("Error in  in location type " + Identifier + " - could not find a job with the identifier \"" + jobIdentifier + "\".");
                        continue;
                    }
                    float jobCommonness = subElement.GetAttributeFloat("commonness", 1.0f);
                    totalHireableWeight += jobCommonness;
                    Tuple <JobPrefab, float> hireableJob = new Tuple <JobPrefab, float>(jobPrefab, jobCommonness);
                    hireableJobs.Add(hireableJob);
                    break;

                case "symbol":
                    Sprite      = new Sprite(subElement, lazyLoad: true);
                    SpriteColor = subElement.GetAttributeColor("color", Color.White);
                    break;

                case "radiationsymbol":
                    RadiationSprite = new Sprite(subElement, lazyLoad: true);
                    break;

                case "changeto":
                    CanChangeTo.Add(new LocationTypeChange(Identifier, subElement, requireChangeMessages: true));
                    break;

                case "portrait":
                    var portrait = new Sprite(subElement, lazyLoad: true);
                    if (portrait != null)
                    {
                        portraits.Add(portrait);
                    }
                    break;
                }
            }
        }