当前位置: 首页>>代码示例>>C#>>正文


C# Thing.TryGetComp方法代码示例

本文整理汇总了C#中Thing.TryGetComp方法的典型用法代码示例。如果您正苦于以下问题:C# Thing.TryGetComp方法的具体用法?C# Thing.TryGetComp怎么用?C# Thing.TryGetComp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Thing的用法示例。


在下文中一共展示了Thing.TryGetComp方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HasJobOnThing

        public override bool HasJobOnThing( Pawn pawn, Thing t )
        {
#if DEBUG_WORKGIVER
            Log.Message("Checking " + t.LabelCap + " for job.");
            Log.Message("ManagerStation" + ((t as Building_ManagerStation) != null));
            Log.Message("Comp" + (t.TryGetComp<Comp_ManagerStation>() != null));
            Log.Message("Incap" + (!pawn.Dead && !pawn.Downed && !pawn.IsBurning() && !t.IsBurning()));
            Log.Message("CanReserve and reach" + (pawn.CanReserveAndReach(t, PathEndMode, Danger.Some)));
            CompPowerTrader powera = t.TryGetComp<CompPowerTrader>();
            Log.Message("Power" + (powera == null || powera.PowerOn));
            Log.Message("Job" + (Manager.Get.JobStack.NextJob != null));
#endif
            if ( !( t is Building_ManagerStation ) )
            {
                return false;
            }

            if ( t.TryGetComp<Comp_ManagerStation>() == null )
            {
                return false;
            }

            if ( pawn.Dead ||
                 pawn.Downed ||
                 pawn.IsBurning() ||
                 t.IsBurning() )
            {
                return false;
            }

            if ( !pawn.CanReserveAndReach( t, PathEndMode, Danger.Some ) )
            {
                return false;
            }

            CompPowerTrader power = t.TryGetComp<CompPowerTrader>();
            if ( power != null &&
                 !power.PowerOn )
            {
                return false;
            }

            if ( Manager.Get.JobStack.NextJob != null )
            {
                return true;
            }

            return false;
        }
开发者ID:Fozie1,项目名称:Hardcore-SK,代码行数:49,代码来源:WorkGiver_Manager.cs

示例2: HasJobOnThing

        public override bool HasJobOnThing(Pawn pawn, Thing t)
        {
            var wc = t.TryGetComp<CompWaterContainer>();
            if (wc == null) { return false; }

            return wc.ManuallyFillable && wc.FreeSpaceLitres >= MinimumFill && t.IsSociallyProper(pawn);
        }
开发者ID:achan1989,项目名称:Dehydration,代码行数:7,代码来源:WorkGiver_HaulWater.cs

示例3: SpawnSetup

        public override void SpawnSetup()
        {
            base.SpawnSetup();
            vecNorth = Position + IntVec3.North.RotatedBy( Rotation );

            glower = GenSpawn.Spawn( ThingDef.Named( "RedistHeat_HeaterGlower" ), vecNorth );
            compGlower = glower.TryGetComp< CompGlower >();
            compGlower.Lit = false;
        }
开发者ID:ForsakenShell,项目名称:RimWorld-RedistHeat,代码行数:9,代码来源:Building_MediumHeater.cs

示例4: ShouldLinkWith

        public override bool ShouldLinkWith( IntVec3 c, Thing parent )
        {
            var compAir = parent.TryGetComp< CompAir >();
            if ( compAir == null )
                return false;

            var lowerFlag = AirNetGrid.NetAt( c, NetLayer.Lower ) != null && compAir.IsLayerOf( NetLayer.Lower );
            var upperFlag = AirNetGrid.NetAt( c, NetLayer.Upper ) != null && compAir.IsLayerOf( NetLayer.Upper );

            return c.InBounds() && (lowerFlag || upperFlag);
        }
开发者ID:ForsakenShell,项目名称:RimWorld-RedistHeat,代码行数:11,代码来源:Graphic_LinkedAirPipe.cs

示例5: CheckThing

        static bool CheckThing( Thing thing )
        {
            var p = thing.TryGetComp< CompPowerTrader >();

            // Only check for power traders
            // That are connected to a power network
            // Which aren't powered on
            // But want to be powered on
            return
                ( p != null )&&
                ( p.PowerNet != null )&&
                ( !p.PowerOn )&&
                ( p.DesirePowerOn );
        }
开发者ID:soulkata,项目名称:CommunityCoreLibrary,代码行数:14,代码来源:Alert_NeedBatteries.cs

示例6: JobOnThing

 public override Job JobOnThing( Pawn pawn, Thing t )
 {
     if( !pawn.CanReserveAndReach( t, PathEndMode.InteractionCell, pawn.NormalMaxDanger(), 1 ) )
     {
         return null;
     }
     var compPower = t.TryGetComp<CompPowerTrader>();
     if(
         ( compPower != null ) &&
         ( !compPower.PowerOn )
     )
     {   // Power is off on thing
         return null;
     }
     if( !Data.AllRoomMarkersOfColony().Any( marker => marker.AllowRemoteMonitoring ) )
     {   // No markers which can be remotely monitored
         return null;
     }
     return new Job( Data.JobDefOf.MonitorSecurityStation, t, pawn );
 }
开发者ID:ForsakenShell,项目名称:Es-Small-Mods,代码行数:20,代码来源:WorkGiver_Warden_MonitorSecurityStation.cs

示例7: Print

        public override void Print( SectionLayer layer, Thing parent )
        {
            base.Print( layer, parent );
            var compAir = parent.TryGetComp< CompAir >();
            if ( compAir == null )
                return;

            for ( var i = 0; i < 4; i++ )
            {
                var neighCell = parent.Position + GenAdj.CardinalDirections[i];
                if ( !neighCell.InBounds() )
                {
                    continue;
                }

                Material mat;
                if ( compAir.IsLayerOf( NetLayer.Lower ) )
                {
                    var lowerTransmitter = neighCell.GetAirTransmitter( NetLayer.Lower );
                    if ( lowerTransmitter != null && !lowerTransmitter.def.graphicData.Linked )
                    {
                        mat = LinkedDrawMatFrom(parent, neighCell);
                        Printer_Plane.PrintPlane(layer, neighCell.ToVector3ShiftedWithAltitude(parent.def.Altitude),
                            Vector2.one, mat, 0f);
                    }
                }

                else if ( compAir.IsLayerOf( NetLayer.Upper ) )
                {
                    var upperTransmitter = neighCell.GetAirTransmitter( NetLayer.Upper );
                    if ( upperTransmitter != null && !upperTransmitter.def.graphicData.Linked )
                    {
                        mat = LinkedDrawMatFrom(parent, neighCell);
                        Printer_Plane.PrintPlane(layer, neighCell.ToVector3ShiftedWithAltitude(parent.def.Altitude),
                            Vector2.one, mat, 0f);
                    }
                }
            }
        }
开发者ID:ForsakenShell,项目名称:RimWorld-RedistHeat,代码行数:39,代码来源:Graphic_LinkedAirPipe.cs

示例8: RegisterCharger

 public static void RegisterCharger(Thing charger)
 {
     if (charger != null && charger.TryGetComp<CompDroidCharger>() != null && !listerDroids.chargers.Contains(charger))
     {
         listerDroids.chargers.Add(charger);
     }
 }
开发者ID:ProfoundDarkness,项目名称:MD2-Source,代码行数:7,代码来源:ListerDroids.cs

示例9: HasJobOnThing

 // same as Research WorkGiver
 public override bool HasJobOnThing(Pawn pawn, Thing t)
 {
     return t.TryGetComp<CompResearcher>() != null && pawn.CanReserve(t);
 }
开发者ID:RWA-Team,项目名称:RimworldAscension,代码行数:5,代码来源:WorkGiver_DoBill_Research.cs

示例10: ShouldReserveWaterSource

 public static bool ShouldReserveWaterSource(Thing thing, float wantedLitres)
 {
     var wc = thing.TryGetComp<CompWaterContainer>();
     return (wc != null && wc.StoredLitres <= wantedLitres);
 }
开发者ID:achan1989,项目名称:Dehydration,代码行数:5,代码来源:WaterUtility.cs

示例11: SetGlowRadius

 public void SetGlowRadius(Thing caveWell, float glowradius)
 {
     CompGlower glowerComp = caveWell.TryGetComp<CompGlower>();
     if (glowerComp != null)
     {
         glowerComp.Props.glowRadius = glowradius;
         glowerComp.Props.overlightRadius = glowradius;
         Find.GlowGrid.MarkGlowGridDirty(caveWell.Position);
     }
 }
开发者ID:Rikiki123456789,项目名称:Rimworld,代码行数:10,代码来源:MapComponent_CaveWellLight.cs

示例12: JobOnThing

        public override Job JobOnThing(Pawn pawn, Thing t)
        {
            var toWc = t.TryGetComp<CompWaterContainer>();
            if (toWc == null)
            {
                Log.Error("Thing has no CompWaterContainer");
                return null;
            }

            IntVec3 waterNear = t.Position;

            Thing tool = WaterUtility.HaulingToolInInventory(pawn);
            if (tool == null)
            {
                tool = WaterUtility.NearestHaulingTool(pawn);
                if (tool == null)
                {
                    JobFailReason.Is("nothing to haul with");
                    return null;
                }
            }

            var toolWc = tool.TryGetComp<CompWaterContainer>();
            float collectLitres = toWc.FreeSpaceLitres - toolWc.StoredLitres;
            if (collectLitres > toolWc.FreeSpaceLitres)
            {
                collectLitres = toolWc.FreeSpaceLitres;
            }

            // If we already have enough water in the tool, can just haul it now.
            if (collectLitres <= 0)
            {
                return MakeHaulJob(TargetInfo.NullThing, t, tool);
            }
            // Otherwise we need to find more.
            else
            {
                // Wells, water carriers on the ground, etc.
                Predicate<Thing> validator = (Thing candidate) =>
                {
                    // Don't take water from the target Thing.
                    if (candidate.Equals(t)) { return false; }

                    var candidateWc = candidate.TryGetComp<CompWaterContainer>();
                    if (candidateWc == null) { return false; }

                    // Only take from containers with a lower priority.
                    if (candidateWc.ManuallyFillable && candidateWc.Priority >= toWc.Priority)
                    {
                        return false;
                    }
                    // Don't haul if the source has too little water.
                    return candidateWc.StoredLitres > MinimumFill;
                };
                var thingWater = WaterUtility.BestWaterSpawnedFor(pawn, collectLitres, validator, waterNear);

                // Rivers, lakes, other terrain-based water sources.
                var terrainWaterVec = WaterUtility.BestTerrainWaterFor(pawn, waterNear);

                // Pick the nearest of the water sources.
                if (thingWater != null && terrainWaterVec != null)
                {
                    float thingDist = (pawn.Position - thingWater.Position).LengthHorizontalSquared;
                    float terrainDist = (pawn.Position - terrainWaterVec.Value).LengthHorizontalSquared;
                    if (thingDist <= terrainDist)
                    {
                        terrainWaterVec = null;
                    }
                    else
                    {
                        thingWater = null;
                    }
                }

                if (thingWater != null)
                {
                    return MakeHaulJob(thingWater, t, tool);
                }
                else if (terrainWaterVec != null)
                {
                    return MakeHaulJob(terrainWaterVec.Value, t, tool);
                }
                else
                {
                    JobFailReason.Is("nowhere to haul from");
                    return null;
                }
            }
        }
开发者ID:achan1989,项目名称:Dehydration,代码行数:89,代码来源:WorkGiver_HaulWater.cs


注:本文中的Thing.TryGetComp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。