private void ApplyDamage(BaseCombatEntity entity, Vector3 point, Vector3 normal)
    {
        float damageAmount = 15f * Random.Range(0.9f, 1.1f);

        if (entity is BasePlayer && Object.op_Inequality((Object)entity, (Object)this.target))
        {
            damageAmount *= 0.5f;
        }
        if (this.PeacekeeperMode() && Object.op_Equality((Object)entity, (Object)this.target))
        {
            this.target.MarkHostileFor(1800f);
        }
        HitInfo info = new HitInfo((BaseEntity)this, (BaseEntity)entity, DamageType.Bullet, damageAmount, point);

        entity.OnAttacked(info);
        if (!(entity is BasePlayer) && !(entity is BaseNpc))
        {
            return;
        }
        Effect.server.ImpactEffect(new HitInfo()
        {
            HitPositionWorld = point,
            HitNormalWorld   = Vector3.op_UnaryNegation(normal),
            HitMaterial      = StringPool.Get("Flesh")
        });
    }
Exemple #2
0
    public void DoRadialDamage()
    {
        List <Collider> obj      = Pool.GetList <Collider>();
        Vector3         position = base.transform.position + new Vector3(0f, radius * 0.75f, 0f);

        Vis.Colliders(position, radius, obj, AttackLayers);
        HitInfo hitInfo = new HitInfo();

        hitInfo.DoHitEffects = true;
        hitInfo.DidHit       = true;
        hitInfo.HitBone      = 0u;
        hitInfo.Initiator    = ((creatorEntity == null) ? GameObjectEx.ToBaseEntity(base.gameObject) : creatorEntity);
        hitInfo.PointStart   = base.transform.position;
        foreach (Collider item in obj)
        {
            if (item.isTrigger && (item.gameObject.layer == 29 || item.gameObject.layer == 18))
            {
                continue;
            }
            BaseCombatEntity baseCombatEntity = GameObjectEx.ToBaseEntity(item.gameObject) as BaseCombatEntity;
            if (!(baseCombatEntity == null) && baseCombatEntity.isServer && baseCombatEntity.IsAlive() && (!ignoreNPC || !baseCombatEntity.IsNpc) && baseCombatEntity.IsVisible(position))
            {
                if (baseCombatEntity is BasePlayer)
                {
                    Effect.server.Run("assets/bundled/prefabs/fx/impacts/additive/fire.prefab", baseCombatEntity, 0u, new Vector3(0f, 1f, 0f), Vector3.up);
                }
                hitInfo.PointEnd         = baseCombatEntity.transform.position;
                hitInfo.HitPositionWorld = baseCombatEntity.transform.position;
                hitInfo.damageTypes.Set(DamageType.Heat, damagePerSecond * tickRate);
                Interface.CallHook("OnFireBallDamage", this, baseCombatEntity, hitInfo);
                baseCombatEntity.OnAttacked(hitInfo);
            }
        }
        Pool.FreeList(ref obj);
    }
Exemple #3
0
    public void ApplyDamage(BaseCombatEntity entity, Vector3 point, Vector3 normal)
    {
        float num = 15f * UnityEngine.Random.Range(0.9f, 1.1f);

        if (entity is BasePlayer && entity != target)
        {
            num *= 0.5f;
        }
        if (PeacekeeperMode() && entity == target)
        {
            target.MarkHostileFor(300f);
        }
        HitInfo info = new HitInfo(this, entity, DamageType.Bullet, num, point);

        entity.OnAttacked(info);
        if (entity is BasePlayer || entity is BaseNpc)
        {
            Effect.server.ImpactEffect(new HitInfo
            {
                HitPositionWorld = point,
                HitNormalWorld   = -normal,
                HitMaterial      = StringPool.Get("Flesh")
            });
        }
    }
    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);
    }
    private void ApplyDamage(BaseCombatEntity entity, Vector3 point, Vector3 normal)
    {
        float single = this.bulletDamage * UnityEngine.Random.Range(0.9f, 1.1f);

        entity.OnAttacked(new HitInfo(this, entity, DamageType.Bullet, single, point));
        if (entity is BasePlayer || entity is BaseNpc)
        {
            Effect.server.ImpactEffect(new HitInfo()
            {
                HitPositionWorld = point,
                HitNormalWorld   = -normal,
                HitMaterial      = StringPool.Get("Flesh")
            });
        }
    }
 internal void DoDamage(
     BaseEntity ent,
     TriggerHurtEx.HurtType type,
     List <DamageTypeEntry> damage,
     GameObjectRef effect,
     float multiply = 1f)
 {
     if (!this.damageEnabled)
     {
         return;
     }
     using (TimeWarning.New("TriggerHurtEx.DoDamage", 0.1f))
     {
         if (damage != null && damage.Count > 0)
         {
             BaseCombatEntity baseCombatEntity = ent as BaseCombatEntity;
             if (Object.op_Implicit((Object)baseCombatEntity))
             {
                 HitInfo info = new HitInfo();
                 info.damageTypes.Add(damage);
                 info.damageTypes.ScaleAll(multiply);
                 info.DoHitEffects = true;
                 info.DidHit       = true;
                 info.Initiator    = ((Component)this).get_gameObject().ToBaseEntity();
                 info.PointStart   = ((Component)this).get_transform().get_position();
                 info.PointEnd     = ((Component)baseCombatEntity).get_transform().get_position();
                 if (type == TriggerHurtEx.HurtType.Simple)
                 {
                     baseCombatEntity.Hurt(info);
                 }
                 else
                 {
                     baseCombatEntity.OnAttacked(info);
                 }
             }
         }
         if (!effect.isValid)
         {
             return;
         }
         Effect.server.Run(effect.resourcePath, ent, StringPool.closest, ((Component)this).get_transform().get_position(), Vector3.get_up(), (Connection)null, false);
     }
 }
Exemple #7
0
    public void DoRadialDamage()
    {
        List <Collider> list     = (List <Collider>)Pool.GetList <Collider>();
        Vector3         position = Vector3.op_Addition(((Component)this).get_transform().get_position(), new Vector3(0.0f, this.radius * 0.75f, 0.0f));

        Vis.Colliders <Collider>(position, this.radius, list, LayerMask.op_Implicit(this.AttackLayers), (QueryTriggerInteraction)2);
        HitInfo info = new HitInfo();

        info.DoHitEffects = true;
        info.DidHit       = true;
        info.HitBone      = 0U;
        info.Initiator    = Object.op_Equality((Object)this.creatorEntity, (Object)null) ? ((Component)this).get_gameObject().ToBaseEntity() : this.creatorEntity;
        info.PointStart   = ((Component)this).get_transform().get_position();
        using (List <Collider> .Enumerator enumerator = list.GetEnumerator())
        {
            while (enumerator.MoveNext())
            {
                Collider current = enumerator.Current;
                if (!current.get_isTrigger() || ((Component)current).get_gameObject().get_layer() != 29 && ((Component)current).get_gameObject().get_layer() != 18)
                {
                    BaseCombatEntity baseEntity = ((Component)current).get_gameObject().ToBaseEntity() as BaseCombatEntity;
                    if (!Object.op_Equality((Object)baseEntity, (Object)null) && baseEntity.isServer && (baseEntity.IsAlive() && baseEntity.IsVisible(position, float.PositiveInfinity)))
                    {
                        if (baseEntity is BasePlayer)
                        {
                            Effect.server.Run("assets/bundled/prefabs/fx/impacts/additive/fire.prefab", (BaseEntity)baseEntity, 0U, new Vector3(0.0f, 1f, 0.0f), Vector3.get_up(), (Connection)null, false);
                        }
                        info.PointEnd         = ((Component)baseEntity).get_transform().get_position();
                        info.HitPositionWorld = ((Component)baseEntity).get_transform().get_position();
                        info.damageTypes.Set(DamageType.Heat, this.damagePerSecond * this.tickRate);
                        baseEntity.OnAttacked(info);
                    }
                }
            }
        }
        // ISSUE: cast to a reference type
        Pool.FreeList <Collider>((List <M0>&) ref list);
    }
    private void ApplyDamage(BaseCombatEntity entity, Vector3 point, Vector3 normal)
    {
        float single = 15f * UnityEngine.Random.Range(0.9f, 1.1f);

        if (entity is BasePlayer && entity != this.target)
        {
            single *= 0.5f;
        }
        if (this.PeacekeeperMode() && entity == this.target)
        {
            this.target.MarkHostileFor(1800f);
        }
        entity.OnAttacked(new HitInfo(this, entity, DamageType.Bullet, single, point));
        if (entity is BasePlayer || entity is BaseNpc)
        {
            Effect.server.ImpactEffect(new HitInfo()
            {
                HitPositionWorld = point,
                HitNormalWorld   = -normal,
                HitMaterial      = StringPool.Get("Flesh")
            });
        }
    }
    public void DoRadialDamage()
    {
        List <Collider> list    = Pool.GetList <Collider>();
        Vector3         vector3 = base.transform.position + new Vector3(0f, this.radius * 0.75f, 0f);

        Vis.Colliders <Collider>(vector3, this.radius, list, this.AttackLayers, QueryTriggerInteraction.Collide);
        HitInfo hitInfo = new HitInfo()
        {
            DoHitEffects = true,
            DidHit       = true,
            HitBone      = 0,
            Initiator    = (this.creatorEntity == null ? base.gameObject.ToBaseEntity() : this.creatorEntity),
            PointStart   = base.transform.position
        };

        foreach (Collider collider in list)
        {
            if (collider.isTrigger && (collider.gameObject.layer == 29 || collider.gameObject.layer == 18))
            {
                continue;
            }
            BaseCombatEntity baseEntity = collider.gameObject.ToBaseEntity() as BaseCombatEntity;
            if (baseEntity == null || !baseEntity.isServer || !baseEntity.IsAlive() || !baseEntity.IsVisible(vector3, Single.PositiveInfinity))
            {
                continue;
            }
            if (baseEntity is BasePlayer)
            {
                Effect.server.Run("assets/bundled/prefabs/fx/impacts/additive/fire.prefab", baseEntity, 0, new Vector3(0f, 1f, 0f), Vector3.up, null, false);
            }
            hitInfo.PointEnd         = baseEntity.transform.position;
            hitInfo.HitPositionWorld = baseEntity.transform.position;
            hitInfo.damageTypes.Set(DamageType.Heat, this.damagePerSecond * this.tickRate);
            baseEntity.OnAttacked(hitInfo);
        }
        Pool.FreeList <Collider>(ref list);
    }
Exemple #10
0
 internal void DoDamage(BaseEntity ent, TriggerHurtEx.HurtType type, List <DamageTypeEntry> damage, GameObjectRef effect, float multiply = 1f)
 {
     if (!this.damageEnabled)
     {
         return;
     }
     using (TimeWarning timeWarning = TimeWarning.New("TriggerHurtEx.DoDamage", 0.1f))
     {
         if (damage != null && damage.Count > 0)
         {
             BaseCombatEntity baseCombatEntity = ent as BaseCombatEntity;
             if (baseCombatEntity)
             {
                 HitInfo hitInfo = new HitInfo();
                 hitInfo.damageTypes.Add(damage);
                 hitInfo.damageTypes.ScaleAll(multiply);
                 hitInfo.DoHitEffects = true;
                 hitInfo.DidHit       = true;
                 hitInfo.Initiator    = base.gameObject.ToBaseEntity();
                 hitInfo.PointStart   = base.transform.position;
                 hitInfo.PointEnd     = baseCombatEntity.transform.position;
                 if (type != TriggerHurtEx.HurtType.Simple)
                 {
                     baseCombatEntity.OnAttacked(hitInfo);
                 }
                 else
                 {
                     baseCombatEntity.Hurt(hitInfo);
                 }
             }
         }
         if (effect.isValid)
         {
             Effect.server.Run(effect.resourcePath, ent, StringPool.closest, base.transform.position, Vector3.up, null, false);
         }
     }
 }
    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);
        }
    }