Esempio n. 1
0
 public void SetActive(Vessel.ActiveResource resource)
 {
     try
     {
         ResourceData res = Array.Find(rs, t => t.name == resource.info.name);
         res.stage    = (float)resource.amount;
         res.stagemax = (float)resource.maxAmount;
     }
     catch (Exception e)
     {
         JUtil.LogErrorMessage(this, "Error SetActive {0}: {1}", resource.info.name, e);
     }
 }
Esempio n. 2
0
        protected bool canAffordReconfigure()
        {
            if (HighLogic.LoadedSceneIsFlight == false)
            {
                return(true);
            }
            if (!payForReconfigure)
            {
                return(true);
            }
            bool   canAffordCost = false;
            string notEnoughPartsMsg;

            PartResourceDefinition definition = ResourceHelper.DefinitionForResource(resourceRequired);

            Vessel.ActiveResource resource = this.part.vessel.GetActiveResource(definition);

            calculateRemodelCostModifier();
            double amount = resourceCost * (1.0 - reconfigureCostModifier);

            //An inflatable part that hasn't been inflated yet is an automatic pass.
            if (switcher.isInflatable && !switcher.isDeployed)
            {
                return(true);
            }

            //now check to make sure the vessel has enough parts.
            if (resource == null)
            {
                canAffordCost = false;
            }

            else if (resource.amount < amount)
            {
                canAffordCost = false;
            }

            if (!canAffordCost)
            {
                notEnoughPartsMsg = string.Format(kInsufficientParts, amount, resourceRequired);
                ScreenMessages.PostScreenMessage(notEnoughPartsMsg, 5.0f, ScreenMessageStyle.UPPER_CENTER);
                return(false);
            }

            return(true);
        }
Esempio n. 3
0
        protected float calculateRepairCost()
        {
            float repairUnits = repairAmount;

            if (FlightGlobals.ActiveVessel.isEVA == false)
            {
                return(-1.0f); //Should not get to here as the event is set up for EVA only.
            }

            //Anybody can repair the scope, but the right skill can reduce the cost by as much as 60%
            Experience.ExperienceTrait experience = FlightGlobals.ActiveVessel.GetVesselCrew()[0].experienceTrait;
            if (experience.TypeName == repairSkill)
            {
                repairUnits = repairUnits * (0.9f - (experience.CrewMemberExperienceLevel() * 0.1f));
            }

            //Now make sure the kerbal has enough resources to conduct repairs.
            //Get the resource definition
            PartResourceDefinition definition = ResourceHelper.DefinitionForResource(repairResource);

            if (definition == null)
            {
                return(-1.0f);
            }

            //make sure the ship has enough of the resource
            Vessel.ActiveResource activeResource = FlightGlobals.ActiveVessel.GetActiveResource(definition);
            if (activeResource == null)
            {
                return(-1.0f);
            }

            if (activeResource.amount < repairUnits)
            {
                return(-1.0f);
            }

            return(repairUnits);
        }
 public void SetActive(Vessel.ActiveResource resource)
 {
     data[resource.info.id].stage    = resource.amount;
     data[resource.info.id].stagemax = resource.maxAmount;
 }
        protected override bool canAffordReconfigure(string templateName)
        {
            if (HighLogic.LoadedSceneIsFlight == false)
            {
                return(true);
            }
            if (!payForReconfigure)
            {
                return(true);
            }
            string value;
            bool   canAffordCost = false;

            requriredResource = templatesModel[templateName].GetValue("rocketParts");
            if (string.IsNullOrEmpty(requriredResource) == false)
            {
                float reconfigureAmount           = float.Parse(requriredResource);
                PartResourceDefinition definition = ResourceHelper.DefinitionForResource("RocketParts");
                Vessel.ActiveResource  resource   = this.part.vessel.GetActiveResource(definition);

                //An inflatable part that hasn't been inflated yet is an automatic pass.
                if (isInflatable && !isDeployed)
                {
                    return(true);
                }

                //Get the current template's rocket part cost.
                value = CurrentTemplate.GetValue("rocketParts");
                if (string.IsNullOrEmpty(value) == false)
                {
                    float recycleAmount = float.Parse(value);

                    //calculate the amount of parts that we can recycle.
                    recycleAmount *= calculateRecycleAmount();

                    //Now recalculate rocketPartCost, accounting for the parts we can recycle.
                    //A negative value means we'll get parts back, a positive number means we pay additional parts.
                    //Ex: current configuration takes 1200 parts. new configuration takes 900.
                    //We recycle 90% of the current configuration (1080 parts).
                    //The reconfigure cost is: 900 - 1080 = -180 parts
                    //If we reverse the numbers so new configuration takes 1200: 1200 - (900 * .9) = 390
                    reconfigureCost = reconfigureAmount - recycleAmount;
                }

                //now check to make sure the vessel has enough parts.
                if (resource == null)
                {
                    canAffordCost = false;
                }

                else if (resource.amount < reconfigureCost)
                {
                    canAffordCost = false;
                }

                else
                {
                    canAffordCost = true;
                }
            }

            if (!canAffordCost)
            {
                string notEnoughPartsMsg = string.Format(kInsufficientParts, reconfigureCost, "RocketParts");
                ScreenMessages.PostScreenMessage(notEnoughPartsMsg, 5.0f, ScreenMessageStyle.UPPER_CENTER);
                return(false);
            }

            return(true);
        }
Esempio n. 6
0
        public override void ToggleInflation()
        {
            PartResourceDefinition definition = ResourceHelper.DefinitionForResource("RocketParts");

            Vessel.ActiveResource resource = this.part.vessel.GetActiveResource(definition);
            string parts = CurrentTemplate.GetValue("rocketParts");

            if (string.IsNullOrEmpty(parts))
            {
                base.ToggleInflation();
                return;
            }
            float partCost = float.Parse(parts);

            calculateRemodelCostModifier();
            float adjustedPartCost = partCost;

            if (reconfigureCostModifier > 0f)
            {
                adjustedPartCost *= reconfigureCostModifier;
            }

            //Do we pay for resources? If so, either pay the resources if we're deploying the module, or refund the recycled parts
            if (payForReconfigure)
            {
                //If we aren't deployed then see if we can afford to pay the resource cost.
                if (!isDeployed)
                {
                    //Can we afford it?
                    if (resource == null || resource.amount < adjustedPartCost)
                    {
                        notEnoughParts();
                        string notEnoughPartsMsg = string.Format("Insufficient resources to assemble the module. You need a total of {0:f2} RocketParts to assemble.", partCost);
                        ScreenMessages.PostScreenMessage(notEnoughPartsMsg, 5.0f, ScreenMessageStyle.UPPER_CENTER);
                        return;
                    }

                    //Yup, we can afford it
                    //Pay the reconfigure cost
                    reconfigureCost = adjustedPartCost;
                    payPartsCost();

                    // Toggle after payment.
                    base.ToggleInflation();
                }

                //We are deployed, calculate the amount of parts that can be refunded.
                else
                {
                    // Toggle first in case deflate confirmation is needed, we'll check the state after the toggle.
                    base.ToggleInflation();

                    // deflateConfirmed's logic seems backward.
                    if (!HasResources() || (HasResources() && deflateConfirmed == false))
                    {
                        // The part came from the factory configured which represents an additional resource cost. If reconfigured in the field, the difference was paid at
                        // that time. Deflating doesn't remove any functionality, so no refund beyond the original adjusted part cost.
                        float recycleAmount = adjustedPartCost;

                        //Do we have sufficient space in the vessel to store the recycled parts?
                        float availableStorage = (float)(resource.maxAmount - resource.amount);

                        if (availableStorage < recycleAmount)
                        {
                            float amountLost = recycleAmount - availableStorage;
                            ScreenMessages.PostScreenMessage(string.Format("Module deflated, {0:f2} {1:s} lost due to insufficient storage.", amountLost, "RocketParts"), 5.0f, ScreenMessageStyle.UPPER_CENTER);

                            //We'll only recycle what we have room to store.
                            recycleAmount = availableStorage;
                        }

                        //Yup, we have the space
                        reconfigureCost = -recycleAmount;
                        payPartsCost();
                    }
                }
            }

            // Not paying for reconfiguration, check for skill requirements
            else
            {
                if (checkForSkill)
                {
                    if (hasSufficientSkill(CurrentTemplateName))
                    {
                        base.ToggleInflation();
                    }
                    else
                    {
                        return;
                    }
                }

                else
                {
                    base.ToggleInflation();
                }
            }
        }
Esempio n. 7
0
 public ActiveResourceValue(Vessel.ActiveResource activeResource, SharedObjects shared)
 {
     this.activeResource = activeResource;
     this.shared         = shared;
     InitializeActiveResourceSuffixes();
 }
Esempio n. 8
0
 public ActiveResourceValue(Vessel.ActiveResource activeResource, SharedObjects shared)
 {
     this.activeResource = activeResource;
     this.shared = shared;
     InitializeActiveResourceSuffixes();
 }