Esempio n. 1
0
        public bool Do(IAdventurePlayer player, IAdventureItem item)
        {
            var location = player.CurrentLocation;

            if (item is null)
            {
                player.ChatClient.PostDirectMessage(player, $"You cannot see a {item.Name} here!");
                return(false);
            }

            if (!item.IsLocked)
            {
                player.ChatClient.PostDirectMessage(player, $"The {item.Name} is already unlocked!");
                return(false);
            }

            if (player.Inventory.GetItems().All(i => i.ItemId != item.ItemIdToUnlock))
            {
                player.ChatClient.PostDirectMessage(player, $"You need to find something with which to unlock the {item.Name}!");
                return(false);
            }

            player.ChatClient.PostDirectMessage(player, $"You try your {item.ItemIdToUnlock} ...");

            item.IsLocked = false;
            player.ChatClient.PostDirectMessage(player, $"The {item.Name} is now unlocked!");
            return(true);
        }
Esempio n. 2
0
        public override void Invoke(IAdventurePlayer player, ChatCommandEventArgs e)
        {
            var args = e.ArgsAsList;

            if (args.Count == 1)
            {
                player.ChatClient.PostDirectMessage(player, "What would you like to attack?");
                return;
            }
            else
            {
                var victim = args[1].ToLower();

                if (player.Here(victim))
                {
                    var target = player.CurrentLocation.Items.FirstOrDefault(i => i.IsMatch(victim));

                    if (target == null)
                    {
                        var contents = player.CurrentLocation.Items.SelectMany(i => i.Contents);
                        target = contents.FirstOrDefault(i => i.IsMatch(victim));
                    }

                    if (target != null)
                    {
                        target.Attack(player, target);
                    }
                }
            }
        }
Esempio n. 3
0
        public bool MoveAffectedByEncumberedStatus(IAdventurePlayer player, IPlayerMove move)
        {
            if (player.Statuses.Contains(PlayerStatus.IsEncumbered))
            {
                player.ChatClient.PostDirectMessage(player, "You are currently encumbered.");

                if (move.Moves.Contains("up"))
                {
                    player.ChatClient.PostDirectMessage(player, "You are unable to move upward!");
                    player.ChatClient.PostDirectMessage(player, "*" + player.CurrentLocation.Name + "*");
                    return(true);
                }

                if (move.Moves.Contains("down"))
                {
                    player.ChatClient.PostDirectMessage(player, "You slip and fall! All that weight drags you down. " +
                                                        "Your lamp smashes and darkness engulfs you...");
                    player.Statuses.Add(PlayerStatus.IsDead);
                    _game.EndOfGame(player);
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 4
0
        public override void Invoke(IAdventurePlayer player, ChatCommandEventArgs e)
        {
            var moveTo = Location.SecretEastWestCanyon;

            _ = _game.Dungeon.TryGetLocation(moveTo, out var place);

            if (!player.EventRecord.ContainsKey(EventIds.CaveOpen))
            {
                player.EventRecord.Add(EventIds.CaveOpen, 1);
                player.Score += 25;
            }

            if (!player.EventRecord.ContainsKey(EventIds.Dwarves))
            {
                player.EventRecord.Add(EventIds.Dwarves, 1);
                var addItem = new AddToInventory();
                addItem.Do(player, ItemFactory.GetInstance(_game, Item.LittleAxe));

                // Treasures
                addItem.Do(player, ItemFactory.GetInstance(_game, Item.Coins));
                addItem.Do(player, ItemFactory.GetInstance(_game, Item.Diamond));
            }

            player.CurrentLocation = place;
            player.ChatClient.PostDirectMessage(player, "Teleported to *" + player.CurrentLocation.Name + "*");
        }
Esempio n. 5
0
        public bool Do(IAdventurePlayer player, IAdventureItem item)
        {
            var location = player.CurrentLocation;

            if (item is null)
            {
                player.ChatClient.PostDirectMessage(player, $"You cannot see a {item.Name} here!");
                return(false);
            }

            if (item.IsOpen)
            {
                player.ChatClient.PostDirectMessage(player, $"The {item.Name} is already open!");
                return(false);
            }

            if (item.IsLocked)
            {
                player.ChatClient.PostDirectMessage(player, $"The {item.Name} is locked!");
                return(false);
            }

            player.ChatClient.PostDirectMessage(player, $"You have opened the {item.Name}.");
            item.IsOpen = true;
            return(true);
        }
Esempio n. 6
0
        public override bool Interact(string verb, IAdventurePlayer player)
        {
            verb = verb.ToLower();
            var interaction = Interactions.FirstOrDefault(c => c.IsMatch(verb) && c.ShouldExecute());

            if (interaction != null)
            {
                if (interaction.Verbs.Contains("use"))
                {
                    var success = Game.Dungeon.TryGetLocation(Location.FissureWest, out var fissureWest);

                    if (success)
                    {
                        interaction.RegisteredInteractions
                        .Add(new AddToLocation(ItemFactory.GetInstance(Game, Item.CrystalBridge), fissureWest));
                    }
                }

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

                return(true);
            }

            return(false);
        }
Esempio n. 7
0
        public override void Invoke(IAdventurePlayer player, ChatCommandEventArgs e)
        {
            var canMove = false;

            if (player.CurrentLocation.LocationId.Equals(Location.Building))
            {
                var moveTo = Location.Y2;
                canMove = _game.Dungeon.TryGetLocation(moveTo, out var place);
                player.CurrentLocation = place;
            }
            else if (player.CurrentLocation.LocationId.Equals(Location.Y2))
            {
                var moveTo = Location.Building;
                canMove = _game.Dungeon.TryGetLocation(moveTo, out var place);
                player.CurrentLocation = place;
            }

            if (canMove)
            {
                player.ChatClient.PostDirectMessage(player, "From out of thin air, a hollow booming voice says 'Plugh!'");
                return;
            }

            player.ChatClient.PostDirectMessage(player, "Nothing happens...");
        }
Esempio n. 8
0
        public void EndOfGame(IAdventurePlayer player)
        {
            var thePlayer = player as AdventurePlayer;

            if (player.Statuses.Contains(PlayerStatus.IsDead))
            {
                player.ChatClient.PostDirectMessage(player, "You have been killed, another victim of the perils of Colossal Cave.");
            }

            var found = Dungeon.TryGetLocation(Locations.Location.Building, out var building);

            if (found)
            {
                var numberOfTreasuresRecovered = building.Items.Where(x => x.IsTreasure).Count();
                thePlayer.Score += 15 * numberOfTreasuresRecovered;
            }

            if (player.EventRecord.ContainsKey(EventIds.Dwarves))
            {
                thePlayer.Score += 5 * player.EventRecord[EventIds.Dwarves];
            }

            player.ChatClient.PostDirectMessage(player,
                                                $"You earned {thePlayer.Score} during your Adventure in {player.Moves} moves.");

            _players.Remove(thePlayer);
        }
Esempio n. 9
0
        public bool Do(IAdventurePlayer player, IAdventureItem item)
        {
            item.IsActive = false;
            player.ChatClient.PostDirectMessage(player, _message);

            return(true);
        }
Esempio n. 10
0
        public override bool Interact(string verb, IAdventurePlayer player)
        {
            if (!player.Inventory.GetItems().Any(x => x.ItemId.Equals(ItemId)))
            {
                var msg = new Display($"You are not carrying a {ItemId}!");
                msg.Do(player);
                return(true);
            }

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

            if (interaction != null)
            {
                if (interaction.Verbs.Contains("light"))
                {
                    if (IsActive)
                    {
                        var msg = new Display($"Your{ItemId} is already lit!");
                        msg.Do(player);
                        return(true);
                    }
                }

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

                return(true);
            }

            return(false);
        }
Esempio n. 11
0
        public override void Invoke(IAdventurePlayer player, ChatCommandEventArgs e)
        {
            var canMove = false;

            if (player.CurrentLocation.LocationId.Equals(Location.Building))
            {
                var moveTo = Location.Debris;
                canMove = _game.Dungeon.TryGetLocation(moveTo, out var place);
                player.CurrentLocation = place;
            }
            else if (player.CurrentLocation.LocationId.Equals(Location.Debris))
            {
                var moveTo = Location.Building;
                canMove = _game.Dungeon.TryGetLocation(moveTo, out var place);
                player.CurrentLocation = place;
            }

            if (canMove)
            {
                player.ChatClient.PostDirectMessage(player, "You suddenly feel dizzy and space seems to warp around you!");
                return;
            }

            player.ChatClient.PostDirectMessage(player, "Nothing happens...");
        }
Esempio n. 12
0
 public void AddPlayerStatusCondition(IAdventurePlayer player, PlayerStatus status)
 {
     if (status != PlayerStatus.None &&
         !player.Statuses.Contains(status))
     {
         player.Statuses.Add(status);
     }
 }
Esempio n. 13
0
 public void RemovePlayerStatusCondition(IAdventurePlayer player, PlayerStatus status)
 {
     if (status != PlayerStatus.None &&
         player.Statuses.Contains(status))
     {
         player.Statuses.Remove(status);
     }
 }
Esempio n. 14
0
        public override void Invoke(IAdventurePlayer player, ChatCommandEventArgs e)
        {
            var canMove = false;

            if (e.ArgsAsList.Count == 2)
            {
                var direction = e.ArgsAsList[1].ToLower();

                if (player.CurrentLocation.IsDark)
                {
                    if (!player.Statuses.Contains(PlayerStatus.HasLight))
                    {
                        player.ChatClient.PostDirectMessage(player, "It is pitch black! If you move around, you'll probably fall into a chasm or something...");
                    }
                }

                if (player.CurrentLocation.ValidMoves.Any(d => d.IsMatch(direction)))
                {
                    var move     = player.CurrentLocation.ValidMoves.First(d => d.IsMatch(direction));
                    var moveTo   = move.Destination;
                    var moveText = move.MoveText;

                    canMove = _game.Dungeon.TryGetLocation(moveTo, out var place);

                    if (canMove)
                    {
                        if (MoveAffectedByEncumberedStatus(player, move))
                        {
                            return;
                        }

                        player.PriorLocation   = player.CurrentLocation;
                        player.CurrentLocation = place;
                        player.Moves++;

                        if (player.Clocks != null && player.Clocks.Count > 0)
                        {
                            foreach (var key in player.Clocks.Keys)
                            {
                                player.Clocks[key]++;
                            }
                        }

                        if (!string.IsNullOrWhiteSpace(moveText))
                        {
                            player.ChatClient.PostDirectMessage(player, moveText);
                        }

                        player.ChatClient.PostDirectMessage(player, "*" + player.CurrentLocation.Name + "*");

                        return;
                    }
                }
            }

            player.ChatClient.PostDirectMessage(player, "You cannot go in that direction! Try *look* so see where you might go.");
            player.ChatClient.PostDirectMessage(player, "*" + player.CurrentLocation.Name + "*");
        }
Esempio n. 15
0
        public bool Do(IAdventurePlayer player, IAdventureItem item)
        {
            if (!player.Clocks.ContainsKey(_clockName))
            {
                player.Clocks.Add(_clockName, 0);
            }

            return(true);
        }
Esempio n. 16
0
        public bool Do(IAdventurePlayer player, IAdventureItem item)
        {
            if (player.CurrentLocation.LocationId.Equals(_atLocation))
            {
                player.ChatClient.PostDirectMessage(player, _message);
            }

            return(true);
        }
Esempio n. 17
0
        public override void Invoke(IAdventurePlayer player, ChatCommandEventArgs e)
        {
            var canSee      = true;
            var description = new StringBuilder("*" + player.CurrentLocation.Name + "*");

            if (player.CurrentLocation.IsDark)
            {
                if (!player.Statuses.Contains(PlayerStatus.HasLight))
                {
                    canSee = false;
                }
            }

            if (canSee)
            {
                description.AppendLine();
                description.AppendLine($"You are {player.CurrentLocation.LongDescription}");

                var otherPlayersHere = _game.Players.Where(p => p.CurrentLocation.Name == player.CurrentLocation.Name &&
                                                           p.Id != player.Id).ToList();

                if (otherPlayersHere.Any())
                {
                    description.AppendLine();
                    foreach (var otherPlayer in otherPlayersHere)
                    {
                        description.AppendLine($"\t{otherPlayer.UserName} is also here.");
                    }
                }

                description.AppendLine();

                foreach (var item in player.CurrentLocation.Items)
                {
                    description.AppendLine(item.IsEndlessSupply
                        ? $"There are several {item.PluralName} here."
                        : $"There is a {item.Name} here.");

                    if (item.Contents.Any() && (item.IsOpen || item.IsTransparent))
                    {
                        description.AppendLine($"The {item.Name} contains:");

                        foreach (var content in item.Contents)
                        {
                            description.AppendLine($"\tA {content.Name}");
                        }
                    }
                }
            }
            else
            {
                description.AppendLine();
                description.AppendLine("It is pitch black, you cannot see a thing!");
            }

            player.ChatClient.PostDirectMessage(player, description.ToString());
        }
Esempio n. 18
0
        public bool Do(IAdventurePlayer player, IAdventureItem item = null)
        {
            if (player.Statuses.Contains(_status))
            {
                return(false);
            }

            player.Statuses.Add(_status);
            return(true);
        }
Esempio n. 19
0
        public bool Do(IAdventurePlayer player, IAdventureItem item = null)
        {
            if (!player.EventRecord.ContainsKey(_eventId))
            {
                return(false);
            }

            player.EventRecord[_eventId] += _value;
            return(true);
        }
Esempio n. 20
0
        private void RemoveTroll(IAdventurePlayer player, IAdventureItem troll, IAdventureLocation swOfChasm, IAdventureLocation neOfChasm)
        {
            var removeTroll1 = new RemoveFromLocation(troll, swOfChasm);
            var removeTroll2 = new RemoveFromLocation(troll, neOfChasm);

            removeTroll1.Do(player, troll);
            removeTroll2.Do(player, troll);

            AllowPassage(player);
        }
Esempio n. 21
0
        public bool Do(IAdventurePlayer player, IAdventureItem item)
        {
            if (!player.Inventory.Has(item.ItemId))
            {
                player.Inventory.AddItem(item);
                return(true);
            }

            return(false);
        }
Esempio n. 22
0
 private void CreateNewInstance(IAdventurePlayer player, IAdventureItem locationItem)
 {
     if (locationItem.ContainerRequired())
     {
         player.Inventory.AddItemToContainer(ItemFactory.GetInstance(_game, locationItem.ItemId),
                                             locationItem.MustBeContainedIn);
     }
     else
     {
         player.Inventory.AddItem(ItemFactory.GetInstance(_game, locationItem.ItemId));
     }
 }
Esempio n. 23
0
        public override void Attack(IAdventurePlayer player, IAdventureItem troll, IAdventureItem weapon)
        {
            if (weapon != null)
            {
                player.ChatClient.PostDirectMessage(player, $"You try to to attack the dragon, but it breathes acid at your {weapon.Name}!");
                player.ChatClient.PostDirectMessage(player, $"You drop the ruined {weapon.Name} and it quickly dissolves into a puddle of slag!");
                var loseWeapon = new RemoveFromInventory();
                loseWeapon.Do(player, weapon);
            }

            return;
        }
Esempio n. 24
0
        public void PostDirectMessage(IAdventurePlayer player, string text)
        {
            var found = ulong.TryParse(player.Id, out var userId);

            if (found)
            {
                var user           = _discordClient.GetUserAsync(userId).Result;
                var privateChannel = _discordClient.CreateDmAsync(user).Result;
                var channelId      = privateChannel.Id.ToString();
                PostMessage(channelId, text);
            }
        }
Esempio n. 25
0
        public (bool, string) IsMoveAllowed(IAdventurePlayer player, IReadonlyAdventureGame game)
        {
            if (player.Inventory.Count() == 0)
            {
                return(true, string.Empty);
            }

            var message = "Its far too tight to squeeze through the gap whilst you are carrying things! " +
                          "Try dropping what you have with you, and maybe, just maybe, you could get through...";

            return(false, message);
        }
Esempio n. 26
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);
        }
Esempio n. 27
0
        public bool Do(IAdventurePlayer player, IAdventureItem item)
        {
            if (_location is null)
            {
                player.CurrentLocation.RemoveItem(_itemToRemove);
            }
            else
            {
                _location.RemoveItem(_itemToRemove);
            }

            return(true);
        }
Esempio n. 28
0
        public bool HasState(IAdventurePlayer player, string state)
        {
            if (PlayerItemState.ContainsKey(player.Id))
            {
                var states = PlayerItemState[player.Id];

                if (states.Contains(state))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 29
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}");
        }
Esempio n. 30
0
 public override void Attack(IAdventurePlayer player, IAdventureItem troll, IAdventureItem weapon = null)
 {
     if (weapon != null)
     {
         player.ChatClient.PostDirectMessage(player, $"You try to to attack the troll, but it snatches the {weapon.Name} from your puny grasp and casts it into the chasm!");
         var loseWeapon = new RemoveFromInventory();
         loseWeapon.Do(player, weapon);
     }
     else
     {
         player.ChatClient.PostDirectMessage(player, $"As you approach the hideous troll, it points at its sign and yells 'Pay troll!'");
         player.ChatClient.PostDirectMessage(player, $"The creature's foul breath drives you back, gasping for air.");
     }
 }