public void CurrVerbReset() { CompEquippable comp = parent.GetComp <CompEquippable>(); List <Verb> verbs = comp.AllVerbs; if (comp == null) { Log.ErrorOnce("[Explorite]CurrVerbReset Error: comp is null.", 41422); return; } if (verbs == null) { Log.ErrorOnce("[Explorite]CurrVerbReset Error: verbs is null, at comp: " + comp + ".", 41421); return; } if (verbs.Count == 0) { Log.ErrorOnce("[Explorite]CurrVerbReset Error: verbs contains no verb, at comp: " + comp + ", verbs:" + verbs + ".", 41423); return; } if (currentVerb != null) { for (int i = 0; i < verbs.Count; i++) { if (currentVerb == verbs[i]) { return; } } } for (int i = 0; i < verbs.Count; i++) { if (verbs[i].verbProps.isPrimary) { currentVerb = verbs[i]; return; } } currentVerb = verbs[0]; }
private static void DrawMeshModified(Mesh mesh, Vector3 position, Quaternion rotation, Material mat, int layer, Thing eq, float aimAngle) { CompOversizedWeapon compOversized = eq.TryGetCompFast <CompOversizedWeapon>(); CompEquippable equippable = eq.TryGetCompFast <CompEquippable>(); Pawn pawn = equippable.PrimaryVerb.CasterPawn; if (pawn == null) { return; } if (compOversized == null || (compOversized != null && compOversized.CompDeflectorIsAnimatingNow) || pawn == null || eq == null) { OversizedUtil.Draw(mesh, default(Matrix4x4), mat, layer, eq, pawn, position, rotation); return; } Vector3 s; if (pawn.RaceProps.Humanlike) { if (HarmonyPatches_OversizedWeapon.enabled_AlienRaces) { Vector2 v = AlienRaceUtility.AlienRacesPatch(pawn, eq); float f = Mathf.Max(v.x, v.y); s = new Vector3(eq.def.graphicData.drawSize.x * f, 1f, eq.def.graphicData.drawSize.y * f); } else { s = new Vector3(eq.def.graphicData.drawSize.x, 1f, eq.def.graphicData.drawSize.y); } } else { Vector2 v = pawn.ageTracker.CurKindLifeStage.bodyGraphicData.drawSize; s = new Vector3(eq.def.graphicData.drawSize.x + v.x / 10, 1f, eq.def.graphicData.drawSize.y + v.y / 10); } Matrix4x4 matrix = default(Matrix4x4); matrix.SetTRS(position, rotation, s); OversizedUtil.Draw(mesh, matrix, mat, 0, eq, pawn, position, rotation); }
// debugging /* * public static void TicksPerMove_PostFix(Pawn __instance, ref float __result, bool diagonal) { * if ( __instance.IsColonist ) { * float num = __instance.GetStatValue(StatDefOf.MoveSpeed, true); * // Log.Message("move speed : "+__instance.Name+ " : (GetStatValue of MoveSpeed:" +num+") (TicksPerMove:"+__result+")"); * } * } */ public static void PrimaryVerb_PostFix(CompEquippable __instance, ref Verb __result) { if (__instance.parent.TryGetComp <OgsCompSlotLoadable.CompSlotLoadable>() != null) { foreach (SlotLoadable slot in __instance.parent.TryGetComp <OgsCompSlotLoadable.CompSlotLoadable>().Slots) { if (slot.SlotOccupant != null) { CompSlottedBonus bonus = slot.SlotOccupant.TryGetComp <CompSlottedBonus>(); if (bonus.Props.verbReplacer != null) { __result.verbProps = bonus.Props.verbReplacer; return; } } } if (__result.verbProps.LaunchesProjectile && __result.verbProps != __instance.parent.def.Verbs[0]) { __result.verbProps = __instance.parent.def.Verbs[0]; } } }
public override string GetDescriptionPart() { string str = string.Empty; CompEquippable c = parent.GetComp <CompEquippable>(); if (ForceWeapon) { List <Tool> list = parent.def.tools.FindAll(x => x.capacities.Any(y => y.defName.Contains("OG_ForceWeapon_"))); List <string> listl = new List <string>(); list.ForEach(x => listl.Add(x.label)); str = str + string.Format("\n Force Weapon: Attacks made by the following Tools can cause Force Attacks if the wielder is a Psyker:\n{0}", listl.ToCommaList(), ForceWeaponKillChance); } if (Witchblade) { List <Tool> list = parent.def.tools.FindAll(x => x.capacities.Any(y => y.defName.Contains("OG_WitchbladeWeapon_"))); List <string> listl = new List <string>(); list.ForEach(x => listl.Add(x.label)); str = str + string.Format("\n Witchblade: Attacks made by the following Tools can cause increased damage if the wielder is a Psyker:\n{0}", listl.ToCommaList()); } return(str); }
public virtual void GiveDeflectJob(DamageInfo dinfo) { try { Pawn pawn2 = dinfo.Instigator as Pawn; if (pawn2 != null) { Job job = new Job(CompDeflectorDefOf.CastDeflectVerb); job.playerForced = true; job.locomotionUrgency = LocomotionUrgency.Sprint; if (pawn2.equipment != null) { CompEquippable compEquip = pawn2.equipment.PrimaryEq; if (compEquip != null) { if (compEquip.PrimaryVerb != null) { Verb_Deflected verbToUse = (Verb_Deflected)CopyAndReturnNewVerb(compEquip.PrimaryVerb); verbToUse = (Verb_Deflected)ReflectionHandler(deflectVerb); verbToUse.lastShotReflected = this.lastShotReflected; pawn2 = ResolveDeflectionTarget(pawn2); bool shouldContinue = false; CriticalFailureHandler(dinfo, pawn2, out shouldContinue); if (shouldContinue) { job.targetA = pawn2; job.verbToUse = verbToUse; job.killIncappedTarget = pawn2.Downed; GetPawn.jobs.TryTakeOrderedJob(job); } } } } } } catch (NullReferenceException) { } ////Log.Message("TryToTakeOrderedJob Called"); }
// Token: 0x06000028 RID: 40 RVA: 0x00002978 File Offset: 0x00000B78 public static bool Patch_VerbTracker_PrimaryVerb_Prefix(ref VerbTracker __instance, ref Verb __result) { bool flag = __instance.AllVerbs == null && MechaniteForgeHarmonyPatches.VerbTracker_InitVerbs != null; if (flag) { MechaniteForgeHarmonyPatches.VerbTracker_InitVerbs.Invoke(__instance, new object[0]); } CompEquippable compEquippable = __instance.directOwner as CompEquippable; MultiVerbComp multiVerbComp = null; bool flag2 = compEquippable != null && (multiVerbComp = compEquippable.parent.TryGetComp <MultiVerbComp>()) != null; if (flag2) { __result = __instance.AllVerbs[multiVerbComp.currentVerbIndex]; bool flag3 = __result != null; if (flag3) { return(false); } } return(true); }
public static IEnumerable <Command> Postfix(IEnumerable <Command> commands, CompEquippable __instance) { if (__instance is CompEquipable_SecondaryThrown compSec && __instance.ParentHolder?.ParentHolder is Pawn pawn && pawn.IsColonistPlayerControlled) { //Log.Message($"Found CompEquipable_SecondaryThrown"); ThingWithComps owner = __instance.parent; //Want to return a verb that allows for single throws yield return(new VerbTarget_ThrownLight() { defaultDesc = owner.LabelCap + ": " + owner.def.description.CapitalizeFirst(), icon = owner.def.uiIcon, iconAngle = owner.def.uiIconAngle, iconOffset = owner.def.uiIconOffset, verb = __instance.PrimaryVerb, comp = owner.GetComp <Comp_ChangeableProjectile_Thrown>() }); } foreach (Command command in commands) { yield return(command); } }
public static void TryStartCastOn_SmartGun_Prefix(ref Verb __instance, LocalTargetInfo castTarg, ref bool __result) { if (__instance.GetType() == typeof(Verb_Shoot)) { if (__instance.GetProjectile() != null) { // Log.Message("checking for EquipmentSource"); if (__instance.EquipmentSource != null) { if (!__instance.EquipmentSource.AllComps.NullOrEmpty()) { // Log.Message("checking for smartgun"); if (__instance.EquipmentSource.GetComp <CompSmartgunSystem>() != null) { if (__instance.EquipmentSource.GetComp <CompSmartgunSystem>() is CompSmartgunSystem GunExt) { // Log.Message("smartgun checking for targeter"); Thing equipment = __instance.EquipmentSource; CompEquippable eq = __instance.EquipmentSource.TryGetComp <CompEquippable>(); Pawn pawn = __instance.CasterPawn; if (GunExt.hasTargheter) { __instance.verbProps.warmupTime = GunExt.AdjustedWarmup; // Log.Message(string.Format("smartgun adjusted warmup: {0}", GunExt.AdjustedWarmup)); } else { __instance.verbProps.warmupTime = GunExt.originalwarmupTime; // Log.Message(string.Format("smartgun original warmup: {0}", GunExt.originalwarmupTime)); } } } } } } } }
public static void TryStartCastOn_RapidFire_Postfix(ref Verb __instance, LocalTargetInfo castTarg, float __state) { List <Type> types = typeof(Verb_LaunchProjectile).AllSubclassesNonAbstract().ToList(); types.Add(typeof(Verb_LaunchProjectile)); List <Type> nottypes = typeof(AbilityUser.Verb_UseAbility).AllSubclassesNonAbstract().ToList(); nottypes.Add(typeof(AbilityUser.Verb_UseAbility)); if (!types.Contains(__instance.GetType()) || nottypes.Contains(__instance.GetType())) { /* * List<string> listl = new List<string>(); * types.ForEach(x => listl.Add(x.Name)); * Log.Message(string.Format("Mismatched Verbtype: {0}, needs {1}", __instance.GetType(), listl.ToCommaList())); */ return; } if (__instance.EquipmentSource != null) { ThingWithComps gun = __instance.EquipmentSource; CompEquippable compeq = gun.TryGetComp <CompEquippable>(); if (!__instance.EquipmentSource.AllComps.NullOrEmpty()) { if (__instance.EquipmentSource.GetComp <CompWeapon_GunSpecialRules>() != null) { if (__instance.EquipmentSource.GetComp <CompWeapon_GunSpecialRules>() is CompWeapon_GunSpecialRules GunExt) { if (GunExt.OriginalwarmupTime != 0) { __instance.verbProps.warmupTime = (float)GunExt.OriginalwarmupTime; } } } } // Log.Message(string.Format("postfix Instance modified Values, Warmup: {0}, ticksbetween: {1}, cooldown: {2}", __instance.verbProps.warmupTime, __instance.verbProps.ticksBetweenBurstShots, __instance.verbProps.defaultCooldownTime)); } }
/// <summary> /// Refreshes the cached bulk and weight. Call this whenever items are added/removed from inventory /// </summary> public void UpdateInventory() { if (parentPawn == null) { Log.Error("CompInventory on non-pawn " + this.parent.ToString()); return; } float newBulk = 0f; float newWeight = 0f; // Add equipped weapon if (parentPawn.equipment != null && parentPawn.equipment.Primary != null) { GetEquipmentStats(parentPawn.equipment.Primary, out newWeight, out newBulk); } // Add apparel if (parentPawn.apparel != null && parentPawn.apparel.WornApparelCount > 0) { foreach (Thing apparel in parentPawn.apparel.WornApparel) { float apparelBulk = apparel.GetStatValue(StatDef.Named("WornBulk")); float apparelWeight = apparel.GetStatValue(StatDef.Named("WornWeight")); newBulk += apparelBulk; newWeight += apparelWeight; } } // Add inventory items if (parentPawn.inventory != null && parentPawn.inventory.container != null) { ammoListCached.Clear(); meleeWeaponListCached.Clear(); rangedWeaponListCached.Clear(); foreach (Thing thing in parentPawn.inventory.container) { // Check for weapons ThingWithComps eq = thing as ThingWithComps; CompEquippable compEq = thing.TryGetComp <CompEquippable>(); if (eq != null && compEq != null) { if (compEq.PrimaryVerb != null) { rangedWeaponListCached.Add(eq); } else { meleeWeaponListCached.Add(eq); } // Calculate equipment weight float eqWeight; float eqBulk; GetEquipmentStats(eq, out eqWeight, out eqBulk); newWeight += eqWeight * thing.stackCount; newBulk += eqBulk * thing.stackCount; } else { // Add item weight newBulk += thing.GetStatValue(StatDef.Named("Bulk")) * thing.stackCount; newWeight += thing.GetStatValue(StatDef.Named("Weight")) * thing.stackCount; } // Update ammo list if (thing.def is AmmoDef) { ammoListCached.Add(thing); } } } this.currentBulkCached = newBulk; this.currentWeightCached = newWeight; }
public List <VerbEntry> GetUpdatedAvailableVerbsList() { Profiler.BeginSample("GetUpdatedAvailableVerbsList"); Pawn_MeleeVerbs.meleeVerbs.Clear(); List <Verb> allVerbs = this.pawn.verbTracker.AllVerbs; for (int i = 0; i < allVerbs.Count; i++) { if (allVerbs[i].IsStillUsableBy(this.pawn)) { Pawn_MeleeVerbs.meleeVerbs.Add(new VerbEntry(allVerbs[i], this.pawn, null)); } } if (this.pawn.equipment != null) { List <ThingWithComps> allEquipmentListForReading = this.pawn.equipment.AllEquipmentListForReading; for (int j = 0; j < allEquipmentListForReading.Count; j++) { ThingWithComps thingWithComps = allEquipmentListForReading[j]; CompEquippable comp = thingWithComps.GetComp <CompEquippable>(); if (comp != null) { List <Verb> allVerbs2 = comp.AllVerbs; if (allVerbs2 != null) { for (int k = 0; k < allVerbs2.Count; k++) { if (allVerbs2[k].IsStillUsableBy(this.pawn)) { Pawn_MeleeVerbs.meleeVerbs.Add(new VerbEntry(allVerbs2[k], this.pawn, thingWithComps)); } } } } } } if (this.pawn.apparel != null) { List <Apparel> wornApparel = this.pawn.apparel.WornApparel; for (int l = 0; l < wornApparel.Count; l++) { Apparel apparel = wornApparel[l]; CompEquippable comp2 = apparel.GetComp <CompEquippable>(); if (comp2 != null) { List <Verb> allVerbs3 = comp2.AllVerbs; if (allVerbs3 != null) { for (int m = 0; m < allVerbs3.Count; m++) { if (allVerbs3[m].IsStillUsableBy(this.pawn)) { Pawn_MeleeVerbs.meleeVerbs.Add(new VerbEntry(allVerbs3[m], this.pawn, apparel)); } } } } } } foreach (Verb verb in this.pawn.health.hediffSet.GetHediffsVerbs()) { if (verb.IsStillUsableBy(this.pawn)) { Pawn_MeleeVerbs.meleeVerbs.Add(new VerbEntry(verb, this.pawn, null)); } } if (this.pawn.Spawned) { TerrainDef terrainDef = this.pawn.Map.terrainGrid.TerrainAt(this.pawn.Position); if (this.terrainVerbs == null || this.terrainVerbs.def != terrainDef) { this.terrainVerbs = Pawn_MeleeVerbs_TerrainSource.Create(this, terrainDef); } List <Verb> allVerbs4 = this.terrainVerbs.tracker.AllVerbs; for (int n = 0; n < allVerbs4.Count; n++) { Verb verb2 = allVerbs4[n]; if (verb2.IsStillUsableBy(this.pawn)) { Pawn_MeleeVerbs.meleeVerbs.Add(new VerbEntry(verb2, this.pawn, null)); } } } Profiler.EndSample(); return(Pawn_MeleeVerbs.meleeVerbs); }
public static void TryStartCastOn_RapidFire_Prefix(ref Verb __instance, LocalTargetInfo castTarg, float __state, ref bool __result) { if (__instance.GetType() == typeof(Verb_Shoot)) { if (__instance.EquipmentSource != null && __instance.CasterPawn != null) { Pawn pawn = __instance.CasterPawn; if (castTarg != null /*&& castTarg.HasThing*/ && __instance.CanHitTarget(castTarg)) { if (__instance.EquipmentSource.TryGetComp <CompLaserCapacitor>() != null) { if (__instance.EquipmentSource.GetComp <CompLaserCapacitor>() is CompLaserCapacitor GunExt) { if (GunExt.initalized == false) { GunExt.originalwarmupTime = __instance.verbProps.warmupTime; GunExt.initalized = true; } if (GunExt.hotshot) { CompEquippable eq = __instance.EquipmentSource.TryGetComp <CompEquippable>(); IntVec3 lastpos = (IntVec3)GunExt.lastFiringLocation; if (lastpos == pawn.Position) { GunExt.shotstack++; __instance.verbProps.warmupTime = Math.Max(GunExt.originalwarmupTime - (GunExt.Props.WarmUpReductionPerShot * GunExt.shotstack), 0); } else { GunExt.shotstack = 0; __instance.verbProps.warmupTime = GunExt.originalwarmupTime; } GunExt.lastFiringLocation = pawn.Position; if (GunExt.Props.Overheats && __instance.verbProps.warmupTime == 0f) { if (Rand.Chance(GunExt.Props.OverheatChance)) { GunExt.CriticalOverheatExplosion((Verb_Shoot)__instance); if (GunExt.Props.OverheatDestroys) { eq.parent.Destroy(); } } else { if (GunExt.Props.OverheatMoteThrown != null) { MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(GunExt.Props.OverheatMoteThrown, null); moteThrown.Scale = Rand.Range(2f, 3f) * GunExt.Props.OverheatMoteSize; moteThrown.exactPosition = GunExt.lastFiringLocation.CenterVector3; moteThrown.rotationRate = Rand.Range(-0.5f, 0.5f); moteThrown.SetVelocity((float)Rand.Range(30, 40), Rand.Range(0.008f, 0.012f)); GenSpawn.Spawn(moteThrown, GunExt.lastFiringLocation.Cell, pawn.Map, WipeMode.Vanish); } } } } else { if (GunExt.originalwarmupTime != 0) { __instance.verbProps.warmupTime = GunExt.originalwarmupTime; } } } } } } } }
public static void DrawMeshModified(Mesh mesh, Vector3 position, Quaternion rotation, Material mat, int layer, Thing eq, float aimAngle) { if (enabled_YayosCombat) { Log.Message("Yayos Oversized"); } CompOversizedWeapon compOversized = eq.TryGetCompFast <CompOversizedWeapon>(); CompEquippable equippable = eq.TryGetCompFast <CompEquippable>(); Pawn pawn = equippable.PrimaryVerb.CasterPawn; if (pawn == null) { return; } if (compOversized == null || (compOversized != null && compOversized.CompDeflectorIsAnimatingNow) || pawn == null || eq == null) { OversizedUtil.Draw(mesh, default(Matrix4x4), mat, layer, eq, pawn, position, rotation); return; } ThingWithComps thingWithComps = eq as ThingWithComps; bool DualWeapon = compOversized.Props != null && compOversized.Props.isDualWeapon; float offHandAngle = aimAngle; float mainHandAngle = aimAngle; Stance_Busy stance_Busy = pawn.stances.curStance as Stance_Busy; LocalTargetInfo localTargetInfo = null; if (stance_Busy != null && !stance_Busy.neverAimWeapon) { localTargetInfo = stance_Busy.focusTarg; } bool Aiming = OversizedUtil.CurrentlyAiming(stance_Busy); Vector3 offsetMainHand = default(Vector3); Vector3 offsetOffHand = default(Vector3); if (compOversized.Props != null) { OversizedUtil.SetAnglesAndOffsets(eq, thingWithComps, aimAngle, pawn, ref offsetMainHand, ref offsetOffHand, ref offHandAngle, ref mainHandAngle, Aiming, DualWeapon && Aiming); } if (DualWeapon) { Vector3 drawLoc = position + offsetMainHand; compOversized.renderPos = drawLoc; PawnRenderer_DrawEquipmentAiming_Vanilla_Transpiler.DrawEquipmentAimingOverride(mesh, eq, drawLoc, offHandAngle, compOversized, equippable, pawn); } if (Aiming && localTargetInfo != null) { mainHandAngle = OversizedUtil.GetAimingRotation(pawn, localTargetInfo); offsetMainHand.y += 0.1f; Vector3 drawLoc2 = pawn.DrawPos + new Vector3(0f, 0f, 0.4f).RotatedBy(mainHandAngle) + (DualWeapon ? offsetOffHand : offsetMainHand); if (DualWeapon) { compOversized.renderPosDual = drawLoc2; } else { compOversized.renderPos = drawLoc2; } PawnRenderer_DrawEquipmentAiming_Vanilla_Transpiler.DrawEquipmentAimingOverride(mesh, thingWithComps, drawLoc2, (DualWeapon ? mainHandAngle : aimAngle), compOversized, equippable, pawn, DualWeapon); } else { Vector3 drawLoc2 = position + (DualWeapon ? offsetOffHand : offsetMainHand); if (DualWeapon) { compOversized.renderPosDual = drawLoc2; } else { compOversized.renderPos = drawLoc2; } PawnRenderer_DrawEquipmentAiming_Vanilla_Transpiler.DrawEquipmentAimingOverride(mesh, thingWithComps, drawLoc2, (DualWeapon ? mainHandAngle : aimAngle), compOversized, equippable, pawn, false); } }
/// <summary> /// Refreshes the cached bulk and weight. Call this whenever items are added/removed from inventory /// </summary> public void UpdateInventory() { if (parentPawn == null) { Log.Error("CompInventory on non-pawn " + parent.ToString()); return; } float newBulk = 0f; float newWeight = 0f; // Add equipped weapon if (parentPawn.equipment != null && parentPawn.equipment.Primary != null) { GetEquipmentStats(parentPawn.equipment.Primary, out newWeight, out newBulk); } // Add apparel if (parentPawn.apparel != null && parentPawn.apparel.WornApparelCount > 0) { foreach (Thing apparel in parentPawn.apparel.WornApparel) { float apparelBulk = apparel.GetStatValue(CE_StatDefOf.WornBulk); float apparelWeight = apparel.GetStatValue(StatDefOf.Mass); newBulk += apparelBulk; newWeight += apparelWeight; if (apparelBulk > 0 && parentPawn != null && parentPawn.IsColonist && parentPawn.Spawned) { LessonAutoActivator.TeachOpportunity(CE_ConceptDefOf.CE_WornBulk, OpportunityType.GoodToKnow); } } } // Add inventory items if (parentPawn.inventory != null && parentPawn.inventory.innerContainer != null) { ammoListCached.Clear(); meleeWeaponListCached.Clear(); rangedWeaponListCached.Clear(); List <HoldRecord> recs = LoadoutManager.GetHoldRecords(parentPawn); foreach (Thing thing in parentPawn.inventory.innerContainer) { // Check for weapons ThingWithComps eq = thing as ThingWithComps; CompEquippable compEq = thing.TryGetComp <CompEquippable>(); if (eq != null && compEq != null) { if (eq.def.IsRangedWeapon) { rangedWeaponListCached.Add(eq); } else { meleeWeaponListCached.Add(eq); } // Calculate equipment weight float eqWeight; float eqBulk; GetEquipmentStats(eq, out eqWeight, out eqBulk); newWeight += eqWeight * thing.stackCount; newBulk += eqBulk * thing.stackCount; } else { // Add item weight newBulk += thing.GetStatValue(CE_StatDefOf.Bulk) * thing.stackCount; newWeight += thing.GetStatValue(StatDefOf.Mass) * thing.stackCount; } // Update ammo list if (thing.def is AmmoDef) { ammoListCached.Add(thing); } if (recs != null) { HoldRecord rec = recs.FirstOrDefault(hr => hr.thingDef == thing.def); if (rec != null && !rec.pickedUp) { rec.pickedUp = true; } } } } currentBulkCached = newBulk; currentWeightCached = newWeight; }
public override IEnumerable <Gizmo> EquippedGizmos() { ThingWithComps owner = IsWorn ? GetWearer : parent; bool flag = Find.Selector.SingleSelectedThing == GetWearer; // Log.Message(string.Format("0")); if (flag) { CompEquippable c = parent.GetComp <CompEquippable>(); // Log.Message(string.Format("there are {0} verbs", c.verbTracker.AllVerbs.Count)); // Verb verbA = parent.def.Verbs; foreach (Verb v in c.verbTracker.AllVerbs) { // Log.Message(string.Format("v fires {0} {1}", v.verbProps.burstShotCount, v.verbProps.defaultProjectile.label)); if (v != v.verbTracker.PrimaryVerb && !v.IsMeleeAttack) { // Log.Message(string.Format("selected v fires {0} {1}", v.verbProps.burstShotCount, v.verbProps.defaultProjectile.label)); verb = v; Command_VerbTarget command_VerbTarget = new Command_VerbTarget(); command_VerbTarget.defaultDesc = parent.LabelCap + ": " + parent.def.description.CapitalizeFirst(); command_VerbTarget.icon = parent.def.uiIcon; command_VerbTarget.iconAngle = parent.def.uiIconAngle; command_VerbTarget.iconOffset = parent.def.uiIconOffset; command_VerbTarget.tutorTag = "VerbTarget"; command_VerbTarget.verb = verb; command_VerbTarget.verb.verbProps = verb.verbProps; command_VerbTarget.verb.verbProps.defaultProjectile = verb.verbProps.defaultProjectile; command_VerbTarget.verb.verbProps.defaultCooldownTime = verb.verbProps.defaultCooldownTime; command_VerbTarget.verb.verbProps.burstShotCount = verb.verbProps.burstShotCount; command_VerbTarget.verb.verbProps.verbClass = verb.verbProps.verbClass; command_VerbTarget.verb.verbProps.warmupTime = verb.verbProps.warmupTime; command_VerbTarget.verb.verbProps.ticksBetweenBurstShots = verb.verbProps.ticksBetweenBurstShots; command_VerbTarget.verb.verbProps.soundCast = verb.verbProps.soundCast; command_VerbTarget.defaultLabel = "Fire: " + parent.def.label; command_VerbTarget.activateSound = SoundDef.Named("Click"); if (verb.caster.Faction != Faction.OfPlayer) { command_VerbTarget.Disable("CannotOrderNonControlled".Translate()); } else if (verb.CasterIsPawn) { if (verb.CasterPawn.story.WorkTagIsDisabled(WorkTags.Violent)) { command_VerbTarget.Disable("IsIncapableOfViolence".Translate(verb.CasterPawn.LabelShort, verb.CasterPawn)); } else if (!verb.CasterPawn.drafter.Drafted) { command_VerbTarget.Disable("IsNotDrafted".Translate(verb.CasterPawn.LabelShort, verb.CasterPawn)); } } yield return(command_VerbTarget); } else { Command_Action command_Action = new Command_Action(); command_Action.defaultLabel = parent.def.label; command_Action.defaultDesc = "This colonist is equipped with a " + parent.def.label; command_Action.hotKey = KeyBindingDefOf.Misc2; command_Action.icon = parent.def.uiIcon; command_Action.disabled = true; yield return(command_Action); } } } yield break; }
public List <VerbEntry> GetUpdatedAvailableVerbsList(bool terrainTools) { meleeVerbs.Clear(); verbsToAdd.Clear(); if (!terrainTools) { List <Verb> allVerbs = pawn.verbTracker.AllVerbs; for (int i = 0; i < allVerbs.Count; i++) { if (IsUsableMeleeVerb(allVerbs[i])) { verbsToAdd.Add(allVerbs[i]); } } if (pawn.equipment != null) { List <ThingWithComps> allEquipmentListForReading = pawn.equipment.AllEquipmentListForReading; for (int j = 0; j < allEquipmentListForReading.Count; j++) { CompEquippable comp = allEquipmentListForReading[j].GetComp <CompEquippable>(); if (comp == null) { continue; } List <Verb> allVerbs2 = comp.AllVerbs; if (allVerbs2 == null) { continue; } for (int k = 0; k < allVerbs2.Count; k++) { if (IsUsableMeleeVerb(allVerbs2[k])) { verbsToAdd.Add(allVerbs2[k]); } } } } if (pawn.apparel != null) { List <Apparel> wornApparel = pawn.apparel.WornApparel; for (int l = 0; l < wornApparel.Count; l++) { CompEquippable comp2 = wornApparel[l].GetComp <CompEquippable>(); if (comp2 == null) { continue; } List <Verb> allVerbs3 = comp2.AllVerbs; if (allVerbs3 == null) { continue; } for (int m = 0; m < allVerbs3.Count; m++) { if (IsUsableMeleeVerb(allVerbs3[m])) { verbsToAdd.Add(allVerbs3[m]); } } } } foreach (Verb hediffsVerb in pawn.health.hediffSet.GetHediffsVerbs()) { if (IsUsableMeleeVerb(hediffsVerb)) { verbsToAdd.Add(hediffsVerb); } } } else if (pawn.Spawned) { TerrainDef terrain = pawn.Position.GetTerrain(pawn.Map); if (terrainVerbs == null || terrainVerbs.def != terrain) { terrainVerbs = Pawn_MeleeVerbs_TerrainSource.Create(this, terrain); } List <Verb> allVerbs4 = terrainVerbs.tracker.AllVerbs; for (int n = 0; n < allVerbs4.Count; n++) { Verb verb = allVerbs4[n]; if (IsUsableMeleeVerb(verb)) { verbsToAdd.Add(verb); } } } float num = 0f; foreach (Verb item in verbsToAdd) { float num2 = VerbUtility.InitialVerbWeight(item, pawn); if (num2 > num) { num = num2; } } foreach (Verb item2 in verbsToAdd) { meleeVerbs.Add(new VerbEntry(item2, pawn, verbsToAdd, num)); } return(meleeVerbs); bool IsUsableMeleeVerb(Verb v) { if (v.IsStillUsableBy(pawn)) { return(v.IsMeleeAttack); } return(false); } }
public static bool Muzzle(this Thing thing, out float barrelLength, out float barrelOffset, out float bulletOffset, out FleckDef flareDef, out float flareSize, out FleckDef smokeDef, out float smokeSize) { bool result = false; IMuzzlePosition m; barrelLength = 0; barrelOffset = 0; bulletOffset = 0; flareDef = null; flareSize = 0; smokeDef = null; smokeSize = 0; string rstring = "\nbarrelLength: {0} barrelOffset: {1}\nflareDef: {2} flareSize: {3}\nsmokeDef: {4} smokeSize: {5}"; StringBuilder builder = new StringBuilder(); CompEquippable eq = thing.TryGetCompFast <CompEquippable>(); if (eq != null) { if ((m = eq.PrimaryVerb?.verbProps as IMuzzlePosition) != null) { result = true; barrelLength = m.BarrelLength; barrelOffset = m.BarrelOffset; bulletOffset = m.BulletOffset; flareDef ??= m.MuzzleFlareDef; flareSize = m.MuzzleFlareSize > 0 ? m.MuzzleFlareSize : flareSize; smokeDef ??= m.MuzzleSmokeDef; smokeSize = m.MuzzleSmokeSize > 0 ? m.MuzzleSmokeSize : smokeSize; builder.AppendLine("m = " + thing.Label + " verbProps" + string.Format(rstring, barrelLength, barrelOffset, flareDef, flareSize, smokeDef, smokeSize)); } else { if ((m = thing as IMuzzlePosition) != null) { result = true; barrelLength = m.BarrelLength; barrelOffset = m.BarrelOffset; bulletOffset = m.BulletOffset; flareDef ??= m.MuzzleFlareDef; flareSize = m.MuzzleFlareSize > 0 ? m.MuzzleFlareSize : flareSize; smokeDef ??= m.MuzzleSmokeDef; smokeSize = m.MuzzleSmokeSize > 0 ? m.MuzzleSmokeSize : smokeSize; builder.AppendLine("m = " + thing.Label + " IMuzzlePosition" + string.Format(rstring, barrelLength, barrelOffset, flareDef, flareSize, smokeDef, smokeSize)); } if ((m = thing.def.GetModExtensionFast <BarrelOffsetExtension>()) != null) { result = true; barrelLength = m.BarrelLength; barrelOffset = m.BarrelOffset; bulletOffset = m.BulletOffset; flareDef ??= m.MuzzleFlareDef; flareSize = m.MuzzleFlareSize > 0 ? m.MuzzleFlareSize : flareSize; smokeDef ??= m.MuzzleSmokeDef; smokeSize = m.MuzzleSmokeSize > 0 ? m.MuzzleSmokeSize : smokeSize; builder.AppendLine("m = " + thing.Label + " BarrelOffsetExtension" + string.Format(rstring, barrelLength, barrelOffset, flareDef, flareSize, smokeDef, smokeSize)); } } if ((m = eq.PrimaryVerb?.GetProjectile()?.GetModExtensionFast <ProjectileVFX>()) != null) { result = true; barrelLength += m.BarrelLength; barrelOffset += m.BarrelOffset; bulletOffset += m.BulletOffset; flareDef ??= m.MuzzleFlareDef; flareSize = m.MuzzleFlareSize > 0 ? m.MuzzleFlareSize : flareSize; smokeDef ??= m.MuzzleSmokeDef; smokeSize = m.MuzzleSmokeSize > 0 ? m.MuzzleSmokeSize : smokeSize; builder.AppendLine("m = " + thing.Label + " PrimaryVerb GetProjectile" + string.Format(rstring, barrelLength, barrelOffset, flareDef, flareSize, smokeDef, smokeSize)); } } else { if ((m = thing.def.GetModExtensionFast <ProjectileVFX>()) != null) { result = true; barrelLength += m.BarrelLength; barrelOffset += m.BarrelOffset; bulletOffset += m.BulletOffset; flareDef ??= m.MuzzleFlareDef; flareSize = m.MuzzleFlareSize > 0 ? m.MuzzleFlareSize : flareSize; smokeDef ??= m.MuzzleSmokeDef; smokeSize = m.MuzzleSmokeSize > 0 ? m.MuzzleSmokeSize : smokeSize; builder.AppendLine("m = " + thing.Label + " EffectProjectileExtension" + string.Format(rstring, barrelLength, barrelOffset, flareDef, flareSize, smokeDef, smokeSize)); } } if (builder.Length > 0 && MechanicusDebugViewSettings.drawMuzzlePosition) { // Log.Message(builder.ToString()); } return(result); }
public override float GetValueUnfinalized(StatRequest req, bool applyPostProcess = true) { if (!(req.Def is ThingDef def)) { return(0.0f); } CompEquippable equipComp = null; CompLootAffixableThing lootComp = null; if (req.HasThing) { var thing = (ThingWithComps)req.Thing; equipComp = thing.TryGetComp <CompEquippable>(); lootComp = thing.TryGetComp <CompLootAffixableThing>(); } Verb verb = equipComp?.AllVerbs.First(v => v.verbProps.isPrimary); VerbProperties verbProps = verb != null ? verb.verbProps : def.Verbs.First(vp => vp.isPrimary); Pawn attacker = req.HasThing ? GetCurrentWeaponUser(req.Thing) : null; var projProps = verbProps.defaultProjectile.projectile; var projModifier = (LootAffixModifier_VerbPropertiesChange_Def)lootComp?.AllModifiers.FirstOrFallback( lam => lam.AppliesTo == ModifierTarget.VerbProperties && lam is LootAffixModifier_VerbPropertiesChange_Def lamVPCD && lamVPCD.affectedField == "defaultProjectile" ); ThingDef modProjectile = projModifier != null ? (ThingDef)projModifier.resolvedDef : null; var modProjProps = modProjectile?.projectile; float chance = modProjProps != null ? 1f - projModifier.GetRealChance(lootComp.parent) : 1f; if (chance <= 0.05f) { chance = 1f; // already permanently set to "base" verbProps } float baseDamage = projProps.damageDef.harmsHealth == false ? 0f : req.HasThing ? projProps.GetDamageAmount(req.Thing) : req.StuffDef != null?projProps.GetDamageAmount(def.GetStatValueAbstract(StatDefOf.RangedWeapon_DamageMultiplier, req.StuffDef)) : projProps.GetDamageAmount(def.GetStatValueAbstract(StatDefOf.RangedWeapon_DamageMultiplier)) ; float damage = baseDamage * verbProps.burstShotCount * chance; if (chance < 1f) { float modChance = 1f - chance; float modBaseDamage = modProjProps.damageDef.harmsHealth == false ? 0f : modProjProps.GetDamageAmount(req.Thing) ; damage += modBaseDamage * verbProps.burstShotCount * modChance; } // FIXME: Confirm warmupTime (and AimingDelayFactor) is used in a full shot cycle // FIXME: warmupTime * this.CasterPawn.GetStatValue(StatDefOf.AimingDelayFactor, true)).SecondsToTicks() float secondsSpent = 0; if (verb != null) { secondsSpent = verbProps.AdjustedFullCycleTime(verb, attacker); } else { secondsSpent = verbProps.warmupTime + ((verbProps.burstShotCount - 1) * verbProps.ticksBetweenBurstShots).TicksToSeconds(); secondsSpent += req.HasThing ? req.Thing.GetStatValue(StatDefOf.RangedWeapon_Cooldown, true) : req.StuffDef != null?def.GetStatValueAbstract(StatDefOf.RangedWeapon_Cooldown, req.StuffDef) : def.GetStatValueAbstract(StatDefOf.RangedWeapon_Cooldown) ; } // Every integer range possible as an average float avgAccuracy = 0; for (int i = 3; i <= verbProps.range; i++) { float rngAccuracy = verbProps.GetHitChanceFactor(req.Thing, i); if (attacker != null) { rngAccuracy *= ShotReport.HitFactorFromShooter(attacker, i); } avgAccuracy += rngAccuracy; } if (verbProps.range >= 3) { avgAccuracy /= verbProps.range - 2; } return(secondsSpent == 0 ? 0.0f : damage / secondsSpent * avgAccuracy); }
public override string GetExplanationUnfinalized(StatRequest req, ToStringNumberSense numberSense) { if (!(req.Def is ThingDef def)) { return(null); } /* Damage section */ CompEquippable equipComp = null; CompLootAffixableThing lootComp = null; if (req.HasThing) { var thing = (ThingWithComps)req.Thing; equipComp = thing.TryGetComp <CompEquippable>(); lootComp = thing.TryGetComp <CompLootAffixableThing>(); } Verb verb = equipComp?.AllVerbs.First(v => v.verbProps.isPrimary); VerbProperties verbProps = verb != null ? verb.verbProps : def.Verbs.First(vp => vp.isPrimary); Pawn attacker = req.HasThing ? GetCurrentWeaponUser(req.Thing) : null; var projProps = verbProps.defaultProjectile.projectile; var projModifier = (LootAffixModifier_VerbPropertiesChange_Def)lootComp?.AllModifiers.FirstOrFallback( lam => lam.AppliesTo == ModifierTarget.VerbProperties && lam is LootAffixModifier_VerbPropertiesChange_Def lamVPCD && lamVPCD.affectedField == "defaultProjectile" ); ThingDef modProjectile = projModifier != null ? (ThingDef)projModifier.resolvedDef : null; var modProjProps = modProjectile?.projectile; float chance = modProjProps != null ? 1f - projModifier.GetRealChance(lootComp.parent) : 1f; if (chance <= 0.05f) { chance = 1f; // already permanently set to "base" verbProps } string chanceStr = GenText.ToStringPercent(chance); float baseDamage = projProps.damageDef.harmsHealth == false ? 0f : req.HasThing ? projProps.GetDamageAmount(req.Thing) : req.StuffDef != null?projProps.GetDamageAmount(def.GetStatValueAbstract(StatDefOf.RangedWeapon_DamageMultiplier, req.StuffDef)) : projProps.GetDamageAmount(def.GetStatValueAbstract(StatDefOf.RangedWeapon_DamageMultiplier)) ; float damage = baseDamage * verbProps.burstShotCount * chance; string reportText = "Damage".Translate() + ":\n"; if (chance < 1f) { reportText += " " + "RimLoot_StatsReport_ProjectileWithChance".Translate( verbProps.defaultProjectile.Named("PROJECTILE"), chanceStr.Named("chance") ) + "\n"; reportText += string.Format(" {0}: {1} * {2} * {3} = {4}\n\n", "Damage".Translate(), baseDamage.ToStringDecimalIfSmall(), verbProps.burstShotCount, chanceStr, damage.ToStringDecimalIfSmall() ); float modChance = 1f - chance; string modChanceStr = GenText.ToStringPercent(modChance); float modBaseDamage = modProjProps.damageDef.harmsHealth == false ? 0f : modProjProps.GetDamageAmount(req.Thing) ; float modDamage = modBaseDamage * verbProps.burstShotCount * modChance; reportText += " " + "RimLoot_StatsReport_ProjectileWithChance".Translate( modProjectile.Named("PROJECTILE"), modChanceStr.Named("chance") ) + "\n"; reportText += string.Format(" {0}: {1} * {2} * {3} = {4}\n\n", "Damage".Translate(), modBaseDamage.ToStringDecimalIfSmall(), verbProps.burstShotCount, modChanceStr, modDamage.ToStringDecimalIfSmall() ); reportText += string.Format("{0}: {1}\n\n", "StatsReport_TotalValue".Translate(), (damage + modDamage).ToStringDecimalIfSmall()); } else { reportText += " " + "RimLoot_StatsReport_Projectile".Translate(verbProps.defaultProjectile.Named("PROJECTILE")) + "\n"; reportText += string.Format(" {0}: {1} * {2} = {3}\n\n", "Damage".Translate(), baseDamage.ToStringDecimalIfSmall(), verbProps.burstShotCount, damage.ToStringDecimalIfSmall() ); } /* Seconds per attack */ float secondsSpent = 0; float cooldown = req.HasThing ? req.Thing.GetStatValue(StatDefOf.RangedWeapon_Cooldown, true) : req.StuffDef != null?def.GetStatValueAbstract(StatDefOf.RangedWeapon_Cooldown, req.StuffDef) : def.GetStatValueAbstract(StatDefOf.RangedWeapon_Cooldown) ; float burstShotTime = ((verbProps.burstShotCount - 1) * verbProps.ticksBetweenBurstShots).TicksToSeconds(); if (verb != null) { secondsSpent = verbProps.AdjustedFullCycleTime(verb, attacker); } else { secondsSpent = verbProps.warmupTime + cooldown + burstShotTime; } reportText += GenText.ToTitleCaseSmart("SecondsPerAttackLower".Translate()) + ":\n"; reportText += string.Format(" {0}: {1}\n", "WarmupTime".Translate(), "PeriodSeconds".Translate(verbProps.warmupTime.ToStringDecimalIfSmall())); if (burstShotTime > 0) { reportText += string.Format(" {0}: {1}\n", "BurstShotFireRate".Translate(), "PeriodSeconds".Translate(burstShotTime.ToStringDecimalIfSmall())); } reportText += string.Format(" {0}: {1}\n", "CooldownTime".Translate(), "PeriodSeconds".Translate(cooldown.ToStringDecimalIfSmall())); reportText += string.Format("{0}: {1}\n\n", "StatsReport_TotalValue".Translate(), "PeriodSeconds".Translate(secondsSpent.ToStringDecimalIfSmall())); /* Average accuracy */ // Every integer range possible as an average float wpnAccuracy = 0; float pawnAccuracy = 0; for (int i = 3; i <= verbProps.range; i++) { wpnAccuracy += verbProps.GetHitChanceFactor(req.Thing, i); if (attacker != null) { pawnAccuracy += ShotReport.HitFactorFromShooter(attacker, i); } } if (verbProps.range >= 3) { wpnAccuracy /= verbProps.range - 2; if (attacker != null) { pawnAccuracy /= verbProps.range - 2; } } reportText += "AverageAccuracy".Translate() + ":\n"; reportText += string.Format(" {0}: {1}\n", "ShootReportWeapon".Translate(), wpnAccuracy.ToStringPercent("F1")); if (pawnAccuracy > 0) { reportText += string.Format(" {0}: {1}\n", "ShootReportShooterAbility".Translate(), pawnAccuracy.ToStringPercent("F1")); } return(reportText); }
public void UpdateRangedVerbs() { this.rangedVerbs.Clear(); List <Verb> allVerbs = this.Pawn.verbTracker.AllVerbs; if (!allVerbs.NullOrEmpty()) { for (int i = 0; i < allVerbs.Count; i++) { if (!allVerbs[i].IsMeleeAttack && allVerbs[i].IsStillUsableBy(this.Pawn)) { this.rangedVerbs.Add(new VerbEntry(allVerbs[i], this.Pawn)); } } } if (this.Pawn.equipment != null) { List <ThingWithComps> allEquipmentListForReading = this.Pawn.equipment.AllEquipmentListForReading; for (int j = 0; j < allEquipmentListForReading.Count; j++) { ThingWithComps thingWithComps = allEquipmentListForReading[j]; CompEquippable equipmentComp = thingWithComps.GetComp <CompEquippable>(); if (equipmentComp != null) { List <Verb> allEquipmentVerbs = equipmentComp.AllVerbs; if (allEquipmentVerbs != null) { for (int k = 0; k < allEquipmentVerbs.Count; k++) { if (VEF_ModCompatibilityCheck.enabled_rooloDualWield) { try { ((Action)(() => { object[] parameters = new object[] { pawn.equipment, null }; bool hasOffHandThing = (bool)VEF_ReflectionData.MB_TryGetOffHandEquipment.Invoke(null, parameters); ThingWithComps offHandThing = (ThingWithComps)parameters[1]; if (hasOffHandThing != false) { if (!allEquipmentVerbs[k].IsMeleeAttack && allEquipmentVerbs[k].EquipmentSource != offHandThing && allEquipmentVerbs[k].IsStillUsableBy(this.Pawn)) { this.rangedVerbs.Add(new VerbEntry(allEquipmentVerbs[k], this.Pawn)); } } else { if (!allEquipmentVerbs[k].IsMeleeAttack && allEquipmentVerbs[k].IsStillUsableBy(this.Pawn)) { this.rangedVerbs.Add(new VerbEntry(allEquipmentVerbs[k], this.Pawn)); } } }))(); } catch (TypeLoadException ex) { } } else if (VEF_ModCompatibilityCheck.enabled_CombatExtended) { try { ((Action)(() => { if (allEquipmentVerbs[k].verbProps.GetType().Equals(typeof(CombatExtended.VerbPropertiesCE)) && !allEquipmentVerbs[k].IsMeleeAttack && allEquipmentVerbs[k].IsStillUsableBy(this.Pawn) && allEquipmentVerbs[k].EquipmentSource.TryGetComp <CombatExtended.CompAmmoUser>() == null || allEquipmentVerbs[k].EquipmentSource.TryGetComp <CombatExtended.CompAmmoUser>().CanBeFiredNow) { this.rangedVerbs.Add(new VerbEntry(allEquipmentVerbs[k], this.Pawn)); } }))(); } catch (TypeLoadException ex) { } } else { if (!allEquipmentVerbs[k].IsMeleeAttack && allEquipmentVerbs[k].IsStillUsableBy(this.Pawn)) { this.rangedVerbs.Add(new VerbEntry(allEquipmentVerbs[k], this.Pawn)); } } } } } } } if (!VEF_ModCompatibilityCheck.enabled_CombatExtended) { foreach (Verb verb in this.Pawn.health.hediffSet.GetHediffsVerbs()) { if (!verb.IsMeleeAttack && verb.IsStillUsableBy(this.Pawn)) { this.rangedVerbs.Add(new VerbEntry(verb, this.Pawn)); } } return; } }
public static void TryStartCastOn_RapidFire_Prefix(ref Verb __instance, LocalTargetInfo castTarg, float __state) { /* * List<Type> types = typeof(Verb_LaunchProjectile).AllSubclassesNonAbstract().ToList(); * types.Add(typeof(Verb_LaunchProjectile)); * List<Type> nottypes = typeof(AbilityUser.Verb_UseAbility).AllSubclassesNonAbstract().ToList(); * nottypes.Add(typeof(AbilityUser.Verb_UseAbility)); * if (!types.Contains(__instance.GetType()) || nottypes.Contains(__instance.GetType())) * { * return; * } */ if (__instance.GetType() != typeof(Verb_Shoot) && __instance.GetType() != typeof(Verb_ShootEquipment)) { return; } if (__instance.EquipmentSource != null) { ThingWithComps gun = __instance.EquipmentSource; CompEquippable compeq = gun.TryGetComp <CompEquippable>(); if (!__instance.EquipmentSource.AllComps.NullOrEmpty()) { if (__instance.EquipmentSource.GetComp <CompWeapon_GunSpecialRules>() != null) { if (__instance.EquipmentSource.GetComp <CompWeapon_GunSpecialRules>() is CompWeapon_GunSpecialRules GunExt) { // Log.Message(string.Format("prefix pre-modified Values, Warmup: {0}, ticksbetween: {1}, cooldown: {2}, last move tick: {3}", gun.def.Verbs[0].warmupTime, gun.def.Verbs[0].ticksBetweenBurstShots, gun.def.Verbs[0].defaultCooldownTime, GunExt.LastMovedTick)); if (GunExt.RapidFire) { if (__instance.caster.Position.InHorDistOf(castTarg.Cell, __instance.verbProps.range / 2)) { if (GunExt.DualFireMode && GunExt.Toggled) { __instance.verbProps.warmupTime = GunExt.Props.VerbEntries[1].VerbProps.warmupTime / 2; } else { __instance.verbProps.warmupTime = GunExt.OriginalwarmupTime / 2; } } else { if (GunExt.DualFireMode && GunExt.Toggled) { __instance.verbProps.warmupTime = GunExt.Props.VerbEntries[1].VerbProps.warmupTime; } else { __instance.verbProps.warmupTime = GunExt.OriginalwarmupTime; } } } else if (GunExt.HeavyWeapon) { if (GunExt.ticksHere < GunExt.HeavyWeaponSetupTime.SecondsToTicks()) { __instance.verbProps.warmupTime = GunExt.OriginalwarmupTime + (GunExt.HeavyWeaponSetupTime - GunExt.ticksHere.TicksToSeconds()); } else { __instance.verbProps.warmupTime = GunExt.OriginalwarmupTime; } } } } if (compeq != null) { if (__instance.GetProjectile().projectile.Conversion()) { float distance = __instance.caster.Position.DistanceTo(castTarg.Cell); __instance.verbProps.warmupTime = (float)__state + (distance / 30); } } } } }
public List <VerbEntry> GetUpdatedAvailableVerbsList() { Pawn_MeleeVerbs.meleeVerbs.Clear(); List <Verb> allVerbs = this.pawn.verbTracker.AllVerbs; for (int i = 0; i < allVerbs.Count; i++) { if (allVerbs[i].IsStillUsableBy(this.pawn)) { Pawn_MeleeVerbs.meleeVerbs.Add(new VerbEntry(allVerbs[i], this.pawn, null)); } } if (this.pawn.equipment != null) { List <ThingWithComps> allEquipmentListForReading = this.pawn.equipment.AllEquipmentListForReading; for (int j = 0; j < allEquipmentListForReading.Count; j++) { ThingWithComps thingWithComps = allEquipmentListForReading[j]; CompEquippable comp = thingWithComps.GetComp <CompEquippable>(); if (comp != null) { List <Verb> allVerbs2 = comp.AllVerbs; if (allVerbs2 != null) { for (int k = 0; k < allVerbs2.Count; k++) { Pawn_MeleeVerbs.meleeVerbs.Add(new VerbEntry(allVerbs2[k], this.pawn, thingWithComps)); } } } } } if (this.pawn.apparel != null) { List <Apparel> wornApparel = this.pawn.apparel.WornApparel; for (int l = 0; l < wornApparel.Count; l++) { Apparel apparel = wornApparel[l]; CompEquippable comp2 = apparel.GetComp <CompEquippable>(); if (comp2 != null) { List <Verb> allVerbs3 = comp2.AllVerbs; if (allVerbs3 != null) { for (int m = 0; m < allVerbs3.Count; m++) { Pawn_MeleeVerbs.meleeVerbs.Add(new VerbEntry(allVerbs3[m], this.pawn, apparel)); } } } } } foreach (Verb hediffsVerb in this.pawn.health.hediffSet.GetHediffsVerbs()) { if (hediffsVerb.IsStillUsableBy(this.pawn)) { Pawn_MeleeVerbs.meleeVerbs.Add(new VerbEntry(hediffsVerb, this.pawn, null)); } } return(Pawn_MeleeVerbs.meleeVerbs); }
public static bool GetVerbsCommands_Prefix(ref IEnumerable <Command> __result, CompEquippable __instance) { var rangedVerbs = __instance.AllVerbs.Where(v => !v.IsMeleeAttack).ToList(); if (rangedVerbs.Count <= 1) { return(true); } var man = __instance.PrimaryVerb?.CasterPawn?.Manager(false); __result = rangedVerbs .SelectMany(v => v.GetGizmosForVerb(man?.GetManagedVerbForVerb(v))) .OfType <Command>(); return(false); }
public List <VerbEntry> GetUpdatedAvailableVerbsList(bool terrainTools) { meleeVerbs.Clear(); if (!terrainTools) { List <Verb> allVerbs = pawn.verbTracker.AllVerbs; for (int i = 0; i < allVerbs.Count; i++) { if (allVerbs[i].IsStillUsableBy(pawn)) { meleeVerbs.Add(new VerbEntry(allVerbs[i], pawn)); } } if (pawn.equipment != null) { List <ThingWithComps> allEquipmentListForReading = pawn.equipment.AllEquipmentListForReading; for (int j = 0; j < allEquipmentListForReading.Count; j++) { ThingWithComps thingWithComps = allEquipmentListForReading[j]; CompEquippable comp = thingWithComps.GetComp <CompEquippable>(); if (comp != null) { List <Verb> allVerbs2 = comp.AllVerbs; if (allVerbs2 != null) { for (int k = 0; k < allVerbs2.Count; k++) { if (allVerbs2[k].IsStillUsableBy(pawn)) { meleeVerbs.Add(new VerbEntry(allVerbs2[k], pawn)); } } } } } } if (pawn.apparel != null) { List <Apparel> wornApparel = pawn.apparel.WornApparel; for (int l = 0; l < wornApparel.Count; l++) { Apparel apparel = wornApparel[l]; CompEquippable comp2 = apparel.GetComp <CompEquippable>(); if (comp2 != null) { List <Verb> allVerbs3 = comp2.AllVerbs; if (allVerbs3 != null) { for (int m = 0; m < allVerbs3.Count; m++) { if (allVerbs3[m].IsStillUsableBy(pawn)) { meleeVerbs.Add(new VerbEntry(allVerbs3[m], pawn)); } } } } } } foreach (Verb hediffsVerb in pawn.health.hediffSet.GetHediffsVerbs()) { if (hediffsVerb.IsStillUsableBy(pawn)) { meleeVerbs.Add(new VerbEntry(hediffsVerb, pawn)); } } } else if (pawn.Spawned) { TerrainDef terrain = pawn.Position.GetTerrain(pawn.Map); if (terrainVerbs == null || terrainVerbs.def != terrain) { terrainVerbs = Pawn_MeleeVerbs_TerrainSource.Create(this, terrain); } List <Verb> allVerbs4 = terrainVerbs.tracker.AllVerbs; for (int n = 0; n < allVerbs4.Count; n++) { Verb verb = allVerbs4[n]; if (verb.IsStillUsableBy(pawn)) { meleeVerbs.Add(new VerbEntry(verb, pawn)); } } } return(meleeVerbs); }
public static void DrawEquipmentAimingOverride(Mesh mesh, Thing eq, Vector3 drawLoc, float aimAngle, CompOversizedWeapon compOversized, CompEquippable equippable, Pawn pawn, bool offhand = false) { float num = aimAngle - 90f; if (aimAngle > 20f && aimAngle < 160f) { mesh = MeshPool.plane10; num += eq.def.equippedAngleOffset; } else { if (aimAngle > 200f && aimAngle < 340f) { mesh = offhand ? (mesh == MeshPool.plane10 ? MeshPool.plane10Flip : MeshPool.plane10) : MeshPool.plane10Flip; num -= 180f; num -= eq.def.equippedAngleOffset; } else { mesh = MeshPool.plane10; num += eq.def.equippedAngleOffset; } } num %= 360f; Vector3 s; if (pawn.RaceProps.Humanlike) { if (HarmonyPatches_OversizedWeapon.enabled_AlienRaces) { Vector2 v = AlienRaceUtility.AlienRacesPatch(pawn, eq); float f = Mathf.Max(v.x, v.y); s = new Vector3(eq.def.graphicData.drawSize.x * f, 1f, eq.def.graphicData.drawSize.y * f); } else { s = new Vector3(eq.def.graphicData.drawSize.x, 1f, eq.def.graphicData.drawSize.y); } } else { Vector2 v = pawn.ageTracker.CurKindLifeStage.bodyGraphicData.drawSize; s = new Vector3(eq.def.graphicData.drawSize.x + v.x / 10, 1f, eq.def.graphicData.drawSize.y + v.y / 10); } Matrix4x4 matrix = default(Matrix4x4); Quaternion rotation = Quaternion.AngleAxis(num, Vector3.up); matrix.SetTRS(drawLoc, rotation, s); Graphic_StackCount graphic_StackCount = eq.Graphic as Graphic_StackCount; bool flag3 = graphic_StackCount != null; Material matSingle; if (flag3) { matSingle = graphic_StackCount.SubGraphicForStackCount(1, eq.def).MatSingle; } else { matSingle = eq.Graphic.MatSingle; } OversizedUtil.Draw(mesh, matrix, matSingle, 0, eq, pawn, drawLoc, rotation); }
public static void GetVerbsCommandsPostfix(ref VerbTracker __instance, ref IEnumerable <Command> __result) { CompEquippable compEquippable = __instance.directOwner as CompEquippable; if (compEquippable == null) { return; } Thing thing = compEquippable.parent; CompRangedWeaponAvali compWeaponAvali = null; //Log.Message("thing: " + thing); if (thing != null) { compWeaponAvali = thing.TryGetComp <CompRangedWeaponAvali>(); } if (compWeaponAvali == null) { return; } string currentBindMode = compWeaponAvali.currentBindMode; //Log.Message("currentBindMode: " + currentBindMode); bool isDisabled = false; string isDisabledReason = "CannotOrderNonControlled".Translate(); Pawn holderPawn = compEquippable.PrimaryVerb.CasterPawn; //Log.Message("ownerPawn: " + ownerPawn); if (holderPawn == null || holderPawn.IsColonist == false) { return; } if (!holderPawn.Awake()) { isDisabled = true; isDisabledReason = string.Format("NotAwake".Translate(), holderPawn.LabelShort.CapitalizeFirst()); } else if (compWeaponAvali.ownerPawn != null && holderPawn != compWeaponAvali.ownerPawn) { if (currentBindMode == CompRangedWeaponAvali.bindMode.OwnerPawnOnly.ToString() || currentBindMode == CompRangedWeaponAvali.bindMode.AnyPawnInFaction.ToString()) { isDisabled = true; isDisabledReason = "OwnerNotCasterPawn".Translate(); } } else if (holderPawn.Drafted) { isDisabled = true; isDisabledReason = string.Format("ShouldBeUndrafted".Translate(), holderPawn.LabelShort.CapitalizeFirst()); } //Log.Message("isDisabled: " + isDisabled); List <Command> result = __result.ToList(); /*result.Add(new Command_Action * { * action = delegate * { * compWeaponAvali.ChangeBindMode(); * }, * disabled = isDisabled, * disabledReason = isDisabledReason, * //defaultLabel = ("BindMode_" + currentBindMode).Translate(), * defaultDesc = ("BindMode_" + currentBindMode + "Desc").Translate(), * icon = ContentFinder<Texture2D>.Get("UI/Commands/" + "BindMode_" + currentBindMode, true), * hotKey = KeyBindingDefOf.Misc4 * });*/ result.Add(new Command_Action { action = delegate { compWeaponAvali.EraseOwnerPawnInfo(); }, disabled = isDisabled, disabledReason = isDisabledReason, //defaultLabel = "EraseOwnerPawnInfo".Translate(), defaultDesc = "EraseOwnerPawnInfoDesc".Translate(), icon = ContentFinder <Texture2D> .Get("UI/Commands/EraseOwnerPawnInfo", true), hotKey = KeyBindingDefOf.Misc5 }); List <Verb> verbs = __instance.AllVerbs; for (int i = 0; i < verbs.Count; i++) { Verb verb = verbs[i]; if (verb.verbProps.hasStandardCommand) { __result = result; } } }
public static void ThrowMuzzleFlash(IntVec3 cell, Map map, ThingDef moteDef, float scale, Verb verb) { bool skip = false; if (!AMAMod.settings.AllowMuzzlePosition) { skip = true; } if (verb.GetProjectile() != null) { if (verb.GetProjectile() as Lasers.LaserBeamDef != null) { skip = true; } if (verb.GetProjectile().GetType().ToString().Contains("Lasers.LaserBeamDef")) { skip = true; } } if (verb.EquipmentSource != null && !skip) { if (verb.verbProps.range > 1.48f) { ThingDef mote = moteDef; CompEquippable equippable = verb.EquipmentCompSource; Vector3 origin = verb.CasterIsPawn ? verb.CasterPawn.Drawer.DrawPos : verb.Caster.DrawPos; Vector3 a = verb.CurrentTarget.CenterVector3; float aimAngle = 0f; if ((a - origin).MagnitudeHorizontalSquared() > 0.001f) { aimAngle = (a - origin).AngleFlat(); } if (verb.Caster is Building_TurretGun _TurretGun) { origin += new Vector3(_TurretGun.def.building.turretTopOffset.x, 0, _TurretGun.def.building.turretTopOffset.y); } else { OgsCompOversizedWeapon.CompOversizedWeapon compOversized = verb.EquipmentSource.TryGetCompFast <OgsCompOversizedWeapon.CompOversizedWeapon>(); if (compOversized != null) { bool DualWeapon = compOversized.Props != null && compOversized.Props.isDualWeapon; Vector3 offsetMainHand = default(Vector3); Vector3 offsetOffHand = default(Vector3); float offHandAngle = aimAngle; float mainHandAngle = aimAngle; OgsCompOversizedWeapon.OversizedUtil.SetAnglesAndOffsets(compOversized.parent, compOversized.parent, aimAngle, verb.Caster, ref offsetMainHand, ref offsetOffHand, ref offHandAngle, ref mainHandAngle, true, DualWeapon && !compOversized.FirstAttack); // if (DualWeapon && AMAMod.Dev) Log.Message("Throwing flash for " + compOversized.parent.LabelCap + " offsetMainHand: " + offsetMainHand + " offsetOffHand: " + offsetOffHand + " Using " + (!compOversized.FirstAttack ? "OffHand" : "MainHand") + " FirstAttack: " + compOversized.FirstAttack); origin += DualWeapon && !compOversized.FirstAttack ? offsetOffHand : offsetMainHand; // origin += compOversized.AdjustRenderOffsetFromDir(equippable.PrimaryVerb.CasterPawn, !compOversized.FirstAttack); if (compOversized.Props.isDualWeapon) { compOversized.FirstAttack = !compOversized.FirstAttack; } } } origin = verb.MuzzlePositionFor(aimAngle, true); if (verb.GetProjectile() != null) { origin.y = verb.GetProjectile().Altitude; } AdeptusMoteMaker.MakeStaticMote(origin, map, mote, scale); return; } } { AdeptusMoteMaker.MakeStaticMote(cell.ToVector3Shifted(), map, moteDef, scale); } }
public static bool GetVerbsCommands_Prefix(ref IEnumerable <Command> __result, CompEquippable __instance) { var rangedVerbs = __instance.AllVerbs.Where(v => !v.IsMeleeAttack).ToList(); var melee = VerbManager.PreferMelee(__instance.parent); if (rangedVerbs.Count <= 1 && !melee) { return(true); } var man = __instance.PrimaryVerb?.CasterPawn?.Manager(false); __result = rangedVerbs .SelectMany(v => v.GetGizmosForVerb(man?.GetManagedVerbForVerb(v))) .OfType <Command>(); if (melee) { __result = __result.Prepend((Command)CreateVerbTargetCommand.Invoke(__instance.verbTracker, new object[] { __instance.parent, __instance.AllVerbs.First(v => v.verbProps.IsMeleeAttack) })); } return(false); }
public static float AdjustedWarmup(float warmUpTime, Verb verb, LocalTargetInfo castTarg) { if (AdeptusIntergrationUtility.enabled_CombatExtended) { if (!CE(verb)) { return(warmUpTime); } } else { if (!(verb is Verb_Shoot) && !(verb is AbilitesExtended.Verb_ShootEquipment)) { return(warmUpTime); } } float result = warmUpTime; // AdvancedVerbProperties props = verb.verbProps as AdvancedVerbProperties; IAdvancedVerb props = verb.verbProps as IAdvancedVerb; ThingWithComps gun = verb.EquipmentSource; CompEquippable compeq = verb.EquipmentCompSource; Thing caster = verb.caster; Pawn CasterPawn = verb.CasterPawn; if (props != null) { if (verb.GetsHot(out bool GetsHotCrit, out float GetsHotCritChance, out bool GetsHotCritExplosion, out float GetsHotCritExplosionChance, out bool canDamageWeapon, out float extraWeaponDamage)) { } if (props.RapidFire) { // log.message(string.Format("RapidFire prefix pre-modified Values, Warmup: {0}", gun.def.Verbs[0].warmupTime, cooldown)); if (caster.Position.InHorDistOf(castTarg.Cell, verb.verbProps.range * props.RapidFireRange)) { float reduction = ((verb.verbProps.burstShotCount - 1) * verb.verbProps.ticksBetweenBurstShots).TicksToSeconds() / 4; reduction += warmUpTime / 2; result -= reduction; } // log.message(string.Format("RapidFire prefix post-modified Values, Warmup: {0}", gun.def.Verbs[0].warmupTime, cooldown)); } else if (props.HeavyWeapon && verb.CasterIsPawn) { CompWeapon_GunSpecialRules GunExt = gun.TryGetCompFast <CompWeapon_GunSpecialRules>(); if (GunExt.ticksHere < (props.HeavyWeaponSetupTime.SecondsToTicks())) { float extra = props.HeavyWeaponSetupTime; if (CasterPawn.story?.bodyType == BodyTypeDefOf.Hulk) { extra *= 0.5f; } extra = Math.Max(0, extra - GunExt.ticksHere.TicksToSeconds()); // Log.Message(string.Format("HeavyWeapon prefix pre-modified Values, Warmup: {0} + {1}, last move tick: {2}", __instance.verbProps.warmupTime, extra, GunExt.LastMovedTick)); result += extra; } // log.message(string.Format("HeavyWeapon prefix post-modified Values, Warmup: {0}, last move tick: {1}", gun.def.Verbs[0].warmupTime, GunExt.LastMovedTick)); } if (compeq != null) { if (verb.GetProjectile().projectile.Conversion()) { float distance = caster.Position.DistanceTo(castTarg.Cell); result = (float)warmUpTime + (distance / 30); } } } // Log.Message("Testing return result" + result + " warmUpTime: " + warmUpTime + " for verb: " + verb + " casting at " + castTarg); return(result); }
public static bool GetUpdatedAvailableVerbsList(Pawn_MeleeVerbs __instance, ref List <VerbEntry> __result, bool terrainTools) { Pawn this_pawn = pawn(__instance); //meleeVerbs.Clear(); //verbsToAdd.Clear(); List <VerbEntry> meleeVerbs = new List <VerbEntry>(); List <Verb> verbsToAdd = new List <Verb>(); if (!terrainTools) { List <Verb> allVerbs1 = this_pawn.verbTracker.AllVerbs; for (int index = 0; index < allVerbs1.Count; ++index) { if (IsUsableMeleeVerb(allVerbs1[index])) { verbsToAdd.Add(allVerbs1[index]); } } if (this_pawn.equipment != null) { List <ThingWithComps> equipmentListForReading = this_pawn.equipment.AllEquipmentListForReading; for (int index1 = 0; index1 < equipmentListForReading.Count; ++index1) { CompEquippable comp = equipmentListForReading[index1].GetComp <CompEquippable>(); if (comp != null) { List <Verb> allVerbs2 = comp.AllVerbs; if (allVerbs2 != null) { for (int index2 = 0; index2 < allVerbs2.Count; ++index2) { if (IsUsableMeleeVerb(allVerbs2[index2])) { verbsToAdd.Add(allVerbs2[index2]); } } } } } } if (this_pawn.apparel != null) { List <Apparel> wornApparel = this_pawn.apparel.WornApparel; for (int index1 = 0; index1 < wornApparel.Count; ++index1) { CompEquippable comp = wornApparel[index1].GetComp <CompEquippable>(); if (comp != null) { List <Verb> allVerbs2 = comp.AllVerbs; if (allVerbs2 != null) { for (int index2 = 0; index2 < allVerbs2.Count; ++index2) { if (IsUsableMeleeVerb(allVerbs2[index2])) { verbsToAdd.Add(allVerbs2[index2]); } } } } } } foreach (Verb hediffsVerb in this_pawn.health.hediffSet.GetHediffsVerbs()) { if (IsUsableMeleeVerb(hediffsVerb)) { verbsToAdd.Add(hediffsVerb); } } } else if (this_pawn.Spawned) { TerrainDef terrain = this_pawn.Position.GetTerrain(this_pawn.Map); if (terrainVerbs(__instance) == null || terrainVerbs(__instance).def != terrain) { terrainVerbs(__instance) = Pawn_MeleeVerbs_TerrainSource.Create(__instance, terrain); } List <Verb> allVerbs = terrainVerbs(__instance).tracker.AllVerbs; for (int index = 0; index < allVerbs.Count; ++index) { Verb v = allVerbs[index]; if (IsUsableMeleeVerb(v)) { verbsToAdd.Add(v); } } } float highestSelWeight = 0.0f; foreach (Verb v in verbsToAdd) { float num = VerbUtility.InitialVerbWeight(v, this_pawn); if ((double)num > (double)highestSelWeight) { highestSelWeight = num; } } foreach (Verb verb in verbsToAdd) { meleeVerbs.Add(new VerbEntry(verb, this_pawn, verbsToAdd, highestSelWeight)); } __result = meleeVerbs; return(false); bool IsUsableMeleeVerb(Verb v) { return(v.IsStillUsableBy(this_pawn) && v.IsMeleeAttack); } }