コード例 #1
0
ファイル: LobbyServer.cs プロジェクト: kojasou/wewladh
        private void MsgHandler_ClientVersion(Client client, ClientPacket msg)
        {
            var p = new ServerPacket(0x00);

            p.WriteByte(0x00);
            p.WriteUInt32(Program.Checksum);
            p.WriteByte(0x00);
            p.WriteString8("NexonInc.");
            client.Enqueue(p);

            Program.WriteLine("Client connected: {0}", ((IPEndPoint)client.Socket.RemoteEndPoint).Address);
        }
コード例 #2
0
        public void SendPaper(Item item, byte color)
        {
            Player.Paper = item;
            var packet = new ServerPacket(0x1B);

            packet.WriteByte((byte)item.Slot);
            packet.WriteByte(color);
            packet.WriteByte(0x0F);
            packet.WriteByte(0x14);
            packet.WriteString16(item.MiscData);
            Enqueue(packet);
        }
コード例 #3
0
        public void SpellAnimation(uint id, int animation, int speed, uint fromId, int fromAnimation)
        {
            var p = new ServerPacket(0x29);

            p.WriteByte(0x00); // ??
            p.WriteUInt32((uint)id);
            p.WriteUInt32((uint)fromId);
            p.WriteUInt16((ushort)animation);
            p.WriteUInt16((ushort)fromAnimation);
            p.WriteUInt16((ushort)speed);
            p.WriteByte(0x00);
            Enqueue(p);
        }
コード例 #4
0
 private void MsgHandler_RequestMetafile(Client client, ClientPacket msg)
 {
     if (!msg.ReadBoolean())
     {
         string fileName = msg.ReadString(msg.ReadByte());
         if (GameServer.MetafileDatabase.ContainsKey(fileName))
         {
             var p = new ServerPacket(0x6F);
             p.WriteByte(0);
             p.WriteString8(fileName);
             p.WriteUInt32(GameServer.MetafileDatabase[fileName].Checksum);
             p.WriteUInt16((ushort)GameServer.MetafileDatabase[fileName].RawData.Length);
             p.Write(GameServer.MetafileDatabase[fileName].RawData);
             client.Enqueue(p);
         }
     }
     else
     {
         var p = new ServerPacket(0x6F);
         p.WriteByte(1);
         p.WriteUInt16((ushort)GameServer.MetafileDatabase.Count);
         foreach (var kvp in GameServer.MetafileDatabase)
         {
             p.WriteString8(kvp.Value.Name);
             p.WriteUInt32(kvp.Value.Checksum);
         }
         client.Enqueue(p);
     }
 }
コード例 #5
0
        private void MsgHandler_ClientJoin(Client client, ClientPacket msg)
        {
            byte seed = msg.ReadByte();

            byte[] key  = msg.Read(msg.ReadByte());
            string name = msg.ReadString(msg.ReadByte());
            uint   id   = msg.ReadUInt32();

            Encryption.Parameters encryptionParameters = new Encryption.Parameters(key, seed);

            if (ExpectedRedirects.ContainsKey(id) && (ExpectedRedirects[id] != null))
            {
                Redirection r = ExpectedRedirects[id];
                if ((r.Name == name) && r.EncryptionParameters.Matches(encryptionParameters))
                {
                    if (r.SourceServer == Program.LobbyServer || r.SourceServer is LoginServer)
                    {
                        var p = new ServerPacket(0x60);
                        p.WriteByte(0x00);
                        p.WriteUInt32(Notification.Checksum);
                        client.Enqueue(p);

                        var packet = new ServerPacket(0x6F);
                        packet.WriteByte(1);
                        packet.WriteUInt16((ushort)GameServer.MetafileDatabase.Count);
                        foreach (var kvp in GameServer.MetafileDatabase)
                        {
                            packet.WriteString8(kvp.Value.Name);
                            packet.WriteUInt32(kvp.Value.Checksum);
                        }
                        client.Enqueue(packet);
                    }
                }
            }
        }
コード例 #6
0
        public virtual bool Turn(Direction direction, bool forcefully)
        {
            if (!forcefully && (Sleeping || Frozen || Coma || Dizzy || MindControlled || Polymorphed))
            {
                return(false);
            }

            Direction = direction;

            switch (Direction)
            {
            case Direction.North: XOffset = 0; YOffset = -1; break;

            case Direction.South: XOffset = 0; YOffset = 1; break;

            case Direction.West: XOffset = -1; YOffset = 0; break;

            case Direction.East: XOffset = 1; YOffset = 0; break;
            }

            foreach (var c in Map.Objects)
            {
                if (WithinRange(c, 12) && c is Player)
                {
                    var p = new ServerPacket(0x11);
                    p.WriteUInt32(ID);
                    p.WriteByte((byte)direction);
                    (c as Player).Client.Enqueue(p);
                }
            }

            return(true);
        }
コード例 #7
0
        public void Refresh()
        {
            SendMapInfo();
            SendLocation();
            Player.Display();
            foreach (var c in Player.Map.Objects)
            {
                if (c.WithinRange(Player, 12))
                {
                    c.DisplayTo(Player);
                }
            }

            //for (int x = 0; x < Player.Map.Width; x++)
            //{
            //    for (int y = 0; y < Player.Map.Height; y++)
            //    {
            //        if (Player.Map.Doors[x, y] != null)
            //            ToggleDoor(Player.Map.Doors[x, y]);
            //    }
            //}

            var p = new ServerPacket(0x22);

            p.WriteByte(0x00);
            Enqueue(p);
            Player.LastRefresh = DateTime.UtcNow;
        }
コード例 #8
0
ファイル: Item.cs プロジェクト: kojasou/wewladh
        public override void DisplayTo(VisibleObject obj)
        {
            if (obj is Player)
            {
                var player = (obj as Player);
                var client = player.Client;

                var p = new ServerPacket(0x07);
                p.WriteUInt16(1);
                p.WriteUInt16((ushort)Point.X);
                p.WriteUInt16((ushort)Point.Y);
                p.WriteUInt32((uint)ID);
                if (Value < 10)
                {
                    p.WriteUInt16((ushort)(139 + 0x8000));
                }
                else if (Value < 100)
                {
                    p.WriteUInt16((ushort)(142 + 0x8000));
                }
                else if (Value < 1000)
                {
                    p.WriteUInt16((ushort)(138 + 0x8000));
                }
                else if (Value < 10000)
                {
                    p.WriteUInt16((ushort)(141 + 0x8000));
                }
                else if (Value < 100000)
                {
                    p.WriteUInt16((ushort)(137 + 0x8000));
                }
                else if (Value < 1000000)
                {
                    p.WriteUInt16((ushort)(140 + 0x8000));
                }
                else
                {
                    p.WriteUInt16((ushort)(136 + 0x8000));
                }
                p.WriteByte(0); // random 1
                p.WriteByte(0); // random 2
                p.WriteByte(0); // random 3

                client.Enqueue(p);
            }
        }
コード例 #9
0
        private void MsgHandler_RequestWebsite(Client client, ClientPacket msg)
        {
            var p1 = new ServerPacket(0x66);

            p1.WriteByte(0x03);
            p1.WriteString8("http://www.wewladh.com");
            client.Enqueue(p1);
        }
コード例 #10
0
        public void SendMap(Map map)
        {
            int tile = 0;

            for (int row = 0; row < map.Height; row++)
            {
                var p = new ServerPacket(0x3C);
                p.WriteUInt16((ushort)row);
                for (int column = 0; column < map.Width * 6; column += 2)
                {
                    p.WriteByte(map.RawData[tile + 1]);
                    p.WriteByte(map.RawData[tile]);
                    tile += 2;
                }
                Enqueue(p);
            }
        }
コード例 #11
0
        public void SendLoginMessage(int type, string msg)
        {
            var p = new ServerPacket(0x02);

            p.WriteByte((byte)type);
            p.WriteString8(msg);
            Enqueue(p);
        }
コード例 #12
0
        private void MsgHandler_RequestNotification(Client client, ClientPacket msg)
        {
            var p1 = new ServerPacket(0x60);

            p1.WriteByte(0x01);
            p1.WriteUInt16((ushort)Notification.RawData.Length);
            p1.Write(Notification.RawData);
            client.Enqueue(p1);
        }
コード例 #13
0
        public void BodyAnimation(uint id, int animation, int speed)
        {
            var p = new ServerPacket(0x1A);

            p.WriteUInt32((uint)id);
            p.WriteByte((byte)animation);
            p.WriteUInt16((ushort)speed);
            p.WriteUInt16(0x00);
            Enqueue(p);
        }
コード例 #14
0
        public void SendWorldMap()
        {
            Player.WorldMap.IsOpen = true;
            var packet = new ServerPacket(0x2E);

            packet.WriteString8(Player.WorldMap.FileName);
            packet.WriteByte((byte)Player.WorldMap.Nodes.Count);
            packet.WriteByte(0x09);
            for (int i = 0; i < Player.WorldMap.Nodes.Count; i++)
            {
                var node = Player.WorldMap.Nodes[i];
                packet.WriteUInt16((ushort)node.X);
                packet.WriteUInt16((ushort)node.Y);
                packet.WriteString8(node.MapName);
                packet.WriteInt32(i);
                packet.WriteUInt16((ushort)node.MapX);
                packet.WriteUInt16((ushort)node.MapY);
            }
            Enqueue(packet);
        }
コード例 #15
0
        public void SpellAnimation(int animation, int x, int y, int speed)
        {
            var p = new ServerPacket(0x29);

            p.WriteByte(0x00); // ??
            p.WriteUInt32(uint.MinValue);
            p.WriteUInt16((ushort)animation);
            p.WriteUInt16((ushort)speed);
            p.WriteUInt16((ushort)x);
            p.WriteUInt16((ushort)y);
            Enqueue(p);
        }
コード例 #16
0
ファイル: Item.cs プロジェクト: kojasou/wewladh
        public override void DisplayTo(VisibleObject obj)
        {
            if (obj is Player)
            {
                var player = (obj as Player);
                var client = player.Client;

                if (player.Quests.ContainsKey(QuestName))
                {
                    bool returnQuest = true;

                    var quest = player.Quests[QuestName];
                    if (QuestStep == quest.CurrentStep)
                    {
                        var subQuest = quest.QuestStep;
                        if (subQuest.Progress == QuestProgress.InProgress)
                        {
                            returnQuest = false;
                        }
                    }

                    if (returnQuest)
                    {
                        return;
                    }
                }

                var p = new ServerPacket(0x07);
                p.WriteUInt16(1);
                p.WriteUInt16((ushort)Point.X);
                p.WriteUInt16((ushort)Point.Y);
                p.WriteUInt32((uint)ID);
                p.WriteUInt16((ushort)(Sprite + 0x8000));
                p.WriteByte(0); // random 1
                p.WriteByte(0); // random 2
                p.WriteByte(0); // random 3

                client.Enqueue(p);
            }
        }
コード例 #17
0
 public void ToggleDoor(Door door)
 {
     foreach (var point in door.Points)
     {
         var packet = new ServerPacket(0x32);
         packet.WriteByte(0x01);
         packet.WriteByte((byte)point.X);
         packet.WriteByte((byte)point.Y);
         packet.WriteByte(!door.IsOpen);
         packet.WriteByte((byte)door.Direction);
         packet.WriteByte(0x00);
         Enqueue(packet);
     }
 }
コード例 #18
0
        public void AcceptConnection()
        {
            if (listener.Pending())
            {
                var socket   = listener.AcceptSocket();
                var greetMsg = new ServerPacket(0x7E);
                var client   = new Client(socket, this);

                var ip = ((IPEndPoint)socket.RemoteEndPoint).Address.ToString();

                if (Program.IPBanList.Contains(ip))
                {
                    client.Connected = false;
                    return;
                }

                Clients.Add(client);
                greetMsg.WriteByte(0x1B);
                greetMsg.WriteString("CONNECTED SERVER\n");
                client.Enqueue(greetMsg);
            }
        }
コード例 #19
0
        public virtual void Say(string msg, int type)
        {
            foreach (var c in Map.Objects)
            {
                if (c is Player && (WithinRange(c, 12) || type == 1))
                {
                    var player = c as Player;
                    var packet = new ServerPacket(0x0D);
                    packet.WriteByte((byte)type);
                    packet.WriteUInt32(ID);
                    switch (type)
                    {
                    case 0: packet.WriteString8("{0}: {1}", Name, msg); break;

                    case 1: packet.WriteString8("{0}! {1}", Name, msg); break;

                    default: packet.WriteString8(msg); break;
                    }
                    player.Client.Enqueue(packet);
                }
            }
        }
コード例 #20
0
        public void SendMapInfo()
        {
            var p = new ServerPacket(0x15);

            p.WriteUInt16((ushort)Player.Map.Number);
            p.WriteByte((byte)(Player.Map.Width % 256));
            p.WriteByte((byte)(Player.Map.Height % 256));
            byte flags = 0;

            if ((Player.Map.Flags & MapFlags.Snow) == MapFlags.Snow)
            {
                flags |= 1;
            }
            if ((Player.Map.Flags & MapFlags.Rain) == MapFlags.Rain)
            {
                flags |= 2;
            }
            if ((Player.Map.Flags & MapFlags.NoMap) == MapFlags.NoMap)
            {
                flags |= 64;
            }
            if ((Player.Map.Flags & MapFlags.Winter) == MapFlags.Winter)
            {
                flags |= 128;
            }
            p.WriteByte(flags);
            p.WriteByte((byte)(Player.Map.Width / 256));
            p.WriteByte((byte)(Player.Map.Height / 256));
            p.WriteByte((byte)(Player.Map.Checksum % 256));
            p.WriteByte((byte)(Player.Map.Checksum / 256));
            p.WriteString8(Player.Map.Name);
            Enqueue(p);

            if (Player.CurrentMusic != Player.Map.Music)
            {
                Player.CurrentMusic = Player.Map.Music;
                SoundEffect(0x8000 + Player.Map.Music);
            }

            Player.WorldMap.IsOpen = false;
        }
コード例 #21
0
        private void MsgHandler_Login(Client client, ClientPacket msg)
        {
            var name      = msg.ReadString(msg.ReadByte());
            var password1 = msg.ReadString(msg.ReadByte());

            var accountid  = 0;
            var password2  = String.Empty;
            var gamemaster = AdminRights.None;
            var active     = false;
            var exists     = false;

            var com = Program.MySqlConnection.CreateCommand();

            com.CommandText = "SELECT characters.acct_id, characters.password, characters.gm, accounts.active "
                              + "FROM characters "
                              + "LEFT JOIN accounts "
                              + "ON characters.acct_id = accounts.acct_id "
                              + "WHERE (characters.name = @name) AND (characters.server = @server)";
            com.Parameters.AddWithValue("@name", name);
            com.Parameters.AddWithValue("@server", GameServer.Name);
            var reader = com.ExecuteReader();

            if (reader.Read())
            {
                accountid  = reader.GetInt32(0);
                password2  = reader.GetString(1);
                gamemaster = (AdminRights)Enum.Parse(typeof(AdminRights), reader.GetString(2));
                active     = (!reader.IsDBNull(3) && reader.GetBoolean(3));
                exists     = true;
            }
            reader.Close();

            if (!GameServer.AllowLogin)
            {
                client.SendLoginMessage(14, "The game server is currently closed.");
                return;
            }

            if (!exists)
            {
                client.SendLoginMessage(14, "That character does not exist.");
                return;
            }

            if (password1 != password2)
            {
                client.SendLoginMessage(14, "Incorrect password.");
                return;
            }

            if (accountid == 0)
            {
                client.SendLoginMessage(14, "Please register your character at game.wewladh.com");
                return;
            }

            if (!active)
            {
                client.SendLoginMessage(14, "Your account has been locked.");
                return;
            }

            foreach (Client c in GameServer.Clients)
            {
                if ((c.Player != null) && c.Player.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase))
                {
                    c.Connected = false;
                    client.SendLoginMessage(14, "Your character is already playing.");
                    return;
                }
                if ((c.Player != null) && (accountid != 0) && (c.Player.AccountID == accountid))
                {
                    c.Connected = false;
                    client.SendLoginMessage(14, "Your account is already playing.");
                    return;
                }
            }

            if (Program.RunningSlowly)
            {
                client.SendLoginMessage(14, "The game server is busy right now. Please try again.");
                return;
            }

            client.SendLoginMessage(0, "\0");

            var p = new ServerPacket(0x22);

            p.WriteByte(0x00);
            client.Enqueue(p);

            foreach (var message in File.ReadAllLines(GameServer.DataPath + "\\login.txt"))
            {
                client.SendMessage(message);
            }

            var r = new Redirection();

            r.DestinationServer    = GameServer;
            r.EncryptionParameters = client.EncryptionParams;
            r.Name         = name;
            r.SourceServer = this;
            client.Redirect(r);
        }
コード例 #22
0
        public void SendProfile()
        {
            var p = new ServerPacket(0x39);

            p.WriteByte(Player.GameServer.NationDatabase[Player.Nation].Flag);
            p.WriteString8((Player.Guild != null) ? Player.GuildRank.ToString() : string.Empty);

            var masks = new List <byte>();

            for (int i = 0; i < Player.GameServer.TitleDatabase.Count; i++)
            {
                var title = Player.GameServer.TitleDatabase[i];

                var value = i % 8;

                if (value == 0)
                {
                    masks.Add(0);
                }

                var index = masks.Count - 1;

                if (title.Available(Player))
                {
                    switch (value)
                    {
                    case 0: masks[index] += 0x80; break;

                    case 1: masks[index] += 0x40; break;

                    case 2: masks[index] += 0x20; break;

                    case 3: masks[index] += 0x10; break;

                    case 4: masks[index] += 0x08; break;

                    case 5: masks[index] += 0x04; break;

                    case 6: masks[index] += 0x02; break;

                    case 7: masks[index] += 0x01; break;
                    }
                }
            }

            p.WriteByte((byte)masks.Count);
            foreach (var mask in masks)
            {
                p.WriteByte(mask);
            }

            p.WriteByte((byte)Player.Title);
            if (!Player.Group.HasMembers)
            {
                p.WriteString8("그룹 없음");
            }
            else
            {
                StringBuilder sb = new StringBuilder("그룹구성원\n");
                foreach (var player in Player.Group.Members)
                {
                    sb.AppendFormat("{0} {1}\n", (player == Player.Group.Leader) ? "*" : " ", player.Name);
                }
                sb.AppendFormat("총 {0}명", Player.Group.Members.Count);
                p.WriteString8(sb.ToString());
            }
            p.WriteByte(Player.GroupToggle);
            p.WriteByte(0x00); // ??
            p.WriteByte((byte)Player.Class);
            p.WriteByte(0x01); // ??
            p.WriteByte(0x00); // ??
            p.WriteString8(string.Format("{0}{1}{2}",
                                         Player.Master ? "Master " : string.Empty,
                                         (Player.Specialization != Specialization.None) ? Player.Specialization + " " : string.Empty,
                                         Player.Class));
            p.WriteString8((Player.Guild != null) ? Player.Guild.Name : string.Empty);
            p.WriteByte((byte)Player.Legend.Count);
            foreach (var kvp in Player.Legend.OrderBy(l => l.Value.DateUpdated))
            {
                p.WriteByte((byte)kvp.Value.Icon);
                p.WriteByte((byte)kvp.Value.Color);
                p.WriteString8(kvp.Value.Key);
                p.WriteString8(kvp.Value.ToString());
            }
            p.WriteByte(0x00);   // ??
            p.WriteUInt16(Player.DisplayBitmask);
            p.WriteByte(0x02);   // ??
            p.WriteUInt32(0x00); // ??
            p.WriteByte(0x00);   // ??
            Enqueue(p);
        }
コード例 #23
0
        public virtual void Damage(double dmg, Character attacker = null, int sound = 0, DamageType damageType = DamageType.RawDamage, DamageFlags flags = DamageFlags.None)
        {
            if (LifeStatus != LifeStatus.Alive)
            {
                return;
            }

            RemoveStatus("Morph");

            var realDamage = dmg;

            if ((flags & DamageFlags.CanBeAbsorbed) == DamageFlags.CanBeAbsorbed)
            {
                if (AbsorbingAbsoluteDamage)
                {
                    CurrentAbsoluteDamageAbsorbed += dmg;
                    if (MaximumAbsoluteDamageAbsorbed <= CurrentAbsoluteDamageAbsorbed)
                    {
                        RemoveStatus("AbsoluteAbsorb");
                    }
                    realDamage = 0;
                    SpellAnimation(AbsoluteAbsorbAnimation, 100);
                }
                else if (AbsorbingPhysicalDamage && damageType == DamageType.Physical)
                {
                    CurrentPhysicalDamageAbsorbed += dmg;
                    if (MaximumPhysicalDamageAbsorbed <= CurrentPhysicalDamageAbsorbed)
                    {
                        RemoveStatus("PhysicalAbsorb");
                    }
                    realDamage = 0;
                    SpellAnimation(PhysicalAbsorbAnimation, 100);
                }
                else if (AbsorbingMagicalDamage && damageType == DamageType.Magical)
                {
                    CurrentMagicalDamageAbsorbed += dmg;
                    if (MaximumMagicalDamageAbsorbed <= CurrentMagicalDamageAbsorbed)
                    {
                        RemoveStatus("MagicalAbsorb");
                    }
                    realDamage = 0;
                    SpellAnimation(MagicalAbsorbAnimation, 100);
                }
            }

            if (damageType == DamageType.Physical)
            {
                realDamage *= ArmorProtection * (1d - PhysicalProtection);
            }
            else if (damageType == DamageType.Magical)
            {
                realDamage -= (realDamage * (MagicResistance / 100d));
                realDamage *= (1d - MagicalProtection);
            }

            if (Map.Flags.HasFlag(MapFlags.PlayerKill))
            {
                dmg *= 0.75;
            }

            if (attacker != null)
            {
                if (!Enemies.Contains(attacker))
                {
                    Enemies.Add(attacker);
                }
                if (!attacker.Enemies.Contains(this))
                {
                    attacker.Enemies.Add(this);
                }
                LastAttacker = attacker;
            }

            if ((flags & DamageFlags.CanBeRedirected) == DamageFlags.CanBeRedirected)
            {
                if (RedirectingPhysicalDamage && damageType == DamageType.Physical)
                {
                    if (PhysicalRedirectTarget != null && PhysicalRedirectTarget != this && WithinRange(PhysicalRedirectTarget, 12))
                    {
                        var yourDamage = realDamage * PhysicalRedirectPercent;
                        realDamage -= yourDamage;
                        PhysicalRedirectTarget.Damage(yourDamage, null, 0, DamageType.RawDamage, DamageFlags.None);
                    }
                    if (--PhysicalRedirectCount == 0)
                    {
                        RemoveStatus("PhysicalRedirect");
                    }
                }

                if (RedirectingMagicalDamage && damageType == DamageType.Magical)
                {
                    if (MagicalRedirectTarget != null && MagicalRedirectTarget != this && WithinRange(MagicalRedirectTarget, 12))
                    {
                        var yourDamage = realDamage * MagicalRedirectPercent;
                        realDamage -= yourDamage;
                        MagicalRedirectTarget.Damage(yourDamage, null, 0, DamageType.RawDamage, DamageFlags.None);
                    }
                    if (--MagicalRedirectCount == 0)
                    {
                        RemoveStatus("MagicalRedirect");
                    }
                }
            }

            if ((flags & DamageFlags.CanBeConvertedToManaDamage) == DamageFlags.CanBeConvertedToManaDamage)
            {
                if (ConvertingPhysicalDamageToManaDamage && damageType == DamageType.Physical)
                {
                    CurrentMP -= (long)realDamage;
                    if (CurrentMP < 0)
                    {
                        CurrentMP = 0;
                    }
                    CurrentPhysicalDamageConvertedToManaDamage += dmg;
                    if (MaximumPhysicalDamageConvertedToManaDamage <= CurrentPhysicalDamageConvertedToManaDamage)
                    {
                        RemoveStatus("PhysicalConvertToMana");
                    }
                    realDamage = 0;
                    SpellAnimation(PhysicalConvertToManaAnimation, 100);
                }
                if (ConvertingMagicalDamageToManaDamage && damageType == DamageType.Magical)
                {
                    CurrentMP -= (long)realDamage;
                    if (CurrentMP < 0)
                    {
                        CurrentMP = 0;
                    }
                    CurrentMagicalDamageConvertedToManaDamage += dmg;
                    if (MaximumMagicalDamageConvertedToManaDamage <= CurrentPhysicalDamageConvertedToManaDamage)
                    {
                        RemoveStatus("MagicalConvertToMana");
                    }
                    realDamage = 0;
                    SpellAnimation(MagicalConvertToManaAnimation, 100);
                }
            }

            CurrentHP -= (long)realDamage;

            if (CurrentHP < 0)
            {
                CurrentHP = 0;
            }

            if (attacker != null)
            {
                if (Attackers.ContainsKey(attacker))
                {
                    Attackers[attacker] += realDamage;
                }
                else
                {
                    Attackers.Add(attacker, realDamage);
                }
            }

            double percent = Math.Floor((double)CurrentHP / (double)MaximumHP * 100.0);

            if (percent < 0)
            {
                percent = 0;
            }

            if (percent > 100)
            {
                percent = 100;
            }

            var dot = (flags & DamageFlags.DamageOverTime) == DamageFlags.DamageOverTime;
            var id  = (attacker != null) ? attacker.ID : ID;

            foreach (Character c in Map.Objects)
            {
                if (WithinRange(c, 12) && (c is Player))
                {
                    var packet = new ServerPacket(0x13);
                    packet.WriteUInt32(id);
                    packet.WriteUInt32(ID);
                    packet.WriteByte(dot);
                    packet.WriteByte((byte)percent);
                    packet.WriteUInt32((uint)realDamage);
                    packet.WriteByte((byte)sound);
                    (c as Player).Client.Enqueue(packet);
                }
            }
        }
コード例 #24
0
        public virtual bool Heal(Character healer, double amount, int sound = 255)
        {
            if (LifeStatus != LifeStatus.Alive)
            {
                return(false);
            }

            if (amount > uint.MaxValue)
            {
                amount = uint.MaxValue;
            }

            if (amount < uint.MinValue)
            {
                amount = uint.MinValue;
            }

            if (ConvertHealToDamage)
            {
                amount *= -1;
            }

            CurrentHP += (long)amount;

            if (CurrentHP > MaximumHP)
            {
                CurrentHP = MaximumHP;
            }

            if (CurrentHP < 0)
            {
                CurrentHP = 0;
            }

            var percent = Math.Floor((double)CurrentHP / (double)MaximumHP * 100.0);

            if (percent > 100)
            {
                percent = 100;
            }

            if (percent < 0)
            {
                percent = 0;
            }

            foreach (Character c in Map.Objects)
            {
                if (WithinRange(c, 12) && c is Player)
                {
                    var packet = new ServerPacket(0x13);
                    packet.WriteUInt32((healer == null) ? ID : healer.ID);
                    packet.WriteUInt32(ID);
                    packet.WriteByte(0x00);
                    packet.WriteByte((byte)percent);
                    packet.WriteUInt32((uint)(0 - amount));
                    packet.WriteByte((byte)sound);
                    (c as Player).Client.Enqueue(packet);
                }
            }
            return(true);
        }
コード例 #25
0
        public void SendStatistics(StatUpdateFlags flags)
        {
            if (Player.CanWalkThroughWalls || Player.CanWalkThroughUnits)
            {
                flags |= StatUpdateFlags.GameMasterA;
            }
            else
            {
                flags |= StatUpdateFlags.Swimming;
            }

            var p = new ServerPacket(0x08);

            p.WriteByte((byte)flags);
            if ((flags & StatUpdateFlags.Primary) == StatUpdateFlags.Primary)
            {
                p.Write(new byte[] { 1, 0, 0 });
                p.WriteByte((byte)Player.Level);
                p.WriteByte(0x00);
                p.WriteByte((byte)Player.Ability);
                p.WriteUInt32(Player.MaximumHP);
                p.WriteUInt32(Player.MaximumMP);
                p.WriteUInt16(Player.Str);
                p.WriteUInt16(Player.Int);
                p.WriteUInt16(Player.Wis);
                p.WriteUInt16(Player.Con);
                p.WriteUInt16(Player.Dex);
                p.WriteByte(Player.AvailableStatPoints > 0);
                p.WriteByte((byte)Player.AvailableStatPoints);
                p.WriteUInt16((ushort)Player.MaximumWeight);
                p.WriteUInt16((ushort)Player.CurrentWeight);
                p.WriteUInt32(uint.MinValue);
            }
            if ((flags & StatUpdateFlags.Current) == StatUpdateFlags.Current)
            {
                p.WriteUInt32((uint)Player.CurrentHP);
                p.WriteUInt32((uint)Player.CurrentMP);
            }
            if ((flags & StatUpdateFlags.Experience) == StatUpdateFlags.Experience)
            {
                p.WriteUInt32((uint)Player.Experience);
                p.WriteUInt32((uint)(Player.ToNextLevel - Player.Experience));
                p.WriteUInt32((uint)(Player.ToNextLevel - Player.ToThisLevel));
                p.WriteUInt32((uint)Player.AbilityExp);
                p.WriteUInt32((uint)(Player.ToNextAbility - Player.AbilityExp));
                p.WriteUInt32((uint)(Player.ToNextAbility - Player.ToThisAbility));
                p.WriteUInt32((uint)Player.GamePoints);
                p.WriteUInt32((uint)Player.Gold);
            }
            if ((flags & StatUpdateFlags.Secondary) == StatUpdateFlags.Secondary)
            {
                p.WriteUInt32(uint.MinValue);
                p.WriteUInt16(ushort.MinValue);
                p.WriteByte((byte)Player.OffenseElement);
                p.WriteByte((byte)Player.DefenseElement);
                p.WriteByte((byte)(Player.MagicResistance / 10));
                p.WriteByte(byte.MinValue);
                p.WriteSByte(Player.ArmorClass);
                p.WriteSByte(Player.Dmg);
                p.WriteSByte(Player.Hit);
            }
            Enqueue(p);
        }