Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/net/tfminecraft/simplefactions/enums/SFGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public enum SFGUI {
INSTALLATION_DETAIL_VIEW,
SUPPLY_HUB_VIEW,
HOSTED_SUPPLY_HUB_VIEW,
HUB_PROPOSAL_LIST,
HUB_NEGOTIATION,
HUB_OFFER_LIST,
PLAYER_LEDGER_VIEW,
COMPANY_VIEW,
COMPANY_SLOTS_VIEW,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static void deliver(List<HubAgreementService.HubNotice> notices) {
Player player = online(notice.playerName());
if (player != null && notice.message() != null) {
player.sendMessage(notice.message());
net.tfminecraft.simplefactions.managers.inventory.HubProposalMenu.refresh(player);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ public static boolean hasAgreement(Guild guild, String hostFactionId, String ins
return findAgreement(guild, hostFactionId, installationId) != null;
}

public static HubOffer offer(Guild guild, String hostFactionId, String installationId) {
return findOffer(guild, hostFactionId, installationId);
}

public static HubAgreement findAgreement(Guild guild, String hostFactionId, String installationId) {
if (guild == null || guild.getHubAgreements() == null) {
return null;
Expand Down Expand Up @@ -251,6 +255,9 @@ static AgreementResult accept(
if (offer == null) {
return missingOrLapsed(guild, hostFactionId, installationId, facts, nowMillis);
}
if (offer.lastActor() != null && offer.lastActor().equalsIgnoreCase(actorName)) {
return AgreementResult.fail("§cYou can only accept terms the other side sent");
}
if (!actsFor(offer.awaiting(), guild, actorName, hostFactionId, facts)) {
OfferSide sender = offer.awaiting() == OfferSide.HOST ? OfferSide.GUILD : OfferSide.HOST;
if (actsFor(sender, guild, actorName, hostFactionId, facts)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package net.tfminecraft.simplefactions.guild.hub;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import net.tfminecraft.simplefactions.guild.hub.HubEstimates.Destination;
import net.tfminecraft.simplefactions.guild.hub.HubEstimates.Group;
import net.tfminecraft.simplefactions.guild.hub.HubEstimates.Terms;
import net.tfminecraft.simplefactions.utils.Formatter;

/** Lore for the hub proposal list and the negotiation chest. Tax and fee are not recalculated here. */
public final class HubProposalCopy {
private HubProposalCopy() {
}

public static int startingRate(int minPercent, int maxPercent) {
if (maxPercent < minPercent) {
return minPercent;
}
return (minPercent + maxPercent) / 2;
}

public static int clampRate(int rate, int minPercent, int maxPercent) {
return Math.max(minPercent, Math.min(maxPercent, rate));
}

public static long clampFeeCents(long cents, double maxFeeDenars) {
long maxCents = Math.round(Math.max(0, maxFeeDenars) * 100.0);
return Math.max(0, Math.min(maxCents, cents));
}

public static List<String> destinationLore(Destination destination) {
List<String> lore = new ArrayList<>();
if (destination == null) {
lore.add("§7Estimates are not ready yet");
return lore;
}
lore.add(destination.group() == Group.READY ? "§aReady now" : "§eWorth building");
lore.add("§7You: about " + signed(destination.operatorGain()) + "§7 a day");
lore.add("§7Host: about " + signed(destination.hostGain()) + "§7 a day");
if (destination.assumedRailway()) {
lore.add("§7No railway yet; assumes about "
+ Math.round(destination.assumedTrackBlocks()) + " blocks of track");
}
if (destination.group() == Group.WORTH_BUILDING || destination.installationId() == null) {
lore.add("§7A station has to be built here first");
} else if (destination.ownRealm()) {
lore.add("§eClick to build this hub");
} else {
lore.add("§eClick to negotiate");
}
return lore;
}

public static List<String> operatorLines(Destination destination, Terms terms) {
List<String> lore = new ArrayList<>();
if (destination == null || terms == null) {
lore.add("§7Estimates are not ready yet");
return lore;
}
if (destination.ownRealm()) {
lore.add("§7Your guild: about " + signed(destination.operatorGain()) + "§7 a day");
return lore;
}
lore.add("§7Your guild: about " + signed(destination.operatorGain()) + "§7 a day before tax");
lore.add("§7Tax §c-" + Formatter.formatMoney(terms.tax())
+ "§7, fee §c-" + Formatter.formatMoney(terms.fee()));
lore.add("§7Net " + signed(terms.operatorNet()) + "§7 a day");
return lore;
}

public static List<String> hostLines(Destination destination, Terms terms, Map<String, String> guildNames) {
List<String> lore = new ArrayList<>();
if (destination == null || terms == null) {
lore.add("§7Estimates are not ready yet");
return lore;
}
if (destination.ownRealm()) {
lore.add("§7Your realm: about " + signed(destination.hostGain()) + "§7 a day");
return lore;
}
lore.add("§7Your guilds: about " + signed(destination.hostGain()) + "§7 a day");
lore.add("§7Hub tax §a+" + Formatter.formatMoney(terms.tax())
+ "§7, fee §a+" + Formatter.formatMoney(terms.fee()));
lore.add("§7Net " + signed(terms.hostNet()) + "§7 a day");
if (destination.hostGuildGains() != null) {
for (Map.Entry<String, Double> entry : destination.hostGuildGains().entrySet()) {
if (entry.getKey() == null || entry.getValue() == null) {
continue;
}
String name = guildNames == null ? null : guildNames.get(entry.getKey());
lore.add("§7" + (name == null || name.isBlank() ? entry.getKey() : name)
+ ": about " + signed(entry.getValue()));
}
}
return lore;
}

/**
* The rate at which the host's net is zero, given the fee already on the screen.
* The host gains before that rate when their other guilds already gain from the hub.
*/
public static String breakEvenLine(Destination destination, long feeCents, int minPercent, int maxPercent) {
if (destination == null || destination.ownRealm()) {
return "§7A hub in your own realm has no tax or fee";
}
double fee = Math.max(0, feeCents) / 100.0;
double taxable = destination.taxableIncome();
if (taxable <= 0.0001) {
if (destination.hostGain() + fee >= 0) {
return "§7The host gains even at " + minPercent + "%";
}
return "§7The host does not break even inside " + minPercent + "-" + maxPercent + "%";
}
int shown = (int) Math.round((-destination.hostGain() - fee) * 100.0 / taxable);
if (shown < minPercent) {
return "§7The host gains even at " + minPercent + "%";
}
if (shown > maxPercent) {
return "§7The host does not break even inside " + minPercent + "-" + maxPercent + "%";
}
if (fee > 0) {
return "§7Break-even is about §e" + shown + "%§7 at this fee";
}
return "§7Break-even is about §e" + shown + "%";
}

static String signed(double amount) {
String money = Formatter.formatMoney(Math.abs(amount));
if (amount > 0.0001) {
return "§a+" + money;
}
if (amount < -0.0001) {
return "§c-" + money;
}
return "§e" + money;
}
}
Loading
Loading