Пример #1
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 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);
            }
        }
Пример #2
0
        /// <summary>
        /// Shows attack and damage to player
        /// </summary>
        /// <param name="attacker">the attacker</param>
        /// <param name="defender">the defender</param>
        /// <param name="room">The rom</param>
        /// <param name="toHit">Target tohit value</param>
        /// <param name="chance">Chance to hit value</param>
        /// <param name="skillUsed">This is used for skills and spells only</param>
        /// <param name="damage">This is used for skills and spells only</param>
        public static void ShowAttack(Player attacker, Player defender, Room room, double toHit, int chance, Skill skillUsed, int damage = 0)
        {
            bool alive      = IsAlive(attacker, defender);
            int  IsCritical = CriticalHit(toHit, chance);

            if (alive)
            {
                if (toHit > chance)
                {
                    var dam = damage > 0 ? damage : Damage(attacker, defender, IsCritical);

                    var damageText = DamageText(dam);


                    HubContext.SendToClient("Your " + WeaponAttackName(attacker, skillUsed).Key + " " + damageText.Value + " " + Helpers.ReturnName(defender, attacker, null) + " [" + dam + "]", attacker.HubGuid);

                    HubContext.SendToClient(Helpers.ReturnName(attacker, defender, null) + "'s " + WeaponAttackName(attacker, skillUsed).Value + " " + damageText.Value + " you [" + dam + "]", defender.HubGuid);

                    HubContext.SendToAllExcept(Helpers.ReturnName(attacker, defender, null) + "'s " + WeaponAttackName(attacker, skillUsed).Value + " " + damageText.Value + " " + Helpers.ReturnName(defender, attacker, null), room.fighting, room.players);

                    defender.HitPoints -= dam;

                    if (defender.HitPoints < 0)
                    {
                        defender.HitPoints = 0;
                    }


                    if (!IsAlive(attacker, defender))
                    {
                        IsDead(attacker, defender, room);
                    }
                }
                else
                {
                    HubContext.SendToClient("Your " + WeaponAttackName(attacker, skillUsed).Key + " misses " + Helpers.ReturnName(defender, attacker, null), attacker.HubGuid);

                    HubContext.SendToClient(Helpers.ReturnName(attacker, defender, null) + "'s " + WeaponAttackName(attacker, skillUsed).Key + " misses you ", defender.HubGuid);

                    HubContext.SendToAllExcept(Helpers.ReturnName(attacker, defender, null) + "'s " + WeaponAttackName(attacker, skillUsed).Key + " misses " + Helpers.ReturnName(defender, attacker, null), room.fighting, room.players);
                }
            }
        }
Пример #3
0
        public static void ShowAttack(Player attacker, Player defender, Room room, double toHit, int chance)
        {
            bool alive      = IsAlive(attacker, defender);
            int  IsCritical = CriticalHit(toHit, chance);

            if (alive)
            {
                if (toHit > chance)
                {
                    int dam        = Damage(attacker, defender, IsCritical);
                    var damageText = DamageText(dam);


                    HubContext.SendToClient("Your hit " + damageText.Value + " " + defender.Name + "[" + dam + "]", attacker.HubGuid);

                    HubContext.SendToClient(attacker.Name + "'s hit " + damageText.Value + " you [" + dam + "]", defender.HubGuid);


                    defender.HitPoints -= dam;

                    if (defender.HitPoints < 0)
                    {
                        defender.HitPoints = 0;
                    }
                    HubContext.SendToAllExcept(attacker.Name + "'s hit " + damageText.Value + " " + defender.Name, room.fighting, room.players);

                    if (!IsAlive(attacker, defender))
                    {
                        IsDead(attacker, defender, room);
                    }
                }
                else
                {
                    HubContext.SendToClient("You miss " + defender.Name, attacker.HubGuid);

                    HubContext.SendToClient(attacker.Name + " misses you ", defender.HubGuid);

                    HubContext.SendToAllExcept(attacker.Name + " misses " + defender.Name, room.fighting, room.players);
                }
            }
        }
Пример #4
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;
        }
Пример #5
0
        public static void IsDead(Player attacker, Player defender, Room room)
        {
            if (defender.HitPoints <= 0)
            {
                HubContext.SendToAllExcept(defender.Name + " dies ", room.fighting, room.players);


                HubContext.SendToClient("You die", defender.HubGuid);

                HubContext.SendToClient(defender.Name + " dies", attacker.HubGuid);

                defender.Target = null;


                //Turn corpse into room item
                var defenderCorpse = new Item
                {
                    name           = "The corpse of " + defender.Name,
                    container      = true,
                    containerItems = new List <Item>(),
                    description    = new Description {
                        look = "The slain corpse of " + defender.Name + " is here.", room = "The slain corpse of " + defender.Name
                    }
                };

                foreach (var invItem in defender.Inventory)
                {
                    invItem.location = Item.ItemLocation.Room;
                    defenderCorpse.containerItems.Add(invItem);
                }



                var oldRoom = room;
                room.items.Add(defenderCorpse);
                room.corpses.Add(defender);

                if (defender.Type == Player.PlayerTypes.Mob || string.IsNullOrEmpty(defender.HubGuid))
                {
                    room.mobs.Remove(defender);
                }
                else
                {
                    //room.players.Remove(defender);
                    //Add slain player to recall
                }

                defender.Target = null;
                attacker.Target = null;

                attacker.Status = PlayerSetup.Player.PlayerStatus.Standing;

                defender.Status = defender.Type == Player.PlayerTypes.Player ? PlayerSetup.Player.PlayerStatus.Ghost : PlayerSetup.Player.PlayerStatus.Dead;

                Cache.updateRoom(room, oldRoom);

                var xp = new Experience();

                int xpGain = xp.GainXp(attacker, defender);
                attacker.Experience      += xpGain;
                attacker.TotalExperience += xpGain;
                HubContext.SendToClient(xpGain + "XP", attacker.HubGuid);

                xp.GainLevel(attacker);
                //calc xp
                //create corpse

                foreach (var player in room.players)
                {
                    var roomdata = LoadRoom.DisplayRoom(room, player.Name);
                    Score.UpdateUiRoom(player, roomdata);
                }
            }
        }
Пример #6
0
        private static async Task DoMagicMissile(Player attacker, Room room)
        {
            _taskRunnning   = true;
            attacker.Status = Player.PlayerStatus.Busy;


            await Task.Delay(1000);


            //get attacker strength
            var die = new PlayerStats();

            var ballCount = 1;

            if (attacker.Level == 1)
            {
                ballCount = 1;
            }
            else if (attacker.Level <= 5)
            {
                ballCount = 2;
            }
            else if (attacker.Level <= 10)
            {
                ballCount = 3;
            }
            else if (attacker.Level <= 15)
            {
                ballCount = 4;
            }
            else if (attacker.Level >= 20)
            {
                ballCount = 5;
            }

            var castingTextAttacker = ballCount == 1  ? "A red crackling energy ball hurls from your hands straight at " + Helpers.ReturnName(attacker.Target, null) : ballCount + " red crackling energy balls hurl from your hands in a wide arc closing in on " + Helpers.ReturnName(attacker.Target, null);

            var castingTextDefender = ballCount == 1 ? Helpers.ReturnName(attacker, null) + " hurls a red crackling energy ball straight towards you."
                :  Helpers.ReturnName(attacker, null) + " launches " + ballCount + " red crackling energy balls from " + Helpers.ReturnHisOrHers(attacker.Gender) + "  hands in a wide arc closing in on you";


            var castingTextRoom = ballCount == 1 ? Helpers.ReturnName(attacker, null) + " hurls a red crackling energy ball straight towards " + Helpers.ReturnName(attacker.Target, null) + "."
              : Helpers.ReturnName(attacker, null) + " launches " + ballCount + " red crackling energy balls from " + Helpers.ReturnHisOrHers(attacker.Gender) + "  hands in a wide arc closing in on" + Helpers.ReturnName(attacker.Target, null);



            //level dependant but for testing launch 4 balls
            HubContext.SendToClient(castingTextAttacker, attacker.HubGuid);
            HubContext.SendToClient(castingTextDefender, attacker.Target.HubGuid);
            HubContext.SendToAllExcept(castingTextRoom, room.fighting, room.players);

            for (int i = 0; i < ballCount; i++)
            {
                var dam    = die.dice(1, 4);
                var toHit  = Helpers.GetPercentage(attacker.Skills.Find(x => x.Name.Equals(MagicMissileAb().Name, StringComparison.CurrentCultureIgnoreCase)).Proficiency, 95); // always 5% chance to miss
                int chance = die.dice(1, 100);
                Fight2.ShowAttack(attacker, attacker.Target, room, toHit, chance, MagicMissileAb(), dam);
            }



            _taskRunnning   = false;
            attacker.Status = Player.PlayerStatus.Fighting;
        }
Пример #7
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));
                }
            }
        }