Esempio n. 1
0
        /// <summary>Try to continue harvesting. Called each update</summary>
        /// <returns>1: is harvesting over ? 2: did harvesting suceed ?</returns>
        protected override (bool over, bool succeed) Execute(IBoatActionTarget target, Inventory inventory)
        {
            var resource = (Resource)target;

            var availableSpace = inventory.AvailableSpace(resource.Type);
            var quantity       = 0;

            if (availableSpace > 0)
            {
                quantity = resource.Harvest(availableSpace < Quantity ? availableSpace : Quantity);
                inventory.Add(resource.Type, quantity);
            }

            return(over : availableSpace == quantity || resource.Quantity == 0,
                   succeed : quantity > 0);
        }
Esempio n. 2
0
        /// <summary>Try to continue an action. Called each update</summary>
        /// <returns>Action over ?</returns>
        public bool TryExecute(IBoatActionTarget target, Inventory inventory)
        {
            if (Vector3.Distance(transform.position, target.transform.position) < _range &&
                _lastExecute + _actionFrequency * target.ActionFrequencyMultiplier < Time.timeSinceLevelLoad)
            {
                _lastExecute = Time.timeSinceLevelLoad;
                (bool over, bool succeed) = Execute(target, inventory);
                if (succeed)
                {
                    NotifyBoatAction?.Invoke(this, new BoatActionArg(target.transform.position, _actionFrequency, _lastExecute, _quantity));
                }

                return(over);
            }
            return(false);
        }
Esempio n. 3
0
        /// <summary>Try to continue building. Called each update</summary>
        /// <returns>is building action over ? inventory empty/missmatch or structure finished</returns>
        protected override (bool over, bool succeed) Execute(IBoatActionTarget target, Inventory inventory)
        {
            var blueprint = (Blueprint)target;

            var missingItems = blueprint.MissingItems.ToList();
            var missingItem  = missingItems.FirstOrDefault(x => inventory.Items.ContainsKey(x.Type));

            if (missingItem.Quantity > 0)
            {
                int inventoryQuantity = inventory.Items[missingItem.Type].Quantity;
                int buildQuantity     = missingItem.Quantity <= inventoryQuantity ? missingItem.Quantity : inventoryQuantity;
                buildQuantity = buildQuantity <= Quantity ? buildQuantity : Quantity;
                inventory.Pick(missingItem.Type, buildQuantity);
                blueprint.Build(missingItem.Type, buildQuantity);
                return(over : missingItems.Count == 1 && missingItem.Quantity == buildQuantity,
                       succeed : true);
            }
            return(over : true,
                   succeed : false);
        }
Esempio n. 4
0
 protected abstract (bool over, bool succeed) Execute(IBoatActionTarget target, Inventory inventory);