Example #1
0
    public bool UpdatePlacement(Transform transform, Construction common, ref Target target)
    {
        if (!target.valid)
        {
            return(false);
        }
        if (!common.canBypassBuildingPermission && !target.player.CanBuild())
        {
            lastPlacementError = "You don't have permission to build here";
            return(false);
        }
        List <Socket_Base> obj = Pool.GetList <Socket_Base>();

        common.FindMaleSockets(target, obj);
        foreach (Socket_Base item in obj)
        {
            Placement placement = null;
            if (target.entity != null && target.socket != null && target.entity.IsOccupied(target.socket))
            {
                continue;
            }
            if (placement == null)
            {
                placement = item.DoPlacement(target);
            }
            if (placement == null)
            {
                continue;
            }
            if (!item.CheckSocketMods(placement))
            {
                transform.position = placement.position;
                transform.rotation = placement.rotation;
                continue;
            }
            if (!TestPlacingThroughRock(ref placement, target))
            {
                transform.position = placement.position;
                transform.rotation = placement.rotation;
                lastPlacementError = "Placing through rock";
                continue;
            }
            if (!TestPlacingThroughWall(ref placement, transform, common, target))
            {
                transform.position = placement.position;
                transform.rotation = placement.rotation;
                lastPlacementError = "Placing through wall";
                continue;
            }
            if (!TestPlacingCloseToRoad(ref placement, target))
            {
                transform.position = placement.position;
                transform.rotation = placement.rotation;
                lastPlacementError = "Placing too close to road";
                continue;
            }
            if (Vector3.Distance(placement.position, target.player.eyes.position) > common.maxplaceDistance + 1f)
            {
                transform.position = placement.position;
                transform.rotation = placement.rotation;
                lastPlacementError = "Too far away";
                continue;
            }
            DeployVolume[] volumes = PrefabAttribute.server.FindAll <DeployVolume>(prefabID);
            if (DeployVolume.Check(placement.position, placement.rotation, volumes))
            {
                transform.position = placement.position;
                transform.rotation = placement.rotation;
                lastPlacementError = "Not enough space";
                continue;
            }
            if (BuildingProximity.Check(target.player, this, placement.position, placement.rotation))
            {
                transform.position = placement.position;
                transform.rotation = placement.rotation;
                lastPlacementError = "Too close to another building";
                continue;
            }
            if (common.isBuildingPrivilege && !target.player.CanPlaceBuildingPrivilege(placement.position, placement.rotation, common.bounds))
            {
                transform.position = placement.position;
                transform.rotation = placement.rotation;
                lastPlacementError = "Cannot stack building privileges";
                continue;
            }
            bool flag = target.player.IsBuildingBlocked(placement.position, placement.rotation, common.bounds);
            if (!common.canBypassBuildingPermission && flag)
            {
                transform.position = placement.position;
                transform.rotation = placement.rotation;
                lastPlacementError = "You don't have permission to build here";
                continue;
            }
            target.inBuildingPrivilege = flag;
            transform.SetPositionAndRotation(placement.position, placement.rotation);
            Pool.FreeList(ref obj);
            return(true);
        }
        Pool.FreeList(ref obj);
        return(false);
    }
Example #2
0
    public bool UpdatePlacement(
        Transform transform,
        Construction common,
        ref Construction.Target target)
    {
        if (!target.valid)
        {
            return(false);
        }
        if (!common.canBypassBuildingPermission && !target.player.CanBuild())
        {
            Construction.lastPlacementError = "Player doesn't have permission";
            return(false);
        }
        List <Socket_Base> list = (List <Socket_Base>)Pool.GetList <Socket_Base>();

        common.FindMaleSockets(target, list);
        foreach (Socket_Base socketBase in list)
        {
            Construction.Placement placement = (Construction.Placement)null;
            if (!Object.op_Inequality((Object)target.entity, (Object)null) || !((PrefabAttribute)target.socket != (PrefabAttribute)null) || !target.entity.IsOccupied(target.socket))
            {
                if (placement == null)
                {
                    placement = socketBase.DoPlacement(target);
                }
                if (placement != null)
                {
                    if (!socketBase.CheckSocketMods(placement))
                    {
                        transform.set_position(placement.position);
                        transform.set_rotation(placement.rotation);
                    }
                    else if (!this.TestPlacingThroughRock(ref placement, target))
                    {
                        transform.set_position(placement.position);
                        transform.set_rotation(placement.rotation);
                        Construction.lastPlacementError = "Placing through rock";
                    }
                    else if (!Construction.TestPlacingThroughWall(ref placement, transform, common, target))
                    {
                        transform.set_position(placement.position);
                        transform.set_rotation(placement.rotation);
                        Construction.lastPlacementError = "Placing through wall";
                    }
                    else if ((double)Vector3.Distance(placement.position, target.player.eyes.position) > (double)common.maxplaceDistance + 1.0)
                    {
                        transform.set_position(placement.position);
                        transform.set_rotation(placement.rotation);
                        Construction.lastPlacementError = "Too far away";
                    }
                    else
                    {
                        DeployVolume[] all = PrefabAttribute.server.FindAll <DeployVolume>(this.prefabID);
                        if (DeployVolume.Check(placement.position, placement.rotation, all, -1))
                        {
                            transform.set_position(placement.position);
                            transform.set_rotation(placement.rotation);
                            Construction.lastPlacementError = "Not enough space";
                        }
                        else if (BuildingProximity.Check(target.player, this, placement.position, placement.rotation))
                        {
                            transform.set_position(placement.position);
                            transform.set_rotation(placement.rotation);
                        }
                        else if (common.isBuildingPrivilege && !target.player.CanPlaceBuildingPrivilege(placement.position, placement.rotation, common.bounds))
                        {
                            transform.set_position(placement.position);
                            transform.set_rotation(placement.rotation);
                            Construction.lastPlacementError = "Cannot stack building privileges";
                        }
                        else
                        {
                            bool flag = target.player.IsBuildingBlocked(placement.position, placement.rotation, common.bounds);
                            if (!common.canBypassBuildingPermission && flag)
                            {
                                transform.set_position(placement.position);
                                transform.set_rotation(placement.rotation);
                                Construction.lastPlacementError = "Building privilege";
                            }
                            else
                            {
                                target.inBuildingPrivilege = flag;
                                transform.set_position(placement.position);
                                transform.set_rotation(placement.rotation);
                                // ISSUE: cast to a reference type
                                Pool.FreeList <Socket_Base>((List <M0>&) ref list);
                                return(true);
                            }
                        }
                    }
                }
            }
        }
        // ISSUE: cast to a reference type
        Pool.FreeList <Socket_Base>((List <M0>&) ref list);
        return(false);
    }
Example #3
0
    public bool UpdatePlacement(Transform transform, Construction common, ref Construction.Target target)
    {
        bool flag;

        if (!target.valid)
        {
            return(false);
        }
        if (!common.canBypassBuildingPermission && !target.player.CanBuild())
        {
            Construction.lastPlacementError = "Player doesn't have permission";
            return(false);
        }
        List <Socket_Base> list = Pool.GetList <Socket_Base>();

        common.FindMaleSockets(target, list);
        List <Socket_Base> .Enumerator enumerator = list.GetEnumerator();
        try
        {
            while (enumerator.MoveNext())
            {
                Socket_Base            current   = enumerator.Current;
                Construction.Placement placement = null;
                if (target.entity != null && target.socket != null && target.entity.IsOccupied(target.socket))
                {
                    continue;
                }
                if (placement == null)
                {
                    placement = current.DoPlacement(target);
                }
                if (placement == null)
                {
                    continue;
                }
                if (!current.CheckSocketMods(placement))
                {
                    transform.position = placement.position;
                    transform.rotation = placement.rotation;
                }
                else if (!this.TestPlacingThroughRock(ref placement, target))
                {
                    transform.position = placement.position;
                    transform.rotation = placement.rotation;
                    Construction.lastPlacementError = "Placing through rock";
                }
                else if (!Construction.TestPlacingThroughWall(ref placement, transform, common, target))
                {
                    transform.position = placement.position;
                    transform.rotation = placement.rotation;
                    Construction.lastPlacementError = "Placing through wall";
                }
                else if (Vector3.Distance(placement.position, target.player.eyes.position) <= common.maxplaceDistance + 1f)
                {
                    DeployVolume[] deployVolumeArray = PrefabAttribute.server.FindAll <DeployVolume>(this.prefabID);
                    if (DeployVolume.Check(placement.position, placement.rotation, deployVolumeArray, -1))
                    {
                        transform.position = placement.position;
                        transform.rotation = placement.rotation;
                        Construction.lastPlacementError = "Not enough space";
                    }
                    else if (BuildingProximity.Check(target.player, this, placement.position, placement.rotation))
                    {
                        transform.position = placement.position;
                        transform.rotation = placement.rotation;
                    }
                    else if (!common.isBuildingPrivilege || target.player.CanPlaceBuildingPrivilege(placement.position, placement.rotation, common.bounds))
                    {
                        bool flag1 = target.player.IsBuildingBlocked(placement.position, placement.rotation, common.bounds);
                        if (common.canBypassBuildingPermission || !flag1)
                        {
                            target.inBuildingPrivilege = flag1;
                            transform.position         = placement.position;
                            transform.rotation         = placement.rotation;
                            Pool.FreeList <Socket_Base>(ref list);
                            flag = true;
                            return(flag);
                        }
                        else
                        {
                            transform.position = placement.position;
                            transform.rotation = placement.rotation;
                            Construction.lastPlacementError = "Building privilege";
                        }
                    }
                    else
                    {
                        transform.position = placement.position;
                        transform.rotation = placement.rotation;
                        Construction.lastPlacementError = "Cannot stack building privileges";
                    }
                }
                else
                {
                    transform.position = placement.position;
                    transform.rotation = placement.rotation;
                    Construction.lastPlacementError = "Too far away";
                }
            }
            Pool.FreeList <Socket_Base>(ref list);
            return(false);
        }
        finally
        {
            ((IDisposable)enumerator).Dispose();
        }
        return(flag);
    }