예제 #1
0
        public static void TryTendToRandomPawn(Caravan caravan)
        {
            CaravanTendUtility.FindPawnsNeedingTend(caravan, CaravanTendUtility.tmpPawnsNeedingTreatment);
            if (!CaravanTendUtility.tmpPawnsNeedingTreatment.Any <Pawn>())
            {
                return;
            }
            Pawn patient = CaravanTendUtility.tmpPawnsNeedingTreatment.RandomElement <Pawn>();
            Pawn pawn    = CaravanTendUtility.FindBestDoctor(caravan, patient);

            if (pawn == null)
            {
                return;
            }
            Medicine medicine = null;
            Pawn     pawn2    = null;

            CaravanInventoryUtility.TryGetBestMedicine(caravan, patient, out medicine, out pawn2);
            TendUtility.DoTend(pawn, patient, medicine);
            if (medicine != null && medicine.Destroyed && pawn2 != null)
            {
                pawn2.inventory.innerContainer.Remove(medicine);
            }
            CaravanTendUtility.tmpPawnsNeedingTreatment.Clear();
        }
예제 #2
0
        public static void TryTendToAnyPawn(Caravan caravan)
        {
            CaravanTendUtility.FindPawnsNeedingTend(caravan, CaravanTendUtility.tmpPawnsNeedingTreatment);
            if (!CaravanTendUtility.tmpPawnsNeedingTreatment.Any <Pawn>())
            {
                return;
            }
            CaravanTendUtility.tmpPawnsNeedingTreatment.SortByDescending(new Func <Pawn, float>(CaravanTendUtility.GetTendPriority));
            Pawn patient = null;
            Pawn pawn    = null;

            for (int i = 0; i < CaravanTendUtility.tmpPawnsNeedingTreatment.Count; i++)
            {
                patient = CaravanTendUtility.tmpPawnsNeedingTreatment[i];
                pawn    = CaravanTendUtility.FindBestDoctorFor(caravan, patient);
                if (pawn != null)
                {
                    break;
                }
            }
            if (pawn == null)
            {
                return;
            }
            Medicine medicine = null;
            Pawn     pawn2    = null;

            CaravanInventoryUtility.TryGetBestMedicine(caravan, patient, out medicine, out pawn2);
            TendUtility.DoTend(pawn, patient, medicine);
            if (medicine != null && medicine.Destroyed && pawn2 != null)
            {
                pawn2.inventory.innerContainer.Remove(medicine);
            }
            CaravanTendUtility.tmpPawnsNeedingTreatment.Clear();
        }
예제 #3
0
파일: Caravan.cs 프로젝트: potsh/RimWorld
 public override void Tick()
 {
     base.Tick();
     CheckAnyNonWorldPawns();
     pather.PatherTick();
     tweener.TweenerTick();
     forage.ForageTrackerTick();
     carryTracker.CarryTrackerTick();
     beds.BedsTrackerTick();
     needs.NeedsTrackerTick();
     CaravanDrugPolicyUtility.CheckTakeScheduledDrugs(this);
     CaravanTendUtility.CheckTend(this);
 }
 public static void CheckTend(Caravan caravan)
 {
     for (int i = 0; i < caravan.pawns.Count; i++)
     {
         Pawn pawn = caravan.pawns[i];
         if (CaravanTendUtility.IsValidDoctorFor(pawn, null, caravan))
         {
             if (pawn.IsHashIntervalTick(1250))
             {
                 CaravanTendUtility.TryTendToAnyPawn(caravan);
             }
         }
     }
 }
예제 #5
0
 public override void Tick()
 {
     base.Tick();
     this.CheckAnyNonWorldPawns();
     this.pather.PatherTick();
     this.tweener.TweenerTick();
     CaravanPawnsNeedsUtility.TrySatisfyPawnsNeeds(this);
     if (this.IsHashIntervalTick(120))
     {
         CaravanDrugPolicyUtility.TryTakeScheduledDrugs(this);
     }
     if (this.IsHashIntervalTick(2000))
     {
         CaravanTendUtility.TryTendToRandomPawn(this);
     }
 }
        private static Pawn FindBestDoctorFor(Caravan caravan, Pawn patient)
        {
            float       num  = 0f;
            Pawn        pawn = null;
            List <Pawn> pawnsListForReading = caravan.PawnsListForReading;

            for (int i = 0; i < pawnsListForReading.Count; i++)
            {
                Pawn pawn2 = pawnsListForReading[i];
                if (CaravanTendUtility.IsValidDoctorFor(pawn2, patient, caravan))
                {
                    float statValue = pawn2.GetStatValue(StatDefOf.MedicalTendQuality, true);
                    if (statValue > num || pawn == null)
                    {
                        num  = statValue;
                        pawn = pawn2;
                    }
                }
            }
            return(pawn);
        }