internal void ReclaimWeapons(bool force = false)
        {
            if (base.Map == null)
            {
                return;
            }

            List <ThingWithComps> l = BuildingUtil.FindThingsOfTypeNextTo <ThingWithComps>(base.Map, base.Position, 1);

            if (l.Count > 0)
            {
                foreach (ThingWithComps t in l)
                {
                    if (!this.AddWeapon(t) &&
                        force &&
                        t.Spawned &&
                        (t.def.IsWeapon || CombatExtendedUtil.IsAmmo(t)) &&
                        !t.def.defName.Equals("WoodLog"))
                    {
                        t.DeSpawn();
                        if (this.forceAddedWeapons == null)
                        {
                            forceAddedWeapons = new List <Thing>(l.Count);
                        }
                        this.forceAddedWeapons.Add(t);
                    }
                }
                l.Clear();
            }
        }
Example #2
0
        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);
            this.compPowerTrader             = base.GetComp <CompPowerTrader>();
            this.compPowerTrader.PowerOutput = -LOW_POWER_COST;

            this.CurrentMap = map;

            foreach (Building_WeaponStorage s in BuildingUtil.FindThingsOfTypeNextTo <Building_WeaponStorage>(base.Map, base.Position, Settings.RepairAttachmentDistance))
            {
                this.Add(s);
            }

#if DEBUG_REPAIR
            Log.Warning(this.Label + " adding attached dressers:");
            foreach (Building_Dresser d in this.AttachedDressers)
            {
                Log.Warning(" " + d.Label);
            }
#endif

            this.compPowerTrader.powerStartedAction = new Action(delegate()
            {
                this.compPowerTrader.PowerOutput = LOW_POWER_COST;
            });

            this.compPowerTrader.powerStoppedAction = new Action(delegate()
            {
                this.StopRepairing();
                this.compPowerTrader.PowerOutput = 0;
            });
        }
        public static bool TryDropAmmo(ThingDef def, int count, IntVec3 position, Map map, out Thing droppedAmmo)
        {
            //Log.Warning("Util Drop: " + def.defName + " x" + count);
            if (count > 0 &&
                def != null &&
                Ammo.TryGetValue(def, out int i) &&
                i > 0)
            {
                if (i < count)
                {
                    count = i;
                }

                i -= count;

                //Log.Message("    Dropping Count: " + count);
                droppedAmmo = MakeAmmo(def, count);
                if (BuildingUtil.DropThing(droppedAmmo, position, map))
                {
                    //Log.Message("    Remaining Count: " + i);
                    Ammo[def] = i;
                    return(true);
                }
                else
                {
                    Log.Error("Failed to drop " + def.defName + " x" + count);
                }
            }
            droppedAmmo = null;
            return(false);
        }
Example #4
0
        public static void UnequipPrimaryWeapon(Pawn pawn, AssignedWeaponContainer c)
        {
            ThingWithComps weapon = pawn?.equipment?.Primary;

            if (weapon == null)
            {
                return;
            }

            pawn.equipment.Remove(weapon);

            if (c != null && c.Contains(weapon))
            {
                c.Add(weapon);
                return;
            }

            if (WorldComp.Add(weapon))
            {
                return;
            }

            if (!BuildingUtil.DropSingleThing(weapon, pawn.Position, pawn.Map, false))
            {
                Log.Warning("Failed to drop " + pawn.Name.ToStringShort + "'s primary weapon [" + pawn.equipment.Primary.Label + "].");
            }
        }
        public static bool Drop(ThingWithComps w)
        {
            foreach (Building_WeaponStorage ws in WeaponStoragesToUse)
            {
                if (BuildingUtil.DropThing(w, ws, ws.Map))
                {
                    return(true);
                }
            }

            return(false);
        }
 private static void DropAllNoUpate(ThingDef def, int count, Building_WeaponStorage ws)
 {
     while (count > 0)
     {
         int toDrop = Math.Max(def.stackLimit, 1);
         if (toDrop > count)
         {
             toDrop = count;
         }
         BuildingUtil.DropThing(MakeAmmo(def, toDrop), ws, ws.Map);
         count -= toDrop;
     }
 }
        private void Dispose()
        {
            try
            {
                if (this.StoredWeapons != null)
                {
                    foreach (LinkedList <ThingWithComps> l in this.StoredWeapons.Values)
                    {
                        foreach (ThingWithComps t in l)
                        {
                            this.DropThing(t);
                        }
                    }
                    this.StoredWeapons.Clear();
                }
                if (this.StoredBioEncodedWeapons != null)
                {
                    foreach (LinkedList <ThingWithComps> l in this.StoredBioEncodedWeapons.Values)
                    {
                        foreach (ThingWithComps t in l)
                        {
                            this.DropThing(t);
                        }
                    }
                    this.StoredBioEncodedWeapons.Clear();
                }
            }
            catch (Exception e)
            {
                Log.Error(
                    this.GetType().Name + ".Dispose\n" +
                    e.GetType().Name + " " + e.Message + "\n" +
                    e.StackTrace);
            }

            WorldComp.Remove(this);
            foreach (Building_RepairWeaponStorage r in BuildingUtil.FindThingsOfTypeNextTo <Building_RepairWeaponStorage>(base.Map, base.Position, Settings.RepairAttachmentDistance))
            {
#if DEBUG_REPAIR
                Log.Warning("Removing Dresser " + this.Label + " to " + r.Label);
#endif
                r.Remove(this);
            }
        }
        public override void Notify_ReceivedThing(Thing newItem)
        {
            if (!this.AllowAdds)
            {
                if (!newItem.Spawned)
                {
                    DropThing(newItem);
                }
                return;
            }

            if (!((newItem is ThingWithComps) && ((ThingWithComps)newItem).def.IsWeapon) &&
                !CombatExtendedUtil.IsAmmo(newItem))
            {
                if (!newItem.Spawned)
                {
                    DropThing(newItem);
                }
                return;
            }

            base.Notify_ReceivedThing(newItem);

            if (!CombatExtendedUtil.AddAmmo(newItem))
            {
                if (newItem is ThingWithComps &&
                    !this.Contains((ThingWithComps)newItem))
                {
                    // Must go after 'contains' check. In the case of 'drop on floor' Notify_ReceiveThing gets called before the weapon is removed from the list
                    if (newItem.Spawned)
                    {
                        newItem.DeSpawn();
                    }

                    if (!this.AddWeapon(newItem as ThingWithComps) &&
                        !WorldComp.Add(newItem as ThingWithComps))
                    {
                        BuildingUtil.DropThing(newItem, this, this.CurrentMap, true);
                    }
                }
            }
        }
Example #9
0
        static void Postfix(Pawn __instance, ref State __state)
        {
            if (__instance.Dead && __instance.IsColonist && __instance.apparel?.LockedApparel?.Count == 0 && __state.Weapon != null)
            {
                if (WorldComp.Add(__state.Weapon))
                {
                    __instance.equipment?.Remove(__state.Weapon);
                }

                if (WorldComp.TryGetAssignedWeapons(__instance, out AssignedWeaponContainer c))
                {
                    WorldComp.RemoveAssignedWeapons(__instance);

                    foreach (ThingWithComps w in c.Weapons)
                    {
                        if (!WorldComp.Add(w))
                        {
                            BuildingUtil.DropSingleThing(w, __instance.Position, __state.Map);
                        }
                    }
                }
            }
        }
        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);
            this.CurrentMap = map;

            if (settings == null)
            {
                base.settings = new StorageSettings(this);
                base.settings.CopyFrom(this.def.building.defaultStorageSettings);
                base.settings.filter.SetDisallowAll();
            }
            this.UpdatePreviousStorageFilter();
            WorldComp.Add(this);

            foreach (Building_RepairWeaponStorage r in BuildingUtil.FindThingsOfTypeNextTo <Building_RepairWeaponStorage>(base.Map, base.Position, Settings.RepairAttachmentDistance))
            {
#if DEBUG_REPAIR
                Log.Warning("Adding Dresser " + this.Label + " to " + r.Label);
#endif
                r.Add(this);
            }

            WorldComp.InitializeAssignedWeapons();
        }
 private bool DropThing(Thing t)
 {
     return(BuildingUtil.DropThing(t, this, this.CurrentMap));
 }