Пример #1
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);
        }
    }