diff --git a/.classpath b/.classpath index 465f836e..6d739bfc 100644 --- a/.classpath +++ b/.classpath @@ -30,5 +30,6 @@ + diff --git a/lib/commons-lang3-3.1.jar b/lib/commons-lang3-3.1.jar new file mode 100644 index 00000000..a85e539b Binary files /dev/null and b/lib/commons-lang3-3.1.jar differ diff --git a/scripts/gcwzones.py b/scripts/gcwzones.py index 5393ce01..1208f056 100644 --- a/scripts/gcwzones.py +++ b/scripts/gcwzones.py @@ -11,8 +11,8 @@ def addZones(core): gcwService.addZone('corellia', 'gcw_region_corellia_10', -142, -4482, 1750, 89285715, 0) gcwService.addZone('corellia', 'gcw_region_corellia_11', 3338, -5382, 1750, 35714286, 0) gcwService.addZone('corellia', 'gcw_region_corellia_12', 6618, -5602, 1382, 35714286, 0) - gcwService.addZone('corellia', 'gcw_region_corellia_13', 0, 0, 0, 35714286, 0) - gcwService.addZone('corellia', 'gcw_region_corellia_14', 0, 0, 0, 89285715, 0) + gcwService.addZone('corellia', 'gcw_region_corellia_13', 0, 0, 0, 35714286, 1) + gcwService.addZone('corellia', 'gcw_region_corellia_14', 0, 0, 0, 89285715, 2) gcwService.addZone('corellia', 'gcw_region_corellia_2', -3472, 3228, 1500, 35714286, 0) gcwService.addZone('corellia', 'gcw_region_corellia_3', -1032, 5708, 1750, 35714286, 0) gcwService.addZone('corellia', 'gcw_region_corellia_4', -302, 2178, 1750, 35714285, 0) @@ -34,8 +34,8 @@ def addZones(core): gcwService.addZone('dantooine', 'gcw_region_dantooine_13', 1588, -6552, 1400, 33898305, 0) gcwService.addZone('dantooine', 'gcw_region_dantooine_14', 4439, -4461, 2011, 33898305, 0) gcwService.addZone('dantooine', 'gcw_region_dantooine_15', 6839, -2161, 1161, 33898305, 0) - gcwService.addZone('dantooine', 'gcw_region_dantooine_16', 0, 0, 0, 33898305, 0) - gcwService.addZone('dantooine', 'gcw_region_dantooine_17', 0, 0, 0, 84745762, 0) + gcwService.addZone('dantooine', 'gcw_region_dantooine_16', 0, 0, 0, 33898305, 1) + gcwService.addZone('dantooine', 'gcw_region_dantooine_17', 0, 0, 0, 84745762, 2) gcwService.addZone('dantooine', 'gcw_region_dantooine_2', -932, 5708, 2000, 33898305, 0) gcwService.addZone('dantooine', 'gcw_region_dantooine_3', -6532, -252, 1468, 33898305, 0) gcwService.addZone('dantooine', 'gcw_region_dantooine_4', -3352, 628, 1750, 33898305, 0) @@ -53,8 +53,8 @@ def addZones(core): gcwService.addZone('dathomir', 'gcw_region_dathomir_1', -6400, 940, 1250, 39215687, 0) gcwService.addZone('dathomir', 'gcw_region_dathomir_10', 4458, -942, 1750, 39215687, 0) gcwService.addZone('dathomir', 'gcw_region_dathomir_11', 6918, 838, 1082, 39215687, 0) - gcwService.addZone('dathomir', 'gcw_region_dathomir_12', 0, 0, 0, 98039216, 0) - gcwService.addZone('dathomir', 'gcw_region_dathomir_13', 0, 0, 0, 39215686, 0) + gcwService.addZone('dathomir', 'gcw_region_dathomir_12', 0, 0, 0, 98039216, 2) + gcwService.addZone('dathomir', 'gcw_region_dathomir_13', 0, 0, 0, 39215686, 1) gcwService.addZone('dathomir', 'gcw_region_dathomir_2', -3922, 2698, 1750, 39215686, 0) gcwService.addZone('dathomir', 'gcw_region_dathomir_3', -1432, 4908, 1500, 39215686, 0) gcwService.addZone('dathomir', 'gcw_region_dathomir_4', 1958, 4878, 1500, 39215686, 0) @@ -76,8 +76,8 @@ def addZones(core): gcwService.addZone('endor', 'gcw_region_endor_12', 1398, -4842, 1250, 30769231, 0) gcwService.addZone('endor', 'gcw_region_endor_13', 3368, -3552, 1000, 30769231, 0) gcwService.addZone('endor', 'gcw_region_endor_14', 5848, -5352, 2000, 30769231, 0) - gcwService.addZone('endor', 'gcw_region_endor_15', 0, 0, 0, 30769231, 0) - gcwService.addZone('endor', 'gcw_region_endor_16', 0, 0, 0, 76923077, 0) + gcwService.addZone('endor', 'gcw_region_endor_15', 0, 0, 0, 30769231, 1) + gcwService.addZone('endor', 'gcw_region_endor_16', 0, 0, 0, 76923077, 2) gcwService.addZone('endor', 'gcw_region_endor_2', -3542, 3258, 2000, 30769231, 0) gcwService.addZone('endor', 'gcw_region_endor_3', -882, 1578, 1000, 30769231, 0) gcwService.addZone('endor', 'gcw_region_endor_4', 1058, 2918, 1250, 30769231, 0) @@ -290,8 +290,8 @@ def addZones(core): gcwService.addZone('lok', 'gcw_region_lok_10', 5268, 588, 2000, 35714286, 0) gcwService.addZone('lok', 'gcw_region_lok_11', 1588, -5412, 2000, 35714286, 0) gcwService.addZone('lok', 'gcw_region_lok_12', 5188, -3452, 2000, 35714286, 0) - gcwService.addZone('lok', 'gcw_region_lok_13', 0, 0, 0, 35714286, 0) - gcwService.addZone('lok', 'gcw_region_lok_14', 0, 0, 0, 89285715, 0) + gcwService.addZone('lok', 'gcw_region_lok_13', 0, 0, 0, 35714286, 1) + gcwService.addZone('lok', 'gcw_region_lok_14', 0, 0, 0, 89285715, 2) gcwService.addZone('lok', 'gcw_region_lok_2', -1192, 5428, 2000, 89285715, 0) gcwService.addZone('lok', 'gcw_region_lok_3', -4832, -472, 2000, 35714286, 0) gcwService.addZone('lok', 'gcw_region_lok_4', -1272, 1408, 2000, 35714286, 0) @@ -310,8 +310,8 @@ def addZones(core): gcwService.addZone('naboo', 'gcw_region_naboo_10', 1118, -3342, 2250, 32258065, 0) gcwService.addZone('naboo', 'gcw_region_naboo_11', 4868, -1852, 1700, 32258065, 0) gcwService.addZone('naboo', 'gcw_region_naboo_12', 4638, -5342, 1750, 32258065, 0) - gcwService.addZone('naboo', 'gcw_region_naboo_13', 0, 0, 0, 32258065, 0) - gcwService.addZone('naboo', 'gcw_region_naboo_14', 0, 0, 0, 80645162, 0) + gcwService.addZone('naboo', 'gcw_region_naboo_13', 0, 0, 0, 32258065, 1) + gcwService.addZone('naboo', 'gcw_region_naboo_14', 0, 0, 0, 80645162, 2) gcwService.addZone('naboo', 'gcw_region_naboo_2', -1682, 5658, 1650, 32258065, 0) gcwService.addZone('naboo', 'gcw_region_naboo_3', 1978, 6734, 1266, 32258065, 0) gcwService.addZone('naboo', 'gcw_region_naboo_4', 5378, 5678, 2000, 32258064, 0) @@ -326,12 +326,12 @@ def addZones(core): gcwService.addZone('naboo', 'space_naboo_space_pve', 0, 0, 0, 80645161, 0) gcwService.addZone('naboo', 'space_naboo_space_pvp', 0, 0, 0, 80645161, 0) - gcwService.addZone('rori', 'gcw_region_naboo_14', 0, 0, 0, 84745763, 0) + gcwService.addZone('rori', 'gcw_region_naboo_14', 0, 0, 0, 84745763, 2) gcwService.addZone('rori', 'gcw_region_rori_1', -4780, 6000, 1900, 33898306, 0) gcwService.addZone('rori', 'gcw_region_rori_10', 4648, -1852, 1900, 33898306, 0) gcwService.addZone('rori', 'gcw_region_rori_11', -4772, -5512, 1900, 33898306, 0) gcwService.addZone('rori', 'gcw_region_rori_12', 5128, -5792, 2000, 33898306, 0) - gcwService.addZone('rori', 'gcw_region_rori_13', 0, 0, 0, 33898305, 0) + gcwService.addZone('rori', 'gcw_region_rori_13', 0, 0, 0, 33898305, 1) gcwService.addZone('rori', 'gcw_region_rori_2', 168, 4588, 3100, 33898305, 0) gcwService.addZone('rori', 'gcw_region_rori_3', 5088, 5808, 1900, 135593220, 0) gcwService.addZone('rori', 'gcw_region_rori_4', -4312, 2188, 1900, 33898305, 0) @@ -346,7 +346,7 @@ def addZones(core): gcwService.addZone('rori', 'space_naboo_space_pve', 0, 0, 0, 84745762, 0) gcwService.addZone('rori', 'space_naboo_space_pvp', 0, 0, 0, 84745762, 0) - gcwService.addZone('talus', 'gcw_region_corellia_14', 0, 0, 0, 76923077, 0) + gcwService.addZone('talus', 'gcw_region_corellia_14', 0, 0, 0, 76923077, 2) gcwService.addZone('talus', 'gcw_region_talus_1', -3280, 5480, 1600, 30769231, 0) gcwService.addZone('talus', 'gcw_region_talus_10', 528, 508, 1600, 30769231, 0) gcwService.addZone('talus', 'gcw_region_talus_11', 3548, -772, 1600, 30769231, 0) @@ -354,7 +354,7 @@ def addZones(core): gcwService.addZone('talus', 'gcw_region_talus_13', -2812, -4052, 1600, 30769231, 0) gcwService.addZone('talus', 'gcw_region_talus_14', 558, -3002, 1850, 123076924, 0) gcwService.addZone('talus', 'gcw_region_talus_15', 3968, -3972, 1600, 30769231, 0) - gcwService.addZone('talus', 'gcw_region_talus_16', 0, 0, 0, 30769231, 0) + gcwService.addZone('talus', 'gcw_region_talus_16', 0, 0, 0, 30769231, 1) gcwService.addZone('talus', 'gcw_region_talus_2', 468, 5488, 1600, 30769231, 0) gcwService.addZone('talus', 'gcw_region_talus_3', 4368, 5488, 1600, 30769231, 0) gcwService.addZone('talus', 'gcw_region_talus_4', -5072, 1108, 1600, 30769231, 0) @@ -372,8 +372,8 @@ def addZones(core): gcwService.addZone('tatooine', 'gcw_region_tatooine_1', -5320, 5200, 2500, 33333334, 0) gcwService.addZone('tatooine', 'gcw_region_tatooine_10', 108, -5332, 1000, 33333334, 0) gcwService.addZone('tatooine', 'gcw_region_tatooine_11', 3460, -4768, 1750, 83333334, 0) - gcwService.addZone('tatooine', 'gcw_region_tatooine_12', 0, 0, 0, 83333334, 0) - gcwService.addZone('tatooine', 'gcw_region_tatooine_13', 0, 0, 0, 33333334, 0) + gcwService.addZone('tatooine', 'gcw_region_tatooine_12', 0, 0, 0, 83333334, 2) + gcwService.addZone('tatooine', 'gcw_region_tatooine_13', 0, 0, 0, 33333334, 1) gcwService.addZone('tatooine', 'gcw_region_tatooine_2', -2960, 2200, 1250, 33333334, 0) gcwService.addZone('tatooine', 'gcw_region_tatooine_3', 1480, 3240, 1200, 33333333, 0) gcwService.addZone('tatooine', 'gcw_region_tatooine_4', 3840, 2420, 1200, 33333333, 0) @@ -381,7 +381,7 @@ def addZones(core): gcwService.addZone('tatooine', 'gcw_region_tatooine_6', -132, 28, 2200, 33333333, 0) gcwService.addZone('tatooine', 'gcw_region_tatooine_7', 4140, -940, 2100, 33333333, 0) gcwService.addZone('tatooine', 'gcw_region_tatooine_8', -5192, -5952, 1700, 33333333, 0) - gcwService.addZone('tatooine', 'gcw_region_tatooine_9', -1232, -3652, 1100, 33333333, 0) + gcwService.addZone('tatooine', 'gcw_region_tatooine_9', -1232, -3652, 1100, 133333333, 0) gcwService.addZone('tatooine', 'space_tatooine_space_pve', 0, 0, 0, 83333333, 0) gcwService.addZone('tatooine', 'space_tatooine_space_pvp', 0, 0, 0, 83333333, 0) gcwService.addZone('tatooine', 'tatooine_airspace', 0, 0, 0, 33333333, 0) @@ -396,8 +396,8 @@ def addZones(core): gcwService.addZone('yavin4', 'gcw_region_yavin4_14', -2502, -7022, 750, 30303031, 0) gcwService.addZone('yavin4', 'gcw_region_yavin4_15', -552, -5512, 1500, 30303031, 0) gcwService.addZone('yavin4', 'gcw_region_yavin4_16', 3998, -6242, 1150, 30303031, 0) - gcwService.addZone('yavin4', 'gcw_region_yavin4_17', 0, 0, 0, 30303031, 0) - gcwService.addZone('yavin4', 'gcw_region_yavin4_18', 0, 0, 0, 75757576, 0) + gcwService.addZone('yavin4', 'gcw_region_yavin4_17', 0, 0, 0, 30303031, 1) + gcwService.addZone('yavin4', 'gcw_region_yavin4_18', 0, 0, 0, 75757576, 2) gcwService.addZone('yavin4', 'gcw_region_yavin4_2', -2482, 3698, 1300, 30303030, 0) gcwService.addZone('yavin4', 'gcw_region_yavin4_3', -312, 4908, 1150, 30303030, 0) gcwService.addZone('yavin4', 'gcw_region_yavin4_4', 2618, 2718, 1700, 30303030, 0) diff --git a/src/main/NGECore.java b/src/main/NGECore.java index 092a13b1..9ca9b389 100644 --- a/src/main/NGECore.java +++ b/src/main/NGECore.java @@ -123,7 +123,7 @@ public class NGECore { private ObjectDatabase mailODB; public NGECore() { - + } public void start() { diff --git a/src/protocol/swg/ChatOnChangeFriendStatus.java b/src/protocol/swg/ChatOnChangeFriendStatus.java index acfa6759..c78c24be 100644 --- a/src/protocol/swg/ChatOnChangeFriendStatus.java +++ b/src/protocol/swg/ChatOnChangeFriendStatus.java @@ -8,8 +8,6 @@ import org.apache.mina.core.buffer.IoBuffer; import engine.resources.config.Config; import engine.resources.config.DefaultConfig; -import resources.objects.player.PlayerObject; - public class ChatOnChangeFriendStatus extends SWGMessage { diff --git a/src/resources/common/FactionStatus.java b/src/resources/common/FactionStatus.java new file mode 100644 index 00000000..95a24034 --- /dev/null +++ b/src/resources/common/FactionStatus.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2013 + * + * This File is part of NGECore2. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Using NGEngine to work with NGECore2 is making a combined work based on NGEngine. + * Therefore all terms and conditions of the GNU Lesser General Public License cover the combination. + ******************************************************************************/ +package resources.common; + +public class FactionStatus { + + public static int OnLeave = 0; + public static int Combatant = 1; + public static int SpecialForces = 2; + +} diff --git a/src/resources/gcw/CurrentServerGCWZoneHistory.java b/src/resources/gcw/CurrentServerGCWZoneHistory.java index a7623337..f56ed235 100644 --- a/src/resources/gcw/CurrentServerGCWZoneHistory.java +++ b/src/resources/gcw/CurrentServerGCWZoneHistory.java @@ -25,15 +25,18 @@ import java.nio.ByteOrder; import org.apache.mina.core.buffer.IoBuffer; +import com.sleepycat.persist.model.Persistent; + import resources.objects.ListObject; -public class CurrentServerGCWZoneHistory extends ListObject { +@Persistent +public class CurrentServerGCWZoneHistory extends ListObject implements Cloneable { private int lastUpdateTime; private int percent; public CurrentServerGCWZoneHistory(CurrentServerGCWZonePercent zone) { - this.percent = zone.getPercent(); + this.percent = zone.getPercent().intValue(); this.lastUpdateTime = zone.getLastUpdateTime(); } @@ -42,7 +45,7 @@ public class CurrentServerGCWZoneHistory extends ListObject { return lastUpdateTime; } } - + public int getPercent() { synchronized(objectMutex) { return percent; @@ -58,4 +61,13 @@ public class CurrentServerGCWZoneHistory extends ListObject { } } + public CurrentServerGCWZoneHistory clone() { + try { + return (CurrentServerGCWZoneHistory) super.clone(); + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + return null; + } + } + } diff --git a/src/resources/gcw/CurrentServerGCWZonePercent.java b/src/resources/gcw/CurrentServerGCWZonePercent.java index 451b5f70..ad9c3895 100644 --- a/src/resources/gcw/CurrentServerGCWZonePercent.java +++ b/src/resources/gcw/CurrentServerGCWZonePercent.java @@ -21,34 +21,47 @@ ******************************************************************************/ package resources.gcw; +import java.math.BigDecimal; +import java.math.MathContext; import java.nio.ByteOrder; import org.apache.mina.core.buffer.IoBuffer; +import com.sleepycat.persist.model.Persistent; + import engine.resources.scene.Point2D; import resources.objects.ListObject; -public class CurrentServerGCWZonePercent extends ListObject { +@Persistent +public class CurrentServerGCWZonePercent extends ListObject implements Cloneable { private Point2D position; - private float radius; - private int group; - private float weight; - private int percent = 50; - private int gcwPoints = 0; - private long lastUpdateTime = System.currentTimeMillis(); + private float radius = 0; + private BigDecimal weight; + private int type = 0; + private BigDecimal percent; + private int gcwPoints = 1; + private long lastUpdateTime = (System.currentTimeMillis() / ((long) 1000)); - public CurrentServerGCWZonePercent(Point2D position, float radius, int group, float weight) { + public CurrentServerGCWZonePercent(Point2D position, float radius, int weight, int type) { this.position = position; this.radius = radius; - this.group = group; - this.weight = weight; + this.weight = new BigDecimal(weight, MathContext.DECIMAL128); + this.weight = this.weight.divide(new BigDecimal("10000000.0", MathContext.DECIMAL128), MathContext.DECIMAL128); + this.type = type; + this.percent = new BigDecimal("50.0", MathContext.DECIMAL128); } public Point2D getPosition() { synchronized(objectMutex) { - return position; + return position.clone(); + } + } + + public void setPosition(Point2D position) { + synchronized(objectMutex) { + this.position = position; } } @@ -58,27 +71,53 @@ public class CurrentServerGCWZonePercent extends ListObject { } } - public int getGroup() { + public void setRadius(float radius) { synchronized(objectMutex) { - return group; + this.radius = radius; } } - public float getWeight() { + public int getGroup() { + synchronized(objectMutex) { + return weight.unscaledValue().intValue(); + } + } + + public BigDecimal getWeight() { synchronized(objectMutex) { return weight; } } - public int getPercent() { + public void setWeight(int weight) { + synchronized(objectMutex) { + this.weight = new BigDecimal(weight, MathContext.DECIMAL128); + this.weight = this.weight.divide(new BigDecimal("10000000.0", MathContext.DECIMAL128), MathContext.DECIMAL128); + } + } + + public int getType() { + synchronized(objectMutex) { + return type; + } + } + + public void setType(int type) { + synchronized(objectMutex) { + this.type = type; + } + } + + public BigDecimal getPercent() { synchronized(objectMutex) { return percent; } } - public CurrentServerGCWZonePercent setPercent(int percent) { + public CurrentServerGCWZonePercent setPercent(BigDecimal percent) { synchronized(objectMutex) { this.percent = percent; + this.lastUpdateTime = (System.currentTimeMillis() / ((long) 1000)); return this; } } @@ -97,22 +136,34 @@ public class CurrentServerGCWZonePercent extends ListObject { public void removeGCWPoints(int gcwPoints) { synchronized(objectMutex) { - this.gcwPoints = (((this.gcwPoints - gcwPoints) < 0) ? 0 : this.gcwPoints - gcwPoints); + this.gcwPoints = (((this.gcwPoints - gcwPoints) < 1) ? 1 : this.gcwPoints - gcwPoints); } } public int getLastUpdateTime() { synchronized(objectMutex) { - return (int) lastUpdateTime; + return ((int) lastUpdateTime); } } public byte[] getBytes() { synchronized(objectMutex) { IoBuffer buffer = bufferPool.allocate(4, false).order(ByteOrder.LITTLE_ENDIAN); - buffer.putInt(percent); + buffer.putInt(percent.intValue()); return buffer.array(); } } + @Override + public CurrentServerGCWZonePercent clone() { + try { + CurrentServerGCWZonePercent object = (CurrentServerGCWZonePercent) super.clone(); + object.setPosition(getPosition()); + return object; + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + return null; + } + } + } diff --git a/src/resources/gcw/OtherServerGCWZonePercent.java b/src/resources/gcw/OtherServerGCWZonePercent.java index 17380a40..6b4d410d 100644 --- a/src/resources/gcw/OtherServerGCWZonePercent.java +++ b/src/resources/gcw/OtherServerGCWZonePercent.java @@ -25,9 +25,12 @@ import java.nio.ByteOrder; import org.apache.mina.core.buffer.IoBuffer; +import com.sleepycat.persist.model.Persistent; + import resources.objects.ListObject; -public class OtherServerGCWZonePercent extends ListObject { +@Persistent +public class OtherServerGCWZonePercent extends ListObject implements Cloneable { private String zone = ""; private int percent = 50; @@ -48,9 +51,9 @@ public class OtherServerGCWZonePercent extends ListObject { } } - public OtherServerGCWZonePercent setPercent(int percent) { + public OtherServerGCWZonePercent setPercent(double percent) { synchronized(objectMutex) { - this.percent = percent; + this.percent = (int) percent; return this; } } @@ -64,4 +67,14 @@ public class OtherServerGCWZonePercent extends ListObject { } } + @Override + public OtherServerGCWZonePercent clone() { + try { + return (OtherServerGCWZonePercent) super.clone(); + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + return null; + } + } + } diff --git a/src/resources/objects/ListObject.java b/src/resources/objects/ListObject.java index efea9b1e..815fe632 100644 --- a/src/resources/objects/ListObject.java +++ b/src/resources/objects/ListObject.java @@ -51,5 +51,5 @@ public abstract class ListObject implements IListObject { protected byte[] getUnicodeString(String string) { return StringUtilities.getUnicodeString(string); } - + } diff --git a/src/resources/objects/MultimapProxy.java b/src/resources/objects/MultimapProxy.java new file mode 100644 index 00000000..67ab5944 --- /dev/null +++ b/src/resources/objects/MultimapProxy.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2013 + * + * This File is part of NGECore2. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Using NGEngine to work with NGECore2 is making a combined work based on NGEngine. + * Therefore all terms and conditions of the GNU Lesser General Public License cover the combination. + ******************************************************************************/ +package resources.objects; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; + +import org.python.google.common.collect.ArrayListMultimap; +import org.python.google.common.collect.Multimap; + +import com.sleepycat.persist.model.Persistent; +import com.sleepycat.persist.model.PersistentProxy; + +@Persistent(proxyFor=Multimap.class) +public class MultimapProxy implements PersistentProxy> { + + private int size = 0; + private K[] keys; + private V[] values; + + private MultimapProxy() { } + + public void initializeProxy(Multimap object) { + List keyList = new ArrayList(); + List valueList = new ArrayList(); + + for (Entry entry : object.entries()) { + keyList.add(entry.getKey()); + valueList.add(entry.getValue()); + } + + size = object.entries().size(); + + keys = keyList.toArray(keys); + values = valueList.toArray(values); + } + + public Multimap convertProxy() { + Multimap map = ArrayListMultimap.create(); + + for (int i = 0; i < size; i++) { + map.put(keys[i], values[i]); + } + + return map; + } + +} diff --git a/src/resources/objects/SWGList.java b/src/resources/objects/SWGList.java index 7f979e4c..cbef0018 100644 --- a/src/resources/objects/SWGList.java +++ b/src/resources/objects/SWGList.java @@ -54,6 +54,7 @@ public class SWGList implements List { this.viewType = (byte) viewType; this.updateType = (short) updateType; } + @Override public boolean add(E e) { synchronized(objectMutex) { @@ -64,6 +65,7 @@ public class SWGList implements List { return false; } } + @Override public void add(int index, E element) { synchronized(objectMutex) { @@ -73,6 +75,7 @@ public class SWGList implements List { } } } + @Override public boolean addAll(Collection c) { synchronized(objectMutex) { @@ -101,6 +104,7 @@ public class SWGList implements List { return false; } } + @Override public boolean addAll(int index, Collection c) { synchronized(objectMutex) { @@ -125,6 +129,7 @@ public class SWGList implements List { return false; } } + @Override public void clear() { synchronized(objectMutex) { @@ -132,63 +137,74 @@ public class SWGList implements List { queue(item(4, 0, null, false, false)); } } + @Override public boolean contains(Object o) { synchronized(objectMutex) { return list.contains(o); } } + @Override public boolean containsAll(Collection c) { synchronized(objectMutex) { return list.containsAll(c); } } + @Override public E get(int index) { synchronized(objectMutex) { return list.get(index); } } + public List get() { return list; } + @Override public int indexOf(Object o) { synchronized(objectMutex) { return list.indexOf(o); } } + @Override public boolean isEmpty() { synchronized(objectMutex) { return list.isEmpty(); } } + @Override public Iterator iterator() { synchronized(objectMutex) { return list.iterator(); } } + @Override public int lastIndexOf(Object o) { synchronized(objectMutex) { return list.lastIndexOf(o); } } + @Override public ListIterator listIterator() { synchronized(objectMutex) { return list.listIterator(); } } + @Override public ListIterator listIterator(int index) { synchronized(objectMutex) { return listIterator(index); } } + @Override public boolean remove(Object o) { synchronized(objectMutex) { @@ -202,6 +218,7 @@ public class SWGList implements List { } } } + @Override public E remove(int index) { synchronized(objectMutex) { @@ -212,6 +229,7 @@ public class SWGList implements List { return (E) element; } } + @Override public boolean removeAll(Collection c) { synchronized(objectMutex) { @@ -239,12 +257,14 @@ public class SWGList implements List { return false; } } + @Override public boolean retainAll(Collection c) { synchronized(objectMutex) { return list.retainAll(c); } } + @Override public E set(int index, E element) { synchronized(objectMutex) { @@ -287,24 +307,28 @@ public class SWGList implements List { return false; } } + @Override public int size() { synchronized(objectMutex) { return list.size(); } } + @Override public List subList(int fromIndex, int toIndex) { synchronized(objectMutex) { return list.subList(fromIndex, toIndex); } } + @Override public Object[] toArray() { synchronized(objectMutex) { return list.toArray(); } } + @Override public T[] toArray(T[] a) { synchronized(objectMutex) { @@ -332,7 +356,7 @@ public class SWGList implements List { return buffer.array(); } - + private void queue(byte[] data) { IoBuffer buffer = messageBuilder.bufferPool.allocate((data.length + 8), false).order(ByteOrder.LITTLE_ENDIAN); buffer.putInt(1); @@ -355,5 +379,5 @@ public class SWGList implements List { messageBuilder.sendListDelta(viewType, updateType, buffer); } - + } diff --git a/src/resources/objects/SWGMap.java b/src/resources/objects/SWGMap.java index ebb8c980..d3485f93 100644 --- a/src/resources/objects/SWGMap.java +++ b/src/resources/objects/SWGMap.java @@ -35,21 +35,24 @@ import org.apache.mina.core.buffer.IoBuffer; import resources.common.StringUtilities; import com.sleepycat.persist.model.NotPersistent; +import com.sleepycat.persist.model.Persistent; @SuppressWarnings("unused") +@Persistent public class SWGMap implements Map { private Map map = new TreeMap(); @NotPersistent - private int updateCounter; - + private int updateCounter = 0; private ObjectMessageBuilder messageBuilder; private byte viewType; private short updateType; - + @NotPersistent protected final Object objectMutex = new Object(); + public SWGMap() { } + public SWGMap(ObjectMessageBuilder messageBuilder, int viewType, int updateType) { this.messageBuilder = messageBuilder; this.viewType = (byte) viewType; @@ -65,10 +68,6 @@ public class SWGMap implements Map { } } - public SWGMap() { - - } - public void clear() { throw new UnsupportedOperationException(); } @@ -195,6 +194,10 @@ public class SWGMap implements Map { } } + public Object getMutex() { + return objectMutex; + } + private byte[] item(int type, Object index, byte[] data, boolean useIndex, boolean useData) { if (useIndex && !(index instanceof Byte) && !(index instanceof Short) && !(index instanceof Integer) && !(index instanceof Float) diff --git a/src/resources/objects/SWGMultiMap.java b/src/resources/objects/SWGMultiMap.java index ab18a5c9..a73157fe 100644 --- a/src/resources/objects/SWGMultiMap.java +++ b/src/resources/objects/SWGMultiMap.java @@ -41,21 +41,24 @@ import org.python.google.common.collect.TreeMultimap; import resources.common.StringUtilities; import com.sleepycat.persist.model.NotPersistent; +import com.sleepycat.persist.model.Persistent; @SuppressWarnings("unused") +@Persistent public class SWGMultiMap implements Multimap { private Multimap map = ArrayListMultimap.create(); @NotPersistent - private int updateCounter; - + private int updateCounter = 0; private ObjectMessageBuilder messageBuilder; private byte viewType; private short updateType; - + @NotPersistent protected final Object objectMutex = new Object(); + public SWGMultiMap() { } + public SWGMultiMap(ObjectMessageBuilder messageBuilder, int viewType, int updateType) { this.messageBuilder = messageBuilder; this.viewType = (byte) viewType; @@ -71,10 +74,6 @@ public class SWGMultiMap implements Multimap { } } - public SWGMultiMap() { - - } - public Map> asMap() { synchronized(objectMutex) { return map.asMap(); @@ -284,6 +283,10 @@ public class SWGMultiMap implements Multimap { } } + public Object getMutex() { + return objectMutex; + } + private byte[] item(int type, Object index, byte[] data, boolean useIndex, boolean useData) { if (useIndex && !(index instanceof Byte) && !(index instanceof Short) && !(index instanceof Integer) && !(index instanceof Float) diff --git a/src/resources/objects/guild/GuildObject.java b/src/resources/objects/guild/GuildObject.java index 1dd0278a..0107ff79 100644 --- a/src/resources/objects/guild/GuildObject.java +++ b/src/resources/objects/guild/GuildObject.java @@ -21,6 +21,9 @@ ******************************************************************************/ package resources.objects.guild; +import java.util.Map; +import java.util.TreeMap; + import org.apache.mina.core.buffer.IoBuffer; import main.NGECore; @@ -33,19 +36,28 @@ import resources.objects.SWGList; import resources.objects.SWGMap; import resources.objects.SWGMultiMap; +import com.sleepycat.je.Environment; +import com.sleepycat.je.Transaction; +import com.sleepycat.persist.model.Entity; import com.sleepycat.persist.model.NotPersistent; import engine.clients.Client; +import engine.resources.objects.IPersistent; import engine.resources.objects.SWGObject; import engine.resources.scene.Planet; import engine.resources.scene.Point3D; import engine.resources.scene.Quaternion; -public class GuildObject extends SWGObject { +@Entity +public class GuildObject extends SWGObject implements IPersistent { protected NGECore core; @NotPersistent private GuildMessageBuilder messageBuilder = new GuildMessageBuilder(this); + + private Map> zoneMap = new TreeMap>(); + @NotPersistent + private Transaction txn; // GILD 3 private float complexity = 0x803F0F00; @@ -242,6 +254,12 @@ public class GuildObject extends SWGObject { notifyAll(messageBuilder.buildUnknown3(unknown3)); } + public Map> getZoneMap() { + synchronized(objectMutex) { + return zoneMap; + } + } + @Override public void sendBaselines(Client destination) { destination.getSession().write(messageBuilder.buildBaseline3()); @@ -256,4 +274,12 @@ public class GuildObject extends SWGObject { } } + public Transaction getTransaction() { + return txn; + } + + public void createTransaction(Environment env) { + txn = env.beginTransaction(null, null); + } + } diff --git a/src/resources/objects/player/PlayerMessageBuilder.java b/src/resources/objects/player/PlayerMessageBuilder.java index e121fbf3..9891a3a5 100644 --- a/src/resources/objects/player/PlayerMessageBuilder.java +++ b/src/resources/objects/player/PlayerMessageBuilder.java @@ -22,7 +22,6 @@ package resources.objects.player; import java.nio.ByteOrder; -import java.util.List; import java.util.Map.Entry; import org.apache.mina.core.buffer.IoBuffer; diff --git a/src/resources/objects/player/PlayerObject.java b/src/resources/objects/player/PlayerObject.java index 6f732952..8e4445fd 100644 --- a/src/resources/objects/player/PlayerObject.java +++ b/src/resources/objects/player/PlayerObject.java @@ -26,7 +26,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import resources.objects.SWGList; import resources.objects.waypoint.WaypointObject; import com.sleepycat.persist.model.NotPersistent; diff --git a/src/services/chat/ChatService.java b/src/services/chat/ChatService.java index faa920a8..f8f7123c 100644 --- a/src/services/chat/ChatService.java +++ b/src/services/chat/ChatService.java @@ -22,11 +22,8 @@ package services.chat; import java.nio.ByteOrder; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Date; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Random; @@ -55,14 +52,12 @@ import protocol.swg.ChatFriendsListUpdate; import protocol.swg.ChatInstantMessageToCharacter; import protocol.swg.ChatInstantMessagetoClient; import protocol.swg.ChatOnAddFriend; -import protocol.swg.ChatOnGetFriendsList; import protocol.swg.ChatOnSendInstantMessage; import protocol.swg.ChatOnSendPersistentMessage; import protocol.swg.ChatPersistentMessageToClient; import protocol.swg.ChatPersistentMessageToServer; import protocol.swg.ChatRequestPersistentMessage; import protocol.swg.ObjControllerMessage; -import protocol.swg.clientSecureTradeManager.AddItemMessage; import protocol.swg.objectControllerObjects.PlayerEmote; import protocol.swg.objectControllerObjects.SpatialChat; import main.NGECore; diff --git a/src/services/gcw/GCWService.java b/src/services/gcw/GCWService.java index 0bd34d86..ae91af89 100644 --- a/src/services/gcw/GCWService.java +++ b/src/services/gcw/GCWService.java @@ -21,21 +21,19 @@ ******************************************************************************/ package services.gcw; +import java.math.BigDecimal; +import java.math.MathContext; import java.nio.ByteOrder; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Random; +import java.util.Map.Entry; import java.util.TreeMap; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import org.apache.mina.core.buffer.IoBuffer; -import org.apache.mina.core.buffer.SimpleBufferAllocator; import org.apache.mina.core.session.IoSession; import org.python.google.common.collect.ArrayListMultimap; import org.python.google.common.collect.Multimap; @@ -43,12 +41,9 @@ import org.python.google.common.collect.Multimap; import protocol.swg.GcwGroupsRsp; import protocol.swg.GcwRegionsReq; import protocol.swg.GcwRegionsRsp; -import protocol.swg.GetMapLocationsMessage; -import protocol.swg.GetMapLocationsResponseMessage; -import resources.common.Factions; +import resources.common.FactionStatus; import resources.common.Opcodes; -import resources.common.PvpStatus; import resources.gcw.CurrentServerGCWZoneHistory; import resources.gcw.CurrentServerGCWZonePercent; import resources.gcw.OtherServerGCWZonePercent; @@ -60,17 +55,14 @@ import main.NGECore; import engine.clients.Client; import engine.resources.objects.SWGObject; import engine.resources.scene.Point2D; -import engine.resources.scene.Point3D; import engine.resources.service.INetworkDispatch; import engine.resources.service.INetworkRemoteEvent; -@SuppressWarnings("unused") - public class GCWService implements INetworkDispatch { private NGECore core; private GuildObject object; - private Map> zoneMap = new TreeMap>(); + private Map> zoneMap() { return object.getZoneMap(); } private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); @@ -98,24 +90,53 @@ public class GCWService implements INetworkDispatch { private void checkFactionalPresence() { try { - for (String planet : zoneMap.keySet()) { - for (String zoneName : zoneMap.get(planet).keySet()) { - CurrentServerGCWZonePercent zone = zoneMap.get(planet).get(zoneName); - - if (zone.getRadius() > 0) { - List players = core.simulationService.get(core.terrainService.getPlanetByName(planet), zone.getPosition().x, zone.getPosition().z, (int) zone.getRadius()); + List flagged = getSFPlayers(); + + for (SWGObject player : flagged) { + if (player.getParentId() == 0) { + if (!core.terrainService.isWater(player.getPlanetId(), player.getPosition().x, player.getPosition().z)) { + String planet = player.getPlanet().getName(); + boolean inContestedRegion = false; - for (SWGObject player : players) { - if (!core.terrainService.isWater(player.getPlanetId(), player.getPosition().x, player.getPosition().z)) { - if ((player instanceof CreatureObject)) { - if (((CreatureObject) player).getParentId() > 0) { - if (((CreatureObject) player).getFactionStatus() == 2) { - adjustZone(planet, zoneName, ((CreatureObject) player).getFaction(), 1); + if (zoneMap().containsKey(planet)) { + for (String zoneName : zoneMap().get(planet).keySet()) { + CurrentServerGCWZonePercent zone = zoneMap().get(planet).get(zoneName).clone(); + + if (zone.getRadius() > 0) { + List objects = core.simulationService.get(core.terrainService.getPlanetByName(planet), zone.getPosition().x, zone.getPosition().z, (int) zone.getRadius()); + + if (objects.contains(player)) { + inContestedRegion = true; + + if ((player instanceof CreatureObject)) { + if (((CreatureObject) player).getFactionStatus() == FactionStatus.SpecialForces) { + adjustZone(planet, zoneName, ((CreatureObject) player).getFaction(), 1); + break; + } } } } } } + + if (!inContestedRegion) { + if ((player instanceof CreatureObject)) { + if (((CreatureObject) player).getFactionStatus() == FactionStatus.SpecialForces) { + String zone = ""; + + for (Entry entry : zoneMap().get(planet).entrySet()) { + if (entry.getValue().getType() == 1) { + zone = entry.getKey(); + break; + } + } + + if (zone.length() != 0) { + adjustZone(planet, zone, ((CreatureObject) player).getFaction(), 1); + } + } + } + } } } } @@ -123,7 +144,7 @@ public class GCWService implements INetworkDispatch { e.printStackTrace(); } } - }, 3, 3, TimeUnit.SECONDS); + }, 5, 10, TimeUnit.SECONDS); scheduler.scheduleAtFixedRate(new Runnable() { @Override public void run() { updateGCWZones(); } @@ -135,38 +156,45 @@ public class GCWService implements INetworkDispatch { Multimap zoneHistoryUpdates = ArrayListMultimap.create(); Multimap totalHistoryUpdates = ArrayListMultimap.create(); - int galaxyPercent = 0; + BigDecimal galaxyPercent = new BigDecimal("0.0", MathContext.DECIMAL128); - for (String planet : zoneMap.keySet()) { + for (String planet : zoneMap().keySet()) { if (!planet.equals("galaxy")) { - int planetPercent = 0; + BigDecimal planetPercent = new BigDecimal("0.0", MathContext.DECIMAL128); - for (String zone : zoneMap.get(planet).keySet()) { - planetPercent += zoneMap.get(planet).get(zone).getPercent(); + for (String zone : zoneMap().get(planet).keySet()) { + BigDecimal zonePercent; - if (zoneMap.get(planet).get(zone).getPercent() != object.getCurrentServerGCWZonePercentMap().get(zone).getPercent()) { - zoneUpdates.put(zone, zoneMap.get(planet).get(zone)); + zonePercent = zoneMap().get(planet).get(zone).getPercent(); + zonePercent = zonePercent.multiply(zoneMap().get(planet).get(zone).getWeight()); + zonePercent = zonePercent.divide((new BigDecimal("100.0", MathContext.DECIMAL128))); + planetPercent = planetPercent.add(zonePercent); + + if (((int) zoneMap().get(planet).get(zone).getPercent().intValue()) != ((int) object.getCurrentServerGCWZonePercentMap().get(zone).getPercent().intValue())) { + zoneUpdates.put(zone, zoneMap().get(planet).get(zone).clone()); zoneHistoryUpdates.put(zone, new CurrentServerGCWZoneHistory(object.getCurrentServerGCWZonePercentMap().get(zone))); } } - planetPercent = ((planetPercent / (zoneMap.get(planet).size() * 100)) * 100); + //System.out.println("Percent for " + planet + ": " + planetPercent.doubleValue()); - if (planetPercent != object.getCurrentServerGCWTotalPercentMap().get(planet).getPercent()) { - CurrentServerGCWZonePercent planetObject = object.getCurrentServerGCWTotalPercentMap().get(planet); + galaxyPercent = galaxyPercent.add(planetPercent); + + if (((int) planetPercent.intValue()) != ((int) object.getCurrentServerGCWTotalPercentMap().get(planet).getPercent().intValue())) { + CurrentServerGCWZonePercent planetObject = object.getCurrentServerGCWTotalPercentMap().get(planet).clone(); planetObject.setPercent(planetPercent); totalUpdates.put(planet, planetObject); totalHistoryUpdates.put(planet, new CurrentServerGCWZoneHistory(object.getCurrentServerGCWTotalPercentMap().get(planet))); } - - galaxyPercent += planetPercent; } } - galaxyPercent = ((galaxyPercent / ((object.getCurrentServerGCWTotalPercentMap().size() - 1) * 100)) * 100); + galaxyPercent = galaxyPercent.divide((new BigDecimal((Integer.toString((object.getCurrentServerGCWTotalPercentMap().size() - 1))), MathContext.DECIMAL128))); + + //System.out.println("Percent for galaxy: " + galaxyPercent.doubleValue()); - if (galaxyPercent != object.getCurrentServerGCWTotalPercentMap().get("galaxy").getPercent()) { - CurrentServerGCWZonePercent galaxyObject = object.getCurrentServerGCWTotalPercentMap().get("galaxy"); + if (((int) galaxyPercent.intValue()) != ((int) object.getCurrentServerGCWTotalPercentMap().get("galaxy").getPercent().intValue())) { + CurrentServerGCWZonePercent galaxyObject = object.getCurrentServerGCWTotalPercentMap().get("galaxy").clone(); galaxyObject.setPercent(galaxyPercent); totalUpdates.put("galaxy", galaxyObject); totalHistoryUpdates.put("galaxy", new CurrentServerGCWZoneHistory(object.getCurrentServerGCWTotalPercentMap().get("galaxy"))); @@ -200,11 +228,11 @@ public class GCWService implements INetworkDispatch { galaxyWideZones.addAll(object.getOtherServerGCWZonePercentMap().get("SWG")); for (int i = 0; i < galaxyWideZones.size(); i++) { - OtherServerGCWZonePercent zone = galaxyWideZones.get(i); - int percent = object.getCurrentServerGCWZonePercentMap().get(zone.getZone()).getPercent(); + OtherServerGCWZonePercent zone = galaxyWideZones.get(i).clone(); + BigDecimal percent = object.getCurrentServerGCWZonePercentMap().get(zone.getZone()).getPercent(); - if (zone.getPercent() != percent) { - zone.setPercent(percent); + if (((int) zone.getPercent()) != percent.intValue()) { + zone.setPercent(percent.intValue()); galaxyWideZones.set(i, zone); } } @@ -223,11 +251,10 @@ public class GCWService implements INetworkDispatch { private void decrementZoneStrength() { try { - for (String planet : zoneMap.keySet()) { + for (String planet : zoneMap().keySet()) { if (!planet.equals("galaxy")) { - for (String zone : zoneMap.get(planet).keySet()) { - zoneMap.get(planet).get(zone).removeGCWPoints(1); - object.getCurrentServerGCWZonePercentMap().get(zone).removeGCWPoints(1); + for (String zone : zoneMap().get(planet).keySet()) { + zoneMap().get(planet).get(zone).removeGCWPoints(1); } } } @@ -242,13 +269,13 @@ public class GCWService implements INetworkDispatch { private void resetWeakGCWZones() { try { - for (String planet : zoneMap.keySet()) { - for (String zoneName : zoneMap.get(planet).keySet()) { - CurrentServerGCWZonePercent zone = zoneMap.get(planet).get(zoneName); + for (String planet : zoneMap().keySet()) { + for (String zoneName : zoneMap().get(planet).keySet()) { + CurrentServerGCWZonePercent zone = zoneMap().get(planet).get(zoneName).clone(); - if (zone.getGCWPoints() == 0 && zone.getPercent() != 50) { - zone.setPercent(50); - zoneMap.get(planet).put(zoneName, zone); + if ((zone.getGCWPoints() == 1) && (((int) zone.getPercent().intValue()) != 50)) { + zone.setPercent((new BigDecimal("50.0", MathContext.DECIMAL128))); + zoneMap().get(planet).put(zoneName, zone); } } } @@ -259,57 +286,106 @@ public class GCWService implements INetworkDispatch { }, 2, 2, TimeUnit.DAYS); } - public void addZone(String planet, String zone, float x, float y, float radius, int group, float weight) { - if (!zoneMap.containsKey(planet)) { - zoneMap.put(planet, new TreeMap()); - } + public void addZone(String planet, String zone, float x, float z, float radius, int weight, int type) { + CurrentServerGCWZonePercent zoneObject; - zoneMap.get(planet).put(zone, new CurrentServerGCWZonePercent(new Point2D(x, y), radius, group, weight)); - - if (planet != "galaxy") { - object.getCurrentServerGCWZonePercentMap().put(zone, zoneMap.get(planet).get(zone)); - object.getOtherServerGCWZonePercentMap().put("SWG", new OtherServerGCWZonePercent(zone)); - } - - if (!object.getCurrentServerGCWTotalPercentMap().containsKey(planet)) { + if (!zoneMap().containsKey(planet)) { + zoneMap().put(planet, new TreeMap()); object.getCurrentServerGCWTotalPercentMap().put(planet, new CurrentServerGCWZonePercent(new Point2D(0, 0), 0, 0, 0)); + object.getCurrentServerGCWTotalHistoryMap().put(planet, new CurrentServerGCWZoneHistory(object.getCurrentServerGCWTotalPercentMap().get(planet).clone())); object.getOtherServerGCWTotalPercentMap().put("SWG", new OtherServerGCWZonePercent(planet)); } + + if (zoneMap().get(planet).containsKey(zone)) { + zoneObject = zoneMap().get(planet).get(zone); + + if (zoneObject.getPosition().x != x) { + zoneObject.getPosition().x = x; + } + + if (zoneObject.getPosition().z != z) { + zoneObject.getPosition().z = z; + } + + if (zoneObject.getRadius() != radius) { + zoneObject.setRadius(radius); + } + + if (zoneObject.getWeight().unscaledValue().intValue() != weight) { + zoneObject.setWeight(weight); + } + + if (zoneObject.getType() != type) { + zoneObject.setType(type); + } + } else { + zoneObject = new CurrentServerGCWZonePercent(new Point2D(x, z), radius, weight, type); + + zoneMap().get(planet).put(zone, zoneObject); + + if (!planet.equals("galaxy")) { + object.getCurrentServerGCWZonePercentMap().put(zone, zoneMap().get(planet).get(zone).clone()); + object.getCurrentServerGCWZoneHistoryMap().put(zone, new CurrentServerGCWZoneHistory(zoneMap().get(planet).get(zone).clone())); + object.getOtherServerGCWZonePercentMap().put("SWG", new OtherServerGCWZonePercent(zone)); + } + } } public void adjustZone(String planet, String zone, String faction, int amount) { synchronized(objectMutex) { - CurrentServerGCWZonePercent zoneObject = zoneMap.get(planet).get(zone); - int newPercent = ((amount / zoneObject.getGCWPoints()) * 100); + CurrentServerGCWZonePercent zoneObject = zoneMap().get(planet).get(zone).clone(); + BigDecimal newPercent = new BigDecimal(Double.toString(((((double) amount) / ((double) zoneObject.getGCWPoints())) * ((double) 100.0))), MathContext.DECIMAL128); switch (faction) { case "rebel": { - zoneMap.get(planet).get(zone).setPercent(((zoneObject.getPercent() - newPercent) < 0) ? 0 : (zoneObject.getPercent() - newPercent)); - zoneMap.get(planet).get(zone).addGCWPoints(amount); + newPercent = newPercent.multiply(zoneObject.getPercent()).divide((new BigDecimal("100.0", MathContext.DECIMAL128))); + zoneMap().get(planet).get(zone).setPercent(((zoneObject.getPercent().subtract(newPercent).intValue() < 0) ? (new BigDecimal("0.0", MathContext.DECIMAL128)) : (zoneObject.getPercent().subtract(newPercent)))); + zoneMap().get(planet).get(zone).addGCWPoints(amount); + break; } case "imperial": { - zoneMap.get(planet).get(zone).setPercent(((zoneObject.getPercent() + newPercent) > 100) ? 0 : (zoneObject.getPercent() + newPercent)); - zoneMap.get(planet).get(zone).addGCWPoints(amount); + newPercent = newPercent.multiply(((new BigDecimal("100.0", MathContext.DECIMAL128).subtract(zoneObject.getPercent())))).divide((new BigDecimal("100.0", MathContext.DECIMAL128))); + zoneMap().get(planet).get(zone).setPercent(((zoneObject.getPercent().subtract(newPercent).intValue() > 100) ? (new BigDecimal("100.0", MathContext.DECIMAL128)) : (zoneObject.getPercent().add(newPercent)))); + zoneMap().get(planet).get(zone).addGCWPoints(amount); + break; } } + } } public void adjustZone(String zone, String faction, int amount) { - for (String planet : zoneMap.keySet()) { + for (String planet : zoneMap().keySet()) { if (!planet.equals("galaxy")) { - if (zoneMap.get(planet).containsKey(zone)) { + if (zoneMap().get(planet).containsKey(zone)) { adjustZone(planet, zone, faction, amount); } } } } + public List getSFPlayers() { + List flagged = new ArrayList(); + + synchronized(core.getActiveConnectionsMap()) { + for (Client client : core.getActiveConnectionsMap().values()) { + if (client.getParent() != null) { + if (client.getParent() instanceof CreatureObject) { + if (((CreatureObject) client.getParent()).getFactionStatus() == 2) { + flagged.add(client.getParent()); + } + } + } + } + } + + return flagged; + } + public void insertOpcodes(Map swgOpcodes, Map objControllerOpcodes) { swgOpcodes.put(Opcodes.GcwRegionsReq, new INetworkRemoteEvent() { - @Override public void handlePacket(IoSession session, IoBuffer data) throws Exception { data.order(ByteOrder.LITTLE_ENDIAN); @@ -330,8 +406,8 @@ public class GCWService implements INetworkDispatch { return; } - session.write((new GcwRegionsRsp(zoneMap)).serialize()); - session.write((new GcwGroupsRsp(zoneMap)).serialize()); + session.write((new GcwRegionsRsp(zoneMap())).serialize()); + session.write((new GcwGroupsRsp(zoneMap())).serialize()); } diff --git a/src/services/guild/GuildService.java b/src/services/guild/GuildService.java index 80163d63..1a309fc0 100644 --- a/src/services/guild/GuildService.java +++ b/src/services/guild/GuildService.java @@ -41,7 +41,15 @@ public class GuildService implements INetworkDispatch { public GuildService(NGECore core) { this.core = core; - object = (GuildObject) this.core.objectService.createObject("object/guild/shared_guild_object.iff", core.terrainService.getPlanetList().get(0)); + for (SWGObject swgObject : core.objectService.getObjectList()) { + if (swgObject.getTemplate().equals("object/guild/shared_guild_object.iff") && swgObject instanceof GuildObject) { + object = (GuildObject) swgObject; + } + } + + if (object == null) { + object = (GuildObject) this.core.objectService.createObject("object/guild/shared_guild_object.iff", core.terrainService.getPlanetList().get(0)); + } } public Guild createGuild(String abbreviation, String name, SWGObject leader) {