Ejemplo n.º 1
0
 public bool IsGrabbed(Body component)
 {
     return(GrabbedComponents.Any(item => item.Component == component));
 }
Ejemplo n.º 2
0
 public Inventory(string name, Body parent) :
     base(name, parent, Matrix.Identity, parent.BoundingBox.Extents(), parent.BoundingBoxPos)
 {
     DropRate = 0.75f;
 }
Ejemplo n.º 3
0
        public IEnumerable <Status> WaitUntilBored()
        {
            Timer waitTimer = new Timer(SitTime, false);
            Body  body      = Creature.AI.Blackboard.GetData <Body>("Chair");

            // Snap relative the chair's position, not their own...
            Vector3 snapPosition = body.Position + new Vector3(0, 0.4f, 0);

            if (body == null || body.IsDead)
            {
                Creature.OverrideCharacterMode = false;
                yield return(Status.Success);

                yield break;
            }

            while (true)
            {
                if (Creature.AI.Tasks.Count > 1)
                {
                    Creature.OverrideCharacterMode = false;
                    yield return(Status.Success);
                }

                if (Creature.AI.Status.Energy.IsDissatisfied())
                {
                    Creature.OverrideCharacterMode = false;
                    yield return(Status.Success);
                }

                if (Creature.AI.Status.Hunger.IsDissatisfied())
                {
                    Creature.OverrideCharacterMode = false;
                    yield return(Status.Success);
                }

                if (Creature.AI.Sensor.Enemies.Count > 0)
                {
                    Creature.OverrideCharacterMode = false;
                    yield return(Status.Success);
                }

                waitTimer.Update(DwarfTime.LastTime);

                if (waitTimer.HasTriggered)
                {
                    Creature.OverrideCharacterMode = false;
                    yield return(Status.Success);
                }

                ConverseFriends();


                Agent.Position = snapPosition;
                Agent.Physics.PropogateTransforms();
                Agent.Physics.IsSleeping       = true;
                Agent.Physics.Velocity         = Vector3.Zero;
                Creature.CurrentCharacterMode  = CharacterMode.Sitting;
                Creature.OverrideCharacterMode = true;
                yield return(Status.Running);
            }
        }
Ejemplo n.º 4
0
        public bool Perform(Creature performer, Body other, DwarfTime time, float bonus, Vector3 pos, string faction)
        {
            switch (TriggerMode)
            {
            case AttackTrigger.Timer:
                RechargeTimer.Update(time);
                if (!RechargeTimer.HasTriggered)
                {
                    HasTriggered = false;
                    return(false);
                }
                break;

            case AttackTrigger.Animation:
                if (!performer.Sprite.AnimPlayer.HasValidAnimation() ||
                    performer.Sprite.AnimPlayer.CurrentFrame != TriggerFrame)
                {
                    HasTriggered = false;
                    return(false);
                }
                break;
            }

            if (HasTriggered)
            {
                return(true);
            }

            HasTriggered = true;
            switch (Mode)
            {
            case AttackMode.Melee:
            case AttackMode.Dogfight:
            {
                var otherCreature = other.GetRoot().GetComponent <Creature>();
                if (otherCreature != null && !String.IsNullOrEmpty(DiseaseToSpread))
                {
                    var disease = DiseaseLibrary.GetDisease(DiseaseToSpread);
                    if (MathFunctions.RandEvent(disease.LikelihoodOfSpread))
                    {
                        otherCreature.AcquireDisease(DiseaseToSpread);
                    }
                }
                var health = other.GetRoot().EnumerateAll().OfType <Health>().FirstOrDefault();
                if (health != null)
                {
                    health.Damage(DamageAmount + bonus);
                    var injury = DiseaseLibrary.GetRandomInjury();

                    if (MathFunctions.RandEvent(injury.LikelihoodOfSpread))
                    {
                        var creature = other.GetRoot().GetComponent <Creature>();
                        if (creature != null)
                        {
                            creature.AcquireDisease(injury.Name);
                        }
                    }
                    Vector3 knock = other.Position - performer.Physics.Position;
                    knock.Normalize();
                    knock *= 0.2f;
                    if (other.AnimationQueue.Count == 0)
                    {
                        other.AnimationQueue.Add(new KnockbackAnimation(0.15f, other.LocalTransform, knock));
                    }
                }

                PlayNoise(other.GlobalTransform.Translation);
                if (HitParticles != "")
                {
                    performer.Manager.World.ParticleManager.Trigger(HitParticles, other.LocalTransform.Translation, Color.White, 5);
                }

                if (HitAnimation != null)
                {
                    IndicatorManager.DrawIndicator(HitAnimation, other.BoundingBox.Center(), 10.0f, 1.0f, MathFunctions.RandVector2Circle(), Color.White, MathFunctions.Rand() > 0.5f);
                }

                Physics physics = other as Physics;

                if (physics != null)
                {
                    Vector3 force = other.Position - pos;

                    if (force.LengthSquared() > 0.01f)
                    {
                        force.Normalize();
                        physics.ApplyForce(force * Knockback, 1.0f);
                    }
                }

                break;
            }

            case AttackMode.Ranged:
            {
                PlayNoise(other.GlobalTransform.Translation);
                LaunchProjectile(pos, other.Position, other);

                var injury = DiseaseLibrary.GetRandomInjury();

                if (MathFunctions.RandEvent(injury.LikelihoodOfSpread))
                {
                    var creature = other.GetRoot().GetComponent <Creature>();
                    if (creature != null)
                    {
                        creature.AcquireDisease(injury.Name);
                    }
                }
                break;
            }
            }

            return(true);
        }
Ejemplo n.º 5
0
 public bool Pickup(Body component)
 {
     return(Pickup(Item.CreateItem(null, component)));
 }
Ejemplo n.º 6
0
        public TradeEnvoy SendTradeEnvoy(Faction natives, WorldManager world)
        {
            if (!world.PlayerFaction.GetRooms().Any(room => room is BalloonPort && room.IsBuilt))
            {
                world.MakeAnnouncement(String.Format("Trade envoy from {0} left: No balloon port!", natives.Name));
                SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_negative_generic, 0.15f);
                return(null);
            }
            TradeEnvoy envoy = null;

            List <CreatureAI> creatures =
                world.MonsterSpawner.Spawn(world.MonsterSpawner.GenerateSpawnEvent(natives,
                                                                                   world.PlayerFaction, MathFunctions.Random.Next(4) + 1, false));

            if (natives.TradeMoney < 100m)
            {
                natives.TradeMoney += MathFunctions.Rand(250.0f, 5000.0f);
            }

            envoy = new TradeEnvoy(world.Time.CurrentDate)
            {
                Creatures    = creatures,
                OtherFaction = world.PlayerFaction,
                ShouldRemove = false,
                OwnerFaction = natives,
                TradeGoods   = natives.Race.GenerateResources(world),
                TradeMoney   = natives.TradeMoney
            };

            if (natives.Race.IsNative)
            {
                if (natives.Economy == null)
                {
                    natives.Economy = new Economy(natives, 1000.0m, World, new CompanyInformation()
                    {
                        Name = natives.Name
                    });
                }

                foreach (CreatureAI creature in envoy.Creatures)
                {
                    creature.Physics.AddChild(new ResourcePack(World.ComponentManager));
                    creature.Physics.AddChild(new Flag(World.ComponentManager, Vector3.Up * 0.5f + Vector3.Backward * 0.25f, natives.Economy.Company.Information));
                }
            }
            else
            {
                Body balloon = world.PlayerFaction.DispatchBalloon();

                if (balloon != null)
                {
                    foreach (CreatureAI creature in creatures)
                    {
                        Matrix tf = creature.Physics.LocalTransform;
                        tf.Translation = balloon.LocalTransform.Translation;
                        creature.Physics.LocalTransform = tf;
                    }
                }
                else
                {
                    if (natives.Economy == null)
                    {
                        natives.Economy = new Economy(natives, 1000.0m, World, new CompanyInformation()
                        {
                            Name = natives.Name
                        });
                    }

                    foreach (CreatureAI creature in envoy.Creatures)
                    {
                        creature.Physics.AddChild(new ResourcePack(World.ComponentManager));
                        creature.Physics.AddChild(new Flag(World.ComponentManager, Vector3.Up * 0.5f + Vector3.Backward * 0.25f, natives.Economy.Company.Information));
                    }
                }
            }

            foreach (CreatureAI creature in envoy.Creatures)
            {
                creature.Physics.AddChild(new ResourcePack(World.ComponentManager));
            }

            envoy.DistributeGoods();
            natives.TradeEnvoys.Add(envoy);
            world.MakeAnnouncement(new DwarfCorp.Gui.Widgets.QueuedAnnouncement
            {
                Text        = String.Format("Trade envoy from {0} has arrived!", natives.Name),
                ClickAction = (gui, sender) =>
                {
                    if (envoy.Creatures.Count > 0)
                    {
                        envoy.Creatures.First().ZoomToMe();
                        World.MakeWorldPopup(String.Format("Traders from {0} ({1}) have entered our territory.\nThey will try to get to our balloon port to trade with us.", natives.Name, natives.Race.Name),
                                             envoy.Creatures.First().Physics, -10);
                    }
                },
                ShouldKeep = () =>
                {
                    return(envoy.ExpiditionState == Expedition.State.Arriving);
                }
            });

            SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_positive_generic, 0.15f);


            world.Tutorial("trade");
            if (!String.IsNullOrEmpty(natives.Race.TradeMusic))
            {
                SoundManager.PlayMusic(natives.Race.TradeMusic);
            }

            return(envoy);
        }
Ejemplo n.º 7
0
 public GreedyPathAct(CreatureAI creature, Body target, float threshold)
     : base(creature)
 {
     Target    = target;
     Threshold = threshold;
 }
Ejemplo n.º 8
0
        public virtual Task ActOnIdle()
        {
            if(GatherManager.VoxelOrders.Count == 0 && (GatherManager.StockOrders.Count == 0 || !Faction.HasFreeStockpile()))
            {
                // Find a room to train in
                if (Stats.CurrentClass.HasAction(GameMaster.ToolMode.Attack) && MathFunctions.RandEvent(0.01f))
                {
                    Body closestTraining = Faction.FindNearestItemWithTags("Train", Position, true);

                    if (closestTraining != null)
                    {
                        return new ActWrapperTask(new GoTrainAct(this));    
                    }
                }

                // Otherwise, try to find a chair to sit in
                if (IdleTimer.HasTriggered && MathFunctions.RandEvent(0.25f))
                {
                    return new ActWrapperTask(new GoToChairAndSitAct(this)) { Priority = Task.PriorityType.Eventually, AutoRetry = false };
                }
                else if (IdleTimer.HasTriggered)
                {
                    IdleTimer.Reset(IdleTimer.TargetTimeSeconds);
                    return new ActWrapperTask(new WanderAct(this, 2, 0.5f + MathFunctions.Rand(-0.25f, 0.25f), 1.0f))
                    {
                        Priority = Task.PriorityType.Eventually
                    };
                }
                Physics.Velocity *= 0.0f;
                return null;
            }
            // If we have no more build orders, look for gather orders
            else if (GatherManager.VoxelOrders.Count == 0)
            {
                GatherManager.StockOrder order = GatherManager.StockOrders[0];
                GatherManager.StockOrders.RemoveAt(0);
                return new ActWrapperTask(new StockResourceAct(this, order.Resource))
                {
                    Priority = Task.PriorityType.Low
                };
            }
            // Otherwise handle build orders.
            else
            {
                List<Voxel> voxels = new List<Voxel>();
                List<VoxelType> types = new List<VoxelType>();
                foreach (GatherManager.BuildVoxelOrder order in GatherManager.VoxelOrders)
                {
                   voxels.Add(order.Voxel);
                    types.Add(order.Type);
                }

                GatherManager.VoxelOrders.Clear();
                return new ActWrapperTask(new BuildVoxelsAct(this, voxels, types))
                {
                    Priority = Task.PriorityType.Low,
                    AutoRetry = true
                };

            }
        }
Ejemplo n.º 9
0
 public void Kill(Body entity)
 {
     KillEntityTask killTask = new KillEntityTask(entity, KillEntityTask.KillType.Auto);
     if (!Tasks.Contains(killTask))
         Tasks.Add(killTask);
 }
Ejemplo n.º 10
0
 public bool IsDesignation(Body Entity, DesignationType Type)
 {
     return(EntityDesignations.Count(e => Object.ReferenceEquals(e.Body, Entity) && TypeSet(e.Type, Type)) != 0);
 }
Ejemplo n.º 11
0
        public FireballProjectile(ComponentManager manager, Vector3 position, Vector3 initialVelocity, Body target) :
            base(manager, position, initialVelocity, new Health.DamageAmount() { Amount = 15.0f, DamageType = Health.DamageType.Fire }, 0.25f, ContentPaths.Particles.fireball, "flame", ContentPaths.Audio.Oscar.sfx_ic_demon_fire_hit_1, target)
        {
            Sprite.LightsWithVoxels  = false;
            Sprite2.LightsWithVoxels = false;

            HitAnimation = AnimationLibrary.CreateSimpleAnimation(ContentPaths.Effects.pierce);
        }
Ejemplo n.º 12
0
        public void Render(DwarfTime gameTime,
                           ChunkManager chunks,
                           Camera camera,
                           SpriteBatch spriteBatch,
                           GraphicsDevice graphicsDevice,
                           Effect effect,
                           WaterRenderType waterRenderMode, float waterLevel)
        {
            bool renderForWater = (waterRenderMode != WaterRenderType.None);

            if (!renderForWater)
            {
                visibleComponents.Clear();
                componentsToDraw.Clear();


                List <Body> list = FrustrumCullLocatableComponents(camera);
                foreach (Body component in list)
                {
                    visibleComponents.Add(component);
                }


                Camera = camera;
                foreach (GameComponent component in Components.Values)
                {
                    bool isLocatable = component is Body;

                    if (isLocatable)
                    {
                        Body loc = (Body)component;


                        if (((loc.GlobalTransform.Translation - camera.Position).LengthSquared() < chunks.DrawDistanceSquared &&
                             visibleComponents.Contains(loc) || !(loc.FrustrumCull) || !(loc.WasAddedToOctree) && !loc.IsAboveCullPlane)
                            )
                        {
                            componentsToDraw.Add(component);
                        }
                    }
                    else
                    {
                        componentsToDraw.Add(component);
                    }
                }
            }


            effect.Parameters["xEnableLighting"].SetValue(GameSettings.Default.CursorLightEnabled ? 1 : 0);
            graphicsDevice.RasterizerState = RasterizerState.CullNone;

            foreach (GameComponent component in componentsToDraw)
            {
                if (waterRenderMode == WaterRenderType.Reflective && !RenderReflective(component, waterLevel))
                {
                    continue;
                }
                component.Render(gameTime, chunks, camera, spriteBatch, graphicsDevice, effect, renderForWater);
            }

            effect.Parameters["xEnableLighting"].SetValue(0);
        }
Ejemplo n.º 13
0
        public bool IsVisibleToCamera(Body component, Camera camera)
        {
            BoundingFrustum frustrum = new BoundingFrustum(camera.ViewMatrix * camera.ProjectionMatrix);

            return(component.Intersects(frustrum));
        }
Ejemplo n.º 14
0
        public static List <Body> GenerateRoomComponentsTemplate(
            RoomData roomData,
            List <VoxelHandle> voxels,
            ComponentManager componentManager,
            Microsoft.Xna.Framework.Content.ContentManager content,
            GraphicsDevice graphics)
        {
            List <Body> components = new List <Body>();

            RoomTile[,] currentTiles = RoomTemplate.CreateFromRoom(
                voxels, componentManager.World.ChunkManager);
            float[,] rotations = new float[currentTiles.GetLength(0), currentTiles.GetLength(1)];
            foreach (RoomTemplate myTemp in roomData.Templates)
            {
                RoomTemplate template = new RoomTemplate(myTemp)
                {
                    Rotation = 0
                };
                for (int r = -2; r < currentTiles.GetLength(0) + 1; r++)
                {
                    for (int c = -2; c < currentTiles.GetLength(1) + 1; c++)
                    {
                        for (int rotation = 0; rotation < 5; rotation++)
                        {
                            template.PlaceTemplate(ref currentTiles, ref rotations, r, c);
                            template.RotateClockwise(1);
                        }
                    }
                }
            }

            var box        = VoxelHelpers.GetVoxelBoundingBox(voxels);
            int thingsMade = 0;

            for (int r = 0; r < currentTiles.GetLength(0); r++)
            {
                for (int c = 0; c < currentTiles.GetLength(1); c++)
                {
                    RoomTile tile             = currentTiles[r, c];
                    Body     createdComponent = null;
                    Vector3  noise            =
                        VertexNoise.GetNoiseVectorFromRepeatingTexture(box.Min +
                                                                       new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1));
                    switch (tile)
                    {
                    case RoomTile.Barrel:
                        createdComponent = EntityFactory.CreateEntity <Body>("Barrel", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.Wheat:
                        createdComponent = EntityFactory.CreateEntity <Body>("Wheat", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.Mushroom:
                        createdComponent = EntityFactory.CreateEntity <Body>("Mushroom", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.Table:
                        createdComponent = EntityFactory.CreateEntity <Body>("Table", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.Stove:
                        createdComponent = EntityFactory.CreateEntity <Body>("Stove", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.KitchenTable:
                        createdComponent = EntityFactory.CreateEntity <Body>("Cutting Board", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.Lamp:
                        createdComponent = EntityFactory.CreateEntity <Body>("Lamp", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.Flag:
                        createdComponent = EntityFactory.CreateEntity <Body>("Flag", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.Chair:
                        createdComponent = EntityFactory.CreateEntity <Body>("Chair", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.Books:
                        createdComponent = EntityFactory.CreateEntity <Body>(MathFunctions.RandEvent(0.5f) ? "Books" : "Potions", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.Anvil:
                        createdComponent = EntityFactory.CreateEntity <Body>("Anvil", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.Forge:
                        createdComponent = EntityFactory.CreateEntity <Body>("Forge", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.Target:
                        createdComponent = EntityFactory.CreateEntity <Body>("Target", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.Strawman:
                        createdComponent = EntityFactory.CreateEntity <Body>("Strawman", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.BookShelf:
                        createdComponent = EntityFactory.CreateEntity <Body>("Bookshelf", box.Min + new Vector3(r - 1 + 0.5f, 1.5f, c - 1 + 0.5f) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.Pillow:

                        for (int dx = -1; dx < 2; dx++)
                        {
                            for (int dy = -1; dy < 2; dy++)
                            {
                                if (Math.Abs(dx) + Math.Abs(dy) != 1 || r + dx < 0 || r + dx >= currentTiles.GetLength(0) || c + dy < 0 || c + dy >= currentTiles.GetLength(1))
                                {
                                    continue;
                                }

                                if (currentTiles[r + dx, c + dy] != RoomTile.Bed)
                                {
                                    continue;
                                }

                                createdComponent = EntityFactory.CreateEntity <Body>("Bed", box.Min + new Vector3(r - 1 + 0.5f, 1.5f, c - 1 + 0.5f) + noise);
                                break;
                            }
                        }


                        thingsMade++;
                        break;

                    default:
                        break;
                    }

                    if (createdComponent == null)
                    {
                        continue;
                    }
                    createdComponent.Tags.Add("Moveable");
                    createdComponent.Tags.Add("Deconstructable");
                    createdComponent.LocalTransform = Matrix.CreateRotationY(-(rotations[r, c] + (float)Math.PI * 0.5f)) * createdComponent.LocalTransform;
                    components.Add(createdComponent);
                }
            }
            return(components);
        }