Esempio n. 1
0
 public bool NearMountPoint(BasePlayer player)
 {
     if (player == null)
     {
         return(false);
     }
     if (mountAnchor == null)
     {
         return(false);
     }
     if (Vector3.Distance(player.transform.position, mountAnchor.position) <= maxMountDistance)
     {
         RaycastHit hitInfo;
         if (!UnityEngine.Physics.SphereCast(player.eyes.HeadRay(), 0.25f, out hitInfo, 2f, 1218652417))
         {
             return(false);
         }
         BaseEntity entity = RaycastHitEx.GetEntity(hitInfo);
         if (entity != null)
         {
             if (entity == this || EqualNetID(entity))
             {
                 return(true);
             }
             BaseEntity baseEntity = entity.GetParentEntity();
             if (RaycastHitEx.IsOnLayer(hitInfo, Rust.Layer.Vehicle_Detailed) && (baseEntity == this || EqualNetID(baseEntity)))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Esempio n. 2
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);
    }
Esempio n. 3
0
    public void ServerUse_Strike()
    {
        BasePlayer ownerPlayer = GetOwnerPlayer();

        if (ownerPlayer == null)
        {
            return;
        }
        Vector3 position = ownerPlayer.eyes.position;
        Vector3 vector   = ownerPlayer.eyes.BodyForward();

        for (int i = 0; i < 2; i++)
        {
            List <RaycastHit> obj = Facepunch.Pool.GetList <RaycastHit>();
            GamePhysics.TraceAll(new Ray(position - vector * ((i == 0) ? 0f : 0.2f), vector), (i == 0) ? 0f : attackRadius, obj, effectiveRange + 0.2f, 1219701521);
            bool flag = false;
            for (int j = 0; j < obj.Count; j++)
            {
                RaycastHit hit    = obj[j];
                BaseEntity entity = RaycastHitEx.GetEntity(hit);
                if (entity == null || (entity != null && (entity == ownerPlayer || entity.EqualNetID(ownerPlayer))) || (entity != null && entity.isClient) || entity.Categorize() == ownerPlayer.Categorize())
                {
                    continue;
                }
                float num = 0f;
                foreach (DamageTypeEntry damageType in damageTypes)
                {
                    num += damageType.amount;
                }
                entity.OnAttacked(new HitInfo(ownerPlayer, entity, DamageType.Slash, num * npcDamageScale));
                HitInfo obj2 = Facepunch.Pool.Get <HitInfo>();
                obj2.HitEntity        = entity;
                obj2.HitPositionWorld = hit.point;
                obj2.HitNormalWorld   = -vector;
                if (entity is BaseNpc || entity is BasePlayer)
                {
                    obj2.HitMaterial = StringPool.Get("Flesh");
                }
                else
                {
                    obj2.HitMaterial = StringPool.Get((RaycastHitEx.GetCollider(hit).sharedMaterial != null) ? AssetNameCache.GetName(RaycastHitEx.GetCollider(hit).sharedMaterial) : "generic");
                }
                ServerUse_OnHit(obj2);
                Effect.server.ImpactEffect(obj2);
                Facepunch.Pool.Free(ref obj2);
                flag = true;
                if (!(entity != null) || entity.ShouldBlockProjectiles())
                {
                    break;
                }
            }
            Facepunch.Pool.FreeList(ref obj);
            if (flag)
            {
                break;
            }
        }
    }
Esempio n. 4
0
    public bool CheckTrigger()
    {
        if (Time.realtimeSinceStartup < nextTriggerCheckTime)
        {
            return(false);
        }
        nextTriggerCheckTime = Time.realtimeSinceStartup + 1f / triggerCheckRate;
        List <RaycastHit>    obj            = Pool.GetList <RaycastHit>();
        HashSet <BaseEntity> entityContents = trigger.entityContents;
        bool flag = false;

        if (entityContents != null)
        {
            foreach (BaseEntity item in entityContents)
            {
                BasePlayer component = item.GetComponent <BasePlayer>();
                if (component.IsSleeping() || !component.IsAlive())
                {
                    continue;
                }
                object obj2 = Interface.CallHook("CanBeTargeted", component, this);
                if (obj2 is bool)
                {
                    Pool.FreeList(ref obj);
                    return((bool)obj2);
                }
                if (!(component.transform.position.y <= GetEyePosition().y + 0.5f) || component.IsBuildingAuthed())
                {
                    continue;
                }
                obj.Clear();
                GamePhysics.TraceAll(new Ray(component.eyes.position, (GetEyePosition() - component.eyes.position).normalized), 0f, obj, 9f, 1218519297);
                for (int i = 0; i < obj.Count; i++)
                {
                    BaseEntity entity = RaycastHitEx.GetEntity(obj[i]);
                    if (entity != null && (entity == this || entity.EqualNetID(this)))
                    {
                        flag = true;
                        break;
                    }
                    if (!(entity != null) || entity.ShouldBlockProjectiles())
                    {
                        break;
                    }
                }
                if (flag)
                {
                    break;
                }
            }
        }
        Pool.FreeList(ref obj);
        return(flag);
    }
Esempio n. 5
0
        public static void mount(Arg arg)
        {
            BasePlayer basePlayer = ArgEx.Player(arg);

            if (!basePlayer.IsAdmin && !basePlayer.IsDeveloper && !Server.cinematic)
            {
                return;
            }
            uint       uInt        = arg.GetUInt(0);
            BasePlayer basePlayer2 = BasePlayer.FindByID(uInt);

            if (basePlayer2 == null)
            {
                basePlayer2 = BasePlayer.FindBot(uInt);
            }
            RaycastHit hitInfo;

            if (!basePlayer2 || !UnityEngine.Physics.Raycast(basePlayer.eyes.position, basePlayer.eyes.HeadForward(), out hitInfo, 5f, 10496, QueryTriggerInteraction.Ignore))
            {
                return;
            }
            BaseEntity entity = RaycastHitEx.GetEntity(hitInfo);

            if (!entity)
            {
                return;
            }
            BaseMountable baseMountable = entity.GetComponent <BaseMountable>();

            if (!baseMountable)
            {
                BaseVehicle baseVehicle = entity.GetComponentInParent <BaseVehicle>();
                if ((bool)baseVehicle)
                {
                    if (!baseVehicle.isServer)
                    {
                        baseVehicle = BaseNetworkable.serverEntities.Find(baseVehicle.net.ID) as BaseVehicle;
                    }
                    baseVehicle.AttemptMount(basePlayer2);
                    return;
                }
            }
            if ((bool)baseMountable && !baseMountable.isServer)
            {
                baseMountable = BaseNetworkable.serverEntities.Find(baseMountable.net.ID) as BaseMountable;
            }
            if ((bool)baseMountable)
            {
                baseMountable.AttemptMount(basePlayer2);
            }
        }
        private bool IsCarOnLift(ModularCar car)
        {
            RaycastHit hitInfo;

            // This isn't perfect as it can hit other deployables such as rugs
            if (!Physics.SphereCast(car.transform.position + Vector3.up, 1f, Vector3.down, out hitInfo, 1f))
            {
                return(false);
            }

            var lift = RaycastHitEx.GetEntity(hitInfo) as ModularCarGarage;

            return(lift != null && lift.carOccupant == car);
        }
Esempio n. 7
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;
            }
        }
    }
Esempio n. 8
0
    public LiquidContainer GetFacingLiquidContainer()
    {
        BasePlayer ownerPlayer = GetOwnerPlayer();

        if (!ownerPlayer)
        {
            return(null);
        }
        RaycastHit hitInfo;

        if (UnityEngine.Physics.Raycast(ownerPlayer.eyes.HeadRay(), out hitInfo, 2f, 1236478737))
        {
            BaseEntity entity = RaycastHitEx.GetEntity(hitInfo);
            if ((bool)entity && !hitInfo.collider.gameObject.CompareTag("Not Player Usable") && !hitInfo.collider.gameObject.CompareTag("Usable Primary"))
            {
                entity = entity.ToServer <BaseEntity>();
                return(entity.GetComponent <LiquidContainer>());
            }
        }
        return(null);
    }
Esempio n. 9
0
    public bool ObjectVisible(BaseCombatEntity obj)
    {
        object obj2 = Interface.CallHook("CanBeTargeted", obj, this);

        if (obj2 is bool)
        {
            return((bool)obj2);
        }
        List <RaycastHit> obj3     = Facepunch.Pool.GetList <RaycastHit>();
        Vector3           position = eyePos.transform.position;
        Vector3           vector   = AimOffset(obj);
        float             num      = Vector3.Distance(vector, position);
        Vector3           vector2  = Vector3.Cross((vector - position).normalized, Vector3.up);

        for (int i = 0; (float)i < (CheckPeekers() ? 3f : 1f); i++)
        {
            Vector3 normalized = (vector + vector2 * visibilityOffsets[i] - position).normalized;
            obj3.Clear();
            GamePhysics.TraceAll(new Ray(position, normalized), 0f, obj3, num * 1.1f, 1218652417);
            for (int j = 0; j < obj3.Count; j++)
            {
                BaseEntity entity = RaycastHitEx.GetEntity(obj3[j]);
                if ((!(entity != null) || !entity.isClient) && (!(entity != null) || !(entity.ToPlayer() != null) || entity.EqualNetID(obj)) && (!(entity != null) || !entity.EqualNetID(this)))
                {
                    if (entity != null && (entity == obj || entity.EqualNetID(obj)))
                    {
                        Facepunch.Pool.FreeList(ref obj3);
                        peekIndex = i;
                        return(true);
                    }
                    if (!(entity != null) || entity.ShouldBlockProjectiles())
                    {
                        break;
                    }
                }
            }
        }
        Facepunch.Pool.FreeList(ref obj3);
        return(false);
    }
Esempio n. 10
0
    private static bool TestPlacingThroughWall(ref Placement placement, Transform transform, Construction common, Target target)
    {
        Vector3    vector = placement.position - target.ray.origin;
        RaycastHit hitInfo;

        if (!Physics.Raycast(target.ray.origin, vector.normalized, out hitInfo, vector.magnitude, 2097152))
        {
            return(true);
        }
        StabilityEntity stabilityEntity = RaycastHitEx.GetEntity(hitInfo) as StabilityEntity;

        if (stabilityEntity != null && target.entity == stabilityEntity)
        {
            return(true);
        }
        if (vector.magnitude - hitInfo.distance < 0.2f)
        {
            return(true);
        }
        lastPlacementError = "object in placement path";
        transform.SetPositionAndRotation(hitInfo.point, placement.rotation);
        return(false);
    }
Esempio n. 11
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);
        }
    }
Esempio n. 12
0
    public virtual void FireGun(Vector3 targetPos, float aimCone, Transform muzzleToUse = null, BaseCombatEntity target = null)
    {
        if (IsOffline())
        {
            return;
        }
        if (muzzleToUse == null)
        {
            muzzleToUse = muzzlePos;
        }
        Vector3 vector  = GetCenterMuzzle().transform.position - GetCenterMuzzle().forward * 0.25f;
        Vector3 vector2 = GetCenterMuzzle().transform.forward;
        Vector3 modifiedAimConeDirection = AimConeUtil.GetModifiedAimConeDirection(aimCone, vector2);

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

        GamePhysics.TraceAll(new Ray(vector, modifiedAimConeDirection), 0f, obj, 300f, 1219701521);
        bool flag = false;

        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))) || (PeacekeeperMode() && target != null && entity != null && entity.GetComponent <BasePlayer>() != null && !entity.EqualNetID(target)))
            {
                continue;
            }
            BaseCombatEntity baseCombatEntity = entity as BaseCombatEntity;
            if (baseCombatEntity != null)
            {
                ApplyDamage(baseCombatEntity, hit.point, modifiedAimConeDirection);
                if (baseCombatEntity.EqualNetID(target))
                {
                    flag = true;
                }
            }
            if (!(entity != null) || entity.ShouldBlockProjectiles())
            {
                targetPos = hit.point;
                vector2   = (targetPos - vector).normalized;
                break;
            }
        }
        int num = 2;

        if (!flag)
        {
            numConsecutiveMisses++;
        }
        else
        {
            numConsecutiveMisses = 0;
        }
        if (target != null && targetVisible && numConsecutiveMisses > num)
        {
            ApplyDamage(target, target.transform.position - vector2 * 0.25f, vector2);
            numConsecutiveMisses = 0;
        }
        ClientRPC(null, "CLIENT_FireGun", StringPool.Get(muzzleToUse.gameObject.name), targetPos);
        Facepunch.Pool.FreeList(ref obj);
    }