Ejemplo n.º 1
0
 /// <summary>
 /// create a new aspect impactor instance
 /// </summary>
 /// <param name="aspect"></param>
 public AspectCapacityImpactor(Aspect aspect)
 {
     Aspect = aspect;
 }
Ejemplo n.º 2
0
 private void AspectRemoved(AspectTracker sender, Aspect _)
 {
     ResetCaches();
 }
Ejemplo n.º 3
0
        private void Produce(int amount, float chance, ThingDef resource, ThingDef rareResource, ThoughtDef stageThought)
        {
            RandUtilities.PushState();

            MemoryThoughtHandler thoughts   = Pawn.needs?.mood?.thoughts?.memories;
            EtherState           etherState = Pawn.GetEtherState();

            HatchingTicker = 0;
            var    thingCount     = 0;
            var    rareThingCount = 0;
            Aspect infusedAspect  = Pawn.GetAspectTracker()?.GetAspect(AspectDefOf.MutagenInfused);

            int?sIndex = infusedAspect?.StageIndex;


            for (var i = 0; i < amount; i++)
            {
                bool shouldProduceRare;
                switch (sIndex)
                {
                case null:
                    shouldProduceRare = Rand.RangeInclusive(0, 100) <= chance;
                    break;

                case 0:
                    shouldProduceRare = true;
                    break;

                case 1:
                    shouldProduceRare = false;
                    break;

                case 2:
                    return;     //produce nothing

                default:
                    throw new ArgumentOutOfRangeException(sIndex.Value.ToString());
                }

                if (shouldProduceRare && rareResource != null)
                {
                    rareThingCount++;
                }
                else
                {
                    thingCount++;
                }
            }

            Thing thing = ThingMaker.MakeThing(resource);

            thing.stackCount = thingCount;

            Color?skinColor = Pawn.GetHighestInfluence()?.GetSkinColorOverride(Pawn);  //dont want wool thats mostly human-skin colored

            if (resource.thingCategories.Contains(PMThingCategoryDefOf.Textiles) && resource.CompDefFor <CompColorable>() != null && skinColor.HasValue)
            {
                thing.SetColor(skinColor.Value);
            }
            if (thing.stackCount > 0)
            {
                GenPlace.TryPlaceThing(thing, Pawn.PositionHeld, Pawn.Map, ThingPlaceMode.Near);
            }

            if (rareResource != null)
            {
                Thing rareThing = ThingMaker.MakeThing(rareResource);
                rareThing.stackCount = rareThingCount;
                if (rareResource.thingCategories.Contains(PMThingCategoryDefOf.Textiles) && resource.CompDefFor <CompColorable>() != null && skinColor.HasValue)
                {
                    thing.SetColor(skinColor.Value);
                }
                if (rareThing.stackCount > 0)
                {
                    GenPlace.TryPlaceThing(rareThing, Pawn.PositionHeld, Pawn.Map, ThingPlaceMode.Near);
                }
            }

            if (etherState == EtherState.None)
            {
                if (Rand.RangeInclusive(0, 100) <= bondChance)
                {
                    GiveEtherState(EtherState.Bond);
                    etherState = EtherState.Bond;
                    Find.LetterStack.ReceiveLetter(
                        "LetterHediffFromEtherBondLabel".Translate(Pawn).CapitalizeFirst(),
                        "LetterHediffFromEtherBond".Translate(Pawn).CapitalizeFirst(),
                        LetterDefOf.NeutralEvent, Pawn);
                }
                else if (Rand.RangeInclusive(0, 100) <= brokenChance)
                {
                    GiveEtherState(EtherState.Broken);
                    etherState = EtherState.Broken;
                    Find.LetterStack.ReceiveLetter(
                        "LetterHediffFromEtherBrokenLabel".Translate(Pawn).CapitalizeFirst(),
                        "LetterHediffFromEtherBroken".Translate(Pawn).CapitalizeFirst(),
                        LetterDefOf.NeutralEvent, Pawn);
                }
            }

            if (stageThought != null)
            {
                thoughts?.TryGainMemory(stageThought);
            }

            ThoughtDef addThought;

            switch (etherState)
            {
            case EtherState.None:
                addThought = Props.genderAversion == Pawn.gender ? Props.wrongGenderThought ?? Props.thought : Props.thought;
                break;

            case EtherState.Broken:
                addThought = Props.etherBrokenThought;
                break;

            case EtherState.Bond:
                addThought = Props.etherBondThought;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            if (addThought != null)
            {
                thoughts?.TryGainMemory(addThought);
            }

            if (etherState == EtherState.None)
            {
                brokenChance += 0.5f;
                bondChance   += 0.2f;
            }
            totalProduced += rareThingCount + thingCount;
            RandUtilities.PopState();
        }
Ejemplo n.º 4
0
 private void OnAspectAdded(AspectTracker sender, Aspect _)
 {
     ResetCaches();
 }