Example #1
0
        public int Charge(Player player, Player target, Room room, string obj)
        {
            if (player.Status == CharacterStatus.Status.Fighting)
            {
                _writer.WriteLine("You are already in combat, Charge can only be used to start a combat.");
                return(0);
            }

            var nthTarget = Helpers.findNth(obj);

            var character = Helpers.FindMob(nthTarget, room) ?? Helpers.FindPlayer(nthTarget, room);


            var weaponDam = player.Equipped.Wielded != null ? player.Equipped.Wielded.Damage.Maximum : 1 * 2;
            var str       = player.Attributes.Attribute[EffectLocation.Strength];
            var damage    = _dice.Roll(1, 1, weaponDam) + str / 5;


            _skillManager.DamagePlayer("charge", damage, player, target, room);

            player.Lag += 2;

            _skillManager.updateCombat(player, target, room);

            return(damage);
        }
Example #2
0
        public Player CheckTarget(Skill.Model.Skill spell, string target, Room room, Player player)
        {
            if (string.IsNullOrEmpty(target) || target.Equals(spell.Name, StringComparison.CurrentCultureIgnoreCase))
            {
                return(null);
            }

            var victim = string.IsNullOrEmpty(target) ? player : GetTarget(target, room);

            if (victim == null)
            {
                _writer.WriteLine(
                    (spell.ValidTargets & ValidTargets.TargetPlayerWorld) != 0
                        ? "You can't find them in the realm."
                        : "You don't see them here.", player.ConnectionId);

                return(null);
            }

            //if (spell.StartsCombat && victim.Id == player.Id)
            //{
            //    _writer.WriteLine("Casting this on yourself is a bad idea.", player.ConnectionId);
            //    return null;
            //}

            return(victim);
        }
 public void Say(string n, int delay, Room room, Player player)
 {
     if (!IsInRoom(room, player))
     {
         return;
     }
     _writeToClient.WriteLine($"<p class='mob-emote'>{n.Replace("#name#", player.Name)}</p>", player.ConnectionId, delay);
 }
Example #4
0
        public void ShowSkills(Player player)
        {
            _writeToClient.WriteLine("Skills:");

            foreach (var skill in player.Skills)
            {
                _writeToClient.WriteLine($"Level {skill.Level} : {skill.SkillName} {skill.Proficiency}%", player.ConnectionId);
            }
        }
Example #5
0
        public bool ValidStatus(Player player)
        {
            switch (player.Status)
            {
            case CharacterStatus.Status.Sleeping:
                _writer.WriteLine("You can't do this while asleep.");
                return(false);

            //case CharacterStatus.Status.Stunned:
            //    _writer.WriteLine("You are stunned.");
            //    return false;
            //case CharacterStatus.Status.Dead:
            //case CharacterStatus.Status.Ghost:
            //case CharacterStatus.Status.Incapacitated:
            //    _writer.WriteLine("You can't do this while dead.");
            //    return false;
            //case CharacterStatus.Status.Resting:
            //case CharacterStatus.Status.Sitting:
            //    _writer.WriteLine("You need to stand up before you do that.");
            //    return false;
            //case CharacterStatus.Status.Busy:
            //    _writer.WriteLine("You can't do that right now.");
            //    return false;
            default:
                return(true);
            }
        }
Example #6
0
        /// <summary>
        /// get message from client
        /// </summary>
        /// <returns></returns>
        public void SendToServer(string message, string connectionId)
        {
            var player = _cache.GetPlayer(connectionId);

            if (player == null)
            {
                _writeToClient.WriteLine("<p>Refresh the page to reconnect!</p>");
                return;
            }
            player.Buffer.Enqueue(message);
        }
        public void Identify(Player player, string obj, Room room)
        {
            if (string.IsNullOrEmpty(obj))
            {
                _writer.WriteLine("Identify what!?", player.ConnectionId);
                return;
            }
            var item = player.Inventory.FirstOrDefault(x => x.Name.Contains(obj, StringComparison.CurrentCultureIgnoreCase));

            if (item == null)
            {
                _writer.WriteLine($"You don't have an item starting with '{item}'", player.ConnectionId);
                return;
            }

            var sb = new StringBuilder();


            List <string> itemFlags = new List <string>();

            foreach (Item.Item.ItemFlags itemFlag in Enum.GetValues(typeof(Item.Item.ItemFlags)))
            {
                if ((item.ItemFlag & itemFlag) != 0)
                {
                    itemFlags.Add(itemFlag.ToString());
                }
            }

            sb.Append($"<p>Object '{item.Name}' is type {item.ItemType}, extra flags: {(itemFlags.Any() ? String.Join(",", itemFlags) : "none")}.<br />");
            sb.Append($"Weight is {item.Weight}, value is {item.Value}, level is {item.Level}.<br />");

            if (item.ItemType == Item.Item.ItemTypes.Armour)
            {
                sb.Append($"Armour Type: {item.ArmourType}, Defense {item.ArmourRating.Armour} and {item.ArmourRating.Magic} vs magic.<br />");
            }

            if (item.ItemType == Item.Item.ItemTypes.Weapon)
            {
                sb.Append($"Weapon Type: {item.WeaponType}, Damage is {item.Damage.Minimum}-{item.Damage.Maximum} (average {item.Damage.Minimum + item.Damage.Maximum / 2}).<br />");
                sb.Append($"Attack type: {item.AttackType}</br>");
                sb.Append($"Damage type: {item.DamageType}</br>");
            }

            // TODO: container? Affects? what else?
            // show crafted by
            // show enchanted by

            sb.Append("</p>");

            _writer.WriteLine(sb.ToString(), player.ConnectionId);
        }
Example #8
0
        public void EmoteSocial(Player player, Room room, Emote social, string target)
        {
            if (string.IsNullOrEmpty(target))
            {
                _writeToClient.WriteLine($"<p>{social.CharNoTarget}</p>", player.ConnectionId);

                foreach (var pc in room.Players)
                {
                    if (pc.Id == player.Id)
                    {
                        continue;
                    }
                    _writeToClient.WriteLine($"<p>{ReplaceSocialTags(social.RoomNoTarget, player, null)}</p>", pc.ConnectionId);
                }

                return;
            }

            var getTarget = target.Equals("self", StringComparison.CurrentCultureIgnoreCase) ? player : room.Players.FirstOrDefault(x => x.Name.StartsWith(target, StringComparison.CurrentCultureIgnoreCase));

            if (getTarget == null)
            {
                getTarget = room.Mobs.FirstOrDefault(x => x.Name.StartsWith(target, StringComparison.CurrentCultureIgnoreCase));
            }
            if (getTarget != null)
            {
                if (getTarget.Id == player.Id)
                {
                    foreach (var pc in room.Players)
                    {
                        if (pc.Id == player.Id)
                        {
                            _writeToClient.WriteLine($"<p>{ReplaceSocialTags(social.TargetSelf, player, getTarget)}</p>", pc.ConnectionId);
                            continue;
                        }
                        _writeToClient.WriteLine($"<p>{ReplaceSocialTags(social.RoomSelf, player, getTarget)}</p>", pc.ConnectionId);
                    }
                    return;
                }
                _writeToClient.WriteLine($"<p>{ReplaceSocialTags(social.TargetFound, player,getTarget)}<p>", player.ConnectionId);
                _writeToClient.WriteLine($"<p>{ReplaceSocialTags(social.ToTarget, player, getTarget)}</p>", getTarget.ConnectionId);
                foreach (var pc in room.Players)
                {
                    if (pc.Id == player.Id || pc.Id == getTarget.Id)
                    {
                        continue;
                    }
                    _writeToClient.WriteLine($"<p>{ReplaceSocialTags(social.RoomTarget, player,getTarget)}</p>", pc.ConnectionId);
                }
            }
            else
            {
                _writeToClient.WriteLine("<p>They are not here.</p>", player.ConnectionId);
            }
        }
Example #9
0
        public void ShowSkills(Player player, string fullCommand)
        {
            if (fullCommand.Equals("skills all", StringComparison.CurrentCultureIgnoreCase))
            {
                ReturnSkillList(player.Skills.Where(x => x.IsSpell == false).ToList(), player, "Skills:");
                return;
            }

            if (fullCommand.Equals("skills", StringComparison.CurrentCultureIgnoreCase) || fullCommand.Equals("skill", StringComparison.CurrentCultureIgnoreCase))
            {
                ReturnSkillList(player.Skills.Where(x => x.IsSpell == false && x.Level <= player.Level).ToList(), player, "Skills:");
                return;
            }

            if (fullCommand.Equals("spells all", StringComparison.CurrentCultureIgnoreCase))
            {
                var spells = player.Skills.Where(x => x.IsSpell == true).ToList();

                if (spells.Any())
                {
                    ReturnSkillList(player.Skills.Where(x => x.IsSpell == true).ToList(), player, "Spells:");
                    return;
                }
                else
                {
                    _writeToClient.WriteLine("You have no spells, try skills instead.", player.ConnectionId);
                    return;
                }
            }

            if (fullCommand.Equals("spells", StringComparison.CurrentCultureIgnoreCase))
            {
                var spells = player.Skills.Where(x => x.IsSpell == true && x.Level <= player.Level).ToList();
                if (spells.Any())
                {
                    ReturnSkillList(player.Skills.Where(x => x.IsSpell == true && x.Level <= player.Level).ToList(), player, "Spells:");
                    return;
                }
                else
                {
                    _writeToClient.WriteLine("You have no spells, try skills instead.", player.ConnectionId);
                    return;
                }
            }


            ReturnSkillList(player.Skills.ToList(), player, "Skills &amp; Spells:");
        }
Example #10
0
        public void List(Player player)
        {
            var inventory = new StringBuilder();

            inventory.Append("<p>You are carrying:</p>");

            if (player.Inventory.Count > 0)
            {
                inventory.Append("<ul>");


                foreach (var item in player.Inventory.List(false))
                {
                    inventory.Append($"<li>{item.Name}</li>");
                }

                inventory.Append("</ul>");
            }
            else
            {
                inventory.Append("<p>Nothing.</p>");
            }


            _writer.WriteLine(inventory.ToString(), player.ConnectionId);
        }
Example #11
0
        public void IsQuestMob(Player player, string mobName)
        {
            foreach (var quest in player.QuestLog)
            {
                if (quest.Type != QuestTypes.Kill)
                {
                    continue;
                }

                var questCompleted = false;

                foreach (var mob in quest.MobsToKill)
                {
                    if (!mob.Name.Equals(mobName))
                    {
                        continue;
                    }

                    mob.Current    = mob.Current + 1;
                    questCompleted = mob.Count == mob.Current;
                }


                if (questCompleted)
                {
                    quest.Completed = true;

                    _writeToClient.WriteLine($"<h3 class='gain'>{quest.Title} Completed!</h3><p>Return to the quest giver for your reward.</p>", player.ConnectionId);
                }
            }
            _updateClientUi.UpdateQuest(player);
        }
Example #12
0
        public void Who(Player player)
        {
            var sb = new StringBuilder();

            sb.Append("<ul>");
            foreach (var pc in _cache.GetPlayerCache())
            {
                sb.Append(
                    $"<li>[{pc.Value.Level} {pc.Value.Race} {pc.Value.ClassName}] ");
                sb.Append(
                    $"<span class='player'>{pc.Value.Name}</span></li>");
            }

            sb.Append("</ul>");
            sb.Append($"<p>Players found: {_cache.GetPlayerCache().Count}</p>");

            _writeToClient.WriteLine(sb.ToString(), player.ConnectionId);
        }
        public void DamagePlayer(string spellName, int damage, Player player, Player target, Room room)
        {
            if (_fight.IsTargetAlive(target))
            {
                var totalDam = _fight.CalculateSkillDamage(player, target, damage);

                _writer.WriteLine(
                    $"<p>Your {spellName} {_damage.DamageText(totalDam).Value} {target.Name}  <span class='damage'>[{damage}]</span></p>",
                    player.ConnectionId);
                _writer.WriteLine(
                    $"<p>{player.Name}'s {spellName} {_damage.DamageText(totalDam).Value} you!  <span class='damage'>[{damage}]</span></p>",
                    target.ConnectionId);

                foreach (var pc in room.Players)
                {
                    if (pc.ConnectionId.Equals(player.ConnectionId) ||
                        pc.ConnectionId.Equals(target.ConnectionId))
                    {
                        continue;
                    }

                    _writer.WriteLine(
                        $"<p>{player.Name}'s {spellName} {_damage.DamageText(totalDam).Value} {target.Name}  <span class='damage'>[{damage}]</span></p>",
                        pc.ConnectionId);
                }

                target.Attributes.Attribute[EffectLocation.Hitpoints] -= totalDam;

                if (!_fight.IsTargetAlive(target))
                {
                    _fight.TargetKilled(player, target, room);

                    _updateClientUi.UpdateHP(target);
                    return;
                    //TODO: create corpse, refactor fight method from combat.cs
                }

                //update UI
                _updateClientUi.UpdateHP(target);

                _fight.AddCharToCombat(target);
                _fight.AddCharToCombat(player);
            }
        }
Example #14
0
        public int Haggle(Player player, Player target)
        {
            var foundSkill = player.Skills.FirstOrDefault(x =>
                                                          x.SkillName.StartsWith("haggle", StringComparison.CurrentCultureIgnoreCase));

            if (foundSkill == null)
            {
                return(0);
            }

            var getSkill = _cache.GetSkill(foundSkill.SkillId);

            if (getSkill == null)
            {
                var skill = _cache.GetAllSkills().FirstOrDefault(x => x.Name.Equals("haggle", StringComparison.CurrentCultureIgnoreCase));
                foundSkill.SkillId = skill.Id;
                getSkill           = skill;
            }

            var proficiency = foundSkill.Proficiency;
            var success     = _dice.Roll(1, 1, 100);

            if (success == 1 || success == 101)
            {
                return(0);
            }

            //TODO Charisma Check
            if (proficiency >= success)
            {
                _writer.WriteLine($"<p>You charm {target.Name} in offering you favourable prices.</p>",
                                  player.ConnectionId);
                return(25);
            }

            _writer.WriteLine("<p>Your haggle attempts fail.</p>",
                              player.ConnectionId);

            if (foundSkill.Proficiency == 100)
            {
                return(0);
            }

            var increase = _dice.Roll(1, 1, 5);

            foundSkill.Proficiency += increase;

            _gain.GainExperiencePoints(player, 100 * foundSkill.Level / 4, false);

            _updateClientUi.UpdateExp(player);

            _writer.WriteLine(
                $"<p class='improve'>You learn from your mistakes and gain {100 * foundSkill.Level / 4} experience points.</p>" +
                $"<p class='improve'>Your knowledge of {foundSkill.SkillName} increases by {increase}%.</p>",
                player.ConnectionId, 0);

            return(0);
        }
Example #15
0
        public Item.Item CheckTargetItem(Spell.Model.Spell spell, string target, Room room, Player player)
        {
            var item = GetTargetItem(target, player);

            if (item == null)
            {
                _writer.WriteLine("You can't find that item on you.", player.ConnectionId);
                return(null);
            }

            return(item);
        }
Example #16
0
        public void SendHelpFileToUser(Help help, Player player)
        {
            var sb = new StringBuilder();


            sb.Append("<div class='help-section'><table><tr>");
            sb.Append($"<td>Help Title</td><td>{help.Title}</td></tr>");

            sb.Append($"<td>Help Keywords</td><td>{help.Keywords}</td></tr>");

            if (!string.IsNullOrEmpty(help.RelatedHelpFiles))
            {
                sb.Append($"<tr><td>Related Helps</td><td>{help.RelatedHelpFiles}</td></tr>");
            }

            sb.Append($"<tr><td>Last Updated</td><td>{help.DateUpdated.Value:MMMM dd, yyyy}</td></tr></table>");

            sb.Append($"<pre>{help.Description}</pre>");

            _writer.WriteLine(sb.ToString(), player.ConnectionId);
        }
Example #17
0
        public void GainExperiencePoints(Player player, Player target)
        {
            var expWorth = GetExpWorth(target);

            if (Math.Floor((double)(player.Level / 2)) > target.Level)
            {
                expWorth /= 2;
            }
            player.Experience            += expWorth;
            player.ExperienceToNextLevel -= expWorth;

            _clientUi.UpdateExp(player);

            if (expWorth == 1)
            {
                _writer.WriteLine(
                    $"<p class='improve'>You gain 1 measly experience point.</p>",
                    player.ConnectionId);
            }

            _writer.WriteLine(
                $"<p class='improve'>You receive {expWorth} experience points.</p>",
                player.ConnectionId);

            GainLevel(player);
            _clientUi.UpdateExp(player);
        }
        public Player CheckTarget(Skill.Model.Skill spell, string target, Room room, Player player)
        {
            var victim = GetTarget(target, room);

            if (victim == null)
            {
                _writer.WriteLine(
                    (spell.ValidTargets & ValidTargets.TargetPlayerWorld) != 0
                        ? "You can't find them in the realm."
                        : "You don't see them here.", player.ConnectionId);

                return(null);
            }

            if (spell.StartsCombat && victim.Id == player.Id)
            {
                _writer.WriteLine("Casting this on yourself is a bad idea.", player.ConnectionId);
                return(null);
            }

            return(victim);
        }
Example #19
0
        public void Say(string text, Room room, Player player)
        {
            _writer.WriteLine($"<p class='say'>You say {text}</p>", player.ConnectionId);
            foreach (var pc in room.Players)
            {
                if (pc.Name == player.Name)
                {
                    continue;
                }

                _writer.WriteLine($"<p class='say'>{player.Name} says {text}</p>", pc.ConnectionId);
                _updateClient.UpdateCommunication(pc, $"<p class='say'>{player.Name} says {text}</p>", "room");
            }
            _updateClient.UpdateCommunication(player, $"<p class='say'>You say {text}</p>", "room");
        }
Example #20
0
        public void DisplayTimeOfDayMessage(string TickMessage)
        {
            var players = _cache.GetPlayerCache();

            foreach (var pc in players.Values)
            {
                var room = _cache.GetRoom(pc.RoomId);

                if (room.Terrain != Room.TerrainType.Inside && room.Terrain != Room.TerrainType.Underground && !string.IsNullOrEmpty(TickMessage))
                {
                    _writeToClient.WriteLine(TickMessage, pc.ConnectionId);
                }
            }
        }
Example #21
0
        public void HandleCommand(string key, string obj, string target, Player player, Room room)
        {
            // oddballs is shit name
            // but might be times where we need a command to trigger
            // a skill that does not match the name
            // here second matches on second attack
            // but I want second to allow selecting a second weapon
            var oddBalls = new List <Tuple <string, string> >()
            {
                new Tuple <string, string>("second", "dual wield"),
                new Tuple <string, string>("warcry", "war cry"),
            };

            var oddBallMatch = oddBalls.FirstOrDefault(x => x.Item1.StartsWith(key));

            if (oddBallMatch != null)
            {
                key = oddBallMatch.Item2;
            }


            //check player skill
            var foundSkill = _cache.GetAllSkills()
                             .FirstOrDefault(x => x.Name.StartsWith(key, StringComparison.CurrentCultureIgnoreCase) && x.Type != SkillType.Passive);

            if (foundSkill != null)
            {
                _Skill.PerfromSkill(foundSkill, key, player, obj, room);
                return;
            }



            //check socials
            var social = _cache.GetSocials().Keys.FirstOrDefault(x => x.StartsWith(key));

            if (social != null)
            {
                var emoteTarget = key == obj ? "" : obj;
                _socials.EmoteSocial(player, room, _cache.GetSocials()[social], emoteTarget);
                return;
            }


            _writeToClient.WriteLine("That is not a command.", player.ConnectionId);
        }
Example #22
0
        public void DisplayTimeOfDayMessage(string TickMessage)
        {
            var players = _cache.GetPlayerCache();

            foreach (var pc in players.Values)
            {
                var room = _cache.GetRoom(pc.RoomId);

                if (room == null)
                {
                    return;
                }

                if (room.Terrain != Room.TerrainType.Inside && room.Terrain != Room.TerrainType.Underground && !string.IsNullOrEmpty(TickMessage))
                {
                    _writeToClient.WriteLine($"<span class='time-of-day'>{TickMessage}</span>", pc.ConnectionId);
                }
            }
        }
Example #23
0
        public void DisplayScore(Player player)
        {
            var sb = new StringBuilder();

            sb.Append($"<table class=\"score-table\"><tr><td class=\"cell-title\">Level:</td><td>{player.Level}</td><td class=\"cell-title\">Race:</td><td>{player.Race}</td><td class=\"cell-title\">Born on:</td><td>{player.DateCreated}</td></tr>");
            sb.Append($"<tr><td class=\"cell-title\">Years:</td><td>n/a</td><td class=\"cell-title\">Class:</td><td>{player.ClassName}</td><td class=\"cell-title\">Played:</td><td>{player.PlayTime} hours</td></tr>");
            sb.Append($"<tr><td class=\"cell-title\">STR:</td><td>{player.Attributes.Attribute[EffectLocation.Strength]}({player.MaxAttributes.Attribute[EffectLocation.Strength]})</td><td class=\"cell-title\"></td> <!-- hit roll --><td></td><td class=\"cell-title\">Sex:</td><td>{player.Gender}</td></tr>");
            sb.Append($"<tr><td class=\"cell-title\">DEX:</td><td>{player.Attributes.Attribute[EffectLocation.Dexterity]}({player.MaxAttributes.Attribute[EffectLocation.Dexterity]})<td class=\"cell-title\"></td><!-- dam roll --><td></td><td class=\"cell-title\">Wimpy:</td><td>XX</td></tr>");
            sb.Append($"<tr><td class=\"cell-title\">Con:</td><td>{player.Attributes.Attribute[EffectLocation.Constitution]}({player.MaxAttributes.Attribute[EffectLocation.Constitution]})<td class=\"cell-title\">Align:</td><td>{player.AlignmentScore}</td><td></td><td></td></tr>");
            sb.Append($"<tr><td class=\"cell-title\">INT:</td><td>{player.Attributes.Attribute[EffectLocation.Intelligence]}({player.MaxAttributes.Attribute[EffectLocation.Intelligence]})<td class=\"cell-title\">Armour:</td><td>xxx</td><td></td><td></td></tr>");
            sb.Append($"<tr><td class=\"cell-title\">WIS:</td><td>{player.Attributes.Attribute[EffectLocation.Wisdom]}({player.MaxAttributes.Attribute[EffectLocation.Wisdom]})<td class=\"cell-title\">Pos'n:</td><td>Standing</td><td></td><td></td></tr>");
            sb.Append($"<tr><td class=\"cell-title\">CHA:</td><td>{player.Attributes.Attribute[EffectLocation.Charisma]}({player.MaxAttributes.Attribute[EffectLocation.Charisma]})<td class=\"cell-title\">Style:</td><td>Standard</td><td></td><td></td></tr>");
            sb.Append("<tr><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td class=\"cell-title\"></td><td></td><td></td><td></td></tr>");
            sb.Append($"<tr><td class=\"cell-title\">Qpoints:</td><td>0</td><td class=\"cell-title\">HP</td><td> {player.Attributes.Attribute[EffectLocation.Hitpoints]}/{player.MaxAttributes.Attribute[EffectLocation.Hitpoints]}</td><td class=\"cell-title\">weight:</td><td>{player.Attributes.Attribute[EffectLocation.Strength] * 3}(max:{player.Attributes.Attribute[EffectLocation.Strength] * 3})</td></tr>");
            sb.Append($"<tr><td class=\"cell-title\">Pract:</td><td>0</td><td class=\"cell-title\">Mana</td><td> {player.Attributes.Attribute[EffectLocation.Mana]}/{player.MaxAttributes.Attribute[EffectLocation.Mana]}</td><td class=\"cell-title\">Mkills:</td><td>0</td></tr>");
            sb.Append($"<tr><td class=\"cell-title\">Train:</td><td>0</td><td class=\"cell-title\">Moves</td><td> {player.Attributes.Attribute[EffectLocation.Moves]}/{player.MaxAttributes.Attribute[EffectLocation.Moves]}</td><td class=\"cell-title\">MDeaths:</td><td>0</td></tr>");
            sb.Append($"<tr><td class=\"cell-title\">Gold:</td><td>0</td><td class=\"cell-title\">XP</td><td>{player.Experience}</td><td class=\"cell-title\"></td><td></td></tr>");
            sb.Append($"<tr><td class=\"cell-title\">Bank:</td><td>0</td><td class=\"cell-title\">TNL</td><td>{player.ExperienceToNextLevel}</td><td class=\"cell-title\"></td><td></td></tr></table>");

            _writer.WriteLine(sb.ToString(), player.ConnectionId);
        }
        public void HandleCommand(string key, string obj, string target, Player player, Room room)
        {
            var foundCommand = false;

            //check player skills
            if (false)
            {
            }

            //check socials
            var social = _cache.GetSocials().Keys.FirstOrDefault(x => x.StartsWith(key));

            if (social != null)
            {
                foundCommand = true;
                var emoteTarget = key == obj ? "" : obj;
                _socials.EmoteSocial(player, room, _cache.GetSocials()[social], emoteTarget);
                return;
            }

            _writeToClient.WriteLine("That is not a command.", player.ConnectionId);
        }
Example #25
0
        public void DisplayInventory(Player mob, Player player)
        {
            var hagglePriceReduction = Haggle(player, mob);

            _writer.WriteLine(mob.Name + " says 'I offer the following spells:'", player.ConnectionId);
            var sb = new StringBuilder();

            sb.Append("<table class='data'><tr><td style='width: 275px; text-align: left;'>Spell</td><td>Price</td</tr>");

            int i = 0;

            foreach (var item in mob.SpellList.OrderBy(x => x.Cost))
            {
                i++;
                sb.Append($"<tr><td style='width: 275px; text-align: left;'>{item.Name}</td><td>{DisplayUnit(item.Cost, hagglePriceReduction)} GP</td></tr>");
            }

            sb.Append("</table>");
            sb.Append("<p>Type heal &lt;type&gt; to be healed.</p>");
            _writer.WriteLine(sb.ToString(), player.ConnectionId);
        }
Example #26
0
        public void List(Player player)
        {
            var inventory = new StringBuilder();

            inventory.Append("<p>You are carrying:</p>");

            if (player.Inventory.Where(x => x.Equipped == false).ToList().Count > 0)
            {
                inventory.Append("<ul>");
                var inv = new ItemList();

                foreach (var item in player.Inventory.Where(x => x.Equipped == false).ToList())
                {
                    inv.Add(item);
                }

                foreach (var item in inv.List(false))
                {
                    if (player.Affects.Blind)
                    {
                        inventory.Append($"<li>Something</li>");
                    }
                    else
                    {
                        inventory.Append($"<li>{item.Name}</li>");
                    }
                }

                inventory.Append("</ul>");
            }
            else
            {
                inventory.Append("<p>Nothing.</p>");
            }


            _writer.WriteLine(inventory.ToString(), player.ConnectionId);
        }
Example #27
0
        public void Get(string target, string container, Room room, Player player)
        {
            //TODO: Get all, get nth (get 2.apple)
            if (target == "all" && string.IsNullOrEmpty(container))
            {
                GetAll(room, player);
                return;
            }

            if (!string.IsNullOrEmpty(container))
            {
                GetFromContainer(target, container, room, player);
                return;
            }

            //Check room first
            var item = room.Items.Where(x => x.Stuck == false).FirstOrDefault(x => x.Name.Contains(target, StringComparison.CurrentCultureIgnoreCase));

            if (item == null)
            {
                _writer.WriteLine("<p>You don't see that here.</p>", player.ConnectionId);
                return;
            }

            room.Items.Remove(item);

            foreach (var pc in room.Players)
            {
                if (pc.Name == player.Name)
                {
                    continue;
                }

                _writer.WriteLine($"<p>{player.Name} picks up {item.Name.ToLower()}.</p>", pc.ConnectionId);
            }

            player.Inventory.Add(item);
            _writer.WriteLine($"<p>You pick up {item.Name.ToLower()}.</p>", player.ConnectionId);
            _updateUi.UpdateInventory(player);
            room.Clean = false;
            // TODO: You are over encumbered
        }
Example #28
0
        public async Task UpdateTime()
        {
            Console.WriteLine("started loop");
            while (true)
            {
                //2 mins
                await Task.Delay(120000);

                var rooms   = _cache.GetAllRoomsToRepop();
                var players = _cache.GetPlayerCache().Values.ToList();

                foreach (var room in rooms)
                {
                    var originalRoom = _db.GetById <Room>(room.Id, DataBase.Collections.Room);

                    foreach (var mob in originalRoom.Mobs)
                    {
                        // need to check if mob exists before adding
                        var mobExist = room.Mobs.FirstOrDefault(x => x.Id.Equals(mob.Id));

                        if (mobExist == null)
                        {
                            room.Mobs.Add(mob);
                        }
                        else
                        {
                            mobExist.Attributes.Attribute[EffectLocation.Hitpoints] += _dice.Roll(1, 2, 5) * mobExist.Level;
                            mobExist.Attributes.Attribute[EffectLocation.Mana]      += _dice.Roll(1, 2, 5) * mobExist.Level;
                            mobExist.Attributes.Attribute[EffectLocation.Moves]     += _dice.Roll(1, 2, 5) * mobExist.Level;
                        }
                    }

                    foreach (var item in originalRoom.Items)
                    {
                        // need to check if item exists before adding
                        var itemExist = room.Items.FirstOrDefault(x => x.Id.Equals(item.Id));

                        if (itemExist == null)
                        {
                            room.Items.Add(item);
                        }
                    }

                    // reset doors
                    room.Exits = originalRoom.Exits;

                    //set room clean
                    room.Clean = true;

                    foreach (var player in room.Players)
                    {
                        _writeToClient.WriteLine("<p>The hairs on your neck stand up.</p>", player.ConnectionId);
                    }
                }

                foreach (var player in players)
                {
                    player.Attributes.Attribute[EffectLocation.Hitpoints] += _dice.Roll(1, 2, 5) * player.Level;
                    player.Attributes.Attribute[EffectLocation.Mana]      += _dice.Roll(1, 2, 5) * player.Level;
                    player.Attributes.Attribute[EffectLocation.Moves]     += _dice.Roll(1, 2, 5) * player.Level;

                    if (player.Attributes.Attribute[EffectLocation.Hitpoints] > player.MaxAttributes.Attribute[EffectLocation.Hitpoints])
                    {
                        player.Attributes.Attribute[EffectLocation.Hitpoints] = player.MaxAttributes.Attribute[EffectLocation.Hitpoints];
                    }

                    if (player.Attributes.Attribute[EffectLocation.Mana] > player.MaxAttributes.Attribute[EffectLocation.Mana])
                    {
                        player.Attributes.Attribute[EffectLocation.Mana] = player.MaxAttributes.Attribute[EffectLocation.Mana];
                    }

                    if (player.Attributes.Attribute[EffectLocation.Moves] > player.MaxAttributes.Attribute[EffectLocation.Moves])
                    {
                        player.Attributes.Attribute[EffectLocation.Moves] = player.MaxAttributes.Attribute[EffectLocation.Moves];
                    }

                    _client.UpdateHP(player);
                    _client.UpdateMana(player);
                    _client.UpdateMoves(player);
                    _client.UpdateScore(player);
                }
            }
        }
Example #29
0
        public void DisplayInventory(Player mob, Player player)
        {
            _writer.WriteLine(mob.Name + " says 'Here's what I have for sale.'", player.ConnectionId);
            var sb = new StringBuilder();

            sb.Append("<table class='data'><tr><td style='width: 30px; text-align: center;'>#</td><td style='width: 30px; text-align: center;'>Level</td><td  style='width: 65px;'>Price</td><td>Item</td></tr>");

            int i = 0;

            foreach (var item in mob.Inventory.Distinct().OrderBy(x => x.Level).ThenBy(x => x.Value))
            {
                i++;
                sb.Append($"<tr><td style='width: 30px; text-align: center;'>{i}</td><td style='width: 30px; text-align: center;'>{item.Level}</td><td  style='width: 65px;'>{DisplayUnit(item.Value)}</td><td>{item.Name}</td></tr>");
            }

            sb.Append("</table>");
            _writer.WriteLine(sb.ToString(), player.ConnectionId);
        }
Example #30
0
        public void Move(Room room, Player character, string direction)
        {
            switch (character.Status)
            {
            case CharacterStatus.Status.Fighting:
            case CharacterStatus.Status.Incapacitated:
                _writeToClient.WriteLine("<p>NO WAY! you are fighting.</p>", character.ConnectionId);
                return;

            case CharacterStatus.Status.Resting:
                _writeToClient.WriteLine("<p>Nah... You feel too relaxed to do that..</p>", character.ConnectionId);
                return;

            case CharacterStatus.Status.Sleeping:
                _writeToClient.WriteLine("<p>In your dreams.</p>", character.ConnectionId);
                return;

            case CharacterStatus.Status.Stunned:
                _writeToClient.WriteLine("<p>You are too stunned to move.</p>", character.ConnectionId);
                return;
            }

            if (CharacterCanMove(character) == false)
            {
                _writeToClient.WriteLine("<p>You are too exhausted to move.</p>", character.ConnectionId);
                return;
            }


            var getExitToNextRoom = FindExit(room, direction);

            if (getExitToNextRoom == null)
            {
                _writeToClient.WriteLine("<p>You can't go that way.</p>", character.ConnectionId);
                return;
            }


            var nextRoomKey =
                $"{getExitToNextRoom.AreaId}{getExitToNextRoom.Coords.X}{getExitToNextRoom.Coords.Y}{getExitToNextRoom.Coords.Z}";
            var getNextRoom = _cache.GetRoom(nextRoomKey);

            if (getNextRoom == null)
            {
                _writeToClient.WriteLine("<p>A mysterious force prevents you from going that way.</p>", character.ConnectionId);
                //TODO: log bug that the new room could not be found
                return;
            }

            //flee bug
            character.Status = CharacterStatus.Status.Standing;

            if (getExitToNextRoom.Closed)
            {
                _writeToClient.WriteLine("<p>The door is close.</p>", character.ConnectionId);
                //TODO: log bug that the new room could not be found
                return;
            }

            OnPlayerLeaveEvent(room, character);
            NotifyRoomLeft(room, character, direction);

            NotifyRoomEnter(getNextRoom, character, direction);

            UpdateCharactersLocation(getExitToNextRoom, character, room);

            character.Attributes.Attribute[EffectLocation.Moves] -= 1;

            if (character.Attributes.Attribute[EffectLocation.Moves] < 0)
            {
                character.Attributes.Attribute[EffectLocation.Moves] = 0;
            }

            if (character.ConnectionId == "mob")
            {
                return;
            }

            _roomActions.Look("", getNextRoom, character);

            OnPlayerEnterEvent(getNextRoom, character);


            _updateUi.GetMap(character, _cache.GetMap(getExitToNextRoom.AreaId));
            _updateUi.UpdateMoves(character);

            if (character.Followers.Count >= 1)
            {
                foreach (var follower in character.Followers)
                {
                    if (room.Players.Contains(follower))
                    {
                        Move(room, follower, direction);
                    }
                }
            }
        }