Ejemplo n.º 1
0
            public static void Listener(CompPowerTrader __instance, ref float ___powerOutputInt)
            {
                CompReloadStation rs = __instance.parent.TryGetComp <CompReloadStation>();

                if (rs != null)
                {
                    rs.refreshPowerConsumed();
                }
            }
        public override IEnumerable <FloatMenuOption> GetFloatMenuOptions(Pawn myPawn)
        {
            FloatMenuOption failureReason = this.GetFailureReason(myPawn);

            if (failureReason != null)
            {
                yield return(failureReason);
            }
            else
            {
                yield return(new FloatMenuOption("ATPP_ForceReload".Translate(), delegate(){
                    CompReloadStation rs = this.TryGetComp <CompReloadStation>();

                    Job job = new Job(DefDatabase <JobDef> .GetNamed("ATPP_GoReloadBattery"), new LocalTargetInfo(rs.getFreeReloadPlacePos(myPawn)), new LocalTargetInfo(this));
                    myPawn.jobs.TryTakeOrderedJob(job, JobTag.Misc);
                }, MenuOptionPriority.Default, null, null, 0f, null, null));
            }
        }
        private FloatMenuOption GetFailureReason(Pawn myPawn)
        {
            if (!myPawn.CanReach(this, PathEndMode.InteractionCell, Danger.Some, false, TraverseMode.ByPawn))
            {
                return(new FloatMenuOption("CannotUseNoPath".Translate(), null, MenuOptionPriority.Default, null, null, 0f, null, null));
            }
            if (base.Spawned && base.Map.gameConditionManager.ConditionIsActive(GameConditionDefOf.SolarFlare))
            {
                return(new FloatMenuOption("CannotUseSolarFlare".Translate(), null, MenuOptionPriority.Default, null, null, 0f, null, null));
            }
            if (!this.TryGetComp <CompPowerTrader>().PowerOn)
            {
                return(new FloatMenuOption("CannotUseNoPower".Translate(), null, MenuOptionPriority.Default, null, null, 0f, null, null));
            }
            if (!Utils.ExceptionAndroidList.Contains(myPawn.def.defName))
            {
                return(new FloatMenuOption("ATPP_CanOnlyBeUsedByAndroid".Translate(), null, MenuOptionPriority.Default, null, null, 0f, null, null));
            }

            CompAndroidState ca = myPawn.TryGetComp <CompAndroidState>();

            if (ca == null || !ca.UseBattery)
            {
                return(new FloatMenuOption("ATPP_CannotUseBecauseNotInBatteryMode".Translate(), null, MenuOptionPriority.Default, null, null, 0f, null, null));
            }


            CompReloadStation rs = this.TryGetComp <CompReloadStation>();
            int nb = rs.getNbAndroidReloading(true);

            if (nb >= 8)
            {
                return(new FloatMenuOption("ATPP_CannotUseEveryPlaceUsed".Translate(), null, MenuOptionPriority.Default, null, null, 0f, null, null));
            }

            return(null);
        }
            public static void Listener(Pawn pawn, ref Job __result)
            {
                try
                {
                    //Si android alors OK
                    if (Utils.ExceptionAndroidCanReloadWithPowerList.Contains(pawn.def.defName))
                    {
                        //Check si l'android utilise sa batterie le cas non echeant on arrete l'override ET on l'arret aussi si l'android dans une caravane !!
                        CompAndroidState ca = pawn.TryGetComp <CompAndroidState>();
                        if (ca == null || !pawn.Spawned || !ca.UseBattery || pawn.Drafted)
                        {
                            return;
                        }

                        //SI recharge LWPN en cours valide alors on annule la recharge par nourrite ou elec traditionelle
                        if (Utils.POWERPP_LOADED && ca.connectedLWPNActive && ca.connectedLWPN != null)
                        {
                            __result = null;
                            return;
                        }


                        Building_Bed pod = null;
                        //Check disponibilité d'un POD alimenté
                        try
                        {
                            pod = Utils.getAvailableAndroidPodForCharging(pawn, pawn.def.defName == "M7Mech");
                        }
                        catch (Exception)
                        {
                        }

                        if (pod != null)
                        {
                            __result = new Job(DefDatabase <JobDef> .GetNamed("ATPP_GoReloadBattery"), new LocalTargetInfo(pod));
                            return;
                        }

                        //Log.Message("Android want EAT !!! ");
                        //Recherche reload station disponible sur la map
                        Building rsb = Utils.GCATPP.getFreeReloadStation(pawn.Map, pawn);
                        if (rsb == null)
                        {
                            __result = null;
                            //Log.Message("No ReloadStation found !!");
                            return;
                        }
                        //Obtention place disponible sur la RS
                        CompReloadStation rs = rsb.TryGetComp <CompReloadStation>();

                        if (rs == null)
                        {
                            __result = null;
                            //Log.Message("No Place available on ReloadStation");
                            return;
                        }

                        __result = new Job(DefDatabase <JobDef> .GetNamed("ATPP_GoReloadBattery"), new LocalTargetInfo(rs.getFreeReloadPlacePos(pawn)), new LocalTargetInfo(rsb));
                    }
                }
                catch (Exception e)
                {
                    Log.Message("[ATPP] JobGiver_GetFood.TryGiveJob : " + e.Message + " - " + e.StackTrace);
                }
            }