public override void Buy(Player player) { Manager.Database.DoActionAsync(db => { if (ObjectType == 0x01ca) //Merchant { if (TryDeduct(player)) { for (var i = 0; i < player.Inventory.Length; i++) { try { XElement ist; Manager.GameData.ObjectTypeToElement.TryGetValue((ushort)MType, out ist); if (player.Inventory[i] == null && (player.SlotTypes[i] == 10 || player.SlotTypes[i] == Convert.ToInt16(ist.Element("SlotType").Value))) { player.Inventory[i] = Manager.GameData.Items[(ushort)MType]; player.CurrentFame = player.Client.Account.Stats.Fame = db.UpdateFame(player.Client.Account, -Price); { _accId = db.GetMarketCharId(MType, Price); } { if (logic.CheckConfig.IsDebugOn()) { Console.WriteLine("Attempted to give Player " + _accId + ", " + Price + " fame"); } MySqlCommand cmd = db.CreateQuery(); cmd.CommandText = "UPDATE stats SET fame = fame + @Price WHERE accId=@accId"; cmd.Parameters.AddWithValue("@accId", _accId); cmd.Parameters.AddWithValue("@Price", Price); cmd.ExecuteNonQuery(); } { if (logic.CheckConfig.IsDebugOn()) { Console.WriteLine("Attemping to delete item from database: " + MType + " | " + Price); } MySqlCommand cmd = db.CreateQuery(); cmd.CommandText = "DELETE FROM market WHERE itemid=@itemid AND fame=@fame AND playerid=@id"; cmd.Parameters.AddWithValue("@itemid", MType); cmd.Parameters.AddWithValue("@fame", Price); cmd.Parameters.AddWithValue("@id", _accId); cmd.ExecuteNonQuery(); } player.Client.SendPacket(new BuyResultPacket { Result = 0, Message = "{\"key\":\"server.buy_success\"}" }); player.Client.Save(); player.UpdateCount++; UpdateCount++; Merchant.updatePrice(MType, Manager); return; } } catch (Exception e) { Console.WriteLine(e); } } player.Client.SendPacket(new BuyResultPacket { Result = 0, Message = "{\"key\":\"server.inventory_full\"}" }); } else { switch (Currency) { case CurrencyType.Fame: player.Client.SendPacket(new BuyResultPacket { Result = BuyNoFame, Message = "{\"key\":\"server.not_enough_fame\"}" }); break; } } } }); }
public override void Buy(Player player) { Manager.Database.DoActionAsync(db => { if (ObjectType == 0x01ca) //Merchant { if (player._buyCooldown > 0) { player.SendDialogError("You are buying items too fast, please slow down and re-enter the world if needed"); return; } if (TryDeduct(player)) { for (var i = 0; i < player.Inventory.Length; i++) { try { XElement ist; Manager.GameData.ObjectTypeToElement.TryGetValue((ushort)MType, out ist); if (player.Inventory[i] == null && (player.SlotTypes[i] == 10 || player.SlotTypes[i] == Convert.ToInt16(ist.Element("SlotType").Value))) { if (Currency == CurrencyType.Fame) { player.CurrentFame = player.Client.Account.Stats.Fame = db.UpdateFame(player.Client.Account, -Price); } else { player.Credits = player.Client.Account.Credits = db.UpdateCredit(player.Client.Account, -Price); } if (_playerMarket) { var item = db.GetMarketInfo(MType, Price, player.Manager.GameData); MySqlCommand cmd = db.CreateQuery(); cmd.CommandText = "UPDATE stats SET fame = fame + @Price WHERE accId=@accId"; cmd.Parameters.AddWithValue("@accId", item.currentUser); cmd.Parameters.AddWithValue("@Price", Price); cmd.ExecuteNonQuery(); cmd.CommandText = "DELETE FROM market WHERE serialid=@id"; cmd.Parameters.AddWithValue("@id", item.serialId); cmd.ExecuteNonQuery(); player.Inventory[i] = item; Merchant.updatePrice(MType, Manager); } else { player.Inventory[i] = Manager.CreateSerial(Manager.GameData.Items[(ushort)MType], "Nexus Merchant"); } player.Client.SendPacket(new BuyResultPacket { Result = 0, Message = "{\"key\":\"server.buy_success\"}" }); player.Client.Save(); player.UpdateCount++; UpdateCount++; return; } } catch (Exception e) { Console.WriteLine(e); } } player.Client.SendPacket(new BuyResultPacket { Result = 0, Message = "{\"key\":\"server.inventory_full\"}" }); } else { if (Currency == CurrencyType.Fame) { player.Client.SendPacket(new BuyResultPacket { Result = BuyNoFame, Message = "{\"key\":\"server.not_enough_fame\"}" }); } else { player.Client.SendPacket(new BuyResultPacket { Result = BuyNoGold, Message = "{\"key\":\"server.not_enough_fame\"}" }); } } } }); }