Пример #1
0
        public override void OnAcceptKeyPressed()
        {
            base.OnAcceptKeyPressed();
            SoundDefOf.ExecuteTrade.PlayOneShotOnCamera();

            if (daysAmount > 0 && hireData.Any(kvp => kvp.Value.First > 0))
            {
                var pawns = new List <Pawn>();

                var remainingCost = Mathf.RoundToInt(CostFinal);

                var silverList = targetMap.listerThings.ThingsOfDef(ThingDefOf.Silver)
                                 .Where(x => !x.Position.Fogged(x.Map) && (targetMap.areaManager.Home[x.Position] || x.IsInAnyStorage())).ToList();
                while (remainingCost > 0)
                {
                    var silver = silverList.First(t => t.stackCount > 0);
                    var num    = Mathf.Min(remainingCost, silver.stackCount);
                    silver.SplitOff(num).Destroy();
                    remainingCost -= num;
                }

                if (!RCellFinder.TryFindRandomPawnEntryCell(out var cell, targetMap, 1f))
                {
                    cell = CellFinder.RandomEdgeCell(targetMap);
                }

                foreach (var kvp in hireData)
                {
                    for (var i = 0; i < kvp.Value.First; i++)
                    {
                        var flag = kvp.Key.ignoreFactionApparelStuffRequirements;
                        kvp.Key.ignoreFactionApparelStuffRequirements = true;
                        var pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(kvp.Key, mustBeCapableOfViolence: true, faction: Faction.OfPlayer,
                                                                                        forbidAnyTitle: true, fixedIdeo: curFaction.referencedFaction is null
                                ? hiredIdeo ?? (hiredIdeo = IdeoGenerator.GenerateIdeo(new IdeoGenerationParms(Faction.OfPlayer.def, classic: true)))
                                : Find.World.factionManager.FirstFactionOfDef(curFaction.referencedFaction).ideos.GetRandomIdeoForNewPawn()));
                        kvp.Key.ignoreFactionApparelStuffRequirements = flag;
                        pawn.playerSettings.hostilityResponse         = HostilityResponseMode.Attack;
                        pawns.Add(pawn);
                        var loc = DropCellFinder.TryFindSafeLandingSpotCloseToColony(targetMap, IntVec2.Two);

                        var activeDropPodInfo = new ActiveDropPodInfo();
                        activeDropPodInfo.innerContainer.TryAdd(pawn, 1);
                        activeDropPodInfo.openDelay = 60;
                        activeDropPodInfo.leaveSlag = false;
                        activeDropPodInfo.despawnPodBeforeSpawningThing = true;
                        activeDropPodInfo.spawnWipeMode = WipeMode.Vanish;
                        DropPodUtility.MakeDropPodAt(loc, targetMap, activeDropPodInfo);
                    }
                }

                Find.World.GetComponent <HiringContractTracker>().SetNewContract(daysAmount, pawns, hireable, curFaction, CostFinal);
            }
        }