public void DropAll() { //var resourceCounts = Aggregate(); var parentBody = GetRoot(); var myBox = GetBoundingBox(); var box = parentBody == null?GetBoundingBox() : new BoundingBox(myBox.Min - myBox.Center() + parentBody.Position, myBox.Max - myBox.Center() + parentBody.Position); //var aggregatedResources = resourceCounts.Select(c => new ResourceTypeAmount(c.Key, c.Value.Count)); //var piles = EntityFactory.CreateResourcePiles(aggregatedResources, box).ToList(); var piles = EntityFactory.CreateResourcePiles(Manager, Resources.Select(r => r.Resource), box).ToList(); if (Attacker != null && !Attacker.IsDead) { foreach (var item in piles) { Attacker.Creature.Gather(item, TaskPriority.Eventually); } } Resources.Clear(); if (GetRoot().GetComponent <Flammable>().HasValue(out var flames) && flames.Heat >= flames.Flashpoint) { foreach (var item in piles) { if (item.GetRoot().GetComponent <Flammable>().HasValue(out var itemFlames)) { itemFlames.Heat = flames.Heat; } } } }
public void DropAll() { var resourceCounts = new Dictionary <ResourceType, int>(); foreach (var resource in Resources) { if (!resourceCounts.ContainsKey(resource.Resource)) { resourceCounts[resource.Resource] = 0; } resourceCounts[resource.Resource]++; } var parentBody = GetRoot() as Body; var myBox = GetBoundingBox(); var box = parentBody == null?GetBoundingBox() : new BoundingBox(myBox.Min - myBox.Center() + parentBody.Position, myBox.Max - myBox.Center() + parentBody.Position); var aggregatedResources = resourceCounts.Select(c => new ResourceAmount(c.Key, c.Value)); var piles = EntityFactory.CreateResourcePiles(aggregatedResources, box).ToList(); if (Attacker != null && !Attacker.IsDead) { foreach (var item in piles) { Attacker.Creature.Gather(item); } } //else // foreach (var item in piles) // World.Master.TaskManager.AddTask(new GatherItemTask(item)); Resources.Clear(); }
public override void Destroy() { var box = GetBoundingBox(); box.Min += Vector3.Up; box.Max += Vector3.Up; foreach (var resource in EntityFactory.CreateResourcePiles(World.ComponentManager, Resources.Enumerate(), box)) { } foreach (var resource in Resources.Enumerate()) { if (Library.GetResourceType(resource.TypeName).HasValue(out var resourceType)) { foreach (var tag in resourceType.Tags) { if (World.PersistentData.CachedResourceTagCounts.ContainsKey(tag)) // Todo: Move to World Manager. { World.PersistentData.CachedResourceTagCounts[tag] -= 1; System.Diagnostics.Trace.Assert(World.PersistentData.CachedResourceTagCounts[tag] >= 0); } } } } World.RecomputeCachedVoxelstate(); base.Destroy(); }
public override void Destroy() { var box = GetBoundingBox(); box.Min += Vector3.Up; box.Max += Vector3.Up; foreach (var resource in EntityFactory.CreateResourcePiles(Resources.Resources.Values, box)) { } if (Faction != null) { Faction.Stockpiles.Remove(this); } base.Destroy(); }