/// <summary>
        /// Registers a collision between two passed in Entities by adding a
        /// reference to the other Entity in its Collision Component. If the Entity
        /// does not have a Collision Component, one is added.
        /// </summary>
        /// <param name="entOne">The first Entity in the collision.</param>
        /// <param name="entTwo">The second Entity in the collision..</param>
        private void RegisterCollision(ulong entOne, ulong entTwo)
        {
            CCollision entOneCollision;
            CCollision entTwoCollision;

            //Handle collision for the first Entity
            if (!World.EntityHasComponent(entOne, typeof(CCollision)))
            {
                World.AddComponent(entOne, new CCollision(entTwo));
            }
            else
            {
                entOneCollision = World.GetComponent <CCollision>(entOne);
                entOneCollision.AddCollision(entTwo);
            }

            //Handle collision for the second Entity
            if (!World.EntityHasComponent(entTwo, typeof(CCollision)))
            {
                World.AddComponent(entTwo, new CCollision(entOne));
            }
            else
            {
                entTwoCollision = World.GetComponent <CCollision>(entTwo);
                entTwoCollision.AddCollision(entOne);
            }
        }
        public override void Process()
        {
            CCollision collision;
            CFrozen    freezeZoneFrozen;
            CFrozen    collidedFrozen;

            List <int> deadFreezeEffects = new List <int>();

            /// <summary>
            /// This loop represents each Freeze Zone.
            /// Backwards loop to allow Entities to be removed while looping.
            /// </summary>
            for (int i = Entities.Count - 1; i >= 0; i--)
            {
                freezeZoneFrozen = World.GetComponent <CFrozen>(Entities[i]);
                collision        = World.GetComponent <CCollision>(Entities[i]);

                /// <summary>
                /// This loop represents each Entity colliding with the Freeze Zone.
                /// </summary>
                for (int j = 0; j < collision.Count; j++)
                {
                    //If not already Frozen, add a Frozen Component.
                    if (!World.EntityHasComponent(collision[j], typeof(CFrozen)))
                    {
                        //Don't freeze projectiles
                        if (!World.EntityHasComponent(collision[j], typeof(CProjectile)))
                        {
                            World.AddComponent(collision[j], new CFrozen(freezeZoneFrozen.Duration, World.GameTime));
                        }

                        if (!World.EntityHasComponent(collision[j], typeof(CGotStatusEffect)))
                        {
                            World.AddComponent(collision[j], new CGotStatusEffect(typeof(CFrozen)));
                        }
                        else
                        {
                            CGotStatusEffect statusEffects = World.GetComponent <CGotStatusEffect>(collision[j]);
                            statusEffects.AddEffect(typeof(CFrozen));
                        }
                    }
                    else //If already Frozen, refresh the duration.
                    {
                        collidedFrozen             = World.GetComponent <CFrozen>(collision[i]);
                        collidedFrozen.TimeApplied = World.GameTime;
                    }
                }

                /// <summary>
                /// Freeze Zone only lasts for one frame to apply Frozen Components.
                /// Each Freeze Zone is removed from the World once its collisions are processed.
                /// </summary>
                World.RemoveEntity(Entities[i]);
            }
        }
        /// <summary>
        /// Checks the collisions of each Entity which deals damage on impact. If it has collided with something containing a Health Component,
        /// an Attack is registered with the Damage System.
        /// </summary>
        public override void Process()
        {
            /// <summary>
            /// The System where Attacks are registered.
            /// </summary>
            DamageSystem damageSystem = World.GetSystem <DamageSystem>();

            for (int i = Entities.Count - 1; i >= 0; i--)
            {
                CDamage          damage;
                CCollision       collision;
                CDamagesOnImpact dmgOnImp;

                collision = World.GetComponent <CCollision>(Entities[i]);

                /// <summary>
                /// Apply damage to the first Entity the Entity has collided with that still exists in
                /// the World and also has a Health Component. If none are found, the Arrow remains live.
                /// </summary>
                for (int j = 0; j < collision.Count; j++)
                {
                    if (World.HasEntity(collision[j]))
                    {
                        if (World.EntityHasComponent(collision[j], typeof(CHealth)))
                        {
                            damage = World.GetComponent <CDamage>(Entities[i]);
                            damageSystem.RegisterAttack(collision[j], damage.Damage);
                        }
                    }
                }

                /// <summary>
                /// If the Entity is set to die after impact, remove it from the World.
                /// </summary>
                dmgOnImp = World.GetComponent <CDamagesOnImpact>(Entities[i]);

                if (dmgOnImp.DiesAfterImpact)
                {
                    World.RemoveEntity(Entities[i]);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Checks each Entity colliding with each Poison Zone. If the Entity does not have
        /// a Poison Component, then a Poison Component and a GotStatusEffect Component are added.
        /// Otherwise, the Entity's Poison Component duration is refreshed.
        /// </summary>
        public override void Process()
        {
            CPoison    poisonEffect;
            CPoison    targetPoisonEffect;
            CCollision collision;

            /// <summary>
            /// This loop represents each Poison Zone.
            /// </summary>
            for (int i = 0; i < Entities.Count; i++)
            {
                poisonEffect = World.GetComponent <CPoison>(Entities[i]);
                collision    = World.GetComponent <CCollision>(Entities[i]);

                /// <summary>
                /// This loop represents each Entity colliding with the Poison Zone.
                /// </summary>
                for (int j = 0; j < collision.Count; j++)
                {
                    if (!World.EntityHasComponent(collision[j], typeof(CPoison)))
                    {
                        World.AddComponent(collision[j], new CPoison(poisonEffect.Strength, poisonEffect.Duration, World.GameTime));

                        if (!World.EntityHasComponent(collision[j], typeof(CGotStatusEffect)))
                        {
                            World.AddComponent(collision[j], new CGotStatusEffect(typeof(CPoison)));
                        }
                        else
                        {
                            CGotStatusEffect statusEffects = World.GetComponent <CGotStatusEffect>(collision[j]);
                            statusEffects.AddEffect(typeof(CPoison));
                        }
                    }
                    else //If entity already has a Poison Component, refresh its duration.
                    {
                        targetPoisonEffect             = World.GetComponent <CPoison>(collision[j]);
                        targetPoisonEffect.TimeApplied = World.GameTime;
                    }
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Determines whether or not the passed in Entity meets the requirements of the System.
        /// This checks against both the Include and Exclude Type Lists.
        /// </summary>
        /// <returns><c>true</c> if the Entity passes the filter, <c>false</c> otherwise.</returns>
        /// <param name="entID">The Entity to check.</param>
        public bool EntityPassesFilter(ulong entID)
        {
            //Check Entity has all components the System will operate on.
            foreach (Type t in Include)
            {
                if (!World.EntityHasComponent(entID, t))
                {
                    return(false);
                }
            }

            //Check Entity does NOT have any components the System will NOT operate on.
            foreach (Type t in Exclude)
            {
                if (World.EntityHasComponent(entID, t))
                {
                    return(false);
                }
            }

            //The Entity meets the requirements and will be added to the System.
            return(true);
        }
예제 #6
0
        /// <summary>
        /// Updates and Draws each Animation in each Entity's StatusAnimation Component.
        /// If an Entity no longer has the required Component for the StatusAnimation, it
        /// is removed from the StatusAnimations Component.
        /// </summary>
        public override void Process()
        {
            CStatusAnimations statusAnims;
            CStatusAnimation  anim;
            CPosition         pos;

            /// <summary>
            /// This loop represents each Entity with a Status Animations Component.
            /// </summary>
            for (int i = 0; i < Entities.Count; i++)
            {
                statusAnims = World.GetComponent <CStatusAnimations>(Entities[i]);
                pos         = World.GetComponent <CPosition>(Entities[i]);

                /// <summary>
                /// This loop represents each Status Animation inside the Status Animations Component.
                /// Backwards loop to allow Status Animations to be removed while looping.
                /// </summary>
                for (int j = statusAnims.Anims.Count - 1; j >= 0; j--)
                {
                    anim = statusAnims[j];

                    if (World.EntityHasComponent(Entities[i], anim.LinkedComponent))
                    {
                        float x = pos.X + anim.XOffset;
                        float y = pos.Y + anim.YOffset;

                        SwinGame.DrawAnimation(anim.Anim, anim.Img, x, y);
                        SwinGame.UpdateAnimation(anim.Anim);
                    }
                    else
                    {
                        statusAnims.Anims.RemoveAt(j);
                    }
                }
            }
        }