static void LoadInventory(Fougerite.Player player) { JsonAPI json = JsonAPI.GetInstance; User user = Data.Globals.usersOnline.Find(x => x.Name == player.Name); if (user != null) { List <UserInventoryItem> playerItems = json.DeSerializeJsonToObject <List <UserInventoryItem> >(user.InternalInventory); foreach (UserInventoryItem item in playerItems) { if (item != null && item.Name != "" && item.Quantity != -1) { player.Inventory.AddItemTo(item.Name, item.Slot, item.Quantity); Inventory inventory = player.PlayerClient.controllable.GetComponent <Inventory>(); PlayerItem playerItem = new PlayerItem(ref inventory, item.Slot); IInventoryItem dataItem = playerItem.RInventoryItem as IInventoryItem; dataItem.SetCondition(item.Condition); if (playerItem != null) { if (playerItem.isWeapon) { dataItem.SetUses(item.WeaponBullets); playerItem.heldItem.SetTotalModSlotCount(item.WeaponSlots); if (item.WeaponSlot1 != null) { playerItem.addWeaponMod(item.WeaponSlot1); } if (item.WeaponSlot2 != null && item.WeaponSlot2 != "null") { playerItem.addWeaponMod(item.WeaponSlot2); } if (item.WeaponSlot3 != null && item.WeaponSlot3 != "null") { playerItem.addWeaponMod(item.WeaponSlot3); } if (item.WeaponSlot4 != null && item.WeaponSlot4 != "null") { playerItem.addWeaponMod(item.WeaponSlot4); } if (item.WeaponSlot5 != null && item.WeaponSlot5 != "null") { playerItem.addWeaponMod(item.WeaponSlot5); } } } else { Logger.LogError("LoadInventory - playerItem is Null"); } } } } }
public bool CompleteRepair(Inventory ingredientInv) { BlueprintDataBlock block; if (!this.CanRepair(ingredientInv)) { return(false); } IInventoryItem repairItem = this.GetRepairItem(); if (!BlueprintDataBlock.FindBlueprintForItem <BlueprintDataBlock>(repairItem.datablock, out block)) { return(false); } for (int i = 0; i < block.ingredients.Length; i++) { BlueprintDataBlock.IngredientEntry entry = block.ingredients[i]; int count = Mathf.RoundToInt(block.ingredients[i].amount * this.GetResourceScalar()); if (count > 0) { while (count > 0) { int totalNum = 0; IInventoryItem item2 = ingredientInv.FindItem(entry.Ingredient, out totalNum); if (item2 != null) { if (item2.Consume(ref count)) { ingredientInv.RemoveItem(item2.slot); } } else { return(false); } } } } float num4 = repairItem.maxcondition - repairItem.condition; float num5 = (num4 * 0.2f) + 0.05f; repairItem.SetMaxCondition(repairItem.maxcondition - num5); repairItem.SetCondition(repairItem.maxcondition); return(true); }
public bool CompleteRepair(Inventory ingredientInv) { BlueprintDataBlock blueprintDataBlock; if (!this.CanRepair(ingredientInv)) { return(false); } IInventoryItem repairItem = this.GetRepairItem(); if (!BlueprintDataBlock.FindBlueprintForItem <BlueprintDataBlock>(repairItem.datablock, out blueprintDataBlock)) { return(false); } for (int i = 0; i < (int)blueprintDataBlock.ingredients.Length; i++) { BlueprintDataBlock.IngredientEntry ingredientEntry = blueprintDataBlock.ingredients[i]; int num = Mathf.RoundToInt((float)blueprintDataBlock.ingredients[i].amount * this.GetResourceScalar()); if (num > 0) { while (num > 0) { int num1 = 0; IInventoryItem inventoryItem = ingredientInv.FindItem(ingredientEntry.Ingredient, out num1); if (inventoryItem == null) { return(false); } if (inventoryItem.Consume(ref num)) { ingredientInv.RemoveItem(inventoryItem.slot); } } } } float single = repairItem.maxcondition - repairItem.condition; float single1 = single * 0.2f + 0.05f; repairItem.SetMaxCondition(repairItem.maxcondition - single1); repairItem.SetCondition(repairItem.maxcondition); return(true); }
public virtual void InstallData(IInventoryItem item) { item.SetUses(1); item.SetMaxCondition(1f); item.SetCondition(1f); }
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; } }