protected override void ProcessEntity(Engine engine, Entity entity) { // 2 per 1000 milliseconds var amountPerSecond = 2; var people = entity.GetComponent<PeopleComponent>().Amount; entity.GetComponent<GoldComponent>().Amount += (engine.DeltaMs*amountPerSecond/1000.0) * people; }
private void Attach(int uid) { _master = Owner.EntityManager.GetEntity(uid); // TODO handle this using event queue so that these sorts of interactions are deferred until we can be sure the target entity exists _master.GetComponent<TransformComponent>(ComponentFamily.Transform).OnMove += HandleOnMove; Translate(_master.GetComponent<TransformComponent>(ComponentFamily.Transform).Position); }
/// <summary> /// Renders all entities with a sprite and a transform to the screen. /// </summary> /// <param name="e"></param> public override void Process(Entity e) { try { //Get sprite data and transform ITransform transform = e.GetComponent<ITransform>(); Sprite sprite = e.GetComponent<Sprite>(); if (sprite.Source != null) //Draw to sprite batch spriteBatch.Draw( sprite.SpriteSheet.Texture, ConvertUnits.ToDisplayUnits(transform.Position), sprite.CurrentRectangle, sprite.Color, transform.Rotation, sprite.Origin, sprite.Scale, SpriteEffects.None, sprite.Layer); } catch { e.Delete(); Console.WriteLine("Exception try-caught in RenderSystem"); } }
/// <summary> /// Updates all the positions by applying velocity. /// </summary> /// <param name="entity"></param> protected override void Process(Entity entity) { var pos = entity.GetComponent<PositionComponent>(); var vel = entity.GetComponent<VelocityComponent>(); var dif = vel.Value * (float)AlmiranteEngine.Time.Frame; pos.Set(dif.X + pos.X, dif.Y + pos.Y); }
public static void attack(Entity attacker, Entity target) { // calc dmg Weapon weapon = ((Equipment)attacker.GetComponent("Equipment")).MainHand; int predamage = RollManager.roll(weapon.Dice_Num, weapon.Dice_Sides, weapon.Roll_Mod); // subtract dmg reduction Armor armor = ((Equipment)target.GetComponent("Equipment")).Chest; int damage = predamage - armor.DmgReduction; // reduce hp and shoot messages Information targetInfo = target.GetComponent("Information") as Information; Information attackerInfo = attacker.GetComponent("Information") as Information; if (damage > 0) { target.DoAction("TakeDamage", new TakeDamageArgs(damage)); string message = String.Format("{0} swings at {1} for {2} damage.", attackerInfo.Username, targetInfo.Username, damage); MessageManager.Instance.addMessage(message); if (!((Hitpoints)target.GetComponent("Hitpoints")).Alive) MessageManager.Instance.addMessage(String.Format("{0} dies!", (target.GetComponent("Information") as Information).Username)); } else { string message = String.Format("{0} attacks {1}, but it glances off.", attackerInfo.Username, targetInfo.Username, damage); MessageManager.Instance.addMessage(message); } }
public override void Process(Entity e) { Body b = e.GetComponent<Body>(); Origin o = e.GetComponent<Origin>(); if (o != null) { Entity parent = o.Parent; Vector2 origin = parent.GetComponent<Body>().Position; float lastTime = elapsedSeconds; elapsedSeconds += 16 / 1000f; if (elapsedSeconds > orbitTime) { elapsedSeconds = 0f; } Vector2 oldPosition = origin + new Vector2((float)(ConvertUnits.ToSimUnits(Radius) * (Math.Cos(MathHelper.ToRadians(360 / orbitTime) * lastTime))), (float)(ConvertUnits.ToSimUnits(Radius) * (Math.Sin(MathHelper.ToRadians(360 / orbitTime) * lastTime)))); Vector2 newPosition = origin + new Vector2((float)(ConvertUnits.ToSimUnits(Radius) * (Math.Cos(MathHelper.ToRadians(360 / orbitTime) * elapsedSeconds))), (float)(ConvertUnits.ToSimUnits(Radius) * (Math.Sin(MathHelper.ToRadians(360 / orbitTime) * elapsedSeconds)))); //b.LinearVelocity = parent.GetComponent<Body>().LinearVelocity + (newPosition - oldPosition); b.Position = newPosition; } }
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 override void Process(Entity e) { Damage d = e.GetComponent<Damage>(); Health h = e.GetComponent<Health>(); if (d.Seconds <= 0) { e.RemoveComponent<Damage>(d); e.Refresh(); return; } d.Seconds -= (float)world.Delta / 1000; h.SetHealth(e, h.CurrentHealth - d.DamagePerSecond * (world.Delta / 1000)); Sprite s = e.GetComponent<Sprite>(); Vector2 offset; if (!e.Tag.Contains("Boss")) { double mes = Math.Sqrt(s.CurrentRectangle.Width * s.CurrentRectangle.Height / 4); offset = new Vector2((float)((r.NextDouble() * 2 - 1) * mes), (float)((r.NextDouble() * 2 - 1) * mes)); } else { offset = new Vector2((float)((r.NextDouble() * 2 - 1) * s.CurrentRectangle.Width / 2), (float)((r.NextDouble() * 2 - 1) * s.CurrentRectangle.Height / 2)); } world.CreateEntity("GREENFAIRY", e, ConvertUnits.ToSimUnits(offset)).Refresh(); }
// Updates the entities position based on it's velocity. protected override void Process(Entity entity) { var vel = entity.GetComponent<VelocityComponent>(); var transform = entity.GetComponent<TransformComponent>(); transform.Position += vel.Velocity * entityWorld.DeltaTime.Milliseconds; }
private void PlaceItem(Entity actor, Entity item) { var rnd = new Random(); actor.SendMessage(this, ComponentMessageType.DropItemInCurrentHand); item.GetComponent<SpriteComponent>(ComponentFamily.Renderable).drawDepth = DrawDepth.ItemsOnTables; //TODO Unsafe, fix. item.GetComponent<TransformComponent>(ComponentFamily.Transform).TranslateByOffset( new Vector2f(rnd.Next(-28, 28), rnd.Next(-28, 15))); }
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); } } }
protected override bool OnCollision(Entity Entity, EntityClassification Classification) { var sc = Entity.GetComponent<ScoreComponent>(); sc.Coins += Value; var ftc = Entity.GetComponent<FloatingTextComponent>(); if (ftc != null) ftc.Add("+" + Value.ToString(), Color.Gold); AudioManager.PlaySoundEffect("CoinPickup"); Parent.Dispose(); return true; }
private bool SpecialSquareTo(Entity mEntity, int mNextX, int mNextY, bool mNextSuccess, out bool mAbort) { mAbort = false; if (mEntity.GetComponent<TDCWielder>() == null) return true; if (!mNextSuccess) return true; if (!TrySheateEntity(mEntity)) return true; mEntity.GetComponent<TDCDirection>().Direction = TDCDirection.GetDirection(new TDVector2(mNextX, mNextY)); return true; }
/// <summary> /// /// </summary> /// <param name="e"></param> /// <param name="args">args[0] = Entity smasher, args[1] = Smasher loc</param> /// <returns></returns> public Entity BuildEntity(Entity e, params object[] args) { string spriteKey = "smasherball"; #region Body Body bitch = e.AddComponent<Body>(new Body(_World, e)); FixtureFactory.AttachEllipse(ConvertUnits.ToSimUnits(_SpriteSheet[spriteKey][0].Width / 2), ConvertUnits.ToSimUnits(_SpriteSheet[spriteKey][0].Height / 2), 20, 1f, bitch); Sprite s = new Sprite(_SpriteSheet, spriteKey, bitch, 1f, Color.White, 0.5f); e.AddComponent<Sprite>(s); bitch.BodyType = GameLibrary.Dependencies.Physics.Dynamics.BodyType.Dynamic; bitch.CollisionCategories = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat2 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat1; bitch.CollidesWith = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat6 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat1; bitch.OnCollision += LambdaComplex.BossCollision(); ++bitch.Mass; Entity smasher = (args[0] as Entity); float dist = ConvertUnits.ToSimUnits(20f); Vector2 pos = smasher.GetComponent<Body>().Position + new Vector2(0, dist); bitch.Position = pos; #endregion Body #region Animation if (s.Source.Count() > 1) e.AddComponent<Animation>(new Animation(AnimationType.Bounce, 10)); #endregion Animation #region Health e.AddComponent<Health>(new Health(1000000)).OnDeath += ent => { Vector2 poss = e.GetComponent<ITransform>().Position; _World.CreateEntityGroup("BigExplosion", "Explosions", poss, 10, e, e.GetComponent<IVelocity>().LinearVelocity); int splodeSound = rbitch.Next(1, 5); SoundManager.Play("Explosion" + splodeSound.ToString()); }; #endregion Health e.AddComponent<Origin>(new Origin(smasher)); e.Group = "Enemies"; e.Tag = "SmasherBall"; return e; }
public Entity BuildEntity(Entity e, params object[] args) { e.Tag = "Player"; Rectangle source = (Rectangle)args[1]; FixtureFactory.AttachCircle(ConvertUnits.ToSimUnits(source.Height/2),1f,e.AddComponent<Body>(new Body(_World, e))); e.GetComponent<Body>().BodyType = GameLibrary.Dependencies.Physics.Dynamics.BodyType.Dynamic; e.GetComponent<Body>().FixedRotation = true; e.AddComponent<Sprite>(new Sprite(args[0] as Texture2D, source, new Vector2(30,16),1f,Color.White,0.1f)); //Sprite return e; }
private bool SpecialSquareMove(Entity mEntity, int mNextX, int mNextY, bool mNextSuccess, out bool mAbort) { mAbort = false; if (!mNextSuccess) return true; var cWielder = mEntity.GetComponent<TDCWielder>(); if (cWielder == null) return true; TDLSounds.Play("SoundMimic"); if (Weapon != null) { var tempWeapon = cWielder.WeaponEntity; cWielder.SetWeapon(Weapon); cWielder.IsSheated = false; Weapon = tempWeapon; } else { cWielder.WeaponComponent.OnUnEquip.SafeInvoke(cWielder); Weapon = cWielder.WeaponEntity; cWielder.SetWeapon(null); } if (Weapon != null) Weapon.IsOutOfField = true; RecalculateWeaponSprite(); return true; }
private bool TrySheateEntity(Entity mEntity) { var cWielder = mEntity.GetComponent<TDCWielder>(); if (cWielder.WeaponEntity == null || !cWielder.WeaponEntity.HasTag(TDLTags.AffectedByOremites)) return false; cWielder.IsSheated = true; return true; }
private void BuildBullet(Entity entity) { var position = entity.GetComponent<Position>(); if (position == null) return; BulletTemplate.Create(Manager, position); }
private bool SpecialSquareFrom(Entity mEntity, int mNextX, int mNextY, bool mNextSuccess, out bool mAbort) { mAbort = false; var cWielder = mEntity.GetComponent<TDCWielder>(); if (!mNextSuccess || cWielder == null) return true; if (cWielder.WeaponEntity != null && !cWielder.WeaponEntity.HasTag(TDLTags.AffectedByOremites)) return true; cWielder.IsSheated = false; var directionComponent = mEntity.GetComponent<TDCDirection>(); if (directionComponent != null) directionComponent.Direction = TDCDirection.GetDirection(new TDVector2(mNextX, mNextY)); return true; }
private static bool ShouldMob(Entity self, EntityBeliefs ent) { var trace = new TraceLine(self.World); trace.Origin = ent.LastPos; trace.HitGeometry = true; trace.HitEntities = false; trace.HullSize = self.GetComponent<Collision>().Size; int survivors = 1; int zombies = 1; var it = new NearbyEntityEnumerator(self.World, ent.LastPos, MobRadius); while (it.MoveNext()) { var cur = it.Current; if (cur == self || cur == ent.Entity) continue; if (!cur.HasComponent<Human>() || !cur.HasComponent<Health>()) continue; if (!cur.GetComponent<Health>().IsAlive) continue; trace.Target = cur.Position2D; if (trace.GetResult().Hit) continue; if (cur.HasComponent<Survivor>()) { survivors += cur.GetComponent<Health>().Value; } else { zombies += cur.GetComponent<Health>().Value; } } return zombies <= MaxMobRatio * survivors; }
void Awake() { player = GameObject.FindGameObjectWithTag("Player").GetComponent<Entity>(); Inventory i = player.GetComponent<Inventory>(); i.onCardAdded.AddListener(CardAdded); i.onCardRemoved.AddListener(CardRemoved); }
//TODO: Totally a hacky method of doing this. /// <summary> /// Creates a explosions around the specified entity. /// </summary> public static void CreateAoEEntity(Entity entity) { var CPComponent = entity.GetComponent<CombatPropertiesComponent>(); var SEAComponent = entity.GetComponent<StatusEffectPropertiesComponent>(); var AttributesComponent = entity.GetComponent<AttributesComponent>(); var EquipmentComponent = entity.GetComponent<EquipmentComponent>(); var MovementComponent = entity.GetComponent<MovementComponent>(); var aoeOffset = new Vector2(CorvusExtensions.GetSign(MovementComponent.CurrentDirection) * CPComponent.AoEOffset.X, CPComponent.AoEOffset.Y); var aoe = CorvEngine.Components.Blueprints.EntityBlueprint.GetBlueprint("AreaOfEffect").CreateEntity(); aoe.Size = new Vector2(CPComponent.AoESize.X, CPComponent.AoESize.Y); var center = entity.Location.Center; aoe.Position = new Vector2(center.X - (aoe.Size.X / 2) + aoeOffset.X , center.Y - (aoe.Size.Y / 2) + aoeOffset.Y); entity.Scene.AddEntity(aoe); var spriteName = CPComponent.AoEName; var effect = CorvusGame.Instance.GlobalContent.LoadSprite(spriteName); var sc = aoe.GetComponent<SpriteComponent>(); sc.Sprite = effect; var anim = sc.Sprite.ActiveAnimation; sc.Sprite.PlayAnimation(anim.Name, TimeSpan.FromSeconds(CPComponent.AoEDuration)); //give it it's properties. if (EquipmentComponent.UseWeaponBonuses) { var ec = aoe.GetComponent<EquipmentComponent>(); ec.UseWeaponBonuses = true; ec.EquipWeapon(EquipmentComponent.CurrentWeapon); var se = aoe.GetComponent<StatusEffectPropertiesComponent>(); se.StatusEffectAttributes = EquipmentComponent.CurrentWeapon.Effect; } else { var se = aoe.GetComponent<StatusEffectPropertiesComponent>(); se.StatusEffectAttributes = SEAComponent.StatusEffectAttributes; } var cpc = aoe.GetComponent<CombatPropertiesComponent>(); cpc.CombatProperties = CPComponent.CombatProperties; var ac = aoe.GetComponent<AttributesComponent>(); ac.Attributes = AttributesComponent.Attributes; var aoec = aoe.GetComponent<AreaOfEffectComponent>(); aoec.Classification = CPComponent.AoEHitableEntities; AudioManager.PlaySoundEffect(CPComponent.AoESound); }
private bool DoHandsToActorInteraction(Entity user, Entity obj) { var hands = user.GetComponent<HumanHandsComponent>(ComponentFamily.Hands); if (hands.IsEmpty(hands.CurrentHand)) { return DoEmptyHandToActorInteraction(user, obj); } return DoApplyItemToActor(user, hands.GetEntity(hands.CurrentHand), obj); }
private void Place(GameManager game, Entity selected, Vector2f position) { selected.GetComponent<Position>().position = position + offset; Entity system = EntityFinder.GetEntityAt(game.GetEntitiesWith<SystemType>(), position); if (system != null) { game.Rules.PlaceSelected(system.GetComponent<SystemType>().info); } }
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(); } }; }
protected override bool OnCollision(Entity Entity, EntityClassification Classification) { var se = Entity.GetComponent<StatusEffectsComponent>(); if (se == null) return false; var seac = this.GetDependency<StatusEffectPropertiesComponent>(); se.ApplyStatusEffect(seac.StatusEffectAttributes); return true; }
protected override bool OnCollision(Entity Entity, EntityClassification Classification) { var ec = Entity.GetComponent<EquipmentComponent>(); if (ec == null) return false; var ac = this.GetDependency<AttributesComponent>(); var cpc = this.GetDependency<CombatPropertiesComponent>(); var wdc = this.GetDependency<WeaponPropertiesComponent>(); var seac = Parent.GetComponent<StatusEffectPropertiesComponent>(); ec.EquipWeapon(new Weapon(wdc.WeaponData, cpc.CombatProperties, ac.Attributes, seac.StatusEffectAttributes)); var ftc = Entity.GetComponent<FloatingTextComponent>(); ftc.Add(wdc.WeaponData.Name, Color.Black); CorvEngine.AudioManager.PlaySoundEffect("WeaponPickup"); return true; }
protected override bool OnCollision(Entity Entity, EntityClassification Classification) { var pc = Entity.GetComponent<PhysicsComponent>(); if (pc == null) return false; CorvEngine.AudioManager.PlaySoundEffect(LaunchSound); pc.Velocity = LaunchVelocity; return true; }
public FenFireAI (Entity entity, GameState state) { gameState = state; this.entity = entity; AIcomp = entity.GetComponent<ArtificialIntelligenceComponent>(); Provider = state.MessageProxy; Provider += this; }
public override void Process(Entity e) { Body b = e.GetComponent<Body>(); if (b.Position.Y > ConvertUnits.ToSimUnits(ScreenHelper.Viewport.Height) / 2 || Math.Abs(b.Position.X) > ConvertUnits.ToSimUnits(ScreenHelper.Viewport.Width) / 2) { e.Delete(); } }