Exemplo n.º 1
0
        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");
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 public virtual void InstallData(IInventoryItem item)
 {
     item.SetUses(1);
     item.SetMaxCondition(1f);
     item.SetCondition(1f);
 }
Exemplo n.º 3
0
        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;
            }
        }