static void Prefix(ref Thing eq, ref Vector3 drawLoc, ref float aimAngle, PawnRenderer __instance)
        {
            Pawn pawn = pawnField.GetValue(__instance) as Pawn;

            if (pawn == null)
            {
                return;
            }

            IDrawnWeaponWithRotation gun = eq as IDrawnWeaponWithRotation;

            if (gun == null)
            {
                return;
            }

            Stance_Busy stance_Busy = pawn.stances.curStance as Stance_Busy;

            if (stance_Busy != null && !stance_Busy.neverAimWeapon && stance_Busy.focusTarg.IsValid)
            {
                drawLoc -= new Vector3(0f, 0f, 0.4f).RotatedBy(aimAngle);
                aimAngle = (aimAngle + gun.RotationOffset) % 360;
                drawLoc += new Vector3(0f, 0f, 0.4f).RotatedBy(aimAngle);
            }
        }
示例#2
0
        public void Impact(Thing hitThing, Vector3 muzzle)
        {
            bool shielded = hitThing.IsShielded() && laserBeamDef.IsWeakToShields;

            LaserGunDef defWeapon = equipmentDef as LaserGunDef;
            Vector3     dir       = (destination - muzzle).normalized;


            Vector3 b;

            if (hitThing == null)
            {
                b = destination;
            }
            else if (shielded)
            {
                b = hitThing.TrueCenter() - dir.RotatedBy(Rand.Range(-22.5f, 22.5f)) * 0.8f;
            }
            else if ((destination - hitThing.TrueCenter()).magnitude < 1)
            {
                b = destination;
            }
            else
            {
                b    = hitThing.TrueCenter();
                b.x += Rand.Range(-0.5f, 0.5f);
                b.z += Rand.Range(-0.5f, 0.5f);
            }

            /*
             * bool createsExplosion = this.def.projectile.explosionRadius>0f;
             * if (createsExplosion)
             * {
             *  this.Explode(hitThing, false);
             *  GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(this, this.def.projectile.damageDef, this.launcher.Faction);
             * }
             */
            Pawn pawn = launcher as Pawn;
            IDrawnWeaponWithRotation weapon = null;

            if (pawn != null && pawn.equipment != null)
            {
                weapon = pawn.equipment.Primary as IDrawnWeaponWithRotation;
            }
            if (weapon == null)
            {
                Building_LaserGunCE turret = launcher as Building_LaserGunCE;
                if (turret != null)
                {
                    weapon = turret.Gun as IDrawnWeaponWithRotation;
                }
            }

            if (hitThing is Pawn && shielded)
            {
                DamageModifier *= laserBeamDef.shieldDamageMultiplier;
                SpawnBeamReflections(muzzle, b, 5);
            }
            base.Impact(hitThing);
        }
        public static Vector3 MuzzlePositionFor(this Thing thing, Vector3 origin, float aimAngle)
        {
            Map map = thing.Map;

            if (thing.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 + bulletOffset;
                float offset = -barrelOffset;
                IDrawnWeaponWithRotation gun = thing as IDrawnWeaponWithRotation;
                if (gun != null)
                {
                    aimAngle = (aimAngle + gun.RotationOffset) % 360;
                }
                if (aimAngle > 200f && aimAngle < 340f)
                {
                    offset = -offset;
                }
                offset *= (thing.def.graphicData.drawSize.magnitude / 2);
                length *= (thing.def.graphicData.drawSize.magnitude / 2);

                /*
                 * //    Log.Message(thing.Label + " graphicData drawSize: " + thing.def.graphicData.drawSize.magnitude + "  / 2 = " + thing.def.graphicData.drawSize.magnitude / 2);
                 * //    Log.Message(thing.Label + " graphic drawSize: " + thing.def.graphic.drawSize.magnitude + "  / 2 = " + thing.def.graphic.drawSize.magnitude / 2);
                 */
                origin += new Vector3(0f + offset, 0f, 0.4f + length).RotatedBy(aimAngle);


                origin.y -= 0.0367346928f;
            }
            return(origin);
        }
        static void Prefix(Pawn ___pawn, ref Thing eq, ref Vector3 drawLoc, ref float aimAngle, PawnRenderer __instance)
        {
            if (___pawn == null)
            {
                return;
            }

            IDrawnWeaponWithRotation gun = eq as IDrawnWeaponWithRotation;

            if (gun == null)
            {
                return;
            }

            Stance_Busy stance_Busy = ___pawn.stances.curStance as Stance_Busy;

            if (stance_Busy != null && !stance_Busy.neverAimWeapon && stance_Busy.focusTarg.IsValid)
            {
                drawLoc -= new Vector3(0f, 0f, 0.4f).RotatedBy(aimAngle);
                float f = gun.RotationOffset;

                /*
                 * if ((aimAngle > 330 && aimAngle < 360) || aimAngle > 0 && aimAngle < 30)
                 * {
                 * if (AMAMod.Dev && f != 0) Log.Message(___pawn.Name + " aiming "+eq.LabelCap+" @: "+drawLoc+" Angle: "+aimAngle + " Offet: "+ f);
                 * }
                 */
                aimAngle = (aimAngle + gun.RotationOffset) % 360;
                drawLoc += new Vector3(0f, 0f, 0.4f).RotatedBy(aimAngle);
            }
        }
示例#5
0
        protected override void Impact(Thing hitThing)
        {
            bool shielded = hitThing.IsShielded() && def.IsWeakToShields;

            LaserGunDef defWeapon = equipmentDef as LaserGunDef;
            Vector3     dir       = (destination - origin).normalized;

            dir.y = 0;

            Vector3 a = origin + dir * (defWeapon == null ? 0.9f : defWeapon.barrelLength);
            Vector3 b = shielded ? hitThing.TrueCenter() - dir.RotatedBy(Rand.Range(-22.5f, 22.5f)) * 0.8f : destination;

            a.y = b.y = def.Altitude;

            SpawnBeam(a, b);

            Pawn pawn = launcher as Pawn;
            IDrawnWeaponWithRotation weapon = null;

            if (pawn != null && pawn.equipment != null)
            {
                weapon = pawn.equipment.Primary as IDrawnWeaponWithRotation;
            }
            if (weapon == null)
            {
                weapon = launcher as IDrawnWeaponWithRotation;
            }
            if (weapon != null)
            {
                float angle = (b - a).AngleFlat() - (intendedTarget.CenterVector3 - a).AngleFlat();
                weapon.RotationOffset = (angle + 180) % 360 - 180;
            }

            if (hitThing == null)
            {
                TriggerEffect(def.explosionEffect, destination);
            }
            else
            {
                if (hitThing is Pawn)
                {
                    Pawn hitPawn = hitThing as Pawn;
                    if (shielded)
                    {
                        weaponDamageMultiplier *= def.shieldDamageMultiplier;

                        SpawnBeamReflections(a, b, 5);
                    }
                }

                TriggerEffect(def.explosionEffect, ExactPosition);
            }

            base.Impact(hitThing);
        }
示例#6
0
        public static Vector2 MuzzlePosition(Vector2 sourceLoc, Verb_LaunchProjectileCE instance)
        {
            //    Log.Message("MuzzlePosition CE");
            Vector2 result = sourceLoc;
            //    Log.Message("MuzzlePosition CE sourceLoc: " + sourceLoc);
            string msg      = "CE MuzzlePosition {0}: {1}, aimAngle: {2}";
            float  aimAngle = 0f;

            if (instance.EquipmentSource is Thing equipment)
            {
                //    Log.Message("MuzzlePosition CE EquipmentSource: " + equipment);
                Thing   launcher    = instance.Shooter;
                Vector3 origin      = new Vector3(sourceLoc.x, 0, sourceLoc.y);
                Vector3 destination = instance.CurrentTarget.Cell.ToVector3Shifted();
                if ((destination - origin).MagnitudeHorizontalSquared() > 0.001f)
                {
                    aimAngle = (destination - origin).AngleFlat();
                }
                IDrawnWeaponWithRotation rotation = equipment as IDrawnWeaponWithRotation;
                if (rotation != null)
                {
                    //    Log.Message(rotation + " is IDrawnWeaponWithRotation with RotationOffset: " + rotation.RotationOffset);
                    aimAngle += rotation.RotationOffset;
                }
                Log.Message(string.Format(msg, "Original", sourceLoc, aimAngle));
                GunDrawExtension gunDrawExtension = equipment.def.GetModExtensionFast <GunDrawExtension>();
                if (gunDrawExtension != null)
                {
                    Log.Message("gunDrawExtension");
                }
                else
                if (equipment.def.HasComp(typeof(OgsCompOversizedWeapon.CompOversizedWeapon)))
                {
                    OgsCompOversizedWeapon.CompOversizedWeapon compOversized = equipment.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(equipment, equipment as ThingWithComps, aimAngle, launcher, ref offsetMainHand, ref offsetOffHand, ref offHandAngle, ref mainHandAngle, true, DualWeapon && !compOversized.FirstAttack);
                        Vector3 vector = DualWeapon && !compOversized.FirstAttack ? offsetOffHand : offsetMainHand;
                        //    Vector3 vector = compOversized.AdjustRenderOffsetFromDir(equippable.PrimaryVerb.CasterPawn, !compOversized.FirstAttack);
                        origin += vector;
                    }
                }
                origin = equipment.MuzzlePositionFor(origin, aimAngle);
                result = new Vector2(origin.x, origin.z);
            }
            Log.Message(string.Format(msg, "result", result, aimAngle));
            return(result);
        }
        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);
        }
示例#8
0
        public static void ExtraProjectiles(Projectile projectile2, Thing launcher, Vector3 origin, LocalTargetInfo usedTarget, LocalTargetInfo intendedTarget, ProjectileHitFlags hitFlags, bool preventFriendlyFire, Thing equipment, ThingDef targetCoverDef, ShootLine shootLine, Verb_LaunchProjectile instance)
        {
            IDrawnWeaponWithRotation weapon = null;
            Pawn pawn = launcher as Pawn;

            if (pawn != null && pawn.equipment != null)
            {
                weapon = pawn.equipment.Primary as IDrawnWeaponWithRotation;
            }
            if (weapon == null)
            {
                Building_LaserGun turret = launcher as Building_LaserGun;
                if (turret != null)
                {
                    weapon = turret.gun as IDrawnWeaponWithRotation;
                }
            }
            if (weapon != null)
            {
                float angle = (usedTarget.CenterVector3 - origin).AngleFlat() - (intendedTarget.CenterVector3 - origin).AngleFlat();
                weapon.RotationOffset = (angle + 180) % 360 - 180;
            }
            projectile2.Launch(launcher, origin, usedTarget, intendedTarget, hitFlags, preventFriendlyFire, equipment, targetCoverDef);
            int           extras = 0;
            IAdvancedVerb Props  = instance.verbProps as IAdvancedVerb;

            if (Props != null)
            {
                extras = Props.ScattershotCount;
            }
            else
            {
                ScattershotProjectileExtension ext = projectile2.def.GetModExtensionFast <ScattershotProjectileExtension>();
                if (ext != null && ext.projectileCount.HasValue)
                {
                    extras = ext.projectileCount.Value;
                }
            }
            if (extras > 0)
            {
                for (int i = 0; i < extras; i++)
                {
                    Projectile projectile3 = (Projectile)GenSpawn.Spawn(projectile2.def, shootLine.Source, launcher.Map, WipeMode.Vanish);
                    projectile3.Launch(launcher, origin, usedTarget, intendedTarget, hitFlags, preventFriendlyFire, equipment, targetCoverDef);
                }
            }
        }
示例#9
0
        public static Vector3 MuzzlePosition(Vector3 DrawPos, Verb_LaunchProjectile instance, Thing equipment, Thing launcher)
        {
            Vector3 result = DrawPos;

            if (equipment == null || !AMAMod.settings.AllowMuzzlePosition)
            {
                return(result);
            }
            Vector3 destination = instance.CurrentTarget.Cell.ToVector3Shifted();
            float   aimAngle    = 0f;

            if ((destination - result).MagnitudeHorizontalSquared() > 0.001f)
            {
                aimAngle = (destination - result).AngleFlat();
            }
            IDrawnWeaponWithRotation rotation = equipment as IDrawnWeaponWithRotation;

            if (rotation != null)
            {
                //    Log.Message(gunOG + " is IDrawnWeaponWithRotation with RotationOffset: "+ gunOG.RotationOffset);
                aimAngle += rotation.RotationOffset;
            }
            if (equipment.def.HasComp(typeof(OgsCompOversizedWeapon.CompOversizedWeapon)))
            {
                OgsCompOversizedWeapon.CompOversizedWeapon compOversized = equipment.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;

                    OversizedUtil.SetAnglesAndOffsets(equipment, equipment as ThingWithComps, aimAngle, launcher, ref offsetMainHand, ref offsetOffHand, ref offHandAngle, ref mainHandAngle, true, DualWeapon && !compOversized.FirstAttack);
                    Vector3 vector = DualWeapon && !compOversized.FirstAttack ? offsetOffHand : offsetMainHand;
                    //    Vector3 vector = compOversized.AdjustRenderOffsetFromDir(equippable.PrimaryVerb.CasterPawn, !compOversized.FirstAttack);
                    result += vector;
                }
            }
            result = equipment.MuzzlePositionFor(result, aimAngle);
            return(result);
        }
        static bool Prefix(TurretTop __instance, Vector3 recoilDrawOffset, float recoilAngleOffset, float ___curRotationInt, Building_Turret ___parentTurret)
        {
            Building_LaserGun turret = ___parentTurret as Building_LaserGun;

            if (turret == null)
            {
                return(true);
            }
            float rotation = ___curRotationInt;

            if (turret.TargetCurrentlyAimingAt.HasThing)
            {
                rotation = (turret.TargetCurrentlyAimingAt.CenterVector3 - turret.TrueCenter()).AngleFlat();
            }

            IDrawnWeaponWithRotation gunRotation = turret.gun as IDrawnWeaponWithRotation;

            if (gunRotation != null)
            {
                rotation += gunRotation.RotationOffset;
            }

            Material material = ___parentTurret.def.building.turretTopMat;
            SpinningLaserGunTurret spinningGun = turret.gun as SpinningLaserGunTurret;

            if (spinningGun != null)
            {
                spinningGun.turret = turret;
                material           = spinningGun.Graphic.MatSingle;
            }

            Vector3 offset = new Vector3(___parentTurret.def.building.turretTopOffset.x, 0f, ___parentTurret.def.building.turretTopOffset.y).RotatedBy(___curRotationInt);
            float   scale  = ___parentTurret.def.building.turretTopDrawSize;

            offset  = offset.RotatedBy(recoilAngleOffset);
            offset += recoilDrawOffset;
            Matrix4x4 Matrix = default(Matrix4x4);

            Matrix.SetTRS(___parentTurret.DrawPos + Altitudes.AltIncVect + offset, (___curRotationInt + (float)TurretTop.ArtworkRotation).ToQuat(), new Vector3(scale, 1f, scale));
            Graphics.DrawMesh(MeshPool.plane10, Matrix, material, 0);
            return(false);
        }
        static bool Prefix(TurretTop __instance)
        {
            Building_LaserGun turret = parentTurretField.GetValue(__instance) as Building_LaserGun;

            if (turret == null)
            {
                return(true);
            }

            float rotation = (float)curRotationIntField.GetValue(__instance);

            if (turret.TargetCurrentlyAimingAt.HasThing)
            {
                rotation = (turret.TargetCurrentlyAimingAt.CenterVector3 - turret.TrueCenter()).AngleFlat();
            }

            IDrawnWeaponWithRotation gunRotation = turret.gun as IDrawnWeaponWithRotation;

            if (gunRotation != null)
            {
                rotation += gunRotation.RotationOffset;
            }

            Material material = turret.def.building.turretTopMat;
            SpinningLaserGunTurret spinningGun = turret.gun as SpinningLaserGunTurret;

            if (spinningGun != null)
            {
                spinningGun.turret = turret;
                material           = spinningGun.Graphic.MatSingle;
            }

            Vector3   b = new Vector3(turret.def.building.turretTopOffset.x, 0f, turret.def.building.turretTopOffset.y);
            float     turretTopDrawSize = turret.def.building.turretTopDrawSize;
            Matrix4x4 matrix            = default(Matrix4x4);

            matrix.SetTRS(turret.DrawPos + Altitudes.AltIncVect + b, rotation.ToQuat(), new Vector3(turretTopDrawSize, 1f, turretTopDrawSize));
            Graphics.DrawMesh(MeshPool.plane10, matrix, material, 0);

            return(false);
        }
示例#12
0
        protected override void Impact(Thing hitThing)
        {
            this.hitThing = hitThing;
            bool shielded = hitThing.IsShielded() && def.IsWeakToShields;

            LaserGunDef defWeapon = equipmentDef as LaserGunDef;
            Vector3     dir       = (destination - origin).normalized;

            dir.y = 0;

            Vector3 a = origin + dir * (defWeapon == null ? 0.9f : defWeapon.barrelLength);
            Vector3 b;

            if (hitThing == null)
            {
                b = destination;
            }
            else if (shielded)
            {
                b = hitThing.TrueCenter() - dir.RotatedBy(Rand.Range(-22.5f, 22.5f)) * 0.8f;
            }
            else if ((destination - hitThing.TrueCenter()).magnitude < 1)
            {
                b = destination;
            }
            else
            {
                b    = hitThing.TrueCenter();
                b.x += Rand.Range(-0.5f, 0.5f);
                b.z += Rand.Range(-0.5f, 0.5f);
            }

            a.y = b.y = def.Altitude;

            //    SpawnBeam(a, b);

            if (this.def.projectile.explosionRadius > 0f)
            {
                this.Explode(hitThing, false);
                GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(this, this.def.projectile.damageDef, this.launcher.Faction);
            }

            Pawn pawn = launcher as Pawn;
            IDrawnWeaponWithRotation weapon = null;

            if (pawn != null && pawn.equipment != null)
            {
                weapon = pawn.equipment.Primary as IDrawnWeaponWithRotation;
            }
            if (weapon == null)
            {
                Building_LaserGun turret = launcher as Building_LaserGun;
                if (turret != null)
                {
                    weapon = turret.gun as IDrawnWeaponWithRotation;
                }
            }
            if (weapon != null)
            {
                float angle = (b - a).AngleFlat() - (intendedTarget.CenterVector3 - a).AngleFlat();
                weapon.RotationOffset = (angle + 180) % 360 - 180;
            }

            if (hitThing == null)
            {
                Rand.PushState();
                bool flag2 = this.def.causefireChance > 0f && Rand.Chance(this.def.causefireChance);
                Rand.PopState();
                if (flag2)
                {
                    FireUtility.TryStartFireIn(b.ToIntVec3(), pawn.Map, 0.01f);
                }
            }
            else
            {
                if (hitThing is Pawn && shielded)
                {
                    weaponDamageMultiplier *= def.shieldDamageMultiplier;

                    SpawnBeamReflections(a, b, 5);
                }

                Rand.PushState();
                bool flag2 = this.def.causefireChance > 0f && Rand.Chance(this.def.causefireChance);
                Rand.PopState();
                if (flag2)
                {
                    hitThing.TryAttachFire(0.01f);
                }
                AddeEffects(hitThing);
            }
            //    TriggerEffect(def.explosionEffect, b, hitThing);
            Map     map      = base.Map;
            IntVec3 position = base.Position;

            GenClamor.DoClamor(this, 2.1f, ClamorDefOf.Impact);
            this.Destroy(DestroyMode.Vanish);
            BattleLogEntry_RangedImpact battleLogEntry_RangedImpact = new BattleLogEntry_RangedImpact(this.launcher, hitThing, this.intendedTarget.Thing, this.equipmentDef, this.def, this.targetCoverDef);

            Find.BattleLog.Add(battleLogEntry_RangedImpact);
            this.NotifyImpact(hitThing, map, position);
            if (hitThing != null)
            {
                DamageInfo dinfo = new DamageInfo(this.def.projectile.damageDef, (float)this.DamageAmount, this.ArmorPenetration, this.ExactRotation.eulerAngles.y, this.launcher, null, this.equipmentDef, DamageInfo.SourceCategory.ThingOrUnknown, this.intendedTarget.Thing);
                hitThing.TakeDamage(dinfo).AssociateWithLog(battleLogEntry_RangedImpact);
                if (pawn != null && pawn.stances != null && pawn.BodySize <= this.def.projectile.StoppingPower + 0.001f)
                {
                    pawn.stances.StaggerFor(95);
                }
                if (this.def.projectile.extraDamages == null)
                {
                    return;
                }
                using (List <ExtraDamage> .Enumerator enumerator = this.def.projectile.extraDamages.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ExtraDamage extraDamage = enumerator.Current;
                        if (Rand.Chance(extraDamage.chance))
                        {
                            DamageInfo dinfo2 = new DamageInfo(extraDamage.def, extraDamage.amount, extraDamage.AdjustedArmorPenetration(), this.ExactRotation.eulerAngles.y, this.launcher, null, this.equipmentDef, DamageInfo.SourceCategory.ThingOrUnknown, this.intendedTarget.Thing);
                            hitThing.TakeDamage(dinfo2).AssociateWithLog(battleLogEntry_RangedImpact);
                        }
                    }
                    return;
                }
            }
            SoundDefOf.BulletImpact_Ground.PlayOneShot(new TargetInfo(base.Position, map, false));
            if (base.Position.GetTerrain(map).takeSplashes)
            {
                MoteMaker.MakeWaterSplash(this.ExactPosition, map, Mathf.Sqrt((float)base.DamageAmount) * 1f, 4f);
                return;
            }
            //    MoteMaker.MakeStaticMote(this.ExactPosition, map, ThingDefOf.Mote_ShotHit_Dirt, 1f);
        }
示例#13
0
        protected override void Impact(Thing hitThing)
        {
            bool shielded = hitThing.IsShielded() && def.IsWeakToShields;

            LaserGunDef defWeapon = equipmentDef as LaserGunDef;
            Vector3     dir       = (destination - origin).normalized;

            dir.y = 0;

            Vector3 a = origin + dir * (defWeapon == null ? 0.9f : defWeapon.barrelLength);
            Vector3 b = shielded ? hitThing.TrueCenter() - dir.RotatedBy(Rand.Range(-22.5f, 22.5f)) * 0.8f : destination;

            a.y = b.y = def.Altitude;

            SpawnBeam(a, b);
            bool createsExplosion = this.def.projectile.explosionRadius > 0f;

            if (createsExplosion)
            {
                this.Explode(hitThing, false);
                GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(this, this.def.projectile.damageDef, this.launcher.Faction);
            }
            Pawn pawn = launcher as Pawn;
            IDrawnWeaponWithRotation weapon = null;

            if (pawn != null && pawn.equipment != null)
            {
                weapon = pawn.equipment.Primary as IDrawnWeaponWithRotation;
            }
            if (weapon == null)
            {
                Building_LaserGun turret = launcher as Building_LaserGun;
                if (turret != null)
                {
                    weapon = turret.gun as IDrawnWeaponWithRotation;
                }
            }
            if (weapon != null)
            {
                float angle = (b - a).AngleFlat() - (intendedTarget.CenterVector3 - a).AngleFlat();
                weapon.RotationOffset = (angle + 180) % 360 - 180;
            }

            if (hitThing == null)
            {
                TriggerEffect(def.explosionEffect, destination);
                bool flag2 = this.def.causefireChance > 0f && Rand.Chance(this.def.causefireChance);
                if (flag2)
                {
                    FireUtility.TryStartFireIn(destination.ToIntVec3(), pawn.Map, 0.05f);
                }
            }
            else
            {
                if (hitThing is Pawn)
                {
                    Pawn hitPawn = hitThing as Pawn;
                    if (shielded)
                    {
                        weaponDamageMultiplier *= def.shieldDamageMultiplier;

                        SpawnBeamReflections(a, b, 5);
                    }
                }

                bool flag2 = this.def.causefireChance > 0f && Rand.Range(0f, 1f) > this.def.causefireChance;
                if (flag2)
                {
                    hitThing.TryAttachFire(0.05f);
                }
                TriggerEffect(def.explosionEffect, ExactPosition);
            }
            if (def.HediffToAdd != null)
            {
                AddedEffect(hitThing);
            }
            Map map = base.Map;

            base.Impact(hitThing);
            BattleLogEntry_RangedImpact battleLogEntry_RangedImpact = new BattleLogEntry_RangedImpact(this.launcher, hitThing, this.intendedTarget.Thing, this.equipmentDef, this.def, this.targetCoverDef);

            Find.BattleLog.Add(battleLogEntry_RangedImpact);
            if (hitThing != null)
            {
                DamageDef  damageDef        = this.def.projectile.damageDef;
                float      amount           = DamageAmount;
                float      armorPenetration = ArmorPenetration;
                float      y            = this.ExactRotation.eulerAngles.y;
                Thing      launcher     = this.launcher;
                ThingDef   equipmentDef = this.equipmentDef;
                DamageInfo dinfo        = new DamageInfo(damageDef, amount, armorPenetration, y, launcher, null, equipmentDef, DamageInfo.SourceCategory.ThingOrUnknown, this.intendedTarget.Thing);
                hitThing.TakeDamage(dinfo).AssociateWithLog(battleLogEntry_RangedImpact);
                Pawn hitPawn = hitThing as Pawn;
                if (hitPawn != null && hitPawn.stances != null && hitPawn.BodySize <= this.def.projectile.StoppingPower + 0.001f)
                {
                    hitPawn.stances.StaggerFor(95);
                }
            }
            else
            {
                SoundDefOf.BulletImpact_Ground.PlayOneShot(new TargetInfo(base.Position, map, false));
                MoteMaker.MakeStaticMote(this.ExactPosition, map, ThingDefOf.Mote_ShotHit_Dirt, 1f);
                if (base.Position.GetTerrain(map).takeSplashes)
                {
                    MoteMaker.MakeWaterSplash(this.ExactPosition, map, Mathf.Sqrt((float)base.DamageAmount) * 1f, 4f);
                }
            }
        }
示例#14
0
        protected override void Impact(Thing hitThing)
        {
            bool shielded = hitThing.IsShielded() && def.IsWeakToShields;

            LaserGunDef defWeapon = equipmentDef as LaserGunDef;
            Vector3     dir       = (destination - origin).normalized;

            dir.y = 0;

            Vector3 a = origin + dir * (defWeapon == null ? 0.9f : defWeapon.barrelLength);
            Vector3 b = shielded ? hitThing.TrueCenter() - dir.RotatedBy(Rand.Range(-22.5f, 22.5f)) * 0.8f : destination;

            a.y = b.y = def.Altitude;

            SpawnBeam(a, b);
            bool createsExplosion = this.def.canExplode && this.def.projectile.explosionRadius > 0f;

            if (createsExplosion)
            {
                this.Explode(hitThing, false);
                GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(this, this.def.projectile.damageDef, this.launcher.Faction);
            }
            Pawn pawn = launcher as Pawn;
            IDrawnWeaponWithRotation weapon = null;

            if (pawn != null && pawn.equipment != null)
            {
                weapon = pawn.equipment.Primary as IDrawnWeaponWithRotation;
            }

            /* if (weapon == null) {
             *   Building_LaserGun turret = launcher as Building_LaserGun;
             *   if (turret != null) {
             *       weapon = turret.gun as IDrawnWeaponWithRotation;
             *   }
             * }
             */
            if (weapon != null)
            {
                float angle = (b - a).AngleFlat() - (intendedTarget.CenterVector3 - a).AngleFlat();
                weapon.RotationOffset = (angle + 180) % 360 - 180;
            }

            if (hitThing == null)
            {
                TriggerEffect(def.explosionEffect, destination);
                bool flag2 = this.def.causefireChance > 0f && Rand.Chance(this.def.causefireChance);
                if (flag2)
                {
                    FireUtility.TryStartFireIn(destination.ToIntVec3(), pawn.Map, 0.05f);
                }
            }
            else
            {
                if (hitThing is Pawn)
                {
                    Pawn hitPawn = hitThing as Pawn;
                    if (shielded)
                    {
                        weaponDamageMultiplier *= def.shieldDamageMultiplier;

                        SpawnBeamReflections(a, b, 5);
                    }
                }

                bool flag2 = this.def.causefireChance > 0f && Rand.Range(0f, 1f) > this.def.causefireChance;
                if (flag2)
                {
                    hitThing.TryAttachFire(0.05f);
                }
                TriggerEffect(def.explosionEffect, ExactPosition);
            }
            base.Impact(hitThing);
        }
示例#15
0
        protected override void Impact(Thing hitThing)
        {
            bool shielded = hitThing.IsShielded() && def.IsWeakToShields;

            LaserGunDef defWeapon = equipmentDef as LaserGunDef;
            Vector3     dir       = ShotLine.direction;

            dir.y = 0;

            Vector3 a = Origin + dir * (defWeapon == null ? 0.9f : defWeapon.barrelLength);
            Vector3 b;

            if (hitThing == null)
            {
                b = ExactPosition;
            }
            else if (shielded)
            {
                Rand.PushState();
                b = ExactPosition - dir.RotatedBy(Rand.Range(-22.5f, 22.5f)) * 0.8f;
                Rand.PopState();
            }
            else if ((destination - ExactPosition).magnitude < 1)
            {
                b = ExactPosition;
            }
            else
            {
                b = ExactPosition;
                Rand.PushState();
                b.x += Rand.Range(-0.5f, 0.5f);
                b.z += Rand.Range(-0.5f, 0.5f);
                Rand.PopState();
            }
            a.y = b.y = def.Altitude;
            //    SpawnBeam(a, b);

            /*
             * bool createsExplosion = this.def.projectile.explosionRadius>0f;
             * if (createsExplosion)
             * {
             *  this.Explode(hitThing, false);
             *  GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(this, this.def.projectile.damageDef, this.launcher.Faction);
             * }
             */
            Pawn pawn = launcher as Pawn;
            IDrawnWeaponWithRotation weapon = null;

            if (pawn != null && pawn.equipment != null)
            {
                weapon = pawn.equipment.Primary as IDrawnWeaponWithRotation;
            }
            if (weapon == null)
            {
                Building_LaserGunCE turret = launcher as Building_LaserGunCE;
                if (turret != null)
                {
                    weapon = turret.Gun as IDrawnWeaponWithRotation;
                }
            }
            if (weapon != null)
            {
                float angle = (b - a).AngleFlat() - (destination - a).AngleFlat();
                weapon.RotationOffset = (angle + 180) % 360 - 180;
            }
            if (hitThing == null)
            {
                TriggerEffect(def.explosionEffect, b);
                Rand.PushState();
                bool flag2 = this.def.causefireChance > 0f && Rand.Chance(this.def.causefireChance);
                Rand.PopState();
                if (flag2)
                {
                    FireUtility.TryStartFireIn(b.ToIntVec3(), pawn.Map, 0.01f);
                }
            }
            else
            {
                if (hitThing is Pawn && shielded)
                {
                    //    weaponDamageMultiplier *= def.shieldDamageMultiplier;

                    SpawnBeamReflections(a, b, 5);
                }

                Rand.PushState();
                bool flag2 = this.def.causefireChance > 0f && Rand.Chance(this.def.causefireChance);
                Rand.PopState();
                if (flag2)
                {
                    hitThing.TryAttachFire(0.01f);
                }
                TriggerEffect(def.explosionEffect, b, hitThing);
            }
            if (def.HediffToAdd != null)
            {
                AddedEffect(hitThing);
            }
            Map map = base.Map;

            base.Impact(hitThing);

            /*
             * if (this.equipmentDef==null)
             * {
             *  this.equipmentDef = this.launcher.def;
             * }
             * BattleLogEntry_RangedImpact battleLogEntry_RangedImpact = new BattleLogEntry_RangedImpact(this.launcher, hitThing, this.intendedTarget, this.equipmentDef, this.def, null);
             * Find.BattleLog.Add(battleLogEntry_RangedImpact);
             * if (hitThing != null)
             * {
             *  DamageDef damageDef = this.def.projectile.damageDef;
             *  float amount = DamageAmount;
             *  float armorPenetration = ArmorPenetration;
             *  float y = this.ExactRotation.eulerAngles.y;
             *  Thing launcher = this.launcher;
             *  ThingDef equipmentDef = this.equipmentDef;
             *  DamageInfo dinfo = new DamageInfo(damageDef, amount, armorPenetration, y, launcher, null, equipmentDef, DamageInfo.SourceCategory.ThingOrUnknown, this.intendedTarget);
             *  hitThing.TakeDamage(dinfo).AssociateWithLog(battleLogEntry_RangedImpact);
             *  Pawn hitPawn = hitThing as Pawn;
             *  if (hitPawn != null && hitPawn.stances != null && hitPawn.BodySize <= this.def.projectile.StoppingPower + 0.001f)
             *  {
             *      hitPawn.stances.StaggerFor(95);
             *  }
             * }
             * else
             * {
             *  SoundDefOf.BulletImpact_Ground.PlayOneShot(new TargetInfo(base.Position, map, false));
             *  MoteMaker.MakeStaticMote(this.ExactPosition, map, ThingDefOf.Mote_ShotHit_Dirt, 1f);
             *  if (base.Position.GetTerrain(map).takeSplashes)
             *  {
             *      MoteMaker.MakeWaterSplash(this.ExactPosition, map, Mathf.Sqrt((float)this.def.projectile.GetDamageAmount(1f, null)) * 1f, 4f);
             *  }
             * }
             */
        }