コード例 #1
0
ファイル: PartsPlayer.cs プロジェクト: JPANv2/RareItemSwap
        public override bool ShiftClickSlot(Item[] inventory, int context, int slot)
        {
            if (PartExchangeUI.visible && inventory != null && inventory[slot] != null && !inventory[slot].IsAir)
            {
                if (ARareItemSwapJPANs.tokenList.Contains(ARareItemSwapJPANs.ItemToTag(inventory[slot])))
                {
                    this.addPart(inventory[slot]);
                    inventory[slot].TurnToAir();
                    return(true);
                }
                if (PartRecipes.ContainsAsResult(inventory[slot]))
                {
                    List <PartRecipe> target = PartRecipes.recipesByResult[ARareItemSwapJPANs.ItemToTag(inventory[slot])];
                    for (int i = 0; i < target.Count; i++)
                    {
                        if (target[i].irreversible || !target[i].isAvailable() || target[i].result.stack > inventory[slot].stack)
                        {
                            target.RemoveAt(i);
                            i--;
                        }
                    }
                    if (target.Count > 0)
                    {
                        PartRecipe pr  = target[0];
                        int        min = pr.result.stack;
                        for (int i = 1; i < target.Count; i++)
                        {
                            if (min > target[i].result.stack)
                            {
                                min = target[i].result.stack;
                                pr  = target[i];
                            }
                        }

                        int stack;
                        int cnt = 0;
                        do
                        {
                            stack = inventory[slot].stack;
                            pr.refund(this, ref inventory[slot]);
                            cnt++;
                        }while (inventory[slot].stack > 0 && stack != inventory[slot].stack);
                    }
                    if (inventory[slot].stack <= 0)
                    {
                        inventory[slot].TurnToAir();
                    }
                }
                return(true);
            }
            return(false);
        }
コード例 #2
0
ファイル: UIItemSlot.cs プロジェクト: JPANv2/RareItemSwap
        public override void whileMouseHovering()
        {
            PartsPlayer p = Main.player[Main.myPlayer].GetModPlayer <PartsPlayer>();

            if (Main.mouseLeftRelease && Main.mouseLeft)
            {
                if (Main.mouseItem == null || Main.mouseItem.type == 0)
                {
                    if (!isSelected)
                    {
                        ((ARareItemSwapJPANs)ModLoader.GetMod("ARareItemSwapJPANs")).ExchangeUISelectRecipe(recipe);
                    }
                    else
                    {
                        Main.mouseItem = recipe.Purchase(p);
                    }
                }
                else
                {
                    recipe.refund(p, ref Main.mouseItem);
                }
            }
            else if (Main.stackSplit <= 1 && Main.mouseRight)
            {
                if (item.maxStack >= 1 && (Main.mouseItem.IsTheSameAs(item) || Main.mouseItem.type == 0) && (Main.mouseItem.stack < Main.mouseItem.maxStack || Main.mouseItem.type == 0))
                {
                    if (Main.mouseItem.type == 0)
                    {
                        Main.mouseItem = recipe.Purchase(p);
                    }
                    else
                    {
                        if (Main.mouseItem.stack + recipe.result.stack <= Main.mouseItem.maxStack)
                        {
                            Item purchased = recipe.Purchase(p);
                            if (!purchased.IsAir)
                            {
                                Main.mouseItem.stack += purchased.stack;
                            }
                        }
                    }
                    Recipe.FindRecipes();
                    Main.soundInstanceMenuTick.Stop();
                    Main.soundInstanceMenuTick = Main.soundMenuTick.CreateInstance();
                    Main.PlaySound(12, -1, -1, 1, 1f, 0f);
                    if (Main.stackSplit == 0)
                    {
                        Main.stackSplit = 15;
                    }
                    else
                    {
                        Main.stackSplit = Main.stackDelay;
                    }
                }
            }
            Main.hoverItemName = item.Name;
            string hoverItemName = Main.hoverItemName;

            Main.hoverItemName = hoverItemName + " ( " + item.stack + ")\nCosts:\n";
            foreach (Item pr in recipe.parts)
            {
                Main.hoverItemName += " - " + pr.Name + " (" + pr.stack + ");\n";
            }
            if (recipe.irreversible)
            {
                Main.hoverItemName += "IRREVERSIBLE!";
            }
            if (ModLoader.GetMod("ResearchFrom14") != null)
            {
                Mod rmod       = ModLoader.GetMod("ResearchFrom14");
                int?toResearch = (rmod.Call("isresearched", p.player, item)) as int?;
                if (toResearch != null)
                {
                    if (toResearch < 0)
                    {
                        Main.hoverItemName += "\nUnresearchable!";
                    }
                    else if (toResearch == 0)
                    {
                        Main.hoverItemName += "\nResearched!";
                    }
                    else
                    {
                        Main.hoverItemName += "\nResearch " + toResearch + " more to unlock.";
                    }
                }
            }
        }