예제 #1
0
        public bool Pickup(GameComponent item, RestockType restockType)
        {
            if (item == null || item.IsDead)
            {
                return(false);
            }

            if (item is ResourceEntity)
            {
                var entity = item as ResourceEntity;
                Resources.Add(new InventoryItem()
                {
                    MarkedForRestock = restockType == RestockType.RestockResource,
                    MarkedForUse     = restockType != RestockType.RestockResource,
                    Resource         = entity.Resource
                });
            }
            else
            {
                throw new InvalidOperationException();
            }

            item.SetFlag(Flag.Active, false);
            var toss = new BodyTossMotion(0.5f + MathFunctions.Rand(0.05f, 0.08f), 1.0f, item.GlobalTransform, Parent);

            item.AnimationQueue.Add(toss);
            toss.OnComplete += () => item.GetRoot().Delete();

            return(true);
        }
예제 #2
0
        public bool Pickup(Body item, RestockType restockType)
        {
            if (item == null || item.IsDead)
            {
                return(false);
            }

            if (item is ResourceEntity)
            {
                ResourceEntity entity = item as ResourceEntity;
                for (int i = 0; i < entity.Resource.NumResources; i++)
                {
                    Resources.Add(new InventoryItem()
                    {
                        MarkedForRestock = restockType == RestockType.RestockResource,
                        MarkedForUse     = restockType != RestockType.RestockResource,
                        Resource         = entity.Resource.ResourceType
                    });
                }
            }
            else
            {
                Resources.Add(new InventoryItem()
                {
                    MarkedForRestock = restockType == RestockType.RestockResource,
                    MarkedForUse     = restockType != RestockType.RestockResource,
                    Resource         = item.Tags[0]
                });
            }

            item.SetFlag(Flag.Active, false);
            BodyTossMotion toss = new BodyTossMotion(0.5f + MathFunctions.Rand(0.05f, 0.08f),
                                                     1.0f, item.GlobalTransform, Parent as Body);

            item.SetUpdateRateRecursive(1);
            item.AnimationQueue.Add(toss);
            toss.OnComplete += () => item.GetRoot().Delete();

            return(true);
        }