Ejemplo n.º 1
0
        public override bool AddItem(GameComponent component)
        {
            if (component.Tags.Count == 0)
            {
                return(false);
            }

            var resourceType = component.Tags[0];

            if (!IsAllowed(resourceType))
            {
                return(false);
            }

            bool worked = base.AddItem(component);

            HandleBoxes();

            if (Boxes.Count > 0)
            {
                TossMotion toss = new TossMotion(1.0f, 2.5f, component.LocalTransform,
                                                 Boxes[Boxes.Count - 1].LocalTransform.Translation + new Vector3(0.5f, 0.5f, 0.5f));
                component.GetRoot().GetComponent <Physics>().CollideMode = Physics.CollisionMode.None;
                component.AnimationQueue.Add(toss);
                toss.OnComplete += component.Die;
            }
            else
            {
                component.Die();
            }

            World.RecomputeCachedResourceState();
            return(worked);
        }
Ejemplo n.º 2
0
 public IEnumerable <Act.Status> SummonSkeleton(GameComponent grave)
 {
     if (grave.IsDead)
     {
         SetMessage("Failed to summon skeleton: grave is nonexistent.");
         yield return(Act.Status.Fail);
     }
     SummonSkeleton(grave.Position);
     grave.Die();
     yield return(Act.Status.Success);
 }
Ejemplo n.º 3
0
 public void GatherImmediately(GameComponent item, Inventory.RestockType restockType = Inventory.RestockType.None)
 {
     if (item is CoinPile coins)
     {
         Faction.AddMoney(coins.Money);
         item.Die();
     }
     else
     {
         Inventory.Pickup(item, restockType);
     }
 }
Ejemplo n.º 4
0
        public bool RemoveResourcesWithToss(ResourceAmount resources, Vector3 position, Zone Zone) // Todo: Kill this one.
        {
            if (!Zone.Resources.HasResource(resources))
            {
                return(false);
            }
            if (!(Zone is Stockpile))
            {
                return(false);
            }

            var stock = Zone as Stockpile;

            // Todo: Stockpile deals with it's own boxes.
            var resourceType = Library.GetResourceType(resources.Type);
            var num          = stock.Resources.RemoveMaxResources(resources, resources.Count);

            stock.HandleBoxes();

            foreach (var tag in resourceType.Tags)
            {
                if (PersistentData.CachedResourceTagCounts.ContainsKey(tag)) // Move cache into worldmanager...
                {
                    PersistentData.CachedResourceTagCounts[tag] -= num;
                    Trace.Assert(PersistentData.CachedResourceTagCounts[tag] >= 0);
                }
            }

            for (int i = 0; i < num; i++)
            {
                // Make a toss from the last crate to the agent.
                var startPosition = stock.Voxels.Count > 0 ? stock.Voxels.First().Center + new Vector3(0.0f, 1.0f, 0.0f) : Vector3.Zero;
                if (stock.Boxes.Count > 0)
                {
                    startPosition = stock.Boxes.Last().Position + MathFunctions.RandVector3Cube() * 0.5f;
                }

                GameComponent newEntity = EntityFactory.CreateEntity <GameComponent>(resources.Type + " Resource", startPosition);

                TossMotion toss = new TossMotion(1.0f + MathFunctions.Rand(0.1f, 0.2f), 2.5f + MathFunctions.Rand(-0.5f, 0.5f), newEntity.LocalTransform, position);
                if (newEntity.GetRoot().GetComponent <Physics>().HasValue(out var newPhysics))
                {
                    newPhysics.CollideMode = Physics.CollisionMode.None;
                }
                newEntity.AnimationQueue.Add(toss);
                toss.OnComplete += () => newEntity.Die();
            }

            RecomputeCachedVoxelstate();
            return(true);
        }