public override object Run(object[] args, int start = 1) { if (args.Length - start <= 1) { ARareItemSwapJPANs.LogError(name, "Requires at least 2 Arguments;\n" + Help()); return(null); } Player p = getPlayerFromObject(args[start]); if (p == null) { ARareItemSwapJPANs.LogError(name, "Invalid player"); return(null); } PartsPlayer pp = p.GetModPlayer <PartsPlayer>(); if (pp == null) { ARareItemSwapJPANs.LogError(name, "Invalid player"); return(null); } Item itm = getItemFromObject(args[start + 1]); if (itm == null) { ARareItemSwapJPANs.LogError(name, "Invalid item for part: null"); return(null); } long total = pp.getPartAmount(ARareItemSwapJPANs.ItemToTag(itm)); if (total == -1) { ARareItemSwapJPANs.LogError(name, "Invalid item for part: item is not a part"); return(null); } if (args.Length - start > 2) { long?toCheck = getLongFromObject(args[start + 2]); if (toCheck == null || !toCheck.HasValue) { ARareItemSwapJPANs.LogError(name, "Invalid long for count"); return(null); } return(pp.decreasePart(ARareItemSwapJPANs.ItemToTag(itm), toCheck.Value)); } else { return(pp.decreasePart(ARareItemSwapJPANs.ItemToTag(itm))); } }
public void refund(PartsPlayer player, ref Item toRefund) { if (isAvailable() && !irreversible && toRefund.type == result.type && toRefund.stack >= result.stack) { foreach (Item itm in parts) { player.addPart(itm.Clone()); } toRefund.stack -= result.stack; if (toRefund.stack <= 0) { toRefund.TurnToAir(); } } }
public Item Purchase(PartsPlayer player) { if (isAvailable() && player.CraftPartRecipe(this)) { if (cloneReward) { return(result.Clone()); } else { Item itm = new Item(); itm.SetDefaults(result.type); itm.stack = result.stack; return(itm); } } return(new Item()); }
public override bool ItemSpace(Item item, Player player) { PartsPlayer p = player.GetModPlayer <PartsPlayer>(); if (p.autoDestroy) { if (!ARareItemSwapJPANs.tokenList.Contains(ARareItemSwapJPANs.ItemToTag(item)) && PartRecipes.ContainsAsResult(item)) { foreach (PartRecipe pr in PartRecipes.recipesByResult[ARareItemSwapJPANs.ItemToTag(item)]) { if (pr.isAvailable() && !pr.irreversible && item.stack > pr.result.stack) { return(true); } } } } return(base.ItemSpace(item, player)); }
public override void Update(GameTime gameTime) { if (hasChanges || selected != parent.selectedRecipe || selected == null || !selected.Equals(parent.selectedRecipe)) { selected = parent.selectedRecipe; internalGrid.Left.Set(0, 0); internalGrid.Top.Set(0, 0); internalGrid.Width.Set(this.Width.Pixels - 4, 0); internalGrid.Height.Set(this.Height.Pixels - 4, 0); internalGrid.Clear(); float startX = 0; float startY = 0; if (selected != null) { PartsPlayer prt = Main.player[Main.myPlayer].GetModPlayer <PartsPlayer>(); foreach (Item part in selected.parts) { PartItemSlot pt = new PartItemSlot(ARareItemSwapJPANs.ItemToTag(part), part.stack); //pt.Left.Set(startX, 0); // pt.Top.Set(startY, 0); /*startX += pt.Width.Pixels + 2; * if (startX + pt.Width.Pixels + 2 > this.Height.Pixels - 4) * { * startX = 0; * startY += pt.Height.Pixels + 2; * }*/ internalGrid.Add(pt); } } // internalGrid.Height.Set(Math.Max(this.Height.Pixels, startY + parent.destroySlot.Height.Pixels + 2), 0); internalGrid.Recalculate(); Recalculate(); hasChanges = false; } base.Update(gameTime); }
public override bool OnPickup(Item item, Player player) { PartsPlayer p = player.GetModPlayer <PartsPlayer>(); PartRecipe pr; if (p.autoDestroy && item.active) { if (!ARareItemSwapJPANs.tokenList.Contains(ARareItemSwapJPANs.ItemToTag(item)) && PartRecipes.ContainsAsResult(item)) { List <PartRecipe> smallest = new List <PartRecipe>(); int j = 0; for (j = 0; j < PartRecipes.recipesByResult[ARareItemSwapJPANs.ItemToTag(item)].Count; j++) { pr = PartRecipes.recipesByResult[ARareItemSwapJPANs.ItemToTag(item)][j]; if (pr.isAvailable() && !pr.irreversible && item.stack >= pr.result.stack) { smallest.Add(pr); break; } } if (smallest.Count <= 0) { return(base.OnPickup(item, player)); } for (int i = j; i < PartRecipes.recipesByResult[ARareItemSwapJPANs.ItemToTag(item)].Count; i++) { if (PartRecipes.recipesByResult[ARareItemSwapJPANs.ItemToTag(item)][i].isAvailable() && !PartRecipes.recipesByResult[ARareItemSwapJPANs.ItemToTag(item)][i].irreversible) { if (PartRecipes.recipesByResult[ARareItemSwapJPANs.ItemToTag(item)][i].result.stack < smallest[0].result.stack) { smallest.Clear(); smallest.Add(PartRecipes.recipesByResult[ARareItemSwapJPANs.ItemToTag(item)][i]); } else if (PartRecipes.recipesByResult[ARareItemSwapJPANs.ItemToTag(item)][i].result.stack == smallest[0].result.stack) { smallest.Add(PartRecipes.recipesByResult[ARareItemSwapJPANs.ItemToTag(item)][i]); } } } pr = smallest[Main.rand.Next(smallest.Count)]; int stack; int cnt = 0; do { stack = item.stack; pr.refund(p, ref item); // Main.NewText(stack + " = " + item.stack); cnt++; }while (item.stack > 0 && stack != item.stack); if (cnt > 0) { int i = 1; foreach (Item prt in pr.parts) { Item cln = prt.Clone(); cln.position = new Microsoft.Xna.Framework.Vector2(item.position.X, item.position.Y + 30 * i); cln.stack = (int)prt.stack * cnt; Main.PlaySound(SoundID.Grab, player.position); ItemText.NewText(cln, (int)prt.stack * cnt); i++; } } if (item.stack <= 0) { item.TurnToAir(); /* * for (j = 0; j < 400; j++) * { * if (Main.item[j] == item) * { * * Main.item[j] = new Item(); * if (Main.netMode == 1) * { * Main.NewText("Updated Item " + j); * NetMessage.SendData(21, -1, -1, null, item.whoAmI, 0f, 0f, 0f, 0, 0, 0); * } * } * }*/ return(false); } } } return(base.OnPickup(item, player)); }
public void whileMouseHovering() { PartsPlayer p = Main.player[Main.myPlayer].GetModPlayer <PartsPlayer>(); if (Main.mouseLeftRelease && Main.mouseLeft) { if (Main.mouseItem == null || Main.mouseItem.type == 0) { Main.mouseItem = ARareItemSwapJPANs.getItemFromTag(partTag); if (p.getPartAmount(partTag) >= Main.mouseItem.maxStack) { Main.mouseItem.stack = Main.mouseItem.maxStack; p.decreasePart(partTag, Main.mouseItem.maxStack); } else if (p.getPartAmount(partTag) > 0) { Main.mouseItem.stack = (int)p.getPartAmount(partTag); p.decreasePart(partTag, p.getPartAmount(partTag)); } else { Main.mouseItem.TurnToAir(); } } else { if (p.addPart(Main.mouseItem)) { Main.mouseItem.TurnToAir(); } } } 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) { if (p.decreasePart(partTag) != -1) { Main.mouseItem = ARareItemSwapJPANs.getItemFromTag(partTag); Main.mouseItem.stack = 1; } } else { if (Main.mouseItem.stack <= Main.mouseItem.maxStack && ARareItemSwapJPANs.ItemToTag(Main.mouseItem).Equals(partTag)) { if (p.decreasePart(partTag) != -1) { Main.mouseItem.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; } } } }
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."; } } } }
public void recreateList() { internalGrid.Left.Set(0, 0); internalGrid.Top.Set(0, 0); internalGrid.Width.Set(this.Width.Pixels - 4, 0); internalGrid.Height.Set(this.Height.Pixels - 4, 0); restart: changedToList = false; internalGrid.Clear(); if (parent.destroySlot.item != null && parent.destroySlot.item.type != 0 && !ARareItemSwapJPANs.tokenList.Contains(ARareItemSwapJPANs.ItemToTag(parent.destroySlot.item)) && PartRecipes.recipesByResult.ContainsKey(ARareItemSwapJPANs.ItemToTag(parent.destroySlot.item))) { foreach (PartRecipe pr in PartRecipes.recipesByResult[ARareItemSwapJPANs.ItemToTag(parent.destroySlot.item)]) { if (pr.isAvailable()) { PurchaseItemSlot pt = new PurchaseItemSlot(pr); if (parent.selectedRecipe == null) { parent.selectedRecipe = pr; } if (pr.Equals(parent.selectedRecipe)) { pt.select(true); } internalGrid.Add(pt); if (changedToList) { goto restart; } } } } else if (selected.Equals(changer.availableTree)) { List <PartRecipe> prtList = new List <PartRecipe>(); prtList.AddRange(PartRecipes.allRecipes); prtList.Sort(PartRecipe.orderByResultName); for (int i = 0; i < prtList.Count; i++) { if (!prtList[i].isAvailable()) { prtList.RemoveAt(i); i--; } else { if (!Main.player[Main.myPlayer].GetModPlayer <PartsPlayer>().CanCraftRecipe(prtList[i])) { prtList.RemoveAt(i); i--; } } if (changedToList) { goto restart; } } foreach (PartRecipe pr in prtList) { if (search == null || search.Trim().Length == 0 || pr.result.Name.ToLower().Contains(search.ToLower()) || (tooltipSearch && condensedTooltip(pr.result).ToLower().Contains(search.ToLower()))) { PurchaseItemSlot pt = new PurchaseItemSlot(pr); internalGrid.Add(pt); } if (changedToList) { goto restart; } } } else if (selected.Equals(changer.allTree)) { List <PartRecipe> prtList = new List <PartRecipe>(); prtList.AddRange(PartRecipes.allRecipes); prtList.Sort(PartRecipe.orderByResultName); foreach (PartRecipe pr in prtList) { if (pr.isAvailable()) { if (search == null || search.Trim().Length == 0 || pr.result.Name.ToLower().Contains(search.ToLower()) || (tooltipSearch && condensedTooltip(pr.result).ToLower().Contains(search.ToLower()))) { PurchaseItemSlot pt = new PurchaseItemSlot(pr); internalGrid.Add(pt); } if (changedToList) { goto restart; } } } } else if (selected.Equals(changer.partsTree)) { PartsPlayer prt = Main.player[Main.myPlayer].GetModPlayer <PartsPlayer>(); foreach (string s in ARareItemSwapJPANs.tokenList) { if (prt.parts.ContainsKey(s)) { Item part = ARareItemSwapJPANs.getItemFromTag(s); if (search == null || search.Trim().Length == 0 || part.Name.ToLower().Contains(search.ToLower()) || (tooltipSearch && condensedTooltip(part).ToLower().Contains(search.ToLower()))) { PartItemSlot pt = new PartItemSlot(s, -1); internalGrid.Add(pt); } if (changedToList) { goto restart; } } } } else { if (selected != null && PartRecipes.recipesByCategory.ContainsKey(selected.getFullPath())) { List <PartRecipe> prtList = new List <PartRecipe>(); prtList.AddRange(PartRecipes.recipesByCategory[selected.getFullPath()]); prtList.Sort(PartRecipe.orderByResultName); foreach (PartRecipe pr in prtList) { if (pr.isAvailable()) { if (search == null || search.Length == 0 || pr.result.Name.ToLower().Contains(search.ToLower()) || (tooltipSearch && condensedTooltip(pr.result).ToLower().Contains(search.ToLower()))) { PurchaseItemSlot pt = new PurchaseItemSlot(pr); internalGrid.Add(pt); } } if (changedToList) { goto restart; } } } } }