示例#1
0
        // TryCastShotFrom(muzzlePos)
        public bool TryCastShotFrom(Vector3 muzzlePos)
        {
            if (!TryFindCEShootLineFromTo(caster.Position, currentTarget, out var shootLine))
            {
                return(false);
            }
            if (projectilePropsCE.pelletCount < 1)
            {
                Log.Error(EquipmentSource.LabelCap + " tried firing with pelletCount less than 1.");
                return(false);
            }
            ShiftVecReport report = ShiftVecReportFor(currentTarget);
            bool           pelletMechanicsOnly = false;

            numShotsFired = (int)AccessTools.Field(typeof(Verb_LaunchProjectileCE), "numShotsFired").GetValue(this);
            shotAngle     = (float)AccessTools.Field(typeof(Verb_LaunchProjectileCE), "shotAngle").GetValue(this);
            shotRotation  = (float)AccessTools.Field(typeof(Verb_LaunchProjectileCE), "shotRotation").GetValue(this);
            shotSpeed     = (float)AccessTools.Field(typeof(Verb_LaunchProjectileCE), "shotSpeed").GetValue(this);
            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;

                var targDist = (muzzlePos.ToIntVec3().ToIntVec2.ToVector2Shifted() - currentTarget.Cell.ToIntVec2.ToVector2Shifted()).magnitude;
                if (targDist <= 2)
                {
                    targDist *= 2;                      // Double to account for divide by 4 in ProjectileCE minimum collision distance calculations
                }
                //	projectile.minCollisionSqr = Mathf.Pow(targDist, 2);
                projectile.intendedTarget = currentTarget.Thing;
                projectile.mount          = caster.Position.GetThingList(caster.Map).FirstOrDefault(t => t is Pawn && t != caster);
                projectile.AccuracyFactor = report.accuracyFactor * report.swayDegrees * ((numShotsFired + 1) * 0.75f);
                projectile.Launch(
                    Shooter,                        //Shooter instead of caster to give turret operators' records the damage/kills obtained
                    new Vector2(muzzlePos.x, muzzlePos.z),
                    shotAngle,
                    shotRotation,
                    ShotHeight,
                    ShotSpeed,
                    EquipmentSource
                    );
                pelletMechanicsOnly = true;
            }
            /// Log.Message("Fired from "+caster.ThingID+" at "+ShotHeight); ///
            pelletMechanicsOnly = false;
            numShotsFired++;
            if (CompAmmo != null && !CompAmmo.CanBeFiredNow)
            {
                CompAmmo?.TryStartReload();
            }
            if (CompReloadable != null)
            {
                CompReloadable.UsedOnce();
            }
            return(true);
        }
        internal static string ShotCalculationTipString(Thing target)
        {
            StringBuilder stringBuilder = new StringBuilder();

            if (Find.Selector.SingleSelectedThing != null)
            {
                Pawn pawn = Find.Selector.SingleSelectedThing as Pawn;
                if (pawn != null && pawn != target && pawn.equipment != null && pawn.equipment.Primary != null)
                {
                    Verb_LaunchProjectile verb_LaunchProjectile = pawn.equipment.PrimaryEq.PrimaryVerb as Verb_LaunchProjectile;
                    if (verb_LaunchProjectile != null)
                    {
                        stringBuilder.AppendLine();
                        stringBuilder.Append("ShotBy".Translate(new object[]
                        {
                            pawn.LabelBaseShort
                        }) + ":");
                        if (verb_LaunchProjectile.CanHitTarget(target))
                        {
                            HitReport hitReport = verb_LaunchProjectile.HitReportFor(target);
                            stringBuilder.Append(hitReport.GetTextReadout());
                        }
                        else
                        {
                            stringBuilder.Append("CannotHit".Translate());
                        }
                    }
                    // Append CR tooltip
                    else
                    {
                        Verb_LaunchProjectileCR verbCR = pawn.equipment.PrimaryEq.PrimaryVerb as Verb_LaunchProjectileCR;
                        if (verbCR != null)
                        {
                            stringBuilder.AppendLine();
                            stringBuilder.Append("ShotBy".Translate(new object[] { pawn.LabelBaseShort }) + ":\n");
                            if (verbCR.CanHitTarget(target))
                            {
                                ShiftVecReport report = verbCR.ShiftVecReportFor(target);
                                stringBuilder.Append(report.GetTextReadout());
                            }
                            else
                            {
                                stringBuilder.Append("CannotHit".Translate());
                            }
                        }
                    }
                }
            }
            return(stringBuilder.ToString());
        }
 public static void Postfix(ref string __result, Thing target)
 {
     if (__result.NullOrEmpty() && Find.Selector.SingleSelectedThing != null)
     {
         // Create CE Tooltip
         StringBuilder           stringBuilder = new StringBuilder();
         Verb_LaunchProjectileCE verbCE        = null;
         Pawn pawn = Find.Selector.SingleSelectedThing as Pawn;
         if (pawn != null && pawn != target && pawn.equipment != null &&
             pawn.equipment.Primary != null && pawn.equipment.PrimaryEq.PrimaryVerb is Verb_LaunchProjectileCE)
         {
             verbCE = pawn.equipment.PrimaryEq.PrimaryVerb as Verb_LaunchProjectileCE;
         }
         Building_TurretGunCE turret = Find.Selector.SingleSelectedThing as Building_TurretGunCE;
         if (turret != null && turret != target)
         {
             verbCE = turret.AttackVerb as Verb_LaunchProjectileCE;
         }
         if (verbCE != null)
         {
             stringBuilder.AppendLine();
             stringBuilder.Append("ShotBy".Translate(new object[] { Find.Selector.SingleSelectedThing.LabelShort }) + ":\n");
             string obstructReport;
             if (verbCE.CanHitTarget(target, out obstructReport))
             {
                 ShiftVecReport report = verbCE.ShiftVecReportFor(target);
                 stringBuilder.Append(report.GetTextReadout());
             }
             else
             {
                 stringBuilder.Append("CannotHit".Translate());
                 if (!obstructReport.NullOrEmpty())
                 {
                     stringBuilder.Append(" " + obstructReport + ".");
                 }
             }
         }
         __result = stringBuilder.ToString();
     }
 }
        internal static string ShotCalculationTipString(Thing target)
        {
            StringBuilder stringBuilder = new StringBuilder();

            if (Find.Selector.SingleSelectedThing != null)
            {
                Verb verb = null;
                Verb_LaunchProjectileCE verbCE = null;
                Pawn pawn = Find.Selector.SingleSelectedThing as Pawn;
                if (pawn != null && pawn != target && pawn.equipment != null && pawn.equipment.Primary != null && pawn.equipment.PrimaryEq.PrimaryVerb is Verb_LaunchProjectile)
                {
                    verb = pawn.equipment.PrimaryEq.PrimaryVerb;
                }
                Building_TurretGun building_TurretGun = Find.Selector.SingleSelectedThing as Building_TurretGun;
                if (building_TurretGun != null && building_TurretGun != target)
                {
                    verb = building_TurretGun.AttackVerb;
                }
                if (verb != null)
                {
                    stringBuilder.AppendLine();
                    stringBuilder.Append("ShotBy".Translate(new object[]
                    {
                        Find.Selector.SingleSelectedThing.LabelShort
                    }) + ": ");
                    if (verb.CanHitTarget(target))
                    {
                        stringBuilder.Append(ShotReport.HitReportFor(verb.caster, verb, target).GetTextReadout());
                    }
                    else
                    {
                        stringBuilder.Append("CannotHit".Translate());
                    }
                }
                // Append CE tooltip
                else
                {
                    if (pawn != null && pawn != target && pawn.equipment != null &&
                        pawn.equipment.Primary != null && pawn.equipment.PrimaryEq.PrimaryVerb is Verb_LaunchProjectileCE)
                    {
                        verbCE = pawn.equipment.PrimaryEq.PrimaryVerb as Verb_LaunchProjectileCE;
                    }
                    Building_TurretGun building_TurretGun2 = Find.Selector.SingleSelectedThing as Building_TurretGun;
                    if (building_TurretGun != null && building_TurretGun != target)
                    {
                        verbCE = building_TurretGun.AttackVerb as Verb_LaunchProjectileCE;
                    }
                    if (verbCE != null)
                    {
                        stringBuilder.AppendLine();
                        stringBuilder.Append("ShotBy".Translate(new object[] { pawn.LabelShort }) + ":\n");
                        if (verbCE.CanHitTarget(target))
                        {
                            ShiftVecReport report = verbCE.ShiftVecReportFor(target);
                            stringBuilder.Append(report.GetTextReadout());
                        }
                        else
                        {
                            stringBuilder.Append("CannotHit".Translate());
                        }
                    }
                }
            }
            return(stringBuilder.ToString());
        }