Example #1
0
        public static List <Entity> SpawnLobbyNPC(GameLevel level, string gameName, PlayerLocation spawnLocation)
        {
            //Ensure this NPC can be seen
            PlayerNPC npc = new PlayerNPC("", level, spawnLocation, GameUtil.ShowGameList, gameName)
            {
                Scale         = 1.5,
                KnownPosition = spawnLocation
            };

            PlayerLocation changeGameLocation = (PlayerLocation)spawnLocation.Clone();

            changeGameLocation.Y += 3.1f;

            Hologram changeGameHologram = new Hologram("§d§lChange Game", level, changeGameLocation);

            PlayerLocation clickHereLocation = (PlayerLocation)spawnLocation.Clone();

            clickHereLocation.Y += 2.8f;

            Hologram clickHereHologram = new Hologram("§e(Click Here)", level, clickHereLocation);

            SkyCoreAPI.Instance.AddPendingTask(() =>
            {
                npc.SpawnEntity();

                changeGameHologram.SpawnEntity();

                clickHereHologram.SpawnEntity();
            });

            return(new List <Entity> {
                npc, changeGameHologram, clickHereHologram
            });
        }
Example #2
0
        public void Test1(Player player)
        {
            List <Pig> pigs = new List <Pig>();

            for (int i = 0; i < 10; i++)
            {
                Pig pig = new Pig(player.Level);
                pig.KnownPosition = (PlayerLocation)player.KnownPosition.Clone();
                pig.SpawnEntity();
                pigs.Add(pig);
            }
            player.SendMessage("Spawned pigs");

            Thread.Sleep(4000);

            PlayerLocation loc = (PlayerLocation)player.KnownPosition.Clone();

            loc.Y = loc.Y + 10;
            loc.X = loc.X + 10;
            loc.Z = loc.Z + 10;

            player.SendMessage("Moved pigs");

            Thread.Sleep(4000);

            foreach (var pig in pigs)
            {
                pig.KnownPosition   = (PlayerLocation)loc.Clone();
                pig.LastUpdatedTime = DateTime.UtcNow;
            }

            player.SendMessage("Moved ALL pigs");
        }
Example #3
0
        private bool IsOnGround(PlayerLocation position)
        {
            PlayerLocation pos = (PlayerLocation)position.Clone();

            pos.Y -= 0.1f;
            Block block = Level.GetBlock(new BlockCoordinates(pos));

            return(block.Id != 0);            // Should probably test for solid
        }
Example #4
0
 private PlayerLocation GetSafeLocation(Level level, PlayerLocation location)
 {
     while (!(level.GetBlock(location) is Air))
     {
         location = location.Clone() as PlayerLocation;
         location.Y++;
     }
     return(location);
 }
Example #5
0
        public static void SpawnHubNPC(GameLevel level, string npcName, PlayerLocation spawnLocation, string command)
        {
            NPCSpawnTask spawnTask = (gameLevel) =>
            {
                try
                {
                    if (String.IsNullOrEmpty(npcName))
                    {
                        Console.WriteLine("§c§l(!) §r§cInvalid NPC text. /hologram <text>");
                        return;
                    }

                    npcName = npcName.Replace("_", " ").Replace("&", "§");

                    if (npcName.Equals("\"\""))
                    {
                        npcName = "";
                    }

                    string     gameName = command;
                    onInteract action   = null;
                    if (!String.IsNullOrEmpty(command))
                    {
                        if (command.StartsWith("GID:"))
                        {
                            gameName = command.Split(':')[1];

                            switch (gameName)
                            {
                            case "murder":
                            case "build-battle":
                            {
                                action = player =>
                                {
                                    //Freeze the players movement
                                    player.Freeze(true);
                                    RunnableTask.RunTaskLater(() => ExternalGameHandler.AddPlayer(player, gameName), 200);
                                };
                                break;
                            }
                            }
                        }
                    }

                    if (gameName.Equals(command))
                    {
                        SkyUtil.log($"Unknown game command '{command}'");
                        return;
                    }

                    //Ensure this NPC can be seen
                    PlayerNPC npc;

                    /*if (action != null)
                     * {
                     *      npc = new PlayerNPC("§a(Punch to play)", gameLevel, spawnLocation, action, gameName) { Scale = 1.5 };
                     * }
                     * else
                     * {
                     *      npc = new PlayerNPC("§e(Coming Soon)", gameLevel, spawnLocation, null, gameName) { Scale = 1.5 };
                     * }*/
                    npc = new PlayerNPC("", gameLevel, spawnLocation, action, gameName)
                    {
                        Scale = 1.5
                    };

                    SkyCoreAPI.Instance.AddPendingTask(() =>
                    {
                        npc.KnownPosition = spawnLocation;
                        //npc.Width = 0D;
                        //npc.Height = 1.0D;
                        npc.SpawnEntity();
                    });

                    {
                        PlayerLocation playerCountLocation = (PlayerLocation)spawnLocation.Clone();

                        //Spawn a hologram with player counts
                        PlayerCountHologram hologram = new PlayerCountHologram(npcName, gameLevel, playerCountLocation, gameName);

                        SkyCoreAPI.Instance.AddPendingTask(() => hologram.SpawnEntity());
                    }

                    {
                        PlayerLocation gameNameLocation = (PlayerLocation)spawnLocation.Clone();
                        gameNameLocation.Y += 3.1f;

                        Hologram gameNameHologram = new Hologram(npcName, gameLevel, gameNameLocation);

                        SkyCoreAPI.Instance.AddPendingTask(() => gameNameHologram.SpawnEntity());
                    }

                    Console.WriteLine($"§e§l(!) §r§eSpawned NPC with text '{npcName}§r'");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            };

            if (String.IsNullOrWhiteSpace(command))
            {
                SkyUtil.log("Found null command as key. Using npc game name instead.");
                command = npcName;
            }

            GameNPCs.Add(command, spawnTask);

            if (level != null)
            {
                spawnTask.Invoke(level);
            }
        }