Exemplo n.º 1
0
        public IEnumerator OnRoundCoroutine()
        {
            CrunchPlayer.GetSelf().SendBroadcast($"First wave will start in 30 seconds!");
            yield return(new WaitForSeconds(30f));

            while (CrunchySdk.IsInMission)
            {
                MelonLogger.Log($"Enemies alive: {CrunchEnemy.LivingEnemies}");
                if (CrunchEnemy.LivingEnemies == 0)
                {
                    foreach (var gameObject in GameObject.FindObjectsOfType <GameObject>())
                    {
                        if (gameObject.name.Contains("Alien"))
                        {
                            if (!gameObject.TryGetComponent(typeof(CrunchEnemy), out var ignored))
                            {
                                Object.Destroy(gameObject);
                            }
                        }
                    }

                    //New Round
                    Round++;
                    ClearDebris();
                    int enemyCount = 2 * Round;
                    if (Round >= 10)
                    {
                        enemyCount += 3;
                    }
                    MelonLogger.Log("[1]");
                    var walkableAreas = CrunchySdk.Map.slots.Values.Select(x => x.room).ToList();
                    MelonLogger.Log(walkableAreas.ToString());
                    MelonLogger.Log("[2]");
                    CrunchPlayer.GetSelf().CurrentRoom?.neighbors?.ForEach(neighbor =>
                    {
                        if (neighbor.room == null)
                        {
                            return;
                        }
                        walkableAreas.Remove(neighbor.room);
                    });
                    MelonLogger.Log("[3]");
                    var playerLoc   = CrunchPlayer.GetSelf().Position;
                    var spawnPoints = walkableAreas.SelectMany(x =>
                    {
                        try
                        {
                            return(x?.GetSpawnPoints() ?? new List <Vector3>());
                        }
                        catch (Exception e)
                        {
                            return(new List <Vector3>());
                        }
                    }).Where(x => Vector3.Distance(playerLoc, x) >= 25).ToArray();
                    MelonLogger.Log("[4]");
                    CrunchEnemy.Spawn(spawnPoints, enemyCount);
                    MelonLogger.Log("[5]");
                    CrunchPlayer.AllPlayers.ForEach(x => x.Health = x.MaxHealth);
                    CrunchPlayer.GetSelf().SendBroadcast($"Round {Round-1} completed!\nNext Wave incoming...");
                }
                else
                {
                    try
                    {
                        var playerPositions = CrunchPlayer.AllPlayers.ToDictionary(x => x, x => x.Position);
                        foreach (var crunchEnemy in CrunchEnemy.Enemies)
                        {
                            var pos         = crunchEnemy.Position;
                            var orderedDict = playerPositions.ToDictionary(
                                e => Vector3.Distance(e.Value, pos),
                                e => e.Key,
                                new FloatComparer());
                            crunchEnemy.Hunt(orderedDict.ToArray()[0].Value.transform);
                        }
                    }
                    catch (Exception e)
                    {
                        MelonLogger.LogError(e.ToString());
                    }
                }
                yield return(new WaitForSeconds(1));
            }
        }
Exemplo n.º 2
0
        public void Create()
        {
            if (_createLock)
            {
                return;
            }
            if (UI != null)
            {
                if (!UI.activeSelf || !UI.activeInHierarchy)
                {
                    Object.Destroy(UI);
                }
            }
            _createLock = true;
            var playerTransform = Player.instance.leftHand.transform;

            UI = Object.Instantiate(CrunchySdk.instance.uiPrefab, playerTransform.TransformPoint(0.0f, 0.0f, 0.5f),
                                    playerTransform.rotation);
            UI.AddComponent <UIPointerAttach>();
            var tabs               = GameObject.Find($"{UI.name}/Root/Tabs");
            var tabGamemodes       = GameObject.Find($"{UI.name}/Root/Tabs/Gamemodes");
            var tabActions         = GameObject.Find($"{UI.name}/Root/Tabs/Actions");
            var tabSettings        = GameObject.Find($"{UI.name}/Root/Tabs/Settings");
            var tabAbout           = GameObject.Find($"{UI.name}/Root/Tabs/About");
            var tabGamemodesButton = GameObject.Find($"{UI.name}/Root/Navigation/Gamemodes");
            var tabActionsButton   = GameObject.Find($"{UI.name}/Root/Navigation/Actions");
            var tabSettingsButton  = GameObject.Find($"{UI.name}/Root/Navigation/Settings");
            var tabAboutButton     = GameObject.Find($"{UI.name}/Root/Navigation/About");
            var tabController      = tabs.AddComponent <TabController>();

            tabController.tabs    = new [] { tabGamemodes, tabActions, tabSettings, tabAbout };
            tabController.buttons = new[] { tabGamemodesButton, tabActionsButton, tabSettingsButton, tabAboutButton };

            var showoff = GameObject.Find($"{UI.name}/Root/Tabs/Gamemodes/Showoff Button");

            showoff.AddComponent <ResetSelfButton>();
            showoff.GetComponent <Button>().onClick.AddListener(
                () => { MelonLogger.Log("Showoff"); });
            var zombies = GameObject.Find($"{UI.name}/Root/Tabs/Gamemodes/Zombies Button");

            zombies.AddComponent <ResetSelfButton>();
            zombies.GetComponent <Button>().onClick.AddListener(
                () =>
            {
                ZombiesModule module = new ZombiesModule();
                module.RegisterListener();
                CrunchySdk.instance.QuickJoin();
            });
            var heal = GameObject.Find($"{UI.name}/Root/Tabs/Actions/Heal Button");

            heal.AddComponent <ResetSelfButton>();
            heal.GetComponent <Button>().onClick
            .AddListener(
                () =>
            {
                var player    = CrunchPlayer.GetSelf();
                player.Health = player.MaxHealth;
                player.SendBroadcast("Your health has been restored");
            });
            var quickplay = GameObject.Find($"{UI.name}/Root/Tabs/Actions/Quickplay Button");

            quickplay.AddComponent <ResetSelfButton>();
            quickplay.GetComponent <Button>().onClick
            .AddListener(() => CrunchySdk.instance.QuickJoin());
            var euler = UI.transform.rotation.eulerAngles;

            euler.x += 45;
            UI.transform.rotation = Quaternion.Euler(euler);
            UI.transform.SetParent(playerTransform);
            UI.SetActive(false);
            _createLock = false;
        }