private void InventoryOnItemUsed(InventoryItemBase item, ItemType type) { if (item == null || type == ItemType.Resource) { return; } int?eventArgument; if (System.Type.op_Equality(item.GetType(), typeof(FoodInventoryItem))) { FoodInventoryItem foodInventoryItem = (FoodInventoryItem)item; PlayerInventory.PlayerPed.get_Task().PlayAnimation(foodInventoryItem.AnimationDict, foodInventoryItem.AnimationName, 8f, foodInventoryItem.AnimationDuration, foodInventoryItem.AnimationFlags); // ISSUE: reference to a compiler-generated field PlayerInventory.OnUsedFoodEvent foodUsed = PlayerInventory.FoodUsed; if (foodUsed != null) { foodUsed(foodInventoryItem, foodInventoryItem.FoodType); } } else if (System.Type.op_Equality(item.GetType(), typeof(WeaponInventoryItem))) { WeaponInventoryItem weapon = (WeaponInventoryItem)item; PlayerInventory.PlayerPed.get_Weapons().Give(weapon.Hash, weapon.Ammo, true, true); // ISSUE: reference to a compiler-generated field PlayerInventory.OnUsedWeaponEvent weaponUsed = PlayerInventory.WeaponUsed; if (weaponUsed != null) { weaponUsed(weapon); } } else if (System.Type.op_Equality(item.GetType(), typeof(BuildableInventoryItem)) || System.Type.op_Equality(item.GetType(), typeof(WeaponStorageInventoryItem))) { if (PlayerInventory.PlayerPed.IsInVehicle()) { UI.Notify("You can't build while in a vehicle!"); return; } BuildableInventoryItem buildableInventoryItem = (BuildableInventoryItem)item; ItemPreview itemPreview = new ItemPreview(); itemPreview.StartPreview(buildableInventoryItem.PropName, buildableInventoryItem.GroundOffset, buildableInventoryItem.IsDoor); while (!itemPreview.PreviewComplete) { Script.Yield(); } Prop result = itemPreview.GetResult(); if (Entity.op_Equality((Entity)result, (Entity)null)) { return; } PlayerInventory.AddBlipToProp((IProp)buildableInventoryItem, buildableInventoryItem.Id, (Entity)result); // ISSUE: reference to a compiler-generated field PlayerInventory.OnUsedBuildableEvent buildableUsed = PlayerInventory.BuildableUsed; if (buildableUsed != null) { buildableUsed(buildableInventoryItem, result); } } else if (System.Type.op_Equality(item.GetType(), typeof(UsableInventoryItem))) { foreach (UsableItemEvent itemEvent in ((UsableInventoryItem)item).ItemEvents) { switch (itemEvent.Event) { case ItemEvent.GiveArmor: eventArgument = itemEvent.EventArgument as int?; int num1 = eventArgument ?? 0; Ped playerPed1 = PlayerInventory.PlayerPed; ((Entity)playerPed1).set_Health(((Entity)playerPed1).get_Health() + num1); break; case ItemEvent.GiveHealth: eventArgument = itemEvent.EventArgument as int?; int num2 = eventArgument ?? 0; Ped playerPed2 = PlayerInventory.PlayerPed; playerPed2.set_Armor(playerPed2.get_Armor() + num2); break; } } } else if (System.Type.op_Equality(item.GetType(), typeof(CraftableInventoryItem)) && !((CraftableInventoryItem)item).Validation.Invoke()) { return; } this._inventory.AddItem(item, -1, type); }
private void InventoryOnItemUsed(InventoryItemBase item, ItemType type) { if (item != null && type != 0) { if (item.GetType() == typeof(FoodInventoryItem)) { FoodInventoryItem foodItem = (FoodInventoryItem)item; PlayerPed.Task.PlayAnimation(foodItem.AnimationDict, foodItem.AnimationName, 8f, foodItem.AnimationDuration, foodItem.AnimationFlags); PlayerInventory.FoodUsed?.Invoke(foodItem, foodItem.FoodType); } else if (item.GetType() == typeof(WeaponInventoryItem)) { WeaponInventoryItem weaponItem = (WeaponInventoryItem)item; PlayerPed.Weapons.Give(weaponItem.Hash, weaponItem.Ammo, true, true); PlayerInventory.WeaponUsed?.Invoke(weaponItem); } else if (item.GetType() == typeof(BuildableInventoryItem) || item.GetType() == typeof(WeaponStorageInventoryItem)) { if (PlayerPed.IsInVehicle()) { UI.Notify("You can't build while in a vehicle!"); return; } BuildableInventoryItem buildableItem = (BuildableInventoryItem)item; ItemPreview preview = new ItemPreview(); preview.StartPreview(buildableItem.PropName, buildableItem.GroundOffset, buildableItem.IsDoor); while (!preview.PreviewComplete) { Script.Yield(); } Prop result = preview.GetResult(); if (result == null) { return; } AddBlipToProp(buildableItem, buildableItem.Id, result); PlayerInventory.BuildableUsed?.Invoke(buildableItem, result); } else if (item.GetType() == typeof(UsableInventoryItem)) { UsableInventoryItem usableItem = (UsableInventoryItem)item; UsableItemEvent[] events = usableItem.ItemEvents; UsableItemEvent[] array = events; foreach (UsableItemEvent @event in array) { switch (@event.Event) { case ItemEvent.GiveArmor: { int arg = (@event.EventArgument as int?) ?? 0; Ped playerPed2 = new Ped(PlayerPed.Handle); playerPed2.Health = playerPed2.Health + arg; break; } case ItemEvent.GiveHealth: { int arg2 = (@event.EventArgument as int?) ?? 0; Ped playerPed = new Ped(PlayerPed.Handle); playerPed.Armor = playerPed.Armor + arg2; break; } } } } else if (item.GetType() == typeof(CraftableInventoryItem)) { CraftableInventoryItem craftableItem = (CraftableInventoryItem)item; if (!craftableItem.Validation()) { return; } } _inventory.AddItem(item, -1, type); } }