Beispiel #1
0
    // Adaptation of GameUtils.WZ(ItemActionAttackData itemActionAttackData, ItemValue itemValue, int num, float num2, string text, bool flag = true).
    // .WZ is obfuscated if will be named different on your machine.
    public void AddHarvestItemToInventory(ItemValue itemValue, int num, float num2, string text)
    {
        //string msg = "Harvest: " + itemValue.ItemClass.GetItemName();
        if (itemValue == null || itemValue.ItemClass == null || (itemValue.ItemClass.GetItemName() == "yuccaFibers" && !harvestBlocks.Contains("grass")))
        {
            //DebugMsg(msg += " (NOT HARVESTED)");
            return;
        }
        //DebugMsg(msg);

        if (UnityEngine.Random.value <= num2 && num > 0)
        {
            ItemStack itemStack         = new ItemStack(itemValue, num);
            bool      addedToVehicleInv = false;
            if (harvestToVehicleInventory && entityVehicle.HasStorage())
            {
                //addedToVehicleInv = entityVehicle.xuiC_VehicleContainer.AddItem(itemStack);
                //XUiC_VehicleContainer vehicleContainer = entityVehicle.GetVehicleContainer();
                //XUiC_VehicleContainer vehicleContainer = EntityCustomVehicle.GetVehicleContainer(entityVehicle, entityVehicle.player, entityVehicle.vehicleXuiName);
                //if (vehicleContainer != null)
                if (entityVehicle.xuiC_VehicleContainer != null)
                {
                    //addedToVehicleInv = entityVehicle.inventory.AddItem(itemStack);
                    //addedToVehicleInv = vehicleContainer.AddItem(itemStack);
                    addedToVehicleInv = entityVehicle.xuiC_VehicleContainer.AddItem(itemStack);
                }
            }
            if (!addedToVehicleInv)
            {
                LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(entityVehicle.player);
                //if (!entityVehicle.playerInventory.AddItem(itemStack, true))
                //if (!entityVehicle.player.inventory.AddItem(itemStack))
                if (!uiforPlayer.xui.PlayerInventory.AddItem(itemStack, true))
                {
                    GameManager.Instance.ItemDropServer(new ItemStack(itemValue, num), entityVehicle.player.GetPosition(), Vector3.zero, entityVehicle.player.GetInstanceID(), 60f, false);
                }
            }
            // The harvesting XP is only added when destroyed blocks are also harvested and when HarvestXPFactor xml property > 0.
            if (harvestXPFactor != 0)
            {
                entityVehicle.player.AddExp(Mathf.RoundToInt(itemStack.itemValue.ItemClass.MadeOfMaterial.Experience * (float)num * harvestXPFactor));
            }
        }
    }
Beispiel #2
0
    // Adaptation of GameUtils.WZ(ItemActionAttackData itemActionAttackData, ItemValue itemValue, int num, float num2, string text, bool flag = true).
    // .WZ is obfuscated if will be named different on your machine.
    public void AddHarvestItemToInventory(ItemValue itemValue, int num, float num2, string text)
    {
        //string msg = "Harvest: " + itemValue.ItemClass.GetItemName();
        if (itemValue == null || itemValue.ItemClass == null || (itemValue.ItemClass.GetItemName() == "yuccaFibers" && !harvestBlocks.Contains("grass")))
        {
            //DebugMsg(msg += " (NOT HARVESTED)");
            return;
        }
        //DebugMsg(msg);

        if (UnityEngine.Random.value <= num2 && num > 0)
        {
            LocalPlayerUI uiforPlayer       = LocalPlayerUI.GetUIForPlayer(entityVehicle.player);
            ItemStack     itemStack         = new ItemStack(itemValue, num);
            bool          addedToVehicleInv = false;
            if (harvestToVehicleInventory && entityVehicle.HasStorage())
            {
                //addedToVehicleInv = entityVehicle.xuiC_VehicleContainer.AddItem(itemStack);
                //XUiC_VehicleContainer vehicleContainer = entityVehicle.GetVehicleContainer();
                //XUiC_VehicleContainer vehicleContainer = EntityCustomVehicle.GetVehicleContainer(entityVehicle, entityVehicle.player, entityVehicle.vehicleXuiName);
                //if (vehicleContainer != null)
                if (entityVehicle.xuiC_VehicleContainer != null)
                {
                    //addedToVehicleInv = entityVehicle.inventory.AddItem(itemStack);
                    //addedToVehicleInv = vehicleContainer.AddItem(itemStack);
                    ItemStack itemStackClone = itemStack.Clone();
                    addedToVehicleInv = entityVehicle.xuiC_VehicleContainer.AddItem(itemStack);
                    //Debug.Log("Harvest: " + itemStack.itemValue.ItemClass.GetItemName() + "(" + itemStack.count.ToString() + ")");
                    //Debug.Log("Harvest Clone: " + itemStackClone.itemValue.ItemClass.GetItemName() + "(" + itemStackClone.count.ToString() + ")");
                    //if (addedToVehicleInv)
                    {
                        //uiforPlayer.xui.CollectedItemList.viewComponent.IsVisible = true;
                        //uiforPlayer.xui.CollectedItemList.AddItemStack(itemStackClone, false);
                        //uiforPlayer.xui.CollectedItemList.
                        //uiforPlayer.xui.CollectedItemList.IsDirty = true;
                        //uiforPlayer.xui.CollectedItemList.viewComponent.IsDirty = true;
                        //uiforPlayer.xui.CollectedItemList.Update(Time.deltaTime);
                        //uiforPlayer.xui.CollectedItemList.viewComponent.Update(Time.deltaTime);
                        //uiforPlayer.xui.CollectedItemList.Parent.IsDirty = true;
                        //itemStack.count = 0;

                        //entityVehicle.hudStatBar.xui.CollectedItemList.viewComponent.IsVisible = true;
                        //entityVehicle.hudStatBar.xui.CollectedItemList.PrefabItems.gameObject.SetActive(true);
                        //entityVehicle.hudStatBar.xui.CollectedItemList.AddItemStack(itemStackClone, false);
                        //entityVehicle.hudStatBar.IsDirty = true;

                        /*if (VehicleCollectedItemList != null)
                         * {
                         *  VehicleCollectedItemList.AddItemStack(itemStackClone, false);
                         * }*/
                    }
                }
            }
            if (!addedToVehicleInv)
            {
                //LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(entityVehicle.player);

                //if (!entityVehicle.playerInventory.AddItem(itemStack, true))
                //if (!entityVehicle.player.inventory.AddItem(itemStack))
                if (!uiforPlayer.xui.PlayerInventory.AddItem(itemStack, true))
                {
                    GameManager.Instance.ItemDropServer(new ItemStack(itemValue, num), entityVehicle.player.GetPosition(), Vector3.zero, entityVehicle.player.GetInstanceID(), 60f, false);
                }
            }
            // The harvesting XP is only added when destroyed blocks are also harvested and when HarvestXPFactor xml property > 0.
            if (harvestXPFactor != 0)
            {
                entityVehicle.player.AddExp(Mathf.RoundToInt(itemStack.itemValue.ItemClass.MadeOfMaterial.Experience * (float)num * harvestXPFactor));
            }
        }
    }