Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
        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;
            }
        }
Ejemplo n.º 3
0
        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>();
        }