public override IEnumerable <Status> Run() { Creature.IsCloaked = false; Timer waitTimer = new Timer(1.0f, true); if (Agent.Faction.Economy.Funds < Money) { Agent.SetTaskFailureReason("Failed to remove money from zone."); yield return(Status.Fail); } else { Agent.AddMoney(Money); Agent.Faction.Economy.Funds -= Money; Money = 0; var component = EntityFactory.CreateEntity <GameComponent>("Coins", Agent.Physics.Position + new Microsoft.Xna.Framework.Vector3(0.0f, 2.0f, 0.0f)); var toss = new TossMotion(1.0f, 2.5f, component.LocalTransform, Agent.Physics.Position); component.AnimationQueue.Add(toss); toss.OnComplete += component.Die; Agent.Creature.Sprite.ResetAnimations(Creature.Stats.CurrentClass.AttackMode); while (!waitTimer.HasTriggered) { Agent.Creature.CurrentCharacterMode = Creature.Stats.CurrentClass.AttackMode; waitTimer.Update(DwarfTime.LastTime); yield return(Status.Running); } Agent.Creature.CurrentCharacterMode = CharacterMode.Idle; yield return(Status.Success); } }
public bool AddMoney(Vector3 dwarfPos, DwarfBux money, ref DwarfBux moneyPut) { DwarfBux totalMoney = MoneyPerPile * Voxels.Count; DwarfBux moneyToPut = money; if (Money + money > totalMoney) { DwarfBux remainder = totalMoney - Money; if (remainder <= 0) { moneyPut = 0; return(false); } moneyToPut = remainder; } Vector3 targetToss = Coins.Count == 0 ? Voxels[0].WorldPosition + new Vector3(0.5f, 0.5f, 0.5f) : Coins[Coins.Count - 1].LocalTransform.Translation + new Vector3(0.5f, 0.5f, 0.5f); Body component = EntityFactory.CreateEntity <Body>("Coins", dwarfPos); component.UpdateRate = 1; TossMotion toss = new TossMotion(1.0f, 2.5f, component.LocalTransform, targetToss); component.AnimationQueue.Add(toss); toss.OnComplete += component.Die; Money += moneyToPut; Faction.Economy.CurrentMoney += moneyToPut; moneyPut = moneyToPut; return(moneyPut >= money); }
public override IEnumerable <Status> Run() { Creature.IsCloaked = false; if (Zone == null) { Agent.SetMessage("Failed to stash money. Null zone."); yield return(Act.Status.Fail); yield break; } Timer waitTimer = new Timer(1.0f, true); DwarfBux moneyRemoved = Math.Min(Money, Zone.Money); bool removed = Zone.RemoveMoney(Agent.Position, moneyRemoved); if (!removed) { Agent.SetMessage("Failed to remove money from zone."); yield return(Status.Fail); } else { Agent.AddMoney(Money); Money -= moneyRemoved; Agent.Creature.Sprite.ResetAnimations(Creature.AttackMode); while (!waitTimer.HasTriggered) { Agent.Creature.CurrentCharacterMode = Creature.AttackMode; waitTimer.Update(DwarfTime.LastTime); yield return(Status.Running); } Agent.Creature.CurrentCharacterMode = CharacterMode.Idle; yield return(Status.Success); } }
public Economy(Faction faction, DwarfBux currentMoney, WorldManager worldManager, CompanyInformation CompanyInformation) { this.WorldManager = worldManager; Company = Company.GenerateRandom(currentMoney, 1.0m, Company.Sector.Exploration); Company.Information = CompanyInformation; Company.Assets = currentMoney; CurrentMoney = currentMoney; Faction = faction; Market = new List <Company> { Company, Company.GenerateRandom(1000m, 1.0m, Company.Sector.Exploration), Company.GenerateRandom(1200m, 5.0m, Company.Sector.Exploration), Company.GenerateRandom(1500m, 10.0m, Company.Sector.Exploration), Company.GenerateRandom(1300m, 10.0m, Company.Sector.Manufacturing), Company.GenerateRandom(1200m, 10.0m, Company.Sector.Manufacturing), Company.GenerateRandom(1500m, 15.0m, Company.Sector.Military), Company.GenerateRandom(1300m, 10.0m, Company.Sector.Military), Company.GenerateRandom(1200m, 15.0m, Company.Sector.Military), Company.GenerateRandom(1500m, 25.0m, Company.Sector.Magic), Company.GenerateRandom(1200m, 30.0m, Company.Sector.Magic), Company.GenerateRandom(1300m, 40.0m, Company.Sector.Magic), Company.GenerateRandom(1500m, 50.0m, Company.Sector.Finance), Company.GenerateRandom(1800m, 60.0m, Company.Sector.Finance) }; if (worldManager != null) { WorldManager.Time.NewDay += Time_NewDay; } }
public Resource(Resource other) { Name = other.Name; ShortName = other.ShortName; MoneyValue = other.MoneyValue; Description = new string(other.Description.ToCharArray()); GuiLayers = new List <TileReference>(); GuiLayers.AddRange(other.GuiLayers); Tint = other.Tint; Tags = new List <ResourceTags>(); Tags.AddRange(other.Tags); FoodContent = other.FoodContent; ShortName = other.ShortName; PlantToGenerate = other.PlantToGenerate; CanCraft = other.CanCraft; CraftPrerequisites = new List <Quantitiy <Resource.ResourceTags> >(); CraftPrerequisites.AddRange(other.CraftPrerequisites); CraftInfo = other.CraftInfo; Generated = true; if (other.CompositeLayers != null) { CompositeLayers = new List <CompositeLayer>(); CompositeLayers.AddRange(other.CompositeLayers); } else { CompositeLayers = null; } TrinketData = other.TrinketData; AleName = other.AleName; }
public void HandleCoins() { if (Voxels == null || Coins == null) { return; } if (Voxels.Count == 0) { foreach (Body component in Coins) { KillCoins(component); } Coins.Clear(); } int numCoins = (int)Math.Ceiling(Math.Min(Math.Max((float)(decimal)Money / (float)(decimal)MoneyPerPile, 1.0f), (float)Voxels.Count)); if (Money == 0m) { numCoins = 0; } if (Coins.Count > numCoins) { for (int i = Coins.Count - 1; i >= numCoins; i--) { KillCoins(Coins[i]); Coins.RemoveAt(i); } } else if (Coins.Count < numCoins) { for (int i = Coins.Count; i < numCoins; i++) { CreateCoins(Voxels[i].WorldPosition + VertexNoise.GetNoiseVectorFromRepeatingTexture(Voxels[i].WorldPosition)); } } for (int i = 0; i < Coins.Count - 1; i++) { var fixture = Coins[i].GetRoot().GetComponent <CoinPileFixture>(); fixture.SetFullness(1.0f); fixture.Name = MoneyPerPile.ToString(); } DwarfBux remainder = Money - (Coins.Count - 1) * MoneyPerPile; if (Coins.Count > 0) { var fixture = Coins.Last().GetRoot().GetComponent <CoinPileFixture>(); fixture.SetFullness((float)(decimal)remainder / (float)(decimal)MoneyPerPile); fixture.Name = remainder.ToString(); } if (IsFull() && Faction.Treasurys.Count(t => !t.IsFull()) == 0 && Voxels.Count > 0) { Faction.World.MakeAnnouncement("Our treasury is full! Build more treasuries to store more money."); } }
public StockMoneyAct(CreatureAI agent, DwarfBux money) : base(agent) { Tree = null; Name = "Stock money"; Money = money; }
public Treasury(Faction faction, bool designation, IEnumerable <VoxelHandle> designations, RoomData data, WorldManager world) : base(designation, designations, data, world, faction) { Coins = new List <Body>(); Money = 0; faction.Treasurys.Add(this); Faction = faction; }
public PutMoneyInZoneAct(CreatureAI agent, string stockpileName, string voxelname, DwarfBux money) : base(agent) { Money = money; VoxelName = voxelname; Name = "Stash money in zone"; StockpileName = stockpileName; }
/// <summary> Pay the creature this amount of money. The money goes into the creature's wallet. </summary> public void AddMoney(DwarfBux pay) { Stats.Money += pay; bool good = pay > 0; Color textColor = good ? GameSettings.Default.Colors.GetColor("Positive", Color.Green) : GameSettings.Default.Colors.GetColor("Negative", Color.Red); string prefix = good ? "+" : ""; IndicatorManager.DrawIndicator(prefix + pay, Position + Vector3.Up + MathFunctions.RandVector3Cube() * 0.5f, 1.0f, textColor); }
public void AddMoney(DwarfBux money) { if (money == 0.0m) { return; } // In this case, we need to remove money from the economy. // This means that we first take money from treasuries. If there is any left, // we subtract it from the current money count. if (money < 0) { DwarfBux amountLeft = -money; foreach (Treasury treasury in Treasurys) { DwarfBux amountToTake = System.Math.Min(treasury.Money, amountLeft); treasury.Money -= amountToTake; amountLeft -= amountToTake; } return; } DwarfBux amountRemaining = money; foreach (Treasury treasury in Treasurys) { if (amountRemaining <= 0) { break; } DwarfBux maxInTreasury = treasury.Voxels.Count * Treasury.MoneyPerPile - treasury.Money; DwarfBux amountToTake = System.Math.Min(maxInTreasury, amountRemaining); amountRemaining -= amountToTake; treasury.Money += amountToTake; } if (amountRemaining > 0 && RoomBuilder.DesignatedRooms.Count > 0) { World.MakeAnnouncement("We need more treasuries!"); // Generate a number of coin piles. for (DwarfBux total = 0m; total < amountRemaining; total += 1024m) { Zone randomZone = Datastructures.SelectRandom(RoomBuilder.DesignatedRooms); Vector3 point = MathFunctions.RandVector3Box(randomZone.GetBoundingBox()) + new Vector3(0, 1.0f, 0); CoinPile pile = EntityFactory.CreateEntity <CoinPile>("Coins Resource", point); pile.Money = 1024m; // Special case where we just need to add a little bit of money (less than 64 coins) if (money - total < 1024m) { pile.Money = money - total; } } } }
public void AddMoney(DwarfBux money) { if (money == 0.0m) { return; } Economy.Funds += money; }
public CreatureStatus() { Money = 0; IsAsleep = false; IsOnStrike = false; Statuses = new Dictionary <string, Status>(); Hunger = new Status { MaxValue = 100.0f, MinValue = 0.0f, Name = "Hunger", SatisfiedThreshold = 95.0f, DissatisfiedThreshold = 15.0f, CurrentValue = 100.0f }; Energy = new Status { MaxValue = 100.0f, MinValue = 0.0f, Name = "Energy", SatisfiedThreshold = 99.0f, DissatisfiedThreshold = 15.0f, CurrentValue = 100.0f }; Happiness = new Status { MaxValue = 100.0f, MinValue = 0.0f, Name = "Happiness", SatisfiedThreshold = 49.0f, DissatisfiedThreshold = 20.0f, CurrentValue = 50.0f }; Boredom = new Status { MaxValue = 35.0f, MinValue = 0.0f, Name = "Boredom", SatisfiedThreshold = 20.0f, DissatisfiedThreshold = 15.0f, CurrentValue = 30.0f }; Health = new Status { MaxValue = 1.0f, MinValue = 0.0f, Name = "Health", SatisfiedThreshold = 0.8f, DissatisfiedThreshold = 0.15f, CurrentValue = 1.0f }; }
public static List <DwarfBux> GenerateRandomStockHistory(DwarfBux current, int length) { List <DwarfBux> history = new List <DwarfBux>(); DwarfBux startPrice = current + (float)MathFunctions.Random.NextDouble() * current * 0.5f - current * 0.5f; double slope = (double)((current - startPrice).Value) / (double)length; for (int i = 0; i < length - 1; i++) { history.Add((decimal)(MathFunctions.Random.NextDouble() * 0.5 + slope * i + (double)startPrice.Value)); } history.Add(current); return(history); }
public override IEnumerable <Status> Run() { if (Zone == null) { Creature.DrawIndicator(IndicatorManager.StandardIndicators.Question); yield return(Status.Fail); yield break; } if (Money <= 0) { yield return(Status.Success); yield break; } DwarfBux moneyPut = 0m; if (Zone.AddMoney(Creature.AI.Position, Money, ref moneyPut)) { Creature.AI.AddMoney(-Money); Creature.NoiseMaker.MakeNoise("Stockpile", Creature.AI.Position); Creature.Stats.NumItemsGathered++; Creature.AI.AddXP(1); Creature.CurrentCharacterMode = CharacterMode.Attacking; Creature.Sprite.ResetAnimations(CharacterMode.Attacking); Creature.Sprite.PlayAnimations(CharacterMode.Attacking); while (!Creature.Sprite.AnimPlayer.IsDone()) { yield return(Status.Running); } yield return(Status.Running); } else { Creature.DrawIndicator(IndicatorManager.StandardIndicators.Question); Creature.CurrentCharacterMode = CharacterMode.Idle; Creature.AI.GatherManager.StockMoneyOrders.Add(new GatherManager.StockMoneyOrder() { Destination = null, Money = Money - moneyPut }); yield return(Status.Fail); } Creature.CurrentCharacterMode = CharacterMode.Idle; yield return(Status.Success); }
public GetMoneyAct(CreatureAI agent, DwarfBux money, Faction faction = null) : base(agent) { Name = "Get paid " + money.ToString(); Money = money; if (faction == null) { Faction = Creature.Faction; } else { Faction = faction; } }
public static Resource GetLeastValuableWithTag(Resource.ResourceTags tag) { Resource min = null; DwarfBux minValue = decimal.MaxValue; foreach (var r in Resources.Values.Where(resource => resource.Tags.Contains(tag))) { if (r.MoneyValue < minValue) { minValue = r.MoneyValue; min = r; } } return(min); }
public void PayEmployees() { DwarfBux total = 0; bool noMoney = false; foreach (CreatureAI creature in PlayerFaction.Minions) { if (creature.Stats.IsOverQualified) { creature.Creature.AddThought("I am overqualified for this job.", new TimeSpan(1, 0, 0, 0), -10.0f); } var thoughts = creature.Physics.GetComponent <DwarfThoughts>(); if (thoughts != null) { thoughts.Thoughts.RemoveAll(thought => thought.Description.Contains("paid")); } DwarfBux pay = creature.Stats.CurrentLevel.Pay; total += pay; if (total >= PlayerFaction.Economy.Funds) { if (!noMoney) { MakeAnnouncement("We have no money!"); Tutorial("money"); SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_negative_generic, 0.5f); } noMoney = true; } else { creature.Creature.AddThought("I got paid recently.", new TimeSpan(1, 0, 0, 0), 10.0f); } creature.AssignTask(new ActWrapperTask(new GetMoneyAct(creature, pay)) { AutoRetry = true, Name = "Get paid.", Priority = TaskPriority.High }); } MakeAnnouncement(String.Format("We paid our employees {0} today.", total)); SoundManager.PlaySound(ContentPaths.Audio.change, 0.15f); Tutorial("pay"); }
// Todo: Why exactly is Faction.Minions a list of CreatureAI and not a list of Creature? public void PayEmployees() { DwarfBux total = 0; bool noMoney = false; foreach (CreatureAI creature in Faction.Minions) { if (creature.Stats.IsOverQualified) { creature.Creature.AddThought(Thought.ThoughtType.IsOverQualified); } if (!noMoney) { DwarfBux pay = creature.Stats.CurrentLevel.Pay; total += pay; creature.AssignTask(new ActWrapperTask(new GetMoneyAct(creature, pay)) { AutoRetry = true, Name = "Get paid.", Priority = Task.PriorityType.High }); } else { creature.Creature.AddThought(Thought.ThoughtType.NotPaid); } if (total >= Faction.Economy.CurrentMoney) { if (!noMoney) { World.MakeAnnouncement("We have no money!"); World.Tutorial("money"); SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_negative_generic, 0.5f); } noMoney = true; } else { creature.Creature.AddThought(Thought.ThoughtType.GotPaid); } } World.MakeAnnouncement(String.Format("We paid our employees {0} today.", total)); SoundManager.PlaySound(ContentPaths.Audio.change, 0.15f); World.Tutorial("pay"); }
public Resource(ResourceLibrary.ResourceType type, DwarfBux money, string description, NamedImageFrame image, int WidgetsSprite, Color tint, params ResourceTags[] tags) { Type = type; MoneyValue = money; Description = description; Image = image; this.GuiLayers = new List <TileReference>(); GuiLayers.Add(new TileReference("resources", WidgetsSprite)); Tint = tint; Tags = new List <ResourceTags>(); Tags.AddRange(tags); FoodContent = 0; CanCraft = false; CraftPrereqs = new List <Quantitiy <Resource.ResourceTags> >(); CompositeLayers = null; AleName = ""; }
public override void Destroy() { DwarfBux moneyLeft = Money; foreach (Body coinPile in Coins) { CoinPile coins = EntityFactory.CreateEntity <CoinPile>("Coins Resource", coinPile.Position); coins.Money = Math.Min(MoneyPerPile, moneyLeft); moneyLeft -= coins.Money; } Faction.Economy.CurrentMoney -= Money; if (Faction != null) { Faction.Treasurys.Remove(this); } base.Destroy(); }
public static Company GenerateRandom(DwarfBux assets, DwarfBux stockPrice, Sector industry) { // Todo: Find out how random companies are actually used and reimplement logo generation. /* * Texture2D texture = TextureManager.GetTexture(ContentPaths.Logos.logos); * * int row = 0; * switch (industry) * { * case Sector.Magic: * row = 3; * break; * case Sector.Finance: * row = 3; * break; * case Sector.Exploration: * row = 0; * break; * case Sector.Manufacturing: * row = 1; * break; * case Sector.Military: * row = 2; * break; * } * NamedImageFrame image = new NamedImageFrame(ContentPaths.Logos.logos, 32, MathFunctions.Random.Next(0, texture.Width / 32), row); * * Color c = new Color(MathFunctions.Random.Next(0, 255), MathFunctions.Random.Next(0, 255), * MathFunctions.Random.Next(0, 255)); * */ return(new Company() { Assets = assets, //StockPrice = stockPrice, Industry = industry, Information = new CompanyInformation { Name = GenerateName(industry), Motto = GenerateMotto() }, StockHistory = GenerateRandomStockHistory(stockPrice, 10), LastAssets = assets }); }
public override IEnumerable <Status> Run() { if (Target == null) { yield return(Status.Fail); } if (Target is CoinPile) { DwarfBux money = (Target as CoinPile).Money; Creature.AI.AddMoney(money); Target.Die(); } else if (!Creature.Inventory.Pickup(Target, Inventory.RestockType.RestockResource)) { yield return(Status.Fail); } //if (Creature.Faction.Designations.IsDesignation(Target, DesignationType.Gather)) // Creature.Faction.Designations.RemoveEntityDesignation(Target, DesignationType.Gather); //else //{ // yield return Status.Fail; // break; //} if (Target is ResourceEntity resEnt) { var resource = resEnt.Resource; // Todo: This is disgusting. //var resource = new ResourceAmount(Target.Tags[0], 1); Agent.Blackboard.SetData(StashedItemOut, resource); Agent.Creature.NoiseMaker.MakeNoise("Stash", Agent.Position); yield return(Status.Success); } else { yield return(Status.Fail); } }
public bool RemoveMoney(Vector3 dwarfPos, DwarfBux money) { if (Money < money) { return(false); } Body lastCoins = Coins.LastOrDefault(); if (lastCoins == null) { return(false); } Body component = EntityFactory.CreateEntity <Body>("Coins", lastCoins.Position); TossMotion toss = new TossMotion(1.0f, 2.5f, component.LocalTransform, dwarfPos); component.AnimationQueue.Add(toss); toss.OnComplete += component.Die; Money -= money; Faction.Economy.CurrentMoney -= money; return(true); }
public bool CanAddMoney(DwarfBux toPut) { return(Money + toPut <= MoneyPerPile * Voxels.Count); }
public CollectPay(CreatureAI agent, DwarfBux money) : base(agent) { Money = money; Name = "Stash " + Money; }
public bool HasFreeTreasury(DwarfBux toPut) { return(Treasurys.Any(s => s.IsBuilt && !s.IsFull())); }
public StashMoneyAct(CreatureAI agent, DwarfBux money) : base(agent) { Money = money; Name = "Stash " + Money; }
public void SetMoney(DwarfBux value) { Agent.Blackboard.SetData(MoneyName, value); }
public override IEnumerable <Status> Run() { if (Target == null) { yield return(Status.Fail); } switch (PickType) { case (PickUpType.Room): case (PickUpType.Stockpile): { if (Zone == null) { yield return(Status.Fail); break; } bool removed = Zone.Resources.RemoveResource(new ResourceAmount(Target.Tags[0])); if (removed) { if (Creature.Inventory.Pickup(Target, Inventory.RestockType.RestockResource)) { Agent.Blackboard.SetData(StashedItemOut, new ResourceAmount(Target)); Agent.Creature.NoiseMaker.MakeNoise("Stash", Agent.Position); yield return(Status.Success); } else { yield return(Status.Fail); } } else { yield return(Status.Fail); } break; } case (PickUpType.None): { if (Target is CoinPile) { DwarfBux money = (Target as CoinPile).Money; Creature.AI.AddMoney(money); Target.Die(); } else if (!Creature.Inventory.Pickup(Target, Inventory.RestockType.RestockResource)) { yield return(Status.Fail); } //if (Creature.Faction.Designations.IsDesignation(Target, DesignationType.Gather)) // Creature.Faction.Designations.RemoveEntityDesignation(Target, DesignationType.Gather); //else //{ // yield return Status.Fail; // break; //} ResourceAmount resource = new ResourceAmount(Target); Agent.Blackboard.SetData(StashedItemOut, resource); Agent.Creature.NoiseMaker.MakeNoise("Stash", Agent.Position); yield return(Status.Success); break; } } }