• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

First Machine Age's Mods (Combined repo.)


Commit MetaInfo

Révisione59f178d54935d61280116918ded5a2bb61496ca (tree)
l'heure2020-07-20 14:20:56
Auteurmelchior <melchior@user...>
Commitermelchior

Message de Log

W.I.P. Generic Steel Item class "universal?'

Change Summary

Modification

--- a/ElementalTools/Assignments.cs
+++ b/ElementalTools/Assignments.cs
@@ -3,10 +3,13 @@ using System.Collections.Generic;
33
44 using System.Linq;
55 using System.Threading;
6+
67 using Newtonsoft.Json.Linq;
8+
79 using Vintagestory.API.Client;
810 using Vintagestory.API.Common;
911 using Vintagestory.API.Config;
12+using Vintagestory.GameContent;
1013 using Vintagestory.ServerMods;
1114
1215 namespace ElementalTools
@@ -14,6 +17,7 @@ namespace ElementalTools
1417 public partial class ElementalToolsSystem : ModSystem
1518 {
1619 internal const string malletItemKey = @"ItemMallet";
20+ internal const string genericSteelSwordKey = @"Steel_ItemSword";
1721 internal const string pack_carburizationBlockKey = @"pack_carburization";
1822 internal const string pack_stateFired = @"fired";
1923 internal const string malletAssetKey = @"mallet";
@@ -37,6 +41,9 @@ namespace ElementalTools
3741 private void RegisterItemClasses( )
3842 {
3943 CoreAPI.RegisterItemClass(malletItemKey, typeof(ItemMallet));
44+
45+ CoreAPI.RegisterItemClass(genericSteelSwordKey, typeof(SteelItem<ItemSword>) );
46+
4047 }
4148
4249 private void RegisterBlockClasses( )
--- a/ElementalTools/ElementalTools.csproj
+++ b/ElementalTools/ElementalTools.csproj
@@ -73,9 +73,8 @@
7373 <Compile Include="Block\PackCarburization.cs" />
7474 <Compile Include="BlockEntities\PackCarburizationEntity.cs" />
7575 <Compile Include="Helpers.cs" />
76- <Compile Include="Items\ItemTemperableMetal.cs" />
7776 <Compile Include="General\IAmSteel.cs" />
78- <Compile Include="General\ElementOfSteel.cs" />
77+ <Compile Include="Items\SteelItem.cs" />
7978 </ItemGroup>
8079 <ItemGroup>
8180 <Folder Include="Items\" />
@@ -140,6 +139,7 @@
140139 <None Include="assets\fma\recipes\grid\remapping\blister_steel_mappings.json">
141140 <CopyToOutputDirectory>Always</CopyToOutputDirectory>
142141 </None>
142+ <None Include="General\FactoryOfSteel.cs" />
143143 </ItemGroup>
144144 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
145145 </Project>
\ No newline at end of file
--- a/ElementalTools/General/ElementOfSteel.cs
+++ /dev/null
@@ -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-
--- /dev/null
+++ b/ElementalTools/General/FactoryOfSteel.cs
@@ -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+
--- a/ElementalTools/General/IAmSteel.cs
+++ b/ElementalTools/General/IAmSteel.cs
@@ -1,15 +1,50 @@
11 using System;
2+
3+using Vintagestory.API.Common;
4+
25 namespace ElementalTools
36 {
47 public interface IAmSteel
58 {
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...
1039
1140 }
1241
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>
1348 public enum SharpnessState : byte
1449 {
1550 Rough = 0,//Unsharpened state *Default*
@@ -20,6 +55,12 @@ namespace ElementalTools
2055 Razor,
2156 }
2257
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>
2364 public enum HardnessState : byte
2465 {
2566 Soft = 0,
--- a/ElementalTools/Helpers.cs
+++ b/ElementalTools/Helpers.cs
@@ -3,7 +3,9 @@ using System.Collections;
33 using System.Collections.Generic;
44 using System.Linq;
55 using System.Text;
6+
67 using Vintagestory.API.Common;
8+using Vintagestory.API.Datastructures;
79
810 namespace ElementalTools
911 {
@@ -59,6 +61,14 @@ namespace ElementalTools
5961 }
6062 return originalAsset.Code;
6163 }
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+
6272 }
6373 }
6474
--- a/ElementalTools/Items/ItemTemperableMetal.cs
+++ /dev/null
@@ -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-
--- /dev/null
+++ b/ElementalTools/Items/SteelItem.cs
@@ -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+