| 182 | | |
|---|
| 183 | | ship.setEnergy((int)Math.floor(ship.getEnergy() * factor.get("eps"))); |
|---|
| 184 | | ship.setHull((int)Math.floor(ship.getHull() * factor.get("hull"))); |
|---|
| 185 | | ship.setCrew((int)Math.floor(ship.getCrew() * factor.get("crew"))); |
|---|
| 186 | | ship.setShields((int)Math.floor(ship.getShields() * factor.get("shields"))); |
|---|
| 187 | | ship.setAblativeArmor((int)Math.floor(ship.getAblativeArmor() * factor.get("ablativearmor"))); |
|---|
| 188 | | ship.setMarines((int)Math.floor(ship.getMarines() * factor.get("marines"))); |
|---|
| 189 | | |
|---|
| 190 | | ship.recalculateModules(); |
|---|
| 191 | | |
|---|
| 192 | | String id = "l " + ship.getId(); |
|---|
| 193 | | int fighterDocks = ship.getTypeData().getJDocks(); |
|---|
| 194 | | if (ship.getLandedCount() > fighterDocks) |
|---|
| | 182 | try |
|---|
| 196 | | List fighters = db.createQuery("from Ship where docked = ?").setString(0, id).list(); |
|---|
| 197 | | long toStart = ship.getLandedCount() - fighterDocks; |
|---|
| 198 | | int fighterCount = 0; |
|---|
| 199 | | |
|---|
| 200 | | for (Iterator iter2 = fighters.iterator(); iter2.hasNext() && fighterCount < toStart;) |
|---|
| 201 | | { |
|---|
| 202 | | Ship fighter = (Ship) iter2.next(); |
|---|
| 203 | | |
|---|
| 204 | | fighter.setDocked(""); |
|---|
| 205 | | fighterCount++; |
|---|
| | 184 | ship.setEnergy((int)Math.floor(ship.getEnergy() * factor.get("eps"))); |
|---|
| | 185 | ship.setHull((int)Math.floor(ship.getHull() * factor.get("hull"))); |
|---|
| | 186 | ship.setCrew((int)Math.floor(ship.getCrew() * factor.get("crew"))); |
|---|
| | 187 | ship.setShields((int)Math.floor(ship.getShields() * factor.get("shields"))); |
|---|
| | 188 | ship.setAblativeArmor((int)Math.floor(ship.getAblativeArmor() * factor.get("ablativearmor"))); |
|---|
| | 189 | ship.setMarines((int)Math.floor(ship.getMarines() * factor.get("marines"))); |
|---|
| | 190 | |
|---|
| | 191 | ship.recalculateModules(); |
|---|
| | 192 | |
|---|
| | 193 | String id = "l " + ship.getId(); |
|---|
| | 194 | int fighterDocks = ship.getTypeData().getJDocks(); |
|---|
| | 195 | if (ship.getLandedCount() > fighterDocks) |
|---|
| | 196 | { |
|---|
| | 197 | List fighters = db.createQuery("from Ship where docked = ?").setString(0, id).list(); |
|---|
| | 198 | long toStart = ship.getLandedCount() - fighterDocks; |
|---|
| | 199 | int fighterCount = 0; |
|---|
| | 200 | |
|---|
| | 201 | for (Iterator iter2 = fighters.iterator(); iter2.hasNext() && fighterCount < toStart;) |
|---|
| | 202 | { |
|---|
| | 203 | Ship fighter = (Ship) iter2.next(); |
|---|
| | 204 | |
|---|
| | 205 | fighter.setDocked(""); |
|---|
| | 206 | fighterCount++; |
|---|
| | 207 | } |
|---|
| | 208 | } |
|---|
| | 209 | |
|---|
| | 210 | //Docked |
|---|
| | 211 | id = Integer.toString(ship.getId()); |
|---|
| | 212 | int outerDocks = ship.getTypeData().getADocks(); |
|---|
| | 213 | if (ship.getDockedCount() > outerDocks) |
|---|
| | 214 | { |
|---|
| | 215 | List outerDocked = db.createQuery("from Ship where docked = ?").setString(0, id).list(); |
|---|
| | 216 | long toStart = ship.getDockedCount() - outerDocks; |
|---|
| | 217 | int dockedCount = 0; |
|---|
| | 218 | |
|---|
| | 219 | for (Iterator iter2 = outerDocked.iterator(); iter2.hasNext() && dockedCount < toStart;) |
|---|
| | 220 | { |
|---|
| | 221 | Ship outer = (Ship) iter2.next(); |
|---|
| | 222 | outer.setDocked(""); |
|---|
| | 223 | |
|---|
| | 224 | dockedCount++; |
|---|
| | 225 | } |
|---|
| | 226 | } |
|---|
| | 227 | |
|---|
| | 228 | if(ship.getId() >= 0) |
|---|
| | 229 | { |
|---|
| | 230 | ship.recalculateShipStatus(); |
|---|
| | 231 | } |
|---|
| | 232 | |
|---|
| | 233 | count++; |
|---|
| | 234 | if (count % 20 == 0) |
|---|
| | 235 | { |
|---|
| | 236 | db.flush(); |
|---|
| | 237 | HibernateFacade.evictAll(db, Ship.class, ShipModules.class, Offizier.class); |
|---|
| 214 | | List outerDocked = db.createQuery("from Ship where docked = ?").setString(0, id).list(); |
|---|
| 215 | | long toStart = ship.getDockedCount() - outerDocks; |
|---|
| 216 | | int dockedCount = 0; |
|---|
| 217 | | |
|---|
| 218 | | for (Iterator iter2 = outerDocked.iterator(); iter2.hasNext() && dockedCount < toStart;) |
|---|
| 219 | | { |
|---|
| 220 | | Ship outer = (Ship) iter2.next(); |
|---|
| 221 | | outer.setDocked(""); |
|---|
| 222 | | |
|---|
| 223 | | dockedCount++; |
|---|
| 224 | | } |
|---|
| 225 | | } |
|---|
| 226 | | |
|---|
| 227 | | ship.recalculateShipStatus(); |
|---|
| 228 | | |
|---|
| 229 | | count++; |
|---|
| 230 | | if (count % 20 == 0) |
|---|
| 231 | | { |
|---|
| 232 | | db.flush(); |
|---|
| 233 | | HibernateFacade.evictAll(db, Ship.class, ShipModules.class, Offizier.class); |
|---|
| | 242 | //Riskant, aber, dass nach einem Fehler alle anderen Schiffe nicht aktualisiert werden muss verhindert werden |
|---|
| | 243 | Common.LOG.error("Das Schiff mit der ID " + ship.getId() + " konnte nicht aktualisiert werden. Fehler: " + e.getMessage()); |
|---|
| 245 | | battleShip.setShields((int)Math.floor(battleShip.getShields() * factor.get("shields"))); |
|---|
| 246 | | battleShip.setHull((int)Math.floor(battleShip.getHull() * factor.get("hull"))); |
|---|
| 247 | | battleShip.setAblativeArmor((int)Math.floor(battleShip.getAblativeArmor() * factor.get("ablativearmor"))); |
|---|
| 248 | | count++; |
|---|
| 249 | | //All unflushed changes are part of the sessioncache, so we need to clean it regularly |
|---|
| 250 | | if (count % 20 == 0) |
|---|
| | 255 | try |
|---|
| | 256 | { |
|---|
| | 257 | battleShip.setShields((int)Math.floor(battleShip.getShields() * factor.get("shields"))); |
|---|
| | 258 | battleShip.setHull((int)Math.floor(battleShip.getHull() * factor.get("hull"))); |
|---|
| | 259 | battleShip.setAblativeArmor((int)Math.floor(battleShip.getAblativeArmor() * factor.get("ablativearmor"))); |
|---|
| | 260 | count++; |
|---|
| | 261 | //All unflushed changes are part of the sessioncache, so we need to clean it regularly |
|---|
| | 262 | if (count % 20 == 0) |
|---|
| | 263 | { |
|---|
| | 264 | db.flush(); |
|---|
| | 265 | HibernateFacade.evictAll(db, BattleShip.class, Ship.class); |
|---|
| | 266 | } |
|---|
| | 267 | } |
|---|
| | 268 | catch(Exception e) |
|---|