Esempio n. 1
0
        public void Update()
        {
            if (Alive == false)
            {
                _level.RemoveNpc(this);
                return;
            }

            if (!_isAwareOfPlayer)
            {
                // When the enemy is not aware of the player
                // check the map to see if they are in field-of-view
                if (_map.IsInFov(X, Y))
                {
                    _isAwareOfPlayer = true;
                }
            }
            // Once the enemy is aware of the player
            // they will never lose track of the player
            // and will pursue relentlessly
            if (_isAwareOfPlayer)
            {
                if (Info.IsEnemy)
                {
                    _path.CreateFrom(X, Y);
                    // Use the CombatManager to check if the player located
                    // at the cell we are moving into
                    if (Global.CombatManager.IsPlayerAt(_path.FirstCell.X, _path.FirstCell.Y))
                    {
                        // Make an attack against the player
                        Global.CombatManager.Attack(this,
                                                    Global.CombatManager.FigureAt(_path.FirstCell.X, _path.FirstCell.Y));
                        SoundPlayer.PlaySound(Sound.MeleeAttack);
                    }
                    else
                    {
                        // Since the player wasn't in the cell, just move into as normal
                        _level.MoveNpc(this, X, Y, _path.FirstCell.X, _path.FirstCell.Y);
                        //X = _path.FirstCell.X;
                        //Y = _path.FirstCell.Y;
                    }
                }
            }
        }
Esempio n. 2
0
        public static Npc CreateNpc(FigureInfo info, Level level, int x, int y)
        {
            Npc npc = null;

            //Level level = LevelManager.GetCurrentLevel();
            //if (info.IsEnemy)
            {
                Texture2D tex = null;
                TileHelper.GetTileTexture(0, ref tex);
                var pathFromAggressiveEnemy =
                    new PathToPlayer(Global.Player, level.Map, tex);
                pathFromAggressiveEnemy.CreateFrom(x, y);

                npc = new Npc(level.Map, level, pathFromAggressiveEnemy)
                {
                    X      = x,
                    Y      = y,
                    Sprite = UIState._selectedTexture,
                    Damage = Dice.Parse("d3"),
                };

                npc.Info = info;

                if (npc.Info.IsMerchant)
                {
                    npc.Info.Inventory = new List <int>();
                    npc.Info.Inventory.Add(2569);
                    npc.Info.Inventory.Add(2569);
                    npc.Info.Inventory.Add(2569);
                }
                //level.AddNpc(npc);
            }
            //else
            //{
            //}

            return(npc);
        }