Beispiel #1
0
        //     var slotsUsed = ApparelSlotMaker.Create(body, wornApparel);
        //     foreach (var def in Utility.apparelDefs.Where(t => t.IsApparel && !slotsUsed.Intersects(ApparelSlotMaker.Create(body, t))))
        //         yield return def;

        public static List <Tuple <Item, Tag> > WornApparelFor(BodyDef def, List <Tuple <Item, Tag, int> > apparels)
        {
            var         wornApparels     = new List <Tuple <Item, Tag> >();
            ApparelSlot wornApparelSlots = null;

            foreach (var(apparel, tag, _) in apparels.OrderBy(app => app.Item3))
            {
                // can obviously wear it if we aren't wearing anything
                if (wornApparelSlots == null)
                {
                    wornApparelSlots = ApparelSlotMaker.Create(def, apparel.Def);
                    wornApparels.Add(new Tuple <Item, Tag>(apparel, tag));
                    continue;
                }

                var apparelSlots = ApparelSlotMaker.Create(def, apparel.Def);

                if (!wornApparelSlots.Intersects(apparelSlots))
                {
                    wornApparels.Add(new Tuple <Item, Tag>(apparel, tag));

                    wornApparelSlots = ApparelSlotMaker.Create(def, wornApparels.Select(kv => kv.Item1.Def));
                }
            }
            return(wornApparels);
        }
Beispiel #2
0
        private bool IntersectsWith(ApparelSlot other)
        {
            if (other.bodyDef != bodyDef)
            {
                Log.ErrorOnce("Trying to do intersection calculations on an a pair of ApparelSlots which refer to different body defs", 23869504);
            }

            foreach (var(key, value) in other.bodyPartGroups)
            {
                if (interferingBodyPartGroups.TryGetValue(key, out var bodyPartGroupDefs) && bodyPartGroupDefs.Intersect(value).Any())
                {
                    return(true);
                }
            }

            foreach (var(key, value) in bodyPartGroups)
            {
                if (other.interferingBodyPartGroups.TryGetValue(key, out var bodyPartGroupDefs) && bodyPartGroupDefs.Intersect(value).Any())
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #3
0
        public bool Intersects(ApparelSlot other)
        {
            if (!intersectionCache.TryGetValue(other, out var intersects))
            {
                intersects = IntersectsWith(other);
                intersectionCache.Add(other, intersects);
            }

            return(intersects);
        }
Beispiel #4
0
        public static ApparelSlot Create(BodyDef def, ThingDef apparel)
        {
            var kp = new KeyPair(def, apparel);

            if (!cachedApparelSlots.TryGetValue(kp, out var slot))
            {
                slot = new ApparelSlot(def, apparel);
                cachedApparelSlots.Add(kp, slot);
            }

            return(slot);
        }