/// <summary> /// Attempts to equip a weapon from the inventory, puts currently equipped weapon into inventory if it exists /// </summary> /// <param name="useFists">Whether to put the currently equipped weapon away even if no replacement is found</param> public void SwitchToNextViableWeapon(bool useFists = true) { ThingWithComps newEq = null; // Stop current job if (parentPawn.jobs != null) { parentPawn.jobs.StopAll(); } // Cycle through available ranged weapons foreach (ThingWithComps gun in rangedWeaponListCached) { if (parentPawn.equipment != null && parentPawn.equipment.Primary != gun) { CompAmmoUser compAmmo = gun.TryGetComp <CompAmmoUser>(); if (compAmmo == null || compAmmo.HasAndUsesAmmoOrMagazine) { newEq = gun; break; } } } // If no ranged weapon was found, use first available melee weapons if (newEq == null) { newEq = meleeWeaponListCached.FirstOrDefault(); } // Equip the weapon if (newEq != null) { TrySwitchToWeapon(newEq); } else if (useFists) { // Put away current weapon ThingWithComps eq = parentPawn.equipment?.Primary; if (eq != null && !parentPawn.equipment.TryTransferEquipmentToContainer(eq, container)) { // If we can't put it into our inventory, drop it if (parentPawn.Position.InBounds(parentPawn.Map)) { ThingWithComps unused; parentPawn.equipment.TryDropEquipment(eq, out unused, parentPawn.Position); } else { #if DEBUG Log.Warning("CE :: CompInventory :: SwitchToNextViableWeapon :: destroying out of bounds equipment" + eq.ToString()); #endif if (!eq.Destroyed) { eq.Destroy(); } } } } }
protected override bool TryCastShot() { bool flag = false; this.TargetsAoE.Clear(); this.UpdateTargets(); int shotsPerBurst = this.ShotsPerBurst; bool flag2 = this.UseAbilityProps.AbilityTargetCategory != AbilityTargetCategory.TargetAoE && this.TargetsAoE.Count > 1; if (flag2) { this.TargetsAoE.RemoveRange(0, this.TargetsAoE.Count - 1); } bool flag3 = this.UseAbilityProps.mustHaveTarget && this.TargetsAoE.Count == 0; bool result; if (flag3) { Messages.Message("AU_NoTargets".Translate(), MessageTypeDefOf.RejectInput, true); this.Ability.Notify_AbilityFailed(true); result = false; } else { for (int i = 0; i < this.TargetsAoE.Count; i++) { ThingWithComps createdWeapon = (ThingWithComps)ThingMaker.MakeThing(RWBYDefOf.RWBY_Cinder_Blades); createdWeapon.TryGetComp <CompQuality>().SetQuality(QualityCategory.Masterwork, ArtGenerationContext.Colony); ThingWithComps currentWeapon = CasterPawn.equipment.AllEquipmentListForReading.Find(s => s.def.equipmentType.Equals(EquipmentType.Primary)); if (currentWeapon != null) { if (currentWeapon.TryGetComp <CompLightCopy>() != null) { currentWeapon.Destroy(); } else { CasterPawn.inventory.GetDirectlyHeldThings().TryAddOrTransfer(currentWeapon); } } CasterPawn.equipment.AddEquipment(createdWeapon); bool abilitySucceeded = true; if (abilitySucceeded) { flag = true; } } this.PostCastShot(flag, out flag); bool postSucceed = !flag; if (postSucceed) { this.Ability.Notify_AbilityFailed(this.UseAbilityProps.refundsPointsAfterFailing); } result = flag; } return(result); }
public void removeDroppedEquipment() { while (DroppedApparel.Any()) { Apparel apparel = DroppedApparel[0]; UsedApparelList.Remove(DroppedApparel[0]); if (apparel != null && apparel.Destroyed == false) { apparel.Destroy(); } } while (DroppedWeapons.Any()) { ThingWithComps weapon = DroppedWeapons[0]; UsedWeaponList.Remove(DroppedWeapons[0]); if (weapon != null && weapon.Destroyed == false) { weapon.Destroy(); } } }
public static void ConvertToZombie(ThingWithComps thing, bool force = false) { var pawn = thing is Corpse corpse ? corpse.InnerPawn : thing as Pawn; if (pawn == null || pawn.RaceProps.Humanlike == false) { return; } // clear zombie hediffs to avoid triggering this convert method again // var pawnName = pawn.Name; if (force == false && (pawn.health == null || pawnName == emptyName)) { return; } pawn.Name = emptyName; var pos = thing is IThingHolder?ThingOwnerUtility.GetRootPosition(thing as IThingHolder) : thing.Position; var map = thing is IThingHolder?ThingOwnerUtility.GetRootMap(thing as IThingHolder) : thing.Map; var tickManager = map.GetComponent <TickManager>(); var rot = pawn.Rotation; var wasInGround = thing.Map == null; if (map == null && thing.Destroyed == false) { thing.Destroy(); return; } var it = ZombieGenerator.SpawnZombieIterativ(pos, map, ZombieGenerator.ZombieType.Normal, (Zombie zombie) => { zombie.Name = pawnName; zombie.gender = pawn.gender; if (zombie.ageTracker != null && pawn.ageTracker != null) { zombie.ageTracker.AgeBiologicalTicks = pawn.ageTracker.AgeBiologicalTicks; zombie.ageTracker.AgeChronologicalTicks = pawn.ageTracker.AgeChronologicalTicks; zombie.ageTracker.BirthAbsTicks = pawn.ageTracker.BirthAbsTicks; } if (zombie.story != null && pawn.story != null) { zombie.story.childhood = pawn.story.childhood; zombie.story.adulthood = pawn.story.adulthood; zombie.story.melanin = pawn.story.melanin; zombie.story.crownType = pawn.story.crownType; zombie.story.hairDef = pawn.story.hairDef; zombie.story.bodyType = pawn.story.bodyType; } // redo because we changed stuff if (ZombieSettings.Values.useCustomTextures) { var it2 = ZombieGenerator.AssignNewGraphics(zombie); while (it2.MoveNext()) { ; } } var zTweener = Traverse.Create(zombie.Drawer.tweener); var pTweener = Traverse.Create(pawn.Drawer.tweener); new[] { "tweenedPos", "lastDrawFrame", "lastTickSpringPos" } .Do(field => zTweener.Field(field).SetValue(pTweener.Field(field).GetValue())); zombie.Rotation = rot; if (wasInGround == false) { zombie.rubbleCounter = Constants.RUBBLE_AMOUNT; zombie.state = ZombieState.Wandering; } zombie.wasMapPawnBefore = true; if (zombie.apparel != null && pawn.apparel != null) { zombie.apparel.DestroyAll(); pawn.apparel.WornApparel.ForEach(apparel => { if (pawn.apparel.TryDrop(apparel, out var newApparel)) { zombie.apparel.Wear(newApparel); newApparel.SetForbidden(false, false); newApparel.HitPoints = 1; var compQuality = newApparel.TryGetComp <CompQuality>(); if (compQuality != null) { compQuality.SetQuality(QualityCategory.Awful, ArtGenerationContext.Colony); } zombie.apparel.Notify_ApparelAdded(newApparel); } }); } if (thing is Corpse) { if (thing.Destroyed == false) { thing.Destroy(); } } else { var previousProgramState = Current.ProgramState; Current.ProgramState = ProgramState.Entry; pawn.Kill(null); Current.ProgramState = previousProgramState; Find.ColonistBar.MarkColonistsDirty(); if (pawn.Corpse != null && pawn.Corpse.Destroyed == false) { pawn.Corpse.Destroy(); } } tickManager.allZombiesCached.Add(zombie); var label = "BecameAZombieLabel".Translate(); var text = "BecameAZombieDesc".SafeTranslate(new object[] { pawnName.ToStringShort }); Find.LetterStack.ReceiveLetter(label, text, LetterDefOf.ThreatBig, zombie); }); while (it.MoveNext()) { ; } }