private void updateWearableStats(IInventory inv, IServerPlayer player) { StatModifiers allmod = new StatModifiers(); float walkSpeedmul = player.Entity.Stats.GetBlended("armorWalkSpeedAffectedness"); foreach (var slot in inv) { if (slot.Empty || !(slot.Itemstack.Item is ItemWearable)) { continue; } StatModifiers statmod = (slot.Itemstack.Item as ItemWearable).StatModifers; if (statmod == null) { continue; } allmod.canEat &= statmod.canEat; allmod.healingeffectivness += statmod.healingeffectivness; allmod.hungerrate += statmod.hungerrate; if (statmod.walkSpeed < 0) { allmod.walkSpeed += statmod.walkSpeed * walkSpeedmul; } else { allmod.walkSpeed += statmod.walkSpeed; } allmod.rangedWeaponsAcc += statmod.rangedWeaponsAcc; allmod.rangedWeaponsSpeed += statmod.rangedWeaponsSpeed; } EntityPlayer entity = player.Entity; entity.Stats .Set("walkspeed", "wearablemod", allmod.walkSpeed, true) .Set("healingeffectivness", "wearablemod", allmod.healingeffectivness, true) .Set("hungerrate", "wearablemod", allmod.hungerrate, true) .Set("rangedWeaponsAcc", "wearablemod", allmod.rangedWeaponsAcc, true) .Set("rangedWeaponsSpeed", "wearablemod", allmod.rangedWeaponsSpeed, true) ; entity.WatchedAttributes.SetBool("canEat", allmod.canEat); }
public override void OnLoaded(ICoreAPI api) { base.OnLoaded(api); string strdress = Attributes["clothescategory"].AsString(); EnumCharacterDressType dt = EnumCharacterDressType.Unknown; Enum.TryParse(strdress, true, out dt); DressType = dt; JsonObject jsonObj = Attributes?["footStepSound"]; if (jsonObj?.Exists == true) { string soundloc = jsonObj.AsString(null); if (soundloc != null) { AssetLocation loc = AssetLocation.Create(soundloc, Code.Domain).WithPathPrefixOnce("sounds/"); if (soundloc.EndsWith("*")) { loc.Path = loc.Path.TrimEnd('*'); FootStepSounds = api.Assets.GetLocations(loc.Path, loc.Domain).ToArray(); } else { FootStepSounds = new AssetLocation[] { loc }; } } } jsonObj = Attributes?["statModifiers"]; if (jsonObj?.Exists == true) { try { StatModifers = jsonObj.AsObject <StatModifiers>(); } catch (Exception e) { api.World.Logger.Error("Failed loading statModifiers for item/block {0}. Will ignore. Exception: {1}", Code, e); StatModifers = null; } } ProtectionModifiers defMods = null; jsonObj = Attributes?["defaultProtLoss"]; if (jsonObj?.Exists == true) { try { defMods = jsonObj.AsObject <ProtectionModifiers>(); } catch (Exception e) { api.World.Logger.Error("Failed loading defaultProtLoss for item/block {0}. Will ignore. Exception: {1}", Code, e); } } jsonObj = Attributes?["protectionModifiers"]; if (jsonObj?.Exists == true) { try { ProtectionModifiers = jsonObj.AsObject <ProtectionModifiers>(); } catch (Exception e) { api.World.Logger.Error("Failed loading protectionModifiers for item/block {0}. Will ignore. Exception: {1}", Code, e); ProtectionModifiers = null; } } if (ProtectionModifiers != null && ProtectionModifiers.PerTierFlatDamageReductionLoss == null) { ProtectionModifiers.PerTierFlatDamageReductionLoss = defMods?.PerTierFlatDamageReductionLoss; } if (ProtectionModifiers != null && ProtectionModifiers.PerTierRelativeProtectionLoss == null) { ProtectionModifiers.PerTierRelativeProtectionLoss = defMods?.PerTierRelativeProtectionLoss; } }