public override void Run(EntityManager.Entity entity) { if (!entity.HasComponent <WanderingMonster>()) { return; } if (!entity.HasComponent <Location>()) { return; } var actual = entity.GetComponent <Location>(); var desired = entity.GetComponent <Destination>(); var point = new Point(actual.X, actual.Y); if (_engine.GetPlayerViewable().Contains(point)) { desired = new Destination() { X = _engine.GetPlayerLocation().X, Y = _engine.GetPlayerLocation().Y }; entity.AddOrUpdateComponent((IComponent)desired); } else if (desired == null || desired == actual) { entity.RemoveComponent <Destination>(); var randCell = walkable[rand.Next(0, walkable.Count)]; desired = entity.AddComponent <Destination>(); desired.X = randCell.X; desired.Y = randCell.Y; } }
public override void Init() { _inputManager = _engineSystems.GetSystem <InputManager>(); _worldManager = _engineSystems.GetSystem <WorldManager>(); _entityManager = _engineSystems.GetSystem <EntityManager>(); _resourceManager = _engineSystems.GetSystem <ResourceManager>(); _uiManager = _engineSystems.GetSystem <UIManager>(); var world = _worldManager.NewWorld(); _worldManager.SetActiveWorld(world); entity = _entityManager.NewEntity(); entity.AddComponent(new RenderableComponent(_resourceManager.LoadModel("Models/2b.obj"))); world.AddChild(entity); entity.Transform.Scale = new Vector3(0.1f, 0.1f, 0.1f); var camera = world.AddCamera(new Camera(new Vector3(0.0f, 0.0f, -1.0f))); world.SetActiveCamera(camera); light = world.AddPointLight(new PointLight(new Color4(1.0f, 1.0f, 1.0f, 1.0f), new Color4(1.0f, 1.0f, 1.0f, 1.0f), Color4.White)); light.Transform.Position = new Vector3(5.0f, 5.0f, 5.0f); _uiManager.AddScreen("test", new TestScreen()); _uiManager.SetActiveScreen("test"); }
public override void Run(EntityManager.Entity entity) { if (!entity.HasComponent <Producer>()) { return; } var production = entity.GetComponent <Producer>(); foreach (var product in production.ProducedItems) { product.inprogress += product.rate; var wholeItems = (int)(product.inprogress); product.inprogress = -wholeItems; var inventory = entity.GetComponent <Inventory>(); var numToAdd = Math.Min(inventory.Size, wholeItems); for (int i = 0; i < numToAdd; i++) { var item = _em.CreateEntity(); item.AddComponent(new Item() { Type = product.product }); inventory.Items.Add(item); } } }
public override void Run(EntityManager.Entity entity) { if (!entity.HasComponent <Actor>()) { return; } var actor = entity.GetComponent <Actor>(); actor.Energy += actor.Speed; }
private void UpdateEntityTransform(EntityManager.Entity entity) { if (entity.Transform.IsDirty) { var transform = entity.Transform; var rotationQuat = Quaternion.FromEulerAngles(transform.EularRotation); var modelMatrix = Matrix4.Identity; var translationMatrix = Matrix4.CreateTranslation(transform.Position); var rotationXMatrix = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(transform.EularRotation.X)); var rotationYMatrix = Matrix4.CreateRotationY(MathHelper.DegreesToRadians(transform.EularRotation.Y)); var rotationZMatrix = Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(transform.EularRotation.Z)); var scaleMatrix = Matrix4.CreateScale(transform.Scale); var rotateTranslateMatrix = rotationXMatrix * rotationYMatrix * rotationZMatrix * translationMatrix; var right = -rotateTranslateMatrix.Row0.Xyz; var up = rotateTranslateMatrix.Row1.Xyz; var front = rotateTranslateMatrix.Row2.Xyz; modelMatrix = scaleMatrix * rotateTranslateMatrix; if (entity.Parent != null) { modelMatrix *= entity.Parent.Transform.ModelMatrix; } entity.Transform.RotationQuat = rotationQuat; entity.Transform.ModelMatrix = modelMatrix; entity.Transform.Right = right; entity.Transform.Up = up; entity.Transform.Front = front; entity.Transform.IsDirty = false; } foreach (var entityChild in entity.Children) { UpdateEntityTransform(entityChild); } }
public override void Run(EntityManager.Entity entity) { if (!entity.HasComponent <Attacked>()) { return; } var attacked = entity.GetComponent <Attacked>(); var alive = entity.GetComponent <Life>(); var attackStat = attacked.attacker.GetComponent <AttackStat>(); var defense = entity.GetComponent <DefenseStat>(); if (alive != null && attackStat != null) { string attackerName = attacked.attacker.GetComponent <Name>()?.NameString ?? entity.Id.ToString(); string victimName = entity.GetComponent <Name>()?.NameString ?? entity.Id.ToString(); var hit = _rand.Next(100); if (hit < attackStat.Accuracy) { var damage = _rand.Next(attackStat.Power) + 1; if (defense != null) { if (hit > defense.Chance) { _logger.Log($"{attackerName} hit {victimName} for {damage} damage."); alive.Health -= damage; } } } else { _logger.Log($"{attackerName} missed {victimName}."); } } entity.RemoveComponent <Attacked>(); }
public override void Run(EntityManager.Entity entity) { var life = entity.GetComponent <Life>(); if (life == null) { return; } if (life.Health < life.MaxHealth) { var regenRole = rand.Next(1000); if (regenRole < life.MaxHealth) { life.Health++; } } if (life.Health <= 0) { var nameComponent = entity.GetComponent <Name>(); string name = ""; if (nameComponent != null) { name = nameComponent.NameString; } _logger.Log($"{name}({entity.Id.ToString()}) has run out of hitpoints and died."); entity.RemoveComponent <Actor>(); entity.RemoveComponent <Life>(); entity.AddComponent <Dead>(); var glyph = entity.GetComponent <Glyph>(); glyph.glyph = CORPSE; } }
public void AddChild(EntityManager.Entity entity) { ChildEntities.Add(entity); }
public void EntityRemoved(EntityManager.Entity entity) { _renderableEntities.Remove(entity); }
public void EntityAdded(EntityManager.Entity entity) { _renderableEntities.Add(entity); }
public abstract void OnEntityRemoved(EntityManager.Entity entity);
public abstract void OnEntityAdded(EntityManager.Entity entity);
public void EntityRemoved(EntityManager.Entity entity) { _systemEntities.Remove(entity.Id); OnEntityRemoved(entity); }
public void EntityAdded(EntityManager.Entity entity) { _systemEntities.Add(entity.Id, entity); OnEntityAdded(entity); }