Пример #1
0
 void Start()
 {
     _villagerStateRef = GetComponent<VillagerState>();
     _villagerInventoryRef = GetComponent<VillagerInventory>();
     _brainRef = GetComponent<VillagerBrain>();
     _storeRef = transform.parent.gameObject.transform.parent.gameObject.GetComponent<VillageGenerator>().StoreHouse;
     _waterSourceRef = transform.parent.gameObject.transform.parent.gameObject.GetComponent<VillageGenerator>().Well;
     _navMeshComp = GetComponent<NavMeshAgent>();
     _maxHunger = _villagerStateRef.getMaxHungerTime();
     _maxThirst = _villagerStateRef.getMaxThirstTime();
     _maxSickness = _villagerStateRef.getMaxSicknessTime();
     _maxFear = _villagerStateRef.getMaxFearTime();
 }
Пример #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;
    }
Пример #3
0
    public void HandlePlayerCollision(Player p)
    {
        if (!isInteracting)
        {

            if (this.isColliding(p.swordCollision))
            {
                this._direction = (Direction)((int)(p.CurrentDirection + 2) % Enum.GetValues(typeof(Direction)).Length);
                this.State = VillagerState.IDLE;
                PlayAnim(true);
                xAcc = 0;
                yAcc = 0;
                xVel = 0;
                yVel = 0;
                scaleX = _direction == Direction.RIGHT ? -1 : 1;
                isInteracting = true;
                this.indicator.Show();
            }
        }
        else
        {
            if (C.getKeyDown(C.JUMP_KEY))
            {
                world.ui.dialogue.ShowMessage(new List<string>(dialogue));
            }
            if (!this.isColliding(p.swordCollision))
            {
                stateCount = 0;
                this.indicator.Hide();
                isInteracting = false;
            }
        }
    }
Пример #4
0
    public override void OnFixedUpdate()
    {
        if (walks && !isInteracting && stateCount > minState)
        {
            if (RXRandom.Float() < .3f)
            {
                switch (State)
                {
                    case VillagerState.IDLE:
                        if (RXRandom.Float() < .5f)
                        {
                            //left or right
                            if (RXRandom.Float() < .5f)
                                xAcc = moveSpeed;
                            else
                                xAcc = -moveSpeed;
                        }
                        else
                        {
                            //up or down
                            if (RXRandom.Float() < .5f)
                                yAcc = moveSpeed;
                            else
                                yAcc = -moveSpeed;
                        }
                        State = VillagerState.MOVING;
                        break;
                    case VillagerState.MOVING:
                        if (RXRandom.Float() < .3f)
                        {
                            //stop
                            State = VillagerState.IDLE;
                            PlayAnim(true);
                            xAcc = 0;
                            yAcc = 0;

                        }
                        else
                        {
                            //Just turn
                            if (RXRandom.Float() < .5f)
                            {
                                if (RXRandom.Float() < .5f)
                                    xAcc = moveSpeed;
                                else
                                    xAcc = -moveSpeed;
                                yAcc = 0;
                            }
                            else
                            {
                                if (RXRandom.Float() < .5f)
                                    yAcc = moveSpeed;
                                else
                                    yAcc = -moveSpeed;
                                xAcc = 0;
                            }
                            stateCount = 0;
                        }
                        break;
                }
            }
        }
        base.OnFixedUpdate();
        this.indicator.scaleX = scaleX;
        if (xAcc == 0)
            xVel *= .8f;
        if (yAcc == 0)
            yVel *= .8f;
        PlayAnim();
    }
Пример #5
0
 public void Idle()
 {
     state = VillagerState.Idle;
 }