Пример #1
0
        public Hediff BuildHediff(PartCustomisePack pack, BodyPartRecord rec, Droid d)
        {
            Hediff_DroidStatsApplier hediff = (Hediff_DroidStatsApplier)HediffMaker.MakeHediff(DroidsDefOf.MD3_DroidStatsApplier, d, rec);
            HediffStageSaveable      stage  = new HediffStageSaveable();

            stage.statOffsets      = new List <StatModifier>();
            hediff.AddedPartHealth = pack.Part.addedPartHealth;
            if (pack.Part.statOffsets != null && pack.Part.statOffsets.Count > 0)
            {
                stage.statOffsets.AddRange(pack.Part.statOffsets);
            }
            if (pack.Part.requirements != null && pack.Part.requirements.Count > 0)
            {
                stage.statOffsets.AddRange(pack.Part.requirements);
            }
            if (pack.Part.capMods.Count > 0)
            {
                foreach (var capMod in pack.Part.capMods)
                {
                    stage.capMods.Add(capMod);
                }
            }
            hediff.Stage = stage;
            hediff.label = pack.Part.LabelCap;
            return(hediff);
        }
Пример #2
0
 public void AddHediffsToDroid(Droid d)
 {
     if (HasModifiedBody)
     {
         var packs = (from t in Parts
                      where t.Part.BasePart == false
                      select t).ToList();
         foreach (var pack in packs)
         {
             var list = d.GetBodyPartRecords(pack.ChassisPoint, pack.BodyPosition);
             if (list.Count > 0)
             {
                 foreach (var rec in list)
                 {
                     var hediff = BuildHediff(pack, rec, d);
                     d.health.AddHediff(hediff, rec);
                 }
             }
             else
             {
                 throw new Exception($"Have customisation packs for body but couldn't find the parts! {pack.ToString()}");
             }
         }
     }
 }
Пример #3
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (!(pawn is ICharge))
            {
                return(null);
            }
            ICharge chargee = (ICharge)pawn;
            Droid   droid   = (Droid)pawn;

            if (droid != null && !droid.Active)
            {
                return(null);
            }

            float chargeThreshold;
            float distance;

            switch (stage)
            {
            case 1:
            {
                chargeThreshold = chargee.PowerSafeThreshold;
                distance        = 20f;
                break;
            }

            case 2:
            {
                chargeThreshold = chargee.PowerLowThreshold;
                distance        = 50f;
                break;
            }

            case 3:
            {
                chargeThreshold = chargee.PowerCriticalThreshold;
                distance        = 9999f;
                break;
            }

            default:
            {
                chargeThreshold = chargee.PowerLowThreshold;
                distance        = 50f;
                break;
            }
            }
            if (chargee.TotalCharge <= chargee.MaxEnergy * chargeThreshold)
            {
                Thing target = DroidManager.Instance.ClosestChargerFor(chargee, droid.Map, distance);
                if (target != null)
                {
                    if (droid.CanReserve(target, 1, -1, null, false))
                    {
                        return(new Job(DefDatabase <JobDef> .GetNamed("MD3_ChargeDroidJob"), new LocalTargetInfo(target)));
                    }
                }
            }
            return(null);
        }
Пример #4
0
 public void AddSkillsToDroid(Droid d)
 {
     foreach (var skillRecord in d.skills.skills)
     {
         SkillLevel sl = GetSkillLevel(skillRecord);
         skillRecord.levelInt = sl.Level;
     }
 }
Пример #5
0
 public static Droid StatDummy(Blueprint bp)
 {
     if (statDummy == null || statDummy.kindDef != bp.KindDef || statDummy.blueprint != bp)
     {
         statDummy           = (Droid)PawnGenerator.GeneratePawn(bp.KindDef);
         statDummy.blueprint = bp;
         statDummy.InitialiseFromBlueprint();
         StatsReportUtility.Reset();
     }
     return(statDummy);
 }
Пример #6
0
        static bool NotifyPlayerOfKilled(Pawn_HealthTracker __instance, ref DamageInfo?dinfo)
        {
            var pawn = (typeof(Pawn_HealthTracker).GetField("pawn", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(__instance));

            if (pawn is Droid)
            {
                Droid d = pawn as Droid;
                //TODO:: Write custom droid destroyed message
                return(false);
            }
            return(true);
        }
Пример #7
0
 public static Droid GenerateDroid(PawnKindDef kindDef, Blueprint bp, Faction faction = null)
 {
     try
     {
         Droid d = (Droid)PawnGenerator.GeneratePawn(kindDef, faction);
         d.blueprint = bp;
         d.InitialiseFromBlueprint();
         return(d);
     }
     catch (Exception ex)
     {
         Log.Error($"Error generating droid: {ex}");
         return(null);
     }
 }
Пример #8
0
 protected override void PasteTo(Pawn p)
 {
     if (p is Droid)
     {
         Droid d = p as Droid;
         List <WorkTypeDef> allDefsListForReading = DefDatabase <WorkTypeDef> .AllDefsListForReading;
         for (int i = 0; i < allDefsListForReading.Count; i++)
         {
             WorkTypeDef workTypeDef = allDefsListForReading[i];
             if (d.aiPackages.CapableOfWorkType(workTypeDef))
             {
                 p.workSettings.SetPriority(workTypeDef, clipboard[workTypeDef]);
             }
         }
     }
 }
 public override void DoCell(Rect rect, Pawn pawn, PawnTable table)
 {
     if (pawn is Droid)
     {
         Droid droid = pawn as Droid;
         if (!pawn.Dead && pawn.workSettings != null && pawn.workSettings.EverWork)
         {
             Text.Font = GameFont.Medium;
             float x         = rect.x + (rect.width - 25f) / 2f;
             float y         = rect.y + 2.5f;
             bool  incapable = false;// IsIncapableOfWholeWorkType(pawn, def.workType);
             if (droid.aiPackages.CapableOfWorkType(def.workType))
             {
                 WidgetsWork.DrawWorkBoxFor(x, y, pawn, def.workType, incapable);
             }
             Rect rect2 = new Rect(x, y, 25f, 25f);
             TooltipHandler.TipRegion(rect2, () => WidgetsWork.TipForPawnWorker(pawn, def.workType, incapable), pawn.thingIDNumber ^ def.workType.GetHashCode());
             Text.Font = GameFont.Small;
         }
     }
 }
Пример #10
0
 public Droid_AIPackageTracker(Droid droid)
 {
     this.droid = droid;
 }
Пример #11
0
 public void DeregisterDroid(Droid droid)
 {
     droids.Remove(droid);
 }
Пример #12
0
 public void RegisterDroid(Droid droid)
 {
     droids.Add(droid);
 }
Пример #13
0
 public Droid_WorkManager(Droid droid)
 {
     this.droid = droid;
 }
Пример #14
0
        public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams)
        {
            Droid d = null;

            if (pawn is Droid)
            {
                d = pawn as Droid;
            }
            else
            {
                return(ThinkResult.NoJob);
            }
            List <WorkGiver> list               = emergency ? d.workManager.WorkGiversInOrderEmergency : d.workManager.WorkGiversInOrder;
            int               num               = -999;
            TargetInfo        targetInfo        = TargetInfo.Invalid;
            WorkGiver_Scanner workGiver_Scanner = null;
            WorkGiver_Scanner scanner;

            for (int j = 0; j < list.Count; j++)
            {
                WorkGiver workGiver = list[j];
                if (workGiver.def.priorityInType != num && targetInfo.IsValid)
                {
                    break;
                }
                if (PawnCanUseWorkGiver(pawn, workGiver))
                {
                    try
                    {
                        Job job2 = workGiver.NonScanJob(pawn);
                        if (job2 != null)
                        {
                            return(new ThinkResult(job2, this, list[j].def.tagToGive, false));
                        }
                        scanner = (workGiver as WorkGiver_Scanner);
                        if (scanner != null)
                        {
                            IntVec3 intVec;
                            if (scanner.def.scanThings)
                            {
                                Predicate <Thing>   predicate  = (Thing t) => !t.IsForbidden(pawn) && scanner.HasJobOnThing(pawn, t, false);
                                IEnumerable <Thing> enumerable = scanner.PotentialWorkThingsGlobal(pawn);
                                Thing thing;
                                if (scanner.Prioritized)
                                {
                                    IEnumerable <Thing> enumerable2 = enumerable;
                                    if (enumerable2 == null)
                                    {
                                        enumerable2 = pawn.Map.listerThings.ThingsMatching(scanner.PotentialWorkThingRequest);
                                    }
                                    if (scanner.AllowUnreachable)
                                    {
                                        intVec = pawn.Position;
                                        IEnumerable <Thing> searchSet = enumerable2;
                                        Predicate <Thing>   validator = predicate;
                                        thing = GenClosest.ClosestThing_Global(intVec, searchSet, 99999f, validator, (Thing x) => scanner.GetPriority(pawn, x));
                                    }
                                    else
                                    {
                                        intVec = pawn.Position;
                                        Map map = pawn.Map;
                                        IEnumerable <Thing> searchSet      = enumerable2;
                                        PathEndMode         pathEndMode    = scanner.PathEndMode;
                                        TraverseParms       traverseParams = TraverseParms.For(pawn, scanner.MaxPathDanger(pawn), TraverseMode.ByPawn, false);
                                        Predicate <Thing>   validator      = predicate;
                                        thing = GenClosest.ClosestThing_Global_Reachable(intVec, map, searchSet, pathEndMode, traverseParams, 9999f, validator, (Thing x) => scanner.GetPriority(pawn, x));
                                    }
                                }
                                else if (scanner.AllowUnreachable)
                                {
                                    IEnumerable <Thing> enumerable3 = enumerable;
                                    if (enumerable3 == null)
                                    {
                                        enumerable3 = pawn.Map.listerThings.ThingsMatching(scanner.PotentialWorkThingRequest);
                                    }
                                    intVec = pawn.Position;
                                    IEnumerable <Thing> searchSet = enumerable3;
                                    Predicate <Thing>   validator = predicate;
                                    thing = GenClosest.ClosestThing_Global(intVec, searchSet, 99999f, validator, null);
                                }
                                else
                                {
                                    intVec = pawn.Position;
                                    Map               map = pawn.Map;
                                    ThingRequest      potentialWorkThingRequest = scanner.PotentialWorkThingRequest;
                                    PathEndMode       pathEndMode       = scanner.PathEndMode;
                                    TraverseParms     traverseParams    = TraverseParms.For(pawn, scanner.MaxPathDanger(pawn), TraverseMode.ByPawn, false);
                                    Predicate <Thing> validator         = predicate;
                                    bool              forceGlobalSearch = enumerable != null;
                                    thing = GenClosest.ClosestThingReachable(intVec, map, potentialWorkThingRequest, pathEndMode, traverseParams, 9999f, validator, enumerable, 0, scanner.LocalRegionsToScanFirst, forceGlobalSearch, RegionType.Set_Passable, false);
                                }
                                if (thing != null)
                                {
                                    targetInfo        = thing;
                                    workGiver_Scanner = scanner;
                                }
                            }
                            if (scanner.def.scanCells)
                            {
                                IntVec3 position         = pawn.Position;
                                float   num2             = 99999f;
                                float   num3             = -3.40282347E+38f;
                                bool    prioritized      = scanner.Prioritized;
                                bool    allowUnreachable = scanner.AllowUnreachable;
                                Danger  maxDanger        = scanner.MaxPathDanger(pawn);
                                foreach (IntVec3 item in scanner.PotentialWorkCellsGlobal(pawn))
                                {
                                    bool flag = false;
                                    intVec = item - position;
                                    float num4 = (float)intVec.LengthHorizontalSquared;
                                    float num5 = 0f;
                                    if (prioritized)
                                    {
                                        if (scanner.HasJobOnCell(pawn, item))
                                        {
                                            if (!allowUnreachable && !pawn.CanReach(item, scanner.PathEndMode, maxDanger, false, TraverseMode.ByPawn))
                                            {
                                                continue;
                                            }
                                            num5 = scanner.GetPriority(pawn, item);
                                            if (num5 > num3 || (num5 == num3 && num4 < num2))
                                            {
                                                flag = true;
                                            }
                                        }
                                    }
                                    else if (num4 < num2 && scanner.HasJobOnCell(pawn, item))
                                    {
                                        if (!allowUnreachable && !pawn.CanReach(item, scanner.PathEndMode, maxDanger, false, TraverseMode.ByPawn))
                                        {
                                            continue;
                                        }
                                        flag = true;
                                    }
                                    if (flag)
                                    {
                                        targetInfo        = new TargetInfo(item, pawn.Map, false);
                                        workGiver_Scanner = scanner;
                                        num2 = num4;
                                        num3 = num5;
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(pawn + " threw exception in WorkGiver " + workGiver.def.defName + ": " + ex.ToString());
                    }
                    finally
                    {
                    }
                    if (targetInfo.IsValid)
                    {
                        pawn.mindState.lastGivenWorkType = workGiver.def.workType;
                        Job job3 = (!targetInfo.HasThing) ? workGiver_Scanner.JobOnCell(pawn, targetInfo.Cell) : workGiver_Scanner.JobOnThing(pawn, targetInfo.Thing, false);
                        if (job3 != null)
                        {
                            return(new ThinkResult(job3, this, list[j].def.tagToGive, false));
                        }
                        Log.ErrorOnce(workGiver_Scanner + " provided target " + targetInfo + " but yielded no actual job for pawn " + pawn + ". The CanGiveJob and JobOnX methods may not be synchronized.", 6112651);
                    }
                    num = workGiver.def.priorityInType;
                }
            }
            return(ThinkResult.NoJob);
        }
Пример #15
0
        protected override void FillTab()
        {
            if (selBlueprint == null)
            {
                size = SmallSize;
            }
            else
            {
                size = LargeSize;
            }

            Rect baseRect = new Rect(0f, 20f, size.x, size.y - 20f);
            Rect mainRect = baseRect.ContractedBy(10f);

            try
            {
                GUI.BeginGroup(mainRect);

                //Designs list area
                Rect designsListRect = new Rect(0f, 0f, 240f, mainRect.height - CreateButtonSize.y - SectionMargin);
                Widgets.DrawBoxSolid(designsListRect, BoxColor);
                DrawDesignList(designsListRect);

                //DEBUG:: Spawn droid button
                Rect spawnButtonRect = new Rect(designsListRect.xMax - 70f, designsListRect.yMax - 30f, 50f, 30f);
                if (Widgets.ButtonText(spawnButtonRect, "spawn"))
                {
                    if (selBlueprint != null)
                    {
                        Droid d = DroidGenerator.GenerateDroid(DefDatabase <PawnKindDef> .GetNamed("MD3_Droid"), selBlueprint, Faction.OfPlayer);
                        GenSpawn.Spawn(d, ((Building)SelObject).InteractionCell, ((Building)SelObject).Map);
                    }
                }

                //Create button
                Rect createButtonRect = new Rect(designsListRect.xMax - CreateButtonSize.x, designsListRect.yMax + SectionMargin, CreateButtonSize.x, CreateButtonSize.y);
                if (Widgets.ButtonText(createButtonRect, "New".Translate()))
                {
                    Find.WindowStack.Add(new Dialog_NewBlueprint(new Blueprint()));
                }

                //Delete button
                if (selBlueprint != null)
                {
                    Rect deleteButtonRect = new Rect(0f, createButtonRect.y, createButtonRect.x - 2f, CreateButtonSize.y);
                    if (Widgets.ButtonText(deleteButtonRect, "Delete".Translate()) && selBlueprint != null)
                    {
                        Dialog_Confirm confirm = new Dialog_Confirm("ConfirmDeleteBlueprint".Translate(), delegate
                        {
                            DroidManager.Instance.Blueprints.Remove(selBlueprint);
                            selBlueprint = null;
                        });
                        Find.WindowStack.Add(confirm);
                    }
                }

                if (selBlueprint != null)
                {
                    Rect blueprintRect = new Rect(designsListRect.xMax + SectionMargin, 0f, mainRect.width - designsListRect.width - SectionMargin, mainRect.height);
                    bpHandler?.DrawWindow(blueprintRect);
                }
            }
            finally
            {
                GUI.EndGroup();
            }
        }