Ejemplo n.º 1
0
        public override bool Interact(string verb, IAdventurePlayer player)
        {
            var retVal = false;

            verb = verb.ToLower();
            var interaction = Interactions.FirstOrDefault(c => c.IsMatch(verb) && c.ShouldExecute());

            if (interaction != null)
            {
                var dwarf = GetDwarfIfPresent(player);

                if (dwarf != null)
                {
                    var killed = false;

                    foreach (var action in interaction.RegisteredInteractions)
                    {
                        killed = action.Do(player, this);
                    }

                    if (killed)
                    {
                        Game.Dungeon.TryGetLocation(Location.Nowhere, out var nowhere);
                        dwarf.CurrentLocation = nowhere;

                        if (player.EventRecord.ContainsKey(EventIds.Dwarves))
                        {
                            player.EventRecord[EventIds.Dwarves]++;
                        }

                        player.ChatClient.PostDirectMessage(player, "Your aim is true and the dwarf falls dead!" +
                                                            " The body disappears in a cloud of greasy smoke...");
                    }
                    else
                    {
                        player.ChatClient.PostDirectMessage(player, "The dwarf dodged out of harms way!");
                    }

                    retVal = true;
                }
                else
                {
                    player.ChatClient.PostDirectMessage(player,
                                                        "The axe doesn't seem to be of much use in this particular situation!");
                }

                var addItem = new AddToLocation(this);
                addItem.Do(player, null);
            }

            return(retVal);
        }
Ejemplo n.º 2
0
        public override void Give(IAdventurePlayer player, IAdventureItem item, IAdventureItem snake)
        {
            var removeItem = new RemoveFromInventory();

            removeItem.Do(player, item);

            // Place item in the Hall of the Mountain King
            Game.Dungeon.TryGetLocation(Location.HallOfMountainKing, out var location);
            var addToLocation = new AddToLocation(item, location);

            addToLocation.Do(player, item);

            player.ChatClient.PostDirectMessage(player, $"The snake hisses and snaps at you! It ignores the {item.Name}");
        }
Ejemplo n.º 3
0
        public override void Attack(IAdventurePlayer player, IAdventureItem troll, IAdventureItem weapon)
        {
            player.ChatClient.PostDirectMessage(player, "The snake hisses horribly and strikes it you!");

            if (weapon != null)
            {
                player.ChatClient.PostDirectMessage(player, $"You are so startled that you drop your {weapon.Name}!");

                var removeItem = new RemoveFromInventory();
                removeItem.Do(player, weapon);

                // Place item in the Hall of the Mountain King
                Game.Dungeon.TryGetLocation(Location.HallOfMountainKing, out var location);
                var addToLocation = new AddToLocation(weapon, location);
                addToLocation.Do(player, weapon);
            }

            return;
        }
Ejemplo n.º 4
0
        public override void Give(IAdventurePlayer player, IAdventureItem item, IAdventureItem troll)
        {
            // Destroy item
            var removeItem = new RemoveFromInventory();

            removeItem.Do(player, item);

            if (item.IsTreasure)
            {
                // Place item in the Troll's Cave
                Game.Dungeon.TryGetLocation(Location.TrollCave, out var location);

                var addToLocation = new AddToLocation(item, location);
                addToLocation.Do(player, item);

                // Troll will move away from the bridge
                player.ChatClient.PostDirectMessage(player,
                                                    $"The troll accepts your {item.Name}, appraises it with a critical eye, and retreats under its bridge!");
            }
            else
            {
                // The troll throws the item into the chasm
                player.ChatClient.PostDirectMessage(player,
                                                    $"The troll scowls at you and throws the {item.Name} into the chasm. 'Pay Troll!', it roars.");

                return;
            }

            Game.Dungeon.TryGetLocation(Location.SouthWestOfChasm, out var swOfChasm);
            Game.Dungeon.TryGetLocation(Location.NorthEastOfChasm, out var neOfChasm);
            RemoveTroll(player, troll, swOfChasm, neOfChasm);

            var clock = new StartClock("troll");

            clock.Do(player, troll);
        }
Ejemplo n.º 5
0
        public static void CheckForEvents(IAdventurePlayer player)
        {
            if (player.Statuses.Contains(PlayerStatus.IsDead))
            {
                return;
            }

            // Item Event processing...
            foreach (var carriedItem in player.Inventory.GetItems())
            {
                carriedItem.RunItemEvents(player, carriedItem);
            }


            if (player.CurrentLocation.Level.Equals(1))
            {
                if (!player.EventRecord.ContainsKey(EventIds.CaveOpen))
                {
                    // Cave is opened
                    player.EventRecord.Add(EventIds.CaveOpen, 1);
                    player.Score += 25;
                }
            }

            if (!player.EventRecord.ContainsKey(EventIds.CaveOpen))
            {
                return;
            }

            var game = player.CurrentLocation.Game;

            // Monsters act
            foreach (var manager in game.MonsterManagers)
            {
                manager.Act(game, player);
            }

            // Points for recovering stolen treasure
            if (!player.EventRecord.ContainsKey(EventIds.RecoveredStolenTreasure))
            {
                if (player.CurrentLocation.LocationId == Location.PirateChestCave)
                {
                    var found = game.Dungeon.TryGetLocation(Location.PirateChestCave, out var pirateChest);
                    if (found && pirateChest.Items.Where(x => x.IsTreasure).Count() > 0)
                    {
                        player.EventRecord.Add(EventIds.RecoveredStolenTreasure, 1);
                        player.Score += 10;
                    }
                }
            }

            // Handle dead dragon -> rotting dead dragon
            if (player.Clocks.ContainsKey(TheDragon) && (player.Clocks[TheDragon] > 10))
            {
                game.Dungeon.TryGetLocation(Location.SecretNorthEastCanyon, out var location);

                var remove = new RemoveFromLocation(ItemFactory.GetInstance(game, Item.DeadDragon), location);
                remove.Do(null, null);
                var addItem = new AddToLocation(ItemFactory.GetInstance(game, Item.RottingDeadDragon), location);
                addItem.Do(null, null);

                player.Clocks.Remove(TheDragon);
            }

            // Handle return of troll to guard its bridge
            if (player.Clocks.ContainsKey(TheTroll) && (player.Clocks[TheTroll] > 5))
            {
                var troll = ItemFactory.GetInstance(game, Item.Troll);

                game.Dungeon.TryGetLocation(Location.SouthWestOfChasm, out var swOfChasm);
                game.Dungeon.TryGetLocation(Location.NorthEastOfChasm, out var neOfChasm);
                var addTroll1 = new AddToLocation(troll, swOfChasm);
                var addTroll2 = new AddToLocation(troll, neOfChasm);
                addTroll1.Do(player, troll);
                addTroll2.Do(player, troll);

                // Block access to Troll Bridge
                var denyPassage1 = new RemoveDestination(game, Location.TrollBridge, swOfChasm.LocationId);
                var denyPassage2 = new RemoveDestination(game, Location.TrollBridge, neOfChasm.LocationId);
                denyPassage1.Do(player, troll);
                denyPassage2.Do(player, troll);

                player.Clocks.Remove(TheTroll);
            }
        }
Ejemplo n.º 6
0
        public void Act(IReadonlyAdventureGame game, IAdventurePlayer player)
        {
            if (player.CurrentLocation.Level == 1)
            {
                if (!player.EventRecord.ContainsKey(EventIds.Dwarves))
                {
                    if (DieRoller.SixSider(2))
                    {
                        player.EventRecord.Add(EventIds.Dwarves, 1);
                        player.ChatClient.PostDirectMessage(player, "A hunched dwarf just walked " +
                                                            "around a corner, saw you, threw a little axe at you (which missed), cursed, and ran away.");
                        var addItem = new AddToLocation(ItemFactory.GetInstance(game, Item.LittleAxe),
                                                        player.CurrentLocation);
                        addItem.Do(null, null);

                        return;
                    }
                }
            }

            if (player.EventRecord.ContainsKey(EventIds.Dwarves))
            {
                if (Monsters.Count == 0)
                {
                    SpawnDwarfs(player.CurrentLocation);
                    return;
                }

                var dwarfs = Monsters.Where(d => d.CurrentLocation != null).ToArray();

                foreach (var dwarf in dwarfs)
                {
                    if (dwarf.CurrentLocation.LocationId != Location.Nowhere)
                    {
                        // Dwarf is not dead
                        var possibleMoves = new List <Location>();

                        var movesAvailable = (dwarf.CurrentLocation.MonsterValidMoves.Count > 0)
                            ? dwarf.CurrentLocation.MonsterValidMoves
                            : dwarf.CurrentLocation.ValidMoves;

                        foreach (var move in movesAvailable)
                        {
                            var found = game.Dungeon.TryGetLocation(move.Destination, out var potentialMove);

                            if (found && (potentialMove.Level == 1) &&
                                (potentialMove.NumberOfExits > 1) &&
                                (move.Destination != dwarf.CurrentLocation.LocationId))
                            {
                                possibleMoves.Add(move.Destination);
                            }
                        }

                        // Has the dwarf seen the player?
                        if ((dwarf.HasSeenPlayer && (player.CurrentLocation.Level == 1)) ||
                            dwarf.PrevLocation.LocationId.Equals(player.CurrentLocation.LocationId) ||
                            dwarf.CurrentLocation.LocationId.Equals(player.CurrentLocation.LocationId))
                        {
                            // Stick with the player
                            dwarf.HasSeenPlayer   = true;
                            dwarf.PrevLocation    = dwarf.CurrentLocation;
                            dwarf.CurrentLocation = player.CurrentLocation;

                            continue;
                        }

                        dwarf.HasSeenPlayer = false;

                        // Random movement
                        var moveToLocation = 0;

                        if (possibleMoves.Count > 1)
                        {
                            var dieRoll = DieRoller.Percentage();
                            moveToLocation = (dieRoll * possibleMoves.Count) / 100;
                        }

                        game.Dungeon.TryGetLocation(possibleMoves[moveToLocation], out var newLocation);

                        dwarf.PrevLocation    = dwarf.CurrentLocation;
                        dwarf.CurrentLocation = newLocation;
                    }
                }

                var numDwarfs  = 0;
                var numAttacks = 0;

                foreach (var dwarf in Monsters.Where(d => d.CurrentLocation != null))
                {
                    if (player.CurrentLocation.LocationId.Equals(dwarf.CurrentLocation.LocationId))
                    {
                        // A dwarf is in the room with the player
                        numDwarfs++;
                        if (dwarf.CurrentLocation.LocationId.Equals(dwarf.PrevLocation.LocationId))
                        {
                            numAttacks++;
                        }
                    }
                }

                if (numDwarfs > 0)
                {
                    if (numDwarfs == 1)
                    {
                        player.ChatClient.PostDirectMessage(player, "There is a nasty-looking dwarf in the room with you!");

                        if (numAttacks == 1)
                        {
                            player.ChatClient.PostDirectMessage(player, "The dwarf lunges at you with a wickedly sharp knife!");
                        }
                    }
                    else
                    {
                        player.ChatClient.PostDirectMessage(player, $"There are {numDwarfs} nasty-looking dwarfs in the room with you!");

                        if (numAttacks > 0)
                        {
                            player.ChatClient.PostDirectMessage(player, "The dwarfs lunge at you with wickedly sharp knives!");
                        }
                    }

                    if (numAttacks > 0)
                    {
                        var numberOfHits = RollToHit(numAttacks);

                        if (numberOfHits > 0)
                        {
                            // Player is hit by the knife and dies?
                            var woundDescr = (numberOfHits == 1)
                                ? "A knife sinks into your flesh"
                                : ($"{numberOfHits} knives pierce your body");
                            player.ChatClient.PostDirectMessage(player, ($"{woundDescr} and you feel your ") +
                                                                "lifeblood ebbing away...");
                            player.Statuses.Add(PlayerStatus.IsDead);
                            game.EndOfGame(player);
                        }
                        else
                        {
                            player.ChatClient.PostDirectMessage(player, "Phew - missed! You deftly dodge out of the way of danger!");
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public void Act(IReadonlyAdventureGame game, IAdventurePlayer player)
        {
            if (Monsters.Count == 0)
            {
                SpawnPirates();
                return;
            }

            var pirates = Monsters.Where(d => d.CurrentLocation != null).ToArray();

            foreach (var pirate in pirates)
            {
                if (pirate.CurrentLocation.LocationId != Location.Nowhere)
                {
                    // Pirate is still active
                    var possibleMoves = new List <Location>();

                    var movesAvailable = (pirate.CurrentLocation.MonsterValidMoves.Count > 0)
                        ? pirate.CurrentLocation.MonsterValidMoves
                        : pirate.CurrentLocation.ValidMoves;

                    foreach (var move in movesAvailable)
                    {
                        var found = game.Dungeon.TryGetLocation(move.Destination, out var potentialMove);

                        if (found && (potentialMove.Level == 1) &&
                            (potentialMove.NumberOfExits > 1) &&
                            (move.Destination != pirate.CurrentLocation.LocationId))
                        {
                            possibleMoves.Add(move.Destination);
                        }
                    }

                    // Has the pirate seen the player?
                    if ((pirate.HasSeenPlayer && (player.CurrentLocation.Level == 1)) ||
                        pirate.CurrentLocation.LocationId.Equals(player.CurrentLocation.LocationId))
                    {
                        // Stick with the player
                        pirate.HasSeenPlayer   = true;
                        pirate.PrevLocation    = pirate.CurrentLocation;
                        pirate.CurrentLocation = player.CurrentLocation;

                        player.ChatClient.PostDirectMessage(player, "You hear a rustling noise behind you...");
                    }
                    else
                    {
                        pirate.HasSeenPlayer = false;
                    }

                    var playerLocation = player.CurrentLocation.LocationId;

                    if (possibleMoves.Contains(playerLocation) && !pirate.HasSeenPlayer)
                    {
                        // Pirate is 1 move away from the player
                        player.ChatClient.PostDirectMessage(player, "You hear a rustling noise in the darkness...");
                        continue;
                    }

                    if (!pirate.HasSeenPlayer)
                    {
                        // Random movement
                        var moveToLocation = 0;

                        if (possibleMoves.Count > 1)
                        {
                            var dieRoll = DieRoller.Percentage();
                            moveToLocation = (dieRoll * possibleMoves.Count) / 100;
                        }

                        game.Dungeon.TryGetLocation(possibleMoves[moveToLocation], out var newLocation);

                        pirate.PrevLocation    = pirate.CurrentLocation;
                        pirate.CurrentLocation = newLocation;

                        continue;
                    }

                    // Steal treasure?
                    if (player.Inventory.HasTreasure())
                    {
                        if (DieRoller.Percentage(49))
                        {
                            var found = game.Dungeon.TryGetLocation(Location.PirateChestCave, out var pirateChest);

                            if (found)
                            {
                                var treasures = player.Inventory.GetTreasures();

                                foreach (var treasure in treasures)
                                {
                                    player.Inventory.RemoveItem(treasure);
                                    var addItem = new AddToLocation(treasure, pirateChest);
                                    addItem.Do(null, null);
                                }

                                game.Dungeon.TryGetLocation(Location.Nowhere, out var nowhere);
                                pirate.CurrentLocation = nowhere;
                                pirate.PrevLocation    = nowhere;

                                player.ChatClient.PostDirectMessage(player, "...and a pirate jumps out of the darkness!");
                                player.ChatClient.PostDirectMessage(player, "Before you can react, he has swiped all of " +
                                                                    "your treasure and vanished into the gloom! As he leaves, you hear the pirate laughing: " +
                                                                    "'I'll hide this treasure in my maze!'");
                            }
                        }
                    }
                    else
                    {
                        pirate.HasSeenPlayer = false;
                    }
                }
            }
        }