コード例 #1
0
        public static Dictionary <string, SnacksRosterResource> LoadFromAstronautData(ConfigNode node)
        {
            Dictionary <string, SnacksRosterResource> rosterResources = new Dictionary <string, SnacksRosterResource>();

            ConfigNode[]         resourceNodes = node.GetNodes(RosterResourceNode);
            double               value         = 0;
            SnacksRosterResource resource;
            SnacksRosterResource resourceDef;
            string               resourceName;

            for (int index = 0; index < resourceNodes.Length; index++)
            {
                resource = new SnacksRosterResource();

                resourceName = resourceNodes[index].GetValue(RosterResourceName);

                if (SnacksScenario.Instance.rosterResources.ContainsKey(resourceName))
                {
                    resourceDef             = SnacksScenario.Instance.rosterResources[resourceName];
                    resource.displayName    = resourceDef.displayName;
                    resource.statusFormat   = resourceDef.statusFormat;
                    resource.showInSnapshot = resourceDef.showInSnapshot;
                }

                double.TryParse(resourceNodes[index].GetValue(RosterResourceAmount), out value);
                resource.amount = value;

                double.TryParse(resourceNodes[index].GetValue(RosterResourceMaxAmount), out value);
                resource.maxAmount = value;

                rosterResources.Add(resourceName, resource);
            }

            return(rosterResources);
        }
コード例 #2
0
        public static Dictionary <string, SnacksRosterResource> LoadRosterResources()
        {
            Dictionary <string, SnacksRosterResource> rosterResources = new Dictionary <string, SnacksRosterResource>();

            ConfigNode[]         resourceNodes = GameDatabase.Instance.GetConfigNodes(RosterResourceNode);
            SnacksRosterResource resource;

            for (int index = 0; index < resourceNodes.Length; index++)
            {
                resource = new SnacksRosterResource(resourceNodes[index]);
                rosterResources.Add(resource.resourceName, resource);
            }

            return(rosterResources);
        }
コード例 #3
0
        /// <summary>
        /// Adds the roster resource to the kerbal if needed
        /// </summary>
        /// <param name="astronaut">The ProtoCrewMember to check.</param>
        public virtual void addResourceIfNeeded(ProtoCrewMember astronaut)
        {
            SnacksRosterResource resource;
            AstronautData        astronautData = SnacksScenario.Instance.GetAstronautData(astronaut);

            if (!astronautData.rosterResources.ContainsKey(resourceName))
            {
                resource                = new SnacksRosterResource();
                resource.displayName    = displayName;
                resource.resourceName   = resourceName;
                resource.showInSnapshot = showInSnapshot;
                resource.amount         = amount;
                resource.maxAmount      = maxAmount;

                astronautData.rosterResources.Add(resourceName, resource);
                SnacksScenario.Instance.SetAstronautData(astronautData);
            }
        }
コード例 #4
0
        public override void Initialize()
        {
            base.Initialize();

            //Replace the existing roster resource with a customized Stress version. We calculate max roster amount in the processor.
            SnacksRosterResource resource       = SnacksScenario.Instance.rosterResources[StressResourceName];
            StressRosterResource stressResource = new StressRosterResource();

            stressResource.resourceName             = resource.resourceName;
            stressResource.displayName              = resource.displayName;
            stressResource.amount                   = 0;
            stressResource.maxAmount                = 0;
            stressResource.experienceBonusAmount    = 0;
            stressResource.experienceBonusMaxAmount = resource.experienceBonusMaxAmount;
            SnacksScenario.Instance.rosterResources[StressResourceName] = stressResource;
            stressResource.statusFormat = resource.statusFormat;

            secondsPerCycle = SnacksScenario.GetSecondsPerDay();

            outcomes.Add(new OnStrikePenalty(StressConditionName, false, StressPlayerMessage));

            SnacksScenario.onRosterResourceUpdated.Add(onRosterResourceUpdated);
        }
コード例 #5
0
        protected void onRosterResourceUpdated(Vessel vessel, SnacksRosterResource rosterResource, AstronautData astronautData, ProtoCrewMember astronaut)
        {
            //Make sure it's a resource we're interested in.
            if (!rosterResource.resourceName.Contains(StressConditionName))
            {
                return;
            }

            //If the resource has gone down below max, then remove the stress condition.
            if (rosterResource.amount < rosterResource.maxAmount && astronautData.conditionSummary.Contains(StressConditionName))
            {
                astronautData.ClearCondition(StressConditionName);
                SnacksScenario.Instance.RestoreSkillsIfNeeded(astronaut);
                ScreenMessages.PostScreenMessage(astronaut.name + " " + StressRecoveryMessage, 5.0f, ScreenMessageStyle.UPPER_LEFT);
            }

            //If the resource has maxed out then add the stress condition
            else if (rosterResource.amount >= rosterResource.maxAmount && !astronautData.conditionSummary.Contains(StressConditionName))
            {
                astronautData.SetCondition(StressConditionName);
                SnacksScenario.Instance.RemoveSkillsIfNeeded(astronaut);
                ScreenMessages.PostScreenMessage(vessel.vesselName + ": " + astronaut.name + " " + StressPlayerMessage, 5.0f, ScreenMessageStyle.UPPER_LEFT);
            }
        }
コード例 #6
0
        /// <summary>
        /// Saves persistent astronaut data to the supplied config node.
        /// </summary>
        /// <param name="crewData">A map of astronaut data, keyed by kerbal name.</param>
        /// <param name="node">The ConfigNode to save the data to.</param>
        public static void Save(DictionaryValueList <string, AstronautData> crewData, ConfigNode node)
        {
            List <AstronautData> .Enumerator dataValues = crewData.GetListEnumerator();
            AstronautData astronautData;
            ConfigNode    configNode;
            ConfigNode    astronautNode;

            string[] keys;

            while (dataValues.MoveNext())
            {
                astronautData = dataValues.Current;
                astronautNode = new ConfigNode(AstronautNode);
                astronautNode.AddValue(AstronautNodeName, astronautData.name);
                astronautNode.AddValue(AstronautNodeTrait, astronautData.experienceTrait);
                astronautNode.AddValue(AstronautNodeUpdated, astronautData.lastUpdated);
                astronautNode.AddValue(AstronautNodeExempt, astronautData.isExempt);

                if (!string.IsNullOrEmpty(astronautData.conditionSummary))
                {
                    astronautNode.AddValue(AstronautNodeCondition, astronautData.conditionSummary);
                }

                if (!string.IsNullOrEmpty(astronautData.disqualifiedPreconditions))
                {
                    astronautNode.AddValue(AstronautNodeDisqualifiers, astronautData.disqualifiedPreconditions);
                }

                //Save keyvalue pairs
                keys = astronautData.keyValuePairs.Keys.ToArray();
                for (int index = 0; index < keys.Length; index++)
                {
                    configNode = new ConfigNode(KeyValueNode);
                    configNode.AddValue(KeyValuePairKey, keys[index]);
                    configNode.AddValue(KeyValuePairValue, astronautData.keyValuePairs[keys[index]]);
                    astronautNode.AddNode(configNode);
                }

                //Save resource process results
                keys = astronautData.processedResourceSuccesses.Keys.ToArray();
                for (int index = 0; index < keys.Length; index++)
                {
                    configNode = new ConfigNode(ResourceCounterNode);
                    configNode.AddValue(ResourceCounterName, keys[index]);
                    configNode.AddValue(ResourceCounterIsSuccess, true);
                    configNode.AddValue(ResourceCounterValue, astronautData.processedResourceSuccesses[keys[index]]);
                    astronautNode.AddNode(configNode);
                }

                keys = astronautData.processedResourceFailures.Keys.ToArray();
                for (int index = 0; index < keys.Length; index++)
                {
                    configNode = new ConfigNode(ResourceCounterNode);
                    configNode.AddValue(ResourceCounterName, keys[index]);
                    configNode.AddValue(ResourceCounterIsSuccess, false);
                    configNode.AddValue(ResourceCounterValue, astronautData.processedResourceFailures[keys[index]]);
                    astronautNode.AddNode(configNode);
                }

                //Save roster resources
                SnacksRosterResource.SaveToAstronautData(astronautData.rosterResources, astronautNode);

                node.AddNode(astronautNode);
            }
        }
コード例 #7
0
        /// <summary>
        /// Loads the astronaut data from the config node supplied.
        /// </summary>
        /// <returns>A map keyed kerbal name that contains astronaut data.</returns>
        /// <param name="node">The ConfigNode to read data from.</param>
        public static DictionaryValueList <string, AstronautData> Load(ConfigNode node)
        {
            DictionaryValueList <string, AstronautData> crewData = new DictionaryValueList <string, AstronautData>();

            ConfigNode[] astronautNodess = node.GetNodes(AstronautNode);

            foreach (ConfigNode astronautNode in astronautNodess)
            {
                try
                {
                    AstronautData astronautData = new AstronautData();

                    astronautData.name            = astronautNode.GetValue(AstronautNodeName);
                    astronautData.experienceTrait = astronautNode.GetValue(AstronautNodeTrait);
                    astronautData.lastUpdated     = double.Parse(astronautNode.GetValue(AstronautNodeUpdated));
                    astronautData.isExempt        = bool.Parse(astronautNode.GetValue(AstronautNodeExempt));

                    if (astronautNode.HasValue(AstronautNodeCondition))
                    {
                        astronautData.conditionSummary = astronautNode.GetValue(AstronautNodeCondition);
                    }

                    if (astronautNode.HasValue(AstronautNodeDisqualifiers))
                    {
                        astronautData.disqualifiedPreconditions = astronautNode.GetValue(AstronautNodeDisqualifiers);
                    }

                    //Key value pairs
                    astronautData.keyValuePairs = new DictionaryValueList <string, string>();
                    if (astronautNode.HasNode(KeyValueNode))
                    {
                        ConfigNode[] keyValuePairs = astronautNode.GetNodes(KeyValueNode);
                        foreach (ConfigNode keyValue in keyValuePairs)
                        {
                            astronautData.keyValuePairs.Add(keyValue.GetValue(KeyValuePairKey), keyValue.GetValue(KeyValuePairValue));
                        }
                    }

                    //Success/fail counters
                    if (astronautNode.HasNode(ResourceCounterNode))
                    {
                        ConfigNode[] resourceCounterNodes = astronautNode.GetNodes(ResourceCounterNode);
                        ConfigNode   counterNode;
                        string       resourceName = string.Empty;
                        int          count        = 0;
                        bool         isSuccess    = false;
                        for (int index = 0; index < resourceCounterNodes.Length; index++)
                        {
                            counterNode  = resourceCounterNodes[index];
                            resourceName = counterNode.GetValue(ResourceCounterName);
                            int.TryParse(counterNode.GetValue(ResourceCounterValue), out count);
                            isSuccess = false;
                            bool.TryParse(counterNode.GetValue(ResourceCounterIsSuccess), out isSuccess);

                            if (isSuccess)
                            {
                                astronautData.processedResourceSuccesses.Add(resourceName, count);
                            }
                            else
                            {
                                astronautData.processedResourceFailures.Add(resourceName, count);
                            }
                        }
                    }

                    //Roster resources
                    if (astronautNode.HasNode(SnacksRosterResource.RosterResourceNode))
                    {
                        astronautData.rosterResources = SnacksRosterResource.LoadFromAstronautData(astronautNode);
                    }

                    crewData.Add(astronautData.name, astronautData);
                }
                catch (Exception ex)
                {
                    Log("error encountered: " + ex + " skipping kerbal.");
                    continue;
                }
            }

            return(crewData);
        }
コード例 #8
0
        public override bool IsValid(ProtoCrewMember astronaut)
        {
            if (!base.IsValid(astronaut))
            {
                return(false);
            }
            if (string.IsNullOrEmpty(resourceName))
            {
                return(false);
            }

            //Get roster resource
            double amount     = 0;
            double maxAmount  = 0;
            double percentage = 0;

            if (isRosterResource)
            {
                AstronautData astronautData = SnacksScenario.Instance.GetAstronautData(astronaut);
                if (astronautData == null)
                {
                    return(false);
                }
                if (!astronautData.rosterResources.ContainsKey(resourceName))
                {
                    return(false);
                }

                SnacksRosterResource rosterResource = astronautData.rosterResources[resourceName];
                amount     = rosterResource.amount;
                maxAmount  = rosterResource.maxAmount;
                percentage = amount / maxAmount;
            }

            //Try to get vessel resource
            else
            {
                if (astronaut.KerbalRef == null || astronaut.KerbalRef.InVessel == null)
                {
                    return(false);
                }

                List <ProtoPartResourceSnapshot> protoPartResources = new List <ProtoPartResourceSnapshot>();
                ProcessedResource.GetResourceTotals(astronaut.KerbalRef.InVessel, resourceName, out amount, out maxAmount, protoPartResources);
                percentage = amount / maxAmount;
            }

            //Now perform the check
            if (checkMaxAmount)
            {
                amount = maxAmount;
            }
            else if (checkAsPercentage)
            {
                amount = percentage;
            }
            switch (checkType)
            {
            case CheckValueConditionals.checkEquals:
                return(amount.Equals(valueToCheck));

            case CheckValueConditionals.checkGreaterOrEqual:
                return(amount.Equals(valueToCheck) || amount > valueToCheck);

            case CheckValueConditionals.checkGreaterThan:
                return(amount > valueToCheck);

            case CheckValueConditionals.checkLesserOrEqual:
                return(amount.Equals(valueToCheck) || amount < valueToCheck);

            case CheckValueConditionals.checkLessThan:
                return(amount < valueToCheck);
            }

            return(false);
        }
コード例 #9
0
        public override void ApplyOutcome(Vessel vessel, SnacksProcessorResult result)
        {
            if (!isRosterResource && vessel != null)
            {
                List <ProtoPartResourceSnapshot> protoPartResources = new List <ProtoPartResourceSnapshot>();
                double vesselCurrentAmount = 0;
                double vesselMaxAmount     = 0;
                double demand = amount;

                //Select random amount if enabled
                if (randomMin != randomMax)
                {
                    demand = UnityEngine.Random.Range(randomMin, randomMax);
                }

                //Get current totals
                ProcessedResource.GetResourceTotals(vessel, resourceName, out vesselCurrentAmount, out vesselMaxAmount, protoPartResources);

                //If the vessel has no resource at all then it hasn't been visited in-game yet.
                if (vesselMaxAmount <= 0)
                {
                    result.resultType = SnacksResultType.notApplicable;

                    //Call the base class
                    base.ApplyOutcome(vessel, result);

                    return;
                }

                //Multiply demand by affected crew count
                if (result.appliedPerCrew && !selectRandomCrew)
                {
                    demand *= result.affectedKerbalCount;
                }

                //If we have enough to support the whole crew, then we're good.
                if ((vesselCurrentAmount / demand) >= 0.999)
                {
                    //Request resource
                    ProcessedResource.RequestResource(vessel, resourceName, demand, protoPartResources);
                }

                //We don't have enough to support the whole crew. Figure out how many we can support.
                else
                {
                    int totalServed = (int)Math.Floor(vesselCurrentAmount / amount);

                    demand = totalServed * amount;
                    ProcessedResource.RequestResource(vessel, resourceName, vesselCurrentAmount, protoPartResources);
                }

                //Inform player
                if (!string.IsNullOrEmpty(playerMessage))
                {
                    ScreenMessages.PostScreenMessage(playerMessage, 5, ScreenMessageStyle.UPPER_LEFT);
                }
            }

            else if (result.afftectedAstronauts.Count > 0)
            {
                ProtoCrewMember[] astronauts    = null;
                AstronautData     astronautData = null;
                string            message       = string.Empty;

                //Get the crew manifest
                astronauts = result.afftectedAstronauts.ToArray();

                //Select random crew if needed
                if (selectRandomCrew)
                {
                    int randomIndex = UnityEngine.Random.Range(0, astronauts.Length - 1);
                    astronauts = new ProtoCrewMember[] { astronauts[randomIndex] };
                }

                for (int index = 0; index < astronauts.Length; index++)
                {
                    astronautData = SnacksScenario.Instance.GetAstronautData(astronauts[index]);

                    if (astronautData.rosterResources.ContainsKey(resourceName))
                    {
                        SnacksRosterResource resource = astronautData.rosterResources[resourceName];
                        resource.amount -= amount;
                        if (resource.amount <= 0)
                        {
                            resource.amount = 0;
                        }
                        astronautData.rosterResources[resourceName] = resource;

                        SnacksScenario.onRosterResourceUpdated.Fire(vessel, resource, astronautData, astronauts[index]);
                    }

                    //Inform player
                    if (!string.IsNullOrEmpty(playerMessage))
                    {
                        message = vessel.vesselName + ": " + astronauts[index].name + " " + playerMessage;
                        ScreenMessages.PostScreenMessage(message, 5.0f, ScreenMessageStyle.UPPER_LEFT);
                    }
                }

                //Call the base class
                base.ApplyOutcome(vessel, result);
            }
        }