public static void InitComponent() { using (MySqlConnection connection = new MySqlConnection(Data.Database.Connection.GetConnectionString())) { connection.Open(); MySqlCommand command = connection.CreateCommand(); command.CommandText = "SELECT * FROM store_items"; MySqlDataReader reader = command.ExecuteReader(); DataTable schemaTable = reader.GetSchemaTable(); int InternalID = 1; while (reader.HasRows) { while (reader.Read()) { Data.Entities.StoreItem newItem = new Data.Entities.StoreItem { ID = reader.GetInt32("id"), InternalID = InternalID, UserID = reader.GetInt32("user_id"), Price = reader.GetInt32("price"), Date = reader.GetString("date"), ItemName = reader.GetString("item_name"), ItemQuantity = reader.GetInt32("item_quantity"), ItemCategory = reader.GetInt32("item_category"), ItemCondition = reader.GetInt32("item_condition"), ItemWeaponSlots = reader.GetInt32("item_weapon_slots"), ItemWeaponBullets = reader.GetInt32("item_weapon_bullets"), ItemWeaponSlot1 = reader.GetString("item_weapon_slot_1"), ItemWeaponSlot2 = reader.GetString("item_weapon_slot_2"), ItemWeaponSlot3 = reader.GetString("item_weapon_slot_3"), ItemWeaponSlot4 = reader.GetString("item_weapon_slot_4"), ItemWeaponSlot5 = reader.GetString("item_weapon_slot_5"), }; if (reader.GetInt32("purchased") == 1) { newItem.Purchased = true; } StoreItems.Add(newItem); InternalID += 1; Logger.Log($"StoreItem {InternalID} cargado."); } reader.NextResult(); } } }
public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatArguments) { var pl = Fougerite.Server.Cache[Arguments.argUser.userID]; string lang = LanguageComponent.LanguageComponent.GetPlayerLangOrDefault(pl); if (!RustPP.Data.Globals.UserIsLogged(pl)) { char ch = '☢'; pl.Notice(ch.ToString(), LanguageComponent.LanguageComponent.getMessage("notice_not_logged", lang), 4f); return; } RustPP.Data.Entities.User user = RustPP.Data.Globals.GetInternalUser(pl); if (ChatArguments.Length < 1) { pl.SendClientMessage("-[color #db8cff] /tienda lista [/color] Ver todos los objetos en venta"); pl.SendClientMessage("-[color #db8cff] /tienda ver [/color] Mira los detalles de un objeto en venta, ejemplo: Estado [color red]¡Importante!"); pl.SendClientMessage("-[color #db8cff] /tienda vender [/color] Inserta en la tienda un objeto que tengas en el inventario."); pl.SendClientMessage("-[color #db8cff] /tienda comprar [/color] Compra un objeto de la tienda"); pl.SendClientMessage("-[color #db8cff] /tienda cuenta [/color] Para ver los objetos en venta de tu cuenta."); pl.SendClientMessage("-[color #db8cff] /tienda retirar [/color] Para retirar un objeto de tu pertenencia."); return; } string search = ChatArguments[0].ToLower(); if (search == "lista") { if (ChatArguments.Length < 2) { List <Data.Entities.StoreItem> playerItems = EconomyComponent.StoreItems.FindAll(x => x.Purchased == false); List <RustPP.Data.Entities.StoreItem> itemList = EconomyComponent.GetPageItemss(playerItems, 1, 10); pl.SendClientMessage("[color #db8cff] ---------------------- [color white]HYRUST TIENDA[/color] ----------------------"); foreach (Data.Entities.StoreItem item in itemList) { if (item.ItemQuantity > 1) { pl.SendClientMessage($"[color #db8cff]# {item.InternalID}[/color] | [color purple]{item.ItemName}[/color] x [color #db8cff]{item.ItemQuantity}[/color] | [color purple]${item.Price}[/color] | [color #db8cff]{Data.Globals.GetUserNameByID(item.UserID)}"); } else { pl.SendClientMessage($"[color #db8cff]# {item.InternalID}[/color] | [color purple]{item.ItemName}[/color] | [color purple]${item.Price}[/color] | [color #db8cff]{Data.Globals.GetUserNameByID(item.UserID)}"); } } List <RustPP.Data.Entities.StoreItem> nextPage = EconomyComponent.GetPageItemss(playerItems, 2, 10); if (nextPage.Count > 0) { pl.SendClientMessage("[color purple]<!>[/color] Use [color #db8cff]/tienda lista 2[/color] para ver más resultados."); } pl.SendClientMessage("[color purple]<!>[/color] TIP: Use [color #db8cff]/tienda ver <Numero>[/color] para ver los detalles del Item y [color #db8cff]/tienda comprar[/color] para comprarlo."); } else { string pagestring = ChatArguments[1]; int page = Int32.Parse(pagestring); List <Data.Entities.StoreItem> playerItems = EconomyComponent.StoreItems.FindAll(x => x.Purchased == false); List <RustPP.Data.Entities.StoreItem> itemList = EconomyComponent.GetPageItemss(playerItems, page, 10); pl.SendClientMessage($"[color #db8cff] ---------------------- [color white]HYRUST TIENDA - Pagina {page}[/color] ----------------------"); foreach (Data.Entities.StoreItem item in itemList) { if (item.ItemQuantity > 1) { pl.SendClientMessage($"[color #db8cff]# {item.InternalID}[/color] | [color purple]{item.ItemName}[/color] x [color #db8cff]{item.ItemQuantity}[/color] | [color purple]${item.Price}[/color] | [color #db8cff]{Data.Globals.GetUserNameByID(item.UserID)}"); } else { pl.SendClientMessage($"[color #db8cff]# {item.InternalID}[/color] | [color purple]{item.ItemName}[/color] | [color purple]${item.Price}[/color] | [color #db8cff]{Data.Globals.GetUserNameByID(item.UserID)}"); } } List <RustPP.Data.Entities.StoreItem> nextPage = EconomyComponent.GetPageItemss(playerItems, page + 1, 10); if (nextPage.Count > 0) { pl.SendClientMessage($"[color purple]<!>[/color] Use [color #db8cff]/tienda lista {page+1}[/color] para ver más resultados."); } } } else if (search == "ver") { if (ChatArguments.Length < 2) { pl.SendClientMessage("[color red]<Sintaxis>[/color] Use [color #db8cff] /tienda ver <Numero> [/color] El numero es el que se encuentra después del # en la lista de items."); return; } string itemstring = ChatArguments[1]; int itemID = Int32.Parse(itemstring); if (EconomyComponent.StoreItems.Exists(x => x.InternalID == itemID && x.Purchased == false)) { Data.Entities.StoreItem storeItem = EconomyComponent.StoreItems.Find(x => x.InternalID == itemID); pl.SendClientMessage($"[color #db8cff] ----- [color white]{storeItem.ItemName} [color #db8cff]|[/color] #{storeItem.InternalID}[/color] -----"); pl.SendClientMessage($"[color purple]Propietario: [/color] [color #db8cff]{Data.Globals.GetUserNameByID(storeItem.UserID)}[/color]"); pl.SendClientMessage($"[color purple]Precio: [/color] [color #db8cff]${storeItem.Price}[/color]"); pl.SendClientMessage($"[color purple]Cantidad: [/color] [color #db8cff]{storeItem.ItemQuantity}[/color]"); pl.SendClientMessage($"[color purple]Estado: [/color] [color #db8cff]{storeItem.ItemCondition*100}/100[/color]"); if (storeItem.ItemCategory == EconomyComponent.GetCategoryNumber("Weapons")) { pl.SendClientMessage($"[color purple]Balas: [/color] [color #db8cff]{storeItem.ItemWeaponBullets}[/color]"); pl.SendClientMessage($"[color purple]Slots: [/color] [color #db8cff]{storeItem.ItemWeaponSlots}[/color]"); if (storeItem.ItemWeaponSlot1 != "null") { pl.SendClientMessage($"[color purple]Slot 1: [/color] [color #db8cff]{storeItem.ItemWeaponSlot1}[/color]"); } if (storeItem.ItemWeaponSlot2 != "null") { pl.SendClientMessage($"[color purple]Slot 1: [/color] [color #db8cff]{storeItem.ItemWeaponSlot2}[/color]"); } if (storeItem.ItemWeaponSlot3 != "null") { pl.SendClientMessage($"[color purple]Slot 1: [/color] [color #db8cff]{storeItem.ItemWeaponSlot3}[/color]"); } if (storeItem.ItemWeaponSlot4 != "null") { pl.SendClientMessage($"[color purple]Slot 1: [/color] [color #db8cff]{storeItem.ItemWeaponSlot4}[/color]"); } if (storeItem.ItemWeaponSlot5 != "null") { pl.SendClientMessage($"[color purple]Slot 1: [/color] [color #db8cff]{storeItem.ItemWeaponSlot5}[/color]"); } } pl.SendClientMessage($"[color purple]<!>[/color] Use [color #db8cff]/tienda comprar {storeItem.InternalID}[/color] para comprar este objeto."); } else { pl.SendClientMessage("[color red]<Error>[/color] Este objeto no existe en la tienda o ya no esta a la venta."); pl.SendClientMessage("[color red]<Sintaxis>[/color] Use [color #db8cff] /tienda ver <Numero> [/color] El numero es el que se encuentra después del # en la lista de items."); return; } } else if (search == "vender") { if (ChatArguments.Length < 3) { pl.SendClientMessage("[color red]<!>[/color] Para vender un objeto coloca lo que quieres vender en tu barra de acceso rápido e indica el SLOT."); pl.SendClientMessage("[color red]<Sintaxis>[/color] /tienda vender <Slot> <Precio>"); return; } string slotstring = ChatArguments[1]; int slot = Int32.Parse(slotstring); if (slot < 1 || slot > 6) { pl.SendClientMessage("[color red]<!>[/color] Slot inválido, selecciona un slot del 1 al 6."); pl.SendClientMessage("[color red]<Sintaxis>[/color] /tienda vender <Slot> <Precio>"); return; } string pricestring = ChatArguments[2]; int price = Int32.Parse(pricestring); if (price < 1) { pl.SendClientMessage("[color red]<!>[/color] Precio inválido, tiene que ser mas de $1."); pl.SendClientMessage("[color red]<Sintaxis>[/color] /tienda vender <Slot> <Precio>"); return; } int sloot = EconomyComponent.GetItemSlot(slot); Fougerite.PlayerItem item = EconomyComponent.GetItem(pl.Inventory, sloot); if (item == null || item.Name == "" && item.Quantity == -1) { pl.SendClientMessage($"[color red]<!>[/color] Probablemente tu ranura este vacía, coloca un item en la ranura {slot}."); pl.SendClientMessage("[color red]<Sintaxis>[/color] /tienda vender <Slot> <Precio>"); return; } string cat = item.RInventoryItem.datablock.category.ToString(); pl.SendClientMessage($"[color purple]<Tienda>[/color] Estas por publlicar {item.Name} x {item.Quantity} en {cat} por ${price}."); pl.SendClientMessage($"[color purple]<Tienda>[/color] Se necesita confirmación, utilice /confirmar."); Data.Entities.StoreItem storeItem = EconomyComponent.GetStoreItem(user, item, price); user.SellingItem = storeItem; } else if (search == "comprar") { if (ChatArguments.Length < 2) { pl.SendClientMessage("[color red]<!>[/color] Asegurese de que el numero de objeto a comprar sea correcto, no hay vuelta atrás."); pl.SendClientMessage("[color red]<Sintaxis>[/color] /tienda comprar <Numero>"); return; } string item = ChatArguments[1]; int internalid = Int32.Parse(item); EconomyComponent.PurchaseItem(user, internalid); } else if (search == "retirar") { if (ChatArguments.Length < 2) { pl.SendClientMessage("[color red]<!>[/color] Para retirar un objeto de su propiedad de la tienda ingrese el numero de Objeto."); pl.SendClientMessage("[color red]<Sintaxis>[/color] /tienda retirar <Numero>"); return; } string item = ChatArguments[1]; int internalid = Int32.Parse(item); EconomyComponent.PurchaseItem(user, internalid); } else if (search == "cuenta") { if (ChatArguments.Length < 2) { List <Data.Entities.StoreItem> playerItems = EconomyComponent.StoreItems.FindAll(x => x.UserID == user.ID); List <RustPP.Data.Entities.StoreItem> itemList = EconomyComponent.GetPageItemss(playerItems, 1, 10); pl.SendClientMessage("[color #db8cff] ---------------------- [color white]HYRUST TIENDA[/color] ----------------------"); foreach (Data.Entities.StoreItem item in itemList) { if (item.ItemQuantity > 1) { pl.SendClientMessage($"[color #db8cff]# {item.InternalID}[/color] | [color purple]{item.ItemName}[/color] x [color #db8cff]{item.ItemQuantity}[/color] | [color purple]${item.Price}[/color] | [color #db8cff]{Data.Globals.GetUserNameByID(item.UserID)}"); } else { pl.SendClientMessage($"[color #db8cff]# {item.InternalID}[/color] | [color purple]{item.ItemName}[/color] | [color purple]${item.Price}[/color] | [color #db8cff]{Data.Globals.GetUserNameByID(item.UserID)}"); } } List <RustPP.Data.Entities.StoreItem> nextPage = EconomyComponent.GetPageItemss(EconomyComponent.StoreItems, 2, 10); if (nextPage.Count > 0) { pl.SendClientMessage("[color purple]<!>[/color] Use [color #db8cff]/tienda cuenta 2[/color] para ver más resultados."); } pl.SendClientMessage("[color purple]<!>[/color] TIP: Use [color #db8cff]/tienda ver <Numero>[/color] para ver los detalles del Item y [color #db8cff]/tienda comprar[/color] para comprarlo."); } else { string pagestring = ChatArguments[1]; int page = Int32.Parse(pagestring); List <Data.Entities.StoreItem> playerItems = EconomyComponent.StoreItems.FindAll(x => x.UserID == user.ID); List <RustPP.Data.Entities.StoreItem> itemList = EconomyComponent.GetPageItemss(playerItems, page, 10); pl.SendClientMessage($"[color #db8cff] ---------------------- [color white]HYRUST TIENDA - Pagina {page}[/color] ----------------------"); foreach (Data.Entities.StoreItem item in itemList) { if (item.ItemQuantity > 1) { pl.SendClientMessage($"[color #db8cff]# {item.InternalID}[/color] | [color purple]{item.ItemName}[/color] x [color #db8cff]{item.ItemQuantity}[/color] | [color purple]${item.Price}[/color] | [color #db8cff]{Data.Globals.GetUserNameByID(item.UserID)}"); } else { pl.SendClientMessage($"[color #db8cff]# {item.InternalID}[/color] | [color purple]{item.ItemName}[/color] | [color purple]${item.Price}[/color] | [color #db8cff]{Data.Globals.GetUserNameByID(item.UserID)}"); } } List <RustPP.Data.Entities.StoreItem> nextPage = EconomyComponent.GetPageItemss(EconomyComponent.StoreItems, page + 1, 10); if (nextPage.Count > 0) { pl.SendClientMessage($"[color purple]<!>[/color] Use [color #db8cff]/tienda cuenta {page + 1}[/color] para ver más resultados."); } } } }
public static void PurchaseItem(Data.Entities.User user, int InternalID) { if (StoreItems.Exists(x => x.InternalID == InternalID && x.Purchased == false)) { Data.Entities.StoreItem storeItem = StoreItems.Find(x => x.InternalID == InternalID); if (storeItem != null && storeItem.ItemName != "" && storeItem.ItemQuantity != -1) { int Slot = user.Player.Inventory.FirstFreeSlot; if (Slot == -1) { user.Player.SendClientMessage($"No tienes espacio en el inventario para recibir el objeto."); return; } Logger.LogError($"Vendedor {user.ID} - {storeItem.UserID}"); if (user.Cash < storeItem.Price && user.ID != storeItem.UserID) { user.Player.SendClientMessage($"No tienes dinero suficiente para comprar este objeto"); return; } user.Player.Inventory.AddItemTo(storeItem.ItemName, Slot, storeItem.ItemQuantity); Inventory inventory = user.Player.PlayerClient.controllable.GetComponent <Inventory>(); PlayerItem playerItem = new PlayerItem(ref inventory, Slot); IInventoryItem dataItem = playerItem.RInventoryItem as IInventoryItem; dataItem.SetCondition(storeItem.ItemCondition); if (user.ID != storeItem.UserID) { user.Cash -= storeItem.Price; if (Data.Globals.UserIsConnected(storeItem.UserID)) { Data.Entities.User seller = Data.Globals.usersOnline.FindLast(x => x.ID == storeItem.UserID); seller.Cash += storeItem.Price; seller.Save(); seller.Player.SendClientMessage($"[color purple]<Tienda>[/color] Vendiste una [color #db8cff]{storeItem.ItemName}[/color] a [color #db8cff]${storeItem.Price}[/color]."); storeItem.Delete(); StoreItems.Remove(storeItem); } else { storeItem.Purchased = true; storeItem.Save(); } user.Player.SendClientMessage($"[color purple]<Tienda>[/color] Compraste una [color #db8cff]{storeItem.ItemName}[/color] a [color #db8cff]${storeItem.Price}[/color]."); } else { storeItem.Delete(); StoreItems.Remove(storeItem); user.Player.SendClientMessage($"[color purple]<Tienda>[/color] Retiraste una [color #db8cff]{storeItem.ItemName}[/color] de la tienda."); } if (playerItem != null) { if (playerItem.isWeapon) { dataItem.SetUses(storeItem.ItemWeaponBullets); playerItem.heldItem.SetTotalModSlotCount(storeItem.ItemWeaponSlots); if (storeItem.ItemWeaponSlot1 != null && storeItem.ItemWeaponSlot1 != "null") { playerItem.addWeaponMod(storeItem.ItemWeaponSlot1); } if (storeItem.ItemWeaponSlot2 != null && storeItem.ItemWeaponSlot2 != "null") { playerItem.addWeaponMod(storeItem.ItemWeaponSlot2); } if (storeItem.ItemWeaponSlot3 != null && storeItem.ItemWeaponSlot3 != "null") { playerItem.addWeaponMod(storeItem.ItemWeaponSlot3); } if (storeItem.ItemWeaponSlot4 != null && storeItem.ItemWeaponSlot4 != "null") { playerItem.addWeaponMod(storeItem.ItemWeaponSlot4); } if (storeItem.ItemWeaponSlot5 != null && storeItem.ItemWeaponSlot5 != "null") { playerItem.addWeaponMod(storeItem.ItemWeaponSlot5); } } } } } else { user.Player.SendClientMessage($"[color red]<Error>[/color] El objeto que intentas comprar ya no esta en venta."); return; } }
public static Data.Entities.StoreItem GetStoreItem(Data.Entities.User user, Fougerite.PlayerItem item, int price = 1) { if (item.Name != "" && item.Quantity != -1 && item != null) { IInventoryItem itemdata = item.RInventoryItem; string category = item.RInventoryItem.datablock.category.ToString(); int internalID = 1; if (StoreItems.Count > 0) { Data.Entities.StoreItem lastItem = StoreItems.Last <Data.Entities.StoreItem>(); if (lastItem != null) { internalID = lastItem.InternalID + 1; } } Data.Entities.StoreItem newItem = new Data.Entities.StoreItem { InternalID = internalID, UserID = user.ID, Price = price, Date = DateTime.Now.ToString(), ItemName = item.Name, ItemCategory = GetCategoryNumber(category), ItemQuantity = item.Quantity, ItemCondition = itemdata.condition, Item = item, }; if (user.Player != null) { newItem.Player = user.Player; } else { return(null); } if (item.isWeapon) { newItem.ItemWeaponBullets = itemdata.uses; ItemModDataBlock mod1 = item.getModSlot(0); ItemModDataBlock mod2 = item.getModSlot(1); ItemModDataBlock mod3 = item.getModSlot(2); ItemModDataBlock mod4 = item.getModSlot(3); ItemModDataBlock mod5 = item.getModSlot(4); newItem.ItemWeaponSlots = item.getModSlotsCount; if (mod1 != null) { newItem.ItemWeaponSlot1 = mod1.name; } if (mod2 != null) { newItem.ItemWeaponSlot2 = mod2.name; } if (mod3 != null) { newItem.ItemWeaponSlot3 = mod3.name; } if (mod4 != null) { newItem.ItemWeaponSlot4 = mod4.name; } if (mod5 != null) { newItem.ItemWeaponSlot5 = mod5.name; } } return(newItem); } return(null); }
public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatArguments) { var pl = Fougerite.Server.Cache[Arguments.argUser.userID]; string lang = LanguageComponent.LanguageComponent.GetPlayerLangOrDefault(pl); if (!RustPP.Data.Globals.UserIsLogged(pl)) { char ch = '☢'; pl.Notice(ch.ToString(), LanguageComponent.LanguageComponent.getMessage("notice_not_logged", lang), 4f); return; } RustPP.Data.Entities.User user = RustPP.Data.Globals.GetInternalUser(pl); if (user.SellingItem == null) { pl.SendClientMessage("[color red]<Error>[/color] No tienes nada para confirmar."); return; } Data.Entities.StoreItem item = user.SellingItem; if (item.Item == null) { pl.SendClientMessage("[color red]<Error>[/color] Al parecer ya no tienes el objeto que pretendías vender."); return; } Fougerite.PlayerItem playerItem = EconomyComponent.EconomyComponent.GetItem(pl.Inventory, item.Item.Slot); if (playerItem == null) { pl.SendClientMessage("[color red]<Error>[/color] Al parecer ya no tienes el objeto que pretendías vender."); return; } Data.Entities.StoreItem actualItem = EconomyComponent.EconomyComponent.GetStoreItem(user, playerItem, item.Price); if (actualItem == null) { pl.SendClientMessage("[color red]<Error>[/color] Al parecer ya no tienes el objeto que pretendías vender."); return; } if (item.ItemName == actualItem.ItemName && item.ItemQuantity == actualItem.ItemQuantity && item.ItemCondition == actualItem.ItemCondition && item.ItemWeaponSlots == actualItem.ItemWeaponSlots && item.ItemWeaponBullets == actualItem.ItemWeaponBullets && item.ItemWeaponSlot1 == actualItem.ItemWeaponSlot1 && item.ItemWeaponSlot2 == actualItem.ItemWeaponSlot2 && item.ItemWeaponSlot3 == actualItem.ItemWeaponSlot3 && item.ItemWeaponSlot4 == actualItem.ItemWeaponSlot4 && item.ItemWeaponSlot5 == actualItem.ItemWeaponSlot5) { EconomyComponent.EconomyComponent.StoreItems.Add(item); pl.Inventory.RemoveItem(item.Item.Slot); item.Create(); foreach (Fougerite.Player player in Fougerite.Server.GetServer().Players) { if (player.IsOnline && Data.Globals.UserIsLogged(player)) { RustPP.Data.Entities.User uuser = RustPP.Data.Globals.GetInternalUser(player); if (uuser.TiendaEnabled || uuser.Name == user.Name) { string quantity = ""; if (item.ItemQuantity > 1) { quantity = $" x {item.ItemQuantity}"; } player.SendClientMessage($"[color purple]<Tienda>[/color] [color #db8cff]{user.Name}{quantity}[/color] publicó un objeto en la tienda - [color #db8cff]{item.ItemName}[/color] [color #db8cff]${item.Price}[/color] ({item.InternalID})"); } } } return; } else { pl.SendClientMessage("[color red]<Error>[/color] Al parecer ya no tienes el objeto que pretendías vender o el objeto cambió su estado."); return; } }