예제 #1
0
        public static bool ApplyOccultChance(SimDescription sim, List <OccultTypes> validTypes, int chanceOfOccult, int chanceOfMutation, int maximumOccultPerSim)
        {
            if (sim == null)
            {
                return(false);
            }

            if (FutureDescendantServiceEx.OccultProcessed.Contains(sim.SimDescriptionId))
            {
                return(false);
            }

            List <OccultTypes> possibleOccults = OccultTypeHelper.CreateListOfAllOccults(true);

            int occultsAdded = -1;

            if (OccultTypeHelper.CreateList(sim).Count > 0) // this handles the possible occult added by EA when the Sim was generated
            {
                occultsAdded = 0;
            }

            foreach (OccultTypes type in validTypes)
            {
                if (occultsAdded >= maximumOccultPerSim)
                {
                    break;
                }

                if (!RandomUtil.RandomChance(chanceOfOccult))
                {
                    continue;
                }

                if (RandomUtil.RandomChance(chanceOfMutation) && possibleOccults.Count > 0)
                {
                    while (possibleOccults.Count > 0)
                    {
                        OccultTypes mutationType = RandomUtil.GetRandomObjectFromList <OccultTypes>(possibleOccults);

                        if (OccultTypeHelper.Add(sim, mutationType, false, false))
                        {
                            possibleOccults.Remove(mutationType);
                            occultsAdded++;
                            break;
                        }

                        possibleOccults.Remove(mutationType);
                    }
                }

                if (OccultTypeHelper.Add(sim, type, false, false))
                {
                    occultsAdded++;
                }
            }

            OccultTypeHelper.ValidateOccult(sim, null);
            FutureDescendantServiceEx.OccultProcessed.Add(sim.SimDescriptionId);

            if (occultsAdded > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }