public bool resolve() { FactionFC factionfc = Find.World.GetComponent <FactionFC>(); if (PaymentUtil.getSilver() >= -1 * taxes.silverAmount || taxes.silverAmount >= 0) { //if have enough silver on the current map to pay & map belongs to player FCEventMaker.createTaxEvent(this); if (taxes.researchCompleted != 0) { factionfc.researchPointPool += taxes.researchCompleted; Messages.Message("PointsAddedToResearchPool".Translate(taxes.researchCompleted), MessageTypeDefOf.PositiveEvent); } if (taxes.electricityAllotted != 0) { factionfc.powerPool += taxes.electricityAllotted; } return(true); } string messageString = "NotEnoughSilverForBill".Translate() + " " + settlement.name + ". " + "ConfiscatedTithes".Translate() + "." + " " + "UnpaidTitheEffect".Translate(); settlement.GainUnrestWithReason(new Message(messageString, MessageTypeDefOf.NegativeEvent), 10d); settlement.GainHappiness(-10d); factionfc.Bills.Remove(this); return(false); }
public bool resolve() { FactionFC factionfc = Find.World.GetComponent <FactionFC>(); if (PaymentUtil.getSilver() >= -1 * taxes.silverAmount || taxes.silverAmount >= 0) { //if have enough silver on the current map to pay & map belongs to player FCEventMaker.createTaxEvent(this); if (taxes.researchCompleted != 0) { factionfc.researchPointPool += taxes.researchCompleted; Messages.Message("PointsAddedToResearchPool".Translate(taxes.researchCompleted), MessageTypeDefOf.PositiveEvent); } if (taxes.electricityAllotted != 0) { factionfc.powerPool += taxes.electricityAllotted; } return(true); } Messages.Message("NotEnoughSilverForBill".Translate() + " " + settlement.name + ". " + "ConfiscatedTithes".Translate() + "." + " " + "UnpaidTitheEffect".Translate(), MessageTypeDefOf.NegativeEvent); settlement.unrest += 10 * TraitUtilsFC.cycleTraits(new double(), "unrestGainedMultiplier", settlement.traits, "multiply") * TraitUtilsFC.cycleTraits(new double(), "unrestGainedMultiplier", factionfc.traits, "multiply"); settlement.happiness -= 10 * TraitUtilsFC.cycleTraits(new double(), "happinessLostMultiplier", settlement.traits, "multiply") * TraitUtilsFC.cycleTraits(new double(), "happinessLostMultiplier", factionfc.traits, "multiply"); factionfc.Bills.Remove(this); return(false); }
public bool attemptResolve() { FactionFC factionfc = Find.World.GetComponent <FactionFC>(); if (PaymentUtil.getSilver() >= -1 * this.taxes.silverAmount || this.taxes.silverAmount >= 0) { //if have enough silver on the current map to pay & map belongs to player FCEventMaker.createTaxEvent(this); if (this.taxes.researchCompleted != 0) { factionfc.researchPointPool += this.taxes.researchCompleted; Messages.Message(TranslatorFormattedStringExtensions.Translate("PointsAddedToResearchPool", this.taxes.researchCompleted), MessageTypeDefOf.PositiveEvent); } if (this.taxes.electricityAllotted != 0) { factionfc.powerPool += this.taxes.electricityAllotted; } return(true); } else { return(false); } }
private void DrawCreateSettlementButton() { Text.Font = GameFont.Small; Text.Anchor = TextAnchor.MiddleCenter; int buttonLength = 130; if (Widgets.ButtonText(new Rect((InitialSize.x - 32 - buttonLength) / 2f, 535, buttonLength, 32), "Settle".Translate() + ": (" + settlementCreationCost + ")")) //add inital cost { if (!CanCreateSettlementHere()) { return; } PaymentUtil.paySilver(settlementCreationCost); //create settle event FCEvent evt = FCEventMaker.MakeEvent(FCEventDefOf.settleNewColony); evt.location = currentTileSelected; evt.planetName = Find.World.info.name; evt.timeTillTrigger = Find.TickManager.TicksGame + timeToTravel; evt.source = faction.capitalLocation; faction.addEvent(evt); faction.settlementCaravansList.Add(evt.location.ToString()); Messages.Message("CaravanSentToLocation".Translate() + " " + (evt.timeTillTrigger - Find.TickManager.TicksGame).ToTimeString() + "!", MessageTypeDefOf.PositiveEvent); DoPostEventCreationTraitThings(); } }
public static void calculateSuccess(FCOptionDef option, FCEvent parentEvent) { float baseChance = option.baseChanceOfSuccess; int roll = Rand.Range(1, 100); //Log.Message(roll.ToString()); FCEvent tempEvent = new FCEvent(true); if (roll <= baseChance) { //if success if (option.parentEvent.settlementsCarryOver == true) { tempEvent = FCEventMaker.MakeRandomEvent(option.successEvent, parentEvent.settlementTraitLocations); } else { tempEvent = FCEventMaker.MakeRandomEvent(option.successEvent, null); } } else { if (option.parentEvent.settlementsCarryOver == true) { tempEvent = FCEventMaker.MakeRandomEvent(option.failEvent, parentEvent.settlementTraitLocations); } else { tempEvent = FCEventMaker.MakeRandomEvent(option.failEvent, null); } } if (tempEvent.def != FCEventDefOf.Null) { Find.World.GetComponent <FactionFC>().addEvent(tempEvent); //letter string settlementString = ""; foreach (SettlementFC loc in tempEvent.settlementTraitLocations) { if (settlementString == "") { settlementString = settlementString + loc.name; } else { settlementString = settlementString + ", " + loc.name; } } if (settlementString != "") { Find.LetterStack.ReceiveLetter(tempEvent.def.label, tempEvent.def.desc + "\n This event is affecting the following settlements: " + settlementString, LetterDefOf.NeutralEvent); } else { Find.LetterStack.ReceiveLetter(tempEvent.def.label, tempEvent.def.desc, LetterDefOf.NeutralEvent); } } }
public override void DoWindowContents(Rect inRect) { //grab before anchor/font GameFont fontBefore = Text.Font; TextAnchor anchorBefore = Text.Anchor; //Settlement Tax Collection Header Text.Anchor = TextAnchor.MiddleLeft; Text.Font = GameFont.Medium; Widgets.DrawMenuSection(new Rect(0, 0, 544, 150)); Widgets.Label(new Rect(10, 0, 500, 60), header); Widgets.DrawLineHorizontal(0, 155, 544); Text.Anchor = TextAnchor.UpperLeft; Text.Font = GameFont.Tiny; Widgets.Label(new Rect(20, 60, 470, 90), desc); Text.Anchor = TextAnchor.MiddleLeft; Text.Font = GameFont.Tiny; for (int i = 0; i < options.Count(); i++) { if (Widgets.ButtonTextSubtle(new Rect(xoffset, yoffset + (i * (height + yspacing)), length, height), "")) { if (PaymentUtil.getSilver() >= options[i].silverCost) { PaymentUtil.paySilver(options[i].silverCost); FCEventMaker.calculateSuccess(options[i], parentEvent); //Log.Message(options[i].label); Find.WindowStack.TryRemove(this); } else { Messages.Message("You do not have enough silver on the map to pay for that option", MessageTypeDefOf.RejectInput); } } //label Widgets.Label(new Rect(xoffset + 5, yoffset + 5 + (i * (height + yspacing)), length - 10, height - 10), options[i].label); } //Widgets.DrawBox(new Rect(xoffset, yoffset - yspacing, length, height - yspacing * 2)); //reset anchor/font Text.Font = fontBefore; Text.Anchor = anchorBefore; }
public static void attackPlayerSettlement(militaryForce attackingForce, SettlementFC settlement, Faction enemyFaction) { FactionFC factionfc = Find.World.GetComponent <FactionFC>(); FCEvent tmp = FCEventMaker.MakeEvent(FCEventDefOf.settlementBeingAttacked); tmp.hasCustomDescription = true; tmp.timeTillTrigger = Find.TickManager.TicksGame + 60000; tmp.location = settlement.mapLocation; tmp.planetName = settlement.planetName; tmp.hasDestination = true; tmp.customDescription = "settlementAboutToBeAttacked" .Translate(settlement.name, enemyFaction.Name); tmp.militaryForceDefending = militaryForce.createMilitaryForceFromSettlement(settlement); tmp.militaryForceDefendingFaction = FactionColonies.getPlayerColonyFaction(); tmp.militaryForceAttacking = attackingForce; tmp.militaryForceAttackingFaction = enemyFaction; tmp.settlementFCDefending = settlement; SettlementFC highest = null; foreach (SettlementFC settlementCompare in factionfc.settlements) { if (settlementCompare.autoDefend && settlementCompare.militaryBusy == false && settlementCompare.settlementMilitaryLevel > settlement.settlementMilitaryLevel && (highest == null || settlementCompare.settlementMilitaryLevel > highest.settlementMilitaryLevel)) { highest = settlementCompare; } } if (highest != null) { changeDefendingMilitaryForce(tmp, highest); } settlement.worldSettlement.defenderForce = tmp.militaryForceDefending; settlement.worldSettlement.attackerForce = tmp.militaryForceAttacking; Find.World.GetComponent <FactionFC>().addEvent(tmp); tmp.customDescription += "\n\nThe estimated attacking force's power is: " + tmp.militaryForceAttacking.forceRemaining; settlement.isUnderAttack = true; Find.LetterStack.ReceiveLetter("settlementInDanger".Translate(), tmp.customDescription, LetterDefOf.ThreatBig, new LookTargets(Find.WorldObjects.WorldObjectAt <WorldSettlementFC>(settlement.mapLocation))); }
public static void attackPlayerSettlement(militaryForce attackingForce, SettlementFC settlement, Faction enemyFaction) { FCEvent tmp = FCEventMaker.MakeEvent(FCEventDefOf.settlementBeingAttacked); tmp.hasCustomDescription = true; tmp.timeTillTrigger = Find.TickManager.TicksGame + 60000; tmp.location = settlement.mapLocation; tmp.hasDestination = true; tmp.customDescription = TranslatorFormattedStringExtensions.Translate("settlementAboutToBeAttacked", settlement.name, enemyFaction.Name);// + tmp.militaryForceDefending = militaryForce.createMilitaryForceFromSettlement(settlement); tmp.militaryForceDefendingFaction = FactionColonies.getPlayerColonyFaction(); tmp.militaryForceAttacking = attackingForce; tmp.militaryForceAttackingFaction = enemyFaction; tmp.settlementFCDefending = settlement; Find.World.GetComponent <FactionFC>().addEvent(tmp); tmp.customDescription += "\n\nThe estimated attacking force's power is: " + tmp.militaryForceAttacking.forceRemaining; settlement.isUnderAttack = true; Find.LetterStack.ReceiveLetter("settlementInDanger".Translate(), tmp.customDescription, LetterDefOf.ThreatBig, new LookTargets(Find.WorldObjects.SettlementAt(settlement.mapLocation))); }
//Drawing public override void DoWindowContents(Rect inRect) { FactionFC faction = Find.World.GetComponent <FactionFC>(); faction.roadBuilder.displayPaths(); if (Find.WorldSelector.selectedTile != -1 && Find.WorldSelector.selectedTile != currentTileSelected) { currentTileSelected = Find.WorldSelector.selectedTile; //Log.Message("Current: " + currentTileSelected + ", Selected: " + Find.WorldSelector.selectedTile); currentBiomeSelected = DefDatabase <BiomeResourceDef> .GetNamed(Find.WorldGrid.tiles[currentTileSelected].biome.ToString(), false); //default biome if (currentBiomeSelected == default(BiomeResourceDef)) { //Log Modded Biome currentBiomeSelected = BiomeResourceDefOf.defaultBiome; } currentHillinessSelected = DefDatabase <BiomeResourceDef> .GetNamed(Find.WorldGrid.tiles[currentTileSelected].hilliness.ToString()); if (currentBiomeSelected.canSettle == true && currentHillinessSelected.canSettle == true && currentTileSelected != 1) { timeToTravel = FactionColonies.ReturnTicksToArrive(Find.World.GetComponent <FactionFC>().capitalLocation, currentTileSelected); } else { timeToTravel = 0; } } //grab before anchor/font GameFont fontBefore = Text.Font; TextAnchor anchorBefore = Text.Anchor; int silverToCreateSettlement = (int)(traitUtilsFC.cycleTraits(new double(), "createSettlementMultiplier", Find.World.GetComponent <FactionFC>().traits, "multiply") * (FactionColonies.silverToCreateSettlement + (500 * (Find.World.GetComponent <FactionFC>().settlements.Count() + Find.World.GetComponent <FactionFC>().settlementCaravansList.Count())) + (traitUtilsFC.cycleTraits(new double(), "createSettlementBaseCost", Find.World.GetComponent <FactionFC>().traits, "add")))); //Draw Label Text.Font = GameFont.Medium; Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(new Rect(0, 0, 268, 40), "SettleANewColony".Translate()); //hori line Widgets.DrawLineHorizontal(0, 40, 300); //Upper menu Widgets.DrawMenuSection(new Rect(5, 45, 258, 220)); DrawLabelBox(10, 50, 100, 100, "TravelTime".Translate(), GenDate.ToStringTicksToDays(timeToTravel)); DrawLabelBox(153, 50, 100, 100, "InitialCost".Translate(), silverToCreateSettlement + " " + "Silver".Translate()); //Lower Menu label Text.Font = GameFont.Medium; Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(new Rect(0, 270, 268, 40), "BaseProductionStats".Translate()); //Lower menu Widgets.DrawMenuSection(new Rect(5, 310, 258, 220)); //Draw production Text.Font = GameFont.Small; Text.Anchor = TextAnchor.MiddleCenter; //Production headers Widgets.Label(new Rect(40, 310, 60, 25), "Base".Translate()); Widgets.Label(new Rect(110, 310, 60, 25), "Modifier".Translate()); Widgets.Label(new Rect(180, 310, 60, 25), "Final".Translate()); if (currentTileSelected != -1) { for (int i = 0; i < Find.World.GetComponent <FactionFC>().returnNumberResource(); i++) { int height = 15; if (Widgets.ButtonImage(new Rect(20, 335 + i * (5 + height), height, height), faction.returnResourceByInt(i).getIcon())) { Find.WindowStack.Add(new descWindowFC("SettlementProductionOf".Translate() + ": " + faction.returnResourceByInt(i).label, char.ToUpper(faction.returnResourceByInt(i).label[0]) + faction.returnResourceByInt(i).label.Substring(1))); } Widgets.Label(new Rect(40, 335 + i * (5 + height), 60, height + 2), (currentBiomeSelected.BaseProductionAdditive[i] + currentHillinessSelected.BaseProductionAdditive[i]).ToString()); Widgets.Label(new Rect(110, 335 + i * (5 + height), 60, height + 2), (currentBiomeSelected.BaseProductionMultiplicative[i] * currentHillinessSelected.BaseProductionMultiplicative[i]).ToString()); Widgets.Label(new Rect(180, 335 + i * (5 + height), 60, height + 2), ((currentBiomeSelected.BaseProductionAdditive[i] + currentHillinessSelected.BaseProductionAdditive[i]) * (currentBiomeSelected.BaseProductionMultiplicative[i] * currentHillinessSelected.BaseProductionMultiplicative[i])).ToString()); } } //Settle button Text.Font = GameFont.Small; Text.Anchor = TextAnchor.MiddleCenter; int buttonLength = 130; if (Widgets.ButtonText(new Rect((InitialSize.x - 32 - buttonLength) / 2f, 535, buttonLength, 32), "Settle".Translate() + ": (" + silverToCreateSettlement + ")")) //add inital cost { //if click button to settle if (PaymentUtil.getSilver() >= silverToCreateSettlement) //if have enough monies to make new settlement { StringBuilder reason = new StringBuilder(); if (!TileFinder.IsValidTileForNewSettlement(currentTileSelected, reason) || currentTileSelected == -1 || Find.World.GetComponent <FactionFC>().checkSettlementCaravansList(currentTileSelected.ToString())) { //Alert Error to User Messages.Message(reason.ToString() ?? "CaravanOnWay".Translate() + "!", MessageTypeDefOf.NegativeEvent); } else { //Else if valid tile PaymentUtil.paySilver(silverToCreateSettlement); //if PROCESS MONEY HERE //create settle event FCEvent tmp = FCEventMaker.MakeEvent(FCEventDefOf.settleNewColony); tmp.location = currentTileSelected; tmp.planetName = Find.World.info.name; tmp.timeTillTrigger = Find.TickManager.TicksGame + timeToTravel; tmp.source = Find.World.GetComponent <FactionFC>().capitalLocation; Find.World.GetComponent <FactionFC>().addEvent(tmp); Find.World.GetComponent <FactionFC>().settlementCaravansList.Add(tmp.location.ToString()); Messages.Message("CaravanSentToLocation".Translate() + " " + GenDate.ToStringTicksToDays((tmp.timeTillTrigger - Find.TickManager.TicksGame)) + "!", MessageTypeDefOf.PositiveEvent); // when event activate FactionColonies.createPlayerColonySettlement(currentTileSelected); } } else { //if don't have enough monies to make settlement Messages.Message("NotEnoughSilverToSettle".Translate() + "!", MessageTypeDefOf.NeutralEvent); } } //reset anchor/font Text.Font = fontBefore; Text.Anchor = anchorBefore; }
public override void DoWindowContents(Rect inRect) { //grab before anchor/font GameFont fontBefore = Text.Font; TextAnchor anchorBefore = Text.Anchor; //top label Text.Font = GameFont.Small; Text.Anchor = TextAnchor.MiddleCenter; //build outline Widgets.DrawMenuSection(billsBox); //loop through each bill //GoTo Here if change Reset: int i = 0; Text.Anchor = TextAnchor.MiddleCenter; foreach (BillFC bill in bills) { i++; Rect settlement = new Rect(); Rect date = new Rect(); Rect amount = new Rect(); Rect tithe = new Rect(); Rect resolve = new Rect(); Rect highlight = new Rect(); settlement = billNameBase; date = billDescBase; amount = billLocationBase; tithe = billTimeRemaining; resolve = billResolveBase; settlement.y = scroll + billHeight * i; date.y = scroll + billHeight * i; amount.y = scroll + billHeight * i; tithe.y = scroll + billHeight * i; resolve.y = scroll + billHeight * i; highlight = new Rect(settlement.x, settlement.y, resolve.x + resolve.width, billHeight); if (i % 2 == 0) { Widgets.DrawHighlight(highlight); } String settlementName; if (bill.settlement != null) { settlementName = bill.settlement.name; } else { settlementName = "Null"; } if (Widgets.ButtonText(settlement, settlementName)) { if (bill.settlement != null) { Find.WindowStack.Add(new settlementWindowFC(bill.settlement)); } } // Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(date, GenDate.ToStringTicksToDays(bill.dueTick - Find.TickManager.TicksGame)); // Widgets.Label(amount, bill.taxes.silverAmount.ToString()); // bool bul; bul = (bill.taxes.itemTithes.Count > 0); Widgets.Checkbox(new Vector2(tithe.x + tithe.width / 2 - 12, tithe.y), ref bul); if (Widgets.ButtonText(resolve, "ResolveBill".Translate())) { if (PaymentUtil.getSilver() >= -1 * (bill.taxes.silverAmount) || bill.taxes.silverAmount >= 0) { //if have enough silver on the current map to pay & map belongs to player FCEventMaker.createTaxEvent(bill); if (bill.taxes.researchCompleted != 0) { faction.researchPointPool += bill.taxes.researchCompleted; Messages.Message(TranslatorFormattedStringExtensions.Translate("PointsAddedToResearchPool", bill.taxes.researchCompleted), MessageTypeDefOf.PositiveEvent); } if (bill.taxes.electricityAllotted != 0) { faction.powerPool += bill.taxes.electricityAllotted; } goto Reset; } else { Messages.Message("NotEnoughSilverOnMapToPayBill".Translate() + "!", MessageTypeDefOf.RejectInput); } } } //Top label Widgets.ButtonTextSubtle(billNameBase, "Settlement".Translate()); Widgets.ButtonTextSubtle(billDescBase, "DueFC".Translate()); Widgets.ButtonTextSubtle(billLocationBase, "Amount".Translate()); Widgets.ButtonTextSubtle(billTimeRemaining, "HasTithe".Translate()); if (Widgets.ButtonTextSubtle(billResolveBase, "Auto-Resolve")) { List <FloatMenuOption> list = new List <FloatMenuOption>(); FloatMenuOption option = new FloatMenuOption("Auto-Resolving : " + faction.autoResolveBills, delegate { faction.autoResolveBills = !faction.autoResolveBills; switch (faction.autoResolveBills) { case true: Messages.Message("Bills are now autoresolving!", MessageTypeDefOf.NeutralEvent); PaymentUtil.autoresolveBills(bills); break; case false: Messages.Message("Bills are now not autoresolving.", MessageTypeDefOf.NeutralEvent); break; } }); list.Add(option); FloatMenu menu = new FloatMenu(list); Find.WindowStack.Add(menu); } Widgets.Checkbox(new Vector2(billResolveBase.x + billResolveBase.width - 30, billResolveBase.y + 3), ref faction.autoResolveBills, 24, true); //Menu Outline Widgets.DrawBox(billsBox); //reset anchor/font Text.Font = fontBefore; Text.Anchor = anchorBefore; if (Event.current.type == EventType.ScrollWheel) { scrollWindow(Event.current.delta.y); } }