private void Outcome_Triumph(Caravan caravan)
        {
            int randomInRange = FactionRelationOffset.RandomInRange;

            this.parent.Faction.TryAffectGoodwillWith(other: Faction.OfPlayer, goodwillChange: randomInRange);

            List <Pawn> allMembersCapableOfGrowing = AllCaravanMembersCapableOfGrowing(caravan: caravan);
            float       totalYieldPowerForCaravan  = CalculateYieldForCaravan(caravanMembersCapableOfGrowing: allMembersCapableOfGrowing);

            //TODO: Calculate a good amount
            //v1 (first vers): base of 20 * Sum of plant harvest yield * count * avg grow skill (20 * 2.96 * 3 * 14.5) = ~2579 or 20*5.96*6*20 = 14400
            //v2 (2018/08/03): base of 50 * avg of plant harvest yield * count * avg grow skill (50 * 0.99 * 3 * 14.5) = ~2153 or 40*0.99*6*20 = 4752
            float totalreward = basereward * totalYieldPowerForCaravan * (allMembersCapableOfGrowing.Count
                                                                          * Mathf.Max(a: 1, b: (float)allMembersCapableOfGrowing.Average(selector: pawn => pawn.skills.GetSkill(skillDef: SkillDefOf.Plants).Level)));

            Thing reward = ThingMaker.MakeThing(def: RandomRawFood());

            reward.stackCount = Mathf.RoundToInt(f: totalreward);
            CaravanInventoryUtility.GiveThing(caravan: caravan, thing: reward);

            Find.LetterStack.ReceiveLetter(label: "MFI_LetterLabelHarvest_Triumph".Translate(), text: GetLetterText(baseText: "MFI_Harvest_Triumph".Translate(
                                                                                                                        this.parent.Faction.def.pawnsPlural, this.parent.Faction.Name,
                                                                                                                        Mathf.RoundToInt(f: randomInRange),
                                                                                                                        reward.LabelCap
                                                                                                                        ), caravan: caravan), textLetterDef: LetterDefOf.PositiveEvent, lookTargets: caravan, relatedFaction: this.parent.Faction);

            allMembersCapableOfGrowing.ForEach(action: pawn => pawn.skills.Learn(sDef: SkillDefOf.Plants, xp: expGain, direct: true));
        }
Пример #2
0
        private void TakeFromCaravan(Caravan caravan, List <ThingCount> demands, Faction enemyFaction)
        {
            List <Thing> list = new List <Thing>();

            for (int i = 0; i < demands.Count; i++)
            {
                ThingCount thingCount = demands[i];
                if (thingCount.Thing is Pawn)
                {
                    Pawn pawn = (Pawn)thingCount.Thing;
                    caravan.RemovePawn(pawn);
                    foreach (Thing thing in ThingOwnerUtility.GetAllThingsRecursively(pawn, false))
                    {
                        list.Add(thing);
                        thing.holdingOwner.Take(thing);
                    }
                    enemyFaction.kidnapped.KidnapPawn(pawn, null);
                }
                else
                {
                    thingCount.Thing.SplitOff(thingCount.Count).Destroy(DestroyMode.Vanish);
                }
            }
            for (int j = 0; j < list.Count; j++)
            {
                if (!list[j].Destroyed)
                {
                    CaravanInventoryUtility.GiveThing(caravan, list[j]);
                }
            }
        }
Пример #3
0
        // I had to take into account the old defs of ISR2G that used to be buildings, and replace them with new ISR2G defs that are craftable items
        public void OldDefsCleanup()
        {
            int     newISRG2  = 0;
            int     newAISRG2 = 0;
            Caravan caravan   = this.GetCaravan();

            foreach (Thing aThing in CaravanInventoryUtility.AllInventoryItems(caravan))
            {
                if (aThing.GetInnerIfMinified().def.defName == "RotR_ISR2G")
                {
                    newISRG2++;
                    aThing.Destroy();
                }
                else if (aThing.GetInnerIfMinified().def.defName == "RotR_AISR2G")
                {
                    newAISRG2++;
                    aThing.Destroy();
                }
            }
            for (int i = newISRG2; i > 0; i--)
            {
                Thing newThing = ThingMaker.MakeThing(ThingDef.Named("RotR_ISR2GNew"));
                CaravanInventoryUtility.GiveThing(caravan, newThing);
                RoadsOfTheRim.DebugLog("Replacing an ISR2G in caravan " + caravan.ToString());
            }
            for (int j = newAISRG2; j > 0; j--)
            {
                Thing newThing = ThingMaker.MakeThing(ThingDef.Named("RotR_AISR2GNew"));
                CaravanInventoryUtility.GiveThing(caravan, newThing);
                RoadsOfTheRim.DebugLog("Replacing an AISR2G in caravan " + caravan.ToString());
            }
        }
Пример #4
0
        public override void GiveRewards(Caravan caravan)
        {
            int level = (int)TechLevel.Spacer;

            if ((int)Faction.def.techLevel >= level)
            {
                base.GiveRewards(caravan);

                Find.LetterStack.ReceiveLetter("GiveItemsSuccessTitle".Translate(), "GiveItemsSuccess".Translate(), LetterDefOf.PositiveEvent);
            }
            else
            {
                if (caravan != null)
                {
                    foreach (var reward in Rewards)
                    {
                        CaravanInventoryUtility.GiveThing(caravan, reward);
                    }

                    Find.LetterStack.ReceiveLetter("GiveItemsSuccessTitle".Translate(), "GiveItemsSuccess2".Translate(), LetterDefOf.PositiveEvent);
                }
            }

            Faction.TryAffectGoodwillWith(Faction.OfPlayer, 25);
        }
Пример #5
0
        private void Outcome_Triumph(Caravan caravan)
        {
            var randomInRange = FactionRelationOffset.RandomInRange;

            parent.Faction?.TryAffectGoodwillWith(Faction.OfPlayer, randomInRange);

            var allMembersCapableOfGrowing = AllCaravanMembersCapableOfGrowing(caravan);
            var totalYieldPowerForCaravan  = CalculateYieldForCaravan(allMembersCapableOfGrowing);

            //TODO: Calculate a good amount
            //v1 (first vers): base of 20 * Sum of plant harvest yield * count * avg grow skill (20 * 2.96 * 3 * 14.5) = ~2579 or 20*5.96*6*20 = 14400
            //v2 (2018/08/03): base of 50 * avg of plant harvest yield * count * avg grow skill (50 * 0.99 * 3 * 14.5) = ~2153 or 40*0.99*6*20 = 4752 ((5940 for 50))
            //v3 (2018/12/18): base of 50 * avg of plant harvest yield * (count*0.75) * avg grow skill = (50 * 0.99 * (2.25) * 14.5 = ~1615 or (50 * 0.99 * (4.5) * 20 = 4455
            var totalreward = basereward * totalYieldPowerForCaravan * (allMembersCapableOfGrowing.Count * 0.75f)
                              * Mathf.Max(1,
                                          (float)allMembersCapableOfGrowing.Average(pawn =>
                                                                                    pawn.skills.GetSkill(SkillDefOf.Plants).Level));

            var reward = ThingMaker.MakeThing(RandomRawFood());

            reward.stackCount = Mathf.RoundToInt(totalreward);
            CaravanInventoryUtility.GiveThing(caravan, reward);

            Find.LetterStack.ReceiveLetter("MFI_LetterLabelHarvest_Triumph".Translate(), GetLetterText(
                                               "MFI_Harvest_Triumph".Translate(
                                                   parent.Faction?.def.pawnsPlural, parent.Faction?.Name,
                                                   Mathf.RoundToInt(randomInRange),
                                                   reward.LabelCap
                                                   ), caravan), LetterDefOf.PositiveEvent, caravan, parent.Faction);

            allMembersCapableOfGrowing.ForEach(pawn => pawn.skills.Learn(SkillDefOf.Plants, expGain, true));
        }
        public override void Notify_QuestSignalReceived(Signal signal)
        {
            base.Notify_QuestSignalReceived(signal);
            if (!(signal.tag == inSignal))
            {
                return;
            }
            pawns.RemoveAll((Pawn x) => x.Destroyed);
            Caravan arg = caravan;

            if (arg == null)
            {
                signal.args.TryGetArg("CARAVAN", out arg);
            }
            if (arg == null || !Things.Any())
            {
                return;
            }
            for (int i = 0; i < pawns.Count; i++)
            {
                if (pawns[i].Faction != Faction.OfPlayer)
                {
                    pawns[i].SetFaction(Faction.OfPlayer);
                }
                arg.AddPawn(pawns[i], addCarriedPawnToWorldPawnsIfAny: true);
            }
            for (int j = 0; j < items.Count; j++)
            {
                CaravanInventoryUtility.GiveThing(arg, items[j]);
            }
            items.Clear();
        }
 private string MaybeTheySuckAndDontHaveItYet(Buff buff, Pawn pawn, Caravan caravan, ThingSetMakerDef thingSetMakerDef)
 {
     if (thingSetMakerDef == eventDef.rewardFirstPlace && !MFI_Utilities.CaravanOrRichestColonyHasAnyOf(buff.RelevantThingDef(), caravan, out _))
     {
         Thing thing = ThingMaker.MakeThing(buff.RelevantThingDef());
         thing.stackCount = Mathf.Min(thing.def.stackLimit, 75); //suck it, stackXXL users.
         CaravanInventoryUtility.GiveThing(caravan, thing);
         string anReward = Find.ActiveLanguageWorker.WithDefiniteArticlePostProcessed(thing.Label);
         return("\n\n" + "MFI_SinceYouSuckAndDidntHaveIt".Translate(anReward));
     }
     return(string.Empty);
 }
        private void CallResourcesToCaravan(Pawn caller, Faction faction, bool free)
        {
            Caravan caravan = caller.GetCaravan();

            for (int i = 0; i < def.royalAid.itemsToDrop.Count; i++)
            {
                Thing thing = ThingMaker.MakeThing(def.royalAid.itemsToDrop[i].thingDef);
                thing.stackCount = def.royalAid.itemsToDrop[i].count;
                CaravanInventoryUtility.GiveThing(caravan, thing);
            }
            Messages.Message("MessagePermitTransportDropCaravan".Translate(faction.Named("FACTION"), caller.Named("PAWN")), caravan, MessageTypeDefOf.NeutralEvent);
            caller.royalty.GetPermit(def, faction).Notify_Used();
            if (!free)
            {
                caller.royalty.TryRemoveFavor(faction, def.royalAid.favorCost);
            }
        }
Пример #9
0
        private static void SpawnRandomCaravan()
        {
            int num = GenWorld.MouseTile();

            if (Find.WorldGrid[num].biome.impassable)
            {
                return;
            }
            List <Pawn> list = new List <Pawn>();
            int         num2 = Rand.RangeInclusive(1, 10);

            for (int i = 0; i < num2; i++)
            {
                Pawn pawn = PawnGenerator.GeneratePawn(Faction.OfPlayer.def.basicMemberKind, Faction.OfPlayer);
                list.Add(pawn);
                if (!pawn.WorkTagIsDisabled(WorkTags.Violent) && Rand.Value < 0.9f)
                {
                    ThingDef thingDef = DefDatabase <ThingDef> .AllDefs.Where((ThingDef def) => def.IsWeapon && def.PlayerAcquirable).RandomElementWithFallback();

                    pawn.equipment.AddEquipment((ThingWithComps)ThingMaker.MakeThing(thingDef, GenStuff.RandomStuffFor(thingDef)));
                }
            }
            int num3 = Rand.RangeInclusive(-4, 10);

            for (int j = 0; j < num3; j++)
            {
                Pawn item = PawnGenerator.GeneratePawn(DefDatabase <PawnKindDef> .AllDefs.Where((PawnKindDef d) => d.RaceProps.Animal && d.RaceProps.wildness < 1f).RandomElement(), Faction.OfPlayer);
                list.Add(item);
            }
            Caravan      caravan = CaravanMaker.MakeCaravan(list, Faction.OfPlayer, num, addToWorldPawnsIfNotAlready: true);
            List <Thing> list2   = ThingSetMakerDefOf.DebugCaravanInventory.root.Generate();

            for (int k = 0; k < list2.Count; k++)
            {
                Thing thing = list2[k];
                if (!(thing.GetStatValue(StatDefOf.Mass) * (float)thing.stackCount > caravan.MassCapacity - caravan.MassUsage))
                {
                    CaravanInventoryUtility.GiveThing(caravan, thing);
                    continue;
                }
                break;
            }
        }
        private void TakeFromCaravan(Caravan caravan, List <ThingCount> demands, Faction enemyFaction)
        {
            List <Thing> list = new List <Thing>();

            for (int i = 0; i < demands.Count; i++)
            {
                ThingCount thingCount = demands[i];
                if (thingCount.Thing is Pawn)
                {
                    Pawn pawn = (Pawn)thingCount.Thing;
                    caravan.RemovePawn(pawn);
                    foreach (Thing item in ThingOwnerUtility.GetAllThingsRecursively(pawn, allowUnreal: false))
                    {
                        list.Add(item);
                        item.holdingOwner.Take(item);
                    }
                    if (pawn.RaceProps.Humanlike)
                    {
                        enemyFaction.kidnapped.Kidnap(pawn, null);
                    }
                    else if (!Find.WorldPawns.Contains(pawn))
                    {
                        Find.WorldPawns.PassToWorld(pawn);
                    }
                }
                else
                {
                    thingCount.Thing.SplitOff(thingCount.Count).Destroy();
                }
            }
            for (int j = 0; j < list.Count; j++)
            {
                if (!list[j].Destroyed)
                {
                    CaravanInventoryUtility.GiveThing(caravan, list[j]);
                }
            }
        }
        public static DiaNode DialogueResolverArtOffer(string textResult, Thing broughtSculpture, Caravan caravan)
        {
            var marketValue = broughtSculpture.GetStatValue(StatDefOf.MarketValue);
            var resolver    = new DiaNode(textResult.Translate(broughtSculpture, marketValue * OVERPAYINGBY, marketValue));
            var accept      = new DiaOption("RansomDemand_Accept".Translate())
            {
                resolveTree = true,
                action      = () =>
                {
                    broughtSculpture.Destroy();
                    var silver = ThingMaker.MakeThing(ThingDefOf.Silver);
                    silver.stackCount = (int)(marketValue * OVERPAYINGBY);
                    CaravanInventoryUtility.GiveThing(caravan, silver);
                }
            };
            var reject = new DiaOption("RansomDemand_Reject".Translate())
            {
                resolveTree = true
            };

            resolver.options.Add(accept);
            resolver.options.Add(reject);
            return(resolver);
        }
        // I had to take into account the old defs of ISR2G that used to be buildings, and replace them with new ISR2G defs that are craftable items
        private void OldDefsCleanup()
        {
            var newISRG2  = 0;
            var newAISRG2 = 0;
            var caravan   = GetCaravan();

            foreach (var aThing in CaravanInventoryUtility.AllInventoryItems(caravan))
            {
                switch (aThing.GetInnerIfMinified().def.defName)
                {
                case "RotR_ISR2G":
                    newISRG2++;
                    aThing.Destroy();
                    break;

                case "RotR_AISR2G":
                    newAISRG2++;
                    aThing.Destroy();
                    break;
                }
            }

            for (var i = newISRG2; i > 0; i--)
            {
                var newThing = ThingMaker.MakeThing(ThingDef.Named("RotR_ISR2GNew"));
                CaravanInventoryUtility.GiveThing(caravan, newThing);
                RoadsOfTheRim.DebugLog("Replacing an ISR2G in caravan " + caravan);
            }

            for (var j = newAISRG2; j > 0; j--)
            {
                var newThing = ThingMaker.MakeThing(ThingDef.Named("RotR_AISR2GNew"));
                CaravanInventoryUtility.GiveThing(caravan, newThing);
                RoadsOfTheRim.DebugLog("Replacing an AISR2G in caravan " + caravan);
            }
        }