Ejemplo n.º 1
0
        public void RefreshDebug()
        {
            if (!debugVisibleObject)
            {
                return;
            }
            Vector3 p = astar.maze.GetGroundPosition(coord), u = Vector3.up * .125f;

            debugVisibleObject.transform.position = p + u;
            bool   isVisible = visMap[coord];
            string text      = (_f < 0 && _g < 0)
                                ? coord.ToString()
                                : $"{coord}\nf:{_f}\ng:{_g}\n{_edge}";

            UiText.SetText(debugVisibleObject, text);
            UiText.SetColor(debugVisibleObject, isVisible ? Color.white : Color.black);
        }
Ejemplo n.º 2
0
    public void GoalCheck(GameObject inventoryObject)
    {
        if (idolCreator.idols == null)
        {
            return;
        }
        int unclaimedIdolCount = idolCreator.CountUnclaimedIdols();

        //Show.Log("checking..."+unclaimedIdolCount);
        if (unclaimedIdolCount > 0)
        {
            return;
        }
        nextLevelButton.SetActive(true);
        timer.Pause();
        LevelState lvl = levels.Find(l => l.stage == maze.stage);

        if (lvl == null)
        {
            throw new Exception("level not properly initialized");
        }
        int  t          = timer.GetDuration();
        bool firstTime  = lvl.bestTime == 0;
        bool betterTime = t < lvl.bestTime;

        if (firstTime || betterTime)
        {
            lvl.bestTime = t;
        }
        if (betterTime)
        {
            UiText.SetColor(timer.gameObject, Color.green);
        }
        else if (!firstTime)
        {
            UiText.SetColor(timer.gameObject, Color.gray);
        }
        bestTimeLabel.text = "best time: " + GameTimer.TimingToString(lvl.bestTime, true);
        bestTimeLabel.gameObject.SetActive(true);
    }
Ejemplo n.º 3
0
    public void LevelGenerate(LevelState lvl)
    {
        Team      team      = Global.GetComponent <Team>();
        EventBind checkGoal = new EventBind(this, nameof(GoalCheck));

        if (lvl == null)
        {
            lvl                  = new LevelState();
            lvl.stage            = maze.stage;
            lvl.seed             = random.Seed;
            lvl.idolsDistributed = idolCreator.idolsDistributed;
            if (inventory.GetItems() != null)
            {
                lvl.idolInventory = CodeConvert.Stringify(inventory.GetItems().ConvertAll(go => {
                    Idol t = go.GetComponent <Idol>(); return(t ? t.intMetaData : null);
                }));
            }
            else
            {
                lvl.idolInventory = "";
            }
            lvl.variables = CodeConvert.Stringify(mainDictionaryKeeper.Dictionary);
            lvl.allies    = CodeConvert.Stringify(team.members.ConvertAll(m => npcCreator.npcs.FindIndex(n => n.gameObject == m)));
            levels.Add(lvl);
        }
        else
        {
            Tokenizer tokenizer = new Tokenizer();
            // check if level is valid
            if (levels.IndexOf(lvl) < 0)
            {
                throw new Exception("TODO validate the level plz!");
            }
            // set allies
            int[] allies; CodeConvert.TryParse(lvl.allies, out allies, null, tokenizer);
            team.Clear();
            team.AddMember(firstPlayer);
            for (int i = 0; i < allies.Length; ++i)
            {
                int index = allies[i];
                if (index < 0)
                {
                    continue;
                }
                team.AddMember(npcCreator.npcs[index].gameObject);
            }
            // clear existing idols
            idolCreator.Clear();
            // reset inventory to match start state
            inventory.RemoveAllItems();
            int[][] invToLoad;
            CodeConvert.TryParse(lvl.idolInventory, out invToLoad, null, tokenizer);
            //Debug.Log(Show.Stringify(invToLoad,false));
            Vector3 playerLoc = Global.GetComponent <CharacterControlManager>().localPlayerInterfaceObject.transform.position;
            for (int i = 0; i < invToLoad.Length; ++i)
            {
                int[] t = invToLoad[i];
                if (t == null || t.Length == 0)
                {
                    continue;
                }
                GameObject idol = idolCreator.CreateIdol(t[0], t[1], checkGoal);
                idol.transform.position = playerLoc + Vector3.forward;
                inventory.AddItem(idol);
            }
            // set stage
            maze.stage = lvl.stage;
            // set seed
            random.Seed = lvl.seed;
            // set variables
            HashTable_stringobject d = mainDictionaryKeeper.Dictionary;
            CodeConvert.TryParse(lvl.variables, out d, null, tokenizer);
            // set
        }
        MarkTouchdown.ClearMarkers();
        clickToMove.ClearAllWaypoints();
        seedLabel.text = "level " + maze.stage + "." + Convert.ToBase64String(BitConverter.GetBytes(random.Seed));
        maze.Generate(random);
        Discovery.ResetAll();
        idolCreator.Generate(checkGoal);
        int len = Mathf.Min(maze.floorTileNeighborHistogram[2], idolCreator.idolMaterials.Count);

        npcCreator.GenerateMore(len);
        if (testingPickups)
        {
            idolCreator.GenerateMoreIdols(checkGoal);
        }
        // TODO maze should have a list of unfilled tiles sorted by weight
        for (int i = 0; i < npcCreator.npcs.Count; ++i)
        {
            maze.PlaceObjectOverTile(npcCreator.npcs[i].transform, maze.floorTiles[maze.floorTileNeighborHistogram[1] + i]);
        }
        team.AddMember(firstPlayer);
        maze.PlaceObjectOverTile(team.members[0].transform, maze.floorTiles[maze.floorTiles.Count - 1]);
        Vector3 pos = team.members[0].transform.position;

        for (int i = 0; i < team.members.Count; ++i)
        {
            team.members[i].transform.position = pos;
            CharacterMove cm = team.members[i].GetComponent <CharacterMove>();
            if (cm != null)
            {
                cm.SetAutoMovePosition(pos);
                cm.MoveForwardMovement = 0;
                cm.StrafeRightMovement = 0;
            }
        }
        UiText.SetColor(timer.gameObject, Color.white);
        timer.Start();
        GoalCheck(null);
        nextLevelButton.SetActive(false);
        bestTimeLabel.gameObject.SetActive(false);
    }