Esempio n. 1
0
        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);
        }
Esempio n. 3
0
        public override void Impact()
        {
            if (Payload != null)
            {
                if (Payload.projectile.explosionDelay == 0)
                {
                    this.Explode();
                    return;
                }
                this.landed            = true;
                this.ticksToDetonation = Payload.projectile.explosionDelay;
                GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(this, Payload.projectile.damageDef, this.launcher.Faction);
            }
            else
            if (this.def.skyfaller.CausesExplosion)
            {
                //	Log.Message("CausesExplosion");
                GenExplosion.DoExplosion(base.Position, base.Map, this.def.skyfaller.explosionRadius, this.def.skyfaller.explosionDamage, null, GenMath.RoundRandom((float)this.def.skyfaller.explosionDamage.defaultDamage * this.def.skyfaller.explosionDamageFactor), -1f, null, null, null, null, null, 0f, 1, false, null, 0f, 1, 0f, false, null, (!this.def.skyfaller.damageSpawnedThings) ? this.innerContainer.ToList <Thing>() : null);
            }
            //	this.SpawnThings();
            this.innerContainer.ClearAndDestroyContents(DestroyMode.Vanish);
            CellRect cellRect = this.OccupiedRect();

            for (int i = 0; i < cellRect.Area * this.def.skyfaller.motesPerCell; i++)
            {
                AdeptusFleckMaker.ThrowDustPuff(cellRect.RandomVector3, base.Map, 2f);
            }
            if (this.def.skyfaller.MakesShrapnel)
            {
                SkyfallerShrapnelUtility.MakeShrapnel(base.Position, base.Map, this.shrapnelDirection, this.def.skyfaller.shrapnelDistanceFactor, this.def.skyfaller.metalShrapnelCountRange.RandomInRange, this.def.skyfaller.rubbleShrapnelCountRange.RandomInRange, true);
            }
            if (this.def.skyfaller.cameraShake > 0f && base.Map == Find.CurrentMap)
            {
                Find.CameraDriver.shaker.DoShake(this.def.skyfaller.cameraShake);
            }
            if (this.def.skyfaller.impactSound != null)
            {
                this.def.skyfaller.impactSound.PlayOneShot(SoundInfo.InMap(new TargetInfo(base.Position, base.Map, false), MaintenanceType.None));
            }
            this.Destroy(DestroyMode.Vanish);
        }
Esempio n. 4
0
 public override void Tick()
 {
     if (Payload == null)
     {
         Log.Warning("Tried to spawn Artillery Strike with no Payload");
         this.Destroy();
         return;
     }
     if (this.ticksToDetonation > 0)
     {
         this.ticksToDetonation--;
         if (this.ticksToDetonation <= 0)
         {
             this.Explode();
         }
     }
     this.innerContainer.ThingOwnerTick(true);
     if (this.SpawnTimedMotes)
     {
         CellRect cellRect = this.OccupiedRect();
         for (int i = 0; i < cellRect.Area * this.def.skyfaller.motesPerCell; i++)
         {
             AdeptusFleckMaker.ThrowDustPuff(cellRect.RandomVector3, base.Map, 2f);
         }
     }
     if (this.def.skyfaller.reversed)
     {
         this.ticksToImpact++;
         if (!this.anticipationSoundPlayed && this.def.skyfaller.anticipationSound != null && this.ticksToImpact > this.def.skyfaller.anticipationSoundTicks)
         {
             this.anticipationSoundPlayed = true;
             this.def.skyfaller.anticipationSound.PlayOneShot(new TargetInfo(base.Position, base.Map, false));
         }
         if (this.ticksToImpact == 220)
         {
             this.LeaveMap();
             return;
         }
         if (this.ticksToImpact > 220)
         {
             Log.Error("ticksToImpact > LeaveMapAfterTicks. Was there an exception? Destroying skyfaller.");
             this.Destroy(DestroyMode.Vanish);
             return;
         }
     }
     else
     {
         this.ticksToImpact--;
         if (this.ticksToImpact == 15)
         {
             this.HitRoof();
         }
         if (!this.anticipationSoundPlayed && this.def.skyfaller.anticipationSound != null && this.ticksToImpact < this.def.skyfaller.anticipationSoundTicks)
         {
             this.anticipationSoundPlayed = true;
             this.def.skyfaller.anticipationSound.PlayOneShot(new TargetInfo(base.Position, base.Map, false));
         }
         if (this.ticksToImpact <= 0 && this.ticksToDetonation <= 0)
         {
             this.Impact();
             return;
         }
         if (this.ticksToImpact < 0 && Payload.projectile.explosionDelay == 0)
         {
             Log.Error("ticksToImpact < 0. Was there an exception? Destroying skyfaller.");
             this.Destroy(DestroyMode.Vanish);
         }
     }
 }
Esempio n. 5
0
        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);
            }
        }