public static void SendInventoryTo(IHasInventory HasInventory, int Receiver) { var Ids = new Items.ID[HasInventory.Inventory.Contents.Length]; var Counts = new int[HasInventory.Inventory.Contents.Length]; int Index = 0; while (Index < HasInventory.Inventory.Contents.Length) { Items.Instance Item = HasInventory.Inventory.Contents[Index]; if (Item is null) { Ids[Index] = Items.ID.NONE; Counts[Index] = 0; Index += 1; continue; } Ids[Index] = Item.Id; Counts[Index] = Item.Count; Index += 1; } Self.RpcUnreliableId(Receiver, nameof(ReceiveInventory), HasInventory.Name, Ids, Counts); }
public void NetUpdateInventorySlot(int Slot, Items.ID ItemId, int Count) { if (Slot == 10) { //This is the eleventh slot, it is used only for dropping stacks if (Possessed) { Vector3 StartPos = Translation + Cam.Translation; for (int Index = 0; Index < Count; Index++) { World.Self.DropItem(ItemId, StartPos, CalcThrowVelocity()); } } } else { Inventory.UpdateSlot(Slot, ItemId, Count); } if (Possessed) { HUDInstance.HotbarUpdate(); } else if (Net.Work.IsNetworkServer()) { RpcId(Id, nameof(NetUpdateInventorySlot), Slot, ItemId, Count); } }
public void DropOrUpdateItem(Items.ID Type, Vector3 Position, float Rotation, Vector3 BaseMomentum, string Name) //Performs the actual drop { if (EntitiesRoot.HasNode(Name)) { DroppedItem Instance = EntitiesRoot.GetNode <DroppedItem>(Name); Instance.Translation = Position; Instance.RotationDegrees = new Vector3(0, Rotation, 0); 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)) { var ToDrop = (DroppedItem)DroppedItemScene.Instance(); ToDrop.Translation = Position; ToDrop.RotationDegrees = new Vector3(0, Rotation, 0); ToDrop.Momentum = BaseMomentum; ToDrop.Type = Type; ToDrop.Name = Name; ToDrop.GetNode <MeshInstance>("MeshInstance").Mesh = Items.Meshes[Type]; AddItemToChunk(ToDrop); ItemList.Add(ToDrop); EntitiesRoot.AddChild(ToDrop); } } }
public static void Give(string[] Args) { if (!Net.Work.IsNetworkServer()) { Console.ThrowPrint("Must be the host player to give items"); return; } if (ArgCountMismatch(Args, 3)) { return; } string PlayerName = Args[0]; string TypeString = Args[1]; string CountString = Args[2]; Player TargetPlayer = null; foreach (KeyValuePair <int, string> CurrentNick in Net.Nicknames) { if (CurrentNick.Value == PlayerName) { TargetPlayer = Net.Players[CurrentNick.Key].Plr.ValueOr((Player)null); } } if (TargetPlayer is null) { Console.ThrowPrint($"No player named '{PlayerName}'"); return; } Items.ID Id = Items.ID.ERROR; foreach (Items.ID CurrentId in System.Enum.GetValues(typeof(Items.ID))) { if (CurrentId.ToString() == TypeString) { Id = CurrentId; break; } } if (Id == Items.ID.ERROR) { Console.ThrowPrint($"No item type by the name '{TypeString}'"); return; } if (int.TryParse(CountString, out int GiveCount) && GiveCount > 0) { TargetPlayer.ItemGive(new Items.Instance(Id) { Count = GiveCount }); } else { Console.ThrowPrint($"Invalid item count '{CountString}'"); return; } }
public void DropOrUpdateItem(Items.ID Type, Vector3 Position, float Rotation, Vector3 BaseMomentum, string Name) //Performs the actual drop { if (EntitiesRoot.HasNode(Name)) { DroppedItem Instance = EntitiesRoot.GetNode <DroppedItem>(Name); Instance.Translation = Position; Instance.RotationDegrees = new Vector3(0, Rotation, 0); Instance.Momentum = BaseMomentum; Instance.PhysicsEnabled = true; } else { Game.PossessedPlayer.MatchSome( (Plr) => { var PositionChunk = GetChunkTuple(Position); if (ChunkWithinDistanceFrom(PositionChunk, Game.ChunkRenderDistance, Plr.Translation)) { var ToDrop = (DroppedItem)DroppedItemScene.Instance(); ToDrop.Translation = Position; ToDrop.RotationDegrees = new Vector3(0, Rotation, 0); ToDrop.Momentum = BaseMomentum; ToDrop.Type = Type; ToDrop.Name = Name; ToDrop.GetNode <MeshInstance>("MeshInstance").Mesh = Items.Meshes[Type]; AddItemToChunk(ToDrop); ItemList.Add(ToDrop); EntitiesRoot.AddChild(ToDrop); } } ); } }
public Tile PlaceWithName(Items.ID 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 } } var Branch = (Tile)Scenes[BranchType].Instance(); Branch.Type = BranchType; Branch.OwnerId = OwnerId; Branch.Translation = Position; Branch.RotationDegrees = Rotation; Branch.Name = Name; //Name is a GUID and can be used to reference a structure over network TilesRoot.AddChild(Branch); AddTileToChunk(Branch); Grid.AddItem(Branch); Grid.QueueUpdateNearby(Branch.Translation); if (GetTree().NetworkPeer != null && GetTree().IsNetworkServer()) { TryAddTileToPathfinder(Branch); 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 void NetUpdateInventorySlot(int Slot, Items.ID ItemId, int Count) { Inventory.UpdateSlot(Slot, ItemId, Count); if (Net.Work.IsNetworkServer()) { Net.SteelRpc(this, nameof(NetUpdateInventorySlot), Slot, ItemId, Count); } }
public override void _Process(float Delta) { Assert(MinAdsMultiplyer > 0 && MinAdsMultiplyer <= 1); if (Ads) { AdsMultiplyer = Clamp(AdsMultiplyer - (Delta * (1 - MinAdsMultiplyer) / AdsTime), MinAdsMultiplyer, 1); } else { AdsMultiplyer = Clamp(AdsMultiplyer + (Delta * (1 - MinAdsMultiplyer) / AdsTime), MinAdsMultiplyer, 1); } Cam.Fov = Game.Fov * AdsMultiplyer; ApplyLookVertical(0); var ToRemove = new List <Hitscan.AdditiveRecoil>(); foreach (Hitscan.AdditiveRecoil Instance in ActiveAdditiveRecoil) { Instance.Life += Delta; if (Instance.Life > Instance.Length) { ToRemove.Add(Instance); } } foreach (Hitscan.AdditiveRecoil Instance in ToRemove) { ActiveAdditiveRecoil.Remove(Instance); } if (Inventory[InventorySlot] != null) { Items.ID Id = Inventory[InventorySlot].Id; ViewmodelItem.Mesh = Items.Meshes[Id]; ShaderMaterial Mat = new ShaderMaterial(); Mat.Shader = Items.TileShader; Mat.SetShaderParam("texture_albedo", Items.Textures[Id]); ViewmodelItem.MaterialOverride = Mat; ViewmodelItem.Show(); { Items.IdInfo Info = Items.IdInfos[Inventory[InventorySlot].Id]; if (IsPrimaryFiring && CurrentCooldown >= CurrentMaxCooldown && Info.UseDelegate != null && Info.FullAuto) { Items.UseItem(Inventory[InventorySlot], this); } } } else { ViewmodelItem.Hide(); } }
public static bool Give(Items.ID Type) //TODO: Allow as client and giving items to other players { if (!Net.Work.IsNetworkServer()) { Console.ThrowPrint("Cannot give item as client"); return(false); } Game.PossessedPlayer.ItemGive(new Items.Instance(Type)); return(true); }
public static void PlaceOn(Items.ID BranchType, Tile Base, float PlayerOrientation, int BuildRotation, Vector3 HitPoint, int OwnerId) { Vector3?Position = Items.TryCalculateBuildPosition(BranchType, Base, PlayerOrientation, BuildRotation, HitPoint); if (Position != null) //If null then unsupported branch/base combination { Vector3 Rotation = Items.CalculateBuildRotation(BranchType, Base, PlayerOrientation, BuildRotation, HitPoint); string GuidName = System.Guid.NewGuid().ToString(); Self.PlaceWithName(BranchType, (Vector3)Position, Rotation, OwnerId, GuidName); Net.SteelRpc(Self, nameof(PlaceWithName), BranchType, (Vector3)Position, Rotation, OwnerId, GuidName); } }
public static Tile Place(Items.ID BranchType, Vector3 Position, Vector3 Rotation, int OwnerId) { string Name = System.Guid.NewGuid().ToString(); Tile Branch = Self.PlaceWithName(BranchType, Position, Rotation, OwnerId, Name); if (Self.GetTree().NetworkPeer != null) //Don't sync place if network is not ready { Net.SteelRpc(Self, nameof(PlaceWithName), new object[] { BranchType, Position, Rotation, OwnerId, Name }); } return(Branch); }
public override void _Ready() { GhostMesh = (MeshInstance)GD.Load <PackedScene>("res://World/GhostMesh.tscn").Instance(); 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.Id]; CurrentMeshType = Item.Id; } }
public static Tile PlaceOn(Items.ID BranchType, Tile Base, float PlayerOrientation, int BuildRotation, Vector3 HitPoint, int OwnerId) { Vector3?Position = Items.TryCalculateBuildPosition(BranchType, Base, PlayerOrientation, BuildRotation, HitPoint); if (Position != null) //If null then unsupported branch/base combination { Vector3 Rotation = Items.CalculateBuildRotation(BranchType, Base, PlayerOrientation, BuildRotation, HitPoint); return(Place(BranchType, (Vector3)Position, Rotation, OwnerId)); } return(null); }
public void UpdateIcon() { if (Source.Inventory[Slot] == null) { CurrentId = Items.ID.NONE; Texture = ParentMenu.Alpha; } else { CurrentId = Source.Inventory[Slot].Id; Texture = Items.Thumbnails[CurrentId]; } }
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 SavedTile(Items.ID 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 void DropItem(Items.ID 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 static void SendInventory(IHasInventory HasInventory) { if (!Net.Work.IsNetworkServer()) { throw new Exception($"Cannot run {nameof(SendInventory)} on client"); } foreach (int Receiver in Net.Players.Keys) { if (Receiver == Net.Work.GetNetworkUniqueId()) { continue; } Net.Players[Receiver].Plr.MatchSome( (Plr) => { var EntityChunk = World.GetChunkTuple(HasInventory.Translation); if (World.ChunkWithinDistanceFrom(EntityChunk, World.ChunkRenderDistances[Receiver], Plr.Translation)) { var Ids = new Items.ID[HasInventory.Inventory.Contents.Length]; var Counts = new int[HasInventory.Inventory.Contents.Length]; int Index = 0; while (Index < HasInventory.Inventory.Contents.Length) { Items.Instance Item = HasInventory.Inventory.Contents[Index]; if (Item is null) { Ids[Index] = Items.ID.NONE; Counts[Index] = 0; Index += 1; continue; } Ids[Index] = Item.Id; Counts[Index] = Item.Count; Index += 1; } Self.RpcUnreliableId(Receiver, nameof(ReceiveInventory), HasInventory.Name, Ids, Counts); } } ); } }
public void DropItem(Items.ID Type, Vector3 Position, Vector3 BaseMomentum) { if (Self.GetTree().NetworkPeer != null) { float Rotation = Game.Rand.Next(0, 360); //Int cast to float, limited resolution is fine if (Self.GetTree().IsNetworkServer()) { string Name = System.Guid.NewGuid().ToString(); DropOrUpdateItem(Type, Position, Rotation, BaseMomentum, Name); Net.SteelRpc(Self, nameof(DropOrUpdateItem), Type, Position, Rotation, BaseMomentum, Name); } else { Self.RpcId(Net.ServerId, nameof(DropItem), Type, Position, BaseMomentum); } } }
public SavedTile(SavedChunk Chunk, Tile Branch) { Id = Branch.ItemId; Owner = Branch.OwnerId; Pos = Branch.Translation; Rot = Branch.RotationDegrees; if (Branch is IHasInventory HasInventory) { InventoryIndex = Chunk.AddInventory(new SavedInventory(HasInventory.Inventory)); } //TODO: Hmmmmm for (int i = 0; i <= 2; i++) { Pos[i] = (float)Math.Round(Pos[i]); Rot[i] = (float)Math.Round(Rot[i]); } }
public override void _Process(float Delta) { if (Inventory[InventorySlot] != null) { Items.ID Id = Inventory[InventorySlot].Id; ViewmodelItem.Mesh = Items.Meshes[Id]; ShaderMaterial Mat = new ShaderMaterial(); Mat.Shader = Items.TileShader; Mat.SetShaderParam("texture_albedo", Items.Textures[Id]); ViewmodelItem.MaterialOverride = Mat; ViewmodelItem.Show(); } else { ViewmodelItem.Hide(); } }
public override void _Process(float Delta) { if (!Possessed) { NetUpdateDelta += Delta; return; } if (Dying) { return; } Assert.ActualAssert(MinAdsMultiplier > 0 && MinAdsMultiplier <= 1); AdsMultiplier = Ads ? Clamp(AdsMultiplier - (Delta * (1 - MinAdsMultiplier) / AdsTime), MinAdsMultiplier, 1) : Clamp(AdsMultiplier + (Delta * (1 - MinAdsMultiplier) / AdsTime), MinAdsMultiplier, 1); Cam.Fov = Game.Fov * AdsMultiplier; float Length = Clamp(ViewmodelMomentum.Length() - Delta * ViewmodelMomentumFriction, 0, 1); ViewmodelMomentum = ViewmodelMomentum.Normalized() * Length; ViewmodelItem.RotationDegrees = new Vector3( SafeSign(ViewmodelMomentum.y) * ViewmodelMomentum.y * ViewmodelMomentum.y * MaxViewmodelItemRotation * AdsMultiplier, 180 - SafeSign(ViewmodelMomentum.x) * ViewmodelMomentum.x * ViewmodelMomentum.x * MaxViewmodelItemRotation * AdsMultiplier, 0 ); ViewmodelArmJoint.RotationDegrees = new Vector3( -SafeSign(ViewmodelMomentum.y) * ViewmodelMomentum.y * ViewmodelMomentum.y * MaxViewmodelArmRotation * AdsMultiplier, -SafeSign(ViewmodelMomentum.x) * ViewmodelMomentum.x * ViewmodelMomentum.x * MaxViewmodelArmRotation * AdsMultiplier, 0 ); ViewmodelArmJoint.Translation = new Vector3( NormalViewmodelArmX * ((AdsMultiplier - MinAdsMultiplier) * (1 / (1 - MinAdsMultiplier))), ViewmodelArmJoint.Translation.y, ViewmodelArmJoint.Translation.z ); ApplyLookVertical(0); var ToRemove = new List <Hitscan.AdditiveRecoil>(); foreach (Hitscan.AdditiveRecoil Instance in ActiveAdditiveRecoil) { Instance.Life += Delta; if (Instance.Life > Instance.Length) { ToRemove.Add(Instance); } } foreach (Hitscan.AdditiveRecoil Instance in ToRemove) { ActiveAdditiveRecoil.Remove(Instance); } if (Inventory[InventorySlot] != null) { Items.ID Id = Inventory[InventorySlot].Id; ViewmodelItem.Mesh = Items.Meshes[Id]; ShaderMaterial Mat = new ShaderMaterial(); Mat.Shader = Items.TileShader; Mat.SetShaderParam("texture_albedo", Items.Textures[Id]); ViewmodelItem.MaterialOverride = Mat; ViewmodelItem.Show(); { Items.IdInfo Info = Items.IdInfos[Inventory[InventorySlot].Id]; if (IsPrimaryFiring && CurrentCooldown >= CurrentMaxCooldown && Info.UseDelegate != null && Info.FullAuto) { Items.UseItem(Inventory[InventorySlot], this); } } } else { ViewmodelItem.Hide(); } }
private void ActualUpdate(Transform TargetTransform, float HeadRotation, bool Jumping, bool Crouching, float Hp, Items.ID ItemId, float ForwardMomentum) { Health = Hp; this.Transform = this.Transform.InterpolateWith( TargetTransform, NetUpdateDelta * 20 ); HeadJoint.Transform = HeadJoint.Transform.InterpolateWith( new Transform( new Quat( new Vector3(Deg2Rad(-HeadRotation), 0, 0) ), HeadJoint.Transform.origin ), NetUpdateDelta * 20 ); float LegsJointTarget = 0; if (!Crouching) { LegsJointTarget = Clamp((ForwardMomentum / MovementSpeed) * MaxGroundLegRotation, -MaxAirLegRotation, MaxAirLegRotation); } else { LegsJointTarget = MaxAirLegRotation * SafeSign(ForwardMomentum); } LegsJoint.Transform = LegsJoint.Transform.InterpolateWith( new Transform( new Quat( new Vector3(Deg2Rad(LegsJointTarget), 0, 0) ), LegsJoint.Transform.origin ), NetUpdateDelta * 20 ); if (RoundToInt(ForwardMomentum) == 0 && !Jumping) { RightLegFlames.Emitting = false; LeftLegFlames.Emitting = false; } else { RightLegFlames.Emitting = true; LeftLegFlames.Emitting = true; } if (ItemId == Items.ID.ERROR) { ThirdPersonItem.Hide(); } else { ThirdPersonItem.Mesh = Items.Meshes[ItemId]; ((ShaderMaterial)ThirdPersonItem.MaterialOverride).SetShaderParam("texture_albedo", Items.Textures[ItemId]); ThirdPersonItem.Show(); } NetUpdateDelta = Single.Epsilon; }
public virtual bool ShouldRemoveTile(Items.ID BranchType, Vector3 Position, Vector3 Rotation, int OwnerId) { return(true); }
public virtual bool ShouldPickupItem(Items.ID Type) { return(true); }
public void PickupItem(Items.ID Type) { ItemGive(new Items.Instance(Type)); }
public override void _PhysicsProcess(float Delta) { GhostMesh.Translation = OldPositions[0]; GhostMesh.RotationDegrees = OldRotations[0]; GhostMesh.Visible = OldVisible[0]; GhostMesh.Mesh = Items.Meshes[OldType[0]]; CurrentMeshType = OldType[0]; Player Plr = Game.PossessedPlayer; OldVisible.RemoveAt(0); OldVisible.Add(false); if (Plr.Inventory[Plr.InventorySlot] != null) { var BuildRayCast = Plr.GetNode <RayCast>("SteelCamera/RayCast"); if (BuildRayCast.IsColliding()) { if (BuildRayCast.GetCollider() is Tile Base) { Vector3?GhostPosition = Items.TryCalculateBuildPosition(CurrentMeshType, Base, Plr.RotationDegrees.y, Plr.BuildRotation, BuildRayCast.GetCollisionPoint()); if (GhostPosition != null) { Vector3 GhostRotation = Items.CalculateBuildRotation(CurrentMeshType, Base, Plr.RotationDegrees.y, Plr.BuildRotation, BuildRayCast.GetCollisionPoint()); 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) { bool _CanBuild = true; foreach (Node Body in GetOverlappingBodies()) { Items.Instance SelectedItem = Game.PossessedPlayer.Inventory[Game.PossessedPlayer.InventorySlot]; if (SelectedItem == null) { continue; } Items.ID[] DisallowedCollisions = Items.IdInfos[SelectedItem.Id].DisallowedCollisions; if (DisallowedCollisions != null && Body is Tile && DisallowedCollisions.Contains(((Tile)Body).Type)) { GhostMesh.MaterialOverride = RedMat; _CanBuild = false; } } OldCanBuild.Add(_CanBuild); if (_CanBuild) { GhostMesh.MaterialOverride = GreenMat; } } else { GhostMesh.MaterialOverride = GreenMat; OldCanBuild.Add(true); } CanBuild = OldCanBuild[0]; OldPositions.RemoveAt(0); OldPositions.Add(Translation); OldRotations.RemoveAt(0); OldRotations.Add(RotationDegrees); Items.Instance Item = Game.PossessedPlayer.Inventory[Game.PossessedPlayer.InventorySlot]; if (Item != null && Item.Id != CurrentMeshType) //null means no item in slot { OldType.RemoveAt(0); OldType.Add(Item.Id); } }
public override void _Process(float Delta) { Game.PossessedPlayer.Match( none: () => GhostMesh.Visible = false, some: (Plr) => { if (Plr.Inventory[Plr.InventorySlot] == null) { GhostMesh.Visible = false; CurrentMeshType = Items.ID.NONE; return; } CurrentMeshType = Plr.Inventory[Plr.InventorySlot].Id; GhostMesh.Mesh = Items.Meshes[CurrentMeshType]; var BuildRayCast = Plr.GetNode <RayCast>("SteelCamera/RayCast"); if (BuildRayCast.IsColliding() && BuildRayCast.GetCollider() is Tile Base) { Vector3?GhostPosition = Items.TryCalculateBuildPosition(CurrentMeshType, Base, Plr.RotationDegrees.y, Plr.BuildRotation, BuildRayCast.GetCollisionPoint()); if (GhostPosition != null) { GhostMesh.Visible = true; Vector3 GhostRotation = Items.CalculateBuildRotation(CurrentMeshType, Base, Plr.RotationDegrees.y, Plr.BuildRotation, BuildRayCast.GetCollisionPoint()); Translation = (Vector3)GhostPosition; RotationDegrees = GhostRotation; GhostMesh.Translation = (Vector3)GhostPosition; GhostMesh.RotationDegrees = GhostRotation; CanBuild = true; if (GetOverlappingBodies().Count > 0) { foreach (Node Body in GetOverlappingBodies()) { Items.ID[] DisallowedCollisions = Items.IdInfos[CurrentMeshType].DisallowedCollisions; if (DisallowedCollisions != null && Body is Tile Branch && DisallowedCollisions.Contains(Branch.ItemId)) { CanBuild = false; } } } if (CanBuild) { GhostMesh.MaterialOverride = GreenMat; } else { GhostMesh.MaterialOverride = RedMat; } return; } } CanBuild = false; GhostMesh.Visible = false; } ); }
public void PlaceWithName(Items.ID BranchType, Vector3 Position, Vector3 Rotation, int OwnerId, string Name) { //Nested if to prevent very long line if (Net.Work.NetworkPeer != null && !Net.Work.IsNetworkServer() && Game.PossessedPlayer.HasValue) { Player Plr = Game.PossessedPlayer.ValueOrFailure(); var PositionChunk = GetChunkTuple(Position); if (!ChunkWithinDistanceFrom(PositionChunk, Game.ChunkRenderDistance, Plr.Translation)) { //If network is inited, not the server, and platform it to far away then... return; //...don't place } } var Branch = (Tile)Scenes[BranchType].Instance(); Branch.ItemId = BranchType; Branch.OwnerId = OwnerId; Branch.Translation = Position; Branch.RotationDegrees = Rotation; Branch.Name = Name; //Name is a GUID and can be used to reference a structure over network EntitiesRoot.AddChild(Branch); AddTileToChunk(Branch); Grid.AddItem(Branch); Grid.QueueUpdateNearby(Branch.Translation); if (Net.Work.NetworkPeer != null && Net.Work.IsNetworkServer()) { TryAddTileToPathfinder(Branch); if (Game.PossessedPlayer.HasValue) { Player Plr = Game.PossessedPlayer.ValueOrFailure(); var PositionChunk = GetChunkTuple(Position); if (!ChunkWithinDistanceFrom(PositionChunk, Game.ChunkRenderDistance, Plr.Translation)) { //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.Players.Keys) { if (Id == Net.ServerId) //Skip self (we are the server) { continue; } Net.Players[Id].Plr.MatchSome( (Plr) => { var PositionChunk = GetChunkTuple(Position); if (ChunkWithinDistanceFrom(PositionChunk, ChunkRenderDistances[Id], Plr.Translation)) { if (!RemoteLoadedChunks[Id].Contains(GetChunkTuple(Position))) { RemoteLoadedChunks[Id].Add(GetChunkTuple(Position)); } } } ); } } }
public Instance(Items.ID IdArg) { Id = IdArg; }