Example #1
0
 public GoToStorageAction(AIAgent agent, Storage storage)
     : base(agent)
 {
     BaseUtility = 5;
     Name = "Go to Starage";
     _storage = storage;
 }
        public override IEnumerator Execute()
        {
            _storage = StorageManager.Instance.GetStorageByItemContaining(_agent, _type);
            if (_storage == null)
            {
                Debug.LogError("Can't find a storage with an itemType: " + _type.ToString());
                Cancel();
                yield break;
            }

            //проверяем расстояние до нужного склада
            var sqrMagnitude = Vector3.SqrMagnitude(_agent.transform.position - _storage.transform.position);
            if (sqrMagnitude > 1)
            {
                var goToStorage = new GoToStorageAction(_agent, _storage);

                yield return _agent.StartCoroutine(goToStorage.Execute());

                yield return new WaitForSeconds(1);
            }
            var item = _storage.GetItem(_type);
            _agent.Character.BackPack.AddItem((PickableItem)item);

            Finished(true);
        }
 public PutDownItemToStorageAction(AIAgent agent, Storage place)
     : base(agent)
 {
     _storage = place;
     Name = "Putdown item";
     BaseUtility = 10;
     _backpack = _agent.Character.BackPack;
 }
Example #4
0
        public override IEnumerator Execute()
        {
            if (_storage == null)
                _storage = StorageManager.Instance.GetClosestStorage(_agent.transform.position);
            if (_storage == null)
            {
                Debug.LogError("There are no any available storages!");
                Cancel();
                yield break;
            }

            yield return new WaitForSeconds(1);

            var moveTo = new MoveToAction(_agent, _storage.transform.position);
            yield return _agent.StartCoroutine(moveTo.Execute());

            if (!_agent.Character.BackPack.IsEmpty)
            {
                var putDown = new PutDownItemToStorageAction(_agent, _storage);
                yield return _agent.StartCoroutine(putDown.Execute());
            }
            Finished(true);
        }