public void Explode(Vector3 surfaceNormal)
 {
     if (!base.isServer)
     {
         return;
     }
     for (int i = 0; (float)i < this.numToCreate; i++)
     {
         GameManager gameManager = GameManager.server;
         string      str         = this.createOnExplode.resourcePath;
         Vector3     vector3     = base.transform.position;
         Quaternion  quaternion  = new Quaternion();
         BaseEntity  baseEntity  = gameManager.CreateEntity(str, vector3, quaternion, true);
         if (baseEntity)
         {
             baseEntity.transform.position = base.transform.position;
             Vector3 modifiedAimConeDirection = AimConeUtil.GetModifiedAimConeDirection(this.spreadAngle, surfaceNormal, true);
             baseEntity.transform.rotation = Quaternion.LookRotation(modifiedAimConeDirection);
             baseEntity.creatorEntity      = (this.creatorEntity == null ? baseEntity : this.creatorEntity);
             baseEntity.Spawn();
             baseEntity.SetVelocity(modifiedAimConeDirection * UnityEngine.Random.Range(this.minVelocity, this.maxVelocity));
         }
     }
     base.Explode();
 }
 public override void ServerProjectileHit(HitInfo info)
 {
     for (int i = 0; i < numToCreateChances; i++)
     {
         if (!createOnImpact.isValid || !(Random.Range(0f, 1f) < createOnImpactChance))
         {
             continue;
         }
         BaseEntity baseEntity = GameManager.server.CreateEntity(createOnImpact.resourcePath);
         if ((bool)baseEntity)
         {
             Vector3 hitPositionWorld = info.HitPositionWorld;
             Vector3 normalized       = info.HitNormalWorld.normalized;
             Vector3 normalized2      = info.ProjectileVelocity.normalized;
             baseEntity.transform.position = hitPositionWorld - normalized2 * 0.1f;
             baseEntity.transform.rotation = Quaternion.LookRotation(-normalized2);
             baseEntity.Spawn();
             if (spreadAngle > 0f)
             {
                 Vector3 modifiedAimConeDirection = AimConeUtil.GetModifiedAimConeDirection(spreadAngle, normalized);
                 baseEntity.SetVelocity(modifiedAimConeDirection * Random.Range(1f, 3f));
             }
         }
     }
     base.ServerProjectileHit(info);
 }
예제 #3
0
    public void FireBullet()
    {
        float   damageAmount     = 10f;
        Vector3 vector3          = Vector3.op_Subtraction(((Component)this.muzzlePos).get_transform().get_position(), Vector3.op_Multiply(this.muzzlePos.get_forward(), 0.25f));
        Vector3 aimConeDirection = AimConeUtil.GetModifiedAimConeDirection((float)this.aimCone, ((Component)this.muzzlePos).get_transform().get_forward(), true);

        this.ClientRPC <Vector3>((Connection)null, "CLIENT_FireGun", Vector3.op_Addition(vector3, Vector3.op_Multiply(aimConeDirection, 300f)));
        List <RaycastHit> list = (List <RaycastHit>)Pool.GetList <RaycastHit>();

        GamePhysics.TraceAll(new Ray(vector3, aimConeDirection), 0.1f, list, 300f, 1219701521, (QueryTriggerInteraction)0);
        for (int index = 0; index < list.Count; ++index)
        {
            RaycastHit hit    = list[index];
            BaseEntity entity = hit.GetEntity();
            if (!Object.op_Inequality((Object)entity, (Object)null) || !Object.op_Equality((Object)entity, (Object)this) && !entity.EqualNetID((BaseNetworkable)this))
            {
                if (Object.op_Inequality((Object)(entity as BaseCombatEntity), (Object)null))
                {
                    HitInfo info = new HitInfo((BaseEntity)this, entity, DamageType.Bullet, damageAmount, ((RaycastHit) ref hit).get_point());
                    entity.OnAttacked(info);
                    if (entity is BasePlayer || entity is BaseNpc)
                    {
                        Effect.server.ImpactEffect(new HitInfo()
                        {
                            HitPositionWorld = ((RaycastHit) ref hit).get_point(),
                            HitNormalWorld   = Vector3.op_UnaryNegation(((RaycastHit) ref hit).get_normal()),
                            HitMaterial      = StringPool.Get("Flesh")
                        });
예제 #4
0
    public void FireGunTest()
    {
        if (UnityEngine.Time.time < this.nextFireTime)
        {
            return;
        }
        this.nextFireTime = UnityEngine.Time.time + 0.25f;
        this.numBursted++;
        if (this.numBursted >= 4)
        {
            this.nextFireTime = UnityEngine.Time.time + 5f;
            this.numBursted   = 0;
        }
        Vector3 modifiedAimConeDirection = AimConeUtil.GetModifiedAimConeDirection(2f, this.CannonMuzzle.rotation * Vector3.forward, true);
        Vector3 cannonPitch = (this.CannonPitch.transform.rotation * Vector3.back) + (base.transform.up * -1f);
        Vector3 vector3     = cannonPitch.normalized;

        this.myRigidBody.AddForceAtPosition(vector3 * this.recoilScale, this.CannonPitch.transform.position, ForceMode.Impulse);
        Effect.server.Run(this.mainCannonMuzzleFlash.resourcePath, this, StringPool.Get(this.CannonMuzzle.gameObject.name), Vector3.zero, Vector3.zero, null, false);
        BaseEntity baseEntity = GameManager.server.CreateEntity(this.mainCannonProjectile.resourcePath, this.CannonMuzzle.transform.position, Quaternion.LookRotation(modifiedAimConeDirection), true);

        if (baseEntity == null)
        {
            return;
        }
        ServerProjectile component = baseEntity.GetComponent <ServerProjectile>();

        if (component)
        {
            component.InitializeVelocity(modifiedAimConeDirection * component.speed);
        }
        baseEntity.Spawn();
    }
예제 #5
0
 public override void ServerProjectileHit(HitInfo info)
 {
     for (int index = 0; index < this.numToCreateChances; ++index)
     {
         if (this.createOnImpact.isValid && (double)Random.Range(0.0f, 1f) < (double)this.createOnImpactChance)
         {
             BaseEntity entity = GameManager.server.CreateEntity(this.createOnImpact.resourcePath, (Vector3)null, (Quaternion)null, true);
             if (Object.op_Implicit((Object)entity))
             {
                 ((Component)entity).get_transform().set_position(Vector3.op_Addition(info.HitPositionWorld, Vector3.op_Multiply(info.HitNormalWorld, 0.1f)));
                 ((Component)entity).get_transform().set_rotation(Quaternion.LookRotation(info.HitNormalWorld));
                 if (!GamePhysics.LineOfSight(info.HitPositionWorld, ((Component)entity).get_transform().get_position(), 2162688, 0.0f))
                 {
                     ((Component)entity).get_transform().set_position(info.HitPositionWorld);
                 }
                 entity.Spawn();
                 if ((double)this.spreadAngle > 0.0)
                 {
                     Vector3 aimConeDirection = AimConeUtil.GetModifiedAimConeDirection(this.spreadAngle, info.HitNormalWorld, true);
                     entity.SetVelocity(Vector3.op_Multiply(aimConeDirection, Random.Range(1f, 3f)));
                 }
             }
         }
     }
     base.ServerProjectileHit(info);
 }
예제 #6
0
    public void FireGun(Vector3 targetPos, float aimCone, bool isCoax)
    {
        Transform transforms = (isCoax ? this.coaxMuzzle : this.topTurretMuzzle);
        Vector3   vector3    = transforms.transform.position - (transforms.forward * 0.25f);
        Vector3   vector31   = targetPos - vector3;
        Vector3   modifiedAimConeDirection = AimConeUtil.GetModifiedAimConeDirection(aimCone, vector31.normalized, true);

        targetPos = vector3 + (modifiedAimConeDirection * 300f);
        List <RaycastHit> list = Facepunch.Pool.GetList <RaycastHit>();

        GamePhysics.TraceAll(new Ray(vector3, modifiedAimConeDirection), 0f, list, 300f, 1219701521, QueryTriggerInteraction.UseGlobal);
        for (int i = 0; i < list.Count; i++)
        {
            RaycastHit item   = list[i];
            BaseEntity entity = item.GetEntity();
            if (!(entity != null) || !(entity == this) && !entity.EqualNetID(this))
            {
                BaseCombatEntity baseCombatEntity = entity as BaseCombatEntity;
                if (baseCombatEntity != null)
                {
                    this.ApplyDamage(baseCombatEntity, item.point, modifiedAimConeDirection);
                }
                if (!(entity != null) || entity.ShouldBlockProjectiles())
                {
                    targetPos = item.point;
                    break;
                }
            }
        }
        base.ClientRPC <bool, Vector3>(null, "CLIENT_FireGun", isCoax, targetPos);
        Facepunch.Pool.FreeList <RaycastHit>(ref list);
    }
예제 #7
0
    public void FireGunTest()
    {
        if (UnityEngine.Time.time < nextFireTime)
        {
            return;
        }
        nextFireTime = UnityEngine.Time.time + 0.25f;
        numBursted++;
        if (numBursted >= 4)
        {
            nextFireTime = UnityEngine.Time.time + 5f;
            numBursted   = 0;
        }
        Vector3 modifiedAimConeDirection = AimConeUtil.GetModifiedAimConeDirection(2f, CannonMuzzle.rotation * Vector3.forward);
        Vector3 normalized = (CannonPitch.transform.rotation * Vector3.back + base.transform.up * -1f).normalized;

        myRigidBody.AddForceAtPosition(normalized * recoilScale, CannonPitch.transform.position, ForceMode.Impulse);
        Effect.server.Run(mainCannonMuzzleFlash.resourcePath, this, StringPool.Get(CannonMuzzle.gameObject.name), Vector3.zero, Vector3.zero);
        BaseEntity baseEntity = GameManager.server.CreateEntity(mainCannonProjectile.resourcePath, CannonMuzzle.transform.position, Quaternion.LookRotation(modifiedAimConeDirection));

        if (!(baseEntity == null))
        {
            ServerProjectile component = baseEntity.GetComponent <ServerProjectile>();
            if ((bool)component)
            {
                component.InitializeVelocity(modifiedAimConeDirection * component.speed);
            }
            baseEntity.Spawn();
        }
    }
예제 #8
0
    public void FireGun(Vector3 targetPos, float aimCone, bool isCoax)
    {
        Transform transform  = (isCoax ? coaxMuzzle : topTurretMuzzle);
        Vector3   vector     = transform.transform.position - transform.forward * 0.25f;
        Vector3   normalized = (targetPos - vector).normalized;
        Vector3   modifiedAimConeDirection = AimConeUtil.GetModifiedAimConeDirection(aimCone, normalized);

        targetPos = vector + modifiedAimConeDirection * 300f;
        List <RaycastHit> obj = Facepunch.Pool.GetList <RaycastHit>();

        GamePhysics.TraceAll(new Ray(vector, modifiedAimConeDirection), 0f, obj, 300f, 1219701521);
        for (int i = 0; i < obj.Count; i++)
        {
            RaycastHit hit    = obj[i];
            BaseEntity entity = RaycastHitEx.GetEntity(hit);
            if (!(entity != null) || (!(entity == this) && !entity.EqualNetID(this)))
            {
                BaseCombatEntity baseCombatEntity = entity as BaseCombatEntity;
                if (baseCombatEntity != null)
                {
                    ApplyDamage(baseCombatEntity, hit.point, modifiedAimConeDirection);
                }
                if (!(entity != null) || entity.ShouldBlockProjectiles())
                {
                    targetPos = hit.point;
                    break;
                }
            }
        }
        ClientRPC(null, "CLIENT_FireGun", isCoax, targetPos);
        Facepunch.Pool.FreeList(ref obj);
    }
예제 #9
0
    public override void ServerUse(float damageModifier, Transform originOverride = null)
    {
        ItemModProjectile component = primaryMagazine.ammoType.GetComponent <ItemModProjectile>();

        if (!component)
        {
            return;
        }
        if (primaryMagazine.contents <= 0)
        {
            SignalBroadcast(Signal.DryFire);
            StartAttackCooldown(1f);
            return;
        }
        if (!component.projectileObject.Get().GetComponent <ServerProjectile>())
        {
            base.ServerUse(damageModifier, originOverride);
            return;
        }
        primaryMagazine.contents--;
        if (primaryMagazine.contents < 0)
        {
            primaryMagazine.contents = 0;
        }
        Vector3 vector   = MuzzlePoint.transform.forward;
        Vector3 position = MuzzlePoint.transform.position;
        float   num      = GetAimCone() + component.projectileSpread;

        if (num > 0f)
        {
            vector = AimConeUtil.GetModifiedAimConeDirection(num, vector);
        }
        float      num2 = 1f;
        RaycastHit hitInfo;

        if (UnityEngine.Physics.Raycast(position, vector, out hitInfo, num2, 1236478737))
        {
            num2 = hitInfo.distance - 0.1f;
        }
        BaseEntity baseEntity = GameManager.server.CreateEntity(component.projectileObject.resourcePath, position + vector * num2);

        if (!(baseEntity == null))
        {
            BasePlayer       ownerPlayer = GetOwnerPlayer();
            bool             flag        = ownerPlayer != null && ownerPlayer.IsNpc;
            ServerProjectile component2  = baseEntity.GetComponent <ServerProjectile>();
            if ((bool)component2)
            {
                component2.InitializeVelocity(vector * component2.speed);
            }
            baseEntity.SendMessage("SetDamageScale", flag ? npcDamageScale : turretDamageScale);
            baseEntity.Spawn();
            StartAttackCooldown(ScaleRepeatDelay(repeatDelay));
            SignalBroadcast(Signal.Attack, string.Empty);
            GetOwnerItem()?.LoseCondition(UnityEngine.Random.Range(1f, 2f));
        }
    }
예제 #10
0
 public void SpawnEggsAtPoint(int numEggs, Vector3 pos, Vector3 aimDir, float minDist = 1f, float maxDist = 2f)
 {
     for (int i = 0; i < numEggs; i++)
     {
         Vector3 vector = pos;
         aimDir   = ((!(aimDir == Vector3.zero)) ? AimConeUtil.GetModifiedAimConeDirection(90f, aimDir) : UnityEngine.Random.onUnitSphere);
         vector   = pos + Vector3Ex.Direction2D(pos + aimDir * 10f, pos) * UnityEngine.Random.Range(minDist, maxDist);
         vector.y = TerrainMeta.HeightMap.GetHeight(vector);
         CollectableEasterEgg collectableEasterEgg = GameManager.server.CreateEntity(HuntablePrefab[UnityEngine.Random.Range(0, HuntablePrefab.Length)].resourcePath, vector) as CollectableEasterEgg;
         collectableEasterEgg.Spawn();
         _spawnedEggs.Add(collectableEasterEgg);
     }
 }
    public void FireGun(Vector3 targetPos, float aimCone, bool left)
    {
        RaycastHit raycastHit;

        if (PatrolHelicopter.guns == 0)
        {
            return;
        }
        Vector3 vector3  = ((left ? this.helicopterBase.left_gun_muzzle.transform : this.helicopterBase.right_gun_muzzle.transform)).position;
        Vector3 vector31 = (targetPos - vector3).normalized;

        vector3 = vector3 + (vector31 * 2f);
        Vector3 modifiedAimConeDirection = AimConeUtil.GetModifiedAimConeDirection(aimCone, vector31, true);

        if (!GamePhysics.Trace(new Ray(vector3, modifiedAimConeDirection), 0f, out raycastHit, 300f, 1219701521, QueryTriggerInteraction.UseGlobal))
        {
            targetPos = vector3 + (modifiedAimConeDirection * 300f);
        }
        else
        {
            targetPos = raycastHit.point;
            if (raycastHit.collider)
            {
                BaseEntity entity = raycastHit.GetEntity();
                if (entity && entity != this.helicopterBase)
                {
                    BaseCombatEntity baseCombatEntity = entity as BaseCombatEntity;
                    HitInfo          hitInfo          = new HitInfo(this.helicopterBase, entity, DamageType.Bullet, this.helicopterBase.bulletDamage * PatrolHelicopter.bulletDamageScale, raycastHit.point);
                    if (!baseCombatEntity)
                    {
                        entity.OnAttacked(hitInfo);
                    }
                    else
                    {
                        baseCombatEntity.OnAttacked(hitInfo);
                        if (baseCombatEntity is BasePlayer)
                        {
                            Effect.server.ImpactEffect(new HitInfo()
                            {
                                HitPositionWorld = raycastHit.point - (modifiedAimConeDirection * 0.25f),
                                HitNormalWorld   = -modifiedAimConeDirection,
                                HitMaterial      = StringPool.Get("Flesh")
                            });
                        }
                    }
                }
            }
        }
        this.helicopterBase.ClientRPC <bool, Vector3>(null, "FireGun", left, targetPos);
    }
예제 #12
0
    public virtual void FireGun(
        Vector3 targetPos,
        float aimCone,
        Transform muzzleToUse   = null,
        BaseCombatEntity target = null)
    {
        if (this.IsOffline())
        {
            return;
        }
        if (Object.op_Equality((Object)muzzleToUse, (Object)null))
        {
            muzzleToUse = this.muzzlePos;
        }
        Vector3 vector3_1        = Vector3.op_Subtraction(((Component)this.GetCenterMuzzle()).get_transform().get_position(), Vector3.op_Multiply(this.GetCenterMuzzle().get_forward(), 0.25f));
        Vector3 forward          = ((Component)this.GetCenterMuzzle()).get_transform().get_forward();
        Vector3 aimConeDirection = AimConeUtil.GetModifiedAimConeDirection(aimCone, forward, true);

        targetPos = Vector3.op_Addition(vector3_1, Vector3.op_Multiply(aimConeDirection, 300f));
        List <RaycastHit> list = (List <RaycastHit>)Pool.GetList <RaycastHit>();

        GamePhysics.TraceAll(new Ray(vector3_1, aimConeDirection), 0.0f, list, 300f, 1219701521, (QueryTriggerInteraction)0);
        for (int index = 0; index < list.Count; ++index)
        {
            RaycastHit hit     = list[index];
            BaseEntity entity1 = hit.GetEntity();
            if ((!Object.op_Inequality((Object)entity1, (Object)null) || !Object.op_Equality((Object)entity1, (Object)this) && !entity1.EqualNetID((BaseNetworkable)this)) && (!Object.op_Inequality((Object)target, (Object)null) || !Object.op_Inequality((Object)entity1, (Object)null) || (!Object.op_Inequality((Object)((Component)entity1).GetComponent <BasePlayer>(), (Object)null) || entity1.EqualNetID((BaseNetworkable)target))))
            {
                BaseCombatEntity entity2 = entity1 as BaseCombatEntity;
                if (Object.op_Inequality((Object)entity2, (Object)null))
                {
                    this.ApplyDamage(entity2, ((RaycastHit) ref hit).get_point(), aimConeDirection);
                }
                if (!Object.op_Inequality((Object)entity1, (Object)null) || entity1.ShouldBlockProjectiles())
                {
                    targetPos = ((RaycastHit) ref hit).get_point();
                    Vector3 vector3_2 = Vector3.op_Subtraction(targetPos, vector3_1);
                    ((Vector3) ref vector3_2).get_normalized();
                    break;
                }
            }
        }
        this.ClientRPC <uint, Vector3>((Connection)null, "CLIENT_FireGun", StringPool.Get(((Object)((Component)muzzleToUse).get_gameObject()).get_name()), targetPos);
        // ISSUE: cast to a reference type
        Pool.FreeList <RaycastHit>((List <M0>&) ref list);
    }
예제 #13
0
    public void TryToSpread()
    {
        float num = 0.9f - generation * 0.1f;

        if (UnityEngine.Random.Range(0f, 1f) < num && spreadSubEntity.isValid)
        {
            BaseEntity baseEntity = GameManager.server.CreateEntity(spreadSubEntity.resourcePath);
            if ((bool)baseEntity)
            {
                baseEntity.transform.position = base.transform.position + Vector3.up * 0.25f;
                baseEntity.Spawn();
                Vector3 modifiedAimConeDirection = AimConeUtil.GetModifiedAimConeDirection(45f, Vector3.up);
                baseEntity.creatorEntity = ((creatorEntity == null) ? baseEntity : creatorEntity);
                Interface.CallHook("OnFireBallSpread", this, baseEntity);
                baseEntity.SetVelocity(modifiedAimConeDirection * UnityEngine.Random.Range(5f, 8f));
                baseEntity.SendMessage("SetGeneration", generation + 1f);
            }
        }
    }
예제 #14
0
    public void TryToSpread()
    {
        if ((double)Random.Range(0.0f, 1f) >= 0.899999976158142 - (double)this.generation * 0.100000001490116 || !this.spreadSubEntity.isValid)
        {
            return;
        }
        BaseEntity entity = GameManager.server.CreateEntity(this.spreadSubEntity.resourcePath, (Vector3)null, (Quaternion)null, true);

        if (!Object.op_Implicit((Object)entity))
        {
            return;
        }
        ((Component)entity).get_transform().set_position(Vector3.op_Addition(((Component)this).get_transform().get_position(), Vector3.op_Multiply(Vector3.get_up(), 0.25f)));
        entity.Spawn();
        Vector3 aimConeDirection = AimConeUtil.GetModifiedAimConeDirection(45f, Vector3.get_up(), true);

        entity.creatorEntity = Object.op_Equality((Object)this.creatorEntity, (Object)null) ? entity : this.creatorEntity;
        entity.SetVelocity(Vector3.op_Multiply(aimConeDirection, Random.Range(5f, 8f)));
        ((Component)entity).SendMessage("SetGeneration", (object)(float)((double)this.generation + 1.0));
    }
예제 #15
0
    public void FireBullet()
    {
        float   damageAmount = 10f;
        Vector3 vector       = muzzlePos.transform.position - muzzlePos.forward * 0.25f;
        Vector3 vector2      = AimConeUtil.GetModifiedAimConeDirection(inputVec: muzzlePos.transform.forward, aimCone: aimCone);
        Vector3 arg          = vector + vector2 * 300f;

        ClientRPC(null, "CLIENT_FireGun", arg);
        List <RaycastHit> list = Pool.GetList <RaycastHit>();
        int layerMask          = 1219701505;

        GamePhysics.TraceAll(new Ray(vector, vector2), 0.1f, list, 300f, layerMask);
        for (int i = 0; i < list.Count; i++)
        {
            RaycastHit hit    = list[i];
            BaseEntity entity = RaycastHitEx.GetEntity(hit);
            if (entity != null && (entity == this || entity.EqualNetID(this)))
            {
                continue;
            }
            if (entity as BaseCombatEntity != null)
            {
                HitInfo info = new HitInfo(this, entity, DamageType.Bullet, damageAmount, hit.point);
                entity.OnAttacked(info);
                if (entity is BasePlayer || entity is BaseNpc)
                {
                    Effect.server.ImpactEffect(new HitInfo
                    {
                        HitPositionWorld = hit.point,
                        HitNormalWorld   = -hit.normal,
                        HitMaterial      = StringPool.Get("Flesh")
                    });
                }
            }
            if (!(entity != null) || entity.ShouldBlockProjectiles())
            {
                arg = hit.point;
                break;
            }
        }
    }
    public void FireRocket()
    {
        RaycastHit raycastHit;
        string     str;

        this.numRocketsLeft--;
        this.lastRocketTime = UnityEngine.Time.realtimeSinceStartup;
        float single = 4f;
        bool  flag   = this.leftTubeFiredLast;

        this.leftTubeFiredLast = !this.leftTubeFiredLast;
        Transform transforms           = (flag ? this.helicopterBase.rocket_tube_left.transform : this.helicopterBase.rocket_tube_right.transform);
        Vector3   vector3              = transforms.position + (transforms.forward * 1f);
        Vector3   strafeTargetPosition = (this.strafe_target_position - vector3).normalized;

        if (single > 0f)
        {
            strafeTargetPosition = AimConeUtil.GetModifiedAimConeDirection(single, strafeTargetPosition, true);
        }
        if (UnityEngine.Physics.Raycast(vector3, strafeTargetPosition, out raycastHit, 1f, 1236478737))
        {
        }
        Effect.server.Run(this.helicopterBase.rocket_fire_effect.resourcePath, this.helicopterBase, StringPool.Get((flag ? "rocket_tube_left" : "rocket_tube_right")), Vector3.zero, Vector3.forward, null, true);
        GameManager gameManager = GameManager.server;

        str = (this.useNapalm ? this.rocketProjectile_Napalm.resourcePath : this.rocketProjectile.resourcePath);
        Quaternion quaternion = new Quaternion();
        BaseEntity baseEntity = gameManager.CreateEntity(str, vector3, quaternion, true);

        if (baseEntity == null)
        {
            return;
        }
        ServerProjectile component = baseEntity.GetComponent <ServerProjectile>();

        if (component)
        {
            component.InitializeVelocity(strafeTargetPosition * component.speed);
        }
        baseEntity.Spawn();
    }
예제 #17
0
 public void Explode(Vector3 surfaceNormal)
 {
     if (!this.isServer)
     {
         return;
     }
     for (int index = 0; (double)index < (double)this.numToCreate; ++index)
     {
         BaseEntity entity = GameManager.server.CreateEntity(this.createOnExplode.resourcePath, ((Component)this).get_transform().get_position(), (Quaternion)null, true);
         if (Object.op_Implicit((Object)entity))
         {
             ((Component)entity).get_transform().set_position(((Component)this).get_transform().get_position());
             Vector3 aimConeDirection = AimConeUtil.GetModifiedAimConeDirection(this.spreadAngle, surfaceNormal, true);
             ((Component)entity).get_transform().set_rotation(Quaternion.LookRotation(aimConeDirection));
             entity.creatorEntity = Object.op_Equality((Object)this.creatorEntity, (Object)null) ? entity : this.creatorEntity;
             entity.Spawn();
             entity.SetVelocity(Vector3.op_Multiply(aimConeDirection, Random.Range(this.minVelocity, this.maxVelocity)));
         }
     }
     base.Explode();
 }
예제 #18
0
 public void Explode(Vector3 surfaceNormal)
 {
     if (!base.isServer)
     {
         return;
     }
     for (int i = 0; (float)i < numToCreate; i++)
     {
         BaseEntity baseEntity = GameManager.server.CreateEntity(createOnExplode.resourcePath, base.transform.position);
         if ((bool)baseEntity)
         {
             Vector3 modifiedAimConeDirection = AimConeUtil.GetModifiedAimConeDirection(spreadAngle, surfaceNormal);
             baseEntity.transform.SetPositionAndRotation(base.transform.position, Quaternion.LookRotation(modifiedAimConeDirection));
             baseEntity.creatorEntity = ((creatorEntity == null) ? baseEntity : creatorEntity);
             Interface.CallHook("OnFlameExplosion", this, baseEntity);
             baseEntity.Spawn();
             baseEntity.SetVelocity(modifiedAimConeDirection * UnityEngine.Random.Range(minVelocity, maxVelocity));
         }
     }
     base.Explode();
 }
예제 #19
0
    public virtual void FireGun(Vector3 targetPos, float aimCone, Transform muzzleToUse = null, BaseCombatEntity target = null)
    {
        if (this.IsOffline())
        {
            return;
        }
        if (muzzleToUse == null)
        {
            muzzleToUse = this.muzzlePos;
        }
        Vector3 centerMuzzle             = this.GetCenterMuzzle().transform.position - (this.GetCenterMuzzle().forward * 0.25f);
        Vector3 vector3                  = this.GetCenterMuzzle().transform.forward;
        Vector3 modifiedAimConeDirection = AimConeUtil.GetModifiedAimConeDirection(aimCone, vector3, true);

        targetPos = centerMuzzle + (modifiedAimConeDirection * 300f);
        List <RaycastHit> list = Facepunch.Pool.GetList <RaycastHit>();

        GamePhysics.TraceAll(new Ray(centerMuzzle, modifiedAimConeDirection), 0f, list, 300f, 1219701521, QueryTriggerInteraction.UseGlobal);
        for (int i = 0; i < list.Count; i++)
        {
            RaycastHit item   = list[i];
            BaseEntity entity = item.GetEntity();
            if ((!(entity != null) || !(entity == this) && !entity.EqualNetID(this)) && (!(target != null) || !(entity != null) || !(entity.GetComponent <BasePlayer>() != null) || entity.EqualNetID(target)))
            {
                BaseCombatEntity baseCombatEntity = entity as BaseCombatEntity;
                if (baseCombatEntity != null)
                {
                    this.ApplyDamage(baseCombatEntity, item.point, modifiedAimConeDirection);
                }
                if (!(entity != null) || entity.ShouldBlockProjectiles())
                {
                    targetPos = item.point;
                    vector3   = (targetPos - centerMuzzle).normalized;
                    break;
                }
            }
        }
        base.ClientRPC <uint, Vector3>(null, "CLIENT_FireGun", StringPool.Get(muzzleToUse.gameObject.name), targetPos);
        Facepunch.Pool.FreeList <RaycastHit>(ref list);
    }
예제 #20
0
    public void FireBullet()
    {
        float   single   = 10f;
        Vector3 vector3  = this.muzzlePos.transform.position - (this.muzzlePos.forward * 0.25f);
        Vector3 vector31 = this.muzzlePos.transform.forward;
        Vector3 modifiedAimConeDirection = AimConeUtil.GetModifiedAimConeDirection((float)this.aimCone, vector31, true);
        Vector3 vector32 = vector3 + (modifiedAimConeDirection * 300f);

        base.ClientRPC <Vector3>(null, "CLIENT_FireGun", vector32);
        List <RaycastHit> list = Pool.GetList <RaycastHit>();

        GamePhysics.TraceAll(new Ray(vector3, modifiedAimConeDirection), 0.1f, list, 300f, 1219701521, QueryTriggerInteraction.UseGlobal);
        for (int i = 0; i < list.Count; i++)
        {
            RaycastHit item   = list[i];
            BaseEntity entity = item.GetEntity();
            if (!(entity != null) || !(entity == this) && !entity.EqualNetID(this))
            {
                if (entity is BaseCombatEntity)
                {
                    HitInfo hitInfo = new HitInfo(this, entity, DamageType.Bullet, single, item.point);
                    entity.OnAttacked(hitInfo);
                    if (entity is BasePlayer || entity is BaseNpc)
                    {
                        Effect.server.ImpactEffect(new HitInfo()
                        {
                            HitPositionWorld = item.point,
                            HitNormalWorld   = -item.normal,
                            HitMaterial      = StringPool.Get("Flesh")
                        });
                    }
                }
                if (!(entity != null) || entity.ShouldBlockProjectiles())
                {
                    vector32 = item.point;
                    return;
                }
            }
        }
    }
예제 #21
0
 public void SpawnEggsAtPoint(int numEggs, Vector3 pos, Vector3 aimDir, float minDist = 1f, float maxDist = 2f)
 {
     for (int i = 0; i < numEggs; i++)
     {
         Vector3 height = pos;
         if (aimDir != Vector3.zero)
         {
             aimDir = AimConeUtil.GetModifiedAimConeDirection(90f, aimDir, true);
         }
         else
         {
             aimDir = UnityEngine.Random.onUnitSphere;
         }
         height   = pos + (Vector3Ex.Direction2D(pos + (aimDir * 10f), pos) * UnityEngine.Random.Range(minDist, maxDist));
         height.y = TerrainMeta.HeightMap.GetHeight(height);
         GameManager          gameManager          = GameManager.server;
         string               eggPrefabs           = this.EggPrefabs[UnityEngine.Random.Range(0, (int)this.EggPrefabs.Length)].resourcePath;
         Quaternion           quaternion           = new Quaternion();
         CollectableEasterEgg collectableEasterEgg = gameManager.CreateEntity(eggPrefabs, height, quaternion, true) as CollectableEasterEgg;
         collectableEasterEgg.Spawn();
         this._spawnedEggs.Add(collectableEasterEgg);
     }
 }
 public override void ServerProjectileHit(HitInfo info)
 {
     for (int i = 0; i < this.numToCreateChances; i++)
     {
         if (this.createOnImpact.isValid && UnityEngine.Random.Range(0f, 1f) < this.createOnImpactChance)
         {
             GameManager gameManager = GameManager.server;
             string      str         = this.createOnImpact.resourcePath;
             Vector3     vector3     = new Vector3();
             Quaternion  quaternion  = new Quaternion();
             BaseEntity  baseEntity  = gameManager.CreateEntity(str, vector3, quaternion, true);
             if (baseEntity)
             {
                 Vector3 hitPositionWorld = info.HitPositionWorld;
                 Vector3 hitNormalWorld   = info.HitNormalWorld.normalized;
                 Vector3 vector31         = hitPositionWorld + (hitNormalWorld * 0.1f);
                 if (!GamePhysics.LineOfSight(hitPositionWorld, vector31, 2162688, 0f))
                 {
                     baseEntity.transform.position = hitPositionWorld;
                 }
                 else
                 {
                     baseEntity.transform.position = vector31;
                 }
                 baseEntity.transform.rotation = Quaternion.LookRotation(hitNormalWorld);
                 baseEntity.Spawn();
                 if (this.spreadAngle > 0f)
                 {
                     Vector3 modifiedAimConeDirection = AimConeUtil.GetModifiedAimConeDirection(this.spreadAngle, hitNormalWorld, true);
                     baseEntity.SetVelocity(modifiedAimConeDirection * UnityEngine.Random.Range(1f, 3f));
                 }
             }
         }
     }
     base.ServerProjectileHit(info);
 }
예제 #23
0
            public void FireRocket()
            {
                RaycastHit raycastHit;
                string     str;

                this.lastRocketTime = Time.realtimeSinceStartup;
                float     single     = 4f;
                Transform transforms = this.entity.frontWheel.transform;
                Vector3   vector3    = transforms.position + (transforms.forward * 1f);

                if (single > 0f)
                {
                    strafeTargetPosition = AimConeUtil.GetModifiedAimConeDirection(single, entity.frontWheel.transform.rotation * Vector3.forward, true);
                }
                if (Physics.Raycast(vector3, strafeTargetPosition, out raycastHit, 1f, 1236478737))
                {
                }
                //Effect.server.Run(this.helicopterBase.rocket_fire_effect.resourcePath, this.helicopterBase, StringPool.Get((flag ? "rocket_tube_left" : "rocket_tube_right")), Vector3.zero, Vector3.forward, null, true);
                GameManager gameManager = GameManager.server;

                str = "assets/prefabs/npc/patrol helicopter/rocket_heli_airburst.prefab";
                Quaternion quaternion = new Quaternion();
                BaseEntity baseEntity = gameManager.CreateEntity(str, vector3, quaternion, true);

                if (baseEntity == null)
                {
                    return;
                }
                ServerProjectile component = baseEntity.GetComponent <ServerProjectile>();

                if (component)
                {
                    component.InitializeVelocity(strafeTargetPosition * component.speed);
                }
                baseEntity.Spawn();
            }
예제 #24
0
 public void TryToSpread()
 {
     if (UnityEngine.Random.Range(0f, 1f) >= 0.9f - this.generation * 0.1f)
     {
         return;
     }
     if (this.spreadSubEntity.isValid)
     {
         GameManager gameManager = GameManager.server;
         string      str         = this.spreadSubEntity.resourcePath;
         Vector3     vector3     = new Vector3();
         Quaternion  quaternion  = new Quaternion();
         BaseEntity  baseEntity  = gameManager.CreateEntity(str, vector3, quaternion, true);
         if (baseEntity)
         {
             baseEntity.transform.position = base.transform.position + (Vector3.up * 0.25f);
             baseEntity.Spawn();
             Vector3 modifiedAimConeDirection = AimConeUtil.GetModifiedAimConeDirection(45f, Vector3.up, true);
             baseEntity.creatorEntity = (this.creatorEntity == null ? baseEntity : this.creatorEntity);
             baseEntity.SetVelocity(modifiedAimConeDirection * UnityEngine.Random.Range(5f, 8f));
             baseEntity.SendMessage("SetGeneration", this.generation + 1f);
         }
     }
 }
예제 #25
0
    private void SV_Launch(BaseEntity.RPCMessage msg)
    {
        BasePlayer player = msg.player;

        if (!this.VerifyClientAttack(player))
        {
            this.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
        }
        else if (this.reloadFinished && this.HasReloadCooldown())
        {
            AntiHack.Log(player, AntiHackType.ProjectileHack, "Reloading (" + this.ShortPrefabName + ")");
            player.stats.combat.Log((AttackEntity)this, "reload_cooldown");
        }
        else
        {
            this.reloadStarted  = false;
            this.reloadFinished = false;
            if (this.primaryMagazine.contents <= 0)
            {
                AntiHack.Log(player, AntiHackType.ProjectileHack, "Magazine empty (" + this.ShortPrefabName + ")");
                player.stats.combat.Log((AttackEntity)this, "magazine_empty");
            }
            else
            {
                --this.primaryMagazine.contents;
                this.SignalBroadcast(BaseEntity.Signal.Attack, string.Empty, player.net.get_connection());
                Vector3    eyePos     = msg.read.Vector3();
                Vector3    vector3    = msg.read.Vector3();
                Vector3    inputVec   = ((Vector3) ref vector3).get_normalized();
                int        num1       = msg.read.Bit() ? 1 : 0;
                BaseEntity baseEntity = player.GetParentEntity();
                if (Object.op_Equality((Object)baseEntity, (Object)null))
                {
                    baseEntity = (BaseEntity)player.GetMounted();
                }
                if (num1 != 0)
                {
                    if (Object.op_Inequality((Object)baseEntity, (Object)null))
                    {
                        eyePos   = ((Component)baseEntity).get_transform().TransformPoint(eyePos);
                        inputVec = ((Component)baseEntity).get_transform().TransformDirection(inputVec);
                    }
                    else
                    {
                        eyePos   = player.eyes.position;
                        inputVec = player.eyes.BodyForward();
                    }
                }
                if (!this.ValidateEyePos(player, eyePos))
                {
                    return;
                }
                ItemModProjectile component1 = (ItemModProjectile)((Component)this.primaryMagazine.ammoType).GetComponent <ItemModProjectile>();
                if (!Object.op_Implicit((Object)component1))
                {
                    AntiHack.Log(player, AntiHackType.ProjectileHack, "Item mod not found (" + this.ShortPrefabName + ")");
                    player.stats.combat.Log((AttackEntity)this, "mod_missing");
                }
                else
                {
                    float aimCone = this.GetAimCone() + component1.projectileSpread;
                    if ((double)aimCone > 0.0)
                    {
                        inputVec = AimConeUtil.GetModifiedAimConeDirection(aimCone, inputVec, true);
                    }
                    float      num2 = 1f;
                    RaycastHit raycastHit;
                    if (Physics.Raycast(eyePos, inputVec, ref raycastHit, num2, 1236478737))
                    {
                        num2 = ((RaycastHit) ref raycastHit).get_distance() - 0.1f;
                    }
                    BaseEntity entity = GameManager.server.CreateEntity(component1.projectileObject.resourcePath, Vector3.op_Addition(eyePos, Vector3.op_Multiply(inputVec, num2)), (Quaternion)null, true);
                    if (Object.op_Equality((Object)entity, (Object)null))
                    {
                        return;
                    }
                    entity.creatorEntity = (BaseEntity)player;
                    ServerProjectile component2 = (ServerProjectile)((Component)entity).GetComponent <ServerProjectile>();
                    if (Object.op_Implicit((Object)component2))
                    {
                        component2.InitializeVelocity(Vector3.op_Addition(player.GetInheritedProjectileVelocity(), Vector3.op_Multiply(inputVec, component2.speed)));
                    }
                    entity.Spawn();
                    this.StartAttackCooldown(this.ScaleRepeatDelay(this.repeatDelay));
                    Interface.CallHook("OnRocketLaunched", (object)player, (object)entity);
                    this.GetOwnerItem()?.LoseCondition(Random.Range(1f, 2f));
                }
            }
        }
    }
예제 #26
0
    private void SV_Launch(BaseEntity.RPCMessage msg)
    {
        RaycastHit raycastHit;
        BasePlayer basePlayer = msg.player;

        if (!this.VerifyClientAttack(basePlayer))
        {
            base.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
            return;
        }
        if (this.reloadFinished && base.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)
        {
            AntiHack.Log(basePlayer, AntiHackType.ProjectileHack, string.Concat("Magazine empty (", base.ShortPrefabName, ")"));
            basePlayer.stats.combat.Log(this, "magazine_empty");
            return;
        }
        this.primaryMagazine.contents--;
        base.SignalBroadcast(BaseEntity.Signal.Attack, string.Empty, basePlayer.net.connection);
        Vector3    vector3 = msg.read.Vector3();
        Vector3    modifiedAimConeDirection = msg.read.Vector3().normalized;
        bool       flag         = msg.read.Bit();
        BaseEntity parentEntity = basePlayer.GetParentEntity();

        if (parentEntity == null)
        {
            parentEntity = basePlayer.GetMounted();
        }
        if (flag)
        {
            if (parentEntity == null)
            {
                vector3 = basePlayer.eyes.position;
                modifiedAimConeDirection = basePlayer.eyes.BodyForward();
            }
            else
            {
                vector3 = parentEntity.transform.TransformPoint(vector3);
                modifiedAimConeDirection = parentEntity.transform.TransformDirection(modifiedAimConeDirection);
            }
        }
        if (!base.ValidateEyePos(basePlayer, vector3))
        {
            return;
        }
        ItemModProjectile component = this.primaryMagazine.ammoType.GetComponent <ItemModProjectile>();

        if (!component)
        {
            AntiHack.Log(basePlayer, AntiHackType.ProjectileHack, string.Concat("Item mod not found (", base.ShortPrefabName, ")"));
            basePlayer.stats.combat.Log(this, "mod_missing");
            return;
        }
        float aimCone = this.GetAimCone() + component.projectileSpread;

        if (aimCone > 0f)
        {
            modifiedAimConeDirection = AimConeUtil.GetModifiedAimConeDirection(aimCone, modifiedAimConeDirection, true);
        }
        float single = 1f;

        if (UnityEngine.Physics.Raycast(vector3, modifiedAimConeDirection, out raycastHit, single, 1236478737))
        {
            single = raycastHit.distance - 0.1f;
        }
        GameManager gameManager = GameManager.server;
        string      str         = component.projectileObject.resourcePath;
        Vector3     vector31    = vector3 + (modifiedAimConeDirection * single);
        Quaternion  quaternion  = new Quaternion();
        BaseEntity  baseEntity  = gameManager.CreateEntity(str, vector31, quaternion, true);

        if (baseEntity == null)
        {
            return;
        }
        baseEntity.creatorEntity = basePlayer;
        ServerProjectile serverProjectile = baseEntity.GetComponent <ServerProjectile>();

        if (serverProjectile)
        {
            serverProjectile.InitializeVelocity(basePlayer.GetInheritedProjectileVelocity() + (modifiedAimConeDirection * serverProjectile.speed));
        }
        baseEntity.Spawn();
        base.StartAttackCooldown(base.ScaleRepeatDelay(this.repeatDelay));
        Interface.CallHook("OnRocketLaunched", basePlayer, baseEntity);
        Item ownerItem = base.GetOwnerItem();

        if (ownerItem == null)
        {
            return;
        }
        ownerItem.LoseCondition(UnityEngine.Random.Range(1f, 2f));
    }
예제 #27
0
    private void SV_Launch(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)
        {
            AntiHack.Log(player, AntiHackType.ProjectileHack, "Magazine empty (" + base.ShortPrefabName + ")");
            player.stats.combat.Log(this, "magazine_empty");
            return;
        }
        primaryMagazine.contents--;
        SignalBroadcast(Signal.Attack, string.Empty, player.net.connection);
        Vector3    vector  = msg.read.Vector3();
        Vector3    vector2 = msg.read.Vector3().normalized;
        bool       num     = msg.read.Bit();
        BaseEntity mounted = player.GetParentEntity();

        if (mounted == null)
        {
            mounted = player.GetMounted();
        }
        if (num)
        {
            if (mounted != null)
            {
                vector  = mounted.transform.TransformPoint(vector);
                vector2 = mounted.transform.TransformDirection(vector2);
            }
            else
            {
                vector  = player.eyes.position;
                vector2 = player.eyes.BodyForward();
            }
        }
        if (!ValidateEyePos(player, vector))
        {
            return;
        }
        ItemModProjectile component = primaryMagazine.ammoType.GetComponent <ItemModProjectile>();

        if (!component)
        {
            AntiHack.Log(player, AntiHackType.ProjectileHack, "Item mod not found (" + base.ShortPrefabName + ")");
            player.stats.combat.Log(this, "mod_missing");
            return;
        }
        float num2 = GetAimCone() + component.projectileSpread;

        if (num2 > 0f)
        {
            vector2 = AimConeUtil.GetModifiedAimConeDirection(num2, vector2);
        }
        float      num3 = 1f;
        RaycastHit hitInfo;

        if (UnityEngine.Physics.Raycast(vector, vector2, out hitInfo, num3, 1236478737))
        {
            num3 = hitInfo.distance - 0.1f;
        }
        BaseEntity baseEntity = GameManager.server.CreateEntity(component.projectileObject.resourcePath, vector + vector2 * num3);

        if (!(baseEntity == null))
        {
            baseEntity.creatorEntity = player;
            ServerProjectile component2 = baseEntity.GetComponent <ServerProjectile>();
            if ((bool)component2)
            {
                component2.InitializeVelocity(GetInheritedVelocity(player) + vector2 * component2.speed);
            }
            baseEntity.Spawn();
            StartAttackCooldown(ScaleRepeatDelay(repeatDelay));
            Interface.CallHook("OnRocketLaunched", player, baseEntity);
            GetOwnerItem()?.LoseCondition(UnityEngine.Random.Range(1f, 2f));
        }
    }
예제 #28
0
    public void ThrowEgg(BaseEntity.RPCMessage msg)
    {
        RaycastHit raycastHit;
        BasePlayer basePlayer = msg.player;

        if (!this.VerifyClientAttack(basePlayer))
        {
            base.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
            return;
        }
        if (!this.HasAmmo())
        {
            return;
        }
        this.UseAmmo();
        Vector3    vector3 = msg.read.Vector3();
        Vector3    modifiedAimConeDirection = msg.read.Vector3().normalized;
        bool       flag         = msg.read.Bit();
        BaseEntity parentEntity = basePlayer.GetParentEntity();

        if (parentEntity == null)
        {
            parentEntity = basePlayer.GetMounted();
        }
        if (flag)
        {
            if (parentEntity == null)
            {
                vector3 = basePlayer.eyes.position;
                modifiedAimConeDirection = basePlayer.eyes.BodyForward();
            }
            else
            {
                vector3 = parentEntity.transform.TransformPoint(vector3);
                modifiedAimConeDirection = parentEntity.transform.TransformDirection(modifiedAimConeDirection);
            }
        }
        if (!base.ValidateEyePos(basePlayer, vector3))
        {
            return;
        }
        float single = 2f;

        if (single > 0f)
        {
            modifiedAimConeDirection = AimConeUtil.GetModifiedAimConeDirection(single, modifiedAimConeDirection, true);
        }
        float single1 = 1f;

        if (UnityEngine.Physics.Raycast(vector3, modifiedAimConeDirection, out raycastHit, single1, 1236478737))
        {
            single1 = raycastHit.distance - 0.1f;
        }
        GameManager gameManager = GameManager.server;
        string      str         = this.eggProjectile.resourcePath;
        Vector3     vector31    = vector3 + (modifiedAimConeDirection * single1);
        Quaternion  quaternion  = new Quaternion();
        BaseEntity  baseEntity  = gameManager.CreateEntity(str, vector31, quaternion, true);

        if (baseEntity == null)
        {
            return;
        }
        baseEntity.creatorEntity = basePlayer;
        ServerProjectile component = baseEntity.GetComponent <ServerProjectile>();

        if (component)
        {
            component.InitializeVelocity(basePlayer.GetInheritedProjectileVelocity() + (modifiedAimConeDirection * component.speed));
        }
        baseEntity.Spawn();
        Item ownerItem = base.GetOwnerItem();

        if (ownerItem == null)
        {
            return;
        }
        ownerItem.LoseCondition(UnityEngine.Random.Range(1f, 2f));
    }
예제 #29
0
    public override void ServerUse(float damageModifier, Transform originOverride = null)
    {
        if (base.isClient || HasAttackCooldown())
        {
            return;
        }
        BasePlayer ownerPlayer = GetOwnerPlayer();
        bool       flag        = ownerPlayer != null;

        if (primaryMagazine.contents <= 0)
        {
            SignalBroadcast(Signal.DryFire);
            StartAttackCooldownRaw(1f);
            return;
        }
        primaryMagazine.contents--;
        if (primaryMagazine.contents < 0)
        {
            primaryMagazine.contents = 0;
        }
        bool flag2 = flag && ownerPlayer.IsNpc;

        if (flag2 && (ownerPlayer.isMounted || ownerPlayer.GetParentEntity() != null))
        {
            NPCPlayer nPCPlayer = ownerPlayer as NPCPlayer;
            if (nPCPlayer != null)
            {
                nPCPlayer.SetAimDirection(nPCPlayer.GetAimDirection());
            }
            else
            {
                HTNPlayer hTNPlayer = ownerPlayer as HTNPlayer;
                if (hTNPlayer != null)
                {
                    hTNPlayer.AiDomain.ForceProjectileOrientation();
                    hTNPlayer.ForceOrientationTick();
                }
            }
        }
        StartAttackCooldownRaw(repeatDelay);
        UnityEngine.Vector3 vector   = (flag ? ownerPlayer.eyes.position : MuzzlePoint.transform.position);
        UnityEngine.Vector3 inputVec = MuzzlePoint.transform.forward;
        if (originOverride != null)
        {
            vector   = originOverride.position;
            inputVec = originOverride.forward;
        }
        ItemModProjectile component = primaryMagazine.ammoType.GetComponent <ItemModProjectile>();

        SignalBroadcast(Signal.Attack, string.Empty);
        Projectile component2 = component.projectileObject.Get().GetComponent <Projectile>();
        BaseEntity baseEntity = null;

        if (flag && ownerPlayer.IsNpc && AI.npc_only_hurt_active_target_in_safezone && ownerPlayer.InSafeZone())
        {
            IAIAgent iAIAgent = ownerPlayer as IAIAgent;
            if (iAIAgent != null)
            {
                baseEntity = iAIAgent.AttackTarget;
            }
            else
            {
                IHTNAgent iHTNAgent = ownerPlayer as IHTNAgent;
                if (iHTNAgent != null)
                {
                    baseEntity = iHTNAgent.MainTarget;
                }
            }
        }
        bool flag3 = flag && ownerPlayer is IHTNAgent;

        if (flag)
        {
            inputVec = ((!flag3) ? ownerPlayer.eyes.BodyForward() : (ownerPlayer.eyes.rotation * UnityEngine.Vector3.forward));
        }
        for (int i = 0; i < component.numProjectiles; i++)
        {
            UnityEngine.Vector3 vector2 = ((!flag3) ? AimConeUtil.GetModifiedAimConeDirection(component.projectileSpread + GetAimCone() + GetAIAimcone() * 1f, inputVec) : AimConeUtil.GetModifiedAimConeDirection(component.projectileSpread + aimCone, inputVec));
            List <RaycastHit>   obj     = Facepunch.Pool.GetList <RaycastHit>();
            GamePhysics.TraceAll(new Ray(vector, vector2), 0f, obj, 300f, 1219701505);
            for (int j = 0; j < obj.Count; j++)
            {
                RaycastHit hit    = obj[j];
                BaseEntity entity = RaycastHitEx.GetEntity(hit);
                if ((entity != null && (entity == this || entity.EqualNetID(this))) || (entity != null && entity.isClient))
                {
                    continue;
                }
                ColliderInfo component3 = hit.collider.GetComponent <ColliderInfo>();
                if (component3 != null && !component3.HasFlag(ColliderInfo.Flags.Shootable))
                {
                    continue;
                }
                BaseCombatEntity baseCombatEntity = entity as BaseCombatEntity;
                if (entity != null && baseCombatEntity != null && (baseEntity == null || entity == baseEntity || entity.EqualNetID(baseEntity)))
                {
                    HitInfo hitInfo = new HitInfo();
                    AssignInitiator(hitInfo);
                    hitInfo.Weapon             = this;
                    hitInfo.WeaponPrefab       = base.gameManager.FindPrefab(base.PrefabName).GetComponent <AttackEntity>();
                    hitInfo.IsPredicting       = false;
                    hitInfo.DoHitEffects       = component2.doDefaultHitEffects;
                    hitInfo.DidHit             = true;
                    hitInfo.ProjectileVelocity = vector2 * 300f;
                    hitInfo.PointStart         = MuzzlePoint.position;
                    hitInfo.PointEnd           = hit.point;
                    hitInfo.HitPositionWorld   = hit.point;
                    hitInfo.HitNormalWorld     = hit.normal;
                    hitInfo.HitEntity          = entity;
                    hitInfo.UseProtection      = true;
                    component2.CalculateDamage(hitInfo, GetProjectileModifier(), 1f);
                    hitInfo.damageTypes.ScaleAll(GetDamageScale() * damageModifier * (flag2 ? npcDamageScale : turretDamageScale));
                    baseCombatEntity.OnAttacked(hitInfo);
                    component.ServerProjectileHit(hitInfo);
                    if (entity is BasePlayer || entity is BaseNpc)
                    {
                        hitInfo.HitPositionLocal = entity.transform.InverseTransformPoint(hitInfo.HitPositionWorld);
                        hitInfo.HitNormalLocal   = entity.transform.InverseTransformDirection(hitInfo.HitNormalWorld);
                        hitInfo.HitMaterial      = StringPool.Get("Flesh");
                        Effect.server.ImpactEffect(hitInfo);
                    }
                }
                if (!(entity != null) || entity.ShouldBlockProjectiles())
                {
                    break;
                }
            }
            Facepunch.Pool.FreeList(ref obj);
            UnityEngine.Vector3 vector3 = ((flag && ownerPlayer.isMounted) ? (vector2 * 6f) : UnityEngine.Vector3.zero);
            CreateProjectileEffectClientside(component.projectileObject.resourcePath, vector + vector3, vector2 * component.projectileVelocity, UnityEngine.Random.Range(1, 100), null, IsSilenced(), true);
        }
    }
예제 #30
0
    public override void Explode()
    {
        RaycastHit raycastHit;

        base.Explode();
        if (WaterLevel.Test(base.transform.position))
        {
            return;
        }
        ResourceDepositManager.ResourceDeposit orCreate = ResourceDepositManager.GetOrCreate(base.transform.position);
        if (orCreate == null)
        {
            return;
        }
        if (Time.realtimeSinceStartup - orCreate.lastSurveyTime < 10f)
        {
            return;
        }
        orCreate.lastSurveyTime = Time.realtimeSinceStartup;
        if (!TransformUtil.GetGroundInfo(base.transform.position, out raycastHit, 0.3f, 8388608, null))
        {
            return;
        }
        Vector3             vector3  = raycastHit.point;
        Vector3             vector31 = raycastHit.normal;
        List <SurveyCrater> list     = Pool.GetList <SurveyCrater>();

        Vis.Entities <SurveyCrater>(base.transform.position, 10f, list, 1, QueryTriggerInteraction.Collide);
        bool count = list.Count > 0;

        Pool.FreeList <SurveyCrater>(ref list);
        if (count)
        {
            return;
        }
        bool flag  = false;
        bool flag1 = false;

        foreach (ResourceDepositManager.ResourceDeposit.ResourceDepositEntry _resource in orCreate._resources)
        {
            if (_resource.spawnType != ResourceDepositManager.ResourceDeposit.surveySpawnType.ITEM || _resource.isLiquid || _resource.amount < 1000)
            {
                continue;
            }
            int num  = Mathf.Clamp(Mathf.CeilToInt(2.5f / _resource.workNeeded * 10f), 0, 5);
            int num1 = 1;
            flag = true;
            if (_resource.isLiquid)
            {
                flag1 = true;
            }
            for (int i = 0; i < num; i++)
            {
                Item    item = ItemManager.Create(_resource.type, num1, (ulong)0);
                Vector3 modifiedAimConeDirection = AimConeUtil.GetModifiedAimConeDirection(20f, Vector3.up, true);
                item.Drop(base.transform.position + (Vector3.up * 1f), this.GetInheritedDropVelocity() + (modifiedAimConeDirection * UnityEngine.Random.Range(5f, 10f)), UnityEngine.Random.rotation).SetAngularVelocity(UnityEngine.Random.rotation.eulerAngles * 5f);
            }
        }
        if (flag)
        {
            string     str        = (flag1 ? this.craterPrefab_Oil.resourcePath : this.craterPrefab.resourcePath);
            BaseEntity baseEntity = GameManager.server.CreateEntity(str, vector3, Quaternion.identity, true);
            if (baseEntity)
            {
                baseEntity.Spawn();
            }
        }
    }