Пример #1
0
        private bool TryInteractRandomly()
        {
            if (InteractedTooRecentlyToInteract())
            {
                return(false);
            }
            if (!InteractionUtility.CanInitiateRandomInteraction(pawn))
            {
                return(false);
            }
            List <Pawn> collection = pawn.Map.mapPawns.SpawnedPawnsInFaction(pawn.Faction);

            workingList.Clear();
            workingList.AddRange(collection);
            workingList.Shuffle();
            List <InteractionDef> allDefsListForReading = DefDatabase <InteractionDef> .AllDefsListForReading;

            for (int i = 0; i < workingList.Count; i++)
            {
                Pawn p = workingList[i];
                if (p != pawn && CanInteractNowWith(p) && InteractionUtility.CanReceiveRandomInteraction(p) && !pawn.HostileTo(p) && allDefsListForReading.TryRandomElementByWeight((InteractionDef x) => (!CanInteractNowWith(p, x)) ? 0f : x.Worker.RandomSelectionWeight(pawn, p), out InteractionDef result))
                {
                    if (TryInteractWith(p, result))
                    {
                        workingList.Clear();
                        return(true);
                    }
                    Log.Error(pawn + " failed to interact with " + p);
                }
            }
            workingList.Clear();
            return(false);
        }
        private bool TryInteractRandomly()
        {
            if (this.InteractedTooRecentlyToInteract())
            {
                return(false);
            }
            if (!InteractionUtility.CanInitiateRandomInteraction(this.pawn))
            {
                return(false);
            }
            List <Pawn> collection = this.pawn.Map.mapPawns.SpawnedPawnsInFaction(this.pawn.Faction);

            Pawn_InteractionsTracker.workingList.Clear();
            Pawn_InteractionsTracker.workingList.AddRange(collection);
            Pawn_InteractionsTracker.workingList.Shuffle <Pawn>();
            List <InteractionDef> allDefsListForReading = DefDatabase <InteractionDef> .AllDefsListForReading;

            for (int i = 0; i < Pawn_InteractionsTracker.workingList.Count; i++)
            {
                Pawn p = Pawn_InteractionsTracker.workingList[i];
                if (p != this.pawn && this.CanInteractNowWith(p) && InteractionUtility.CanReceiveRandomInteraction(p) && !this.pawn.HostileTo(p))
                {
                    InteractionDef intDef;
                    if (allDefsListForReading.TryRandomElementByWeight((InteractionDef x) => x.Worker.RandomSelectionWeight(this.pawn, p), out intDef))
                    {
                        if (this.TryInteractWith(p, intDef))
                        {
                            return(true);
                        }
                        Log.Error(this.pawn + " failed to interact with " + p);
                    }
                }
            }
            return(false);
        }