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); } } }
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); }
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); } }
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); } }
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); }
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 }); } }
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); }
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; } }
public Vector3 Calculate(Structure Base, Items.TYPE BranchType) { switch (BranchType) { case (Items.TYPE.PLATFORM): return(PlatformBranch(Base, BranchType)); default: return(new Vector3()); } }
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); } }
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); } }
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; } }
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); } } }
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]); } }
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()); } }
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 } } } }
public Instance(Items.TYPE TypeArg) { this.Type = TypeArg; }
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 }))); }
public static bool Give(Items.TYPE Type) //TODO: Allow giving items to other players { Game.PossessedPlayer.ItemGive(new Items.Instance(Type)); return(true); }
public void PickupItem(Items.TYPE Type) { ItemGive(new Items.Instance(Type)); }
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 })); }
public virtual bool ShouldPickupItem(Items.TYPE Type) { return(true); }
public virtual bool ShouldRemoveStructure(Items.TYPE BranchType, Vector3 Position, Vector3 Rotation, int OwnerId) { return(true); }
public virtual bool ShouldPlaceStructure(Items.TYPE BranchType, Vector3 Position, Vector3 Rotation) { return(true); }
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 }); }
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()); }