Exemplo n.º 1
0
        public void EnemyTurn()
        {
            var npcs = EntityManager.GetEntitiesWithComponent <NPCComponent>();

            foreach (var npc in npcs)
            {
                var health = EntityManager.GetComponent <HealthComponent>(npc);

                if (health != null)
                {
                    if (health.Amount <= 0)
                    {
                        continue; // npc already died this turn
                    }
                }

                var pos = LocationSystem.GetPosition(npc);
                int distanceToPlayer = LocationSystem.GetDistance(Util.PlayerID, pos);

                // TODO: different ranges
                int range = 10;

                if (distanceToPlayer <= range)
                {
                    var nextPos = LocationSystem.StepTowards(Util.PlayerID, pos);
                    var dir     = (nextPos - pos).ToDirection();
                    //Log.Message(String.Format("{0}: Pos: {1}, NexPos: {2}, Dir: {3}", DescriptionSystem.GetNameWithID(npc), pos, nextPos, dir.ToString()));
                    RaiseEnemyMovedEvent(npc, dir);
                }
            }
        }
Exemplo n.º 2
0
        public void HandleLostHealth(int entity, float amountLost)
        {
            var healthComponent = EntityManager.GetComponent <HealthComponent>(entity);

            healthComponent.Amount -= amountLost;

            // ded
            if (healthComponent.Amount <= 0)
            {
                UISystem.Message(DescriptionSystem.GetNameWithID(entity) + " dies!");
                Util.CurrentFloor.RemoveCharacter(LocationSystem.GetPosition(entity));
                EntityManager.RemoveEntity(entity); // mark entity for deletion
            }

            //Log.Message("Entity " + entity + " HP: " + healthComponent.Amount + "|" + healthComponent.Max + " (-" + amountLost + ")");
        }