コード例 #1
0
ファイル: InventoryManager.cs プロジェクト: zepa19/MineBattle
    private void CraftingTableINLeftClick()
    {
        if (CopyOfItem == null)
        {
            if (GameManager._Instance.CraftTableData.B[ButtonID].BlockID != 0)
            {
                CopyOfItem = GameManager._Instance.CraftTableData.B[ButtonID];
                GameManager._Instance.CraftTableData.B[ButtonID] = new BlockItem();
            }
        }
        else
        {
            if (GameManager._Instance.CraftTableData.B[ButtonID].BlockID != 0)
            {
                BlockItem tmp = GameManager._Instance.CraftTableData.B[ButtonID];
                GameManager._Instance.CraftTableData.B[ButtonID] = CopyOfItem;
                CopyOfItem = tmp;
            }
            else
            {
                GameManager._Instance.CraftTableData.B[ButtonID] = CopyOfItem;
                CopyOfItem = null;
            }
        }

        PlayerCrafting.DoCrafting(false);
        PlayerGUI.UpdateCraftingTable();
        SetTextTemp3();
    }
コード例 #2
0
        private void OnCraftBlueprintRequested(PlayerCrafting crafting, ref ushort itemId, ref byte blueprintIndex, ref bool shouldAllow)
        {
            UnturnedPlayer player = GetUnturnedPlayer(crafting.player);

            UnturnedPlayerCraftingEvent @event = new UnturnedPlayerCraftingEvent(player, itemId, blueprintIndex);

            Emit(@event);

            itemId         = @event.ItemId;
            blueprintIndex = @event.BlueprintIndex;
            shouldAllow    = [email protected];
        }
コード例 #3
0
    void Awake()
    {
        persistantDataLoadedEvent = new UnityEvent();
        devDataLoadedEvent        = new UnityEvent();

        playerQuests    = GetComponent <PlayerQuests>();
        playerCrafting  = GetComponent <PlayerCrafting>();
        playerArtifacts = GetComponent <PlayerArtifacts>();
        playerAbilities = GetComponent <PlayerAbilities>();
        playerStats     = GetComponent <PlayerStats>();
        playerInventory = GetComponent <PlayerInventory>();
    }
コード例 #4
0
        private void OnCraftBlueprintRequested(PlayerCrafting crafting, ref ushort itemId, ref byte blueprintIndex, ref bool shouldAllow) // lgtm [cs/too-many-ref-parameters]
        {
            var player = GetUnturnedPlayer(crafting.player) !;
            var @event = new UnturnedPlayerCraftingEvent(player, itemId, blueprintIndex)
            {
                IsCancelled = !shouldAllow
            };

            Emit(@event);

            itemId         = @event.ItemId;
            blueprintIndex = @event.BlueprintIndex;
            shouldAllow    = [email protected];
        }
コード例 #5
0
    public static void Instantiate()
    {
        _Instance = new MainLoop();
        Logger.Instantiate();
        World.Instantiate();

        BlockRegistry.RegisterBlocks();
        PlayerMiniCrafting.Initialize();
        PlayerCrafting.Initialize();

        Player.Instantiate();
        DayNightCycle.Instantiate();
        // TODO
    }
コード例 #6
0
ファイル: InventoryManager.cs プロジェクト: zepa19/MineBattle
    private void CraftingTableOUTLeftClick()
    {
        if (CopyOfItem == null)
        {
            if (GameManager._Instance.CraftTableData.B[ButtonID].BlockID != 0)
            {
                CopyOfItem = GameManager._Instance.CraftTableData.B[ButtonID];
                GameManager._Instance.CraftTableData.B[ButtonID] = new BlockItem();
            }
        }

        PlayerCrafting.DoCrafting(true);
        PlayerGUI.UpdateCraftingTable();
        SetTextTemp3();
    }
コード例 #7
0
ファイル: PlayerScript.cs プロジェクト: ARZUMATA/unitystation
 private void Awake()
 {
     playerSprites        = GetComponent <PlayerSprites>();
     playerNetworkActions = GetComponent <PlayerNetworkActions>();
     registerTile         = GetComponent <RegisterPlayer>();
     playerHealth         = GetComponent <PlayerHealthV2>();
     pushPull             = GetComponent <ObjectBehaviour>();
     weaponNetworkActions = GetComponent <WeaponNetworkActions>();
     mouseInputController = GetComponent <MouseInputController>();
     chatIcon             = GetComponentInChildren <ChatIcon>(true);
     playerMove           = GetComponent <PlayerMove>();
     playerDirectional    = GetComponent <Directional>();
     DynamicItemStorage   = GetComponent <DynamicItemStorage>();
     Equipment            = GetComponent <Equipment>();
     Cooldowns            = GetComponent <HasCooldowns>();
     PlayerOnlySyncValues = GetComponent <PlayerOnlySyncValues>();
     playerCrafting       = GetComponent <PlayerCrafting>();
 }
コード例 #8
0
ファイル: InventoryManager.cs プロジェクト: zepa19/MineBattle
    private void CraftingTableINRightClick()
    {
        if (CopyOfItem != null)
        {
            if (GameManager._Instance.CraftTableData.B[ButtonID].BlockID != 0)
            {
                if (GameManager._Instance.CraftTableData.B[ButtonID].BlockID == CopyOfItem.BlockID)
                {
                    if (GameManager._Instance.CraftTableData.B[ButtonID].Count < 64)
                    {
                        if (GameManager._Instance.CraftTableData.B[ButtonID].IncrementBlocks())
                        {
                            CopyOfItem.DecrementBlocks();

                            if (CopyOfItem.Count == 0)
                            {
                                CopyOfItem = null;
                            }
                        }
                    }
                }
            }
            else
            {
                GameManager._Instance.CraftTableData.B[ButtonID].Set(CopyOfItem.BlockID, 1, CopyOfItem.Level);
                CopyOfItem.DecrementBlocks();

                if (CopyOfItem.Count == 0)
                {
                    CopyOfItem = null;
                }
            }
        }

        PlayerCrafting.DoCrafting(false);
        PlayerGUI.UpdateCraftingTable();
        SetTextTemp3();
    }
コード例 #9
0
ファイル: MiningRock.cs プロジェクト: dbirtola/Clicker
 void Awake()
 {
     playerCrafting = FindObjectOfType <PlayerCrafting>();
 }
コード例 #10
0
    void Update()
    {
        GameObject player = Player.player;

        if (!player)
        {
            return;
        }

        PlayerCrafting crafting  = player.GetComponent <PlayerCrafting>();
        Inventory      inventory = player.GetComponent <Inventory>();

        // instantiate/destroy enough slots
        UIUtils.BalancePrefabs(ingredientSlotPrefab.gameObject, crafting.indices.Count, ingredientContent);

        // refresh all
        for (int i = 0; i < crafting.indices.Count; ++i)
        {
            UICraftingIngredientSlot slot = ingredientContent.GetChild(i).GetComponent <UICraftingIngredientSlot>();
            slot.dragAndDropable.name = i.ToString(); // drag and drop index
            int itemIndex = crafting.indices[i];

            if (0 <= itemIndex && itemIndex < inventory.slots.Count &&
                inventory.slots[itemIndex].amount > 0)
            {
                ItemSlot itemSlot = inventory.slots[itemIndex];

                // refresh valid item
                slot.tooltip.enabled          = true;
                slot.tooltip.text             = itemSlot.ToolTip();
                slot.dragAndDropable.dragable = true;
                slot.image.color  = Color.white;
                slot.image.sprite = itemSlot.item.image;
                slot.amountOverlay.SetActive(itemSlot.amount > 1);
                slot.amountText.text = itemSlot.amount.ToString();
            }
            else
            {
                // reset the index because it's invalid
                crafting.indices[i] = -1;

                // refresh invalid item
                slot.tooltip.enabled          = false;
                slot.dragAndDropable.dragable = false;
                slot.image.color  = Color.clear;
                slot.image.sprite = null;
                slot.amountOverlay.SetActive(false);
            }
        }

        // find valid indices => item templates => matching recipe
        List <int> validIndices = crafting.indices.Where(
            index => 0 <= index && index < inventory.slots.Count &&
            inventory.slots[index].amount > 0
            ).ToList();
        List <ItemSlot>  items  = validIndices.Select(index => inventory.slots[index]).ToList();
        ScriptableRecipe recipe = ScriptableRecipe.dict.Values.ToList().Find(r => r.CanCraftWith(items)); // good enough for now

        if (recipe != null)
        {
            // refresh valid recipe
            Item item = new Item(recipe.result);
            resultSlotToolTip.enabled = true;
            resultSlotToolTip.text    = new ItemSlot(item).ToolTip(); // ItemSlot so that {AMOUNT} is replaced too
            resultSlotImage.color     = Color.white;
            resultSlotImage.sprite    = recipe.result.image;
        }
        else
        {
            // refresh invalid recipe
            resultSlotToolTip.enabled = false;
            resultSlotImage.color     = Color.clear;
            resultSlotImage.sprite    = null;
        }

        // craft result
        // (no recipe != null check because it will be null if those were
        //  the last two ingredients in our inventory)
        if (crafting.craftingState == CraftingState.Success)
        {
            resultText.color = successColor;
            resultText.text  = "Success!";
        }
        else if (crafting.craftingState == CraftingState.Failed)
        {
            resultText.color = failedColor;
            resultText.text  = "Failed :(";
        }
        else
        {
            resultText.text = "";
        }

        // craft button with 'Try' prefix to let people know that it might fail
        // (disabled while in progress)
        craftButton.GetComponentInChildren <Text>().text = recipe != null &&
                                                           recipe.probability < 1 ? "Try Craft" : "Craft";
        craftButton.interactable = recipe != null &&
                                   crafting.craftingState != CraftingState.InProgress &&
                                   inventory.CanAdd(new Item(recipe.result), 1);
        craftButton.onClick.SetListener(() => {
            crafting.craftingState = CraftingState.InProgress; // wait for result
            crafting.Craft(validIndices.ToArray());
        });
    }