Beispiel #1
0
 /// <summary>
 /// Reset selected fire mode back to default when gun is dropped
 /// </summary>
 public override void Notify_EquipmentLost()
 {
     base.Notify_EquipmentLost();
     if (CompFireModes != null)
     {
         CompFireModes.ResetModes();
     }
 }
        public override IEnumerable <Gizmo> GetGizmos()
        {
            foreach (Gizmo gizmo in base.GetGizmos())
            {
                yield return(gizmo);
            }
            // Don't show gizmos on enemy turrets
            if (Faction == Faction.OfPlayer || MannedByColonist)
            {
                // Ammo gizmos
                if (CompAmmo != null)
                {
                    foreach (Command com in CompAmmo.CompGetGizmosExtra())
                    {
                        yield return(com);
                    }
                }
                // Fire mode gizmos
                if (CompFireModes != null)
                {
                    foreach (Command com in CompFireModes.GenerateGizmos())
                    {
                        yield return(com);
                    }
                }
                // Set forced target gizmo
                if (CanSetForcedTarget)
                {
                    yield return(new Command_VerbTarget
                    {
                        defaultLabel = "CommandSetForceAttackTarget".Translate(),
                        defaultDesc = "CommandSetForceAttackTargetDesc".Translate(),
                        icon = ContentFinder <Texture2D> .Get("UI/Commands/Attack", true),
                        verb = GunCompEq.PrimaryVerb,
                        hotKey = KeyBindingDefOf.Misc4
                    });
                }
                // Stop forced attack gizmo
                if (forcedTarget.IsValid)
                {
                    Command_Action stop = new Command_Action();
                    stop.defaultLabel = "CommandStopForceAttack".Translate();
                    stop.defaultDesc  = "CommandStopForceAttackDesc".Translate();
                    stop.icon         = ContentFinder <Texture2D> .Get("UI/Commands/Halt", true);

                    stop.action = delegate
                    {
                        ResetForcedTarget();
                        SoundDefOf.Tick_Low.PlayOneShotOnCamera(null);
                    };
                    if (!this.forcedTarget.IsValid)
                    {
                        stop.Disable("CommandStopAttackFailNotForceAttacking".Translate());
                    }
                    stop.hotKey = KeyBindingDefOf.Misc5;
                    yield return(stop);
                }
                // Toggle fire gizmo
                if (CanToggleHoldFire)
                {
                    yield return(new Command_Toggle
                    {
                        defaultLabel = "CommandHoldFire".Translate(),
                        defaultDesc = "CommandHoldFireDesc".Translate(),
                        icon = ContentFinder <Texture2D> .Get("UI/Commands/HoldFire", true),
                        hotKey = KeyBindingDefOf.Misc6,
                        toggleAction = delegate
                        {
                            holdFire = !holdFire;
                            if (holdFire)
                            {
                                ResetForcedTarget();
                            }
                        },
                        isActive = (() => holdFire)
                    });
                }
            }
        }
        /// <summary>
        /// Fires a projectile using the new aiming system
        /// </summary>
        /// <returns>True for successful shot, false otherwise</returns>
        protected override bool TryCastShot()
        {
            ShootLine shootLine;

            if (!TryFindCEShootLineFromTo(caster.Position, currentTarget, out shootLine))
            {
                return(false);
            }

            Pawn p = CasterPawn != null ? CasterPawn : caster as Pawn;


            if (caster != null)
            {
                //        Log.Message("caster: " + caster.ToString() + " pos: " + caster.Position.ToString());
            }
            if (CasterPawn != null)
            {
                //        Log.Message("casterPawn: " + CasterPawn.ToString() + " pos: " + CasterPawn.Position.ToString());
            }
            //    Log.Message("currentTarget: " + currentTarget.ToString() + " pos: " + currentTarget.Cell.ToString());



            if (p != null && !p.IsColonistPlayerControlled && p.equipment != null && p.equipment.Primary != null)
            {
                if (numShotsFired == 0)
                {
                    CompFireModes compFireModes = p.equipment.Primary.TryGetComp <CompFireModes>();
                    if (compFireModes != null)
                    {
                        float lengthToTarget  = Mathf.Abs((currentTarget.Cell - caster.Position).LengthHorizontal);
                        float rangemultiplier = this.VerbPropsCE.range / 60;

                        if (lengthToTarget <= (30 * rangemultiplier))
                        {
                            if (compFireModes.availableAimModes.Contains(AimMode.Snapshot) && compFireModes.currentAimModeInt != AimMode.Snapshot)
                            {
                                compFireModes.currentAimModeInt = AimMode.Snapshot;
                                //    Log.Message("selected aimmode1: " + compFireModes.currentAimModeInt);
                            }
                        }
                        else
                        {
                            if (compFireModes.availableAimModes.Contains(AimMode.AimedShot) && compFireModes.currentAimModeInt != AimMode.AimedShot)
                            {
                                compFireModes.currentAimModeInt = AimMode.AimedShot;
                                //    Log.Message("selected aimmode2: " + compFireModes.currentAimModeInt);
                            }
                        }
                        if (compFireModes.availableFireModes.Count > 1)
                        {
                            if (lengthToTarget <= (50 * rangemultiplier))
                            {
                                if (compFireModes.availableFireModes.Contains(FireMode.AutoFire) && compFireModes.currentFireModeInt != FireMode.AutoFire)
                                {
                                    compFireModes.currentFireModeInt = FireMode.AutoFire;
                                    //    Log.Message("selected firemode1: " + compFireModes.currentFireModeInt.ToString());
                                }
                            }
                            else
                            {
                                if (compFireModes.availableFireModes.Contains(FireMode.SingleFire) && compFireModes.currentFireModeInt != FireMode.SingleFire)
                                {
                                    compFireModes.currentFireModeInt = FireMode.SingleFire;
                                    //    Log.Message("selected firemode2: " + compFireModes.currentFireModeInt.ToString());
                                }
                            }
                        }
                    }
                }
            }

            if (p != null)
            {
                if ((Mathf.Abs(cachedShotRotation - shotRotation)) >= 15 && numShotsFired == 0)
                {
                    cachedShotRotation = shotRotation;
                    p.Drawer.Notify_WarmingCastAlongLine(shootLine, caster.Position);
                }
            }


            if (projectilePropsCE.pelletCount < 1)
            {
                Log.Error(EquipmentSource.LabelCap + " tried firing with pelletCount less than 1.");
                return(false);
            }
            ShiftVecReport report = ShiftVecReportFor(currentTarget);
            bool           pelletMechanicsOnly = false;

            for (int i = 0; i < projectilePropsCE.pelletCount; i++)
            {
                ProjectileCE projectile = (ProjectileCE)ThingMaker.MakeThing(Projectile, null);
                GenSpawn.Spawn(projectile, shootLine.Source, caster.Map);
                ShiftTarget(report, pelletMechanicsOnly);

                //New aiming algorithm
                projectile.canTargetSelf   = false;
                projectile.minCollisionSqr = (sourceLoc - currentTarget.Cell.ToIntVec2.ToVector2Shifted()).sqrMagnitude;
                projectile.intendedTarget  = currentTarget.Thing;
                projectile.Launch(
                    Shooter,            //Shooter instead of caster to give turret operators' records the damage/kills obtained
                    sourceLoc,
                    shotAngle,
                    shotRotation,
                    ShotHeight,
                    ShotSpeed,
                    EquipmentSource
                    );
                pelletMechanicsOnly = true;
                //    Log.Message("proj: " + projectile.ToString() + " shootlineSource: " + shootLine.Source.ToString() + " caster: " + caster.ToString() + " currentTarget.Thing: " + currentTarget.Thing.ToString() + " report: " + report.ToString());
                //    Log.Message("minCollisionSqr: " + projectile.minCollisionSqr.ToString() + " intendedTarget : " + projectile.intendedTarget.ToString() + " Shooter: " + Shooter.ToString()
                //        + " sourceLoc: " + sourceLoc.ToString() + " shotAngle: " + shotAngle.ToString() + " shotRotation: " + shotRotation.ToString() + " ShotHeight: " + ShotHeight.ToString()
                //        + " ShotHeight: " + ShotHeight.ToString() + "ShotSpeed: " + ShotSpeed.ToString() + " EquipmentSource: " + EquipmentSource.ToString());
            }
            pelletMechanicsOnly = false;
            this.numShotsFired++;
            return(true);
        }