示例#1
0
    public void DropOrUpdateItem(Items.TYPE Type, Vector3 Position, Vector3 BaseMomentum, string Name)     //Performs the actual drop
    {
        if (ItemsRoot.HasNode(Name))
        {
            DroppedItem Instance = ItemsRoot.GetNode <DroppedItem>(Name);
            Instance.Translation    = Position;
            Instance.Momentum       = BaseMomentum;
            Instance.PhysicsEnabled = true;
        }
        else
        {
            Vector3 LevelPlayerPos = new Vector3(Game.PossessedPlayer.Translation.x, 0, Game.PossessedPlayer.Translation.z);

            if (GetChunkPos(Position).DistanceTo(LevelPlayerPos) <= Game.ChunkRenderDistance * (PlatformSize * 9))
            {
                DroppedItem ToDrop = DroppedItemScene.Instance() as DroppedItem;
                ToDrop.Translation = Position;
                ToDrop.Momentum    = BaseMomentum;
                ToDrop.Type        = Type;
                ToDrop.Name        = Name;
                ToDrop.GetNode <MeshInstance>("MeshInstance").Mesh = Items.Meshes[Type];

                AddItemToChunk(ToDrop);
                ItemList.Add(ToDrop);
                ItemsRoot.AddChild(ToDrop);
            }
        }
    }
示例#2
0
    public override void _PhysicsProcess(float Delta)
    {
        Items.Instance Item = Game.PossessedPlayer.Inventory[Game.PossessedPlayer.InventorySlot];
        if (Item != null && Item.Type != CurrentMeshType)        //null means no item in slot
        {
            GhostMesh.Mesh  = Meshes[Item.Type];
            CurrentMeshType = Item.Type;
        }

        GhostMesh.Translation     = OldPositions[0];
        GhostMesh.RotationDegrees = OldRotations[0];
        GhostMesh.Visible         = OldVisible[0];

        Player Plr = Game.PossessedPlayer;

        OldVisible.RemoveAt(0);
        OldVisible.Add(false);
        if (Plr.Inventory[Plr.InventorySlot] != null)
        {
            RayCast BuildRayCast = Plr.GetNode("SteelCamera/RayCast") as RayCast;
            if (BuildRayCast.IsColliding())
            {
                Structure Hit = BuildRayCast.GetCollider() as Structure;
                if (Hit != null)
                {
                    System.Nullable <Vector3> GhostPosition = BuildPositions.Calculate(Hit, Plr.Inventory[Plr.InventorySlot].Type);
                    if (GhostPosition != null)
                    {
                        Vector3 GhostRotation = BuildRotations.Calculate(Hit, Plr.Inventory[Plr.InventorySlot].Type);
                        Translation     = (Vector3)GhostPosition;
                        RotationDegrees = GhostRotation;
                        OldVisible[1]   = true;
                    }
                }
            }
        }
        if (OldVisible[1] == false)
        {
            OldVisible[0]     = false;
            GhostMesh.Visible = false;
        }

        OldCanBuild.RemoveAt(0);
        if (GetOverlappingBodies().Count > 0)
        {
            GhostMesh.MaterialOverride = RedMat;
            OldCanBuild.Add(false);
        }
        else
        {
            GhostMesh.MaterialOverride = GreenMat;
            OldCanBuild.Add(true);
        }
        CanBuild = OldCanBuild[0];

        OldPositions.RemoveAt(0);
        OldPositions.Add(Translation);
        OldRotations.RemoveAt(0);
        OldRotations.Add(RotationDegrees);
    }
示例#3
0
 public static void PlaceOn(Structure Base, Items.TYPE BranchType, int OwnerId)
 {
     System.Nullable <Vector3> Position = BuildPositions.Calculate(Base, BranchType);
     if (Position != null)        //If null then unsupported branch/base combination
     {
         Vector3 Rotation = BuildRotations.Calculate(Base, BranchType);
         Place(BranchType, (Vector3)Position, Rotation, OwnerId);
     }
 }
示例#4
0
    public static void Request(Structure Base, Items.TYPE BranchType, int OwnerId)
    {
        System.Nullable <Vector3> Position = BuildPositionsInstance.Calculate(Base, BranchType);
        Vector3 Rotation = BuildRotationsInstance.Calculate(Base, BranchType);

        if (Position != null)
        {
            Perform.PlaceRequest(Events.INVOKER.CLIENT, OwnerId, BranchType, (Vector3)Position, Rotation);
        }
    }
示例#5
0
    public Structure 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 * (PlatformSize * 9))
            {
                //If network is inited, not the server, and platform it to far away then...
                return(null);                //...don't place
            }
        }

        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
        StructureRoot.AddChild(Branch);

        AddStructureToChunk(Branch);
        Grid.AddItem(Branch);

        //Nested if to prevent very long line
        if (GetTree().NetworkPeer != null && GetTree().IsNetworkServer())
        {
            if (GetChunkPos(Position).DistanceTo(LevelPlayerPos) > Game.ChunkRenderDistance * (PlatformSize * 9))
            {
                //If network is inited, am the server, and platform is to far away then...
                Branch.Hide();                 //...make it not visible but allow it to remain in the world
            }

            foreach (int Id in Net.PeerList)
            {
                if (Id == Net.ServerId)                //Skip self (we are the server)
                {
                    continue;
                }

                Vector3 PlayerPos = Net.Players[Id].Translation;
                if (GetChunkPos(Position).DistanceTo(new Vector3(PlayerPos.x, 0, PlayerPos.z)) <= ChunkLoadDistances[Id] * (PlatformSize * 9))
                {
                    if (!RemoteLoadedChunks[Id].Contains(GetChunkTuple(Position)))
                    {
                        RemoteLoadedChunks[Id].Add(GetChunkTuple(Position));
                    }
                }
            }
        }

        return(Branch);
    }
示例#6
0
    public static void Place(Items.TYPE BranchType, Vector3 Position, Vector3 Rotation, int OwnerId)
    {
        string Name = System.Guid.NewGuid().ToString();

        Self.PlaceWithName(BranchType, Position, Rotation, OwnerId, Name);

        if (Self.GetTree().NetworkPeer != null)        //Don't sync place if network is not ready
        {
            Self.Rpc(nameof(PlaceWithName), new object[] { BranchType, Position, Rotation, OwnerId, Name });
        }
    }
示例#7
0
    public static void Place(Items.TYPE BranchType, Vector3 Position, Vector3 Rotation, int OwnerId)
    {
        Structure Branch = Scenes[BranchType].Instance() as Structure;

        Branch.Type            = BranchType;
        Branch.OwnerId         = OwnerId;
        Branch.Translation     = Position;
        Branch.RotationDegrees = Rotation;
        Branch.SetName(System.Guid.NewGuid().ToString());         //name can be used to reference a structure over network

        Game.StructureRoot.AddChild(Branch);
    }
示例#8
0
    public override void _Ready()
    {
        GhostMesh = ((PackedScene)(GD.Load("res://World/GhostMesh.tscn"))).Instance() as MeshInstance;
        GetParent().AddChild(GhostMesh);

        Items.Instance Item = Game.PossessedPlayer.Inventory[Game.PossessedPlayer.InventorySlot];
        if (Item != null)        //null means no item in slot
        {
            GhostMesh.Mesh  = Items.Meshes[Item.Type];
            CurrentMeshType = Item.Type;
        }
    }
示例#9
0
    public Vector3 Calculate(Structure Base, Items.TYPE BranchType)
    {
        switch (BranchType)
        {
        case (Items.TYPE.PLATFORM):
            return(PlatformBranch(Base, BranchType));


        default:
            return(new Vector3());
        }
    }
示例#10
0
    public System.Nullable <Vector3> Calculate(Structure Base, Items.TYPE BranchType)
    {
        switch (BranchType)
        {
        case (Items.TYPE.PLATFORM):
            return(PlatformBranch(Base, BranchType));


        default:
            //Return null if unsuported, will be caught by Building.Request
            return(null);
        }
    }
示例#11
0
    private System.Nullable <Vector3> PlatformBranch(Structure Base, Items.TYPE BranchType)
    {
        switch (Base.Type)
        {
        case (Items.TYPE.PLATFORM):
            float   RotationDegrees = Mathf.Deg2Rad(SteelMath.SnapToGrid(Game.PossessedPlayer.RotationDegrees.y, 360, 4));
            Vector3 Position        = Base.Translation + (new Vector3(0, 0, 12)).Rotated(new Vector3(0, 1, 0), RotationDegrees);
            return(new Vector3(Mathf.Round(Position.x), Mathf.Round(Position.y), Mathf.Round(Position.z)));


        default:
            return(null);
        }
    }
示例#12
0
        public Instance(Items.ID IdArg)
        {
            this.Id = IdArg;

            switch (IdArg)            //NOTE: This could be improved
            {
            case (ID.ROCKET_JUMPER):
                Type = TYPE.USABLE;
                break;

            default:
                Type = TYPE.BUILDABLE;
                break;
            }
        }
示例#13
0
 public void DropItem(Items.TYPE Type, Vector3 Position, Vector3 BaseMomentum)
 {
     if (Self.GetTree().GetNetworkPeer() != null)
     {
         if (Self.GetTree().IsNetworkServer())
         {
             string Name = System.Guid.NewGuid().ToString();
             DropOrUpdateItem(Type, Position, BaseMomentum, Name);
             Net.SteelRpc(Self, nameof(DropOrUpdateItem), Type, Position, BaseMomentum, Name);
         }
         else
         {
             Self.RpcId(Net.ServerId, nameof(DropItem), Type, Position, BaseMomentum);
         }
     }
 }
示例#14
0
    public SavedStructure(Items.TYPE Type, Vector3 Position, Vector3 Rotation)
    {
        this.T = (int)Type;
        this.P = new float[3] {
            Position.x, Position.y, Position.z
        };
        this.R = new float[3] {
            Rotation.x, Rotation.y, Rotation.z
        };

        for (int i = 0; i <= 2; i++)
        {
            P[i] = (float)Math.Round(P[i]);
            R[i] = (float)Math.Round(R[i]);
        }
    }
示例#15
0
    public static Vector3 Calculate(Structure Base, Items.TYPE BranchType)
    {
        switch (BranchType)
        {
        case (Items.TYPE.PLATFORM):
            return(PlatformBranch(Base));

        case (Items.TYPE.WALL):
            return(WallBranch(Base));

        case (Items.TYPE.SLOPE):
            return(SlopeBranch(Base));

        default:
            return(new Vector3());
        }
    }
示例#16
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
                }
            }
        }
    }
示例#17
0
		public Instance(Items.TYPE TypeArg)
		{
			this.Type = TypeArg;
		}
示例#18
0
 public static bool StructureRemove(Items.TYPE BranchType, Vector3 Position, Vector3 Rotation, int OwnerId)
 {
     return(CheckFunctionBoth("_structure_remove", Scripting.ToJs(new object[] { BranchType.ToString(), Position, Rotation, OwnerId })));
 }
示例#19
0
 public static bool Give(Items.TYPE Type)     //TODO: Allow giving items to other players
 {
     Game.PossessedPlayer.ItemGive(new Items.Instance(Type));
     return(true);
 }
示例#20
0
 public void PickupItem(Items.TYPE Type)
 {
     ItemGive(new Items.Instance(Type));
 }
示例#21
0
 public static void Place(Events.INVOKER Invoker, int OwnerId, Items.TYPE BranchType, Vector3 Position, Vector3 Rotation)
 {
     Events.Run(new EventObject(Invoker, Events.TYPE.PLACE, new object[] { OwnerId, BranchType, Position, Rotation }));
 }
示例#22
0
 public virtual bool ShouldPickupItem(Items.TYPE Type)
 {
     return(true);
 }
示例#23
0
 public virtual bool ShouldRemoveStructure(Items.TYPE BranchType, Vector3 Position, Vector3 Rotation, int OwnerId)
 {
     return(true);
 }
示例#24
0
 public virtual bool ShouldPlaceStructure(Items.TYPE BranchType, Vector3 Position, Vector3 Rotation)
 {
     return(true);
 }
示例#25
0
 public static void NetPlaceRequest(int OwnerId, Items.TYPE BranchType, Vector3 Position, Vector3 Rotation)
 {
     Net.SendMessage(Net.ServerId, Net.MESSAGE.PLACE_REQUEST, new object[] { OwnerId, BranchType, Position, Rotation });
 }
示例#26
0
 private Vector3 PlatformBranch(Structure Base, Items.TYPE BranchType)
 {
     //No need for a switch statement, all platforms should have rotation of 0,0,0
     return(new Vector3());
 }