Exemple #1
0
        public override void Destroy(DestroyMode mode = DestroyMode.Vanish)
        {
            IntVec3 oldPos = this.Position != IntVec3.Invalid ? this.Position : this.PositionHeld;
            Map     oldMap = this.Map != null ? this.Map : this.MapHeld;
            X2_Building_AIRobotRechargeStation oldRechargeStation = this.rechargeStation;

            ThingDef wDef = null;

            if (this != null && this.def2 != null && this.def2.destroyedDef != null)
            {
                wDef = this.def2.destroyedDef;
            }

            base.Destroy(DestroyMode.Vanish);

            // spawn destroyed object here
            if (mode != DestroyMode.Vanish && wDef != null)
            {
                X2_AIRobot_disabled thing = (X2_AIRobot_disabled)GenSpawn.Spawn(wDef, oldPos, oldMap);
                thing.stackCount      = 1;
                thing.rechargestation = oldRechargeStation;

                // set the disabled robot in the recharge station
                oldRechargeStation.disabledRobot = thing;
            }
        }
        private Toil Toils_TryToDeconstructRechargeStation(Pawn actor, TargetIndex robotInd)
        {
            X2_AIRobot_disabled target = pawn.jobs.curJob.GetTarget(robotInd).Thing as X2_AIRobot_disabled;

            if (target == null)
            {
                Log.Error("Disabled robot is null!");
                return(null);
            }

            Toil toil = new Toil();

            toil.initAction = () =>
            {
                if (target.rechargestation != null)
                {
                    target.rechargestation.Destroy(DestroyMode.Deconstruct);
                }
            };

            toil.defaultCompleteMode = ToilCompleteMode.Instant;
            toil.defaultDuration     = 0;

            return(toil);
        }
Exemple #3
0
        public Toil DoRepairWork(int duration, string soundDefName, X2_AIRobot_disabled robot)
        {
            float    expPerSecond = 25f;
            SkillDef skillDef     = SkillDefOf.Crafting;

            Toil toil = new Toil();

            //toil.initAction = delegate
            //{

            //};
            toil.tickAction = delegate
            {
                Pawn        actor       = toil.actor;
                Job         curJob      = actor.jobs.curJob;
                SkillRecord skillRecord = actor.skills.GetSkill(skillDef);

                // actor learns something
                actor.skills.Learn(SkillDefOf.Crafting, expPerSecond / 60);
            };

            toil.AddFinishAction(delegate
            {
                Pawn actor = toil.actor;
                Job curJob = actor.jobs.curJob;

                // Calculate possible hitpoint gain multiplicator
                SkillRecord skillRecord = actor.skills.GetSkill(skillDef);

                // Get the partitians
                X2_Building_AIRobotRechargeStation station = curJob.GetTarget(StationIndex).Thing as X2_Building_AIRobotRechargeStation;
                //X2_AIRobot_disabled robot = curJob.GetTarget(RobotIndex).Thing as X2_AIRobot_disabled;

                // vanish ...
                for (int i = this.ingredients.Count - 1; i >= 0; i--)
                {
                    Thing ingredient = ingredients[i];
                    ingredient.Destroy(DestroyMode.Vanish);
                }
                ingredients.Clear();
                ingredients = null;

                //robot.Destroy(DestroyMode.Vanish);

                actor.Map.resourceCounter.UpdateResourceCounts();

                // repair ...
                station.Notify_RobotRepaired();
            });

            toil.handlingFacing      = true;
            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.defaultDuration     = duration;
            toil.WithProgressBarToilDelay(StationIndex, false, -0.4f);
            toil.PlaySustainerOrSound(() => SoundDef.Named(soundDefName));

            return(toil);
        }
Exemple #4
0
        public override IEnumerable <FloatMenuOption> GetFloatMenuOptions(Pawn selPawn)
        {
            foreach (FloatMenuOption fmo in base.GetFloatMenuOptions(selPawn))
            {
                yield return(fmo);
            }

            foreach (FloatMenuOption fmo in X2_AIRobot_disabled.GetFloatMenuOptions(selPawn, this))
            {
                yield return(fmo);
            }
        }
Exemple #5
0
        public override IEnumerable <FloatMenuOption> GetFloatMenuOptions(Pawn selPawn)
        {
            foreach (FloatMenuOption fmo in base.GetFloatMenuOptions(selPawn))
            {
                yield return(fmo);
            }

            if (this.robotIsDestroyed && this.disabledRobot != null)
            {
                foreach (FloatMenuOption fmo in X2_AIRobot_disabled.GetFloatMenuOptions(selPawn, disabledRobot))
                {
                    yield return(fmo);
                }
            }
        }
Exemple #6
0
        //private void StartRepairJob(Pawn pawn)
        //{
        //    List<Thing> foundIngredients;
        //    List<int> foundIngredientsCount;
        //    List<Thing> foundIngredients2;
        //    List<int> foundIngredients2Count;
        //    if (!AIRobot_Helper.GetAllNeededIngredients(pawn, DefDatabase<ThingDef>.GetNamed(ingredientDefName), this.ingredientNeedCount, out foundIngredients, out foundIngredientsCount) ||
        //            foundIngredients == null || foundIngredients.Count == 0)
        //        return;
        //    if (!AIRobot_Helper.GetAllNeededIngredients(pawn, DefDatabase<ThingDef>.GetNamed(ingredient2DefName), this.ingredient2NeedCount, out foundIngredients2, out foundIngredients2Count) ||
        //            foundIngredients == null || foundIngredients.Count == 0)
        //        return;

        //    //Log.Error("foundIngredients="+foundIngredients.Count.ToString() + " " + "foundIngredientsCount="+foundIngredientsCount.Count.ToString());

        //    List<LocalTargetInfo> ingredientsLTI = new List<LocalTargetInfo>();
        //    foreach (Thing t in foundIngredients)
        //        ingredientsLTI.Add(t);
        //    foreach (Thing t in foundIngredients2)
        //        ingredientsLTI.Add(t);

        //    X2_JobDriver_RepairDamagedRobot repairRobot = new X2_JobDriver_RepairDamagedRobot();
        //    Job job = new Job(DefDatabase<JobDef>.GetNamed(this.jobDefName_repair), this.rechargestation, foundIngredients[0], this);
        //    job.targetQueueB = ingredientsLTI;
        //    job.countQueue = foundIngredientsCount;
        //    pawn.jobs.StopAll();
        //    pawn.jobs.StartJob(job);

        //    Log.Error("Pawn.CurJob:" + pawn.CurJob.def.defName);
        //    //Log.Error("Job: "+ job.def.defName + " Ingredients: "+ foundIngredientsCount[0].ToString());

        //}

        public static void StartRepairJob2(Pawn pawn, X2_AIRobot_disabled disabledRobot)
        {
            List <Thing> foundIngredients, foundIngredients2;
            List <int>   foundIngredientsCount, foundIngredients2Count;

            if (!AIRobot_Helper.GetAllNeededIngredients(pawn, disabledRobot.def.costList[0].thingDef, disabledRobot.def.costList[0].count, out foundIngredients, out foundIngredientsCount) ||
                foundIngredients == null || foundIngredients.Count == 0)
            {
                return;
            }
            if (!AIRobot_Helper.GetAllNeededIngredients(pawn, disabledRobot.def.costList[1].thingDef, disabledRobot.def.costList[1].count, out foundIngredients2, out foundIngredients2Count) ||
                foundIngredients2 == null || foundIngredients2.Count == 0)
            {
                return;
            }


            //Log.Error("foundIngredients="+foundIngredients.Count.ToString() + " " + "foundIngredientsCount="+foundIngredientsCount.Count.ToString());

            X2_JobDriver_RepairDamagedRobot repairRobot = new X2_JobDriver_RepairDamagedRobot();
            Job job = new Job(DefDatabase <JobDef> .GetNamed(X2_AIRobot_disabled.jobDefName_repair), disabledRobot.rechargestation, disabledRobot, disabledRobot.rechargestation.Position);

            job.count        = 1;
            job.targetQueueB = new List <LocalTargetInfo>(foundIngredients.Count + foundIngredients2.Count);
            job.countQueue   = new List <int>(foundIngredients.Count + foundIngredients2.Count);

            job.targetQueueB.Add(disabledRobot);
            job.countQueue.Add(1);

            for (int i = 0; i < foundIngredients.Count; i++)
            {
                job.targetQueueB.Add(foundIngredients[i]);
                job.countQueue.Add(foundIngredientsCount[i]);
            }
            for (int i = 0; i < foundIngredients2.Count; i++)
            {
                job.targetQueueB.Add(foundIngredients2[i]);
                job.countQueue.Add(foundIngredients2Count[i]);
            }
            job.haulMode = HaulMode.ToCellNonStorage;


            pawn.jobs.StopAll();
            pawn.jobs.StartJob(job);

            //Log.Error("Pawn.CurJob:" + pawn.CurJob.def.defName);
            //Log.Error("Job: "+ job.def.defName + " Ingredients: "+ foundIngredientsCount[0].ToString());
        }
        private void Button_ResetDestroyedRobot(bool spawn = true)
        {
            if (robot != null && !robot.Destroyed)
            {
                robot.Destroy(DestroyMode.Vanish);
            }

            this.robot       = null;
            robotIsDestroyed = false;
            if (spawn)
            {
                Button_SpawnBot();
            }

            disabledRobot = null;
        }
        private void Button_RepairDamagedRobot()
        {
            NameTriple name = null;
            string     first = null, nick = null, last = null;

            Area area = null;

            X2_AIRobot bot = this.robot;

            if (bot == null && this.container.FirstOrDefault() != null)
            {
                bot = this.container.FirstOrDefault();
            }

            if (bot != null)
            {
                name = AIRobot_Helper.GetRobotName(bot);
            }
            if (bot != null && bot.playerSettings != null)
            {
                area = bot.playerSettings.AreaRestriction;
            }

            if (name != null)
            {
                first = name.First;
                nick  = name.Nick;
                last  = name.Last;
                name  = null;
            }

            if (bot != null && !bot.Destroyed && bot.Spawned)
            {
                bot.Destroy(DestroyMode.Vanish);
            }

            this.container.Clear();
            this.robot                 = null;
            this.robotIsDestroyed      = false;
            this.isRepairRequestActive = false;

            Button_SpawnBot();

            this.disabledRobot = null;

            if (first != null && nick != null && last != null)
            {
                name = new NameTriple(first, nick, last);
            }

            // Robot should again be filled (with the new robot)
            if (this.robot != null)
            {
                if (name != null)
                {
                    AIRobot_Helper.SetRobotName(this.robot, name);
                }
                if (area != null)
                {
                    this.robot.playerSettings.AreaRestriction = area;
                }
            }
        }
Exemple #9
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            robot = this.job.GetTarget(RobotIndex).Thing as X2_AIRobot_disabled;

            //Workbench giver destroyed (only in bill using phase! Not in carry phase)
            this.AddEndCondition(() =>
            {
                var targ = GetActor().jobs.curJob.GetTarget(StationIndex).Thing;
                if (targ == null || (targ is Building && !targ.Spawned))
                {
                    return(JobCondition.Incompletable);
                }
                return(JobCondition.Ongoing);
            });
            this.FailOnBurningImmobile(StationIndex);  //Rechargestation is burning

            this.FailOn(() =>
            {
                X2_Building_AIRobotRechargeStation workbench = job.GetTarget(StationIndex).Thing as X2_Building_AIRobotRechargeStation;

                //conditions only apply during the billgiver-use phase
                if (workbench == null)
                {
                    return(true);
                }
                return(false);
            });

            //Go to the recharge station, this is yielded later, but needed here!
            Toil gotoStation = Toils_Goto.GotoThing(StationIndex, PathEndMode.Touch);

            //Jump over ingredient gathering if there are no ingredients needed
            yield return(Toils_Jump.JumpIf(gotoStation, () => this.job.GetTargetQueue(IngredientIndex).NullOrEmpty()));


            {
                //Get to ingredient weapon and pick it up
                //Note that these fail cases must be on these toils, otherwise the recipe work fails if you stacked
                //   your targetB into another object on the bill giver square.

                Toil extract = Toils_JobTransforms.ExtractNextTargetFromQueue(IngredientIndex);
                yield return(extract);

                //Note that these fail cases must be on these toils, otherwise the recipe work fails if you stacked
                //   your targetB into another object on the bill giver square.
                var getToHaulTarget2 = Toils_Goto.GotoThing(IngredientIndex, PathEndMode.Touch)
                                       .FailOnDespawnedNullOrForbidden(IngredientIndex)
                                       .FailOnSomeonePhysicallyInteracting(IngredientIndex);
                yield return(getToHaulTarget2);

                //Carry ingredient to the workbench
                yield return(Toils_Haul.StartCarryThing(IngredientIndex, true));

                //Jump to pick up more in this run if we're collecting from multiple stacks at once
                yield return(JumpToAlsoCollectTargetInQueue(getToHaulTarget2, IngredientIndex));

                //Carry ingredient to the workbench
                yield return(Toils_Goto.GotoThing(StationIndex, PathEndMode.Touch)
                             .FailOnDestroyedOrNull(IngredientIndex));

                //Place ingredient on the appropriate cell
                Toil findPlaceTarget2 = SetTargetToIngredientPlaceCell(StationIndex, IngredientIndex, IngredientPlaceCellIndex);
                yield return(findPlaceTarget2);

                yield return(Toils_Haul.PlaceHauledThingInCell(IngredientPlaceCellIndex,
                                                               nextToilOnPlaceFailOrIncomplete: findPlaceTarget2,
                                                               storageMode: false));

                // save the ingredient, so that it can be deleted later on!
                Toil saveIngredient = new Toil();
                saveIngredient.initAction          = delegate { this.ingredients.Add(GetActor().jobs.curJob.GetTarget(IngredientIndex).Thing); };
                saveIngredient.defaultCompleteMode = ToilCompleteMode.Instant;
                yield return(saveIngredient);

                //Jump back if another ingredient is queued, or you didn't finish carrying your current ingredient target
                yield return(Toils_Jump.JumpIfHaveTargetInQueue(IngredientIndex, extract));
            }

            //Go to the recharge station
            yield return(gotoStation);


            //Do the repair work
            yield return(DoRepairWork(500, "Interact_ConstructMetal", robot)
                         .FailOnDespawnedNullOrForbiddenPlacedThings()
                         .FailOnCannotTouch(StationIndex, PathEndMode.Touch));
        }
Exemple #10
0
        public static IEnumerable <FloatMenuOption> GetFloatMenuOptions(Pawn selPawn, X2_AIRobot_disabled disabledRobot)
        {
            if (!selPawn.CanReach(disabledRobot, PathEndMode.InteractionCell, Danger.Deadly))
            {
                yield return(new FloatMenuOption("CannotUseNoPath".Translate().CapitalizeFirst(), null));

                yield break;
            }

            if (selPawn.skills.GetSkill(SkillDefOf.Construction).Level < X2_AIRobot_disabled.jobConstructionSkillMin)
            {
                yield return(new FloatMenuOption("ConstructionSkillTooLow".Translate().CapitalizeFirst() + ": " + "MinSkill".Translate() + " " + X2_AIRobot_disabled.jobConstructionSkillMin.ToString(), null));

                yield break;
            }


            ThingDef ingredientDef = disabledRobot.def.costList[0].thingDef;  // DefDatabase<ThingDef>.GetNamed(ingredientDefName);
            ThingDef ingredient2Def = disabledRobot.def.costList[1].thingDef; //DefDatabase<ThingDef>.GetNamed(ingredient2DefName);
            int      availableResources; int availableResources2;

            AIRobot_Helper.FindAvailableNearbyResources(ingredientDef, selPawn, out availableResources);
            AIRobot_Helper.FindAvailableNearbyResources(ingredient2Def, selPawn, out availableResources2);

            bool resourcesOk = true;

            if (resourcesOk && availableResources < disabledRobot.def.costList[0].count) //X2_AIRobot_disabled.ingredientNeedCount)
            {
                resourcesOk = false;
                yield return(new FloatMenuOption("AIRobot_RepairRobot".Translate().CapitalizeFirst() + ": " + "NotEnoughStoredLower".Translate() + " (" + availableResources.ToString() + " / " + disabledRobot.def.costList[0].count.ToString() + " " + ingredientDef.LabelCap + ")", null));
            }
            if (resourcesOk && availableResources2 < disabledRobot.def.costList[1].count) //X2_AIRobot_disabled.ingredient2NeedCount)
            {
                resourcesOk = false;
                yield return(new FloatMenuOption("AIRobot_RepairRobot".Translate().CapitalizeFirst() + ": " + "NotEnoughStoredLower".Translate() + " (" + availableResources2.ToString() + " / " + disabledRobot.def.costList[1].count.ToString() + " " + ingredient2Def.LabelCap + ")", null));
            }
            if (resourcesOk)
            {
                yield return(new FloatMenuOption("AIRobot_RepairRobot".Translate().CapitalizeFirst(), delegate { X2_AIRobot_disabled.StartRepairJob2(selPawn, disabledRobot); }));
            }

            //yield return new FloatMenuOption("AIRobot_DismantleRobot".Translate(), delegate { StartDismantleJob(selPawn); });
        }