Exemple #1
0
        public static Boolean WeaponSkill(Player Attacker, AdvancedEntity Target)
        {
            try
            {
                if (Attacker.TransformEndTime != 0)
                {
                    return(false);
                }

                Item RWeapon = Attacker.GetItemByPos(4);
                Item LWeapon = Attacker.GetItemByPos(5);

                Int16 RType = 0;
                if (RWeapon != null)
                {
                    RType = (Int16)(RWeapon.Type / 1000);
                }

                Int16 LType = 0;
                if (LWeapon != null)
                {
                    LType = (Int16)(LWeapon.Type / 1000);
                }

                if (RType == 421)
                {
                    RType = 420;
                }

                if (LType == 421)
                {
                    LType = 421;
                }

                List <UInt16> Magics = new List <UInt16>();
                foreach (var magic in Attacker.Magics)
                {
                    if (!magic.TargetType.HasFlag(MagicTarget.Passive))
                    {
                        continue;
                    }

                    if (magic.WeaponSubtype != 0 && magic.WeaponSubtype != RType && magic.WeaponSubtype != LType)
                    {
                        continue;
                    }

                    Magics.Add(magic.Type);
                }

                if (Magics.Count <= 0)
                {
                    return(false);
                }

                Byte           RandNumber = (Byte)MyMath.Generate(0, (Magics.Count - 1));
                COServer.Magic WMagic     = Attacker.GetMagicByType(Magics.ToArray()[RandNumber]);
                if (WMagic != null)
                {
                    Magic.Info Info = new Magic.Info();
                    if (Database.AllMagics.TryGetValue((WMagic.Type * 10) + WMagic.Level, out Info))
                    {
                        if (MyMath.Success(Info.Success))
                        {
                            Attacker.MagicType  = WMagic.Type;
                            Attacker.MagicLevel = WMagic.Level;
                            if (Info.Sort == MagicSort.AtkStatus || Info.Sort == MagicSort.Line)
                            {
                                Battle.UseMagic(Attacker, Target, Attacker.X, Attacker.Y);
                                Attacker.MagicType  = 0;
                                Attacker.MagicLevel = 0;
                                return(true);
                            }
                            else
                            {
                                Battle.UseMagic(Attacker, null, Attacker.X, Attacker.Y);
                                Attacker.MagicType  = 0;
                                Attacker.MagicLevel = 0;
                                return(true);
                            }
                        }
                    }
                }
                return(false);
            }
            catch (Exception exc) { sLogger.Error(exc); return(false); }
        }
Exemple #2
0
        /// <summary>
        /// Disconnect the client.
        /// </summary>
        public void Disconnect()
        {
            try
            {
                if (Player != null)
                {
                    if (Player.TransformEndTime != 0)
                    {
                        if (Player.CurHP >= Player.MaxHP)
                        {
                            Player.CurHP = Player.MaxHP;
                        }
                        Double Multiplier = (Double)Player.CurHP / (Double)Player.MaxHP;
                        Player.CalcMaxHP();
                        Player.CurHP = (Int32)(Player.MaxHP * Multiplier);

                        MyMath.GetEquipStats(Player);
                    }
                    //User.mThread.Stop();

                    Database.Save(Player, false);

                    //Mine
                    if (Player.Mining)
                    {
                        Player.Mining = false;
                    }

                    //Booth
                    if (Player.Booth != null)
                    {
                        Player.Booth.Destroy();
                    }

                    //Team
                    if (Player.Team != null)
                    {
                        if (Player.Team.Leader.UniqId == Player.UniqId)
                        {
                            Player.Team.Dismiss(Player);
                        }
                        else
                        {
                            Player.Team.DelMember(Player, true);
                        }
                        Player.Team = null;
                    }

                    // Pet
                    if (Player.Pet != null)
                    {
                        Player.Pet.Brain.Sleep();
                        Player.Pet.Disappear();
                        Player.Pet = null;
                    }

                    //Deal
                    if (Player.Deal != null)
                    {
                        Player.Deal.Release();
                    }

                    //Friends
                    foreach (Int32 FriendUID in Player.Friends.Keys)
                    {
                        Player Friend = null;
                        if (!World.AllPlayers.TryGetValue(FriendUID, out Friend))
                        {
                            continue;
                        }

                        Friend.Send(new MsgFriend(Player.UniqId, Player.Name, MsgFriend.Status.Offline, MsgFriend.Action.FriendOffline));
                    }

                    //Enemies
                    foreach (Player Enemy in World.AllPlayers.Values)
                    {
                        if (!Enemy.Enemies.ContainsKey(Player.UniqId))
                        {
                            continue;
                        }

                        Enemy.Send(new MsgFriend(Player.UniqId, Player.Name, MsgFriend.Status.Offline, MsgFriend.Action.EnemyOffline));
                    }

                    //Screen
                    if (Player.Screen != null)
                    {
                        Player.Screen.Clear(true);
                    }

                    Player.Map.DelEntity(Player);

                    if (World.AllPlayers.ContainsKey(Player.UniqId))
                    {
                        World.AllPlayers.Remove(Player.UniqId);
                    }

                    if (World.AllPlayerNames.ContainsKey(Player.Name))
                    {
                        World.AllPlayerNames.Remove(Player.Name);
                    }

                    Player.Dispose();
                    Player = null;
                }

                Server.NetworkIO.DelClient(this, ref mNetworkWorker);

                if (mSocket != null && mSocket.IsAlive)
                {
                    mSocket.Disconnect();
                }
            }
            catch (Exception exc) { Console.WriteLine(exc); }
        }
Exemple #3
0
        public static void GetLevelStats(Player Player)
        {
            Byte Lvl = (Byte)Player.Level;
            Byte Job = Player.Profession;

            if (Player.Level > 120)
            {
                Lvl = 120;
            }

            if (Player.Profession > 129 && Player.Profession < 136)
            {
                Job = (Byte)(Player.Profession + 60);
            }
            else if (Player.Profession > 139 && Player.Profession < 146)
            {
                Job = (Byte)(Player.Profession + 50);
            }
            else if (Player.Profession > 99 && Player.Profession < 116)
            {
                Job = (Byte)(Player.Profession + 90);
            }

            Job = (Byte)(Job - (Job % 10));

            if (Player.AutoAllot)
            {
                Player.Strength = (UInt16)Database.AllPointAllot[Job, Lvl][0];
                Player.Agility  = (UInt16)Database.AllPointAllot[Job, Lvl][1];
                Player.Vitality = (UInt16)Database.AllPointAllot[Job, Lvl][2];
                Player.Spirit   = (UInt16)Database.AllPointAllot[Job, Lvl][3];

                if (Player.Level > 120)
                {
                    Player.AddPoints = (UInt16)((Player.Level - 120) * 3);
                }
            }
            else
            {
                Player.Strength = (UInt16)Database.AllPointAllot[Job, 1][0];
                Player.Agility  = (UInt16)Database.AllPointAllot[Job, 1][1];
                Player.Vitality = (UInt16)Database.AllPointAllot[Job, 1][2];
                Player.Spirit   = (UInt16)Database.AllPointAllot[Job, 1][3];

                Player.AddPoints = (UInt16)((Player.Level - 1) * 3);
            }

            if (Player.Metempsychosis > 0)
            {
                Player.AddPoints += 30;
            }

            if (Player.FirstLevel == 121 || (Player.FirstLevel == 112 && Player.FirstProfession == 135))
            {
                Player.AddPoints += 1;
            }
            else if (Player.FirstLevel == 122 || (Player.FirstLevel == 114 && Player.FirstProfession == 135))
            {
                Player.AddPoints += 3;
            }
            else if (Player.FirstLevel == 123 || (Player.FirstLevel == 116 && Player.FirstProfession == 135))
            {
                Player.AddPoints += 6;
            }
            else if (Player.FirstLevel == 124 || (Player.FirstLevel == 118 && Player.FirstProfession == 135))
            {
                Player.AddPoints += 10;
            }
            else if (Player.FirstLevel == 125 || (Player.FirstLevel == 120 && Player.FirstProfession == 135))
            {
                Player.AddPoints += 15;
            }
            else if (Player.FirstLevel == 126 || (Player.FirstLevel == 122 && Player.FirstProfession == 135))
            {
                Player.AddPoints += 21;
            }
            else if (Player.FirstLevel == 127 || (Player.FirstLevel == 124 && Player.FirstProfession == 135))
            {
                Player.AddPoints += 28;
            }
            else if (Player.FirstLevel == 128 || (Player.FirstLevel == 126 && Player.FirstProfession == 135))
            {
                Player.AddPoints += 36;
            }
            else if (Player.FirstLevel == 129 || (Player.FirstLevel == 128 && Player.FirstProfession == 135))
            {
                Player.AddPoints += 45;
            }
            else if (Player.FirstLevel == 130 || (Player.FirstLevel == 130 && Player.FirstProfession == 135))
            {
                Player.AddPoints += 55;
            }

            if (Player.SecondLevel == 121)
            {
                Player.AddPoints += 1;
            }
            else if (Player.SecondLevel == 122)
            {
                Player.AddPoints += 3;
            }
            else if (Player.SecondLevel == 123)
            {
                Player.AddPoints += 6;
            }
            else if (Player.SecondLevel == 124)
            {
                Player.AddPoints += 10;
            }
            else if (Player.SecondLevel == 125)
            {
                Player.AddPoints += 15;
            }
            else if (Player.SecondLevel == 126)
            {
                Player.AddPoints += 21;
            }
            else if (Player.SecondLevel == 127)
            {
                Player.AddPoints += 28;
            }
            else if (Player.SecondLevel == 128)
            {
                Player.AddPoints += 36;
            }
            else if (Player.SecondLevel == 129)
            {
                Player.AddPoints += 45;
            }
            else if (Player.SecondLevel == 130)
            {
                Player.AddPoints += 55;
            }

            Player.CalcMaxHP();
            Player.CalcMaxMP();
            MyMath.GetEquipStats(Player);
        }
Exemple #4
0
        /// <summary>
        /// Create a new player with the specified name and profession.
        /// </summary>
        /// <param name="aClient">The client.</param>
        /// <param name="aName">The player name.</param>
        /// <param name="aLook">The player look.</param>
        /// <param name="aProfession">The player profession.</param>
        /// <returns>True on success, false otherwise.</returns>
        public static Boolean CreatePlayer(Client aClient, String aName, Int32 aLook, Byte aProfession)
        {
            UInt16[] points = MyMath.GetLevelStats(1, aProfession);
            if (points == null)
            {
                return(false);
            }

            bool created = false;

            DateTime datetime     = DateTime.Now.ToUniversalTime();
            uint     creationtime = (uint)((datetime.Year * 10000) + (datetime.Month * 100) + datetime.Day);

            Int32  uid  = World.LastPlayerUID++;
            UInt16 life = (UInt16)((points[0] * 3) + (points[1] * 3) + (points[2] * 24) + (points[3] * 3));
            UInt16 mana = (UInt16)(points[3] * 5);

            using (var connection = sDefaultPool.GetConnection())
            {
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = (
                        "INSERT INTO `user` (`account_id`, `id`, `name`, `lookface`, `profession`, " +
                        "`force`, `dexterity`, `health`, `soul`, `life`, `mana`, `creationtime`, `last_login`) " +
                        "VALUES (@account_id, @id, @name, @lookface, @profession, @force, @dexterity, @health, @soul, " +
                        "@life, @mana, @creationtime, @last_login)");
                    command.Parameters.AddWithValue("@account_id", aClient.AccountID);
                    command.Parameters.AddWithValue("@id", uid);
                    command.Parameters.AddWithValue("@name", aName);
                    command.Parameters.AddWithValue("@lookface", aLook);
                    command.Parameters.AddWithValue("@profession", aProfession);
                    command.Parameters.AddWithValue("@force", points[0]);
                    command.Parameters.AddWithValue("@dexterity", points[1]);
                    command.Parameters.AddWithValue("@health", points[2]);
                    command.Parameters.AddWithValue("@soul", points[3]);
                    command.Parameters.AddWithValue("@life", life);
                    command.Parameters.AddWithValue("@mana", mana);
                    command.Parameters.AddWithValue("@creationtime", creationtime);
                    command.Parameters.AddWithValue("@last_login", creationtime);
                    command.Prepare();

                    sLogger.Debug("Executing SQL: {0}", GetSqlCommand(command));

                    try
                    {
                        command.ExecuteNonQuery();
                        created = true;

                        sLogger.Debug("Created player {0} in database.", aName);
                    }
                    catch (MySqlException exc)
                    {
                        if (exc.Number != 1062) // duplicate key
                        {
                            sLogger.Error("Failed to execute the following cmd : \"{0}\"\nError {1}: {2}",
                                          GetSqlCommand(command), exc.Number, exc.Message);
                        }
                    }
                }
            }

            if (created)
            {
                Item.Create(uid, 0, 726100, 0, 0, 0, 0, 0, 3, 0, 1, 1);
            }

            return(created);
        }
Exemple #5
0
        public static Int32 GetDamagePlayer2Environment(Player Attacker, TerrainNPC Target, UInt16 MagicType, Byte MagicLevel)
        {
            Magic.Info Info = new Magic.Info();
            Database.AllMagics.TryGetValue((MagicType * 10) + MagicLevel, out Info);

            Double Damage = 0;

            if (Info.Type == 1115 || (Info.WeaponSubtype != 0 && Info.WeaponSubtype != 500))
            {
                Damage = MyMath.Generate(Attacker.MinAtk, Attacker.MaxAtk);
                if (Info.Power > 30000)
                {
                    Damage *= (Double)(Info.Power - 30000) / 100;
                }
                else
                {
                    Damage += Info.Power;
                }

                Damage -= Target.Defence;
            }
            else if (Info.WeaponSubtype == 500)
            {
                Damage = MyMath.Generate(Attacker.MinAtk, Attacker.MaxAtk);
                if (Info.Power > 30000)
                {
                    Damage *= (Double)(Info.Power - 30000) / 100;
                }
                else
                {
                    Damage += Info.Power;
                }
            }
            else
            {
                Damage = Attacker.MagicAtk;
                if (Info.Power > 30000)
                {
                    Damage *= (Double)(Info.Power - 30000) / 100;
                }
                else
                {
                    Damage += Info.Power;
                }

                Damage *= ((Double)(100 - Target.MagicDef) / 100);
                Damage -= Target.MagicBlock;
            }

            if (Damage < 1)
            {
                Damage = 1;
            }

            if (Attacker.LuckyTime > 0 && MyMath.Success(10))
            {
                Damage *= 2;
                World.BroadcastRoomMsg(Attacker, new MsgName(Attacker.UniqId, "LuckyGuy", Network.MsgName.NameAct.RoleEffect), true);
            }

            return((Int32)Math.Round(Damage, 0));
        }
Exemple #6
0
        public Boolean TradeOK()
        {
            if (mFirstPlayer == null || mSecondPlayer == null)
            {
                return(false);
            }

            if (mFirstPlayer.Map != mSecondPlayer.Map)
            {
                return(false);
            }

            if (!MyMath.CanSee(mFirstPlayer.X, mFirstPlayer.Y, mSecondPlayer.X, mSecondPlayer.Y, 18))
            {
                return(false);
            }

            //Check Money
            if (mFirstPlayer.Money < mFirstPlayerMoney || mSecondPlayer.Money < mSecondPlayerMoney)
            {
                return(false);
            }

            if (mFirstPlayer.Money + mSecondPlayerMoney > Player._MAX_MONEYLIMIT || mSecondPlayer.Money + mFirstPlayerMoney > Player._MAX_MONEYLIMIT)
            {
                return(false);
            }

            //Check Items (1)
            if (mSecondPlayer.ItemInInventory() + mFirstPlayerItems.Count > 40)
            {
                return(false);
            }

            foreach (Int32 UniqId in mFirstPlayerItems)
            {
                Item Item = null;
                if (!mFirstPlayer.Items.TryGetValue(UniqId, out Item))
                {
                    return(false);
                }

                if (Item.Position != 0)
                {
                    return(false);
                }
            }

            //Check Items (2)
            if (mFirstPlayer.ItemInInventory() + mSecondPlayerItems.Count > 40)
            {
                return(false);
            }

            foreach (Int32 UniqId in mSecondPlayerItems)
            {
                Item Item = null;
                if (!mSecondPlayer.Items.TryGetValue(UniqId, out Item))
                {
                    return(false);
                }

                if (Item.Position != 0)
                {
                    return(false);
                }
            }

            //Execute Trade
            if (mFirstPlayerMoney != 0)
            {
                mSecondPlayer.Money += mFirstPlayerMoney;
                mFirstPlayer.Money  -= mFirstPlayerMoney;
            }
            if (mSecondPlayerMoney != 0)
            {
                mFirstPlayer.Money  += mSecondPlayerMoney;
                mSecondPlayer.Money -= mSecondPlayerMoney;
            }

            //mFirstPlayer.Send(new MsgUserAttrib(mFirstPlayer, mFirstPlayer.Money, MsgUserAttrib.Type.Money));
            //mSecondPlayer.Send(new MsgUserAttrib(mSecondPlayer, mSecondPlayer.Money, MsgUserAttrib.Type.Money));

            String Items1 = "[";

            foreach (Int32 UniqId in mFirstPlayerItems)
            {
                Item Item = null;
                if (!mFirstPlayer.Items.TryGetValue(UniqId, out Item))
                {
                    return(false);
                }

                Items1 += UniqId + ":";
                mFirstPlayer.DelItem(Item, true);
                mSecondPlayer.AddItem(Item, true);
            }

            String Items2 = "[";

            foreach (Int32 UniqId in mSecondPlayerItems)
            {
                Item Item = null;
                if (!mSecondPlayer.Items.TryGetValue(UniqId, out Item))
                {
                    return(false);
                }

                Items2 += UniqId + ":";
                mSecondPlayer.DelItem(Item, true);
                mFirstPlayer.AddItem(Item, true);
            }

            mFirstPlayer.SendSysMsg(StrRes.STR_TRADE_SUCCEED);
            mSecondPlayer.SendSysMsg(StrRes.STR_TRADE_SUCCEED);
            var msg = new MsgTrade(0, MsgTrade.Action.Success);

            mFirstPlayer.Send(msg);
            mSecondPlayer.Send(msg);
            mIsSuccess = true;

            Database.Save(mFirstPlayer, true);
            Database.Save(mSecondPlayer, true);

            return(true);
        }
Exemple #7
0
        public static Boolean WeaponAttribute(Player Attacker, AdvancedEntity Target)
        {
            try
            {
                if (Attacker.TransformEndTime != 0)
                {
                    return(false);
                }

                Item RWeapon = Attacker.GetItemByPos(4);
                Item LWeapon = Attacker.GetItemByPos(5);

                List <UInt16> Magics = new List <UInt16>();

                if (RWeapon != null && RWeapon.Attribute >= 200)
                {
                    if (Database.AllMagics.ContainsKey(((RWeapon.Attribute + 10000) * 10)))
                    {
                        Magics.Add((UInt16)(RWeapon.Attribute + 10000));
                    }
                }

                if (LWeapon != null && LWeapon.Attribute >= 200)
                {
                    if (Database.AllMagics.ContainsKey(((LWeapon.Attribute + 10000) * 10)))
                    {
                        Magics.Add((UInt16)(LWeapon.Attribute + 10000));
                    }
                }

                if (Magics.Count <= 0)
                {
                    return(false);
                }

                Byte   RandNumber = (Byte)MyMath.Generate(0, (Magics.Count - 1));
                UInt16 Magic      = Magics.ToArray()[RandNumber];

                Magic.Info Info = new Magic.Info();
                if (Database.AllMagics.TryGetValue((Magic * 10), out Info))
                {
                    if (MyMath.Success(Info.Success))
                    {
                        Attacker.MagicType  = Magic;
                        Attacker.MagicLevel = 0;
                        if (Info.Sort == MagicSort.AtkStatus && Target != null)
                        {
                            Battle.UseMagic(Attacker, Target, Attacker.X, Attacker.Y);
                            return(true);
                        }
                        else
                        {
                            Battle.UseMagic(Attacker, Attacker, Attacker.X, Attacker.Y);
                            return(true);
                        }
                    }
                }
                return(false);
            }
            catch (Exception exc) { sLogger.Error(exc); return(false); }
        }
Exemple #8
0
        public static Int32 GetDamagePlayer2Player(Player Attacker, Player Target, UInt16 MagicType, Byte MagicLevel)
        {
            Magic.Info Info = new Magic.Info();
            Database.AllMagics.TryGetValue((MagicType * 10) + MagicLevel, out Info);

            Double Damage = 0;

            Double Reborn = 1.00;

            if (Target.Metempsychosis == 1)
            {
                Reborn -= 0.30; //30%
            }
            else if (Target.Metempsychosis >= 2)
            {
                Reborn -= 0.50; //50%
            }
            Double Dodge = 1.00 - (Math.Min(Target.Dodge, 100.00) / 100.00);

            if (Info.Type == 1115 || (Info.WeaponSubtype != 0 && Info.WeaponSubtype != 500))
            {
                Damage = MyMath.Generate(Attacker.MinAtk, Attacker.MaxAtk);
                if (Attacker.HasStatus(Status.SuperAtk))
                {
                    Damage *= 0.2; //PvP Reduction!
                }
                if (Info.Power > 30000)
                {
                    Damage *= (Double)(Info.Power - 30000) / 100;
                }
                else
                {
                    Damage += Info.Power;
                }

                Damage -= Target.Defence;
            }
            else if (Info.WeaponSubtype == 500)
            {
                Damage = MyMath.Generate(Attacker.MinAtk, Attacker.MaxAtk);
                if (Attacker.HasStatus(Status.SuperAtk))
                {
                    Damage *= 0.2; //PvP Reduction!
                }
                if (Info.Power > 30000)
                {
                    Damage *= (Double)(Info.Power - 30000) / 100;
                }
                else
                {
                    Damage += Info.Power;
                }

                Damage *= Dodge;
                Damage *= 0.12;
            }
            else
            {
                Damage = Attacker.MagicAtk;
                if (Info.Power > 30000)
                {
                    Damage *= (Double)(Info.Power - 30000) / 100;
                }
                else
                {
                    Damage += Info.Power;
                }

                Damage *= ((Double)(100 - Target.MagicDef) / 100);
                Damage -= Target.MagicBlock;
                Damage *= 0.75;
            }

            Damage *= Reborn;
            Damage *= Target.Bless;
            Damage *= Target.GemBonus;

            if (Damage < 1)
            {
                Damage = 1;
            }

            if (Attacker.LuckyTime > 0 && MyMath.Success(10))
            {
                Damage *= 2;
                World.BroadcastRoomMsg(Attacker, new MsgName(Attacker.UniqId, "LuckyGuy", Network.MsgName.NameAct.RoleEffect), true);
            }
            if (Target.LuckyTime > 0 && MyMath.Success(10))
            {
                Damage = 1;
                World.BroadcastRoomMsg(Target, new MsgName(Target.UniqId, "LuckyGuy", Network.MsgName.NameAct.RoleEffect), true);
            }
            return((Int32)Math.Round(Damage, 0));
        }
Exemple #9
0
        public static void PvM(Player Attacker, Monster Target)
        {
            try
            {
                if (!Attacker.IsAlive())
                {
                    Attacker.IsInBattle = false;
                    return;
                }

                if (Target == null || !Target.IsAlive())
                {
                    Attacker.IsInBattle = false;
                    return;
                }

                if (Attacker.Map != Target.Map)
                {
                    Attacker.IsInBattle = false;
                    return;
                }

                if (!MyMath.CanSee(Attacker.X, Attacker.Y, Target.X, Target.Y, (Attacker.AtkRange + 1)))
                {
                    Attacker.IsInBattle = false;
                    return;
                }

                if (!CanAttack(Attacker, Target))
                {
                    Attacker.IsInBattle = false;
                    return;
                }

                if (Battle.WeaponSkill(Attacker, Target))
                {
                    return;
                }

                Attacker.LastAttackTick = Environment.TickCount;
                if (!MyMath.Success(Attacker.Dexterity))
                {
                    World.BroadcastMapMsg(Attacker, new MsgInteract(Attacker, Target, 0, (MsgInteract.Action)Attacker.AtkType), true);
                    return;
                }

                Int32 Damage = 0;
                Damage = MyMath.GetDamagePlayer2Monster(Attacker, Target);

                if (Attacker.Map.Id != 1039)
                {
                    Attacker.RemoveAtkDura();
                }

                World.BroadcastMapMsg(Attacker, new MsgInteract(Attacker, Target, Damage, MsgInteract.Action.Attack), true);

                if ((Byte)(Target.Id / 100) == 9)
                {
                    Attacker.AttachStatus(Status.Crime, 25000);
                }

                if (Damage >= Target.CurHP)
                {
                    if (Attacker.XP < 99)
                    {
                        Attacker.XP++;
                    }

                    StatusEffect effect;
                    if (Attacker.GetStatus(Status.SuperSpeed, out effect))
                    {
                        effect.IncreaseDuration(820);
                        ++Attacker.CurKO;
                    }
                    if (Attacker.GetStatus(Status.SuperAtk, out effect))
                    {
                        effect.IncreaseDuration(820);
                        ++Attacker.CurKO;
                    }

                    Int32 CurHP = Target.CurHP;
                    Target.Die(Attacker.UniqId);

                    if (Attacker.HasStatus(Status.SuperAtk) || Attacker.HasStatus(Status.SuperSpeed))
                    {
                        World.BroadcastMapMsg(Attacker, new MsgInteract(Attacker, Target, 0xFFFF * (Attacker.CurKO + 1), MsgInteract.Action.Kill), true);
                    }
                    else
                    {
                        World.BroadcastMapMsg(Attacker, new MsgInteract(Attacker, Target, 1, MsgInteract.Action.Kill), true);
                    }

                    UInt32 Exp = AdjustExp(CurHP, Attacker, Target);
                    Attacker.AddExp(Exp, true);

                    Int32 Bonus = (Int32)(Target.MaxHP * 0.05);
                    if (Attacker.Team != null)
                    {
                        Attacker.Team.AwardMemberExp(Attacker, Target, Bonus);
                    }

                    UInt32 BonusExp = AdjustExp(Bonus, Attacker, Target);
                    Attacker.AddExp(BonusExp, true);
                    Attacker.SendSysMsg(StrRes.STR_KILL_EXPERIENCE, BonusExp);

                    Item RightHand = Attacker.GetItemByPos(4);
                    if (RightHand != null && ((RightHand.Type / 100000) == 4 || (RightHand.Type / 100000) == 5))
                    {
                        Attacker.AddWeaponSkillExp((UInt16)(RightHand.Type / 1000), Exp);
                    }
                    else if (RightHand == null)
                    {
                        Attacker.AddWeaponSkillExp(0, Exp);
                    }

                    Item LeftHand = Attacker.GetItemByPos(5);
                    if (LeftHand != null && ((LeftHand.Type / 100000) == 4 || (LeftHand.Type / 100000) == 9))
                    {
                        Attacker.AddWeaponSkillExp((UInt16)(LeftHand.Type / 1000), Exp);
                    }
                }
                else
                {
                    Target.CurHP -= Damage;

                    UInt32 Exp = AdjustExp(Damage, Attacker, Target);
                    Attacker.AddExp(Exp, true);

                    Item RightHand = Attacker.GetItemByPos(4);
                    if (RightHand != null && ((RightHand.Type / 100000) == 4 || (RightHand.Type / 100000) == 5))
                    {
                        Attacker.AddWeaponSkillExp((UInt16)(RightHand.Type / 1000), Exp);
                    }
                    else if (RightHand == null)
                    {
                        Attacker.AddWeaponSkillExp(0, Exp);
                    }

                    Item LeftHand = Attacker.GetItemByPos(5);
                    if (LeftHand != null && ((LeftHand.Type / 100000) == 4 || (LeftHand.Type / 100000) == 9))
                    {
                        Attacker.AddWeaponSkillExp((UInt16)(LeftHand.Type / 1000), Exp);
                    }
                }
                if (Attacker.Map.Id != 1039)
                {
                    Battle.WeaponAttribute(Attacker, Target);
                }
            }
            catch (Exception exc) { sLogger.Error(exc); }
        }
Exemple #10
0
        public static Int32 GetDamagePlayer2Player(Player Attacker, Player Target)
        {
            Double Damage = 0;

            Double Reborn = 1.00;

            if (Target.Metempsychosis == 1)
            {
                Reborn -= 0.30; //30%
            }
            else if (Target.Metempsychosis >= 2)
            {
                Reborn -= 0.50; //50%
            }
            Double Dodge = 1.00 - (Math.Min(Target.Dodge, 100.00) / 100.00);

            switch (Attacker.AtkType)
            {
            case 2:
            {
                Damage = MyMath.Generate(Attacker.MinAtk, Attacker.MaxAtk);

                if (Attacker.HasStatus(Status.SuperAtk))
                {
                    Damage *= 0.2;         //PvP Reduction!
                }
                Damage -= Target.Defence;
                break;
            }

            case 21:
            {
                Damage = Attacker.MagicAtk;

                Damage *= ((Double)(100 - Target.MagicDef) / 100);
                Damage -= Target.MagicBlock;
                Damage *= 0.75;

                break;
            }

            case 25:
            {
                Damage = MyMath.Generate(Attacker.MinAtk, Attacker.MaxAtk);

                if (Attacker.HasStatus(Status.SuperAtk))
                {
                    Damage *= 0.2;         //PvP Reduction!
                }
                Damage *= Dodge;
                Damage *= 0.12;
                break;
            }
            }

            Damage *= Reborn;
            Damage *= Target.Bless;
            Damage *= Target.GemBonus;

            if (Damage < 1)
            {
                Damage = 1;
            }

            if (Attacker.LuckyTime > 0 && MyMath.Success(10))
            {
                Damage *= 2;
                World.BroadcastRoomMsg(Attacker, new MsgName(Attacker.UniqId, "LuckyGuy", Network.MsgName.NameAct.RoleEffect), true);
            }
            if (Target.LuckyTime > 0 && MyMath.Success(10))
            {
                Damage = 1;
                World.BroadcastRoomMsg(Target, new MsgName(Target.UniqId, "LuckyGuy", Network.MsgName.NameAct.RoleEffect), true);
            }
            return((Int32)Math.Round(Damage, 0));
        }
Exemple #11
0
        public static void MvP(Monster Attacker, Player Target)
        {
            try
            {
                if (!Attacker.IsAlive())
                {
                    Attacker.IsInBattle = false;
                    return;
                }

                if (Target == null || !Target.IsAlive())
                {
                    Attacker.IsInBattle = false;
                    return;
                }

                if (Attacker.Map != Target.Map)
                {
                    Attacker.IsInBattle = false;
                    return;
                }

                if (!MyMath.CanSee(Attacker.X, Attacker.Y, Target.X, Target.Y, (Attacker.AtkRange)))
                {
                    Attacker.IsInBattle = false;
                    return;
                }

                if (Target.IsFlying())
                {
                    Attacker.IsInBattle = false;
                    return;
                }

                if (!MyMath.Success(Attacker.Dexterity))
                {
                    World.BroadcastMapMsg(Attacker, new MsgInteract(Attacker, Target, 0, (MsgInteract.Action)Attacker.AtkType));
                    return;
                }

                Int32 Damage = 0;
                Damage = MyMath.GetDamageMonster2Player(Attacker, Target);

                Target.RemoveDefDura();

                if (!Target.Reflect())
                {
                    World.BroadcastMapMsg(Attacker, new MsgInteract(Attacker, Target, Damage, MsgInteract.Action.Attack));
                    if (Damage >= Target.CurHP)
                    {
                        Target.Die(Attacker);
                        World.BroadcastMapMsg(Attacker, new MsgInteract(Attacker, Target, 1, MsgInteract.Action.Kill));
                    }
                    else
                    {
                        Target.CurHP -= Damage;
                        Target.Send(new MsgUserAttrib(Target, Target.CurHP, MsgUserAttrib.AttributeType.Life));
                        if (Target.Team != null)
                        {
                            Target.Team.BroadcastMsg(new MsgUserAttrib(Target, Target.CurHP, MsgUserAttrib.AttributeType.Life));
                        }

                        if (Target.Action == Emotion.SitDown)
                        {
                            Target.Energy /= 2;
                            Target.Send(new MsgUserAttrib(Target, Target.Energy, MsgUserAttrib.AttributeType.Energy));

                            Target.Action = Emotion.StandBy;
                            World.BroadcastRoomMsg(Target, new MsgAction(Target, (int)Target.Action, MsgAction.Action.Emotion), true);
                        }
                    }
                }
                else
                {
                    if (Damage > 2000)
                    {
                        Damage = 2000;
                    }

                    World.BroadcastMapMsg(Attacker, new MsgInteract(Target, Attacker, Damage, MsgInteract.Action.ReflectWeapon));
                    if (Damage >= Attacker.CurHP)
                    {
                        Attacker.Die(0);
                        World.BroadcastMapMsg(Target, new MsgInteract(Target, Attacker, 1, MsgInteract.Action.Kill), true);
                    }
                    else
                    {
                        Attacker.CurHP -= Damage;
                        World.BroadcastMapMsg(Attacker, new MsgUserAttrib(Attacker, Attacker.CurHP, MsgUserAttrib.AttributeType.Life));
                    }
                }
            }
            catch (Exception exc) { sLogger.Error(exc); }
        }
Exemple #12
0
        public static void PvE(Player Attacker, TerrainNPC Target)
        {
            try
            {
                if (!Attacker.IsAlive())
                {
                    Attacker.IsInBattle = false;
                    return;
                }

                if (Target == null || !Target.IsAlive())
                {
                    Attacker.IsInBattle = false;
                    return;
                }

                if (Attacker.Map != Target.Map)
                {
                    Attacker.IsInBattle = false;
                    return;
                }

                if (!MyMath.CanSee(Attacker.X, Attacker.Y, Target.X, Target.Y, (Attacker.AtkRange + 1)))
                {
                    Attacker.IsInBattle = false;
                    return;
                }

                if (Battle.WeaponSkill(Attacker, Target))
                {
                    return;
                }

                Attacker.LastAttackTick = Environment.TickCount;
                if (!MyMath.Success(Attacker.Dexterity))
                {
                    World.BroadcastMapMsg(Attacker, new MsgInteract(Attacker, Target, 0, (MsgInteract.Action)Attacker.AtkType), true);
                    return;
                }

                Int32 Damage = 0;
                Damage = MyMath.GetDamagePlayer2Environment(Attacker, Target);

                if (Attacker.Map.Id != 1039)
                {
                    Attacker.RemoveAtkDura();
                }

                World.BroadcastMapMsg(Attacker, new MsgInteract(Attacker, Target, Damage, MsgInteract.Action.Attack), true);
                if (Damage >= Target.CurHP)
                {
                    if (Attacker.XP < 99)
                    {
                        Attacker.XP++;
                    }

                    Target.GetAttacked(Attacker, Target.CurHP);

                    Int32 CurHP = Target.CurHP;
                    World.BroadcastMapMsg(Attacker, new MsgInteract(Attacker, Target, 1, MsgInteract.Action.Kill), true);
                    Target.Die();

                    if (Target.Type == 21 || Target.Type == 22)
                    {
                        UInt32 Exp = AdjustExp(CurHP, Attacker, Target);
                        Attacker.AddExp(Exp, true);

                        Int32 Bonus = (Int32)(Target.MaxHP * 0.05);

                        UInt32 BonusExp = AdjustExp(Bonus, Attacker, Target);
                        Attacker.AddExp(BonusExp, true);

                        Item RightHand = Attacker.GetItemByPos(4);
                        if (RightHand != null && ((RightHand.Type / 100000) == 4 || (RightHand.Type / 100000) == 5))
                        {
                            Attacker.AddWeaponSkillExp((UInt16)(RightHand.Type / 1000), Exp);
                        }
                        else if (RightHand == null)
                        {
                            Attacker.AddWeaponSkillExp(0, Exp);
                        }

                        Item LeftHand = Attacker.GetItemByPos(5);
                        if (LeftHand != null && ((LeftHand.Type / 100000) == 4 || (LeftHand.Type / 100000) == 9))
                        {
                            Attacker.AddWeaponSkillExp((UInt16)(LeftHand.Type / 1000), Exp);
                        }
                    }
                    else if (Target.Type == (Byte)TerrainNPC.NpcType.SynFlag)
                    {
                        if (Attacker.Syndicate != null)
                        {
                            // TODO re-enable donation gain on pole
                            //if (Attacker.Map.InWar)
                            //    if (Attacker.Syndicate.Id != Attacker.Map.Holder)
                            //    {
                            //        Attacker.Money += (UInt32)(Damage / 10000);
                            //        Attacker.Send(new MsgUserAttrib(Attacker, Attacker.Money, MsgUserAttrib.AttributeType.Money));

                            //        Syndicate.Member Member = Attacker.Syndicate.GetMemberInfo(Attacker.UniqId);
                            //        if (Member != null)
                            //        {
                            //            Member.Donation += (UInt32)(Damage / 10000);
                            //            Attacker.Syndicate.Money += (UInt32)(Damage / 10000);
                            //            Attacker.Send(new MsgSynAttrInfo(Attacker.UniqId, Attacker.Syndicate));
                            //        }
                            //    }
                        }
                    }
                }
                else
                {
                    Target.CurHP -= Damage;
                    Target.GetAttacked(Attacker, Damage);

                    if (Target.Type == 21 || Target.Type == 22)
                    {
                        UInt32 Exp = AdjustExp(Damage, Attacker, Target);
                        Attacker.AddExp(Exp, true);

                        Item RightHand = Attacker.GetItemByPos(4);
                        if (RightHand != null && ((RightHand.Type / 100000) == 4 || (RightHand.Type / 100000) == 5))
                        {
                            Attacker.AddWeaponSkillExp((UInt16)(RightHand.Type / 1000), Exp);
                        }
                        else if (RightHand == null)
                        {
                            Attacker.AddWeaponSkillExp(0, Exp);
                        }

                        Item LeftHand = Attacker.GetItemByPos(5);
                        if (LeftHand != null && ((LeftHand.Type / 100000) == 4 || (LeftHand.Type / 100000) == 9))
                        {
                            Attacker.AddWeaponSkillExp((UInt16)(LeftHand.Type / 1000), Exp);
                        }
                    }
                    else if (Target.Type == (Byte)TerrainNPC.NpcType.SynFlag)
                    {
                        if (Attacker.Syndicate != null)
                        {
                            // TODO re-enable donation gain on pole
                            //if (Attacker.Map.InWar)
                            //    if (Attacker.Syndicate.Id != Attacker.Map.Holder)
                            //    {
                            //        Attacker.Money += (UInt32)(Target.CurHP / 10000);
                            //        Attacker.Send(new MsgUserAttrib(Attacker, Attacker.Money, MsgUserAttrib.AttributeType.Money));

                            //        Syndicate.Member Member = Attacker.Syndicate.GetMemberInfo(Attacker.UniqId);
                            //        if (Member != null)
                            //        {
                            //            Member.Donation += (UInt32)(Target.CurHP / 10000);
                            //            Attacker.Syndicate.Money += (UInt32)(Target.CurHP / 10000);
                            //            Attacker.Send(new MsgSynAttrInfo(Attacker.UniqId, Attacker.Syndicate));
                            //        }
                            //    }
                        }
                    }
                }

                if (Attacker.Map.Id != 1039)
                {
                    Battle.WeaponAttribute(Attacker, Target);
                }
            }
            catch (Exception exc) { sLogger.Error(exc); }
        }
Exemple #13
0
        public static void UseMagic(AdvancedEntity aAttacker, AdvancedEntity aTarget, UInt16 aTargetX, UInt16 aTargetY)
        {
            try
            {
                // a lot of logic depends on the fact that the attacker is a player...
                Player attacker = aAttacker as Player;

                if (!aAttacker.IsAlive())
                {
                    return;
                }

                if (aAttacker.IsPlayer())
                {
                    if (attacker.MagicType == 8000 || attacker.MagicType == 8001)
                    {
                        Item arrow = attacker.GetItemByPos(5);
                        if (arrow.Type / 10000 != 105)
                        {
                            return;
                        }

                        if (attacker.MagicType == 8000)
                        {
                            if (arrow.CurDura < 5)
                            {
                                return;
                            }
                        }

                        if (attacker.MagicType == 8001)
                        {
                            if (arrow.CurDura < 3)
                            {
                                return;
                            }
                        }
                    }
                }

                Magic.Info Info = new Magic.Info();
                if (!Database.AllMagics.TryGetValue((aAttacker.MagicType * 10) + aAttacker.MagicLevel, out Info))
                {
                    return;
                }

                GameMap Map = aAttacker.Map;

                if (aAttacker.IsPlayer() && Program.Debug)
                {
                    attacker.SendSysMsg(String.Format("Using magic skill {0} [sort={1}, power={2}, status={3}]",
                                                      Info.Type, Info.Sort, Info.Power, Info.Status));
                }

                #region Fly | IsWing_Disable
                if (Info.Type == 8002 || Info.Type == 8003)
                {
                    if (Map.IsWing_Disable())
                    {
                        return;
                    }
                }
                #endregion

                #region Use Mp/PP/Xp
                if (aAttacker.IsPlayer())
                {
                    if (Info.UseMP != 0 && attacker.CurMP < Info.UseMP)
                    {
                        return;
                    }

                    if (Info.UseEP != 0 && attacker.Energy < Info.UseEP)
                    {
                        return;
                    }

                    if (Info.UseXP == Magic.TYPE_XPSKILL && attacker.XP < 100)
                    {
                        return;
                    }

                    if (Info.UseMP != 0 && attacker.Map.Id != 1039)
                    {
                        attacker.CurMP -= (UInt16)Info.UseMP;
                        attacker.Send(new MsgUserAttrib(attacker, attacker.CurMP, MsgUserAttrib.AttributeType.Mana));
                    }

                    if (Info.UseEP != 0 && attacker.Map.Id != 1039)
                    {
                        attacker.Energy -= (Byte)Info.UseEP;
                        attacker.Send(new MsgUserAttrib(attacker, attacker.Energy, MsgUserAttrib.AttributeType.Energy));
                    }

                    if (Info.UseXP == Magic.TYPE_XPSKILL)
                    {
                        attacker.XP = 0;
                        attacker.Send(new MsgUserAttrib(attacker, attacker.XP, MsgUserAttrib.AttributeType.XP));
                        attacker.DetachStatus(Status.XpFull);
                    }
                }
                #endregion

                #region Intone
                if (Info.IntoneDuration > 0)
                {
                    aAttacker.MagicIntone = true;
                    // TODO implement intonation
                    //Thread.Sleep((Int32)Info.IntoneDuration);

                    if (!aAttacker.MagicIntone)
                    {
                        return;
                    }

                    aAttacker.MagicIntone = false;
                }
                #endregion

                #region Potential targets
                AdvancedEntity[] potential_targets = new AdvancedEntity[0];
                if (aTarget == null || Info.Sort == MagicSort.RecoverSingleHP || Info.Sort == MagicSort.AttackRoundHP || Info.Sort == MagicSort.DispatchXP)
                {
                    switch (Info.Sort)
                    {
                    case MagicSort.RecoverSingleHP:
                    {
                        // team healing...
                        if (Info.Type == 1055 || Info.Type == 1170)
                        {
                            if ((aTarget.IsPlayer() && (aTarget as Player).Team == null))
                            {
                                potential_targets = new AdvancedEntity[] { aTarget };
                                break;
                            }

                            if (aAttacker.IsPlayer())         // only a player can have a team...
                            {
                                potential_targets = Battle.GetTargetsForType11(attacker);
                            }
                        }
                        else
                        {
                            potential_targets = new AdvancedEntity[] { aTarget }
                        };

                        break;
                    }

                    case MagicSort.AttackSectorHP:
                        potential_targets = Battle.GetTargetsForType04(aAttacker, aTargetX, aTargetY, Info.Distance, Info.Range);
                        break;

                    case MagicSort.AttackRoundHP:
                    {
                        if (aTarget != null)
                        {
                            aTargetX = aTarget.X;
                            aTargetY = aTarget.Y;
                            aTarget  = null;
                        }
                        potential_targets = Battle.GetTargetsForType05(aAttacker, aTargetX, aTargetY, Info.Range);
                        break;
                    }

                    case MagicSort.DispatchXP:
                    {
                        if (aAttacker.IsPlayer())         // only a player can have a team...
                        {
                            potential_targets = Battle.GetTargetsForType11(attacker);
                        }
                        break;
                    }

                    case MagicSort.Line:
                    {
                        potential_targets = Battle.GetTargetsForType14(aAttacker, aTargetX, aTargetY, Info.Range);
                        break;
                    }
                    }
                }
                else
                {
                    potential_targets = new AdvancedEntity[] { aTarget }
                };
                #endregion

                Dictionary <AdvancedEntity, Int32> targets = new Dictionary <AdvancedEntity, Int32>(potential_targets.Length);
                UInt32 Exp      = 0;
                UInt32 MagicExp = 0;

                foreach (AdvancedEntity entity in potential_targets)
                {
                    Boolean    Reflected = false;
                    Player     Player    = entity as Player;
                    Monster    Monster   = entity as Monster;
                    TerrainNPC Npc       = entity as TerrainNPC;

                    // entity == NULL || entity isn't alive and not using pray
                    if (entity == null || (!entity.IsAlive() && Info.Sort != MagicSort.RecoverSingleStatus))
                    {
                        continue;
                    }

                    if (aAttacker.Map != entity.Map)
                    {
                        continue;
                    }

                    if (!MyMath.CanSee(aAttacker.X, aAttacker.Y, entity.X, entity.Y, (Int32)Info.Distance))
                    {
                        continue;
                    }

                    if (Info.Target == 0 && aAttacker.UniqId == entity.UniqId)
                    {
                        continue;
                    }
                    else if (Info.Target == 2 && aAttacker.UniqId != entity.UniqId)
                    {
                        continue;
                    }
                    else if (Info.Target == 4 && aAttacker.UniqId == entity.UniqId)
                    {
                        continue;
                    }
                    else if (Info.Target == 8 && aAttacker.UniqId == entity.UniqId &&
                             !((Info.Type - (Info.Type % 1000)) == 10000))
                    {
                        continue;
                    }

                    if (Info.Ground && entity.IsPlayer()) // Ground skill
                    {
                        if (Player.IsFlying())
                        {
                            continue;
                        }
                    }

                    #region Blue name (Crime)
                    if (aAttacker.IsPlayer() && Info.Crime) // Is a crime to use the skill
                    {
                        if (entity.IsPlayer())
                        {
                            if (!CanAttack(attacker, Player))
                            {
                                continue;
                            }

                            if (!Map.IsPkField() && !Map.IsSynMap() && !Map.IsPrisonMap())
                            {
                                if (!Player.IsCriminal())
                                {
                                    attacker.AttachStatus(Status.Crime, 25000);
                                }
                            }
                        }
                        else if (entity.IsMonster())
                        {
                            if (!CanAttack(attacker, Monster))
                            {
                                continue;
                            }

                            if ((Byte)(Monster.Id / 100) == 9) //Is a guard
                            {
                                attacker.AttachStatus(Status.Crime, 25000);
                            }
                        }
                    }
                    #endregion

                    #region Get base damage
                    Int32 damage = 0;
                    if (Info.Sort == MagicSort.RecoverSingleHP || Info.Sort == MagicSort.AttackSingleStatus || Info.Sort == MagicSort.DispatchXP || Info.Sort == MagicSort.Transform || Info.Sort == MagicSort.AddMana)
                    {
                        damage = (Int32)Info.Power;
                    }
                    else if (Info.Sort == MagicSort.RecoverSingleStatus)
                    {
                        damage = entity.MaxHP;
                    }
                    else if (Info.Sort == MagicSort.DecLife)
                    {
                        damage = (Int32)(entity.CurHP * ((Double)(Info.Power - 30000) / 100.00));
                    }
                    else
                    {
                        if (aAttacker.IsPlayer())
                        {
                            if (entity.IsPlayer())
                            {
                                damage = MyMath.GetDamagePlayer2Player(attacker, Player, attacker.MagicType, attacker.MagicLevel);
                            }
                            else if (entity.IsMonster())
                            {
                                damage = MyMath.GetDamagePlayer2Monster(attacker, Monster, attacker.MagicType, attacker.MagicLevel);
                            }
                            else if (entity.IsTerrainNPC())
                            {
                                damage = MyMath.GetDamagePlayer2Environment(attacker, Npc, attacker.MagicType, attacker.MagicLevel);
                            }
                        }
                        else
                        {
                            if (entity.IsPlayer())
                            {
                                damage = MyMath.GetDamageMonster2Player((Monster)aAttacker, Player, aAttacker.MagicType, aAttacker.MagicLevel);
                            }
                        }
                    }

                    //TargetType -> 8; Passive skill
                    if (Info.Target != 8 && Info.Success != 100 && !MyMath.Success(Info.Success))
                    {
                        damage = 0;
                    }
                    #endregion

                    #region Process damage / skill
                    switch (Info.Sort)
                    {
                    case MagicSort.RecoverSingleHP:
                    {
                        if (entity.CurHP + damage >= entity.MaxHP)
                        {
                            MagicExp    += (UInt32)(entity.MaxHP - entity.CurHP);
                            entity.CurHP = entity.MaxHP;
                        }
                        else
                        {
                            MagicExp     += (UInt32)damage;
                            entity.CurHP += damage;
                        }

                        if (entity.IsPlayer())
                        {
                            var msg = new MsgUserAttrib(Player, Player.CurHP, MsgUserAttrib.AttributeType.Life);
                            Player.Send(msg);
                            if (Player.Team != null)
                            {
                                Player.Team.BroadcastMsg(msg);
                            }
                            msg = null;
                        }
                        break;
                    }

                    case MagicSort.AttackSingleStatus:
                    {
                        int    duration = (int)Info.StepSecs * 1000;
                        double power    = ((double)(damage - 30000) / 100.00);

                        switch (aAttacker.MagicType)
                        {
                        case 1015:
                        {
                            entity.AttachStatus(Status.Accuracy, duration, power);

                            if (entity.IsPlayer())
                            {
                                MyMath.GetEquipStats(Player);
                            }

                            break;
                        }

                        case 1020:
                        {
                            entity.AttachStatus(Status.MagicDefense, duration, power);

                            if (entity.IsPlayer())
                            {
                                MyMath.GetEquipStats(Player);
                            }

                            break;
                        }

                        case 1025:
                        {
                            if (entity.HasStatus(Status.SuperSpeed))
                            {
                                entity.DetachStatus(Status.SuperSpeed);
                            }

                            entity.AttachStatus(Status.SuperAtk, duration, power);

                            if (entity.IsPlayer())
                            {
                                MyMath.GetEquipStats(Player);
                            }

                            break;
                        }

                        case 1075:
                        {
                            ++MagicExp;
                            entity.AttachStatus(Status.Hidden, duration);
                            break;
                        }

                        case 1085:
                        {
                            ++MagicExp;
                            entity.AttachStatus(Status.Accuracy, duration, power);

                            if (entity.IsPlayer())
                            {
                                MyMath.GetEquipStats(Player);
                            }

                            break;
                        }

                        case 1090:
                        {
                            ++MagicExp;
                            entity.AttachStatus(Status.MagicDefense, duration, power);

                            if (entity.IsPlayer())
                            {
                                MyMath.GetEquipStats(Player);
                            }

                            break;
                        }

                        case 1095:
                        {
                            ++MagicExp;
                            entity.AttachStatus(Status.MagicAttack, duration, power);

                            if (entity.IsPlayer())
                            {
                                MyMath.GetEquipStats(Player);
                            }

                            break;
                        }

                        case 1110:
                        {
                            if (entity.HasStatus(Status.SuperAtk))
                            {
                                entity.DetachStatus(Status.SuperAtk);
                            }

                            entity.AttachStatus(Status.SuperSpeed, duration, power);

                            if (entity.IsPlayer())
                            {
                                MyMath.GetEquipStats(Player);
                            }

                            break;
                        }

                        case 8002:
                        {
                            if (entity.HasStatus(Status.MagicDefense))
                            {
                                break;
                            }

                            entity.AttachStatus(Status.Flying, duration);
                            break;
                        }

                        case 8003:
                        {
                            if (entity.HasStatus(Status.MagicDefense))
                            {
                                break;
                            }

                            entity.AttachStatus(Status.Flying, duration);
                            break;
                        }

                        case 9000:
                        {
                            ++MagicExp;
                            entity.AttachStatus((Status)Info.Status, -1, power);
                            break;
                        }

                        case 9876:
                        {
                            entity.AttachStatus(Status.CastingPray);

                            if (entity.IsPlayer())
                            {
                                Player.CastingPray = true;
                                Player.PrayMap     = entity.Map.Id;
                                Player.PrayX       = entity.X;
                                Player.PrayY       = entity.Y;
                            }

                            break;
                        }

                        case 10203:
                        {
                            StatusEffect effect;
                            if (entity.GetStatus(Status.MagicDefense, out effect))
                            {
                                effect.Data = power;
                                effect.ResetTimeout(duration);
                                break;
                            }

                            entity.AttachStatus(Status.MagicDefense, duration, power);

                            if (entity.IsPlayer())
                            {
                                MyMath.GetEquipStats(Player);
                            }

                            break;
                        }

                        default:
                            sLogger.Warn("Magic {0} is not implemented !", aAttacker.MagicType);
                            break;
                        }
                        damage = 0;
                        break;
                    }

                    case MagicSort.RecoverSingleStatus:
                    {
                        if (entity.IsPlayer() && !entity.IsAlive())
                        {
                            Player.Reborn(false);
                        }
                        break;
                    }

                    case MagicSort.DispatchXP:
                    {
                        if (entity.IsPlayer())
                        {
                            if (Player.XP + damage >= 100)
                            {
                                Player.XP = 100;
                            }
                            else
                            {
                                Player.XP += (Byte)damage;
                            }
                            Player.Send(new MsgUserAttrib(Player, Player.XP, MsgUserAttrib.AttributeType.XP));
                        }
                        break;
                    }

                    case MagicSort.Transform:
                    {
                        if (entity.IsPlayer())
                        {
                            MonsterInfo MonsterInfo;
                            if (Database.AllMonsters.TryGetValue(damage, out MonsterInfo))
                            {
                                MagicExp++;
                                Player.TransformEndTime = Environment.TickCount + ((Int32)Info.StepSecs * 1000);

                                // TODO re-enable transformation skills
                                //Player.AddTransform(MonsterInfo.Look);
                                Player.MinAtk     = (Int32)MonsterInfo.MinAtk;
                                Player.MaxAtk     = (Int32)MonsterInfo.MaxAtk;
                                Player.Defence    = (Int32)MonsterInfo.Defense;
                                Player.MagicAtk   = 0;
                                Player.MagicDef   = (Int32)MonsterInfo.MagicDef;
                                Player.MagicBlock = 0;
                                Player.Dodge      = MonsterInfo.Dodge;
                                Player.Dexterity  = 1000;
                                Player.AtkRange   = MonsterInfo.AtkRange;
                                Player.AtkSpeed   = MonsterInfo.AtkSpeed;
                                Player.AtkType    = 2;
                                Player.Bless      = 1.00;
                                Player.GemBonus   = 1.00;
                                if (Player.CurHP >= Player.MaxHP)
                                {
                                    Player.CurHP = Player.MaxHP;
                                }
                                Player.CurHP = (Int32)((Double)MonsterInfo.Life * ((Double)Player.CurHP / (Double)Player.MaxHP));
                                Player.MaxHP = MonsterInfo.Life;

                                Player.Send(new MsgUserAttrib(Player, Player.CurHP, MsgUserAttrib.AttributeType.Life));
                                Player.Send(new MsgUserAttrib(Player, Player.MaxHP, (MsgUserAttrib.AttributeType.Life + 1)));
                                if (Player.Team != null)
                                {
                                    Player.Team.BroadcastMsg(new MsgUserAttrib(Player, Player.CurHP, MsgUserAttrib.AttributeType.Life));
                                    Player.Team.BroadcastMsg(new MsgUserAttrib(Player, Player.MaxHP, (MsgUserAttrib.AttributeType.Life + 1)));
                                }
                                World.BroadcastRoomMsg(Player, new MsgUserAttrib(Player, Player.Look, MsgUserAttrib.AttributeType.Look), true);
                            }
                        }
                        damage = 0;
                        break;
                    }

                    case MagicSort.AddMana:
                    {
                        if (entity.IsPlayer())
                        {
                            if (Player.CurMP + damage >= Player.MaxMP)
                            {
                                MagicExp    += (UInt32)(Player.MaxMP - Player.CurMP);
                                Player.CurMP = Player.MaxMP;
                            }
                            else
                            {
                                MagicExp     += (UInt32)damage;
                                Player.CurMP += (UInt16)damage;
                            }
                            Player.Send(new MsgUserAttrib(Player, Player.CurMP, MsgUserAttrib.AttributeType.Mana));
                        }
                        break;
                    }

                    case MagicSort.CallPet:
                    {
                        if (!aAttacker.IsPlayer())
                        {
                            sLogger.Error("MagicSort::CallPet used by a non-player entity.");
                            return;
                        }

                        damage    = 0;
                        MagicExp += 1;

                        Generator.generatePet((Player)aAttacker, (Int32)Info.Power);
                        break;
                    }

                    default:
                    {
                        if (entity.IsPlayer())
                        {
                            Player.RemoveDefDura();
                        }

                        #region Not a player || Not reflected
                        if (!entity.IsPlayer() || (entity.IsPlayer() && !Player.Reflect()))
                        {
                            if (damage >= entity.CurHP)
                            {
                                if (entity.IsPlayer())
                                {
                                    Player.Die(aAttacker);
                                }
                                else if (entity.IsMonster())
                                {
                                    if (aAttacker.IsPlayer())
                                    {
                                        if (attacker.XP < 99)
                                        {
                                            ++attacker.XP;
                                        }

                                        StatusEffect effect;
                                        if (attacker.GetStatus(Status.SuperSpeed, out effect))
                                        {
                                            effect.IncreaseDuration(820);
                                            ++attacker.CurKO;
                                        }
                                        if (attacker.GetStatus(Status.SuperAtk, out effect))
                                        {
                                            effect.IncreaseDuration(820);
                                            ++attacker.CurKO;
                                        }

                                        Int32 CurHP = entity.CurHP;
                                        Monster.Die(attacker.UniqId);

                                        Exp      += AdjustExp(CurHP, attacker, Monster);
                                        MagicExp += AdjustExp(CurHP, attacker, Monster);

                                        Int32 Bonus = (Int32)(Monster.MaxHP * 0.05);
                                        if (attacker.Team != null)
                                        {
                                            attacker.Team.AwardMemberExp(attacker, Monster, Bonus);
                                        }

                                        UInt32 BonusExp = AdjustExp(Bonus, attacker, Monster);
                                        attacker.AddExp(BonusExp, true);
                                        attacker.SendSysMsg(String.Format(StrRes.STR_KILL_EXPERIENCE, BonusExp));
                                    }
                                }
                                else if (entity.IsTerrainNPC())
                                {
                                    if (attacker.IsPlayer())
                                    {
                                        if (attacker.XP < 99)
                                        {
                                            attacker.XP++;
                                        }

                                        Int32 CurHP = entity.CurHP;

                                        if (Npc.Type == 21 || Npc.Type == 22)
                                        {
                                            Exp      += AdjustExp(CurHP, attacker, Npc);
                                            MagicExp += AdjustExp(CurHP, attacker, Npc);

                                            Int32 Bonus = (Int32)(entity.MaxHP * 0.05);

                                            UInt32 BonusExp = AdjustExp(Bonus, attacker, Npc);
                                            attacker.AddExp(BonusExp, true);
                                        }
                                        else if (Npc.Type == (Byte)TerrainNPC.NpcType.SynFlag)
                                        {
                                            if (attacker.Syndicate != null)
                                            {
                                                // TODO re-enable donation gain on pole
                                                //if (attacker.Map.InWar)
                                                //    if (attacker.Syndicate.Id != attacker.Map.Holder)
                                                //    {
                                                //        attacker.Money += (UInt32)(CurHP / 10000);
                                                //        attacker.Send(new MsgUserAttrib(attacker, attacker.Money, MsgUserAttrib.AttributeType.Money));

                                                //        Syndicate.Member Member = attacker.Syndicate.GetMemberInfo(attacker.UniqId);
                                                //        if (Member != null)
                                                //        {
                                                //            Member.Donation += (UInt32)(CurHP / 10000);
                                                //            attacker.Syndicate.Money += (UInt32)(CurHP / 10000);
                                                //        }
                                                //    }
                                            }
                                        }
                                        Npc.GetAttacked(attacker, Npc.CurHP);

                                        World.BroadcastMapMsg(attacker, new MsgInteract(attacker, entity, 1, MsgInteract.Action.Kill), true);
                                        Npc.Die();
                                    }
                                }

                                if (!entity.IsTerrainNPC())
                                {
                                    if (aAttacker.IsPlayer())
                                    {
                                        if (!entity.IsMonster() || (!aAttacker.HasStatus(Status.SuperAtk) && !aAttacker.HasStatus(Status.SuperSpeed)))
                                        {
                                            World.BroadcastMapMsg(attacker, new MsgInteract(aAttacker, entity, 1, MsgInteract.Action.Kill), true);
                                        }
                                        else
                                        {
                                            World.BroadcastMapMsg(attacker, new MsgInteract(aAttacker, entity, 0xFFFF * (attacker.CurKO + 1), MsgInteract.Action.Kill), true);
                                        }
                                    }
                                    else
                                    {
                                        World.BroadcastMapMsg(aAttacker, new MsgInteract(aAttacker, entity, 1, MsgInteract.Action.Kill));
                                    }
                                }
                            }
                            else
                            {
                                entity.CurHP -= damage;
                                if (entity.IsPlayer())
                                {
                                    Player.Send(new MsgUserAttrib(entity, entity.CurHP, MsgUserAttrib.AttributeType.Life));
                                    if (Player.Team != null)
                                    {
                                        Player.Team.BroadcastMsg(new MsgUserAttrib(entity, entity.CurHP, MsgUserAttrib.AttributeType.Life));
                                    }

                                    if (Player.Action == Emotion.SitDown)
                                    {
                                        Player.Energy /= 2;
                                        Player.Send(new MsgUserAttrib(Player, Player.Energy, MsgUserAttrib.AttributeType.Energy));

                                        Player.Action = Emotion.StandBy;
                                        World.BroadcastRoomMsg(Player, new MsgAction(Player, (int)Player.Action, MsgAction.Action.Emotion), true);
                                    }
                                }
                                else if (entity.IsMonster())
                                {
                                    if (aAttacker.IsPlayer())
                                    {
                                        Exp      += AdjustExp(damage, attacker, Monster);
                                        MagicExp += (UInt32)AdjustExp(damage, attacker, Monster);
                                    }
                                }
                                else if (entity.IsTerrainNPC())
                                {
                                    if (aAttacker.IsPlayer())
                                    {
                                        if (Npc.Type == 21 || Npc.Type == 22)
                                        {
                                            Exp      += AdjustExp(damage, attacker, Npc);
                                            MagicExp += (UInt32)AdjustExp(damage, attacker, Npc);
                                        }
                                        else if (Npc.Type == (Byte)TerrainNPC.NpcType.SynFlag)
                                        {
                                            if (attacker.Syndicate != null)
                                            {
                                                // TODO re-enable donation gain on pole
                                                //if (attacker.Map.InWar)
                                                //    if (attacker.Syndicate.Id != attacker.Map.Holder)
                                                //    {
                                                //        attacker.Money += (UInt32)(damage / 10000);
                                                //        attacker.Send(new MsgUserAttrib(attacker, attacker.Money, MsgUserAttrib.AttributeType.Money));

                                                //        Syndicate.Member Member = attacker.Syndicate.GetMemberInfo(attacker.UniqId);
                                                //        if (Member != null)
                                                //        {
                                                //            Member.Donation += (UInt32)(damage / 10000);
                                                //            attacker.Syndicate.Money += (UInt32)(damage / 10000);
                                                //            attacker.Send(new MsgSynAttrInfo(attacker.UniqId, attacker.Syndicate));
                                                //        }
                                                //    }
                                            }
                                        }
                                        Npc.GetAttacked(attacker, damage);
                                    }
                                }
                            }
                        }
                        #endregion
                        #region Reflected
                        else
                        {
                            if (damage > 2000)
                            {
                                damage = 2000;
                            }

                            var msg = new MsgInteract(entity, aAttacker, damage, MsgInteract.Action.ReflectMagic);
                            if (aAttacker.IsPlayer())
                            {
                                World.BroadcastMapMsg(attacker, msg, true);
                            }
                            else
                            {
                                World.BroadcastMapMsg(aAttacker, msg);
                            }

                            if (damage >= aAttacker.CurHP)
                            {
                                if (aAttacker.IsPlayer())
                                {
                                    attacker.Die(null);
                                }
                                else
                                {
                                    ((Monster)aAttacker).Die(entity.UniqId);
                                }
                                World.BroadcastMapMsg(Player, new MsgInteract(entity, aAttacker, 1, MsgInteract.Action.Kill), true);
                            }
                            else
                            {
                                aAttacker.CurHP -= damage;

                                var msg2 = new MsgUserAttrib(aAttacker, aAttacker.CurHP, MsgUserAttrib.AttributeType.Life);
                                if (aAttacker.IsPlayer())
                                {
                                    attacker.Send(msg2);
                                    if (attacker.Team != null)
                                    {
                                        attacker.Team.BroadcastMsg(msg2);
                                    }
                                }
                                else
                                {
                                    World.BroadcastMapMsg(aAttacker, msg2);
                                }
                            }
                            Reflected = true;
                        }
                        #endregion
                        break;
                    }
                    }
                    #endregion

                    if (aTarget != null && Info.Sort != MagicSort.DispatchXP && Info.Sort != MagicSort.RecoverSingleHP && !Reflected)
                    {
                        var msg = new MsgMagicEffect(aAttacker, aTarget, damage, aTargetX, aTargetY);

                        if (aAttacker.IsPlayer())
                        {
                            World.BroadcastMapMsg(attacker, msg, true);
                        }
                        else
                        {
                            World.BroadcastMapMsg(aAttacker, msg);
                        }
                    }
                    else if (!Reflected)
                    {
                        targets.Add(entity, damage);
                    }
                }

                #region Player: Update LastAttackTick
                if (aAttacker.IsPlayer())
                {
                    attacker.LastAttackTick = Environment.TickCount;
                }
                #endregion

                #region Player: Remove Dura
                if (aAttacker.IsPlayer() && aAttacker.Map.Id != 1039)
                {
                    if (attacker.MagicType == 8000)
                    {
                        for (SByte i = 0; i < 5; i++)
                        {
                            attacker.RemoveAtkDura();
                        }
                    }
                    else if (attacker.MagicType == 8001)
                    {
                        for (SByte i = 0; i < 3; i++)
                        {
                            attacker.RemoveAtkDura();
                        }
                    }
                    else
                    {
                        attacker.RemoveAtkDura();
                    }
                }
                #endregion

                #region Player: Add Exp
                if (aAttacker.IsPlayer())
                {
                    attacker.AddExp(Exp, true);
                    if (MagicExp > 0 && Info.Sort != MagicSort.AtkStatus)
                    {
                        attacker.AddMagicExp(attacker.MagicType, MagicExp);
                    }
                    else if (MagicExp > 0)
                    {
                        attacker.AddMagicExp(attacker.MagicType, 1);
                    }
                }
                #endregion

                if (aTarget == null || Info.Sort == MagicSort.DispatchXP || Info.Sort == MagicSort.RecoverSingleHP)
                {
                    var msg = new MsgMagicEffect(aAttacker, targets, aTargetX, aTargetY);

                    if (aAttacker.IsPlayer())
                    {
                        World.BroadcastMapMsg(attacker, msg, true);
                    }
                    else
                    {
                        World.BroadcastMapMsg(aAttacker, msg);
                    }
                }

                #region Player: Activate the weapon attribute (e.g. Poison Blade)
                if (aAttacker.IsPlayer() && aAttacker.Map.Id != 1039)
                {
                    Battle.WeaponAttribute(attacker, null);
                }
                #endregion
            }
            catch (Exception exc) { sLogger.Error(exc); }
        }
Exemple #14
0
        public static void PvP(Player Attacker, Player Target)
        {
            try
            {
                if (!Attacker.IsAlive())
                {
                    Attacker.IsInBattle = false;
                    return;
                }

                if (Target == null || !Target.IsAlive())
                {
                    Attacker.IsInBattle = false;
                    return;
                }

                if (Attacker.Map != Target.Map)
                {
                    Attacker.IsInBattle = false;
                    return;
                }

                if (!MyMath.CanSee(Attacker.X, Attacker.Y, Target.X, Target.Y, (Attacker.AtkRange + 1)))
                {
                    Attacker.IsInBattle = false;
                    return;
                }

                if (!CanAttack(Attacker, Target))
                {
                    Attacker.IsInBattle = false;
                    return;
                }

                if (Battle.WeaponSkill(Attacker, Target))
                {
                    return;
                }

                if (Attacker.AtkType != 25 && Target.IsFlying())
                {
                    Attacker.IsInBattle = false;
                    return;
                }

                if (!Attacker.Map.IsPkField() && !Attacker.Map.IsSynMap() && !Attacker.Map.IsPrisonMap())
                {
                    if (!Target.IsCriminal())
                    {
                        Attacker.AttachStatus(Status.Crime, 25000);
                    }
                }

                Attacker.LastAttackTick = Environment.TickCount;
                if (!MyMath.Success(Attacker.Dexterity))
                {
                    World.BroadcastMapMsg(Attacker, new MsgInteract(Attacker, Target, 0, (MsgInteract.Action)Attacker.AtkType), true);
                    return;
                }

                Int32 Damage = 0;
                Damage = MyMath.GetDamagePlayer2Player(Attacker, Target);

                if (Attacker.Map.Id != 1039)
                {
                    Attacker.RemoveAtkDura();
                    Target.RemoveDefDura();
                }

                if (!Target.Reflect())
                {
                    World.BroadcastMapMsg(Attacker, new MsgInteract(Attacker, Target, Damage, MsgInteract.Action.Attack), true);
                    if (Damage >= Target.CurHP)
                    {
                        Target.Die(Attacker);
                        World.BroadcastMapMsg(Attacker, new MsgInteract(Attacker, Target, 1, MsgInteract.Action.Kill), true);
                    }
                    else
                    {
                        Target.CurHP -= Damage;
                        Target.Send(new MsgUserAttrib(Target, Target.CurHP, MsgUserAttrib.AttributeType.Life));
                        if (Target.Team != null)
                        {
                            Target.Team.BroadcastMsg(new MsgUserAttrib(Target, Target.CurHP, MsgUserAttrib.AttributeType.Life));
                        }

                        if (Target.Action == Emotion.SitDown)
                        {
                            Target.Energy /= 2;
                            Target.Send(new MsgUserAttrib(Target, Target.Energy, MsgUserAttrib.AttributeType.Energy));

                            Target.Action = Emotion.StandBy;
                            World.BroadcastRoomMsg(Target, new MsgAction(Target, (int)Target.Action, MsgAction.Action.Emotion), true);
                        }
                    }
                }
                else
                {
                    if (Damage > 2000)
                    {
                        Damage = 2000;
                    }

                    World.BroadcastMapMsg(Attacker, new MsgInteract(Target, Attacker, Damage, MsgInteract.Action.ReflectWeapon), true);
                    if (Damage >= Attacker.CurHP)
                    {
                        Attacker.Die(null);
                        World.BroadcastMapMsg(Target, new MsgInteract(Target, Attacker, 1, MsgInteract.Action.Kill), true);
                    }
                    else
                    {
                        Attacker.CurHP -= Damage;
                        Attacker.Send(new MsgUserAttrib(Attacker, Attacker.CurHP, MsgUserAttrib.AttributeType.Life));
                        if (Attacker.Team != null)
                        {
                            Attacker.Team.BroadcastMsg(new MsgUserAttrib(Attacker, Attacker.CurHP, MsgUserAttrib.AttributeType.Life));
                        }
                    }
                }
                if (Attacker.Map.Id != 1039)
                {
                    Battle.WeaponAttribute(Attacker, Target);
                }
            }
            catch (Exception exc) { sLogger.Error(exc); }
        }