Unifying, simplifying and messing around with land claiming and the related costs.

This commit is contained in:
Olof Larsson
2013-04-24 11:16:37 +02:00
parent 8ac19453b6
commit 05da06594a
17 changed files with 312 additions and 291 deletions

View File

@ -4,8 +4,10 @@ import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentSkipListMap;
import org.bukkit.ChatColor;
@ -177,6 +179,29 @@ public class Board extends Entity<Board> implements BoardInterface
}
}
// CHUNKS
@Override
public Set<PS> getChunks(Faction faction)
{
return this.getChunks(faction.getId());
}
public Set<PS> getChunks(String factionId)
{
Set<PS> ret = new HashSet<PS>();
for (Entry<PS, TerritoryAccess> entry : this.map.entrySet())
{
TerritoryAccess ta = entry.getValue();
if (!ta.getHostFactionId().equals(factionId)) continue;
PS ps = entry.getKey();
ps = ps.withWorld(this.getId());
ret.add(ps);
}
return ret;
}
// COUNT
@Override
@ -188,9 +213,11 @@ public class Board extends Entity<Board> implements BoardInterface
public int getCount(String factionId)
{
int ret = 0;
for (TerritoryAccess territoryAccess : this.map.values())
for (TerritoryAccess ta : this.map.values())
{
if(territoryAccess.getHostFactionId().equals(factionId)) ret += 1;
if (!ta.getHostFactionId().equals(factionId)) continue;
ret += 1;
}
return ret;
}

View File

@ -1,6 +1,8 @@
package com.massivecraft.factions.entity;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.Factions;
@ -107,6 +109,19 @@ public class BoardColl extends Coll<Board> implements BoardInterface
}
}
// CHUNKS
@Override
public Set<PS> getChunks(Faction faction)
{
Set<PS> ret = new HashSet<PS>();
for (Board board : this.getAll())
{
ret.addAll(board.getChunks(faction));
}
return ret;
}
// COUNT
@Override

View File

@ -3,7 +3,9 @@ package com.massivecraft.factions.entity;
import java.io.File;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
@ -194,8 +196,19 @@ public class BoardColls extends Colls<BoardColl, Board> implements BoardInterfac
}
}
// COUNT
// CHUNKS
@Override
public Set<PS> getChunks(Faction faction)
{
Set<PS> ret = new HashSet<PS>();
for (BoardColl coll : this.getColls())
{
ret.addAll(coll.getChunks(faction));
}
return ret;
}
// COUNT
@Override
public int getCount(Faction faction)
{

View File

@ -1,6 +1,7 @@
package com.massivecraft.factions.entity;
import java.util.ArrayList;
import java.util.Set;
import com.massivecraft.factions.RelationParticipator;
import com.massivecraft.factions.TerritoryAccess;
@ -20,6 +21,9 @@ public interface BoardInterface
public void removeAt(PS ps);
public void removeAll(Faction faction);
public void clean();
// CHUNKS
public Set<PS> getChunks(Faction faction);
// COUNT
public int getCount(Faction faction);

View File

@ -9,6 +9,7 @@ import com.massivecraft.factions.Const;
import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.event.FactionsEventChunkChangeType;
import com.massivecraft.mcore.store.Entity;
import com.massivecraft.mcore.util.MUtil;
@ -138,11 +139,12 @@ public class UConf extends Entity<UConf>
public String econUniverseAccount = "";
public double econCostClaimWilderness = 30.0;
public double econCostClaimFromFactionBonus = 30.0;
public double econClaimAdditionalMultiplier = 0.5;
public double econClaimRefundMultiplier = 0.7;
public double econClaimUnconnectedFee = 0.0;
public Map<FactionsEventChunkChangeType, Double> econChunkCost = MUtil.map(
FactionsEventChunkChangeType.BUY, 30.0,
FactionsEventChunkChangeType.SELL, -20.0,
FactionsEventChunkChangeType.CONQUER, -10.0,
FactionsEventChunkChangeType.PILLAGE, -10.0
);
public double econCostCreate = 100.0;
public double econCostSethome = 0.0;

View File

@ -14,7 +14,7 @@ import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Lang;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.RelationParticipator;
import com.massivecraft.factions.event.FactionsEventLandClaim;
import com.massivecraft.factions.event.FactionsEventChunkChange;
import com.massivecraft.factions.event.FactionsEventMembershipChange;
import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason;
import com.massivecraft.factions.integration.Econ;
@ -641,26 +641,14 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
{
psChunk = psChunk.getChunk(true);
Faction currentFaction = BoardColls.get().getFactionAt(psChunk);
int ownedLand = forFaction.getLandCount();
if ( ! this.canClaimForFactionAtLocation(forFaction, psChunk, notifyFailure)) return false;
// Event
FactionsEventLandClaim event = new FactionsEventLandClaim(sender, forFaction, psChunk);
FactionsEventChunkChange event = new FactionsEventChunkChange(sender, psChunk, forFaction);
event.run();
if (event.isCancelled()) return false;
// then make 'em pay (if applicable)
// TODO: The economy integration should cancel the event above!
// Calculate the cost to claim the area
double cost = Econ.calculateClaimCost(ownedLand, currentFaction.isNormal());
if (UConf.get(psChunk).econClaimUnconnectedFee != 0.0 && forFaction.getLandCountInWorld(psChunk.getWorld()) > 0 && !BoardColls.get().isConnectedPs(psChunk, forFaction))
{
cost += UConf.get(psChunk).econClaimUnconnectedFee;
}
if (Econ.payForAction(cost, this, "claim this land")) return false;
// TODO: The LWC integration should listen to Monitor for the claim event.
if (LWCFeatures.getEnabled() && forFaction.isNormal() && UConf.get(forFaction).lwcRemoveOnCapture)
{