Пример #1
0
        public override IEnumerable <Gizmo> CompGetGizmosExtra()
        {
            if (Cannons.Count > 0)
            {
                int turretNumber = 0;
                var rotatables   = Cannons.Where(x => x.turretDef.weaponType == TurretType.Rotatable);
                var statics      = Cannons.Where(x => x.turretDef.weaponType == TurretType.Static);
                if (rotatables.NotNullAndAny())
                {
                    foreach (VehicleTurret turret in rotatables)
                    {
                        if (turret.manualTargeting)
                        {
                            Command_TargeterCooldownAction turretCannons = new Command_TargeterCooldownAction
                            {
                                turret        = turret,
                                defaultLabel  = !string.IsNullOrEmpty(turret.gizmoLabel) ? turret.gizmoLabel : $"{turret.turretDef.LabelCap} {turretNumber}",
                                icon          = turret.GizmoIcon,
                                iconDrawScale = turret.turretDef.gizmoIconScale
                            };
                            if (!string.IsNullOrEmpty(turret.turretDef.gizmoDescription))
                            {
                                turretCannons.defaultDesc = turret.turretDef.gizmoDescription;
                            }
                            turretCannons.targetingParams = new TargetingParameters
                            {
                                //Buildings, Things, Animals, Humans, and Mechs default to targetable
                                canTargetLocations = true
                            };
                            turretNumber++;
                            foreach (VehicleHandler relatedHandler in Vehicle.GetAllHandlersMatch(HandlingTypeFlags.Cannon, turret.key))
                            {
                                if (relatedHandler.handlers.Count < relatedHandler.role.slotsToOperate && !DebugSettings.godMode)
                                {
                                    turretCannons.Disable("NotEnoughCannonCrew".Translate(Vehicle.LabelShort, relatedHandler.role.label));
                                    break;
                                }
                            }
                            yield return(turretCannons);

                            if (Vehicle.Faction != Faction.OfPlayer)
                            {
                                turretCannons.Disable("CannotOrderNonControlled".Translate());
                            }
                        }
                        if (Prefs.DevMode)
                        {
                            yield return(new Command_Action()
                            {
                                defaultLabel = $"Full Refill: {turret.gizmoLabel}",
                                action = delegate()
                                {
                                    if (turret.turretDef.ammunition is null)
                                    {
                                        turret.ReloadCannon(null);
                                    }
                                    else if (turret.turretDef.ammunition.AllowedThingDefs.FirstOrDefault() is ThingDef thingDef)
                                    {
                                        Thing ammo = ThingMaker.MakeThing(thingDef);
                                        ammo.stackCount = thingDef.stackLimit;
                                        Vehicle.inventory.innerContainer.TryAddOrTransfer(ammo);
                                        turret.ReloadCannon(thingDef);
                                    }
                                }
                            });