Example #1
0
        private bool Collect(CollectBehavior<T> objectWithSmth, Hero hero)
        {
            if (objectWithSmth.CurrentCount <= 0)
                return false;

            int smthToBagCount = objectWithSmth.CurrentCount < objectWithSmth.PerCollectCount
                ? objectWithSmth.CurrentCount
                : objectWithSmth.PerCollectCount;

            var addedToBagCount = 0;

            for (int i = 0; i < smthToBagCount; i++)
            {
                var objToBag = objectWithSmth.GetSmth();
                if (!hero.AddToBag(objToBag))
                    break;
                
                addedToBagCount++;
            }

            var newCurrent = objectWithSmth.CurrentCount - addedToBagCount;

            objectWithSmth.CurrentCount = Math.Max(0, newCurrent);;

            return objectWithSmth.CurrentCount > 0 && addedToBagCount == smthToBagCount && !hero.Bag.IsFull;
        }
Example #2
0
        public void Act()
        {
            if (TreeBehavior == null || TreeBehavior.CurrentCount <= 0)
            {
                _mobileObject.StateEvent.FireEvent();
                return;
            }

            if (_maxRestingTicks <= _shakingTicks)
            {
                TreeBehavior.CurrentCount = TreeBehavior.CurrentCount - 1;
                var fruit    = TreeBehavior.GetSmth();
                var destCell = Game.Map.GetNearestRandomEmptyCellFromPoint(_mobileObject.Position);

                if (destCell != null)
                {
                    Game.Map.SetObjectFromCell(destCell, fruit as FixedObject);
                }

                _mobileObject.StateEvent.FireEvent();
                return;
            }

            _shakingTicks++;
        }