public virtual AvaliPack GetPack(Pawn pawn) { AvaliPack pack = null; pack = RimValiUtility.GetPack(pawn); return(pack); }
public static SkillRecord GetHighestSkillOfpack(Pawn pawn) { AvaliPack pack = GetPack(pawn); if (pack != null) { return(GetHighestSkillOfpack(pack)); } return(null); }
public static float GetPackAvgOP(AvaliPack pack, Pawn pawn) { List <float> opinions = new List <float>(); foreach (Pawn packmember in pack.pawns) { opinions.Add(packmember.relations.OpinionOf(pawn)); } return(Queryable.Average(opinions.AsQueryable())); }
public static AvaliPack JoinPack(Pawn pawn, AvaliPack pack, int reqOpinionPawn = 30, int reqOpionionPack = 30) { pack.pawns.Add(pawn); pack.size++; /*if (enableDebug) * { * Log.Message("Pawn: " + pawn.Name.ToStringShort + " joined " + pack.name); * }*/ return(pack); }
public static AvaliPack GetPackWithoutSelf(this Pawn pawn) { AvaliPackDriver AvaliPackDriver = Current.Game.GetComponent <AvaliPackDriver>(); if (pawn == null) { if (RimValiMod.settings.enableDebugMode) { Log.Error("Pawn check is null!"); } return(null); } if (AvaliPackDriver.packs == null || AvaliPackDriver.packs.Count == 0) { if (RimValiMod.settings.enableDebugMode) { Log.Message("No packs"); } return(null); } //We really should be getting here if (AvaliPackDriver.packs.Count > 0) { foreach (AvaliPack APack in AvaliPackDriver.packs) { //Checks if somehow a pack has 0 pawns (never should happen), then checks if the pawn is in it. if (APack.pawns.Count > 0) { if (APack.pawns.Contains(pawn)) { AvaliPack returnPack = new AvaliPack(APack.faction); returnPack.pawns.AddRange(APack.pawns); returnPack.pawns.Remove(pawn); //returnPack.size = APack.size; returnPack.deathDates.AddRange(APack.deathDates); returnPack.creationDate = APack.creationDate; return(returnPack); } } } } else { return(null); } //If somehow nothing worked, just return null. /*if (enableDebug) * { * Log.Message("Didn't find pack, returning null."); * }*/ return(null); }
public static AvaliPack EiCreatePack(Pawn pawn) { AvaliPackDriver AvaliPackDriver = Current.Game.GetComponent <AvaliPackDriver>(); AvaliPack PawnPack = new AvaliPack(pawn.Faction); PawnPack.name = pawn.Name.ToStringShort + "'s pack"; if (RimValiMod.settings.enableDebugMode) { Log.Message("Creating pack: " + PawnPack.name); } PawnPack.pawns.Add(pawn); return(PawnPack); }
public static AvaliPack EiCreatePack(Pawn pawn) { /*if (enableDebug) * { * Log.Message("No packs, creating new from pawn: " + pawn.Name.ToStringShort); * }*/ AvaliPack PawnPack = new AvaliPack(); PawnPack.name = pawn.Name.ToStringShort + "'s pack"; Log.Message("Creating pack: " + PawnPack.name); PawnPack.size = 1; PawnPack.faction = pawn.Faction; PawnPack.pawns.Add(pawn); return(PawnPack); }
public static List <AvaliPack> EiPackHandler(List <AvaliPack> packs, Pawn pawn, IEnumerable <ThingDef> racesInPacks, int packLimit) { void createPack() { Log.Message("Creating pack for pawn.."); packs.Add(EiCreatePack(pawn)); } //Log.Message(pawn.Name.ToStringShort); //Log.Message(pawn.Faction.Name); if (packs.Count > 0) { if (!pawn.Spawned) { return(packs); } List <AvaliPack> packsToUse = packs.Where <AvaliPack>(x => x.faction == pawn.Faction).ToList(); if (packsToUse.Count <= 0) { AvaliPack newPack = EiCreatePack(pawn); //Log.Message(newPack.name); packs.Add(newPack); } foreach (AvaliPack pack in packsToUse) { if (pack.pawns.Contains(pawn)) { break; } if (pack.size < packLimit) { Log.Message("Attempting to join pack: " + pack.name + " with " + pawn.Name.ToStringShort); JoinPack(pawn, pack); break; } else { createPack(); return(packs); } } } else { createPack(); } return(packs); }
public void UpdatePawns(Map map) { AvaliPackDriver AvaliPackDriver = Current.Game.GetComponent <AvaliPackDriver>(); IEnumerable <Pawn> pawns = RimValiUtility.CheckAllPawnsInMapAndFaction(map, Faction.OfPlayer).Where(x => AvaliPackDriver.racesInPacks.Contains(x.def)); IEnumerable <AvaliPack> packs = AvaliPackDriver.packs; foreach (Pawn pawn in pawns) { AvaliThoughtDriver avaliThoughtDriver = pawn.TryGetComp <AvaliThoughtDriver>(); PackComp packComp = pawn.TryGetComp <PackComp>(); if (!(avaliThoughtDriver == null)) { //Log.Message("Pawn has pack comp, moving to next step..."); if (AvaliPackDriver.packs == null || AvaliPackDriver.packs.Count == 0) { //Log.Message("How did we get here? [Pack list was 0 or null]"); return; } AvaliPack pawnPack = null; //This errors out when pawns dont have a pack, in rare cases. That is bad. This stops it from doing that. try { pawnPack = pawn.GetPack(); } catch { return; } //Log.Message("Tried to get packs pack, worked."); if (pawnPack == null) { //Log.Message("How did we get here? [Pack was null.]"); break; } foreach (Pawn packmate in pawnPack.pawns) { Thought_Memory thought_Memory2 = (Thought_Memory)ThoughtMaker.MakeThought(packComp.Props.togetherThought); if (!(packmate == pawn) && packmate != null && pawn != null) { bool bubble; if (!thought_Memory2.TryMergeWithExistingMemory(out bubble)) { //Log.Message("Adding thought to pawn."); pawn.needs.mood.thoughts.memories.TryGainMemory(thought_Memory2, packmate); } } } } } }
public static bool CheckIfPackmatesInRoom(Pawn pawn) { Room room = pawn.GetRoom(); if (!(room == null) && (pawn.Position.Roofed(pawn.Map))) { AvaliPack pack = GetPackWithoutSelf(pawn); foreach (Pawn packmate in pack.pawns) { if (packmate.GetRoom() == room) { return(true); } } return(false); } return(false); }
public static bool CheckIfPackmatesInRoom(this Pawn pawn) => ((Func <bool>) delegate { Room room = pawn.GetRoom(); if (room != null && pawn.Position.Roofed(pawn.Map)) { AvaliPack pack = GetPackWithoutSelf(pawn); if (pack != null) { foreach (Pawn p in pack.pawns) { if (p.GetRoom() == room) { return(true); } } } } return(false); })();
public static SkillRecord GetHighestSkillOfpack(AvaliPack pack, List <SkillDef> avoidSkills) { int highestSkillLevel = 0; SkillRecord highestSkill = null; foreach (Pawn pawn in pack.pawns) { List <SkillRecord> list = new List <SkillRecord>(); foreach (SkillRecord skillRecord in pawn.skills.skills.Where(SkillRec => !avoidSkills.Contains(SkillRec.def))) { if (skillRecord.Level > highestSkillLevel) { highestSkillLevel = skillRecord.Level; highestSkill = skillRecord; } } } return(highestSkill); }
public static AvaliPack JoinPack(Pawn pawn, ref AvaliPack pack) { Date date = new Date(); AvaliPackDriver AvaliPackDriver = Current.Game.GetComponent <AvaliPackDriver>(); if (!AvaliPackDriver.pawnsHaveHadPacks.ContainsKey(pawn) || !AvaliPackDriver.pawnsHaveHadPacks[pawn] && date.ToString() == pack.creationDate.ToString()) { pack.pawns.Add(pawn); return(pack); } else { if (GetPackAvgOP(pack, pawn) >= LoadedModManager.GetMod <RimValiMod>().GetSettings <RimValiModSettings>().packOpReq) { pack.pawns.Add(pawn); return(pack); } } return(pack); }
public static SkillRecord GetHighestSkillOfpack(AvaliPack pack) { int highestSkillLevel = 0; SkillRecord highestSkill = null; foreach (Pawn pawn in pack.pawns) { List <SkillRecord> list = new List <SkillRecord>(); foreach (SkillRecord skillRecord in pawn.skills.skills) { list.Add(skillRecord); foreach (SkillRecord skill in list) { if (skill.Level > highestSkillLevel) { highestSkillLevel = skill.Level; highestSkill = skill; } } } } return(highestSkill); }
public static bool PackInBedroom(this Pawn pawn) { int packmatesInRoom = 0; Room room = pawn.GetRoom(); AvaliPack avaliPack = pawn.GetPackWithoutSelf(); if (room != null && avaliPack != null && room.ContainedBeds.Count() > 0) { IEnumerable <Building_Bed> beds = room.ContainedBeds; if (beds.Count() < 2) { return(false); } foreach (Building_Bed bed in beds) { if (bed.OwnersForReading != null) { foreach (Pawn other in bed.OwnersForReading) { if (avaliPack.pawns.Contains(other)) { packmatesInRoom += 1; } } } } } if (packmatesInRoom > 0) { return(true); } else { return(false); } }
// Token: 0x06000035 RID: 53 RVA: 0x0000408C File Offset: 0x0000308C protected override void FillTab() { Rect rect = new Rect(0f, 0f, this.WinSize.x, this.WinSize.y).ContractedBy(10f); Text.Font = GameFont.Small; this.oldColor = GUI.color; AvaliPack pawnPack = null; List <AvaliPack> packs = AvaliPackDriver.packs; Pawn pawn = this.SelPawn; foreach (AvaliPack pack in packs) { if (pack.pawns.Contains(pawn)) { pawnPack = pack; break; } } if (pawnPack == null) { this.NotInPack(rect); return; } List <Pawn> list = pawnPack.pawns; int num = pawnPack.size; if (num < 2 || list == null) { this.NotInPack(rect); return; } if (pawn == null) { pawn = base.SelPawn; } Rect rect2 = new Rect(0f, 20f, this.WinSize.x, 42f).ContractedBy(10f); this.DrawLineHorizontalWithColor(10f, 52f, this.WinSize.x - 20f, Color.gray); Rect rect3 = new Rect(0f, 44f, this.WinSize.x, 42f).ContractedBy(10f); ITab_Avali_Pack.NewRect(rect3, "PackLeader".Translate(), pawn.Name.ToString(), rect3, "PackLeaderDesc".Translate()); Rect rect4 = new Rect(0f, 68f, this.WinSize.x, 42f).ContractedBy(10f); string text = base.SelPawn.Name.ToString(); int num2 = 1; for (int j = 0; j < list.Count; j++) { Pawn pawn3 = list[j]; if (pawn3 != base.SelPawn) { text = text + "\n" + pawn3.Name; num2++; } } ITab_Avali_Pack.NewRect(rect4, "PackMembers".Translate(), num2 + "/" + num, rect4, text); if (base.SelPawn.IsColonist || Prefs.DevMode) { this.DrawLineHorizontalWithColor(10f, 148f, this.WinSize.x - 20f, Color.gray); Rect rect5 = new Rect(0f, 116f, this.WinSize.x, 42f).ContractedBy(10f); float num3 = 30f * base.SelPawn.health.capacities.GetLevel(PawnCapacityDefOf.Hearing); ITab_Avali_Pack.NewRect(rect5, "PackEffects".Translate(), "", rect5, string.Format("PackEffectsDesc".Translate(), (int)num3)); float num4 = 140f; num4 = 140f; } }
protected override void FillTab() { Text.Font = GameFont.Small; Rect rect = new Rect(0f, 20f, this.size.x, this.size.y - 20f).ContractedBy(10f); Rect position = new Rect(rect.x, rect.y, rect.width, rect.height); GUI.BeginGroup(position); Text.Font = GameFont.Small; GUI.color = Color.white; Rect outRect = new Rect(0f, 0f, position.width, position.height); Rect viewRect = new Rect(0f, 0f, position.width - 16f, this.scrollViewHeight); Widgets.BeginScrollView(outRect, ref this.scrollPosition, viewRect, true); Pawn pawn = SelPawn; AvaliPack pack = null; float rectPosY = 0f; pack = this.GetPack(pawn); if (!(pack == null) && pack.size > 1) { string members = "Packmates".Translate(); int onItem = 0; foreach (Pawn packmember in pack.pawns) { if ((onItem + 1) >= pack.pawns.Count) { members = members + packmember.Name.ToStringShort + ". "; } else { members = members + packmember.Name.ToStringShort + ", "; } onItem++; } Text.Font = GameFont.Medium; Rect PackNameRect = new Rect(outRect.xMin, rectPosY, 500f, 30f); Widgets.Label(PackNameRect, GetPackName(rect, pack)); Rect RenameButtonRect = new Rect(outRect.xMax - 30f, rectPosY, 30f, 30f); if (Widgets.ButtonImage(RenameButtonRect, UIResources.Rename, true)) { Find.WindowStack.Add(new Dialog_NamePack(pawn)); } Widgets.DrawLineHorizontal(0f, (PackNameRect.yMax + 10f), rect.width); Text.Font = GameFont.Small; rectPosY = PackNameRect.yMax + 10f; rectPosY += 20f; Rect PackMemberCountRect = new Rect(outRect.xMax - 40f, rectPosY, 40f, 30f); string packcount = pack.size.ToString() + "/" + maxSize.ToString(); Widgets.Label(PackMemberCountRect, packcount); Rect PackMemberListRect = new Rect(outRect.xMin, rectPosY, 500f, outRect.height); Rect PackMemberListViewRect = new Rect(outRect.xMin, rectPosY, 480f, pack.pawns.Count * 30f); Widgets.BeginScrollView(PackMemberListRect, ref membersScrollPos, PackMemberListViewRect, true); float num = rectPosY; float y = membersScrollPos.y; float num2 = membersScrollPos.y + PackMemberListRect.height; for (int i = 0; i < pack.pawns.Count; i++) { float rowHeight = 30f; if (num > y - rowHeight && num < num2) { DrawMemberRow(num, PackMemberListRect.width, pack.pawns[i]); } num += rowHeight; } Widgets.EndScrollView(); } else { Widgets.Label(rect, "NoPack".Translate()); //Log.Message("Pack list size: " + AvaliPackDriver.packs.Count); Widgets.EndScrollView(); } //Widgets.Label(rect, "test"); Widgets.EndScrollView(); GUI.EndGroup(); }
public virtual string GetPackName(Rect rect, AvaliPack pack) { return(pack.name); }
/// <summary> /// Handles the job of managing pack related functions, such as creating packs for a pawn, making a pawn join packs, etc. /// </summary> /// <param name="packs"></param> /// <param name="pawn"></param> /// <param name="racesInPacks"></param> /// <param name="packLimit"></param> /// <returns></returns> public static List <AvaliPack> EiPackHandler(List <AvaliPack> packs, Pawn pawn, IEnumerable <ThingDef> racesInPacks, int packLimit) { AvaliPackDriver AvaliPackDriver = Current.Game.GetComponent <AvaliPackDriver>(); void createPack(string reason = null) { AvaliPack newPack = EiCreatePack(pawn); if (!AvaliPackDriver.packs.Contains(newPack)) { packs.Add(newPack); } if (reason != null) { if (RimValiMod.settings.enableDebugMode) { Log.Message($"Creating pack for reason: {reason}"); } } } //We only want to run this if there are packs, otherwise we'll automatically make a "base" pack. if (packs.Count > 0) { //If the pawn isn't spawned, we don't care. if (!pawn.Spawned) { return(packs); } IEnumerable <AvaliPack> packsToUse = packs.Where <AvaliPack>(x => x.faction == pawn.Faction && x.pawns.Any(p => p.Map == pawn.Map)); if (packsToUse.Count() <= 0) { createPack("packs is less than or equal to zero"); } AvaliPack pack = pawn.GetPack(); //This checks if a pack only has one pawn or if it is null, and also if we can join a random pack. if (((pack != null && !pack.pawns.NullOrEmpty() && pack.pawns.Count == 1) || pack == null) && packsToUse.Any(p => p != pack && p.pawns.Count < packLimit)) { AvaliPack pack2 = packsToUse.Where(p => p.pawns.Count < packLimit).RandomElement(); if (pack2 != null && pack2.pawns.Count < packLimit) { //If we did have a previous pack, just remove it. It's not needed anymore. if (pack != null) { AvaliPackDriver.packs.Remove(pack); } JoinPack(pawn, ref pack2); } } //If we get here, we'll create a new pack. else if (!(pack != null && !pack.pawns.NullOrEmpty() && !(pack.pawns.Count == 1))) { createPack("No pack for pawn"); if (RimValiMod.settings.enableDebugMode) { Log.Message((!(pack != null && !pack.pawns.NullOrEmpty() && !(pack.pawns.Count == 1))).ToString()); } } } else { createPack("No packs in list"); } //Avoids pawns with double packs pawn.CleanupPacks(); //Does pack boosts foreach (AvaliPack pack in AvaliPackDriver.packs.Where(p => p.pawns.Count > 1)) { if (RimValiMod.settings.enableDebugMode) { Log.Message("Updating pack hediffs"); } pack.UpdateHediffForAllMembers(); } //This automatically updates if a pawn can join a pack without opinion and pack loss. pawn.UpdatePackAvailibilty(); return(packs); }