private void CleanupInventory(List <Item> inventory, RiftRecipe recipe, Vector2 position) { List <Item> removals = new List <Item>(); foreach (Item item in inventory.Where(item => recipe.Ingredients.Count(i => i.type == item.type) == 0)) { Item.NewItem(position, item.type); removals.Add(item); } for (int k = 0; k < removals.Count; k++) { inventory.Remove(inventory.FirstOrDefault(item => item == removals[k])); } foreach (RiftIngredient ingredient in recipe.Ingredients) { if (inventory.Any(i => i.type == ingredient.type)) { int total = inventory.Count(i => i.type == ingredient.type); for (int k = total; k > ingredient.count; k--) { Item.NewItem(position, ingredient.type); inventory.Remove(inventory.FirstOrDefault(i => i.type == ingredient.type)); } } } }
public void CloseCrafting(UIMouseEvent evt, UIElement listeningElement) { if (ActiveRecipe != null) { ActiveRecipe = null; return; } else { Crafting = false; ShownRecipes.Clear(); RefreshRecipes(); OpenCodex(evt, listeningElement); } }
public RecipeButton(RiftRecipe recipe) { Recipe = recipe; }
public override void Update() { if (timer >= 1) { timer--; } Rectangle hitbox = new Rectangle(Position.X * 16 - 24, Position.Y * 16 - 56, 64, 128); Vector2 pos = Position.ToVector2() * 16; float rot = Main.rand.NextFloat(6.28f); Vector2 off = new Vector2((float)Math.Cos(rot), (float)Math.Sin(rot) * 3.5f); Dust.NewDustPerfect(hitbox.Center.ToVector2() + (off * 30) - Vector2.One * 4, ModContent.DustType <Dusts.VitricBossTell>(), Vector2.Normalize(off).RotatedBy(1.58f) * -5, 0, new Color(100, 30, 175) * 0.9f, 1.2f); Dust.NewDustPerfect(hitbox.Center.ToVector2() + (off * 30) - Vector2.One * 4, ModContent.DustType <Dusts.VitricBossTell>(), Vector2.Normalize(off).RotatedBy(1.58f) * -5, 0, new Color(1, 1, 1), 0.8f); if (activeCraft == null) { //Adds the items to the inventory of the rift foreach (Item item in Main.item.Where(item => item.active && item.Hitbox.Intersects(hitbox) && item.stack == 1 && item.GetGlobalItem <RiftItem>().crafted == false && item.GetGlobalItem <RiftItem>().tier == 0 && !item.GetGlobalItem <RiftItem>().starless)) { Shake(10, Position.ToVector2() * 16); inventory.Add(item.Clone()); item.TurnToAir(); item.active = false; } if (Main.item.Any(item => item.active && item.GetGlobalItem <RiftItem>().tier > 0 && item.Hitbox.Intersects(hitbox))) //Catalyst check { Item item = Main.item.FirstOrDefault(i => i.active && i.GetGlobalItem <RiftItem>().tier > 0 && i.Hitbox.Intersects(hitbox)); //The Catalyst foreach (RiftRecipe recipe in (mod as StarlightRiver).RiftRecipes) //Checks all the recipies for a valid one { if (recipe.CheckRecipe(inventory) && item.GetGlobalItem <RiftItem>().tier >= recipe.Tier) //Activates that recipe { Shake(30, Position.ToVector2() * 16); activeCraft = recipe; difficulty = recipe.Tier; timer = recipe.Tier * 1800; CleanupInventory(inventory, recipe, Position.ToVector2() * 16); item.TurnToAir(); } } } } else { if (spawnCooldown > 0) { spawnCooldown--; } if (spawnCooldown == 0) { int i = NPC.NewNPC((int)pos.X + Main.rand.Next(-400, 400), (int)pos.Y + Main.rand.Next(-400, 400), activeCraft.SpawnPool[Main.rand.Next(0, activeCraft.SpawnPool.Count)]); Main.npc[i].GetGlobalNPC <RiftNPC>().parent = this; for (int k = 0; k <= 50; k++) { Dust.NewDustPerfect(Main.npc[i].Center, ModContent.DustType <Dusts.Darkness>(), Vector2.One.RotatedByRandom(6.28f) * Main.rand.NextFloat(10)); } spawnCooldown = 180 - activeCraft.Tier * 15; } } if (timer == 1) { inventory.Clear(); Shake(20, Position.ToVector2() * 16); int i = Item.NewItem(Position.ToVector2() * 16, activeCraft.Result); Main.item[i].GetGlobalItem <RiftItem>().crafted = true; activeCraft = null; } if (!Main.player.Any(player => Vector2.Distance(player.Center, Position.ToVector2() * 16) < 1000)) { activeCraft = null; timer = 0; foreach (Item item in inventory.Where(item => item.maxStack == 1)) { int i = Item.NewItem(pos, item.type); Main.item[i].GetGlobalItem <RiftItem>().starless = true; } inventory.Clear(); } }