Esempio n. 1
0
        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);
        }
Esempio n. 2
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;

            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);


            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 is Pawn && shielded)
            {
                weaponDamageMultiplier *= def.shieldDamageMultiplier;

                SpawnBeamReflections(a, b, 5);
            }

            TriggerEffect(def.explosionEffect, b);

            base.Impact(hitThing);
        }