예제 #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
            });
        }
예제 #2
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);
            }
        }