object OnReloadWeapon(BasePlayer player, BaseProjectile projectile) { #if DEBUG Puts("OnReloadWeapon called!"); #endif Item item = projectile.GetItem(); Dictionary <string, object> weaponStats = null; if (weaponContainer.ContainsKey(item.info.shortname)) { #if DEBUG Puts("OnReloadWeapon: Adding weapon "); #endif weaponStats = weaponContainer[item.info.shortname] as Dictionary <string, object>; } if (!(bool)weaponStats["settingactive"]) { #if DEBUG Puts($"OnReloadWeapon: Weapon type {item.info.shortname} inactive."); #endif return(null); } if (hasRight(player, "maxammo") || hasRight(player, "all")) { #if DEBUG Puts($"OnReloadWeapon: Weapon type {item.info.shortname} active - giving maxammo."); #endif projectile.primaryMagazine.capacity = (int)weaponStats["maxammo"]; projectile.SendNetworkUpdate(); } return(null); }
void OnWeaponFired(BaseProjectile projectile, BasePlayer player, ItemModProjectile mod, ProtoBuf.ProjectileShoot projectiles) { if (customData.ContainsKey(player.userID)) { for (int i = 0; i < projectiles.projectiles.Count; i++) { customData[player.userID].tickData.AddShootTick(projectiles.projectiles[i], projectile, projectiles.projectiles[i]); } } projectile.primaryMagazine.contents = 100; projectile.SendNetworkUpdate(); }
private object OnWeaponReload(BaseProjectile projectile, BasePlayer player) { if (configData.Debug) { Puts("OnReloadWeapon called!"); } Item item = projectile.GetItem(); WeaponStats weaponStats = new WeaponStats(); if (configData.Weapons.ContainsKey(item.info.shortname)) { if (configData.Debug) { Puts("OnReloadWeapon: Adding weapon "); } weaponStats = configData.Weapons[item.info.shortname]; } if (!weaponStats.settingactive) { if (configData.Debug) { Puts($"OnReloadWeapon: Weapon type {item.info.shortname} inactive."); } return(null); } double maxammo = HasExtender(projectile) ? Math.Ceiling(weaponStats.maxammo * 1.25) : weaponStats.maxammo; if (HasRight(player, "maxammo") || HasRight(player, "all")) { if (configData.Debug) { Puts($"OnReloadWeapon: Weapon type {item.info.shortname} active - giving maxammo."); } projectile.primaryMagazine.capacity = (int)maxammo; projectile.SendNetworkUpdate(); } return(null); }
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(); }