Improve tool effectiveness subsystem

This commit is contained in:
Drew DeVault 2015-06-26 17:56:07 -06:00
parent fea89a9462
commit 61310e6bbb
27 changed files with 282 additions and 22 deletions

View File

@ -16,6 +16,8 @@ namespace TrueCraft.API.Logic
bool RenderOpaque { get; } bool RenderOpaque { get; }
byte LightModifier { get; } byte LightModifier { get; }
bool DiffuseSkyLight { get; } bool DiffuseSkyLight { get; }
ToolMaterial EffectiveToolMaterials { get; }
ToolType EffectiveTools { get; }
string DisplayName { get; } string DisplayName { get; }
BoundingBox? BoundingBox { get; } // NOTE: Will this eventually need to be metadata-aware? BoundingBox? BoundingBox { get; } // NOTE: Will this eventually need to be metadata-aware?
Tuple<int, int> GetTextureMap(byte metadata); Tuple<int, int> GetTextureMap(byte metadata);

View File

@ -8,36 +8,42 @@ namespace TrueCraft.API
/// <summary> /// <summary>
/// Enumerates the materials tools can be crafted from. /// Enumerates the materials tools can be crafted from.
/// </summary> /// </summary>
[Flags]
public enum ToolMaterial public enum ToolMaterial
{ {
/// <summary> /// <summary>
/// The tool is crafted from no material (special). /// The tool is crafted from no material (special).
/// </summary> /// </summary>
None, None = 1,
/// <summary> /// <summary>
/// The tool is crafted from wood. /// The tool is crafted from wood.
/// </summary> /// </summary>
Wood, Wood = 2,
/// <summary> /// <summary>
/// The tool is crafted from cobblestone. /// The tool is crafted from cobblestone.
/// </summary> /// </summary>
Stone, Stone = 4,
/// <summary> /// <summary>
/// The tool is crafted from iron ingots. /// The tool is crafted from iron ingots.
/// </summary> /// </summary>
Iron, Iron = 8,
/// <summary> /// <summary>
/// The tool is crafted from gold ingots. /// The tool is crafted from gold ingots.
/// </summary> /// </summary>
Gold, Gold = 16,
/// <summary> /// <summary>
/// The tool is crafted from diamonds. /// The tool is crafted from diamonds.
/// </summary> /// </summary>
Diamond Diamond = 32,
/// <summary>
/// Any tool material is valid in these circumstances.
/// </summary>
All = None | Wood | Stone | Iron | Gold | Diamond
} }
} }

16
TrueCraft.API/ToolType.cs Normal file
View File

@ -0,0 +1,16 @@
using System;
namespace TrueCraft.API
{
[Flags]
public enum ToolType
{
None = 1,
Pickaxe = 2,
Axe = 4,
Shovel = 8,
Hoe = 16,
Sword = 32,
All = None | Pickaxe | Axe | Shovel | Hoe | Sword
}
}

View File

@ -106,6 +106,7 @@
<Compile Include="ArmorMaterial.cs" /> <Compile Include="ArmorMaterial.cs" />
<Compile Include="Server\PlayerJoinedQuitEventArgs.cs" /> <Compile Include="Server\PlayerJoinedQuitEventArgs.cs" />
<Compile Include="World\ChunkGeneratedEventArgs.cs" /> <Compile Include="World\ChunkGeneratedEventArgs.cs" />
<Compile Include="ToolType.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup /> <ItemGroup />

View File

@ -31,6 +31,9 @@ namespace TrueCraft.Core.Test.Logic
EntityManager = new Mock<IEntityManager>(); EntityManager = new Mock<IEntityManager>();
User = new Mock<IRemoteClient>(); User = new Mock<IRemoteClient>();
BlockRepository = new Mock<IBlockRepository>(); BlockRepository = new Mock<IBlockRepository>();
var itemRepository = new ItemRepository();
BlockProvider.BlockRepository = BlockRepository.Object;
BlockProvider.ItemRepository = itemRepository;
User.SetupGet(u => u.World).Returns(World.Object); User.SetupGet(u => u.World).Returns(World.Object);
User.SetupGet(u => u.Server).Returns(Server.Object); User.SetupGet(u => u.Server).Returns(Server.Object);
@ -67,7 +70,7 @@ namespace TrueCraft.Core.Test.Logic
EntityManager.Verify(m => m.SpawnEntity(It.Is<ItemEntity>(e => e.Item.ID == 10))); EntityManager.Verify(m => m.SpawnEntity(It.Is<ItemEntity>(e => e.Item.ID == 10)));
World.Verify(w => w.SetBlockID(Coordinates3D.Zero, 0)); World.Verify(w => w.SetBlockID(Coordinates3D.Zero, 0));
blockProvider.Protected().Setup<ItemStack[]>("GetDrop", ItExpr.IsAny<BlockDescriptor>()) blockProvider.Protected().Setup<ItemStack[]>("GetDrop", ItExpr.IsAny<BlockDescriptor>(), ItExpr.IsAny<ItemStack>())
.Returns(() => new[] { new ItemStack(12) }); .Returns(() => new[] { new ItemStack(12) });
blockProvider.Object.BlockMined(descriptor, BlockFace.PositiveY, World.Object, User.Object); blockProvider.Object.BlockMined(descriptor, BlockFace.PositiveY, World.Object, User.Object);
EntityManager.Verify(m => m.SpawnEntity(It.Is<ItemEntity>(e => e.Item.ID == 12))); EntityManager.Verify(m => m.SpawnEntity(It.Is<ItemEntity>(e => e.Item.ID == 12)));

View File

@ -44,7 +44,24 @@ namespace TrueCraft.Core.Logic
public void GenerateDropEntity(BlockDescriptor descriptor, IWorld world, IMultiplayerServer server, ItemStack item) public void GenerateDropEntity(BlockDescriptor descriptor, IWorld world, IMultiplayerServer server, ItemStack item)
{ {
var entityManager = server.GetEntityManagerForWorld(world); var entityManager = server.GetEntityManagerForWorld(world);
var items = GetDrop(descriptor, item); var items = new ItemStack[0];
var type = ToolType.None;
var material = ToolMaterial.None;
var held = ItemRepository.GetItemProvider(item.ID);
if (held is ToolItem)
{
var tool = held as ToolItem;
material = tool.Material;
type = tool.ToolType;
}
if ((EffectiveTools & type) > 0)
{
if ((EffectiveToolMaterials & material) > 0)
items = GetDrop(descriptor, item);
}
foreach (var i in items) foreach (var i in items)
{ {
if (i.Empty) continue; if (i.Empty) continue;
@ -200,6 +217,10 @@ namespace TrueCraft.Core.Logic
/// </summary> /// </summary>
public virtual string DisplayName { get { return string.Empty; } } public virtual string DisplayName { get { return string.Empty; } }
public virtual ToolMaterial EffectiveToolMaterials { get { return ToolMaterial.All; } }
public virtual ToolType EffectiveTools { get { return ToolType.All; } }
public virtual Tuple<int, int> GetTextureMap(byte metadata) public virtual Tuple<int, int> GetTextureMap(byte metadata)
{ {
return null; return null;

View File

@ -24,6 +24,14 @@ namespace TrueCraft.Core.Logic.Blocks
return new Tuple<int, int>(2, 2); return new Tuple<int, int>(2, 2);
} }
public override ToolType EffectiveTools
{
get
{
return ToolType.Pickaxe;
}
}
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item) protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
{ {
return new[] { new ItemStack(CoalItem.ItemID, 1, descriptor.Metadata) }; return new[] { new ItemStack(CoalItem.ItemID, 1, descriptor.Metadata) };

View File

@ -19,7 +19,21 @@ namespace TrueCraft.Core.Logic.Blocks
public override bool Opaque { get { return false; } } public override bool Opaque { get { return false; } }
//TODO: Mark this as a block that diffuses sun light. public override bool DiffuseSkyLight
{
get
{
return true;
}
}
public override ToolType EffectiveTools
{
get
{
return ToolType.Sword;
}
}
public override string DisplayName { get { return "Cobweb"; } } public override string DisplayName { get { return "Cobweb"; } }
@ -30,11 +44,7 @@ namespace TrueCraft.Core.Logic.Blocks
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item) protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
{ {
var provider = ItemRepository.GetItemProvider(item.ID);
if (provider is SwordItem)
return new[] { new ItemStack(StringItem.ItemID, 1, descriptor.Metadata) }; return new[] { new ItemStack(StringItem.ItemID, 1, descriptor.Metadata) };
else
return new ItemStack[0];
} }
} }
} }

View File

@ -46,5 +46,21 @@ namespace TrueCraft.Core.Logic.Blocks
{ {
get { return false; } get { return false; }
} }
public override ToolMaterial EffectiveToolMaterials
{
get
{
return ToolMaterial.Iron | ToolMaterial.Diamond;
}
}
public override ToolType EffectiveTools
{
get
{
return ToolType.Pickaxe;
}
}
} }
} }

View File

@ -19,6 +19,22 @@ namespace TrueCraft.Core.Logic.Blocks
public override string DisplayName { get { return "Diamond Ore"; } } public override string DisplayName { get { return "Diamond Ore"; } }
public override ToolMaterial EffectiveToolMaterials
{
get
{
return ToolMaterial.Iron | ToolMaterial.Diamond;
}
}
public override ToolType EffectiveTools
{
get
{
return ToolType.Pickaxe;
}
}
public override Tuple<int, int> GetTextureMap(byte metadata) public override Tuple<int, int> GetTextureMap(byte metadata)
{ {
return new Tuple<int, int>(2, 3); return new Tuple<int, int>(2, 3);

View File

@ -46,5 +46,21 @@ namespace TrueCraft.Core.Logic.Blocks
{ {
get { return false; } get { return false; }
} }
public override ToolMaterial EffectiveToolMaterials
{
get
{
return ToolMaterial.Iron | ToolMaterial.Diamond;
}
}
public override ToolType EffectiveTools
{
get
{
return ToolType.Pickaxe;
}
}
} }
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using TrueCraft.API.Logic; using TrueCraft.API.Logic;
using TrueCraft.API;
namespace TrueCraft.Core.Logic.Blocks namespace TrueCraft.Core.Logic.Blocks
{ {
@ -21,5 +22,21 @@ namespace TrueCraft.Core.Logic.Blocks
{ {
return new Tuple<int, int>(0, 2); return new Tuple<int, int>(0, 2);
} }
public override ToolMaterial EffectiveToolMaterials
{
get
{
return ToolMaterial.Iron | ToolMaterial.Diamond;
}
}
public override ToolType EffectiveTools
{
get
{
return ToolType.Pickaxe;
}
}
} }
} }

View File

@ -46,5 +46,21 @@ namespace TrueCraft.Core.Logic.Blocks
{ {
get { return false; } get { return false; }
} }
public override ToolMaterial EffectiveToolMaterials
{
get
{
return ToolMaterial.Stone | ToolMaterial.Iron | ToolMaterial.Diamond;
}
}
public override ToolType EffectiveTools
{
get
{
return ToolType.Pickaxe;
}
}
} }
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using TrueCraft.API.Logic; using TrueCraft.API.Logic;
using TrueCraft.API;
namespace TrueCraft.Core.Logic.Blocks namespace TrueCraft.Core.Logic.Blocks
{ {
@ -21,5 +22,21 @@ namespace TrueCraft.Core.Logic.Blocks
{ {
return new Tuple<int, int>(1, 2); return new Tuple<int, int>(1, 2);
} }
public override ToolMaterial EffectiveToolMaterials
{
get
{
return ToolMaterial.Stone | ToolMaterial.Iron | ToolMaterial.Diamond;
}
}
public override ToolType EffectiveTools
{
get
{
return ToolType.Pickaxe;
}
}
} }
} }

View File

@ -58,5 +58,21 @@ namespace TrueCraft.Core.Logic.Blocks
{ {
get { return true; } get { return true; }
} }
public override ToolMaterial EffectiveToolMaterials
{
get
{
return ToolMaterial.Stone | ToolMaterial.Iron | ToolMaterial.Diamond;
}
}
public override ToolType EffectiveTools
{
get
{
return ToolType.Pickaxe;
}
}
} }
} }

View File

@ -28,5 +28,21 @@ namespace TrueCraft.Core.Logic.Blocks
{ {
return new[] { new ItemStack(DyeItem.ItemID, (sbyte)new Random().Next(4, 8), (short)DyeItem.DyeType.LapisLazuli) }; return new[] { new ItemStack(DyeItem.ItemID, (sbyte)new Random().Next(4, 8), (short)DyeItem.DyeType.LapisLazuli) };
} }
public override ToolMaterial EffectiveToolMaterials
{
get
{
return ToolMaterial.Stone | ToolMaterial.Iron | ToolMaterial.Diamond;
}
}
public override ToolType EffectiveTools
{
get
{
return ToolType.Pickaxe;
}
}
} }
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using TrueCraft.API.Logic; using TrueCraft.API.Logic;
using TrueCraft.API;
namespace TrueCraft.Core.Logic.Blocks namespace TrueCraft.Core.Logic.Blocks
{ {
@ -21,5 +22,21 @@ namespace TrueCraft.Core.Logic.Blocks
{ {
return new Tuple<int, int>(5, 2); return new Tuple<int, int>(5, 2);
} }
public override ToolMaterial EffectiveToolMaterials
{
get
{
return ToolMaterial.Diamond;
}
}
public override ToolType EffectiveTools
{
get
{
return ToolType.Pickaxe;
}
}
} }
} }

View File

@ -78,13 +78,17 @@ namespace TrueCraft.Core.Logic.Blocks
return new Tuple<int, int>(2, 4); return new Tuple<int, int>(2, 4);
} }
public override ToolType EffectiveTools
{
get
{
return ToolType.Shovel;
}
}
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item) protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
{ {
var provider = ItemRepository.GetItemProvider(item.ID);
if (provider is ShovelItem)
return new[] { new ItemStack(SnowballItem.ItemID) }; return new[] { new ItemStack(SnowballItem.ItemID) };
else
return new ItemStack[0];
} }
} }
} }

View File

@ -6,7 +6,7 @@ using TrueCraft.API.Entities;
using TrueCraft.API; using TrueCraft.API;
using TrueCraft.API.World; using TrueCraft.API.World;
namespace TrueCraft namespace TrueCraft.Core.Logic
{ {
public class ItemRepository : IItemRepository public class ItemRepository : IItemRepository
{ {
@ -44,7 +44,7 @@ namespace TrueCraft
ItemProviders.Insert(i + 1, provider); ItemProviders.Insert(i + 1, provider);
} }
internal void DiscoverItemProviders() public void DiscoverItemProviders()
{ {
var providerTypes = new List<Type>(); var providerTypes = new List<Type>();
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())

View File

@ -58,6 +58,14 @@ namespace TrueCraft.Core.Logic.Items
return false; return false;
} }
} }
public override ToolType ToolType
{
get
{
return ToolType.Axe;
}
}
} }
public class WoodenAxeItem : AxeItem public class WoodenAxeItem : AxeItem

View File

@ -61,6 +61,14 @@ namespace TrueCraft.Core.Logic.Items
} }
} }
public override ToolType ToolType
{
get
{
return ToolType.Hoe;
}
}
public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user) public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user)
{ {
var id = world.GetBlockID(coordinates); var id = world.GetBlockID(coordinates);

View File

@ -58,6 +58,14 @@ namespace TrueCraft.Core.Logic.Items
return false; return false;
} }
} }
public override ToolType ToolType
{
get
{
return ToolType.Pickaxe;
}
}
} }
public class WoodenPickaxeItem : PickaxeItem public class WoodenPickaxeItem : PickaxeItem

View File

@ -58,6 +58,14 @@ namespace TrueCraft.Core.Logic.Items
return false; return false;
} }
} }
public override ToolType ToolType
{
get
{
return ToolType.Shovel;
}
}
} }
public class WoodenShovelItem : ShovelItem public class WoodenShovelItem : ShovelItem

View File

@ -60,6 +60,14 @@ namespace TrueCraft.Core.Logic.Items
return false; return false;
} }
} }
public override ToolType ToolType
{
get
{
return ToolType.Sword;
}
}
} }
public class WoodenSwordItem : SwordItem public class WoodenSwordItem : SwordItem

View File

@ -10,6 +10,8 @@ namespace TrueCraft.Core.Logic
{ {
public virtual ToolMaterial Material { get { return ToolMaterial.None; } } public virtual ToolMaterial Material { get { return ToolMaterial.None; } }
public virtual ToolType ToolType { get { return ToolType.None; } }
public virtual short BaseDurability { get { return 0; } } public virtual short BaseDurability { get { return 0; } }
public override sbyte MaximumStack { get { return 1; } } public override sbyte MaximumStack { get { return 1; } }

View File

@ -326,6 +326,7 @@
<Compile Include="Windows\ChestWindow.cs" /> <Compile Include="Windows\ChestWindow.cs" />
<Compile Include="TerrainGen\EmptyGenerator.cs" /> <Compile Include="TerrainGen\EmptyGenerator.cs" />
<Compile Include="Lighting\WorldLighter.cs" /> <Compile Include="Lighting\WorldLighter.cs" />
<Compile Include="Logic\ItemRepository.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup> <ItemGroup>

View File

@ -54,7 +54,6 @@
<Compile Include="Handlers\InteractionHandlers.cs" /> <Compile Include="Handlers\InteractionHandlers.cs" />
<Compile Include="Commands\DebugCommands.cs" /> <Compile Include="Commands\DebugCommands.cs" />
<Compile Include="Exceptions\PlayerDisconnectException.cs" /> <Compile Include="Exceptions\PlayerDisconnectException.cs" />
<Compile Include="ItemRepository.cs" />
<Compile Include="CraftingRepository.cs" /> <Compile Include="CraftingRepository.cs" />
<Compile Include="ServerConfiguration.cs" /> <Compile Include="ServerConfiguration.cs" />
<Compile Include="PhysicsEngine.cs" /> <Compile Include="PhysicsEngine.cs" />