Example #1
0
        public void RemoveModule(ArmorModuleDef moduleDef, IntVec3 pos, Map map, bool drop)
        {
            foreach (var armorSlot in Slots)
            {
                if (armorSlot.Category == moduleDef.ModuleCategory)
                {
                    foreach (var slot in armorSlot.Modules)
                    {
                        if (slot.Module != null)
                        {
                            if (slot.Module.def == moduleDef)
                            {
                                slot.Module = null;

                                if (drop && slot.Item != null)
                                {
                                    if (CellFinder.TryFindRandomCellNear(pos, map, 4, null, out IntVec3 result))
                                    {
                                        GenSpawn.Spawn(slot.Item, result, map);
                                        slot.Item = null;
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            }

            Notify_ModulesChanges();
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            yield return(Toils_Reserve.Reserve(TargetIndex.B));

            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.B).FailOnSomeonePhysicallyInteracting(TargetIndex.B));

            yield return(Toils_Haul.StartCarryThing(TargetIndex.B));

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch));

            yield return(Toils_General.Wait(1200).WithProgressBarToilDelay(TargetIndex.A).FailOnDestroyedOrNull(TargetIndex.A));

            Toil finish = new Toil
            {
                initAction = delegate
                {
                    if (module != null)
                    {
                        ArmorModuleDef moduleDef = DefDatabase <ArmorModuleDef> .AllDefs.Where(x => x.Item == module.def).FirstOrDefault();

                        if (moduleDef == null)
                        {
                            return;
                        }

                        armor.AddModule(moduleDef, module);
                        pawn.carryTracker.TryDropCarriedThing(pawn.Position, ThingPlaceMode.Near, out Thing t);
                        module.DeSpawn();
                    }
                },
Example #3
0
        public void RemoveModule(ArmorModuleDef moduleDef)
        {
            foreach (var armorSlot in Slots)
            {
                if (armorSlot.Category == moduleDef.ModuleCategory)
                {
                    foreach (var slot in armorSlot.Modules)
                    {
                        if (slot.Module.def == moduleDef)
                        {
                            slot.Module = null;
                            break;
                        }
                    }
                }
            }

            Notify_ModulesChanges();
        }
Example #4
0
        public void AddModule(ArmorModuleDef moduleDef, Thing item)
        {
            MKArmorModule module = (MKArmorModule)Activator.CreateInstance(moduleDef.workerClass);

            module.def   = moduleDef;
            module.Armor = this;

            foreach (var armorSlot in Slots)
            {
                if (armorSlot.Category == moduleDef.ModuleCategory)
                {
                    foreach (var slot in armorSlot.Modules)
                    {
                        if (slot.Module == null)
                        {
                            slot.Module = module;
                            slot.Item   = item;
                            Notify_ModulesChanges();
                            break;
                        }
                    }
                }
            }
        }