Add possibility for new money system
This commit is contained in:
		
							parent
							
								
									858343d121
								
							
						
					
					
						commit
						0a0cc047ae
					
				| @ -76,7 +76,7 @@ public class CmdFactionsTop extends FactionsCommand | ||||
| 	{ | ||||
| 		switch(category) | ||||
| 		{ | ||||
| 			case MONEY: return Money.get(faction); | ||||
| 			case MONEY: return Econ.getMoney(faction); | ||||
| 			case MEMBERS: return faction.getMPlayers().size(); | ||||
| 			case TERRITORY: return faction.getLandCount(); | ||||
| 			case AGE: return faction.getAge(); | ||||
| @ -89,7 +89,7 @@ public class CmdFactionsTop extends FactionsCommand | ||||
| 		String ret = Txt.parse("%s<i>: ", faction.getName(mplayer)); | ||||
| 		switch(category) | ||||
| 		{ | ||||
| 			case MONEY: ret += Money.format(Money.get(faction), true); break; | ||||
| 			case MONEY: ret += Money.format(Econ.getMoney(faction), true); break; | ||||
| 			case MEMBERS: ret += faction.getMPlayers().size() + " members"; break; | ||||
| 			case TERRITORY: ret += faction.getLandCount() + " chunks"; break; | ||||
| 			case AGE: | ||||
|  | ||||
| @ -59,7 +59,7 @@ public class EngineEcon extends Engine | ||||
| 		if (oldFaction.getMPlayers().size() > 1) return; | ||||
| 		 | ||||
| 		// ... then transfer all money to the player.  | ||||
| 		double money = Money.get(oldFaction); | ||||
| 		double money = Econ.getMoney(oldFaction); | ||||
| 		if (money == 0) return; | ||||
| 		Econ.transferMoney(mplayer, oldFaction, mplayer, money); | ||||
| 	} | ||||
| @ -81,7 +81,7 @@ public class EngineEcon extends Engine | ||||
| 		// ... then transfer all the faction money to the sender. | ||||
| 		Faction faction = event.getFaction(); | ||||
| 	 | ||||
| 		double amount = Money.get(faction); | ||||
| 		double amount = Econ.getMoney(faction); | ||||
| 	 | ||||
| 		// Check that there is an amount | ||||
| 		if (amount == 0) return; | ||||
|  | ||||
| @ -153,7 +153,7 @@ public class EngineShow extends Engine | ||||
| 				// BANK | ||||
| 				if (MConf.get().bankEnabled) | ||||
| 				{ | ||||
| 					double bank = Money.get(faction); | ||||
| 					double bank = Econ.getMoney(faction); | ||||
| 					String bankDesc = Txt.parse("<h>%s", Money.format(bank, true)); | ||||
| 					show(idPriorityLiness, SHOW_ID_FACTION_BANK, SHOW_PRIORITY_FACTION_BANK, "Bank", bankDesc); | ||||
| 				} | ||||
|  | ||||
| @ -136,11 +136,9 @@ public class Faction extends Entity<Faction> implements FactionsParticipator, MP | ||||
| 	// Null means the faction has powerBoost (0). | ||||
| 	private Double powerBoost = null; | ||||
| 
 | ||||
| 	// Can anyone join the Faction? | ||||
| 	// If the faction is open they can. | ||||
| 	// If the faction is closed an invite is required. | ||||
| 	// Null means default. | ||||
| 	// private Boolean open = null; | ||||
| 	// The money a Faction has | ||||
| 	// null means 0.0 | ||||
| 	private Double money = null; | ||||
| 	 | ||||
| 	// This is the ids of the invited players. | ||||
| 	// They are actually "senderIds" since you can invite "@console" to your faction. | ||||
| @ -426,6 +424,28 @@ public class Faction extends Entity<Faction> implements FactionsParticipator, MP | ||||
| 		this.changed(); | ||||
| 	} | ||||
| 
 | ||||
| 	// -------------------------------------------- // | ||||
| 	// FIELD: money | ||||
| 	// -------------------------------------------- // | ||||
| 
 | ||||
| 	public double getMoney() | ||||
| 	{ | ||||
| 		if (!MConf.get().econEnabled) throw new UnsupportedOperationException("econ not enabled"); | ||||
| 		if (!MConf.get().bankEnabled) throw new UnsupportedOperationException("bank not enabled"); | ||||
| 		if (!MConf.get().useNewMoneySystem) throw new UnsupportedOperationException("this server does not use the new econ system"); | ||||
| 
 | ||||
| 		return this.convertGet(this.money, 0D); | ||||
| 	} | ||||
| 
 | ||||
| 	public void setMoney(Double money) | ||||
| 	{ | ||||
| 		if (!MConf.get().econEnabled) throw new UnsupportedOperationException("econ not enabled"); | ||||
| 		if (!MConf.get().bankEnabled) throw new UnsupportedOperationException("bank not enabled"); | ||||
| 		if (!MConf.get().useNewMoneySystem) throw new UnsupportedOperationException("this server does not use the new econ system"); | ||||
| 
 | ||||
| 		this.money = this.convertSet(money, this.money, 0D); | ||||
| 	} | ||||
| 	 | ||||
| 	// -------------------------------------------- // | ||||
| 	// FIELD: open | ||||
| 	// -------------------------------------------- // | ||||
|  | ||||
| @ -625,4 +625,6 @@ public class MConf extends Entity<MConf> | ||||
| 	// If you set this to false the player executing the command will pay instead. | ||||
| 	public boolean bankFactionPaysCosts = true; | ||||
| 
 | ||||
| 	public boolean useNewMoneySystem = false; | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -63,7 +63,7 @@ public class Econ | ||||
| 
 | ||||
| 	public static void sendBalanceInfo(MPlayer to, EconomyParticipator about) | ||||
| 	{ | ||||
| 		to.msg("<a>%s's<i> balance is <h>%s<i>.", about.describeTo(to, true), Money.format(Money.get(about))); | ||||
| 		to.msg("<a>%s's<i> balance is <h>%s<i>.", about.describeTo(to, true), Money.format(getMoney(about))); | ||||
| 	} | ||||
| 
 | ||||
| 	public static boolean isMePermittedYou(EconomyParticipator me, EconomyParticipator you, MPerm mperm) | ||||
| @ -128,7 +128,7 @@ public class Econ | ||||
| 		} | ||||
| 		 | ||||
| 		// Is there enough money for the transaction to happen? | ||||
| 		if (Money.get(from) < amount) | ||||
| 		if (getMoney(from) < amount) | ||||
| 		{ | ||||
| 			// There was not enough money to pay | ||||
| 			if (by != null && notify) | ||||
| @ -139,7 +139,7 @@ public class Econ | ||||
| 		} | ||||
| 		 | ||||
| 		// Transfer money | ||||
| 		if (Money.move(from, to, by, amount, "Factions")) | ||||
| 		if (moveMoney(from, to, by, amount)) | ||||
| 		{ | ||||
| 			if (notify) | ||||
| 			{ | ||||
| @ -219,7 +219,7 @@ public class Econ | ||||
| 	{ | ||||
| 		if ( ! isEnabled()) return true; | ||||
| 
 | ||||
| 		if (Money.get(ep) < delta) | ||||
| 		if (getMoney(ep) < delta) | ||||
| 		{ | ||||
| 			if (toDoThis != null && !toDoThis.isEmpty()) | ||||
| 			{ | ||||
| @ -240,7 +240,7 @@ public class Econ | ||||
| 		 | ||||
| 		boolean hasActionDesctription = (actionDescription != null && !actionDescription.isEmpty()); | ||||
| 
 | ||||
| 		if (Money.spawn(ep, null, delta, "Factions")) | ||||
| 		if (moveMoney(null, ep, null, delta)) | ||||
| 		{ | ||||
| 			modifyUniverseMoney(ep, -delta); | ||||
| 			 | ||||
| @ -274,4 +274,61 @@ public class Econ | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	public static double getMoney(EconomyParticipator ep) | ||||
| 	{ | ||||
| 		if (ep instanceof Faction && MConf.get().useNewMoneySystem) | ||||
| 		{ | ||||
| 			return ((Faction) ep).getMoney(); | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			return Money.get(ep); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	public static boolean moveMoney(EconomyParticipator from, EconomyParticipator to, EconomyParticipator by, double amount) | ||||
| 	{ | ||||
| 		final boolean fromFaction = from instanceof Faction; | ||||
| 		final boolean toFaction = to instanceof Faction; | ||||
| 
 | ||||
| 		// If the old money system is used just do that | ||||
| 		if (!MConf.get().useNewMoneySystem) | ||||
| 		{ | ||||
| 			return Money.move(from, to, by, amount, "Factions"); | ||||
| 		} | ||||
| 
 | ||||
| 		// Or if neither to or from is a faction | ||||
| 		if (!fromFaction && !toFaction) | ||||
| 		{ | ||||
| 			return Money.move(from, to, by, amount, "Factions"); | ||||
| 		} | ||||
| 
 | ||||
| 		// Handle from | ||||
| 		if (fromFaction) | ||||
| 		{ | ||||
| 			Faction faction = (Faction) from; | ||||
| 			double money = faction.getMoney(); | ||||
| 			if (amount > money) return false; | ||||
| 			faction.setMoney(money - amount); | ||||
| 		} | ||||
| 		else if (from != null) | ||||
| 		{ | ||||
| 			Money.despawn(from, by, amount); | ||||
| 		} | ||||
| 
 | ||||
| 		// Handle to | ||||
| 		if (toFaction) | ||||
| 		{ | ||||
| 			Faction faction = (Faction) to; | ||||
| 			double money = faction.getMoney(); | ||||
| 			faction.setMoney(money + amount); | ||||
| 		} | ||||
| 		else if (to != null) | ||||
| 		{ | ||||
| 			Money.spawn(to, by, amount); | ||||
| 		} | ||||
| 
 | ||||
| 		return true; | ||||
| 	} | ||||
| 	 | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user