private void StartRealAttack()
        {
            bool cast = true;
            if (globalTarget.IsValid)
            {
                Log.Message($"Using global target to create local target. ({globalTarget})");
                if (globalTarget.Map == null)
                {
                    if(globalTargetMapLastKnown != null)
                    {
                        Log.Warning($"Global target has null map (most likely missing pawn target). Falling back to last known map ({globalTargetMapLastKnown}).");
                        localTarget = new LocalTargetInfo(lastKnownThingLoc);
                        globalTarget = new GlobalTargetInfo(lastKnownThingLoc, globalTargetMapLastKnown);
                    }
                    else
                    {
                        Log.Error("Global target is valid, but has null map. Last known map is also null. Probably caused by map being unloaded prematurely, or immediately after the updated that added this feature. Strike cancelled to avoid damage to wrong map.");
                        cast = false;
                    }
                }
                else
                {
                    // Convert to local target. Note that Thing may be non-null be destroyed, that is handled below.
                    localTarget = globalTarget.HasThing ? new LocalTargetInfo(globalTarget.Thing) : new LocalTargetInfo(globalTarget.Cell);
                }
            }
            // Make sure that the local target is completely valid: it is possible that thing is destroyed and Target.IsValid is still true.
            if (localTarget.HasThing && localTarget.ThingDestroyed)
            {
                Log.Warning($"M3G_UMIN appears to have been targeting a Thing but that Thing was destroyed. Using last known location: {lastKnownThingLoc}");
                localTarget = new LocalTargetInfo(lastKnownThingLoc);
            }

            // Spawn sky beam of death.
            if (cast)
            {
                bool worked = AttackVerb.TryStartCastOn(localTarget);
                if (!worked)
                {
                    Log.Error("Megumin verb cast failed!");
                    cast = false;
                }
            }

            if (!cast)
            {
                // Cast failed. Stop be beam effect immediately.
                OnStrikeEnd(null);
            }
            

            chargeEffect?.Stop(true, ParticleSystemStopBehavior.StopEmitting);

            // Put on cooldown.
            CooldownTicks = COOLDOWN_TICKS;

            // Delete target position.
            localTarget = LocalTargetInfo.Invalid;
            globalTarget = GlobalTargetInfo.Invalid;
            lastKnownThingLoc = IntVec3.Invalid;
            globalTargetMapLastKnown = null;

            // Spawn a solar flare event on the map that it was fired from.
            if (DoSolarFlare && cast)
            {
                IncidentParms param = new IncidentParms();
                param.forced = true;
                param.target = this.Map;

                bool canFire = AADefOf.SolarFlare.Worker.CanFireNow(param);
                if (!canFire)
                    Log.Warning("SolarFare Worker says that it cannot fire under the current conditions - forcing it to anyway, from M3G_UMIN.");

                bool worked = AADefOf.SolarFlare.Worker.TryExecute(param);
                if (!worked)
                    Log.Error("SolarFare Worker failed to execute (returned false), from M3G_UMIN.");
            }
        }
Exemple #2
0
 protected void BeginBurst()                     // Added handling for ticksUntilAutoReload
 {
     ticksUntilAutoReload = minTicksBeforeAutoReload;
     AttackVerb.TryStartCastOn(CurrentTarget, false, true);
     OnAttackedTarget(CurrentTarget);
 }
Exemple #3
0
 protected void BeginBurst()
 {
     AttackVerb.TryStartCastOn(CurrentTarget);
     OnAttackedTarget(CurrentTarget);
 }