Esempio n. 1
0
        public static void SkillToMobs(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            var map     = client.Metadata["map"] as IMap;
            var mapmobs = (client.Metadata["map"] as IMap).GetSurroundingMobs(client, 3);
            var mobdata = map.GetMobsData;



            var skillid = packet.ReadUShort();
            var unk     = packet.ReadInt();
            var unk1    = packet.ReadByte();
            var unk2    = packet.ReadUShort();
            var unk3    = packet.ReadShort();
            var unk4    = packet.ReadByte();
            var dmg     = packet.ReadUInt();
            var unk5    = packet.ReadByte();
            var unk6    = packet.ReadShort();
            var unk7    = packet.ReadShort();
            var unk8    = packet.ReadShort();
            var unk9    = packet.ReadShort();
            var mobid   = packet.ReadShort();
            var unk11   = packet.ReadByte();
            var unk12   = packet.ReadShort();
            var unk13   = packet.ReadShort();

#if DEBUG
            Log.Notice("SkillID:" + skillid + " SkillSlot:" + unk + " unk1:" + unk1 + " unk2:" + unk2 + " unk3:" + unk3 + " unk4:" + unk4 + " dmg:" + dmg + " unk5:" + unk5 + " unk6:" + unk6 + " unk7:" + unk7 + " unk8:" + unk8 + " unk9:" + unk9 + " MobID:" + mobid + " unk11:" + unk11 + " unk12:" + unk12 + " unk13:" + unk13 + "");
#endif

            //packet.Skip(6);
            var attack = packet.ReadUShort();

            Character character = client.Metadata["fullchar"] as Character;
            uint      hp        = character.stats.curhp;
            uint      mp        = character.stats.curmp;

            SkillLoader s         = new SkillLoader();
            var         skilllist = s.LoadSkillData(skillid);
            var         sid       = skilllist.Find(x => x.ID == skillid);

            var char_atk = (int)client.Metadata["patk"];

            if (sid.Type == 1)
            {
                char_atk = (int)client.Metadata["patk"];
            }
            if (sid.Type == 2)
            {
                char_atk = (int)client.Metadata["matk"];
            }

            var mi = mapmobs.Find(x => x.Id == mobid);
            var md = mobdata[mi.SId];

            uint attack_rate = Convert.ToUInt32(new Random().Next(1, 10));

            var normal_atk = char_atk + (sid.Attack + ((sid.Amp / 100) * sid.Attack));

            var mobdef = new Random().Next(md.Defense, md.DefRate);

            var normal_damage = normal_atk - mobdef;
            var crit_damage   = normal_damage + (normal_damage * sid.Critical);

            var damage = 0;

            var atack_result = 0;

            if (attack_rate <= 5)
            {
                atack_result        = 2;
                damage              = normal_damage;
                character.stats.exp = character.stats.exp + (ulong)damage * 2;
            }
            if (attack_rate == 6)
            {
                atack_result        = 1;
                damage              = crit_damage;
                character.stats.exp = character.stats.exp + (ulong)damage * 2;
            }
            if (attack_rate == 7)
            {
                atack_result = 27;
            }

            if (attack_rate >= 8)
            {
                atack_result = 21;
            }

            //Damage Maked
            if (damage < md.Defense && damage > 0)
            {
                damage = new Random().Next(1, 5);
            }

            if (damage >= mi.CurrentHP && damage > 0)
            {
                damage       = mi.CurrentHP;
                mi.CurrentHP = 0;
                //map.DropItem(mi.CurrentPosX, mi.CurrentPosX, 13, 1,1);
            }
            else
            {
                mi.CurrentHP = mi.CurrentHP - damage;
            }


            var exp      = character.stats.exp;
            var skillexp = character.stats.swordrank + sid.Attack;


            builder.New(0x00AE);
            {
                builder += (ushort)skillid;     //skillid
                builder += hp;                  //Hp
                builder += mp;                  //Mp
                builder += (ushort)0;           //SP
                builder += (ulong)exp;          //Exp
                builder += (ulong)0;            //OXP
                builder += (ulong)skillexp;     //SkillEXP

                builder += new byte[26];

                builder += (uint)0xFFFFFFFF;
                builder += (byte)0;
                builder += hp;
                builder += (uint)0;

                builder += (byte)1;

                builder += (byte)mobid;

                builder += (byte)0;

                builder += (byte)map.ID;
                builder += (byte)2;
                builder += (byte)2;

                builder += (byte)atack_result;

                builder += (int)damage;

                builder += (int)mi.CurrentHP;

                builder += new byte[12];
                builder += (byte)1;
            }

            client.Send(builder, "SkillToMobs");

            if (mi.CurrentHP == 0)
            {
                mi.Spawn = Environment.TickCount + md.Respawn * 10;

                mapmobs.Remove(mi);
            }
        }
Esempio n. 2
0
        public Server(int server, int channel)
        {
            this.server  = server;
            this.channel = channel;

            Console.Title         = "Minerva Channel Server";
            Console.CursorVisible = false;

            int start = Environment.TickCount;

            Util.Info.PrintLogo();
            Console.WriteLine();
            Util.Info.PrintInfo();
            Console.WriteLine();

            AppDomain.CurrentDomain.UnhandledException += UnhandledException;

            Configuration.Load(string.Format("Channel_{0}_{1}", server, channel));
            Log.Start(string.Format("Channel_{0}_{1}", server, channel), Configuration.channelLog, Configuration.channelLogLvl);    // Start logging service

            clients = new Dictionary <ulong, ClientHandler>();
            events  = new EventHandler();

            events.OnClientDisconnect += (sender, client) => {
                if (client.RemoteEndPoint != null)
                {
                    Log.Notice("Client {0} disconnected from Channel Server", client.RemoteEndPoint);
                    if (client.AccountID > 0 && syncServer != null)
                    {
                        Authentication.UpdateOnline(syncServer, client.AccountID, false);
                    }
                    clients.Remove((ulong)client.Metadata["magic"]);
                }
            };

            events.OnError         += (sender, message) => { Log.Error(message, "[Channel::Server::" + sender.GetType() + "()]"); };
            events.OnReceivePacket += (sender, e) => { Log.Received(e.Name, e.Opcode, e.Length); };
            events.OnSendPacket    += (sender, e) => { Log.Sent(e.Name, e.Opcode, e.Length); };
            events.OnWarp          += (sender, client, map, x, y) => { client.Metadata["map"] = maps[map]; maps[map].MoveClient(client, x / 16, y / 16); maps[map].UpdateCells(client); };

            /*Console.WriteLine("Compiling and registering scripts...");
             * scripts = new ScriptHandler();
             * scripts.Concatenate("Events", new string[] { "mscorlib" });
             * scripts.Run("Events");
             * scripts.CreateInstance("Events");
             * dynamic result = scripts.Invoke("_init_", events);*/

            try
            {
                Log.Message("Reading configuration...", Log.DefaultFG);

                mapLoader = new MapLoader();
                maps      = mapLoader.LoadMaps();

                skillLoader = new SkillLoader();
                SkillData   = skillLoader.LoadSkills();

                Log.Message("Registering packets...", Log.DefaultFG);
                packets = new PacketHandler("world", new PacketProtocol().GetType(), events);

                var aa      = Configuration.channelIp;
                var address = BitConverter.ToUInt32(aa.GetAddressBytes(), 0);
                var port    = Configuration.channelPort;

                listener = new TcpListener(aa, port);
                thread   = new Thread(Listen);
                thread.Start();

                syncServer = new SyncReceiver(Configuration.masterIP, Configuration.masterPort, events);
                syncServer.OnSyncSuccess += (sender, e) =>
                {
                    var type       = Configuration.channelType;
                    var maxPlayers = Configuration.maxPlayers;
                    Authentication.RegisterChannel(syncServer, server, channel, type, address, port, maxPlayers);
                };

                Log.Notice("Minerva started in: {0} seconds", (Environment.TickCount - start) / 1000.0f);
            }
            catch (Exception e)
            {
                Log.Error(e.Message, "[Channel::" + e.Source + "::" + e.TargetSite + "()]");
                #if DEBUG
                throw e;
                #endif
            }
        }