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


C# HashSet.FirstElement方法代码示例

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


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

示例1: Activate

 protected override bool Activate(HashSet<MySlimBlock> targets)
 {
     m_otherGrid = null;
     if (targets.Count > 0)
     {
         m_otherGrid = targets.FirstElement().CubeGrid;
     }
     if (Sync.IsServer)
     {             
         float coefficient = (MyShipGrinderConstants.GRINDER_COOLDOWN_IN_MILISECONDS * 0.001f) / targets.Count;             
         foreach (var block in targets)
         {
             m_otherGrid = block.CubeGrid;
             block.DecreaseMountLevel(MySession.Static.GrinderSpeedMultiplier * MyShipGrinderConstants.GRINDER_AMOUNT_PER_SECOND * coefficient, Inventory);
             block.MoveItemsFromConstructionStockpile(Inventory);
            
             
             if (block.IsFullyDismounted)
             {
                 if (block.FatBlock is IMyInventoryOwner) EmptyBlockInventories(block.FatBlock as IMyInventoryOwner);
                 block.SpawnConstructionStockpile();
                 block.CubeGrid.RazeBlock(block.Min);
             }
         }
         
     }
     m_wantsToShake = targets.Count != 0;
     return targets.Count != 0;
 }
开发者ID:austusross,项目名称:SpaceEngineers,代码行数:29,代码来源:MyShipGrinder.cs

示例2: Activate

        protected override bool Activate(HashSet<MySlimBlock> targets)
        {
            m_otherGrid = null;
            if (targets.Count > 0)
            {
                m_otherGrid = targets.FirstElement().CubeGrid;
            }
            if (Sync.IsServer)
            {             
                float coefficient = (MyShipGrinderConstants.GRINDER_COOLDOWN_IN_MILISECONDS * 0.001f) / targets.Count;             
                foreach (var block in targets)
                {
                    if ((MySession.Static.IsScenario || MySession.Static.Settings.ScenarioEditMode) && !block.CubeGrid.BlocksDestructionEnabled)
                        continue;

                    m_otherGrid = block.CubeGrid;

                    float damage = MySession.Static.GrinderSpeedMultiplier * MyShipGrinderConstants.GRINDER_AMOUNT_PER_SECOND * coefficient;
                    MyDamageInformation damageInfo = new MyDamageInformation(false, damage, MyDamageType.Grind, EntityId);

                    if (block.UseDamageSystem)
                        MyDamageSystem.Static.RaiseBeforeDamageApplied(block, ref damageInfo);

                    block.DecreaseMountLevel(damageInfo.Amount, Inventory);
                    block.MoveItemsFromConstructionStockpile(Inventory);

                    if (block.UseDamageSystem)
                        MyDamageSystem.Static.RaiseAfterDamageApplied(block, damageInfo);
                    
                    if (block.IsFullyDismounted)
                    {
                        if (block.FatBlock is IMyInventoryOwner) EmptyBlockInventories(block.FatBlock as IMyInventoryOwner);

                        if(block.UseDamageSystem)
                            MyDamageSystem.Static.RaiseDestroyed(block, damageInfo);

                        block.SpawnConstructionStockpile();
                        block.CubeGrid.RazeBlock(block.Min);
                    }
                }
                
            }
            m_wantsToShake = targets.Count != 0;
            return targets.Count != 0;
        }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:45,代码来源:MyShipGrinder.cs

示例3: Invoke


//.........这里部分代码省略.........
                    {
                        var position = new Vector3D(
                            double.Parse(match.Groups["X1"].Value, CultureInfo.InvariantCulture),
                            double.Parse(match.Groups["Y1"].Value, CultureInfo.InvariantCulture),
                            double.Parse(match.Groups["Z1"].Value, CultureInfo.InvariantCulture));

                        Support.MoveTo(player, position, safely, saveTeleportBack, noSafeLocationMsg);
                        return true;
                    }
                    if (gps1)
                    {
                        var position = new Vector3D(
                            double.Parse(match.Groups["GX1"].Value, CultureInfo.InvariantCulture),
                            double.Parse(match.Groups["GY1"].Value, CultureInfo.InvariantCulture),
                            double.Parse(match.Groups["GZ1"].Value, CultureInfo.InvariantCulture));

                        Support.MoveTo(player, position, safely, saveTeleportBack, noSafeLocationMsg);
                        return true;
                    }
                    if (character1)
                    {
                        if (Int32.TryParse(match.Groups["Character1"].Value.Substring(1), out index) && index > 0 && index <= CommandPlayerStatus.IdentityCache.Count)
                        {
                            IMyIdentity selectedPlayer = CommandPlayerStatus.IdentityCache[index - 1];
                            Support.MoveTo(steamId, player, selectedPlayer.Player(), safely, true, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            return true;
                        }
                    }
                    if (ship1)
                    {
                        if (Int32.TryParse(match.Groups["Ship1"].Value.Substring(1), out index) && index > 0 && index <= CommandListShips.ShipCache.Count)
                        {
                            var currentShipList = new HashSet<IMyEntity> { CommandListShips.ShipCache[index - 1] };
                            var targetShip = currentShipList.FirstElement();
                            Support.MoveTo(player, targetShip, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            return true;
                        }
                    }
                    if (asteroid1)
                    {
                        if (Int32.TryParse(match.Groups["Asteroid1"].Value.Substring(1), out index) && index > 0 && index <= CommandAsteroidsList.AsteroidCache.Count)
                        {
                            var currentAsteroidList = new HashSet<IMyEntity> { CommandAsteroidsList.AsteroidCache[index - 1] };
                            var asteroid = (IMyVoxelBase)currentAsteroidList.FirstElement();
                            Support.MoveTo(player, asteroid, safely, saveTeleportBack, noSafeLocationMsg, emptyTargetMsg, noSafeLocationMsg);
                            return true;
                        }
                    }
                    if (planet1)
                    {
                        if (Int32.TryParse(match.Groups["Planet1"].Value.Substring(1), out index) && index > 0 && index <= CommandPlanetsList.PlanetCache.Count)
                        {
                            var currentPlanetList = new HashSet<IMyEntity> { CommandPlanetsList.PlanetCache[index - 1] };
                            var planet = (IMyVoxelBase)currentPlanetList.FirstElement();
                            Support.MoveTo(player, planet, safely, saveTeleportBack, noSafeLocationMsg, emptyTargetMsg, noSafeLocationMsg);
                            return true;
                        }
                    }
                    if (word1)
                    {
                        var entityName = string.IsNullOrEmpty(match.Groups["Quote1"].Value) ? match.Groups["Word1"].Value : match.Groups["Quote1"].Value;

                        IMyPlayer foundPlayer;
                        IMyEntity foundEntity;
                        IMyGps foundGps;
                        if (Support.FindEntitiesNamed(entityName, true, true, true, true, true, out foundPlayer, out foundEntity, out foundGps))
开发者ID:Intueor,项目名称:Space-Engineers-Admin-script-mod,代码行数:67,代码来源:CommandTeleport.cs

示例4: FindEntitiesNamed

        public static bool FindEntitiesNamed(string entityName, bool findPlayers, bool findShips, bool findAsteroids, bool findPlanets, bool findGps,
            out IMyPlayer player, out IMyEntity entity, out IMyGps gps)
        {
            #region Find Exact name match first.

            var playerList = new List<IMyPlayer>();
            var shipList = new HashSet<IMyEntity>();
            var asteroidList = new List<IMyVoxelBase>();
            var planetList = new List<IMyVoxelBase>();
            var gpsList = new List<IMyGps>();

            if (findPlayers)
                MyAPIGateway.Players.GetPlayers(playerList, p => entityName == null || p.DisplayName.Equals(entityName, StringComparison.InvariantCultureIgnoreCase));

            if (findShips)
                shipList = FindShipsByName(entityName);

            if (findAsteroids)
                MyAPIGateway.Session.VoxelMaps.GetInstances(asteroidList, v => v is IMyVoxelMap && (entityName == null || v.StorageName.Equals(entityName, StringComparison.InvariantCultureIgnoreCase)));

            if (findPlanets)
                MyAPIGateway.Session.VoxelMaps.GetInstances(planetList, v => v is Sandbox.Game.Entities.MyPlanet && (entityName == null || v.StorageName.Equals(entityName, StringComparison.InvariantCultureIgnoreCase)));

            if (findGps)
                gpsList = MyAPIGateway.Session.GPS.GetGpsList(MyAPIGateway.Session.Player.IdentityId).Where(g => entityName == null || g.Name.Equals(entityName, StringComparison.InvariantCultureIgnoreCase)).ToList();

            // identify a unique ship or player by the name.
            if (playerList.Count > 1 || shipList.Count > 1 || asteroidList.Count > 1 || planetList.Count > 1 || gpsList.Count > 1)
            {
                // TODO: too many entities. hotlist or sublist?
                string msg = "Too many entries with that name.";

                if (findPlayers)
                    msg += string.Format("  Players: {0}", playerList.Count);
                if (findShips)
                    msg += string.Format("  Ships: {0}", shipList.Count);
                if (findAsteroids)
                    msg += string.Format("  Asteroids: {0}", asteroidList.Count);
                if (findPlayers)
                    msg += string.Format("  Planets: {0}", planetList.Count);
                if (findGps)
                    msg += string.Format("  Gps: {0}", gpsList.Count);

                MyAPIGateway.Utilities.ShowMessage("Cannot match", msg);

                player = null;
                entity = null;
                gps = null;
                return false;
            }

            if (playerList.Count == 1 && shipList.Count == 0 && asteroidList.Count == 0 && planetList.Count == 0 && gpsList.Count == 0)
            {
                player = playerList[0];
                entity = null;
                gps = null;
                return true;
            }

            if (playerList.Count == 0 && shipList.Count == 1 && asteroidList.Count == 0 && planetList.Count == 0 && gpsList.Count == 0)
            {
                player = null;
                entity = shipList.FirstElement();
                gps = null;
                return true;
            }

            if (playerList.Count == 0 && shipList.Count == 0 && asteroidList.Count == 1 && planetList.Count == 0 && gpsList.Count == 0)
            {
                player = null;
                entity = asteroidList[0];
                gps = null;
                return true;
            }

            if (playerList.Count == 0 && shipList.Count == 0 && asteroidList.Count == 0 && planetList.Count == 1 && gpsList.Count == 0)
            {
                player = null;
                entity = planetList[0];
                gps = null;
                return true;
            }

            if (playerList.Count == 0 && shipList.Count == 0 && asteroidList.Count == 0 && planetList.Count == 0 && gpsList.Count == 1)
            {
                player = null;
                entity = null;
                gps = gpsList[0];
                return true;
            }

            #endregion

            #region find partial name matches.

            playerList.Clear();
            shipList.Clear();
            asteroidList.Clear();
            planetList.Clear();
            gpsList.Clear();
//.........这里部分代码省略.........
开发者ID:Intueor,项目名称:Space-Engineers-Admin-script-mod,代码行数:101,代码来源:Support.cs

示例5: Invoke

        public override bool Invoke(string messageText)
        {
            var match = Regex.Match(messageText, teleportPattern, RegexOptions.IgnoreCase);

            if (match.Success)
            {
                var ship1 = !string.IsNullOrEmpty(match.Groups["Ship1"].Value);
                var ship2 = !string.IsNullOrEmpty(match.Groups["Ship2"].Value);
                var player1 = !string.IsNullOrEmpty(match.Groups["Player1"].Value);
                var player2 = !string.IsNullOrEmpty(match.Groups["Player2"].Value);
                var pos1 = !string.IsNullOrEmpty(match.Groups["X1"].Value);
                var pos2 = !string.IsNullOrEmpty(match.Groups["X2"].Value);
                var word1 = !string.IsNullOrEmpty(match.Groups["Quote1"].Value) || !string.IsNullOrEmpty(match.Groups["Word1"].Value);
                var word2 = !string.IsNullOrEmpty(match.Groups["Quote2"].Value) || !string.IsNullOrEmpty(match.Groups["Word2"].Value);
                var gps1 = !string.IsNullOrEmpty(match.Groups["GX1"].Value);
                var gps2 = !string.IsNullOrEmpty(match.Groups["GX2"].Value);
                var currentPosition = MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.GetPosition();

                if (!ship2 && !player2 && !pos2 && !word2)
                {
                    // move this player or the ship this player is in.
                    var player = MyAPIGateway.Session.Player;

                    if (pos1)
                    {
                        var position = new Vector3D(
                            double.Parse(match.Groups["X1"].Value, CultureInfo.InvariantCulture),
                            double.Parse(match.Groups["Y1"].Value, CultureInfo.InvariantCulture),
                            double.Parse(match.Groups["Z1"].Value, CultureInfo.InvariantCulture));

                        MovePlayerPilotToPosition(player, position);
                        CommandTeleportBack.SaveTeleportInHistory(currentPosition);
                        return true;
                    }
                    if (gps1)
                    {
                        var position = new Vector3D(
                            double.Parse(match.Groups["GX1"].Value, CultureInfo.InvariantCulture),
                            double.Parse(match.Groups["GY1"].Value, CultureInfo.InvariantCulture),
                            double.Parse(match.Groups["GZ1"].Value, CultureInfo.InvariantCulture));

                        MovePlayerPilotToPosition(player, position);
                        CommandTeleportBack.SaveTeleportInHistory(currentPosition);
                        return true;
                    }
                    if (player1)
                    {
                        int index;
                        if (Int32.TryParse(match.Groups["Player1"].Value.Substring(1), out index) && index > 0 && index <= CommandPlayerStatus.IdentityCache.Count)
                        {
                            IMyIdentity selectedPlayer = CommandPlayerStatus.IdentityCache[index - 1];
                            MovePlayerPilotToPlayer(player, selectedPlayer, true);
                            CommandTeleportBack.SaveTeleportInHistory(currentPosition);
                            return true;
                        }
                    }
                    if (ship1)
                    {
                        int index;
                        if (Int32.TryParse(match.Groups["Ship1"].Value.Substring(1), out index) && index > 0 && index <= CommandListShips.ShipCache.Count)
                        {
                            var currentShipList = new HashSet<IMyEntity> { CommandListShips.ShipCache[index - 1] };
                            var ship = currentShipList.FirstElement();
                            MovePlayerPilotToShip(player, ship);
                            CommandTeleportBack.SaveTeleportInHistory(currentPosition);
                            return true;
                        }
                    }
                    if (word1)
                    {
                        var entityName = string.IsNullOrEmpty(match.Groups["Quote1"].Value) ? match.Groups["Word1"].Value : match.Groups["Quote1"].Value;

                        var players = new List<IMyPlayer>();
                        MyAPIGateway.Players.GetPlayers(players, p => p.DisplayName.Equals(entityName, StringComparison.InvariantCultureIgnoreCase));
                        var currentShipList = Support.FindShipsByName(entityName);

                        // identify a unique ship or player by the name.
                        if (players.Count == 0 && currentShipList.Count == 0)
                        {
                            MyAPIGateway.Utilities.ShowMessage("Teleport failed", "Cannot find the player or ship of name '{0}'", entityName);
                            return true;
                        }

                        if (players.Count == 0 && currentShipList.Count == 1)
                        {
                            MovePlayerPilotToShip(player, currentShipList.FirstElement());
                            CommandTeleportBack.SaveTeleportInHistory(currentPosition);
                            return true;
                        }

                        if (players.Count == 1 && currentShipList.Count == 0)
                        {
                            MovePlayerPilotToPlayer(player, players[0], true);
                            CommandTeleportBack.SaveTeleportInHistory(currentPosition);
                            return true;
                        }

                        // TODO: too many entities. hotlist or sublist?

                        MyAPIGateway.Utilities.ShowMessage("Players", "{0}", players.Count);
//.........这里部分代码省略.........
开发者ID:zrisher,项目名称:Space-Engineers-Admin-script-mod,代码行数:101,代码来源:CommandTeleport.cs


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