public override bool UseItem(Player player) { DaesPlayer modPlayer = player.GetModPlayer <DaesPlayer>(); if (modPlayer.hasEndlessAmmo) { return(false); } modPlayer.UnlockEndlessAmmo(); return(true); }
public static void HideInterface(DaesPlayer player) { // Drop item from reforge item slot player.DropReforgeItem(); // Clear list of purchasable items ClearCurrentPrefixes(); // Allow the crafting menu to be shown again Main.HidePlayerCraftingMenu = false; visible = false; }
public static void ItemSlotDraw(ILContext il) { ILCursor cursor = new ILCursor(il); if (!cursor.TryGotoNext(i => i.MatchLdcI4(-1) && i.Next.Next.MatchLdarg(2) && i.Next.Next.Next.MatchLdcI4(13))) { throw new Exception("Could not locate int [x] = -1; if (context == 13) in IL.Terraria.UI.ItemSlot.Draw"); } byte indx = (byte)((VariableDefinition)cursor.Next.Next.Operand).Index; System.Reflection.MethodInfo callTo = typeof(Int32).GetMethod(nameof(Int32.ToString), new Type[] { }); if (!cursor.TryGotoNext(i => i.MatchLdloca(indx) && i.Next.MatchCall(callTo))) { throw new Exception("Could not locate call to ChatManager.DrawColorCodedStringWithShadow"); } cursor.Index += 2; cursor.Emit(Ldloc_1); cursor.EmitDelegate <Func <string, Item, string> >((ammoCount, weapon) => { DaesPlayer modPlayer = Main.LocalPlayer.GetModPlayer <DaesPlayer>(); Item ammo = modPlayer.GetItemForEndlessAmmoType(weapon.useAmmo); if (modPlayer.useEndlessAmmoFirst) { return(ammo.type > ItemID.None ? "Inf" : ammoCount); } if (ammoCount != "0") { return(ammoCount); } return(ammo.type > ItemID.None ? "Inf" : "0"); }); /* Resize text? * cursor.Emit(Stloc_S, indx); * cursor.Emit(Ldloc_S, indx); * * if (cursor.TryGotoNext(i => i.MatchLdcR4(0.8f))) { * cursor.Remove(); * cursor.Emit(Ldloc_S, indx); * cursor.EmitDelegate<Func<string, float>>((count) => { * * if (count != "∞") * return 0.8f; * * return 1.6f; * }); * } */ }
public static void HasAmmo(ILContext il) { ILCursor cursor = new ILCursor(il); cursor.Emit(Ldarg_0); cursor.Emit(Ldarg_1); cursor.EmitDelegate <Func <Player, Item, bool> >((player, item) => { DaesPlayer modPlayer = player.GetModPlayer <DaesPlayer>(); return(modPlayer.GetItemForEndlessAmmoType(item.useAmmo).type > ItemID.None); }); ILLabel label = il.DefineLabel(); cursor.Emit(Brfalse, label); cursor.Emit(Ldc_I4_1); cursor.Emit(Ret); cursor.MarkLabel(label); }
public override void DrawEffects(int i, int j, int type, SpriteBatch spriteBatch, ref Color drawColor, ref int nextSpecialDrawIndex) { DaesPlayer modPlayer = Main.LocalPlayer.GetModPlayer <DaesPlayer>(); if (modPlayer.hasAnomalyDetector) { foreach (AnomalyHighlights anomalyHighlights in DataContainer.Anomalies) { if (!anomalyHighlights.Tiles.Contains(type)) { continue; } byte R = anomalyHighlights.R; byte G = anomalyHighlights.G; byte B = anomalyHighlights.B; if (drawColor.R < R) { drawColor.R = R; } if (drawColor.G < G) { drawColor.G = G; } if (drawColor.B < B) { drawColor.B = B; } drawColor.A = Main.mouseTextColor; if (!Main.gamePaused && !Main.gameInactive && rand.Next(120) == 0) { Dust dust = Dust.NewDustDirect(new Vector2(i * 16, j * 16), 16, 16, anomalyHighlights.DustType, 0f, 0f, 150, default, 0.3f);
public override void Draw(SpriteBatch spriteBatch) { // Hide the crafting menu Main.HidePlayerCraftingMenu = true; // Get reference to current player DaesPlayer player = Main.LocalPlayer.GetModPlayer <DaesPlayer>(); /** * If the player: * - has closed their inventory * - has opened a chest * - has opened another npcs shop * - is no longer in range of the gnome * Close the reforge ui. */ if (!Main.playerInventory || Main.player[Main.myPlayer].chest != -1 || Main.npcShop != 0 || Main.player[Main.myPlayer].talkNPC == -1) { HideInterface(player); return; } /** * Create a point for where the mouse is. Used to check whether the * cursor is inside certain regions of the interface. */ Point mousePoint = new Point(Main.mouseX, Main.mouseY); // Calculate Position of ItemSlot Main.inventoryScale = 0.85f; float xPosition = 50f; float yPosition = Main.instance.invBottom + 12f; // Pre-calculate slot width and height. int slotWidth = (int)(Main.inventoryBackTexture.Width * Main.inventoryScale); int slotHeight = (int)(Main.inventoryBackTexture.Height * Main.inventoryScale); // Create our "collision" rectangle Rectangle slotRectangle = new Rectangle((int)xPosition, (int)yPosition, slotWidth, slotHeight); if (slotRectangle.Contains(mousePoint)) { Main.LocalPlayer.mouseInterface = true; if (Main.mouseLeftRelease && Main.mouseLeft) { // Item.Prefix(-3) checks whether an item can be reforged. if (Main.mouseItem.IsAir || Main.mouseItem.Prefix(-3)) { Utils.Swap(ref player.ReforgeItem, ref Main.mouseItem); if (!Main.mouseItem.IsAir || !player.ReforgeItem.IsAir) { Main.PlaySound(SoundID.Grab); } } UpdateCurrentPrefixesForItem(player.ReforgeItem); } else { ItemSlot.MouseHover(new Item[] { player.ReforgeItem }, ItemSlot.Context.PrefixItem); } } player.ReforgeItem.newAndShiny = false; ItemSlot.Draw(Main.spriteBatch, new Item[] { player.ReforgeItem }, ItemSlot.Context.PrefixItem, 0, new Vector2(xPosition, yPosition), default); // If there's no purchasable prefixes, stop drawing the interface. if (purchasableItemsLength > 0) { xPosition += slotWidth + 8; string labelText = Language.GetTextValue(ValueIDPrefix + "ShopLabel"); ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, labelText, new Vector2(xPosition, yPosition), Color.White, 0f, Vector2.Zero, Vector2.One, -1f, 2f); yPosition -= slotHeight / 2; // List all purchasable prefixes. for (int i = 0; i < purchasableItemsLength; i++) { yPosition += slotHeight + 8; Item item = purchasableItems[i]; int buyCost = item.value * 2; string price = FormatCoinCost(buyCost); // Draw item slot containing the item with the purchasable prefix ItemSlot.Draw(Main.spriteBatch, purchasableItems, ItemSlot.Context.CraftingMaterial, i, new Vector2(xPosition, yPosition), default); // Draw the cost of the item ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, price, new Vector2(xPosition + slotWidth + 8, yPosition), Color.White, 0f, Vector2.Zero, Vector2.One, -1f, 2f); // TODO: Investigate this re-assignment purchasableItems[i] = item; slotRectangle = new Rectangle((int)xPosition, (int)yPosition, slotWidth, slotHeight); if (!slotRectangle.Contains(mousePoint)) { continue; } Main.LocalPlayer.mouseInterface = true; ItemSlot.MouseHover(purchasableItems, ItemSlot.Context.PrefixItem, i); // Check if the player has clicked to buy the reforge AND can afford it. if (Main.mouseItem.IsAir && Main.mouseLeftRelease && Main.mouseLeft && Main.player[Main.myPlayer].CanBuyItem(buyCost, -1)) { Main.mouseLeft = false; Main.mouseLeftRelease = false; Main.player[Main.myPlayer].BuyItem(buyCost, -1); item.favorited = player.ReforgeItem.favorited; item.stack = player.ReforgeItem.stack; item.position.X = Main.player[Main.myPlayer].position.X + (Main.player[Main.myPlayer].width / 2) - (item.width / 2); item.position.Y = Main.player[Main.myPlayer].position.Y + (Main.player[Main.myPlayer].height / 2) - (item.height / 2); Main.mouseItem = item; player.ReforgeItem.TurnToAir(); ItemText.NewText(item, item.stack, noStack: true); Main.PlaySound(SoundID.Item37); ClearCurrentPrefixes(); // player.ReforgeItem = item; // ClearCurrentPrefixes(); break; } } } base.Draw(spriteBatch); }
public override bool CanUseItem(Player player) { DaesPlayer modPlayer = player.GetModPlayer <DaesPlayer>(); return(!modPlayer.hasEndlessAmmo); }
public static void PickAmmo(ILContext il) { ILLabel UseNormalAmmoLabel = il.DefineLabel(); ILLabel UseEndlessAmmoLabel = il.DefineLabel(); ILLabel CanShootLabel = il.DefineLabel(); // Item item = new Item(); // bool flag = false; ILCursor cursor = new ILCursor(il); if (!cursor.TryGotoNext(i => i.MatchLdcI4(0) && i.Next.MatchStloc(1))) { throw new Exception("Could not locate flag = false"); } cursor.Index += 2; // bool useEndlessAmmoFirst = Delegate(this); cursor.Emit(Ldarg_0); // Player player cursor.EmitDelegate <Func <Player, bool> >((player) => { DaesPlayer modPlayer = player.GetModPlayer <DaesPlayer>(); return(modPlayer.useEndlessAmmoFirst); }); cursor.Emit(Stloc_2); // if (useEndlessAmmoFirst == false) goto USE_NORMAL_AMMO; cursor.Emit(Ldloc_2); cursor.Emit(Brfalse, UseNormalAmmoLabel); // USE_ENDLESS_AMMO: cursor.MarkLabel(UseEndlessAmmoLabel); // item = Delegate(this, sItem); cursor.Emit(Ldarg_0); // Player player cursor.Emit(Ldarg_1); // Item weapon cursor.EmitDelegate <Func <Player, Item, Item> >((player, weapon) => { DaesPlayer modPlayer = player.GetModPlayer <DaesPlayer>(); Item playerAmmo = modPlayer.GetItemForEndlessAmmoType(weapon.useAmmo); return(playerAmmo); }); cursor.Emit(Stloc_0); ILLabel IfItemIsAirLabel = il.DefineLabel(); // if (item.type == 0) goto ITEM_IS_AIR; cursor.Emit(Ldloc_0); cursor.Emit(Ldfld, typeof(Item).GetField(nameof(Item.type))); cursor.Emit(Brfalse, IfItemIsAirLabel); // canShoot = true; cursor.Emit(Ldarg, 4); cursor.Emit(Ldc_I4_1); cursor.Emit(Stind_I1); // dontConsume = true; cursor.Emit(Ldc_I4_1); cursor.Emit(Starg, 7); // goto CAN_SHOOT; cursor.Emit(Br, CanShootLabel); // ITEM_IS_AIR: cursor.MarkLabel(IfItemIsAirLabel); // if (useEndlessAmmoFirst == false) goto CAN_SHOOT; cursor.Emit(Ldloc_2); cursor.Emit(Brfalse, CanShootLabel); // USE_NORMAL_AMMO: cursor.MarkLabel(UseNormalAmmoLabel); // .. if (!cursor.TryGotoNext(i => i.MatchLdarg(4) && i.Next.MatchLdindU1())) { throw new Exception("Could not locate canShoot == false conditional."); } // if (useEndlessAmmoFirst) goto CAN_SHOOT; ILLabel SkipAheadLabel = il.DefineLabel(); cursor.Emit(Ldloc_2); cursor.Emit(Brtrue, CanShootLabel); // if (item.type == 0) goto USE_ENDLESS_AMMO; cursor.Emit(Ldloc_0); cursor.Emit(Ldfld, typeof(Item).GetField(nameof(Item.type))); cursor.Emit(Brfalse, UseEndlessAmmoLabel); // CAN_SHOOT: cursor.MarkLabel(CanShootLabel); // if (!canShoot) return; // ... }
private void DrawAmmoPicker(SpriteBatch spriteBatch, DaesPlayer modPlayer) { int dx = LeftX; Color titleColor = new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor); Point mousePoint = new Point(Main.mouseX, Main.mouseY); Main.LocalPlayer.mouseInterface = true; Color locked = new Color(187, 187, 187, 187); float stringScale = 0.75f; float gap = 8; List <Item> ammos = new List <Item>(); float widestAmmoName = Main.fontMouseText.MeasureString($"{UNLOCK_AMOUNT} / {UNLOCK_AMOUNT}").X; float stringHeight = 0; foreach (Item ammoItem in DataContainer.AmmoItems) { if (ammoItem.ammo == AmmoPicker) { ammos.Add(ammoItem); Vector2 stringDimensions = Main.fontMouseText.MeasureString(ammoItem.Name); if (stringDimensions.X > widestAmmoName) { widestAmmoName = stringDimensions.X; } if (stringDimensions.Y > stringHeight) { stringHeight = stringDimensions.Y; } } } Vector2 stringLeftAlignedVertCenter = new Vector2(0, stringHeight / 2); widestAmmoName *= stringScale; stringHeight *= stringScale; float lineHeight = stringHeight * 0.6f; foreach (EndlessAmmoType ammoType in DataContainer.EndlessAmmoTypes) { if (ammoType.Type == AmmoPicker) { ChatManager.DrawColorCodedString(spriteBatch, Main.fontMouseText, ammoType.Title, new Vector2(dx, 84f), titleColor, 0, Vector2.Zero, Vector2.One * 0.75f); break; } } float unit = 56 * Main.inventoryScale; Rect dropdownRect = new Rect(dx, 105f, unit + widestAmmoName + gap, Main.inventoryScale * (52 + (56 * (ammos.Count - 1)))); // Math.Min(3, ammos.Count) LargeItemSlot.DrawPanel(spriteBatch, dropdownRect, Main.inventoryScale); Rect itemRect = new Rect(dx, 105, 52, 52); itemRect.Scale(Main.inventoryScale); Rect textRect = new Rect(dx, 105, unit + widestAmmoName, 52); textRect.Scale(1, Main.inventoryScale); Item hoveringAmmo = new Item(); int action = 0; int hoveringCount = 0; for (int i = 0; i < ammos.Count; i++) { Item ammo = ammos[i]; LargeItemSlot.DrawItem(spriteBatch, itemRect, ammo, Main.inventoryScale); Vector2 position = itemRect.Position(); position.X += unit; position.Y += unit / 2; int count = 0; bool unlocked = modPlayer.HasEndlessAmmoItemUnlocked(ammo.type); bool canUnlock = false; if (unlocked) { ChatManager.DrawColorCodedStringWithShadow( spriteBatch, Main.fontMouseText, ammo.Name, position, Color.White, 0f, stringLeftAlignedVertCenter, Vector2.One * stringScale ); } else { count = Math.Min(UNLOCK_AMOUNT, modPlayer.CountItemsInInventory(ammo.type)); canUnlock = count == UNLOCK_AMOUNT; position.Y -= lineHeight / 2; ChatManager.DrawColorCodedStringWithShadow( spriteBatch, Main.fontMouseText, ammo.Name, position, canUnlock ? UnlockColor : locked, 0f, stringLeftAlignedVertCenter, Vector2.One * stringScale ); position.Y += lineHeight; ChatManager.DrawColorCodedStringWithShadow( spriteBatch, Main.fontMouseText, $"{count} / {UNLOCK_AMOUNT}", position, canUnlock ? Color.White : locked, 0f, stringLeftAlignedVertCenter, Vector2.One * stringScale ); } if (itemRect.Contains(mousePoint)) { hoveringAmmo = ammo; } else if (textRect.Contains(mousePoint)) { hoveringCount = count; hoveringAmmo = ammo; if (unlocked) { action = 1; } else if (canUnlock) { action = 2; } else { action = 3; } } itemRect.Translate(0, unit); textRect.Translate(0, unit); } if (hoveringAmmo.type != ItemID.None) { switch (action) { case 0: Main.HoverItem = hoveringAmmo.Clone(); Main.HoverItem.ammo = 0; Main.HoverItem.material = false; Main.HoverItem.consumable = false; Main.instance.MouseText(hoveringAmmo.Name, hoveringAmmo.rare, 0); break; case 1: Main.instance.MouseText(string.Format("Select {0}", hoveringAmmo.Name)); if (Main.mouseLeft && Main.mouseLeftRelease) { modPlayer.SelectUnlockedAmmo(hoveringAmmo.type); Main.PlaySound(SoundID.Grab); AmmoPicker = AmmoID.None; } break; case 2: Main.instance.MouseText(string.Format("Unlock {0}", hoveringAmmo.Name)); if (Main.mouseLeft && Main.mouseLeftRelease) { if (modPlayer.UnlockEndlessAmmo(hoveringAmmo.type)) { Main.PlaySound(SoundID.Grab); } AmmoPicker = AmmoID.None; } break; case 3: Main.instance.MouseText(string.Format("Unlock {0} ({1} / {2})", hoveringAmmo.Name, hoveringCount, UNLOCK_AMOUNT)); break; } } if (!dropdownRect.Contains(mousePoint) && Main.mouseLeft && Main.mouseLeftRelease) { Main.PlaySound(SoundID.MenuClose); AmmoPicker = AmmoID.None; } }
public override void Draw(SpriteBatch spriteBatch) { DaesPlayer modPlayer = Main.LocalPlayer.GetModPlayer <DaesPlayer>(); if (!modPlayer.hasEndlessAmmo) { base.Draw(spriteBatch); return; } Main.inventoryScale = 0.6f; if (AmmoPicker != AmmoID.None) { DrawAmmoPicker(spriteBatch, modPlayer); base.Draw(spriteBatch); return; } else { AmmoPickerScroll = 0; } int dx = LeftX; Color titleColor = new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor); Point mousePoint = new Point(Main.mouseX, Main.mouseY); Rect checkboxRect = new Rect(dx, 84f, 16, 16); LargeItemSlot.DrawPanel(spriteBatch, checkboxRect, Main.inventoryScale); string EndlessAmmoLabel = "∞ Ammo"; ChatManager.DrawColorCodedString(spriteBatch, Main.fontMouseText, EndlessAmmoLabel, new Vector2(dx + 20, 84f), titleColor, 0, Vector2.Zero, Vector2.One * 0.75f); Rect slotRect = new Rect(52, 52); slotRect.Scale(Main.inventoryScale); int hoverSlot = -1; int hoverAmmoType = 0; Item hoverAmmo = new Item(); for (int i = 0; i < DataContainer.EndlessAmmoTypes.Length; i++) { int x = i / 4; int y = i % 4; slotRect.X = dx + x * DeltaX; slotRect.Y = (int)(105f + y * 56 * Main.inventoryScale); EndlessAmmoType AmmoType = DataContainer.EndlessAmmoTypes[i]; Item ammo = modPlayer.GetItemForEndlessAmmoType(AmmoType.Type); LargeItemSlot.DrawPanel(spriteBatch, slotRect, Main.inventoryScale); if (ammo.type != ItemID.None) { LargeItemSlot.DrawItem(spriteBatch, slotRect, ammo, Main.inventoryScale); } else { Texture2D texture = AmmoType.Texture; Vector2 position = slotRect.Center() - texture.Size() * Main.inventoryScale / 2f; spriteBatch.Draw(texture, position, texture.Frame(), PreviewColor, 0f, Vector2.Zero, Main.inventoryScale, SpriteEffects.None, 0f); } if (modPlayer.CanUnlockAmmoForType(AmmoType.Type)) { Vector2 hPosition = slotRect.Position(); hPosition.X += 24; hPosition.Y += 4; ChatManager.DrawColorCodedStringWithShadow( spriteBatch, Main.fontMouseText, "!", hPosition, UnlockColor, 0f, Vector2.Zero, Vector2.One * 0.6f ); } if (AmmoPicker == AmmoID.None && slotRect.Contains(mousePoint)) { hoverSlot = i; hoverAmmo = ammo; hoverAmmoType = AmmoType.Type; } } if (hoverSlot > -1) { Main.LocalPlayer.mouseInterface = true; if (hoverAmmo.type != ItemID.None) { Main.HoverItem = hoverAmmo.Clone(); Main.HoverItem.ammo = 0; Main.HoverItem.material = false; Main.HoverItem.consumable = false; Main.instance.MouseText(hoverAmmo.Name, hoverAmmo.rare, 0); } else { Main.instance.MouseText(DataContainer.EndlessAmmoTypes[hoverSlot].NoSelected); } if (Main.mouseLeft && Main.mouseLeftRelease) { Main.PlaySound(SoundID.MenuOpen); AmmoPicker = hoverAmmoType; } } if (checkboxRect.Contains(mousePoint)) { Main.LocalPlayer.mouseInterface = true; Main.instance.MouseText("Use endless ammo first."); if (Main.mouseLeft && Main.mouseLeftRelease) { Main.PlaySound(SoundID.MenuTick); modPlayer.useEndlessAmmoFirst = !modPlayer.useEndlessAmmoFirst; } } if (modPlayer.useEndlessAmmoFirst) { Vector2 position = checkboxRect.Center(); position.X += 2; position.Y -= 2; ChatManager.DrawColorCodedStringWithShadow(spriteBatch, Main.fontMouseText, "✓", position, Color.White, 0f, checkboxRect.Dimensions() / 2, Vector2.One * Main.inventoryScale); } base.Draw(spriteBatch); }
public override void UpdateAccessory(Player player, bool hideVisual) { DaesPlayer modPlayer = player.GetModPlayer <DaesPlayer>(); modPlayer.hasAnomalyDetector = true; }
public override void UpdateInventory(Player player) { DaesPlayer modPlayer = player.GetModPlayer <DaesPlayer>(); modPlayer.hasAnomalyDetector = true; }