コード例 #1
0
        public static void ShotgunBlast(Item shooterItem, string projectileID, Transform spawnPoint, float distance, float force, float forceMult, string imbueSpell = null, float throwMult = 1.0f, bool pooled = false, Collider IgnoreArg1 = null)
        {
            if (Physics.Raycast(spawnPoint.position, spawnPoint.forward, out RaycastHit hit, distance))
            {
                Creature hitCreature = hit.collider.transform.root.GetComponentInParent <Creature>();
                if (hitCreature != null)
                {
                    if (hitCreature == Player.currentCreature)
                    {
                        return;
                    }
                    hitCreature.locomotion.rb.AddExplosionForce(force, hit.point, 1.0f, 1.0f, ForceMode.VelocityChange);
                    //hitCreature.ragdoll.SetState(Creature.State.Destabilized);
                    foreach (RagdollPart part in hitCreature.ragdoll.parts)
                    {
                        part.rb.AddExplosionForce(force, hit.point, 1.0f, 1.0f, ForceMode.VelocityChange);
                        part.rb.AddForce(spawnPoint.forward * force, ForceMode.Impulse);
                    }
                }
                else
                {
                    try
                    {
                        hit.collider.attachedRigidbody.AddExplosionForce(force, hit.point, 0.5f, 1.0f, ForceMode.VelocityChange);
                        hit.collider.attachedRigidbody.AddForce(spawnPoint.forward * force, ForceMode.Impulse);
                    }
                    catch { }
                }
            }

            var projectileData = Catalog.GetData <ItemData>(projectileID, true);

            if (projectileData == null)
            {
                Debug.LogError("[Modular-Firearms][ERROR] No projectile named " + projectileID.ToString());
                return;
            }
            foreach (Vector3 offsetVec in buckshotOffsetPosiitions)
            {
                projectileData.SpawnAsync(i =>
                {
                    try
                    {
                        i.transform.position = spawnPoint.position + offsetVec;
                        i.transform.rotation = Quaternion.Euler(spawnPoint.rotation.eulerAngles);
                        i.rb.velocity        = shooterItem.rb.velocity;
                        i.rb.AddForce(i.rb.transform.forward * 1000.0f * forceMult);
                        shooterItem.IgnoreObjectCollision(i);
                        i.IgnoreObjectCollision(shooterItem);
                        i.IgnoreRagdollCollision(Player.local.creature.ragdoll);

                        if (IgnoreArg1 != null)
                        {
                            try
                            {
                                i.IgnoreColliderCollision(IgnoreArg1);
                                foreach (ColliderGroup CG in shooterItem.colliderGroups)
                                {
                                    foreach (Collider C in CG.colliders)
                                    {
                                        Physics.IgnoreCollision(i.colliderGroups[0].colliders[0], C);
                                    }
                                }
                            }
                            catch { }
                        }

                        Projectiles.BasicProjectile projectileController = i.gameObject.GetComponent <Projectiles.BasicProjectile>();
                        if (projectileController != null)
                        {
                            projectileController.SetShooterItem(shooterItem);
                        }
                        if (!String.IsNullOrEmpty(imbueSpell))
                        {
                            if (projectileController != null)
                            {
                                projectileController.AddChargeToQueue(imbueSpell);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.Log("[Modular-Firearms] EXCEPTION IN SPAWNING " + ex.Message + " \n " + ex.StackTrace);
                    }
                },
                                          spawnPoint.position,
                                          Quaternion.Euler(spawnPoint.rotation.eulerAngles),
                                          null,
                                          false);
            }
        }
コード例 #2
0
        /// <summary>
        /// Spawn a projectile from the item catalog, optionally imbue it and propel it forward with a given force
        /// </summary>
        /// <param name="shooterItem"></param>
        /// <param name="projectileID"></param>
        /// <param name="spawnPoint"></param>
        /// <param name="imbueSpell"></param>
        /// <param name="forceMult"></param>
        /// <param name="throwMult"></param>
        /// <param name="pooled"></param>
        public static void ShootProjectile(Item shooterItem, string projectileID, Transform spawnPoint, string imbueSpell = null, float forceMult = 1.0f, float throwMult = 1.0f, bool pooled = false, Collider IgnoreArg1 = null, SetSpawningStatusDelegate SetSpawnStatus = null)
        {
            if ((spawnPoint == null) || (String.IsNullOrEmpty(projectileID)))
            {
                return;
            }
            var projectileData = Catalog.GetData <ItemData>(projectileID, true);

            if (projectileData == null)
            {
                Debug.LogError("[Modular-Firearms][ERROR] No projectile named " + projectileID.ToString());
                return;
            }
            else
            {
                Vector3    shootLocation = new Vector3(spawnPoint.position.x, spawnPoint.position.y, spawnPoint.position.z);
                Quaternion shooterAngles = Quaternion.Euler(spawnPoint.rotation.eulerAngles);
                Vector3    shootVelocity = new Vector3(shooterItem.rb.velocity.x, shooterItem.rb.velocity.y, shooterItem.rb.velocity.z);
                SetSpawnStatus?.Invoke(true);
                projectileData.SpawnAsync(i =>
                {
                    try
                    {
                        i.Throw(1f, Item.FlyDetection.Forced);
                        shooterItem.IgnoreObjectCollision(i);
                        i.IgnoreObjectCollision(shooterItem);
                        i.IgnoreRagdollCollision(Player.local.creature.ragdoll);
                        if (IgnoreArg1 != null)
                        {
                            try
                            {
                                i.IgnoreColliderCollision(IgnoreArg1);
                                foreach (ColliderGroup CG in shooterItem.colliderGroups)
                                {
                                    foreach (Collider C in CG.colliders)
                                    {
                                        Physics.IgnoreCollision(i.colliderGroups[0].colliders[0], C);
                                    }
                                }
                            }
                            catch { }
                        }
                        IgnoreProjectile(shooterItem, i, true);
                        Projectiles.BasicProjectile projectileController = i.gameObject.GetComponent <Projectiles.BasicProjectile>();
                        if (projectileController != null)
                        {
                            projectileController.SetShooterItem(shooterItem);
                        }
                        i.transform.position = shootLocation;
                        i.transform.rotation = shooterAngles;
                        i.rb.velocity        = shootVelocity;
                        i.rb.AddForce(i.rb.transform.forward * 1000.0f * forceMult);
                        if (!String.IsNullOrEmpty(imbueSpell))
                        {
                            if (projectileController != null)
                            {
                                projectileController.AddChargeToQueue(imbueSpell);
                            }
                        }
                        SetSpawnStatus?.Invoke(false);
                    }
                    catch
                    {
                        Debug.Log("[ModularFirearmsFramework] EXCEPTION IN SPAWNING ");
                    }
                },
                                          shootLocation,
                                          Quaternion.Euler(Vector3.zero),
                                          null,
                                          false);
            }
        }