Skip to content

Commit

Permalink
Fix Bugs in the Troops manager / TroopsHolder
Browse files Browse the repository at this point in the history
  • Loading branch information
extremeCrazyCoder committed Aug 26, 2020
1 parent ecfee4a commit bb71148
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
23 changes: 12 additions & 11 deletions Core/src/main/java/de/tor/tribes/util/troops/TroopsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public VillageTroopsHolder getTroopsForVillage(Village pVillage, TROOP_TYPE pTyp
if (pType.equals(TROOP_TYPE.SUPPORT)) {
newHolder = new SupportVillageTroopsHolder(pVillage, new Date());
} else {
newHolder = new VillageTroopsHolder(pVillage, null);
newHolder = new VillageTroopsHolder(pVillage, new Date(0));
}
addManagedElement(group, newHolder);
return newHolder;
Expand Down Expand Up @@ -487,18 +487,19 @@ public void updateInformation(FightReport pReport) {
Village v = pReport.getTargetVillage();
if(! pReport.getDefender().equals(v.getTribe())) return;

VillageTroopsHolder own = getTroopsForVillage(v, TROOP_TYPE.IN_VILLAGE, true);
VillageTroopsHolder outwards = getTroopsForVillage(v, TROOP_TYPE.OUTWARDS, true);
if(own.getState() == null || own.getState().getTime() < pReport.getTimestamp()) {
TroopAmountFixed surviving = pReport.getSurvivingDefenders();
if(surviving != null) {
own.setTroops(surviving);
own.setState(new Date(pReport.getTimestamp()));
TroopAmountFixed surviving = pReport.getSurvivingDefenders();
if(surviving != null) {
VillageTroopsHolder own = getTroopsForVillage(v, TROOP_TYPE.IN_VILLAGE, true);
if(own.getState() == null || own.getState().getTime() < pReport.getTimestamp()) {
own.setTroops(surviving);
own.setState(new Date(pReport.getTimestamp()));
}
}
if(outwards.getState() == null || outwards.getState().getTime() < pReport.getTimestamp()) {
TroopAmountFixed defOTW = pReport.getDefendersOnTheWay();
if(defOTW != null && defOTW.containsInformation()) {

TroopAmountFixed defOTW = pReport.getDefendersOnTheWay();
if(defOTW != null && defOTW.containsInformation()) {
VillageTroopsHolder outwards = getTroopsForVillage(v, TROOP_TYPE.OUTWARDS, true);
if(outwards.getState() == null || outwards.getState().getTime() < pReport.getTimestamp()) {
outwards.setTroops(defOTW);
outwards.setState(new Date(pReport.getTimestamp()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public void loadFromXml(Element e) {

@Override
public Element toXml(String elementName) {
if(state == null) {
state = new Date(0);
logger.error("Found empty state: {}", village);
}

Element troopInfo = new Element(elementName);
troopInfo.setAttribute("type", "normal");
troopInfo.addContent(new Element("id").setText(Integer.toString(village.getId())));
Expand Down

0 comments on commit bb71148

Please sign in to comment.