• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags

Frequently used words (click to add to your profile)

javaandroidc++linuxc#windowsobjective-ccocoaqtpython誰得phprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

VS plugin mod for Basic Armour


Commit MetaInfo

Révisionfd5592b782601ff49a2fd861ea8da5cca36ad760 (tree)
l'heure2019-05-25 10:04:24
Auteurmelchior <melchior@user...>
Commitermelchior

Message de Log

Workaround for duplicated event registration from OnLoad call(s),
New tooltips for armour

Change Summary

Modification

--- a/ArmourMod/Armour/ArmourModHookin.cs
+++ b/ArmourMod/Armour/ArmourModHookin.cs
@@ -21,6 +21,7 @@ namespace ArmourMod
2121 internal const string _domain = @"armourmod";
2222 private const string _thirdPersonKey = @"thirdPersonTransform";
2323 internal const string _configFilename = @"armourmod.json";
24+ private const string _itemArmourName = @"ItemArmour";
2425
2526 private ICoreServerAPI ServerAPI;
2627 private ICoreClientAPI ClientAPI;
@@ -57,7 +58,7 @@ namespace ArmourMod
5758
5859 public override double ExecuteOrder()
5960 {
60- return 1.1D;
61+ return 0.19D;
6162 }
6263
6364 public override bool AllowRuntimeReload
@@ -76,6 +77,7 @@ namespace ArmourMod
7677 base.Start(api);
7778 this.CoreAPI = api;
7879
80+ api.RegisterItemClass(_itemArmourName, typeof(ItemArmour));
7981 }
8082
8183 public override void StartServerSide(ICoreServerAPI api)
--- a/ArmourMod/Armour/EntityArmourPlayer.cs
+++ b/ArmourMod/Armour/EntityArmourPlayer.cs
@@ -12,6 +12,7 @@ namespace ArmourMod
1212 {
1313 public class EntityArmourPlayer : EntityPlayer
1414 {
15+ private static string _clientHookIdKey = @"ClientDelayHookId";
1516 protected ICoreAPI CoreAPI;
1617 protected ICoreClientAPI ClientAPI;
1718 protected ICoreServerAPI ServerAPI;
@@ -23,24 +24,46 @@ namespace ArmourMod
2324 //Pre-compute values;
2425 private DamageFilter finalFilter;
2526
26- private long recurringClientDelayHookId;
27- private long oneShotDelayId;
2827 private bool slotEventAttached;
2928
3029
3130 internal ArmourModConfig CachedConfiguration
3231 {
3332 get
34- {
33+ {
3534 if (CoreAPI.Side.IsServer( )) {
3635 return ( ArmourModConfig )ServerAPI.ObjectCache[ArmourModHookin._configFilename];
3736 } else {
3837 return ( ArmourModConfig )ClientAPI.ObjectCache[ArmourModHookin._configFilename];
3938 }
40-
4139 }
4240 }
4341
42+ private long CachedClientCallbackId
43+ {
44+ get
45+ {
46+ if (ClientAPI.ObjectCache.ContainsKey(_clientHookIdKey + ClientAPI.World.Player.PlayerUID))
47+ {
48+ return (long)ClientAPI.ObjectCache[_clientHookIdKey + ClientAPI.World.Player.PlayerUID];
49+ } else {
50+ return -1L;
51+ }
52+ }
53+ set
54+ {
55+ if (ClientAPI.ObjectCache.ContainsKey(_clientHookIdKey + ClientAPI.World.Player.PlayerUID))
56+ {
57+ Logger.Error("Trying to register duplicate callback-id [value: {0}]", value); ;
58+ }
59+ else
60+ {
61+ ClientAPI.ObjectCache[_clientHookIdKey + ClientAPI.World.Player.PlayerUID] = value;
62+ }
63+ }
64+ }
65+
66+
4467 public Dictionary<EnumCharacterDressType,Item> RenderableWornArmours { get; private set;}//Needs to be client side
4568
4669 public override void Initialize(Vintagestory.API.Common.Entities.EntityProperties properties, ICoreAPI api, long chunkindex3d)
@@ -65,24 +88,26 @@ namespace ArmourMod
6588 }
6689 }
6790
68- public override void OnEntityLoaded()
91+ public override void OnGameTick(float dt)
6992 {
70- base.OnEntityLoaded();
71- #if DEBUG
72- Logger.VerboseDebug( "OnEntityLoaded - EntityArmourPlayer" );
93+ base.OnGameTick(dt);
7394
74- Logger.VerboseDebug( "Side:{0}, gearInv == null?{1}", CoreAPI.Side.ToString( ), this.GearInventory == null );
75- #endif
7695
77- if ( CoreAPI.Side.IsClient() ) {
96+ if (CoreAPI.Side.IsClient( )) {
7897
79- //Attach to Inventory events
80- #if DEBUG
81- Logger.VerboseDebug( "Side:{0}, gearInv == null?{1}", CoreAPI.Side.ToString( ), this.GearInventory == null );
82- #endif
98+ if (ClientAPI.World.Player != null) {
8399
84-
85- this.oneShotDelayId = ClientAPI.Event.RegisterGameTickListener(ClientDelayHook, 250);
100+ if (this.CachedClientCallbackId > 0) {
101+ #if DEBUG
102+ Logger.VerboseDebug("[OnEntityLoaded] Duplicate event attach prevented");
103+ #endif
104+ } else {
105+ this.CachedClientCallbackId = ClientAPI.Event.RegisterGameTickListener(ClientDelayHook, 250);
106+ #if DEBUG
107+ Logger.VerboseDebug("[OnEntityLoaded] oneShotDelayId: {0}", this.CachedClientCallbackId);
108+ #endif
109+ }
110+ }
86111 }
87112 }
88113
@@ -258,43 +283,29 @@ namespace ArmourMod
258283
259284 protected void ClientDelayHook(float delay)
260285 {
261- ClientAPI.Event.UnregisterGameTickListener(oneShotDelayId);
286+ #if DEBUG
287+ Logger.VerboseDebug("[clientDelayHook] oneShotDelayId: {0}", this.CachedClientCallbackId);
288+ #endif
262289
263290 if (this.GearInventory == null) {
264291 Logger.Error("ClientDelayHook: base.GearInventory IS NULL! ");
265- recurringClientDelayHookId = ClientAPI.Event.RegisterCallback(RecurringClientDelayHook, 100);
292+
266293 return;
267294 }
268295
269296 if (slotEventAttached == false) {
270297 slotEventAttached = true;
298+ #if DEBUG
299+ Logger.VerboseDebug("Attached ClientWatchSlotModified (ClientDelayHook)");
300+ #endif
271301 this.GearInventory.SlotModified += ClientWatchSlotModified;
272302 }
273303
274- PopulateWornArmourModels( );
275- }
276-
277- protected void RecurringClientDelayHook(float delayed)
278- {
279- if (this.GearInventory == null) {
280- Logger.Error("RecurringClientDelayHook: base.GearInventory IS NULL! ");
304+ ClientAPI.Event.UnregisterGameTickListener(this.CachedClientCallbackId);
281305
282- return;
283- } else {
284- Logger.Notification("RecurringClientDelayHook: Finally the Gear data arrived - can proceed with event hooks");
285-
286- ClientAPI.Event.UnregisterCallback(recurringClientDelayHookId);
287-
288- if (slotEventAttached == false) {
289- slotEventAttached = true;
290- this.GearInventory.SlotModified += ClientWatchSlotModified;
291- }
292- PopulateWornArmourModels( );
293- }
306+ PopulateWornArmourModels( );
294307 }
295308
296-
297-
298309 private void ServerWatchSlotModified (int slotId)
299310 {
300311 var watchedSlot = this.GearInventory[slotId];
@@ -332,8 +343,9 @@ namespace ArmourMod
332343 private void ClientWatchSlotModified (int slotId)
333344 {
334345 #if DEBUG
335- Logger.VerboseDebug( "(Client) WatchSlotModified:{0}", slotId );
346+ Logger.VerboseDebug( "(Client) WatchSlotModified:{0} PlayerID: {1} InventoryID: {2}", slotId, ClientAPI.World.Player.PlayerUID,this.GearInventory.InventoryID );
336347 #endif
348+
337349 var watchedSlot = this.GearInventory[slotId];
338350
339351 if ( !watchedSlot.Empty ) {
@@ -468,9 +480,9 @@ namespace ArmourMod
468480
469481 if ( CheckIfClothesIsArmour(itemSlot) )
470482 {
471-#if DEBUG
483+ #if DEBUG
472484 Logger.VerboseDebug( "Now wearing armour:{0}", itemSlot.Itemstack.Item.Code.ToString( ) );
473-#endif
485+ #endif
474486
475487 if (RenderableWornArmours.ContainsKey(( EnumCharacterDressType )slotId)) {
476488 Logger.Warning("DUPLICATE assignment; Armour in slot: {0} named: {1}", slotId, itemSlot.Itemstack.Item.Code.ToString( ));
--- /dev/null
+++ b/ArmourMod/Armour/ItemArmour.cs
@@ -0,0 +1,51 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Text;
5+using System.Threading.Tasks;
6+
7+using Vintagestory.API.Common;
8+using Vintagestory.API.Common.Entities;
9+using Vintagestory.API.Config;
10+using Vintagestory.GameContent;
11+
12+namespace ArmourMod
13+{
14+ public class ItemArmour : ItemDress
15+ {
16+ public override void GetHeldItemInfo(ItemStack stack, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo)
17+ {
18+ //base.GetHeldItemInfo(stack, dsc, world, withDebugInfo);
19+
20+ if (this.Durability > 1) {
21+ dsc.AppendLine(Lang.Get("Durability: {0} / {1}", new object[] {
22+ stack.Attributes.GetInt ("durability", this.Durability),
23+ this.Durability}));
24+ }
25+
26+ //Display Protection values
27+ var blunt = stack.ItemAttributes["BluntProtection"].AsFloat( );
28+ var piercing = stack.ItemAttributes["PiercingProtection"].AsFloat( );
29+ var slashing = stack.ItemAttributes["SlashingProtection"].AsFloat( );
30+ var crushing = stack.ItemAttributes["CrushingProtection"].AsFloat( );
31+ var flame = stack.ItemAttributes["FireProtection"].AsFloat( );
32+
33+ dsc.AppendFormat("Protection:\n Blunt {0:P1}\n Piercing {1:P1}\n Slashing {2:P1}\n Crushing {3:P1}\n Flame {4:P1}",
34+ blunt,
35+ piercing,
36+ slashing,
37+ crushing,
38+ flame);
39+
40+ EnumCharacterDressType dresstype;
41+ string strdress = stack.ItemAttributes["clothescategory"].AsString( );
42+
43+ if (!Enum.TryParse(strdress, true, out dresstype)) {
44+ dsc.AppendLine(Lang.Get("Cloth Category: Unknown"));
45+ } else {
46+ dsc.AppendLine(Lang.Get("Cloth Category: {0}", Lang.Get("clothcategory-" + stack.ItemAttributes["clothescategory"].AsString( ))));
47+ }
48+ }
49+ }
50+}
51+
--- a/ArmourMod/ArmourMod.csproj
+++ b/ArmourMod/ArmourMod.csproj
@@ -73,6 +73,7 @@
7373 <Compile Include="Armour\AmourMeshRenderer.cs" />
7474 <Compile Include="Armour\ArmourModelData.cs" />
7575 <Compile Include="Armour\ArmourModConfig.cs" />
76+ <Compile Include="Armour\ItemArmour.cs" />
7677 </ItemGroup>
7778 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
7879 <ItemGroup>
--- a/ArmourMod/assets/armourmod/itemtypes/wearable/clothes-head-potmetal.json
+++ b/ArmourMod/assets/armourmod/itemtypes/wearable/clothes-head-potmetal.json
@@ -1,6 +1,6 @@
11 {
22 code: "clothes",
3- class: "ItemDress",
3+ class: "ItemArmour",
44 variantgroups: [
55 { code: "category", states: ["head"] },
66 { code: "head", combine: "SelectiveMultiply", onVariant: "category",
--- a/ArmourMod/assets/armourmod/itemtypes/wearable/clothes-upperbodyover-vest.json
+++ b/ArmourMod/assets/armourmod/itemtypes/wearable/clothes-upperbodyover-vest.json
@@ -1,6 +1,6 @@
11 {
22 code: "clothes",
3- class: "ItemDress",
3+ class: "ItemArmour",
44 variantgroups: [
55 { code: "category", states: ["upperbodyover"] },
66 { code: "upperbodyover", combine: "SelectiveMultiply", onVariant: "category",