Esempio n. 1
0
 public void Remove()
 {
     if (ShouldDo.StructureRemove(Type, Translation, RotationDegrees, OwnerId))
     {
         Rpc(nameof(NetRemove));
         NetRemove();
     }
 }
Esempio n. 2
0
    public void Update(Vector3 Position, Vector3 Rotation)
    {
        if (ShouldDo.RemotePlayerMove(Id, Position))
        {
            Translation = Position;
        }

        if (ShouldDo.RemotePlayerRotate(Id, Rotation))
        {
            RotationDegrees = Rotation;
        }
    }
Esempio n. 3
0
    public void LookLeft(double Sens)
    {
        if (Sens > 0d)
        {
            float Change = ((float)Sens / LookDivisor) * Game.MouseSensitivity;

            if (ShouldDo.LocalPlayerRotate(+Change))
            {
                LookHorizontal += Change;
                SetRotationDegrees(new Vector3(0, LookHorizontal, 0));
            }
        }
    }
Esempio n. 4
0
    public void LookDown(double Sens)
    {
        if (Sens > 0d)
        {
            float Change = ((float)Sens / LookDivisor) * Game.MouseSensitivity;

            if (ShouldDo.LocalPlayerPitch(-Change))
            {
                LookVertical = Mathf.Clamp(LookVertical - Change, -90, 90);
                GetNode <Camera>("SteelCamera").SetRotationDegrees(new Vector3(LookVertical, 180, 0));
            }
        }
    }
Esempio n. 5
0
    public void PlaceWithName(Items.TYPE BranchType, Vector3 Position, Vector3 Rotation, int OwnerId, string Name)
    {
        Vector3 LevelPlayerPos = new Vector3(Game.PossessedPlayer.Translation.x, 0, Game.PossessedPlayer.Translation.z);

        //Nested if to prevent very long line
        if (GetTree().NetworkPeer != null && !GetTree().IsNetworkServer())
        {
            if (GetChunkPos(Position).DistanceTo(LevelPlayerPos) > Game.ChunkRenderDistance * (Building.PlatformSize * 9))
            {
                //If network is inited, not the server, and platform it to far away then...
                return;                 //...don't place
            }
        }

        if (ShouldDo.StructurePlace(BranchType, Position, Rotation, OwnerId))
        {
            Structure Branch = Scenes[BranchType].Instance() as Structure;
            Branch.Type            = BranchType;
            Branch.OwnerId         = OwnerId;
            Branch.Translation     = Position;
            Branch.RotationDegrees = Rotation;
            Branch.SetName(Name);             //Name is a GUID and can be used to reference a structure over network
            Game.StructureRoot.AddChild(Branch);

            AddToChunk(Branch);

            //Nested if to prevent very long line
            if (GetTree().NetworkPeer != null && GetTree().IsNetworkServer())
            {
                if (GetChunkPos(Position).DistanceTo(LevelPlayerPos) > Game.ChunkRenderDistance * (Building.PlatformSize * 9))
                {
                    //If network is inited, are the server, and platform is to far away then...
                    Branch.Hide();                     //...make it not visible but allow it to remain in the world
                }
            }
        }
    }
Esempio n. 6
0
    public override void _PhysicsProcess(float Delta)
    {
        if (!Possessed)
        {
            return;
        }

        if (ForwardAxis == 0 && IsOnFloor())
        {
            if (Momentum.z > 0)
            {
                Momentum.z = Mathf.Clamp(Momentum.z - Friction * Delta, 0f, MaxMovementSpeed);
            }
            else if (Momentum.z < 0)
            {
                Momentum.z = Mathf.Clamp(Momentum.z + Friction * Delta, -MaxMovementSpeed, 0f);
            }
        }

        if (RightAxis == 0 && IsOnFloor())
        {
            if (Momentum.x > 0)
            {
                Momentum.x = Mathf.Clamp(Momentum.x - Friction * Delta, 0f, MaxMovementSpeed);
            }
            else if (Momentum.x < 0)
            {
                Momentum.x = Mathf.Clamp(Momentum.x + Friction * Delta, -MaxMovementSpeed, 0f);
            }
        }

        if (IsJumping && JumpTimer <= MaxJumpLength)
        {
            JumpTimer += Delta;
            Momentum.y = Mathf.Clamp(Momentum.y + JumpContinueForce * Delta, -MaxMovementSpeed, MaxMovementSpeed);
        }
        else
        {
            JumpTimer  = 0f;
            IsJumping  = false;
            Momentum.y = Mathf.Clamp(Momentum.y - Gravity * Delta, -MaxMovementSpeed, MaxMovementSpeed);
        }

        Vector3 OldPos = Translation;

        MoveAndSlide(Momentum.Rotated(new Vector3(0, 1, 0), Mathf.Deg2Rad(LookHorizontal)), new Vector3(0, 1, 0), true, 4, Mathf.Deg2Rad(60));
        //MoveAndSlide multiplies by *physics* delta internally
        Vector3 NewPos = Translation;

        Translation = OldPos;
        if (NewPos != OldPos)
        {
            if (ShouldDo.LocalPlayerMove(NewPos))
            {
                Translation = NewPos;
            }
        }

        if (IsOnFloor() && Momentum.y <= 0f)
        {
            Momentum.y = -1f;
        }

        RpcUnreliable(nameof(Update), Translation, RotationDegrees);

        if (!Building.GetChunkTuple(Translation).Equals(CurrentChunk))
        {
            CurrentChunk = Building.GetChunkTuple(Translation);
            UnloadAndRequestChunks();
        }
    }