Esempio n. 1
0
    private Pathfinding.ObjectPathData ChooseNextObject(UIGrid room)
    {
        List <Pathfinding.ObjectPathData> nearObjects = room.GetAllPathesFrom(m_CurrentPos);

        Pathfinding.ObjectPathData nextObj = null;

        foreach (Pathfinding.ObjectPathData obj in nearObjects)
        {
            if (!m_ItemVisited.Contains(obj.path[obj.path.Count - 1]))
            {
                // Si on a pas d'objet ou si on a trouvé une porte et que le nouvel objet n'est pas une porte
                if (nextObj == null ||
                    (nextObj.objectFound == UIItem.eType.Door &&
                     obj.objectFound != UIItem.eType.Door))
                {
                    nextObj = obj;
                }

                if (nextObj.objectFound != UIItem.eType.Door)
                {
                    break;
                }
            }
        }

        return(nextObj);
    }
Esempio n. 2
0
    public IEnumerator ExploreRoom(UIGrid room, WaveConfig waveConfig)
    {
        if (GameManager.IsGroupExploring())
        {
            yield break;
        }

        Debug.Log("Door: " + waveConfig.m_Door.ToString());

        m_CurrentWaveConfig = waveConfig;
        Vector2Int start = Vector2Int.zero;

        switch (waveConfig.m_Door)
        {
        case RoomConfig.eDir.UP:
            start = new Vector2Int(5, room.m_RoomConfig.GetUp());
            break;

        case RoomConfig.eDir.DOWN:
            start = new Vector2Int(5, room.m_RoomConfig.GetDown());
            break;

        case RoomConfig.eDir.LEFT:
            start = new Vector2Int(room.m_RoomConfig.GetLeft(), 5);
            break;

        case RoomConfig.eDir.RIGHT:
            start = new Vector2Int(room.m_RoomConfig.GetRight(), 5);
            break;

        default:
            start = new Vector2Int(room.m_RoomConfig.GetLeft(), 5);
            break;
        }

        GameManager.StartGroupExploring();

        m_ReachedExit = false;
        m_ItemVisited = new List <Vector2Int>();

        m_Happiness = m_HeroesConfig.StartHappiness;

        m_CurrentPos = start;

        float wRatio = room.getCellW();
        float hRatio = room.getCellH();

        gameObject.transform.position = room.transform.position + new Vector3(start.x * wRatio, start.y * hRatio);

        yield return(ScaleUp());

        while (!m_ReachedExit)
        {
            m_ItemVisited.Add(m_CurrentPos);

            Pathfinding.ObjectPathData nextObj = null;

            //int currentWaitStep = 0;

            //while (currentWaitStep < m_HeroesConfig.m_MaxWaitingStep && nextObj == null)
            //while (nextObj == null)
            {
                nextObj = ChooseNextObject(room);

                if (nextObj == null)
                {
                    if (speechBubble)
                    {
                        StartCoroutine(speechBubble.SaySomething(SpeechBubble.EReactionType.NoWay, m_HeroesConfig.m_TimeWhenLost));
                        yield return(new WaitForSeconds(m_HeroesConfig.m_TimeWhenLost));
                    }

                    /*
                     * if (speechBubble)
                     * {
                     *  if (currentWaitStep == 0)
                     *  {
                     *      StartCoroutine(speechBubble.SaySomething(SpeechBubble.EReactionType.NoWay + currentWaitStep, m_HeroesConfig.m_MaxWaitingTimes / m_HeroesConfig.m_MaxWaitingStep));
                     *      yield return new WaitForSeconds(0.4f);
                     *  }
                     *
                     *  StartCoroutine(speechBubble.SaySomething(SpeechBubble.EReactionType.Timer1 + currentWaitStep, m_HeroesConfig.m_MaxWaitingTimes / m_HeroesConfig.m_MaxWaitingStep));
                     * }
                     * yield return new WaitForSeconds(m_HeroesConfig.m_MaxWaitingTimes / m_HeroesConfig.m_MaxWaitingStep);
                     * currentWaitStep++;
                     */
                }
            }

            if (nextObj != null)
            {
                yield return(Move(nextObj.path, room));

                if (nextObj.objectFound == UIItem.eType.Door)
                {
                    m_ReachedExit = true;
                }
                else
                {
                    yield return(UseObject(room, m_CurrentPos));

                    for (int i = 0; i < waveConfig.m_Goal.Length; i++)
                    {
                        if (nextObj.objectFound == waveConfig.m_Goal[i] && !waveConfig.m_GoalAccomplished[i])
                        {
                            waveConfig.m_GoalAccomplished[i] = true;
                            break;
                        }
                    }

                    /*
                     * foreach (UIItem.eType objective in waveConfig.m_Goal)
                     * {
                     * } */
                }
            }
            else
            {
                // No path found
                m_Happiness  += m_HeroesConfig.HappinessCannotLeave;
                m_ReachedExit = true;
            }
        }

        yield return(ScaleDown());

        GameManager.StopGroupExploring();
        float happiness = GetPercentageHappiness();

        Debug.Log("Exited with happiness: " + happiness);

        GameManager.m_Happiness  = happiness;
        GameManager.m_GoldReward = 60 + (int)(100 * happiness);

        bool allObjectiveCompleted = true;

        for (int i = 0; i < waveConfig.m_Goal.Length; i++)
        {
            if (waveConfig.m_Goal[i] != UIItem.eType.None && !waveConfig.m_GoalAccomplished[i])
            {
                allObjectiveCompleted = false;
            }
        }

        if (allObjectiveCompleted)
        {
            GameManager.m_GoldReward += waveConfig.m_Reward;
        }
    }