internal AddStaticItem(LightSource lightSource) : this() { Coords = lightSource.Coords; StaticItemType = StaticItemType.LightSource; SubType = (ushort)lightSource.Type; AttachedToFace = lightSource.AttachedToFace; GameObjectId = lightSource.Id; }
internal AddStaticItem(ref Coords coords, StaticItemType staticItemType, ushort subType, Face attachedToFace, int gameObjectId = -1) : this() { Coords = coords; StaticItemType = staticItemType; SubType = subType; AttachedToFace = attachedToFace; GameObjectId = gameObjectId; }
internal override void Receive() { if (!Config.IsSinglePlayer) { lock (TcpClient) { base.Receive(); var bytes = ReadStream(DataLength); Coords = new Coords(bytes, 0); StaticItemType = (StaticItemType)BitConverter.ToUInt16(bytes, Coords.SIZE); SubType = BitConverter.ToUInt16(bytes, Coords.SIZE + sizeof(ushort)); AttachedToFace = (Face)BitConverter.ToUInt16(bytes, Coords.SIZE + sizeof(ushort) * 2); GameObjectId = BitConverter.ToInt32(bytes, Coords.SIZE + sizeof(ushort) * 3); } } switch (StaticItemType) { case StaticItemType.Clutter: throw new NotSupportedException("Clutter cannot be placed yet."); case StaticItemType.LightSource: new LightSource(ref Coords, (LightSourceType)SubType, AttachedToFace, GameObjectId); if (!Config.IsServer) //lighting needs to be updated and affected chunks queued for non servers when adding a light source { var position = Coords.ToPosition(); Task<Queue<Chunk>>.Factory.StartNew(() => Lighting.UpdateLightBox(ref position, null, false, false)).ContinueWith(task => WorldData.QueueAffectedChunks(task.Result)); } break; default: throw new Exception(string.Format("Unknown static item type: {0}", StaticItemType)); } if (Config.IsServer) { foreach (var player in Server.Controller.Players.Values) { new AddStaticItem(ref Coords, StaticItemType, SubType, AttachedToFace, GameObjectId) {ConnectedPlayer = player}.Send(); } } }