public void Reset() { Result = MarketDialogResult.Pending; Transaction = null; PlayerColumns.Reconstruct(Player.Resources, new List <ResourceAmount>(), (int)Player.Money); UpdateBottomDisplays(); Layout(); }
public void Reset() { Result = MarketDialogResult.Pending; Transaction = null; PlayerColumns.Reconstruct(Play.Trading.Helper.AggregateResourcesIntoTradeableItems(Player.Resources), new List <TradeableItem>(), (int)Player.Money); UpdateBottomDisplays(); Layout(); }
public void Reset() { Result = TradeDialogResult.Pending; Transaction = null; EnvoyColumns.Reconstruct(Envoy.Resources, new List <ResourceAmount>(), (int)Envoy.Money); PlayerColumns.Reconstruct(Player.Resources, new List <ResourceAmount>(), (int)Player.Money); UpdateBottomDisplays(); Balance.TradeBalance = 0.0f; Layout(); }
private void EqualizeColumns() { if (EnvoyColumns.Valid && PlayerColumns.Valid) { var net = ComputeNetValue(); var envoyOut = Envoy.ComputeValue(EnvoyColumns.SelectedResources) + EnvoyColumns.TradeMoney; var tradeTarget = envoyOut * 0.25; if (IsReasonableTrade(envoyOut, net)) { Root.ShowTooltip(Root.MousePosition, "This works fine."); return; } List <ResourceAmount> sourceResourcesEnvoy = EnvoyColumns.SourceResources; List <ResourceAmount> selectedResourcesEnvoy = EnvoyColumns.SelectedResources; DwarfBux selectedMoneyEnvoy = EnvoyColumns.TradeMoney; DwarfBux remainingMoneyEnvoy = Envoy.Money - selectedMoneyEnvoy; List <ResourceAmount> sourceResourcesPlayer = PlayerColumns.SourceResources; List <ResourceAmount> selectedResourcesPlayer = PlayerColumns.SelectedResources; DwarfBux selectedMoneyPlayer = PlayerColumns.TradeMoney; DwarfBux remainingMoneyPlayer = Player.Money - selectedMoneyPlayer; int maxIters = 1000; int iter = 0; while (!IsReasonableTrade(envoyOut, net) && iter < maxIters) { float t = MathFunctions.Rand(); if (envoyOut > net) { if (t < 0.05f && selectedMoneyEnvoy > 1) { DwarfBux movement = Math.Min((decimal)MathFunctions.RandInt(1, 5), selectedMoneyEnvoy); selectedMoneyEnvoy -= movement; remainingMoneyEnvoy += movement; } else if (t < 0.1f) { MoveRandomValue(selectedResourcesEnvoy, sourceResourcesEnvoy, Player); } else if (t < 0.15f && remainingMoneyPlayer > 1) { DwarfBux movement = Math.Min((decimal)MathFunctions.RandInt(1, Math.Max((int)(envoyOut - net), 2)), remainingMoneyPlayer); selectedMoneyPlayer += movement; remainingMoneyPlayer -= movement; } else { MoveRandomValue(sourceResourcesPlayer, selectedResourcesPlayer, Envoy); } } else { if (t < 0.05f && selectedMoneyPlayer > 1) { DwarfBux movement = Math.Min((decimal)MathFunctions.RandInt(1, 5), selectedMoneyPlayer); selectedMoneyPlayer -= movement; remainingMoneyPlayer += movement; } else if (t < 0.1f) { MoveRandomValue(selectedResourcesPlayer, sourceResourcesPlayer, Envoy); } else if (t < 0.15f && remainingMoneyEnvoy > 1) { DwarfBux movement = Math.Min((decimal)MathFunctions.RandInt(1, Math.Max((int)(net - envoyOut), 2)), remainingMoneyEnvoy); selectedMoneyEnvoy += movement; remainingMoneyEnvoy -= movement; } else { MoveRandomValue(selectedResourcesEnvoy, sourceResourcesEnvoy, Player); } } envoyOut = Envoy.ComputeValue(selectedResourcesEnvoy) + selectedMoneyEnvoy; tradeTarget = envoyOut * 0.25; net = ComputeNetValue(selectedResourcesPlayer, selectedMoneyPlayer, selectedResourcesEnvoy, selectedMoneyEnvoy); } if (IsReasonableTrade(envoyOut, net)) { Root.ShowTooltip(Root.MousePosition, "How does this work?"); PlayerColumns.Reconstruct(sourceResourcesPlayer, selectedResourcesPlayer, (int)selectedMoneyPlayer); PlayerColumns.TradeMoney = (int)selectedMoneyPlayer; EnvoyColumns.Reconstruct(sourceResourcesEnvoy, selectedResourcesEnvoy, (int)selectedMoneyEnvoy); EnvoyColumns.TradeMoney = (int)selectedMoneyEnvoy; Layout(); return; } else { Root.ShowTooltip(Root.MousePosition, "We don't see how this could work."); return; } } }