Esempio n. 1
0
        private float GetMass(Thing thing)
        {
            if (thing == null)
            {
                return(0f);
            }
            float num  = thing.GetStatValue(StatDefOf.Mass, true);
            Pawn  pawn = thing as Pawn;

            if (pawn != null)
            {
                if (InventoryCalculatorsUtility.ShouldIgnoreInventoryOf(pawn, this.ignorePawnInventoryMass))
                {
                    num -= MassUtility.InventoryMass(pawn);
                }
            }
            else if (this.ignoreSpawnedCorpseGearAndInventoryMass)
            {
                Corpse corpse = thing as Corpse;
                if (corpse != null && corpse.Spawned)
                {
                    num -= MassUtility.GearAndInventoryMass(corpse.InnerPawn);
                }
            }
            return(num);
        }
        public static float MassUsage(List <ThingCount> thingCounts, IgnorePawnsInventoryMode ignoreInventory, bool includePawnsMass = false, bool ignoreSpawnedCorpsesGearAndInventory = false)
        {
            float num = 0f;

            for (int i = 0; i < thingCounts.Count; i++)
            {
                int count = thingCounts[i].Count;
                if (count <= 0)
                {
                    continue;
                }
                Thing thing = thingCounts[i].Thing;
                Pawn  pawn  = thing as Pawn;
                if (pawn != null)
                {
                    num = ((!includePawnsMass) ? (num + MassUtility.GearAndInventoryMass(pawn) * (float)count) : (num + pawn.GetStatValue(StatDefOf.Mass) * (float)count));
                    if (InventoryCalculatorsUtility.ShouldIgnoreInventoryOf(pawn, ignoreInventory))
                    {
                        num -= MassUtility.InventoryMass(pawn) * (float)count;
                    }
                    continue;
                }
                num += thing.GetStatValue(StatDefOf.Mass) * (float)count;
                if (ignoreSpawnedCorpsesGearAndInventory)
                {
                    Corpse corpse = thing as Corpse;
                    if (corpse != null && corpse.Spawned)
                    {
                        num -= MassUtility.GearAndInventoryMass(corpse.InnerPawn) * (float)count;
                    }
                }
            }
            return(Mathf.Max(num, 0f));
        }
        public static float MassUsage(List <ThingStackPart> stackParts, IgnorePawnsInventoryMode ignoreInventory, bool includePawnsMass = false, bool ignoreCorpsesGearAndInventory = false)
        {
            float num = 0f;

            for (int i = 0; i < stackParts.Count; i++)
            {
                int count = stackParts[i].Count;
                if (count > 0)
                {
                    Thing thing = stackParts[i].Thing;
                    Pawn  pawn  = thing as Pawn;
                    if (pawn != null)
                    {
                        if (includePawnsMass)
                        {
                            num += pawn.GetStatValue(StatDefOf.Mass, true) * (float)count;
                        }
                        else
                        {
                            num += MassUtility.GearAndInventoryMass(pawn) * (float)count;
                        }
                        if (InventoryCalculatorsUtility.ShouldIgnoreInventoryOf(pawn, ignoreInventory))
                        {
                            num -= MassUtility.InventoryMass(pawn) * (float)count;
                        }
                    }
                    else
                    {
                        num += thing.GetStatValue(StatDefOf.Mass, true) * (float)count;
                        if (ignoreCorpsesGearAndInventory)
                        {
                            Corpse corpse = thing as Corpse;
                            if (corpse != null)
                            {
                                num -= MassUtility.GearAndInventoryMass(corpse.InnerPawn) * (float)count;
                            }
                        }
                    }
                }
            }
            return(Mathf.Max(num, 0f));
        }
Esempio n. 4
0
        private void DrawMass(Rect rect, TransferableOneWay trad, float availableMass)
        {
            if (!trad.HasAnyThing)
            {
                return;
            }
            Thing anyThing = trad.AnyThing;
            Pawn  pawn     = anyThing as Pawn;

            if (pawn != null && !this.includePawnsMassInMassUsage && !MassUtility.CanEverCarryAnything(pawn))
            {
                return;
            }
            Widgets.DrawHighlightIfMouseover(rect);
            if (pawn == null || this.includePawnsMassInMassUsage)
            {
                float mass = this.GetMass(anyThing);
                if (pawn != null)
                {
                    float gearMass = 0f;
                    float invMass  = 0f;
                    gearMass = MassUtility.GearMass(pawn);
                    if (!InventoryCalculatorsUtility.ShouldIgnoreInventoryOf(pawn, this.ignorePawnInventoryMass))
                    {
                        invMass = MassUtility.InventoryMass(pawn);
                    }
                    TooltipHandler.TipRegion(rect, () => this.GetPawnMassTip(trad, 0f, mass - gearMass - invMass, gearMass, invMass), trad.GetHashCode() * 59);
                }
                else
                {
                    TooltipHandler.TipRegion(rect, "ItemWeightTip".Translate());
                }
                if (mass > availableMass)
                {
                    GUI.color = Color.red;
                }
                else
                {
                    GUI.color = TransferableOneWayWidget.ItemMassColor;
                }
                Widgets.Label(rect, mass.ToStringMass());
            }
            else
            {
                float cap      = MassUtility.Capacity(pawn, null);
                float gearMass = MassUtility.GearMass(pawn);
                float invMass  = (!InventoryCalculatorsUtility.ShouldIgnoreInventoryOf(pawn, this.ignorePawnInventoryMass)) ? MassUtility.InventoryMass(pawn) : 0f;
                float num      = cap - gearMass - invMass;
                if (num > 0f)
                {
                    GUI.color = Color.green;
                }
                else if (num < 0f)
                {
                    GUI.color = Color.red;
                }
                else
                {
                    GUI.color = Color.gray;
                }
                Widgets.Label(rect, num.ToStringMassOffset());
                TooltipHandler.TipRegion(rect, () => this.GetPawnMassTip(trad, cap, 0f, gearMass, invMass), trad.GetHashCode() * 59);
            }
            GUI.color = Color.white;
        }