Skip to content

Commit 319c8ec

Browse files
committed
1.3.4
1 parent 76965ba commit 319c8ec

File tree

3 files changed

+51
-21
lines changed

3 files changed

+51
-21
lines changed

LevelUP/Configuration.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2552,6 +2552,7 @@ public static int HammerGetResultMultiplyByLevel(int level)
25522552
if (level % hammerIncreaseChanceToQuadruplePerLevelReducerPerLevel == 0) incrementChance -= hammerIncreaseChanceToQuadruplePerLevelReducer;
25532553
baseChance += incrementChance;
25542554
}
2555+
if(enableExtendedLog) Debug.Log($"Quadruple chance: {baseChance}");
25552556
// Randomizes the chance and increase if chances hit
25562557
if (baseChance >= new Random().Next(0, 100)) return 4;
25572558
}
@@ -2566,6 +2567,7 @@ public static int HammerGetResultMultiplyByLevel(int level)
25662567
if (level % hammerIncreaseChanceToTriplePerLevelReducerPerLevel == 0) incrementChance -= hammerIncreaseChanceToTriplePerLevelReducer;
25672568
baseChance += incrementChance;
25682569
}
2570+
if(enableExtendedLog) Debug.Log($"Triple chance: {baseChance}");
25692571
// Randomizes the chance and increase if chances hit
25702572
if (baseChance >= new Random().Next(0, 100)) return 3;
25712573
}
@@ -2580,6 +2582,7 @@ public static int HammerGetResultMultiplyByLevel(int level)
25802582
if (level % hammerIncreaseChanceToDoublePerLevelReducerPerLevel == 0) incrementChance -= hammerIncreaseChanceToDoublePerLevelReducer;
25812583
baseChance += incrementChance;
25822584
}
2585+
if(enableExtendedLog) Debug.Log($"Double chance: {baseChance}");
25832586
// Randomizes the chance and increase if chances hit
25842587
if (baseChance >= new Random().Next(0, 100)) return 2;
25852588
}

LevelUP/Shared/OverrideDamageInteraction.cs

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using HarmonyLib;
44
using Vintagestory.API.Common;
55
using Vintagestory.API.Common.Entities;
6+
using Vintagestory.API.Datastructures;
67
using Vintagestory.API.Server;
78
using Vintagestory.GameContent;
89

@@ -42,6 +43,7 @@ public void OverwriteNativeFunctions(Instance _instance)
4243
[HarmonyPatch(typeof(Entity), "ReceiveDamage")]
4344
public static void ReceiveDamageStart(Entity __instance, DamageSource damageSource, ref float damage)
4445
{
46+
4547
#region compatibility
4648
// Compatibility Layer Start Calculation
4749
float compatibilityStartDamage = __instance.Attributes.GetFloat("LevelUP_DamageInteraction_Compatibility_ExtendDamageStart_ReceiveDamage");
@@ -55,19 +57,23 @@ public static void ReceiveDamageStart(Entity __instance, DamageSource damageSour
5557
damage += damage * compatibilityStartDamageMultiply;
5658
#endregion
5759

60+
5861
// Damage bug treatment
5962
if (damage > 0 && __instance.ShouldReceiveDamage(damageSource, damage))
6063
{
64+
6165
// Player Does Damage
6266
// Checking if damage sources is from a player and from a server and if entity is alive
6367
if (damageSource.SourceEntity is EntityPlayer || damageSource.GetCauseEntity() is EntityPlayer && __instance.World.Side == EnumAppSide.Server && __instance.Alive)
6468
{
69+
6570
if (Configuration.enableExtendedLog)
66-
Debug.Log($"{(damageSource.SourceEntity as EntityPlayer)?.GetName() ?? "PlayerProjectile"} previous damage: {damage}");
71+
Debug.Log($"{(damageSource.SourceEntity as EntityPlayer)?.GetName() ?? "PlayerProjectile"} previous damage: {damage}");
6772

6873
// Melee Action
6974
if (damageSource.SourceEntity is EntityPlayer)
7075
{
76+
7177
// Get player source
7278
EntityPlayer playerEntity = damageSource.SourceEntity as EntityPlayer;
7379
// Get player instance
@@ -187,6 +193,7 @@ public static void ReceiveDamageStart(Entity __instance, DamageSource damageSour
187193
#endregion
188194
}
189195

196+
190197
#region hand
191198
if (Configuration.enableLevelHand && player.InventoryManager.ActiveHotbarSlot != null)
192199
{
@@ -202,16 +209,19 @@ public static void ReceiveDamageStart(Entity __instance, DamageSource damageSour
202209
}
203210
}
204211
#endregion
212+
205213
}
206214
// Ranged Action
207215
else if (damageSource.GetCauseEntity() is EntityPlayer && damageSource.SourceEntity is EntityProjectile)
208216
{
217+
209218
// Get entities
210219
EntityPlayer playerEntity = damageSource.GetCauseEntity() as EntityPlayer;
211220

212221
if (damageSource.SourceEntity is EntityProjectile itemDamage)
213222
{
214223

224+
215225
// Get player instance
216226
IPlayer player = __instance.Api.World.PlayerByUid(playerEntity.PlayerUID);
217227

@@ -244,15 +254,17 @@ public static void ReceiveDamageStart(Entity __instance, DamageSource damageSour
244254

245255
};
246256
#endregion
257+
247258
}
248259
}
249260
// Invalid
250261
else Debug.Log($"ERROR: Invalid damage type in OverwriteDamageInteraction, cause entity is invalid: {damageSource.GetCauseEntity()} or source entity is invalid: {damageSource.SourceEntity}");
251-
252262
if (Configuration.enableExtendedLog)
253263
Debug.Log($"{(damageSource.SourceEntity as EntityPlayer)?.GetName() ?? "PlayerProjectile"} final damage: {damage}");
264+
254265
}
255266

267+
256268
#region compatibility
257269
// Compatibility Layer Extend Final Calculation
258270
float compatibilityFinalDamage = __instance.Attributes.GetFloat("LevelUP_DamageInteraction_Compatibility_ExtendDamageFinish_ReceiveDamage");
@@ -266,13 +278,14 @@ public static void ReceiveDamageStart(Entity __instance, DamageSource damageSour
266278
// Receive damage by the compatibility layer
267279
damage += damage * compatibilityFinalDamageMultiply;
268280
#endregion
269-
270281
// Player Receive Damage
271282
// Checking if received damage is a player and if is a server and if is alive
272283
if (__instance is EntityPlayer && __instance.World.Side == EnumAppSide.Server && __instance.Alive)
273284
{
285+
286+
274287
if (Configuration.enableExtendedLog)
275-
Debug.Log($"{(damageSource.SourceEntity as EntityPlayer).Player.PlayerName} received damage: {damage}");
288+
Debug.Log($"{(damageSource.SourceEntity as EntityPlayer)?.GetName()} received damage: {damage}");
276289

277290
// Get player source
278291
EntityPlayer playerEntity = __instance as EntityPlayer;
@@ -298,7 +311,6 @@ public static void ReceiveDamageStart(Entity __instance, DamageSource damageSour
298311

299312
}
300313
#endregion
301-
302314
// Check if the damage received is from a valid entity source damage
303315
// in others cases the armor shouldn't reduce damage
304316
if (damageSource.GetCauseEntity() != null || damageSource.SourceEntity != null)
@@ -329,7 +341,6 @@ public static void ReceiveDamageStart(Entity __instance, DamageSource damageSour
329341
}
330342
}
331343
#endregion
332-
333344
#region leatherarmor
334345
if (Configuration.enableLevelLeatherArmor && damage < Configuration.DamageLimitLeatherArmor)
335346
{
@@ -517,12 +528,13 @@ public static void ReceiveDamageStart(Entity __instance, DamageSource damageSour
517528
}
518529
}
519530
#endregion
531+
520532
}
521533

522534
if (Configuration.enableExtendedLog)
523-
Debug.Log($"{(damageSource.SourceEntity as EntityPlayer).Player.PlayerName} received final damage: {damage}");
524-
};
535+
Debug.Log($"{(damageSource.SourceEntity as EntityPlayer)?.GetName()} received final damage: {damage}");
525536

537+
};
526538
// Double check bug only if is a player hitting in single player
527539
if (damageSource.SourceEntity is EntityPlayer || damageSource.GetCauseEntity() is EntityPlayer)
528540
singlePlayerDoubleCheck = !singlePlayerDoubleCheck;
@@ -652,18 +664,33 @@ public static void ApplyShieldProtectionStart(ModSystemWearableStats __instance,
652664
{
653665
if (!Configuration.enableLevelShield) return;
654666

655-
// Reduces the damage received more than normal based on shield level
656-
double damageReduced = damage * Configuration.ShieldGetReductionMultiplyByLevel(player.Entity.WatchedAttributes.GetInt("LevelUP_Level_Shield"));
657-
damage -= (float)damageReduced;
658-
if (damage < 0) damage = 0;
659-
if (Configuration.enableExtendedLog) Debug.Log($"{player.PlayerName} reduced: {damageReduced} in shield damage");
660-
661-
// Servers
662-
if (instance.serverAPI != null)
663-
instance.serverAPI.OnExperienceEarned(player as IServerPlayer, "Increase_Shield_Hit");
664-
// Single player treatment
665-
else if (instance.clientAPI?.api.IsSinglePlayer ?? false)
666-
instance.clientAPI.compatibilityChannel.SendPacket($"Increase_Shield_Hit&lanplayername={player.PlayerName}");
667+
ItemSlot[] shieldSlots =
668+
[
669+
player.Entity.LeftHandItemSlot,
670+
player.Entity.RightHandItemSlot
671+
];
672+
// Swipe all shields from player hands
673+
for (int i = 0; i < shieldSlots.Length; i++)
674+
{
675+
ItemSlot shieldSlot = shieldSlots[i];
676+
JsonObject attr = shieldSlot.Itemstack?.ItemAttributes?["shield"];
677+
// Checking if is a shield if not continues
678+
if (attr == null || !attr.Exists)
679+
continue;
680+
681+
// Reduces the damage received more than normal based on shield level
682+
double damageReduced = damage * Configuration.ShieldGetReductionMultiplyByLevel(player.Entity.WatchedAttributes.GetInt("LevelUP_Level_Shield"));
683+
damage -= (float)damageReduced;
684+
if (damage < 0) damage = 0;
685+
if (Configuration.enableExtendedLog) Debug.Log($"{player.PlayerName} reduced: {damageReduced} in shield damage");
686+
687+
// Servers
688+
if (instance.serverAPI != null)
689+
instance.serverAPI.OnExperienceEarned(player as IServerPlayer, "Increase_Shield_Hit");
690+
// Single player treatment
691+
else if (instance.clientAPI?.api.IsSinglePlayer ?? false)
692+
instance.clientAPI.compatibilityChannel.SendPacket($"Increase_Shield_Hit&lanplayername={player.PlayerName}");
693+
}
667694
}
668695
#endregion
669696
}

LevelUP/modinfo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"BoboDev"
77
],
88
"description": "Add level system to your character",
9-
"version": "1.3.3",
9+
"version": "1.3.4",
1010
"dependencies": {
1111
"game": ""
1212
}

0 commit comments

Comments
 (0)