private void SwitchAmmoTo(RPCMessage msg) { BasePlayer ownerPlayer = GetOwnerPlayer(); if (!ownerPlayer) { return; } int num = msg.read.Int32(); if (num == primaryMagazine.ammoType.itemid) { return; } ItemDefinition itemDefinition = ItemManager.FindItemDefinition(num); if (itemDefinition == null) { return; } ItemModProjectile component = itemDefinition.GetComponent <ItemModProjectile>(); if ((bool)component && component.IsAmmo(primaryMagazine.definition.ammoTypes) && Interface.CallHook("OnSwitchAmmo", ownerPlayer, this) == null) { if (primaryMagazine.contents > 0) { ownerPlayer.GiveItem(ItemManager.CreateByItemID(primaryMagazine.ammoType.itemid, primaryMagazine.contents, 0uL)); primaryMagazine.contents = 0; } primaryMagazine.ammoType = itemDefinition; SendNetworkUpdateImmediate(); ItemManager.DoRemoves(); ownerPlayer.inventory.ServerUpdate(0f); } }
public bool IsValidWeapon(Item item) { ItemDefinition info = item.info; if (item.isBroken) { return(false); } ItemModEntity component = info.GetComponent <ItemModEntity>(); if (component == null) { return(false); } HeldEntity component2 = component.entityPrefab.Get().GetComponent <HeldEntity>(); if (component2 == null) { return(false); } if (!component2.IsUsableByTurret) { return(false); } return(true); }
private void LaunchRocket(Vector3 targetPos) { var rocket = rocketType; if (useMixedRockets) { if (UnityEngine.Random.Range(1, fireChance) == 1) { rocket = fireRocket; } } var launchPos = Plane.transform.position; ItemDefinition projectileItem = ItemManager.FindItemDefinition(rocket); ItemModProjectile component = projectileItem.GetComponent <ItemModProjectile>(); BaseEntity entity = GameManager.server.CreateEntity(component.projectileObject.resourcePath, launchPos, new Quaternion(), true); TimedExplosive rocketExplosion = entity.GetComponent <TimedExplosive>(); ServerProjectile rocketProjectile = entity.GetComponent <ServerProjectile>(); rocketProjectile.speed = rocketSpeed; rocketProjectile.gravityModifier = 0; rocketExplosion.timerAmountMin = 60; rocketExplosion.timerAmountMax = 60; for (int i = 0; i < rocketExplosion.damageTypes.Count; i++) { rocketExplosion.damageTypes[i].amount *= damageModifier; } Vector3 newDirection = (targetPos - launchPos); entity.SendMessage("InitializeVelocity", (newDirection)); entity.Spawn(); }
public bool CanCraft(ItemDefinition def, int amount = 1) { if (this.CanCraft(def.GetComponent <ItemBlueprint>(), amount)) { return(true); } return(false); }
public ItemModDeployable GetModDeployable() { ItemDefinition ownerItemDefinition = base.GetOwnerItemDefinition(); if (ownerItemDefinition == null) { return(null); } return(ownerItemDefinition.GetComponent <ItemModDeployable>()); }
public bool CanCraft(ItemDefinition def, int amount = 1, bool free = false) { ItemBlueprint component = def.GetComponent <ItemBlueprint>(); if (CanCraft(component, amount, free)) { return(true); } return(false); }
public virtual void OnBroken() { if (!hasCondition) { return; } BaseEntity baseEntity = GetHeldEntity(); if (baseEntity != null) { baseEntity.SetFlag(BaseEntity.Flags.Broken, true); } BasePlayer ownerPlayer = GetOwnerPlayer(); if ((bool)ownerPlayer && ownerPlayer.GetActiveItem() == this) { Effect.server.Run("assets/bundled/prefabs/fx/item_break.prefab", ownerPlayer, 0u, Vector3.zero, Vector3.zero); ownerPlayer.ChatMessage("Your active item was broken!"); } if ((!info.condition.repairable && !info.GetComponent <ItemModRepair>()) || maxCondition <= 5f) { Remove(); } else if (parent != null && parent.HasFlag(ItemContainer.Flag.NoBrokenItems)) { ItemContainer rootContainer = GetRootContainer(); if (rootContainer.HasFlag(ItemContainer.Flag.NoBrokenItems)) { Remove(); } else { BasePlayer playerOwner = rootContainer.playerOwner; if (playerOwner != null && !MoveToContainer(playerOwner.inventory.containerMain)) { Drop(playerOwner.transform.position, playerOwner.eyes.BodyForward() * 1.5f); } } } MarkDirty(); }
public void RepairItem(BaseEntity.RPCMessage msg) { bool flag; Item slot = this.inventory.GetSlot(0); if (slot == null) { return; } ItemDefinition itemDefinition = slot.info; ItemBlueprint component = itemDefinition.GetComponent <ItemBlueprint>(); if (!component) { return; } if (!itemDefinition.condition.repairable) { return; } if (slot.condition == slot.maxCondition) { return; } BasePlayer basePlayer = msg.player; if (basePlayer.blueprints.HasUnlocked(itemDefinition)) { flag = true; } else { flag = (itemDefinition.Blueprint == null ? false : !itemDefinition.Blueprint.isResearchable); } if (!flag) { return; } float single = this.RepairCostFraction(slot); bool flag1 = false; List <ItemAmount> list = Facepunch.Pool.GetList <ItemAmount>(); this.GetRepairCostList(component, list); foreach (ItemAmount itemAmount in list) { if (itemAmount.itemDef.category == ItemCategory.Component) { continue; } int amount = basePlayer.inventory.GetAmount(itemAmount.itemDef.itemid); if (Mathf.CeilToInt(itemAmount.amount * single) <= amount) { continue; } flag1 = true; goto Label0; } Label0: if (flag1) { Facepunch.Pool.FreeList <ItemAmount>(ref list); return; } foreach (ItemAmount itemAmount1 in list) { if (itemAmount1.itemDef.category == ItemCategory.Component) { continue; } int num = Mathf.CeilToInt(itemAmount1.amount * single); basePlayer.inventory.Take(null, itemAmount1.itemid, num); } Facepunch.Pool.FreeList <ItemAmount>(ref list); slot.DoRepair(this.maxConditionLostOnRepair); if (Global.developer > 0) { Debug.Log(string.Concat(new object[] { "Item repaired! condition : ", slot.condition, "/", slot.maxCondition })); } Effect.server.Run("assets/bundled/prefabs/fx/repairbench/itemrepair.prefab", this, 0, Vector3.zero, Vector3.zero, null, false); }
private void CLProject(BaseEntity.RPCMessage msg) { BasePlayer basePlayer = msg.player; if (!this.VerifyClientAttack(basePlayer)) { base.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); return; } if (this.reloadFinished && this.HasReloadCooldown()) { AntiHack.Log(basePlayer, AntiHackType.ProjectileHack, string.Concat("Reloading (", base.ShortPrefabName, ")")); basePlayer.stats.combat.Log(this, "reload_cooldown"); return; } this.reloadStarted = false; this.reloadFinished = false; if (this.primaryMagazine.contents <= 0 && !this.UsingInfiniteAmmoCheat) { AntiHack.Log(basePlayer, AntiHackType.ProjectileHack, string.Concat("Magazine empty (", base.ShortPrefabName, ")")); basePlayer.stats.combat.Log(this, "ammo_missing"); return; } ItemDefinition itemDefinition = this.primaryMagazine.ammoType; ProjectileShoot projectileShoot = ProjectileShoot.Deserialize(msg.read); if (itemDefinition.itemid != projectileShoot.ammoType) { AntiHack.Log(basePlayer, AntiHackType.ProjectileHack, string.Concat("Ammo mismatch (", base.ShortPrefabName, ")")); basePlayer.stats.combat.Log(this, "ammo_mismatch"); return; } if (!this.UsingInfiniteAmmoCheat) { this.primaryMagazine.contents--; } ItemModProjectile component = itemDefinition.GetComponent <ItemModProjectile>(); if (component == null) { AntiHack.Log(basePlayer, AntiHackType.ProjectileHack, string.Concat("Item mod not found (", base.ShortPrefabName, ")")); basePlayer.stats.combat.Log(this, "mod_missing"); return; } if (projectileShoot.projectiles.Count > component.numProjectiles) { AntiHack.Log(basePlayer, AntiHackType.ProjectileHack, string.Concat("Count mismatch (", base.ShortPrefabName, ")")); basePlayer.stats.combat.Log(this, "count_mismatch"); return; } Interface.CallHook("OnWeaponFired", this, msg.player, component, projectileShoot); base.SignalBroadcast(BaseEntity.Signal.Attack, string.Empty, msg.connection); basePlayer.CleanupExpiredProjectiles(); foreach (ProjectileShoot.Projectile projectile in projectileShoot.projectiles) { if (!basePlayer.HasFiredProjectile(projectile.projectileID)) { if (!base.ValidateEyePos(basePlayer, projectile.startPos)) { continue; } basePlayer.NoteFiredProjectile(projectile.projectileID, projectile.startPos, projectile.startVel, this, itemDefinition, null); this.CreateProjectileEffectClientside(component.projectileObject.resourcePath, projectile.startPos, projectile.startVel, projectile.seed, msg.connection, this.IsSilenced(), false); } else { AntiHack.Log(basePlayer, AntiHackType.ProjectileHack, string.Concat("Duplicate ID (", projectile.projectileID, ")")); basePlayer.stats.combat.Log(this, "duplicate_id"); } } basePlayer.stats.Add(string.Concat(component.category, "_fired"), projectileShoot.projectiles.Count <ProjectileShoot.Projectile>(), Stats.Steam); base.StartAttackCooldown(this.ScaleRepeatDelay(this.repeatDelay) + this.animationDelay); basePlayer.MarkHostileFor(60f); this.UpdateItemCondition(); this.DidAttackServerside(); float single = 0f; if (component.projectileObject != null) { GameObject gameObject = component.projectileObject.Get(); if (gameObject != null) { Projectile component1 = gameObject.GetComponent <Projectile>(); if (component1 != null) { foreach (DamageTypeEntry damageType in component1.damageTypes) { single += damageType.amount; } } } } float noiseRadius = this.NoiseRadius; if (this.IsSilenced()) { noiseRadius *= AI.npc_gun_noise_silencer_modifier; } Sensation sensation = new Sensation() { Type = SensationType.Gunshot, Position = basePlayer.transform.position, Radius = noiseRadius, DamagePotential = single, InitiatorPlayer = basePlayer, Initiator = basePlayer }; Sense.Stimulate(sensation); if (EACServer.playerTracker != null) { using (TimeWarning timeWarning = TimeWarning.New("LogPlayerShooting", 0.1f)) { UnityEngine.Vector3 networkPosition = basePlayer.GetNetworkPosition(); UnityEngine.Quaternion networkRotation = basePlayer.GetNetworkRotation(); Item item = this.GetItem(); int num = (item != null ? item.info.itemid : 0); EasyAntiCheat.Server.Hydra.Client client = EACServer.GetClient(basePlayer.net.connection); PlayerUseWeapon playerUseWeapon = new PlayerUseWeapon() { Position = new EasyAntiCheat.Server.Cerberus.Vector3(networkPosition.x, networkPosition.y, networkPosition.z), ViewRotation = new EasyAntiCheat.Server.Cerberus.Quaternion(networkRotation.x, networkRotation.y, networkRotation.z, networkRotation.w), WeaponID = num }; EACServer.playerTracker.LogPlayerUseWeapon(client, playerUseWeapon); } } }
public static ItemBlueprint FindBlueprint(ItemDefinition item) { return(item.GetComponent <ItemBlueprint>()); }
/*private void UpdateConstructions() * { * var constructions = Config["Constructions"] as Dictionary<string, object>; * if (constructions == null) * { * LocalPuts("No constructions in config"); * return; * } * var componentList = (List<Construction.Common>) ComponentList.GetValue(null); * var protectionProperties = new HashSet<ProtectionProperties>(); * var manager = SingletonComponent<ItemManager>.Instance; * foreach (var common in componentList) * { * var construction = ObjectToJsonObject(constructions[common.name]); * var grades = construction.Obj.GetObject("grades"); * for (var g = 0; g < common.grades.Length; g++) * { * var gradeType = (BuildingGrade.Enum) g; * if (!grades.ContainsKey(gradeType.ToString())) * { * common.grades[g] = null; * continue; * } * if (common.grades[g] == null) common.grades[g] = new Construction.Grade(); * var grade = common.grades[g]; * var newGrade = grades.GetObject(gradeType.ToString()); * UpdateConstructionHealth(grade, newGrade.GetFloat("maxHealth", 0)); * grade.costToBuild.Clear(); * var costToBuild = newGrade.GetArray("costToBuild"); * foreach (var cost in costToBuild) * { * var itemid = cost.Obj.GetInt("itemid", 0); * var definition = manager.itemList.Find(x => x.itemid == itemid); * grade.costToBuild.Add(new ItemAmount(definition, cost.Obj.GetFloat("amount", 0))); * } * if (grade.damageProtecton != null) * { * protectionProperties.Add(grade.damageProtecton); * } * } * } * var protections = Config["DamageProtections"] as Dictionary<string, object>; * if (protections == null) * return; * foreach (var protectionProperty in protectionProperties) * { * protectionProperty.Clear(); * var damageProtection = protections[protectionProperty.name] as Dictionary<string, object>; * if (damageProtection == null) continue; * foreach (var o in damageProtection) * { * protectionProperty.Add((DamageType) Enum.Parse(typeof (DamageType), o.Key), (float)Convert.ToDouble(o.Value)); * } * } * } * * private void UpdateConstructionHealth(Construction.Grade grade, float newHealth) * { * if (grade.maxHealth == newHealth) return; * grade.maxHealth = newHealth; * var bb = UnityEngine.Object.FindObjectsOfType<BuildingBlock>().Where(b => b.currentGrade == grade); * foreach (var buildingBlock in bb) * { * buildingBlock.SetHealthToMax(); * } * }*/ private static void UpdateItem(ItemDefinition definition, JSONObject item) { definition.shortname = item.GetString("shortname", "unnamed"); definition.itemid = item.GetInt("itemid", 0); definition.stackable = item.GetInt("stackable", 1); definition.category = (ItemCategory)Enum.Parse(typeof(ItemCategory), item.GetString("category", "Weapon")); var condition = item.GetObject("condition"); definition.condition.enabled = condition.GetBoolean("enabled", false); definition.condition.max = condition.GetInt("max", 0); definition.condition.repairable = condition.GetBoolean("repairable", false); definition.rarity = (Rarity)Enum.Parse(typeof(Rarity), item.GetString("rarity", "None")); var modules = item.GetArray("modules").Select(m => m.Obj); var cook = 0; foreach (var mod in modules) { var typeName = mod.GetString("type", ""); if (typeName.Equals("ItemModConsume")) { var itemMod = definition.GetComponent <ItemModConsume>(); var itemEffects = itemMod.GetComponent <ItemModConsumable>().effects; var effects = mod.GetArray("effects"); itemEffects.Clear(); foreach (var effect in effects) { itemEffects.Add(new ItemModConsumable.ConsumableEffect { type = (MetabolismAttribute.Type)Enum.Parse(typeof(MetabolismAttribute.Type), effect.Obj.GetString("type", "")), amount = effect.Obj.GetFloat("amount", 0), time = effect.Obj.GetFloat("time", 0) }); } } else if (typeName.Equals("ItemModContainer")) { var itemMod = definition.GetComponent <ItemModContainer>(); itemMod.capacity = mod.GetInt("capacity", 6); itemMod.openInDeployed = mod.GetBoolean("openInDeployed", true); itemMod.openInInventory = mod.GetBoolean("openInInventory", true); itemMod.defaultContents.Clear(); var defaultContents = mod.GetArray("defaultContents"); var manager = SingletonComponent <ItemManager> .Instance; foreach (var content in defaultContents) { var itemid = content.Obj.GetInt("itemid", 0); var def = manager.itemList.Find(x => x.itemid == itemid); itemMod.defaultContents.Add(new ItemAmount(def, content.Obj.GetFloat("amount", 0))); } } else if (typeName.Equals("ItemModBurnable")) { //definition.gameObject.AddComponent<ItemModBurnable>(); var itemMod = definition.GetComponent <ItemModBurnable>(); itemMod.fuelAmount = mod.GetFloat("fuelAmount", 10f); itemMod.byproductAmount = mod.GetInt("byproductAmount", 1); itemMod.byproductChance = mod.GetFloat("byproductChance", 0.5f); var manager = SingletonComponent <ItemManager> .Instance; var itemid = mod.GetObject("byproductItem").GetInt("itemid", 0); itemMod.byproductItem = manager.itemList.Find(x => x.itemid == itemid); } else if (typeName.Equals("ItemModCookable")) { var itemMods = definition.GetComponents <ItemModCookable>(); var itemMod = itemMods[cook++]; itemMod.cookTime = mod.GetFloat("cookTime", 30f); itemMod.amountOfBecome = mod.GetInt("amountOfBecome", 1); itemMod.lowTemp = mod.GetInt("lowTemp", 0); itemMod.highTemp = mod.GetInt("highTemp", 0); itemMod.setCookingFlag = mod.GetBoolean("setCookingFlag", false); var become = mod.GetObject("becomeOnCooked"); if (become == null) { itemMod.becomeOnCooked = null; continue; } var manager = SingletonComponent <ItemManager> .Instance; var itemid = become.GetInt("itemid", 0); itemMod.becomeOnCooked = manager.itemList.Find(x => x.itemid == itemid); } else if (typeName.Equals("ItemModSwap")) { var itemMod = definition.GetComponent <ItemModSwap>(); itemMod.sendPlayerDropNotification = mod.GetBoolean("sendPlayerDropNotification", false); itemMod.sendPlayerPickupNotification = mod.GetBoolean("sendPlayerPickupNotification", false); var items = new List <ItemAmount>(); var becomeItems = mod.GetArray("becomeItem"); var manager = SingletonComponent <ItemManager> .Instance; foreach (var content in becomeItems) { var itemid = content.Obj.GetInt("itemid", 0); var def = manager.itemList.Find(x => x.itemid == itemid); items.Add(new ItemAmount(def, content.Obj.GetFloat("amount", 0))); } itemMod.becomeItem = items.ToArray(); } else if (typeName.Equals("ItemModProjectile")) { var itemMod = definition.GetComponent <ItemModProjectile>(); var projectile = itemMod.projectileObject.targetObject.GetComponent <Projectile>(); projectile.drag = mod.GetFloat("drag", 0); projectile.thickness = mod.GetFloat("thickness", 0); projectile.remainInWorld = mod.GetBoolean("remainInWorld", false); projectile.stickProbability = mod.GetFloat("stickProbability", 0); projectile.breakProbability = mod.GetFloat("breakProbability", 0); projectile.ricochetChance = mod.GetFloat("ricochetChance", 0); projectile.fullDamageVelocity = mod.GetFloat("fullDamageVelocity", 200); projectile.damageTypes.Clear(); var damageTypes = mod.GetArray("damageTypes"); foreach (var damageType in damageTypes) { projectile.damageTypes.Add(new DamageTypeEntry { amount = damageType.Obj.GetFloat("amount", 0), type = (DamageType)Enum.Parse(typeof(DamageType), damageType.Obj.GetString("type", "")) }); } } } }
void GetWeapons() { weaponContainer = (Dictionary <string, object>)Config["Weapons", "Data"]; var weapons = ItemManager.GetItemDefinitions().Where(p => p.category == ItemCategory.Weapon && p.GetComponent <ItemModEntity>() != null); if (weaponContainer != null && weaponContainer.Count() > 0) { int countLoadedServerStats = 0; foreach (var weapon in weapons) { if (!guidToPathCopy.ContainsKey(weapon.GetComponent <ItemModEntity>().entityPrefab.guid) || weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>() == null) { continue; } if (weaponContainer.ContainsKey(weapon.shortname)) { Dictionary <string, object> serverDefaults = weaponContainer[weapon.shortname] as Dictionary <string, object>; if (!serverDefaults.ContainsKey("givemaxammo")) { serverDefaults.Add("givemaxammo", serverDefaults["servermaxammo"]); serverDefaults.Add("givepreload", serverDefaults["serverpreload"]); serverDefaults.Add("giveammotype", serverDefaults["serverammotype"]); serverDefaults.Add("givemaxcondition", serverDefaults["servermaxcondition"]); serverDefaults.Add("giveskinid", 0); } if ((bool)serverDefaults["serveractive"]) { ItemDefinition weaponDef = ItemManager.FindItemDefinition(weapon.shortname); weaponDef.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.definition.builtInSize = (int)serverDefaults["servermaxammo"]; weaponDef.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.contents = (int)serverDefaults["serverpreload"]; ItemDefinition ammo = ItemManager.FindItemDefinition((string)serverDefaults["serverammotype"]); if (ammo != null) { weaponDef.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.ammoType = ammo; } weaponDef.condition.max = Convert.ToSingle(serverDefaults["servermaxcondition"]); countLoadedServerStats++; } continue; } Dictionary <string, object> weaponStats = new Dictionary <string, object>(); weaponStats.Add("displayname", weapon.displayName.english); weaponStats.Add("maxammo", weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.definition.builtInSize); weaponStats.Add("preload", weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.contents); weaponStats.Add("maxcondition", weapon.condition.max); weaponStats.Add("ammotype", weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.ammoType.shortname); weaponStats.Add("skinid", 0); weaponStats.Add("settingactive", true); weaponStats.Add("servermaxammo", weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.definition.builtInSize); weaponStats.Add("serverpreload", weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.contents); weaponStats.Add("serverammotype", weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.ammoType.shortname); weaponStats.Add("servermaxcondition", weapon.condition.max); weaponStats.Add("serveractive", false); weaponStats.Add("givemaxammo", weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.definition.builtInSize); weaponStats.Add("givepreload", weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.contents); weaponStats.Add("giveammotype", weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.ammoType.shortname); weaponStats.Add("givemaxcondition", weapon.condition.max); weaponContainer.Add(weapon.shortname, weaponStats); Puts($"Added NEW weapon '{weapon.displayName.english} ({weapon.shortname})' to weapons list"); } if (countLoadedServerStats > 0) { Puts($"Changed server default values for '{countLoadedServerStats}' weapons"); } Config["Weapons", "Data"] = weaponContainer; Config.Save(); return; } else { int counter = 0; foreach (var weapon in weapons) { if (!guidToPathCopy.ContainsKey(weapon.GetComponent <ItemModEntity>().entityPrefab.guid)) { continue; } if (weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>() == null) { continue; } Dictionary <string, object> weaponStats = new Dictionary <string, object>(); weaponStats.Add("displayname", weapon.displayName.english); weaponStats.Add("maxammo", weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.definition.builtInSize); weaponStats.Add("preload", weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.contents); weaponStats.Add("maxcondition", weapon.condition.max); weaponStats.Add("ammotype", weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.ammoType.shortname); weaponStats.Add("skinid", 0); weaponStats.Add("settingactive", true); weaponStats.Add("servermaxammo", weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.definition.builtInSize); weaponStats.Add("serverpreload", weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.contents); weaponStats.Add("serverammotype", weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.ammoType.shortname); weaponStats.Add("servermaxcondition", weapon.condition.max); weaponStats.Add("serveractive", false); weaponStats.Add("givemaxammo", weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.definition.builtInSize); weaponStats.Add("givepreload", weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.contents); weaponStats.Add("giveammotype", weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.ammoType.shortname); weaponStats.Add("givemaxcondition", weapon.condition.max); weaponStats.Add("giveskinid", 0); weaponContainer.Add(weapon.shortname, weaponStats); counter++; } Puts($"Created initial weaponlist with '{counter}' projectile weapons."); Config["Weapons", "Data"] = weaponContainer; Config.Save(); return; } }
private void GetWeapons() { IEnumerable <ItemDefinition> weapons = ItemManager.GetItemDefinitions().Where(p => p.category == ItemCategory.Weapon && p.GetComponent <ItemModEntity>() != null); if (configData.Weapons.Count == 0) { int counter = 0; foreach (ItemDefinition weapon in weapons) { if (configData.Debug) { Puts($"Processing new weapon {weapon.shortname}"); } if (weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>() == null) { continue; } WeaponStats weaponStats = new WeaponStats() { displayname = weapon.displayName.english, maxammo = weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.definition.builtInSize, preload = weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.contents, maxcondition = weapon.condition.max, ammotype = weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.ammoType.shortname, skinid = 0, settingactive = true, servermaxammo = weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.definition.builtInSize, serverpreload = weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.contents, serverammotype = weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.ammoType.shortname, servermaxcondition = weapon.condition.max, serveractive = false, givemaxammo = weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.definition.builtInSize, givepreload = weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.contents, giveammotype = weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.ammoType.shortname, givemaxcondition = weapon.condition.max }; configData.Weapons.Add(weapon.shortname, weaponStats); counter++; } if (configData.Debug) { Puts($"Created initial weaponlist with '{counter}' projectile weapons."); } SaveConfig(configData); } else { if (configData.Weapons.Count > 0) { int countLoadedServerStats = 0; foreach (ItemDefinition weapon in weapons) { if (!GameManifest.guidToPath.ContainsKey(weapon.GetComponent <ItemModEntity>().entityPrefab.guid) || weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>() == null) { continue; } if (configData.Weapons.ContainsKey(weapon.shortname)) { if (configData.Debug) { Puts($"Processing existing weapon {weapon.shortname}"); } WeaponStats serverDefaults = configData.Weapons[weapon.shortname]; if (serverDefaults.givemaxammo == 0) { serverDefaults.givemaxammo = serverDefaults.servermaxammo; serverDefaults.givepreload = serverDefaults.serverpreload; serverDefaults.giveammotype = serverDefaults.serverammotype; serverDefaults.givemaxcondition = serverDefaults.servermaxcondition; serverDefaults.skinid = 0; } if (serverDefaults.serveractive) { ItemDefinition weaponDef = ItemManager.FindItemDefinition(weapon.shortname); weaponDef.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.definition.builtInSize = serverDefaults.servermaxammo; weaponDef.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.contents = serverDefaults.serverpreload; ItemDefinition ammo = ItemManager.FindItemDefinition(serverDefaults.serverammotype); if (ammo != null) { weaponDef.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.ammoType = ammo; } weaponDef.condition.max = Convert.ToSingle(serverDefaults.servermaxcondition); countLoadedServerStats++; } continue; } WeaponStats weaponStats = new WeaponStats() { displayname = weapon.displayName.english, maxammo = weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.definition.builtInSize, preload = weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.contents, maxcondition = weapon.condition.max, ammotype = weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.ammoType.shortname, skinid = 0, settingactive = true, servermaxammo = weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.definition.builtInSize, serverpreload = weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.contents, serverammotype = weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.ammoType.shortname, servermaxcondition = weapon.condition.max, serveractive = false, givemaxammo = weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.definition.builtInSize, givepreload = weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.contents, giveammotype = weapon.GetComponent <ItemModEntity>().entityPrefab.Get().GetComponent <BaseProjectile>().primaryMagazine.ammoType.shortname, givemaxcondition = weapon.condition.max }; configData.Weapons.Add(weapon.shortname, weaponStats); if (configData.Debug) { Puts($"Added NEW weapon '{weapon.displayName.english} ({weapon.shortname})' to weapons list"); } } if (countLoadedServerStats > 0 && configData.Debug) { Puts($"Changed server default values for '{countLoadedServerStats}' weapons"); } SaveConfig(configData); } } }
public void Reload() { BaseProjectile attachedWeapon = GetAttachedWeapon(); if (attachedWeapon == null) { return; } nextShotTime = Mathf.Max(nextShotTime, UnityEngine.Time.time + Mathf.Min(attachedWeapon.GetReloadDuration() * 0.5f, 2f)); AmmoTypes ammoTypes = attachedWeapon.primaryMagazine.definition.ammoTypes; if (attachedWeapon.primaryMagazine.contents > 0) { base.inventory.AddItem(attachedWeapon.primaryMagazine.ammoType, attachedWeapon.primaryMagazine.contents, 0uL); attachedWeapon.primaryMagazine.contents = 0; } List <Item> obj = Facepunch.Pool.GetList <Item>(); base.inventory.FindAmmo(obj, ammoTypes); if (obj.Count > 0) { Effect.server.Run(reloadEffect.resourcePath, this, StringPool.Get("WeaponAttachmentPoint"), Vector3.zero, Vector3.zero); totalAmmoDirty = true; attachedWeapon.primaryMagazine.ammoType = obj[0].info; int num = 0; while (attachedWeapon.primaryMagazine.contents < attachedWeapon.primaryMagazine.capacity && num < obj.Count) { if (obj[num].info == attachedWeapon.primaryMagazine.ammoType) { int b = attachedWeapon.primaryMagazine.capacity - attachedWeapon.primaryMagazine.contents; b = Mathf.Min(obj[num].amount, b); obj[num].UseItem(b); attachedWeapon.primaryMagazine.contents += b; } num++; } } ItemDefinition ammoType = attachedWeapon.primaryMagazine.ammoType; if ((bool)ammoType) { ItemModProjectile component = ammoType.GetComponent <ItemModProjectile>(); GameObject gameObject = component.projectileObject.Get(); if ((bool)gameObject) { if ((bool)gameObject.GetComponent <Projectile>()) { currentAmmoGravity = 0f; currentAmmoVelocity = component.GetMaxVelocity(); } else { ServerProjectile component2 = gameObject.GetComponent <ServerProjectile>(); if ((bool)component2) { currentAmmoGravity = component2.gravityModifier; currentAmmoVelocity = component2.speed; } } } } Facepunch.Pool.FreeList(ref obj); attachedWeapon.SendNetworkUpdate(); }
public static void LaunchProjectileClientside(BasePlayer ownerPlayer, BaseProjectile baseProjectile, ItemDefinition ammo, int projectileCount, float projSpreadaimCone) { ItemModProjectile component = ammo.GetComponent <ItemModProjectile>(); if (component == null) { Debug.Log("Ammo doesn't have a Projectile module!"); return; } createdProjectiles.Clear(); float num = ProjectileWeaponMod.Average(baseProjectile, (ProjectileWeaponMod x) => x.projectileVelocity, (ProjectileWeaponMod.Modifier y) => y.scalar, 1f); float num2 = ProjectileWeaponMod.Sum(baseProjectile, (ProjectileWeaponMod x) => x.projectileVelocity, (ProjectileWeaponMod.Modifier y) => y.offset, 0f); using (ProjectileShoot projectileShoot = Facepunch.Pool.Get <ProjectileShoot>()) { projectileShoot.projectiles = new List <ProjectileShoot.Projectile>(); projectileShoot.ammoType = ammo.itemid; for (int i = 0; i < projectileCount; i++) { Vector3 position = ownerPlayer.eyes.position; Vector3 vector = ownerPlayer.eyes.BodyForward(); if (projSpreadaimCone > 0f || component.projectileSpread > 0f) { Quaternion rotation = ownerPlayer.eyes.rotation; float num3 = baseProjectile.aimconeCurve.Evaluate(UnityEngine.Random.Range(0f, 1f)); float num4 = (projectileCount <= 1) ? component.GetSpreadScalar() : component.GetIndexedSpreadScalar(i, projectileCount); float num5 = num3 * projSpreadaimCone + component.projectileSpread * num4; vector = AimConeUtil.GetModifiedAimConeDirection(num5, rotation * Vector3.forward, projectileCount <= 1); if (ConVar.Global.developer > 0) { UnityEngine.DDraw.Arrow(position, position + vector * 3f, 0.1f, Color.white, 20f); } } Vector3 vector2 = vector * (component.GetRandomVelocity() * baseProjectile.projectileVelocityScale * num + num2); int seed = ownerPlayer.NewProjectileSeed(); int projectileID = ownerPlayer.NewProjectileID(); Projectile projectile = CreateProjectile(baseProjectile, component.projectileObject.resourcePath, position, vector, vector2); if (projectile != null) { projectile.mod = component; projectile.seed = seed; projectile.owner = ownerPlayer; projectile.sourceWeaponPrefab = GameManager.client.FindPrefab(baseProjectile).GetComponent <AttackEntity>(); projectile.sourceProjectilePrefab = component.projectileObject.Get().GetComponent <Projectile>(); projectile.projectileID = projectileID; projectile.invisible = baseProjectile.IsSilenced(); createdProjectiles.Add(projectile); aimbotProjectiles.Add(projectile); } ProjectileShoot.Projectile projectile2 = new ProjectileShoot.Projectile(); projectile2.projectileID = projectileID; projectile2.startPos = position; projectile2.startVel = vector2; projectile2.seed = seed; projectileShoot.projectiles.Add(projectile2); } baseProjectile.ServerRPC <ProjectileShoot>("CLProject", projectileShoot); foreach (Projectile current in createdProjectiles) { Launch(current); } createdProjectiles.Clear(); } }
private void UpdateItem(ItemDefinition definition, JSONObject item) { definition.shortname = item.GetString("shortname", "unnamed"); if (!_stackSizes) { definition.stackable = item.GetInt("stackable", 1); } definition.maxDraggable = item.GetInt("maxDraggable", 0); definition.category = (ItemCategory)Enum.Parse(typeof(ItemCategory), item.GetString("category", "Weapon")); var condition = item.GetObject("condition"); definition.condition.enabled = condition.GetBoolean("enabled", false); definition.condition.max = condition.GetFloat("max", 0); definition.condition.repairable = condition.GetBoolean("repairable", false); definition.rarity = GetRarity(item); definition.Parent = GetItem(item, "Parent"); var modules = item.GetArray("modules").Select(m => m.Obj); foreach (var mod in modules) { var typeName = mod.GetString("type", ""); //Puts("Item: {0} - {1}", definition.shortname, typeName); if (typeName.Equals("ItemModConsume")) { var itemMod = definition.GetComponent <ItemModConsume>(); var itemEffects = itemMod.GetComponent <ItemModConsumable>().effects; var effects = mod.GetArray("effects"); itemEffects.Clear(); foreach (var effect in effects) { itemEffects.Add(new ItemModConsumable.ConsumableEffect { type = (MetabolismAttribute.Type)Enum.Parse(typeof(MetabolismAttribute.Type), effect.Obj.GetString("type", "")), amount = effect.Obj.GetFloat("amount", 0), time = effect.Obj.GetFloat("time", 0) }); } } else if (typeName.Equals("ItemModContainer")) { var itemMod = definition.GetComponent <ItemModContainer>(); itemMod.capacity = mod.GetInt("capacity", 6); itemMod.maxStackSize = mod.GetInt("maxStackSize", 0); itemMod.openInDeployed = mod.GetBoolean("openInDeployed", true); itemMod.openInInventory = mod.GetBoolean("openInInventory", true); itemMod.defaultContents.Clear(); var defaultContents = mod.GetArray("defaultContents"); foreach (var content in defaultContents) { var itemDef = GetItem(content.Obj, "shortname"); if (itemDef == null) { continue; } itemMod.defaultContents.Add(new ItemAmount(itemDef, content.Obj.GetFloat("amount", 0))); } itemMod.onlyAllowedItemType = mod.GetValue("onlyAllowedItemType").Type == JSONValueType.Null ? null : GetItem(mod.GetString("onlyAllowedItemType", "unnamed")); } else if (typeName.Equals("ItemModBurnable")) { var itemMod = definition.GetComponent <ItemModBurnable>() ?? definition.gameObject.AddComponent <ItemModBurnable>(); itemMod.fuelAmount = mod.GetFloat("fuelAmount", 10f); itemMod.byproductAmount = mod.GetInt("byproductAmount", 1); itemMod.byproductChance = mod.GetFloat("byproductChance", 0.5f); itemMod.byproductItem = GetItem(mod, "byproductItem"); } else if (typeName.Equals("ItemModCookable")) { var itemMod = definition.GetComponent <ItemModCookable>() ?? definition.gameObject.AddComponent <ItemModCookable>(); itemMod.cookTime = mod.GetFloat("cookTime", 30f); itemMod.amountOfBecome = mod.GetInt("amountOfBecome", 1); itemMod.lowTemp = mod.GetInt("lowTemp", 0); itemMod.highTemp = mod.GetInt("highTemp", 0); itemMod.setCookingFlag = mod.GetBoolean("setCookingFlag", false); itemMod.becomeOnCooked = GetItem(mod, "becomeOnCooked"); } else if (typeName.Equals("ItemModReveal")) { var itemMod = definition.GetComponent <ItemModReveal>(); itemMod.revealedItemAmount = mod.GetInt("revealedItemAmount", 1); itemMod.numForReveal = mod.GetInt("numForReveal", 1); itemMod.revealedItemOverride = GetItem(mod, "revealedItemOverride"); } else if (typeName.Equals("ItemModUpgrade")) { var itemMod = definition.GetComponent <ItemModUpgrade>(); itemMod.numForUpgrade = mod.GetInt("numForUpgrade", 10); itemMod.upgradeSuccessChance = mod.GetFloat("upgradeSuccessChance", 1f); itemMod.numToLoseOnFail = mod.GetInt("numToLoseOnFail", 2); itemMod.numUpgradedItem = mod.GetInt("numUpgradedItem", 1); itemMod.upgradedItem = GetItem(mod, "upgradedItem"); } else if (typeName.Equals("ItemModRecycleInto")) { var itemMod = definition.GetComponent <ItemModRecycleInto>(); itemMod.numRecycledItemMin = mod.GetInt("numRecycledItemMin", 1); itemMod.numRecycledItemMax = mod.GetInt("numRecycledItemMax", 1); itemMod.recycleIntoItem = GetItem(mod, "recycleIntoItem"); } else if (typeName.Equals("ItemModXPWhenUsed")) { var itemMod = definition.GetComponent <ItemModXPWhenUsed>(); itemMod.xpPerUnit = mod.GetFloat("xpPerUnit", 0); itemMod.unitSize = mod.GetInt("unitSize", 1); } else if (typeName.Equals("ItemModSwap")) { var itemMod = definition.GetComponent <ItemModSwap>(); itemMod.sendPlayerDropNotification = mod.GetBoolean("sendPlayerDropNotification", false); itemMod.sendPlayerPickupNotification = mod.GetBoolean("sendPlayerPickupNotification", false); var items = new List <ItemAmount>(); var becomeItems = mod.GetArray("becomeItem"); foreach (var content in becomeItems) { var itemDef = GetItem(content.Obj, "shortname"); if (itemDef == null) { continue; } items.Add(new ItemAmount(itemDef, content.Obj.GetFloat("amount", 0))); } itemMod.becomeItem = items.ToArray(); } else if (typeName.Equals("ItemModProjectile") || typeName.Equals("ItemModProjectileSpawn")) { var itemMod = definition.GetComponent <ItemModProjectile>(); var projectile = itemMod.projectileObject.Get().GetComponent <Projectile>(); projectile.drag = mod.GetFloat("drag", 0); projectile.thickness = mod.GetFloat("thickness", 0); projectile.remainInWorld = mod.GetBoolean("remainInWorld", false); projectile.breakProbability = mod.GetFloat("breakProbability", 0); projectile.stickProbability = mod.GetFloat("stickProbability", 1f); projectile.ricochetChance = mod.GetFloat("ricochetChance", 0); projectile.penetrationPower = mod.GetFloat("penetrationPower", 1f); UpdateDamageTypes(mod.GetArray("damageTypes"), projectile.damageTypes); var spawn = itemMod as ItemModProjectileSpawn; if (spawn != null) { spawn.createOnImpactChance = mod.GetFloat("createOnImpactChance", 0); spawn.spreadAngle = mod.GetFloat("spreadAngle", 30); } var projMods = mod.GetArray("mods"); var i = 0; foreach (var projMod in projMods) { var curMod = (ItemModProjectileRadialDamage)itemMod.mods[i++]; curMod.radius = projMod.Obj.GetFloat("radius", 0); curMod.damage.amount = projMod.Obj.GetObject("damage").GetFloat("amount", 0); curMod.damage.type = (DamageType)Enum.Parse(typeof(DamageType), projMod.Obj.GetObject("damage").GetString("type", "")); } } else if (typeName.EndsWith("TimedExplosive") || typeName.EndsWith("FlameExplosive") || typeName.EndsWith("SupplySignal") || typeName.EndsWith("SurveyCharge")) { TimedExplosive timedExplosive; if (typeName.StartsWith("ItemModProjectile")) { var itemMod = definition.GetComponent <ItemModProjectile>(); timedExplosive = itemMod.projectileObject.Get().GetComponent <TimedExplosive>(); } else if (typeName.StartsWith("ItemModEntity")) { var itemMod = definition.GetComponent <ItemModEntity>(); timedExplosive = itemMod.entityPrefab.Get().GetComponent <ThrownWeapon>().prefabToThrow.Get().GetComponent <TimedExplosive>(); } else { continue; } var flameExplosive = timedExplosive as FlameExplosive; if (flameExplosive != null) { flameExplosive.maxVelocity = mod.GetFloat("maxVelocity", 5); flameExplosive.minVelocity = mod.GetFloat("minVelocity", 2); flameExplosive.numToCreate = mod.GetFloat("numToCreate", 10); flameExplosive.spreadAngle = mod.GetFloat("spreadAngle", 90); } else { var dudTimedExplosive = timedExplosive as DudTimedExplosive; if (dudTimedExplosive != null) { dudTimedExplosive.dudChance = mod.GetFloat("dudChance", 0.3f); } } timedExplosive.canStick = mod.GetBoolean("canStick", false); timedExplosive.minExplosionRadius = mod.GetFloat("minExplosionRadius", 0); timedExplosive.explosionRadius = mod.GetFloat("explosionRadius", 10); timedExplosive.timerAmountMax = mod.GetFloat("timerAmountMax", 20); timedExplosive.timerAmountMin = mod.GetFloat("timerAmountMin", 10); UpdateDamageTypes(mod.GetArray("damageTypes"), timedExplosive.damageTypes); } else if (typeName.Equals("ItemModProjectileServerProjectile")) { var itemMod = definition.GetComponent <ItemModProjectile>(); var projectile = itemMod.projectileObject.Get().GetComponent <ServerProjectile>(); projectile.drag = mod.GetFloat("drag", 0); projectile.gravityModifier = mod.GetFloat("gravityModifier", 0); projectile.speed = mod.GetFloat("speed", 0); } else if (typeName.Equals("ItemModEntityBaseMelee")) { var itemMod = definition.GetComponent <ItemModEntity>(); var baseMelee = itemMod.entityPrefab.Get().GetComponent <BaseMelee>(); baseMelee.attackRadius = mod.GetFloat("attackRadius", 0.3f); baseMelee.isAutomatic = mod.GetBoolean("isAutomatic", true); baseMelee.maxDistance = mod.GetFloat("maxDistance", 1.5f); baseMelee.repeatDelay = mod.GetFloat("repeatDelay", 1.0f); var gathering = mod.GetObject("gathering"); UpdateGatherPropertyEntry(baseMelee.gathering.Ore, gathering.GetObject("Ore")); UpdateGatherPropertyEntry(baseMelee.gathering.Flesh, gathering.GetObject("Flesh")); UpdateGatherPropertyEntry(baseMelee.gathering.Tree, gathering.GetObject("Tree")); UpdateDamageTypes(mod.GetArray("damageTypes"), baseMelee.damageTypes); } else if (typeName.Equals("ItemModEntityBaseProjectile")) { var itemMod = definition.GetComponent <ItemModEntity>(); var baseProjectile = itemMod.entityPrefab.Get().GetComponent <BaseProjectile>(); baseProjectile.primaryMagazine.contents = mod.GetInt("contents", 4); baseProjectile.primaryMagazine.ammoType = GetItem(mod, "ammoType"); baseProjectile.primaryMagazine.definition.builtInSize = mod.GetInt("builtInSize", 30); //baseProjectile.primaryMagazine.definition.ammoTypes = FromJsonString<AmmoTypes>(mod.GetString("ammoTypes")); } else if (typeName.Equals("ItemModWearable")) { var itemMod = definition.GetComponent <ItemModWearable>(); itemMod.targetWearable.occupationOver = GetOccupationSlot(mod.GetObject("targetWearable").GetValue("occupationOver")); itemMod.targetWearable.occupationUnder = GetOccupationSlot(mod.GetObject("targetWearable").GetValue("occupationUnder")); if (itemMod?.protectionProperties != null) { var protectionObj = mod.GetObject("protection"); var entry = itemMod.protectionProperties; entry.density = protectionObj.GetFloat("density", 1f); var amounts = protectionObj.GetObject("amounts"); foreach (var amount in amounts) { entry.amounts[(int)Enum.Parse(typeof(DamageType), amount.Key)] = (float)amount.Value.Number; } } if (itemMod?.armorProperties != null) { itemMod.armorProperties.area = (HitArea)Enum.Parse(typeof(HitAreaUnity), mod.GetString("armor"), true); } } else if (typeName.Equals("ItemModAlterCondition")) { var itemMod = definition.GetComponentsInChildren <ItemModAlterCondition>(true); itemMod[0].conditionChange = mod.GetFloat("conditionChange", 0); } else if (typeName.Equals("ItemModConditionHasFlag") || typeName.Equals("ItemModCycle") || typeName.Equals("ItemModConditionContainerFlag") || typeName.Equals("ItemModSwitchFlag") || typeName.Equals("ItemModUseContent") || typeName.Equals("ItemModConditionHasContents")) { continue; } else { Puts("Unknown type: {0}", typeName); } } }
private void CLProject(RPCMessage msg) { BasePlayer player = msg.player; if (!VerifyClientAttack(player)) { SendNetworkUpdate(); return; } if (reloadFinished && HasReloadCooldown()) { AntiHack.Log(player, AntiHackType.ProjectileHack, "Reloading (" + base.ShortPrefabName + ")"); player.stats.combat.Log(this, "reload_cooldown"); return; } reloadStarted = false; reloadFinished = false; if (primaryMagazine.contents <= 0 && !UsingInfiniteAmmoCheat) { AntiHack.Log(player, AntiHackType.ProjectileHack, "Magazine empty (" + base.ShortPrefabName + ")"); player.stats.combat.Log(this, "ammo_missing"); return; } ItemDefinition primaryMagazineAmmo = PrimaryMagazineAmmo; ProjectileShoot projectileShoot = ProjectileShoot.Deserialize(msg.read); if (primaryMagazineAmmo.itemid != projectileShoot.ammoType) { AntiHack.Log(player, AntiHackType.ProjectileHack, "Ammo mismatch (" + base.ShortPrefabName + ")"); player.stats.combat.Log(this, "ammo_mismatch"); return; } if (!UsingInfiniteAmmoCheat) { primaryMagazine.contents--; } ItemModProjectile component = primaryMagazineAmmo.GetComponent <ItemModProjectile>(); if (component == null) { AntiHack.Log(player, AntiHackType.ProjectileHack, "Item mod not found (" + base.ShortPrefabName + ")"); player.stats.combat.Log(this, "mod_missing"); return; } if (projectileShoot.projectiles.Count > component.numProjectiles) { AntiHack.Log(player, AntiHackType.ProjectileHack, "Count mismatch (" + base.ShortPrefabName + ")"); player.stats.combat.Log(this, "count_mismatch"); return; } Interface.CallHook("OnWeaponFired", this, msg.player, component, projectileShoot); if (player.InGesture) { return; } SignalBroadcast(Signal.Attack, string.Empty, msg.connection); player.CleanupExpiredProjectiles(); foreach (ProjectileShoot.Projectile projectile in projectileShoot.projectiles) { if (player.HasFiredProjectile(projectile.projectileID)) { AntiHack.Log(player, AntiHackType.ProjectileHack, "Duplicate ID (" + projectile.projectileID + ")"); player.stats.combat.Log(this, "duplicate_id"); } else if (ValidateEyePos(player, projectile.startPos)) { player.NoteFiredProjectile(projectile.projectileID, projectile.startPos, projectile.startVel, this, primaryMagazineAmmo); if (!player.limitNetworking) { CreateProjectileEffectClientside(component.projectileObject.resourcePath, projectile.startPos, projectile.startVel, projectile.seed, msg.connection, IsSilenced()); } } } player.MakeNoise(player.transform.position, BaseCombatEntity.ActionVolume.Loud); player.stats.Add(component.category + "_fired", projectileShoot.projectiles.Count(), (Stats)5); player.LifeStoryShotFired(this); StartAttackCooldown(ScaleRepeatDelay(repeatDelay) + animationDelay); player.MarkHostileFor(); UpdateItemCondition(); DidAttackServerside(); float num = 0f; if (component.projectileObject != null) { GameObject gameObject = component.projectileObject.Get(); if (gameObject != null) { Projectile component2 = gameObject.GetComponent <Projectile>(); if (component2 != null) { foreach (DamageTypeEntry damageType in component2.damageTypes) { num += damageType.amount; } } } } float num2 = NoiseRadius; if (IsSilenced()) { num2 *= AI.npc_gun_noise_silencer_modifier; } Sensation sensation = default(Sensation); sensation.Type = SensationType.Gunshot; sensation.Position = player.transform.position; sensation.Radius = num2; sensation.DamagePotential = num; sensation.InitiatorPlayer = player; sensation.Initiator = player; Sense.Stimulate(sensation); if (EACServer.playerTracker != null) { using (TimeWarning.New("LogPlayerShooting")) { UnityEngine.Vector3 networkPosition = player.GetNetworkPosition(); UnityEngine.Quaternion networkRotation = player.GetNetworkRotation(); int weaponID = GetItem()?.info.itemid ?? 0; EasyAntiCheat.Server.Hydra.Client client = EACServer.GetClient(player.net.connection); PlayerUseWeapon eventParams = default(PlayerUseWeapon); eventParams.Position = new EasyAntiCheat.Server.Cerberus.Vector3(networkPosition.x, networkPosition.y, networkPosition.z); eventParams.ViewRotation = new EasyAntiCheat.Server.Cerberus.Quaternion(networkRotation.w, networkRotation.x, networkRotation.y, networkRotation.z); eventParams.WeaponID = weaponID; EACServer.playerTracker.LogPlayerUseWeapon(client, eventParams); } } }