Example #1
0
        public static bool IsAutoTargetable(IAttackTarget target)
        {
            CompCanBeDormant compCanBeDormant = target.Thing.TryGetComp <CompCanBeDormant>();

            if (compCanBeDormant != null && !compCanBeDormant.Awake)
            {
                return(false);
            }
            CompInitiatable compInitiatable = target.Thing.TryGetComp <CompInitiatable>();

            if (compInitiatable != null && !compInitiatable.Initiated)
            {
                return(false);
            }
            return(true);
        }
        public override void SpawnSetup(Map map, bool respawningAfterLoad)      //Add mannableComp, ticksUntilAutoReload, register to GenClosestAmmo
        {
            base.SpawnSetup(map, respawningAfterLoad);
            Map.GetComponent <TurretTracker>().Register(this);

            dormantComp     = GetComp <CompCanBeDormant>();
            initiatableComp = GetComp <CompInitiatable>();
            powerComp       = GetComp <CompPowerTrader>();
            mannableComp    = GetComp <CompMannable>();

            if (!everSpawned && (!Map.IsPlayerHome || Faction != Faction.OfPlayer))
            {
                compAmmo?.ResetAmmoCount();
                everSpawned = true;
            }

            if (!respawningAfterLoad)
            {
                CELogger.Message($"top is {top?.ToString() ?? "null"}");
                top.SetRotationFromOrientation();
                burstCooldownTicksLeft = def.building.turretInitialCooldownTime.SecondsToTicks();

                //Delay auto-reload for a few seconds after spawn, so player can operate the turret right after placing it, before other colonists start reserving it for reload jobs
                if (mannableComp != null)
                {
                    ticksUntilAutoReload = minTicksBeforeAutoReload;
                }
            }

            // if (CompAmmo == null || CompAmmo.Props == null || CompAmmo.Props.ammoSet == null || CompAmmo.Props.ammoSet.ammoTypes.NullOrEmpty())
            //     return;

            // //"Subscribe" turret to GenClosestAmmo
            // foreach (var ammo in CompAmmo.Props.ammoSet.ammoTypes.Select(x => x.ammo))
            // {
            //     if (!GenClosestAmmo.listeners.ContainsKey(ammo))
            //         GenClosestAmmo.listeners.Add(ammo, new List<Building_TurretGunCE>() { this });
            //     else
            //         GenClosestAmmo.listeners[ammo].Add(this);

            //     if (!GenClosestAmmo.latestAmmoUpdate.ContainsKey(ammo))
            //         GenClosestAmmo.latestAmmoUpdate.Add(ammo, 0);
            // }
        }
        // Token: 0x06004F1C RID: 20252 RVA: 0x001AB3BC File Offset: 0x001A95BC
        public bool ThreatDisabled(IAttackTargetSearcher disabledFor)
        {
            CompPowerTrader comp = base.GetComp <CompPowerTrader>();

            if (comp != null && !comp.PowerOn)
            {
                return(true);
            }
            CompMannable comp2 = base.GetComp <CompMannable>();

            if (comp2 != null && !comp2.MannedNow)
            {
                return(true);
            }
            CompCanBeDormant comp3 = base.GetComp <CompCanBeDormant>();

            if (comp3 != null && !comp3.Awake)
            {
                return(true);
            }
            CompInitiatable comp4 = base.GetComp <CompInitiatable>();

            return(comp4 != null && !comp4.Initiated);
        }