Beispiel #1
0
    void Update()
    {
        switch (_state)
        {
        case CitizenState.WALK_IN:
            WalkIn();
            if (_walkInEnded)
            {
                _state = CitizenState.STAND;
                Stand();
            }
            break;

        case CitizenState.STAND:
            if (_standEnded)
            {
                _state = CitizenState.WALK_OUT;
            }
            break;

        case CitizenState.WALK_OUT:
            WalkOut();
            if (_walkOutEnded)
            {
                _endCitizenEvent.Citizen = gameObject;
                EventManager.Instance.OnEvent(this, _endCitizenEvent);
            }
            break;

        default:
            break;
        }
    }
Beispiel #2
0
    public void Init(Vector3 startPosition, Vector3 standPosition, Vector3 endPosition, CitizenDirection direction, float speed, float standingTime, int row)
    {
        _state        = CitizenState.WALK_IN;
        _walkInEnded  = false;
        _standEnded   = false;
        _walkOutEnded = false;

        transform.position = _startPosition = startPosition;
        _standPosition     = standPosition;
        _endPosition       = endPosition;

        _speed        = speed;
        _standingTime = standingTime;
        Vector3 newScale = transform.localScale;

        if (direction == CitizenDirection.LEFT)
        {
            _direction = Vector3.left;
            newScale.x = -0.85f;
        }
        else
        {
            _direction = Vector3.right;
            newScale.x = 0.85f;
        }
        transform.localScale = newScale;
        _row = row;

        _anim = GetComponent <Animator>();
        _anim.SetBool("stand", false);
        _anim.SetBool("happy", false);
        _anim.SetBool("sad", false);
    }
	public override void Awake() {
		base.Awake();
		
		Cost = new Resources {
			Stone = 0
		};

		Behavior = BehaviorType.StoneMiner;
		CurrentAction = CitizenState.Idle;
		navAgent = GetComponent<NavMeshAgent>();
		navAgent.stoppingDistance = 0;
	}
	//TODO make more of these

	void StoneMinerBehavior() {
		if (CurrentAction == CitizenState.Idle) {
			if (AITimer != AITime) {
				return;
			}
			
			GetComponent<Animator>().SetBool("working", false);

			if (Load < MaxLoad) {
				CurrentTarget = FindClosestChildOf<StoneMine>(GameObject.Find("Resources").transform);

				if (CurrentTarget == null) {
					if (Load > 0) {
						if (FindClosestChildOf<Storehouse>(Parent.transform) != null) {
							CurrentTarget = FindClosestChildOf<Storehouse>(Parent.transform);
							CurrentAction = CitizenState.Depositing;
						}
						return;
					}
				} else {
					navAgent.destination = CurrentTarget.transform.position;
					navAgent.stoppingDistance = CurrentTarget.GetComponent<BasicObject>().InteractRange;
					CurrentAction = CitizenState.Seeking;
				}
			} else {
				GetComponent<Animator>().SetBool("working", false);
				CurrentTarget = FindClosestChildOf<Storehouse>(Parent.transform);

				if (CurrentTarget != null) {
					navAgent.destination = CurrentTarget.transform.position;
					navAgent.stoppingDistance = CurrentTarget.GetComponent<BasicObject>().InteractRange;
					CurrentAction = CitizenState.Depositing;
				}
			}
		} else if (CurrentAction == CitizenState.Seeking) {
			if (CurrentTarget != null) {
				if (navAgent.remainingDistance < CurrentTarget.GetComponent<BasicObject>().InteractRange) {
					CurrentAction = CitizenState.Working;
					GetComponent<Animator>().SetBool("working", true);
				}
			} else {
				CurrentAction = CitizenState.Idle;
			}
		} else if (CurrentAction == CitizenState.Working) {
			if (CurrentTarget == null) {
				CurrentAction = CitizenState.Idle;
				return;
			}

			transform.LookAt(new Vector3(CurrentTarget.transform.position.x, transform.position.y, CurrentTarget.transform.position.z));

			if (CollectionTimer >= CollectionDelay) {
				CollectionTimer = 0;

				if (Load + 1 <= MaxLoad) {
					CurrentTarget.GetComponent<Resource>().Stock--;
					Load++;
				} else {
					CurrentAction = CitizenState.Idle;
				}
			}

			CollectionTimer++;
		} else if (CurrentAction == CitizenState.Depositing) {
			if (CurrentTarget != null) {
				if (navAgent.remainingDistance < CurrentTarget.GetComponent<BasicObject>().InteractRange) {
					Parent.GetComponent<Player>().OwnedResources.Stone += Load;
					Load = 0;
					CurrentAction = CitizenState.Idle;
				}
			} else {
				CurrentAction = CitizenState.Idle;
			}
		}
	}