示例#1
0
        public static void ShootProjectile(Item shooterItem, string projectileID, Transform spawnPoint, string imbueSpell = null, float forceMult = 1.0f, float throwMult = 1.0f, bool pooled = false)
        {
            ItemData spawnedItemData = Catalog.GetData <ItemData>(projectileID, true);

            if (spawnedItemData == null)
            {
                return;
            }
            spawnedItemData.SpawnAsync(i =>
            {
                try
                {
                    i.transform.position = spawnPoint.position;
                    i.transform.rotation = Quaternion.Euler(spawnPoint.rotation.eulerAngles);
                    shooterItem.IgnoreObjectCollision(i);
                    i.ignoredItem = shooterItem;
                    Physics.IgnoreCollision(shooterItem.colliderGroups[0].colliders[0], i.colliderGroups[0].colliders[0]);
                    i.rb.velocity = shooterItem.rb.velocity;
                    i.rb.AddForce(i.rb.transform.forward * 1000.0f * forceMult);
                    //i.rb.useGravity = false;
                    i.Throw(throwMult, Item.FlyDetection.CheckAngle);
                    if (!String.IsNullOrEmpty(imbueSpell))
                    {
                        // Set imbue charge on projectile using ItemProjectileSimple subclass
                        ItemSimpleProjectile projectileController = i.gameObject.GetComponent <ItemSimpleProjectile>();
                        if (projectileController != null)
                        {
                            projectileController.AddChargeToQueue(imbueSpell);
                        }
                    }
                }
                catch { Debug.Log("[Fisher-Firearms] EXCEPTION IN SPAWNING "); }
            },
                                       spawnPoint.position,
                                       Quaternion.Euler(spawnPoint.rotation.eulerAngles),
                                       null,
                                       false);
        }
        private void Fire(bool firedByNPC = false, bool playEffects = true)
        {
            if (playEffects)
            {
                PreFireEffects();
            }
            if (firedByNPC)
            {
                return;
            }

            //ShootProjectile(item, module.projectileID, muzzlePoint, GetItemSpellChargeID(item), module.bulletForce, module.throwMult);

            ItemData spawnedItemData = Catalog.GetData <ItemData>(module.projectileID, true);
            String   imbueSpell      = GetItemSpellChargeID(item);

            if (spawnedItemData == null)
            {
                return;
            }
            currentlySpawningProjectile = true;
            spawnedItemData.SpawnAsync(i =>
            {
                // Debug.Log("[Fisher-Firearms] Time: " + Time.time + " Spawning projectile: " + i.name);
                try
                {
                    i.Throw(1f, Item.FlyDetection.Forced);
                    item.IgnoreObjectCollision(i);
                    i.IgnoreObjectCollision(item);
                    i.IgnoreRagdollCollision(Player.local.creature.ragdoll);
                    IgnoreProjectile(i, true);
                    i.transform.position = muzzlePoint.position;
                    i.transform.rotation = Quaternion.Euler(muzzlePoint.rotation.eulerAngles);
                    i.rb.velocity        = item.rb.velocity;
                    i.rb.AddForce(i.rb.transform.forward * 1000.0f * module.bulletForce);

                    ItemSimpleProjectile projectileController = i.gameObject.GetComponent <ItemSimpleProjectile>();
                    if (projectileController != null)
                    {
                        projectileController.SetShooterItem(this.item);
                    }

                    if (!String.IsNullOrEmpty(imbueSpell))
                    {
                        //  Set imbue charge on projectile using ItemProjectileSimple subclass
                        if (projectileController != null)
                        {
                            projectileController.AddChargeToQueue(imbueSpell);
                        }
                    }
                    ApplyRecoil(item.rb, module.recoilForces, module.recoilMult, gunGripHeldLeft, gunGripHeldRight, module.hapticForce);
                    currentlySpawningProjectile = false;
                }
                catch
                {
                    Debug.Log("[Fisher-Firearms] EXCEPTION IN SPAWNING ");
                }
            },
                                       Vector3.zero,
                                       Quaternion.Euler(Vector3.zero),
                                       null,
                                       false);
        }