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); }
public bool AddMoney(Vector3 dwarfPos, DwarfBux money, ref DwarfBux moneyPut) { DwarfBux totalMoney = MoneyPerPile * Voxels.Count; DwarfBux moneyToPut = money; if (Money + money > totalMoney) { DwarfBux remainder = totalMoney - Money; if (remainder <= 0) { moneyPut = 0; return(false); } moneyToPut = remainder; } Vector3 targetToss = Coins.Count == 0 ? Voxels[0].WorldPosition + new Vector3(0.5f, 0.5f, 0.5f) : Coins[Coins.Count - 1].LocalTransform.Translation + new Vector3(0.5f, 0.5f, 0.5f); Body component = EntityFactory.CreateEntity <Body>("Coins", dwarfPos); component.UpdateRate = 1; TossMotion toss = new TossMotion(1.0f, 2.5f, component.LocalTransform, targetToss); component.AnimationQueue.Add(toss); toss.OnComplete += component.Die; Money += moneyToPut; Faction.Economy.CurrentMoney += moneyToPut; moneyPut = moneyToPut; return(moneyPut >= money); }
public override IEnumerable <Status> Run() { Creature.IsCloaked = false; Timer waitTimer = new Timer(1.0f, true); if (Agent.Faction.Economy.Funds < Money) { Agent.SetTaskFailureReason("Failed to remove money from zone."); yield return(Status.Fail); } else { Agent.AddMoney(Money); Agent.Faction.Economy.Funds -= Money; Money = 0; var component = EntityFactory.CreateEntity <GameComponent>("Coins", Agent.Physics.Position + new Microsoft.Xna.Framework.Vector3(0.0f, 2.0f, 0.0f)); var toss = new TossMotion(1.0f, 2.5f, component.LocalTransform, Agent.Physics.Position); component.AnimationQueue.Add(toss); toss.OnComplete += component.Die; Agent.Creature.Sprite.ResetAnimations(Creature.Stats.CurrentClass.AttackMode); while (!waitTimer.HasTriggered) { Agent.Creature.CurrentCharacterMode = Creature.Stats.CurrentClass.AttackMode; waitTimer.Update(DwarfTime.LastTime); yield return(Status.Running); } Agent.Creature.CurrentCharacterMode = CharacterMode.Idle; yield return(Status.Success); } }
public bool Pickup(Item item) { if (item == null || item.UserData == null || item.UserData.IsDead) { return(false); } bool success = Resources.AddResource (new ResourceAmount { NumResources = 1, ResourceType = item.UserData.Tags[0] }); if (!success) { return(false); } if (item.IsInZone) { item.Zone = null; } TossMotion toss = new TossMotion(0.5f + MathFunctions.Rand(0.05f, 0.08f), 1.0f, item.UserData.GlobalTransform, Position); item.UserData.AnimationQueue.Add(toss); toss.OnComplete += () => item.UserData.GetEntityRootComponent().Delete(); return(true); }
public override IEnumerable <Status> Run() { var zone = Agent.Blackboard.GetData <Zone>(StockpileName); var resource = Agent.Blackboard.GetData <Resource>(ResourceName); if (zone == null || !(zone is Stockpile) || resource == null) { Creature.DrawIndicator(IndicatorManager.StandardIndicators.Question); yield return(Status.Fail); yield break; } var createdItems = Creature.Inventory.RemoveAndCreate(resource, Inventory.RestockType.RestockResource); if ((zone as Stockpile).AddResource(resource)) { var toss = new TossMotion(1.0f, 2.5f, createdItems.LocalTransform, zone.GetBoundingBox().Center() + new Vector3(0.5f, 0.5f, 0.5f)); if (createdItems.GetRoot().GetComponent <Physics>().HasValue(out var physics)) { physics.CollideMode = Physics.CollisionMode.None; } createdItems.AnimationQueue.Add(toss); toss.OnComplete += createdItems.Die; Creature.Stats.NumItemsGathered++; } else { Creature.Inventory.AddResource(resource, Inventory.RestockType.RestockResource); createdItems.Delete(); } Creature.NoiseMaker.MakeNoise("Stockpile", Creature.AI.Position); Creature.CurrentCharacterMode = Creature.Stats.CurrentClass.AttackMode; Creature.Sprite.ResetAnimations(Creature.Stats.CurrentClass.AttackMode); Creature.Sprite.PlayAnimations(Creature.Stats.CurrentClass.AttackMode); while (!Creature.Sprite.AnimPlayer.IsDone()) { yield return(Status.Running); } if (Library.GetResourceType(resource.TypeName).HasValue(out var res) && res.Tags.Contains("Corpse")) { Creature.AddThought("I laid a friend to rest.", new TimeSpan(0, 8, 0, 0), 10.0f); } yield return(Status.Running); Creature.CurrentCharacterMode = CharacterMode.Idle; yield return(Status.Success); }
public override bool AddItem(Body component) { bool worked = base.AddItem(component); HandleBoxes(); 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.AnimationQueue.Add(toss); toss.OnComplete += component.Die; return(worked); }
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); }
public override IEnumerable <Status> Run() { if (!Creature.Faction.WallBuilder.IsDesignation(Voxel)) { yield return(Status.Fail); yield break; } foreach (Status status in Creature.HitAndWait(1.0f, true)) { if (status == Status.Running) { yield return(status); } } Body grabbed = Creature.Inventory.RemoveAndCreate(Resource).FirstOrDefault(); if (grabbed == null) { yield return(Status.Fail); yield break; } else { if (Creature.Faction.WallBuilder.IsDesignation(Voxel)) { TossMotion motion = new TossMotion(1.0f, 2.0f, grabbed.LocalTransform, Voxel.Position + new Vector3(0.5f, 0.5f, 0.5f)); motion.OnComplete += grabbed.Die; grabbed.AnimationQueue.Add(motion); WallBuilder put = Creature.Faction.WallBuilder.GetDesignation(Voxel); put.Put(PlayState.ChunkManager); Creature.Faction.WallBuilder.Designations.Remove(put); Creature.Stats.NumBlocksPlaced++; Creature.AI.AddXP(1); yield return(Status.Success); } else { Creature.Inventory.Resources.AddItem(grabbed); grabbed.Die(); yield return(Status.Fail); } } }
public void RemoveAndCreateWithToss(List <ResourceAmount> resources, Vector3 pos, RestockType type) { 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; } } }
public override IEnumerable <Status> Run() { if ((Creature.Physics.GlobalTransform.Translation - Location).LengthSquared() < 0.5f) { yield return(Act.Status.Success); yield break; } switch (Type) { case TeleportType.Jump: { TossMotion motion = new TossMotion(0.6f, 0.9f, Creature.Physics.GlobalTransform, Location); Creature.Physics.AnimationQueue.Add(motion); SoundManager.PlaySound(ContentPaths.Audio.jump, Creature.Physics.GlobalTransform.Translation); while (!motion.IsDone()) { Creature.CurrentCharacterMode = CharacterMode.Falling; yield return(Status.Running); } break; } case TeleportType.Lerp: { EaseMotion motion = new EaseMotion(0.6f, Creature.Physics.GlobalTransform, Location); while (!motion.IsDone()) { Creature.Physics.PropogateTransforms(); motion.Update(DwarfTime.LastTime); Creature.AI.Position = motion.GetTransform().Translation; yield return(Status.Running); } Creature.Physics.IsSleeping = false; break; } case TeleportType.Snap: Creature.AI.Position = Location; break; } yield return(Status.Success); }
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.SetUpdateRateRecursive(1); body.GetRoot().GetComponent <Physics>().CollideMode = Physics.CollisionMode.None; body.AnimationQueue.Add(toss); toss.OnComplete += body.Delete; createdAny = true; } } return(createdAny); }
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 override bool AddItem(Body component) { 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(); } return(worked); }
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); TossMotion toss = new TossMotion(0.5f + MathFunctions.Rand(0.05f, 0.08f), 1.0f, item.GlobalTransform, Position); item.AnimationQueue.Add(toss); toss.OnComplete += () => item.GetRoot().Delete(); return(true); }
public override IEnumerable <Status> Run() { switch (Type) { case TeleportType.Jump: { TossMotion motion = new TossMotion(0.6f, 0.9f, Creature.Physics.GlobalTransform, Location); Creature.AI.Jump(DwarfTime.LastTime); while (!motion.IsDone()) { Creature.Physics.IsSleeping = true; motion.Update(DwarfTime.LastTime); Creature.AI.Position = motion.GetTransform().Translation; Creature.CurrentCharacterMode = Creature.CharacterMode.Falling; yield return(Status.Running); } break; } case TeleportType.Lerp: { EaseMotion motion = new EaseMotion(0.6f, Creature.Physics.GlobalTransform, Location); while (!motion.IsDone()) { motion.Update(DwarfTime.LastTime); Creature.AI.Position = motion.GetTransform().Translation; yield return(Status.Running); } break; } case TeleportType.Snap: Creature.AI.Position = Location; break; } yield return(Status.Success); }
public bool RemoveMoney(Vector3 dwarfPos, DwarfBux money) { if (Money < money) { return(false); } Body lastCoins = Coins.LastOrDefault(); if (lastCoins == null) { return(false); } Body component = EntityFactory.CreateEntity <Body>("Coins", lastCoins.Position); TossMotion toss = new TossMotion(1.0f, 2.5f, component.LocalTransform, dwarfPos); component.AnimationQueue.Add(toss); toss.OnComplete += component.Die; Money -= money; Faction.Economy.CurrentMoney -= money; return(true); }
public bool RemoveResources(List <ResourceAmount> resources, Vector3 position, bool createItems = true) { Dictionary <ResourceType, ResourceAmount> amounts = new Dictionary <ResourceType, ResourceAmount>(); foreach (ResourceAmount resource in resources) { if (!amounts.ContainsKey(resource.ResourceType)) { amounts.Add(resource.ResourceType, new ResourceAmount(resource)); } else { amounts[resource.ResourceType].NumResources += resource.NumResources; } } if (!HasResources(amounts.Values)) { return(false); } List <Stockpile> stockpilesCopy = new List <Stockpile>(Stockpiles.Where(s => resources.All(r => s.IsAllowed(r.ResourceType)))); stockpilesCopy.Sort((a, b) => CompareZones(a, b, position)); foreach (ResourceAmount resource in resources) { int count = 0; List <Vector3> positions = new List <Vector3>(); foreach (Stockpile stock in stockpilesCopy) { int num = stock.Resources.RemoveMaxResources(resource, resource.NumResources - count); stock.HandleBoxes(); if (stock.Boxes.Count > 0) { for (int i = 0; i < num; i++) { positions.Add(stock.Boxes[stock.Boxes.Count - 1].LocalTransform.Translation); } } count += num; if (count >= resource.NumResources) { break; } } if (createItems) { foreach (Vector3 vec in positions) { Body newEntity = EntityFactory.CreateEntity <Body>(resource.ResourceType + " Resource", vec + MathFunctions.RandVector3Cube() * 0.5f); TossMotion toss = new TossMotion(1.0f + MathFunctions.Rand(0.1f, 0.2f), 2.5f + MathFunctions.Rand(-0.5f, 0.5f), newEntity.LocalTransform, position); newEntity.GetRoot().GetComponent <Physics>().CollideMode = Physics.CollisionMode.None; newEntity.AnimationQueue.Add(toss); newEntity.UpdateRate = 1; toss.OnComplete += () => toss_OnComplete(newEntity); } } } return(true); }
public override IEnumerable<Status> Run() { if (!Creature.Faction.WallBuilder.IsDesignation(Voxel)) { yield return Status.Fail; yield break; } foreach (Status status in Creature.HitAndWait(1.0f, true)) { if (status == Status.Running) { yield return status; } } Body grabbed = Creature.Inventory.RemoveAndCreate(Resource).FirstOrDefault(); if(grabbed == null) { yield return Status.Fail; yield break; } else { if(Creature.Faction.WallBuilder.IsDesignation(Voxel)) { TossMotion motion = new TossMotion(1.0f, 2.0f, grabbed.LocalTransform, Voxel.Position + new Vector3(0.5f, 0.5f, 0.5f)); motion.OnComplete += grabbed.Die; grabbed.AnimationQueue.Add(motion); WallBuilder put = Creature.Faction.WallBuilder.GetDesignation(Voxel); put.Put(PlayState.ChunkManager); Creature.Faction.WallBuilder.Designations.Remove(put); Creature.Stats.NumBlocksPlaced++; Creature.AI.AddXP(1); yield return Status.Success; } else { Creature.Inventory.Resources.AddItem(grabbed); grabbed.Die(); yield return Status.Fail; } } }
public override IEnumerable <Status> Run() { foreach (var res in Agent.Blackboard.GetData <List <Resource> >(ResourceBlackboardName)) { if (!Creature.Inventory.Contains(res)) { yield return(Status.Fail); } } foreach (var status in Creature.HitAndWait(1.0f, true, () => Location.Coordinate.ToVector3() + Vector3.One * 0.5f)) { if (status == Status.Running) { yield return(status); } } foreach (var res in Agent.Blackboard.GetData <List <Resource> >(ResourceBlackboardName)) { var grabbed = Creature.Inventory.RemoveAndCreate(res, Inventory.RestockType.Any); if (grabbed == null) { yield return(Status.Fail); yield break; } else { // If the creature intersects the box, find a voxel adjacent to it that is free, and jump there to avoid getting crushed. if (Creature.Physics.BoundingBox.Intersects(Location.GetBoundingBox())) { var neighbors = VoxelHelpers.EnumerateAllNeighbors(Location.Coordinate) .Select(c => new VoxelHandle(Agent.World.ChunkManager, c)); var closest = VoxelHandle.InvalidHandle; var closestDist = float.MaxValue; foreach (var voxel in neighbors) { if (!voxel.IsValid) { continue; } float dist = (voxel.WorldPosition - Creature.Physics.Position).LengthSquared(); if (dist < closestDist && voxel.IsEmpty) { closestDist = dist; closest = voxel; } } if (closest.IsValid) { TossMotion teleport = new TossMotion(0.5f, 1.0f, Creature.Physics.GlobalTransform, closest.WorldPosition + Vector3.One * 0.5f); Creature.Physics.AnimationQueue.Add(teleport); } } // Todo: Shitbox - what happens if the player saves while this animation is in progress?? How is the OnComplete restored? var motion = new TossMotion(1.0f, 2.0f, grabbed.LocalTransform, Location.Coordinate.ToVector3() + new Vector3(0.5f, 0.5f, 0.5f)); if (grabbed.GetRoot().GetComponent <Physics>().HasValue(out var grabbedPhysics)) { grabbedPhysics.CollideMode = Physics.CollisionMode.None; } grabbed.AnimationQueue.Add(motion); motion.OnComplete += () => grabbed.Die(); } if (Library.GetVoxelType(VoxelType).HasValue(out var vType)) { PlaceVoxel(Location, vType, Creature.Manager.World); } Creature.Stats.NumBlocksPlaced++; Creature.AI.AddXP(1); yield return(Status.Success); yield break; } }
public bool RemoveResources(List<ResourceAmount> resources, Vector3 position, bool createItems = true) { Dictionary<ResourceLibrary.ResourceType, ResourceAmount> amounts = new Dictionary<ResourceLibrary.ResourceType, ResourceAmount>(); foreach (ResourceAmount resource in resources) { if (!amounts.ContainsKey(resource.ResourceType.Type)) { amounts.Add(resource.ResourceType.Type, new ResourceAmount(resource)); } else { amounts[resource.ResourceType.Type].NumResources += resource.NumResources; } } if (!HasResources(amounts)) { return false; } List<Stockpile> stockpilesCopy = new List<Stockpile>(Stockpiles); stockpilesCopy.Sort((a, b) => CompareZones(a, b, position)); foreach(ResourceAmount resource in resources) { int count = 0; List<Vector3> positions = new List<Vector3>(); foreach (Stockpile stock in stockpilesCopy) { int num = stock.Resources.RemoveMaxResources(resource, resource.NumResources - count); stock.HandleBoxes(); if(stock.Boxes.Count > 0) { for(int i = 0; i < num; i++) { positions.Add(stock.Boxes[stock.Boxes.Count - 1].LocalTransform.Translation); } } count += num; if(count >= resource.NumResources) { break; } } if (createItems) { foreach (Vector3 vec in positions) { Body newEntity = EntityFactory.CreateEntity<Body>(resource.ResourceType.ResourceName + " Resource", vec + MathFunctions.RandVector3Cube()*0.5f); TossMotion toss = new TossMotion(1.0f + MathFunctions.Rand(0.1f, 0.2f), 2.5f + MathFunctions.Rand(-0.5f, 0.5f), newEntity.LocalTransform, position); newEntity.AnimationQueue.Add(toss); toss.OnComplete += () => toss_OnComplete(newEntity); } } } return true; }
public override bool AddItem(Body component) { bool worked = base.AddItem(component); HandleBoxes(); 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.AnimationQueue.Add(toss); toss.OnComplete += component.Die; return worked; }
public override IEnumerable <Status> Run() { if (!Creature.Faction.WallBuilder.IsDesignation(Voxel)) { yield return(Status.Fail); yield break; } foreach (Status status in Creature.HitAndWait(1.0f, true, Voxel.Position)) { if (status == Status.Running) { yield return(status); } } Body grabbed = Creature.Inventory.RemoveAndCreate(Resource).FirstOrDefault(); if (grabbed == null) { yield return(Status.Fail); yield break; } else { if (Creature.Faction.WallBuilder.IsDesignation(Voxel)) { // If the creature intersects the box, find a voxel adjacent to it that is free, and jump there to avoid getting crushed. if (Creature.Physics.BoundingBox.Intersects(Voxel.GetBoundingBox())) { List <Voxel> neighbors = Voxel.Chunk.GetNeighborsEuclidean(Voxel); Voxel closest = null; float closestDist = float.MaxValue; foreach (Voxel voxel in neighbors) { float dist = (voxel.Position - Creature.Physics.Position).LengthSquared(); if (dist < closestDist && voxel.IsEmpty) { closestDist = dist; closest = voxel; } } if (closest != null) { TossMotion teleport = new TossMotion(0.5f, 1.0f, Creature.Physics.GlobalTransform, closest.Position + Vector3.One * 0.5f); Creature.Physics.AnimationQueue.Add(teleport); } } TossMotion motion = new TossMotion(1.0f, 2.0f, grabbed.LocalTransform, Voxel.Position + new Vector3(0.5f, 0.5f, 0.5f)); motion.OnComplete += grabbed.Die; grabbed.GetComponent <Physics>().CollideMode = Physics.CollisionMode.None; grabbed.AnimationQueue.Add(motion); WallBuilder put = Creature.Faction.WallBuilder.GetDesignation(Voxel); put.Put(Creature.Manager.World.ChunkManager); Creature.Faction.WallBuilder.Designations.Remove(put); Creature.Stats.NumBlocksPlaced++; Creature.AI.AddXP(1); yield return(Status.Success); } else { Creature.Inventory.Resources.AddItem(grabbed); grabbed.Die(); yield return(Status.Fail); } } }
public override IEnumerable <Status> Run() { Creature.IsCloaked = false; if (Zone != null) { var resourcesToStock = Creature.Inventory.Resources.Where(a => a.MarkedForRestock && Zone is Stockpile && (Zone as Stockpile).IsAllowed(a.Resource.TypeName)).ToList(); foreach (var resource in resourcesToStock) { var createdItem = Creature.Inventory.RemoveAndCreate(resource.Resource, Inventory.RestockType.RestockResource); if (Zone.AddResource(resource.Resource)) { var toss = new TossMotion(1.0f, 2.5f, createdItem.LocalTransform, Zone.GetBoundingBox().Center() + new Vector3(0.5f, 0.5f, 0.5f)); if (createdItem.GetRoot().GetComponent <Physics>().HasValue(out var physics)) { physics.CollideMode = Physics.CollisionMode.None; } createdItem.AnimationQueue.Add(toss); toss.OnComplete += createdItem.Die; Creature.NoiseMaker.MakeNoise("Stockpile", Creature.AI.Position); Creature.Stats.NumItemsGathered++; Creature.CurrentCharacterMode = Creature.Stats.CurrentClass.AttackMode; Creature.Sprite.ResetAnimations(Creature.Stats.CurrentClass.AttackMode); Creature.Sprite.PlayAnimations(Creature.Stats.CurrentClass.AttackMode); while (!Creature.Sprite.AnimPlayer.IsDone()) { yield return(Status.Running); } yield return(Status.Running); } else { Creature.Inventory.AddResource(resource.Resource, Inventory.RestockType.RestockResource); createdItem.Delete(); } } } Timer waitTimer = new Timer(1.0f, true); bool removed = Creature.World.RemoveResourcesFromSpecificZone(Resource, Zone); if (!removed) { yield return(Status.Fail); } else { var newEntity = Agent.Manager.RootComponent.AddChild(new ResourceEntity(Agent.Manager, Resource, Zone.GetBoundingBox().Center() + new Vector3(0.0f, 1.0f, 0.0f))); if (newEntity.GetRoot().GetComponent <Physics>().HasValue(out var newPhysics)) { newPhysics.CollideMode = Physics.CollisionMode.None; } var toss = new TossMotion(1.0f + MathFunctions.Rand(0.1f, 0.2f), 2.5f + MathFunctions.Rand(-0.5f, 0.5f), newEntity.LocalTransform, Agent.Position); newEntity.AnimationQueue.Add(toss); toss.OnComplete += () => newEntity.Die(); Agent.Creature.Inventory.AddResource(Resource, Inventory.RestockType.None); Agent.Creature.Sprite.ResetAnimations(Creature.Stats.CurrentClass.AttackMode); while (!waitTimer.HasTriggered) { Agent.Creature.CurrentCharacterMode = Creature.Stats.CurrentClass.AttackMode; waitTimer.Update(DwarfTime.LastTime); yield return(Status.Running); } Agent.Creature.CurrentCharacterMode = CharacterMode.Idle; yield return(Status.Success); } }
public override IEnumerable <Status> Run() { if (!Creature.Faction.Designations.IsVoxelDesignation(Location, DesignationType.Put)) { yield return(Status.Success); yield break; } if (!Creature.Inventory.HasResource(Resource)) { yield return(Status.Fail); } foreach (var status in Creature.HitAndWait(1.0f, true, () => Location.Coordinate.ToVector3() + Vector3.One * 0.5f)) { if (!Creature.Faction.Designations.IsVoxelDesignation(Location, DesignationType.Put)) { yield return(Status.Success); yield break; } if (status == Status.Running) { yield return(status); } } var grabbed = Creature.Inventory.RemoveAndCreate(Resource, Inventory.RestockType.Any).FirstOrDefault(); if (grabbed == null) { yield return(Status.Fail); yield break; } else { if (Creature.Faction.Designations.IsVoxelDesignation(Location, DesignationType.Put)) { // If the creature intersects the box, find a voxel adjacent to it that is free, and jump there to avoid getting crushed. if (Creature.Physics.BoundingBox.Intersects(Location.GetBoundingBox())) { var neighbors = VoxelHelpers.EnumerateAllNeighbors(Location.Coordinate) .Select(c => new VoxelHandle(Agent.Chunks.ChunkData, c)); var closest = VoxelHandle.InvalidHandle; float closestDist = float.MaxValue; foreach (var voxel in neighbors) { if (!voxel.IsValid) { continue; } float dist = (voxel.WorldPosition - Creature.Physics.Position).LengthSquared(); if (dist < closestDist && voxel.IsEmpty) { closestDist = dist; closest = voxel; } } if (closest.IsValid) { TossMotion teleport = new TossMotion(0.5f, 1.0f, Creature.Physics.GlobalTransform, closest.WorldPosition + Vector3.One * 0.5f); Creature.Physics.AnimationQueue.Add(teleport); } } TossMotion motion = new TossMotion(1.0f, 2.0f, grabbed.LocalTransform, Location.Coordinate.ToVector3() + new Vector3(0.5f, 0.5f, 0.5f)); grabbed.GetRoot().GetComponent <Physics>().CollideMode = Physics.CollisionMode.None; grabbed.AnimationQueue.Add(motion); var put = Creature.Faction.Designations.GetVoxelDesignation(Location, DesignationType.Put) as short?; if (!put.HasValue) { yield return(Status.Fail); yield break; } var putType = VoxelLibrary.GetVoxelType(put.Value); motion.OnComplete += () => { grabbed.Die(); PlaceVoxel(Location, putType, Creature.Manager.World); Creature.Faction.Designations.RemoveVoxelDesignation(Location, DesignationType.Put); Creature.Stats.NumBlocksPlaced++; Creature.AI.AddXP(1); }; yield return(Status.Success); yield break; } else { Creature.Inventory.Pickup(grabbed, Inventory.RestockType.RestockResource); grabbed.Die(); yield return(Status.Success); } } }
public override IEnumerable<Status> Run() { switch (Type) { case TeleportType.Jump: { TossMotion motion = new TossMotion(0.6f, 0.9f, Creature.Physics.GlobalTransform, Location); Creature.AI.Jump(DwarfTime.LastTime); while (!motion.IsDone()) { Creature.Physics.IsSleeping = true; motion.Update(DwarfTime.LastTime); Creature.AI.Position = motion.GetTransform().Translation; Creature.CurrentCharacterMode = Creature.CharacterMode.Falling; yield return Status.Running; } break; } case TeleportType.Lerp: { EaseMotion motion = new EaseMotion(0.6f, Creature.Physics.GlobalTransform, Location); while (!motion.IsDone()) { motion.Update(DwarfTime.LastTime); Creature.AI.Position = motion.GetTransform().Translation; yield return Status.Running; } break; } case TeleportType.Snap: Creature.AI.Position = Location; break; } yield return Status.Success; }