First Machine Age's Mods (Combined repo.)
Révision | e59f178d54935d61280116918ded5a2bb61496ca (tree) |
---|---|
l'heure | 2020-07-20 14:20:56 |
Auteur | melchior <melchior@user...> |
Commiter | melchior |
W.I.P. Generic Steel Item class "universal?'
@@ -3,10 +3,13 @@ using System.Collections.Generic; | ||
3 | 3 | |
4 | 4 | using System.Linq; |
5 | 5 | using System.Threading; |
6 | + | |
6 | 7 | using Newtonsoft.Json.Linq; |
8 | + | |
7 | 9 | using Vintagestory.API.Client; |
8 | 10 | using Vintagestory.API.Common; |
9 | 11 | using Vintagestory.API.Config; |
12 | +using Vintagestory.GameContent; | |
10 | 13 | using Vintagestory.ServerMods; |
11 | 14 | |
12 | 15 | namespace ElementalTools |
@@ -14,6 +17,7 @@ namespace ElementalTools | ||
14 | 17 | public partial class ElementalToolsSystem : ModSystem |
15 | 18 | { |
16 | 19 | internal const string malletItemKey = @"ItemMallet"; |
20 | + internal const string genericSteelSwordKey = @"Steel_ItemSword"; | |
17 | 21 | internal const string pack_carburizationBlockKey = @"pack_carburization"; |
18 | 22 | internal const string pack_stateFired = @"fired"; |
19 | 23 | internal const string malletAssetKey = @"mallet"; |
@@ -37,6 +41,9 @@ namespace ElementalTools | ||
37 | 41 | private void RegisterItemClasses( ) |
38 | 42 | { |
39 | 43 | CoreAPI.RegisterItemClass(malletItemKey, typeof(ItemMallet)); |
44 | + | |
45 | + CoreAPI.RegisterItemClass(genericSteelSwordKey, typeof(SteelItem<ItemSword>) ); | |
46 | + | |
40 | 47 | } |
41 | 48 | |
42 | 49 | private void RegisterBlockClasses( ) |
@@ -73,9 +73,8 @@ | ||
73 | 73 | <Compile Include="Block\PackCarburization.cs" /> |
74 | 74 | <Compile Include="BlockEntities\PackCarburizationEntity.cs" /> |
75 | 75 | <Compile Include="Helpers.cs" /> |
76 | - <Compile Include="Items\ItemTemperableMetal.cs" /> | |
77 | 76 | <Compile Include="General\IAmSteel.cs" /> |
78 | - <Compile Include="General\ElementOfSteel.cs" /> | |
77 | + <Compile Include="Items\SteelItem.cs" /> | |
79 | 78 | </ItemGroup> |
80 | 79 | <ItemGroup> |
81 | 80 | <Folder Include="Items\" /> |
@@ -140,6 +139,7 @@ | ||
140 | 139 | <None Include="assets\fma\recipes\grid\remapping\blister_steel_mappings.json"> |
141 | 140 | <CopyToOutputDirectory>Always</CopyToOutputDirectory> |
142 | 141 | </None> |
142 | + <None Include="General\FactoryOfSteel.cs" /> | |
143 | 143 | </ItemGroup> |
144 | 144 | <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> |
145 | 145 | </Project> |
\ No newline at end of file |
@@ -1,28 +0,0 @@ | ||
1 | -using System; | |
2 | - | |
3 | -using Vintagestory.API.Common; | |
4 | -using Vintagestory.API.Datastructures; | |
5 | -using Vintagestory.API.MathTools; | |
6 | - | |
7 | -namespace ElementalTools | |
8 | -{ | |
9 | - public abstract class ElementOfSteel<T> : IAmSteel where T : CollectibleObject | |
10 | - { | |
11 | - public virtual bool Hardenable { | |
12 | - get; set; | |
13 | - } | |
14 | - | |
15 | - public virtual HardnessState Hardness { | |
16 | - get; set; | |
17 | - } | |
18 | - | |
19 | - public virtual bool Sharpenable { | |
20 | - get; set; | |
21 | - } | |
22 | - | |
23 | - public virtual SharpnessState Sharpness { | |
24 | - get; set; | |
25 | - } | |
26 | - } | |
27 | -} | |
28 | - |
@@ -0,0 +1,61 @@ | ||
1 | +using System; | |
2 | + | |
3 | +//using System.CodeDom; | |
4 | +using System.Reflection; | |
5 | +using System.Reflection.Emit; | |
6 | +using System.Threading; | |
7 | + | |
8 | +using Vintagestory.API.Common; | |
9 | +using Vintagestory.API.Datastructures; | |
10 | +using Vintagestory.API.MathTools; | |
11 | + | |
12 | + | |
13 | + | |
14 | + | |
15 | +namespace ElementalTools | |
16 | +{ | |
17 | + /// <summary> | |
18 | + /// Abstract Factory of (Item) Steel behavior inheriting things | |
19 | + /// </summary> | |
20 | + public static class FactoryOfSteel | |
21 | + { | |
22 | + private static Assembly thineOwnAssembly; | |
23 | + private static AssemblyName steelAssemblyName; | |
24 | + private static AssemblyBuilder stAsmBuilder; | |
25 | + | |
26 | + static FactoryOfSteel() | |
27 | + { | |
28 | + thineOwnAssembly = typeof(FactoryOfSteel).Assembly; | |
29 | + AppDomain localAppDomain = Thread.GetDomain( ); | |
30 | + steelAssemblyName = new AssemblyName(@"Dynamic_Steel"); | |
31 | + stAsmBuilder = localAppDomain.DefineDynamicAssembly( | |
32 | + steelAssemblyName, | |
33 | + AssemblyBuilderAccess.RunAndCollect);//? | |
34 | + } | |
35 | + | |
36 | + /// <summary> | |
37 | + /// Emit Dynamic class of specified 'ResultingClassName'. | |
38 | + /// </summary> | |
39 | + /// <param name="ResultingClassName">Resulting class name.</param> | |
40 | + public static Item ManufactureItemClass( string resultingClassName, Item original ) | |
41 | + { | |
42 | + ModuleBuilder moduleBuilder = stAsmBuilder.DefineDynamicModule(resultingClassName); | |
43 | + | |
44 | + | |
45 | + | |
46 | + //Item customItemClass = original.GetType( ); | |
47 | + | |
48 | + //Generate class & remap methods to Steely ones... | |
49 | + | |
50 | + //var fWrapper = SourceItem.GetAttackPower; | |
51 | + | |
52 | + | |
53 | + return customItemClass; | |
54 | + } | |
55 | + | |
56 | + | |
57 | + | |
58 | + | |
59 | + } | |
60 | +} | |
61 | + |
@@ -1,15 +1,50 @@ | ||
1 | 1 | using System; |
2 | + | |
3 | +using Vintagestory.API.Common; | |
4 | + | |
2 | 5 | namespace ElementalTools |
3 | 6 | { |
4 | 7 | public interface IAmSteel |
5 | 8 | { |
6 | - bool Sharpenable { get; set; } | |
7 | - bool Hardenable { get; set; } | |
8 | - SharpnessState Sharpness { get; set; }//To sharpen - what unit if numerical? | |
9 | - HardnessState Hardness { get; set; }//To harden - Perhaps translate these to brinell units... | |
9 | + //Static read-only properties from Item Def. | |
10 | + string Name { get; }//Blister, Shear, Cast, Damascus...mostly descriptive | |
11 | + bool Sharpenable { get; } | |
12 | + bool Hardenable { get; } | |
13 | + | |
14 | + /// <summary> | |
15 | + /// Read Sharpness; Dynamic properties from ItemStack - attribs | |
16 | + /// </summary> | |
17 | + /// <param name="someStack">Source stack.</param> | |
18 | + SharpnessState Sharpness(ItemStack someStack); | |
19 | + | |
20 | + /// <summary> | |
21 | + /// Set Sharpness | |
22 | + /// </summary> | |
23 | + /// <param name="someStack">Some stack.</param> | |
24 | + /// <param name="set">Value.</param> | |
25 | + void Sharpness(ItemStack someStack, SharpnessState set);//Apply sharpen - what unit if numerical? | |
26 | + | |
27 | + /// <summary> | |
28 | + /// Read Harness | |
29 | + /// </summary> | |
30 | + /// <param name="someStack">Some stack.</param> | |
31 | + HardnessState Hardness(ItemStack someStack); | |
32 | + | |
33 | + /// <summary> | |
34 | + /// Set Hardness | |
35 | + /// </summary> | |
36 | + /// <param name="someStack">Some stack.</param> | |
37 | + /// <param name="set">Value.</param> | |
38 | + void Hardness(ItemStack someStack, HardnessState set);//Apply harden - Perhaps translate these to brinell units... | |
10 | 39 | |
11 | 40 | } |
12 | 41 | |
42 | + /// <summary> | |
43 | + /// "Sharpness" factor of working edge...only where applicable...relative vs. default tool/arm | |
44 | + /// </summary> | |
45 | + /// <remarks> | |
46 | + /// Affects: (GetMiningSpeed) , (GetAttackPower), (DamageItem), (OnConsumedByCrafting) | |
47 | + /// </remarks> | |
13 | 48 | public enum SharpnessState : byte |
14 | 49 | { |
15 | 50 | Rough = 0,//Unsharpened state *Default* |
@@ -20,6 +55,12 @@ namespace ElementalTools | ||
20 | 55 | Razor, |
21 | 56 | } |
22 | 57 | |
58 | + /// <summary> | |
59 | + /// The metals crystal state; changed only by tempering/quenching/annealing | |
60 | + /// </summary> | |
61 | + /// <remarks> | |
62 | + /// Reduces wear - with a penalty of random catastrophic failure... | |
63 | + /// </remarks> | |
23 | 64 | public enum HardnessState : byte |
24 | 65 | { |
25 | 66 | Soft = 0, |
@@ -3,7 +3,9 @@ using System.Collections; | ||
3 | 3 | using System.Collections.Generic; |
4 | 4 | using System.Linq; |
5 | 5 | using System.Text; |
6 | + | |
6 | 7 | using Vintagestory.API.Common; |
8 | +using Vintagestory.API.Datastructures; | |
7 | 9 | |
8 | 10 | namespace ElementalTools |
9 | 11 | { |
@@ -59,6 +61,14 @@ namespace ElementalTools | ||
59 | 61 | } |
60 | 62 | return originalAsset.Code; |
61 | 63 | } |
64 | + | |
65 | + //Why C# 7.0 ? WHY?!?! | |
66 | + public static T GetEnum<T>(this ITreeAttribute treeAttr, string keyword, T defaultValue = default(T)) where T : System.Enum | |
67 | + { | |
68 | + | |
69 | + return defaultValue; | |
70 | + } | |
71 | + | |
62 | 72 | } |
63 | 73 | } |
64 | 74 |
@@ -1,16 +0,0 @@ | ||
1 | -using System; | |
2 | - | |
3 | -using Vintagestory.API.Common; | |
4 | -using Vintagestory.API.Config; | |
5 | -using Vintagestory.API.MathTools; | |
6 | - | |
7 | -namespace ElementalTools | |
8 | -{ | |
9 | - public class ItemTemperableMetal : Item | |
10 | - { | |
11 | - | |
12 | - | |
13 | - | |
14 | - } | |
15 | -} | |
16 | - |
@@ -0,0 +1,101 @@ | ||
1 | +using System; | |
2 | +using System.Text; | |
3 | + | |
4 | +using Vintagestory.API.Common; | |
5 | +using Vintagestory.GameContent; | |
6 | + | |
7 | +namespace ElementalTools | |
8 | +{ | |
9 | + /// <summary> | |
10 | + /// GENERIC Steel item. (Tool / Weapon / Armor...anything) [Possibly: Temperable and/or Hardenable ] | |
11 | + /// </summary> | |
12 | + public class SteelItem<T>: Item, IAmSteel where T : Item | |
13 | + { | |
14 | + internal const string hardenableKeyword = @"hardenable"; | |
15 | + internal const string sharpenableKeyword = @"sharpenable"; | |
16 | + internal const string metalNameKeyword = @"metalName"; | |
17 | + | |
18 | + internal const string hardnessKeyword = @"hardness"; | |
19 | + internal const string sharpnessKeyword = @"sharpness"; | |
20 | + | |
21 | + | |
22 | + | |
23 | + /* | |
24 | + public virtual float GetAttackPower (IItemStack withItemStack) | |
25 | + public virtual float GetDurability (IItemStack itemstack) | |
26 | + public virtual float GetMiningSpeed (IItemStack itemstack, Block block) | |
27 | + public virtual void DamageItem (IWorldAccessor world, Entity byEntity, ItemSlot itemslot, int amount = 1) | |
28 | + public virtual void OnConsumedByCrafting (ItemSlot[] allInputSlots, ItemSlot stackInSlot, GridRecipe gridRecipe, CraftingRecipeIngredient fromIngredient, IPlayer byPlayer, int quantity) | |
29 | + public virtual void OnHeldDropped (IWorldAccessor world, IPlayer byPlayer, ItemSlot slot, int quantity, ref EnumHandling handling) | |
30 | + | |
31 | + public int MiningTier // public int ToolTier; | |
32 | + | |
33 | + public virtual void GetHeldItemInfo(ItemSlot inSlot, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo) | |
34 | + * */ | |
35 | + | |
36 | + public virtual bool Hardenable { | |
37 | + get | |
38 | + { | |
39 | + return this.Attributes[hardenableKeyword].AsBool(false); | |
40 | + } | |
41 | + } | |
42 | + | |
43 | + | |
44 | + public virtual string Name { | |
45 | + get | |
46 | + { | |
47 | + return this.Attributes[metalNameKeyword].AsString("?"); | |
48 | + } | |
49 | + } | |
50 | + | |
51 | + public virtual bool Sharpenable { | |
52 | + get | |
53 | + { | |
54 | + return this.Attributes[sharpenableKeyword].AsBool(false); | |
55 | + } | |
56 | + } | |
57 | + | |
58 | + #region OVER_RIDES | |
59 | + | |
60 | + public override void GetHeldItemInfo(ItemSlot inSlot, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo) | |
61 | + { | |
62 | + dsc.AppendFormat("Metal: '{0}', ",Name); | |
63 | + | |
64 | + if (Hardenable) { | |
65 | + dsc.AppendFormat("Temper: {0}\n", Hardness(inSlot.Itemstack) ); | |
66 | + } | |
67 | + | |
68 | + if (Sharpenable) { | |
69 | + dsc.AppendFormat("Wear: {0}\n", Sharpness(inSlot.Itemstack) ); | |
70 | + } | |
71 | + | |
72 | + } | |
73 | + | |
74 | + public virtual SharpnessState Sharpness(ItemStack someStack) | |
75 | + { | |
76 | + if (someStack.Attributes != null && someStack.Attributes.HasAttribute(sharpnessKeyword)) { | |
77 | + return someStack.Attributes.GetEnum<SharpnessState>(sharpnessKeyword, SharpnessState.Dull); | |
78 | + } | |
79 | + return SharpnessState.Dull; | |
80 | + } | |
81 | + | |
82 | + public virtual void Sharpness(ItemStack someStack, SharpnessState set) | |
83 | + { | |
84 | + | |
85 | + } | |
86 | + | |
87 | + public virtual HardnessState Hardness(ItemStack someStack) | |
88 | + { | |
89 | + | |
90 | + } | |
91 | + | |
92 | + public virtual void Hardness(ItemStack someStack, HardnessState set) | |
93 | + { | |
94 | + | |
95 | + } | |
96 | + | |
97 | + #endregion | |
98 | + | |
99 | + } | |
100 | +} | |
101 | + |