public bool Remove(IEnumerable <Quantitiy <Resource.ResourceTags> > amount, RestockType type) { foreach (var quantity in amount) { for (int i = 0; i < quantity.NumResources; i++) { int kRemove = -1; for (int k = 0; k < Resources.Count; k++) { if (type == RestockType.None && Resources[k].MarkedForRestock) { continue; } else if (type == RestockType.RestockResource && !Resources[k].MarkedForRestock) { continue; } if (!ResourceLibrary.GetResourceByName(Resources[k].Resource) .Tags.Contains(quantity.ResourceType)) { continue; } kRemove = k; break; } if (kRemove < 0) { return(false); } Resources.RemoveAt(kRemove); } } return(true); }
public bool Remove(IEnumerable <ResourceAmount> resourceAmount, RestockType type) { foreach (var quantity in resourceAmount) { for (int i = 0; i < quantity.NumResources; i++) { int kRemove = -1; for (int k = 0; k < Resources.Count; k++) { if (type == RestockType.None && Resources[k].MarkedForRestock) { continue; } else if (type == RestockType.RestockResource && !Resources[k].MarkedForRestock) { continue; } if (Resources[k].Resource != quantity.ResourceType) { continue; } kRemove = k; break; } if (kRemove < 0) { return(false); } Resources.RemoveAt(kRemove); } } return(true); }
public bool Remove(ResourceAmount resourceAmount, RestockType type) { return(Remove(new List <ResourceAmount>() { resourceAmount }, type)); }
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); }
public bool Remove(ResourceAmount resourceAmount, RestockType type) { for (int i = 0; i < resourceAmount.Count; i++) { var kRemove = -1; for (int k = 0; k < Resources.Count; k++) { if (type == RestockType.None && Resources[k].MarkedForRestock) { continue; } else if (type == RestockType.RestockResource && !Resources[k].MarkedForRestock) { continue; } if (Resources[k].Resource != resourceAmount.Type) { continue; } kRemove = k; break; } if (kRemove < 0) { return(false); } Resources.RemoveAt(kRemove); } return(true); }
public void AddResource(Resource tradeGood, RestockType type = RestockType.RestockResource) { Resources.Add(new InventoryItem() { Resource = tradeGood, MarkedForRestock = type == RestockType.RestockResource, MarkedForUse = type != RestockType.RestockResource }); }
public bool Remove(IEnumerable <Resource> Resources, RestockType RestockType) { foreach (var resource in Resources) { if (!Remove(resource, RestockType)) { return(false); } } return(true); }
public GameComponent RemoveAndCreate(Resource Resource, RestockType RestockType) // todo: Kill { var pos = GetRoot().Position; if (!Remove(Resource, RestockType)) { return(null); } return(Manager.RootComponent.AddChild(new ResourceEntity(Manager, Resource, pos + MathFunctions.RandVector3Cube() * 0.5f))); }
public bool Remove(IEnumerable <ResourceAmount> resourceAmount, RestockType type) { foreach (var quantity in resourceAmount) { if (!Remove(quantity, type)) { return(false); } } return(true); }
public void AddResource(ResourceAmount tradeGood, RestockType type = RestockType.RestockResource) { for (int i = 0; i < tradeGood.Count; i++) { Resources.Add(new InventoryItem() { Resource = tradeGood.Type, MarkedForRestock = type == RestockType.RestockResource, MarkedForUse = type != RestockType.RestockResource }); } }
public bool Pickup(ResourceAmount resourceAmount, RestockType restock) { for (int i = 0; i < resourceAmount.NumResources; i++) { Resources.Add(new InventoryItem() { Resource = resourceAmount.ResourceType, MarkedForRestock = restock == RestockType.RestockResource }); } return(true); }
public bool Remove(Resource Resource, RestockType RestockType) { var index = Resources.FindIndex(r => Object.ReferenceEquals(r.Resource, Resource)); if (index >= 0) { Resources.RemoveAt(index); return(true); } #if DEBUG throw new InvalidOperationException("Attempted to remove item from inventory, but it wasn't in inventory."); #else return(false); #endif }
public List <Body> RemoveAndCreate(ResourceAmount resources, RestockType type) { List <Body> toReturn = new List <Body>(); if (!Remove(resources.CloneResource(), type)) { return(toReturn); } for (int i = 0; i < resources.NumResources; i++) { Body newEntity = EntityFactory.CreateEntity <Body>(resources.ResourceType + " Resource", GlobalTransform.Translation + MathFunctions.RandVector3Cube() * 0.5f); toReturn.Add(newEntity); } return(toReturn); }
public bool RemoveAndCreateWithToss(Resource Resource, Vector3 pos, RestockType type) // Todo: Kill { var body = RemoveAndCreate(Resource, type); if (body != null) { var toss = new TossMotion(1.0f, 2.5f, body.LocalTransform, pos); if (body.GetRoot().GetComponent <Physics>().HasValue(out var physics)) { physics.CollideMode = Physics.CollisionMode.None; } body.AnimationQueue.Add(toss); toss.OnComplete += body.Delete; return(true); } return(false); }
public List <Body> RemoveAndCreate(ResourceAmount resources, RestockType type) { var parentBody = GetRoot() as Body; var pos = parentBody == null ? GlobalTransform.Translation : parentBody.Position; List <Body> toReturn = new List <Body>(); if (!Remove(resources.CloneResource(), type)) { return(toReturn); } for (int i = 0; i < resources.NumResources; i++) { Body newEntity = EntityFactory.CreateEntity <Body>(resources.ResourceType + " Resource", pos + MathFunctions.RandVector3Cube() * 0.5f); toReturn.Add(newEntity); } return(toReturn); }
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); }
public List <Resource> EnumerateResources(ResourceTagAmount quantitiy, RestockType type = RestockType.RestockResource) { return(Resources .Where(r => { switch (type) { case RestockType.Any: return true; case RestockType.None: return !r.MarkedForRestock; case RestockType.RestockResource: return r.MarkedForRestock; } return false; }) .Where(r => r.Resource.ResourceType.HasValue(out var res) && res.Tags.Contains(quantitiy.Tag)) .Select(r => r.Resource) .ToList()); }
public Resource Find(String OfType, RestockType RestockType) { return(Resources .Where(r => { switch (RestockType) { case RestockType.Any: return true; case RestockType.None: return !r.MarkedForRestock; case RestockType.RestockResource: return r.MarkedForRestock; } return false; }) .Where(r => r.Resource.TypeName == OfType) .Select(r => r.Resource) .FirstOrDefault()); }
public void AddResource(ResourceAmount tradeGood, RestockType type = RestockType.RestockResource) { Pickup(tradeGood, type); }
public List <ResourceAmount> GetResources(Quantitiy <Resource.ResourceTags> quantitiy, RestockType type = RestockType.RestockResource) { return((from resource in Resources where ResourceLibrary.GetResourceByName(resource.Resource).Tags.Contains(quantitiy.ResourceType) && ((type == RestockType.RestockResource && resource.MarkedForRestock) || (type == RestockType.None && !resource.MarkedForRestock) || (type == RestockType.Any)) select new ResourceAmount(resource.Resource)).ToList()); }
public bool RemoveAndCreateWithToss(List <ResourceAmount> resources, Vector3 pos, RestockType type) { bool createdAny = false; foreach (var resource in resources) { List <Body> things = RemoveAndCreate(resource, type); foreach (var body in things) { TossMotion toss = new TossMotion(1.0f, 2.5f, body.LocalTransform, pos); body.GetRoot().GetComponent <Physics>().CollideMode = Physics.CollisionMode.None; body.AnimationQueue.Add(toss); toss.OnComplete += body.Delete; createdAny = true; } } return(createdAny); }