Remove more code warnings

This commit is contained in:
amevarashi 2022-04-15 21:46:29 +05:00
parent 9589d3dda6
commit 3c548e6ae4
10 changed files with 155 additions and 177 deletions

View file

@ -1,4 +1,5 @@
using RimWorld; using RimWorld;
using System.Diagnostics.CodeAnalysis;
using Verse; using Verse;
namespace RJWSexperience.Ideology namespace RJWSexperience.Ideology
@ -22,7 +23,9 @@ namespace RJWSexperience.Ideology
public class PreceptComp_SelfTookThoughtTagged : PreceptComp_SelfTookMemoryThought public class PreceptComp_SelfTookThoughtTagged : PreceptComp_SelfTookMemoryThought
{ {
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public string tag; public string tag;
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public bool exclusive = false; public bool exclusive = false;
public PreceptComp_SelfTookThoughtTagged() { } public PreceptComp_SelfTookThoughtTagged() { }
@ -57,22 +60,18 @@ namespace RJWSexperience.Ideology
} }
Pawn arg = ev.args.GetArg<Pawn>(HistoryEventArgsNames.Doer); Pawn arg = ev.args.GetArg<Pawn>(HistoryEventArgsNames.Doer);
Pawn partner = ev.args.GetArg<Pawn>(HistoryEventArgsNamesCustom.Partner); Pawn partner = ev.args.GetArg<Pawn>(HistoryEventArgsNamesCustom.Partner);
if (arg.needs != null && arg.needs.mood != null && (!this.onlyForNonSlaves || !arg.IsSlave)) if (arg.needs?.mood != null && (!this.onlyForNonSlaves || !arg.IsSlave))
{ {
if (this.thought.minExpectationForNegativeThought != null && ExpectationsUtility.CurrentExpectationFor(arg).order < this.thought.minExpectationForNegativeThought.order) if (this.thought.minExpectationForNegativeThought != null && ExpectationsUtility.CurrentExpectationFor(arg).order < this.thought.minExpectationForNegativeThought.order)
{ {
return; return;
} }
Thought_Memory thought_Memory = ThoughtMaker.MakeThought(this.thought, precept); Thought_Memory thought_Memory = ThoughtMaker.MakeThought(this.thought, precept);
Thought_KilledInnocentAnimal thought_KilledInnocentAnimal; if (thought_Memory is Thought_KilledInnocentAnimal thought_KilledInnocentAnimal && ev.args.TryGetArg<Pawn>(HistoryEventArgsNames.Victim, out Pawn animal))
Pawn animal;
if ((thought_KilledInnocentAnimal = (thought_Memory as Thought_KilledInnocentAnimal)) != null && ev.args.TryGetArg<Pawn>(HistoryEventArgsNames.Victim, out animal))
{ {
thought_KilledInnocentAnimal.SetAnimal(animal); thought_KilledInnocentAnimal.SetAnimal(animal);
} }
Thought_MemoryObservation thought_MemoryObservation; if (thought_Memory is Thought_MemoryObservation thought_MemoryObservation && ev.args.TryGetArg<Corpse>(HistoryEventArgsNames.Subject, out Corpse target))
Corpse target;
if ((thought_MemoryObservation = (thought_Memory as Thought_MemoryObservation)) != null && ev.args.TryGetArg<Corpse>(HistoryEventArgsNames.Subject, out target))
{ {
thought_MemoryObservation.Target = target; thought_MemoryObservation.Target = target;
} }
@ -83,20 +82,20 @@ namespace RJWSexperience.Ideology
public class PreceptComp_KnowsMemoryThoughtTagged : PreceptComp_KnowsMemoryThought public class PreceptComp_KnowsMemoryThoughtTagged : PreceptComp_KnowsMemoryThought
{ {
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public string tag; public string tag;
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public bool exclusive = false; public bool exclusive = false;
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public bool applyonpartner = false; public bool applyonpartner = false;
public PreceptComp_KnowsMemoryThoughtTagged() { } public PreceptComp_KnowsMemoryThoughtTagged() { }
public override void Notify_MemberWitnessedAction(HistoryEvent ev, Precept precept, Pawn member) public override void Notify_MemberWitnessedAction(HistoryEvent ev, Precept precept, Pawn member)
{ {
if (!applyonpartner) if (!applyonpartner && ev.args.TryGetArg(HistoryEventArgsNamesCustom.Partner, out Pawn pawn) && pawn == member)
{ {
if (ev.args.TryGetArg(HistoryEventArgsNamesCustom.Partner, out Pawn pawn)) return;
{
if (pawn == member) return;
}
} }
if (tag != null) if (tag != null)
{ {

View file

@ -1,19 +1,12 @@
using System; using RimWorld;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Diagnostics.CodeAnalysis;
using System.Text;
using System.Threading.Tasks;
using RimWorld;
using Verse;
namespace RJWSexperience.Ideology namespace RJWSexperience.Ideology
{ {
public class PreceptDef_RequirementExtended : PreceptDef public class PreceptDef_RequirementExtended : PreceptDef
{ {
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public List<MemeDef> requiredAllMemes = new List<MemeDef>(); public List<MemeDef> requiredAllMemes = new List<MemeDef>();
} }
} }

View file

@ -25,15 +25,12 @@ namespace RJWSexperience.Ideology
public static void Postfix(Pawn otherPawn, Pawn ___pawn, ref float __result) public static void Postfix(Pawn otherPawn, Pawn ___pawn, ref float __result)
{ {
Ideo ideo = ___pawn.Ideo; Ideo ideo = ___pawn.Ideo;
if (ideo != null) if (ideo?.HasPrecept(VariousDefOf.Incestuos_IncestOnly) == true && IdeoUtility.IsIncest(___pawn, otherPawn))
{
if (ideo.HasPrecept(VariousDefOf.Incestuos_IncestOnly) && IdeoUtility.IsIncest(___pawn, otherPawn))
{ {
__result *= 8f; __result *= 8f;
} }
} }
} }
}
[HarmonyPatch(typeof(RitualOutcomeEffectWorker_FromQuality), "GiveMemoryToPawn")] [HarmonyPatch(typeof(RitualOutcomeEffectWorker_FromQuality), "GiveMemoryToPawn")]
public static class Rimworld_Patch_GiveMemoryToPawn public static class Rimworld_Patch_GiveMemoryToPawn
@ -51,10 +48,7 @@ namespace RJWSexperience.Ideology
{ {
public static void Postfix(PreceptDef precept, bool checkDuplicates, ref IdeoFoundation __instance, ref AcceptanceReport __result) public static void Postfix(PreceptDef precept, bool checkDuplicates, ref IdeoFoundation __instance, ref AcceptanceReport __result)
{ {
if (precept is PreceptDef_RequirementExtended) if (precept is PreceptDef_RequirementExtended def && !def.requiredAllMemes.NullOrEmpty())
{
PreceptDef_RequirementExtended def = precept as PreceptDef_RequirementExtended;
if (!def.requiredAllMemes.NullOrEmpty())
{ {
for (int i = 0; i < def.requiredAllMemes.Count; i++) for (int i = 0; i < def.requiredAllMemes.Count; i++)
{ {
@ -70,5 +64,4 @@ namespace RJWSexperience.Ideology
} }
} }
} }
}
} }

View file

@ -124,8 +124,7 @@ namespace RJWSexperience.Ideology
}; };
get_banged.tickAction = delegate get_banged.tickAction = delegate
{ {
if ((parteners.Count > 0) && (pawn.IsHashIntervalTick(ticks_between_hearts / parteners.Count))) if ((parteners.Count > 0) && pawn.IsHashIntervalTick(ticks_between_hearts / parteners.Count) && pawn.IsHashIntervalTick(ticks_between_hearts))
if (pawn.IsHashIntervalTick(ticks_between_hearts))
ThrowMetaIconF(pawn.Position, pawn.Map, FleckDefOf.Heart); ThrowMetaIconF(pawn.Position, pawn.Map, FleckDefOf.Heart);
}; };
get_banged.AddEndCondition(new Func<JobCondition>(() => get_banged.AddEndCondition(new Func<JobCondition>(() =>

View file

@ -1,29 +1,26 @@
using System; using RimWorld;
using System.Collections.Generic; using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RimWorld;
using Verse; using Verse;
using rjw;
namespace RJWSexperience.Ideology namespace RJWSexperience.Ideology
{ {
public class RitualOutcomeComp_HediffBased : RitualOutcomeComp_QualitySingleOffset public class RitualOutcomeComp_HediffBased : RitualOutcomeComp_QualitySingleOffset
{ {
HediffDef hediffDef = null; [SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
float minSeverity = 0; public HediffDef hediffDef = null;
string roleId = ""; [SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public float minSeverity = 0;
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public string roleId = "";
protected override string LabelForDesc => label; protected override string LabelForDesc => label;
public override bool DataRequired => false; public override bool DataRequired => false;
public override bool Applies(LordJob_Ritual ritual) public override bool Applies(LordJob_Ritual ritual)
{ {
Pawn victim = null; Pawn victim = null;
foreach(RitualRole ritualRole in ritual.assignments.AllRolesForReading) foreach (RitualRole ritualRole in ritual.assignments.AllRolesForReading)
{ {
if (ritualRole != null && ritualRole.id.Contains(roleId)) if (ritualRole?.id.Contains(roleId) == true)
{ {
victim = ritual.assignments.FirstAssignedPawn(ritualRole); victim = ritual.assignments.FirstAssignedPawn(ritualRole);
} }
@ -39,8 +36,6 @@ namespace RJWSexperience.Ideology
return false; return false;
} }
public override ExpectedOutcomeDesc GetExpectedOutcomeDesc(Precept_Ritual ritual, TargetInfo ritualTarget, RitualObligation obligation, RitualRoleAssignments assignments, RitualOutcomeComp_Data data) public override ExpectedOutcomeDesc GetExpectedOutcomeDesc(Precept_Ritual ritual, TargetInfo ritualTarget, RitualObligation obligation, RitualRoleAssignments assignments, RitualOutcomeComp_Data data)
{ {
return new ExpectedOutcomeDesc return new ExpectedOutcomeDesc
@ -53,13 +48,14 @@ namespace RJWSexperience.Ideology
positive = true positive = true
}; };
} }
} }
public class RitualOutcomeComp_NeedBased : RitualOutcomeComp_QualitySingleOffset public class RitualOutcomeComp_NeedBased : RitualOutcomeComp_QualitySingleOffset
{ {
NeedDef needDef = null; [SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
float minAvgNeed = 0; public NeedDef needDef = null;
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public float minAvgNeed = 0;
protected override string LabelForDesc => label; protected override string LabelForDesc => label;
public override bool DataRequired => false; public override bool DataRequired => false;
@ -71,9 +67,7 @@ namespace RJWSexperience.Ideology
avgNeed += pawn.needs?.TryGetNeed(needDef)?.CurLevel ?? 0f; avgNeed += pawn.needs?.TryGetNeed(needDef)?.CurLevel ?? 0f;
} }
avgNeed /= ritual.assignments.AllPawns.Count; avgNeed /= ritual.assignments.AllPawns.Count;
if (avgNeed >= minAvgNeed) return true; return avgNeed >= minAvgNeed;
return false;
} }
public override ExpectedOutcomeDesc GetExpectedOutcomeDesc(Precept_Ritual ritual, TargetInfo ritualTarget, RitualObligation obligation, RitualRoleAssignments assignments, RitualOutcomeComp_Data data) public override ExpectedOutcomeDesc GetExpectedOutcomeDesc(Precept_Ritual ritual, TargetInfo ritualTarget, RitualObligation obligation, RitualRoleAssignments assignments, RitualOutcomeComp_Data data)
@ -89,7 +83,4 @@ namespace RJWSexperience.Ideology
}; };
} }
} }
} }

View file

@ -1,49 +1,54 @@
using System; using RimWorld;
using System.Collections.Generic; using System;
using System.Linq; using System.Diagnostics.CodeAnalysis;
using System.Text;
using System.Threading.Tasks;
using rjw;
using RimWorld;
using Verse; using Verse;
namespace RJWSexperience.Ideology namespace RJWSexperience.Ideology
{ {
public class StatPart_GenderPrimacy : StatPart public class StatPart_GenderPrimacy : StatPart
{ {
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public float modifier; public float modifier;
public override string ExplanationPart(StatRequest req) public override string ExplanationPart(StatRequest req)
{ {
Pawn pawn = req.Thing as Pawn; if (!req.HasThing || !(req.Thing is Pawn pawn))
Ideo ideo = null; return null;
if (pawn != null) ideo = pawn.Ideo;
Ideo ideo = pawn.Ideo;
float fact = 1f; float fact = 1f;
if (ideo != null && !ideo.memes.NullOrEmpty()) for (int i = 0; i < ideo.memes.Count; i++) if (ideo?.memes.NullOrEmpty() == false)
{
for (int i = 0; i < ideo.memes.Count; i++)
{ {
if (ideo.memes[i] == MemeDefOf.MaleSupremacy) if (ideo.memes[i] == MemeDefOf.MaleSupremacy)
{ {
if (pawn.gender == Gender.Male) fact = modifier; if (pawn.gender == Gender.Male) fact = modifier;
else if (pawn.gender == Gender.Female) fact = 1/modifier; else if (pawn.gender == Gender.Female) fact = 1 / modifier;
break; break;
} }
else if (ideo.memes[i] == MemeDefOf.FemaleSupremacy) else if (ideo.memes[i] == MemeDefOf.FemaleSupremacy)
{ {
if (pawn.gender == Gender.Male) fact = 1/modifier; if (pawn.gender == Gender.Male) fact = 1 / modifier;
else if (pawn.gender == Gender.Female) fact = modifier; else if (pawn.gender == Gender.Female) fact = modifier;
break; break;
} }
} }
}
return Keyed.MemeStatFactor(String.Format("{0:0.##}", fact * 100)); return Keyed.MemeStatFactor(String.Format("{0:0.##}", fact * 100));
} }
public override void TransformValue(StatRequest req, ref float val) public override void TransformValue(StatRequest req, ref float val)
{ {
Pawn pawn = req.Thing as Pawn; if (!req.HasThing || !(req.Thing is Pawn pawn))
Ideo ideo = null; return;
if (pawn != null) ideo = pawn.Ideo;
if (ideo != null && !ideo.memes.NullOrEmpty()) for(int i=0; i< ideo.memes.Count; i++) Ideo ideo = pawn.Ideo;
if (ideo?.memes.NullOrEmpty() == false)
{
for (int i = 0; i < ideo.memes.Count; i++)
{ {
if (ideo.memes[i] == MemeDefOf.MaleSupremacy) if (ideo.memes[i] == MemeDefOf.MaleSupremacy)
{ {
@ -51,16 +56,14 @@ namespace RJWSexperience.Ideology
else if (pawn.gender == Gender.Female) val /= modifier; else if (pawn.gender == Gender.Female) val /= modifier;
break; break;
} }
else if(ideo.memes[i] == MemeDefOf.FemaleSupremacy) else if (ideo.memes[i] == MemeDefOf.FemaleSupremacy)
{ {
if (pawn.gender == Gender.Male) val /= modifier; if (pawn.gender == Gender.Male) val /= modifier;
else if (pawn.gender == Gender.Female) val *= modifier; else if (pawn.gender == Gender.Female) val *= modifier;
break; break;
} }
} }
} }
} }
}
} }

View file

@ -18,7 +18,7 @@ namespace RJWSexperience.Ideology
base.ThoughtInterval(); base.ThoughtInterval();
if (recordIncrement != 0) if (recordIncrement != 0)
{ {
pawn.records.AddTo(recordDef, recordIncrement); pawn.records.AddTo(RecordDef, recordIncrement);
recordIncrement = 0; recordIncrement = 0;
} }
} }

View file

@ -1,5 +1,6 @@
using RimWorld; using RimWorld;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
namespace RJWSexperience.Ideology namespace RJWSexperience.Ideology
{ {
@ -8,6 +9,7 @@ namespace RJWSexperience.Ideology
/// </summary> /// </summary>
public class ThoughtDef_Opinionbased : ThoughtDef public class ThoughtDef_Opinionbased : ThoughtDef
{ {
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public List<float> minimumValueforStage = new List<float>(); public List<float> minimumValueforStage = new List<float>();
} }
@ -17,7 +19,7 @@ namespace RJWSexperience.Ideology
public class Thought_Opinionbased : Thought_Memory public class Thought_Opinionbased : Thought_Memory
{ {
protected ThoughtDef_Opinionbased Def => (ThoughtDef_Opinionbased)def; protected ThoughtDef_Opinionbased Def => (ThoughtDef_Opinionbased)def;
protected List<float> minimumValueforStage => Def.minimumValueforStage; protected List<float> MinimumValueforStage => Def.minimumValueforStage;
public override int CurStageIndex public override int CurStageIndex
{ {
@ -25,9 +27,9 @@ namespace RJWSexperience.Ideology
{ {
float value = 0f; float value = 0f;
if (otherPawn != null) value = pawn.relations?.OpinionOf(otherPawn) ?? 0f; if (otherPawn != null) value = pawn.relations?.OpinionOf(otherPawn) ?? 0f;
for (int i = minimumValueforStage.Count - 1; i > 0; i--) for (int i = MinimumValueforStage.Count - 1; i > 0; i--)
{ {
if (minimumValueforStage[i] < value) return i; if (MinimumValueforStage[i] < value) return i;
} }
return 0; return 0;
} }

View file

@ -1,5 +1,6 @@
using RimWorld; using RimWorld;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
namespace RJWSexperience.Ideology namespace RJWSexperience.Ideology
{ {
@ -8,8 +9,11 @@ namespace RJWSexperience.Ideology
/// </summary> /// </summary>
public class ThoughtDef_Recordbased : ThoughtDef public class ThoughtDef_Recordbased : ThoughtDef
{ {
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public RecordDef recordDef; public RecordDef recordDef;
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public List<float> minimumValueforStage = new List<float>(); public List<float> minimumValueforStage = new List<float>();
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public float increment; public float increment;
} }
@ -19,17 +23,17 @@ namespace RJWSexperience.Ideology
public class Thought_Recordbased : Thought_Memory public class Thought_Recordbased : Thought_Memory
{ {
protected ThoughtDef_Recordbased Def => (ThoughtDef_Recordbased)def; protected ThoughtDef_Recordbased Def => (ThoughtDef_Recordbased)def;
protected RecordDef recordDef => Def.recordDef; protected RecordDef RecordDef => Def.recordDef;
protected List<float> minimumValueforStage => Def.minimumValueforStage; protected List<float> MinimumValueforStage => Def.minimumValueforStage;
public override int CurStageIndex public override int CurStageIndex
{ {
get get
{ {
float value = pawn?.records?.GetValue(recordDef) ?? 0f; float value = pawn?.records?.GetValue(RecordDef) ?? 0f;
for (int i = minimumValueforStage.Count - 1; i > 0; i--) for (int i = MinimumValueforStage.Count - 1; i > 0; i--)
{ {
if (minimumValueforStage[i] < value) return i + 1; if (MinimumValueforStage[i] < value) return i + 1;
} }
return 0; return 0;
} }

View file

@ -1,13 +1,10 @@
using System; using RimWorld;
using rjw;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks;
using Verse;
using RimWorld;
using UnityEngine; using UnityEngine;
using rjw; using Verse;
namespace RJWSexperience.UI namespace RJWSexperience.UI
{ {
@ -19,7 +16,6 @@ namespace RJWSexperience.UI
public const float BASESAT = 0.40f; public const float BASESAT = 0.40f;
public const float ICONSIZE = 30f; public const float ICONSIZE = 30f;
public static void DrawQuirk(this Rect rect, Pawn pawn) public static void DrawQuirk(this Rect rect, Pawn pawn)
{ {
List<Quirk> quirks = Quirk.All.FindAll(x => pawn.Has(x)); List<Quirk> quirks = Quirk.All.FindAll(x => pawn.Has(x));
@ -73,17 +69,16 @@ namespace RJWSexperience.UI
public static void DrawBorder(this Rect rect, Texture border, float thickness = 1f) public static void DrawBorder(this Rect rect, Texture border, float thickness = 1f)
{ {
GUI.DrawTexture(new Rect(rect.x,rect.y,rect.width, thickness), border); GUI.DrawTexture(new Rect(rect.x, rect.y, rect.width, thickness), border);
GUI.DrawTexture(new Rect(rect.x+rect.width-thickness,rect.y, thickness, rect.height), border); GUI.DrawTexture(new Rect(rect.x + rect.width - thickness, rect.y, thickness, rect.height), border);
GUI.DrawTexture(new Rect(rect.x,rect.y+rect.height - thickness,rect.width, thickness), border); GUI.DrawTexture(new Rect(rect.x, rect.y + rect.height - thickness, rect.width, thickness), border);
GUI.DrawTexture(new Rect(rect.x, rect.y, thickness, rect.height), border); GUI.DrawTexture(new Rect(rect.x, rect.y, thickness, rect.height), border);
} }
public static string GetStatExplanation(Pawn pawn, StatDef stat, float val) public static string GetStatExplanation(Pawn pawn, StatDef stat, float val)
{ {
if (!pawn.Dead) if (!pawn.Dead)
return stat.description + "\n" + return stat.description + "\n" + stat.Worker.GetExplanationFull(StatRequest.For(pawn), ToStringNumberSense.Undefined, val);
stat.Worker.GetExplanationFull(StatRequest.For(pawn), ToStringNumberSense.Undefined, val);
return "Dead".Translate(); return "Dead".Translate();
} }
@ -93,6 +88,5 @@ namespace RJWSexperience.UI
else if (printUnknown) return Keyed.Unknown; else if (printUnknown) return Keyed.Unknown;
else return ""; else return "";
} }
} }
} }