public static void PatchPathCostSwimming(TerrainDef water) { bool foundStat = false; StatModifier pathCost = new StatModifier { stat = StatDef.Named(WaterTerrainModExt.terrainPathCostStat), value = WaterSwimCost.TryGetValue(water.defName, DefaultWaterSwimCost) }; if (water.statBases == null) { water.statBases = new List <StatModifier>(); } foreach (StatModifier statBase in water.statBases) { if (statBase.stat == pathCost.stat) { foundStat = true; } } if (!foundStat) { water.statBases.Add(pathCost); } }
public static HashSet <StatDef> TerrainMovementDisallowedPathCostStat(this TerrainDef terrain) { HashSet <StatDef> disallowedPathCostStat = new HashSet <StatDef>(); if (terrain.modExtensions != null) { foreach (DefModExtension ext in terrain.modExtensions) { TerrainMovementTerrainRestrictions restrictions = terrain.LoadTerrainMovementTerrainRestrictionsExtension(ext); if (restrictions != null) { StatDef restrictionDef; // There's no actual StatDef for pathCost, so map it to MoveSpeed if (restrictions.disallowedPathCostStat == null || restrictions.disallowedPathCostStat == "pathCost") { restrictionDef = StatDefOf.MoveSpeed; } else { restrictionDef = StatDef.Named(restrictions.disallowedPathCostStat); } disallowedPathCostStat.Add(restrictionDef); } } } return(disallowedPathCostStat); }
public virtual ShiftVecReport ShiftVecReportFor(LocalTargetInfo target) { IntVec3 targetCell = target.Cell; ShiftVecReport report = new ShiftVecReport(); report.target = target; report.aimingAccuracy = AimingAccuracy; report.sightsEfficiency = SightsEfficiency; report.shotDist = (targetCell - caster.Position).LengthHorizontal; report.maxRange = verbProps.range; report.lightingShift = 1 - caster.Map.glowGrid.GameGlowAt(targetCell); if (!caster.Position.Roofed(caster.Map) || !targetCell.Roofed(caster.Map)) //Change to more accurate algorithm? { report.weatherShift = 1 - caster.Map.weatherManager.CurWeatherAccuracyMultiplier; } report.shotSpeed = ShotSpeed; report.swayDegrees = SwayAmplitude; var spreadmult = projectilePropsCE != null ? projectilePropsCE.spreadMult : 0f; report.spreadDegrees = (EquipmentSource?.GetStatValue(StatDef.Named("ShotSpread")) ?? 0) * spreadmult; Thing cover; float smokeDensity; GetHighestCoverAndSmokeForTarget(target, out cover, out smokeDensity); report.cover = cover; report.smokeDensity = smokeDensity; return(report); }
public static void ApplyInvSave(ref float damAmount, ref float armorPenetration, Thing armorThing, ref DamageDef damageDef, Pawn pawn) { float ir = armorThing.GetStatValue(StatDef.Named("OG_ArmorRating_InvunerableSave"), true); if (ir > 0) { float ar = armorThing.GetStatValue(damageDef.armorCategory.armorRatingStat, true); float ap = armorPenetration; if (armorPenetration > ar) { ap = Mathf.Max(armorPenetration - ir, 0f); } float value = Rand.Value; float num2 = ap * 0.5f; if (value < num2) { damAmount = 0f; if (Prefs.DevMode) { Log.Message("Damage negated by Inv save"); } return; } if (value < ap) { damAmount = (float)GenMath.RoundRandom(damAmount / 2f); if (Prefs.DevMode) { Log.Message("Damage halved by Inv save"); } } } }
// Attempted to add Extended Storage compatibility. static bool ContainsPartialThingWithSameDef(Thing t, IntVec3 c, Map m) { bool matchingStack = false; bool extendedStorageCell = false; bool matchingExtendedStorage = false; int totalExtendedStack = 0; var thingListDest = c.GetThingList(m); var tLimit = t.def.stackLimit; var storageExtended = c.GetFirstBuilding(m) as Building_Storage; if (storageExtended != null && StatDef.Named(ExtendedStorageStatName) != null) { var capacity = storageExtended.GetStatValue(StatDef.Named(ExtendedStorageStatName)); tLimit = (int)(tLimit * capacity); extendedStorageCell = true; } foreach (Thing q in thingListDest) { if (q == null) { continue; } if (q.def == null) { continue; } if (q == t) { continue; } if (q.def == t.def && !extendedStorageCell) { matchingStack |= q.stackCount + t.stackCount <= tLimit; } if (q.def == t.def && extendedStorageCell) { totalExtendedStack += q.stackCount; } } if (extendedStorageCell && totalExtendedStack < tLimit) { matchingExtendedStorage = true; } if (matchingStack || matchingExtendedStorage) { return(true); } return(false); }
public virtual ShiftVecReport ShiftVecReportFor(TargetInfo target) { IntVec3 targetCell = target.Cell; ShiftVecReport report = new ShiftVecReport(); report.target = target; report.aimingAccuracy = this.aimingAccuracy; report.aimEfficiency = this.aimEfficiency; report.shotDist = (targetCell - this.caster.Position).LengthHorizontal; report.lightingShift = 1 - Find.GlowGrid.GameGlowAt(targetCell); if (!this.caster.Position.Roofed() || !targetCell.Roofed()) //Change to more accurate algorithm? { report.weatherShift = 1 - Find.WeatherManager.CurWeatherAccuracyMultiplier; } report.shotSpeed = this.shotSpeed; report.swayDegrees = this.swayAmplitude; report.spreadDegrees = this.ownerEquipment.GetStatValue(StatDef.Named("ShotSpread")) * this.projectilePropsCR.spreadMult; Thing cover; this.GetPartialCoverBetween(this.caster.Position.ToVector3Shifted(), targetCell.ToVector3Shifted(), out cover); report.cover = cover; return(report); }
public static List <IPCInterface.Rows.Apparel> Get() { ceSharpStatWorker = StatDef.Named("BodyPartSharpArmor")?.workerClass?.Assembly.GetName().Name?.Equals("CombatExtended") ?? false; ceBluntStatWorker = StatDef.Named("BodyPartBluntArmor")?.workerClass?.Assembly.GetName().Name?.Equals("CombatExtended") ?? false; var rows = new List <IPCInterface.Rows.Apparel>(); var dataSources = from d in DefDatabase <ThingDef> .AllDefs where d.IsApparel orderby d.BaseMarketValue select d; foreach (var d in dataSources) { if (d.MadeFromStuff) { ThingDef defStuff = GenStuff.DefaultStuffFor(d); foreach (var stuff in GenStuff.AllowedStuffsFor(d)) { rows.Add(MakeRow(d, defStuff, stuff)); } } else { rows.Add(MakeRow(d)); } } return(rows); }
private Toil Manage(TargetIndex targetIndex) { var station = CurJob.GetTarget(targetIndex).Thing as Building_ManagerStation; if (station == null) { Log.Error("Target of manager job was not a manager station. This should never happen."); return(null); } var comp = station.GetComp <Comp_ManagerStation>(); if (comp == null) { Log.Error("Target of manager job does not have manager station comp. This should never happen."); return(null); } var toil = new Toil(); toil.defaultDuration = (int)(comp.Props.Speed * (1 - pawn.GetStatValue(StatDef.Named("ManagingSpeed")) + .5)); #if DEBUG_WORKGIVER Log.Message("Pawn stat: " + pawn.GetStatValue(StatDef.Named("ManagingSpeed")) + " (+0.5) Station speed: " + comp.Props.Speed + "Total time: " + toil.defaultDuration); #endif toil.defaultCompleteMode = ToilCompleteMode.Delay; toil.tickAction = delegate { toil.actor.skills.GetSkill(DefDatabase <SkillDef> .GetNamed("Managing")).Learn(0.11f); }; var finishers = new List <Action>(); finishers.Add(delegate { Manager.For(pawn.Map).TryDoWork(); }); toil.finishActions = finishers; return(toil); }
public override string GetInspectString() { if (powerTrader == null) { powerTrader = GetComp <CompPowerTrader>(); } if (manager == null) { manager = Find.ResearchManager; } if (manager.currentProj == null) { return("No project selected!"); } string inspect; float storage = this.GetStatValue(StatDef.Named("BOTR_Storage"), false); float remainingWork = manager.currentProj.baseCost - manager.currentProj.ProgressReal; if (storage <= remainingWork && powerTrader.PowerOn) { inspect = "Not enough storage for current project. Add drives or research some of it manually. /n"; inspect = inspect + "Storage: " + storage.ToString(); } else if (powerTrader.PowerOn) { inspect = "Storage: " + storage.ToString() + "\n"; inspect = inspect + "Memory: " + this.GetStatValue(StatDef.Named("BOTR_Memory"), false) + "\n"; inspect = inspect + "Research Progress (Pts/Required): " + Math.Round(points, 2).ToString() + "/" + Math.Round(remainingWork, 2).ToString(); } else { inspect = "No power. Any research progress is now lost."; } return(inspect); }
public static void CostructionIV() { DefDatabase <ThingDef> .GetNamed("SCWall", true).SetStatBaseValue(StatDef.Named("MaxHitPoints"), 500f); DefDatabase <ThingDef> .GetNamed("WallConduit", true).SetStatBaseValue(StatDef.Named("MaxHitPoints"), 500f); DefDatabase <ThingDef> .GetNamed("WallLighted", true).SetStatBaseValue(StatDef.Named("MaxHitPoints"), 500f); ConstructionNotifyRepair(); }
public static void SetDefaultStatPriority(ICollection <StatPriority> priorities, string name, float weight) { var stat = StatDef.Named(name); if (stat == null) { Log.Message($"OutfitManager: Could not find apparel stat named '{name}'"); return; } SetDefaultStatPriority(priorities, stat, weight); }
private static void FillRowCombatExtended(Row row, ThingDef d, VerbProperties verb) { var ceAmmo = d.GetCompProperties <CompProperties_AmmoUser>(); row["DamageType".ParserTranslate()] = ceAmmo != null ? ceAmmo.ammoSet.LabelCap : verb.defaultProjectile.projectile.damageDef.label; // TODO: check full stat dump row["CE_SightsEfficiency".ParserTranslate()] = d.GetStatValueAbstract(StatDef.Named("SightsEfficiency")).ToPercent(); row["CE_ShotSpread".ParserTranslate()] = d.GetStatValueAbstract(StatDef.Named("ShotSpread")); row["CE_SwayFactor".ParserTranslate()] = d.GetStatValueAbstract(StatDef.Named("SwayFactor")); row["CE_OneHanded".ParserTranslate()] = d.weaponTags?.Contains("CE_OneHandedWeapon") ?? false; }
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; } }
public override ThinkResult TryIssueJobPackage(Pawn pawn) { Job job = this.TryGiveJob(pawn); ThinkResult result; if (job == null) { result = ThinkResult.NoJob; } else { if (pawn.Faction == Faction.OfPlayer && !robotBodyList.Contains(pawn.def.race.body.defName)) { if (job.def == JobDefOf.CutPlant || job.def == JobDefOf.Harvest) { RightTools.EquipRigthTool(pawn, StatDefOf.PlantWorkSpeed); } else { if (job.def == JobDefOf.Mine) { RightTools.EquipRigthTool(pawn, StatDefOf.MiningSpeed); } else { if (job.def == JobDefOf.FinishFrame || job.def == JobDefOf.Deconstruct) { RightTools.EquipRigthTool(pawn, StatDefOf.ConstructionSpeed); } else { if (job.def == JobDefOf.DoBill && job.bill.recipe.workSkill == SkillDefOf.Cooking) { RightTools.EquipRigthTool(pawn, StatDef.Named("CookSpeed")); } else { if (job.def == JobDefOf.TendPatient) { RightTools.EquipRigthTool(pawn, StatDef.Named("HealingQuality")); } } } } } } result = new ThinkResult(job, this); } return(result); }
private Toil Manage(TargetIndex targetIndex) { var station = GetActor().jobs.curJob.GetTarget(targetIndex).Thing as Building_ManagerStation; if (station == null) { Log.Error("Target of manager job was not a manager station."); return(null); } var comp = station.GetComp <Comp_ManagerStation>(); if (comp == null) { Log.Error("Target of manager job does not have manager station comp. This should never happen."); return(null); } var toil = new Toil(); toil.defaultCompleteMode = ToilCompleteMode.Never; toil.initAction = () => { workDone = 0; workNeeded = (int) (comp.Props.Speed * (1 - pawn.GetStatValue(StatDef.Named("ManagingSpeed")) + .5)); }; toil.tickAction = () => { // learn a bit pawn.skills.GetSkill(DefDatabase <SkillDef> .GetNamed("Intellectual")) .Learn(0.11f); // update counter workDone++; // are we done yet? if (workDone > workNeeded) { Manager.For(pawn.Map).TryDoWork(); ReadyForNextToil(); } }; toil.WithProgressBar(TargetIndex.A, () => workDone / workNeeded); return(toil); }
public static (StatDef moveStat, StatDef costStat) TerrainMovementStatDefPair(this TerrainDef terrain, TerrainMovementStatDef moveStatDef, bool defaultMovementAllowed = true, LocomotionUrgency urgency = LocomotionUrgency.None) { HashSet <StatDef> disallowedPathCostsStats = terrain.TerrainMovementDisallowedPathCostStat(); if (moveStatDef != null && moveStatDef.UrgencyAllowed(urgency)) { StatDef newCostStat; // If there's no actual StatDef for pathCost, so map it to null if (moveStatDef.pawnSpeedStat == null || moveStatDef.pawnSpeedStat == "pathCost") { if (defaultMovementAllowed) { newCostStat = StatDefOf.MoveSpeed; } else { newCostStat = null; } } else { newCostStat = StatDef.Named(moveStatDef.terrainPathCostStat); } // Opt out if the terrain disallows this costStat if (!disallowedPathCostsStats.Contains(newCostStat)) { StatDef newMoveStat; if (moveStatDef.pawnSpeedStat == null) { if (defaultMovementAllowed) { newMoveStat = StatDefOf.MoveSpeed; } else { newMoveStat = null; } } else { newMoveStat = StatDef.Named(moveStatDef.pawnSpeedStat); } return(newMoveStat, newCostStat); } } return(null, null); }
public MarkData(PawnKindDef p) { this.kindDef = p; if (p.defaultFactionType != null) { this.factionDef = p.defaultFactionType; } this.raceDef = p.race; this.MarkScore = p.race.GetStatValueAbstract(StatDef.Named("HMS_MarkScore")); /* * this.Label = p.LabelCap; * this.Humanlike = p.RaceProps.Humanlike; * this.MarkDef = HMSUtility.GetMark(p); * this.MarkDefs = HMSUtility.GetMarks(p); */ }
public void UpdateResists() { float envResist = 0; List <Apparel> wornApparels = pawn.apparel.WornApparel; envResist += pawn.GetStatValue(StatDef.Named("ArmorRating_Enviromental")); for (int i = 0; i < wornApparels.Count; i++) { Apparel wornApparel = wornApparels[i]; envResist += wornApparel.GetStatValue(StatDef.Named("ArmorRating_Enviromental")); } //Log.Message(pawn + " ArmorRating_Enviromental = " + envResist); pawn.TryMakeImmune(envResist, 1, HediffDefOf.ToxicImmunity); Hediff hediff_OxygenAtmosphere = pawn.health.hediffSet.hediffs.Find((Hediff x) => x.def == HediffDefOf.OxygenAtmosphere); if (envResist < minEnvResist) { if (pawn.IsColonist || pawn.IsPrisoner) { if (hediff_OxygenAtmosphere != null) { hediff_OxygenAtmosphere.Severity += 0.001f; } else { pawn.health.AddHediff(HediffDefOf.OxygenAtmosphere); //Hediff hediff = pawn.health.hediffSet.hediffs.Find((Hediff x) => x.def == HediffDefOf.OxygenAtmosphere); //float severity = Rand.Range(10, 100); //hediff.Severity = severity / 1000; } } } else { if (hediff_OxygenAtmosphere != null) { hediff_OxygenAtmosphere.Severity -= 0.001f; if (hediff_OxygenAtmosphere.Severity <= 0.001f) { pawn.health.RemoveHediff(hediff_OxygenAtmosphere); } } } }
public static void CostructionII() { DefDatabase <ThingDef> .GetNamed("SCWall", true).stuffCategories.Add(StuffCategoryDefOf.Metallic); DefDatabase <ThingDef> .GetNamed("WallLighted", true).stuffCategories.Add(StuffCategoryDefOf.Metallic); DefDatabase <ThingDef> .GetNamed("WallConduit", true).stuffCategories.Add(StuffCategoryDefOf.Metallic); DefDatabase <ThingDef> .GetNamed("SCDoor", true).stuffCategories.Add(StuffCategoryDefOf.Metallic); DefDatabase <ThingDef> .GetNamed("SCWall", true).SetStatBaseValue(StatDef.Named("MaxHitPoints"), 400f); DefDatabase <ThingDef> .GetNamed("WallConduit", true).SetStatBaseValue(StatDef.Named("MaxHitPoints"), 400f); DefDatabase <ThingDef> .GetNamed("WallLighted", true).SetStatBaseValue(StatDef.Named("MaxHitPoints"), 400f); ConstructionNotifyRepair(); }
public static IEnumerable <(StatDef moveStat, StatDef costStat)> TerrainMovementStatDefs(this TerrainDef terrain) { HashSet <StatDef> disallowedPathCostsStats = terrain.TerrainMovementDisallowedPathCostStat(); // Check for if default movement is allowed or not if (!disallowedPathCostsStats.Contains(null)) { yield return(StatDefOf.MoveSpeed, null); } if (terrain.modExtensions != null) { foreach (DefModExtension ext in terrain.modExtensions) { TerrainMovementStatDef moveStatDef = terrain.LoadTerrainMovementStatDefExtension(ext); if (moveStatDef != null) { StatDef newCostStat; // There's no actual StatDef for pathCost, so map it to null if (moveStatDef.pawnSpeedStat == null || moveStatDef.pawnSpeedStat == "pathCost") { newCostStat = null; } else { newCostStat = StatDef.Named(moveStatDef.terrainPathCostStat); } // Opt out if the terrain disallows this costStat if (!disallowedPathCostsStats.Contains(newCostStat)) { StatDef newMoveStat; if (moveStatDef.pawnSpeedStat == null) { newMoveStat = StatDefOf.MoveSpeed; } else { newMoveStat = StatDef.Named(moveStatDef.pawnSpeedStat); } yield return(newMoveStat, newCostStat); } } } } }
static bool Prefix(ref bool __result, Pawn pawn, bool canDig, out IntVec3 spot) { spot = IntVec3.Invalid; // Check if the animal involved prefers to swim over walk if (pawn.GetStatValue(StatDefOf.MoveSpeed) >= pawn.GetStatValue(StatDef.Named(SwimmingLoader.SwimStat)) + 0.001) { ToggledDeepWaterWalkable.DeepWaterValid = false; try { TraverseMode mode = canDig ? TraverseMode.PassAllDestroyableThings : TraverseMode.ByPawn; __result = RCellFinder.TryFindBestExitSpot(pawn, out spot, mode); } finally { ToggledDeepWaterWalkable.DeepWaterValid = true; } } return(!__result); }
protected override void Explode() { Map map = base.Map; base.Explode(); if (base.Position != null && map != null) { foreach (Thing hitThing in GenRadial.RadialDistinctThingsAround(base.Position, map, base.def.projectile.explosionRadius, true)) { if (hitThing is Pawn targetPawn && targetPawn != null && targetPawn.health != null && targetPawn.RaceProps.IsFlesh) { float targetPawnToxicSensitivity = targetPawn.GetStatValue(StatDef.Named("ToxicSensitivity")); Hediff targetPawnToxicSludgeHediff = targetPawn.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("TM_ToxicSludge")); float toxicSludgeSeverity = Rand.Range(0.15f, 0.30f) * targetPawnToxicSensitivity; if (targetPawnToxicSludgeHediff != null) { targetPawnToxicSludgeHediff.Severity += toxicSludgeSeverity; } else { Hediff hediff = HediffMaker.MakeHediff(HediffDef.Named("TM_ToxicSludge"), targetPawn, null); hediff.Severity = toxicSludgeSeverity; targetPawn.health.AddHediff(hediff, null, null); } Hediff targetPawnToxicBuildupHediff = targetPawn.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("ToxicBuildup")); float toxicBuildupSeverity = Rand.Range(0.03f, 0.15f) * targetPawnToxicSensitivity; if (targetPawnToxicBuildupHediff != null) { targetPawnToxicBuildupHediff.Severity += toxicBuildupSeverity; } else { Hediff hediff = HediffMaker.MakeHediff(HediffDef.Named("ToxicBuildup"), targetPawn, null); hediff.Severity = toxicBuildupSeverity; targetPawn.health.AddHediff(hediff, null, null); } } else if (hitThing is Plant targetPlant && targetPlant != null) { targetPlant.CropBlighted(); } }
public override IEnumerable <StatDrawEntry> SpecialDisplayStats(StatRequest req) { foreach (var statDrawEntry in base.SpecialDisplayStats(req)) { yield return(statDrawEntry); } if (sourceType == SourceType.Item) { // アイテム1個から得られる水分量 yield return(new StatDrawEntry( MizuDef.StatCategory_Water, StatDef.Named("Mizu_DrawingSpeed"), waterAmount, req, ToStringNumberSense.Undefined, 11)); } }
public virtual ShiftVecReport ShiftVecReportFor(LocalTargetInfo target) { IntVec3 targetCell = target.Cell; ShiftVecReport report = new ShiftVecReport(); report.target = target; report.aimingAccuracy = AimingAccuracy; report.sightsEfficiency = SightsEfficiency; report.shotDist = (targetCell - caster.Position).LengthHorizontal; report.maxRange = verbProps.range; report.lightingShift = CE_Utility.GetLightingShift(caster, LightingTracker.CombatGlowAtFor(caster.Position, targetCell)); if (!caster.Position.Roofed(caster.Map) || !targetCell.Roofed(caster.Map)) //Change to more accurate algorithm? { report.weatherShift = 1 - caster.Map.weatherManager.CurWeatherAccuracyMultiplier; } report.shotSpeed = ShotSpeed; report.swayDegrees = SwayAmplitude; var spreadmult = projectilePropsCE != null ? projectilePropsCE.spreadMult : 0f; report.spreadDegrees = (EquipmentSource?.GetStatValue(StatDef.Named("ShotSpread")) ?? 0) * spreadmult; Thing cover; float smokeDensity; GetHighestCoverAndSmokeForTarget(target, out cover, out smokeDensity); report.cover = cover; report.smokeDensity = smokeDensity; if (Controller.settings.DebugVerbose) { Log.Message($"<color=red>CE</color>: <color=orange>{caster}</color> shooting <color=orange>{target.Thing}</color> <color=yellow>ShiftVecReport</color>\n" + $"1- aimingAccuracy:{report.aimingAccuracy}\n" + $"2- sightsEfficiency:{report.sightsEfficiency}\n" + $"3- maxRange:{report.maxRange}\n" + $"4- lightingShift:{report.lightingShift}\n" + $"5- spreadDegrees:{report.spreadDegrees}\n" + $"6- smokeDensity:{report.smokeDensity}\n" + $"7- swayDegrees:{report.swayDegrees}\n" + $"8- shotSpeed:{report.shotSpeed}\n" + $"9- shotDist:{report.shotDist}\n"); } return(report); }
public override void Tick() { ticksLeft--; if (ticksLeft <= 0) { if (manager == null) { manager = Find.ResearchManager; } float storage = this.GetStatValue(StatDef.Named("BOTR_Storage"), false); if (manager.currentProj != null) { float remainingWork = manager.currentProj.baseCost - manager.currentProj.ProgressReal; if (manager != null && storage >= remainingWork) { if (powerTrader == null) { powerTrader = GetComp <CompPowerTrader>(); } if (powerTrader.PowerOn) { if (points >= manager.currentProj.baseCost - manager.currentProj.ProgressReal) { manager.FinishProject(manager.currentProj, true); points -= manager.currentProj.baseCost - manager.currentProj.ProgressReal; } else { ticksLeft = ticksBetweenPoint; points += this.GetStatValue(StatDef.Named("BOTR_Memory"), false); } } else { points = 0; } } } } base.Tick(); }
public MarkData(ThingDef p) { if (DefDatabase <PawnKindDef> .AllDefs.Any(x => x.race == p)) { this.kindDef = DefDatabase <PawnKindDef> .AllDefs.Where(x => x.race == p).Any() ? DefDatabase <PawnKindDef> .AllDefs.Where(x => x.race == p).RandomElement() : null; } else { Log.Warning(string.Format("Warning, no pawnkinds found for {0} Race def: {1}", p.LabelCap, p.defName)); } this.raceDef = p; this.MarkScore = p.GetStatValueAbstract(StatDef.Named("HMS_MarkScore")); /* * this.Label = p.LabelCap; * this.Humanlike = p.race.Humanlike; * this.MarkDef = HMSUtility.GetMark(p); * this.MarkDefs = HMSUtility.GetMarks(p); */ }
public static string GetProjectileReadout(ThingDef ammoThingDef) { ammoStat ??= StatDef.Named("AmmoCaliber"); if (ammoStat == null) { return("Error generating stats. Please report this bug."); } // Incoming: reflection hell. defInfo ??= typeof(StatRequest).GetField("defInt", BindingFlags.NonPublic | BindingFlags.Instance); StatRequest req = new StatRequest(); object obj = RuntimeHelpers.GetObjectValue(req); defInfo.SetValue(obj, ammoThingDef); req = (StatRequest)obj; string info = ammoStat.Worker.GetExplanationUnfinalized(req, ToStringNumberSense.Factor); return(info); }
public MarkData(Pawn p) { this.kindDef = p.kindDef; this.faction = p.Faction; this.raceDef = p.def; if (Humanlike) { this.Name = p.Name.ToStringShort; } if (this.faction != null) { this.factionDef = this.faction.def; } this.MarkScore = p.GetStatValue(StatDef.Named("HMS_MarkScore")); /* * this.Label = p.kindDef.LabelCap; * this.Humanlike = p.RaceProps.Humanlike; * this.MarkDef = HMSUtility.GetMark(p); * this.MarkDefs = HMSUtility.GetMarks(p); */ }
/// <summary> /// Determines if and how many of an item currently fit into the inventory with regards to weight/bulk constraints. /// </summary> /// <param name="thing">Thing to check</param> /// <param name="count">Maximum amount of that item that can fit into the inventory</param> /// <param name="ignoreEquipment">Whether to include currently equipped weapons when calculating current weight/bulk</param> /// <param name="useApparelCalculations">Whether to use calculations for worn apparel. This will factor in equipped stat offsets boosting inventory space and use the worn bulk and weight.</param> /// <returns>True if one or more items fit into the inventory</returns> public bool CanFitInInventory(Thing thing, out int count, bool ignoreEquipment = false, bool useApparelCalculations = false) { float thingWeight; float thingBulk; if (useApparelCalculations) { thingWeight = thing.GetStatValue(StatDef.Named("WornWeight")); thingBulk = thing.GetStatValue(StatDef.Named("WornBulk")); if (thingWeight <= 0 && thingBulk <= 0) { count = 1; return(true); } // Subtract the stat offsets we get from wearing this thingWeight -= thing.def.equippedStatOffsets.GetStatOffsetFromList(StatDef.Named("CarryWeight")); thingBulk -= thing.def.equippedStatOffsets.GetStatOffsetFromList(StatDef.Named("CarryBulk")); } else { thingWeight = thing.GetStatValue(StatDef.Named("Weight")); thingBulk = thing.GetStatValue(StatDef.Named("Bulk")); } // Subtract weight of currently equipped weapon float eqBulk = 0f; float eqWeight = 0f; if (ignoreEquipment && this.parentPawn.equipment != null && this.parentPawn.equipment.Primary != null) { ThingWithComps eq = this.parentPawn.equipment.Primary; GetEquipmentStats(eq, out eqWeight, out eqBulk); } // Calculate how many items we can fit into our inventory float amountByWeight = thingWeight <= 0 ? thing.stackCount : (availableWeight + eqWeight) / thingWeight; float amountByBulk = thingBulk <= 0 ? thing.stackCount : (availableBulk + eqBulk) / thingBulk; count = Mathf.FloorToInt(Mathf.Min(amountByBulk, amountByWeight, thing.stackCount)); return(count > 0); }
public static float Postfix(float __result, Pawn attacker, Thing equipment) { var offset = 0f; var factor = 1f; var meleePen = StatDef.Named("MeleeArmorPenetration"); if (attacker?.PsiTracker().Activated ?? false) { offset += attacker.PsiTracker().GetTotalOffsetOfStat(meleePen); factor *= attacker.PsiTracker().GetTotalFactorOfStat(meleePen); } // Glad I didn't try to fix this in CyberNet - this is absolute hacks if (attacker?.health.hediffSet.HasHediff(PsiTechDefOf.PTMeleeMastery) ?? false) { factor *= PsiTechDefOf.PTMeleeMastery.stages.First().statOffsets.First(stat => stat.stat == meleePen).value; } __result += offset; __result *= factor; return(__result); }