コード例 #1
0
        public void UpdateFoundDefCache()
        {
            long now = DateTime.Now.Ticks;

            if (now - this.lastCacheUpdate > TimeSpan.TicksPerSecond)
            {
                this.lastCacheUpdate = now;

                this.foundDefCache.Clear();
                foreach (ThingDef def in this.AllowedDefs)
                {
                    if (CombatExtendedUtil.GetAmmoCount(def) > 0)
                    {
                        this.foundDefCache.Add(def);
                        continue;
                    }
                    foreach (Building_WeaponStorage s in WorldComp.GetWeaponStorages(null))
                    {
                        if (s.HasWeapon(this, def))
                        {
                            this.foundDefCache.Add(def);
                            break;
                        }
                    }
                }
            }
        }
コード例 #2
0
        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();
            }
        }
コード例 #3
0
        /*internal void AddWeapons(IEnumerable<ThingWithComps> weapons)
         * {
         * if (weapons == null)
         * return;
         *
         * foreach (ThingWithComps w in weapons)
         * {
         * this.AddWeapon(w);
         * }
         * }*/

        internal bool AddWeapon(ThingWithComps weapon)
        {
            if (this.CanAdd(weapon))
            {
                if (weapon.Spawned)
                {
                    weapon.DeSpawn();
                }

                if (CombatExtendedUtil.AddAmmo(weapon))
                {
                    return(true);
                }

                this.AddToSortedList(weapon, (CompBiocodable.IsBiocoded(weapon)) ? this.StoredBioEncodedWeapons : this.StoredWeapons);
                return(true);
            }
            return(false);
        }
コード例 #4
0
        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);
                    }
                }
            }
        }
コード例 #5
0
 public void UpdateDefCache(ThingDef def)
 {
     if (this.AllowedDefs.Contains(def))
     {
         if (CombatExtendedUtil.GetAmmoCount(def) > 0)
         {
             this.foundDefCache.Add(def);
             return;
         }
         foreach (Building_WeaponStorage s in WorldComp.GetWeaponStorages(null))
         {
             if (s.HasWeapon(this, def))
             {
                 this.foundDefCache.Add(def);
                 return;
             }
         }
     }
     this.foundDefCache.Remove(def);
 }
コード例 #6
0
 public void Empty()
 {
     try
     {
         this.AllowAdds = false;
         foreach (IEnumerable <ThingWithComps> l in this.StoredWeapons.Values)
         {
             this.DropWeapons(l);
         }
         foreach (IEnumerable <ThingWithComps> l in this.StoredBioEncodedWeapons.Values)
         {
             this.DropWeapons(l);
         }
         CombatExtendedUtil.EmptyAmmo(this);
         this.StoredWeapons.Clear();
         this.StoredBioEncodedWeapons.Clear();
     }
     finally
     {
         this.AllowAdds = true;
     }
 }
コード例 #7
0
        public static bool TryRemoveWeapon(ThingDef def, SharedWeaponFilter filter, bool includeBioencoded, out ThingWithComps weapon)
        {
            if (def != null)
            {
                if (CombatExtendedUtil.TryRemoveAmmo(def, 1, out Thing t))
                {
                    weapon = t as ThingWithComps;
                    if (weapon != null)
                    {
                        return(true);
                    }
                }

                foreach (Building_WeaponStorage ws in WeaponStoragesToUse)
                {
                    if (ws.TryRemoveWeapon(def, filter, includeBioencoded, out weapon))
                    {
                        return(true);
                    }
                }
            }
            weapon = null;
            return(false);
        }