Skip to content

Commit

Permalink
Added 2 separate accessories that make up the recipe for the Infinite…
Browse files Browse the repository at this point in the history
…Placement

Each accessory represents one of the functionalities present on the InfinitePlacement accessory
  • Loading branch information
Kirtle committed Jun 11, 2020
1 parent d922e45 commit e694d14
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 12 deletions.
2 changes: 2 additions & 0 deletions BuilderPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public override void Initialize()
public override void ResetEffects()
{
InfinitePlacement = false;
Player.tileRangeX = 5;
Player.tileRangeY = 4;
}

public override void ProcessTriggers(TriggersSet triggersSet)
Expand Down
23 changes: 12 additions & 11 deletions Items/InfinitePlacement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class InfinitePlacement : ModItem
{
public override void SetStaticDefaults()
{
Tooltip.SetDefault("Allows infinite placement");
Tooltip.SetDefault("Allows infinite range and fast placement");
}

public override void SetDefaults()
Expand Down Expand Up @@ -57,7 +57,7 @@ public override bool CanRightClick()
int maxAccessoryIndex = 5 + Main.LocalPlayer.extraAccessorySlots;
for (int i = 13; i < 13 + maxAccessoryIndex; i++)
{
if (Main.LocalPlayer.armor[i].type == item.type)
if (Main.LocalPlayer.armor[i].type == item.type)
return false;
}

Expand All @@ -80,19 +80,20 @@ public override void RightClick(Player player)
public override void UpdateAccessory(Player player, bool hideVisual)
{
player.AddBuff(mod.BuffType("InfinitePlacementBuff"), 90);
player.GetModPlayer<BuilderPlayer>().IsNormalAccessories = false;
player.blockRange += 55;
player.wallSpeed += 10;
player.tileSpeed += 50;
Player.tileRangeX = 65;
Player.tileRangeY = 55;
}

public override void AddRecipes()
{
//Not really worried about balancing at this point
ModRecipe modRecipe = new ModRecipe(mod);
modRecipe.AddIngredient(ItemID.LunarBar, 40);
modRecipe.AddIngredient(ItemID.FragmentNebula, 20);
modRecipe.AddIngredient(ItemID.FragmentSolar, 20);
modRecipe.AddIngredient(ItemID.FragmentStardust, 20);
modRecipe.AddIngredient(ItemID.FragmentVortex, 20);
modRecipe.AddTile(TileID.LunarCraftingStation);
modRecipe.AddIngredient(mod.GetItem("InfiniteUpgrade"), 1);
modRecipe.AddIngredient(mod.GetItem("PlacementWrench"), 1);
modRecipe.AddTile(TileID.TinkerersWorkbench);
modRecipe.SetResult(this);
modRecipe.AddRecipe();
}
Expand All @@ -102,9 +103,9 @@ public partial class InfinitePlacementTile : GlobalTile
{
public override void PlaceInWorld(int i, int j, Item item)
{
if (Main.LocalPlayer.GetModPlayer<BuilderPlayer>().InfinitePlacement)
if (Main.LocalPlayer.GetModPlayer<BuilderPlayer>().InfinitePlacement)
{
item.stack = item.maxStack + 1;
item.stack = item.maxStack + 1;
}
}
}
Expand Down
Binary file removed Items/InfinitePlacement2.png
Binary file not shown.
Binary file removed Items/InfinitePlacement3.png
Binary file not shown.
100 changes: 100 additions & 0 deletions Items/InfiniteUpgrade.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace BuilderEssentials.Items
{
class InfiniteUpgrade : ModItem
{
public override void SetStaticDefaults()
{
Tooltip.SetDefault("Allows infinite placement");
}

public override void SetDefaults()
{
item.accessory = true;
item.vanity = false;
item.width = 24;
item.height = 24;
item.value = Item.sellPrice(0, 10, 0, 0);
item.rare = ItemRarityID.Red;
}

protected (int index, Item accessory) FindDifferentEquippedExclusiveAccessory()
{
int maxAccessoryIndex = 5 + Main.LocalPlayer.extraAccessorySlots;
for (int i = 3; i < 3 + maxAccessoryIndex; i++)
{
Item otherAccessory = Main.LocalPlayer.armor[i];
if (!otherAccessory.IsAir &&
!item.IsTheSameAs(otherAccessory) &&
otherAccessory.modItem is InfinitePlacement)
{
return (i, otherAccessory);
}
}
return (-1, null);
}

public override bool CanEquipAccessory(Player player, int slot)
{
if (slot < 10)
{
int index = FindDifferentEquippedExclusiveAccessory().index;
if (index != -1)
return slot == index;
}
return base.CanEquipAccessory(player, slot);
}

public override bool CanRightClick()
{
int maxAccessoryIndex = 5 + Main.LocalPlayer.extraAccessorySlots;
for (int i = 13; i < 13 + maxAccessoryIndex; i++)
{
if (Main.LocalPlayer.armor[i].type == item.type)
return false;
}

if (FindDifferentEquippedExclusiveAccessory().accessory != null)
return true;

return base.CanRightClick();
}

public override void RightClick(Player player)
{
var (index, accessory) = FindDifferentEquippedExclusiveAccessory();
if (accessory != null)
{
Main.LocalPlayer.QuickSpawnClonedItem(accessory);
Main.LocalPlayer.armor[index] = item.Clone();
}
}

public override void UpdateAccessory(Player player, bool hideVisual)
{
player.AddBuff(mod.BuffType("InfinitePlacementBuff"), 90);
}

public override void AddRecipes()
{
//Not really worried about balancing at this point
ModRecipe modRecipe = new ModRecipe(mod);
modRecipe.AddIngredient(ItemID.LunarBar, 40);
modRecipe.AddIngredient(ItemID.FragmentNebula, 20);
modRecipe.AddIngredient(ItemID.FragmentSolar, 20);
modRecipe.AddIngredient(ItemID.FragmentStardust, 20);
modRecipe.AddIngredient(ItemID.FragmentVortex, 20);
modRecipe.AddTile(TileID.LunarCraftingStation);
modRecipe.SetResult(this);
modRecipe.AddRecipe();
}
}
}
Binary file added Items/InfiniteUpgrade.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
103 changes: 103 additions & 0 deletions Items/PlacementWrench.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace BuilderEssentials.Items
{
class PlacementWrench : ModItem
{
public override void SetStaticDefaults()
{
Tooltip.SetDefault("Allows infinite range");
}

public override void SetDefaults()
{
item.accessory = true;
item.vanity = false;
item.width = 24;
item.height = 24;
item.value = Item.sellPrice(0, 10, 0, 0);
item.rare = ItemRarityID.Red;
}

protected (int index, Item accessory) FindDifferentEquippedExclusiveAccessory()
{
int maxAccessoryIndex = 5 + Main.LocalPlayer.extraAccessorySlots;
for (int i = 3; i < 3 + maxAccessoryIndex; i++)
{
Item otherAccessory = Main.LocalPlayer.armor[i];
if (!otherAccessory.IsAir &&
!item.IsTheSameAs(otherAccessory) &&
otherAccessory.modItem is InfinitePlacement)
{
return (i, otherAccessory);
}
}
return (-1, null);
}

public override bool CanEquipAccessory(Player player, int slot)
{
if (slot < 10)
{
int index = FindDifferentEquippedExclusiveAccessory().index;
if (index != -1)
return slot == index;
}
return base.CanEquipAccessory(player, slot);
}

public override bool CanRightClick()
{
int maxAccessoryIndex = 5 + Main.LocalPlayer.extraAccessorySlots;
for (int i = 13; i < 13 + maxAccessoryIndex; i++)
{
if (Main.LocalPlayer.armor[i].type == item.type)
return false;
}

if (FindDifferentEquippedExclusiveAccessory().accessory != null)
return true;

return base.CanRightClick();
}

public override void RightClick(Player player)
{
var (index, accessory) = FindDifferentEquippedExclusiveAccessory();
if (accessory != null)
{
Main.LocalPlayer.QuickSpawnClonedItem(accessory);
Main.LocalPlayer.armor[index] = item.Clone();
}
}

public override void UpdateAccessory(Player player, bool hideVisual)
{
player.blockRange += 55;
player.wallSpeed += 10;
player.tileSpeed += 50;
Player.tileRangeX = 65;
Player.tileRangeY = 55;
}

public override void AddRecipes()
{
//Not really worried about balancing at this point
ModRecipe modRecipe = new ModRecipe(mod);
modRecipe.AddIngredient(ItemID.ArchitectGizmoPack, 1);
modRecipe.AddIngredient(ItemID.LaserRuler, 1);
modRecipe.AddIngredient(ItemID.Toolbox, 1);
modRecipe.AddIngredient(ItemID.Toolbelt, 1);
modRecipe.AddTile(TileID.AdamantiteForge);
modRecipe.SetResult(this);
modRecipe.AddRecipe();
}
}
}
Binary file added Items/PlacementWrench.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Items/PreHardmodeCraftingStation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class PreHardmodeCraftingStation : ModItem
{
public override void SetStaticDefaults()
{
Tooltip.SetDefault("PreHardmode Crafting Stations");
Tooltip.SetDefault("Pre Hardmode Crafting Stations");
}

public override void SetDefaults()
Expand Down
17 changes: 17 additions & 0 deletions UI/BasePanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Terraria.ModLoader.IO;

namespace BuilderEssentials.UI
{
Expand All @@ -27,6 +28,22 @@ public override void Update(GameTime gameTime)
{
if (button.IsMouseHovering)
Main.LocalPlayer.mouseInterface = true;

if (Main.mouseMiddle)
{
int posX = Main.mouseX;
int posY = Main.mouseY;

//Main.NewText("PosX: " + posX + " / PosY: " + posY);

Tile mouseTile = Main.tile[posX, posY];
//Impossible to convert Tile -> Item but possible to do Item -> Tile...
Main.LocalPlayer.PickTile(posX, posY, 9999);
Main.NewText("click");

//Middle click saves Tile
//Other key makes left click use middle click saved tile?
}
}

public void ChangeAccessories_OnClick(UIMouseEvent evt, UIElement listeningElement)
Expand Down

0 comments on commit e694d14

Please sign in to comment.