Example #1
0
        public EntityBeliefs(Beliefs beliefs, Entity ent)
        {
            Beliefs = beliefs;
            Entity = ent;

            Type = ent.HasComponent<Survivor>() ? EntityType.Survivor
                : ent.HasComponent<Zombie>() ? EntityType.Zombie
                : ent.HasComponent<WoodPile>() ? EntityType.PlankPile
                : ent.HasComponent<WoodenBreakable>() ? EntityType.PlankSource
                : EntityType.Other;

            Update();
        }
 public override void OnAdded(Entity entity)
 {
     if (entity.HasComponent<ShipComponent>())
     {
         entity.AddComponent(new SpatialTokenComponent { Token = Ships.AllocateToken(entity) });
     }
 }
Example #3
0
 public static void DeleteLocalString(Entity entity, string key)
 {
     if (!entity.HasComponent<LocalData>()) return;
     LocalData data = entity.GetComponent<LocalData>();
     if (data.LocalStrings.ContainsKey(key))
         data.LocalStrings.Remove(key);
 }
        public override void Process(Entity e)
        {
            if (!e.HasComponent<FadingText>())
                return;

            e.GetComponent<FadingText>().Draw(spriteBatch, spriteFont);
        }
 private void OnRemoveEntity(Entity entity)
 {
     if (entity.HasComponent<ShipComponent>())
     {
         var token = entity.GetComponent<SpatialTokenComponent>().Token;
         token.Dispose();
     }
 }
 public override void OnUse(Entity targetEnt)
 {
     if (targetEnt.HasComponent(ComponentFamily.StatusEffects)) //Use component messages instead.
     {
         var statComp = (StatusEffectComp) targetEnt.GetComponent(ComponentFamily.StatusEffects);
         statComp.AddEffect("Bleeding", 10);
         parent.StartCooldown(this);
     }
 }
Example #7
0
 public override void Process(Entity entity)
 {
     if (!entity.HasComponent<TimeStamp>())
     {
         Int32 unixTimestamp = (Int32)(DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
         entity.AddComponent(new TimeStamp(unixTimestamp));
         entity.Refresh();
     }
 }
Example #8
0
        public override void Process(Entity e)
        {
            if (!e.HasComponent<AI>())
                return;

            AI ai = e.GetComponent<AI>();

            bool behavior;

            if (ai.Target != null)
            {
                if (World.EntityManager.GetEntity((ai.Target.UserData as Entity).Id) == null)
                    ai.Target = null;
                else if (!(!ai.Recalculate && ai.Calculated) && ai.Target != null && (ai.Target.UserData as Entity) != null && !(behavior = ai.Behavior(ai.Target))) //Run ai behavior, if behavior returns true look for new target.
                {
                    ai.Calculated = true;

                    if (ai.Target == null && e.Group != "Players" && e.Group != "Structures" && !e.Tag.Contains("Cannon"))
                    {
                        if (e.HasComponent<Health>())
                            e.GetComponent<Health>().SetHealth(null, 0);
                        else
                            e.Delete();
                    }

                    return;
                }
            }

            ai.Calculated = true;
            ai.Target = _FindNewTarget(ai, e.GetComponent<Body>());

            if (ai.Target == null && e.Group != "Players" && e.Group != "Structures" && !e.Tag.Contains("Boss"))
            {
                if (e.HasComponent<Health>())
                    e.GetComponent<Health>().SetHealth(null, 0);
                else
                    e.Delete();
            }
            else if (ai.Target == null && e.Group == "Players")
                ai.Behavior(null);

            e.Refresh();
        }
Example #9
0
        public override bool Matches(Entity entity)
        {
            for (int i = 0, indicesLength = indices.Length; i < indicesLength; i++) {
                if (entity.HasComponent(indices[i])) {
                    return false;
                }
            }

            return true;
        }
Example #10
0
 public static Sprite GetIconSprite(Entity entity)
 {
     if(entity.HasComponent(ComponentFamily.Icon))
     {
         var icon = entity.GetComponent<IconComponent>(ComponentFamily.Icon).Icon;
         if (icon == null)
             return IoCManager.Resolve<IResourceManager>().GetNoSprite();
         return icon;
     }
     return IoCManager.Resolve<IResourceManager>().GetNoSprite();
 }
Example #11
0
 public static bool GetIsHostile(Entity entity)
 {
     try
     {
         return entity.HasComponent<Hostile>();
     }
     catch (Exception)
     {
         return false;
     }
 }
        public void SetMaster(Entity m)
        {
            if (!m.HasComponent(ComponentFamily.Renderable))
                return;
            var mastercompo = m.GetComponent<IRenderableComponent>(ComponentFamily.Renderable);
            //If there's no sprite component, then FUCK IT
            if (mastercompo == null)
                return;

            mastercompo.AddSlave(this);
            master = mastercompo;
        }
Example #13
0
 public void HandleCollision(Entity entity, Entity other)
 {
     if (other.HasComponent<CollisionBehaviorComponent> ())
     {
         CollisionDispatcher dispatcher = other.GetComponent<CollisionBehaviorComponent> ()
             .Behavior as CollisionDispatcher;
         if (dispatcher != null)
         {
             dispatcher.DispatchCollision (this, other, entity);
         }
     }
 }
Example #14
0
 /// <summary>
 /// Add a Modifier script to an Entity, based on a code block (delegate) and a VectorFunction
 /// </summary>
 /// <param name="e">Entity to add modifier script to</param>
 /// <param name="scriptCode">Code block (delegate) that is the script</param>
 /// <param name="func">Function whose value will be passed in ScriptContext.FunctionValue to script</param>
 /// <returns></returns>
 public static VectorModifierScript AddModifier(Entity e, VectorModifierDelegate scriptCode, IVectorFunction func)
 {
     if (!e.HasComponent<ScriptComp>())
     {
         e.AddComponent(new ScriptComp());
         e.Refresh();
     }
     var sc = e.GetComponent<ScriptComp>();
     var script = new VectorModifierScript(scriptCode, func);
     sc.Add(script);
     return script;
 }
        public override void Process(Entity e)
        {
            if (!e.HasComponent<FadingText>())
                return;

            FadingText f = e.GetComponent<FadingText>();

            f.Update(world.Delta);

            if (f.Fraction() <= 0)
            {
                e.Delete();
            }
        }
        public override void Process(Entity e)
        {
            #region Float Effect

            if (e.HasComponent<Body>())
            {
                Body b = e.GetComponent<Body>();

                if (ConvertUnits.ToDisplayUnits(b.Position.Y) >= _MaxH)
                    _Direction = -_Speed;
                if (ConvertUnits.ToDisplayUnits(b.Position.Y) <= 0)
                    _Direction = _Speed;

                b.Position += new Microsoft.Xna.Framework.Vector2(b.Position.X - _X, ConvertUnits.ToSimUnits(_Direction));
            }

            #endregion Float Effect
        }
Example #17
0
        public override void Process(Entity ship)
        {
            var shipComponent = ship.GetComponent<ShipComponent>();
            if (ship.HasComponent<RigidBodyComponent>())
            {
                var rigidBody = ship.GetComponent<RigidBodyComponent>();
                Vector2 linearForce = shipComponent.LinearThrustVector;
                if (linearForce.X > 0) linearForce.X *= shipComponent.Ship.Handling.ForwardForce;
                else linearForce.X *= shipComponent.Ship.Handling.ManeuverForce;
                linearForce.Y *= shipComponent.Ship.Handling.ManeuverForce;
                rigidBody.Body.ApplyForce(rigidBody.Body.GetWorldVector(linearForce), rigidBody.Body.WorldCenter);
                rigidBody.Body.ApplyTorque(shipComponent.AngularTorque * shipComponent.Ship.Handling.AngularTorque);
            }          
            UpdateThrusters(ship);

            shipComponent.AngularTorque = 0;
            shipComponent.LinearThrustVector = Vector2.Zero;
        }
        public override void Process(Entity e)
        {
            try
            {
                if (!e.HasComponent<Bullet>())
                    return;
            }
            catch
            {
                return;
            }

            Particle particle = particleMapper.Get(e);
            Bullet bullet = bulletMapper.Get(e);

            world.RayCast(
                delegate(Fixture fix, Vector2 point, Vector2 normal, float fraction) //On hit
                {
                    ++bullet.collisionChecked;
                    if (fix.Body.UserData is Entity)
                    {
                        if ((fix.Body.UserData as Entity).HasComponent<Health>()
                            && (fix.Body.UserData as Entity).Group == bullet.DamageGroup)
                        { //Do damage
                            (fix.Body.UserData as Entity).GetComponent<Health>().SetHealth(bullet.Firer,
                                (fix.Body.UserData as Entity).GetComponent<Health>().CurrentHealth - bullet.Damage);
                            e.Delete(); //Remove bullet

                            if (bullet.OnBulletHit != null)
                            {
                                //Do bullet effects here........... Maybe a call back?{
                                bullet.OnBulletHit(fix.Body.UserData as Entity);
                            }

                            if (!(fix.Body.UserData as Entity).HasComponent<Health>() || (fix.Body.UserData as Entity).GetComponent<Health>().IsAlive)
                                world.CreateEntity("Explosion", 0f, particle.Position, fix.Body.UserData, 1, fix.Body.LinearVelocity, fix.Body.UserData).Refresh();
                        }
                    }
                    return 0;
                }, particle.Position, particle.Position + particle.LinearVelocity * new Vector2(World.Delta * .001f));
        }
Example #19
0
        public override void Process(Entity entity)
        {
            Placement placement = placementMapper.Get(entity);
            Velocity velocity = velocityMapper.Get(entity);

            if (entity.HasComponent<Acceleration>()) {
                Acceleration acceleration = accelerationMapper.Get(entity);

                if (acceleration.Boost > 0.0f) {
                    velocity.Direction = velocity.Direction * velocity.Speed + acceleration.Direction * acceleration.Boost;

                    Vector2 normalized = Vector2.Normalize(velocity.Direction);
                    velocity.Speed = Math.Min(velocity.Direction.Length() / normalized.Length(), 10.0f);
                    velocity.Direction = normalized;
                }
            }

            placement.Coordinates += velocity.Direction * velocity.Speed;

            placement.X = this.ApplyRange(placement.X, this.graphicsDevice.Viewport.Width);
            placement.Y = this.ApplyRange(placement.Y, this.graphicsDevice.Viewport.Height);
        }
Example #20
0
 private void RemoveFromOtherComps(Entity entity)
 {
     Entity holder = null;
     if (entity.HasComponent(ComponentFamily.Item))
         holder = ((BasicItemComponent) entity.GetComponent(ComponentFamily.Item)).CurrentHolder;
     if (holder == null && entity.HasComponent(ComponentFamily.Equippable))
         holder = ((EquippableComponent) entity.GetComponent(ComponentFamily.Equippable)).currentWearer;
     if (holder != null) holder.SendMessage(this, ComponentMessageType.DisassociateEntity, entity);
     else Owner.SendMessage(this, ComponentMessageType.DisassociateEntity, entity);
 }
Example #21
0
 public static void SetLocalValue(Entity entity, string key, float value)
 {
     if (!entity.HasComponent<LocalData>()) return;
     LocalData data = entity.GetComponent<LocalData>();
     data.LocalFloats[key] = value;
 }
Example #22
0
 public static string GetLocalString(Entity entity, string key)
 {
     if (!entity.HasComponent<LocalData>()) return string.Empty;
     LocalData data = entity.GetComponent<LocalData>();
     return data.LocalStrings.ContainsKey(key) ? data.LocalStrings[key] : string.Empty;
 }
Example #23
0
 public static float GetLocalNumber(Entity entity, string key)
 {
     if (!entity.HasComponent<LocalData>()) return 0.0f;
     LocalData data = entity.GetComponent<LocalData>();
     return data.LocalFloats.ContainsKey(key) ? data.LocalFloats[key] : 0.0f;
 }
        public void FreeMovementAndSprite(Entity slave)
        {
            var toRemoveSlaveMover = slave.GetComponent<SlaveMoverComponent>(ComponentFamily.Mover);
            if (toRemoveSlaveMover != null)
            {
                toRemoveSlaveMover.Detach();
            }

            if (slave.HasComponent(ComponentFamily.Renderable))
            {
                slave.GetComponent<IRenderableComponent>(ComponentFamily.Renderable).UnsetMaster();
            }
            slave.RemoveComponent(ComponentFamily.Mover);
            slave.AddComponent(ComponentFamily.Mover, EntityManager.ComponentFactory.GetComponent<BasicMoverComponent>());
            slave.GetComponent<BasicItemComponent>(ComponentFamily.Item).HandleDropped();
        }
 public void EnslaveMovementAndSprite(Entity master, Entity slave)
 {
     slave.RemoveComponent(ComponentFamily.Mover);
     slave.AddComponent(ComponentFamily.Mover, EntityManager.ComponentFactory.GetComponent<SlaveMoverComponent>());
     slave.GetComponent<SlaveMoverComponent>(ComponentFamily.Mover).Attach(master);
     if (slave.HasComponent(ComponentFamily.Renderable) && master.HasComponent(ComponentFamily.Renderable))
     {
         slave.GetComponent<IRenderableComponent>(ComponentFamily.Renderable).SetMaster(master);
     }
 }
        public bool PickUpEntity(Entity user, Entity obj)
        {
            HumanHandsComponent userHands = user.GetComponent<HumanHandsComponent>(ComponentFamily.Hands);
            BasicItemComponent objItem = obj.GetComponent<BasicItemComponent>(ComponentFamily.Item);

            if (userHands != null && objItem != null)
            {
                return AddEntity(user, user, obj, userHands.CurrentHand);
            }
            else if (userHands == null && objItem != null && obj.HasComponent(ComponentFamily.Inventory))
            {
                return AddEntity(user, user, obj, InventoryLocation.Inventory);
            }

            return false;
        }
Example #27
0
 public static void SetVelocityX(Entity entity, float x)
 {
     if (entity.HasComponent<Velocity>())
     {
         entity.GetComponent<Velocity>().X = x;
     }
 }
Example #28
0
 public static void SetFacing(Entity entity, Direction facing)
 {
     if (entity.HasComponent<Position>())
     {
         entity.GetComponent<Position>().Facing = facing;
     }
 }
Example #29
0
 public static void SetVelocityY(Entity entity, float y)
 {
     if (entity.HasComponent<Velocity>())
     {
         entity.GetComponent<Velocity>().Y = y;
     }
 }
        private void RenderThruster(Entity root, Entity thrusterEntity, ref Matrix parentMatrix)
        {
            var thrusterComponent = thrusterEntity.GetComponent<ThrusterComponent>();
            if (thrusterComponent.ThrustPercentage > 0 || thrusterComponent.Part.IsIdleModeOnZeroThrust)
            {
                var sprite = thrusterEntity.GetComponent<SpriteComponent>();
                var thruster = thrusterComponent.Part;
                var xform = thruster.Transform;
                Vector2 scale = xform.Scale;

                float colorAlpha = 0;

                if (thrusterComponent.Part.IsIdleModeOnZeroThrust)
                {
                    scale *= new Vector2(MathHelper.Clamp(thrusterComponent.ThrustPercentage, 0.3f, 1), 1);
                    colorAlpha = MathHelper.Clamp(thrusterComponent.ThrustPercentage, 0.6f, 1);
                }
                else
                {
                    scale *= new Vector2(MathHelper.Clamp(thrusterComponent.ThrustPercentage, 0, 1), 1);
                    colorAlpha = thrusterComponent.ThrustPercentage;
                }

                if (!thrusterEntity.HasComponent<EditorComponent>())
                {
                    // do thruster graphic wobble
                    var time = MathHelper.ToRadians((float)thrusterComponent.GetHashCode() + _totalTime);
                    var amount = (float)Math.Sin(((time * 1.5f) % MathHelper.Pi) * 1f);
                    scale += new Vector2(amount * 0.05f, amount * 0.03f);
                }

                var matrix = UtilityExtensions.GetMatrix(xform.Position, xform.Rotation, scale, xform.Origin) * parentMatrix;
                _batch.Draw(sprite, ref matrix, thruster.Color * colorAlpha);
                //sprite.Draw(batch: _batch, matrix: tempXform.Matrix * parentMatrix, color: thruster.Color * colorAlpha, effects: fx);
                scale *= 0.8f;
                matrix = UtilityExtensions.GetMatrix(xform.Position, xform.Rotation, scale, xform.Origin) * parentMatrix;
                _batch.Draw(sprite, ref matrix, Color.White * colorAlpha);
                //sprite.Draw(batch: _batch, matrix: tempXform.Matrix * parentMatrix, color: Color.White * colorAlpha, effects: fx);
            }
        }