private async Task ItemXChange(ChatInfo info, PlayerInfo player, ItemBox itemBox, bool aChange) { var exchange = new ItemExchangeInfo() { buttonText = "XChange", desc = "Erze in das Tauschfeld legen und tauschen (ESC oder Button), dann die Erze wieder herausnehmen", id = info.playerId, items = GetBoxContents(player.entityId).ToArray(), title = $@"{itemBox.fullName} XChange" }; async void eventCallback(ItemExchangeInfo B) { if (player.entityId != B.id) { return; } Event_Player_ItemExchange -= eventCallback; SetBoxContents(player.entityId, itemBox, B.items); if (aChange) { await ItemXChange(info, player, itemBox, false); } } Event_Player_ItemExchange += eventCallback; await Request_Player_ItemExchange(Timeouts.Wait10m, exchange); }
private void EmpyrionBackpackExtender_Event_Player_ItemExchange( ItemExchangeInfo bpData, ConfigurationManager <BackpackData> currentBackpack, BackpackConfiguration config, int usedBackpackNo) { currentBackpack.Current.Backpacks[usedBackpackNo - 1].Items = config.AllowSuperstack ? SuperstackItems(bpData.items ?? new ItemStack[] { }) : bpData.items ?? new ItemStack[] { }; currentBackpack.Current.OpendByName = null; currentBackpack.Current.OpendBySteamId = null; currentBackpack.Save(); }
private async void ExampleMod_Event_HandleLottoChatMessage(MessageData obj) { Logger.log("lotto check"); if (obj.Text != "lottery") { return; } var list = await Broker.Request_Player_List(); var index = RNG.Next() % list.list.Count; var selectedId = list.list[index]; var msgParam = new IdMsgPrio() { id = selectedId, msg = $"Congratulations!, You Won!" }; var rewardParam = new ItemExchangeInfo() { id = selectedId, buttonText = "ok", title = "test", desc = "testdesc", items = new ItemStack[] { new ItemStack() { id = 256, count = 1 } } }; try { var result = await Broker.Request_Player_ItemExchange(rewardParam); if (result.items.Any()) { return; } MessagePlayer(selectedId, $"Thanks for the gift!"); } catch (EmpyrionAPIException ex) { Logger.log($"itemexchange error: {ex.info.ToString()}"); } }
private void ExampleMod_Event_HandleLottoChatMessage(ChatInfo obj) { log("lotto check"); if (obj.msg != "lottery") { return; } this.Request_Player_List(list => { var index = rnd.Next() % list.list.Count; var selectedId = list.list[index]; var msgParam = new IdMsgPrio() { id = selectedId, msg = $"Congratulations!, You Won!" }; var rewardParam = new ItemExchangeInfo() { id = selectedId, buttonText = "ok", title = "test", desc = "testdesc", items = new ItemStack[] { new ItemStack() { id = 256, count = 1 } } }; this.Request_Player_ItemExchange(rewardParam, result => { log($"itemexchange result count {result.items.Count()}"); if (result.items.Count() == 0) { return; } var tyParam = new IdMsgPrio() { id = selectedId, msg = $"Thanks for the gift!" }; this.Request_InGameMessage_SinglePlayer(tyParam); }, x => log($"itemexchange error: {x.errorType.ToString()}")); }); }
private async Task OpenBackpackItemExcange(int playerId, BackpackConfiguration config, string name, string description, ConfigurationManager <BackpackData> currentBackpack, ItemStack[] items) { var exchange = new ItemExchangeInfo() { buttonText = "close", desc = description, id = playerId, items = items ?? new ItemStack[] { }, title = $"Backpack ({name}) {(config.MaxBackpacks > 1 ? "#" + currentBackpack.Current.LastUsed : string.Empty)}" }; try { await Request_Player_ItemExchange(0, exchange); } // ignore Timeout Exception catch { } }
public static void Request_Player_ItemExchange(ItemExchangeInfo arg, Action <ItemExchangeInfo> callback = null, Action <ErrorInfo> onError = null) { Action <CmdId, object> wiredCallback = null; if (callback != null) { wiredCallback = (_, val) => callback((ItemExchangeInfo)val); } var apiCmd = new GenericAPICommand( CmdId.Request_Player_ItemExchange, arg, wiredCallback, onError ?? noOpErrorHandler ); Broker.Execute(apiCmd); }
private void ProcessEvent_Player_ItemExchange(ItemExchangeInfo itemExchangeInfo) { // from Request_Player_ItemExchange DebugLog("Event_Player_ItemExchange - Player: {0}", itemExchangeInfo.id); }
public async Task <ItemExchangeInfo> Request_Player_ItemExchange(ItemExchangeInfo arg, CancellationToken ct) { return(await Broker.SendRequestAsync <ItemExchangeInfo, ItemExchangeInfo>(CmdId.Request_Player_ItemExchange, arg, ct)); }
public async Task <ItemExchangeInfo> Request_Player_ItemExchange(ItemExchangeInfo arg) { return(await Broker.SendRequestAsync <ItemExchangeInfo, ItemExchangeInfo>(CmdId.Request_Player_ItemExchange, arg)); }
public void Request_Player_ItemExchange(ItemExchangeInfo arg, Action <ItemExchangeInfo> callback = null, Action <ErrorInfo> onError = null) { Broker.Request_Player_ItemExchange(arg, callback, onError); }
public static Task <ItemExchangeInfo> Request_Player_ItemExchange(ItemExchangeInfo param) { return(Broker.CreateCommandWithArgAndReturn <ItemExchangeInfo, ItemExchangeInfo>(CmdId.Request_Player_ItemExchange, param)); }
public static Task <ItemExchangeInfo> Request_Player_ItemExchange(ItemExchangeInfo param, Action <ItemExchangeInfo> callback, Action <ErrorInfo> onError = null) { return(Broker.CreateCommandWithArgAndReturn <ItemExchangeInfo, ItemExchangeInfo>(CmdId.Request_Player_ItemExchange, param, callback, onError)); }
public void Game_Event(CmdId cmdId, ushort seqNr, object data) { try { switch (cmdId) { case CmdId.Event_Player_Connected: Id pc = (Id)data; try { string[] bagLines = System.IO.File.ReadAllLines("Content\\Mods\\Xango\\players\\EID" + pc.id + "\\VirtualBackpack.txt"); int itemStackSize = bagLines.Count(); ItemStack[] itStack = new ItemStack[itemStackSize]; for (int i = 0; i < itemStackSize; ++i) { string[] bagLinesSplit = bagLines[i].Split(','); itStack[i] = new ItemStack(Convert.ToInt32(bagLinesSplit[1]), Convert.ToInt32(bagLinesSplit[2])); //1=ItemNumber, 2=StackSize itStack[i].slotIdx = Convert.ToByte(bagLinesSplit[0]); //0=SlotNumber itStack[i].ammo = Convert.ToInt32(bagLinesSplit[3]); //3=Ammo itStack[i].decay = Convert.ToInt32(bagLinesSplit[4]); //4=Decay } vBackpackDictionary.Add(pc.id, itStack); } catch { }; LogFile("chat.txt", "Player " + pc.id + " Connected"); try { System.IO.Directory.CreateDirectory("Content\\Mods\\Xango\\players\\EID" + pc.id); } catch { }; break; case CmdId.Event_Player_Disconnected: Id pd = (Id)data; LogFile("chat.txt", "Player " + pd.id + " DisConnected"); vBackpackDictionary.Remove(pd.id); break; case CmdId.Event_Player_Info: PlayerInfo PlayerInfoReceived = (PlayerInfo)data; if (BackpackChatDictionary.ContainsKey(PlayerInfoReceived.entityId)) { BackpackChatDictionary.Remove(PlayerInfoReceived.entityId); if (vBackpackDictionary.ContainsKey(PlayerInfoReceived.entityId)) { BackpackChatDictionary.Remove(PlayerInfoReceived.entityId); LogFile("Chat.txt", "show backpack"); GameAPI.Game_Request(CmdId.Request_Player_ItemExchange, (ushort)CmdId.Request_Player_ItemExchange, new ItemExchangeInfo(PlayerInfoReceived.entityId, "Virtual Backpack", "Extra Inventory Space, Yay!", "Save", vBackpackDictionary[PlayerInfoReceived.entityId])); step = "Request ItemExchange"; } else { if (System.IO.File.Exists("Content\\Mods\\Xango\\players\\EID" + Convert.ToString(PlayerInfoReceived.entityId) + "\\VirtualBackpack.txt")) { LogFile("Chat.txt", "Build Blank Backpack"); System.IO.File.Create("Content\\Mods\\Xango\\players\\EID" + Convert.ToString(PlayerInfoReceived.entityId) + "\\VirtualBackpack.txt"); buildItemStack(PlayerInfoReceived.entityId, "blank"); } else { LogFile("Chat.txt", "Show Blank Backpack"); GameAPI.Game_Request(CmdId.Request_Player_ItemExchange, (ushort)CmdId.Request_Player_ItemExchange, new ItemExchangeInfo(PlayerInfoReceived.entityId, "Virtual Backpack", "Extra Inventory Space, Yay!", "Save", EmptyExchange)); step = "Request ItemExchange"; } } } break; case CmdId.Event_Player_ItemExchange: ItemExchangeInfo exchangeInfo = (ItemExchangeInfo)data; vBackpackDictionary[exchangeInfo.id] = exchangeInfo.items; System.IO.File.WriteAllText("Content\\Mods\\Xango\\players\\EID" + exchangeInfo.id + "\\VirtualBackpack.txt", string.Empty); for (int i = 0; i <= exchangeInfo.items.Count(); i++) { LogFile("players\\EID" + exchangeInfo.id + "\\VirtualBackpack.txt", Convert.ToString(exchangeInfo.items[i].slotIdx) + "," + Convert.ToString(exchangeInfo.items[i].id) + "," + Convert.ToString(exchangeInfo.items[i].count) + "," + Convert.ToString(exchangeInfo.items[i].ammo) + "," + Convert.ToString(exchangeInfo.items[i].decay)); } step = "itemExchange complete"; break; case CmdId.Event_Player_DisconnectedWaiting: Id pdw = new Id(); GameAPI.Console_Write("Player " + pdw.id + " Failed Login Attempt"); break; case CmdId.Event_ChatMessage: ChatInfo ci = (ChatInfo)data; LogFile("Chat.txt", ci.playerId + " SAYS: " + ci.msg); if (ci.msg.StartsWith("s! ")) { ci.msg = ci.msg.Remove(0, 3); } ci.msg = ci.msg.ToLower(); if (ci.msg.StartsWith("/backpack")) { BackpackChatDictionary[ci.playerId] = ci.msg; GameAPI.Game_Request(CmdId.Request_Player_Info, (ushort)CmdId.Request_Player_Info, new Eleon.Modding.Id(ci.playerId)); step = "Request Playerinfo"; } break; case CmdId.Event_Error: ErrorInfo err = (ErrorInfo)data; ErrorType err2 = (ErrorType)data; LogFile("ERROR.txt", Convert.ToString(err2) + ": " + Convert.ToString(err)); break; default: break; } } catch (Exception ex) { GameAPI.Console_Write(ex.Message); } }