public override void Process(Entity e) { Animation a = e.GetComponent<Animation>(); if (a.Type == AnimationType.None) { e.Delete(); } }
public override void Process(Entity e) { Expires expires = expiresMapper.Get(e); expires.ReduceLifeTime(world.ElapsedTime); if (expires.IsExpired) { e.Delete(); } }
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(); }
public static void DamageTarget(Entity user, Entity target, int damage, double hitSuccess = 1) { EntityCreator.CreateDamageInfo(target, damage, hitSuccess); BattleStats stats = target.GetComponent<BattleStats>(); stats.Health.Decrease(damage); if (stats.IsDead && !target.GetComponent<Group>().IsHero) { target.Delete(); } }
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) { 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)); }
/// <summary>Processes the specified entity.</summary> /// <param name="entity">The entity.</param> public override void Process(Entity entity) { ExpiresComponent expiresComponent = this.expiresMapper.Get(entity); if (expiresComponent != null) { float ms = TimeSpan.FromTicks(this.EntityWorld.Delta).Milliseconds; expiresComponent.ReduceLifeTime(ms); if (expiresComponent.IsExpired) { entity.Delete(); } } }
/// <summary> /// Builds the crystal at a specified position and a color. /// </summary> /// <param name="e"></param> /// <param name="args">[0] = position; [1] = color; [2] amount</param> /// <returns></returns> public Entity BuildEntity(Entity e, params object[] args) { Vector2 pos = (Vector2)args[0]; Color color = (Color)args[1]; string source = "redcrystal"; e.AddComponent<Components.Timer>(new Components.Timer(10)); if (color == Color.Red) source = "redcrystal"; if (color == Color.Blue) source = "bluecrystal"; if (color == Color.Yellow) source = "yellowcrystal"; if (color == Color.Green) source = "greencrystal"; if (color == Color.Gray) source = "graycrystal"; Sprite s = e.AddComponent<Sprite>(new Sprite(_SpriteSheet, source, 0.2f + (float)crystals / 10000f)); Body b = e.AddComponent<Body>(new Body(_World, e)); b.IsBullet = true; FixtureFactory.AttachEllipse((float)ConvertUnits.ToSimUnits(s.CurrentRectangle.Width / 1.5), (float)ConvertUnits.ToSimUnits(s.CurrentRectangle.Height / 1.5), 3, 1f, b); b.Position = pos; b.BodyType = GameLibrary.Dependencies.Physics.Dynamics.BodyType.Dynamic; e.GetComponent<Body>().OnCollision += LambdaComplex.CrystalCollision(); if (args.Length > 4) { e.AddComponent<Crystal>(new Crystal(color, (int)args[2], true)); e.AddComponent<AI>(new AI((args[3] as Entity).GetComponent<Body>(), AI.CreateFollow(e, 5f, false))); } else if (args.Length > 3) { e.AddComponent<Crystal>(new Crystal(color, (int)args[2])); e.AddComponent<AI>(new AI((args[3] as Entity).GetComponent<Body>(), AI.CreateFollow(e, 5f, false))); } else { e.AddComponent<Crystal>(new Crystal(color, (int)args[2])); } e.Group = "Crystals"; e.AddComponent<AI>(new AI((args[3] as Entity).GetComponent<Body>(), //AI was severely lagging the game. (target) => { if ((target.UserData as Entity).HasComponent<Health>() && (target.UserData as Entity).GetComponent<Health>().IsAlive && target.Position != b.Position && (target.UserData as Entity).Group == "Players") { Vector2 distance = target.Position - b.Position; distance.Normalize(); b.LinearVelocity = distance * new Vector2(14); return false; } else { e.Delete(); return false; } })); e.Refresh(); return e; }
private void AdjustIntensity(Entity beamEntity, BeamComponent beamComponent) { // adjust intensity if (beamComponent.Intensity >= 1 && beamComponent.Beam.Lifetime > 0) { beamComponent.Age += (EntityWorld.Delta / 1000f); if (beamComponent.Age > beamComponent.Beam.Lifetime) { beamComponent.IsPowered = false; } } if (beamComponent.IsPowered) { if (beamComponent.Beam.IntensityFadeInTime > 0) { beamComponent.Intensity += (EntityWorld.Delta / beamComponent.Beam.IntensityFadeInTime) / 1000f; if (beamComponent.Intensity > 1) beamComponent.Intensity = 1; } else { beamComponent.Intensity = 1; } } else { if (beamComponent.Beam.IntensityFadeOutTime > 0) { beamComponent.Intensity -= (EntityWorld.Delta / beamComponent.Beam.IntensityFadeOutTime) / 1000f; if (beamComponent.Intensity < 0) beamComponent.Intensity = 0; } else { beamComponent.Intensity = 0; } if (beamComponent.Intensity <= 0) { beamEntity.Delete(); } } }
public override void Process(Entity entity) { //save command entity.Delete(); }
public override void Process(Entity entity) { entity.Delete(); }
public override void Process(Entity e) { AI ai = e.GetComponent<AI>(); switch (ai.Targeting) { case Targeting.Closest: ai.Target = ClosestTarget(e); break; case Targeting.Strongest: ai.Target = StrongestEntity(world.GetBodiesInArea(e.GetComponent<ITransform>().Position, ai.SearchRadius)).GetComponent<Body>(); break; case Targeting.Weakest: ai.Target = WeakestEntity(world.GetBodiesInArea(e.GetComponent<ITransform>().Position, ai.SearchRadius)).GetComponent<Body>(); break; } if (e.Group == "Crystals") { if ((ai.Target.UserData as Entity).DeletingState != true) { Vector2 distance = e.GetComponent<AI>().Target.Position - e.GetComponent<Body>().Position; distance.Normalize(); e.GetComponent<Body>().LinearVelocity = distance * new Vector2(7); } else { e.Delete(); //ai.Target = ClosestTarget(e); } } e.RemoveComponent<AI>(e.GetComponent<AI>()); e.AddComponent<AI>(ai); }