private void DidCloseStackRandomizer(ItemSlot slot, GuiDialogGeneric dialog) { dialogs.Remove(slot); if (slot.Itemstack == null) { return; } if (dialog.Attributes.GetInt("save") == 0) { return; } slot.Itemstack.Attributes.SetFloat("totalChance", dialog.Attributes.GetFloat("totalChance")); using (MemoryStream ms = new MemoryStream()) { BinaryWriter writer = new BinaryWriter(ms); slot.Itemstack.Attributes.ToBytes(writer); clientChannel.SendPacket(new SaveStackRandomizerAttributes() { TotalChance = dialog.Attributes.GetFloat("totalChance"), InventoryId = slot.Inventory.InventoryID, SlotId = slot.Inventory.GetSlotId(slot) }); } }
private bool SortKey(KeyCombination key) { if (a) { a = false; int modid = capi.Input.GetHotKeyByCode("sortmodifier").CurrentMapping.KeyCode; capi.World.RegisterCallback(dt => a = true, 50); string invid = ""; if (capi.World.Player.InventoryManager.CurrentHoveredSlot != null) { invid = capi.World.Player.InventoryManager.CurrentHoveredSlot.Inventory.InventoryID; } if (capi.Input.KeyboardKeyStateRaw[modid]) { cChannel.SendPacket(new SortResponse() { mode = sorting.Next(ref index).ToString(), inv = invid, }); } else { cChannel.SendPacket(new SortResponse() { mode = sorting[index].ToString(), inv = invid, }); } } return(true); }
public void SendNetworkBlocksUpdateRequestToServer(long networkId) { clientNwChannel.SendPacket <MechClientRequestPacket>(new MechClientRequestPacket() { networkId = networkId }); }
private void OnClientReceiveTeleportMsg(TeleportMsg msg) { if (!msg.DoRemove) { if (Teleports.ContainsKey(msg.Pos)) { Teleports[msg.Pos] = msg.Data; } else { Teleports.Add(msg.Pos, msg.Data); } } else { if (Teleports.ContainsKey(msg.Pos)) { Teleports.Remove(msg.Pos); } } if (!msg.Synced) { clientChannel.SendPacket(new TeleportMsg( msg.Pos, msg.Data, msg.DoRemove )); } }
private void OnSetValuesDialog(string elementCode, string newValue) { switch (elementCode) { case "name": forLocation.SourceName = newValue; break; case "targetlocation": if (newValue.Length > 0) { int pos = int.Parse(newValue); forLocation.TargetPos = targetPositionsOrdered[pos]; forLocation.TargetName = targetNamesOrdered[pos]; } break; case "cancel": dialog.TryClose(); break; case "save": clientChannel.SendPacket(forLocation); dialog.TryClose(); break; } }
public void SendSkinPacket(string newpart, string newvariant) { clientNetworkChannel.SendPacket(new SkinChange() { part = newpart, variant = newvariant }); }
private void OnServerMessage(NetworkApiTestMessage networkMessage) { clientApi.ShowChatNotification("Received following message from server: " + networkMessage.message); clientApi.ShowChatNotification("Sending response."); clientChannel.SendPacket(new NetworkApiTestResponse() { response = "RE: Hello World!" }); }
private void PlayerSitDown(IWorldAccessor world, IPlayer byPlayer, BlockPos chairPosition) { PlayerData playerData = PlayerManager.Instance.GetOrAddPlayerData(byPlayer); // Sets the player to the center of the chair Vec3d centerOfChair = chairPosition.ToVec3d().Add(0.5, 0.5, 0.5); byPlayer.Entity.Pos.SetPos(centerOfChair); // Set player's status to sitting playerData.TogglePlayerSitting(); playerData.SatChairPos = chairPosition; // If there is a table next to chair, set player to face chair BlockPos adjacentTable = GetAdjacentTable(world, chairPosition); // Send packet to server to sync all clients IClientNetworkChannel networkChannel = (IClientNetworkChannel)api.Network.GetChannel("networksit"); networkChannel.SendPacket(new NetworkAnimationSit() { isSitting = true, playerUID = byPlayer.PlayerUID }); // Modify eye height byPlayer.Entity.Properties.SetEyeHeight(SITTINGEYEHEIGHT); // Set player's sitting direction if (adjacentTable != null) { if (byPlayer.Entity.Pos.AsBlockPos.East().Equals(adjacentTable)) { playerData.SetSittingDirection(Cardinal.East); ((ICoreClientAPI)api).Input.MouseYaw = 0; } if (byPlayer.Entity.Pos.AsBlockPos.West().Equals(adjacentTable)) { playerData.SetSittingDirection(Cardinal.West); ((ICoreClientAPI)api).Input.MouseYaw = 0.5f * GameMath.TWOPI; } if (byPlayer.Entity.Pos.AsBlockPos.South().Equals(adjacentTable)) { playerData.SetSittingDirection(Cardinal.South); ((ICoreClientAPI)api).Input.MouseYaw = 0.75f * GameMath.TWOPI; } if (byPlayer.Entity.Pos.AsBlockPos.North().Equals(adjacentTable)) { playerData.SetSittingDirection(Cardinal.North); ((ICoreClientAPI)api).Input.MouseYaw = 0.25f * GameMath.TWOPI; } } }
private void Event_FileDrop(FileDropEvent ev) { FileInfo info = null; long bytes = 0; try { info = new FileInfo(ev.Filename); bytes = info.Length; } catch (Exception ex) { capi.TriggerIngameError(this, "importfailed", string.Format("Unable to import schematic: ", ex)); return; } if (ownWorkspace != null && ownWorkspace.ToolsEnabled && ownWorkspace.ToolName == "Import") { int schematicMaxUploadSizeKb = capi.Settings.Int.Get("schematicMaxUploadSizeKb", 150); // Limit the file size if (bytes / 1024 > schematicMaxUploadSizeKb) { capi.TriggerIngameError(this, "schematictoolarge", Lang.Get("Importing of schematics above {0} KB disabled, adjust config schematicMaxUploadSizeKb to change.", schematicMaxUploadSizeKb)); return; } string err = null; BlockSchematic schematic = BlockSchematic.LoadFromFile(ev.Filename, ref err); if (err != null) { capi.TriggerIngameError(this, "importerror", err); return; } string json = ""; using (TextReader textReader = new StreamReader(ev.Filename)) { json = textReader.ReadToEnd(); textReader.Close(); } if (json.Length < 1024 * 100) { capi.World.Player.ShowChatNotification(Lang.Get("Sending {0} bytes of schematicdata to the server...", json.Length)); } else { capi.World.Player.ShowChatNotification(Lang.Get("Sending {0} bytes of schematicdata to the server, this may take a while...", json.Length)); } capi.Event.RegisterCallback((dt) => { clientChannel.SendPacket <SchematicJsonPacket>(new SchematicJsonPacket() { Filename = info.Name, JsonCode = json }); }, 20); } }
/// <summary> /// If called on the client, pushes an event to the server-side event bus. /// If called on the server, pushes an event to the client-side event buses of all clients. /// </summary> /// <param name="eventAPI">The event API</param> /// <param name="eventName">The event's name</param> /// <param name="data">Optional event data</param> public static void PushRemoteEvent(this IEventAPI eventAPI, string eventName, IAttribute data = null) { SynchronizedEvent synchronizedEvent = ToSynchronizedEvent(eventName, data); if (eventAPI is IServerEventAPI) { serverChannel.BroadcastPacket(synchronizedEvent); } else { clientChannel.SendPacket(synchronizedEvent); } }
private void SendBlockAction(MouseEvent e) { if (e.Button == EnumMouseButton.Right && capi.World.Player.Entity.Controls.Sneak) { if (OnPlayerInteract(capi.World.Player, capi.World.Player.CurrentBlockSelection)) { cChannel.SendPacket(new IWCSPacket() { DataType = EnumDataType.Action }); capi.World.Player.TriggerFpAnimation(EnumHandInteract.HeldItemInteract); e.Handled = true; } } }
private void PlayerStandUp(IPlayer byPlayer) { // Modify eye height byPlayer.Entity.Properties.SetEyeHeight(DEFAULTEYEHEIGHT); // Set sitting direction to something not used playerManager.GetOrAddPlayerData(byPlayer).SetSittingDirection(Cardinal.SouthWest); // Send packet to server to sync all clients IClientNetworkChannel networkChannel = (IClientNetworkChannel)api.Network.GetChannel("networksit"); networkChannel.SendPacket(new NetworkAnimationSit() { isSitting = false, playerUID = byPlayer.PlayerUID }); // Set player's status to not sitting PlayerManager.Instance.GetOrAddPlayerData(byPlayer).TogglePlayerSitting(); }
public void SetPendingNode(NodePos pos) { if (api.Side == EnumAppSide.Server) { return; } if (pendingNode == null) { pendingNode = pos; capi?.ShowChatMessage(String.Format("Pending {0}:{1}", pos.blockPos, pos.index)); } else { capi?.ShowChatMessage(String.Format("trying to attach {0}:{1}", pos.blockPos, pos.index)); WireConnection connection = new WireConnection(pendingNode, pos); clientChannel.SendPacket(new AddConnectionPacket() { connection = connection }); pendingNode = null; } }
public void ToggleMap(EnumDialogType asType) { bool isDlgOpened = worldMapDlg != null && worldMapDlg.IsOpened(); if (!capi.World.Config.GetBool("allowMap", true)) { if (isDlgOpened) { worldMapDlg.TryClose(); } return; } if (worldMapDlg != null) { if (!isDlgOpened) { if (asType == EnumDialogType.HUD) { capi.Settings.Bool["showMinimapHud"] = true; } worldMapDlg.Open(asType); foreach (MapLayer layer in MapLayers) { layer.OnMapOpenedClient(); } clientChannel.SendPacket(new OnMapToggle() { OpenOrClose = true }); return; } else { if (worldMapDlg.DialogType != asType) { worldMapDlg.Open(asType); return; } if (asType == EnumDialogType.HUD) { capi.Settings.Bool["showMinimapHud"] = false; } else if (capi.Settings.Bool["showMinimapHud"]) { worldMapDlg.Open(EnumDialogType.HUD); return; } } worldMapDlg.TryClose(); return; } worldMapDlg = new GuiDialogWorldMap(onViewChangedClient, capi); worldMapDlg.OnClosed += () => { foreach (MapLayer layer in MapLayers) { layer.OnMapClosedClient(); } clientChannel.SendPacket(new OnMapToggle() { OpenOrClose = false }); }; worldMapDlg.Open(asType); foreach (MapLayer layer in MapLayers) { layer.OnMapOpenedClient(); } clientChannel.SendPacket(new OnMapToggle() { OpenOrClose = true }); if (asType == EnumDialogType.HUD) { capi.Settings.Bool["showMinimapHud"] = true; } }
/// <summary> Initialize the client handler. </summary> public void Initialize() { // Register the networking channel. Channel = Capi.Network.RegisterChannel(MistModSystem.MOD_ID) .RegisterMessageType(typeof(BurnMessage)) .RegisterMessageType(typeof(SelectedMetalMessage)) .RegisterMessageType(typeof(ReplaceAlloHelperEntity)); Channel.SetMessageHandler <SelectedMetalMessage>(OnSelectedMetalMessage); Channel.SetMessageHandler <ReplaceAlloHelperEntity>(OnUpdateAlloHelper); // Hotkeys for burning metals. Capi.Input.RegisterHotKey("burn-metal-toggle", "Toggle allomantic metal burn", GlKeys.Z, HotkeyType.CharacterControls, false, true, true); Capi.Input.RegisterHotKey( "burn-metal-inc", "Increase allomantic metal burn", GlKeys.Z, HotkeyType.CharacterControls, false, false, true); Capi.Input.RegisterHotKey( "burn-metal-dec", "Decrease allomantic metal burn", GlKeys.Z, HotkeyType.CharacterControls, false, true, false); Capi.Input.RegisterHotKey( "burn-metal-flare", "Flare allomantic metal", GlKeys.Z, HotkeyType.CharacterControls); Capi.Input.SetHotKeyHandler("burn-metal-toggle", a => { Channel.SendPacket(new BurnMessage(metalSelector.SelectedMetal, 4)); return(true); }); Capi.Input.SetHotKeyHandler("burn-metal-inc", a => { Channel.SendPacket(new BurnMessage(metalSelector.SelectedMetal, 3)); return(true); }); Capi.Input.SetHotKeyHandler("burn-metal-dec", a => { Channel.SendPacket(new BurnMessage(metalSelector.SelectedMetal, 2)); return(true); }); Capi.Input.SetHotKeyHandler("burn-metal-flare", a => { Channel.SendPacket(new BurnMessage(metalSelector.SelectedMetal, 1)); return(true); }); // Hotkeys for GUI Capi.Input.RegisterHotKey( "guimetalselect", "Select allomantic metal", GlKeys.K, HotkeyType.GUIOrOtherControls); Capi.Input.SetHotKeyHandler("guimetalselect", ToggleMetalSelectGui); // Add event to know when the game has loaded. Capi.Event.BlockTexturesLoaded += OnLoad; // Create an allomancy helper for the entity. Capi.Event.LevelFinalize += () => { AllomancyHelper = new AllomancyPropertyHelper(Capi.World.Player.Entity); }; // Register UI updates Capi.Event.RegisterGameTickListener((float dt) => { AllomancyHelper.Entity = Capi.World.Player.Entity; AllomancyHelper.UpdateTree(); if (AllomancyHelper != null) { metalSelector.UpdateUI(dt); } }, 10); motionParticles.gravityEffect = 0; // Visual effects updates Capi.Event.RegisterGameTickListener((float dt) => { if (AllomancyHelper != null) { float maxhealth = ((ITreeAttribute)Capi.World.Player.Entity.WatchedAttributes["health"]).GetFloat("maxhealth"); float fatigue = AllomancyHelper.GetPewterFatigue(); targetVignete = fatigue / maxhealth; if (targetVignete > 1) { targetVignete = 1; } ShaderLoader.VigneteStrength += (targetVignete - ShaderLoader.VigneteStrength) / 5; int tinstatus = AllomancyHelper.GetEffectiveBurnStatus("tin"); targetNightvision = tinstatus * (1.0f / 5.0f); ShaderLoader.NightvisionStrength += (targetNightvision - ShaderLoader.NightvisionStrength) / 5; } }, 0); Capi.Event.RegisterGameTickListener((float dt) => { int tinstatus = AllomancyHelper.GetEffectiveBurnStatus("tin"); if (previousTinStatus == 0 && tinstatus != 0) { Capi.Settings.Int["cachedfov"] = Capi.Settings.Int["fieldOfView"]; } if (tinstatus == 0 && previousTinStatus != 0) { if (Capi.Settings.Int["cachedfov"] != 0) { Capi.Settings.Int["fieldOfView"] = Capi.Settings.Int["cachedfov"]; } } if (tinstatus > 0) { Capi.Settings.Int["fieldOfView"] = 100 - tinstatus * 18; motionParticles.glowLevel = (byte)(255.0f * tinstatus * (1.0f / 5.0f)); float vspeed = 3.0f * tinstatus * (1.0f / 5.0f) + 0.1f; motionParticles.minSize = 3.0f * tinstatus * (1.0f / 5.0f) + 1f; motionParticles.maxSize = 3.0f * tinstatus * (1.0f / 5.0f) + 1f; motionParticles.minVelocity.Y = vspeed; Entity[] nearbyEnts = Capi.World.GetEntitiesAround(Capi.World.Player.Entity.Pos.XYZ, 100, 100); foreach (Entity ent in nearbyEnts) { if (ent == Capi.World.Player.Entity) { continue; } motionParticles.minPos = ent.Pos.XYZ; Capi.World.SpawnParticles(motionParticles); } } previousTinStatus = tinstatus; }, 100); }