示例#1
0
        protected override bool Generate()
        {
            DMAsteroidSurveyContract[] astContracts = ContractSystem.Instance.GetCurrentContracts <DMAsteroidSurveyContract>();
            int offers    = 0;
            int active    = 0;
            int maxOffers = DMContractDefs.DMAsteroid.maxOffers;
            int maxActive = DMContractDefs.DMAsteroid.maxActive;

            for (int i = 0; i < astContracts.Length; i++)
            {
                DMAsteroidSurveyContract a = astContracts[i];
                if (a.ContractState == State.Offered)
                {
                    offers++;
                }
                else if (a.ContractState == State.Active)
                {
                    active++;
                }
            }

            if (offers >= maxOffers)
            {
                return(false);
            }
            if (active >= maxActive)
            {
                return(false);
            }

            switch (prestige)
            {
            case ContractPrestige.Trivial:
                return(false);

            case ContractPrestige.Significant:
                size = rand.Next(0, 3);
                break;

            case ContractPrestige.Exceptional:
                size = rand.Next(2, 4);
                break;
            }

            hash = DMUtils.sizeHash(size);

            //Make sure that the grappling device is available
            if (!DMUtils.partAvailable(new List <string>(1)
            {
                "GrapplingDevice"
            }))
            {
                return(false);
            }

            sciList.AddRange(DMUtils.availableScience[DMScienceType.Asteroid.ToString()].Values);

            //Generates new asteroid science experiments
            for (i = 0; i < 6; i++)
            {
                if (sciList.Count > 0)
                {
                    DMScience    = sciList[rand.Next(0, sciList.Count)];
                    newParams[i] = DMAsteroidGenerator.fetchAsteroidParameter(DMScience);
                    sciList.Remove(DMScience);
                }
                else
                {
                    newParams[i] = null;
                }
            }

            //Add the science collection parent parameter
            DMCompleteParameter DMcp = new DMCompleteParameter(2, 1);

            this.AddParameter(DMcp);

            int limit       = 0;
            int maxRequests = 1;

            switch (prestige)
            {
            case ContractPrestige.Trivial:
                maxRequests = DMContractDefs.DMAsteroid.trivialScienceRequests;
                break;

            case ContractPrestige.Significant:
                maxRequests = DMContractDefs.DMAsteroid.significantScienceRequests;
                break;

            case ContractPrestige.Exceptional:
                maxRequests = DMContractDefs.DMAsteroid.exceptionalScienceRequests;
                break;
            }

            //Add in all acceptable paramaters to the contract
            foreach (DMAsteroidParameter DMAP in newParams)
            {
                if (limit > maxRequests)
                {
                    break;
                }
                if (DMAP != null)
                {
                    if (DMAP.Container == null)
                    {
                        continue;
                    }

                    DMcp.addToSubParams(DMAP);
                    float modifier = ((float)rand.Next(85, 116) / 100f);
                    DMAP.SetScience(DMAP.Container.Exp.baseValue * DMContractDefs.DMAsteroid.Science.ParamReward * (DMUtils.asteroidSubjectVal(size) / 2), null);
                    DMAP.SetFunds(DMContractDefs.DMAsteroid.Funds.ParamReward * modifier, DMContractDefs.DMAsteroid.Funds.ParamFailure * DMUtils.asteroidSubjectVal(size) * modifier, null);
                    DMAP.SetReputation(DMContractDefs.DMAsteroid.Reputation.ParamReward * modifier, DMContractDefs.DMAsteroid.Reputation.ParamFailure * modifier, null);
                    limit++;
                }
            }

            if (DMcp.ParameterCount < 3)
            {
                return(false);
            }

            float primaryModifier = ((float)rand.Next(85, 116) / 100f);

            float Mod = primaryModifier * DMcp.ParameterCount;

            this.agent = AgentList.Instance.GetAgent("DMagic");

            if (this.agent == null)
            {
                this.agent = AgentList.Instance.GetAgentRandom();
            }

            base.SetExpiry(DMContractDefs.DMAsteroid.Expire.MinimumExpireDays, DMContractDefs.DMAsteroid.Expire.MaximumExpireDays);
            base.SetDeadlineYears(DMContractDefs.DMAsteroid.Expire.DeadlineYears * primaryModifier, null);
            base.SetReputation(DMContractDefs.DMAsteroid.Reputation.BaseReward * primaryModifier, DMContractDefs.DMAsteroid.Reputation.BaseFailure * primaryModifier, null);
            base.SetFunds(DMContractDefs.DMAsteroid.Funds.BaseAdvance * Mod, DMContractDefs.DMAsteroid.Funds.BaseReward * Mod, DMContractDefs.DMAsteroid.Funds.BaseFailure * Mod, null);
            base.SetScience(DMContractDefs.DMAsteroid.Science.BaseReward * primaryModifier, null);
            return(true);
        }
        protected override bool Generate()
        {
            DMAsteroidSurveyContract[] astContracts = ContractSystem.Instance.GetCurrentContracts <DMAsteroidSurveyContract>();
            int offers    = 0;
            int active    = 0;
            int maxOffers = DMUtils.maxAsteroidOffered;
            int maxActive = DMUtils.maxAsteroidActive;

            for (int i = 0; i < astContracts.Length; i++)
            {
                DMAsteroidSurveyContract a = astContracts[i];
                if (a.ContractState == State.Offered)
                {
                    offers++;
                }
                else if (a.ContractState == State.Active)
                {
                    active++;
                }
            }

            if (offers >= maxOffers)
            {
                return(false);
            }
            if (active >= maxActive)
            {
                return(false);
            }

            if (this.Prestige == ContractPrestige.Trivial)
            {
                return(false);
            }
            else if (this.Prestige == ContractPrestige.Significant)
            {
                size = rand.Next(0, 3);
            }
            else if (this.Prestige == ContractPrestige.Exceptional)
            {
                size = rand.Next(2, 4);
            }
            else
            {
                return(false);
            }
            hash = DMUtils.sizeHash(size);

            //Make sure that the grappling device is available
            AvailablePart aPart = PartLoader.getPartInfoByName("GrapplingDevice");

            if (aPart == null)
            {
                return(false);
            }
            if (!ResearchAndDevelopment.PartModelPurchased(aPart))
            {
                return(false);
            }

            sciList.AddRange(DMUtils.availableScience[DMScienceType.Asteroid.ToString()].Values);

            //Generates new asteroid science experiments
            for (i = 0; i < 6; i++)
            {
                if (sciList.Count > 0)
                {
                    DMScience    = sciList[rand.Next(0, sciList.Count)];
                    newParams[i] = DMAsteroidGenerator.fetchAsteroidParameter(DMScience);
                    sciList.Remove(DMScience);
                }
                else
                {
                    newParams[i] = null;
                }
            }

            //Add the science collection parent parameter
            DMCompleteParameter DMcp = new DMCompleteParameter(2, 1);

            this.AddParameter(DMcp);

            int limit = 0;

            //Add in all acceptable paramaters to the contract
            foreach (DMAsteroidParameter DMAP in newParams)
            {
                if (limit > 3 + (int)this.prestige)
                {
                    break;
                }
                if (DMAP != null)
                {
                    DMcp.addToSubParams(DMAP, "CollectAsteroidScience");
                    float modifier = ((float)rand.Next(85, 116) / 100f);
                    DMAP.SetScience(DMAP.Container.Exp.baseValue * 0.3f * DMUtils.science * DMUtils.asteroidSubjectVal(1f, size), null);
                    DMAP.SetFunds(5000f * DMUtils.reward * DMUtils.asteroidSubjectVal(1f, size) * modifier, null);
                    limit++;
                }
            }

            if (DMcp.ParameterCount < 3)
            {
                return(false);
            }

            float primaryModifier = ((float)rand.Next(85, 116) / 100f);

            this.agent = AgentList.Instance.GetAgent("DMagic");
            base.SetExpiry(10 * DMUtils.deadline, 20 * DMUtils.deadline);
            base.SetDeadlineYears(3.8f * DMUtils.deadline * primaryModifier, null);
            base.SetReputation(1.5f * DMcp.ParameterCount * DMUtils.reward * (size + 1) * primaryModifier, 1.2f * DMcp.ParameterCount * DMUtils.penalty * primaryModifier, null);
            base.SetFunds(8000 * DMcp.ParameterCount * DMUtils.forward * (size + 1) * primaryModifier, 9500 * DMcp.ParameterCount * DMUtils.reward * (size + 1) * primaryModifier, 7000 * DMcp.ParameterCount * DMUtils.penalty * (size + 1) * primaryModifier, null);
            return(true);
        }