///////////////////////////////////////////////////////////////////////////////// // Put gold to storage ///////////////////////////////////////////////////////////////////////////////// void Player_GiveGoldW(byte type, long gold) { #region Instert gold into storage try { //Check if the user isnt in any state/action that we will not allow. if (!Character.State.Die || !Character.Stall.Stallactive || !Character.Alchemy.working || !Character.Position.Walking) { //Check if the deposit gold is equally or higher then player inventory gold if (Character.Information.Gold >= gold) { //If the user is storing in normal storage if (!Character.Network.Guild.UsingStorage) { //Set new storage gold plus Character.Account.StorageGold += gold; //Update player inventory gold minus Character.Information.Gold -= gold; //Send update packet client.Send(Packet.UpdateGold(Character.Information.Gold)); //Send visual packet of moving gold client.Send(Packet.MoveItem(type, 0, 0, 0, gold, "MOVE_WAREHOUSE_GOLD")); //Save gold information SaveGold(); } //If the user is using guild storage else { //Set new storage gold plus Character.Network.Guild.StorageGold += gold; //Update player inventory gold minus Character.Information.Gold -= gold; //Send update packet client.Send(Packet.UpdateGold(Character.Information.Gold)); client.Send(Packet.GuildGoldUpdate(Character.Network.Guild.StorageGold, 0x20)); client.Send(Packet.GuildStorageGold(Character)); //Save gold information SaveGold(); //Save guild gold SaveGuildGold(); } } //If gold is to low else { //Send error message to player client.Send(Packet.IngameMessages(SERVER_UPDATEGOLD, IngameMessages.UIIT_MSG_STRGERR_NOT_ENOUGH_GOLD)); } } } catch (Exception ex) { Console.WriteLine("Deposit gold error {0}", ex); Systems.Debugger.Write(ex); } //Save player information SavePlayerInfo(); #endregion }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Exchange Approve /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void Exchange_Approve() { try { Systems sys = GetPlayer(Character.Network.TargetID); client.Send(Packet.Exchange_Approve()); Character.Network.Exchange.Approved = true; if (sys.Character.Network.Exchange.Approved) { #region Gold update if (Character.Network.Exchange.Gold != 0) { Character.Information.Gold -= Character.Network.Exchange.Gold; client.Send(Packet.UpdateGold(Character.Information.Gold)); SaveGold(); sys.Character.Information.Gold += Character.Network.Exchange.Gold; sys.client.Send(Packet.UpdateGold(sys.Character.Information.Gold)); sys.SaveGold(); } if (sys.Character.Network.Exchange.Gold != 0) { sys.Character.Information.Gold -= sys.Character.Network.Exchange.Gold; sys.client.Send(Packet.UpdateGold(sys.Character.Information.Gold)); sys.SaveGold(); Character.Information.Gold += sys.Character.Network.Exchange.Gold; client.Send(Packet.UpdateGold(Character.Information.Gold)); SaveGold(); } #endregion #region Items if (Character.Network.Exchange.ItemList.Count > 0) { foreach (Global.slotItem item in Character.Network.Exchange.ItemList) { byte t_slot = sys.GetFreeSlot(); Systems.MsSQL.InsertData("UPDATE char_items SET owner='" + sys.Character.Information.CharacterID + "' WHERE owner='" + Character.Information.CharacterID + "' AND itemid='" + item.ID + "' AND id='" + item.dbID + "' AND storagetype='0'"); } } if (sys.Character.Network.Exchange.ItemList.Count > 0) { foreach (Global.slotItem item in sys.Character.Network.Exchange.ItemList) { byte t_slot = GetFreeSlot(); Systems.MsSQL.InsertData("UPDATE char_items SET owner='" + Character.Information.CharacterID + "' WHERE owner='" + sys.Character.Information.CharacterID + "' AND itemid='" + item.ID + "' AND id='" + item.dbID + "' AND storagetype='0'"); } } #endregion client.Send(Packet.Exchange_Finish()); sys.client.Send(Packet.Exchange_Finish()); Character.State.Exchanging = false; sys.Character.State.Exchanging = false; } } catch (Exception ex) { Systems.Debugger.Write(ex); } }
public void StallBuy() { try { if (!Character.Network.Stall.isOpened) { return; } PacketReader Reader = new PacketReader(PacketInformation.buffer); byte stallslot = Reader.Byte(); stall currentStall = Character.Network.Stall; stall.stallItem sitem = currentStall.ItemList.Find(i => (i.stallSlot == stallslot)); // stall buyer update byte slot = GetFreeSlot(); if (slot <= 12) { return; } if (Character.Information.Gold >= (long)sitem.price) { Character.Information.Gold -= (long)sitem.price; client.Send(Packet.UpdateGold(Character.Information.Gold)); SaveGold(); } else { return; //insufficent gold } // staller update if (currentStall.ItemList.Contains(sitem)) { Systems staller = GetPlayer(currentStall.ownerID); staller.Character.Information.Gold += (long)sitem.price; staller.client.Send(Packet.UpdateGold(staller.Character.Information.Gold)); MsSQL.UpdateData("update character set gold='" + staller.Character.Information.Gold + "' where id='" + staller.Character.Information.CharacterID + "'"); //MsSQL.UpdateData("delete from char_items where itemnumber='item" + sitem.Item.Slot + "' AND owner='" + staller.Character.Information.CharacterID + "'"); Systems.MsSQL.InsertData("UPDATE char_items SET owner='" + Character.Information.CharacterID + "',slot='" + slot + "',itemnumber='item" + slot + "' WHERE owner='" + staller.Character.Information.CharacterID + "' AND itemid='" + sitem.Item.ID + "' AND id='" + sitem.Item.dbID + "' AND storagetype='0'"); //take item out from stall if (currentStall.ItemList.Count == 1) { staller.Character.Stall.Stallactive = false; Character.Stall.Stallactive = false; } currentStall.ItemList.Remove(sitem); client.Send(Packet.StallBuyItem(stallslot, 1)); currentStall.Send(Packet.StallBuyItem2(Character.Information.Name, stallslot, currentStall.ItemList)); } else { Disconnect("ban"); Console.WriteLine("Autobanned user: "******" Due to hacking"); } } catch (Exception ex) { Systems.Debugger.Write(ex); } }
///////////////////////////////////////////////////////////////////////////////// // Take gold from storage ///////////////////////////////////////////////////////////////////////////////// void Player_TakeGoldW(byte type, long gold) { #region Take gold from storage try { //Check if the user isnt in any state/action that we will not allow. if (!Character.State.Die || !Character.Stall.Stallactive || !Character.Alchemy.working || !Character.Position.Walking) { //Normal storage if (!Character.Network.Guild.UsingStorage) { //Check if the gold is equally or higher to the amount withdrawing if (Character.Account.StorageGold >= gold) { //If ok, reduce the gold from storage Character.Account.StorageGold -= gold; //Add the gold to inventory gold Character.Information.Gold += gold; //Send packet update gold client.Send(Packet.UpdateGold(Character.Information.Gold)); //Send visual update client.Send(Packet.MoveItem(type, 0, 0, 0, gold, "MOVE_WAREHOUSE_GOLD")); //Save the gold information SaveGold(); } //If gold is to low else { //Send error message to the player. client.Send(Packet.IngameMessages(SERVER_UPDATEGOLD, IngameMessages.UIIT_MSG_STRGERR_NOT_ENOUGH_GOLD)); } } //Guild storage else { //Check if the gold is equally or higher to the amount withdrawing if (Character.Network.Guild.StorageGold >= gold) { //If ok, reduce the gold from storage Character.Network.Guild.StorageGold -= gold; //Add the gold to inventory gold Character.Information.Gold += gold; //Send packet update gold client.Send(Packet.UpdateGold(Character.Information.Gold)); client.Send(Packet.GuildGoldUpdate(Character.Network.Guild.StorageGold, 0x21)); client.Send(Packet.GuildStorageGold(Character)); //Save the gold information SaveGold(); //Save guild gold SaveGuildGold(); } //If gold is to low else { //Send error message to the player. client.Send(Packet.IngameMessages(SERVER_UPDATEGOLD, IngameMessages.UIIT_MSG_STRGERR_NOT_ENOUGH_GOLD)); } } } } catch (Exception ex) { Systems.Debugger.Write(ex); Console.WriteLine("Take gold from warehouse error {0}", ex); } //Save player information SavePlayerInfo(); #endregion }
///////////////////////////////////////////////////////////////////////////////// // Move item to storage ///////////////////////////////////////////////////////////////////////////////// void Player_MoveItemToStorage(byte f_slot, byte t_slot, int o_id) { #region Move item to storage try { //Check if the user isnt in any state/action that we will not allow. if (Character.State.Die) { return; } if (Character.Stall.Stallactive) { return; } if (Character.Alchemy.working) { return; } if (Character.Position.Walking) { return; } //Normal storage if (!Character.Network.Guild.UsingStorage) { //Get item information Global.slotItem item = GetItem((uint)Character.Information.CharacterID, f_slot, 0); //Get storage price of the item int storageprice = Data.ItemBase[item.ID].Storage_price; //Set amount if its only 1 if (item.Amount == 0) { item.Amount = 1; } //Multiply the price, per amount storageprice *= item.Amount; //Anti hack check make sure that the owner of the item is correct int ownerid = Convert.ToInt32(MsSQL.GetData("SELECT * FROM char_items WHERE id='" + item.dbID + "'", "owner")); //Check if the owner really owns the item. if (ownerid == Character.Information.CharacterID) { //Make sure the stack count is equal or lower then max stack amount if (item.Amount <= Data.ItemBase[item.ID].Max_Stack) { //If the user has enough gold (Equally or higher to storage price). if (Character.Information.Gold >= storageprice) { //Set character gold Character.Information.Gold -= storageprice; //Send update packet for gold client.Send(Packet.UpdateGold(Character.Information.Gold)); //Update mssql database information MsSQL.UpdateData("UPDATE char_items SET itemnumber='item" + t_slot + "',slot='" + t_slot + "',storagetype='1' WHERE storageacc='" + Player.ID + "' AND id='" + item.dbID + "'"); //Send visual move packet to player client.Send(Packet.MoveItem(2, f_slot, t_slot, 0, 0, "MOVE_TO_STORAGE")); //Save the player gold SaveGold(); } //If the user does not have enough gold else { client.Send(Packet.IngameMessages(SERVER_ITEM_MOVE, IngameMessages.UIIT_MSG_STRGERR_NOT_ENOUGH_GOLD)); } } //This should not happen but if the stack is to high. else { return; } } //If the player is not the item owner (Hacking attempt). else { Disconnect("ban"); Console.WriteLine("Autobanned user: "******" Due to hacking"); } } //Guild storage else { //Get item information Global.slotItem item = GetItem((uint)Character.Information.CharacterID, f_slot, 0); //Get storage price of the item int storageprice = Data.ItemBase[item.ID].Storage_price; //Set amount if its only 1 if (item.Amount == 0) { item.Amount = 1; } //Multiply the price, per amount storageprice *= item.Amount; //Anti hack check make sure that the owner of the item is correct int ownerid = Convert.ToInt32(MsSQL.GetData("SELECT * FROM char_items WHERE id='" + item.dbID + "'", "owner")); //Check if the owner really owns the item. if (ownerid == Character.Information.CharacterID) { //Make sure the stack count is equal or lower then max stack amount if (item.Amount <= Data.ItemBase[item.ID].Max_Stack) { //If the user has enough gold (Equally or higher to storage price). if (Character.Information.Gold >= storageprice) { //Set character gold Character.Information.Gold -= storageprice; //Send update packet for gold client.Send(Packet.UpdateGold(Character.Information.Gold)); //Update mssql database information MsSQL.UpdateData("UPDATE char_items SET itemnumber='item" + t_slot + "',slot='" + t_slot + "',storagetype='3' ,guild_storage_id='" + Character.Network.Guild.Guildid + "' WHERE id='" + item.dbID + "'"); //Send visual move packet to player client.Send(Packet.MoveItem(2, f_slot, t_slot, 0, 0, "MOVE_TO_GUILD_STORAGE")); //Save the player gold SaveGold(); } //If the user does not have enough gold else { client.Send(Packet.IngameMessages(SERVER_ITEM_MOVE, IngameMessages.UIIT_MSG_STRGERR_NOT_ENOUGH_GOLD)); } } //This should not happen but if the stack is to high. else { return; } } //If the player is not the item owner (Hacking attempt). else { Disconnect("ban"); Console.WriteLine("Autobanned user: "******" Due to hacking"); } } } catch (Exception ex) { Console.WriteLine("Storage move error : {0}", ex); Systems.Debugger.Write(ex); } //Save player information SavePlayerInfo(); #endregion }
void GuildPromote() { try { //Read client information int32 id PacketReader reader = new PacketReader(PacketInformation.buffer); int guildid = reader.Int32(); reader.Close(); //When a guild has reached its max level if (Character.Network.Guild.Level == 5) { //Send packet to client and return (Message level up max). client.Send(Packet.IngameMessages(Systems.SERVER_GUILD_WAIT, IngameMessages.UIIT_MSG_ERROR_GUILD_LEVEL_UP_FULL)); return; } //Definition for gold needed int GoldRequired; //Definition for guild points needed int GuildPointRequired; //Check if player is allready in process of upgrading if (!IsUpgrading) { //Set bool to true, so we cant dupe IsUpgrading = true; //Load player guild information before we continue (Check last info). LoadPlayerGuildInfo(false); //Create switch on guildl evel switch (Character.Network.Guild.Level) { case 1: GoldRequired = 3000000; GuildPointRequired = 5400; break; case 2: GoldRequired = 9000000; GuildPointRequired = 50400; break; case 3: GoldRequired = 15000000; GuildPointRequired = 135000; break; case 4: GoldRequired = 21000000; GuildPointRequired = 378000; break; default: return; } //Set new guild level definition + 1 int NewLevel = Character.Network.Guild.Level + 1; //Set new guild storage slot amount int NewStorageSlots = Character.Network.Guild.StorageSlots + 30; //If character's gold is not enough if (Character.Information.Gold < GoldRequired) { //Send message to client client.Send(Packet.IngameMessages(SERVER_GUILD_PROMOTE_MSG, IngameMessages.UIIT_MSG_ERROR_GUILD_LEVEL_UP_GOLD_DEFICIT)); return; } //Not enough guildpoints if (Character.Network.Guild.PointsTotal < GuildPointRequired) { //Send client message client.Send(Packet.IngameMessages(SERVER_GUILD_PROMOTE_MSG, IngameMessages.UIIT_MSG_ERROR_GUILD_LEVEL_UP_GP_DEFICIT)); return; } //Max level if (Character.Network.Guild.Level == 5) { //Send client message client.Send(Packet.IngameMessages(SERVER_GUILD_PROMOTE_MSG, IngameMessages.UIIT_MSG_ERROR_GUILD_LEVEL_UP_FULL)); return; } //If everything else is fine else //Upgrade guild initiate { //If max level return just incase. if (Character.Network.Guild.Level == 5) { return; } //Reduct guildpoints Character.Network.Guild.PointsTotal -= GuildPointRequired; //If the upgrade is final upgrade set points to 0 if (Character.Network.Guild.Level == 4) { Character.Network.Guild.PointsTotal = 0; } //Reduct gold Character.Information.Gold -= GoldRequired; //Send update information to client client.Send(Packet.InfoUpdate(1, Character.Network.Guild.PointsTotal, 0)); //Send success message to client client.Send(Packet.PromoteOrDisband(2)); //Update guild in database MsSQL.UpdateData("UPDATE guild SET guild_level='" + NewLevel + "',guild_points='" + Character.Network.Guild.PointsTotal + "',guild_storage_slots='" + NewStorageSlots + "' WHERE guild_name='" + Character.Network.Guild.Name + "'"); //Repeat for each member in our guild foreach (int member in Character.Network.Guild.Members) { //Check if memeber is not null if (member != 0) { //Get detailed member information Systems memberinfo = GetPlayerMainid(member); //Make sure the member is not null if (memberinfo != null) { //Reload information for the current guild member memberinfo.LoadPlayerGuildInfo(false); //Send guild update packet for current guild member memberinfo.client.Send(Packet.GuildUpdate(Character, 5, 0, 0, 0)); } } } //Save player's gold SaveGold(); //Send update gold packet to client client.Send(Packet.UpdateGold(Character.Information.Gold)); } } //Disable the bool so we can upgrade again IsUpgrading = false; } //If any error accures catch (Exception ex) { //Write error to the console Console.WriteLine("Guild Promote Error: {0}", ex); //Write error to debug log Systems.Debugger.Write(ex); } }
///////////////////////////////////////////////////////////////////////////////// // Pickup item ///////////////////////////////////////////////////////////////////////////////// void Player_PickUpItem() { try { //First check if player allready is picking up an item if (Character.Action.PickUping) { //Get item information that the player has selected. world_item item = GetWorldItem(Character.Action.Target); //Checks if (item == null) { Character.Action.PickUping = false; return; } //If the amount is lower then one if (item.amount < 1) { item.amount = 1; } //If not gold model if (item.Model > 3) { //Get our free slots byte slot = GetFreeSlot(); //If to low if (slot <= 12) { Character.Action.PickUping = false; client.Send(Packet.MoveItemError()); return; } //Else continue stop delete timer because its allready beeing removed. item.StopDeleteTimer(); //Remove the world item spawn Systems.WorldItem.Remove(item); //Delete the global id Global.ID.Delete(item.UniqueID); //Move towards the item Send(Packet.MovementOnPickup(new DarkEmu_GameServer.Global.vektor(Character.Information.UniqueID, (float)Formule.packetx((float)item.x, item.xSec), (float)Character.Position.z, (float)Formule.packety((float)(float)item.y, item.ySec), Character.Position.xSec, Character.Position.ySec))); //Send animation packet pickup Send(Packet.Pickup_Animation(Character.Information.UniqueID, 0)); //Check what item type we have (Etc, or armor / weapon). int amount = 0; //Set amount or plusvalue #region Amount definition if (Data.ItemBase[item.Model].Itemtype == Global.item_database.ItemType.BLADE || Data.ItemBase[item.Model].Itemtype == Global.item_database.ItemType.CH_SHIELD || Data.ItemBase[item.Model].Itemtype == Global.item_database.ItemType.EU_SHIELD || Data.ItemBase[item.Model].Itemtype == Global.item_database.ItemType.BOW || Data.ItemBase[item.Model].Itemtype == Global.item_database.ItemType.EU_AXE || Data.ItemBase[item.Model].Itemtype == Global.item_database.ItemType.EU_CROSSBOW || Data.ItemBase[item.Model].Itemtype == Global.item_database.ItemType.EU_DAGGER || Data.ItemBase[item.Model].Itemtype == Global.item_database.ItemType.EU_DARKSTAFF || Data.ItemBase[item.Model].Itemtype == Global.item_database.ItemType.EU_HARP || Data.ItemBase[item.Model].Itemtype == Global.item_database.ItemType.EU_STAFF || Data.ItemBase[item.Model].Itemtype == Global.item_database.ItemType.EU_SWORD || Data.ItemBase[item.Model].Itemtype == Global.item_database.ItemType.EU_TSTAFF || Data.ItemBase[item.Model].Itemtype == Global.item_database.ItemType.EU_TSWORD || Data.ItemBase[item.Model].Itemtype == Global.item_database.ItemType.GLAVIE || Data.ItemBase[item.Model].Itemtype == Global.item_database.ItemType.SPEAR || Data.ItemBase[item.Model].Itemtype == Global.item_database.ItemType.SWORD || Data.ItemBase[item.Model].Itemtype == Global.item_database.ItemType.EARRING || Data.ItemBase[item.Model].Itemtype == Global.item_database.ItemType.RING || Data.ItemBase[item.Model].Itemtype == Global.item_database.ItemType.NECKLACE || Data.ItemBase[item.Model].Type == Global.item_database.ArmorType.ARMOR || Data.ItemBase[item.Model].Type == Global.item_database.ArmorType.GARMENT || Data.ItemBase[item.Model].Type == Global.item_database.ArmorType.GM || Data.ItemBase[item.Model].Type == Global.item_database.ArmorType.HEAVY || Data.ItemBase[item.Model].Type == Global.item_database.ArmorType.LIGHT || Data.ItemBase[item.Model].Type == Global.item_database.ArmorType.PROTECTOR || Data.ItemBase[item.Model].Itemtype == Global.item_database.ItemType.AVATAR || Data.ItemBase[item.Model].Type == Global.item_database.ArmorType.ROBE) { amount = item.PlusValue; } else { amount = item.amount; } #endregion //Send item creation packet client.Send(Packet.GM_MAKEITEM(0, slot, item.Model, (short)amount, (int)Data.ItemBase[item.Model].Defans.Durability, Data.ItemBase[item.Model].ID, item.UniqueID)); //Save to database AddItem(item.Model, (short)amount, slot, Character.Information.CharacterID, item.Model); } //If the item is gold else { //Remove the spawned item Systems.WorldItem.Remove(item); //Remove global id Global.ID.Delete(item.UniqueID); //Movement packet Send(Packet.MovementOnPickup(new DarkEmu_GameServer.Global.vektor(Character.Information.UniqueID, (float)Formule.packetx((float)item.x, item.xSec), (float)Character.Position.z, (float)Formule.packety((float)(float)item.y, item.ySec), Character.Position.xSec, Character.Position.ySec))); //Send animation packet Send(Packet.Pickup_Animation(Character.Information.UniqueID, 0)); //Add gold to player information Character.Information.Gold += item.amount; //Send visual packet for gold client.Send(Packet.UpdateGold(Character.Information.Gold)); //Send message packet gold gained client.Send(Packet.GoldMessagePick(item.amount)); //Save player gold SaveGold(); } //Despawn item for us item.DeSpawnMe(); //Dispose of the item item.Dispose(); //Set picking to false Character.Action.PickUping = false; if (Timer.Pickup != null) { Timer.Pickup.Dispose(); } } } catch (Exception ex) { Console.WriteLine("Pickup Error {0}", ex); Systems.Debugger.Write(ex); } }