private async Task AttemptToAddNewTradeNode() { try { var selection = await SelectionTracker.instance.GetInputAsync <TradeStop>(market => true); var newTradeNode = new TradeNode { target = selection, trades = new ResourceTrade <ResourceType>[] { new ResourceTrade <ResourceType> { amount = 0, type = ResourceType.Food }, new ResourceTrade <ResourceType> { amount = 0, type = ResourceType.Wood } } }; linkedTrader.AddTradeNode(newTradeNode); } catch (ObjectSelectionCancelledException) { } catch (Exception e) { Debug.LogError($"Error when using the asynchronous selection requester"); Debug.LogException(e); throw; } }
public void SetTradeValues( GameSession _game, TradeNode node, TradeNode historynode, int systemId) { this.PostSetProp("TradeNode", (object)node.Produced, (object)node.ProductionCapacity, (object)node.Consumption, (object)node.Freighters, (object)node.DockCapacity, (object)node.ExportInt, (object)node.ExportProv, (object)node.ExportLoc, (object)node.ImportInt, (object)node.ImportProv, (object)node.ImportLoc, (object)node.Range, (object)historynode.Produced, (object)historynode.Freighters, (object)historynode.ImportInt); List <FreighterInfo> freighterInfoList = _game.GameDatabase == null ? new List <FreighterInfo>() : _game.GameDatabase.GetFreighterInfosForSystem(systemId).ToList <FreighterInfo>(); Dictionary <FreighterInfo, int> source = new Dictionary <FreighterInfo, int>(); foreach (FreighterInfo key in freighterInfoList) { source.Add(key, ((IEnumerable <DesignSectionInfo>)key.Design.DesignSections).Sum <DesignSectionInfo>((Func <DesignSectionInfo, int>)(x => x.ShipSectionAsset.FreighterSpace))); } Dictionary <FreighterInfo, int> dictionary = source.OrderByDescending <KeyValuePair <FreighterInfo, int>, int>((Func <KeyValuePair <FreighterInfo, int>, int>)(x => x.Value)).ToDictionary <KeyValuePair <FreighterInfo, int>, FreighterInfo, int>((Func <KeyValuePair <FreighterInfo, int>, FreighterInfo>)(y => y.Key), (Func <KeyValuePair <FreighterInfo, int>, int>)(y => y.Value)); List <object> objectList1 = new List <object>(); objectList1.Add((object)dictionary.Where <KeyValuePair <FreighterInfo, int> >((Func <KeyValuePair <FreighterInfo, int>, bool>)(x => { if (x.Key.PlayerId == _game.LocalPlayer.ID) { return(!x.Key.IsPlayerBuilt); } return(true); })).Count <KeyValuePair <FreighterInfo, int> >()); objectList1.AddRange(dictionary.Where <KeyValuePair <FreighterInfo, int> >((Func <KeyValuePair <FreighterInfo, int>, bool>)(x => { if (x.Key.PlayerId == _game.LocalPlayer.ID) { return(!x.Key.IsPlayerBuilt); } return(true); })).Select <KeyValuePair <FreighterInfo, int>, int>((Func <KeyValuePair <FreighterInfo, int>, int>)(x => x.Value)).Cast <object>()); this.PostSetProp("FreighterCapacities", objectList1.ToArray()); List <object> objectList2 = new List <object>(); objectList2.Add((object)dictionary.Where <KeyValuePair <FreighterInfo, int> >((Func <KeyValuePair <FreighterInfo, int>, bool>)(x => { if (x.Key.PlayerId == _game.LocalPlayer.ID) { return(x.Key.IsPlayerBuilt); } return(false); })).Count <KeyValuePair <FreighterInfo, int> >()); objectList2.AddRange(dictionary.Where <KeyValuePair <FreighterInfo, int> >((Func <KeyValuePair <FreighterInfo, int>, bool>)(x => { if (x.Key.PlayerId == _game.LocalPlayer.ID) { return(x.Key.IsPlayerBuilt); } return(false); })).Select <KeyValuePair <FreighterInfo, int>, int>((Func <KeyValuePair <FreighterInfo, int>, int>)(x => x.Value)).Cast <object>()); this.PostSetProp("PlayerFreighterCapacities", objectList2.ToArray()); }
private TradeNodePanel CreateSingleTradeNode(TradeNode node, float maxTradeAmount) { return(TradeNodePanel.InstantiateOnObject( singleTradeNodePrefab, gameObject, node, maxTradeAmount, () => { InternalTradeRouteUpdated(linkedTrader.tradeRouteReactive.Value); })); }
public static TradeNodePanel InstantiateOnObject( GameObject selfPrefab, GameObject container, TradeNode node, float maxTradeAmount) { Debug.Log($"Creating single node with {node.target.gameObject.name}"); var newTradeNode = GameObject.Instantiate(selfPrefab, container.transform); var selfScript = newTradeNode.GetComponent <TradeNodePanel>(); selfScript.tradeNode = node; selfScript.maxTradeAmount = maxTradeAmount; Debug.Log($"Assigned node with {node.trades.Length} trades"); return(selfScript); }
public static TradeNodePanel InstantiateOnObject( GameObject selfPrefab, GameObject container, TradeNode node, float maxTradeAmount, Action marketChanged) { var newTradeNode = GameObject.Instantiate(selfPrefab, container.transform); var selfScript = newTradeNode.GetComponent <TradeNodePanel>(); selfScript.tradeNode = node; selfScript.maxTradeAmount = maxTradeAmount; selfScript.marketChanged = marketChanged; return(selfScript); }