Exemple #1
0
        /// <summary>
        /// Loops through each Poisoned Entity and applies poison damage. If the poison has expired, then
        /// the Poison Component is removed from the Entity.
        /// </summary>
        public override void Process()
        {
            /// <summary>
            /// The System where Attacks are registered.
            /// </summary>
            DamageSystem damageSystem = World.GetSystem <DamageSystem>();

            if (ReadyToApplyPoison(_lastTick, _tickInterval))
            {
                _lastTick = World.GameTime;

                CPoison poison;

                for (int i = 0; i < Entities.Count; i++)
                {
                    poison = World.GetComponent <CPoison>(Entities[i]);

                    if (!Utils.DurationReached(poison.TimeApplied, poison.Duration))
                    {
                        damageSystem.RegisterAttack(Entities[i], poison.Strength);
                    }
                    else
                    {
                        World.RemoveComponent <CPoison>(Entities[i]);
                    }
                }
            }
        }
        /// <summary>
        /// Performs an Attack for the specified Entity. The Entity's
        /// attack Type is evaluated and the appropriate attack is performed.
        /// </summary>
        /// <param name="entID">The Attacking Entity.</param>
        /// <typeparam name="T">The Team the Entity belongs to.</typeparam>
        protected void Attack <T>(ulong entID) where T : CTeam
        {
            CAI       AI = World.GetComponent <CAI>(entID);
            CDamage   damage;
            CPosition pos;
            CPosition targetPos;

            /// <summary>
            /// The AI has just attacked, so its cooldown is started.
            /// </summary>
            AI.LastAttackTime = World.GameTime;
            AI.AttackIsReady  = false;

            /// <summary>
            /// If the Attack Type is Melee, register an attack with the Damage System.
            /// If the Attack Type is Gun, create an Arrow Entity to travel towards the Target.
            /// </summary>
            switch (AI.AttackType)
            {
            case AttackType.Melee:
            {
                /// <summary>
                /// The System where Attacks are registered.
                /// </summary>
                DamageSystem damageSystem = World.GetSystem <DamageSystem>();

                damage = World.GetComponent <CDamage>(entID);
                damageSystem.RegisterAttack(AI.TargetID, damage.Damage);
                break;
            }

            case AttackType.Bow:
            {
                pos = World.GetComponent <CPosition>(entID);
                CBow bow = World.GetComponent <CBow>(entID);

                targetPos = World.GetComponent <CPosition>(AI.TargetID);

                EntityFactory.CreateArrow <T>(pos.Centre.X, pos.Centre.Y, bow, targetPos);
                break;
            }
            }
        }
        /// <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]);
                }
            }
        }