示例#1
0
    /// <summary>
    /// Chooses a point of interest by type
    /// </summary>
    /// <param name="poi"></param>
    void ChoosePointOfInterest(POIType poi)
    {
        List <PointOfInterest> pointsOfSelectedType = new List <PointOfInterest>();

        for (int i = 0; i < points.Length; i++)
        {
            if (points[i].navPointOfInterest == poi && !points[i].occupied)
            {
                pointsOfSelectedType.Add(points[i]);
            }
        }

        if (currentPOI != null)
        {
            currentPOI.occupied = false;
        }

        if (pointsOfSelectedType.Count == 0)
        {
            state = BrainStates.Lingering;
            return;
        }

        currentPOI = pointsOfSelectedType[Random.Range(0, pointsOfSelectedType.Count)];
        agent.SetDestination(currentPOI.transform.position);
        currentPOI.occupied = true;
        state = BrainStates.Moving;
    }
示例#2
0
        private void DrawPlayControl()
        {
            Event e          = Event.current;
            var   buttonRect = new Rect(81, 0, 80, 80);

            if (e.isMouse && buttonRect.Contains(e.mousePosition))
            {
                if (e.type == EventType.mouseDown)
                {
                    _inPlayMode = !_inPlayMode;
                    _onGui      = true;

                    if (_inPlayMode)
                    {
                        PreparePlayer();
                    }
                    else
                    {
                        QuitPlayMode();
                        BrainState = BrainStates.NavigateMode;
                    }
                }
            }

            GUI.Button(buttonRect, _inPlayMode ? "STOP" : "PLAY");
        }
示例#3
0
    public void StopTrading()
    {
        currentTrade = null;

        if (wantedItems.Count == 0)
        {
            ChoosePointOfInterest(POIType.Door);
        }
        else
        {
            state = BrainStates.Lingering;
        }
    }
示例#4
0
        private void DrawMenu()
        {
            Event e = Event.current;

            for (int i = 0, n = _menuStrings.Length; i < n; i++)
            {
                var buttonRect = new Rect(10, 100 + i * 80, 150, 75);

                if (e.isMouse && buttonRect.Contains(e.mousePosition))
                {
                    if (e.type == EventType.mouseDown)
                    {
                        _onGui     = true;
                        BrainState = (BrainStates)i;
                    }
                    else
                    {
                        _onGui = false;
                    }
                }

                GUI.Button(buttonRect, _menuStrings[i]);
            }
        }
示例#5
0
    void Update()
    {
        switch (state)
        {
        case BrainStates.Browsing:

            break;

        case BrainStates.Lingering:

            lingerTimer += Time.deltaTime;

            //Debug.Log(CurrentStation);

            if (CurrentStation != null && lingerTimer <= lingerTime)
            {
                RotateTowards(CurrentStation.transform);

                if (currentStation.GetType() == typeof(ItemDisplay))
                {
                    ItemDisplay display = (ItemDisplay)currentStation;

                    if (display.displayedItem != null)
                    {
                        for (int i = 0; i < wantedItems.Count; i++)
                        {
                            if (wantedItems[i] == display.displayedItem.itemCode)
                            {
                                hero.PickupItem(currentStation.Interact());
                                lingerTimer = 0f;
                                ChoosePointOfInterest(POIType.Trade);

                                return;
                            }
                        }
                    }
                }
            }

            if (lingerTimer >= lingerTime)
            {
                lingerTimer = 0f;
                if (Random.Range(1, 11) == 1)
                {
                    ChoosePointOfInterest(POIType.Door);
                }
                else
                {
                    ChoosePointOfInterest(POIType.Item);
                }
            }

            break;

        case BrainStates.Moving:
            if (Vector3.Distance(transform.position, agent.destination) <= 1.1f)
            {
                switch (currentPOI.navPointOfInterest)
                {
                case POIType.Door:
                    state = BrainStates.Exiting;
                    break;

                case POIType.Item:
                    state      = BrainStates.Lingering;
                    lingerTime = Random.Range(1f, 5f);
                    break;

                case POIType.Trade:
                    state = BrainStates.WaitingToTrade;
                    break;
                }
            }
            break;

        case BrainStates.WaitingToTrade:

            //Debug.Log(string.Format("{0} | {1} | {2} ", currentStation, currentStation.GetType(), currentTrade == null));

            if (currentStation != null && currentStation.GetType() == typeof(TradeTable) && currentTrade == null)
            {
                TradeTable table = (TradeTable)currentStation;
                //TODO: create actual gold offer logic
                currentTrade = table.CreateTrade(hero.carriedItem, 2, hero);
            }
            break;

        case BrainStates.Exiting:
            ExitShop();
            break;

        case BrainStates.Questing:
            hero.currentQuest.RunQuest();

            //For now just remove the quest
            //TODO: hold on to quest to tell player about?
            EnterShop();
            break;
        }
    }
示例#6
0
 public void ExitShop()
 {
     state = BrainStates.Questing;
 }
示例#7
0
 public void EnterShop()
 {
     //TEMP, TODO: more logic to come when game loop is more built up
     state = BrainStates.Lingering;
 }