Beispiel #1
0
        public static void Say(string message, Player player, Room room)
        {
            string playerId = player.HubGuid;

            HubContext.SendToClient("You say " + message, playerId, null, false, false);
            HubContext.broadcastToRoom(player.Name + " says " + message, room.players, playerId, true);
        }
Beispiel #2
0
        public static void StartKick(Player attacker, Room room)
        {
            //TODO: Fix His to be gender specific
            //TODO: Fist? what if it's a paw?

            if (!_taskRunnning && attacker.Target != null)
            {
                // find target if not in fight
                HubContext.SendToClient("You pull your leg back", attacker.HubGuid);
                HubContext.SendToClient(Helpers.ReturnName(attacker, null) + " pulls " + Helpers.ReturnHisOrHers(attacker.Gender) + " leg back ready to kick at you.", attacker.HubGuid,
                                        attacker.Target.HubGuid, false, true);
                HubContext.broadcastToRoom(
                    Helpers.ReturnName(attacker, null) + " pulls " + Helpers.ReturnHisOrHers(attacker.Gender) + " leg back ready to kick at " + Helpers.ReturnName(attacker.Target, null),
                    room.players, attacker.HubGuid, true);

                Task.Run(() => DoKick(attacker, room));
            }
            else
            {
                if (attacker.Target == null)
                {
                    HubContext.SendToClient("You stop your kick", attacker.HubGuid);
                    return;
                }

                HubContext.SendToClient("You are already trying to kick", attacker.HubGuid);
            }
        }
Beispiel #3
0
        public static async Task KickIdlePlayers()
        {
            try
            {
                foreach (var player in MIMHub._PlayerCache.ToList())
                {
                    if (player.Value != null && player.Value.LastCommandTime.AddMinutes(1) < DateTime.UtcNow)
                    {
                        HubContext.SendToClient("You disappear in the void", player.Value.HubGuid);

                        var room =
                            MIMHub._AreaCache.FirstOrDefault(
                                x =>
                                x.Value.area.Equals(player.Value.Area) && x.Value.areaId.Equals(player.Value.AreaId) &&
                                x.Value.region.Equals(player.Value.Region));

                        if (room.Value != null)
                        {
                            foreach (var players in room.Value.players.ToList())
                            {
                                HubContext.broadcastToRoom(player.Value.Name + " disappears in the void",
                                                           room.Value.players,
                                                           player.Value.HubGuid, true);
                            }
                        }
                    }

                    if (player.Value != null && player.Value.LastCommandTime.AddMinutes(2) < DateTime.UtcNow)
                    {
                        var room =
                            MIMHub._AreaCache.FirstOrDefault(
                                x =>
                                x.Value.area.Equals(player.Value.Area) && x.Value.areaId.Equals(player.Value.AreaId) &&
                                x.Value.region.Equals(player.Value.Region));


                        PlayerSetup.Player removedChar = null;

                        MIMHub._PlayerCache.TryRemove(player.Value.HubGuid, out removedChar);

                        if (removedChar != null)
                        {
                            Command.ParseCommand("quit", player.Value, room.Value);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var log = new Error.Error
                {
                    Date         = DateTime.Now,
                    ErrorMessage = ex.InnerException.ToString(),
                    MethodName   = "KickIdlePlayers"
                };

                Save.LogError(log);
            }
        }
        public static void StartMagicMissile(Player attacker, Room room, string target = "")
        {
            //Check if player has spell
            var hasSpell = Skill.CheckPlayerHasSkill(attacker, MagicMissileAb().Name);

            if (hasSpell == false)
            {
                HubContext.SendToClient("You don't know that spell.", attacker.HubGuid);
                return;
            }

            var foundTarget = Skill.FindTarget(target, room);

            if (foundTarget != null && attacker.Target == null && target != "")
            {
                Fight2.PerpareToFight(attacker, room, foundTarget.Name, true);
            }


            if (!_taskRunnning && attacker.Target != null)
            {
                if (attacker.ManaPoints < MagicMissileAb().ManaCost)
                {
                    HubContext.SendToClient("You clasp your hands together but fail to form any energy", attacker.HubGuid);

                    var excludePlayerInBroadcast = new List <string>();
                    excludePlayerInBroadcast.Add(attacker.HubGuid);

                    HubContext.SendToAllExcept(Helpers.ReturnName(attacker, null) + " clasps " + Helpers.ReturnHisOrHers(attacker.Gender) + " hands together but fails to form any energy", excludePlayerInBroadcast, room.players);

                    return;
                }

                attacker.ManaPoints -= MagicMissileAb().ManaCost;

                Score.UpdateUiPrompt(attacker);

                HubContext.SendToClient("A red ball begins swirling between your hands as you begin chanting magic missle", attacker.HubGuid);

                HubContext.SendToClient("A red ball begins swirling between " + Helpers.ReturnName(attacker, null) + " hands " + Helpers.ReturnHisOrHers(attacker.Gender) + " as they begin chanting magic missle", attacker.HubGuid,
                                        attacker.Target.HubGuid, false, true);

                HubContext.broadcastToRoom("A red ball begins swirling between " +
                                           Helpers.ReturnName(attacker, null) + " hands " + Helpers.ReturnHisOrHers(attacker.Gender) + " as they begin chanting magic missle " + Helpers.ReturnName(attacker.Target, null), room.players, attacker.HubGuid, true);

                Task.Run(() => DoMagicMissile(attacker, room));
            }
            else
            {
                if (attacker.Target == null)
                {
                    HubContext.SendToClient("Cast magic missile at whom?", attacker.HubGuid);
                    return;
                }

                HubContext.SendToClient("You are trying to cast magic missle", attacker.HubGuid);
            }
        }
Beispiel #5
0
 public static void greet(PlayerSetup.Player player, PlayerSetup.Player mob, Room.Room room)
 {
     if (player.Type == PlayerSetup.Player.PlayerTypes.Player)
     {
         string greetMessageToRoom = string.Format(mob.GreetMessage, player.Name);
         HubContext.broadcastToRoom(mob.Name + " Says " + greetMessageToRoom, room.players, player.HubGuid);
     }
     else
     {
         //Greet other mob
     }
 }
Beispiel #6
0
        public static void NewUser(PlayerSetup.Player player, PlayerSetup.Player mob, Room.Room room)
        {
            if (player.Type != PlayerSetup.Player.PlayerTypes.Player)
            {
                return;
            }

            var msg =
                "Welcome to Anker! I am here to guide you and I will keep it brief. To move type the direction shown in the exit list. North for example or n for short. You can also get items or drop them. Wield weapons, wear armour and kill. Kill the cat if you like.";

            HubContext.broadcastToRoom(mob.Name + " says " + msg, room.players, player.HubGuid);
        }
Beispiel #7
0
        private static async Task DoContinualLight(Player attacker, Room room)
        {
            _taskRunnning   = true;
            attacker.Status = Player.PlayerStatus.Busy;


            await Task.Delay(500);

            if (_target == null)
            {
                var castingTextAttacker = $"A bright {_color} ball of light is released by your hands and hovers in the air.";

                HubContext.SendToClient(castingTextAttacker, attacker.HubGuid);

                foreach (var character in room.players)
                {
                    if (character != attacker)
                    {
                        var roomMessage = $"{ Helpers.ReturnName(attacker, character, string.Empty)} releases a {_color} bright ball of light which hovers in the air.";

                        HubContext.SendToClient(roomMessage, character.HubGuid);
                    }
                }

                var ballOfLight = Light.BallOfLight();
                ballOfLight.description = new Description()
                {
                    exam = $"A bright {_color} ball of light hovers here.",
                    look = $"A bright {_color} ball of light hovers here.",
                    room = $"A bright {_color} ball of light hovers here."
                };
                ballOfLight.name     = $"A bright {_color} ball of light";
                ballOfLight.location = Item.Item.ItemLocation.Room;


                room.items.Add(ballOfLight);
            }
            else
            {
                var castingTextAttacker = $"The {_target.name} glows a bright {_color} colour.";

                var castingTextRoom = $"The {_target.name} glows a bright {_color} colour.";

                HubContext.SendToClient(castingTextAttacker, attacker.HubGuid);
                HubContext.broadcastToRoom(castingTextRoom, room.players, attacker.HubGuid, true);

                _target.itemFlags.Add(Item.Item.ItemFlags.glow);
            }

            _target       = null;
            _taskRunnning = false;
        }
Beispiel #8
0
        public static void buyItems(PlayerSetup.Player player, Room.Room room, string itemName)
        {
            var mob = room.mobs.FirstOrDefault(x => x.Shop.Equals(true));

            if (mob != null)
            {
                if (mob.Shop)
                {
                    if (string.IsNullOrEmpty(itemName))
                    {
                        HubContext.SendToClient("Buy? Buy what?", player.HubGuid);
                        return;
                    }

                    var itemToBuy = mob.itemsToSell.FirstOrDefault(x => x.name.ToLower().Contains(itemName.ToLower()));

                    if (itemToBuy != null)
                    {
                        var    result  = AvsAnLib.AvsAn.Query(itemToBuy.name);
                        string article = result.Article;

                        //Can afford

                        if (player.Gold >= itemToBuy.Gold)
                        {
                            itemToBuy.location = Item.Item.ItemLocation.Inventory;
                            player.Inventory.Add(itemToBuy);
                            HubContext.SendToClient(
                                "You buy " + article + itemToBuy.name + " from " + mob.Name,
                                player.HubGuid);
                            HubContext.broadcastToRoom(
                                player.Name + " buys " + article + " " + itemToBuy.name +
                                " from " +
                                mob.Name, room.players, player.HubGuid, true);
                            Score.UpdateUiInventory(player);
                            //deduct gold

                            player.Gold -= itemToBuy.Gold;
                        }
                        else
                        {
                            HubContext.SendToClient("You can't afford " + article + " " + itemToBuy.name, player.HubGuid);
                        }
                    }
                }
                else
                {
                    HubContext.SendToClient("Sorry I don't sell that", player.HubGuid);
                }
            }
        }
Beispiel #9
0
 public static void greet(PlayerSetup.Player player, PlayerSetup.Player mob, Room.Room room, string message = "")
 {
     if (player.Type == PlayerSetup.Player.PlayerTypes.Player && message == string.Empty)
     {
         if (mob.GreetMessage != null)
         {
             string greetMessageToRoom = mob.GreetMessage + " " + player.Name;
             HubContext.broadcastToRoom(mob.Name + " says " + greetMessageToRoom, room.players, player.HubGuid);
         }
     }
     else
     {
     }
 }
Beispiel #10
0
        private static async Task DoPunch(Player attacker, Room room)
        {
            _taskRunnning   = true;
            attacker.Status = Player.PlayerStatus.Busy;


            await Task.Delay(5000);


            //get attacker strength
            var die    = new PlayerStats();
            var dam    = die.dice(1, attacker.Strength);
            var toHit  = Helpers.GetPercentage(attacker.Skills.Find(x => x.Name.Equals("Punch", StringComparison.CurrentCultureIgnoreCase)).Proficiency, 95); // always 5% chance to miss
            int chance = die.dice(1, 100);


            if (toHit > chance)
            {
                //HIt, but what about defenders ability to block and dodge?



                if (attacker.Target != null && attacker.Target.HitPoints > 0)
                {
                    HubContext.SendToClient("Your punch hits", attacker.HubGuid);
                    HubContext.SendToClient(attacker.Name + " punch hits you", attacker.HubGuid, attacker.Target.HubGuid, false, true);
                    HubContext.broadcastToRoom(attacker.Name + " punches " + attacker.Target.Name, room.players, attacker.HubGuid, true);
                    attacker.Target.HitPoints -= dam;
                }


                //find target and hurt them, not yourself!!
            }
            else
            {
                HubContext.SendToClient("You swing a punch at " + attacker.Target.Name + " but miss", attacker.HubGuid);
                HubContext.SendToClient(attacker.Name + " swings a punch at you but misses", attacker.HubGuid, attacker.Target.HubGuid, false, true);
                HubContext.broadcastToRoom(attacker.Name + " swings at " + attacker.Target.Name + " but misses", room.players, attacker.HubGuid, true);
            }

            _taskRunnning   = false;
            attacker.Status = Player.PlayerStatus.Fighting;
        }
Beispiel #11
0
        public static async Task EmoteRoom()
        {
            //Loop every mob in the rooms in cache.
            // only emote if player is in the room

            foreach (var room in MIMHub._AreaCache.Values)
            {
                if (room.players.Count > 0)
                {
                    // check mob emotes

                    if (room.Emotes.Count > 0)
                    {
                        var emoteIndex = Helpers.diceRoll.Next(room.Emotes.Count);
                        HubContext.broadcastToRoom(room.Emotes[emoteIndex], room.players, String.Empty);
                    }
                }
            }
        }
Beispiel #12
0
        private static async Task DoArmour(Player attacker, Room room)
        {
            _taskRunnning   = true;
            attacker.Status = Player.PlayerStatus.Busy;


            await Task.Delay(500);

            if (_target == null)
            {
                var castingTextAttacker =
                    "You release the white sphere from your hands and it surrounds your whole body providing extra protection.";

                var castingTextRoom = Helpers.ReturnName(attacker, null) + " releases a white glowing sphere which surrounds " + Helpers.ReturnHisOrHers(attacker.Gender, false) + " body.";

                HubContext.SendToClient(castingTextAttacker, attacker.HubGuid);

                HubContext.SendToAllExcept(castingTextRoom, room.fighting, room.players);

                attacker.ArmorRating += 20;
            }
            else
            {
                var castingTextAttacker =
                    "You launch a white sphere from your hands towards " + Helpers.ReturnName(_target, null) + " surrounding them in magical armour.";

                var castingTextDefender = Helpers.ReturnName(attacker, null) + " sends a white glowing ball straight towards you surrounding you in magical armour.";

                var castingTextRoom = Helpers.ReturnName(attacker, null) +
                                      " sends a white glowing ball straight towards " + Helpers.ReturnName(_target, null) + " which surrounds them in magical armour..";

                HubContext.SendToClient(castingTextAttacker, attacker.HubGuid);
                HubContext.SendToClient(castingTextDefender, _target.HubGuid);
                HubContext.broadcastToRoom(castingTextRoom, room.players, attacker.HubGuid, true);

                _target.ArmorRating += 20;
            }

            _target       = null;
            _taskRunnning = false;
        }
Beispiel #13
0
        public static void StartPunch(Player attacker, Room room)
        {
            //TODO: Fix His to be gender specific
            //TODO: Fist? what if it's a paw?

            if (!_taskRunnning)
            {
                HubContext.SendToClient("You clench your fist and pull your arm back", attacker.HubGuid);
                HubContext.SendToClient(attacker.Name + " Pulls his arm back aiming a punch at you.", attacker.HubGuid,
                                        attacker.Target.HubGuid, false, true);
                HubContext.broadcastToRoom(
                    attacker.Name + " clenches his fist and pulls his arm back aiming for " + attacker.Target.Name,
                    room.players, attacker.HubGuid, true);


                Task.Run(() => DoPunch(attacker, room));
            }
            else
            {
                HubContext.SendToClient("You are already trying to punch", attacker.HubGuid);
            }
        }
Beispiel #14
0
        public static async Task KickIdlePlayers()
        {
            foreach (var player in MIMHub._PlayerCache)
            {
                if (player.Value != null && player.Value.LastCommandTime.AddMinutes(10) < DateTime.UtcNow)
                {
                    HubContext.SendToClient("You disapear in the void", player.Value.HubGuid);

                    var room =
                        MIMHub._AreaCache.FirstOrDefault(
                            x =>
                            x.Value.area.Equals(player.Value.Area) && x.Value.areaId.Equals(player.Value.AreaId) &&
                            x.Value.region.Equals(player.Value.Region));

                    if (room.Value != null)
                    {
                        foreach (var players in room.Value.players)
                        {
                            HubContext.broadcastToRoom(player.Value.Name + " disapears in the void", room.Value.players,
                                                       player.Value.HubGuid, true);
                        }

                        //room.Value.players.Remove(player.Value);
                    }
                }

                if (player.Value != null && player.Value.LastCommandTime.AddMinutes(20) < DateTime.UtcNow)
                {
                    var room =
                        MIMHub._AreaCache.FirstOrDefault(
                            x =>
                            x.Value.area.Equals(player.Value.Area) && x.Value.areaId.Equals(player.Value.AreaId) &&
                            x.Value.region.Equals(player.Value.Region));

                    Command.ParseCommand("quit", player.Value, room.Value);
                }
            }
        }
Beispiel #15
0
        public static async Task EmoteMob()
        {
            //Loop every mob in the rooms in cache.
            // only emote if player is in the room

            foreach (var room in MIMHub._AreaCache.Values)
            {
                foreach (var mob in room.mobs)
                {
                    if (room.players.Count > 0 && room.mobs.Count > 0)
                    {
                        if (mob.Emotes != null && mob.HitPoints > 0)
                        {
                            await Task.Delay(5000);

                            var emoteIndex = Helpers.diceRoll.Next(mob.Emotes.Count);
                            HubContext.broadcastToRoom(mob.Name + " " + mob.Emotes[emoteIndex], room.players,
                                                       String.Empty);
                        }
                    }
                }
            }
        }
Beispiel #16
0
        private static async Task DoPunch(Player attacker, Room room)
        {
            _taskRunnning   = true;
            attacker.Status = Player.PlayerStatus.Busy;


            await Task.Delay(5000);


            //get attacker strength
            var die    = new PlayerStats();
            var dam    = die.dice(1, attacker.Strength);
            var toHit  = 0.5 * 95; // always 5% chance to miss
            int chance = die.dice(1, 100);


            if (toHit > chance)
            {
                //HIt, but what about defenders ability to block and dodge?

                HubContext.SendToClient("Your punch hits", attacker.HubGuid);
                HubContext.SendToClient(attacker.Name + " punch hits you", attacker.HubGuid, attacker.Target.HubGuid, false, true);
                HubContext.broadcastToRoom(attacker.Name + " punches " + attacker.Target.Name, room.players, attacker.HubGuid, true);

                //find target and hurt them, not yourself!!
                attacker.Target.HitPoints -= dam;
            }
            else
            {
                HubContext.SendToClient("You swing a punch at " + attacker.Target.Name + " but miss", attacker.HubGuid);
                HubContext.SendToClient(attacker.Name + " swings a punch at you but misses", attacker.HubGuid, attacker.Target.HubGuid, false, true);
                HubContext.broadcastToRoom(attacker.Name + " swings at " + attacker.Target.Name + " but misses", room.players, attacker.HubGuid, true);
            }

            _taskRunnning   = false;
            attacker.Status = Player.PlayerStatus.Fighting;
        }
Beispiel #17
0
        public static async Task Punch(Player attacker, Room room)
        {
            //Fight2 needs refactoring so the below skills can use the same methods for damage, damage output, working out chance to hit etc. same for spells



            HubContext.SendToClient("You clench your fist and pull your arm back", attacker.HubGuid);
            HubContext.SendToClient(attacker.Name + " Pulls his arm back aiming a punch at you.", attacker.HubGuid, attacker.Target.HubGuid, false, true);
            HubContext.broadcastToRoom(attacker.Name + " clenches his fist and pulls his arm back aiming for " + attacker.Target.Name, room.players, attacker.HubGuid, true);

            await Task.Delay(1500);

            //get attacker strength
            var die    = new PlayerStats();
            var dam    = die.dice(1, attacker.Strength);
            var toHit  = 0.5 * 95; // always 5% chance to miss
            int chance = D100();


            if (toHit > chance)
            {
                HubContext.SendToClient("Your punch hits", attacker.HubGuid + " " + dam);
                HubContext.SendToClient(attacker.Name + " punch hits you", attacker.HubGuid,
                                        attacker.Target.HubGuid, false, true);
                HubContext.broadcastToRoom(
                    attacker.Name + " punches " + attacker.Target.Name,
                    room.players, attacker.HubGuid, true);

                attacker.Target.HitPoints -= dam;
            }
            else
            {
                HubContext.SendToClient("You swing a punch at " + attacker.Target.Name + " but miss", attacker.HubGuid);
                HubContext.SendToClient(attacker.Name + " swings a punch at you but misses", attacker.HubGuid, attacker.Target.HubGuid, false, true);
                HubContext.broadcastToRoom(attacker.Name + " swings at " + attacker.Target.Name + " but misses", room.players, attacker.HubGuid, true);
            }
        }
Beispiel #18
0
        public static void StartArmour(Player player, Room room, string target = "")
        {
            //Check if player has spell
            var hasSpell = Skill.CheckPlayerHasSkill(player, ArmourAb().Name);

            if (hasSpell == false)
            {
                HubContext.SendToClient("You don't know that spell.", player.HubGuid);
                return;
            }

            _target = Skill.FindTarget(target, room);

            //Fix issue if target has similar name to user and they use abbrivations to target them
            if (_target == player)
            {
                _target = null;
            }


            if (!_taskRunnning && _target != null)
            {
                if (player.ManaPoints < ArmourAb().ManaCost)
                {
                    HubContext.SendToClient("You clasp your hands together but fail to form any energy", player.HubGuid);

                    var excludePlayerInBroadcast = new List <string> {
                        player.HubGuid
                    };

                    HubContext.SendToAllExcept(Helpers.ReturnName(player, null) + " clasps " + Helpers.ReturnHisOrHers(player.Gender) + " hands together but fails to form any energy", excludePlayerInBroadcast, room.players);

                    return;
                }

                //TODO REfactor

                player.ManaPoints -= ArmourAb().ManaCost;

                Score.UpdateUiPrompt(player);

                HubContext.SendToClient("A white sphere begins swirling between your hands as you begin chanting the armour spell", player.HubGuid);

                HubContext.SendToClient("A white sphere begins swirling between the hands of " + Helpers.ReturnName(player, null) + " as they begin chanting the Armour spell", player.HubGuid,
                                        _target.HubGuid, false, true);

                var playersInRoom = new List <Player>(room.players);
                //remove target
                playersInRoom.Remove(_target);

                //todo Stop double echo to target
                //To target: Vall sends a white glowing ball straight towards you surrounding you in magical armour.
                //To room : Vall sends a white glowing ball straight towards Val which surrounds them in magical armour..
                HubContext.broadcastToRoom("A white sphere begins swirling between the hands of " +
                                           Helpers.ReturnName(player, null) + " as they begin chanting the armour spell.", playersInRoom, player.HubGuid, true);

                Task.Run(() => DoArmour(player, room));
            }
            else
            {
                if (_target == null)
                {
                    //TODO REfactor
                    player.ManaPoints -= ArmourAb().ManaCost;

                    Score.UpdateUiPrompt(player);

                    HubContext.SendToClient("A white sphere begins swirling between your hands as you begin chanting the armour spell", player.HubGuid);

                    HubContext.broadcastToRoom("A white sphere begins swirling between the hands of " +
                                               Helpers.ReturnName(player, null) + " as they begin chanting the armour spell ", room.players, player.HubGuid, true);

                    Task.Run(() => DoArmour(player, room));
                }
            }
        }
Beispiel #19
0
        public static void ReturnRoom(Player player, Room room, string commandOptions = "", string keyword = "")
        {
            Room roomData = room;

            if (string.IsNullOrEmpty(commandOptions) && keyword == "look")
            {
                var roomInfo = DisplayRoom(roomData, player.Name);
                HubContext.SendToClient(roomInfo, player.HubGuid);
            }
            else
            {
                int    n    = -1;
                string item = string.Empty;

                if (commandOptions.IndexOf('.') != -1)
                {
                    n    = Convert.ToInt32(commandOptions.Substring(0, commandOptions.IndexOf('.')));
                    item = commandOptions.Substring(commandOptions.LastIndexOf('.') + 1);
                }

                if (roomData.keywords == null)
                {
                    roomData.keywords = new List <RoomObject>();
                }

                var roomDescription = roomData.keywords.Find(x => x.name.ToLower().Contains(commandOptions));

                if (roomData.items == null)
                {
                    roomData.items = new List <Item.Item>();
                }

                var itemDescription = (n == -1)
                                          ? roomData.items.Find(x => x.name.ToLower().Contains(commandOptions))
                                          : roomData.items.FindAll(x => x.name.ToLower().Contains(item))
                                      .Skip(n - 1)
                                      .FirstOrDefault();

                if (roomData.mobs == null)
                {
                    roomData.mobs = new List <Player>();
                }

                var mobDescription = roomData.mobs.Find(x => x.Name.ToLower().Contains(commandOptions));

                if (roomData.players == null)
                {
                    roomData.players = new List <Player>();
                }

                var playerDescription = roomData.players.Find(x => x.Name.ToLower().Contains(commandOptions));

                var targetPlayerId = string.Empty;
                if (playerDescription != null)
                {
                    var isPlayer = playerDescription.Type.Equals("Player");

                    if (isPlayer)
                    {
                        targetPlayerId = playerDescription.HubGuid;
                    }
                }



                //Returns descriptions for important objects in the room
                if (roomDescription != null && keyword != "look in" && !string.IsNullOrWhiteSpace(commandOptions))
                {
                    string descriptionText = string.Empty;
                    string broadcastAction = string.Empty;
                    if (keyword.Equals("look"))
                    {
                        descriptionText = roomDescription.look;
                        broadcastAction = " looks at a " + roomDescription.name;
                    }
                    else if (keyword.StartsWith("examine"))
                    {
                        descriptionText = roomDescription.examine;
                        broadcastAction = " looks closely at a " + roomDescription.name;
                    }
                    else if (keyword.StartsWith("touch"))
                    {
                        descriptionText = roomDescription.touch;
                        broadcastAction = " touches closely a " + roomDescription.name;
                    }
                    else if (keyword.StartsWith("smell"))
                    {
                        descriptionText = roomDescription.smell;
                        broadcastAction = " sniffs a " + roomDescription.name;
                    }
                    else if (keyword.StartsWith("taste"))
                    {
                        descriptionText = roomDescription.taste;
                        broadcastAction = " licks a " + roomDescription.name;
                    }

                    if (!string.IsNullOrEmpty(descriptionText))
                    {
                        HubContext.SendToClient(descriptionText, player.HubGuid);

                        foreach (var players in room.players)
                        {
                            if (player.Name != players.Name)
                            {
                                HubContext.SendToClient(player.Name + broadcastAction, players.HubGuid);
                            }
                        }
                    }
                    else
                    {
                        HubContext.SendToClient("You can't do that to a " + roomDescription.name, player.HubGuid);
                    }
                }
                else if (itemDescription != null && !string.IsNullOrWhiteSpace(commandOptions))
                {
                    string descriptionText = string.Empty;
                    string broadcastAction = string.Empty;

                    if (keyword.Equals("look in", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (itemDescription.open == false)
                        {
                            HubContext.SendToClient("You to to open the " + itemDescription.name + " before you can look inside", player.HubGuid);
                            return;
                        }

                        if (itemDescription.container == true)
                        {
                            if (itemDescription.containerItems.Count > 0)
                            {
                                HubContext.SendToClient("You look into the " + itemDescription.name + " and see:", player.HubGuid);

                                foreach (var containerItem in itemDescription.containerItems)
                                {
                                    HubContext.SendToClient(containerItem.name, player.HubGuid);
                                }
                            }
                            else
                            {
                                HubContext.SendToClient("You look into the " + itemDescription.name + " but it is empty", player.HubGuid);
                            }

                            HubContext.broadcastToRoom(player.Name + " looks in a " + itemDescription.name, room.players, player.HubGuid, true);
                        }
                        else
                        {
                            HubContext.SendToClient(itemDescription.name + " is not a container", player.HubGuid);
                        }
                    }
                    else if (keyword.StartsWith("look"))
                    {
                        descriptionText = itemDescription.description.look;
                        broadcastAction = " looks at a " + itemDescription.name;
                    }
                    else if (keyword.StartsWith("examine"))
                    {
                        descriptionText = itemDescription.description.exam;
                        broadcastAction = " looks closely at a " + itemDescription.name;
                    }

                    if (!keyword.Equals("look in", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (!string.IsNullOrEmpty(descriptionText))
                        {
                            HubContext.SendToClient(descriptionText, player.HubGuid);

                            foreach (var players in room.players)
                            {
                                if (player.Name != players.Name)
                                {
                                    HubContext.SendToClient(player.Name + broadcastAction,
                                                            players.HubGuid);
                                }
                            }
                        }
                        else
                        {
                            HubContext.SendToClient("You can't do that to a " + itemDescription.name, player.HubGuid);
                        }
                    }
                }
                else if (mobDescription != null && !string.IsNullOrWhiteSpace(commandOptions))
                {
                    string descriptionText = string.Empty;

                    if (keyword.StartsWith("look"))
                    {
                        descriptionText = mobDescription.Description;
                    }


                    if (!string.IsNullOrEmpty(descriptionText))
                    {
                        HubContext.SendToClient(descriptionText, player.HubGuid);
                    }
                    else
                    {
                        HubContext.SendToClient("You can't do that to a " + mobDescription.Name, player.HubGuid);
                    }
                }
                else if (playerDescription != null && !string.IsNullOrWhiteSpace(commandOptions))
                {
                    string descriptionText = string.Empty;

                    if (keyword.StartsWith("look"))
                    {
                        descriptionText = playerDescription.Description;
                    }


                    if (!string.IsNullOrEmpty(descriptionText))
                    {
                        HubContext.SendToClient(descriptionText, player.HubGuid);
                        HubContext.SendToClient(player.Name + " looks at you", targetPlayerId);
                    }
                    else
                    {
                        HubContext.SendToClient("You can't do that to a " + playerDescription.Name, player.HubGuid);
                    }
                }
                else
                {
                    HubContext.SendToClient("You don't see that here.", player.HubGuid);
                }
            }
        }
        public static void StartMagicMissile(Player attacker, Room room, string target = "")
        {
            //Check if player has spell
            var hasSpell = Skill.CheckPlayerHasSkill(attacker, MagicMissileAb().Name);

            if (hasSpell == false)
            {
                HubContext.SendToClient("You don't know that spell.", attacker.HubGuid);
                return;
            }

            var canDoSkill = Skill.CanDoSkill(attacker);

            if (!canDoSkill)
            {
                return;
            }

            if (string.IsNullOrEmpty(target) && attacker.Target != null)
            {
                target = attacker.Target.Name;
            }

            var _target = Skill.FindTarget(target, room);

            if (_target == attacker)
            {
                _target = null;
            }

            if (attacker.ActiveSkill != null)
            {
                HubContext.SendToClient("wait till you have finished " + attacker.ActiveSkill.Name, attacker.HubGuid);
                return;
            }
            else
            {
                attacker.ActiveSkill = MagicMissileAb();
                attacker.Target      = _target;
            }



            if (attacker.Target != null)
            {
                if (attacker.ManaPoints < MagicMissileAb().ManaCost)
                {
                    HubContext.SendToClient("You clasp your hands together but fail to form any energy",
                                            attacker.HubGuid);
                    attacker.ActiveSkill = null;
                    Player.SetState(attacker);
                    return;
                }

                attacker.ManaPoints -= MagicMissileAb().ManaCost;

                Score.UpdateUiPrompt(attacker);

                HubContext.SendToClient("A red ball begins swirling between your hands as you begin chanting magic missile", attacker.HubGuid);

                HubContext.SendToClient($"A red ball begins swirling between {Helpers.ReturnName(attacker, attacker.Target, null)} 's hands as they begin chanting magic missile", attacker.HubGuid, attacker.Target.HubGuid, false, true);

                HubContext.broadcastToRoom($"A red ball begins swirling between {Helpers.ReturnName(attacker, attacker.Target, null)} 's hands as they begin chanting magic missile", room.players, attacker.HubGuid, true);

                Task.Run(() => DoMagicMissile(attacker, room));
            }
            else
            {
                Player.SetState(attacker);

                if (attacker.Target == null)
                {
                    HubContext.SendToClient("Cast magic missile at whom?", attacker.HubGuid);
                    attacker.ActiveSkill = null;
                    Player.SetState(attacker);
                    return;
                }

                HubContext.SendToClient("You are trying to cast magic missile", attacker.HubGuid);
            }
        }
Beispiel #21
0
        public static void Say(string message, Player player, Room room)
        {
            string playerId = player.HubGuid;

            HubContext.SendToClient("You say " + message, playerId, null, false, false);
            HubContext.broadcastToRoom(player.Name + " says " + message, room.players, playerId, true);


            //check npc response
            foreach (var mob in room.mobs)
            {
                var response             = string.Empty;
                var hasQuest             = false;
                var questId              = 0;
                var GivePrerequisiteItem = false;

                if (mob.Dialogue != null)
                {
                    foreach (var dialogue in mob.Dialogue)
                    {
                        foreach (var keyword in dialogue.Keyword)
                        {
                            if (message.Contains(keyword))
                            {
                                response = dialogue.Response;
                            }
                        }
                    }
                }



                if (response == string.Empty)
                {
                    if (mob.DialogueTree != null)
                    {
                        foreach (var tree in mob.DialogueTree)
                        {
                            if (message.Equals(tree.MatchPhrase))
                            {
                                response = tree.Message;
                                if (tree.GiveQuest != null)
                                {
                                    hasQuest = (bool)tree.GiveQuest;
                                }
                                if (tree.GivePrerequisiteItem != null)
                                {
                                    GivePrerequisiteItem = (bool)tree.GivePrerequisiteItem;
                                }
                                if (tree.QuestId != null)
                                {
                                    questId = (int)tree.QuestId;
                                }
                            }
                        }
                    }
                }

                if (response != String.Empty)
                {
                    Thread.Sleep(120); // hack, sometimes the responses calls before the questions??

                    if (!hasQuest)
                    {
                        var quest = mob.Quest.FirstOrDefault(x => x.Id.Equals(questId));
                        HubContext.SendToClient(
                            mob.Name + " says to you " + quest.AlreadyOnQuestMessage, playerId,
                            null, true);
                        return;
                    }


                    HubContext.SendToClient(
                        mob.Name + " says to you " + response.Replace("$playerName", player.Name), playerId,
                        null, true);


                    //check branch to show responses from
                    var speak = mob.DialogueTree.FirstOrDefault(x => x.Message.Equals(response));

                    if (speak?.PossibleResponse.Count > 0)
                    {
                        HubContext.SendToClient(
                            mob.Name + " says to you anything else?", playerId,
                            null, true);
                    }



                    var i = 1;
                    foreach (var respond in speak.PossibleResponse)
                    {
                        if (player.QuestLog != null && respond.QuestId > 0)
                        {
                            var doneQuest =
                                player.QuestLog.FirstOrDefault(
                                    x => x.Id.Equals(respond.QuestId) && x.QuestGiver.Equals(mob.Name) && x.Completed.Equals(true));

                            if (doneQuest == null)
                            {
                                var textChoice =
                                    "<a class='multipleChoice' href='javascript:void(0)' onclick='$.connection.mIMHub.server.recieveFromClient(\"say " +
                                    respond.Response + "\",\"" + player.HubGuid + "\")'>" + i + ". " + respond.Response +
                                    "</a>";
                                HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage(textChoice);
                                i++;
                            }
                            else
                            {
                                var textChoice =
                                    "<a class='multipleChoice' href='javascript:void(0)' onclick='$.connection.mIMHub.server.recieveFromClient(\"say " +
                                    respond.Response + "\",\"" + player.HubGuid + "\")'>" + i + ". " + respond.Response +
                                    "</a>";
                                HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage(textChoice);
                                i++;
                            }
                        }
                    }


                    if (hasQuest)
                    {
                        //find quest
                        var quest = mob.Quest.FirstOrDefault(x => x.Id.Equals(questId));

                        var playerHasQuest = player.QuestLog.FirstOrDefault(x => quest != null && x.Name.Equals(quest.Name));

                        if (playerHasQuest == null)
                        {
                            //to player log
                            player.QuestLog.Add(quest);

                            HubContext.SendToClient("<h5>Quest Added: </h5> " + quest.Name, playerId);

                            if (GivePrerequisiteItem)
                            {
                                //  Command.ParseCommand("Give 5 gold " + player.Name, mob, room);
                                player.Gold += 5;
                                HubContext.broadcastToRoom(mob.Name + " " + quest.PrerequisiteItemEmote,
                                                           room.players, String.Empty);
                                HubContext.SendToClient("You get 5 gold from " + mob.Name, playerId);
                            }
                        }
                    }
                }


                else
                {
                    //generic responses?
                }

                if (mob.EventOnComunicate.Count > 0)
                {
                    var triggerEvent = mob.EventOnComunicate.FirstOrDefault(x => x.Value.Equals("yes"));

                    Event.ParseCommand(triggerEvent.Key, player, mob, room, "yes", "player");
                }
            }
        }
Beispiel #22
0
 public static void BroadcastPlayerActions(string playerHub, string playerName, List <PlayerSetup.Player> playersInRoom, string messageForPlayer, string messageForRoom)
 {
     HubContext.SendToClient(messageForPlayer, playerHub);
     HubContext.broadcastToRoom(playerName + " " + messageForRoom, playersInRoom, playerHub, true);
 }
Beispiel #23
0
        private static async Task DoInvis(Player attacker, Room room)
        {
            _taskRunnning   = true;
            attacker.Status = Player.PlayerStatus.Busy;


            await Task.Delay(500);

            if (_target == null)
            {
                var castingTextAttacker = $"You fade out of existence";

                HubContext.SendToClient(castingTextAttacker, attacker.HubGuid);


                foreach (var character in room.players)
                {
                    if (character != attacker)
                    {
                        var roomMessage = $"{ Helpers.ReturnName(attacker, character, string.Empty)} fades out of existence.";

                        HubContext.SendToClient(roomMessage, character.HubGuid);
                    }
                }

                attacker.invis = true;
                var invisAffect = new Affect
                {
                    Name     = "Invis",
                    Duration = InvisAb().Duration *attacker.Level,
                    AffectLossMessagePlayer = "You are no longer invisible.",
                    AffectLossMessageRoom   = "fades into existence."
                };


                if (attacker.Affects != null)
                {
                    var checkExisting = attacker.Affects.FirstOrDefault(x => x.Name.Equals("Invis"));

                    if (checkExisting == null)
                    {
                        attacker.Affects.Add(invisAffect);
                    }
                    else
                    {
                        checkExisting.Duration = InvisAb().Duration;
                    }
                }
                else
                {
                    attacker.Affects = new List <Affect>
                    {
                        invisAffect
                    };
                }
            }
            else
            {
                var castingTextAttacker = $"The {_target.name} fades out of existence.";

                var castingTextRoom = $"The {_target.name} fades out of existence.";

                HubContext.SendToClient(castingTextAttacker, attacker.HubGuid);
                HubContext.broadcastToRoom(castingTextRoom, room.players, attacker.HubGuid, true);

                _target.itemFlags.Add(Item.Item.ItemFlags.invis);
            }

            Player.SetState(attacker);

            _target       = null;
            _taskRunnning = false;
        }
Beispiel #24
0
        public static void StartMagicMissile(Player attacker, Room room, string target = "")
        {
            //Check if player has spell
            var hasSpell = Skill.CheckPlayerHasSkill(attacker, MagicMissileAb().Name);

            if (hasSpell == false)
            {
                HubContext.SendToClient("You don't know that spell.", attacker.HubGuid);
                return;
            }


            var canDoSkill = Skill.CanDoSkill(attacker);

            if (!canDoSkill)
            {
                return;
            }

            attacker.Status = Player.PlayerStatus.Busy;

            var foundTarget = Skill.FindTarget(target, room);

            if (foundTarget != null && attacker.Target == null && target != "")
            {
                Fight2.PerpareToFight(attacker, room, foundTarget.Name, true);
            }


            if (!_taskRunnning && attacker.Target != null)
            {
                if (attacker.ManaPoints < MagicMissileAb().ManaCost)
                {
                    HubContext.SendToClient("You clasp your hands together but fail to form any energy", attacker.HubGuid);


                    foreach (var character in room.players)
                    {
                        if (character != attacker)
                        {
                            HubContext.SendToClient($"{Helpers.ReturnName(attacker, attacker.Target, null)} clasps {Helpers.ReturnHisOrHers(attacker, attacker.Target)} hands together but fails to form any energy", attacker.HubGuid);
                        }
                    }

                    Player.SetState(attacker);
                    return;
                }

                attacker.ManaPoints -= MagicMissileAb().ManaCost;

                Score.UpdateUiPrompt(attacker);

                HubContext.SendToClient("A red ball begins swirling between your hands as you begin chanting magic missile", attacker.HubGuid);

                HubContext.SendToClient($"A red ball begins swirling between {Helpers.ReturnName(attacker, attacker.Target, null)} 's hands as they begin chanting magic missile", attacker.HubGuid, attacker.Target.HubGuid, false, true);

                HubContext.broadcastToRoom($"A red ball begins swirling between {Helpers.ReturnName(attacker, attacker.Target, null)} 's hands as they begin chanting magic missile", room.players, attacker.HubGuid, true);

                Task.Run(() => DoMagicMissile(attacker, room));
            }
            else
            {
                Player.SetState(attacker);

                if (attacker.Target == null)
                {
                    HubContext.SendToClient("Cast magic missile at whom?", attacker.HubGuid);
                    return;
                }

                HubContext.SendToClient("You are trying to cast magic missile", attacker.HubGuid);
            }
        }