Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
DRKV333 committed Jan 8, 2018
2 parents c852d4a + 9f11312 commit 3c0178e
Show file tree
Hide file tree
Showing 48 changed files with 931 additions and 437 deletions.
2 changes: 2 additions & 0 deletions ContainerAdapters/CannonAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public bool InjectItem(int x, int y, Item item)

WorldGen.ShootFromCannon(originX, originY, angle, ammotype, item.damage, item.knockBack, Main.myPlayer);

item.stack--;

return true;
}
}
Expand Down
49 changes: 37 additions & 12 deletions ContainerAdapters/ChestAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace MechTransfer.ContainerAdapters
{
internal class ChestAdapter
{
private Mod mod;

public ChestAdapter(Mod mod)
{
this.mod = mod;
}

private int FindChest(int x, int y)
{
Tile tile = Main.tile[x, y];
Expand All @@ -30,15 +36,16 @@ private int FindChest(int x, int y)
return -1;
}

private void HandleChestItemChange(int chest, int slot)
private void HandleChestItemChange(int chest)
{
int targetPlayer = WhichPlayerInChest(chest);
if (targetPlayer != -1)
{
if (Main.netMode == 2)
{
Item item = Main.chest[chest].item[slot];
NetMessage.SendData(MessageID.SyncChestItem, targetPlayer, -1, null, chest, slot, item.stack, item.prefix, item.type);
ModPacket packet = mod.GetPacket();
packet.Write((byte)MechTransfer.ModMessageID.KickFromChest);
packet.Send(targetPlayer);
}
else if (Main.netMode == 0)
Recipe.FindRecipes();
Expand All @@ -64,16 +71,30 @@ public bool InjectItem(int x, int y, Item item)
if (c == -1)
return false;

bool injectedPartial = false;

if (item.maxStack > 1)
{
for (int i = 0; i < Main.chest[c].item.Length; i++)
{
Item chestItem = Main.chest[c].item[i];
if (item.IsTheSameAs(chestItem) && chestItem.stack < chestItem.maxStack)
{
chestItem.stack++;
HandleChestItemChange(c, i);
return true;
int spaceLeft = chestItem.maxStack - chestItem.stack;
if (spaceLeft >= item.stack)
{
chestItem.stack += item.stack;
item.stack = 0;
HandleChestItemChange(c);
return true;
}
else
{
item.stack -= spaceLeft;
chestItem.stack = chestItem.maxStack;
HandleChestItemChange(c);
injectedPartial = true;
}
}
}
}
Expand All @@ -82,13 +103,14 @@ public bool InjectItem(int x, int y, Item item)
{
if (Main.chest[c].item[i].IsAir)
{
Main.chest[c].item[i] = item;
HandleChestItemChange(c, i);
Main.chest[c].item[i] = item.Clone();
item.stack = 0;
HandleChestItemChange(c);
return true;
}
}

return false;
return injectedPartial;
}

public IEnumerable<Tuple<Item, object>> EnumerateItems(int x, int y)
Expand All @@ -111,8 +133,11 @@ public void TakeItem(int x, int y, object slot, int amount)
if (c == -1)
return;

TransferUtils.EatItem(ref Main.chest[c].item[(int)slot], amount);
HandleChestItemChange(c, (int)slot);
Main.chest[c].item[(int)slot].stack -= amount;
if (Main.chest[c].item[(int)slot].stack < 1)
Main.chest[c].item[(int)slot] = new Item();

HandleChestItemChange(c);
}
}
}
7 changes: 3 additions & 4 deletions ContainerAdapters/CrystalStandAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@ public bool InjectItem(int x, int y, Item item)
if (tile == null || !tile.active())
return false;

int originY = y - tile.frameY % 18;

if (DD2Event.WouldFailSpawningHere(x, originY))
if (DD2Event.WouldFailSpawningHere(x, y))
{
DD2Event.FailureMessage(-1);
return false;
}
else
{
DD2Event.SummonCrystal(x, originY);
DD2Event.SummonCrystal(x, y);
item.stack--;
return true;
}
}
Expand Down
12 changes: 5 additions & 7 deletions ContainerAdapters/ItemFrameAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ private TEItemFrame FindItemFrame(int x, int y)
if (tile == null || !tile.active())
return null;

int originX = x;
int originY = y;
if (tile.frameX % 36 != 0)
originX--;
if (tile.frameY != 0)
originY--;
int originX = x - tile.frameX % 36 / 18;
int originY = y - tile.frameY / 18;

int id = TEItemFrame.Find(originX, originY);
if (id == -1)
Expand All @@ -42,7 +38,9 @@ public bool InjectItem(int x, int y, Item item)
if (!frame.item.IsAir)
return false;

frame.item = item;
frame.item = item.Clone();
frame.item.stack = 1;
item.stack--;
HandleItemFrameChange(x, y, frame.ID);
return true;
}
Expand Down
77 changes: 77 additions & 0 deletions ContainerAdapters/MagicStorageInterfaceAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using MagicStorage;
using MagicStorage.Components;
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.DataStructures;

namespace MechTransfer.ContainerAdapters
{
internal class MagicStorageInterfaceAdapter
{
private TEStorageHeart FindHeart(int x, int y)
{
Point16 center = TEStorageComponent.FindStorageCenter(new Point16(x, y));
if (center.X == -1 && center.Y == -1)
return null;

TEStorageHeart heart = ((TEStorageCenter)TileEntity.ByPosition[center]).GetHeart();

return heart;
}

private void HandleStorageItemChange(TEStorageHeart heart)
{
if (Main.netMode == 2)
{
NetHelper.SendRefreshNetworkItems(heart.ID);
}
else if (Main.netMode == 0)
{
StorageGUI.RefreshItems();
}
}

public void KickMe()
{
Main.LocalPlayer.GetModPlayer<StoragePlayer>().CloseStorage();
}

public bool InjectItem(int x, int y, Item item)
{
int oldstack = item.stack;

TEStorageHeart targetHeart = FindHeart(x, y);
targetHeart.DepositItem(item);

if (oldstack != item.stack)
{
HandleStorageItemChange(targetHeart);
return true;
}
return false;
}

public IEnumerable<Tuple<Item, object>> EnumerateItems(int x, int y)
{
TEStorageHeart targetHeart = FindHeart(x, y);
foreach (var item in targetHeart.GetStoredItems())
{
yield return new Tuple<Item, object>(item, item.type);
}
}

public void TakeItem(int x, int y, object slot, int amount)
{
TEStorageHeart targetHeart = FindHeart(x, y);

Item toWithdraw = new Item();
toWithdraw.SetDefaults((int)slot);
toWithdraw.stack = amount;

targetHeart.TryWithdraw(toWithdraw);

HandleStorageItemChange(targetHeart);
}
}
}
9 changes: 6 additions & 3 deletions ContainerAdapters/OmniTurretAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ internal class OmniTurretAdapter
private int[] fireRate = new int[] { 11, 7, 0 };
private int[] shootSpeed = new int[] { 10, 10, 20 };

public OmniTurretAdapter(Mod m)
public OmniTurretAdapter(Mod mod)
{
mod = m;
this.mod = mod;
}

public void TakeItem(int x, int y, object slot, int amount)
Expand All @@ -31,7 +31,7 @@ public IEnumerable<Tuple<Item, object>> EnumerateItems(int x, int y)

public bool InjectItem(int x, int y, Item item)
{
if (!item.consumable || item.ammo == 0 || item.shoot == 0)
if (item.ammo == 0 || item.shoot == 0 || item.ammo == AmmoID.Rocket)
return false;

Tile tile = Main.tile[x, y];
Expand Down Expand Up @@ -76,6 +76,9 @@ public bool InjectItem(int x, int y, Item item)
packet.Send();
}

if (item.consumable)
item.stack--;

return true;
}
}
Expand Down
2 changes: 2 additions & 0 deletions ContainerAdapters/SnowballLauncherAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public bool InjectItem(int x, int y, Item item)
velocityY *= velocity;

Projectile.NewProjectile(position.X, position.Y, velocityX, velocityY, ProjectileID.SnowBallFriendly, 35, 3.5f, Main.myPlayer, 0, 0);

item.stack--;
return true;
}
}
Expand Down
37 changes: 23 additions & 14 deletions ContainerAdapters/WeaponRackAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ internal class WeaponRackAdapter
{
//By god, this weapon rack thing is a complete mess...

public Point16 FindOrigin(int x, int y, out bool something)
public Point16 FindOrigin(int x, int y, out bool facingRight)
{
Tile tile = Main.tile[x, y];

int originY = y - tile.frameY % 36 / 18 + 1;
int originY = y - tile.frameY / 18 + 1;

int realFrameX = 0;
int temp = Math.DivRem(tile.frameX, 5000, out realFrameX);
Expand All @@ -23,11 +23,11 @@ public Point16 FindOrigin(int x, int y, out bool something)
realFrameX = (temp - 1) * 18;
}

something = false;
facingRight = false;
if (realFrameX >= 54)
{
realFrameX -= 54;
something = true;
facingRight = true;
}

int originX = x - realFrameX / 18;
Expand All @@ -46,26 +46,34 @@ public void HandleRackItemChange(int x, int y)

public void TakeItem(int x, int y, object slot, int amount)
{
bool something;
Point16 origin = FindOrigin(x, y, out something);
bool facingRight;
Point16 origin = FindOrigin(x, y, out facingRight);

Main.tile[origin.X, origin.Y].frameX = 0;
Main.tile[origin.X + 1, origin.Y].frameX = 18;
if (facingRight)
{
Main.tile[origin.X, origin.Y].frameX = 54;
Main.tile[origin.X + 1, origin.Y].frameX = 72;
}
else
{
Main.tile[origin.X, origin.Y].frameX = 0;
Main.tile[origin.X + 1, origin.Y].frameX = 18;
}

HandleRackItemChange(origin.X, origin.Y);
}

public IEnumerable<Tuple<Item, object>> EnumerateItems(int x, int y)
{
bool something;
Point16 origin = FindOrigin(x, y, out something);
bool facingRight;
Point16 origin = FindOrigin(x, y, out facingRight);

if (Main.tile[origin.X, origin.Y].frameX < 5000)
yield break; //Empty

Item item = new Item();

if (something)
if (facingRight)
{
item.netDefaults(Main.tile[origin.X, origin.Y].frameX - 20100);
item.prefix = (byte)(Main.tile[origin.X + 1, origin.Y].frameX - 25000);
Expand All @@ -84,13 +92,13 @@ public bool InjectItem(int x, int y, Item item)
if (!Main.LocalPlayer.ItemFitsWeaponRack(item))
return false;

bool something;
Point16 origin = FindOrigin(x, y, out something);
bool facingRight;
Point16 origin = FindOrigin(x, y, out facingRight);

if (Main.tile[origin.X, origin.Y].frameX >= 5000)
return false; //Already has item

if (something)
if (facingRight)
{
Main.tile[origin.X, origin.Y].frameX = (short)(item.netID + 20100);
Main.tile[origin.X + 1, origin.Y].frameX = (short)(item.prefix + 25000);
Expand All @@ -103,6 +111,7 @@ public bool InjectItem(int x, int y, Item item)

HandleRackItemChange(origin.X, origin.Y);

item.stack--;
return true;
}
}
Expand Down
19 changes: 19 additions & 0 deletions Interfaces.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Terraria;
using Terraria.DataStructures;

namespace MechTransfer
{
public interface ITransferTarget
{
ushort Type { get; }

bool Receive(TransferUtils agent, Point16 location, Item item);
}

public interface ITransferPassthrough
{
ushort Type { get; }

bool ShouldPassthrough(TransferUtils agent, Point16 location, Item item);
}
}
Binary file added Items/InverseTransferFilterItem.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Items/InverseTransferFilterItem.xcf
Binary file not shown.
Binary file added Items/MagicStorageInterfaceItem.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Items/MagicStorageInterfaceItem.xcf
Binary file not shown.
Loading

0 comments on commit 3c0178e

Please sign in to comment.