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


C# Object.DeleteTargetTeleporter方法代码示例

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


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

示例1: Use

        public void Use(IActor actor)
        {
            //set up needed Variables
            IGameServer Server = actor.State as IGameServer;
            IBiomeSystem currentSystem = ((IGameServer)actor.State).Biomes.GetSystems()[actor.InstanceID];

            //Permission Check, is the Player allowed to use the Teleporter?
            if (currentSystem.Nation != string.Empty && currentSystem.Nation != actor.Nation)
            {
                Server.ChatManager.SendActorMessage("You must be in the Nation that claimed this System to use the Teleporter.", actor);
                return;
            }

            //Set up ChunkDictionary so we can access the Chunks in System (We need the Chunk to Teleport the player to later)
            Dictionary<Point3D, IChunk> ChunkDictionary = SNScriptUtils._Utils.CreateChunkDictionary(currentSystem);

            //create offset List (the 4 Positions around our Activator where we expect at least one Teleporter)
            List<Point3D> offsetList = new List<Point3D>();
            offsetList.Add(new Point3D(0, -1, -1)); offsetList.Add(new Point3D(0, -1, 1));offsetList.Add(new Point3D(1, -1, 0)); offsetList.Add(new Point3D(-1, -1, 0));

            List<Object[,]> SpecialBlockList = null;
            Teleporter nearbyTeleporter = new Object() as Teleporter;

            //Get List of Teleporters in vicinity to the Activator based on offsetList (expected Teleporter locations)
            if (SNScriptUtils._Utils.FindCustomSpecialBlocksAround(this.Position, this.Chunk, offsetList, (uint)7100, ChunkDictionary, out SpecialBlockList))
            {
                //just take the first one found for now
                IChunk tmpChunk = SpecialBlockList[0][0, 1] as IChunk;
                Point3D TeleporterLocalPos = (Point3D)SpecialBlockList[0][0, 0];
                ISpecialBlock targetSpecialBlock = tmpChunk.GetSpecialBlocks().FirstOrDefault(item => (item is Teleporter) && ((item as Teleporter).Position == TeleporterLocalPos));
                nearbyTeleporter = targetSpecialBlock as Teleporter;

            }
            else
            {
                Server.ChatManager.SendActorMessage("There is no Teleporter around the Activator!", actor);
                return;
            }

            //Check if Player is standing on the Teleporter right now
            Point3D teleporterPadFakeGlobalPos = new Point3D(
                nearbyTeleporter.Position.X + (int)((IChunk)SpecialBlockList[0][0, 1]).Position.X,
                nearbyTeleporter.Position.Y + (int)((IChunk)SpecialBlockList[0][0, 1]).Position.Y + 1,
                nearbyTeleporter.Position.Z + (int)((IChunk)SpecialBlockList[0][0, 1]).Position.Z
                );

            Point3D actorPos = _Utils.GetActorFakeGlobalPos(actor, new Point3D(0, -1, 0));

            if (teleporterPadFakeGlobalPos != actorPos)
            {
                Server.ChatManager.SendActorMessage("You have to stand on the Teleporter platform to use the Teleporter!", actor);
                return;
            }

            //Get TargetTeleporterPos
            Point3D TargetTeleporterFakeGlobalPos = nearbyTeleporter.GetTargetTeleporter();

            //Check if TargetTeleporter exists
            //Get Chunk where the TargetTeleporter is in
            IChunk targetChunk = new Object() as IChunk;
            if (SNScriptUtils._Utils.getChunkObjFromFakeGlobalPos(TargetTeleporterFakeGlobalPos, ChunkDictionary, out targetChunk))
            {
                Point3D TargetTeleporterLocalPos = new Point3D(
                TargetTeleporterFakeGlobalPos.X - (int)targetChunk.Position.X,
                TargetTeleporterFakeGlobalPos.Y - (int)targetChunk.Position.Y,
                TargetTeleporterFakeGlobalPos.Z - (int)targetChunk.Position.Z
                );
                ushort targetBlockID = new ushort();
                targetBlockID = targetChunk.Blocks[targetChunk.GetBlockIndex(TargetTeleporterLocalPos.X, TargetTeleporterLocalPos.Y, TargetTeleporterLocalPos.Z)];
                if ((targetBlockID) == (ushort)7100) //TargetTeleporter still exists!
                {
                    ISpecialBlock targetSpecialBlock = targetChunk.GetSpecialBlocks().FirstOrDefault(item => (item is Teleporter) && ((item as Teleporter).Position == TargetTeleporterLocalPos));
                    Teleporter targetTeleporter = targetSpecialBlock as Teleporter;
                    //Teleport Player to TargetTeleporterPos + Offset (2.1 Blocks Up (Y)) or he'd get stuck in the Teleporter
                    double playerTeleportLocalPosY = (double)targetTeleporter.Position.Y + 2.1;
                    DoubleVector3 playerTeleportLocalPos = new DoubleVector3((double)targetTeleporter.Position.X, playerTeleportLocalPosY, (double)targetTeleporter.Position.Z);
                    actor.SetLocalPosition(targetChunk.ID, targetChunk.World, playerTeleportLocalPos);
                }
                else
                {
                    if (debug) { Console.WriteLine("TargetTeleporter does not exist anymore, other block ID found: " + ((int)targetBlockID).ToString()); };
                    if (debug) { Console.WriteLine("I've been looking at Position: " + TargetTeleporterLocalPos.ToString()); };

                    Server.ChatManager.SendActorMessage("The Teleporter you wanted to teleport to, does not exist anymore!", actor);
                    nearbyTeleporter.DeleteTargetTeleporter();
                    return;
                }
            }
            else
            {
                if (debug) { Console.WriteLine("Chunk does not exist! Pos: " + TargetTeleporterFakeGlobalPos.ToString()); };
                Server.ChatManager.SendActorMessage("The Teleporter you wanted to teleport to, does not exist anymore!", actor);
                nearbyTeleporter.DeleteTargetTeleporter();
                return;
            }
        }
开发者ID:Retoc,项目名称:MoreBlocks,代码行数:96,代码来源:TeleportActivator.cs


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