Exemplo n.º 1
0
            public static void Listener(Pawn p, ref ThoughtState __result)
            {
                try
                {
                    if (!__result.Active)
                    {
                        return;
                    }

                    CompSurrogateOwner cso = p.TryGetComp <CompSurrogateOwner>();

                    Pawn otherPawn          = LovePartnerRelationUtility.ExistingMostLikedLovePartnerRel(p, false).otherPawn;
                    CompSurrogateOwner cso2 = null;
                    if (otherPawn != null)
                    {
                        cso2 = otherPawn.TryGetComp <CompSurrogateOwner>();
                    }

                    if (p.IsAndroidTier() || p.IsSurrogateAndroid() || (cso != null && cso.skyCloudHost != null) || (otherPawn != null && (otherPawn.IsAndroidTier() || otherPawn.IsSurrogateAndroid() || (cso2 != null && cso2.skyCloudHost != null))))
                    {
                        __result = false;
                    }
                }
                catch (Exception e)
                {
                    Log.Message("[ATTP] ThoughtWorker_WantToSleepWithSpouseOrLover.CurrentStateInternal " + e.Message + " " + e.StackTrace);
                }
            }
        public override void FinalizeDesignationSucceeded()
        {
            base.FinalizeDesignationSucceeded();


            CompSurrogateOwner cso = controller.ATCompSurrogateOwner;

            if (cso != null)
            {
                if (kindOfTarget == 1)
                {
                    cso.controlMode = true;
                    cso.setControlledSurrogate((Pawn)target);
                }
                else if (kindOfTarget == 2)
                {
                    if (cso.skyCloudHost != null)
                    {
                        CompSkyCloudCore csc = cso.skyCloudHost.TryGetComp <CompSkyCloudCore>();
                        if (csc != null)
                        {
                            csc.setRemotelyControlledTurret(controller, (Building)target);
                        }
                    }
                }
            }

            if (!controller.VX3ChipPresent())
            {
                Find.DesignatorManager.Deselect();
            }
        }
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            CompAndroidState cas = pawn.TryGetComp <CompAndroidState>();

            if (cas == null)
            {
                return;
            }

            //Le cas echeant on deconnecte le controlleur s'il y en a un
            if (cas.surrogateController != null)
            {
                CompSurrogateOwner cso = cas.surrogateController.TryGetComp <CompSurrogateOwner>();
                if (cso != null)
                {
                    cso.disconnectControlledSurrogate(pawn);
                }
            }

            //On définis le fait qu'il ne sagit plus d'un surrogate mais d'un blank neural net andorid
            cas.isSurrogate = false;
            Hediff he = pawn.health.hediffSet.GetFirstHediffOfDef(Utils.hediffNoHost);

            if (he != null)
            {
                pawn.health.RemoveHediff(he);
            }

            cas.isBlankAndroid = true;
            pawn.health.AddHediff(Utils.hediffBlankAndroid);
        }
        public override void PostDrawExtraSelectionOverlays()
        {
            base.PostDrawExtraSelectionOverlays();

            //Affichage minds connectés
            foreach (var p in storedMinds)
            {
                //Colon digitalisé connecté à un surrogate on trace le lien
                CompSurrogateOwner cso = p.ATCompSurrogateOwner;

                foreach (var csx in cso.availableSX)
                {
                    if (parent.Map == csx.Map)
                    {
                        GenDraw.DrawLineBetween(parent.TrueCenter(), csx.TrueCenter(), SimpleColor.Red);
                    }
                }
            }

            //Affichage turets connectés
            foreach (var p in controlledTurrets)
            {
                if (parent.Map == p.Value.Map)
                {
                    GenDraw.DrawLineBetween(parent.TrueCenter(), p.Value.TrueCenter(), SimpleColor.Red);
                }
            }
        }
Exemplo n.º 5
0
            public static void Listener(MentalStateDef stateDef, string reason, bool forceWake, bool causedByMood, Pawn otherPawn, bool transitionSilently, Pawn ___pawn, MentalStateHandler __instance, ref bool __result)
            {
                if (__result && ___pawn.IsSurrogateAndroid())
                {
                    CompAndroidState cas = ___pawn.TryGetComp <CompAndroidState>();

                    if (cas == null || cas.surrogateController == null)
                    {
                        return;
                    }

                    CompSurrogateOwner cso = cas.surrogateController.TryGetComp <CompSurrogateOwner>();
                    if (cso.skyCloudHost != null)
                    {
                        CompSkyCloudCore csc = cso.skyCloudHost.TryGetComp <CompSkyCloudCore>();
                        if (csc == null)
                        {
                            return;
                        }


                        //Ajout a une liste de minds boudant avec timeout
                        csc.setMentalBreak(cas.surrogateController);
                    }
                }
            }
        public override string CompInspectStringExtra()
        {
            string   ret   = "";
            Building build = (Building)parent;

            if (parent.Map == null)
            {
                return(base.CompInspectStringExtra());
            }

            ret += getName() + "\n";
            ret += "ATPP_CentralCoreNbStoredMind".Translate(storedMinds.Count) + "\n";
            ret += "ATPP_CentralCoreNbAssistingMinds".Translate(assistingMinds.Count) + "\n";

            if (build.TryGetComp <CompPowerTrader>().PowerOn)
            {
                if (!Booted())
                {
                    ret += "ATPP_SkyCloudCoreBooting".Translate((int)(Math.Max(0, bootGT - Find.TickManager.TicksGame)).TicksToSeconds());
                }
                else
                {
                    //Check migration en cours de mind
                    foreach (var m in storedMinds)
                    {
                        CompSurrogateOwner cso = m.ATCompSurrogateOwner;

                        if (cso == null)
                        {
                            continue;
                        }

                        if (cso.replicationEndingGT != -1)
                        {
                            float p = Math.Min(1.0f, (float)(Find.TickManager.TicksGame - cso.replicationStartGT) / (float)(cso.replicationEndingGT - cso.replicationStartGT));

                            ret += "=>" + ("ATPP_CentralCoreReplicationInProgress".Translate(m.LabelShortCap, ((int)(p * (float)100)).ToString())) + "\n";
                        }
                        //ATPP_CentralCoreReplicationInProgress

                        else if (cso.migrationEndingGT != -1 && cso.migrationSkyCloudHostDest != null)
                        {
                            CompSkyCloudCore csc2 = cso.migrationSkyCloudHostDest.TryGetComp <CompSkyCloudCore>();
                            float            p    = Math.Min(1.0f, (float)(Find.TickManager.TicksGame - cso.migrationStartGT) / (float)(cso.migrationEndingGT - cso.migrationStartGT));

                            ret += "=>" + ("ATPP_CentralCoreMigrationInProgress".Translate(m.LabelShortCap, csc2.getName(), ((int)(p * (float)100)).ToString())) + "\n";
                        }

                        else if (inMentalBreak.ContainsKey(m))
                        {
                            ret += "=>" + "ATPP_CentralCoreProcessInMentalBreak".Translate(m.LabelShortCap) + "\n";
                        }
                    }
                }
            }

            return(ret.TrimEnd('\r', '\n') + base.CompInspectStringExtra());
        }
Exemplo n.º 7
0
 public static void Listener(Thing __instance, ref bool __result)
 {
     if (__instance is Pawn)
     {
         CompSurrogateOwner cso = ((Pawn)__instance).TryGetComp <CompSurrogateOwner>();
         if (cso != null && cso.skyCloudHost != null)
         {
             __result = true;
         }
     }
 }
 private void disconnectAllSurrogates()
 {
     foreach (var m in storedMinds)
     {
         CompSurrogateOwner cso = m.ATCompSurrogateOwner;
         if (cso != null)
         {
             cso.stopControlledSurrogate(null);
         }
     }
 }
Exemplo n.º 9
0
            public static bool Prefix(Rect outRect, Pawn pawn, bool allowOperations, bool showBloodLoss, Thing thingForMedBills)
            {
                Utils.curSelPatientDrawMedOperationsTab = pawn;
                CompSurrogateOwner cso = pawn.ATCompSurrogateOwner;

                if (cso != null && cso.skyCloudHost != null)
                {
                    return(false);
                }
                return(true);
            }
            public static bool Listener(Pawn ___pawn)
            {
                CompSurrogateOwner cso = ___pawn.TryGetComp <CompSurrogateOwner>();

                if (cso != null && cso.skyCloudHost != null)
                {
                    return(false);
                }

                return(true);
            }
            public static bool Listener(Pawn __instance, DamageInfo?dinfo, Hediff exactCulprit = null)
            {
                try
                {
                    if (__instance.IsSurrogateAndroid())
                    {
                        Utils.insideKillFuncSurrogate = true;

                        //Si c'est un surrogate controllé temporaire alors on le restitue a sa faction
                        CompSkyMind csm = __instance.TryGetComp <CompSkyMind>();
                        if (csm != null)
                        {
                            //Log.Message("Restitution surrogate a sa faction");
                            csm.tempHackingEnding();
                        }
                    }
                    //disconnect killed user
                    Utils.GCATPP.disconnectUser(__instance);
                    //Log.Message("YOU KILLED "+__instance.LabelCap);
                    //Is surrogate android used ?
                    if (__instance.IsSurrogateAndroid(true))
                    {
                        //Obtention controlleur
                        CompAndroidState cas = __instance.TryGetComp <CompAndroidState>();
                        if (cas == null)
                        {
                            return(true);
                        }

                        //Arret du mode de control chez le controller
                        CompSurrogateOwner cso = cas.surrogateController.TryGetComp <CompSurrogateOwner>();
                        cso.stopControlledSurrogate(__instance, false, false, true);

                        //On reset les données pour une potentiel futur resurection
                        cas.resetInternalState();
                    }


                    //Log.Message("YOU KILLED END");
                    Utils.insideKillFuncSurrogate = false;
                    return(true);
                }
                catch (Exception e)
                {
                    Log.Message("[ATPP] Pawn.Kill(Error) : " + e.Message + " - " + e.StackTrace);

                    if (__instance.IsSurrogateAndroid())
                    {
                        Utils.insideKillFuncSurrogate = false;
                    }
                    return(true);
                }
            }
Exemplo n.º 12
0
        public override void PostDrawExtraSelectionOverlays()
        {
            CompSurrogateOwner csc = null;

            if (controller != null)
            {
                csc = controller.TryGetComp <CompSurrogateOwner>();
            }

            if (csm != null && csm.connected && controller != null && csc != null && csc.skyCloudHost != null && csc.skyCloudHost.Map == parent.Map)
            {
                GenDraw.DrawLineBetween(parent.TrueCenter(), csc.skyCloudHost.TrueCenter(), SimpleColor.Red);
            }
        }
        public void stopMindActivities(Pawn mind, bool serverShutdown = false)
        {
            stopRemotelyControlledTurret(mind);
            CompSurrogateOwner cso = mind.ATCompSurrogateOwner;

            if (cso != null && cso.isThereSX())
            {
                cso.disconnectControlledSurrogate(null);
            }

            if (!serverShutdown && assistingMinds.Contains(mind))
            {
                assistingMinds.Remove(mind);
            }
        }
        public int getNbMindsConnectedToSurrogate()
        {
            int ret = 0;

            foreach (var m in storedMinds)
            {
                CompSurrogateOwner cso = m.ATCompSurrogateOwner;
                if (cso != null && cso.isThereSX())
                {
                    ret++;
                }
            }

            return(ret);
        }
            public static void Listener(Pawn pawn, Thing thing, bool forced, ref Job __result, WorkGiver_DoBill __instance)
            {
                try
                {
                    if (!Settings.androidsCanOnlyBeHealedByCrafter)
                    {
                        if (__instance.def.workType == Utils.WorkTypeDefSmithing && Utils.CrafterDoctorJob.Contains(__instance.def))
                        {
                            __result = null;
                        }

                        return;
                    }

                    //Medecin normal on jerte si t est un android
                    if (__instance.def.workType == WorkTypeDefOf.Doctor)
                    {
                        if (thing is Pawn && ((Pawn)thing).IsAndroidTier())
                        {
                            __result = null;
                        }
                    }
                    else
                    {
                        if (Utils.CrafterDoctorJob.Contains(__instance.def))
                        {
                            //Crafteur on jerte si patient pas un android
                            if (thing is Pawn && ((Pawn)thing).IsAndroidTier())
                            {
                                CompSurrogateOwner cso = pawn.TryGetComp <CompSurrogateOwner>();

                                if (cso == null || !cso.repairAndroids)
                                {
                                    __result = null;
                                }
                            }
                            else
                            {
                                __result = null;
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Message("[ATPP] WorkGiver_DoBill.JobOnThing " + e.Message + " " + e.StackTrace);
                }
            }
Exemplo n.º 16
0
        public static void Listener(Building_TurretGun __instance)
        {
            CompRemotelyControlledTurret crt = __instance.TryGetComp <CompRemotelyControlledTurret>();

            //Si pas de controlleur alors on ne peut pas controller la tourelle
            if (crt == null || crt.controller == null)
            {
                return;
            }
            CompSkyMind csm = __instance.TryGetComp <CompSkyMind>();

            CompSurrogateOwner csc = crt.controller.TryGetComp <CompSurrogateOwner>();

            if (csm != null && csm.connected && crt.controller != null && csc != null && csc.skyCloudHost != null && csc.skyCloudHost.Map == __instance.Map)
            {
                GenDraw.DrawLineBetween(__instance.TrueCenter(), csc.skyCloudHost.TrueCenter(), SimpleColor.Red);
            }
        }
Exemplo n.º 17
0
 private void disconnectConnectedMind()
 {
     if (controller != null)
     {
         CompSurrogateOwner cso = controller.TryGetComp <CompSurrogateOwner>();
         if (cso != null)
         {
             if (cso.skyCloudHost != null)
             {
                 CompSkyCloudCore csc = cso.skyCloudHost.TryGetComp <CompSkyCloudCore>();
                 if (csc != null)
                 {
                     csc.stopRemotelyControlledTurret(controller);
                 }
             }
         }
     }
 }
        public static void Listener(Building_TurretGun __instance)
        {
            var crt = __instance.TryGetComp <CompRemotelyControlledTurret>();

            if (crt?.controller == null)
            {
                return;
            }

            CompSurrogateOwner csc = null;
            var csm = __instance.TryGetComp <CompSkyMind>();

            csc = crt.controller.TryGetComp <CompSurrogateOwner>();

            if (csm != null && csm.connected && crt.controller != null && csc != null && csc.skyCloudHost != null && csc.skyCloudHost.Map == __instance.Map)
            {
                GenDraw.DrawLineBetween(__instance.TrueCenter(), csc.skyCloudHost.TrueCenter(), SimpleColor.Red);
            }
        }
Exemplo n.º 19
0
            public static void Listener(Pawn ___pawn, DamageInfo?dinfo, Hediff hediff)
            {
                try {
                    // Deconnexion of Is surrogate android used et que appartenant au joueur ====>>>> POUR eviter les problemes de reminescence fantome de surrogates d'autres factions dans des Lord qui reste a cause du fait que le MakeDown les enleves de la liste mais le disconnect va essayer de relancer un CONNECT (dans le cadre des surrogates externes)
                    if (___pawn.IsSurrogateAndroid(true) && ___pawn.Faction.IsPlayer)
                    {
                        //Obtention controlleur
                        CompAndroidState cas = ___pawn.ATCompState;
                        if (cas == null)
                        {
                            return;
                        }

                        //Arret du mode de control chez le controller
                        CompSurrogateOwner cso = cas.surrogateController.ATCompSurrogateOwner;
                        cso.stopControlledSurrogate(null);
                    }
                }
                catch (Exception e) {
                    Log.Message("[ATPP] Pawn_HealthTracker.MakeDowned : " + e.Message + " - " + e.StackTrace);
                }
            }
            public static void Listener(Pawn victim, DamageInfo?dinfo)
            {
                try
                {
                    if (victim.IsSurrogateAndroid())
                    {
                        Utils.insideKillFuncSurrogate = true;
                    }
                    //Deconnecte le tué
                    Utils.GCATPP.disconnectUser(victim);
                    //Log.Message("YOU KILLED "+__instance.LabelCap);
                    //Is surrogate android used ?
                    if (victim.IsSurrogateAndroid(true))
                    {
                        //Obtention controlleur
                        CompAndroidState cas = victim.TryGetComp <CompAndroidState>();
                        if (cas == null)
                        {
                            return;
                        }

                        //Arret du mode de control chez le controller
                        CompSurrogateOwner cso = cas.surrogateController.TryGetComp <CompSurrogateOwner>();
                        cso.stopControlledSurrogate(victim);
                    }
                    //Log.Message("YOU KILLED END");
                    Utils.insideKillFuncSurrogate = false;
                }
                catch (Exception e)
                {
                    Log.Message("[ATPP] TaleUtility.Notify_PawnDied(Error) : " + e.Message + " - " + e.StackTrace);

                    if (victim.IsSurrogateAndroid())
                    {
                        Utils.insideKillFuncSurrogate = false;
                    }
                }
            }
        public override void CompTick()
        {
            if (!this.parent.Spawned)
            {
                return;
            }

            int CGT = Find.TickManager.TicksGame;

            if (CGT % 60 == 0)
            {
                //Rafraichissement qt de courant consommé
                refreshPowerConsumed();

                //Check si demarrage du core
                if (bootGT > 0 && bootGT < CGT)
                {
                    //On rend accessible les controles
                    bootGT = -1;

                    if (((Building)parent).TryGetComp <CompPowerTrader>().PowerOn)
                    {
                        Utils.GCATPP.pushSkyCloudCore((Building)parent);
                    }

                    //ATPP_SkyCloudCoreBooted
                    Find.LetterStack.ReceiveLetter("ATPP_SkyCloudCoreBooted".Translate(getName()), "ATPP_SkyCloudCoreBootedDesc".Translate(getName()), LetterDefOf.NeutralEvent, parent);

                    //Play sound
                    Utils.playVocal("soundDefSkyCloudPrimarySystemsOnline");
                }
            }

            if (CGT % 120 == 0)
            {
                List <CompSurrogateOwner> migrationsDone  = null;
                List <CompSurrogateOwner> replicationDone = null;

                foreach (var m in storedMinds)
                {
                    CompSurrogateOwner cso = m.ATCompSurrogateOwner;
                    if (cso == null)
                    {
                        continue;
                    }

                    cso.checkInterruptedUpload();

                    //Atteinte fin attente de la replication d'un mind
                    if (cso.replicationEndingGT != -1 && cso.replicationEndingGT < CGT)
                    {
                        if (replicationDone == null)
                        {
                            replicationDone = new List <CompSurrogateOwner>();
                        }
                        replicationDone.Add(cso);
                    }

                    if (cso.migrationEndingGT != -1 && cso.migrationEndingGT < CGT)
                    {
                        if (migrationsDone == null)
                        {
                            migrationsDone = new List <CompSurrogateOwner>();
                        }
                        migrationsDone.Add(cso);
                    }
                }

                if (migrationsDone != null)
                {
                    foreach (var md in migrationsDone)
                    {
                        md.OnMigrated();
                    }

                    Utils.playVocal("soundDefSkyCloudMindMigrationCompleted");
                }
                if (replicationDone != null)
                {
                    foreach (var md in replicationDone)
                    {
                        md.OnReplicate();
                    }

                    Utils.playVocal("soundDefSkyCloudMindReplicationCompleted");
                }
            }

            if (CGT % 600 == 0)
            {
                //CHECK de la fin des mental breaks des minds stockés --  decrementation temps
                if (((Building)parent).TryGetComp <CompPowerTrader>().PowerOn&& inMentalBreak.Count > 0)
                {
                    var keys = new List <Pawn>(inMentalBreak.Keys);
                    foreach (var ck in keys)
                    {
                        inMentalBreak[ck] -= 600;
                        if (inMentalBreak[ck] <= 0)
                        {
                            inMentalBreak.Remove(ck);

                            Messages.Message("ATPP_ProcessNoLongerInMentalBreak".Translate(ck.LabelShortCap, getName()), parent, MessageTypeDefOf.PositiveEvent);
                        }
                    }
                }
            }
        }
        public bool mindIsBusy(Pawn mind)
        {
            CompSurrogateOwner cso = mind.ATCompSurrogateOwner;

            return(controlledTurrets.ContainsKey(mind) || replicatingMinds.Contains(mind) || inMentalBreak.ContainsKey(mind) || assistingMinds.Contains(mind) || (cso != null && cso.migrationEndingGT != -1));
        }
        public void showFloatMenuMindsStored(Action <Pawn> onClick, bool hideSurrogate = false, bool hideTurretController = false, bool showOnlyConnectedDevices = false, bool resolveSurrogates = false, List <FloatMenuOption> supOpts = null, bool hideAssistingMinds = false, bool showOnlyAssistingMinds = false)
        {
            List <FloatMenuOption> opts = new List <FloatMenuOption>();
            FloatMenu floatMenuMap;

            if (supOpts != null)
            {
                opts = opts.Concat(supOpts).ToList();
            }

            //Listing des SkyCloud Cores
            foreach (var m in storedMinds)
            {
                //Log.Message("Suspended => " +m.LabelCap+" "+ m.Suspended);
                CompSurrogateOwner cso     = m.ATCompSurrogateOwner;
                bool isSurrogateController = cso != null && cso.isThereSX();
                bool turretController      = controlledTurrets.ContainsKey(m);
                bool isAssistingMind       = assistingMinds.Contains(m);

                //Si mind dans un mental break
                if (inMentalBreak.ContainsKey(m))
                {
                    continue;
                }

                //Si mind en cours de replication on le masque
                if (replicatingMinds.Contains(m))
                {
                    continue;
                }

                //Si migration en cours sur un mind on le jerte de la liste des minds consultables
                if (cso != null && cso.migrationEndingGT != -1)
                {
                    continue;
                }

                if ((hideAssistingMinds && isAssistingMind) || showOnlyAssistingMinds && !isAssistingMind)
                {
                    continue;
                }

                if (hideTurretController && turretController)
                {
                    continue;
                }

                if (hideSurrogate && isSurrogateController)
                {
                    continue;
                }

                string name = m.LabelShortCap;

                if (isSurrogateController)
                {
                    //On affiche le nom du colon numérisé car il est permuté avec le surrogate
                    if (!cso.isThereSX())
                    {
                        name = m.LabelShortCap;
                    }
                    else
                    {
                        if (cso.SX != null)
                        {
                            name = cso.SX.LabelShortCap;
                        }
                        else
                        {
                            name = m.LabelShortCap;
                        }
                    }
                }

                if (showOnlyConnectedDevices)
                {
                    if (!isSurrogateController && !turretController)
                    {
                        continue;
                    }
                }


                opts.Add(new FloatMenuOption(name, delegate {
                    Pawn sel = m;
                    if (resolveSurrogates && isSurrogateController)
                    {
                        if (cso.isThereSX())
                        {
                            if (cso.isThereSX())
                            {
                                if (cso.SX != null)
                                {
                                    sel = cso.SX;
                                }
                                else
                                {
                                    sel = m;
                                }
                            }
                            else
                            {
                                sel = m;
                            }
                        }
                        else
                        {
                            sel = m;
                        }
                    }

                    onClick(sel);
                }, MenuOptionPriority.Default, null, null, 0f, null, null));
            }
            opts.SortBy((x) => x.Label);

            if (opts.Count == 0)
            {
                return;
            }

            floatMenuMap = new FloatMenu(opts, "ATPP_SkyCloudFloatMenuMindsStoredSelect".Translate());
            Find.WindowStack.Add(floatMenuMap);
        }
Exemplo n.º 24
0
        public override bool TryExecuteWorker(IncidentParms parms)
        {
            if (Settings.disableSkyMindSecurityStuff)
            {
                return(false);
            }

            List <Pawn>   victims;
            List <string> cryptolockedThings = new List <string>();
            string        title = "";
            string        msg   = "";
            int           nbConnectedClients   = Utils.GCATPP.getNbThingsConnected();
            int           nbSurrogates         = Utils.GCATPP.getNbSurrogateAndroids();
            int           nbUnsecurisedClients = nbConnectedClients - Utils.GCATPP.getNbSlotSecurisedAvailable();

            LetterDef letter;
            //Selection type virus
            int attackType = 1;
            int fee        = 0;

            //Check si sur lensemble des clients connecté il y a quand meme des surrogates
            if (nbSurrogates <= 0)
            {
                return(false);
            }

            //Attaque virale faible
            if (nbUnsecurisedClients <= 0)
            {
                if (!Rand.Chance(Settings.riskSecurisedSecuritySystemGetVirus))
                {
                    return(false);
                }

                int nb = 0;


                nb = nbSurrogates / 2;
                if (nb != 0)
                {
                    nb = Rand.Range(1, nb + 1);
                }
                else
                {
                    nb = 1;
                }

                letter = LetterDefOf.ThreatSmall;
                //Obtention des victimes
                victims = Utils.GCATPP.getRandomSurrogateAndroids(nb);
                if (victims.Count == 0)
                {
                    return(false);
                }

                foreach (var v in victims)
                {
                    CompSkyMind      csm = v.TryGetComp <CompSkyMind>();
                    CompAndroidState cas = v.ATCompState;
                    if (csm == null || cas == null)
                    {
                        continue;
                    }

                    csm.Infected = 4;

                    //Deconnection du contorlleur le cas echeant
                    if (cas.surrogateController != null)
                    {
                        CompSurrogateOwner cso = cas.surrogateController.ATCompSurrogateOwner;
                        if (cso != null)
                        {
                            cso.disconnectControlledSurrogate(null);
                        }
                    }

                    Hediff he = v.health.hediffSet.GetFirstHediffOfDef(Utils.hediffNoHost);
                    if (he != null)
                    {
                        v.health.RemoveHediff(he);
                    }

                    Utils.ignoredPawnNotifications = v;
                    Utils.VirusedRandomMentalBreak.RandomElement().Worker.TryStart(v, null, false);
                    Utils.ignoredPawnNotifications = null;
                    //v.mindState.mentalStateHandler.TryStartMentalState(  , null, false, false, null, false);
                }


                title = "ATPP_IncidentSurrogateHackingVirus".Translate();
                msg   = "ATPP_IncidentSurrogateHackingLiteDesc".Translate(nb);
            }
            else
            {
                letter = LetterDefOf.ThreatBig;

                attackType = Rand.Range(1, 4);

                int nb = 0;
                LordJob_AssaultColony lordJob;
                Lord lord = null;

                if (attackType != 3)
                {
                    //Attaque virale douce
                    //Obtention des victimes (qui peut allez de 1 victime a N/2 victimes
                    nb = nbSurrogates / 2;
                    if (nb != 0)
                    {
                        nb = Rand.Range(1, nb + 1);
                    }
                    else
                    {
                        nb = 1;
                    }

                    lordJob = new LordJob_AssaultColony(Faction.OfAncientsHostile, false, false, false, false, false);

                    if (lordJob != null)
                    {
                        lord = LordMaker.MakeNewLord(Faction.OfAncientsHostile, lordJob, Current.Game.CurrentMap, null);
                    }
                }
                else
                {
                    nb = nbSurrogates;
                }

                msg = "ATPP_IncidentSurrogateHackingHardDesc".Translate(nb) + "\n";

                switch (attackType)
                {
                case 1:
                    title = "ATPP_IncidentSurrogateHackingVirus".Translate();
                    msg  += "ATPP_IncidentVirusedDesc".Translate();
                    break;

                case 2:
                    title = "ATPP_IncidentSurrogateHackingExplosiveVirus".Translate();
                    msg  += "ATPP_IncidentVirusedExplosiveDesc".Translate();
                    break;

                case 3:
                    title = "ATPP_IncidentSurrogateHackingCryptolocker".Translate();
                    msg  += "ATPP_IncidentCryptolockerDesc".Translate();
                    break;
                }

                victims = Utils.GCATPP.getRandomSurrogateAndroids(nb);
                if (victims.Count != nb)
                {
                    return(false);
                }

                foreach (var v in victims)
                {
                    CompSkyMind csm = v.TryGetComp <CompSkyMind>();

                    v.mindState.canFleeIndividual = false;
                    csm.Infected = attackType;
                    if (v.jobs != null)
                    {
                        v.jobs.StopAll();
                        v.jobs.ClearQueuedJobs();
                    }
                    if (v.mindState != null)
                    {
                        v.mindState.Reset(true);
                    }


                    switch (attackType)
                    {
                    //Virus
                    case 1:
                        //Devient hostile
                        if (lord != null)
                        {
                            lord.AddPawn(v);
                        }
                        break;

                    //Virus explosif
                    case 2:
                        //Devient hostile
                        if (lord != null)
                        {
                            lord.AddPawn(v);
                        }
                        break;

                    //Virus cryptolocker
                    case 3:
                        cryptolockedThings.Add(v.GetUniqueLoadID());

                        switch (v.def.defName)
                        {
                        case Utils.T2:
                            fee += Settings.ransomCostT2;
                            break;

                        case Utils.T3:
                            fee += Settings.ransomCostT3;
                            break;

                        case Utils.T4:
                            fee += Settings.ransomCostT4;
                            break;

                        case Utils.T5:
                            fee += Settings.ransomCostT5;
                            break;

                        case Utils.T1:
                        default:
                            fee += Settings.ransomCostT1;
                            break;
                        }
                        break;
                    }

                    if (attackType == 1 || attackType == 2)
                    {
                        //On va attribuer aleatoirement des poids d'attaque aux surrogate
                        SkillRecord shooting = v.skills.GetSkill(SkillDefOf.Shooting);
                        if (shooting != null && !shooting.TotallyDisabled)
                        {
                            shooting.levelInt = Rand.Range(3, 19);
                        }
                        SkillRecord melee = v.skills.GetSkill(SkillDefOf.Melee);
                        if (melee != null && !melee.TotallyDisabled)
                        {
                            melee.levelInt = Rand.Range(3, 19);
                        }
                    }
                }
            }

            Find.LetterStack.ReceiveLetter(title, msg, letter, (LookTargets)victims, null, null);


            if (attackType == 3)
            {
                //Déduction faction ennemis au hasard
                Faction faction = Find.FactionManager.RandomEnemyFaction();

                ChoiceLetter_RansomDemand ransom = (ChoiceLetter_RansomDemand)LetterMaker.MakeLetter(DefDatabase <LetterDef> .GetNamed("ATPP_CLPayCryptoRansom"));
                ransom.label              = "ATPP_CryptolockerNeedPayRansomTitle".Translate();
                ransom.text               = "ATPP_CryptolockerNeedPayRansom".Translate(faction.Name, fee);
                ransom.faction            = faction;
                ransom.radioMode          = true;
                ransom.fee                = fee;
                ransom.cryptolockedThings = cryptolockedThings;
                ransom.StartTimeout(60000);
                Find.LetterStack.ReceiveLetter(ransom, null);
            }

            return(true);
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            if (Settings.disableSkyMindSecurityStuff)
            {
                return(false);
            }

            Pawn   victim;
            string title = "ATPP_LetterFactionRansomware".Translate();
            int    nbConnectedClients   = Utils.GCATPP.getNbThingsConnected();
            int    nbUnsecurisedClients = nbConnectedClients - Utils.GCATPP.getNbSlotSecurisedAvailable();
            //Déduction faction ennemis au hasard
            Faction faction = Find.FactionManager.RandomEnemyFaction();

            LetterDef letter = LetterDefOf.ThreatBig;

            //Si pas de config insécurisé alors on dégage
            if (nbUnsecurisedClients < 0)
            {
                return(false);
            }

            victim = Utils.GCATPP.getRandomSkyMindUser();
            if (victim == null)
            {
                return(false);
            }

            CompSurrogateOwner cso = victim.TryGetComp <CompSurrogateOwner>();

            if (cso == null)
            {
                return(false);
            }

            cso.clearRansomwareVar();

            string msg;
            string ransomMsg;
            int    fee;

            //Bad traits added
            if (Rand.Chance(0.5f))
            {
                ISet <TraitDef> tr = Utils.RansomAddedBadTraits.ToHashSet();

                //Purge des traits deja possédé par la victime ET incompatibles avec ceux present
                for (int i = 0; i < Utils.RansomAddedBadTraits.Count; i++)
                {
                    TraitDef t = Utils.RansomAddedBadTraits[i];
                    for (int i1 = 0; i1 < victim.story.traits.allTraits.Count; i1++)
                    {
                        Trait t2 = victim.story.traits.allTraits[i1];
                        if (t2.def == t || (t.conflictingTraits != null && t.conflictingTraits.Contains(t2.def)))
                        {
                            tr.Remove(t2.def);
                            break;
                        }
                    }
                }

                //Selection trait aleatoire ajouté
                cso.ransomwareTraitAdded = tr.RandomElement();
                victim.story.traits.GainTrait(new Trait(cso.ransomwareTraitAdded, 0, true));

                fee = Rand.Range(Settings.ransomwareMinSilverToPayForBasTrait, Settings.ransomwareMaxSilverToPayForBasTrait);

                string traitLabel = "";

                if (cso.ransomwareTraitAdded.degreeDatas != null && cso.ransomwareTraitAdded.degreeDatas.First() != null)
                {
                    traitLabel = cso.ransomwareTraitAdded.degreeDatas.First().label;
                }

                //Log.Message("=======>"+cso.ransomwareTraitAdded.defName);

                msg       = "ATPP_LetterFactionRansomwareBadTraitDownloadedDesc".Translate(faction.Name, victim.LabelShortCap, traitLabel);
                ransomMsg = "ATPP_RansomNeedPayRansomDownloadedTrait".Translate(faction.Name, traitLabel, victim.LabelShortCap, fee);
            }
            else
            {
                //Skill enlevé

                SkillDef    find = null;
                SkillRecord sel  = null;
                int         v    = -1;
                //Check tu plus gros skill de la victime
                for (int i = 0; i < victim.skills.skills.Count; i++)
                {
                    SkillRecord s = victim.skills.skills[i];
                    if (s.levelInt >= v)
                    {
                        v    = s.levelInt;
                        find = s.def;
                        sel  = s;
                    }
                }

                //APplication effet négatif
                sel.levelInt = 0;

                //Sauvegarde infos de skill pour restauration
                cso.ransomwareSkillStolen = find;
                cso.ransomwareSkillValue  = v;

                fee = v * Settings.ransomwareSilverToPayToRestoreSkillPerLevel;

                msg       = "ATPP_LetterFactionRansomwareSkillStolenDesc".Translate(faction.Name, cso.ransomwareSkillStolen.LabelCap, victim.LabelShortCap);
                ransomMsg = "ATPP_RansomNeedPayRansomCorruptedSKill".Translate(faction.Name, cso.ransomwareSkillStolen.LabelCap, victim.LabelShortCap, fee);
            }



            Find.LetterStack.ReceiveLetter(title, msg, letter, (LookTargets)victim, null, null);

            ChoiceLetter_RansomwareDemand ransom = (ChoiceLetter_RansomwareDemand)LetterMaker.MakeLetter(DefDatabase <LetterDef> .GetNamed("ATPP_CLPayRansomwareRansom"));

            ransom.label     = "ATPP_RansomNeedPayRansomTitle".Translate();
            ransom.text      = ransomMsg;
            ransom.faction   = faction;
            ransom.victim    = victim;
            ransom.radioMode = true;
            ransom.StartTimeout(60000);
            ransom.fee = fee;
            Find.LetterStack.ReceiveLetter(ransom, null);

            return(true);
        }
Exemplo n.º 26
0
        public void tempHackingEnding()
        {
            if (hacked != 3)
            {
                return;
            }
            //Fin du hack temporaire du surrogate on deconnecte le joueur
            Pawn cp = (Pawn)parent;

            CompAndroidState cas = cp.ATCompState;

            if (cas.surrogateController != null)
            {
                CompSurrogateOwner cso = cas.surrogateController.ATCompSurrogateOwner;
                cso.stopControlledSurrogate(cp, true);
            }

            cp.SetFaction(hackOrigFaction, null);
            //Si le surrogate été un prisonnier on le restaure en tant que tel
            if (hackWasPrisoned)
            {
                if (cp.guest != null)
                {
                    cp.guest.SetGuestStatus(Faction.OfPlayer, true);
                    if (cp.workSettings == null)
                    {
                        cp.workSettings = new Pawn_WorkSettings(cp);
                        cp.workSettings.EnableAndInitializeIfNotAlreadyInitialized();
                    }
                }
            }

            if (cp.jobs != null)
            {
                cp.jobs.StopAll();
                cp.jobs.ClearQueuedJobs();
            }
            if (cp.mindState != null)
            {
                cp.mindState.Reset(true);
            }

            PawnComponentsUtility.AddAndRemoveDynamicComponents(cp, false);
            hacked          = -1;
            hackEndGT       = -1;
            hackWasPrisoned = false;

            cp.Map.attackTargetsCache.UpdateTarget(cp);

            foreach (var p in cp.Map.mapPawns.AllPawnsSpawned)
            {
                if (p.mindState == null)
                {
                    continue;
                }

                Thing aim = p.mindState.enemyTarget;

                if (aim != null && aim is Pawn)
                {
                    //Log.Message("=>" + aim.def.defName);

                    Pawn pawnTarget = (Pawn)aim;
                    if (pawnTarget == cp)
                    {
                        if (p.jobs != null)
                        {
                            p.jobs.StopAll();
                            p.jobs.ClearQueuedJobs();
                        }
                    }
                }
            }

            Find.ColonistBar.MarkColonistsDirty();
        }
            public static void Listener(Pawn __instance, ref IEnumerable <Gizmo> __result)
            {
                try
                {
                    CompSkyMind csm = __instance.TryGetComp <CompSkyMind>();

                    //Si prisonnier et possede une VX2 on va obtenir les GIZMOS associés OU virusé
                    if (__instance.IsPrisoner || (csm != null && csm.Hacked == 1))
                    {
                        IEnumerable <Gizmo> tmp;
                        //Si posseseur d'une VX2

                        if (__instance.VXChipPresent())
                        {
                            CompSurrogateOwner cso = __instance.TryGetComp <CompSurrogateOwner>();
                            if (cso != null)
                            {
                                tmp = cso.CompGetGizmosExtra();
                                if (tmp != null)
                                {
                                    __result = __result.Concat(tmp);
                                }
                            }
                        }

                        //Si android prisonier ou virusé
                        if (__instance.IsAndroidTier())
                        {
                            CompAndroidState cas = __instance.TryGetComp <CompAndroidState>();

                            if (cas != null)
                            {
                                tmp = cas.CompGetGizmosExtra();
                                if (tmp != null)
                                {
                                    __result = __result.Concat(tmp);
                                }
                            }
                        }

                        if (csm != null && csm.Hacked == -1)
                        {
                            tmp = csm.CompGetGizmosExtra();
                            if (tmp != null)
                            {
                                __result = __result.Concat(tmp);
                            }
                        }
                    }

                    //Si animal posséder par player
                    if (__instance.IsPoweredAnimalAndroids())
                    {
                        CompAndroidState cas = null;
                        cas = __instance.TryGetComp <CompAndroidState>();
                        if (cas != null)
                        {
                            IEnumerable <Gizmo> tmp = cas.CompGetGizmosExtra();
                            if (tmp != null)
                            {
                                __result = __result.Concat(tmp);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Message("[ATPP] Pawn.GetGizmos " + e.Message + " " + e.StackTrace);
                }
            }
Exemplo n.º 28
0
            public static void Listener(PawnGroupMakerParms parms, bool warnOnZeroResults, ref IEnumerable <Pawn> __result)
            {
                try {
                    //If active solar flare then no surrogates are generated to prevent ridiculous spawn of dawned surrogates
                    if (!Settings.otherFactionsCanUseSurrogate || Utils.ExceptionBlacklistedFactionNoSurrogate.Contains(parms.faction.def.defName) || Utils.getRandomMapOfPlayer().gameConditionManager.ConditionIsActive(GameConditionDefOf.SolarFlare) || (Settings.androidsAreRare && Rand.Chance(0.95f)))
                    {
                        return;
                    }

                    int nbHumanoids = 0;

                    foreach (var e in __result)
                    {
                        //Si humanoide
                        if (e.def.race != null && e.def.race.Humanlike)
                        {
                            //Si pas commercant
                            if (e.trader == null && e.TraderKind == null)
                            {
                                nbHumanoids++;
                            }

                            //Si android T1/T2 suppression traits ==> Je suis bete cest a cause des surrogates que j'ai crus qu'il avais des traits

                            /*if(e.def.defName == Utils.T1 || e.def.defName == Utils.T2)
                             * {
                             *  Utils.removeAllTraits(e);
                             * }*/
                        }
                    }

                    //Faction de niveau industriel et plus ET nb pawn généré supérieur ou égal à 5
                    if (parms.faction.def.techLevel >= TechLevel.Industrial && nbHumanoids >= 5)
                    {
                        List <Pawn> other = new List <Pawn>();
                        List <Pawn> ret   = new List <Pawn>();
                        List <Pawn> tmp   = __result.ToList();

                        //On supprime les non humains ET trader
                        //int nba = tmp.RemoveAll((Pawn x) => (x.def.race == null || !x.def.race.Humanlike || x.trader != null || x.TraderKind != null));
                        foreach (var x in tmp)
                        {
                            if (x.def.race == null || !x.def.race.Humanlike || x.trader != null || x.TraderKind != null)
                            {
                                other.Add(x);
                            }
                        }

                        //Purge dans list de travail
                        foreach (var e in other)
                        {
                            tmp.Remove(e);
                        }

                        //Log.Message(other.Count + " animaux et traders virés");

                        //Calcul nb pawn a recreer en mode surrogate
                        int nb = (int)(tmp.Count() * Rand.Range(Settings.percentageOfSurrogateInAnotherFactionGroupMin, Settings.percentageOfSurrogateInAnotherFactionGroup));
                        if (nb <= 0)
                        {
                            if (Settings.percentageOfSurrogateInAnotherFactionGroupMin == 0.0f)
                            {
                                return;
                            }
                            else
                            {
                                nb = 1;
                            }
                        }

                        //On va supprimer aleatoirement N pawns pour arriver a nb
                        while (tmp.Count > nb)
                        {
                            Pawn p = tmp.RandomElement();
                            other.Add(p);
                            tmp.Remove(p);
                        }

                        //Log.Message("HERE");
                        //On va se servir des nb pawn pregénéré par la fonction patché comme controller
                        for (int i = 0; i != nb; i++)
                        {
                            //PawnGenerationRequest request = new PawnGenerationRequest(Utils.AndroidsPKD[3], parms.faction, PawnGenerationContext.NonPlayer, parms.tile, false, false, false, false, true, false, 1f, false, true, true, false, false, false, false, null, null, null, null, null, null, null, null);
                            //Pawn surrogate = PawnGenerator.GeneratePawn(request);

                            PawnKindDef rpkd = null;

                            if (parms.groupKind == PawnGroupKindDefOf.Peaceful || parms.groupKind == PawnGroupKindDefOf.Trader)
                            {
                                if (Rand.Chance(0.10f))
                                {
                                    if (!Utils.TXSERIE_LOADED || Rand.Chance(0.5f))
                                    {
                                        rpkd = Utils.AndroidsPKDNeutral[3];
                                    }
                                    else if (Rand.Chance(0.75f))
                                    {
                                        rpkd = Utils.AndroidsXISeriePKDNeutral[3];
                                    }
                                    else
                                    {
                                        rpkd = Utils.AndroidsXSeriePKDNeutral[3];
                                    }
                                }
                                else if (Rand.Chance(0.35f))
                                {
                                    if (!Utils.TXSERIE_LOADED || Rand.Chance(0.5f))
                                    {
                                        rpkd = Utils.AndroidsPKDNeutral[2];
                                    }
                                    else if (Rand.Chance(0.75f))
                                    {
                                        rpkd = Utils.AndroidsXISeriePKDNeutral[2];
                                    }
                                    else
                                    {
                                        rpkd = Utils.AndroidsXSeriePKDNeutral[2];
                                    }
                                }
                                else if (Rand.Chance(0.55f))
                                {
                                    if (!Utils.TXSERIE_LOADED || Rand.Chance(0.75f))
                                    {
                                        rpkd = Utils.AndroidsPKDNeutral[1];
                                    }
                                    else if (Rand.Chance(0.75f))
                                    {
                                        rpkd = Utils.AndroidsXISeriePKDNeutral[1];
                                    }
                                    else
                                    {
                                        rpkd = Utils.AndroidsXSeriePKDNeutral[1];
                                    }
                                }
                                else
                                {
                                    if (!Utils.TXSERIE_LOADED || Rand.Chance(0.5f))
                                    {
                                        rpkd = Utils.AndroidsPKDNeutral[0];
                                    }
                                    else if (Rand.Chance(0.75f))
                                    {
                                        rpkd = Utils.AndroidsXISeriePKDNeutral[0];
                                    }
                                    else
                                    {
                                        rpkd = Utils.AndroidsXSeriePKDNeutral[0];
                                    }
                                }
                            }
                            else
                            {
                                if (Rand.Chance(0.10f))
                                {
                                    if (!Utils.TXSERIE_LOADED || Rand.Chance(0.5f))
                                    {
                                        rpkd = Utils.AndroidsPKDHostile[3];
                                    }
                                    else if (Rand.Chance(0.75f))
                                    {
                                        rpkd = Utils.AndroidsXISeriePKDHostile[3];
                                    }
                                    else
                                    {
                                        rpkd = Utils.AndroidsXSeriePKDHostile[3];
                                    }
                                }
                                else if (Rand.Chance(0.35f))
                                {
                                    if (!Utils.TXSERIE_LOADED || Rand.Chance(0.5f))
                                    {
                                        rpkd = Utils.AndroidsPKDHostile[2];
                                    }
                                    else if (Rand.Chance(0.75f))
                                    {
                                        rpkd = Utils.AndroidsXISeriePKDHostile[2];
                                    }
                                    else
                                    {
                                        rpkd = Utils.AndroidsXSeriePKDHostile[2];
                                    }
                                }
                                else if (Rand.Chance(0.55f))
                                {
                                    if (!Utils.TXSERIE_LOADED || Rand.Chance(0.75f))
                                    {
                                        rpkd = Utils.AndroidsPKDHostile[1];
                                    }
                                    else if (Rand.Chance(0.75f))
                                    {
                                        rpkd = Utils.AndroidsXISeriePKDHostile[1];
                                    }
                                    else
                                    {
                                        rpkd = Utils.AndroidsXSeriePKDHostile[1];
                                    }
                                }
                                else
                                {
                                    if (!Utils.TXSERIE_LOADED || Rand.Chance(0.5f))
                                    {
                                        rpkd = Utils.AndroidsPKDHostile[0];
                                    }
                                    else if (Rand.Chance(0.75f))
                                    {
                                        rpkd = Utils.AndroidsXISeriePKDHostile[0];
                                    }
                                    else
                                    {
                                        rpkd = Utils.AndroidsXSeriePKDHostile[0];
                                    }
                                }
                            }

                            //Utils.AndroidsPKD.RandomElement();
                            Pawn surrogate = Utils.generateSurrogate(parms.faction, rpkd, IntVec3.Invalid, null, false, true, parms.tile, true, parms.inhabitants);

                            //Si en mode rare alors override de la creation d'androides en ancient, on squeeze l'init du pawn
                            if (!surrogate.IsAndroidTier())
                            {
                                surrogate.Destroy();
                                ret.Add(tmp[i]);
                                continue;
                            }

                            //Log.Message("--Surrogate generated pour "+tmp[i].def.defName);

                            //On vire les equipements/inventaires/vetements du surrogate
                            if (surrogate.inventory != null && surrogate.inventory.innerContainer != null)
                            {
                                surrogate.inventory.innerContainer.Clear();
                            }

                            surrogate.apparel.DestroyAll();

                            surrogate.equipment.DestroyAllEquipment();


                            CompAndroidState cas = surrogate.ATCompState;
                            if (cas != null)
                            {
                                cas.externalController = tmp[i];
                                CompSurrogateOwner cso = tmp[i].ATCompSurrogateOwner;
                                if (cso != null)
                                {
                                    cso.setControlledSurrogate(surrogate, true);
                                }
                            }

                            //Transfere equipement
                            //Log.Message("--Traitement des equipements");
                            if (tmp[i].equipment != null && surrogate.equipment != null)
                            {
                                /*Pawn_EquipmentTracker pet = tmp[i].equipment;
                                 * pet.pawn = surrogate;
                                 * tmp[i].equipment = surrogate.equipment;
                                 * tmp[i].equipment.pawn = tmp[i];
                                 * surrogate.equipment = pet;*/
                                surrogate.equipment.DestroyAllEquipment();

                                foreach (var e in tmp[i].equipment.AllEquipmentListForReading.ToList())
                                {
                                    try
                                    {
                                        tmp[i].equipment.Remove(e);
                                        if (!(e.def.equipmentType == EquipmentType.Primary && surrogate.equipment.Primary != null))
                                        {
                                            surrogate.equipment.AddEquipment(e);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Log.Message("[ATPP] PawnGroupMakerUtility.GeneratePawns.transfertEquipment " + ex.Message + " " + ex.StackTrace);
                                    }
                                }


                                foreach (var e in surrogate.equipment.AllEquipmentListForReading)
                                {
                                    try
                                    {
                                        if (Utils.CELOADED && e != null && e.def.IsRangedWeapon)
                                        {
                                            ThingComp ammoUser = Utils.TryGetCompByTypeName(e, "CompAmmoUser", "CombatExtended");
                                            if (ammoUser != null)
                                            {
                                                var      props        = Traverse.Create(ammoUser).Property("Props").GetValue();
                                                int      magazineSize = Traverse.Create(props).Field("magazineSize").GetValue <int>();
                                                ThingDef def          = Traverse.Create(ammoUser).Field("selectedAmmo").GetValue <ThingDef>();
                                                if (def != null)
                                                {
                                                    Traverse.Create(ammoUser).Method("ResetAmmoCount", new object[] { def }).GetValue();
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                            }

                            /*foreach(var e in tmp[i].equipment.AllEquipmentListForReading.ToList())
                             * {
                             *  e.
                             *  surrogate.equipment.AddEquipment(e);
                             * }*/


                            //Transfert vetements
                            if (tmp[i].apparel != null)
                            {
                                try
                                {
                                    //Log.Message("--Traitement des vetements");
                                    foreach (var e in tmp[i].apparel.WornApparel.ToList())
                                    {
                                        //Check si vetement peut etre porté par le surrogate
                                        string path = "";
                                        if (e.def.apparel.LastLayer == ApparelLayerDefOf.Overhead)
                                        {
                                            path = e.def.apparel.wornGraphicPath;
                                        }
                                        else
                                        {
                                            path = e.def.apparel.wornGraphicPath + "_" + surrogate.story.bodyType.defName + "_south";
                                        }

                                        Texture2D appFoundTex = null;
                                        Texture2D appTex      = null;
                                        //CHeck dans les mods de la texture
                                        for (int j = LoadedModManager.RunningModsListForReading.Count - 1; j >= 0; j--)
                                        {
                                            appTex = LoadedModManager.RunningModsListForReading[j].GetContentHolder <Texture2D>().Get(path);
                                            if (appTex != null)
                                            {
                                                appFoundTex = appTex;
                                                break;
                                            }
                                        }
                                        //Check RW mods  de la texture
                                        if (appFoundTex == null)
                                        {
                                            path        = GenFilePaths.ContentPath <Texture2D>() + path;
                                            appFoundTex = (Texture2D)((object)Resources.Load <Texture2D>(path));
                                        }

                                        //SI pb avec texture on ne l'ajoute pas
                                        if (appFoundTex != null)
                                        {
                                            tmp[i].apparel.Remove(e);
                                            surrogate.apparel.Wear(e);
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Log.Message("[ATPP] PawnGroupMakerUtility.TransfertApparel " + ex.Message + " " + ex.StackTrace);
                                }
                            }


                            //Log.Message((tmp[i].inventory == null)+" "+(tmp[i].inventory.innerContainer == null)+" "+(surrogate.inventory == null)+" "+(surrogate.inventory.innerContainer== null));
                            //Inventaire
                            if (tmp[i].inventory != null && tmp[i].inventory.innerContainer != null && surrogate.inventory != null && surrogate.inventory.innerContainer != null)
                            {
                                //foreach (var e in tmp[i].inventory.innerContainer.ToList())
                                //{
                                //Log.Message("Items transfered " + tmp[i].inventory.innerContainer.Count);
                                try
                                {
                                    tmp[i].inventory.innerContainer.TryTransferAllToContainer(surrogate.inventory.innerContainer);

                                    //Suppression des drogues
                                    foreach (var el in surrogate.inventory.innerContainer.ToList())
                                    {
                                        if (el.def.IsDrug)
                                        {
                                            surrogate.inventory.innerContainer.Remove(el);
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Log.Message("[ATPP] PawnGroupMakerUtility.GeneratePawns.transfertInventory " + ex.Message + " " + ex.StackTrace);
                                }
                                //}
                            }

                            ret.Add(surrogate);
                        }

                        //On remet dans le ret les autres pawns non "surogatisés"
                        __result = other.Concat(ret);
                    }
                }
                catch (Exception ex)
                {
                    Log.Message("[ATPP] PawnGroupMakerUtility.GeneratePawns " + ex.Message + " " + ex.StackTrace);
                }
            }
        protected override void FinalizeDesignationSucceeded()
        {
            base.FinalizeDesignationSucceeded();

            CompSkyMind        csm           = target.TryGetComp <CompSkyMind>();
            CompAndroidState   cas           = target.TryGetComp <CompAndroidState>();
            string             surrogateName = target.LabelShortCap;
            CompSurrogateOwner cso           = null;

            if (cas.externalController != null)
            {
                surrogateName = cas.externalController.LabelShortCap;
                cso           = cas.externalController.TryGetComp <CompSurrogateOwner>();
            }

            Lord clord        = target.GetLord();
            int  nbp          = Utils.GCATPP.getNbHackingPoints();
            int  nbpToConsume = 0;

            //Check points
            switch (hackType)
            {
            case 1:
                nbpToConsume = Settings.costPlayerVirus;
                break;

            case 2:
                nbpToConsume = Settings.costPlayerExplosiveVirus;
                break;

            case 3:
                nbpToConsume = Settings.costPlayerHackTemp;
                break;

            case 4:
                nbpToConsume = Settings.costPlayerHack;
                break;
            }

            if (nbpToConsume > nbp)
            {
                Messages.Message("ATPP_CannotHackNotEnoughtHackingPoints".Translate(), MessageTypeDefOf.NegativeEvent);
                return;
            }

            //Si faction alliée ou neutre ==> pénalitée
            if (target.Faction.RelationKindWith(Faction.OfPlayer) != FactionRelationKind.Hostile)
            {
                target.Faction.TryAffectGoodwillWith(Faction.OfPlayer, -1 * Rand.Range(5, 36));
            }

            //Application effet
            switch (hackType)
            {
            case 1:
            case 2:

                csm.Hacked = hackType;
                //Surrogate va attaquer la colonnie
                target.SetFactionDirect(Faction.OfAncients);
                LordJob_AssistColony lordJob;
                Lord lord = null;

                IntVec3 fallbackLocation;
                RCellFinder.TryFindRandomSpotJustOutsideColony(target.PositionHeld, target.Map, out fallbackLocation);

                target.mindState.Reset();
                target.mindState.duty = null;
                target.jobs.StopAll();
                target.jobs.ClearQueuedJobs();
                target.ClearAllReservations();
                if (target.drafter != null)
                {
                    target.drafter.Drafted = false;
                }

                lordJob = new LordJob_AssistColony(Faction.OfAncients, fallbackLocation);
                if (lordJob != null)
                {
                    lord = LordMaker.MakeNewLord(Faction.OfAncients, lordJob, Current.Game.CurrentMap, null);
                }

                if (clord != null)
                {
                    if (clord.ownedPawns.Contains(target))
                    {
                        clord.Notify_PawnLost(target, PawnLostCondition.IncappedOrKilled, null);
                    }
                }

                lord.AddPawn(target);

                //Si virus explosive enclenchement de la détonnation
                if (hackType == 2)
                {
                    csm.infectedExplodeGT = Find.TickManager.TicksGame + (Settings.nbSecExplosiveVirusTakeToExplode * 60);
                }
                break;

            case 3:
            case 4:
                bool    wasPrisonner = target.IsPrisoner;
                Faction prevFaction  = target.Faction;
                target.SetFaction(Faction.OfPlayer);

                if (target.workSettings == null)
                {
                    target.workSettings = new Pawn_WorkSettings(target);
                    target.workSettings.EnableAndInitialize();
                }

                if (clord != null)
                {
                    if (clord.ownedPawns.Contains(target))
                    {
                        clord.Notify_PawnLost(target, PawnLostCondition.ChangedFaction, null);
                    }
                }

                if (cso != null)
                {
                    cso.disconnectControlledSurrogate(null);
                }

                if (hackType == 4)
                {
                    //Contorle definitif on jerte l'externalController
                    if (cas != null)
                    {
                        cas.externalController = null;
                    }
                }

                target.Map.attackTargetsCache.UpdateTarget(target);
                PawnComponentsUtility.AddAndRemoveDynamicComponents(target, false);
                Find.ColonistBar.MarkColonistsDirty();

                if (hackType == 3)
                {
                    csm.Hacked          = hackType;
                    csm.hackOrigFaction = prevFaction;
                    if (wasPrisonner)
                    {
                        csm.hackWasPrisoned = true;
                    }
                    else
                    {
                        csm.hackWasPrisoned = false;
                    }
                    csm.hackEndGT = Find.TickManager.TicksGame + (Settings.nbSecDurationTempHack * 60);
                }
                else
                {
                    //Si le surrogate quon veux controlé est infecté alors on enleve l'infection et on reset ses stats
                    if (csm.Infected != -1)
                    {
                        csm.Infected = -1;

                        if (target.skills != null && target.skills.skills != null)
                        {
                            foreach (var sr in target.skills.skills)
                            {
                                sr.levelInt = 0;
                            }
                        }
                    }
                }


                break;
            }

            Utils.GCATPP.decHackingPoints(nbpToConsume);

            Utils.soundDefSurrogateHacked.PlayOneShot(null);

            //Notif d'applciation de l'effet
            Messages.Message("ATPP_SurrogateHackOK".Translate(surrogateName), target, MessageTypeDefOf.PositiveEvent);

            //ANimation sonore et visuelle
            Utils.soundDefSurrogateConnection.PlayOneShot(null);
            MoteMaker.ThrowDustPuffThick(pos.ToVector3Shifted(), cmap, 4.0f, Color.red);

            Find.DesignatorManager.Deselect();
        }
        public override IEnumerable <Gizmo> CompGetGizmosExtra()
        {
            Building build = (Building)parent;

            //Si aucun mind stocké
            if (storedMinds.Count() == 0 || !build.TryGetComp <CompPowerTrader>().PowerOn || !Booted())
            {
                yield break;
            }

            yield return(new Command_Action {
                icon = Tex.processInfo,
                defaultLabel = "ATPP_ProcessInfo".Translate(),
                defaultDesc = "ATPP_ProcessInfoDesc".Translate(),
                action = delegate() {
                    showFloatMenuMindsStored(delegate(Pawn p) {
                        Find.WindowStack.Add(new Dialog_InfoCard(p));
                    }, false, false, false, true);
                }
            });

            yield return(new Command_Action {
                icon = Tex.processRemove,
                defaultLabel = "ATPP_ProcessRemove".Translate(),
                defaultDesc = "ATPP_ProcessRemoveDesc".Translate(),
                action = delegate() {
                    showFloatMenuMindsStored(delegate(Pawn p) {
                        Find.WindowStack.Add(new Dialog_Msg("ATPP_ProcessRemove".Translate(), "ATPP_ProcessRemoveDescConfirm".Translate(p.LabelShortCap, getName()), delegate {
                            stopMindActivities(p);

                            RemoveMind(p);
                            p.Kill(null, null);

                            Messages.Message("ATPP_ProcessRemoveOK".Translate(p.LabelShortCap), parent, MessageTypeDefOf.PositiveEvent);

                            Utils.playVocal("soundDefSkyCloudMindDeletionCompleted");
                        }, false));
                    }, false, false, false, false);
                }
            });

            yield return(new Command_Action {
                icon = Tex.processDuplicate,
                defaultLabel = "ATPP_ProcessDuplicate".Translate(),
                defaultDesc = "ATPP_ProcessDuplicateDesc".Translate(),
                action = delegate() {
                    showFloatMenuMindsStored(delegate(Pawn p) {
                        CompSurrogateOwner cso = p.ATCompSurrogateOwner;
                        if (cso == null)
                        {
                            return;
                        }

                        int GT = Find.TickManager.TicksGame;

                        cso.replicationStartGT = GT;
                        cso.replicationEndingGT = GT + (Settings.mindReplicationHours * 2500);

                        replicatingMinds.Add(p);
                        stopMindActivities(p);

                        Messages.Message("ATPP_ProcessDuplicateOK".Translate(p.LabelShortCap), parent, MessageTypeDefOf.PositiveEvent);
                    }, false, false, false, false);
                }
            });

            yield return(new Command_Action {
                icon = Tex.processAssist,
                defaultLabel = "ATPP_ProcessAssist".Translate(),
                defaultDesc = "ATPP_ProcessAssistDesc".Translate(),
                action = delegate() {
                    List <FloatMenuOption> opts = new List <FloatMenuOption>();
                    //Affichage des minds affectés à l'assistement
                    opts.Add(new FloatMenuOption("ATPP_ProcessAssistAssignedMinds".Translate(), delegate {
                        List <FloatMenuOption> optsAdd = null;

                        //Check s'il y a lieu d'jaouter l'option (il y a au moin 1+ minds assigné à supprimer
                        if (assistingMinds.Count > 0)
                        {
                            optsAdd = new List <FloatMenuOption>();
                            optsAdd.Add(new FloatMenuOption("-" + ("ATPP_ProcessAssistUnassignAll".Translate()), delegate {
                                int nb = 0;
                                foreach (var m in storedMinds)
                                {
                                    if (assistingMinds.Contains(m))
                                    {
                                        assistingMinds.Remove(m);
                                        nb++;
                                    }
                                }

                                if (nb > 0)
                                {
                                    Messages.Message("ATPP_ProcessMassUnassist".Translate(nb), parent, MessageTypeDefOf.PositiveEvent);
                                }
                            }, MenuOptionPriority.Default, null, null, 0f, null, null));
                        }

                        showFloatMenuMindsStored(delegate(Pawn p) {
                            assistingMinds.Remove(p);

                            Messages.Message("ATPP_ProcessUnassistOK".Translate(p.LabelShortCap), parent, MessageTypeDefOf.PositiveEvent);
                        }, false, false, false, false, optsAdd, false, true);
                    }, MenuOptionPriority.Default, null, null, 0f, null, null));

                    //Affichage des minds non affectés à l'assistement
                    opts.Add(new FloatMenuOption("ATPP_ProcessAssistUnassignedMinds".Translate(), delegate {
                        List <FloatMenuOption> optsAdd = null;

                        //Check s'il y a lieu d'jaouter l'option (il y a des minds et des minds non ajoutés)
                        if (storedMinds.Count > 0 && getNbUnassistingMinds() > 0)
                        {
                            optsAdd = new List <FloatMenuOption>();
                            optsAdd.Add(new FloatMenuOption("-" + ("ATPP_ProcessAssistAssignAll".Translate()), delegate {
                                int nb = 0;
                                foreach (var m in storedMinds)
                                {
                                    if (!assistingMinds.Contains(m))
                                    {
                                        stopMindActivities(m);
                                        assistingMinds.Add(m);
                                        nb++;
                                    }
                                }

                                if (nb > 0)
                                {
                                    Messages.Message("ATPP_ProcessMassAssist".Translate(nb), parent, MessageTypeDefOf.PositiveEvent);
                                }
                            }, MenuOptionPriority.Default, null, null, 0f, null, null));
                        }

                        showFloatMenuMindsStored(delegate(Pawn p) {
                            stopMindActivities(p);
                            assistingMinds.Add(p);

                            Messages.Message("ATPP_ProcessAssistOK".Translate(p.LabelShortCap), parent, MessageTypeDefOf.PositiveEvent);
                        }, false, false, false, false, optsAdd, true);
                    }, MenuOptionPriority.Default, null, null, 0f, null, null));

                    FloatMenu floatMenuMap = new FloatMenu(opts);
                    Find.WindowStack.Add(floatMenuMap);
                }
            });

            yield return(new Command_Action {
                icon = Tex.processMigrate,
                defaultLabel = "ATPP_ProcessMigrate".Translate(),
                defaultDesc = "ATPP_ProcessMigrateDesc".Translate(),
                action = delegate() {
                    showFloatMenuMindsStored(delegate(Pawn p) {
                        Utils.ShowFloatMenuSkyCloudCores(delegate(Building core) {
                            CompSurrogateOwner cso = p.ATCompSurrogateOwner;
                            stopMindActivities(p);
                            cso.startMigration(core);
                        }, (Building)parent);
                    }, false, false, false, false);
                }
            });

            yield return(new Command_Action {
                icon = Tex.processSkillUp,
                defaultLabel = "ATPP_Skills".Translate(),
                defaultDesc = "ATPP_SkillsDesc".Translate(),
                action = delegate() {
                    showFloatMenuMindsStored(delegate(Pawn p) {
                        Find.WindowStack.Add(new Dialog_SkillUp(p, true));
                    }, false, false, false, true);
                }
            });

            yield return(new Command_Action {
                icon = Tex.AndroidToControlTarget,
                defaultLabel = "ATPP_AndroidToControlTarget".Translate(),
                defaultDesc = "ATPP_AndroidToControlTargetDesc".Translate(),
                action = delegate() {
                    showFloatMenuMindsStored(delegate(Pawn p) {
                        //Listing map de destination
                        List <FloatMenuOption> opts = new List <FloatMenuOption>();
                        string lib = "";
                        foreach (var m in Find.Maps)
                        {
                            if (m == Find.CurrentMap)
                            {
                                lib = "ATPP_ThisCurrentMap".Translate(m.Parent.Label);
                            }
                            else
                            {
                                lib = m.Parent.Label;
                            }

                            opts.Add(new FloatMenuOption(lib, delegate {
                                Current.Game.CurrentMap = m;
                                Designator_AndroidToControl x = new Designator_AndroidToControl(p, true);
                                Find.DesignatorManager.Select(x);
                            }, MenuOptionPriority.Default, null, null, 0f, null, null));
                        }
                        if (opts.Count != 0)
                        {
                            if (opts.Count == 1)
                            {
                                Designator_AndroidToControl x = new Designator_AndroidToControl(p, true);
                                Find.DesignatorManager.Select(x);
                            }
                            else
                            {
                                FloatMenu floatMenuMap = new FloatMenu(opts);
                                Find.WindowStack.Add(floatMenuMap);
                            }
                        }
                    }, true, true, false, false, null, true);
                }
            });

            if (Utils.isThereNotControlledSurrogateInCaravan())
            {
                //Si drones SX no controllés dans une caravane
                yield return(new Command_Action {
                    icon = Tex.AndroidToControlTargetRecovery,
                    defaultLabel = "ATPP_AndroidToControlTargetRecoverCaravan".Translate(),
                    defaultDesc = "ATPP_AndroidToControlTargetRecoverCaravanDesc".Translate(),
                    action = delegate() {
                        showFloatMenuMindsStored(delegate(Pawn p) {
                            Utils.ShowFloatMenuNotCOntrolledSurrogateInCaravan(p, delegate(Pawn sSX) {
                                CompSurrogateOwner cso = p.ATCompSurrogateOwner;
                                if (cso == null)
                                {
                                    return;
                                }

                                if (!Utils.GCATPP.isConnectedToSkyMind(sSX))
                                {
                                    //Tentative connection au skymind
                                    if (!Utils.GCATPP.connectUser(sSX))
                                    {
                                        return;
                                    }
                                }
                                cso.setControlledSurrogate(sSX);
                            });
                        }, true, true, false, false, null, true);
                    }
                });
            }

            if (getNbMindsConnectedToSurrogate() != 0 || controlledTurrets.Count() != 0)
            {
                yield return(new Command_Action {
                    icon = Tex.AndroidToControlTargetDisconnect,
                    defaultLabel = "ATPP_AndroidToControlTargetDisconnect".Translate(),
                    defaultDesc = "ATPP_AndroidToControlTargetDisconnectDesc".Translate(),
                    action = delegate() {
                        List <FloatMenuOption> opts = new List <FloatMenuOption>();
                        opts.Add(new FloatMenuOption("ATPP_ProcessDisconnectAllSurrogates".Translate(), delegate {
                            disconnectAllSurrogates();
                            disconnectAllRemotelyControlledTurrets();
                            Utils.playVocal("soundDefSkyCloudAllMindDisconnected");
                        }, MenuOptionPriority.Default, null, null, 0f, null, null));

                        showFloatMenuMindsStored(delegate(Pawn p) {
                            CompSurrogateOwner cso = p.ATCompSurrogateOwner;
                            if (cso != null && cso.isThereSX())
                            {
                                cso.disconnectControlledSurrogate(null);
                            }
                            stopRemotelyControlledTurret(p);
                        }, false, false, true, false, opts);
                    }
                });
            }

            yield break;
        }