Ejemplo n.º 1
0
        private async void DropInventoryItem(Client sender, int id)
        {
            if (!sender.isInVehicle)
            {
                if (!sender.inFreefall && !sender.isParachuting && !sender.isOnLadder)
                {
                    Player    player = Player.PlayerData[sender];
                    Inventory item   = InventoryRepository.GetInventoryItemById(id);

                    API.playPlayerAnimation(player.Client, 0, "pickup_object", "putdown_low");

                    await Task.Run(() =>
                    {
                        Thread.Sleep(350);

                        item.DroppedPos       = Player.GetPositionInFrontOfPlayer(sender, 0.4f, -0.74);
                        item.DroppedRot       = Inventory.GetRotationForItem[item.Type];
                        item.OwnerId          = -1;
                        item.OwnerType        = InventoryOwnerType.Dropped;
                        item.DroppedDimension = sender.dimension;

                        item.DroppedObj = API.createObject(Inventory.GetObjectForItem[item.Type], item.DroppedPos, item.DroppedRot, item.DroppedDimension);
                        item.ApplyPhysics();

                        if (item.IsPhone())
                        {
                            Phone p = PhoneRepository.GetPhoneByIMEI(long.Parse(item.Value));
                            if (p.IsPrimary)
                            {
                                API.triggerClientEvent(sender, "hidePhoneUI");
                            }

                            p.IsPrimary = false;
                            PhoneRepository.UpdateAsync(p);
                        }
                        List <Inventory> inv = null;
                        if (player.InEvent == PlayerEvent.AccessingInventory)
                        {
                            if (player.VehicleInteractingWith != null)
                            {
                                inv = player.VehicleInteractingWith.TrunkItems;
                            }
                            else
                            {
                                inv = player.Inventory;
                            }
                        }
                        inv?.Remove(inv.FirstOrDefault(il => il.Id == item.Id));
                        InventoryRepository.UpdateAsync(item);
                        Inventory.DroppedItems.Add(item);

                        RefreshAfterDropChange(item);
                    });
                }
                else
                {
                    API.SendErrorNotification(sender, "You have to be on the ground to drop items.");
                }
            }
            else
            {
                API.SendErrorNotification(sender, "You drop items in a vehicle");
            }
        }
Ejemplo n.º 2
0
        private async void OnClientEventTrigger(Client sender, string eventName, params object[] arguments)
        {
            switch (eventName)
            {
            case "getInventoryTypeActions":
            {
                Inventory inv = InventoryRepository.GetInventoryItemById((int)arguments[0]);
                if (inv.IsPhone())
                {
                    Phone p = PhoneRepository.GetPhoneByIMEI(long.Parse(inv.Value));
                    API.triggerClientEvent(sender, "displayActionsForItem", inv.Id,
                                           p.IsPrimary
                                    ? JsonConvert.SerializeObject("GIVE,DROP,UNSET PRIMARY".Split(','))
                                    : JsonConvert.SerializeObject("GIVE,DROP,SET PRIMARY".Split(',')));
                    return;
                }

                API.triggerClientEvent(sender, "displayActionsForItem", inv.Id, JsonConvert.SerializeObject(Inventory.GetActionsByType[inv.Type]));
            }
            break;

            case "performActionOnItem":
            {
                Inventory inv = InventoryRepository.GetInventoryItemById((int)arguments[0]);
                switch (arguments[1].ToString())
                {
                case "USE":
                    UsePlayerInventoryItem(sender, (int)arguments[0]);
                    break;

                case "GIVE":
                    GetPlayerToGiveItem(sender, (int)arguments[0]);
                    break;

                case "DROP":
                    DropInventoryItem(sender, (int)arguments[0]);
                    break;

                case "SET PRIMARY":
                    SetPhonePrimary(sender, inv, true);
                    break;

                case "UNSET PRIMARY":
                    SetPhonePrimary(sender, inv, false);
                    break;

                case "RELEASE":
                    DestroyInventoryItem(sender, (int)arguments[0]);
                    break;
                }
            }
            break;

            case "giveItemToPlayer":
                if ((int)arguments[0] == 1)
                {
                    GiveInventoryItem(sender, arguments[1].ToString());
                }
                break;

            case "DisplayPlayerInventory":
            {
                Player p = Player.PlayerData[sender];
                UpdatePlayerInventory(p);
            }
            break;

            case "OnInventoryItemMoved":
            {
                Player    p = Player.PlayerData[sender];
                Inventory item;
                try
                {
                    item = p.Inventory.Single(i => i.Id == (int)arguments[0]);
                }
                catch
                {
                    item = Inventory.DroppedItems.Single(i => i.Id == (int)arguments[0]);
                    Inventory.DroppedItems.Remove(item);
                    API.deleteEntity(item.DroppedObj);

                    if (!Inventory.IsStackable(item))
                    {
                        item.OwnerId   = p.Id;
                        item.OwnerType = InventoryOwnerType.Player;
                        p.Inventory.Add(item);

                        API.SendInfoNotification(p.Client, String.Format("You have picked up a {0}", item.Name));
                        API.playPlayerAnimation(p.Client, 0, "pickup_object", "pickup_low");
                        RefreshAfterDropChange(item);
                    }
                }
                item.SlotPosition = int.Parse(arguments[1].ToString() + arguments[2].ToString());

                InventoryRepository.UpdateAsync(item);
            }
            break;

            case "OnFriskInventoryItemTaken":
            {
                Player    p    = Player.PlayerData[sender];
                Inventory item = null;
                try
                {
                    item = p.Inventory.Single(i => i.Id == (int)arguments[0]);
                }
                catch
                {
                    item = p.PlayerInteractingWith.Inventory.Single(i => i.Id == (int)arguments[0]);
                }

                if (item != null)
                {
                    int    newOwnerId = (int)arguments[1];
                    Player oldOwner   = Player.PlayerData.Values.FirstOrDefault(pl => pl.Id == item.OwnerId);
                    Player newOwner   = Player.PlayerData.Values.FirstOrDefault(pl => p.Id == newOwnerId);

                    API.SendCloseMessage(sender, 10.0f, "~#C2A2DA~",
                                         p != oldOwner
                                    ? string.Format("{0} {1} takes a {2} from {3}.", p.Faction.Ranks[p.FactionRank].Title,
                                                    API.getPlayerName(sender), item.Name, oldOwner.Username.Roleplay())
                                    : string.Format("{0} {1} places a {2} on {3}.", p.Faction.Ranks[p.FactionRank].Title,
                                                    API.getPlayerName(sender), item.Name, newOwner.Username.Roleplay()));

                    item.OwnerId      = newOwner.Id;
                    item.OwnerType    = InventoryOwnerType.Player;
                    item.SlotPosition = int.Parse(arguments[2].ToString() + arguments[3].ToString());

                    InventoryRepository.UpdateAsync(item);

                    RefreshPlayerInventory(p.PlayerInteractingWith);
                    ShowFriskInventory(p, p.PlayerInteractingWith);
                }
            }
            break;

            case "OnTrunkInventoryItemTaken":
            {
                int    oldOwnerId;
                Player p    = Player.PlayerData[sender];
                string type = arguments[2].ToString();

                Vehicle   vTo   = null;
                Player    from  = null;
                Vehicle   vFrom = null;
                Player    to    = null;
                Inventory item  = null;

                item = InventoryRepository.GetInventoryItemById((int)arguments[0]);
                Console.WriteLine(arguments[1].ToString());

                if (type == "trunk")
                {
                    vTo = Vehicle.VehicleData.Values.FirstOrDefault(
                        ve => ve.Id == int.Parse(arguments[1].ToString()));
                    from = p;
                }
                else
                {
                    to = Player.PlayerData.Values.FirstOrDefault(
                        pl => pl.Id == int.Parse(arguments[1].ToString()));
                    if (item.OwnerType == InventoryOwnerType.Vehicle)
                    {
                        vFrom = Vehicle.VehicleData.Values.FirstOrDefault(ve => ve.Id == item.OwnerId);
                    }
                }

                oldOwnerId = item.OwnerId;

                item.OwnerType = vTo != null
                            ? InventoryOwnerType.Vehicle
                            : to != null
                                ? InventoryOwnerType.Player
                                : InventoryOwnerType.Dropped;
                item.OwnerId      = vTo != null ? vTo.Id : to != null ? p.Id : -1;
                item.SlotPosition = int.Parse(arguments[3].ToString() + arguments[4].ToString());

                InventoryRepository.UpdateAsync(item);

                if (oldOwnerId == -1)
                {
                    Inventory.DroppedItems.Remove(Inventory.DroppedItems.Single(i => i.Id == (int)arguments[0]));
                    API.deleteEntity(item.DroppedObj);

                    API.SendInfoNotification(p.Client, String.Format("You have picked up a {0}", item.Name));
                    API.playPlayerAnimation(p.Client, 0, "pickup_object", "pickup_low");
                    RefreshAfterDropChange(item);
                }

                p.Inventory = await InventoryRepository.GetInventoryByOwnerIdAsync(p.Id);

                if (vFrom != null)
                {
                    vFrom.TrunkItems.Remove(vFrom.TrunkItems.FirstOrDefault(vl => vl.Id == item.Id));
                }
                if (item.OwnerType == InventoryOwnerType.Vehicle)
                {
                    if (oldOwnerId != item.OwnerId)
                    {
                        vTo.TrunkItems.Add(item);
                    }
                    else
                    {
                        vTo.TrunkItems.FirstOrDefault(vl => vl.Id == item.Id).SlotPosition = item.SlotPosition;
                    }
                }

                ShowTrunkInventory(p, p.VehicleInteractingWith);

                if (p == to)
                {
                    return;
                }

                string fromString = vTo != null ? $"{vTo.DisplayName}" : $"{vFrom.DisplayName}";
                API.SendCloseMessage(sender, 10.0f, "~#C2A2DA~",
                                     vTo == null
                                ? string.Format("{0} takes a {1} from the {2}.",
                                                API.getPlayerName(sender), item.Name, fromString)
                                : string.Format("{0} places a {1} on the {2}.",
                                                API.getPlayerName(sender), item.Name, fromString));
                break;
            }

            case "OnHeaderSlotItemSelected":
            {
                Player    p    = Player.PlayerData[sender];
                Inventory item = null;
                try
                {
                    item = p.Inventory.FirstOrDefault(i => i.Id == (int)arguments[0]);
                }
                catch
                {
                    Console.WriteLine("{0}: Error occurred when trying to open Header Slot with ID: {1}", Server.Date.ToString(), (int)arguments[0]);
                    return;
                }

                if (item != null)
                {
                    if (item.IsBag())
                    {
                    }
                }
            }
            break;

            case "OnInventoryClose":
            {
                Player p = Player.PlayerData[sender];
                if (p.AccessingBank != -1)
                {
                }
                p.InEvent = PlayerEvent.None;
            }
            break;
            }
        }