Esempio n. 1
0
        public static int GetWeaponDmg(Pawn pawn)
        {
            CompAbilityUserMight comp = pawn.GetComp <CompAbilityUserMight>();
            MightPowerSkill      pwr  = comp.MightData.MightPowerSkill_SeismicSlash.FirstOrDefault((MightPowerSkill x) => x.label == "TM_SeismicSlash_pwr");
            MightPowerSkill      ver  = comp.MightData.MightPowerSkill_SeismicSlash.FirstOrDefault((MightPowerSkill x) => x.label == "TM_SeismicSlash_ver");
            MightPowerSkill      str  = comp.MightData.MightPowerSkill_global_strength.FirstOrDefault((MightPowerSkill x) => x.label == "TM_global_strength_pwr");

            verVal = ver.level;
            pwrVal = pwr.level;
            if (pawn.story.traits.HasTrait(TorannMagicDefOf.Faceless))
            {
                MightPowerSkill mver = comp.MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_ver");
                MightPowerSkill mpwr = comp.MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_pwr");
                verVal = mver.level;
                pwrVal = mpwr.level;
            }
            int            dmgNum          = 0;
            ThingWithComps weaponComp      = pawn.equipment.Primary;
            float          weaponDPS       = weaponComp.GetStatValue(StatDefOf.MeleeWeapon_AverageDPS, false) * .7f;
            float          dmgMultiplier   = weaponComp.GetStatValue(StatDefOf.MeleeWeapon_DamageMultiplier, false);
            float          pawnDPS         = pawn.GetStatValue(StatDefOf.MeleeDPS, false);
            float          skillMultiplier = (.7f + (.07f * pwrVal) + (.025f * str.level));

            return(dmgNum = Mathf.RoundToInt(skillMultiplier * dmgMultiplier * (pawnDPS + weaponDPS)));
        }
Esempio n. 2
0
        public static void GetEquipmentStats(ThingWithComps eq, out float weight, out float bulk)
        {
            weight = eq.GetStatValue(StatDef.Named("Weight"));
            bulk   = eq.GetStatValue(StatDef.Named("Bulk"));
            CompAmmoUser comp = eq.TryGetComp <CompAmmoUser>();

            if (comp != null && comp.currentAmmo != null)
            {
                weight += comp.currentAmmo.GetStatValueAbstract(StatDef.Named("Weight")) * comp.curMagCount;
                bulk   += comp.currentAmmo.GetStatValueAbstract(StatDef.Named("Bulk")) * comp.curMagCount;
            }
        }
Esempio n. 3
0
        public static int GetWeaponDmg(Pawn pawn)
        {
            CompAbilityUserMight comp       = pawn.GetComp <CompAbilityUserMight>();
            MightPowerSkill      str        = comp.MightData.MightPowerSkill_global_strength.FirstOrDefault((MightPowerSkill x) => x.label == "TM_global_strength_pwr");
            ThingWithComps       weaponComp = pawn.equipment.Primary;
            float weaponDPS       = weaponComp.GetStatValue(StatDefOf.MeleeWeapon_AverageDPS, false) * .7f;
            float dmgMultiplier   = weaponComp.GetStatValue(StatDefOf.MeleeWeapon_DamageMultiplier, false);
            float pawnDPS         = pawn.GetStatValue(StatDefOf.MeleeDPS, false);
            float skillMultiplier = (.6f) * comp.mightPwr;

            return(Mathf.RoundToInt(skillMultiplier * dmgMultiplier * (pawnDPS + weaponDPS)));
        }
Esempio n. 4
0
        public static void GetEquipmentStats(ThingWithComps eq, out float weight, out float bulk)
        {
            weight = eq.GetStatValue(StatDefOf.Mass);
            //old     weight = eq.GetStatValue(CE_StatDefOf.Weight);
            bulk = eq.GetStatValue(CE_StatDefOf.Bulk);
            CompAmmoUser comp = eq.TryGetComp <CompAmmoUser>();

            if (comp != null && comp.CurrentAmmo != null)
            {
                weight += comp.CurrentAmmo.GetStatValueAbstract(StatDefOf.Mass) * comp.CurMagCount;
                //old     weight += comp.currentAmmo.GetStatValueAbstract(CE_StatDefOf.Weight) * comp.curMagCount;
                bulk += comp.CurrentAmmo.GetStatValueAbstract(CE_StatDefOf.Bulk) * comp.CurMagCount;
            }
        }
        private float GetEquipmentStat(ThingWithComps equipment, StatDef stat)
        {
            EquipmentStatKey key = new EquipmentStatKey(equipment);

            return(cachedStats.TryGetValue(key, out float value) ?
                   value : cachedStats[key] = equipment.GetStatValue(stat));
        }
 public static void Pop(CompReloadable comp)
 {
     if (comp != null && comp.CanBeUsed)
     {
         ThingWithComps parent = comp.parent;
         Pawn           wearer = comp.Wearer;
         GenExplosion.DoExplosion(wearer.Position, wearer.Map, parent.GetStatValue(StatDefOf.SmokepopBeltRadius), DamageDefOf.Smoke, null, -1, -1f, null, null, null, null, ThingDefOf.Gas_Smoke, 1f);
         comp.UsedOnce();
     }
 }
Esempio n. 7
0
        protected override bool TryCastShot()
        {
            if (this.CasterPawn.equipment.Primary != null && !this.CasterPawn.equipment.Primary.def.IsRangedWeapon)
            {
                CellRect cellRect = CellRect.CenteredOn(base.CasterPawn.Position, 1);
                Map      map      = base.CasterPawn.Map;
                cellRect.ClipInsideMap(map);

                IntVec3 centerCell        = cellRect.CenterCell;
                CompAbilityUserMight comp = this.CasterPawn.GetComp <CompAbilityUserMight>();
                pwr = comp.MightData.MightPowerSkill_BladeSpin.FirstOrDefault((MightPowerSkill x) => x.label == "TM_BladeSpin_pwr");
                ver = comp.MightData.MightPowerSkill_BladeSpin.FirstOrDefault((MightPowerSkill x) => x.label == "TM_BladeSpin_ver");
                str = comp.MightData.MightPowerSkill_global_strength.FirstOrDefault((MightPowerSkill x) => x.label == "TM_global_strength_pwr");

                weaponComp      = base.CasterPawn.equipment.Primary;
                weaponDPS       = weaponComp.GetStatValue(StatDefOf.MeleeWeapon_AverageDPS, false) * .7f;
                dmgMultiplier   = weaponComp.GetStatValue(StatDefOf.MeleeWeapon_DamageMultiplier, false);
                pawnDPS         = base.CasterPawn.GetStatValue(StatDefOf.MeleeDPS, false);
                skillMultiplier = (.6f + (.025f * str.level));
                dmgNum          = Mathf.RoundToInt(skillMultiplier * dmgMultiplier * (pawnDPS + weaponDPS));
                ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef();
                if (!this.CasterPawn.IsColonistPlayerControlled && settingsRef.AIHardMode)
                {
                    dmgNum += 10;
                }

                SearchForTargets(base.CasterPawn.Position, (2f + (float)(.5f * ver.level)), map);
            }
            else
            {
                Messages.Message("MustHaveMeleeWeapon".Translate(new object[]
                {
                    this.CasterPawn.LabelCap
                }), MessageTypeDefOf.RejectInput);
                return(false);
            }

            this.burstShotsLeft = 0;
            this.PostCastShot(flag10, out flag10);
            return(flag10);
        }
Esempio n. 8
0
        public static float RangedSpeed(ThingWithComps weapon)
        {
            Verb           atkVerb           = (weapon.GetComp <CompEquippable>()).PrimaryVerb;
            VerbProperties atkProps          = atkVerb.verbProps;
            float          warmup            = atkProps.warmupTime;
            float          cooldown          = weapon.GetStatValue(StatDefOf.RangedWeapon_Cooldown);
            int            burstShot         = atkProps.burstShotCount;
            int            ticksBetweenShots = atkProps.ticksBetweenBurstShots;
            float          speedFactor       = (((warmup + cooldown)) + (burstShot - 1) * (ticksBetweenShots / 60f));

            return(speedFactor);
        }
Esempio n. 9
0
        public static void EMP(CompReloadable comp)
        {
            if (comp == null || !comp.CanBeUsed)
            {
                return;
            }
            ThingWithComps parent = comp.parent;
            Pawn           wearer = comp.Wearer;

            GenExplosion.DoExplosion(wearer.Position, wearer.Map, parent.GetStatValue(AvaliDefs.ExplodeEMPRadius, true), DamageDefOf.EMP, (Thing)null, -1, -1f, (SoundDef)null, (ThingDef)null, (ThingDef)null, (Thing)null, (ThingDef)null, 0.0f, 1, false, (ThingDef)null, 0.0f, 1, 0.0f, false, new float?(), (List <Thing>)null);
            comp.UsedOnce();
        }
Esempio n. 10
0
        private void HandleMeatThatNeedsSalting(ThingWithComps meat)
        {
            var   count       = meat.stackCount;
            float curHP       = meat.HitPoints;
            var   curDefName  = meat.def.defName;
            var   curPosition = meat.PositionHeld;
            var   curMap      = meat.MapHeld;

            this.parent.Destroy(DestroyMode.Vanish);
            var newThing = (ThingWithComps)ThingMaker.MakeThing(ThingDef.Named(curDefName + "Salted"));

            newThing.stackCount = count;
            newThing.HitPoints  = Mathf.RoundToInt(curHP / meat.GetStatValue(StatDefOf.MaxHitPoints) * newThing.MaxHitPoints); // curHP;
            GenPlace.TryPlaceThing(newThing, curPosition, curMap, ThingPlaceMode.Direct);
        }
Esempio n. 11
0
        //far as I know, this all now works completely differently again. Yay.

        /*internal static float ReduceForArmorType(StatDef deflectionStat, Pawn target)
         * {
         *  float reduction = 1.0f;
         *  if (target != null)
         *  {
         *      BodyPartGroupDef bodyPartTest = BodyPartGroupDefOf.Torso;   //For statistical purposes, consider torso only
         *
         *      if (target.apparel != null && target.apparel.WornApparel != null)
         *      {
         *          foreach (Apparel apparel in target.apparel.WornApparel.Where(a => a.def.apparel.bodyPartGroups.Contains(bodyPartTest)))
         *          {
         *              reduction *= GetArmorTypeFactor(apparel.GetStatValue(deflectionStat, true));
         *          }
         *      }
         *
         *      reduction *= GetArmorTypeFactor(target.GetStatValue(deflectionStat, true));
         *  }
         *  return reduction;
         * }
         *
         * internal static float GetArmorTypeFactor(float armorRating)
         * {
         *  // Word from Tynan himself, praise be unto he
         *  // https://www.reddit.com/r/RimWorld/comments/2q542f/alpha_eight_armor_changes/
         *
         *   //One armor value.
         *   //Up to 50%, damage resistance increases.
         *   //Past 50%, damage deflection increases.
         *   //Past 100%, damage deflection and resistance both increase at 1/4 rate up to a maximum of 90% and 90%.
         *
         *  float resistance;
         *  float deflectChance;
         *
         *  if (armorRating <= 0.50)
         *  {
         *      resistance = armorRating;
         *      deflectChance = 0;
         *  }
         *  else if (armorRating < 1.0f)
         *  {
         *      resistance = 0.5f;
         *      deflectChance = armorRating - 0.5f;
         *  }
         *  else
         *  {
         *      resistance = 0.5f + (armorRating - 1f) * 0.25f;
         *      deflectChance = 0.5f + (armorRating - 1f) * 0.25f;
         *  }
         *
         *  if (resistance > 0.9f)
         *      resistance = 0.9f;
         *  if (deflectChance > 0.9f)
         *      deflectChance = 0.9f;
         *
         *  // Game code computes deflect or resist, we're looking for just the statistical average:
         *  return (1.0f - resistance) * (1.0f - deflectChance);
         * }*/

        internal static float MeleeDPS(Pawn pawn, ThingWithComps weapon, float speedBias, Pawn target)
        {
            if (pawn == null)
            {
                Log.Warning("attempted to calc meleeDPS for null pawn!");
                return(0);
            }
            float dps;

            if (weapon == null)
            {
                dps = pawn.GetStatValue(StatDefOf.MeleeDPS);
            }
            else
            {
                dps = weapon.GetStatValue(StatDefOf.MeleeWeapon_AverageDPS);
            }
            //float dps = GetMeleeDamage(pawn, weapon, target) * GetMeleeHitChance(pawn) / GetMeleeCooldown(pawn, weapon);
            return(dps);
        }
Esempio n. 12
0
        public void Draw(Rect rect, ThingWithComps ownerPawn)
        {
            Text.Font = GameFont.Small;
            string value = "-";

            switch (oType)
            {
                case objectType.Stat:
                    Text.Anchor = TextAnchor.MiddleCenter;
                    StatDef stat = (StatDef)displayObject;
                    string statValue = (stat.ValueToString(ownerPawn.GetStatValue((StatDef)displayObject, true)));
                    Widgets.Label(rect, statValue);
                    if (Mouse.IsOver(rect))
                    {
                        GUI.DrawTexture(rect, TexUI.HighlightTex);
                    }

                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine(stat.LabelCap);
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine(stat.description);                
                    TooltipHandler.TipRegion(rect, new TipSignal(stringBuilder.ToString(), rect.GetHashCode()));
                    break;    

                case objectType.Skill:
                    if ((ownerPawn is Pawn) && (ownerPawn as Pawn).RaceProps.Humanlike) DrawSkill(rect, ownerPawn as Pawn);
                    break;

                case objectType.Need:
                    if (ownerPawn is Pawn) DrawNeed(rect, ownerPawn as Pawn);
                    break;

                case objectType.Age:
                    Text.Anchor = TextAnchor.MiddleCenter;
                    string ageValue = ((ownerPawn as Pawn).ageTracker.AgeBiologicalYears.ToString());
                    Widgets.Label(rect, ageValue);
                    if (Mouse.IsOver(rect))
                    {
                        GUI.DrawTexture(rect, TexUI.HighlightTex);
                    }
                    break;

                case objectType.Gear:
                    DrawGear(rect, ownerPawn);
                    break;

                case objectType.ControlPrisonerGetsFood:
                    if (ownerPawn is Pawn)
                    {
                        if (Mouse.IsOver(rect))
                        {
                            GUI.DrawTexture(rect, TexUI.HighlightTex);
                        }
                        bool getsFood = (ownerPawn as Pawn).guest.GetsFood;
                        Widgets.CheckboxLabeled(new Rect(rect.x + 8f, rect.y + 3f, 27f, 27f), "", ref getsFood, false);
                        (ownerPawn as Pawn).guest.GetsFood = getsFood;
                    }
                    break;

                case objectType.ControlPrisonerInteraction:
                    if (ownerPawn is Pawn)
                    {
                        if (Mouse.IsOver(rect))
                        {
                            GUI.DrawTexture(rect, TexUI.HighlightTex);
                        }
                        float x = 8f;

                        GUI.BeginGroup(rect);
                        IEnumerator enumerator = Enum.GetValues(typeof(PrisonerInteractionMode)).GetEnumerator();
                        try
                        {
                            while (enumerator.MoveNext())
                            {
                                PrisonerInteractionMode prisonerInteractionMode = (PrisonerInteractionMode)((byte)enumerator.Current);
                                if (Widgets.RadioButton(new Vector2(x, 3f), (ownerPawn as Pawn).guest.interactionMode == prisonerInteractionMode))
                                {
                                    (ownerPawn as Pawn).guest.interactionMode = prisonerInteractionMode;
                                }
                                TooltipHandler.TipRegion(new Rect(x, 0f, 30f, 30f), new TipSignal(prisonerInteractionMode.GetLabel()));
                                x += 30f;
                            }
                        }
                        finally
                        {
                            IDisposable disposable = enumerator as IDisposable;
                            if (disposable != null)
                            {
                                disposable.Dispose();
                            }
                        }
                        GUI.EndGroup();
                    }
                    break;

                case objectType.ControlMedicalCare:
                    if (ownerPawn is Pawn) MedicalCareSetter(rect, ref (ownerPawn as Pawn).playerSettings.medCare);
                    break;

                case objectType.AnimalMilkFullness:
                    Text.Anchor = TextAnchor.MiddleCenter;
                    if (ownerPawn is Pawn && ((Pawn)ownerPawn).ageTracker.CurLifeStage.milkable)
                    {
                        var comp = ((Pawn)ownerPawn).AllComps.Where<ThingComp>(x => x is CompMilkable).FirstOrDefault();
                        if(comp != null)
                        value = ((CompMilkable)comp).Fullness.ToStringPercent();
                    }

                    Widgets.Label(rect, value);
                    break;

                case objectType.AnimalWoolGrowth:
                    Text.Anchor = TextAnchor.MiddleCenter;
                    if (ownerPawn is Pawn && ((Pawn)ownerPawn).ageTracker.CurLifeStage.shearable)
                    {
                        var comp = ((Pawn)ownerPawn).AllComps.Where<ThingComp>(x => x is CompShearable).FirstOrDefault();
                        if (comp != null)
                            value = ((CompShearable)comp).Fullness.ToStringPercent();
                    }

                    Widgets.Label(rect, value);
                    break;

                case objectType.CurrentJob:
                    if(ownerPawn is Pawn)
                    {
                        string text = ((Pawn)ownerPawn).jobs.curDriver.GetReport();
                        Text.Anchor = TextAnchor.MiddleLeft;
                        Rect tRect = new Rect(rect.xMin + 2, rect.yMin + 3, rect.width - 2, rect.height);
                        GenText.SetTextSizeToFit(text, tRect);

                        if (Text.Font == GameFont.Tiny)
                            Widgets.Label(tRect, text);
                        else
                        {
                            Rect sRect = new Rect(rect.xMin + 2, rect.yMin, rect.width - 2, rect.height);
                            Widgets.Label(sRect, text);
                        }

                        if (Mouse.IsOver(rect))
                        {
                            GUI.DrawTexture(rect, TexUI.HighlightTex);
                        }
                    }
                    break;
            }


        }
Esempio n. 13
0
        protected override bool TryCastShot()
        {
            bool flag10 = false;

            this.TargetsAoE.Clear();
            this.UpdateTargets();
            int  shotsPerBurst = this.ShotsPerBurst;
            bool flag2         = this.UseAbilityProps.AbilityTargetCategory != AbilityTargetCategory.TargetAoE && this.TargetsAoE.Count > 1;

            if (flag2)
            {
                this.TargetsAoE.RemoveRange(0, this.TargetsAoE.Count - 1);
            }
            for (int i = 0; i < this.TargetsAoE.Count; i++)
            {
                bool?flag3    = this.TryLaunchProjectile(this.verbProps.defaultProjectile, this.TargetsAoE[i]);
                bool hasValue = flag3.HasValue;
                if (hasValue)
                {
                    bool flag4 = flag3 == true;
                    if (flag4)
                    {
                        flag10 = true;
                    }
                    bool flag5 = flag3 == false;
                    if (flag5)
                    {
                        flag10 = false;
                    }
                }
            }

            CellRect cellRect = CellRect.CenteredOn(base.CasterPawn.Position, 1);
            Map      map      = base.CasterPawn.Map;

            cellRect.ClipInsideMap(map);

            IntVec3 centerCell        = cellRect.CenterCell;
            CompAbilityUserMight comp = this.CasterPawn.GetComp <CompAbilityUserMight>();

            pwr = comp.MightData.MightPowerSkill_Cleave.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Cleave_pwr");
            str = comp.MightData.MightPowerSkill_global_strength.FirstOrDefault((MightPowerSkill x) => x.label == "TM_global_strength_pwr");
            ver = comp.MightData.MightPowerSkill_Cleave.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Cleave_ver");
            int dmgNum = 0;

            if (this.CasterPawn.equipment.Primary != null && !this.CasterPawn.equipment.Primary.def.IsRangedWeapon)
            {
                weaponComp      = base.CasterPawn.equipment.Primary;
                weaponDPS       = weaponComp.GetStatValue(StatDefOf.MeleeWeapon_AverageDPS, false) * .7f;
                dmgMultiplier   = weaponComp.GetStatValue(StatDefOf.MeleeWeapon_DamageMultiplier, false);
                pawnDPS         = base.CasterPawn.GetStatValue(StatDefOf.MeleeDPS, false);
                skillMultiplier = (1.2f + (.025f * str.level));
                dmgNum          = Mathf.RoundToInt(skillMultiplier * dmgMultiplier * (pawnDPS + weaponDPS));
                ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef();
                if (!this.CasterPawn.IsColonist && settingsRef.AIHardMode)
                {
                    dmgNum += 10;
                }
            }
            else
            {
                dmgNum = 4;
            }

            for (int i = 0; i < 8; i++)
            {
                IntVec3 searchCell = base.CasterPawn.Position + GenAdj.AdjacentCells8WayRandomized()[i];
                Pawn    victim     = searchCell.GetFirstPawn(map);
                if (victim != null && base.CasterPawn != null & dmgNum != 0 && victim.Faction != base.CasterPawn.Faction)
                {
                    dinfo = new DamageInfo(TMDamageDefOf.DamageDefOf.TM_Cleave, dmgNum, 0, (float)-1, this.CasterPawn, null, null, DamageInfo.SourceCategory.ThingOrUnknown);
                    ApplyCleaveDamage(dinfo, this.CasterPawn, victim, map, ver.level);
                    DrawCleaving(victim, base.CasterPawn, 10);
                    i = 8;
                }
            }

            this.burstShotsLeft = 0;
            this.PostCastShot(flag10, out flag10);
            return(flag10);
        }
Esempio n. 14
0
        public void Draw(Rect rect, ThingWithComps ownerPawn)
        {
            Text.Font = GameFont.Small;
            string value = "-";

            switch (oType)
            {
            case ObjectType.Stat:
                Text.Anchor = TextAnchor.MiddleCenter;
                StatDef stat = (StatDef)displayObject;
                stat.neverDisabled = true;
                string statValue = (stat.ValueToString(ownerPawn.GetStatValue((StatDef)displayObject, true)));
                Widgets.Label(rect, statValue);
                if (Mouse.IsOver(rect))
                {
                    GUI.DrawTexture(rect, TexUI.HighlightTex);
                }

                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.AppendLine(stat.LabelCap);
                stringBuilder.AppendLine();
                stringBuilder.AppendLine(stat.description);
                TooltipHandler.TipRegion(rect, new TipSignal(stringBuilder.ToString(), rect.GetHashCode()));
                break;

            case ObjectType.Skill:
                if ((ownerPawn is Pawn) && (ownerPawn as Pawn).RaceProps.Humanlike)
                {
                    DrawSkill(rect, ownerPawn as Pawn);
                }
                break;

            case ObjectType.Need:
                if (ownerPawn is Pawn)
                {
                    DrawNeed(rect, ownerPawn as Pawn);
                }
                break;

            case ObjectType.Capacity:
                Text.Anchor = TextAnchor.MiddleCenter;
                if (ownerPawn is Pawn p)
                {
                    PawnCapacityDef cap = (PawnCapacityDef)displayObject;

                    Pair <string, Color> effLabel = HealthCardUtility.GetEfficiencyLabel(p, cap);
                    string pawnCapTip             = HealthCardUtility.GetPawnCapacityTip(p, cap);

                    // I stole this one line from Fluffy's Medical Tab. THANKS FLUFFY!
                    string capValue = (p.health.capacities.GetLevel(cap) * 100f).ToString("F0") + "%";
                    GUI.color = effLabel.Second;
                    Widgets.Label(rect, capValue);
                    GUI.color = Color.white;

                    if (Mouse.IsOver(rect))
                    {
                        GUI.DrawTexture(rect, TexUI.HighlightTex);
                    }

                    StringBuilder stringBuilder2 = new StringBuilder();
                    stringBuilder2.AppendLine(cap.LabelCap);
                    stringBuilder2.AppendLine();
                    stringBuilder2.AppendLine(cap.description);
                    TooltipHandler.TipRegion(rect, new TipSignal(stringBuilder2.ToString(), rect.GetHashCode()));
                }
                break;

            case ObjectType.Record:
                Text.Anchor = TextAnchor.MiddleCenter;
                if (ownerPawn is Pawn pawn)
                {
                    RecordDef recordDef = (RecordDef)displayObject;
                    string    recordValue;

                    if (recordDef.type == RecordType.Time)
                    {
                        recordValue = pawn.records.GetAsInt(recordDef).ToStringTicksToPeriod();
                    }
                    else
                    {
                        recordValue = pawn.records.GetValue(recordDef).ToString("0.##");
                    }

                    Widgets.Label(rect, recordValue);

                    if (Mouse.IsOver(rect))
                    {
                        GUI.DrawTexture(rect, TexUI.HighlightTex);
                    }

                    StringBuilder recordDefStringBuilder = new StringBuilder();
                    recordDefStringBuilder.AppendLine(recordDef.LabelCap);
                    recordDefStringBuilder.AppendLine();
                    recordDefStringBuilder.AppendLine(recordDef.description);
                    TooltipHandler.TipRegion(rect, new TipSignal(recordDefStringBuilder.ToString(), rect.GetHashCode()));
                }
                break;

            case ObjectType.MentalState:
                Text.Font   = GameFont.Tiny;
                Text.Anchor = TextAnchor.MiddleCenter;
                if (ownerPawn is Pawn && (ownerPawn as Pawn).MentalState != null)
                {
                    string ms = ((ownerPawn as Pawn).MentalState.InspectLine);
                    Widgets.Label(rect, ms);
                    if (Mouse.IsOver(rect))
                    {
                        GUI.DrawTexture(rect, TexUI.HighlightTex);
                    }
                }
                Text.Font = GameFont.Medium;
                break;

            case ObjectType.Age:
                Text.Anchor = TextAnchor.MiddleCenter;
                string ageValue = ((ownerPawn as Pawn).ageTracker.AgeBiologicalYears.ToString());
                Widgets.Label(rect, ageValue);
                if (Mouse.IsOver(rect))
                {
                    GUI.DrawTexture(rect, TexUI.HighlightTex);
                }
                break;

            case ObjectType.Race:
                Text.Anchor = TextAnchor.MiddleCenter;
                string race = ((ownerPawn as Pawn).kindDef.race.LabelCap) ?? string.Empty;
                Widgets.Label(rect, race);
                if (Mouse.IsOver(rect))
                {
                    GUI.DrawTexture(rect, TexUI.HighlightTex);
                }
                break;

            case ObjectType.Gear:
                DrawGear(rect, ownerPawn);
                break;

            case ObjectType.ControlPrisonerGetsFood:
                if (ownerPawn is Pawn)
                {
                    if (Mouse.IsOver(rect))
                    {
                        GUI.DrawTexture(rect, TexUI.HighlightTex);
                    }
                    bool getsFood = (ownerPawn as Pawn).guest.GetsFood;
                    Widgets.CheckboxLabeled(new Rect(rect.x + 8f, rect.y + 3f, 27f, 27f), "", ref getsFood, false);
                    (ownerPawn as Pawn).guest.GetsFood = getsFood;
                }
                break;

            case ObjectType.ControlPrisonerInteraction:
                if (ownerPawn is Pawn)
                {
                    if (Mouse.IsOver(rect))
                    {
                        GUI.DrawTexture(rect, TexUI.HighlightTex);
                    }
                    float x = 8f;

                    GUI.BeginGroup(rect);
                    foreach (PrisonerInteractionModeDef current in from prisonerinteractionmode in DefDatabase <PrisonerInteractionModeDef> .AllDefs
                             orderby prisonerinteractionmode.listOrder
                             select prisonerinteractionmode)
                    {
                        if (Widgets.RadioButton(new Vector2(x, 3f), (ownerPawn as Pawn).guest.interactionMode == current))
                        {
                            (ownerPawn as Pawn).guest.interactionMode = current;
                        }
                        TooltipHandler.TipRegion(new Rect(x, 0f, 30f, 30f), new TipSignal(current.LabelCap));
                        x += 30f;
                    }
                    GUI.EndGroup();
                }
                break;

            case ObjectType.PrisonerRecruitmentDifficulty:
                Text.Anchor = TextAnchor.MiddleCenter;
                if (ownerPawn is Pawn)
                {
                    value = (ownerPawn as Pawn).RecruitDifficulty(Faction.OfPlayer, false).ToStringPercent();
                }
                Widgets.Label(rect, value);
                break;

            case ObjectType.ControlMedicalCare:
                if (ownerPawn is Pawn)
                {
                    MedicalCareSetter(rect, ref (ownerPawn as Pawn).playerSettings.medCare);
                }
                break;

            case ObjectType.AnimalMilkFullness:
                Text.Anchor = TextAnchor.MiddleCenter;
                if (ownerPawn is Pawn && ((Pawn)ownerPawn).ageTracker.CurLifeStage.milkable)
                {
                    var comp = ((Pawn)ownerPawn).AllComps.Where <ThingComp>(x => x is CompMilkable).FirstOrDefault();
                    if (comp != null)
                    {
                        value = ((CompMilkable)comp).Fullness.ToStringPercent();
                    }
                }

                Widgets.Label(rect, value);
                break;

            case ObjectType.AnimalWoolGrowth:
                Text.Anchor = TextAnchor.MiddleCenter;
                if (ownerPawn is Pawn && ((Pawn)ownerPawn).ageTracker.CurLifeStage.shearable)
                {
                    var comp = ((Pawn)ownerPawn).AllComps.Where <ThingComp>(x => x is CompShearable).FirstOrDefault();
                    if (comp != null)
                    {
                        value = ((CompShearable)comp).Fullness.ToStringPercent();
                    }
                }

                Widgets.Label(rect, value);
                break;

            case ObjectType.AnimalEggProgress:
                Text.Anchor = TextAnchor.MiddleCenter;
                if (ownerPawn is Pawn && ((Pawn)ownerPawn).ageTracker.CurLifeStage.reproductive)
                {
                    var comp = ((Pawn)ownerPawn).AllComps.Where <ThingComp>(x => x is CompEggLayer).FirstOrDefault();
                    if (comp != null)
                    {
                        value = ((CompEggLayer)comp).CompInspectStringExtra();
                    }
                }

                Widgets.Label(rect, value);
                break;

            case ObjectType.CurrentJob:
                if (ownerPawn is Pawn && ((Pawn)ownerPawn).jobs?.curDriver != null)
                {
                    string text = ((Pawn)ownerPawn).jobs.curDriver.GetReport();
                    Text.Anchor = TextAnchor.MiddleLeft;
                    Rect tRect = new Rect(rect.xMin + 2, rect.yMin + 3, rect.width - 2, rect.height);
                    GenText.SetTextSizeToFit(text, tRect);

                    if (Text.Font == GameFont.Tiny)
                    {
                        Widgets.Label(tRect, text);
                    }
                    else
                    {
                        Rect sRect = new Rect(rect.xMin + 2, rect.yMin, rect.width - 2, rect.height);
                        Widgets.Label(sRect, text);
                    }

                    if (Mouse.IsOver(rect))
                    {
                        GUI.DrawTexture(rect, TexUI.HighlightTex);
                    }
                }

                break;

            case ObjectType.QueuedJob:
                if (ownerPawn is Pawn && ((Pawn)ownerPawn).jobs?.jobQueue.Count > 0)
                {
                    string text = ((Pawn)ownerPawn).jobs.jobQueue[0].job.GetReport((Pawn)ownerPawn);
                    Text.Anchor = TextAnchor.MiddleLeft;
                    Rect tRect = new Rect(rect.xMin + 2, rect.yMin + 3, rect.width - 2, rect.height);
                    GenText.SetTextSizeToFit(text, tRect);

                    if (Text.Font == GameFont.Tiny)
                    {
                        Widgets.Label(tRect, text);
                    }
                    else
                    {
                        Rect sRect = new Rect(rect.xMin + 2, rect.yMin, rect.width - 2, rect.height);
                        Widgets.Label(sRect, text);
                    }

                    if (Mouse.IsOver(rect))
                    {
                        GUI.DrawTexture(rect, TexUI.HighlightTex);
                    }
                }
                break;
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Determines the armor penetration value of a given dinfo. Attempts to extract the tool/verb from the damage info.
        /// </summary>
        /// <param name="dinfo">DamageInfo to determine penetration for</param>
        /// <returns>Armor penetration value for attack used, 0 if it can't be determined</returns>
        private static float GetPenetrationValue(DamageInfo dinfo)
        {
            if (dinfo.Def.isExplosive)
            {
                return(dinfo.Amount * 0.1f); // Explosions have 10% of their damage as penetration
            }

            if (dinfo.Weapon != null)
            {
                // Case 1: projectile attack
                ProjectilePropertiesCE projectileProps = dinfo.Weapon.projectile as ProjectilePropertiesCE;
                if (projectileProps != null)
                {
                    return(projectileProps.armorPenetration);
                }

                // Case 2: melee attack
                Pawn instigatorPawn = dinfo.Instigator as Pawn;
                if (instigatorPawn != null)
                {
                    // Case 2.1: .. of an equiped melee weapon
                    if (dinfo.Weapon.IsMeleeWeapon)
                    {
                        ThingWithComps equipment = instigatorPawn.equipment?.Primary;

                        if (equipment == null || equipment.def != dinfo.Weapon)
                        {
                            Log.Error("CE tried getting armor penetration from melee weapon " + dinfo.Weapon.defName + " but instigator " + dinfo.Instigator.ToString() + " equipment does not match");
                            return(0);
                        }
                        var penetrationMult = equipment.GetStatValue(CE_StatDefOf.MeleePenetrationFactor);
                        var tool            = equipment.def.tools.OfType <ToolCE>().GetUsedTool(dinfo);

                        return(tool.armorPenetration * penetrationMult);
                    }

                    // Case 2.2: .. of a ranged weapon
                    if (dinfo.Weapon.IsRangedWeapon)
                    {
                        var tool = dinfo.Weapon.tools.OfType <ToolCE>().GetUsedTool(dinfo);
                        return(tool.armorPenetration);
                    }

                    // Case 2.3: .. of the pawn
                    if (instigatorPawn.def == dinfo.Weapon)
                    {
                        Verb availableVerb = instigatorPawn.meleeVerbs.TryGetMeleeVerb();

                        // Case 2.3.1: .. of a weaponized hediff (power claw, scyther blade)
                        HediffCompProperties_VerbGiver compProps = dinfo.WeaponLinkedHediff?.CompPropsFor(typeof(HediffComp_VerbGiver)) as HediffCompProperties_VerbGiver;
                        if (compProps != null)
                        {
                            var tool = compProps.tools.OfType <ToolCE>().GetUsedTool(dinfo);

                            if (tool != null)
                            {
                                return(tool.armorPenetration);
                            }

                            VerbPropertiesCE verbProps = compProps.verbs?.FirstOrDefault(v => v is VerbPropertiesCE) as VerbPropertiesCE;

                            var verbs = compProps.verbs;

                            if (verbs.Count() > 1)
                            {
                                Log.ErrorOnce("CE :: HediffCompProperties_VerbGiver for " + dinfo.WeaponLinkedHediff + " has multiple VerbPropertiesCE. [While evaluating DamageInfo " + dinfo.ToString() + "]", dinfo.WeaponLinkedHediff.GetHashCode() + 128937921);
                            }

                            if (verbProps != null)
                            {
                                Log.ErrorOnce("CE :: HediffCompProperties_VerbGiver from DamageInfo " + dinfo.ToString() + " has VerbPropertiesCE, but these should be moved to <tools> for B18", dinfo.WeaponLinkedHediff.GetHashCode() + 128937921);

                                return(verbProps.meleeArmorPenetration);
                            }
                        }

                        // AllVerbs: bodyparts of the pawn
                        // meleeVerbs: all verbs considered "melee worthy"

                        // Case 2.4: .. of a tool naturally on the body (hands/fist, head)
                        if (instigatorPawn.verbTracker != null &&
                            !instigatorPawn.verbTracker.AllVerbs.NullOrEmpty())
                        {
                            var verbs = instigatorPawn.verbTracker.AllVerbs.Where(v => v.tool is ToolCE && v.tool.linkedBodyPartsGroup == dinfo.WeaponBodyPartGroup);

                            if (verbs.Count() > 1)
                            {
                                Log.ErrorOnce("CE :: Race " + instigatorPawn.def + " has multiple ToolCE with linkedBodyPartsGroup=" + dinfo.WeaponBodyPartGroup.ToString() + " which can not be distunguished between. Consider using different linkedBodyPartsGroups. [While evaluating DamageInfo " + dinfo.ToString() + "]", instigatorPawn.def.GetHashCode() + 128937921);
                            }

                            if (!verbs.Any())
                            {
                                Log.ErrorOnce("CE :: Pawn " + instigatorPawn.ToString() + " for BodyPartGroup " + dinfo.WeaponBodyPartGroup.ToString() + " could not find matching verb (in AllVerbs: " + String.Join(",", instigatorPawn.verbTracker.AllVerbs.Select(x => x.ToString()).ToArray()) + ") [While evaluating DamageInfo " + dinfo.ToString() + "]", instigatorPawn.def.GetHashCode() + 128937921);
                                return(0);
                            }

                            return((verbs.First().tool as ToolCE).armorPenetration);
                        }
                    }
                }
            }
#if DEBUG
            Log.Warning("CE could not determine armor penetration, defaulting");
#endif
            return(9999);    // Really high default value so vanilla damage sources such as GiveInjuriesToKill always penetrate
        }
Esempio n. 16
0
        public void Draw(Rect rect, ThingWithComps ownerPawn)
        {
            Text.Font = GameFont.Small;
            string value = "-";

            switch (oType)
            {
            case objectType.Stat:
                Text.Anchor = TextAnchor.MiddleCenter;
                StatDef stat = (StatDef)displayObject;
                stat.neverDisabled = true;
                string statValue = (stat.ValueToString(ownerPawn.GetStatValue((StatDef)displayObject, true)));
                Widgets.Label(rect, statValue);
                if (Mouse.IsOver(rect))
                {
                    GUI.DrawTexture(rect, TexUI.HighlightTex);
                }

                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.AppendLine(stat.LabelCap);
                stringBuilder.AppendLine();
                stringBuilder.AppendLine(stat.description);
                TooltipHandler.TipRegion(rect, new TipSignal(stringBuilder.ToString(), rect.GetHashCode()));
                break;

            case objectType.Skill:
                if ((ownerPawn is Pawn) && (ownerPawn as Pawn).RaceProps.Humanlike)
                {
                    DrawSkill(rect, ownerPawn as Pawn);
                }
                break;

            case objectType.Need:
                if (ownerPawn is Pawn)
                {
                    DrawNeed(rect, ownerPawn as Pawn);
                }
                break;

            case objectType.Capacity:
                Text.Anchor = TextAnchor.MiddleCenter;
                if (ownerPawn is Pawn)
                {
                    Pawn            p   = (Pawn)ownerPawn;
                    PawnCapacityDef cap = (PawnCapacityDef)displayObject;

                    Pair <string, Color> effLabel = HealthCardUtility.GetEfficiencyLabel(p, cap);
                    string pawnCapTip             = HealthCardUtility.GetPawnCapacityTip(p, cap);


                    // I stole this one line from Fluffy's Medical Tab. THANKS FLUFFY!
                    string capValue = (p.health.capacities.GetLevel(cap) * 100f).ToString("F0") + "%";
                    GUI.color = effLabel.Second;
                    Widgets.Label(rect, capValue);
                    GUI.color = Color.white;

                    if (Mouse.IsOver(rect))
                    {
                        GUI.DrawTexture(rect, TexUI.HighlightTex);
                    }

                    StringBuilder stringBuilder2 = new StringBuilder();
                    stringBuilder2.AppendLine(cap.LabelCap);
                    stringBuilder2.AppendLine();
                    stringBuilder2.AppendLine(cap.description);
                    TooltipHandler.TipRegion(rect, new TipSignal(stringBuilder2.ToString(), rect.GetHashCode()));
                }
                break;

            case objectType.MentalState:
                Text.Font   = GameFont.Tiny;
                Text.Anchor = TextAnchor.MiddleCenter;
                if (ownerPawn is Pawn && (ownerPawn as Pawn).MentalState != null)
                {
                    string ms = ((ownerPawn as Pawn).MentalState.InspectLine);
                    Widgets.Label(rect, ms);
                    if (Mouse.IsOver(rect))
                    {
                        GUI.DrawTexture(rect, TexUI.HighlightTex);
                    }
                }
                Text.Font = GameFont.Medium;
                break;

            case objectType.Age:
                Text.Anchor = TextAnchor.MiddleCenter;
                string ageValue = ((ownerPawn as Pawn).ageTracker.AgeBiologicalYears.ToString());
                Widgets.Label(rect, ageValue);
                if (Mouse.IsOver(rect))
                {
                    GUI.DrawTexture(rect, TexUI.HighlightTex);
                }
                break;

            case objectType.Gear:
                DrawGear(rect, ownerPawn);
                break;

            case objectType.ControlPrisonerGetsFood:
                if (ownerPawn is Pawn)
                {
                    if (Mouse.IsOver(rect))
                    {
                        GUI.DrawTexture(rect, TexUI.HighlightTex);
                    }
                    bool getsFood = (ownerPawn as Pawn).guest.GetsFood;
                    Widgets.CheckboxLabeled(new Rect(rect.x + 8f, rect.y + 3f, 27f, 27f), "", ref getsFood, false);
                    (ownerPawn as Pawn).guest.GetsFood = getsFood;
                }
                break;

            case objectType.ControlPrisonerInteraction:
                if (ownerPawn is Pawn)
                {
                    if (Mouse.IsOver(rect))
                    {
                        GUI.DrawTexture(rect, TexUI.HighlightTex);
                    }
                    float x = 8f;

                    GUI.BeginGroup(rect);
                    IEnumerator enumerator = Enum.GetValues(typeof(PrisonerInteractionModeDef)).GetEnumerator();
                    try
                    {
                        while (enumerator.MoveNext())
                        {
                            PrisonerInteractionModeDef prisonerInteractionMode = (PrisonerInteractionModeDef)(enumerator.Current);
                            if (Widgets.RadioButton(new Vector2(x, 3f), (ownerPawn as Pawn).guest.interactionMode == prisonerInteractionMode))
                            {
                                (ownerPawn as Pawn).guest.interactionMode = prisonerInteractionMode;
                            }
                            TooltipHandler.TipRegion(new Rect(x, 0f, 30f, 30f), new TipSignal(prisonerInteractionMode.label));
                            x += 30f;
                        }
                    }
                    finally
                    {
                        IDisposable disposable = enumerator as IDisposable;
                        if (disposable != null)
                        {
                            disposable.Dispose();
                        }
                    }
                    GUI.EndGroup();
                }
                break;

            case objectType.ControlMedicalCare:
                if (ownerPawn is Pawn)
                {
                    MedicalCareSetter(rect, ref (ownerPawn as Pawn).playerSettings.medCare);
                }
                break;

            case objectType.AnimalMilkFullness:
                Text.Anchor = TextAnchor.MiddleCenter;
                if (ownerPawn is Pawn && ((Pawn)ownerPawn).ageTracker.CurLifeStage.milkable)
                {
                    var comp = ((Pawn)ownerPawn).AllComps.Where <ThingComp>(x => x is CompMilkable).FirstOrDefault();
                    if (comp != null)
                    {
                        value = ((CompMilkable)comp).Fullness.ToStringPercent();
                    }
                }

                Widgets.Label(rect, value);
                break;

            case objectType.AnimalWoolGrowth:
                Text.Anchor = TextAnchor.MiddleCenter;
                if (ownerPawn is Pawn && ((Pawn)ownerPawn).ageTracker.CurLifeStage.shearable)
                {
                    var comp = ((Pawn)ownerPawn).AllComps.Where <ThingComp>(x => x is CompShearable).FirstOrDefault();
                    if (comp != null)
                    {
                        value = ((CompShearable)comp).Fullness.ToStringPercent();
                    }
                }

                Widgets.Label(rect, value);
                break;

            case objectType.CurrentJob:
                if (ownerPawn is Pawn && ((Pawn)ownerPawn).jobs.curDriver != null)
                {
                    string text = ((Pawn)ownerPawn).jobs.curDriver.GetReport();
                    Text.Anchor = TextAnchor.MiddleLeft;
                    Rect tRect = new Rect(rect.xMin + 2, rect.yMin + 3, rect.width - 2, rect.height);
                    GenText.SetTextSizeToFit(text, tRect);

                    if (Text.Font == GameFont.Tiny)
                    {
                        Widgets.Label(tRect, text);
                    }
                    else
                    {
                        Rect sRect = new Rect(rect.xMin + 2, rect.yMin, rect.width - 2, rect.height);
                        Widgets.Label(sRect, text);
                    }

                    if (Mouse.IsOver(rect))
                    {
                        GUI.DrawTexture(rect, TexUI.HighlightTex);
                    }
                }
                break;
            }
        }
Esempio n. 17
0
        public void Draw(Rect rect, ThingWithComps ownerPawn)
        {
            Text.Font = GameFont.Small;
            string value = "-";

            switch (oType)
            {
            case objectType.Stat:
                Text.Anchor = TextAnchor.MiddleCenter;
                StatDef stat      = (StatDef)displayObject;
                string  statValue = (stat.ValueToString(ownerPawn.GetStatValue((StatDef)displayObject, true)));
                Widgets.Label(rect, statValue);
                if (Mouse.IsOver(rect))
                {
                    GUI.DrawTexture(rect, TexUI.HighlightTex);
                }

                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.AppendLine(stat.LabelCap);
                stringBuilder.AppendLine();
                stringBuilder.AppendLine(stat.description);
                TooltipHandler.TipRegion(rect, new TipSignal(stringBuilder.ToString(), rect.GetHashCode()));
                break;

            case objectType.Skill:
                if ((ownerPawn is Pawn) && (ownerPawn as Pawn).RaceProps.Humanlike)
                {
                    DrawSkill(rect, ownerPawn as Pawn);
                }
                break;

            case objectType.Need:
                if (ownerPawn is Pawn)
                {
                    DrawNeed(rect, ownerPawn as Pawn);
                }
                break;

            case objectType.Age:
                Text.Anchor = TextAnchor.MiddleCenter;
                string ageValue = ((ownerPawn as Pawn).ageTracker.AgeBiologicalYears.ToString());
                Widgets.Label(rect, ageValue);
                if (Mouse.IsOver(rect))
                {
                    GUI.DrawTexture(rect, TexUI.HighlightTex);
                }
                break;

            case objectType.Gear:
                DrawGear(rect, ownerPawn);
                break;

            case objectType.ControlPrisonerGetsFood:
                if (ownerPawn is Pawn)
                {
                    if (Mouse.IsOver(rect))
                    {
                        GUI.DrawTexture(rect, TexUI.HighlightTex);
                    }
                    bool getsFood = (ownerPawn as Pawn).guest.GetsFood;
                    Widgets.CheckboxLabeled(new Rect(rect.x + 8f, rect.y + 3f, 27f, 27f), "", ref getsFood, false);
                    (ownerPawn as Pawn).guest.GetsFood = getsFood;
                }
                break;

            case objectType.ControlPrisonerInteraction:
                if (ownerPawn is Pawn)
                {
                    if (Mouse.IsOver(rect))
                    {
                        GUI.DrawTexture(rect, TexUI.HighlightTex);
                    }
                    float x = 8f;

                    GUI.BeginGroup(rect);
                    IEnumerator enumerator = Enum.GetValues(typeof(PrisonerInteractionMode)).GetEnumerator();
                    try
                    {
                        while (enumerator.MoveNext())
                        {
                            PrisonerInteractionMode prisonerInteractionMode = (PrisonerInteractionMode)((byte)enumerator.Current);
                            if (Widgets.RadioButton(new Vector2(x, 3f), (ownerPawn as Pawn).guest.interactionMode == prisonerInteractionMode))
                            {
                                (ownerPawn as Pawn).guest.interactionMode = prisonerInteractionMode;
                            }
                            TooltipHandler.TipRegion(new Rect(x, 0f, 30f, 30f), new TipSignal(prisonerInteractionMode.GetLabel()));
                            x += 30f;
                        }
                    }
                    finally
                    {
                        IDisposable disposable = enumerator as IDisposable;
                        if (disposable != null)
                        {
                            disposable.Dispose();
                        }
                    }
                    GUI.EndGroup();
                }
                break;

            case objectType.ControlMedicalCare:
                if (ownerPawn is Pawn)
                {
                    MedicalCareSetter(rect, ref (ownerPawn as Pawn).playerSettings.medCare);
                }
                break;

            case objectType.AnimalMilkFullness:
                Text.Anchor = TextAnchor.MiddleCenter;
                if (ownerPawn is Pawn && ((Pawn)ownerPawn).ageTracker.CurLifeStage.milkable)
                {
                    var comp = ((Pawn)ownerPawn).AllComps.Where <ThingComp>(x => x is CompMilkable).FirstOrDefault();
                    if (comp != null)
                    {
                        value = ((CompMilkable)comp).Fullness.ToStringPercent();
                    }
                }

                Widgets.Label(rect, value);
                break;

            case objectType.AnimalWoolGrowth:
                Text.Anchor = TextAnchor.MiddleCenter;
                if (ownerPawn is Pawn && ((Pawn)ownerPawn).ageTracker.CurLifeStage.shearable)
                {
                    var comp = ((Pawn)ownerPawn).AllComps.Where <ThingComp>(x => x is CompShearable).FirstOrDefault();
                    if (comp != null)
                    {
                        value = ((CompShearable)comp).Fullness.ToStringPercent();
                    }
                }

                Widgets.Label(rect, value);
                break;

            case objectType.CurrentJob:
                if (ownerPawn is Pawn)
                {
                    string text = ((Pawn)ownerPawn).jobs.curDriver.GetReport();
                    Text.Anchor = TextAnchor.MiddleLeft;
                    Rect tRect = new Rect(rect.xMin + 2, rect.yMin + 3, rect.width - 2, rect.height);
                    GenText.SetTextSizeToFit(text, tRect);

                    if (Text.Font == GameFont.Tiny)
                    {
                        Widgets.Label(tRect, text);
                    }
                    else
                    {
                        Rect sRect = new Rect(rect.xMin + 2, rect.yMin, rect.width - 2, rect.height);
                        Widgets.Label(sRect, text);
                    }

                    if (Mouse.IsOver(rect))
                    {
                        GUI.DrawTexture(rect, TexUI.HighlightTex);
                    }
                }
                break;
            }
        }
Esempio n. 18
0
        protected override bool TryCastShot()
        {
            bool result = false;
            bool arg_40_0;

            CompAbilityUserMight comp = this.CasterPawn.GetComp <CompAbilityUserMight>();

            pwr = comp.MightData.MightPowerSkill_PhaseStrike.FirstOrDefault((MightPowerSkill x) => x.label == "TM_PhaseStrike_pwr");
            ver = comp.MightData.MightPowerSkill_PhaseStrike.FirstOrDefault((MightPowerSkill x) => x.label == "TM_PhaseStrike_ver");
            str = comp.MightData.MightPowerSkill_global_strength.FirstOrDefault((MightPowerSkill x) => x.label == "TM_global_strength_pwr");

            if (this.CasterPawn.equipment.Primary != null && !this.CasterPawn.equipment.Primary.def.IsRangedWeapon)
            {
                weaponComp      = base.CasterPawn.equipment.Primary;
                weaponDPS       = weaponComp.GetStatValue(StatDefOf.MeleeWeapon_AverageDPS, false) * .7f;
                dmgMultiplier   = weaponComp.GetStatValue(StatDefOf.MeleeWeapon_DamageMultiplier, false);
                pawnDPS         = base.CasterPawn.GetStatValue(StatDefOf.MeleeDPS, false);
                skillMultiplier = (.8f + (.025f * str.level));
                dmgNum          = Mathf.RoundToInt(skillMultiplier * dmgMultiplier * (pawnDPS + weaponDPS));
                ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef();
                if (!this.CasterPawn.IsColonistPlayerControlled && settingsRef.AIHardMode)
                {
                    dmgNum += 10;
                }

                if (this.currentTarget != null && base.CasterPawn != null)
                {
                    arg_29_0 = this.currentTarget.Cell;
                    Vector3 vector = this.currentTarget.CenterVector3;
                    arg_40_0 = this.currentTarget.Cell.IsValid;
                    arg_41_0 = vector.InBounds(base.CasterPawn.Map);
                    arg_42_0 = true; // vector.ToIntVec3().Standable(base.CasterPawn.Map);
                }
                else
                {
                    arg_40_0 = false;
                }
                bool flag  = arg_40_0;
                bool flag2 = arg_41_0;
                bool flag3 = arg_42_0;
                if (flag)
                {
                    if (flag2 & flag3)
                    {
                        Pawn    p    = this.CasterPawn;
                        Map     map  = this.CasterPawn.Map;
                        IntVec3 pLoc = this.CasterPawn.Position;
                        if (p.IsColonistPlayerControlled)
                        {
                            try
                            {
                                ThingSelectionUtility.SelectNextColonist();
                                this.CasterPawn.DeSpawn();
                                //p.SetPositionDirect(this.currentTarget.Cell);
                                SearchForTargets(arg_29_0, (2f + (float)(.5f * ver.level)), map, p);
                                GenSpawn.Spawn(p, this.currentTarget.Cell, map);
                                DrawBlade(p.Position.ToVector3Shifted(), 4f + (float)(ver.level));
                                p.drafter.Drafted = true;
                                ThingSelectionUtility.SelectPreviousColonist();
                            }
                            catch
                            {
                                if (!CasterPawn.Spawned)
                                {
                                    GenSpawn.Spawn(p, pLoc, map);
                                    p.drafter.Drafted = true;
                                    Log.Message("Phase strike threw exception - despawned pawn has been recovered at casting location");
                                }
                            }
                            this.Ability.PostAbilityAttempt();
                        }
                        else
                        {
                            this.CasterPawn.DeSpawn();
                            SearchForTargets(arg_29_0, (2f + (float)(.5f * ver.level)), map, p);
                            GenSpawn.Spawn(p, this.currentTarget.Cell, map);
                            DrawBlade(p.Position.ToVector3Shifted(), 4f + (float)(ver.level));
                        }

                        //this.CasterPawn.SetPositionDirect(this.currentTarget.Cell);
                        //base.CasterPawn.SetPositionDirect(this.currentTarget.Cell);
                        //this.CasterPawn.pather.ResetToCurrentPosition();
                        result = true;
                    }
                    else
                    {
                        Messages.Message("InvalidTargetLocation".Translate(), MessageTypeDefOf.RejectInput);
                    }
                }
            }
            else
            {
                Messages.Message("MustHaveMeleeWeapon".Translate(new object[]
                {
                    this.CasterPawn.LabelCap
                }), MessageTypeDefOf.RejectInput);
                return(false);
            }

            this.burstShotsLeft = 0;
            //this.ability.TicksUntilCasting = (int)base.UseAbilityProps.SecondsToRecharge * 60;
            return(result);
        }
Esempio n. 19
0
        private static float GetMeleeDamage(Pawn pawn, ThingWithComps weapon, Pawn target)
        {
            Log.Message("calcing melee damage for " + ((weapon == null) ? "unarmed" : weapon.def.defName));

            if (pawn == null)
            {
                Log.Warning("attempted to calc meleeDPS for null pawn!");
                return(0);
            }

            if (weapon == null)
            {
                Log.Message("no weapon, getting unarmed");

                Log.Message("pawn unarmed atk dmg is: " + pawn.GetStatValue(StatDefOf.MeleeDPS));
                return(pawn.GetStatValue(StatDefOf.MeleeDPS));
                //calc unarmed damage

                /*if (pawn.equipment != null)
                 * {
                 *  pawn.equipment.s
                 *  float meleeDPSWithWeapon = pawn.GetStatValue(StatDefOf.MeleeDPS);
                 *  ThingWithComps primary = pawn.equipment.Primary;
                 *  UnsafeUtilities.SetPropertyValue(pawn.equipment, "Primary", null);
                 *  float meleeDPSWithoutWeapon = pawn.GetStatValue(StatDefOf.MeleeDPS);
                 *  UnsafeUtilities.SetPropertyValue(pawn.equipment, "Primary", primary);
                 *  Log.Warning("DPS with " + primary.def.defName + ": " + meleeDPSWithWeapon + " without: " + meleeDPSWithoutWeapon);
                 *  return meleeDPSWithoutWeapon;
                 * }
                 * else
                 * {
                 *  Log.Message("pawn unarmed atk dmg is: "+ pawn.GetStatValue(StatDefOf.MeleeDPS));
                 *  return pawn.GetStatValue(StatDefOf.MeleeDPS);
                 * }*/
            }
            else
            {
                Log.Message("weapon dmg is: " + weapon.GetStatValue(StatDefOf.MeleeDPS));
                return(weapon.GetStatValue(StatDefOf.MeleeDPS));
            }

            //I dont even know what to say, really

            /*
             * List<Verb_MeleeAttack> verbs = GetUnarmedVerbs(pawn);
             *
             * if(weapon != null)
             * {
             *  CompEquippable equippable = weapon.TryGetComp<CompEquippable>();
             *  if (equippable != null)
             *  {
             *      foreach (Tool tool in weapon.def.tools)
             *      {
             *          foreach (Verb_MeleeAttack verb in weapon.GetComp<CompEquippable>().VerbTracker.AllVerbs.Where((Verb v) => (v is Verb_MeleeAttack)).Cast<Verb_MeleeAttack>())
             *          {
             *              if (verb.IsStillUsableBy(pawn))
             *                  verbs.Add(verb);
             *          }
             *      }
             *  }
             * }
             *
             * if (weapon == null)
             *  Log.Message("melee damage for fists calculated from ");
             * else
             *  Log.Message("melee damage for " + weapon.def.defName+ " calculated from ");
             *
             * string list = "";
             * foreach (Verb_MeleeAttack verb in verbs)
             * {
             *  list += verb + " " + verb.tool + "";
             * }
             *
             * if (verbs.Count == 0)
             * {
             *  return 0f;
             * }
             * float num = 0f;
             * foreach (Verb_MeleeAttack verb in verbs)
             * {
             *  num += verb.verbProps.AdjustedMeleeSelectionWeight(verb, pawn);
             * }
             * float num2 = 0f;
             * foreach (Verb_MeleeAttack verb in verbs)
             * {
             *  float selectionWeight = verb.verbProps.AdjustedMeleeSelectionWeight(verb, pawn);
             *  float damage = (float)verb.verbProps.AdjustedMeleeDamageAmount(verb, pawn);
             *
             *  //TODO: Note to self: this is where all the armor related stuff should be
             *
             *  //StatDef deflectionStat = verbsList[j].verbProps.meleeDamageDef.armorCategory.armorRatingStat;
             *  //damage *= ReduceForArmorType(deflectionStat, target);
             *
             *  num2 += selectionWeight / num * damage;
             * }
             * return num2;*/
        }
Esempio n. 20
0
        protected override bool TryCastShot()
        {
            CellRect cellRect = CellRect.CenteredOn(base.CasterPawn.Position, 1);
            Map      map      = base.CasterPawn.Map;

            cellRect.ClipInsideMap(map);

            IntVec3 centerCell        = cellRect.CenterCell;
            CompAbilityUserMight comp = this.CasterPawn.GetComp <CompAbilityUserMight>();

            pwr                = comp.MightData.MightPowerSkill_SeismicSlash.FirstOrDefault((MightPowerSkill x) => x.label == "TM_SeismicSlash_pwr");
            ver                = comp.MightData.MightPowerSkill_SeismicSlash.FirstOrDefault((MightPowerSkill x) => x.label == "TM_SeismicSlash_ver");
            str                = comp.MightData.MightPowerSkill_global_strength.FirstOrDefault((MightPowerSkill x) => x.label == "TM_global_strength_pwr");
            this.origin        = base.CasterPawn.Position.ToVector3();
            this.destination   = this.currentTarget.Cell.ToVector3Shifted();
            this.ticksToImpact = Mathf.RoundToInt((this.origin - this.destination).magnitude);

            if (this.CasterPawn.equipment.Primary != null && !this.CasterPawn.equipment.Primary.def.IsRangedWeapon)
            {
                weaponComp      = base.CasterPawn.equipment.Primary;
                weaponDPS       = weaponComp.GetStatValue(StatDefOf.MeleeWeapon_AverageDPS, false) * .7f;
                dmgMultiplier   = weaponComp.GetStatValue(StatDefOf.MeleeWeapon_DamageMultiplier, false);
                pawnDPS         = base.CasterPawn.GetStatValue(StatDefOf.MeleeDPS, false);
                skillMultiplier = (.7f + (.07f * pwr.level) + (.025f * str.level));
                dmgNum          = Mathf.RoundToInt(skillMultiplier * dmgMultiplier * (pawnDPS + weaponDPS));
                ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef();
                if (!this.CasterPawn.IsColonistPlayerControlled && settingsRef.AIHardMode)
                {
                    dmgNum += 10;
                }

                Vector3 strikeVec = this.origin;
                DrawBlade(strikeVec, 0);
                for (int i = 0; i < this.StartingTicksToImpact; i++)
                {
                    strikeVec = this.ExactPosition;
                    Pawn victim = strikeVec.ToIntVec3().GetFirstPawn(map);
                    if (victim != null && victim.Faction != base.CasterPawn.Faction)
                    {
                        DrawStrike(strikeVec.ToIntVec3(), strikeVec, map);
                        damageEntities(victim, null, dmgNum, DamageDefOf.Cut);
                    }
                    MoteMaker.ThrowTornadoDustPuff(strikeVec, map, .6f, Color.white);
                    for (int j = 0; j < 2 + (2 * ver.level); j++)
                    {
                        IntVec3 searchCell = strikeVec.ToIntVec3() + GenAdj.AdjacentCells8WayRandomized()[j];
                        MoteMaker.ThrowTornadoDustPuff(searchCell.ToVector3(), map, .1f, Color.gray);
                        victim = searchCell.GetFirstPawn(map);
                        if (victim != null && victim.Faction != base.CasterPawn.Faction)
                        {
                            DrawStrike(searchCell, searchCell.ToVector3(), map);
                            damageEntities(victim, null, dmgNum, DamageDefOf.Cut);
                        }
                    }
                    this.ticksToImpact--;
                }
            }
            else
            {
                Messages.Message("MustHaveMeleeWeapon".Translate(new object[]
                {
                    this.CasterPawn.LabelCap
                }), MessageTypeDefOf.RejectInput);
                return(false);
            }

            this.burstShotsLeft = 0;
            this.PostCastShot(flag10, out flag10);
            return(flag10);
        }