/// <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> /// Evaluates the state of each Explosion Man. Two key events occur with Explosion Men: /// -When the Spawn Animation finishes, the explosion is created. /// -When the Explosion Animation finishes, the Entity is removed. /// This System checks the state and animation of each Explosion Man. /// </summary> public override void Process() { CExplosionMan explosion; CAnimation anim; CPosition pos; for (int i = Entities.Count - 1; i >= 0; i--) { anim = World.GetComponent <CAnimation>(Entities[i]); /// <summary> /// If one of the two key events are happening. /// </summary> if (SwinGame.AnimationEnded(anim.Anim)) { explosion = World.GetComponent <CExplosionMan>(Entities[i]); /// <summary> /// If not ready to explode, the Spawn animation has just finished. /// Therefore, create the explosion. /// </summary> if (!explosion.ReadyToExplode) { explosion.ReadyToExplode = true; pos = World.GetComponent <CPosition>(Entities[i]); /// <summary> /// Update size details as the Entity is now an Explosion. /// </summary> pos.Width = EntityFactory.EXPLOSION_SIZE; pos.Height = EntityFactory.EXPLOSION_SIZE; /// <summary> /// Adjust position details so explosion is in centre of the cell. /// </summary> CollisionCheckSystem collisions = World.GetSystem <CollisionCheckSystem>(); Point2D cellPos = collisions.CentreOfCell(explosion.TargetCell); pos.X = cellPos.X - (pos.Width / 2); pos.Y = cellPos.Y - (pos.Height / 2); /// <summary> /// Create explosion animation. /// </summary> anim.Img = SwinGame.BitmapNamed("Explosion"); SwinGame.AssignAnimation(anim.Anim, "Explode", anim.AnimScript); /// <summary> /// Add new components to the Entity. /// </summary> World.AddComponent(Entities[i], new CDamagesOnImpact(false)); World.AddComponent(Entities[i], new CDamage(EntityFactory.EXPLOSION_DAMAGE)); World.AddComponent(Entities[i], new CCollidable()); } else //If ready to explode, the Explode animation has just finished. Therefore, remove the Entity. { World.RemoveEntity(Entities[i]); } } } }
public override void Process() { /// <summary> /// Mouse Position is evaluated once per frame and passed to relevant methods. /// </summary> Point2D pt = SwinGame.MousePosition(); PlayerSystem playerSystem = World.GetSystem <PlayerSystem>(); if (SwinGame.KeyDown(KeyCode.AKey)) { playerSystem.BuyArcher(); } if (SwinGame.KeyTyped(KeyCode.EKey)) { playerSystem.BuyExplosionMan(); } if (SwinGame.MouseClicked(MouseButton.LeftButton)) { playerSystem.CastPoisonZone(pt); } if (SwinGame.MouseClicked(MouseButton.RightButton)) { playerSystem.CastFreezingBullet(pt); } }
/// <summary> /// Checks if the Entity is within the System. If it is, its loot component is extracted /// and its contents sent to the fetched Player Gold System. /// </summary> /// <param name="entID">The Entity to remove.</param> public override void Remove(ulong entID) { if (HasEntity(entID)) { CLoot lootToGive = World.GetComponent <CLoot>(entID); PlayerSystem playerSystem = World.GetSystem <PlayerSystem>(); playerSystem.GiveLoot(lootToGive); } base.Remove(entID); }
/// <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]); } } }