예제 #1
0
        // Token: 0x0600006C RID: 108 RVA: 0x00004C1C File Offset: 0x00002E1C
        public static Toil FinalizeRemoving(TargetIndex RemoveFrom)
        {
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                Job          curJob       = toil.actor.CurJob;
                Thing        thing        = curJob.GetTarget(RemoveFrom).Thing;
                Thing        removedThing = null;
                CompAquarium AQComp       = thing.TryGetComp <CompAquarium>();
                if (AQComp != null && AQComp.fishData.Count > 0)
                {
                    List <string> newList  = new List <string>();
                    int           newIndex = 0;
                    bool          removed  = false;
                    foreach (string value in AQComp.fishData)
                    {
                        newIndex++;
                        string prevDefVal = CompAquarium.StringValuePart(value, 1);
                        int    prevHealth = CompAquarium.NumValuePart(value, 2);
                        int    prevAge    = CompAquarium.NumValuePart(value, 3);
                        int    prevAct    = CompAquarium.NumValuePart(value, 4);
                        if (prevAct == 2 && !removed)
                        {
                            Thing thing2 = ThingMaker.MakeThing(ThingDef.Named(prevDefVal), null);
                            thing2.stackCount = 1;
                            GenPlace.TryPlaceThing(thing2, toil.actor.Position, toil.actor.Map, ThingPlaceMode.Near, out Thing newFishBag, null, null, default);
예제 #2
0
        // Token: 0x0600006A RID: 106 RVA: 0x00004BBC File Offset: 0x00002DBC
        public static Toil FinalizeFeeding(TargetIndex feedable, TargetIndex food)
        {
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                Job          curJob      = toil.actor.CurJob;
                Thing        thing       = curJob.GetTarget(feedable).Thing;
                Thing        excessThing = null;
                CompAquarium AQComp      = thing.TryGetComp <CompAquarium>();
                if (AQComp != null)
                {
                    int numFoodToAdd = AQUtility.GetFoodNumToFullyFeed(AQComp);
                    if (numFoodToAdd > 0)
                    {
                        Thing foodybits = curJob.GetTarget(food).Thing;
                        if (foodybits != null)
                        {
                            int numFoodHave = foodybits.stackCount;
                            int numAdding;
                            if (numFoodHave <= numFoodToAdd)
                            {
                                numAdding = numFoodHave;
                                foodybits.Destroy(DestroyMode.Vanish);
                            }
                            else
                            {
                                numAdding             = numFoodToAdd;
                                foodybits.stackCount -= numAdding;
                                GenPlace.TryPlaceThing(foodybits, toil.actor.Position, toil.actor.Map, ThingPlaceMode.Near, out Thing newFoodDrop, null, null, default);
예제 #3
0
        // Token: 0x06000005 RID: 5 RVA: 0x00002128 File Offset: 0x00000328
        internal static float GetJoyGainFactor(float beautyFactor, Thing FishyThing)
        {
            float        fishFactor = 1f;
            float        agefactor  = 1f;
            float        compare    = 30f;
            CompAquarium CompAQ     = FishyThing.TryGetComp <CompAquarium>();

            if (CompAQ != null)
            {
                List <string> list = CompAQ.fishData;
                if (list.Count > 0)
                {
                    foreach (string listing in list)
                    {
                        ThingDef fishdef = ThingDef.Named(CompAquarium.StringValuePart(listing, 1));
                        if (fishdef != null)
                        {
                            float value = Math.Max(10f, Math.Min(50f, fishdef.BaseMarketValue));
                            fishFactor *= value / compare;
                            agefactor  *= Mathf.Lerp(0.75f, 1f, Math.Min(CompAquarium.oldFishAge, CompAquarium.NumValuePart(listing, 3)) / CompAquarium.oldFishAge);
                        }
                    }
                }
            }
            return(beautyFactor * fishFactor * agefactor);
        }
예제 #4
0
        // Token: 0x06000066 RID: 102 RVA: 0x00004B04 File Offset: 0x00002D04
        public static Toil FinalizeAdding(TargetIndex addable, TargetIndex fish)
        {
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                Job   curJob    = toil.actor.CurJob;
                Thing tankThing = curJob.GetTarget(addable).Thing;
                Thing fishThing = curJob.GetTarget(fish).Thing;
                if (tankThing != null && fishThing != null)
                {
                    CompAquarium AQComp = tankThing.TryGetComp <CompAquarium>();
                    if (AQComp != null)
                    {
                        List <string> newList  = new List <string>();
                        int           newIndex = 0;
                        if (AQComp.fishData.Count > 0)
                        {
                            bool tryToAdd = true;
                            foreach (string value in AQComp.fishData)
                            {
                                string prevDefVal = CompAquarium.StringValuePart(value, 1);
                                int    prevHealth = CompAquarium.NumValuePart(value, 2);
                                int    prevAge    = CompAquarium.NumValuePart(value, 3);
                                int    prevAct    = CompAquarium.NumValuePart(value, 4);
                                newIndex++;
                                if (prevAct == 1 && tryToAdd && (prevDefVal == fishThing.def.defName || prevDefVal == "AQRandomFish"))
                                {
                                    int             health = 100;
                                    int             age    = 0;
                                    CompAQFishInBag CBag   = fishThing.TryGetComp <CompAQFishInBag>();
                                    if (CBag != null)
                                    {
                                        health = CBag.fishhealth;
                                        age    = CBag.age;
                                    }
                                    string newValue = CompAquarium.CreateValuePart(newIndex, fishThing.def.defName, health, age, 0);
                                    newList.Add(newValue);
                                    AQComp.numFish++;
                                    tryToAdd = false;
                                }
                                else
                                {
                                    string newValue3 = CompAquarium.CreateValuePart(newIndex, prevDefVal, prevHealth, prevAge, prevAct);
                                    newList.Add(newValue3);
                                }
                            }
                        }
                        AQComp.fishData = newList;
                        AQComp.GenerateBeauty(AQComp.fishData);
                    }
                }
                fishThing.Destroy(DestroyMode.Vanish);
                toil.actor.skills.Learn(SkillDefOf.Animals, 75f, false);
            };
            toil.defaultCompleteMode = ToilCompleteMode.Instant;
            return(toil);
        }
예제 #5
0
        // Token: 0x0600000A RID: 10 RVA: 0x000024A4 File Offset: 0x000006A4
        internal static bool AddOrRemove(Thing t, out bool Add, out ThingDef fishAddDef, out bool Remove)
        {
            bool result = false;
            bool flag   = Remove = false;

            Add        = flag;
            fishAddDef = null;
            CompAquarium CA = t.TryGetComp <CompAquarium>();

            if (CA != null)
            {
                List <string> listing = CA.fishData;
                if (listing.Count > 0)
                {
                    foreach (string value in listing)
                    {
                        int action = CompAquarium.NumValuePart(value, 4);
                        if (action == 1)
                        {
                            Add = true;
                            var fishDefString = (CompAquarium.StringValuePart(value, 1));
                            if (fishDefString == "AQRandomFish")
                            {
                                if (hammeringCounter != 0)
                                {
                                    hammeringCounter--;
                                    return(false);
                                }
                                var reachableFish = CA.ReachableDefs;
                                if (reachableFish.Count > 0)
                                {
                                    fishDefString = reachableFish.RandomElement();
                                }
                                else
                                {
                                    hammeringCounter = 20;
                                    return(false);
                                }
                            }
                            fishAddDef = ThingDef.Named(fishDefString);
                            return(true);
                        }
                        if (action == 2)
                        {
                            Remove = true;
                            return(true);
                        }
                    }
                    return(result);
                }
            }
            return(result);
        }
 // Token: 0x06000070 RID: 112 RVA: 0x00004C88 File Offset: 0x00002E88
 public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
 {
     if (pawn.CanReserveAndReach(t, PathEndMode.Touch, Danger.None, 1, -1, null, false))
     {
         CompAquarium CA = t.TryGetComp <CompAquarium>();
         if (CA != null)
         {
             float trigger = Controller.Settings.RespondClean / 100f;
             if (CA.cleanPct <= trigger)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
예제 #7
0
        // Token: 0x06000068 RID: 104 RVA: 0x00004B64 File Offset: 0x00002D64
        public static Toil FinalizeCleaning(TargetIndex cleanable)
        {
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                CompAquarium AQComp = toil.actor.CurJob.GetTarget(cleanable).Thing.TryGetComp <CompAquarium>();
                if (AQComp != null)
                {
                    AQComp.cleanPct = 1f;
                    toil.actor.skills.Learn(SkillDefOf.Animals, 50f, false);
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Instant;
            return(toil);
        }
 // Token: 0x0600007F RID: 127 RVA: 0x00004E68 File Offset: 0x00003068
 public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
 {
     if (pawn.CanReserveAndReach(t, PathEndMode.Touch, Danger.None, 1, -1, null, false))
     {
         CompAquarium CA = t.TryGetComp <CompAquarium>();
         if (CA != null)
         {
             float trigger = Controller.Settings.RespondFood / 100f;
             if (CA.foodPct <= trigger && CA.numFish > 0 && AQUtility.GetClosestFeed(pawn, t) != null)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
예제 #9
0
 // Token: 0x06000014 RID: 20 RVA: 0x000029CC File Offset: 0x00000BCC
 public override void CompTick()
 {
     base.CompTick();
     if (parent.IsHashIntervalTick(bagTicks))
     {
         bool died = false;
         age += bagTicks;
         if (age + (int)CompAquarium.RandomFloat(-450000f, 450000f) > CompAquarium.oldFishAge)
         {
             fishhealth--;
         }
         if (parent.Spawned)
         {
             ticksInBagRemain -= bagTicks;
             if (ticksInBagRemain <= 0)
             {
                 fishhealth--;
             }
             if (parent.AmbientTemperature < 1f || parent.AmbientTemperature > 55f)
             {
                 fishhealth--;
             }
         }
         if (fishhealth <= 0)
         {
             died = true;
         }
         if (died)
         {
             if (parent.Spawned)
             {
                 ThingWithComps parent = this.parent;
                 if ((parent?.Map) != null && this.parent.Map.ParentFaction == Faction.OfPlayerSilentFail)
                 {
                     if (Controller.Settings.DoDeathMsgs)
                     {
                         Messages.Message("Aquarium.FishDied".Translate(), this.parent, MessageTypeDefOf.NegativeEvent, false);
                     }
                     AQUtility.DoSpawnTropicalFishMeat(this.parent, age);
                 }
             }
             parent.Destroy(DestroyMode.Vanish);
         }
     }
 }
예제 #10
0
        // Token: 0x0600000C RID: 12 RVA: 0x00002644 File Offset: 0x00000844
        internal static Thing GetClosestFeed(Pawn p, Thing t)
        {
            CompAquarium CA  = t.TryGetComp <CompAquarium>();
            int          num = 0;

            if (CA != null)
            {
                if (CA.numFish < 1)
                {
                    return(null);
                }
                num = Math.Max(1, (int)((1f - CA.foodPct) * 10f * Math.Max(1, CA.numFish)));
            }
            if (num > 0)
            {
                List <Thing> potentials = p.Map.listerThings.ThingsOfDef(ThingDef.Named("AQFishFood"));
                Thing        BestThing  = null;
                float        BestScore  = 0f;
                if (potentials.Count > 0)
                {
                    foreach (Thing potential in potentials)
                    {
                        if (potential.Spawned && p.CanReserveAndReach(potential, PathEndMode.Touch, Danger.None, 1, -1, null, false))
                        {
                            float stackFactor = 1f;
                            if (potential.stackCount < num)
                            {
                                stackFactor = 0.5f;
                            }
                            float distance = p.Position.DistanceTo(potential.Position);
                            float score    = Mathf.Lerp(1f, 0.01f, distance / 9999f) * stackFactor;
                            if (score > BestScore)
                            {
                                BestScore = score;
                                BestThing = potential;
                            }
                        }
                    }
                }
                return(BestThing);
            }
            return(null);
        }
예제 #11
0
        // Token: 0x06000010 RID: 16 RVA: 0x000028C0 File Offset: 0x00000AC0
        internal static void DebugFishData(CompAquarium CompAQ, int maxNum = 0)
        {
            Log.Message(string.Concat(new string[]
            {
                CompAQ.parent.Label,
                " : ",
                CompAQ.numFish.ToString(),
                " : ",
                maxNum.ToString()
            }), false);
            List <string> list = CompAQ.fishData;

            if (list.Count > 0)
            {
                foreach (string text in list)
                {
                    Log.Message(text, false);
                }
            }
        }
예제 #12
0
        // Token: 0x06000006 RID: 6 RVA: 0x00002210 File Offset: 0x00000410
        internal static void ApplyMoodBoostAndInspire(Pawn pawn, Thing FishyThing)
        {
            CompAquarium      CompAQ = FishyThing.TryGetComp <CompAquarium>();
            Pawn_NeedsTracker needs  = pawn.needs;

            if ((needs?.mood) != null)
            {
                float fishFactor = 1f;
                float agefactor  = 1f;
                float compare    = 30f;
                if (CompAQ != null && CompAQ.numFish > 0 && pawn.IsHashIntervalTick(1000))
                {
                    List <string> list = CompAQ.fishData;
                    if (list.Count > 0)
                    {
                        foreach (string listing in list)
                        {
                            ThingDef fishdef = ThingDef.Named(CompAquarium.StringValuePart(listing, 1));
                            if (fishdef != null)
                            {
                                float value = Math.Max(10f, Math.Min(50f, fishdef.BaseMarketValue));
                                fishFactor *= value / compare;
                                agefactor  *= Mathf.Lerp(0.75f, 1f, Math.Min(CompAquarium.oldFishAge, CompAquarium.NumValuePart(listing, 3)) / CompAquarium.oldFishAge);
                            }
                        }
                    }
                    if (IsInspired((int)(CompAQ.numFish * 25 * fishFactor * agefactor)))
                    {
                        ThoughtDef fishRelaxDef = ThoughtDef.Named("AQObserveFish");
                        pawn.needs.mood.thoughts.memories.TryGainMemory(fishRelaxDef, null);
                    }
                }
            }
            if (CompAQ != null && CompAQ.numFish > 0 && Controller.Settings.AllowInspire && pawn.IsHashIntervalTick(1000) && !pawn.IsPrisoner && IsInspired((int)(CompAQ.numFish * Controller.Settings.BaseInspChance)) && !pawn.mindState.inspirationHandler.Inspired)
            {
                InspirationDef IDef = (from x in DefDatabase <InspirationDef> .AllDefsListForReading
                                       where x.Worker.InspirationCanOccur(pawn)
                                       select x).RandomElementByWeightWithFallback((InspirationDef x) => x.Worker.CommonalityFor(pawn), null);
                pawn.mindState.inspirationHandler.TryStartInspiration_NewTemp(IDef, null);
            }
        }
예제 #13
0
 // Token: 0x06000009 RID: 9 RVA: 0x00002479 File Offset: 0x00000679
 internal static int GetCleanTime(CompAquarium AQComp)
 {
     return(Math.Max(120, (int)((1f - AQComp.cleanPct) * 10f * 2f * 60f)));
 }
예제 #14
0
 // Token: 0x06000008 RID: 8 RVA: 0x00002450 File Offset: 0x00000650
 internal static int GetFoodNumToFullyFeed(CompAquarium AQComp)
 {
     return(Math.Max(0, (int)((1f - AQComp.foodPct) * 10f * Math.Max(0, AQComp.numFish))));
 }
예제 #15
0
 // Token: 0x06000007 RID: 7 RVA: 0x00002438 File Offset: 0x00000638
 internal static bool IsInspired(int chance)
 {
     return(CompAquarium.RandomFloat(1f, 100f) < chance);
 }
예제 #16
0
        // Token: 0x0600000D RID: 13 RVA: 0x0000277C File Offset: 0x0000097C
        internal static bool HasFish(Thing thing)
        {
            CompAquarium CAQ = thing.TryGetComp <CompAquarium>();

            return(CAQ != null && CAQ.numFish > 0);
        }