public override void Process(Entity e)
        {
            Health h = healthMapper.Get(e);

            if (h == null)
                return;

            if (e.HasComponent<Origin>())
            {
                Origin o = e.GetComponent<Origin>();
                Entity parent = o.Parent;

                if (!parent.HasComponent<Body>() || !parent.GetComponent<Health>().IsAlive)
                {
                    if (e.HasComponent<Health>())
                        e.GetComponent<Health>().SetHealth(e, 0);
                    else
                        e.Delete();
                }
            }

            if (!h.IsAlive)
            {
                h.SetHealth(e, 0);
                e.Delete();
            }
        }
 public bool UserClickedEntity(Entity user, Entity obj, int mouseClickType)
 {
     if (user.HasComponent(ComponentFamily.Hands))
     {
         //It's something with hands!
         if (mouseClickType == MouseClickType.Left)
         {
             if (obj.HasComponent(ComponentFamily.Item))
             {
                 //It's something with hands using their hands on an item!
                 return DoHandsToItemInteraction(user, obj);
             }
             if (obj.HasComponent(ComponentFamily.LargeObject))
             {
                 //It's something with hands using their hands on a large object!
                 return DoHandsToLargeObjectInteraction(user, obj);
             }
             if (obj.HasComponent(ComponentFamily.Actor))
             {
                 //It's something with hands using their hands on an actor!
                 return DoHandsToActorInteraction(user, obj);
             }
         }
         if (mouseClickType == MouseClickType.Right)
         {
             if (obj.HasComponent(ComponentFamily.Item))
             {
                 //It's something with hands using their hands on an item!
                 return DoHandsToItemInteraction(user, obj);
             }
             if (obj.HasComponent(ComponentFamily.LargeObject))
             {
                 //It's something with hands using their hands on a large object!
                 return DoHandsToLargeObjectInteraction(user, obj);
             }
             if (obj.HasComponent(ComponentFamily.Actor))
             {
                 //It's something with hands using their hands on an actor!
                 return DoHandsToActorInteraction(user, obj);
             }
         }
     }
     return false;
 }
        public override void Process(Entity e)
        {
            if (!e.HasComponent<Animation>())
                return;

            Sprite sprite = e.GetComponent<Sprite>();
            Animation anim = e.GetComponent<Animation>();

            if (anim.Type != AnimationType.None)
            {
                anim._Tick += world.Delta;

                if (anim._Tick >= anim.FrameRate)
                {
                    anim._Tick -= anim.FrameRate;
                    switch (anim.Type)
                    {
                        case AnimationType.Loop:
                            sprite.FrameIndex++; //Console.WriteLine("Animation happened");
                            break;

                        case AnimationType.ReverseLoop:
                            sprite.FrameIndex--;
                            break;

                        case AnimationType.Increment:
                            sprite.FrameIndex++;
                            anim.Type = AnimationType.None;
                            break;

                        case AnimationType.Decrement:
                            sprite.FrameIndex--;
                            anim.Type = AnimationType.None;
                            break;

                        case AnimationType.Bounce:
                            sprite.FrameIndex += anim.FrameInc;
                            if (sprite.FrameIndex == sprite.Source.Count() - 1)
                                anim.FrameInc = -1;

                            if (sprite.FrameIndex == 0)
                                anim.FrameInc = 1;
                            break;

                        case AnimationType.Once:
                            if (sprite.FrameIndex < sprite.Source.Count() - 1)
                                sprite.FrameIndex++;
                            else
                                anim.Type = AnimationType.None;
                            break;
                    }
                    e.RemoveComponent<Sprite>(e.GetComponent<Sprite>());
                    e.AddComponent<Sprite>(sprite);
                }
            }
        }
        public bool apply(Entity entity)
        {
            foreach (Type componentType in ComponentTypes) {
                if (!entity.HasComponent(componentType)) {
                    return false;
                }
            }

            return true;
        }
Beispiel #5
0
		public static CluwneSprite 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();
        }
Beispiel #6
0
 // Process a single entity if it has all required components.
 internal void ProcessEntity(Entity entity)
 {
     // Make sure it has all required components.
     foreach (var t in Types)
     {
         if (!entity.HasComponent(t))
         {
             return;
         }
     }
     Process(entity);
 }
Beispiel #7
0
        public void RegisterEntity (Entity entity)
        {
            if (!entity.HasComponent<TransformComponent>())
            {
                Logger.Log.AddLogEntry (LogLevel.Error, "AIManager",
                    "An error occured while registering new entity in AIManager: " +
                    "'{0}' has no TransformComponent!}");
            }

            lock (entities)
            {
                entities.Add (entity);
            }
        }
Beispiel #8
0
 public ItemStats(Entity item)
 {
     this.item = item;
     if (translate == null)
     {
         translate = new StatTranslator();
     }
     stats = new float[Enum.GetValues(typeof(ItemStatEnum)).Length];
     ParseSockets();
     ParseExplicitMods();
     if (item.HasComponent<Weapon>())
     {
         ParseWeaponStats();
     }
 }
        public override bool ApplyTo(Entity target, Entity sourceActor)
        {
            string sourceName = sourceActor.Name;
            string targetName = (sourceActor.Uid == target.Uid) ? "himself" : target.Name;
            if (!active)
            {
                IoCManager.Resolve<IChatManager>()
                    .SendChatMessage(ChatChannel.Damage, sourceName + " tries to attack " + targetName
                                                         + " with the " + owner.Owner.Name + ", but nothing happens!",
                                     null, sourceActor.Uid);
                return true;
            }

            var targetedArea = BodyPart.Torso;

            ComponentReplyMessage reply = sourceActor.SendMessage(this, ComponentFamily.Actor,
                                                                  ComponentMessageType.GetActorSession);

            if (reply.MessageType == ComponentMessageType.ReturnActorSession)
            {
                var session = (IPlayerSession) reply.ParamsList[0];
                targetedArea = session.TargetedArea;
            }
            else
                throw new NotImplementedException("Actor has no session or No actor component that returns a session");

            //Damage the item that is doing the damage.
            owner.Owner.SendMessage(this, ComponentMessageType.Damage, owner.Owner, 5, DamageType.Collateral);

            //Damage the target.
            if (target.HasComponent(ComponentFamily.Damageable))
            {
                target.SendMessage(this, ComponentMessageType.Damage, owner.Owner, damageAmount, damType, targetedArea);


                //string suffix = (sourceActor.Uid == target.Uid) ? " What a f*****g weirdo..." : "";
                IoCManager.Resolve<IChatManager>()
                    .SendChatMessage(ChatChannel.Damage,
                                     sourceName + " " + DamTypeMessage(damType) + " " + targetName + " in the " +
                                     BodyPartMessage(targetedArea) + " with a " + owner.Owner.Name + "!",
                                     null, sourceActor.Uid);
                return true;
            }
            return false;
        }
        public static Action<Entity> BigEnemyDeath(Entity e, EntityWorld _World, int points)
        {
            return ent =>
            {
                Vector2 poss = e.GetComponent<ITransform>().Position;
                _World.CreateEntityGroup("BigExplosion", "Explosions", poss, 10, ent, e.GetComponent<IVelocity>().LinearVelocity);

                int splodeSound = rbitch.Next(1, 5);
                SoundManager.Play("Explosion" + splodeSound.ToString());

                if (ent is Entity && (ent as Entity).Group != null && ((ent as Entity).Group == "Players" || (ent as Entity).Group == "Structures") && e.HasComponent<Crystal>())
                {
                    _World.CreateEntity("Crystal", e.GetComponent<ITransform>().Position, e.GetComponent<Crystal>().Color, e.GetComponent<Crystal>().Amount, e);
                    ScoreSystem.GivePoints(points);
                    _World.CreateEntity("Score", points.ToString(), poss).Refresh();
                }
            };
        }
        public override void Process(Entity e)
        {
            ITransform t = TransformMapper.Get(e);
            if (t == null)
                return;
            if (Vector2.Distance(t.Position, Vector2.Zero) > bound)
            {
                e.Delete();
                return;
            }

            if (e.HasComponent<Components.Timer>() && e.GetComponent<Components.Timer>().Update(world.Delta))
            {
                if (e.Tag == "Boss1")
                    Console.WriteLine("Whooops");

                e.Delete();
            }
        }
        public override void Process(Entity e)
        {
            Slow slow = slowMapper.Get(e);
            if (slow != null && slow != Slow.None) //If particle is slowing
            {
                slow.Elapsed--;
                if (slow.Elapsed <= 0)
                {
                    e.RemoveComponent<Slow>(slow);
                    IDamping d = dampingMapper.Get(e);
                    d.LinearDamping = 0;
                    d.AngularDamping = 0;
                    if (e.HasComponent<AI>())
                    {
                        AI a = e.GetComponent<AI>();
                        e.RemoveComponent<AI>(e.GetComponent<AI>());
                        a.Calculated = false;
                        e.AddComponent<AI>(a);
                    }

                    e.Refresh();
                    return;
                }
                IVelocity velocity = velocityMapper.Get(e);
                IDamping damping = dampingMapper.Get(e);

                //Slow particle angular speed
                if (velocity.AngularVelocity > slow.AngularTargetVelocity || damping.AngularDamping != slow.AngularSlowRate)
                    damping.AngularDamping = slow.AngularSlowRate;
                else
                    damping.AngularDamping = 0;

                //Slow particle linear speed
                if (velocity.LinearVelocity.Length() - slow.LinearTargetVelocity.Length() > 1 || damping.LinearDamping != slow.LinearSlowRate)
                    damping.LinearDamping = slow.LinearSlowRate;
                else
                    damping.LinearDamping = 0;

                SpawnFrostEffect(e);
            }
        }
        public override bool ApplyTo(Entity target, Entity sourceActor)
        {
            if (capacity <= 0)
            {
                return false;
                //TODO send the player using the item a message
            }
            var targetedArea = BodyPart.Torso;

            ComponentReplyMessage reply = sourceActor.SendMessage(this, ComponentFamily.Actor,
                                                                  ComponentMessageType.GetActorSession);

            if (reply.MessageType == ComponentMessageType.ReturnActorSession)
            {
                var session = (IPlayerSession) reply.ParamsList[0];
                targetedArea = session.TargetedArea;
            }
            else
                throw new NotImplementedException("Actor has no session or No actor component that returns a session");

            //Reduce the capacity.
            capacity -= 20;

            //Heal the target.
            if (target.HasComponent(ComponentFamily.Damageable))
            {
                target.SendMessage(this, ComponentMessageType.Heal, owner.Owner, 20, damType, targetedArea);

                string sourceName = sourceActor.Name;
                string targetName = (sourceActor.Uid == target.Uid) ? "his" : target.Name + "'s";
                //string suffix = (sourceActor.Uid == target.Uid) ? " What a f*****g weirdo..." : "";
                IoCManager.Resolve<IChatManager>()
                    .SendChatMessage(ChatChannel.Damage,
                                     sourceName + " applies the " + owner.Owner.Name + " to " + targetName + " " +
                                     BodyPartMessage(targetedArea) + ".",
                                     null, sourceActor.Uid);
                return true;
            }
            return false;
        }
        public void SetMaster(Entity m)
        {
            if (!m.HasComponent(ComponentFamily.Renderable))
                return;
            var mastercompo = m.GetComponent<SpriteComponent>(ComponentFamily.Renderable);
            //If there's no sprite component, then F**K IT
            if (mastercompo == null)
                return;

            mastercompo.AddSlave(this);
            master = mastercompo;
        }
Beispiel #15
0
        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;
        }
        /// <summary>
        ///  Cancels object placement mode for given mob.
        /// </summary>
        public void SendPlacementCancel(Entity mob)
        {
            NetOutgoingMessage message = IoCManager.Resolve<ISS14NetServer>().CreateMessage();
            message.Write((byte) NetMessage.PlacementManagerMessage);
            message.Write((byte) PlacementManagerMessage.CancelPlacement);

            if (mob.HasComponent(ComponentFamily.Actor))
            {
                var playerConnection = mob.GetComponent<IActorComponent>(ComponentFamily.Actor).GetPlayerSession().ConnectedClient;
                if (playerConnection != null)
                {
                    IoCManager.Resolve<ISS14NetServer>().SendMessage(message, playerConnection,
                                                                     NetDeliveryMethod.ReliableOrdered);
                }
            }
        }
Beispiel #17
0
        public bool RemoveEntity(Entity user, Entity inventory, Entity toRemove, InventoryLocation location = InventoryLocation.Any)
        {
            var comHands = inventory.GetComponent<HumanHandsComponent>(ComponentFamily.Hands);
            var comEquip = inventory.GetComponent<EquipmentComponent>(ComponentFamily.Equipment);
            var comInv = inventory.GetComponent<InventoryComponent>(ComponentFamily.Inventory);

            if ((location == InventoryLocation.Inventory) && comInv != null)
            {
                if (comInv.RemoveEntity(user, toRemove))
                {
                    //Do sprite stuff and detaching
                    return true;
                }
            }
            else if ((location == InventoryLocation.HandLeft || location == InventoryLocation.HandRight) && comHands != null)
            {
                if (comHands.RemoveEntity(user, toRemove))
                {
                    //Do sprite stuff and attaching
                    var toRemoveSlaveMover = toRemove.GetComponent<SlaveMoverComponent>(ComponentFamily.Mover);
                    if(toRemoveSlaveMover != null)
                    {
                        toRemoveSlaveMover.Detach();
                    }

                    if (toRemove.HasComponent(ComponentFamily.Renderable))
                    {
                        toRemove.GetComponent<IRenderableComponent>(ComponentFamily.Renderable).UnsetMaster();
                    }
                    toRemove.RemoveComponent(ComponentFamily.Mover);
                    toRemove.AddComponent(ComponentFamily.Mover, EntityManager.ComponentFactory.GetComponent<BasicMoverComponent>());
                    toRemove.GetComponent<BasicItemComponent>(ComponentFamily.Item).HandleDropped();
                    return true;
                }
            }
            else if ((location == InventoryLocation.Equipment || location == InventoryLocation.Any) && comEquip != null)
            {
                if (comEquip.RemoveEntity(user, toRemove))
                {
                    //Do sprite stuff and detaching
                    EquippableComponent eqCompo = toRemove.GetComponent<EquippableComponent>(ComponentFamily.Equippable);
                    if(eqCompo != null) eqCompo.currentWearer = null;
                    return true;
                }
            }
            else if (location == InventoryLocation.Any)
            {
                //Do sprite stuff and detaching
                bool done = false;

                if (comInv != null)
                    done = comInv.RemoveEntity(user, toRemove);

                if (comEquip != null && !done)
                    done = comEquip.RemoveEntity(user, toRemove);

                if (comHands != null && !done)
                    done = comHands.RemoveEntity(user, toRemove);

                return done;
            }

            return false;
        }
Beispiel #18
0
        public static Func<Body, bool> CreateBigGreen(Entity ent, float speed, float sideTime, float shootTime, float shotTime, float nonShoot, Sprite s, EntityWorld _World)
        {
            bool shot = false;
            float shotttt = 0f;
            float time = 0f;
            float ttttime = 0f;

            return
                (target) =>
                {
                    if (ttttime > sideTime)
                    {
                        ttttime = 0f;
                    }

                    Body b = ent.GetComponent<Body>();
                    float x = (float)(ConvertUnits.ToSimUnits(ScreenHelper.Viewport.Width / 2) * (Math.Cos(MathHelper.ToRadians(360 / sideTime) * ttttime)));

                    time += (float)_World.Delta / 1000;

                    if (shot)
                    {
                        if (shotttt > shotTime)
                        {
                            shotttt = 0f;

                            Vector2 offset = ConvertUnits.ToSimUnits(new Vector2(0, 25));

                            float rot = (float)Math.PI / 2;

                            Transform fireAt = new Transform(b.Position + offset, rot);

                            SoundManager.Play("Shot1");
                            _World.CreateEntity("BigGreenBullet", fireAt).Refresh();
                        }
                        if (time > shootTime)
                        {
                            time = 0f;
                            shot = false;
                        }
                    }
                    else
                    {
                        if (time > nonShoot)
                        {
                            time = 0f;
                            shot = true;
                        }
                    }

                    if (!ent.HasComponent<Slow>())
                    {
                        b.Position = new Vector2(x, b.Position.Y + speed * _World.Delta / 1000);
                        shotttt += (float)_World.Delta / 1000;
                        time += (float)_World.Delta / 1000;
                        ttttime += (float)_World.Delta / 1000;
                    }
                    else
                    {
                        handleSlow(ent, _World);
                    }
                    return false;
                };
        }
 /// <summary>
 ///  Places mob in tile placement mode with given settings.
 /// </summary>
 public void SendPlacementBeginTile(Entity mob, int range, string tileType, string alignOption)
 {
     var mapMgr = (MapManager) IoCManager.Resolve<IMapManager>();
     NetOutgoingMessage message = IoCManager.Resolve<ISS14NetServer>().CreateMessage();
     message.Write((byte) NetMessage.PlacementManagerMessage);
     message.Write((byte) PlacementManagerMessage.StartPlacement);
     message.Write(range);
     message.Write(true); //Is a tile.
     message.Write(tileType);
     message.Write(alignOption);
     if (mob.HasComponent(ComponentFamily.Actor))
     {
         var playerConnection = mob.GetComponent<IActorComponent>(ComponentFamily.Actor).GetPlayerSession().ConnectedClient;
         if (playerConnection != null)
         {
             IoCManager.Resolve<ISS14NetServer>().SendMessage(message, playerConnection,
                                                              NetDeliveryMethod.ReliableOrdered);
         }
     }
 }
Beispiel #20
0
        public static Func<Body, bool> CreateKillerGun(Entity ent, Entity origin, Vector2 offs, float shotTime, float shootTime, float nonShot, Sprite s, EntityWorld _World, bool shit)
        {
            bool shot = false;
            float shotttt = 0f;
            float time = 0f;

            return
                (target) =>
                {
                    Body b = ent.GetComponent<Body>();
                    Body b2 = origin.GetComponent<Body>();
                    b.RotateTo(Vector2.UnitX);
                    b.Position = b2.Position + offs;

                    if (shot)
                    {
                        if (shotttt > shotTime)
                        {
                            shotttt = 0f;

                            Vector2 offset = ConvertUnits.ToSimUnits(new Vector2(0, 50));

                            if (shit)
                                offset.X = ConvertUnits.ToSimUnits(6);
                            float rot = (float)Math.PI / 2;

                            Transform fireAt = new Transform(b.Position + offset, rot);

                            SoundManager.Play("Shot1");
                            _World.CreateEntity("KillerBullet", fireAt).Refresh();
                        }
                        if (time > shootTime)
                        {
                            time = 0f;
                            shot = false;
                        }
                    }
                    else
                    {
                        if (time > nonShot)
                        {
                            time = 0f;
                            shot = true;
                        }
                    }

                    if (!ent.HasComponent<Slow>())
                    {
                        shotttt += (float)_World.Delta / 1000;
                        time += (float)_World.Delta / 1000;
                    }

                    return false;
                };
        }
Beispiel #21
0
        /// <summary>
        /// Moves an entity from one game state to antother.
        /// </summary>
        /// <param name="entity">Entity.</param>
        /// <param name="source">Source.</param>
        /// <param name="destination">Destination.</param>
        public void MoveEntityToGameState(Entity entity, GameState source, GameState destination)
        {
            if (entity.HasComponent<ModelComponent>())
            {
                var model = entity.GetComponent<ModelComponent>().Model;
                source.Scene.RemoveObject(model);
                destination.Scene.AddObject(model);
            }

            if (entity.HasComponent<SkyboxComponent>())
            {
                var model = entity.GetComponent<SkyboxComponent>().Skybox;
                source.Scene.RemoveObject(model);
                destination.Scene.AddObject(model);
            }

            if (entity.HasComponent<PhysicsComponent> ())
            {
                var rigidBody = entity.GetComponent<PhysicsComponent> ().RigidBody;
                source.PhysicsManager.World.RemoveBody (rigidBody);
                destination.PhysicsManager.World.AddBody (rigidBody);
            }

            if (entity.HasComponent<LightComponent> ())
            {
                var light = entity.GetComponent<LightComponent> ().Light;
                source.Scene.RemoveLight (light);
                destination.Scene.AddLight (light);
            }

            entity.SwitchMessageProvider(source.MessageProxy, destination.MessageProxy);
        }
 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);
 }
Beispiel #23
0
        public static Func<Body, bool> CreateFlamer(Entity ent, float speed, Body bitch, Sprite s, EntityWorld _World)
        {
            int times = 0;
            return
                (target) =>
                {
                    ++times;
                    Body b = ent.GetComponent<Body>();
                    Vector2 distance = target.Position - b.Position;

                    if (distance != Vector2.Zero)
                        distance.Normalize();
                    distance *= speed;

                    if (target != null && target.LinearVelocity != distance && !ent.HasComponent<Slow>())
                    {
                        b.LinearVelocity = distance;
                    }

                    if (times % 10 == 0)
                    {
                        int range = s.CurrentRectangle.Width / 2;
                        float posx = -range;
                        Vector2 pos1 = bitch.Position + ConvertUnits.ToSimUnits(new Vector2(posx, 0));
                        Vector2 pos2 = bitch.Position - ConvertUnits.ToSimUnits(new Vector2(posx, 0));
                        float x = posx / range;

                        float y = 1;

                        Vector2 velocity1 = new Vector2(x, y);
                        velocity1.Normalize();
                        velocity1 *= 7;
                        Vector2 velocity2 = new Vector2(-velocity1.X, velocity1.Y);

                        _World.CreateEntity("Fire", pos1, velocity1).Refresh();
                        _World.CreateEntity("Fire", pos2, velocity2).Refresh();
                    }
                    return false;
                };
        }
Beispiel #24
0
        /// <summary>
        /// Creates a follow behavior
        /// </summary>
        /// <param name="speed"></param>
        /// <param name="rotateTo"></param>
        /// <returns></returns>
        public static Func<Body, bool> CreateFollow(Entity ent, float speed, bool rotateTo)
        {
            return
                (target) =>
                {
                    Entity e = target.UserData as Entity;
                    if (e.HasComponent<Health>() && ent.HasComponent<Health>() && !e.GetComponent<Health>().IsAlive)
                    {
                        ent.GetComponent<Health>().SetHealth(null, 0);
                        return false;
                    }

                    Body b = ent.GetComponent<Body>();
                    Vector2 distance = target.Position - b.Position;

                    if (distance != Vector2.Zero)
                        distance.Normalize();
                    distance *= speed;

                    if (target != null && target.LinearVelocity != distance && !ent.HasComponent<Slow>())
                    {
                        b.LinearVelocity = distance;
                        if (rotateTo)
                            b.RotateTo(distance);
                        else if (ent.Tag == null || !ent.Tag.Contains("Boss"))
                            b.AngularVelocity = (float)Math.PI * 4;
                    }

                    return false;
                };
        }
Beispiel #25
0
 private static bool IsVisualEntityToMerge(Entity entity)
 {
     return entity.IsStatic && entity.ComponentCount == 1 && entity.HasComponent<ModelEntityComponent>();
 }
Beispiel #26
0
        private Vector2 TryMove(Entity obstacle, Vector2 move)
        {
            if (obstacle == Entity || !obstacle.HasComponent<Collision>())
                return move;

            Collision that = obstacle.GetComponent<Collision>();

            if (!that.Model.HasFlag(CollisionModel.Box))
                return move;

            Vector2 diff = World.Difference(Position2D, that.Position2D);

            float al = Offset.X;
            float ar = al + Size.X;
            float at = Offset.Y;
            float ab = at + Size.Y;

            float bl = diff.X + that.Offset.X;
            float br = bl + that.Size.X;
            float bt = diff.Y + that.Offset.Y;
            float bb = bt + that.Size.Y;

            bool intersecting = al < br && ar > bl && at < bb && ab > bt;

            float ix = 0.0f, iy = 0.0f;

            if (intersecting) {
                float il = br - al;
                float ir = ar - bl;
                ix = (il < ir) ? il : -ir;

                float it = bb - at;
                float ib = ab - bt;
                iy = (it < ib) ? it : -ib;
            }

            if (intersecting) {
                if (Math.Abs(ix) <= Math.Abs(iy))
                    return new Vector2(ix, move.Y);
                else
                    return new Vector2(move.X, iy);
            }

            if (move.X > 0) {
                if (ar < bl && ar + move.X > bl) {
                    float dx = bl - ar;
                    float dy = (dx / move.X) * move.Y;

                    if (at + dy < bb && ab + dy > bt)
                        return new Vector2(dx, move.Y);
                }
            } else if (move.X < 0) {
                if (al > br && al + move.X < br) {
                    float dx = br - al;
                    float dy = (dx / move.X) * move.Y;

                    if (at + dy < bb && ab + dy > bt)
                        return new Vector2(dx, move.Y);
                }
            }

            if (move.Y > 0) {
                if (at < bt && at + move.Y > bt) {
                    float dy = bt - ab;
                    float dx = (dy / move.Y) * move.X;

                    if (al + dx < br && ar + dx > bl)
                        return new Vector2(move.X, dy);
                }
            } else if (move.Y < 0) {
                if (at > bb && at + move.Y < bb) {
                    float dy = bb - at;
                    float dx = (dy / move.Y) * move.X;

                    if (al + dx < br && ar + dx > bl)
                        return new Vector2(move.X, dy);
                }
            }

            return move;
        }
        public override void Process(Entity e)
        {
            //Process guns
            Inventory inv = invMapper.Get(e);
            Gun gun = inv.CurrentGun;
            ITransform transform = transformMapper.Get(e);

            gun.Elapsed += elapsedMilli;

            //Update power
            if (gun.Power > 1)
            {
                gun.UpdatePower(elapsedMilli);
            }

            if (e.Group.Equals("Players"))
            {
                ITransform t = e.GetComponent<ITransform>();

                int index;
                try
                {
                    index = int.Parse(e.Tag.Replace("P", "")) - 1;
                }
                catch
                {
                    return;
                }

                if (!e.HasComponent<AI>())
                {
                    PlayerIndex playerIndex = (PlayerIndex)index;
                    GamePadState padState = GamePad.GetState(playerIndex);
                    KeyboardState keyState = Keyboard.GetState();

                    if (padState.IsConnected)
                    {
                        if (padState.IsButtonDown(Buttons.RightTrigger))
                            gun.BulletsToFire = true;
                    }

                    else if (Mouse.GetState().LeftButton == ButtonState.Pressed)
                        gun.BulletsToFire = true;

                    if (!inv.BuildMode &&
                        (GamePad.GetState((PlayerIndex)index).IsButtonDown(Buttons.LeftTrigger) ||
                        (!GamePad.GetState((PlayerIndex)index).IsConnected && Mouse.GetState().RightButton == ButtonState.Pressed)))
                    {
                        world.CreateEntityGroup("BaseShot", "Bullets", e);
                        if (gun.Ammunition <= 0)
                            inv.ChangeGun(e, GunType.WHITE);
                    }
                }
            }

            //Fire bullets bro
            if (!inv.BuildMode && gun.Elapsed > gun.Interval / gun.Power && gun.BulletsToFire && gun.Ammunition > 0)
            {
                if (inv._type == InvType.Cannon)
                {
                    ITransform t = e.GetComponent<ITransform>();
                    world.CreateEntity("ExplosiveBullet", t.Position, new Vector2((float)Math.Cos(t.Rotation) * 8, (float)Math.Sin(t.Rotation) * 8), 1).Refresh();
                }
                else
                {
                    foreach (Vector2 offset in gun.GunOffsets)
                    {
                        float rotation = transform.Rotation;
                        float r_o = (float)Math.Atan2(offset.X, offset.Y);
                        float r_a = (float)Math.Atan2(offset.Y, offset.X);

                        Vector2 rotatedOffset = ConvertUnits.ToSimUnits(new Vector2((float)Math.Cos(r_a + rotation) * offset.Length(), (float)Math.Sin(r_a + rotation) * offset.Length()));
                        Transform fireAt = new Transform(transform.Position + rotatedOffset, rotation);

                        Entity bullet = world.CreateEntity(gun.BulletTemplateTag, fireAt);
                        gun.BulletVelocity = bullet.GetComponent<IVelocity>().LinearVelocity;
                        Bullet bb = bullet.GetComponent<Bullet>();
                        bb.Firer = e;
                        bullet.RemoveComponent<Bullet>(bullet.GetComponent<Bullet>());
                        bullet.AddComponent<Bullet>(bb);
                        bullet.Refresh();

                        int shot = r.Next(1, 3);
                        if (e.Group == "Structures" || e.Group == "Enemies")
                            SoundManager.Play("Shot" + shot.ToString(), .25f);
                        else
                            SoundManager.Play("Shot" + shot.ToString());
                    }

                    --gun.Ammunition;
                    if (gun.Ammunition == 0)
                    {
                        inv.CurrentGun = inv.WHITE;
                    }
                }

                gun.BulletsToFire = false;
                gun.Elapsed = 0;
            }
        }
Beispiel #28
0
        public static Func<Body, bool> CreateWarMachine(Entity ent, float speed, Body bitch, float sideTime, float shootTime, Sprite s, EntityWorld _World)
        {
            float shotTime = 0f;
            float time = 0f;

            return
                (target) =>
                {
                    if (time > sideTime)
                        time = 0f;

                    Body b = ent.GetComponent<Body>();
                    float x = (float)(ConvertUnits.ToSimUnits(ScreenHelper.Viewport.Width / 2) * (Math.Cos(MathHelper.ToRadians(360 / sideTime) * time)));

                    if (shotTime > shootTime)
                    {
                        shotTime = 0f;
                        Vector2 velocity1 = new Vector2(0, 1);
                        velocity1 *= 8f;

                        SoundManager.Play("Shot2");
                        _World.CreateEntity("ExplosiveBullet", bitch.Position, velocity1, 1, "reddownmissile").Refresh();
                    }

                    if (!ent.HasComponent<Slow>())
                    {
                        b.Position = new Vector2(x, b.Position.Y + speed * _World.Delta / 1000);
                        shotTime += (float)_World.Delta / 1000;
                        time += (float)_World.Delta / 1000;
                    }
                    else
                    {
                        handleSlow(ent, _World);
                    }
                    return false;
                };
        }
Beispiel #29
0
        public static Func<Body, bool> CreateKiller(Entity ent, float speed, float sideTime, EntityWorld world)
        {
            float time = 0f;

            return
                (target) =>
                {
                    if (time > sideTime)
                    {
                        time = 0f;
                    }

                    Body b = ent.GetComponent<Body>();
                    float x = (float)(ConvertUnits.ToSimUnits(ScreenHelper.Viewport.Width / 2) * (Math.Cos(MathHelper.ToRadians(360 / sideTime) * time)));

                    if (!ent.HasComponent<Slow>())
                    {
                        b.Position = new Vector2(x, b.Position.Y + speed * world.Delta / 1000);

                        time += (float)world.Delta / 1000;
                        ent.GetComponent<Children>().CallChildren(b);
                    }
                    else
                    {
                        handleSlow(ent, world);
                    }

                    return false;
                };
        }
Beispiel #30
0
        public bool AddEntity(Entity user, Entity inventory, Entity toAdd, InventoryLocation location = InventoryLocation.Any)
        {
            var comHands = inventory.GetComponent<HumanHandsComponent>(ComponentFamily.Hands);
            var comEquip = inventory.GetComponent<EquipmentComponent>(ComponentFamily.Equipment);
            var comInv = inventory.GetComponent<InventoryComponent>(ComponentFamily.Inventory);

            if ((location == InventoryLocation.Inventory) && comInv != null)
            {
                if (comInv.AddEntity(user, toAdd))
                {
                    //Do sprite stuff and attaching
                    return true;
                }
            }
            else if ((location == InventoryLocation.HandLeft || location == InventoryLocation.HandRight) && comHands != null)
            {
                if (comHands.AddEntity(user, toAdd, location))
                {
                    //Do sprite stuff and attaching
                    toAdd.RemoveComponent(ComponentFamily.Mover);
                    toAdd.AddComponent(ComponentFamily.Mover, EntityManager.ComponentFactory.GetComponent<SlaveMoverComponent>());
                    toAdd.GetComponent<SlaveMoverComponent>(ComponentFamily.Mover).Attach(inventory);
                    if (toAdd.HasComponent(ComponentFamily.Renderable) && inventory.HasComponent(ComponentFamily.Renderable))
                    {
                        toAdd.GetComponent<IRenderableComponent>(ComponentFamily.Renderable).SetMaster(inventory);
                    }
                    toAdd.GetComponent<BasicItemComponent>(ComponentFamily.Item).HandlePickedUp(inventory, location);
                    return true;
                }
            }
            else if ((location == InventoryLocation.Equipment || location == InventoryLocation.Any) && comEquip != null)
            {
                if (comEquip.AddEntity(user, toAdd))
                {
                    EquippableComponent eqCompo = toAdd.GetComponent<EquippableComponent>(ComponentFamily.Equippable);
                    eqCompo.currentWearer = user;
                    //Do sprite stuff and attaching.
                    return true;
                }
            }     
            else if (location == InventoryLocation.Any)
            {
                //Do sprite stuff and attaching.
                bool done = false;

                if (comInv != null)
                    done = comInv.AddEntity(user, toAdd);

                if (comEquip != null && !done)
                    done = comEquip.AddEntity(user, toAdd);

                if (comHands != null && !done)
                    done = comHands.AddEntity(user, toAdd, location);

                return done;
            }

            return false;
        }