public void Setup(Thing launcher, Vector3 origin, Vector3 destination, Verb verb = null, Thing hitThing = null, Effecter effecter = null, EffecterDef effecterDef = null) { //SetColor(launcher); this.launcher = launcher; this.verb = verb; this.a = origin; this.b = destination; this.hitThing = hitThing ?? null; this.effecter = effecter ?? null; this.effecterDef = effecterDef ?? null; Map map = verb?.Caster?.Map ?? launcher.Map; Vector3 dir = (destination - origin).normalized; dir.y = 0; Vector3 a = origin;// += dir * (defWeapon == null ? 0.9f : defWeapon.barrelLength); if (verb != null) { if (verb.Muzzle(out float barrelLength, out float barrelOffset, out float bulletOffset, out FleckDef flareDef, out float flareSize, out FleckDef smokeDef, out float smokeSize)) { a = origin -= dir * (barrelOffset * (verb.EquipmentSource.def.graphicData.drawSize.magnitude / 4)); a.y += 0.0367346928f; if (flareDef != null) { IAdvancedVerb properties = verb.verbProps as IAdvancedVerb; Rand.PushState(); AdeptusFleckMaker.Static(a, map, flareDef, flareSize, properties?.MuzzleFlareColor, properties != null && properties.MuzzleFlareRotates ? (float?)Rand.Range(0, 350) : null, projDef.lifetime); Rand.PopState(); } if (smokeDef != null) { AdeptusFleckMaker.ThrowSmoke(a, smokeSize, map, smokeDef); } } FleckMaker.Static(a, launcher.Map, FleckDefOf.ShotFlash, verb.verbProps.muzzleFlashScale); } if (effecter == null) { TriggerEffect(effecterDef, b, hitThing); } ProjectileVFX ext = this.projDef.GetModExtensionFast <ProjectileVFX>(); if (ext != null && destination.InBounds(launcher.Map)) { Vector3 pos = destination; ThingDef explosionMoteDef = ext.ExplosionMoteDef ?? projDef.projectile.damageDef.explosionCellMote ?? null; SoundDef sound = projDef.projectile.damageDef.soundExplosion; Color? color = ext.useGraphicColor ? projDef.graphic.color : (ext.useGraphicColorTwo ? projDef.graphic.colorTwo : projDef.projectile.damageDef.explosionColorCenter); float scale = ext.scaleWithProjectile ? projDef.graphic.drawSize.magnitude : 1f; ext.ImpactEffects(pos, map, explosionMoteDef, ext.ExplosionMoteSize * scale, color, sound, ext.ImpactMoteDef, ext.ImpactMoteSize * scale, ext.ImpactGlowMoteDef, ext.ImpactGlowMoteSize * scale, hitThing, null, (int)((projDef.lifetime - ticks) * 1.1f)); // ext.ImpactEffects(destination, launcher.Map, ext.ExplosionMoteDef ?? this.projDef.projectile.damageDef.explosionCellMote, ext.ExplosionMoteSize, this.projDef.projectile.damageDef.explosionColorCenter, this.projDef.projectile.damageDef.soundExplosion, ext.ImpactMoteDef, ext.ImpactMoteSize, ext.ImpactGlowMoteDef, ext.ImpactGlowMoteSize, hitThing); } }
public static Vector3 MuzzlePositionFor(this Verb verb, float aimAngle, bool throwMotes = false) { Vector3 origin = verb.CasterIsPawn ? verb.CasterPawn.Drawer.DrawPos : verb.Caster.DrawPos; if (verb == null) { Log.Error("Cannot find Muzzle position, Verb is Null"); return(origin); } if (verb.verbProps == null) { Log.Error("Cannot find Muzzle position, verbProps are null"); return(origin); } Map map = verb.Caster.Map; if (verb.Muzzle(out float barrelLength, out float barrelOffset, out float bulletOffset, out FleckDef flareDef, out float flareSize, out FleckDef smokeDef, out float smokeSize)) { float length = barrelLength; float offset = -barrelOffset; IDrawnWeaponWithRotation gun = verb.EquipmentSource as IDrawnWeaponWithRotation; if (gun != null) { aimAngle = (aimAngle + gun.RotationOffset) % 360; } if (aimAngle > 200f && aimAngle < 340f) { offset = -offset; } float f = (verb.caster is Building_TurretGun turretGun ? turretGun.def.building.turretTopDrawSize : verb.EquipmentSource.def.graphicData.drawSize.magnitude) / 2; offset *= f; length *= f; origin += new Vector3(0f + offset, 0f, 0.4f + length).RotatedBy(aimAngle); origin.y += 0.0367346928f; if (throwMotes) { Rand.PushState(); if (flareDef != null && flareSize > 0) { AdeptusFleckMaker.Static(origin, map, flareDef, flareSize, null, Rand.Range(0, 360)); } if (smokeDef != null && smokeSize > 0) { AdeptusFleckMaker.ThrowSmoke(origin, smokeSize, map, smokeDef, null, Rand.Range(0, 360)); } Rand.PopState(); } } return(origin); }
public static void ThrowMuzzleFlash(IntVec3 cell, Map map, FleckDef 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) { FleckDef 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 <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; 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; } AdeptusFleckMaker.Static(origin, map, mote, scale); return; } } { AdeptusFleckMaker.Static(cell.ToVector3Shifted(), map, moteDef, scale); } }