Пример #1
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 + "].");
            }
        }
Пример #2
0
 static void Postfix(ref bool __result, ref Pawn __state, ThingWithComps eq)
 {
     if (__state != null)
     {
         if (WorldComp.TryGetAssignedWeapons(__state, out AssignedWeaponContainer c) &&
             c.Contains(eq))
         {
             if (!Settings.AllowPawnsToDropWeapon)
             {
                 if (!WorldComp.Add(eq))
                 {
                     Log.Warning($"unable to find weapon storage that can hold {eq.ThingID} so it will be dropped.");
                     WorldComp.Drop(eq);
                 }
             }
             else
             {
                 if (c.Remove(eq))
                 {
                     if (eq.def.IsRangedWeapon)
                     {
                         if (!HarmonyPatchUtil.EquipRanged(c))
                         {
                             HarmonyPatchUtil.EquipMelee(c);
                         }
                     }
                     else
                     {
                         if (!HarmonyPatchUtil.EquipMelee(c))
                         {
                             HarmonyPatchUtil.EquipRanged(c);
                         }
                     }
                 }
                 if (Settings.PlaceDroppedWeaponsInStorage)
                 {
                     if (!WorldComp.Add(eq))
                     {
                         Log.Warning($"unable to find weapon storage that can hold {eq.ThingID} so it will be dropped.");
                         WorldComp.Drop(eq);
                     }
                 }
             }
         }
         else
         {
             foreach (SharedWeaponFilter swf in WorldComp.SharedWeaponFilter)
             {
                 if (swf.Allows(eq) &&
                     !WorldComp.Add(eq))
                 {
                     Log.Warning($"unable to find weapon storage that can hold {eq.ThingID} so it will be dropped.");
                     WorldComp.Drop(eq);
                     break;
                 }
             }
         }
     }
 }
        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);
                    }
                }
            }
        }
        private void CullStorage(List <ThingWithComps> removed, LinkedList <ThingWithComps> l)
        {
            LinkedListNode <ThingWithComps> n = l.First;

            while (n != null)
            {
                var next = n.Next;
                if (!this.CanAdd(n.Value))
                {
                    removed.Add(n.Value);
                    l.Remove(n);
                }
                n = next;
            }

            foreach (ThingWithComps t in removed)
            {
                if (!WorldComp.Add(t))
                {
                    this.DropThing(t);
                }
            }
        }
Пример #5
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();
        }