Exemple #1
0
    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();
    }