private bool IsReasonableTrade(DwarfBux envoyOut, DwarfBux net) { var tradeMin = envoyOut * 0.25; var tradeMax = envoyOut * 3.0; return(net >= tradeMin && net <= tradeMax && Math.Abs(net) > 1); }
public void EndGame() { State = Status.Ended; if (Participants.Count > 0 && Pot > 0.0m) { Participants[0].World.LogEvent(String.Format("Dice: {0} dwarfs split a pot of {1}", Participants.Count, Pot)); DwarfBux potDistribution = Pot / (decimal)Participants.Count; foreach (var participant in Participants) { participant.Status.Money += potDistribution; IndicatorManager.DrawIndicator((potDistribution).ToString(), participant.AI.Position + Microsoft.Xna.Framework.Vector3.Up + Microsoft.Xna.Framework.Vector3.Forward * 0.1f, 10.0f, GameSettings.Default.Colors.GetColor("Positive", Microsoft.Xna.Framework.Color.Green)); } Pot = 0.0m; } if (PotFixture != null) { PotFixture.Delete(); PotFixture = null; } }
private void CalculateTradeAmount(out DwarfBux net, out DwarfBux tradeTarget) { net = (Envoy.ComputeValue(PlayerColumns.SelectedResources) + PlayerColumns.TradeMoney) - (Envoy.ComputeValue(EnvoyColumns.SelectedResources) + EnvoyColumns.TradeMoney); var envoyOut = Envoy.ComputeValue(EnvoyColumns.SelectedResources) + EnvoyColumns.TradeMoney; tradeTarget = 1.0m; }
private bool IsReasonableTrade(DwarfBux envoyOut, DwarfBux net) { if (Envoy.TraderFaction.ParentFaction.IsCorporate) { return(true); // Trades with Corporate always succeed. } var tradeMin = envoyOut * 0.25; var tradeMax = envoyOut * 3.0; return(net >= tradeMin && net <= tradeMax && Math.Abs(net) > 1); }
public void Eat(DateTime time) { bool outOfFood = false; foreach (var creature in Party) { var resource = Resources.FirstOrDefault(r => r.NumResources > 0 && ResourceLibrary.GetResourceByName(r.ResourceType).Tags.Contains(Resource.ResourceTags.Edible)); if (resource != null) { resource.NumResources--; } else if (MathFunctions.RandEvent(0.5f)) { outOfFood = true; creature.Creature.Hp -= MathFunctions.Rand(1, 10); var thoughts = creature.Creature.GetComponent <DwarfThoughts>(); if (thoughts != null) { thoughts.AddThought(Thought.ThoughtType.FeltHungry); } } } var numDied = Party.Count(p => p.Creature.Hp <= 0); foreach (var creature in Party.Where(p => p.Creature.Hp <= 0)) { creature.Delete(); } if (outOfFood) { if (numDied == 0) { LastEvent = "The adventuring party ran out of food!"; } else { LastEvent = String.Format("The adventuring party ran out of food! {0} starved to death.", numDied); } } Party.RemoveAll(p => p.Creature.Hp <= 0); if (Party.Count == 0) { AdventureState = State.Done; LastEvent = "All of the members of the adventuring party starved to death."; Resources.Clear(); Money = 0; } HourOfLastEating = time.Hour; }
public override void OnGameEvent(WorldManager World, GameEvent Event) { if (State == GoalState.Complete) { return; } var trade = Event as Events.Trade; if (trade != null && trade.OtherFaction.Name == "Ordu") { Gold += trade.PlayerGold - trade.OtherGold; if (Gold >= 500) { State = GoalState.Complete; World.MakeAnnouncement("Goal met. You have traded 500 gold to Uzzikal."); World.GoalManager.UnlockGoal(typeof(Ordu_Elf_Envoy)); } } }
public void AddMoney(DwarfBux Money) { SourceEnvoy.TradeMoney += Money; }
public void SetTradeItems(List <ResourceAmount> leftResources, List <ResourceAmount> rightResources, DwarfBux leftMoney, DwarfBux rightMoney) { Update(); LeftItems.Clear(); RightItems.Clear(); var left = GetTopResources(leftResources).ToList(); int leftCount = left.Count + (leftMoney > 0.0m ? 1 : 0); int k = 0; foreach (var resource in left) { var resourceType = ResourceLibrary.GetResourceByName(resource.ResourceType); LeftItems.AddChild(new ResourceIcon() { Layers = resourceType.GuiLayers, MinimumSize = new Point(32, 32), MaximumSize = new Point(32, 32), Rect = new Rectangle(LeftWidget.Rect.X + 16 + k * 4 - leftCount * 2, LeftWidget.Rect.Y + 5, 32, 32) }); k++; } if (leftMoney > 0.0m) { LeftItems.AddChild(new Widget() { Background = new TileReference("coins", 1), MinimumSize = new Point(32, 32), MaximumSize = new Point(32, 32), Rect = new Rectangle(LeftWidget.Rect.X + 16 + k * 4 - leftCount * 2, LeftWidget.Rect.Y + 5, 32, 32) }); } var right = GetTopResources(rightResources).ToList(); int rightCount = right.Count + (rightMoney > 0.0m ? 1 : 0); k = 0; foreach (var resource in GetTopResources(rightResources)) { var resourceType = ResourceLibrary.GetResourceByName(resource.ResourceType); RightItems.AddChild(new ResourceIcon() { Layers = resourceType.GuiLayers, MinimumSize = new Point(32, 32), MaximumSize = new Point(32, 32), Rect = new Rectangle(RightWidget.Rect.X + 16 + k * 4 - rightCount * 2, RightWidget.Rect.Y + 5, 32, 32) }); k++; } if (rightMoney > 0.0m) { RightItems.AddChild(new Widget() { Background = new TileReference("coins", 1), MinimumSize = new Point(32, 32), MaximumSize = new Point(32, 32), Rect = new Rectangle(RightWidget.Rect.X + 16 + k * 4 - rightCount * 2, RightWidget.Rect.Y + 5, 32, 32) }); } LeftItems.Invalidate(); RightItems.Invalidate(); }
private void EqualizeColumns() { if (EnvoyColumns.Valid && PlayerColumns.Valid) { var net = ComputeNetValue(); var envoyOut = Envoy.ComputeValue(EnvoyColumns.SelectedResources) + EnvoyColumns.TradeMoney; var tradeTarget = 1.0m; 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; } } }
private DwarfBux ComputeNetValue(List <ResourceAmount> playerResources, DwarfBux playerTradeMoney, List <ResourceAmount> envoyResources, DwarfBux envoyMoney) { return((Envoy.ComputeValue(playerResources) + playerTradeMoney) - (Envoy.ComputeValue(envoyResources) + envoyMoney)); }
public void AddMoney(DwarfBux Money) { }
public void AddMoney(DwarfBux Money) { Faction.AddMoney(Money); }
public void AddMoney(DwarfBux Money) { World.Overworld.PlayerCorporationFunds += Money; }
public override void OnAction(WorldManager world) { var owner = world.Factions.Factions[OwnerFaction]; var dest = world.Factions.Factions[DestinationFaction]; var strength = Party.Sum(p => p.Stats.BuffedStr); var politics = world.Diplomacy.GetPolitics(owner, dest); List <ResourceAmount> destGoods = dest.Race.GenerateResources(world); int turns = MathFunctions.RandInt(1, (int)strength); List <ResourceAmount> stolenGoods = new List <ResourceAmount>(); DwarfBux stolenMoney = 0.0m; int numDead = 0; for (int turn = 0; turn < turns; turn++) { numDead += Party.Count(p => p.Creature.Hp <= 0); Party.RemoveAll(p => p.Creature.Hp <= 0); if (Party.Count == 0) { break; } var randomCritter = Datastructures.SelectRandom(Party); var con = randomCritter.Stats.BuffedCon; var enemyAttack = MathFunctions.RandInt(1, 20); if (enemyAttack - con > 10 || enemyAttack == 20) { randomCritter.Creature.Hp -= MathFunctions.RandInt(5, 100); if (randomCritter.Creature.Hp <= 0) { randomCritter.GetRoot().Delete(); } var thoughts = randomCritter.Creature.GetComponent <DwarfThoughts>(); if (thoughts != null) { thoughts.AddThought(Thought.ThoughtType.TookDamage); } } else { stolenGoods.Add(new ResourceAmount(Datastructures.SelectRandom(destGoods).ResourceType, MathFunctions.RandInt(1, 5))); stolenMoney += (DwarfBux)(decimal)MathFunctions.RandInt(1, 100); } } politics.RecentEvents.Add(new Diplomacy.PoliticalEvent() { Change = -5, Description = "You attacked us!", Duration = new TimeSpan(5, 0, 0, 0, 0), Time = world.Time.CurrentDate }); politics.WasAtWar = true; politics.HasMet = true; if (Party.Count == 0) { LastEvent = "All of the raiding party members died!"; Resources.Clear(); Money = 0.0m; AdventureState = State.Done; return; } Resources.AddRange(stolenGoods); Money += stolenMoney; if (numDead == 0) { LastEvent = String.Format("The raiding party is returning home unscathed! They stole {0} goods and {1}.", stolenGoods.Sum(g => g.NumResources), stolenMoney); AdventureState = State.ComingBack; } else { LastEvent = String.Format("The raiding party is returning home. They stole {0} goods and {1}, but {2} member(s) died.", stolenGoods.Sum(g => g.NumResources), stolenMoney, numDead); AdventureState = State.ComingBack; } foreach (var creature in Party) { var thoughts = creature.Creature.GetComponent <DwarfThoughts>(); if (thoughts != null) { thoughts.AddThought(Thought.ThoughtType.KilledThing); } } base.OnAction(world); }
public void AddMoney(DwarfBux Money) { AvailableMoney += Money; }
public void NextRound() { RoundTimer.Reset(); int countBefore = Participants.Count; Participants.RemoveAll(creature => creature == null || creature.IsDead || creature.Status.Money < 10.0m || creature.Physics.IsInLiquid); int countAfter = Participants.Count; if (countAfter > 0 && countAfter < countBefore) { Participants[0].World.LogEvent(String.Format("Dice: {0} player(s) left the game.", countBefore - countAfter)); } if (Participants.Count < 2) { EndGame(); return; } foreach (var participant in Participants) { var money = participant.Status.Money; var bet = (decimal)(int)(MathFunctions.Rand(0.1f, 0.25f) * money); Pot += (DwarfBux)bet; participant.Status.Money -= (DwarfBux)bet; IndicatorManager.DrawIndicator((-(DwarfBux)bet).ToString(), participant.AI.Position + Microsoft.Xna.Framework.Vector3.Up, 4.0f, GameSettings.Default.Colors.GetColor("Negative", Microsoft.Xna.Framework.Color.Red)); } Participants[0].World.LogEvent(String.Format("Dice: Entering round {0}/{1}. The Pot is {2}.", CurrentRound, MaxRounds, Pot.ToString())); List <Creature> winners = new List <Creature>(); List <int> rolls = new List <int>(); int maxRoll = 0; foreach (var participant in Participants) { Microsoft.Xna.Framework.Vector3 vel = (participant.AI.Position - Location) + MathFunctions.RandVector3Cube() * 0.5f; vel.Normalize(); vel *= 5; vel += Microsoft.Xna.Framework.Vector3.Up * 1.5f; participant.World.ParticleManager.Create("dice", participant.AI.Position, -vel, Microsoft.Xna.Framework.Color.White); int roll = MathFunctions.RandInt(1, 7); rolls.Add(roll); if (roll >= maxRoll) { maxRoll = roll; } } for (int k = 0; k < rolls.Count; k++) { if (rolls[k] >= maxRoll) { winners.Add(Participants[k]); } } if (winners.Count == 1) { var maxParticipant = winners[0]; maxParticipant.Status.Money += Pot; winners[0].World.LogEvent(String.Format("{0} won {1} at dice.", maxParticipant.Stats.FullName, Pot)); maxParticipant.NoiseMaker.MakeNoise("Pleased", maxParticipant.AI.Position, true, 0.5f); IndicatorManager.DrawIndicator((Pot).ToString(), maxParticipant.AI.Position + Microsoft.Xna.Framework.Vector3.Up + Microsoft.Xna.Framework.Vector3.Forward * 0.1f, 10.0f, GameSettings.Default.Colors.GetColor("Positive", Microsoft.Xna.Framework.Color.Green)); Pot = 0.0m; maxParticipant.AddThought(Thought.ThoughtType.WonGambling); } else { Participants[0].World.LogEvent(String.Format("Nobody won this round of dice. The Pot is {0}.", Pot.ToString())); } if (PotFixture != null) { PotFixture.SetFullness((float)(decimal)(Pot / 500.0m)); } CurrentRound++; if (CurrentRound > MaxRounds) { CurrentRound = 1; EndGame(); } }
public override void Construct() { Border = "border-one"; Text = "Select Resources to Trade"; Font = "font16"; InteriorMargin = new Margin(32, 5, 5, 5); var existingResources = Faction.ListResources(); StayingResources = new List <ResourceAmount>(); foreach (var resource in existingResources) { StayingResources.Add(resource.Value); } var TradeEntity = new ExpeditionTradeEntity() { Faction = this.Faction, AvailableMoney = this.Faction.Economy.CurrentMoney, AvailableResources = StayingResources, Space = 9999 }; var container = AddChild(new Widget() { Rect = GetDrawableInterior().Interior(new Margin(64, 64, 32, 32)) }); ResourceColumns columns = container.AddChild(new ResourceColumns() { AutoLayout = AutoLayout.DockFill, TradeEntity = TradeEntity, ValueSourceEntity = TradeEntity, LeftHeader = "In Stockpiles", RightHeader = "With Expedition", MoneyLabel = "Trade Money" }) as ResourceColumns; columns.Reconstruct(StayingResources, new List <ResourceAmount>(), (int)Faction.Economy.CurrentMoney); AddChild(new Button() { Text = "Cancel", Tooltip = "Go back to the factions view.", AutoLayout = AutoLayout.FloatBottomLeft, OnClick = (sender, args) => { if (OnCanceled != null) { OnCanceled.Invoke(); } Close(); } }); AddChild(new Button() { Text = "Send Expedition", Tooltip = "The expedition will begin immediately!", AutoLayout = AutoLayout.FloatBottomRight, OnClick = (sender, args) => { SelectedResources = columns.SelectedResources; SelectedMoney = columns.TradeMoney; if (OnProceed != null) { OnProceed.Invoke(this); } Close(); } }); Layout(); base.Construct(); }
public Company(Faction OwnerFaction, DwarfBux StartupFunds, CompanyInformation CompanyInformation) { Funds = StartupFunds; Faction = OwnerFaction; Information = CompanyInformation; }