示例#1
0
        static void Postfix(Projectile __instance, Vector3 ___destination, ref float ___ticksToImpact, Thing launcher, ref Vector3 ___origin, LocalTargetInfo usedTarget, LocalTargetInfo intendedTarget, ProjectileHitFlags hitFlags, Thing equipment, ThingDef targetCoverDef)
        {
            GunPropDef prop = GunplaySetup.GunProp(equipment);

            if (prop == null)
            {
                return;
            }

            CompGun comp = equipment.TryGetComp <CompGun>();

            if (comp != null)
            {
                float angle = (___destination - ___origin).AngleFlat() - (intendedTarget.CenterVector3 - ___origin).AngleFlat();
                comp.RotationOffset = (angle + 180) % 360 - 180;
            }

            if (launcher as Pawn != null)
            {
                ___origin += (___destination - ___origin).normalized * prop.barrelLength;
            }

            if (Gunplay.settings.enableTrails)
            {
                ProjectileTrail trail = GenSpawn.Spawn(prop.trail, ___origin.ToIntVec3(), launcher.Map, WipeMode.Vanish) as ProjectileTrail;
                trail.Initialize(__instance, ___destination, equipment);
            }
        }
示例#2
0
        static float Postfix(float value, Projectile __instance)
        {
            GunPropDef prop = GunplaySetup.GunProp(__instance.EquipmentDef);

            if (prop == null || prop.preserveSpeed)
            {
                return(value);
            }

            return(value / Gunplay.settings.projectileSpeed);
        }
示例#3
0
        static void Prefix(Projectile __instance, Thing hitThing, Vector3 ___origin)
        {
            Map map = __instance.Map;

            if (map == null)
            {
                return;
            }

            GunPropDef prop = GunplaySetup.GunProp(__instance.EquipmentDef);

            if (prop == null)
            {
                return;
            }

            MaterialKind kind = MaterialKind.None;

            if (hitThing != null)
            {
                kind = MaterialKindGetter.Get(hitThing);
            }

            if (kind == MaterialKind.None)
            {
                TerrainDef terrainDef = map.terrainGrid.TerrainAt(CellIndicesUtility.CellToIndex(__instance.Position, map.Size.x));
                kind = MaterialKindGetter.Get(terrainDef);
            }

            if (Gunplay.settings.enableSounds)
            {
                SoundDef sound = prop.projectileImpactSound == null ? null : prop.projectileImpactSound.Effect(kind);
                if (sound != null)
                {
                    sound.PlayOneShot(new TargetInfo(__instance.Position, map, false));
                }
            }

            if (Gunplay.settings.enableEffects)
            {
                EffecterDef effecterDef = prop.projectileImpactEffect == null ? null : prop.projectileImpactEffect.Effect(kind);
                if (effecterDef != null)
                {
                    Effecter effecter = new Effecter(effecterDef);
                    effecter.Trigger(__instance, new TargetInfo(___origin.ToIntVec3(), __instance.Map));
                    effecter.Cleanup();
                }
            }
        }
示例#4
0
        static bool Prefix(ref Thing eq, ref Vector3 drawLoc, ref float aimAngle, PawnRenderer __instance)
        {
            if (!Gunplay.settings.enableWeaponAnimations)
            {
                return(true);
            }

            CompGun comp = eq.TryGetComp <CompGun>();

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

            Pawn pawn = pawnField.GetValue(__instance) as Pawn;

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

            Stance_Busy stance_Busy = pawn.stances.curStance as Stance_Busy;

            if (stance_Busy != null && !stance_Busy.neverAimWeapon && stance_Busy.focusTarg.IsValid)
            {
                drawLoc -= equipmentDir.RotatedBy(aimAngle);
                aimAngle = (aimAngle + comp.RotationOffset) % 360;
                drawLoc += equipmentDir.RotatedBy(aimAngle);
            }

            GunPropDef prop = GunplaySetup.GunProp(eq);

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

            float num = aimAngle - 90f;
            Mesh  mesh;

            if (aimAngle > 20f && aimAngle < 160f)
            {
                mesh = MeshPool.plane10;
                num += eq.def.equippedAngleOffset;
            }
            else if (aimAngle > 200f && aimAngle < 340f)
            {
                mesh = MeshPool.plane10Flip;
                num -= 180f;
                num -= eq.def.equippedAngleOffset;
            }
            else
            {
                mesh = MeshPool.plane10;
                num += eq.def.equippedAngleOffset;
            }
            num %= 360f;

            drawingScale.x = drawingScale.z = prop.drawScale;
            CompPrimer primer = eq.TryGetComp <CompPrimer>();

            if (primer != null)
            {
                primer.Draw(mesh, drawLoc, num, drawingScale);
                return(false);
            }

            if (prop.drawScale == 1f)
            {
                return(true);
            }

            Material mat;

            Graphic_StackCount graphic_StackCount = eq.Graphic as Graphic_StackCount;

            if (graphic_StackCount != null)
            {
                mat = graphic_StackCount.SubGraphicForStackCount(1, eq.def).MatSingle;
            }
            else
            {
                mat = eq.Graphic.MatSingle;
            }

            drawingMatrix.SetTRS(drawLoc, Quaternion.AngleAxis(num, Vector3.up), drawingScale);
            Graphics.DrawMesh(mesh, drawingMatrix, mat, 0);

            return(false);
        }