Ejemplo n.º 1
0
 void resetVariables()
 {
     trapPos = new Vector3(0, 0, 0);
     myState = executionState.GRID_CHOOSING;
     trapSelectionPanel.SetActive(false);
     trapToBePlaced = null;
     timer          = 1.0f;
 }
Ejemplo n.º 2
0
    void Start()
    {
        renderer = GetComponent<SpriteRenderer>();


        _state = GetComponent<VillagerState>();
        _actions = GetComponent<VillagerActions>();
        _inventory = GetComponent<VillagerInventory>();
        _storeRef =  transform.parent.gameObject.transform.parent.gameObject.GetComponent<VillageGenerator>().StoreHouse.GetComponent<storeManagement>();
        currentState = executionState.Free;
        if (_state.workplace == null)
            _state.workplace = transform.parent.gameObject.transform.parent.gameObject.GetComponent<VillageGenerator>().Crop;
        _workplace = _state.workplace.transform.position;
        if (_state.wareHouse == null)
            _state.wareHouse = transform.parent.gameObject.transform.parent.gameObject.GetComponent<VillageGenerator>().Warehouse;
        _warehouse = _state.wareHouse.transform.position;
        currentWorkingState = workingState.standby;
        _dangerTimer = 0;
    }
Ejemplo n.º 3
0
 public void setToChooseTrap()
 {
     myState = executionState.TRAP_CHOOSING;             //Change state
     trapSelectionPanel.SetActive(true);                 //activate panel to choose trap
 }
Ejemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        float hungerVal = _state.getHunger();
        float thirstVal = _state.getThirst();
        float sicknessVal = _state.getSickness();
        float happinessVal = _state.getHappiness();
        float fearVal = _state.getFear();
        
            if (hungerVal == 10 || thirstVal == 10 || sicknessVal == 10 || happinessVal == 10 || fearVal == 10)
                _dangerTimer = _dangerTime;
            else
                _dangerTimer = 0;
        
        if(_dangerTimer!=0) {
            _dangerTimer -= Time.deltaTime;
            if (_dangerTimer <= 0)
                currentState = executionState.Danger;
        }

        // Animate sprite.
        if (currentState == executionState.ExecutingAction || currentWorkingState == workingState.goingToWarehouse ||
            currentWorkingState == workingState.goingToWorkplace)
        {
            passedTime += Time.deltaTime;
            if (passedTime > 0.1)
            {
                renderer.sprite = WalkSprites[Mathf.RoundToInt(animIncrement++%WalkSprites.Length)];
                passedTime = 0;
            }
        }
        else
        {
            passedTime = 0;
            animIncrement = 0;
            renderer.sprite = WalkSprites[0];
        }

        if (currentState == executionState.Free)
        {


            if (thirstVal >= 5)
            {
                if (!_actions.drink())
                    _actions.searchForDrink();
            }
            else {
                if (hungerVal >= 5)
                {
                    if (!_actions.eat())
                        _actions.searchForFood();
                }
                else
                    if (sicknessVal >= 5) {
                    if (!_actions.takeDrug())
                        _actions.searchForMedicine();
                }
                else { 
                    
                        switch (currentWorkingState)
                        {
                            case workingState.standby:
                                _actions.goToWorkplace(_workplace);
                                break;
                            case workingState.goingToWorkplace:
                                _actions.checkIfArrivedToWorkplace();
                                break;
                            case workingState.goingToWarehouse:
                                _actions.checkIfArrivedToWarehouse();
                                break;
                            case workingState.gatheringResources:
                                _actions.gatherResourcesAndGoToWarehouse(_warehouse);
                                break;
                            case workingState.leavingResources:
                                _actions.leaveResourcesAndGoStandby();
                                break;
                        }
                    }

            }
        }
        else
            if (currentState == executionState.Danger)
            _actions.die();




    }
Ejemplo n.º 5
0
 // Use this for initialization
 public void setState(executionState state)
 {
     currentState = state;
 }