Exemplo n.º 1
0
        public static void BeginSkill(int Index_)
        {
            Player.Objects[Index_].UsingSkill = true;

            Silkroad.Skill_ tmpSkill = Silkroad.GetSkillById(Player.Objects[Index_].AttackingSkillID);

            Player.Stats[Index_].CMP -= tmpSkill.RequiredMp;
            Stats.MPUpdate(Index_, true);

            Player.Objects[Index_].AttackingCastingID = (uint)random.Next(500, 50000);

            PacketWriter writer = new PacketWriter();

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_SKILL_ATTACK);
            writer.AppendByte(1);
            writer.AppendByte(1);
            ServerSocket.Send(writer.getWorkspace(), Index_);

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ATTACK);
            writer.AppendWord(0x201);
            writer.AppendDword(Player.Objects[Index_].AttackingSkillID);
            writer.AppendDword(Player.General[Index_].UniqueID);
            writer.AppendDword(Player.Objects[Index_].AttackingCastingID);
            writer.AppendDword(Player.Objects[Index_].AttackingObjectId);
            writer.AppendByte(0);

            ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);

            if (tmpSkill.CastTime <= 0)
            {
                EndSkill(Index_);
            }

            else
            {
                Timers.CastAttackTimer[Index_].Interval = tmpSkill.CastTime * 1000;
                Timers.CastAttackTimer[Index_].Start();
            }
        }
Exemplo n.º 2
0
        public static void OnUnique(uint monsterid, bool kill, string name)
        {
            PacketWriter writer = new PacketWriter();

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_UNIQUE);
            if (kill)
            {
                writer.AppendByte(6);
                writer.AppendDword(monsterid);
                writer.AppendWord((ushort)name.Length);
                writer.AppendString(false, name);
            }
            else
            {
                writer.AppendByte(5);
                writer.AppendDword(monsterid);
            }

            int ObjectIndex = Players.GetObjectIndex(monsterid);

            ServerSocket.SendPacketIfMonsterIsSpawned(writer.getWorkspace(), ObjectIndex);
        }
Exemplo n.º 3
0
        public static void HPMPUpdate(int Index_)
        {
            // make sure that we don't add a higher value than maxHP
            if (Player.Stats[Index_].CHP > Player.Stats[Index_].HP)
            {
                Player.Stats[Index_].CHP = (int)Player.Stats[Index_].HP;
            }
            // make sure that we don't add a higher value than maxMP
            if (Player.Stats[Index_].CMP > Player.Stats[Index_].MP)
            {
                Player.Stats[Index_].CMP = (int)Player.Stats[Index_].MP;
            }

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_HPMP_UPDATE);
            writer.AppendDword(Player.General[Index_].UniqueID);
            writer.AppendByte(0x10);
            writer.AppendByte(0x00);
            writer.AppendByte(0x03);
            writer.AppendDword((uint)Player.Stats[Index_].CHP);
            writer.AppendDword((uint)Player.Stats[Index_].CMP);
            ServerSocket.Send(writer.getWorkspace(), Index_);
        }
Exemplo n.º 4
0
        public static void OnDeSpawn(int Index_, uint ObjectId)
        {
            if (ObjectId != 0)
            {
                int ObjectIndex = Players.GetObjectIndexAndType(Index_, ObjectId);

                Timers.MonsterAttack[ObjectIndex].Stop();
                Timers.MonsterMovement[ObjectIndex].Stop();

                Monsters.General[ObjectIndex]  = new Monsters._General();
                Monsters.Position[ObjectIndex] = new _Position();

                for (int i = 0; i < Player.PlayersOnline; i++)
                {
                    if (Player.General[i].UniqueID != 0 && Player.Objects[i].SpawnedMonsterIndex.Contains(ObjectIndex))
                    {
                        ServerSocket.Send(Players.CreateDeSpawnPacket(ObjectId), i);
                        Player.Objects[i].SpawnedMonsterIndex.Remove(ObjectIndex);
                    }
                }
            }
        }
Exemplo n.º 5
0
        private static void UnEquipItem(int Index_, int CharacterItemSourceIndex, int CharacterItemDestinationIndex)
        {
            PacketWriter writer = new PacketWriter();

            Silkroad.Item_ SourceItem = Silkroad.GetItemById(DatabaseCore.Item.ItemId[CharacterItemSourceIndex]);

            if (DatabaseCore.Item.Slot[CharacterItemSourceIndex] <= 5)
            {
                Player.Stats[Index_].PhyDef -= (ushort)SourceItem.MAX_PHYSDEF;
                Player.Stats[Index_].MagDef -= (ushort)SourceItem.MAGDEF_MAX;
                Player.Stats[Index_].Parry  -= (ushort)SourceItem.MIN_PARRY;
            }
            else if (DatabaseCore.Item.Slot[CharacterItemSourceIndex] == 6)
            {
                Player.Stats[Index_].MinPhy      -= (ushort)SourceItem.MIN_LPHYATK;
                Player.Stats[Index_].MaxPhy      -= (ushort)SourceItem.MIN_HPHYATK;
                Player.Stats[Index_].MinMag      -= (ushort)SourceItem.MIN_LMAGATK;
                Player.Stats[Index_].MaxMag      -= (ushort)SourceItem.MIN_HMAGATK;
                Player.General[Index_].WeaponType = 0;
            }
            else if (DatabaseCore.Item.Slot[CharacterItemSourceIndex] == 7)
            {
                Player.Stats[Index_].PhyDef -= (ushort)SourceItem.MAX_PHYSDEF;
                Player.Stats[Index_].MagDef -= (ushort)SourceItem.MAGDEF_MAX;
            }

            else if (DatabaseCore.Item.Slot[CharacterItemSourceIndex] >= 9 && DatabaseCore.Item.Slot[CharacterItemSourceIndex] <= 12)
            {
                Player.Stats[Index_].TotalAccessoriesAbsorption -= SourceItem.ABSORB_INC;
            }

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_UNEQUIP);
            writer.AppendDword(Player.General[Index_].UniqueID);
            writer.AppendByte(DatabaseCore.Item.Slot[CharacterItemSourceIndex]);
            writer.AppendDword(DatabaseCore.Item.ItemId[CharacterItemSourceIndex]);

            ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);
        }
Exemplo n.º 6
0
        private static void BanPlayer(PacketReader reader_, int Index_)
        {
            ushort charlen = reader_.ReadWord();

            string name = reader_.ReadString(false, charlen);

            bool banned = false;

            for (int i = 0; i <= Player.PlayersOnline; i++)
            {
                if (name == Player.General[i].CharacterName && Index_ != i)
                {
                    ServerSocket.DisconnectSocket(i);
                    DatabaseCore.WriteQuery("UPDATE user SET banned='1' WHERE name='{0}'", Player.General[i].User);
                    banned = true;
                }
            }

            if (!banned)
            {
                DatabaseCore.WriteQuery("UPDATE user SET banned='1' WHERE name='{0}'", name);
            }
        }
Exemplo n.º 7
0
        private static void PrepareBuff(int Index_)
        {
            PacketWriter writer = new PacketWriter();

            Player.Objects[Index_].UsingSkill = true;

            uint CastingId = (uint)random.Next(65536, 1048575);

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ATTACK);
            writer.AppendByte(1);
            writer.AppendByte(0);
            writer.AppendDword(Player.Objects[Index_].UsingSkillID);
            writer.AppendDword(Player.General[Index_].UniqueID);
            writer.AppendDword(CastingId);
            writer.AppendByte(0);
            writer.AppendDword(0);

            ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);

            Silkroad.Skill_ tmpSkill = Silkroad.GetSkillById(Player.Objects[Index_].UsingSkillID);
            Player.Objects[Index_].BuffCastingID  = CastingId;
            Timers.CastBuffTimer[Index_].Interval = tmpSkill.CastTime * 1000;
            Timers.CastBuffTimer[Index_].Start();
        }
Exemplo n.º 8
0
        public static void EquipCape(int Index_)
        {
            PacketWriter writer = new PacketWriter();

            if (!Player.Flags[Index_].WearingCape)
            {
                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_EQUIP);
                writer.AppendDword(Player.General[Index_].UniqueID);
                writer.AppendByte(DatabaseCore.Item.Slot[Player.Objects[Index_].SourceItemIndex]);
                writer.AppendDword(DatabaseCore.Item.ItemId[Player.Objects[Index_].SourceItemIndex]);
                writer.AppendByte(0);

                ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);
                Player.Flags[Index_].WearingCape = true;
            }
            else
            {
                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_UNEQUIP);
                writer.AppendDword(Player.General[Index_].UniqueID);
                writer.AppendByte(DatabaseCore.Item.Slot[Player.Objects[Index_].SourceItemIndex]);
                writer.AppendDword(DatabaseCore.Item.ItemId[Player.Objects[Index_].SourceItemIndex]);

                ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);
                Player.Flags[Index_].WearingCape = false;
            }

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
            writer.AppendWord(1);
            writer.AppendByte(DatabaseCore.Item.Slot[Player.Objects[Index_].SourceItemIndex]);
            writer.AppendByte(DatabaseCore.Item.Slot[Player.Objects[Index_].DestinationItemIndex]);
            writer.AppendWord(0);
            writer.AppendByte(0);
            ServerSocket.Send(writer.getWorkspace(), Index_);

            MoveItemToDatabase(Player.Objects[Index_].SourceItemIndex, Player.Objects[Index_].DestinationItemIndex, Player.General[Index_].CharacterName);
        }
Exemplo n.º 9
0
        private static byte UnEnquipWeapon(int Index_, int[] CharacterItemIndex, int CharacterItemSourceIndex)
        {
            Silkroad.Item_ SourceItem = Silkroad.GetItemById(DatabaseCore.Item.ItemId[CharacterItemSourceIndex]);

            if (DatabaseCore.Item.ItemId[CharacterItemSourceIndex] != 0 && SourceItem.CLASS_C != 2 && SourceItem.CLASS_C != 3)
            {
                Player.Stats[Index_].MinPhy      -= (ushort)SourceItem.MIN_LPHYATK;
                Player.Stats[Index_].MaxPhy      -= (ushort)SourceItem.MIN_HPHYATK;
                Player.Stats[Index_].MinMag      -= (ushort)SourceItem.MIN_LMAGATK;
                Player.Stats[Index_].MaxMag      -= (ushort)SourceItem.MIN_HMAGATK;
                Player.General[Index_].WeaponType = 0;

                byte freeslot = FreeSlot(CharacterItemIndex);

                PacketWriter writer = new PacketWriter();

                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_UNEQUIP);
                writer.AppendDword(Player.General[Index_].UniqueID);
                writer.AppendByte(6);
                writer.AppendDword(DatabaseCore.Item.ItemId[CharacterItemSourceIndex]);

                ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);

                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                writer.AppendByte(1);
                writer.AppendByte(0);
                writer.AppendByte(6);
                writer.AppendByte(freeslot);
                writer.AppendWord(1);
                writer.AppendByte(0);
                ServerSocket.Send(writer.getWorkspace(), Index_);

                return(freeslot);
            }
            return(255);
        }
Exemplo n.º 10
0
        public static void GetXP(int Index_, int ObjectIndex)
        {
            int xprate = 2, sprate = 2, goldrate = 2;

            Silkroad.Gold_ tmpGold = Silkroad.GetGoldDataByLevel(Monsters.General[ObjectIndex].Level);
            ulong          sp      = (ulong)random.Next(tmpGold.Skillpoints, tmpGold.Skillpoints + 25);
            ulong          exp     = Monsters.General[ObjectIndex].Exp;

            if (Player.Stats[Index_].Level < Monsters.General[ObjectIndex].Level)
            {
                exp = ((ulong)(Monsters.General[ObjectIndex].Level - Player.Stats[Index_].Level) * Monsters.General[ObjectIndex].Exp) * (ulong)xprate;
            }
            if (Player.Stats[Index_].Level > Monsters.General[ObjectIndex].Level)
            {
                exp = ((ulong)(Player.Stats[Index_].Level - Monsters.General[ObjectIndex].Level) / Monsters.General[ObjectIndex].Exp) * (ulong)xprate;
                if (exp == 0)
                {
                    exp = 1;
                }
            }
            if (Player.Stats[Index_].Level == Monsters.General[ObjectIndex].Level)
            {
                exp = (Monsters.General[ObjectIndex].Exp * (ulong)xprate);
            }

            sp *= (ulong)sprate;

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_EXP);
            writer.AppendDword(Monsters.General[ObjectIndex].UniqueID);
            writer.AppendLword(exp);
            writer.AppendLword(sp);
            writer.AppendByte(0);
            if (CheckIfNewLevel(Index_, exp))
            {
                writer.AppendWord(Player.Stats[Index_].Attributes);
                ServerSocket.Send(writer.getWorkspace(), Index_);

                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ANIMATION_LEVEL_UP);
                writer.AppendDword(Player.General[Index_].UniqueID);

                ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);

                Formula.CalculateHP(Index_);
                Formula.CalculateMP(Index_);
                STRUpdate(Index_);
                INTUpdate(Index_);
            }
            else
            {
                ServerSocket.Send(writer.getWorkspace(), Index_);
            }

            CheckIfNewSp(Index_, sp);

            HPUpdate(Index_, false);
            MPUpdate(Index_, false);
            OnStatPacket(Index_);

            DatabaseCore.WriteQuery("UPDATE characters SET experience='{0}',level = '{1}',sp = '{2}',skillpointbar = '{3}' WHERE name='{4}'", Player.Stats[Index_].Experience, Player.Stats[Index_].Level, Player.Stats[Index_].Skillpoints, Player.Stats[Index_].SkillpointBar, Player.General[Index_].CharacterName);
            uint goldamount = (uint)(tmpGold.Gold * goldrate);

            int ItemIndex = Item.ItemAmount;

            if (goldamount < 10000)
            {
                Item.General[ItemIndex].Pk2ID = 1;
            }
            else if (goldamount >= 10000 && goldamount <= 500000)
            {
                Item.General[ItemIndex].Pk2ID = 2;
            }
            else if (goldamount >= 500001)
            {
                Item.General[ItemIndex].Pk2ID = 3;
            }

            Item.General[ItemIndex].UniqueID   = (uint)random.Next(76000000, 79999999);
            Item.General[ItemIndex].Plus       = 0;
            Item.General[ItemIndex].Durability = 0;
            Item.General[ItemIndex].Pickable   = true;
            Item.General[ItemIndex].Quantity   = goldamount;
            Item.Position[ItemIndex].XSector   = Monsters.Position[ObjectIndex].XSector;
            Item.Position[ItemIndex].YSector   = Monsters.Position[ObjectIndex].YSector;
            byte randomplace = (byte)random.Next(1, 7);

            Item.Position[ItemIndex].X = Monsters.Position[ObjectIndex].X + randomplace;
            Item.Position[ItemIndex].Z = Monsters.Position[ObjectIndex].Z;
            Item.Position[ItemIndex].Y = Monsters.Position[ObjectIndex].Y + randomplace;
            Item.General[ItemIndex].DroppedByUniqueId = Monsters.General[ObjectIndex].UniqueID;
            Item.ItemAmount++;

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_SPAWN);
            if (goldamount < 10000)
            {
                writer.AppendDword(1);
            }
            else if (goldamount >= 10000 && goldamount <= 500000)
            {
                writer.AppendDword(2);
            }
            else if (goldamount >= 500001)
            {
                writer.AppendDword(3);
            }
            writer.AppendDword(goldamount);
            writer.AppendDword(Item.General[ItemIndex].UniqueID);
            writer.AppendByte(Item.Position[ItemIndex].XSector);
            writer.AppendByte(Item.Position[ItemIndex].YSector);
            writer.AppendFloat(Item.Position[ItemIndex].X);
            writer.AppendFloat(Item.Position[ItemIndex].X);
            writer.AppendFloat(Item.Position[ItemIndex].Y);
            writer.AppendWord(0xDC72);
            writer.AppendByte(0);
            writer.AppendByte(0);
            writer.AppendByte(5);
            writer.AppendDword(0);
            byte[] tmpBuffer = writer.getWorkspace();

            for (int i = 0; i < Player.PlayersOnline; i++)
            {
                if (Player.General[i].CharacterID != 0)
                {
                    if (Formula.CalculateDistance(Item.Position[ItemIndex], Player.Position[i]) <= 800)
                    {
                        ServerSocket.Send(tmpBuffer, i);
                        Player.Objects[i].SpawnedItemsIndex.Add(ItemIndex);
                    }
                }
            }
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            Console.WriteLine("-------------------------------------------------------");
            Console.WriteLine(" <Silkroad Gameserver>  Copyright (C) <2011>  <DarkEmu>");
            Console.WriteLine("-------------------------------------------------------");
            Console.WriteLine("Loading essentiel data and connecting to database.\nThis could take some minutes!");
            Database.Connect(Settings.ReadSettings("Settings.txt"));

            Database.CheckTables(new string[] { "mastery", "user", "characters", "skills", "items" });

            DatabaseCore.SetPulseTime(5000);
            DatabaseCore.SetPulseFlag(false);
            DatabaseCore.SetQueryLocation("tmpQueryGameServer.txt");
            DatabaseCore.Start();

            Console.WriteLine("Data from database loaded, Changes on the database wont effect the server now!");

            Timers.LoadTimers();
            Silkroad.DumpObjects();

            ServerSocket server = new ServerSocket("127.0.0.1", 15780);
            server.Start();

            Console.WriteLine("Use 'help' to get all commands.");
            while (exit == false)
                Commands(Console.ReadLine());
        }
Exemplo n.º 12
0
        private static void PickUpItem(int Index_, int ObjectIndex)
        {
            int[] CharacterItemIndex = DatabaseCore.Item.GetIndexByName(Player.General[Index_].CharacterName);

            PacketWriter writer = new PacketWriter();

            for (int i = 0; i < Player.PlayersOnline; i++)
            {
                if (Player.General[i].UniqueID != 0)
                {
                    double Distance = Formula.CalculateDistance(Item.Position[ObjectIndex], Player.Position[i]);
                    if (Distance <= 800)
                    {
                        if (Player.Objects[i].SpawnedItemsIndex.Contains(ObjectIndex))
                        {
                            ServerSocket.Send(Players.CreateDeSpawnPacket(Item.General[ObjectIndex].UniqueID), i);
                            Player.Objects[i].SpawnedItemsIndex.Remove(ObjectIndex);
                        }
                    }
                }
            }

            Silkroad.Item_ tmpItem = Silkroad.GetItemById(Item.General[ObjectIndex].Pk2ID);

            byte freeslot = 0;

            if (Item.General[ObjectIndex].Pk2ID == 1 || Item.General[ObjectIndex].Pk2ID == 2 || Item.General[ObjectIndex].Pk2ID == 3)
            {
                freeslot = 254;
            }
            else
            {
                freeslot = Items.FreeSlot(CharacterItemIndex);
            }

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
            writer.AppendWord(0x601);
            writer.AppendByte(freeslot);
            if (freeslot != 254)
            {
                writer.AppendDword(Item.General[ObjectIndex].Pk2ID);
            }
            if (tmpItem.ITEM_TYPE_NAME.Contains("CH") || tmpItem.ITEM_TYPE_NAME.Contains("EU"))
            {
                writer.AppendByte(Item.General[ObjectIndex].Plus);
                writer.AppendLword(0);
                writer.AppendDword((uint)tmpItem.MIN_DURA);
                writer.AppendByte(0);

                DatabaseCore.WriteQuery("UPDATE items SET itemid='{0}',plusvalue='{1}',type='0',durability='{2}' WHERE itemnumber='item{3}' AND owner ='{4}'", Item.General[ObjectIndex].Pk2ID, Item.General[ObjectIndex].Plus, Item.General[ObjectIndex].Durability, freeslot, Player.General[Index_].CharacterName);
                Items.AddItemToDatabase(CharacterItemIndex[freeslot], Item.General[ObjectIndex].Pk2ID, 0, 0, (byte)Item.General[ObjectIndex].Durability, Item.General[ObjectIndex].Plus, 0);
            }
            else if (tmpItem.ITEM_TYPE_NAME.Contains("ETC"))
            {
                if (freeslot == 254)
                {
                    writer.AppendDword(Item.General[ObjectIndex].Quantity);
                    Player.Stats[Index_].Gold += Item.General[ObjectIndex].Quantity;
                    DatabaseCore.WriteQuery("UPDATE characters SET gold='{0}' WHERE name='{1}'", Player.Stats[Index_].Gold, Player.General[Index_].CharacterName);
                }
                else
                {
                    writer.AppendWord((ushort)Item.General[ObjectIndex].Quantity);
                    DatabaseCore.WriteQuery("UPDATE items SET itemid='{0}',plusvalue='0',type='1',durability='{1}',quantity='{2}' WHERE itemnumber='item{3}' AND owner ='{4}'", Item.General[ObjectIndex].Pk2ID, Item.General[ObjectIndex].Durability, Item.General[ObjectIndex].Quantity, freeslot, Player.General[Index_].CharacterName);
                    Items.AddItemToDatabase(CharacterItemIndex[freeslot], Item.General[ObjectIndex].Pk2ID, 1, (byte)Item.General[ObjectIndex].Quantity, (byte)Item.General[ObjectIndex].Durability, 0, 0);
                }
            }

            ServerSocket.Send(writer.getWorkspace(), Index_);

            Item.General[ObjectIndex]  = new Item._General();
            Item.Position[ObjectIndex] = new _Position();

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_NEW_GOLD_AMOUNT);
            writer.AppendByte(1);
            writer.AppendLword(Player.Stats[Index_].Gold);
            writer.AppendByte(0);
            ServerSocket.Send(writer.getWorkspace(), Index_);

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ANIMATION_ITEM_PICKUP);
            writer.AppendDword(Player.General[Index_].UniqueID);
            writer.AppendByte(141);
            ServerSocket.Send(writer.getWorkspace(), Index_);

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_SKILL_ATTACK);
            writer.AppendByte(2);
            writer.AppendByte(0);
            ServerSocket.Send(writer.getWorkspace(), Index_);
        }
Exemplo n.º 13
0
        private static void SkillAttackType(int Index_)
        {
            PacketWriter writer = new PacketWriter();

            Silkroad.Skill_ tmpSkill = Silkroad.GetSkillById(Player.Objects[Index_].AttackingSkillID);

            byte weapontype = 0;

            if (Player.General[Index_].WeaponType == 6)
            {
                weapontype = Silkroad.TypeTable.Bow;
            }
            if ((Player.General[Index_].WeaponType == 2) || (Player.General[Index_].WeaponType == 3))
            {
                weapontype = Silkroad.TypeTable.Bicheon;
            }
            if ((Player.General[Index_].WeaponType == 4) || (Player.General[Index_].WeaponType == 5))
            {
                weapontype = Silkroad.TypeTable.Heuksal;
            }

            byte skilltype = tmpSkill.Type2;

            if (!(weapontype == skilltype) && !(skilltype == Silkroad.TypeTable.All))
            {
                Player.Objects[Index_].UsingSkill = false;
                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ATTACK);
                writer.AppendWord(0xD02);
                ServerSocket.Send(writer.getWorkspace(), Index_);

                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_SKILL_ATTACK);
                writer.AppendWord(3);
                writer.AppendByte(4);
                ServerSocket.Send(writer.getWorkspace(), Index_);
            }
            else
            {
                int ObjectIndex = Players.GetObjectIndexAndType(Index_, Player.Objects[Index_].AttackingObjectId);
                if (Player.Objects[Index_].SelectedObjectType == 2)
                {
                    Timers.MonsterMovement[ObjectIndex].Stop();
                }

                bool attack = false;

                if (Player.Objects[Index_].SelectedObjectType == 2)
                {
                    attack = Movement.MoveToObject(Index_, ref Player.Position[Index_], Monsters.Position[ObjectIndex], Player.General[Index_].UniqueID, Player.General[Index_].CharacterID, tmpSkill.Distance * 10, weapontype, false);
                }

                else
                {
                    attack = Movement.MoveToObject(Index_, ref Player.Position[Index_], Player.Position[ObjectIndex], Player.General[Index_].UniqueID, Player.General[Index_].CharacterID, tmpSkill.Distance * 10, weapontype, false);
                }

                if (attack)
                {
                    Attack.BeginSkill(Index_);
                }
            }
        }
Exemplo n.º 14
0
        public static void OnMonsterAttack(int Index_)
        {
            uint SkillId = 161;

            if (Monsters.General[Index_].Skills.Count != 0)
            {
                int rnd = random.Next(0, Monsters.General[Index_].Skills.Count);
                SkillId = (uint)Monsters.General[Index_].Skills[rnd];
            }

            if (Player.General[Monsters.General[Index_].AttackingObjectIndex].UniqueID != 0)
            {
                /*   Silkroad.Skill_ tmpAttackSkill = Silkroad.GetSkillById(SkillId);
                 * Silkroad.Object_ tmpMonster = Silkroad.GetObjectById(Monsters.General[Index_].ID);
                 *
                 * uint BasicAttackPower = (uint)(tmpMonster.ParryRatio * 10);//parry ratio == att ratio?
                 *
                 * double SkillAttackPower = 1;
                 * double SkillIncreaseRate = 0;
                 *
                 * double EnemyAbsorbation = Player.Stats[Monsters.General[Index_].AttackingObjectIndex].TotalAccessoriesAbsorption / (double)100;
                 * double EnemyDefence =( Player.Stats[Monsters.General[Index_].AttackingObjectIndex].PhyDef + Player.Stats[Monsters.General[Index_].AttackingObjectIndex].MagDef) / 2;
                 * double TotalDamageIncreaseRate = 0;
                 *
                 * double Damage = Formula.CalculateDmg(
                 *     BasicAttackPower,
                 *     SkillAttackPower,
                 *     SkillIncreaseRate,
                 *     EnemyAbsorbation,
                 *     EnemyDefence,
                 *     tmpMonster.Level,
                 *     0,
                 *    0,
                 *     TotalDamageIncreaseRate,
                 *     tmpAttackSkill.PwrPercent / (double)100);
                 *
                 * Console.WriteLine(Damage);*/
                double Damage = (double)random.Next(1, 100);

                if (Monsters.General[Index_].Type == 3 || Monsters.General[Index_].Type == 0x10 || Monsters.General[Index_].Type == 20)
                {
                    Damage *= 2;
                }

                Player.Stats[Monsters.General[Index_].AttackingObjectIndex].CHP -= (int)Damage;
                byte AfterState = 0;

                if (Player.Stats[Monsters.General[Index_].AttackingObjectIndex].CHP <= 0)
                {
                    AfterState = 0x80;
                    Player.Stats[Monsters.General[Index_].AttackingObjectIndex].CHP = 0;
                }
                Stats.HPUpdate(Monsters.General[Index_].AttackingObjectIndex, true);

                PacketWriter writer = new PacketWriter();
                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ATTACK);
                writer.AppendByte(1);
                writer.AppendByte(2);
                writer.AppendDword(SkillId);
                writer.AppendDword(Monsters.General[Index_].UniqueID);
                writer.AppendDword((uint)random.Next(65536, 1048575));
                writer.AppendDword(Player.General[Monsters.General[Index_].AttackingObjectIndex].UniqueID);
                writer.AppendByte(1);
                writer.AppendByte(1);
                writer.AppendByte(1);
                writer.AppendDword(Player.General[Monsters.General[Index_].AttackingObjectIndex].UniqueID);
                writer.AppendByte(AfterState);
                writer.AppendByte(1);
                writer.AppendDword((uint)Damage);
                writer.AppendByte(0);
                writer.AppendWord(0);

                ServerSocket.SendPacketIfMonsterIsSpawned(writer.getWorkspace(), Index_);

                if (AfterState == 0x80)
                {
                    Timers.MonsterAttack[Index_].Stop();
                    Player.General[Index_].State = 1;
                    Character.Die(Monsters.General[Index_].AttackingObjectIndex);
                    Character.Die2(Monsters.General[Index_].AttackingObjectIndex);
                    Player.Flags[Monsters.General[Index_].AttackingObjectIndex].Dead = true;
                }
            }
        }
Exemplo n.º 15
0
        unsafe public static void OnMovement(byte *ptr, int Index_)
        {
            Silkroad.C_S.MOVEMENT_GROUND *tmpPtr = (Silkroad.C_S.MOVEMENT_GROUND *)ptr;

            if (tmpPtr->Type == 0)
            {
                Silkroad.C_S.MOVEMENT_SKY *MovingSky = (Silkroad.C_S.MOVEMENT_SKY *)ptr;
                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_MOVEMENT);
                writer.AppendDword(Player.General[Index_].UniqueID);
                writer.AppendByte(MovingSky->Type);
                writer.AppendByte(MovingSky->Flag);
                writer.AppendWord((ushort)((MovingSky->Angle * 360) / 65536));
                writer.AppendByte(1);
                writer.AppendByte(Player.Position[Index_].XSector);
                writer.AppendByte(Player.Position[Index_].YSector);
                writer.AppendWord((ushort)Player.Position[Index_].X);
                writer.AppendFloat(Player.Position[Index_].Z);
                writer.AppendWord((ushort)Player.Position[Index_].Y);
            }
            else if (tmpPtr->Type == 1)
            {
                if (Player.General[Index_].State != 4 || Player.General[Index_].State != 10 || Player.General[Index_].State != 1)
                {
                    Player.Objects[Index_].AttackingSkillID = 0;
                    Player.Objects[Index_].NormalAttack     = false;
                    Player.Objects[Index_].UsingSkill       = false;
                    Player.General[Index_].Busy             = false;
                    Timers.PlayerAttack[Index_].Stop();

                    Player.Position[Index_].XSector = tmpPtr->XSector;
                    Player.Position[Index_].YSector = tmpPtr->YSector;
                    Player.Position[Index_].X       = tmpPtr->X;
                    Player.Position[Index_].Z       = tmpPtr->Z;
                    Player.Position[Index_].Y       = tmpPtr->Y;

                    writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_MOVEMENT);
                    writer.AppendDword(Player.General[Index_].UniqueID);
                    writer.AppendByte(tmpPtr->Type);
                    writer.AppendByte(Player.Position[Index_].XSector);
                    writer.AppendByte(Player.Position[Index_].YSector);
                    writer.AppendWord((ushort)Player.Position[Index_].X);
                    writer.AppendWord((ushort)Player.Position[Index_].Z);
                    writer.AppendWord((ushort)Player.Position[Index_].Y);
                    writer.AppendByte(0);

                    byte[] tmpBuffer = writer.getWorkspace();

                    for (int i = 0; i < Player.PlayersOnline; i++)
                    {
                        if (Player.General[i].CharacterID != 0)
                        {
                            if (i == Index_)
                            {
                                ServerSocket.Send(tmpBuffer, i);
                            }
                            else
                            {
                                if (Formula.CalculateDistance(Player.Position[Index_], Player.Position[i]) <= 800 && Player.Objects[i].SpawnedIndex.Contains(Index_))
                                {
                                    ServerSocket.Send(tmpBuffer, i);
                                }
                            }
                        }
                    }

                    DatabaseCore.WriteQuery("UPDATE characters SET xsect='{0}', ysect='{1}', xpos='{2}', zpos='{3}', ypos='{4}' where id='{5}'", Player.Position[Index_].XSector, Player.Position[Index_].YSector, Player.Position[Index_].X, Player.Position[Index_].Z, Player.Position[Index_].Y, Player.General[Index_].CharacterID);

                    for (int i = 0; i < Player.PlayersOnline; i++)
                    {
                        if (Player.General[i].CharacterID != 0 && Index_ != i)
                        {
                            double Distance = Formula.CalculateDistance(Player.Position[Index_], Player.Position[i]);
                            if (Distance <= 800)
                            {
                                if (!Player.Objects[Index_].SpawnedIndex.Contains(i))
                                {
                                    ServerSocket.Send(Character.CreateSpawnPacket(Player.General[i], Player.Flags[i], Player.Position[i], Player.Stats[i], Player.Speeds[i]), Index_);
                                    Player.Objects[Index_].SpawnedIndex.Add(i);

                                    ServerSocket.Send(Character.CreateSpawnPacket(Player.General[Index_], Player.Flags[Index_], Player.Position[Index_], Player.Stats[Index_], Player.Speeds[Index_]), i);
                                    Player.Objects[i].SpawnedIndex.Add(Index_);
                                }
                            }
                            else if (Distance > 800)
                            {
                                if (Player.Objects[Index_].SpawnedIndex.Contains(i))
                                {
                                    ServerSocket.Send(Players.CreateDeSpawnPacket(Player.General[i].UniqueID), Index_);
                                    Player.Objects[Index_].SpawnedIndex.Remove(i);

                                    ServerSocket.Send(Players.CreateDeSpawnPacket(Player.General[Index_].UniqueID), i);
                                    Player.Objects[i].SpawnedIndex.Remove(Index_);
                                }
                            }
                        }
                    }

                    for (int i = 0; i < Monsters.MonsterAmount; i++)
                    {
                        if (Monsters.General[i].UniqueID != 0 && !Monsters.General[i].Dead)
                        {
                            double Distance = Formula.CalculateDistance(Player.Position[Index_], Monsters.Position[i]);
                            if (Distance <= 800)
                            {
                                if (!Player.Objects[Index_].SpawnedMonsterIndex.Contains(i))
                                {
                                    ServerSocket.Send(MonsterSpawn.CreateSpawnPacket(Monsters.General[i].ID, Monsters.General[i].UniqueID, Monsters.Position[i], Monsters.General[i].Type), Index_);
                                    Player.Objects[Index_].SpawnedMonsterIndex.Add(i);
                                }
                            }
                            else if (Distance > 800)
                            {
                                if (Player.Objects[Index_].SpawnedMonsterIndex.Contains(i))
                                {
                                    ServerSocket.Send(Players.CreateDeSpawnPacket(Monsters.General[i].UniqueID), Index_);
                                    Player.Objects[Index_].SpawnedMonsterIndex.Remove(i);
                                }
                            }
                        }
                    }

                    for (int i = 0; i < Item.ItemAmount; i++)
                    {
                        if (Item.General[i].UniqueID != 0)
                        {
                            double Distance = Formula.CalculateDistance(Player.Position[Index_], Item.Position[i]);
                            if (Distance <= 800)
                            {
                                if (!Player.Objects[Index_].SpawnedItemsIndex.Contains(i))
                                {
                                    ServerSocket.Send(Items.CreateSpawnPacket(Item.General[i], Item.Position[i]), Index_);
                                    Player.Objects[Index_].SpawnedItemsIndex.Add(i);
                                }
                            }
                            else if (Distance > 800)
                            {
                                if (Player.Objects[Index_].SpawnedItemsIndex.Contains(i))
                                {
                                    ServerSocket.Send(Players.CreateDeSpawnPacket(Item.General[i].UniqueID), Index_);
                                    Player.Objects[Index_].SpawnedItemsIndex.Remove(i);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 16
0
        public static void OnSpawn(PacketReader reader_, int Index_)
        {
            int  MonsterIndex = Monsters.MonsterAmount;
            uint monsterid    = reader_.ReadDword();
            byte monstertype  = reader_.ReadByte();


            uint uniqueid = (uint)Monsters.MonsterAmount + 1000;

            if (monstertype == 1)
            {
                monstertype = 0;
            }

            Silkroad.Object_ tmpMonster = Silkroad.GetObjectById(monsterid);

            PacketWriter writer = new PacketWriter();

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_SPAWN);

            writer.AppendDword(monsterid);
            writer.AppendDword(uniqueid);

            writer.AppendByte(Player.Position[Index_].XSector);
            writer.AppendByte(Player.Position[Index_].YSector);
            writer.AppendFloat(Player.Position[Index_].X);
            writer.AppendFloat(Player.Position[Index_].Z);
            writer.AppendFloat(Player.Position[Index_].Y);

            writer.AppendWord(0);
            writer.AppendByte(0);
            writer.AppendByte(1);
            writer.AppendByte(0);
            writer.AppendWord(0);
            writer.AppendWord(1);
            writer.AppendByte(0);

            writer.AppendFloat(tmpMonster.Speed);
            writer.AppendFloat(tmpMonster.Speed);
            writer.AppendFloat(tmpMonster.Speed);

            writer.AppendByte(0);
            writer.AppendByte(0);

            writer.AppendByte(monstertype);
            writer.AppendByte(1);
            byte[] tmpBuffer = writer.getWorkspace();
            //   ServerSocket.SendPacketInRange(writer.getWorkspace(),Index_);


            int   monsterhp = (int)tmpMonster.Hp;
            ulong exp       = tmpMonster.Exp;

            switch (monstertype)
            {
            case 2:
                monsterhp *= 2;
                exp       *= 2;
                break;

            case 3:
                exp *= 7;
                break;

            case 4:
                monsterhp *= 20;
                exp       *= 3;
                break;

            case 6:
                monsterhp *= 4;
                exp       *= 4;
                break;

            case 16:
                monsterhp *= 10;
                exp       *= 5;
                break;

            case 17:
                monsterhp *= 20;
                exp       *= 6;

                break;

            case 20:
                monsterhp *= 200;
                exp       *= 8;
                break;
            }

            Monsters.General[MonsterIndex].ID       = monsterid;
            Monsters.General[MonsterIndex].UniqueID = uniqueid;
            Monsters.General[MonsterIndex].Type     = monstertype;
            Monsters.General[MonsterIndex].HP       = monsterhp;
            Monsters.Position[MonsterIndex].XSector = Player.Position[Index_].XSector;
            Monsters.Position[MonsterIndex].YSector = Player.Position[Index_].YSector;
            Monsters.Position[MonsterIndex].X       = Player.Position[Index_].X;
            Monsters.Position[MonsterIndex].Z       = Player.Position[Index_].Z;
            Monsters.Position[MonsterIndex].Y       = Player.Position[Index_].Y;
            Monsters.General[MonsterIndex].Exp      = exp;
            Monsters.General[MonsterIndex].Level    = tmpMonster.Level;
            Monsters.General[MonsterIndex].Skills   = new ArrayList();
            Monsters.General[MonsterIndex].Dead     = false;

            for (int i = 0; i < Player.PlayersOnline; i++)
            {
                if (Player.General[i].CharacterID != 0)
                {
                    if (Formula.CalculateDistance(Monsters.Position[MonsterIndex], Player.Position[i]) <= 800)
                    {
                        ServerSocket.Send(tmpBuffer, i);
                        Player.Objects[i].SpawnedMonsterIndex.Add(MonsterIndex);
                    }
                }
            }


            uint[] skill = new uint[9];
            skill[0] = tmpMonster.Skill1;
            skill[1] = tmpMonster.Skill2;
            skill[2] = tmpMonster.Skill3;
            skill[3] = tmpMonster.Skill4;
            skill[4] = tmpMonster.Skill5;
            skill[5] = tmpMonster.Skill6;
            skill[6] = tmpMonster.Skill7;
            skill[7] = tmpMonster.Skill8;
            skill[8] = tmpMonster.Skill9;

            for (int i = 0; i <= 8; i++)
            {
                if (skill[i] != 0 && skill[i] <= 3000)
                {
                    Monsters.General[MonsterIndex].Skills.Add(skill[i]);
                }
            }

            Monsters.MonsterAmount++;

            if (monstertype == 3)
            {
                Unique.OnUnique(monsterid, false, null);
            }


            Timers.MonsterMovement[MonsterIndex].Interval = 5000;
            Timers.MonsterMovement[MonsterIndex].Start();
        }
Exemplo n.º 17
0
        public static void OnUseItem(PacketReader reader, int Index_)
        {
            int[] CharacterItemIndex = DatabaseCore.Item.GetIndexByName(Player.General[Index_].CharacterName);
            byte  slot = reader.ReadByte();

            Silkroad.Item_ item = Silkroad.GetItemById(DatabaseCore.Item.ItemId[CharacterItemIndex[slot]]);

            if (DatabaseCore.Item.ItemId[CharacterItemIndex[slot]] >= 4 && DatabaseCore.Item.ItemId[CharacterItemIndex[slot]] <= 23)
            {
                if ((DatabaseCore.Item.Quantity[CharacterItemIndex[slot]] - 1) > 0)
                {
                    DatabaseCore.Item.Quantity[CharacterItemIndex[slot]]--;
                }
                else
                {
                    DeleteFromDatabase(CharacterItemIndex[slot]);
                    DatabaseCore.WriteQuery("DELETE FROM items WHERE itemnumber='item{0}' AND owner='{1}'", slot, Player.General[Index_].CharacterName);
                }

                PacketWriter writer = new PacketWriter();
                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_USE);
                writer.AppendByte(1);
                writer.AppendByte(slot);
                writer.AppendWord(DatabaseCore.Item.Quantity[CharacterItemIndex[slot]]);
                writer.AppendWord(reader.ReadWord());
                ServerSocket.Send(writer.getWorkspace(), Index_);

                writer = new PacketWriter();
                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ANIMATION_POTION);
                writer.AppendDword(Player.General[Index_].UniqueID);
                if (item.ITEM_TYPE_NAME.Contains("HP") && !item.ITEM_TYPE_NAME.Contains("SPOTION"))
                {
                    writer.AppendDword(0x04);
                    ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);

                    Player.Stats[Index_].CHP += item.USE_TIME;
                    Stats.HPUpdate(Index_, false);
                }
                else if (item.ITEM_TYPE_NAME.Contains("HP") && item.ITEM_TYPE_NAME.Contains("SPOTION"))
                {
                    writer.AppendDword(0x04);
                    ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);

                    Player.Stats[Index_].CHP += ((int)Player.Stats[Index_].HP * item.USE_TIME2 / 100);
                    Stats.HPUpdate(Index_, false);
                }
                else if (item.ITEM_TYPE_NAME.Contains("MP") && !item.ITEM_TYPE_NAME.Contains("SPOTION"))
                {
                    writer.AppendDword(0x0E);
                    ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);

                    Player.Stats[Index_].CMP += item.USE_TIME3;
                    Stats.MPUpdate(Index_, false);
                }
                else if (item.ITEM_TYPE_NAME.Contains("MP") && item.ITEM_TYPE_NAME.Contains("SPOTION"))
                {
                    writer.AppendDword(0x0E);
                    ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);

                    Player.Stats[Index_].CMP += ((int)Player.Stats[Index_].MP * item.USE_TIME4 / 100);
                    Stats.MPUpdate(Index_, false);
                }
                else if (item.ITEM_TYPE_NAME.Contains("ALL") && !item.ITEM_TYPE_NAME.Contains("SPOTION"))
                {
                    writer.AppendDword(0x17);
                    ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);

                    Player.Stats[Index_].CHP += item.USE_TIME;
                    Player.Stats[Index_].CMP += item.USE_TIME3;
                    Stats.HPMPUpdate(Index_);
                }
                else if (item.ITEM_TYPE_NAME.Contains("ALL") && item.ITEM_TYPE_NAME.Contains("SPOTION"))
                {
                    writer.AppendDword(0x17);
                    ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);

                    Player.Stats[Index_].CHP += ((int)Player.Stats[Index_].HP * item.USE_TIME2 / 100);
                    Player.Stats[Index_].CMP += ((int)Player.Stats[Index_].MP * item.USE_TIME4 / 100);
                    Stats.HPMPUpdate(Index_);
                }
            }
        }
Exemplo n.º 18
0
        public static void NormalAttack(int Index_)
        {
            uint SkillId      = 0;
            byte AttackAmount = GetAmountAndSkillIdByWeaponType(Index_, ref SkillId);

            bool AttackingPlayer = false;

            for (int i = 0; i <= Player.PlayersOnline; i++)
            {
                if (Player.Objects[Index_].AttackingObjectId == Player.General[i].UniqueID)
                {
                    AttackingPlayer = true;
                }
            }

            int ObjectIndex = Players.GetObjectIndexAndType(Index_, Player.Objects[Index_].AttackingObjectId);

            Silkroad.Skill_ tmpAttackSkill = Silkroad.GetSkillById(SkillId);

            uint BasicAttackPower = 0;

            if (tmpAttackSkill.Type == Silkroad.TypeTable.Phy)
            {
                BasicAttackPower = (uint)random.Next(Player.Stats[Index_].MinPhy, Player.Stats[Index_].MaxPhy);
            }
            else if (tmpAttackSkill.Type == Silkroad.TypeTable.Mag)
            {
                BasicAttackPower = (uint)random.Next(Player.Stats[Index_].MinMag, Player.Stats[Index_].MaxMag);
            }

            double SkillAttackPower  = 1; //cause its normal attack
            double SkillIncreaseRate = 0; // needs to be calculated from passive skills/active buffs

            double EnemyAbsorbation = 0;

            if (AttackingPlayer)
            {
                EnemyAbsorbation = Player.Stats[ObjectIndex].TotalAccessoriesAbsorption / (double)100;
            }

            double EnemyDefence = 0;

            if (AttackingPlayer)
            {
                if (tmpAttackSkill.Type == Silkroad.TypeTable.Phy)
                {
                    EnemyDefence = Player.Stats[ObjectIndex].PhyDef;
                }
                else if (tmpAttackSkill.Type == Silkroad.TypeTable.Mag)
                {
                    EnemyDefence = Player.Stats[ObjectIndex].MagDef;
                }
            }
            else
            {
                if (tmpAttackSkill.Type == Silkroad.TypeTable.Phy)
                {
                    EnemyDefence = Silkroad.GetObjectById(Monsters.General[ObjectIndex].ID).PhyDef;
                }
                else if (tmpAttackSkill.Type == Silkroad.TypeTable.Mag)
                {
                    EnemyDefence = Silkroad.GetObjectById(Monsters.General[ObjectIndex].ID).MagDef;
                }
            }

            double TotalDamageIncreaseRate = 0;//needs to be calculated from the players equipment

            double Damage = Formula.CalculateDmg(
                BasicAttackPower,
                SkillAttackPower,
                SkillIncreaseRate,
                EnemyAbsorbation,
                EnemyDefence,
                Player.Stats[Index_].Level,
                Player.Stats[Index_].Strength,
                Player.Stats[Index_].Intelligence,
                TotalDamageIncreaseRate,
                tmpAttackSkill.PwrPercent / (double)100);

            byte Critical = 0;

            Player.Objects[Index_].NormalAttack = true;

            if (Player.Objects[Index_].SelectedObjectType == 2)
            {
                Timers.MonsterMovement[ObjectIndex].Stop();
            }

            PacketWriter writer = new PacketWriter();

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ATTACK);
            writer.AppendByte(1);
            writer.AppendByte(2);
            writer.AppendDword(SkillId);
            writer.AppendDword(Player.General[Index_].UniqueID);
            writer.AppendDword((uint)(random.Next(1000, 10000) + Player.General[Index_].UniqueID));
            writer.AppendDword(Player.Objects[Index_].AttackingObjectId);
            writer.AppendByte(1);
            writer.AppendByte(AttackAmount);
            writer.AppendByte(1);
            writer.AppendDword(Player.Objects[Index_].AttackingObjectId);

            byte afterstate = 0;

            for (int i = 1; i <= AttackAmount; i++)
            {
                if (tmpAttackSkill.Type == Silkroad.TypeTable.Phy)
                {
                    if (random.Next(1, 10) >= 7)
                    {
                        Damage  *= 2;
                        Critical = 2;
                    }
                }
                if (Player.Objects[Index_].SelectedObjectType == 2)
                {
                    Monsters.General[ObjectIndex].HP -= (int)Damage;
                    if (Monsters.General[ObjectIndex].HP < 0)
                    {
                        afterstate = 0x80;
                        Monsters.General[ObjectIndex].HP = 0;
                    }
                }
                else if (Player.Objects[Index_].SelectedObjectType == 1)
                {
                    int tmpHp = (int)(Player.Stats[ObjectIndex].CHP - Damage);
                    if (tmpHp < 0)
                    {
                        afterstate = 0x80;
                        Player.Stats[ObjectIndex].CHP = 0;
                    }
                    else
                    {
                        Player.Stats[ObjectIndex].CHP -= (int)Damage;
                    }
                }

                writer.AppendByte(afterstate);
                writer.AppendByte(Critical);
                writer.AppendDword((uint)Damage);
                writer.AppendByte(0);
                writer.AppendWord(0);
            }

            ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);

            Player.General[Index_].Busy          = true;
            Player.Objects[Index_].NormalAttack  = true;
            Timers.PlayerAttack[Index_].Interval = 1350.0;
            Timers.PlayerAttack[Index_].Start();


            if (afterstate == 0x80)
            {
                Player.Objects[Index_].AttackingObjectDeadID = Player.Objects[Index_].AttackingObjectId;

                Player.General[Index_].Busy = false;
                Timers.PlayerAttack[Index_].Stop();
                Player.Objects[Index_].NormalAttack = false;
                if (Player.Objects[Index_].SelectedObjectType == 1)
                {
                    Player.General[ObjectIndex].State        = 10;
                    Player.Objects[ObjectIndex].NormalAttack = false;
                    Player.General[ObjectIndex].Busy         = false;
                    Timers.PlayerAttack[ObjectIndex].Stop();

                    Character.Die(ObjectIndex);
                    Character.Die2(ObjectIndex);
                    Player.Flags[ObjectIndex].Dead = true;
                }
                if (Player.Objects[Index_].SelectedObjectType == 2)
                {
                    Stats.GetBerserk(Index_, ObjectIndex);
                    Stats.GetXP(Index_, ObjectIndex);

                    if (Monsters.General[ObjectIndex].Type == 3)
                    {
                        Unique.OnUnique((uint)Monsters.General[ObjectIndex].ID, true, Player.General[Index_].CharacterName);
                    }

                    Monsters.General[ObjectIndex].Dead = true;

                    Timers.MonsterAttack[ObjectIndex].Stop();
                    Timers.MonsterDeath[Index_].Interval = 3000.0;
                    Timers.MonsterDeath[Index_].Start();
                }
            }
            else
            {
                if (Player.Objects[Index_].SelectedObjectType == 2)
                {
                    if (!Timers.MonsterAttack[ObjectIndex].Enabled)
                    {
                        Monsters.General[ObjectIndex].AttackingObjectIndex = Index_;
                        Timers.MonsterAttack[ObjectIndex].Interval         = 2350;
                        Timers.MonsterAttack[ObjectIndex].Start();
                    }
                }
            }
        }
Exemplo n.º 19
0
        unsafe public static void MoveItem(byte *ptr, int Index_)
        {
            Silkroad.C_S.MOVE_ITEM *tmpPtr = (Silkroad.C_S.MOVE_ITEM *)ptr;

            PacketWriter writer = new PacketWriter();

            switch (tmpPtr->Type)
            {
            case 0:

                int[]          CharacterItemIndex = DatabaseCore.Item.GetIndexByName(Player.General[Index_].CharacterName);
                Silkroad.Item_ SourceItem_        = Silkroad.GetItemById(DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Source]]);
                Silkroad.Item_ DestinationItem_   = Silkroad.GetItemById(DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Destination]]);

                if (SourceItem_.ITEM_TYPE_NAME.Contains("FRPVP_VOUCHER"))
                {
                    if (Player.Stats[Index_].Level >= 10 && CheckItemGender(SourceItem_, Index_))
                    {
                        writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ANIMATION_CAPE);
                        writer.AppendDword(Player.General[Index_].UniqueID);
                        writer.AppendWord(0x102);
                        writer.AppendByte(0xA);

                        ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);
                        Timers.UsingItemTimer[Index_].Interval      = 10000;
                        Player.Objects[Index_].SourceItemIndex      = CharacterItemIndex[tmpPtr->Source];
                        Player.Objects[Index_].DestinationItemIndex = CharacterItemIndex[tmpPtr->Destination];
                        Timers.UsingItemTimer[Index_].Start();
                    }
                    else
                    {
                        writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                        writer.AppendWord(0x1002);
                        ServerSocket.Send(writer.getWorkspace(), Index_);
                    }
                }
                else
                {
                    if (tmpPtr->Destination < 13)
                    {
                        if (!SourceItem_.ITEM_TYPE_NAME.Contains("ETC"))
                        {
                            if (!CheckItemGender(SourceItem_, Index_))
                            {
                                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                                writer.AppendWord(0x1602);
                                ServerSocket.Send(writer.getWorkspace(), Index_);
                                return;
                            }
                            else if (!CheckItemLevel(SourceItem_, Index_))
                            {
                                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                                writer.AppendWord(0x1002);
                                ServerSocket.Send(writer.getWorkspace(), Index_);
                                return;
                            }

                            if (tmpPtr->Destination == 6)
                            {
                                Player.General[Index_].WeaponType = SourceItem_.CLASS_C;
                            }

                            Silkroad.Item_ WeaponItem = Silkroad.GetItemById(DatabaseCore.Item.ItemId[CharacterItemIndex[6]]);

                            Console.WriteLine(WeaponItem.CLASS_C);
                            if (tmpPtr->Destination == 6 && DatabaseCore.Item.ItemId[CharacterItemIndex[7]] != 0 && (Player.General[Index_].WeaponType != 2 && Player.General[Index_].WeaponType != 3 && Player.General[Index_].WeaponType != 7 && Player.General[Index_].WeaponType != 10 && Player.General[Index_].WeaponType != 15))
                            {
                                byte unequipped = UnEnquipShield(Index_, CharacterItemIndex, CharacterItemIndex[7]);
                                if (unequipped != 255)
                                {
                                    MoveItemToDatabase(CharacterItemIndex[7], unequipped, Player.General[Index_].CharacterName);
                                }
                            }

                            if (tmpPtr->Destination == 7 && DatabaseCore.Item.ItemId[CharacterItemIndex[6]] != 0 && (WeaponItem.CLASS_C != 2 && WeaponItem.CLASS_C != 3 && WeaponItem.CLASS_C != 7 && WeaponItem.CLASS_C != 10 && WeaponItem.CLASS_C != 15))
                            {
                                byte unequipped = UnEnquipWeapon(Index_, CharacterItemIndex, CharacterItemIndex[6]);
                                if (unequipped != 255)
                                {
                                    MoveItemToDatabase(CharacterItemIndex[6], unequipped, Player.General[Index_].CharacterName);
                                }
                            }

                            EquipItem(Index_, CharacterItemIndex[tmpPtr->Source], CharacterItemIndex[tmpPtr->Destination]);
                        }
                        else
                        {
                            if (!(tmpPtr->Destination == 7 && (Player.General[Index_].WeaponType == 6 || Player.General[Index_].WeaponType == 12) && DatabaseCore.Item.ItemId[CharacterItemIndex[7]] != 0))
                            {
                                return;
                            }
                        }
                    }
                    if (tmpPtr->Source < 13)
                    {
                        UnEquipItem(Index_, CharacterItemIndex[tmpPtr->Source], CharacterItemIndex[tmpPtr->Destination]);
                    }

                    writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                    writer.AppendByte(1);
                    writer.AppendByte(tmpPtr->Type);
                    writer.AppendByte(tmpPtr->Source);
                    writer.AppendByte(tmpPtr->Destination);
                    writer.AppendWord(tmpPtr->Amount);
                    writer.AppendByte(0);
                    ServerSocket.Send(writer.getWorkspace(), Index_);

                    MoveItemToDatabase(CharacterItemIndex[tmpPtr->Source], CharacterItemIndex[tmpPtr->Destination], Player.General[Index_].CharacterName);
                }
                Stats.OnStatPacket(Index_);
                break;

            case 7:
                CharacterItemIndex = DatabaseCore.Item.GetIndexByName(Player.General[Index_].CharacterName);

                int ItemIndex = Item.ItemAmount;
                Item.General[ItemIndex].Pk2ID      = DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Source]];
                Item.General[ItemIndex].UniqueID   = (uint)random.Next(76000000, 79999999);
                Item.General[ItemIndex].Plus       = DatabaseCore.Item.PlusValue[CharacterItemIndex[tmpPtr->Source]];
                Item.General[ItemIndex].Durability = DatabaseCore.Item.Durability[CharacterItemIndex[tmpPtr->Source]];
                Item.General[ItemIndex].Pickable   = true;
                Item.General[ItemIndex].Quantity   = DatabaseCore.Item.Quantity[CharacterItemIndex[tmpPtr->Source]];
                Item.Position[ItemIndex].XSector   = Player.Position[Index_].XSector;
                Item.Position[ItemIndex].YSector   = Player.Position[Index_].YSector;
                byte randomplace = (byte)random.Next(1, 7);
                Item.Position[ItemIndex].X = Player.Position[Index_].X + randomplace;
                Item.Position[ItemIndex].Z = Player.Position[Index_].Z;
                Item.Position[ItemIndex].Y = Player.Position[Index_].Y + randomplace;
                Item.General[ItemIndex].DroppedByUniqueId = Player.General[Index_].UniqueID;
                Item.ItemAmount++;

                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                writer.AppendByte(1);
                writer.AppendByte(tmpPtr->Type);
                writer.AppendByte(tmpPtr->Source);
                ServerSocket.Send(writer.getWorkspace(), Index_);

                Silkroad.Item_ tmpItem = Silkroad.GetItemById(DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Source]]);

                byte[] tmpBuffer = new byte[0];
                if (tmpItem.ITEM_TYPE_NAME.Contains("CH") || tmpItem.ITEM_TYPE_NAME.Contains("EU"))
                {
                    writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_SPAWN);
                    writer.AppendDword(DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Source]]);
                    writer.AppendByte(DatabaseCore.Item.PlusValue[CharacterItemIndex[tmpPtr->Source]]);
                    writer.AppendDword(Item.General[ItemIndex].UniqueID);
                    writer.AppendByte(Item.Position[ItemIndex].XSector);
                    writer.AppendByte(Item.Position[ItemIndex].YSector);
                    writer.AppendFloat(Item.Position[ItemIndex].X);
                    writer.AppendFloat(Item.Position[ItemIndex].X);
                    writer.AppendFloat(Item.Position[ItemIndex].Y);
                    writer.AppendWord(0xAAA6);
                    writer.AppendByte(0);
                    writer.AppendByte(0);
                    writer.AppendByte(6);
                    writer.AppendDword(Item.General[ItemIndex].DroppedByUniqueId);
                    tmpBuffer = writer.getWorkspace();
                }
                else if (tmpItem.ITEM_TYPE_NAME.Contains("ETC"))
                {
                    writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_SPAWN);
                    writer.AppendDword(DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Source]]);
                    writer.AppendDword(Item.General[ItemIndex].UniqueID);
                    writer.AppendByte(Item.Position[ItemIndex].XSector);
                    writer.AppendByte(Item.Position[ItemIndex].YSector);
                    writer.AppendFloat(Item.Position[ItemIndex].X);
                    writer.AppendFloat(Item.Position[ItemIndex].X);
                    writer.AppendFloat(Item.Position[ItemIndex].Y);
                    writer.AppendWord(0xAAA6);
                    writer.AppendByte(0);
                    writer.AppendByte(0);
                    writer.AppendByte(6);
                    writer.AppendDword(Item.General[ItemIndex].DroppedByUniqueId);
                    tmpBuffer = writer.getWorkspace();
                }

                for (int i = 0; i < Player.PlayersOnline; i++)
                {
                    if (Player.General[i].CharacterID != 0)
                    {
                        if (Formula.CalculateDistance(Item.Position[ItemIndex], Player.Position[i]) <= 800)
                        {
                            ServerSocket.Send(tmpBuffer, i);
                            Player.Objects[i].SpawnedItemsIndex.Add(ItemIndex);
                        }
                    }
                }

                DatabaseCore.WriteQuery("UPDATE items SET itemid='0',plusvalue='0' ,durability='30' WHERE itemnumber='item{0}' AND owner='{1}'", tmpPtr->Source, Player.General[Index_].CharacterName);
                Stats.OnStatPacket(Index_);

                DeleteFromDatabase(CharacterItemIndex[tmpPtr->Source]);

                break;

            case 10:
                if (Player.Stats[Index_].Gold != 0)
                {
                    PacketReader reader = new PacketReader(ptr, 5);
                    reader.ModifyIndex(1);
                    uint goldamount = reader.ReadDword();


                    ItemIndex = Item.ItemAmount;
                    if (goldamount < 10000)
                    {
                        Item.General[ItemIndex].Pk2ID = 1;
                    }
                    else if (goldamount >= 10000 && goldamount <= 500000)
                    {
                        Item.General[ItemIndex].Pk2ID = 2;
                    }
                    else if (goldamount >= 500001)
                    {
                        Item.General[ItemIndex].Pk2ID = 3;
                    }

                    Item.General[ItemIndex].UniqueID   = (uint)random.Next(76000000, 79999999);
                    Item.General[ItemIndex].Plus       = 0;
                    Item.General[ItemIndex].Durability = 0;
                    Item.General[ItemIndex].Pickable   = true;
                    Item.General[ItemIndex].Quantity   = goldamount;
                    Item.Position[ItemIndex].XSector   = Player.Position[Index_].XSector;
                    Item.Position[ItemIndex].YSector   = Player.Position[Index_].YSector;
                    randomplace = (byte)random.Next(1, 7);
                    Item.Position[ItemIndex].X = Player.Position[Index_].X + randomplace;
                    Item.Position[ItemIndex].Z = Player.Position[Index_].Z;
                    Item.Position[ItemIndex].Y = Player.Position[Index_].Y + randomplace;
                    Item.General[ItemIndex].DroppedByUniqueId = Player.General[Index_].UniqueID;
                    Item.ItemAmount++;

                    writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_SPAWN);
                    if (goldamount < 10000)
                    {
                        writer.AppendDword(1);
                    }
                    else if (goldamount >= 10000 && goldamount <= 500000)
                    {
                        writer.AppendDword(2);
                    }
                    else if (goldamount >= 500001)
                    {
                        writer.AppendDword(3);
                    }
                    writer.AppendDword(goldamount);
                    writer.AppendDword(Item.General[ItemIndex].UniqueID);
                    writer.AppendByte(Item.Position[ItemIndex].XSector);
                    writer.AppendByte(Item.Position[ItemIndex].YSector);
                    writer.AppendFloat(Item.Position[ItemIndex].X);
                    writer.AppendFloat(Item.Position[ItemIndex].X);
                    writer.AppendFloat(Item.Position[ItemIndex].Y);
                    writer.AppendWord(0xDC72);
                    writer.AppendByte(0);
                    writer.AppendByte(0);
                    writer.AppendByte(6);
                    writer.AppendDword(0);

                    tmpBuffer = writer.getWorkspace();

                    for (int i = 0; i < Player.PlayersOnline; i++)
                    {
                        if (Player.General[i].CharacterID != 0)
                        {
                            if (Formula.CalculateDistance(Item.Position[ItemIndex], Player.Position[i]) <= 800)
                            {
                                ServerSocket.Send(tmpBuffer, i);
                                Player.Objects[i].SpawnedItemsIndex.Add(ItemIndex);
                            }
                        }
                    }

                    Player.Stats[Index_].Gold -= goldamount;
                    writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_NEW_GOLD_AMOUNT);
                    writer.AppendByte(1);
                    writer.AppendLword(Player.Stats[Index_].Gold);
                    writer.AppendByte(0);
                    ServerSocket.Send(writer.getWorkspace(), Index_);


                    writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                    writer.AppendByte(1);
                    writer.AppendByte(10);
                    writer.AppendDword(goldamount);
                    ServerSocket.Send(writer.getWorkspace(), Index_);

                    DatabaseCore.WriteQuery("UPDATE characters SET gold='{0}' WHERE name='{1}'", Player.Stats[Index_].Gold, Player.General[Index_].CharacterName);
                }
                break;
            }
        }