// Token: 0x06000041 RID: 65 RVA: 0x000049B0 File Offset: 0x00002BB0
        internal static float GetQualFactor(Apparel apparel)
        {
            if (QualityUtility.TryGetQuality(apparel, out QualityCategory qualityCategory))
            {
                switch (qualityCategory)
                {
                case QualityCategory.Awful:
                    return(0.96f);

                case QualityCategory.Poor:
                    return(0.98f);

                case QualityCategory.Normal:
                    return(1f);

                case QualityCategory.Good:
                    return(1.02f);

                case QualityCategory.Excellent:
                    return(1.04f);

                case QualityCategory.Masterwork:
                    return(1.06f);

                case QualityCategory.Legendary:
                    return(1.08f);

                default:
                    break;
                }
            }
            return(1f);
        }
Exemple #2
0
        // Token: 0x0600001B RID: 27 RVA: 0x00003198 File Offset: 0x00001398
        internal static int GetQualOffset(Apparel apparel)
        {
            if (QualityUtility.TryGetQuality(apparel, out QualityCategory qualityCategory))
            {
                switch (qualityCategory)
                {
                case QualityCategory.Awful:
                    return(-10);

                case QualityCategory.Poor:
                    return(-5);

                case QualityCategory.Normal:
                    return(0);

                case QualityCategory.Good:
                    return(5);

                case QualityCategory.Excellent:
                    return(10);

                case QualityCategory.Masterwork:
                    return(15);

                case QualityCategory.Legendary:
                    return(20);

                default:
                    break;
                }
            }
            return(0);
        }
Exemple #3
0
        public static ThingTrade CreateTrade(Thing thing, int count)
        {
            var that = new ThingTrade();

            that.SetBaseInfo(thing, count); //Data заполняется!
            that.DataThing = thing;
            that.Concrete  = true;

            that.DefName      = thing.def.defName;
            that.StuffName    = thing.Stuff == null ? null : thing.Stuff.defName;
            that.HitPoints    = thing.HitPoints;
            that.MaxHitPoints = thing.MaxHitPoints;

            QualityCategory qq;

            if (QualityUtility.TryGetQuality(thing, out qq))
            {
                that.Quality = (int)qq;
            }

            Apparel thingA = thing as Apparel;

            if (thingA != null)
            {
                that.WornByCorpse = thingA.WornByCorpse;
            }

            return(that);
        }
Exemple #4
0
        public static ThingTrade CreateTrade(Thing thing, int count, bool withData = true)
        {
            var that = new ThingTrade();

            that.SetBaseInfo(thing, count);
            if (withData)
            {
                that.SetData(thing);
            }
            that.DataThing = thing;
            that.Concrete  = true;

            that.DefName   = thing.def.defName;
            that.StuffName = thing.Stuff == null ? null : thing.Stuff.defName;

            var pawn = thing as Pawn;

            if (pawn == null)
            {
                that.HitPoints    = thing.HitPoints;
                that.MaxHitPoints = thing.MaxHitPoints;
            }
            else
            {
                that.HitPoints    = (int)(pawn.health.summaryHealth.SummaryHealthPercent * 100f);
                that.MaxHitPoints = 100;
            }

            QualityCategory qq;

            if (QualityUtility.TryGetQuality(thing, out qq))
            {
                that.Quality = (int)qq;
            }

            Apparel thingA = thing as Apparel;

            if (thingA != null)
            {
                that.WornByCorpse = thingA.WornByCorpse;
            }

            that.Rotation = thing.Rotation.AsInt;

            Plant thingP = thing as Plant;

            if (thingP != null)
            {
                that.Growth = thingP.Growth;
            }

            that.Position = new IntVec3S(thing.Position);

            return(that);
        }
Exemple #5
0
        // Token: 0x06000062 RID: 98 RVA: 0x00006438 File Offset: 0x00004638
        public static void CorrectActiveApparel(Apparel apparel, Pawn pawn = null)
        {
            Thing thing = ThingMaker.MakeThing(apparel.def, apparel.Stuff);

            if (QualityUtility.TryGetQuality(apparel, out QualityCategory qualityCategory))
            {
                CompQuality compQuality = ThingCompUtility.TryGetComp <CompQuality>(thing);
                if (compQuality != null)
                {
                    compQuality.SetQuality(qualityCategory, ArtGenerationContext.Colony);
                }
            }
            CompColorable compColorable = ThingCompUtility.TryGetComp <CompColorable>(apparel);

            if (compColorable != null)
            {
                CompColorable compColorable2 = ThingCompUtility.TryGetComp <CompColorable>(thing);
                if (compColorable2 != null)
                {
                    compColorable2.Color = compColorable.Color;
                }
            }
            if (pawn != null)
            {
                pawn.apparel.Remove(apparel);
                apparel.Destroy(0);
                pawn.apparel.Wear(thing as Apparel, true, false);
                return;
            }
            if (apparel.Spawned)
            {
                IntVec3 intVec = IntVec3.Zero;
                Map     map    = apparel?.Map;
                if (map != null)
                {
                    intVec = apparel.Position;
                }
                apparel.Destroy(0);
                if (intVec != IntVec3.Zero)
                {
                    GenSpawn.Spawn(thing, intVec, map, 0);
                }
            }
        }
Exemple #6
0
        public static ThingTrade CreateTrade(Thing thing, int count, bool withData = true)
        {
            var that = new ThingTrade();

            that.SetBaseInfo(thing, count);
            if (withData)
            {
                that.SetData(thing);
            }
            that.DataThing = thing;
            that.Concrete  = true;

            that.DefName      = thing.def.defName;
            that.StuffName    = thing.Stuff == null ? null : thing.Stuff.defName;
            that.HitPoints    = thing.HitPoints;
            that.MaxHitPoints = thing.MaxHitPoints;

            QualityCategory qq;

            if (QualityUtility.TryGetQuality(thing, out qq))
            {
                that.Quality = (int)qq;
            }

            Apparel thingA = thing as Apparel;

            if (thingA != null)
            {
                that.WornByCorpse = thingA.WornByCorpse;
            }

            that.Rotation = thing.Rotation.AsInt;

            Plant thingP = thing as Plant;

            if (thingP != null)
            {
                that.Growth = thingP.Growth;
            }

            return(that);
        }
Exemple #7
0
        private static List <TransferableOneWay> ChechToTradeDo(IEnumerable <ThingTrade> targets, IEnumerable <Thing> allThings, ref int rate, bool setRect)
        {
            bool result  = true;
            var  selects = new List <TransferableOneWay>();
            var  source  = allThings.ToDictionary(i => i, i => i.stackCount);
            //сортируем вещи сначала более плохие
            var sourceKeys = source.Keys
                             .Select(t =>
            {
                QualityCategory qq;
                QualityUtility.TryGetQuality(t, out qq);
                return(new { thing = t, q = qq });
            })
                             .OrderBy(t => t.thing.def.defName + "#" + ((int)t.q).ToString() + (10000 - t.thing.HitPoints).ToString() + t.thing.stackCount.ToString().PadLeft(6))
                             .Select(t => t.thing)
                             .ToList();

            foreach (var target in targets)
            {
                if (target.Count == 0)
                {
                    target.NotTrade = false;
                    continue;
                }
                if (setRect && target.Count > 100 && rate > 1000000)
                {
                    rate = 1000000;                                                  //от переполнения
                }
                var select = new TransferableOneWay();
                //Log.Message(target.DefName);
                foreach (var thing in sourceKeys)
                {
                    if (target.Count * rate <= select.CountToTransfer)
                    {
                        break;
                    }
                    if (source[thing] == 0)
                    {
                        continue;
                    }
                    if (target.MatchesThing(thing))
                    {
                        //нам подходит выбираем нужное кол-во
                        select.things.Add(thing);
                        var count = target.Count * rate - select.CountToTransfer > source[thing]
                            ? source[thing]
                            : target.Count * rate - select.CountToTransfer;
                        select.ForceTo(select.CountToTransfer + count);
                        source[thing] -= count;
                        //Log.Message(target.DefName + " == " + thing.def.defName + " o:" + source[thing].ToString() + " g:" + select.CountToTransfer.ToString() + " rate:" + rate.ToString());
                    }
                    //else Log.Message(target.DefName + " != " + thing.def.defName + " " + select.CountToTransfer.ToString());
                }
                if (setRect && target.Count > select.CountToTransfer ||
                    !setRect && target.Count * rate > select.CountToTransfer)
                {
                    result          = false;
                    target.NotTrade = true;
                    //Log.Message("NotTrade " + target.Count.ToString() + " > " + select.CountToTransfer.ToString());
                }
                else
                {
                    if (setRect && target.Count * rate > select.CountToTransfer)
                    {
                        rate = select.CountToTransfer / target.Count;
                        //Log.Message(" rate:" + rate.ToString());
                    }
                    selects.Add(select);
                    target.NotTrade = false;
                }
            }
            return(result ? selects : null);
        }
        public static List <Thing> RemoveRememberedWeaponsFromThingList(List <Thing> carvanInventory, IEnumerable <Pawn> pawns)
        {
            // get remembered weapons for all pawns
            var rememberedNonEquippedCount = new Dictionary <ThingDefStuffDefPair, int>();

            foreach (var pawn in pawns)
            {
                // check if the pawn is a colonist
                if (!pawn.IsColonist)
                {
                    continue;
                }

                // retrieve siderarm memory
                var memory = CompSidearmMemory.GetMemoryCompForPawn(pawn);
                if (memory == null)
                {
                    continue;
                }

                // iterate over every remembered weapon
                foreach (var weapon in memory.RememberedWeapons)
                {
                    // ignore equipped remembered weapons
                    if (pawn.equipment?.Primary?.matchesThingDefStuffDefPair(weapon) == true)
                    {
                        continue;
                    }

                    // count remembered weapons which are not equipped
                    if (rememberedNonEquippedCount.ContainsKey(weapon))
                    {
                        rememberedNonEquippedCount[weapon]++;
                    }
                    else
                    {
                        rememberedNonEquippedCount.Add(weapon, 1);
                    }
                }
            }

            // sort items by quality so the highest quality items will be reserved for pawns
            carvanInventory.SortByDescending((thing) =>
            {
                QualityUtility.TryGetQuality(thing, out QualityCategory qc);
                return((int)qc); // NOTE: what about high quality weapons with low hitpoints?
            });

            // check for biocoded weapons and remove them from the list if the biocoded pawns are part of the caravan and remembers them
            for (int i = 0; i < carvanInventory.Count;)
            {
                var thing = carvanInventory[i];
                // check if thing is biocodable, is biocoded and if the pawn whom it is biocoded to is part of the caravan
                if (thing.TryGetComp <CompBiocodable>() is CompBiocodable biocode &&
                    biocode.Biocoded &&
                    biocode.CodedPawn is Pawn pawn &&
                    pawn.IsColonist &&
                    pawns.Contains(pawn))
                {
                    // if the pawn whom this weapon is biocoded to remembers this weapon, remove it from the output
                    var pair   = thing.toThingDefStuffDefPair();
                    var memory = CompSidearmMemory.GetMemoryCompForPawn(pawn);
                    if (memory != null && memory.RememberedWeapons.Contains(pair))
                    {
                        //Log.Message($"'{thing}' is biocoded and remembered by caravan member '{pawn}', removing from output");

                        // remove thing from output
                        carvanInventory.Remove(thing);
                        rememberedNonEquippedCount[pair]--;
                        continue;
                    }
                }
                i++;
            }

            // iterate over quality-sorted list of things in caravan inventory
            for (int i = 0; i < carvanInventory.Count;)
            {
                // if thing is a remembered weapon, skip it; this removes it from the output
                var thing = carvanInventory[i];
                var pair  = thing.toThingDefStuffDefPair();
                if (pair != null &&
                    rememberedNonEquippedCount.ContainsKey(pair) &&
                    rememberedNonEquippedCount[pair] > 0)
                {
                    //Log.Message($"'{thing}' is remembered by caravan member, removing from output");

                    // remove thing from output
                    carvanInventory.Remove(thing);
                    rememberedNonEquippedCount[pair]--;
                    continue;
                }
                i++;
            }

            // return output
            return(carvanInventory);
        }
        public static void TransferWeaponsToCorrectInventory(List <Pawn> pawns)
        {
            if (!(pawns?.Count > 0))
            {
                return;
            }

            var missingWeaponsForPawn   = new Dictionary <Pawn, List <ThingDefStuffDefPair> >();
            var availableThings         = new List <ThingWithComps>();
            var availableBiocodedThings = new Dictionary <Pawn, List <ThingWithComps> >();

            foreach (var pawn in pawns)
            {
                var pawnThings = new List <ThingWithComps>();

                // add equipped weapon to list
                if (pawn.equipment?.Primary != null)
                {
                    pawnThings.Add(pawn.equipment.Primary);
                }

                // add all weapons in inventory to list
                var inventory = pawn.inventory?.innerContainer;
                if (inventory != null)
                {
                    // filter out all weapons in inventory
                    foreach (var thing in inventory)
                    {
                        if ((thing.def.IsMeleeWeapon || thing.def.IsRangedWeapon) &&
                            thing is ThingWithComps thingWithComps)
                        {
                            pawnThings.Add(thingWithComps);
                        }
                    }
                }

                // check if we are looking at a colonist with an inventory
                if (pawn?.IsColonist == true)
                {
                    var pawnWeapons = new List <ThingDefStuffDefPair>(CompSidearmMemory.GetMemoryCompForPawn(pawn)?.RememberedWeapons);

                    // first remove things biocoded to this pawn; no-one else can use them anyway
                    for (int i = 0; i < pawnThings.Count;)
                    {
                        var thing = pawnThings[i];

                        // check if thing is biocoded to this pawn
                        var biocode = thing.TryGetComp <CompBiocodable>();
                        if (biocode?.Biocoded == true)
                        {
                            if (biocode.CodedPawn == pawn)
                            {
                                // remove from remembered weapon list
                                var weaponMemory = thing.toThingDefStuffDefPair();
                                if (weaponMemory != null)
                                {
                                    pawnWeapons.Remove(weaponMemory);
                                }
                            }
                            else
                            {
                                // add biocoded thing to their own list
                                var codedPawn = biocode.CodedPawn;
                                if (!availableBiocodedThings.ContainsKey(codedPawn))
                                {
                                    availableBiocodedThings.Add(codedPawn, new List <ThingWithComps>());
                                }
                                availableBiocodedThings[codedPawn].Add(thing);
                            }

                            // remove from thing list
                            pawnThings.Remove(thing);
                            continue;
                        }
                        i++;
                    }

                    // then remove things that fit the remembered weapons found on the pawn
                    if (pawnWeapons.Count > 0)
                    {
                        for (int i = 0; i < pawnThings.Count;)
                        {
                            var thing = pawnThings[i];

                            // check if thing is remembered
                            var weaponMemory = thing.toThingDefStuffDefPair();
                            if (weaponMemory != null && pawnWeapons.Contains(weaponMemory))
                            {
                                // remove remembered weapon and the thing that fits it
                                pawnWeapons.Remove(weaponMemory);
                                pawnThings.Remove(thing);
                                continue;
                            }
                            i++;
                        }
                    }

                    // finally all weapons still in the pawn's remembered weapons list are missing; we will look for them on other pawns
                    if (pawnWeapons.Count > 0 && !missingWeaponsForPawn.ContainsKey(pawn))
                    {
                        missingWeaponsForPawn.Add(pawn, new List <ThingDefStuffDefPair>());
                    }
                    foreach (var weapon in pawnWeapons)
                    {
                        missingWeaponsForPawn[pawn].Add(weapon);
                    }
                }

                // all things in the pawn's thing list are not remembered weapons for this pawn; they can be used by other pawns
                foreach (var thing in pawnThings)
                {
                    availableThings.Add(thing);
                }
            }

            // sort by quality; this way we should give every pawn the best weapon, unless they got a biocoded one
            availableThings.SortByDescending((thing) =>
            {
                QualityUtility.TryGetQuality(thing, out QualityCategory qc);
                return((int)qc);
            });

            // transfer unassigned weapons to pawns missing sidearms
            foreach (var entry in missingWeaponsForPawn)
            {
                var pawn           = entry.Key;
                var missingWeapons = entry.Value;

                List <ThingWithComps> biocodedToThisPawn = null;
                if (availableBiocodedThings.ContainsKey(pawn))
                {
                    biocodedToThisPawn = availableBiocodedThings[pawn];
                }

                // iterate over every missing weapon
                for (int i = 0; i < missingWeapons.Count;)
                {
                    var weaponMemory = missingWeapons[i];

                    // check available biocoded weapons first
                    if (biocodedToThisPawn != null)
                    {
                        // iterate over biocoded items
                        for (int j = 0; biocodedToThisPawn.Count > j;)
                        {
                            // get ThingDefStuffDefPair for thing
                            var thing       = biocodedToThisPawn[j];
                            var thingMemory = thing.toThingDefStuffDefPair();

                            // check if thing fits weapon memory
                            if (weaponMemory.Equals(thingMemory))
                            {
                                //Log.Message($"Transferring '{thing}' from '{ThingOwnerUtility.GetAnyParent<Pawn>(thing)}' ({thing.ParentHolder}) to '{pawn}' [biocoded]");
                                // transfer weapon
                                if (thing.holdingOwner.TryTransferToContainer(thing, pawn.inventory.innerContainer, 1) == 1)
                                {
                                    // remove weapon from missing weapons list and thing from unassigned things list
                                    missingWeapons.Remove(weaponMemory);
                                    biocodedToThisPawn.Remove(thing);
                                    goto CONTINUE;
                                }

                                // if it gets here, tranferring the weapon failed; this should obviously not happen
                                Log.Error($"Failed to transfer '{thing}' from '{ThingOwnerUtility.GetAnyParent<Pawn>(thing)}' ({thing.ParentHolder}) to '{pawn}'! [biocoded]");
                            }
                            j++;
                        }
                    }

                    // for each missing weapon, we check all things to find it
                    for (int j = 0; j < availableThings.Count;)
                    {
                        // get ThingDefStuffDefPair for thing
                        var thing       = availableThings[j];
                        var thingMemory = thing.toThingDefStuffDefPair();

                        // all things in this list should have a ThingDefStuffDefPair, remove it if it does not
                        if (thingMemory == null)
                        {
                            Log.Warning($"'{thing}' had null ThingDefStuffDefPair; removing from unassigned things");
                            availableThings.Remove(thing);
                            continue;
                        }

                        // check if thing fits weapon memory
                        if (weaponMemory.Equals(thingMemory))
                        {
                            //Log.Message($"Transferring '{thing}' from '{ThingOwnerUtility.GetAnyParent<Pawn>(thing)}' ({thing.ParentHolder}) to '{pawn}' [standard]");
                            // transfer weapon
                            if (thing.holdingOwner.TryTransferToContainer(thing, pawn.inventory.innerContainer, 1) == 1)
                            {
                                // remove weapon from missing weapons list and thing from unassigned things list
                                missingWeapons.Remove(weaponMemory);
                                availableThings.Remove(thing);
                                goto CONTINUE;
                            }

                            // if it gets here, tranferring the weapon failed; this should obviously not happen
                            Log.Error($"Failed to transfer '{thing}' from '{ThingOwnerUtility.GetAnyParent<Pawn>(thing)}' ({thing.ParentHolder}) to '{pawn}'! [standard]");
                        }
                        j++;
                    }
                    i++;

                    // if missing weapon was found go here without increasing the index
                    CONTINUE :;
                }
            }
        }