//=================================== COMPACTIVATABLE // Verse.Pawn_EquipmentTracker public static void TryDropEquipment_PreFix(Pawn_EquipmentTracker __instance, ThingWithComps eq) { Pawn_EquipmentTracker pawn_EquipmentTracker = __instance; if (pawn_EquipmentTracker != null) { //Log.Message("2"); //ThingWithComps thingWithComps = (ThingWithComps)AccessTools.Field(typeof(Pawn_EquipmentTracker), "primaryInt").GetValue(pawn_EquipmentTracker); ThingWithComps thingWithComps = pawn_EquipmentTracker.Primary; if (thingWithComps != null) { //Log.Message("3"); CompActivatableEffect compActivatableEffect = thingWithComps.GetComp <CompActivatableEffect>(); if (compActivatableEffect != null) { if (compActivatableEffect.CurrentState == CompActivatableEffect.State.Activated) { compActivatableEffect.Deactivate(); } } } } }
public static void AddEquipment_PostFix(Pawn_EquipmentTracker __instance, ThingWithComps newEq) { Pawn pawn = (Pawn)AccessTools.Field(typeof(Pawn_EquipmentTracker), "pawn").GetValue(__instance); CompLightsaberActivatableEffect lightsaberEffect = newEq.TryGetComp <CompLightsaberActivatableEffect>(); if (lightsaberEffect != null) { if (pawn != null) { if (pawn.Faction != null) { if (pawn.Faction != Faction.OfPlayerSilentFail) { CompCrystalSlotLoadable crystalSlot = newEq.GetComp <CompCrystalSlotLoadable>(); if (crystalSlot != null) { CrystalSlotter(crystalSlot, lightsaberEffect); } } } } } }
static void Postfix(VerbProperties __instance, ref Thing equipment, ref float __result) { if (equipment == null || equipment.holdingOwner == null || !(equipment.holdingOwner.Owner is Pawn_EquipmentTracker)) { return; } if (equipment == null || equipment.holdingOwner == null || equipment.holdingOwner.Owner == null) { return; } Pawn_EquipmentTracker eqt = (Pawn_EquipmentTracker)equipment.holdingOwner.Owner; Pawn pawn = Traverse.Create(eqt).Field("pawn").GetValue <Pawn>(); if (pawn == null || pawn.stances == null) { return; } if (pawn.stances.curStance is Stance_RunAndGun || pawn.stances.curStance is Stance_RunAndGun_Cooldown) { int value = Base.accuracyPenalty.Value; float factor = ((float)(100 - value) / 100); __result *= factor; } }
// Token: 0x06000022 RID: 34 RVA: 0x00003818 File Offset: 0x00001A18 public static bool TryGetOffHandEquipment(this Pawn_EquipmentTracker instance, out ThingWithComps result) { result = null; bool result2; if (instance.pawn.HasMissingArmOrHand()) { result2 = false; } else { ExtendedDataStorage extendedDataStorage = Base.Instance.GetExtendedDataStorage(); foreach (ThingWithComps thingWithComps in instance.AllEquipmentListForReading) { if (extendedDataStorage.TryGetExtendedDataFor(thingWithComps, out ExtendedThingWithCompsData extendedThingWithCompsData) && extendedThingWithCompsData.isOffHand) { result = thingWithComps; return(true); } } result2 = false; } return(result2); }
public static void GetGizmosPrefix(Pawn __instance, ref IEnumerable <Gizmo> __result) { //Log.Message("1"); Pawn_EquipmentTracker pawn_EquipmentTracker = __instance.equipment; if (pawn_EquipmentTracker != null) { //Log.Message("2"); //ThingWithComps thingWithComps = (ThingWithComps)AccessTools.Field(typeof(Pawn_EquipmentTracker), "primaryInt").GetValue(pawn_EquipmentTracker); ThingWithComps thingWithComps = pawn_EquipmentTracker.Primary; if (thingWithComps != null) { //Log.Message("3"); CompActivatableEffect compActivatableEffect = thingWithComps.GetComp <CompActivatableEffect>(); if (compActivatableEffect != null) { //Log.Message("4"); if (__instance != null) { if (__instance.Faction == Faction.OfPlayer) { __result = __result.Concat <Gizmo>(GizmoGetter(compActivatableEffect)); } else { if (compActivatableEffect.CurrentState == CompActivatableEffect.State.Deactivated) { compActivatableEffect.Activate(); } } } } } } }
internal static bool TryTransferEquipmentToContainer(this Pawn_EquipmentTracker _this, ThingWithComps eq, ThingContainer container, out ThingWithComps resultingEq) { // Fetch private fields Pawn pawn = (Pawn)pawnFieldInfo.GetValue(_this); ThingWithComps primaryInt = (ThingWithComps)primaryIntFieldInfo.GetValue(_this); if (!_this.AllEquipment.Contains(eq)) { Log.Warning(pawn.LabelCap + " tried to transfer equipment he didn't have: " + eq); resultingEq = null; return(false); } if (container.TryAdd(eq)) { resultingEq = null; } else { resultingEq = eq; } if (primaryInt == eq) { primaryIntFieldInfo.SetValue(_this, null); // Changed assignment to SetValue() since we're fetching a private variable through reflection } pawn.meleeVerbs.Notify_EquipmentLost(); Utility.TryUpdateInventory(pawn); // Equipment was stored away, update inventory // Cancel current job (use verb, etc.) if (pawn.Spawned) { pawn.stances.CancelBusyStanceSoft(); } return(resultingEq == null); }
public static Job TryGiveJobStatic(Pawn pawn, bool inCombat) { if (RestraintsUtility.InRestraints(pawn)) { return(null); } { //SetNextTryTick(pawn, Find.TickManager.TicksGame + UnityEngine.Random.Range(PickupCheckIntervalMin, PickupCheckIntervalMax)); Pawn_EquipmentTracker equipment = pawn.equipment; if (equipment == null) { return(null); } GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(pawn); if (pawnMemory == null) { return(null); } WeaponAssingment.reequipPrimaryIfNeededAndAvailable(pawn, pawnMemory); foreach (string wepName in pawnMemory.weapons) { ThingDef def = DefDatabase <ThingDef> .GetNamedSilentFail(wepName); if (def == null) { continue; } if (!pawn.hasWeaponSomewhere(wepName)) { float maxDist = 1000f; if (pawn.Faction != Faction.OfPlayer || inCombat) { maxDist = 30f; } List <Thing> matchingWeapons = pawn.Map.listerThings.ThingsOfDef(def); Thing thing = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, matchingWeapons, PathEndMode.OnCell, TraverseParms.For(pawn), maxDist, (Thing t) => !t.IsForbidden(pawn) && pawn.CanReserve(t), (Thing t) => SimpleSidearms.ReEquipBest ? t.GetStatValue(StatDefOf.MeleeWeapon_AverageDPS, false) : 0); if (thing == null) { continue; } if (!inCombat) { return(new Job(SidearmsDefOf.EquipSecondary, thing)); } else { return(new Job(SidearmsDefOf.EquipSecondaryCombat, thing, pawn.Position)); } } } return(null); } }
public static void ShieldPatchAddEquipment(Pawn_EquipmentTracker __instance, ThingWithComps newEq) { Pawn owner = __instance.pawn; // must have picked up a weapon if (PawnHasShieldEquiped(owner) || PawnHasShieldInInventory(owner)) { if (newEq.def.IsWeapon) { if (PawnHasValidEquipped(owner) && PawnHasShieldInInventory(owner)) { for (int i = 0; i < owner.inventory.innerContainer.Count; i++) { if (owner.inventory.innerContainer[i].def.thingCategories == null) { continue; } foreach (ThingCategoryDef ApparelItem in owner.inventory.innerContainer[i].def.thingCategories) { if (ApparelItem.defName == "Shield") { Thing whocares; __instance.pawn.inventory.innerContainer.TryDrop(owner.inventory.innerContainer[i], ThingPlaceMode.Direct, out whocares, null, null); owner.apparel.Wear(whocares as Apparel); } } } } else { if (PawnHasShieldEquiped(owner) && !PawnHasValidEquipped(owner)) { Apparel shield = null; // do we have a shield equipped for (int i = 0; i < owner.inventory.innerContainer.Count; i++) { if (owner.inventory.innerContainer[i].def.thingCategories == null) { continue; } foreach (ThingCategoryDef ApparelItem in owner.inventory.innerContainer[i].def.thingCategories) { if (ApparelItem.defName == "Shield") { Thing whocares; __instance.pawn.inventory.innerContainer.TryDrop(owner.inventory.innerContainer[i], ThingPlaceMode.Direct, out whocares, null, null); } } } for (int i = 0; i < owner.apparel.WornApparelCount; i++) { if (owner.apparel.WornApparel[i].def.thingCategories == null) { continue; } foreach (ThingCategoryDef ApparelItem in owner.apparel.WornApparel[i].def.thingCategories) { if (ApparelItem.defName == "Shield") { shield = owner.apparel.WornApparel[i]; } } } // we have a shield equipped if (shield != null) { owner.apparel.Remove(shield); owner.inventory.innerContainer.TryAddOrTransfer(shield, false); } } } } } }
///// <summary> ///// Prevents the user from having damage with the verb. ///// </summary> ///// <param name="__instance"></param> ///// <param name="__result"></param> ///// <param name="pawn"></param> //public static void GetDamageFactorForPostFix(Verb __instance, ref float __result, Pawn pawn) //{ // Pawn_EquipmentTracker pawn_EquipmentTracker = pawn.equipment; // if (pawn_EquipmentTracker != null) // { // //Log.Message("2"); // ThingWithComps thingWithComps = (ThingWithComps)AccessTools.Field(typeof(Pawn_EquipmentTracker), "primaryInt").GetValue(pawn_EquipmentTracker); // if (thingWithComps != null) // { // //Log.Message("3"); // CompActivatableEffect compActivatableEffect = thingWithComps.GetComp<CompActivatableEffect>(); // if (compActivatableEffect != null) // { // if (compActivatableEffect.CurrentState != CompActivatableEffect.State.Activated) // { // //Messages.Message("DeactivatedWarning".Translate(), MessageSound.RejectInput); // __result = 0f; // } // } // } // } //} /// <summary> /// Adds another "layer" to the equipment aiming if they have a /// weapon with a CompActivatableEffect. /// </summary> /// <param name="__instance"></param> /// <param name="eq"></param> /// <param name="drawLoc"></param> /// <param name="aimAngle"></param> public static void DrawEquipmentAimingPostFix(PawnRenderer __instance, Thing eq, Vector3 drawLoc, float aimAngle) { Pawn pawn = (Pawn)AccessTools.Field(typeof(PawnRenderer), "pawn").GetValue(__instance); Pawn_EquipmentTracker pawn_EquipmentTracker = pawn.equipment; if (pawn_EquipmentTracker != null) { //Log.Message("2"); //ThingWithComps thingWithComps = (ThingWithComps)AccessTools.Field(typeof(Pawn_EquipmentTracker), "primaryInt").GetValue(pawn_EquipmentTracker); ThingWithComps thingWithComps = pawn_EquipmentTracker.Primary; //(ThingWithComps)AccessTools.Field(typeof(Pawn_EquipmentTracker), "primaryInt").GetValue(pawn_EquipmentTracker); if (thingWithComps != null) { //Log.Message("3"); CompActivatableEffect compActivatableEffect = thingWithComps.GetComp <CompActivatableEffect>(); if (compActivatableEffect != null) { //Log.Message("4"); if (compActivatableEffect.Graphic != null) { if (compActivatableEffect.CurrentState == CompActivatableEffect.State.Activated) { float num = aimAngle - 90f; bool flip = false; if (aimAngle > 20f && aimAngle < 160f) { //mesh = MeshPool.GridPlaneFlip(thingWithComps.def.graphicData.drawSize); num += eq.def.equippedAngleOffset; } else if (aimAngle > 200f && aimAngle < 340f) { //mesh = MeshPool.GridPlane(thingWithComps.def.graphicData.drawSize); flip = true; num -= 180f; num -= eq.def.equippedAngleOffset; } else { //mesh = MeshPool.GridPlaneFlip(thingWithComps.def.graphicData.drawSize); num += eq.def.equippedAngleOffset; } if (eq is ThingWithComps eqComps) { ThingComp deflector = eqComps.AllComps.FirstOrDefault <ThingComp>((ThingComp y) => y.GetType().ToString().Contains("Deflect")); if (deflector != null) { bool isActive = (bool)AccessTools.Property(deflector.GetType(), "IsAnimatingNow").GetValue(deflector, null); if (isActive) { float numMod = (int)AccessTools.Property(deflector.GetType(), "AnimationDeflectionTicks").GetValue(deflector, null); //float numMod2 = new float(); //numMod2 = numMod; if (numMod > 0) { if (!flip) { num += ((numMod + 1) / 2); } else { num -= ((numMod + 1) / 2); } } } } } num %= 360f; //ThingWithComps eqComps = eq as ThingWithComps; //if (eqComps != null) //{ // ThingComp deflector = eqComps.AllComps.FirstOrDefault<ThingComp>((ThingComp y) => y.GetType().ToString() == "CompDeflector.CompDeflector"); // if (deflector != null) // { // float numMod = (float)((int)AccessTools.Property(deflector.GetType(), "AnimationDeflectionTicks").GetValue(deflector, null)); // //Log.ErrorOnce("NumMod " + numMod.ToString(), 1239); //numMod = (numMod + 1) / 2; //if (subtract) num -= numMod; //else num += numMod; // } //} Material matSingle = compActivatableEffect.Graphic.MatSingle; //if (mesh == null) mesh = MeshPool.GridPlane(thingWithComps.def.graphicData.drawSize); Vector3 s = new Vector3(eq.def.graphicData.drawSize.x, 1f, eq.def.graphicData.drawSize.y); Matrix4x4 matrix = default(Matrix4x4); matrix.SetTRS(drawLoc, Quaternion.AngleAxis(num, Vector3.up), s); if (!flip) { Graphics.DrawMesh(MeshPool.plane10, matrix, matSingle, 0); } else { Graphics.DrawMesh(MeshPool.plane10Flip, matrix, matSingle, 0); } //Graphics.DrawMesh(mesh, drawLoc, Quaternion.AngleAxis(num, Vector3.up), matSingle, 0); } } } } } }
protected override void Impact(Thing hitThing) { Map map = base.Map; base.Impact(hitThing); ThingDef def = this.def; pawn = this.launcher as Pawn; Pawn victim = hitThing as Pawn; CompAbilityUserMight comp = pawn.GetComp <CompAbilityUserMight>(); MightPowerSkill pwr = pawn.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Headshot.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Headshot_pwr"); MightPowerSkill ver = pawn.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Headshot.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Headshot_ver"); MightPowerSkill str = comp.MightData.MightPowerSkill_global_strength.FirstOrDefault((MightPowerSkill x) => x.label == "TM_global_strength_pwr"); CellRect cellRect = CellRect.CenteredOn(base.Position, 1); cellRect.ClipInsideMap(map); ThingWithComps arg_3C_0; int value = 0; if (pawn == null) { arg_3C_0 = null; } else { Pawn_EquipmentTracker expr_eq = pawn.equipment; arg_3C_0 = ((expr_eq != null) ? expr_eq.Primary : null); } ThingWithComps thing; bool flag31 = (thing = arg_3C_0) != null; if (flag31) { value = Mathf.RoundToInt(thing.GetStatValue(StatDefOf.MarketValue)); } int dmg; if (value > 1000) { value -= 1000; dmg = (this.def.projectile.damageAmountBase) + (int)((20 + (value / 120)) * (1 + (.1f * pwr.level) + (.05f * str.level))); } else { dmg = (this.def.projectile.damageAmountBase) + (int)((value / 50) * (1 + (.1f * pwr.level) + (.05f * str.level))); } ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef(); if (!pawn.IsColonistPlayerControlled && settingsRef.AIHardMode) { dmg += 8; } if (victim != null && Rand.Chance(this.launcher.GetStatValue(StatDefOf.ShootingAccuracy, true))) { this.PenetratingShot(victim, dmg, DamageDefOf.Bullet); if (victim.Dead) { comp.Stamina.CurLevel += (.1f * ver.level); } } }
public static void Prefix(ref Thing __instance, Map map, bool respawningAfterLoad) { if (respawningAfterLoad) { Type type = __instance.GetType(); ThingWithComps original = __instance as ThingWithComps; if (original != null) { try { Pawn pawn = original as Pawn; if (pawn != null) { // if (AMAMod.Dev) Log.Message(string.Format("checking {0}", pawn.Name.ToStringFull ?? pawn.NameShortColored)); Pawn_EquipmentTracker equipmentTracker = pawn.equipment; Pawn_ApparelTracker apparelTracker = pawn.apparel; Pawn_InventoryTracker inventoryTracker = pawn.inventory; if (equipmentTracker != null) { if (!equipmentTracker.AllEquipmentListForReading.NullOrEmpty()) { // if (AMAMod.Dev) Log.Message(string.Format("checking {0}'s equipment", pawn.NameShortColored)); for (int i = 0; i < equipmentTracker.AllEquipmentListForReading.Count; i++) { if (ShouldUpdate(equipmentTracker.AllEquipmentListForReading[i])) { // if (AMAMod.Dev) Log.Message(string.Format("repalce {0}'s equipment({1}) class", pawn.NameShortColored, equipmentTracker.AllEquipmentListForReading[i])); equipmentTracker.AllEquipmentListForReading[i] = ReplacedThing(equipmentTracker.AllEquipmentListForReading[i]) as ThingWithComps; } } } } if (apparelTracker != null) { if (!apparelTracker.WornApparel.NullOrEmpty()) { // if (AMAMod.Dev) Log.Message(string.Format("checking {0}'s apparel", pawn.NameShortColored)); for (int i = 0; i < apparelTracker.WornApparel.Count; i++) { if (ShouldUpdate(apparelTracker.WornApparel[i])) { // if (AMAMod.Dev) Log.Message(string.Format("repalce {0}'s apparel({1}) class", pawn.NameShortColored, apparelTracker.WornApparel[i])); apparelTracker.WornApparel[i] = ReplacedThing(apparelTracker.WornApparel[i]) as Apparel; } } } } if (inventoryTracker != null) { if (!inventoryTracker.GetDirectlyHeldThings().NullOrEmpty()) { // if (AMAMod.Dev) Log.Message(string.Format("checking {0}'s inventory", pawn.NameShortColored)); for (int i = inventoryTracker.GetDirectlyHeldThings().Count - 1; i > 0; i--) { if (ShouldUpdate(inventoryTracker.GetDirectlyHeldThings()[i])) { // if (AMAMod.Dev) Log.Message(string.Format("replace {0}'s inventory({1}) class", pawn.NameShortColored, inventoryTracker.GetDirectlyHeldThings()[i])); Thing replace = ReplacedThing(inventoryTracker.GetDirectlyHeldThings()[i] as ThingWithComps); inventoryTracker.GetDirectlyHeldThings().RemoveAt(i); inventoryTracker.GetDirectlyHeldThings().TryAdd(ReplacedThing(replace as ThingWithComps)); } } } } } else { if (ShouldUpdate(original)) { __instance = ReplacedThing(original); } } } catch (Exception) { if (AMAMod.Dev) { Log.Warning("Something went wrong trying to replace " + __instance.LabelCap + "'s ThingClass"); } } finally { if (type != __instance.def.thingClass && type != typeof(Pawn)) { if (AMAMod.Dev) { Log.Warning("Failed to replace " + __instance.LabelCap + "'s ThingClass(" + type.Name + ") to " + __instance.def.thingClass.Name); } } } } } }
private static void DropOffHand(Pawn_EquipmentTracker __instance, ThingWithComps eq, ThingWithComps offHand) { if (__instance.TryDropEquipment(offHand, out ThingWithComps resultingEq, __instance.pawn.Position)) { resultingEq?.SetForbidden(value: false); }
public static Job TryGiveJobStatic(Pawn pawn, bool inCombat) { if (RestraintsUtility.InRestraints(pawn)) { return(null); } else { Pawn_EquipmentTracker equipment = pawn.equipment; if (equipment == null) { return(null); } GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(pawn); if (pawnMemory == null) { return(null); } if (SimpleSidearms.ToolAutoSwitch && ((Find.TickManager.TicksGame - pawnMemory.delayIdleSwitchTimestamp) < 60)) { return(null); } WeaponAssingment.equipBestWeaponFromInventoryByPreference(pawn, Globals.DroppingModeEnum.Calm); if (pawnMemory.RememberedWeapons is null) { Log.Warning("pawnMemory of " + pawn.Label + " is missing remembered weapons"); } Dictionary <ThingDefStuffDefPair, int> dupeCounters = new Dictionary <ThingDefStuffDefPair, int>(); foreach (ThingDefStuffDefPair weaponMemory in pawnMemory.RememberedWeapons) { if (!dupeCounters.ContainsKey(weaponMemory)) { dupeCounters[weaponMemory] = 0; } if (!pawn.hasWeaponSomewhere(weaponMemory, dupeCounters[weaponMemory])) { float maxDist = 1000f; if (pawn.Faction != Faction.OfPlayer) { maxDist = 30f; } if (inCombat) { maxDist = 12f; } IEnumerable <Thing> matchingWeapons = pawn.Map.listerThings.ThingsOfDef(weaponMemory.thing).Where(t => t.Stuff == weaponMemory.stuff); Thing thing = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, matchingWeapons, PathEndMode.OnCell, TraverseParms.For(pawn), maxDist, (Thing t) => !t.IsForbidden(pawn) && pawn.CanReserve(t), (Thing t) => SimpleSidearms.ReEquipBest ? t.GetStatValue(StatDefOf.MeleeWeapon_AverageDPS, false) : 0); //this works properly because better ranged weapons also happen to be better at pistolwhipping //okay past me, WHAT? Why? if (thing == null) { continue; } if (!inCombat) { return(JobMaker.MakeJob(SidearmsDefOf.ReequipSecondary, thing)); } else { return(JobMaker.MakeJob(SidearmsDefOf.ReequipSecondaryCombat, thing, pawn.Position)); } } dupeCounters[weaponMemory]++; } return(null); } }
protected override Job TryGiveJob(Pawn pawn) { //Log.Message("retrieval precheck for " + pawn.LabelShort); if (pawn.Faction != Faction.OfPlayer) { return(null); } if (pawn.Drafted) { return(null); } /*if (Find.TickManager.TicksGame > GetNextTryTick(pawn)) * { * return null; * } * else*/ { //SetNextTryTick(pawn, Find.TickManager.TicksGame + UnityEngine.Random.Range(PickupCheckIntervalMin, PickupCheckIntervalMax)); //Log.Message("retrieval check for " + pawn.LabelShort); Pawn_EquipmentTracker equipment = pawn.equipment; if (equipment == null) { return(null); } GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(pawn); if (pawnMemory == null) { return(null); } WeaponAssingment.reequipPrimaryIfNeededAndAvailable(pawn, pawnMemory); foreach (string wepName in pawnMemory.weapons) { //Log.Message("checking "+wepName); ThingDef def = DefDatabase <ThingDef> .GetNamedSilentFail(wepName); if (def == null) { continue; } if (!pawn.hasWeaponSomewhere(wepName)) { //Log.Message("looking for"); ThingRequest request = new ThingRequest(); request.singleDef = def; Thing thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, request, PathEndMode.OnCell, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 1000f, (Thing x) => (!x.IsForbidden(pawn)) && pawn.CanReserve(x, 1, -1, null, false)); if (thing == null) { continue; } return(new Job(SidearmsJobDefOf.EquipSecondary, thing)); } } return(null); } }
public static bool TryExecuteWorker(IncidentParms parms) { StringBuilder builder = new StringBuilder(); if (parms.faction.def.defName.EqualsIgnoreCase("ra2_soviet")) { Find.MusicManagerPlay.ForceStartSong(DefDatabase <SongDef> .GetNamed("ra2_soviet_music", true), false); // Log.Warning("your points is :"+ parms.points); if (parms.points >= 600) { spawnSpecialPawn(parms, "ra2_SovietEngineer"); } if (parms.points >= 3600) { Pawn apoTank = spawnSpecialPawn(parms, "ra2_ApoTank"); SoundStarter.PlayOneShotOnCamera(DefDatabase <SoundDef> .GetNamed("ra2_apo_enter"), (Map)parms.target); String text = Translator.Translate("DangerousunitMsg", new object[] { parms.faction.Name, apoTank.def.label }); builder.AppendLine(text); Find.LetterStack.ReceiveLetter(Translator.Translate("Dangerousunit"), builder.ToString(), LetterDefOf.Death, apoTank); // Messages.Message(text+apoTank,MessageTypeDefOf.PawnDeath); } return(true); } else if (parms.faction.def.defName.EqualsIgnoreCase("ra2_allied")) { Find.MusicManagerPlay.ForceStartSong(DefDatabase <SongDef> .GetNamed("ra2_allied_music", true), false); if (parms.points >= 600) { spawnSpecialPawn(parms, "ra2_AlliedEngineer"); } if (parms.points >= 3600) { Pawn item = getTanya(parms); Pawn_EquipmentTracker et = item.equipment; Random nr = new Random((int)parms.points); int result = nr.Next(100); et.AddEquipment((ThingWithComps)ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed(result > 33 ? "ra2_Gun_Tanya" : "ra2_TanyaC4Bomb", true))); IntVec3 loc = CellFinder.RandomClosewalkCellNear(parms.spawnCenter, (Map)parms.target, 8, null); Pawn pp = (Pawn)(GenSpawn.Spawn(item, loc, (Map)parms.target, parms.spawnRotation, WipeMode.Vanish, false)); //Lord ld = LordMaker.MakeNewLord(parms.faction, new LordJob_AssaultColony(parms.faction, false, false, true, false, true), (Map)parms.target); //ld.AddPawn(pp); List <Pawn> pl = new List <Pawn>(); pl.Add(pp); parms.raidStrategy.Worker.MakeLords(parms, pl); SoundStarter.PlayOneShotOnCamera(DefDatabase <SoundDef> .GetNamed("ra2_tanya_enter"), (Map)parms.target); String text = Translator.Translate("DangerousunitMsg", new object[] { parms.faction.Name, item.Name }); builder.AppendLine(text); builder.AppendLine("TanyaWeaponUse".Translate() + ":" + DefDatabase <ThingDef> .GetNamed(result > 33 ? "ra2_Gun_Tanya" : "ra2_TanyaC4Bomb", true).label); Find.LetterStack.ReceiveLetter(Translator.Translate("Dangerousunit"), builder.ToString(), LetterDefOf.Death, pp); } return(true); } else if (parms.faction.def.defName.EqualsIgnoreCase("ra2_yuri")) { Find.MusicManagerPlay.ForceStartSong(DefDatabase <SongDef> .GetNamed("ra2_yuri_music", true), false); // Log.Warning("your points is :"+ parms.points); if (parms.points >= 500) { spawnSpecialPawn(parms, "ra2_YuriEngineer"); } return(true); } return(false); }
// Token: 0x06000038 RID: 56 RVA: 0x000030B0 File Offset: 0x000012B0 public Pawn FromRealmPawn(RealmData realmData) { var named = DefDatabase <PawnKindDef> .GetNamed(kindDefName); var pawn = (Pawn)ThingMaker.MakeThing(named.race); foreach (var pawn2 in Find.WorldPawns.ForcefullyKeptPawns) { var health = pawn2.health; float?num; if (health == null) { num = null; } else { var hediffSet = health.hediffSet; if (hediffSet == null) { num = null; } else { var firstHediffOfDef = hediffSet.GetFirstHediffOfDef(PhiHediffDefOf.Phi_Key); num = firstHediffOfDef != null ? new float?(firstHediffOfDef.Severity) : null; } } var num2 = num ?? -1f; var list = hediffs; float?num3; if (list == null) { num3 = null; } else { var realmHediff = list.First(h => h.hediffDefName == PhiHediffDefOf.Phi_Key.defName); num3 = realmHediff != null ? new float?(realmHediff.severity) : null; } if (num2 != num3) { continue; } pawn = pawn2; break; } pawn.kindDef = named; pawn.SetFactionDirect(Faction.OfPlayer); PawnComponentsUtility.CreateInitialComponents(pawn); var pawnName = pawn.Name; switch (name.Length) { case 1: pawnName = new NameSingle(name[0]); break; case 2: pawnName = new NameTriple(name[0], name[1], name[1]); break; case 3: pawnName = new NameTriple(name[0], name[1], name[2]); break; } pawn.Name = pawnName; pawn.gender = gender; pawn.ageTracker.AgeBiologicalTicks = ageBiologicalTicks; pawn.ageTracker.AgeChronologicalTicks = ageChronologicalTicks; var story = pawn.story; if (story != null) { story.melanin = melanin; story.crownType = crownType; story.hairColor = new Color(hairColor[0], hairColor[1], hairColor[2], hairColor[3]); if (!BackstoryDatabase.TryGetWithIdentifier(childhoodKey, out story.childhood)) { throw new Exception($"Couldn't find backstory '{childhoodKey}'"); } if (!string.IsNullOrEmpty(adulthoodKey) && !BackstoryDatabase.TryGetWithIdentifier(adulthoodKey, out story.adulthood)) { throw new Exception($"Couldn't find backstory '{adulthoodKey}'"); } story.bodyType = DefDatabase <BodyTypeDef> .GetNamed(bodyTypeDefName); story.hairDef = DefDatabase <HairDef> .GetNamed(hairDefName); story.traits.allTraits.Clear(); foreach (var realmTrait in traits) { var named2 = DefDatabase <TraitDef> .GetNamed(realmTrait.traitDefName); story.traits.GainTrait(new Trait(named2, realmTrait.degree)); } } if (skills != null) { using var enumerator3 = skills.AsEnumerable().GetEnumerator(); while (enumerator3.MoveNext()) { var item2 = enumerator3.Current; var skillDef = DefDatabase <SkillDef> .AllDefs.First(def => def.label == item2?.skillDefLabel); var skill = pawn.skills.GetSkill(skillDef); if (item2 == null) { continue; } skill.Level = item2.level; skill.passion = item2.passion; } } var workSettings = pawn.workSettings; workSettings?.EnableAndInitialize(); if (apparels != null) { var pawn_ApparelTracker = new Pawn_ApparelTracker(pawn); foreach (var realmThing in apparels) { var apparel = (Apparel)realmData.FromRealmThing(realmThing); pawn_ApparelTracker.Wear(apparel); } } if (equipments != null) { var pawn_EquipmentTracker = new Pawn_EquipmentTracker(pawn); foreach (var realmThing2 in equipments) { var newEq = (ThingWithComps)realmData.FromRealmThing(realmThing2); pawn_EquipmentTracker.AddEquipment(newEq); } } if (inventory != null) { var pawn_InventoryTracker = pawn.inventory; foreach (var realmThing3 in inventory) { var item = realmData.FromRealmThing(realmThing3); pawn_InventoryTracker.innerContainer.TryAdd(item); } } if (hediffs == null) { Log.Warning("RealmHediffs is null in received colonist"); } foreach (var realmHediff2 in hediffs ?? new List <RealmHediff>()) { var named3 = DefDatabase <HediffDef> .GetNamed(realmHediff2.hediffDefName); BodyPartRecord part = null; if (realmHediff2.bodyPartIndex != -1) { part = pawn.RaceProps.body.GetPartAtIndex(realmHediff2.bodyPartIndex); } pawn.health.AddHediff(named3, part); var hediff = pawn.health.hediffSet.hediffs.Last(); hediff.source = realmHediff2.sourceDefName == null ? null : DefDatabase <ThingDef> .GetNamedSilentFail(realmHediff2.sourceDefName); hediff.ageTicks = realmHediff2.ageTicks; hediff.Severity = realmHediff2.severity; if (float.IsNaN(realmHediff2.immunity) || pawn.health.immunity.ImmunityRecordExists(named3)) { continue; } var immunity = pawn.health.immunity; immunity.GetType().GetMethod("TryAddImmunityRecord", BindingFlags.Instance | BindingFlags.NonPublic) .Invoke(immunity, new object[] { named3 }); immunity.GetImmunityRecord(named3).immunity = realmHediff2.immunity; } if (training != null) { pawn.training = new Pawn_TrainingTracker(pawn); foreach (var realmTrainingRecord in training) { var named4 = DefDatabase <TrainableDef> .GetNamed(realmTrainingRecord.trainingDefLabel); if (realmTrainingRecord.wanted) { pawn.training.SetWantedRecursive(named4, false); } if (realmTrainingRecord.learned) { pawn.training.Train(named4, null, true); } } } var field = pawn.health.GetType().GetField("healthState", BindingFlags.Instance | BindingFlags.NonPublic); if (field == null) { Log.Error("Unable to find healthState field"); } else { field.SetValue(pawn.health, healthState); } if (workPriorities == null) { return(pawn); } foreach (var keyValuePair in workPriorities ?? new Dictionary <string, int>()) { var namedSilentFail = DefDatabase <WorkTypeDef> .GetNamedSilentFail(keyValuePair.Key); if (namedSilentFail == null) { Log.Warning($"Ignoring unknown workType: {keyValuePair.Key}"); } else { pawn.workSettings.SetPriority(namedSilentFail, keyValuePair.Value); } } return(pawn); }
public override IEnumerable <Gizmo> GetWornGizmos() { // base.GetWornGizmos(); if (Find.Selector.SingleSelectedThing != base.Wearer) { yield break; } //tanya if (base.Wearer.kindDef.defName == "ra2_AlliedTanya") { yield return new Command_Action { icon = ContentFinder <Texture2D> .Get(!tanyaHandWeapon()?DefDatabase <ThingDef> .GetNamed("ra2_Gun_Tanya", true).graphicData.texPath : DefDatabase <ThingDef> .GetNamed("ra2_TanyaC4Bomb", true).graphicData.texPath, true), defaultLabel = "TanyaChangeWeapon".Translate(), activateSound = DefDatabase <SoundDef> .GetNamed("ra2_tanya_select", true), action = delegate { Pawn_EquipmentTracker pe = base.Wearer.equipment; ThingDef tempDef = DefDatabase <ThingDef> .GetNamed(tanyaHandWeapon()? "ra2_TanyaC4Bomb" : "ra2_Gun_Tanya", true); pe.Remove(pe.Primary); pe.AddEquipment((ThingWithComps)ThingMaker.MakeThing(tempDef)); } } } ; //chrono TargetingParameters tp = new TargetingParameters(); tp.canTargetBuildings = false; tp.canTargetFires = false; tp.canTargetLocations = true; tp.canTargetPawns = false; tp.canTargetSelf = false; if (base.Wearer.kindDef.defName == "ra2_AlliedChrono") { yield return new Command_TargetPlus { icon = ContentFinder <Texture2D> .Get("ra2/Things/Misc/ChTeleport", true), defaultLabel = "ChronoTeleport".Translate(), activateSound = DefDatabase <SoundDef> .GetNamed("ra2_Chrono_select", true), targetingParams = tp, hotKey = KeyBindingDefOf.Misc4, disabled = !base.Wearer.drafter.Drafted || base.Wearer.stances.stunner.Stunned, aimIcon = ContentFinder <Texture2D> .Get("ra2/Things/Misc/ChTeleport", true), action = delegate(LocalTargetInfo target) { Pawn casterPawn = base.Wearer; Map map = base.Wearer.Map; IEnumerable <Thing> thi = map.thingGrid.ThingsAt(target.Cell); foreach (Thing th in thi) { if (th is Building) { Messages.Message("ChronoNotToBuild".Translate(), MessageTypeDefOf.RejectInput); return; } } MoteMaker.ThrowExplosionCell(target.Cell, map, ThingDefOf.Mote_ExplosionFlash, new UnityEngine.Color(1, 1, 1)); // MoteMaker.ThrowExplosionCell(target.Cell, map, ThingDefOf.Mote_ExplosionFlash, new UnityEngine.Color(1,1,1)); for (int asd = 0; asd < 60; asd++) { MoteMaker.ThrowExplosionCell(casterPawn.Position, map, ThingDefOf.Mote_ExplosionFlash, new UnityEngine.Color(1f - asd * 0.1f, asd * 0.1f, 1f - asd * 0.05f)); } double dist = Math.Sqrt(Math.Pow(casterPawn.Position.x - target.Cell.x, 2) + Math.Pow(casterPawn.Position.z - target.Cell.z, 2)); if (dist < 20) { dist = 20; } ThingSelectionUtility.SelectNextColonist(); base.Wearer.DeSpawn(DestroyMode.Vanish); GenSpawn.Spawn(casterPawn, target.Cell, map, WipeMode.Vanish); casterPawn.drafter.Drafted = true; ThingSelectionUtility.SelectPreviousColonist(); SoundStarter.PlayOneShot(DefDatabase <SoundDef> .GetNamed("ra2_Chrono_move", true), casterPawn); SoundStarter.PlayOneShotOnCamera(DefDatabase <SoundDef> .GetNamed("ra2_Chrono_movesay", true)); DamageInfo dinfo = new DamageInfo(DamageDefOf.Stun, (int)(dist * 0.1), -1, 1, null, null, base.Wearer.equipment.Primary.def, DamageInfo.SourceCategory.ThingOrUnknown, casterPawn); casterPawn.TakeDamage(dinfo); // Log.Warning(target+"VV"); } } } ; //yuri bool isYuri = false; if (this.Wearer != null) { Pawn pawn = this.Wearer; if (pawn.kindDef.defName.EqualsIgnoreCase("ra2_yuriyuri")) { isYuri = true; } } if (isYuri) { bool canCast = this.ticks <= 0 && this.Wearer.drafter.Drafted && !this.Wearer.stances.stunner.Stunned; yield return(new Command_YuriAction { defaultLabel = "YuriExpTitle".Translate(), icon = ContentFinder <Texture2D> .Get("ra2/Things/Misc/yuriExpIcon", true), disabled = !canCast, caster = this.Wearer, hotKey = KeyBindingDefOf.Misc4, action = delegate { Pawn pawn = this.Wearer; DamageDef df = DefDatabase <DamageDef> .GetNamed("YuriExp", true); foreach (IntVec3 cell in CellsAround(pawn.Position, pawn.Map, 7)) { // if (!cell.IsValid) continue; List <Thing> list = (pawn.Map.thingGrid.ThingsListAt(cell)); try { if (list.Count < 1) { continue; } for (int i = 0; i < list.Count; i++) { Pawn p; if ((p = (list[i] as Pawn)) != null) { if (p.kindDef.defName.EqualsIgnoreCase("ra2_yuriyuri")) { continue; } if (p.RaceProps.IsFlesh) { { p.Kill(new DamageInfo(df, 0, 0, -1, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown, null), null); } if (!(p.Faction == Faction.OfPlayer && p.kindDef.defName.StartsWith("ra2_"))) { p.Corpse.Kill(null); } } } } } catch (Exception e) { Log.Warning(e + "233"); } } pawn.stances.stunner.StunFor(120, null); this.ticks = 300; GenExplosion.DoExplosion(pawn.Position, pawn.Map, 7f, df, pawn, 0, -1, null, null, null, null, null, 0, 1, false, null, 0, 1, 0, false); } }); } yield break; } } }
public static IEnumerable <Gizmo> GetGizmosPostfix(IEnumerable <Gizmo> __result, Pawn_EquipmentTracker __instance) { int count = 0; foreach (Gizmo g in __result) { if (g is Command) { switch (count) { case 0: ((Command)g).hotKey = KeyBindingDefOf.Misc1; break; case 1: ((Command)g).hotKey = KeyBindingDefOf.Misc3; break; case 2: ((Command)g).hotKey = KeyBindingDefOf.Misc4; break; case 3: ((Command)g).hotKey = KeyBindingDefOf.Misc5; break; case 4: ((Command)g).hotKey = KeyBindingDefOf.Misc7; break; case 5: ((Command)g).hotKey = KeyBindingDefOf.Misc8; break; case 6: ((Command)g).hotKey = KeyBindingDefOf.Misc9; break; case 7: ((Command)g).hotKey = KeyBindingDefOf.Misc10; break; case 8: ((Command)g).hotKey = KeyBindingDefOf.Misc11; break; default: ((Command)g).hotKey = KeyBindingDefOf.Misc12; break; } } yield return(g); count++; } }
public override void CompPostTick(ref float severityAdjustment) { base.CompPostTick(ref severityAdjustment); { Pawn_EquipmentTracker pe = base.Pawn.equipment; Pawn_ApparelTracker pa = base.Pawn.apparel; if (base.Pawn.Faction == Faction.OfPlayer) { if (base.Pawn.kindDef.defName == "ra2_AlliedTanya") { } else if (pe.Primary == null || pe.Primary.def != getDefaultGun(base.Pawn.kindDef.defName)) { pe.Remove(pe.Primary); pe.AddEquipment((ThingWithComps)ThingMaker.MakeThing(getDefaultGun(base.Pawn.kindDef.defName))); } if (base.Pawn.kindDef.defName == "ra2_AlliedChrono") { bool hasHat = false; foreach (Apparel ap in base.Pawn.apparel.WornApparel) { if (ap.def.defName == "ra2_Hat_Chrono") { hasHat = true; break; } } if (!hasHat) { base.Pawn.apparel.Wear((Apparel)ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("ra2_Hat_Chrono", true))); } } if (pa.WornApparel == null) { pa.Wear((Apparel)ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("ra2_Belt", true))); } bool hasBelt = false; foreach (Apparel ap in pa.WornApparel) { if (ap.def.defName.Equals("ra2_Belt")) { hasBelt = true; break; } } if (!hasBelt) { pa.Wear((Apparel)ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("ra2_Belt", true))); } } } if (base.Pawn.apparel.WornApparel.Find(x => x.TryGetComp <CompDownToDie>() != null) == null) { base.Pawn.health.RemoveHediff(base.parent); } if ((base.Pawn.Downed && !base.Pawn.Dead) || base.Pawn.IsPrisoner) { //Apparel ap = base.Pawn.apparel.WornApparel.Find(x => x.TryGetComp<CompDownToDie>() != null); //ap.Destroy(DestroyMode.Vanish); //base.Pawn.apparel.Remove(ap); DamageInfo dinfo = new DamageInfo(DamageDefOf.Crush, 100, 0, 0, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown); HediffSet bodypart = base.Pawn.health.hediffSet; foreach (BodyPartRecord record in bodypart.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined)) { if (record.def.tags.Contains(BodyPartTagDefOf.BloodPumpingSource)) { dinfo.SetHitPart(record); break; } } base.Pawn.TakeDamage(dinfo); } }
protected override IEnumerable <Toil> MakeNewToils() { yield return(Toils_Reserve.Reserve(TargetIndex.A, 1)); Toil toil = new Toil() { initAction = delegate { this.pawn.pather.StartPath(this.TargetThingA, PathEndMode.ClosestTouch); }, defaultCompleteMode = ToilCompleteMode.PatherArrival }; toil.FailOnDespawnedNullOrForbidden(TargetIndex.A); yield return(toil); yield return(new Toil { initAction = delegate { Thing itemToGather = this.CurJob.targetA.Thing; //bool flag = false; Thing itemToGatherSplit; if (itemToGather.def.stackLimit > 1 && itemToGather.stackCount > 1) { itemToGatherSplit = itemToGather.SplitOff(1); } else { itemToGatherSplit = itemToGather; //flag = true; } //Find the compslotloadable Pawn_EquipmentTracker pawn_EquipmentTracker = this.pawn.equipment; if (pawn_EquipmentTracker != null) { //Log.Message("2"); ThingWithComps thingWithComps = pawn_EquipmentTracker.Primary; //(ThingWithComps)AccessTools.Field(typeof(Pawn_EquipmentTracker), "primaryInt").GetValue(pawn_EquipmentTracker); if (thingWithComps != null) { //Log.Message("3"); CompSlotLoadable CompSlotLoadable = thingWithComps.GetComp <CompSlotLoadable>(); if (CompSlotLoadable != null) { CompSlotLoadable.TryLoadSlot(itemToGather); if (thingWithComps.def.soundInteract != null) { thingWithComps.def.soundInteract.PlayOneShot(new TargetInfo(this.pawn.Position, this.pawn.Map, false)); } //if (flag) //{ // thingWithComps.DeSpawn(); //} } } } }, defaultCompleteMode = ToilCompleteMode.Instant }); yield break; }
public Pawn FromRealmPawn(RealmData realmData) { // This code is mainly a copy/paste of what happens in // PawnGenerator.DoGenerateNakedPawn() PawnKindDef kindDef = DefDatabase <PawnKindDef> .GetNamed(kindDefName); Pawn pawn = (Pawn)ThingMaker.MakeThing(kindDef.race); pawn.kindDef = kindDef; pawn.SetFactionDirect(Faction.OfPlayer); PawnComponentsUtility.CreateInitialComponents(pawn); pawn.gender = gender; // What is done in GenerateRandomAge() pawn.ageTracker.AgeBiologicalTicks = ageBiologicalTicks; pawn.ageTracker.AgeChronologicalTicks = ageChronologicalTicks; // Ignored SetInitialLevels() // Ignored GenerateInitialHediffs() // Ignored GeneratePawnRelations() Pawn_StoryTracker story = pawn.story; story.melanin = melanin; story.crownType = crownType; story.hairColor = new Color(hairColor[0], hairColor[1], hairColor[2], hairColor[3]); // What is done in GiveAppropriateBio() Name nameObj = pawn.Name; switch (name.Count()) { case 1: nameObj = new NameSingle(name[0]); break; case 2: nameObj = new NameTriple(name[0], name[1], name[1]); break; case 3: nameObj = new NameTriple(name[0], name[1], name[2]); break; } pawn.Name = nameObj; if (!BackstoryDatabase.TryGetWithIdentifier(childhoodKey, out story.childhood)) { throw new Exception(string.Format("Couldn't find backstory '{0}'", childhoodKey)); } if (!BackstoryDatabase.TryGetWithIdentifier(adulthoodKey, out story.adulthood)) { throw new Exception(string.Format("Couldn't find backstory '{0}'", adulthoodKey)); } story.hairDef = DefDatabase <HairDef> .GetNamed(hairDefName); // Done in GiveRandomTraits() foreach (RealmTrait trait in traits) { TraitDef traitDef = DefDatabase <TraitDef> .GetNamed(trait.traitDefName); story.traits.GainTrait(new Trait(traitDef, trait.degree)); } // We attribute the skills level foreach (RealmSkillRecord rec in skills.AsEnumerable()) { SkillDef skillDef = DefDatabase <SkillDef> .AllDefs.First((def) => def.label == rec.skillDefLabel); SkillRecord skill = pawn.skills.GetSkill(skillDef); skill.Level = rec.level; skill.passion = rec.passion; } pawn.workSettings.EnableAndInitialize(); // Once we've generated a new solid pawn, we generate the gear of it // GenerateStartingApparelFor() Pawn_ApparelTracker apparelTracker = pawn.apparel; foreach (RealmThing realmThing in apparels) { Apparel apparel = (Apparel)realmData.FromRealmThing(realmThing); apparelTracker.Wear(apparel); } // TryGenerateWeaponFor() Pawn_EquipmentTracker equipmentTracker = pawn.equipment; foreach (RealmThing realmThing in equipments) { ThingWithComps thingWithComps = (ThingWithComps)realmData.FromRealmThing(realmThing); equipmentTracker.AddEquipment(thingWithComps); } // GenerateInventoryFor() Pawn_InventoryTracker inventoryTracker = pawn.inventory; foreach (RealmThing realmThing in inventory) { Thing thing = realmData.FromRealmThing(realmThing); inventoryTracker.innerContainer.TryAdd(thing); } return(pawn); }
private static void StatWorkerInjection_BuildShieldString(StringBuilder stringBuilder, Pawn_EquipmentTracker equipment, StatDef stat) { var shield = equipment.GetShield(); if (shield != null && GearAffectsStats(shield.def, stat)) { stringBuilder.AppendLine(InfoTextLineFromGear(shield, stat)); } }
static void Prefix(Pawn_EquipmentTracker __instance) { __instance.Notify_EquipmentChanged(); }
static bool ReloadCheck(Verb verb, LocalTargetInfo targ, bool surpriseAttack, bool canFreeIntercept, Pawn_EquipmentTracker __instance) { // this is no longer valid: ThingWithComps primaryInt = Traverse.Create(__instance).Field("primaryInt").GetValue() as ThingWithComps; ThingOwner <ThingWithComps> equipment = Traverse.Create(__instance).Field("equipment").GetValue <ThingOwner <ThingWithComps> >(); if (equipment != null && __instance.PrimaryEq != null && verb != null && verb == __instance.PrimaryEq.PrimaryVerb) { if (__instance.Primary != null) { CompAmmoUser compAmmo = __instance.Primary.TryGetComp <CompAmmoUser>(); if (compAmmo != null && !compAmmo.CanBeFiredNow) { if (compAmmo.HasAmmo) { compAmmo.TryStartReload(); } return(false); } } } return(verb != null && verb.TryStartCastOn(targ, surpriseAttack, canFreeIntercept)); }
public static void ShieldPatchWearApparel(Pawn_EquipmentTracker __instance, Apparel newApparel) { bool shield = false; // for apparel with no thingcategory defined if (newApparel.def.thingCategories == null) { return; } foreach (ThingCategoryDef ApparelItem in newApparel.def.thingCategories) { // we have a shield in the inventory if (ApparelItem.defName == "Shield") { shield = true; } } if (!shield) { return; } Pawn owner = __instance.pawn; // must have picked up a weapon if (PawnHasShieldInInventory(owner)) { // do we have a shield equipped for (int i = 0; i < owner.inventory.innerContainer.Count; i++) { if (owner.inventory.innerContainer[i].def.thingCategories == null) { continue; } foreach (ThingCategoryDef ApparelItem in owner.inventory.innerContainer[i].def.thingCategories) { if (ApparelItem.defName == "Shield") { Thing whocares; __instance.pawn.inventory.innerContainer.TryDrop(owner.inventory.innerContainer[i], ThingPlaceMode.Direct, out whocares, null, null); } } } Apparel wornshield = null; for (int i = 0; i < owner.apparel.WornApparelCount; i++) { if (owner.apparel.WornApparel[i].def.thingCategories == null) { continue; } foreach (ThingCategoryDef ApparelItem in owner.apparel.WornApparel[i].def.thingCategories) { if (ApparelItem.defName == "Shield") { wornshield = owner.apparel.WornApparel[i]; } } } // we have a shield equipped if (wornshield != null) { owner.apparel.Remove(wornshield); owner.inventory.innerContainer.TryAddOrTransfer(wornshield, false); } } else { if (!PawnHasValidEquipped(owner)) { Apparel wornshield = null; for (int i = 0; i < owner.apparel.WornApparelCount; i++) { if (owner.apparel.WornApparel[i].def.thingCategories == null) { continue; } foreach (ThingCategoryDef ApparelItem in owner.apparel.WornApparel[i].def.thingCategories) { if (ApparelItem.defName == "Shield") { wornshield = owner.apparel.WornApparel[i]; } } } // we have a shield equipped if (wornshield != null) { owner.apparel.Remove(wornshield); owner.inventory.innerContainer.TryAddOrTransfer(wornshield, false); } } } }
public static IEnumerable <Gizmo> GetGizmosPostfix(IEnumerable <Gizmo> __result, Pawn_EquipmentTracker __instance) { if (__instance.Primary != null && __instance.Primary.def.weaponTags != null && __instance.Primary.def.weaponTags.Contains("AV")) { foreach (ThingComp tc in __instance.Primary.AllComps) { if (!(tc is CompForbiddable)) { foreach (Gizmo g in tc.CompGetGizmosExtra()) { yield return(g); } } } } int count = 0; foreach (Gizmo g in __result) { if (g is Command) { switch (count) { case 0: ((Command)g).hotKey = KeyBindingDefOf.Misc1; break; case 1: ((Command)g).hotKey = KeyBindingDefOf.Misc3; break; case 2: ((Command)g).hotKey = KeyBindingDefOf.Misc4; break; case 3: ((Command)g).hotKey = KeyBindingDefOf.Misc5; break; case 4: ((Command)g).hotKey = KeyBindingDefOf.Misc7; break; case 5: ((Command)g).hotKey = KeyBindingDefOf.Misc8; break; case 6: ((Command)g).hotKey = KeyBindingDefOf.Misc9; break; case 7: ((Command)g).hotKey = KeyBindingDefOf.Misc10; break; case 8: ((Command)g).hotKey = KeyBindingDefOf.Misc11; break; default: ((Command)g).hotKey = KeyBindingDefOf.Misc12; break; } } yield return(g); count++; } }
//=================================== COMPDEFLECTOR //public static void SpecialDisplayStatsPostFix(Thing __instance, ref IEnumerable<StatDrawEntry> __result) //{ // ////Log.Message("3"); // ThingWithComps thingWithComps = __instance as ThingWithComps; // if (thingWithComps != null) // { // CompDeflector compDeflector = thingWithComps.GetComp<CompDeflector>(); // if (compDeflector != null) // { // List<StatDrawEntry> origin = new List<StatDrawEntry>(); // foreach (StatDrawEntry entry in __result) // { // //Log.Message("Entry"); // origin.Add(entry); // } // List<StatDrawEntry> entries = new List<StatDrawEntry>(); // foreach (StatDrawEntry entry in compDeflector.PostSpecialDisplayStats()) // { // //Log.Message("Hey!"); // entries.Add(entry); // } // origin.Concat(entries); // __result = origin; // } // } //} public static void DrawEquipmentAimingPostFix(PawnRenderer __instance, Thing eq, Vector3 drawLoc, float aimAngle) { Pawn pawn = (Pawn)AccessTools.Field(typeof(PawnRenderer), "pawn").GetValue(__instance); if (pawn != null) { ////Log.Message("1"); Pawn_EquipmentTracker pawn_EquipmentTracker = pawn.equipment; if (pawn_EquipmentTracker != null) { ////Log.Message("2"); foreach (ThingWithComps thingWithComps in pawn_EquipmentTracker.AllEquipmentListForReading) { ////Log.Message("3"); if (thingWithComps != null) { ////Log.Message("4"); ////Log.Message("3"); CompDeflector compDeflector = thingWithComps.GetComp <CompDeflector>(); if (compDeflector != null) { ////Log.Message("5"); if (compDeflector.IsAnimatingNow) { bool flip = false; if (!Find.TickManager.Paused && compDeflector.IsAnimatingNow) { compDeflector.AnimationDeflectionTicks -= 20; } float offset = eq.def.equippedAngleOffset; float num = aimAngle - 90f; if (aimAngle > 20f && aimAngle < 160f) { //mesh = MeshPool.plane10; num += offset; if (compDeflector.IsAnimatingNow) { num += ((compDeflector.AnimationDeflectionTicks + 1) / 2); } } else if (aimAngle > 200f && aimAngle < 340f) { //mesh = MeshPool.plane10Flip; flip = true; num -= 180f; num -= offset; if (compDeflector.IsAnimatingNow) { num -= ((compDeflector.AnimationDeflectionTicks + 1) / 2); } } else { //mesh = MeshPool.plane10; num += offset; if (compDeflector.IsAnimatingNow) { num += ((compDeflector.AnimationDeflectionTicks + 1) / 2); } } num %= 360f; Graphic_StackCount graphic_StackCount = eq.Graphic as Graphic_StackCount; Material matSingle; if (graphic_StackCount != null) { matSingle = graphic_StackCount.SubGraphicForStackCount(1, eq.def).MatSingle; } else { matSingle = eq.Graphic.MatSingle; } //mesh = MeshPool.GridPlane(thingWithComps.def.graphicData.drawSize); //Graphics.DrawMesh(mesh, drawLoc, Quaternion.AngleAxis(num, Vector3.up), matSingle, 0); Vector3 s = new Vector3(eq.def.graphicData.drawSize.x, 1f, eq.def.graphicData.drawSize.y); Matrix4x4 matrix = default(Matrix4x4); matrix.SetTRS(drawLoc, Quaternion.AngleAxis(num, Vector3.up), s); if (!flip) { Graphics.DrawMesh(MeshPool.plane10, matrix, matSingle, 0); } else { Graphics.DrawMesh(MeshPool.plane10Flip, matrix, matSingle, 0); } ////Log.Message("DeflectDraw"); } } } } } } }
public static void EquipmentAdded_Postfix(ThingWithComps eq, Pawn_EquipmentTracker __instance) { __instance.pawn.Manager()?.AddVerbs(eq); }
/// <summary> /// Attempts to get the first shield from the equipment tracker. /// </summary> /// <param name="eqTracker">Equipment tracker to get shield from.</param> /// <returns>Shield if tracker has any or null if there is no shield.</returns> public static ThingWithComps GetShield(this Pawn_EquipmentTracker eqTracker) { return(eqTracker.AllEquipmentListForReading.FirstOrDefault(thing => thing.TryGetComp <CompShield>() != null)); }
public static Job TryGiveJobStatic(Pawn pawn, bool inCombat) { if (RestraintsUtility.InRestraints(pawn)) { return(null); } { //SetNextTryTick(pawn, Find.TickManager.TicksGame + UnityEngine.Random.Range(PickupCheckIntervalMin, PickupCheckIntervalMax)); Pawn_EquipmentTracker equipment = pawn.equipment; if (equipment == null) { return(null); } GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(pawn); if (pawnMemory == null) { return(null); } WeaponAssingment.reequipPrimaryIfNeededAndAvailable(pawn, pawnMemory); foreach (string wepName in pawnMemory.weapons) { ThingDef def = DefDatabase <ThingDef> .GetNamedSilentFail(wepName); if (def == null) { continue; } if (!pawn.hasWeaponSomewhere(wepName)) { ThingRequest request = new ThingRequest(); request.singleDef = def; float maxDist = 1000f; if (pawn.Faction != Faction.OfPlayer || inCombat) { maxDist = 30f; } Thing thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, request, PathEndMode.OnCell, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), maxDist, (Thing x) => (!x.IsForbidden(pawn)) && pawn.CanReserve(x, 1, -1, null, false)); if (thing == null) { continue; } if (!inCombat) { return(new Job(SidearmsDefOf.EquipSecondary, thing)); } else { return(new Job(SidearmsDefOf.EquipSecondaryCombat, thing, pawn.Position)); } } } return(null); } }