protected override string GetLetterText(IncidentParms parms, List <Pawn> pawns)
        {
            try {
                Pawn related  = pawns[pawns.Count - 1];
                Pawn captured = MapComponent_Tenants.GetComponent(related.Map).CapturedTenantsToAvenge[0];

                if (captured.ageTracker.AgeBiologicalYears > 25)
                {
                    related.relations.AddDirectRelation(PawnRelationDefOf.Parent, captured);
                }
                else
                {
                    captured.relations.AddDirectRelation(PawnRelationDefOf.Parent, related);
                }
                string str = string.Format(parms.raidArrivalMode.textEnemy, parms.faction.def.pawnsPlural, parms.faction.Name);
                str += "\n\n";
                str += "TenantCapturedRetribution".Translate(related.GetRelations(captured).FirstOrDefault().GetGenderSpecificLabel(captured), related.Named("PAWN"));
                Pawn pawn = pawns.Find((Pawn x) => x.Faction.leader == x);
                if (pawn != null)
                {
                    str += "\n\n";
                    str += "EnemyRaidLeaderPresent".Translate(pawn.Faction.def.pawnsPlural, pawn.LabelShort, pawn.Named("LEADER"));
                }
                MapComponent_Tenants.GetComponent(pawns[0].Map).CapturedTenantsToAvenge.Remove(captured);
                return(str);
            }
            catch (System.Exception) {
                return(Utility.NewBasicRaidMessage(parms, pawns));
            }
        }
        protected override string GetLetterText(IncidentParms parms, List <Pawn> pawns)
        {
            try {
                Pawn   related    = pawns[pawns.Count - 1];
                Pawn   mole       = MapComponent_Tenants.GetComponent((Map)parms.target).Moles[0];
                Tenant tenantComp = mole.GetTenantComponent();
                if (Rand.Value < 0.66f)
                {
                    mole.SetFaction(mole.GetTenantComponent().HiddenFaction);
                    tenantComp.IsTenant = false;
                }

                string str = string.Format(parms.raidArrivalMode.textEnemy, parms.faction.def.pawnsPlural, parms.faction.Name);
                str += "\n\n";
                str += "TenantMoles".Translate();
                Pawn pawn = pawns.Find((Pawn x) => x.Faction.leader == x);
                if (pawn != null)
                {
                    str += "\n\n";
                    str += "EnemyRaidLeaderPresent".Translate(pawn.Faction.def.pawnsPlural, pawn.LabelShort, pawn.Named("LEADER"));
                }
                MapComponent_Tenants.GetComponent((Map)parms.target).CapturedTenantsToAvenge.Remove(mole);
                return(str);
            }
            catch (System.Exception) {
                return(Utility.NewBasicRaidMessage(parms, pawns));
            }
        }
示例#3
0
        public static void GetFloatMenuOptions_PostFix(Building_CommsConsole __instance, ref IEnumerable <FloatMenuOption> __result, Pawn myPawn)
        {
            List <FloatMenuOption> list = __result.ToList();

            if (!MapComponent_Tenants.GetComponent(myPawn.Map).Broadcast)
            {
                void inviteTenant()
                {
                    Job job = new Job(JobDefOf.JobUseCommsConsoleTenants, __instance);

                    myPawn.jobs.TryTakeOrderedJob(job);
                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.OpeningComms, KnowledgeAmount.Total);
                }

                FloatMenuOption inviteTenants = new FloatMenuOption("InviteTenant".Translate(), inviteTenant, MenuOptionPriority.InitiateSocial);
                list.Add(inviteTenants);
            }
            if (!MapComponent_Tenants.GetComponent(myPawn.Map).BroadcastCourier)
            {
                void inviteCourier()
                {
                    Job job = new Job(JobDefOf.JobUseCommsConsoleInviteCourier, __instance);

                    myPawn.jobs.TryTakeOrderedJob(job);
                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.OpeningComms, KnowledgeAmount.Total);
                }

                FloatMenuOption inviteCouriers = new FloatMenuOption("CourierInvite".Translate(SettingsHelper.LatestVersion.CourierCost), inviteCourier, MenuOptionPriority.InitiateSocial);
                list.Add(inviteCouriers);
            }
            __result = list.AsEnumerable();
        }
示例#4
0
        public static bool ContractTenancy(Map map)
        {
            if (!Utility.TryFindSpawnSpot(map, out IntVec3 spawnSpot))
            {
                return(false);
            }
            string title = "", text = "";
            Pawn   pawn = Utility.FindRandomTenant();

            if (pawn == null)
            {
                return(false);
            }
            pawn.relations.everSeenByPlayer = true;
            Tenant tenantComp = pawn.TryGetComp <Tenant>();

            Utility.GenerateBasicTenancyContract(tenantComp);
            StringBuilder stringBuilder = new StringBuilder("");

            //Check if pawn is special
            //Wanted
            if (Rand.Value < 0.2f)
            {
                Utility.GenerateWanted(pawn);
            }
            //Mole
            if (Rand.Value < 0.33f && tenantComp.HiddenFaction.HostileTo(Find.FactionManager.OfPlayer))
            {
                tenantComp.Mole = true;
            }
            if (pawn.GetTenantComponent().Wanted)
            {
                stringBuilder.Append("RequestForTenancyHiding".Translate(tenantComp.WantedBy, pawn.Named("PAWN")));
                title = "RequestForTenancyHidingTitle".Translate(map.Parent.Label);
                tenantComp.Payment = tenantComp.Payment * 2;
                text = Utility.AppendContractDetails(stringBuilder.ToString(), pawn);
            }
            //Broadcasted
            else if (MapComponent_Tenants.GetComponent(map).Broadcast)
            {
                stringBuilder.Append("RequestForTenancyOpportunity".Translate(pawn.Named("PAWN")));
                title = "RequestForTenancyTitle".Translate(map.Parent.Label);
                MapComponent_Tenants.GetComponent(map).Broadcast = false;
                text = Utility.AppendContractDetails(stringBuilder.ToString(), pawn);
            }
            //Normal
            else
            {
                stringBuilder.Append("RequestForTenancyInitial".Translate(pawn.Named("PAWN")));
                title = "RequestForTenancyTitle".Translate(map.Parent.Label);
                text  = Utility.AppendContractDetails(stringBuilder.ToString(), pawn);
            }
            if (Utility.GenerateContractDialogue(title, text, pawn, map, spawnSpot))
            {
            }
            return(true);
        }
        protected override bool CanFireNowSub(IncidentParms parms)
        {
            bool canFire = base.CanFireNowSub(parms);

            if (MapComponent_Tenants.GetComponent((Map)parms.target).WantedTenants.Count < 1)
            {
                canFire = false;
            }

            return(canFire);
        }
示例#6
0
        public static void TenantMole(Pawn pawn)
        {
            Tenant tenantComp = pawn.GetTenantComponent();

            tenantComp.MoleActivated = true;
            tenantComp.MoleMessage   = true;
            MapComponent_Tenants.GetComponent(pawn.Map).Moles.Add(pawn);
            IncidentParms parms = StorytellerUtility.DefaultParmsNow(IncidentCategoryDefOf.ThreatBig, pawn.Map);

            parms.raidStrategy = RaidStrategyDefOf.MoleRaid;
            parms.forced       = true;
            Find.Storyteller.incidentQueue.Add(IncidentDefOf.MoleRaid, Find.TickManager.TicksGame + Rand.Range(5000, 30000), parms, 90000);
        }
示例#7
0
 public static void TenantLeave(Pawn pawn)
 {
     Utility.MakePayment(pawn);
     pawn.jobs.ClearQueuedJobs();
     pawn.SetFaction(Faction.OfAncients);
     pawn.GetTenantComponent().CleanTenancy();
     LordMaker.MakeNewLord(pawn.Faction, new LordJob_ExitMapBest(), pawn.Map, new List <Pawn> {
         pawn
     });
     if (MapComponent_Tenants.GetComponent(pawn.Map).WantedTenants.Contains(pawn))
     {
         MapComponent_Tenants.GetComponent(pawn.Map).WantedTenants.Remove(pawn);
     }
 }
 protected override void ResolveRaidStrategy(IncidentParms parms, PawnGroupKindDef groupKind)
 {
     try {
         base.ResolveRaidStrategy(parms, groupKind);
         Pawn mole = MapComponent_Tenants.GetComponent((Map)parms.target).Moles[0];
         if (mole.GetTenantComponent().HiddenFaction.def.techLevel >= TechLevel.Spacer && Rand.Value < 0.5f)
         {
             parms.raidArrivalMode = PawnsArrivalModeDefOf.CenterDrop;
         }
     }
     catch (System.Exception) {
         base.ResolveRaidStrategy(parms, groupKind);
     }
 }
示例#9
0
 public override void UpdateAllDuties()
 {
     for (int i = 0; i < lord.ownedPawns.Count; i++)
     {
         lord.ownedPawns[i].mindState.duty = new PawnDuty(DutyDefOf.TravelOrWait);
     }
     if (MailBox != null && MapComponent_Tenants.GetComponent(MailBox.Map).IncomingMail.Count > 0)
     {
         int cost = 0, taken = 0;
         if (MapComponent_Tenants.GetComponent(MailBox.Map).CourierCost.Count > 0)
         {
             foreach (Thing thing in MapComponent_Tenants.GetComponent(MailBox.Map).CourierCost)
             {
                 cost += thing.stackCount;
             }
         }
         MailBox mailBoxComp = MailBox.GetMailBoxComponent();
         foreach (Thing thing in MapComponent_Tenants.GetComponent(MailBox.Map).IncomingMail)
         {
             if (cost > 0)
             {
                 if (thing.stackCount > cost)
                 {
                     thing.stackCount -= cost;
                     taken            += cost;
                     cost              = 0;
                 }
                 else
                 {
                     cost            -= thing.stackCount;
                     taken           += thing.stackCount;
                     thing.stackCount = 0;
                 }
             }
             if (thing.stackCount > 0)
             {
                 mailBoxComp.Items.Add(thing);
             }
         }
         MapComponent_Tenants.GetComponent(MailBox.Map).IncomingMail.Clear();
         StringBuilder stringBuilder = new StringBuilder("");
         stringBuilder.Append("MailDelivered".Translate());
         if (taken > 0)
         {
             stringBuilder.Append("CourierCost".Translate(taken));
         }
         Messages.Message(stringBuilder.ToString(), MailBox, MessageTypeDefOf.NeutralEvent);
     }
 }
示例#10
0
        public static void MakePayment(Pawn pawn)
        {
            Tenant tenantComp = pawn.GetTenantComponent();
            int    payment    = (tenantComp.ContractLength / 60000) * tenantComp.Payment;

            while (payment > 500)
            {
                Thing silver = ThingMaker.MakeThing(RimWorld.ThingDefOf.Silver);
                silver.stackCount = 500;
                MapComponent_Tenants.GetComponent(pawn.Map).IncomingMail.Add(silver);
                payment = payment - 500;
            }
            Thing silverRest = ThingMaker.MakeThing(RimWorld.ThingDefOf.Silver);

            silverRest.stackCount = payment;
            MapComponent_Tenants.GetComponent(pawn.Map).IncomingMail.Add(silverRest);
        }
 protected override bool TryResolveRaidFaction(IncidentParms parms)
 {
     try {
         parms.faction = MapComponent_Tenants.GetComponent((Map)parms.target).WantedTenants[0].GetTenantComponent().WantedBy;
         if (FactionCanBeGroupSource(parms.faction, (Map)parms.target))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (System.Exception) {
         return(base.TryResolveRaidFaction(parms));
     }
 }
 protected override string GetLetterText(IncidentParms parms, List <Pawn> pawns)
 {
     try {
         MapComponent_Tenants.GetComponent((Map)parms.target).Broadcast = false;
         string basic = string.Format(parms.raidArrivalMode.textEnemy, parms.faction.def.pawnsPlural, parms.faction.Name);
         basic += "\n\n";
         basic += "TenantOpportunists".Translate();
         Pawn leader = pawns.Find((Pawn x) => x.Faction.leader == x);
         if (leader != null)
         {
             basic += "\n\n";
             basic += "EnemyRaidLeaderPresent".Translate(leader.Faction.def.pawnsPlural, leader.LabelShort, leader.Named("LEADER"));
         }
         return(basic);
     }
     catch (System.Exception) {
         return(base.GetLetterText(parms, pawns));
     }
 }
示例#13
0
        public static void TenantCaptured(Pawn pawn, Pawn byPawn)
        {
            if (pawn.HostileTo(Find.FactionManager.OfPlayer))
            {
                return;
            }
            string text = "TenantCaptured".Translate(pawn.Named("PAWN"));

            text = text.AdjustedFor(pawn);
            string label = "Captured".Translate() + ": " + pawn.LabelShortCap;

            Find.LetterStack.ReceiveLetter(label, text, LetterDefOf.NeutralEvent, pawn);
            Tenant tenantComp = pawn.GetTenantComponent();

            tenantComp.IsTenant = false;
            pawn.GetTenantComponent().CapturedTenant = true;
            pawn.SetFaction(tenantComp.HiddenFaction);

            if (pawn.Faction.HostileTo(Find.FactionManager.OfPlayer))
            {
                if (Rand.Value < 0.25f || tenantComp.Wanted)
                {
                    MapComponent_Tenants.GetComponent(byPawn.Map).CapturedTenantsToAvenge.Add(pawn);
                    IncidentParms parms = StorytellerUtility.DefaultParmsNow(IncidentCategoryDefOf.ThreatBig, byPawn.Map);
                    parms.raidStrategy = RaidStrategyDefOf.Retribution;
                    parms.forced       = true;
                    Find.Storyteller.incidentQueue.Add(IncidentDefOf.RetributionForCaptured, Find.TickManager.TicksGame + Rand.Range(15000, 90000), parms, 240000);
                }
            }
            else
            {
                if (Rand.Value < 0.66f || tenantComp.Wanted)
                {
                    if (tenantComp.HiddenFaction.def != FactionDefOf.Ancients)
                    {
                        FactionRelation relation = pawn.Faction.RelationWith(Find.FactionManager.OfPlayer);
                        relation.goodwill = relation.goodwill - SettingsHelper.LatestVersion.OutragePenalty;
                        Messages.Message("TenantFactionOutrage".Translate(pawn.Faction, SettingsHelper.LatestVersion.OutragePenalty, pawn.Named("PAWN")), MessageTypeDefOf.NegativeEvent);
                    }
                }
            }
        }
示例#14
0
 public static bool Courier(Map map, Building box)
 {
     try {
         if (!Utility.TryFindSpawnSpot(map, out IntVec3 spawnSpot))
         {
             return(false);
         }
         if (MapComponent_Tenants.GetComponent(map).BroadcastCourier == true)
         {
             MapComponent_Tenants.GetComponent(map).BroadcastCourier = false;
         }
         if (MapComponent_Tenants.GetComponent(map).KilledCourier > 0)
         {
             MapComponent_Tenants.GetComponent(map).KilledCourier--;
             string courierDeniedLabel = "CourierDeniedTitle".Translate(map.Parent.Label);
             string courierDeniedText  = "CourierDeniedMessage".Translate();
             Find.LetterStack.ReceiveLetter(courierDeniedLabel, courierDeniedText, LetterDefOf.NegativeEvent);
             return(true);
         }
         Pawn pawn = Utility.FindRandomCourier();
         if (pawn == null)
         {
             return(false);
         }
         GenSpawn.Spawn(pawn, spawnSpot, map);
         pawn.SetFaction(Faction.OfAncients);
         pawn.relations.everSeenByPlayer = true;
         Utility.CourierDress(pawn, map);
         Utility.CourierInventory(pawn, map);
         string letterLabel = "CourierArrivedTitle".Translate(map.Parent.Label);
         string letterText  = "CourierArrivedMessage".Translate(pawn.Named("PAWN"));
         Find.LetterStack.ReceiveLetter(letterLabel, letterText, LetterDefOf.PositiveEvent, pawn);
         LordMaker.MakeNewLord(pawn.Faction, new LordJob_CourierDeliver(map.listerThings.ThingsOfDef(ThingDefOf.Tenants_MailBox).RandomElement()), pawn.Map, new List <Pawn> {
             pawn
         });
         return(true);
     }
     catch (Exception ex) {
         Log.Message(ex.Message);
         return(false);
     }
 }
示例#15
0
 public static void TenantInvite(Building_CommsConsole comms, Pawn pawn)
 {
     Messages.Message("InviteTenantMessage".Translate(), MessageTypeDefOf.NeutralEvent);
     MapComponent_Tenants.GetComponent(pawn.Map).Broadcast = true;
     if (Rand.Value < 0.20f)
     {
         IncidentParms parms = StorytellerUtility.DefaultParmsNow(IncidentCategoryDefOf.ThreatBig, pawn.Map);
         parms.raidStrategy = RaidStrategyDefOf.Retribution;
         parms.forced       = true;
         Find.Storyteller.incidentQueue.Add(IncidentDefOf.Opportunists, Find.TickManager.TicksGame + Rand.Range(25000, 150000), parms, 240000);
     }
     else
     {
         IncidentParms parms = new IncidentParms()
         {
             target = pawn.Map, forced = true
         };
         Find.Storyteller.incidentQueue.Add(IncidentDefOf.RequestForTenancy, Find.TickManager.TicksGame + Rand.Range(15000, 120000), parms, 240000);
     }
 }
示例#16
0
        public static void TenantWanted(Pawn pawn)
        {
            Tenant tenantComp = pawn.GetTenantComponent();

            if (Rand.Value < 0.66 && tenantComp.WantedBy.HostileTo(Find.FactionManager.OfPlayer) && !MapComponent_Tenants.GetComponent(pawn.Map).WantedTenants.Contains(pawn))
            {
                MapComponent_Tenants.GetComponent(pawn.Map).WantedTenants.Add(pawn);
                IncidentParms parms = StorytellerUtility.DefaultParmsNow(IncidentCategoryDefOf.ThreatBig, pawn.Map);
                parms.raidStrategy = RaidStrategyDefOf.WantedRaid;
                parms.forced       = true;
                Find.Storyteller.incidentQueue.Add(IncidentDefOf.WantedRaid, Find.TickManager.TicksGame + Rand.Range(100000, 300000), parms, 60000);
            }
            else if (Rand.Value < 0.5)
            {
                tenantComp.WantedBy.RelationWith(Find.FactionManager.OfPlayer).goodwill -= SettingsHelper.LatestVersion.HarborPenalty;
                Find.FactionManager.OfPlayer.RelationWith(tenantComp.WantedBy).goodwill -= SettingsHelper.LatestVersion.HarborPenalty;

                Messages.Message("HarboringWantedTenant".Translate(pawn.GetTenantComponent().WantedBy, SettingsHelper.LatestVersion.HarborPenalty, pawn.Named("PAWN")), MessageTypeDefOf.NegativeEvent);
            }
        }
示例#17
0
 public static void CourierInvite(Building_CommsConsole comms, Pawn pawn)
 {
     if (MapComponent_Tenants.GetComponent(pawn.Map).KilledCourier > 0)
     {
         string courierDeniedLabel = "CourierDeniedTitle".Translate(pawn.Map.Parent.Label);
         string courierDeniedText  = "CourierDeniedRadioMessage".Translate();
         Find.LetterStack.ReceiveLetter(courierDeniedLabel, courierDeniedText, LetterDefOf.NegativeEvent);
     }
     else
     {
         Messages.Message("CourierInvited".Translate(SettingsHelper.LatestVersion.CourierCost), MessageTypeDefOf.NeutralEvent);
         MapComponent_Tenants.GetComponent(pawn.Map).BroadcastCourier = true;
         IncidentParms parms = new IncidentParms()
         {
             target = pawn.Map, forced = true
         };
         Find.Storyteller.incidentQueue.Add(IncidentDefOf.TenantCourier, Find.TickManager.TicksGame + Rand.Range(15000, 90000), parms, 240000);
         Thing silver = ThingMaker.MakeThing(RimWorld.ThingDefOf.Silver);
         silver.stackCount = (int)SettingsHelper.LatestVersion.CourierCost;
         MapComponent_Tenants.GetComponent(pawn.Map).CourierCost.Add(silver);
     }
 }
示例#18
0
        //public static void Tick_PostFix(Pawn __instance) {
        //    Tenant tenantComp = __instance.GetTenantComponent();
        //    if (tenantComp != null && tenantComp.IsTenant && __instance.IsColonist) {

        //    }
        //}
        public static void TickRare_PostFix(Pawn __instance)
        {
            if (__instance.IsColonist)
            {
                Tenant tenantComp = __instance.GetTenantComponent();
                if (tenantComp != null && tenantComp.IsTenant)
                {
                    //If a tenant has joined but has no contract.
                    if (!tenantComp.Contracted)
                    {
                        tenantComp.IsTenant = false;
                    }
                    //Tenant alone with no colonist
                    Pawn colonist = __instance.Map.mapPawns.FreeColonists.FirstOrDefault(x => x.GetTenantComponent().IsTenant == false);
                    if (colonist == null)
                    {
                        Events.ContractConclusion(__instance, true, 1f);
                        return;
                    }
                    //Tenant contract is out
                    if (Find.TickManager.TicksGame >= tenantComp.ContractEndTick)
                    {
                        Events.ContractConclusion(__instance, false);
                        return;
                    }

                    //If tenancy is to be terminated.
                    if (tenantComp.IsTerminated)
                    {
                        if (__instance.health.Downed)
                        {
                            Messages.Message("ContractTerminateFail".Translate(), MessageTypeDefOf.NeutralEvent);
                        }
                        else
                        {
                            Events.TenantCancelContract(__instance);
                            return;
                        }
                        tenantComp.IsTerminated = false;
                    }
                    ////Operations queue for tenancy rejected.
                    if (__instance.BillStack.Count > 0)
                    {
                        if ((__instance.BillStack.Bills.Where(x => x.recipe.isViolation == true).Count() > 0))
                        {
                            __instance.BillStack.Clear();
                            tenantComp.SurgeryQueue++;
                            if (tenantComp.SurgeryQueue < 2)
                            {
                                Messages.Message("TenantSurgeryWarning".Translate(__instance.Named("PAWN")), MessageTypeDefOf.NeutralEvent);
                            }
                            else
                            {
                                Messages.Message("TenantSurgeryLeave".Translate(__instance.Named("PAWN")), MessageTypeDefOf.NegativeEvent);
                                Events.TenantLeave(__instance);
                            }
                        }
                    }
                    //Tenancy tick per day
                    if (Find.TickManager.TicksGame % 60000 == 0)
                    {
                        if (tenantComp.Wanted)
                        {
                            if (!MapComponent_Tenants.GetComponent(__instance.Map).WantedTenants.Contains(__instance))
                            {
                                Events.TenantWanted(__instance);
                            }
                        }
                    }
                    //Tenancy tick 1/10 per day
                    if (Find.TickManager.TicksGame % 6000 == 0)
                    {
                        if (tenantComp.MoleMessage)
                        {
                            tenantComp.MoleMessage = false;
                            Messages.Message("TenantMoleMessage".Translate(), MessageTypeDefOf.NegativeEvent);
                        }
                        if (tenantComp.Mole && !tenantComp.MoleActivated)
                        {
                            if (Utility.CalculateMood(tenantComp) < 1 && tenantComp.NeutralMoodCount > 2)
                            {
                                Building building = __instance.Map.listerBuildings.allBuildingsColonist.FirstOrDefault(x => x.def.defName.Contains("commsconsole") || x.def.defName.Contains("CommsConsole"));
                                if (building != null)
                                {
                                    Job job = new Job(JobDefOf.JobUseCommsConsoleMole, building);
                                    __instance.jobs.TryTakeOrderedJob(job);
                                }
                            }
                        }
                        if (__instance.needs.mood.CurInstantLevel > 0.8f)
                        {
                            Events.TenantWantToJoin(__instance);
                        }

                        //Calculate mood
                        if (__instance.needs.mood.CurInstantLevel > 0.66f)
                        {
                            tenantComp.HappyMoodCount++;
                            tenantComp.RecentBadMoodsCount = 0;
                        }
                        else if (__instance.needs.mood.CurInstantLevel < __instance.mindState.mentalBreaker.BreakThresholdMinor)
                        {
                            tenantComp.SadMoodCount++;
                            tenantComp.RecentBadMoodsCount++;
                            if (tenantComp.RecentBadMoodsCount > 5)
                            {
                                Events.ContractConclusion(__instance, true);
                            }
                        }
                        else
                        {
                            tenantComp.NeutralMoodCount++;
                            tenantComp.RecentBadMoodsCount = 0;
                        }
                    }
                }
            }
        }