Changeset 8f9e52279a0268453622470ae513c0f6e074289f
- Timestamp:
- 10/21/07 11:07:14 (1 year ago)
- git-parent:
- Files:
-
- src/net/driftingsouls/ds2/server/AdminCommands.java (modified) (2 diffs)
- src/net/driftingsouls/ds2/server/battles/Battle.java (modified) (52 diffs)
- src/net/driftingsouls/ds2/server/battles/BattleShip.java (modified) (4 diffs)
- src/net/driftingsouls/ds2/server/modules/AngriffController.java (modified) (2 diffs)
- src/net/driftingsouls/ds2/server/modules/ks/KSAttackAction.java (modified) (1 diff)
- src/net/driftingsouls/ds2/server/modules/ks/KSMenuBattleConsignAction.java (modified) (1 diff)
- src/net/driftingsouls/ds2/server/scripting/QuestFunctions.java (modified) (5 diffs)
- src/net/driftingsouls/ds2/server/ships/Ship.java (modified) (4 diffs)
- src/net/driftingsouls/ds2/server/ships/ShipLost.java (modified) (1 diff)
- src/net/driftingsouls/ds2/server/tick/regular/BattleTick.java (modified) (5 diffs)
- src/net/driftingsouls/ds2/server/tick/regular/RestTick.java (modified) (3 diffs)
- web/WEB-INF/cfg/hibernatemappings.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/net/driftingsouls/ds2/server/AdminCommands.java
rf034a00 r8f9e522 319 319 if( cmd.equals("end") ) { 320 320 int battleid = Integer.parseInt( command[2] ); 321 Database db = context.getDatabase();322 323 SQLResultRow battledata = db.first("SELECT commander1,commander2,x,y,system FROM battles WHERE id="+battleid);324 325 if( battle data.isEmpty()) {321 org.hibernate.Session db = context.getDB(); 322 323 Battle battle = (Battle)db.get(Battle.class, battleid); 324 325 if( battle == null ) { 326 326 return "Die angegebene Schlacht existiert nicht\n"; 327 327 } … … 329 329 User sourceUser = (User)context.getDB().get(User.class, -1); 330 330 331 PM.send(sourceUser, battledata.getInt("commander1"), "Schlacht beendet", "Die Schlacht bei "+Location.fromResult(battledata)+" wurde durch die Administratoren beendet"); 332 PM.send(sourceUser, battledata.getInt("commander2"), "Schlacht beendet", "Die Schlacht bei "+Location.fromResult(battledata)+" wurde durch die Administratoren beendet"); 333 334 int comid = battledata.getInt("commander1"); 335 336 Battle battle = new Battle(); 337 battle.load(battleid, comid, 0, 0, 0); 331 PM.send(sourceUser, battle.getCommander(0).getID(), "Schlacht beendet", "Die Schlacht bei "+battle.getLocation()+" wurde durch die Administratoren beendet"); 332 PM.send(sourceUser, battle.getCommander(1).getID(), "Schlacht beendet", "Die Schlacht bei "+battle.getLocation()+" wurde durch die Administratoren beendet"); 333 334 battle.load(battle.getCommander(0), null, null, 0); 338 335 battle.endBattle(0, 0, false); 339 336 } src/net/driftingsouls/ds2/server/battles/Battle.java
r144f38e r8f9e522 23 23 import java.io.FileWriter; 24 24 import java.io.IOException; 25 import java.io.Serializable; 25 26 import java.util.ArrayList; 26 27 import java.util.HashMap; … … 30 31 import java.util.Map; 31 32 import java.util.Set; 32 import java.util.Map.Entry; 33 34 import javax.persistence.Entity; 35 import javax.persistence.FetchType; 36 import javax.persistence.GeneratedValue; 37 import javax.persistence.Id; 38 import javax.persistence.JoinColumn; 39 import javax.persistence.ManyToOne; 40 import javax.persistence.Table; 41 import javax.persistence.Transient; 33 42 34 43 import net.driftingsouls.ds2.server.ContextCommon; … … 47 56 import net.driftingsouls.ds2.server.framework.ContextMap; 48 57 import net.driftingsouls.ds2.server.framework.Loggable; 49 import net.driftingsouls.ds2.server.framework.db.Database;50 import net.driftingsouls.ds2.server.framework.db.PreparedQuery;51 import net.driftingsouls.ds2.server.framework.db.SQLResultRow;52 58 import net.driftingsouls.ds2.server.scripting.Quests; 53 59 import net.driftingsouls.ds2.server.scripting.ScriptParser; … … 62 68 import org.apache.commons.lang.SystemUtils; 63 69 import org.apache.commons.lang.math.RandomUtils; 70 import org.hibernate.CallbackException; 71 import org.hibernate.Session; 72 import org.hibernate.classic.Lifecycle; 64 73 65 74 /** … … 68 77 * 69 78 */ 70 public class Battle implements Loggable, Locatable { 79 @Entity 80 @Table(name="battles") 81 public class Battle implements Lifecycle,Loggable, Locatable { 71 82 private static final int LOGFORMAT = 2; 72 83 … … 137 148 public static final int FLAG_BLOCK_SECONDROW_1 = 16; 138 149 139 private int id = 0; 140 private int x = 0; 141 private int y = 0; 142 private int system = 0; 143 private int flags = 0; 150 @Id @GeneratedValue 151 private int id; 152 private int x; 153 private int y; 154 private int system; 155 private int ally1; 156 private int ally2; 157 @ManyToOne(fetch=FetchType.LAZY) 158 @JoinColumn(name="commander1", nullable=false) 159 private User commander1; 160 @ManyToOne(fetch=FetchType.LAZY) 161 @JoinColumn(name="commander2", nullable=false) 162 private User commander2; 163 private boolean ready1; 164 private boolean ready2; 165 private String com1Msg = ""; 166 private String com2Msg = ""; 167 @SuppressWarnings("unused") 168 private int com1Points; 169 @SuppressWarnings("unused") 170 private int com2Points; 171 private boolean com1BETAK = true; 172 private boolean com2BETAK = true; 173 private int takeCommand1; 174 private int takeCommand2; 175 private int blockcount = 2; 176 @SuppressWarnings("unused") 177 private long lastaction; 178 private long lastturn; 179 private int flags; 180 private int inakt; 181 private String onend; 182 private String visibility; 183 private Integer quest; 184 185 @Transient 144 186 private String ownShipGroup = "0"; 187 @Transient 145 188 private String enemyShipGroup = "0"; 146 189 147 private int ownSide = 0; 148 private int enemySide = 0; 149 190 @Transient 191 private int ownSide; 192 @Transient 193 private int enemySide; 194 195 @Transient 150 196 private List<BattleShip> ownShips = new ArrayList<BattleShip>(); 197 @Transient 151 198 private List<BattleShip> enemyShips = new ArrayList<BattleShip>(); 152 199 200 @Transient 153 201 private int[] ally = new int[2]; 154 private int[] commander = new int[2]; 202 @Transient 203 private User[] commander = new User[2]; 204 @Transient 155 205 private boolean[] ready = new boolean[2]; 206 @Transient 156 207 private String[] comMsg = new String[2]; 208 @Transient 157 209 private boolean[] betak = new boolean[2]; 210 @Transient 158 211 private int[] takeCommand = new int[2]; 212 @Transient 159 213 private List<List<Integer>> addCommanders = new ArrayList<List<Integer>>(); 160 161 private int blockcount = 0; 162 private long lastturn = 0; 163 private String visibility = ""; 164 private int quest = 0; 214 215 @Transient 165 216 private boolean guest = false; 166 217 167 private SQLResultRow tableBuffer = null; 168 218 @Transient 169 219 private Map<Integer,Integer> ownShipTypeCount = new HashMap<Integer,Integer>(); 220 @Transient 170 221 private Map<Integer,Integer> enemyShipTypeCount = new HashMap<Integer,Integer>(); 171 222 223 @Transient 172 224 private int activeSOwn = 0; 225 @Transient 173 226 private int activeSEnemy = 0; 174 227 228 @Transient 175 229 private StringBuilder logoutputbuffer = new StringBuilder(); 230 @Transient 176 231 private StringBuilder logenemybuffer = new StringBuilder(); 177 232 … … 186 241 187 242 return "[tooltip="+shiptype.getNickname()+"]"+ship.getName()+"[/tooltip] ("+ship.getId()+")"; 243 } 244 245 /** 246 * Konstruktor 247 * 248 */ 249 public Battle() { 250 // EMPTY 251 } 252 253 public boolean onDelete(Session s) throws CallbackException { 254 return false; 255 } 256 257 public void onLoad(Session s, Serializable id) { 258 this.ally = new int[] {this.ally1, this.ally2}; 259 this.commander = new User[] {this.commander1, this.commander2}; 260 this.ready = new boolean[] {this.ready1, this.ready2}; 261 this.comMsg = new String[] {this.com1Msg, this.com2Msg}; 262 this.betak = new boolean[] {this.com1BETAK, this.com2BETAK}; 263 this.takeCommand = new int[] {this.takeCommand1, this.takeCommand2}; 264 265 this.addCommanders.add(0, new ArrayList<Integer>()); 266 this.addCommanders.add(1, new ArrayList<Integer>()); 267 } 268 269 public boolean onSave(Session s) throws CallbackException { 270 this.ally1 = this.ally[0]; 271 this.ally2 = this.ally[1]; 272 this.commander1 = this.commander[0]; 273 this.commander2 = this.commander[1]; 274 this.ready1 = this.ready[0]; 275 this.ready2 = this.ready[1]; 276 this.com1Msg = this.comMsg[0]; 277 this.com2Msg = this.comMsg[1]; 278 this.com1BETAK = this.betak[0]; 279 this.com2BETAK = this.betak[1]; 280 this.takeCommand1 = this.takeCommand[0]; 281 this.takeCommand2 = this.takeCommand[1]; 282 283 return false; 284 } 285 286 public boolean onUpdate(Session s) throws CallbackException { 287 this.ally1 = this.ally[0]; 288 this.ally2 = this.ally[1]; 289 this.commander1 = this.commander[0]; 290 this.commander2 = this.commander[1]; 291 this.ready1 = this.ready[0]; 292 this.ready2 = this.ready[1]; 293 this.com1Msg = this.comMsg[0]; 294 this.com2Msg = this.comMsg[1]; 295 this.com1BETAK = this.betak[0]; 296 this.com2BETAK = this.betak[1]; 297 this.takeCommand1 = this.takeCommand[0]; 298 this.takeCommand2 = this.takeCommand[1]; 299 300 return false; 188 301 } 189 302 … … 331 444 */ 332 445 public void addComMessage( int side, String text ) { 333 Database db = ContextMap.getContext().getDatabase(); 334 335 db.prepare("UPDATE battles SET com"+(side+1)+"Msg=CONCAT(com"+(side+1)+"Msg, ?) WHERE id= ?") 336 .update(text, this.id); 446 this.comMsg[side] += text; 337 447 } 338 448 … … 345 455 side = this.ownSide; 346 456 } 347 Database db = ContextMap.getContext().getDatabase(); 348 349 db.update("UPDATE battles SET com",(side+1),"Msg='' WHERE id=",this.id); 457 350 458 comMsg[side] = ""; 351 459 } … … 584 692 * @param ignoreinakt Soll das Inaktivitaetsfeld nicht zurueckgesetzt werden (<code>true</code>)? 585 693 */ 586 public void save( boolean ignoreinakt ) { 587 Context context = ContextMap.getContext(); 588 Database db = context.getDatabase(); 589 590 List<String> update = new ArrayList<String>(); 591 List<Object> updateData = new ArrayList<Object>(); 592 List<String> where = new ArrayList<String>(); 593 List<Object> whereData = new ArrayList<Object>(); 594 SQLResultRow data = new SQLResultRow(); 595 596 data.put("ally1", ally[0]); 597 data.put("ally2", this.ally[1]); 598 data.put("commander1", this.commander[0]); 599 data.put("commander2", this.commander[1]); 600 data.put("ready1", this.ready[0]); 601 data.put("ready2", this.ready[1]); 602 data.put("com1BETAK", this.betak[0]); 603 data.put("com2BETAK", this.betak[1]); 604 data.put("takeCommand1", this.takeCommand[0]); 605 data.put("takeCommand2", this.takeCommand[1]); 606 data.put("blockcount", this.blockcount); 607 data.put("lastturn", this.lastturn); 608 data.put("flags", this.flags); 609 610 for( Entry<String,Object> entry : data.entrySet() ) { 611 Object element = entry.getValue(); 612 String key = entry.getKey(); 613 if( ((element != null) && !element.equals(this.tableBuffer.get(key))) || (this.tableBuffer.get(key) != null) ) { 614 update.add(key+"= ? "); 615 updateData.add(element); 616 where.add(key+"= ? "); 617 whereData.add(this.tableBuffer.get(key)); 618 } 619 } 620 621 if( this.tableBuffer.getInt("quest") != this.quest ) { 622 if( this.quest != 0 ) { 623 update.add("quest= ? "); 624 updateData.add(this.quest); 625 } 626 else { 627 update.add("quest=NULL"); 628 } 629 if( this.tableBuffer.getInt("quest") != 0 ) { 630 where.add("quest= ? "); 631 whereData.add(this.tableBuffer.getInt("quest")); 632 } 633 else { 634 where.add("quest=NULL"); 635 } 636 } 637 638 if( (this.visibility != null && !this.visibility.equals(this.tableBuffer.get("visibility"))) || 639 (this.tableBuffer.get("visibility") != null) ) { 640 if( this.visibility != null ) { 641 update.add("visibility= ? "); 642 updateData.add(this.visibility); 643 } 644 else { 645 update.add("visibility=NULL"); 646 } 647 if( this.tableBuffer.get("vsibility") != null ) { 648 where.add("visibility= ? "); 649 whereData.add(this.tableBuffer.get("visibility")); 650 } 651 else { 652 where.add("visibility=NULL"); 653 } 654 } 655 694 @Deprecated 695 public void save( boolean ignoreinakt ) { 656 696 if( !ignoreinakt ) { 657 update.add("inakt= ? "); 658 updateData.add(0); 659 } 660 update.add("lastaction= ? "); 661 updateData.add(Common.time()); 662 663 where.add("id= ? "); 664 whereData.add(this.id); 665 666 PreparedQuery pq = db.prepare("UPDATE battles ", 667 "SET ",Common.implode(",",update)+" ", 668 "WHERE "+Common.implode(" AND ",where)); 669 670 int index=1; 671 for( int i=0; i < updateData.size(); i++ ) { 672 pq.setObject(index++, updateData.get(i)); 673 } 674 for( int i=0; i < whereData.size(); i++ ) { 675 pq.setObject(index++, whereData.get(i)); 676 } 677 pq.tUpdate(1); 678 pq.close(); 697 this.inakt = 0; 698 } 679 699 } 680 700 … … 701 721 Context context = ContextMap.getContext(); 702 722 org.hibernate.Session db = context.getDB(); 703 Database database = context.getDatabase(); 723 704 724 System.err.println("battle: "+id+" :: "+ownShipID+" :: "+enemyShipID); 705 725 // Kann der Spieler ueberhaupt angreifen (Noob-Schutz?) … … 804 824 } 805 825 806 BattleShip battleShip = new BattleShip( 0, aShip);826 BattleShip battleShip = new BattleShip(null, aShip); 807 827 808 828 ShipTypeData shiptype = aShip.getBaseType(); … … 866 886 // 867 887 868 database.update("INSERT INTO battles (x,y,system,ally1,ally2,commander1,com1Points,commander2,com2Points,lastaction,lastturn,flags,com1Msg,com2Msg) ", 869 "VALUES (",ownShip.getShip().getX(),",",ownShip.getShip().getY(),",",ownShip.getShip().getSystem(),",", 870 (ownShip.getOwner().getAlly() != null ? ownShip.getOwner().getAlly().getId() : "0"),",", 871 (enemyShip.getOwner().getAlly() != null ? enemyShip.getOwner().getAlly().getId() : "0"),", ", 872 ownShip.getOwner().getID(),",0,",enemyShip.getOwner().getID(),",0,",Common.time(),",",Common.time(),",'",FLAG_FIRSTROUND,"','','')"); 873 battle.id = database.insertID(); 874 875 if( database.affectedRows() == 0 ) { 876 context.addError("<span style=\"color:red\">Die Schlacht konnte nicht erfolgreich erstellt werden</span>"); 877 return null; 878 } 888 battle.x = ownShip.getShip().getX(); 889 battle.y = ownShip.getShip().getY(); 890 battle.system = ownShip.getShip().getSystem(); 891 battle.ally[0] = ownShip.getOwner().getAlly() != null ? ownShip.getOwner().getAlly().getId() : 0; 892 battle.ally[1] = enemyShip.getOwner().getAlly() != null ? enemyShip.getOwner().getAlly().getId() : 0; 893 battle.commander[0] = ownShip.getOwner(); 894 battle.commander[1] = enemyShip.getOwner(); 895 battle.lastaction = Common.time(); 896 battle.lastturn = Common.time(); 897 battle.flags = FLAG_FIRSTROUND; 898 battle.comMsg[0] = ""; 899 battle.comMsg[1] = ""; 900 db.save(battle); 879 901 880 902 // … … 894 916 idlist.add(enemyShip.getId()); 895 917 896 enemyShip.setBattle Id(battle.id);918 enemyShip.setBattle(battle); 897 919 db.persist(enemyShip); 898 920 899 enemyShip.getShip().setBattle(battle .id);921 enemyShip.getShip().setBattle(battle); 900 922 901 923 for( int i=0; i < battle.enemyShips.size(); i++ ) { … … 911 933 idlist.add(ship.getId()); 912 934 913 ship.setBattle Id(battle.id);935 ship.setBattle(battle); 914 936 db.persist(ship); 915 937 916 ship.getShip().setBattle(battle .id);938 ship.getShip().setBattle(battle); 917 939 } 918 940 if( startlist.size() > 0 ) { … … 928 950 idlist.add(ownShip.getId()); 929 951 930 ownShip.setBattle Id(battle.id);952 ownShip.setBattle(battle); 931 953 db.persist(ownShip); 932 954 933 ownShip.getShip().setBattle(battle .id);955 ownShip.getShip().setBattle(battle); 934 956 ownShip.getShip().setDocked(""); 935 957 … … 945 967 idlist.add(ship.getId()); 946 968 947 ship.setBattle Id(battle.id);969 ship.setBattle(battle); 948 970 db.persist(ship); 949 971 950 ship.getShip().setBattle(battle .id);972 ship.getShip().setBattle(battle); 951 973 } 952 974 if( startOwn && startlist.size() > 0 ) { … … 1045 1067 1046 1068 // Zuerst berechnen wir die eigenen AP 1047 int ownPoints = battle.getActionPoints(battle.ownSide);1069 battle.com1Points = battle.getActionPoints(battle.ownSide); 1048 1070 1049 1071 // Nun berechnen wir die gegnerischen AP 1050 int enemyPoints = battle.getActionPoints(battle.enemySide); 1051 1052 database.update("UPDATE battles SET com1Points=",ownPoints,",com2Points=",enemyPoints," WHERE id=",battle.id); 1053 1072 battle.com2Points = battle.getActionPoints(battle.enemySide); 1073 1054 1074 return battle; 1055 1075 } … … 1130 1150 List<User> users = context.query("select distinct bs.ship.owner " + 1131 1151 "from BattleShip bs " + 1132 "where bs.battle id="+this.id+" and bs.side="+this.enemySide, User.class);1152 "where bs.battle="+this.id+" and bs.side="+this.enemySide, User.class); 1133 1153 1134 1154 for( User euser : users ) { … … 1214 1234 } 1215 1235 1216 BattleShip sid2bs = new BattleShip(this .id, sid2);1236 BattleShip sid2bs = new BattleShip(this, sid2); 1217 1237 sid2bs.setAction(sid2Action); 1218 1238 sid2bs.setSide(this.ownSide); … … 1224 1244 db.persist(sid2bs); 1225 1245 1226 sid2.setBattle(this .id);1246 sid2.setBattle(this); 1227 1247 } 1228 1248 … … 1234 1254 } 1235 1255 1236 BattleShip aBattleShip = new BattleShip(this .id, aship);1256 BattleShip aBattleShip = new BattleShip(this, aship); 1237 1257 aBattleShip.setAction(sidAction); 1238 1258 aBattleShip.setSide(side); … … 1244 1264 db.persist(aBattleShip); 1245 1265 1246 aship.setBattle(this .id);1266 aship.setBattle(this); 1247 1267 } 1248 1268 … … 1258 1278 this.logme("Die "+log_shiplink(shipd)+" ist der Schlacht beigetreten\n\n"); 1259 1279 1260 shipd.setBattle(this .id);1280 shipd.setBattle(this); 1261 1281 } 1262 1282 … … 1266 1286 /** 1267 1287 * Laedt eine Schlacht aus der Datenbank 1268 * @param battleID die ID der Schlacht 1269 * @param id Die ID des aktiven Spielers 1270 * @param ownShipID die ID eines auszuwaehlenden eigenen Schiffes (oder 0) 1271 * @param enemyShipID die ID eines auszuwaehlenden gegnerischen Schiffes (oder 0) 1288 * @param battleId die ID der Schlacht 1289 * @param user Der aktive Spieler 1290 * @param ownShip Das auszuwaehlende eigene Schiff (oder <code>null</code>) 1291 * @param enemyShip Das auszuwaehlende gegnerische Schiff (oder <code>null</code>) 1292 * @param forcejoin Die ID einer Seite (1 oder 2), welche als die eigene zu waehlen ist. Falls 0 wird automatisch eine gewaehlt 1293 * 1294 * @return Die Schlacht oder <code>null</code> 1295 */ 1296 public static Battle loadBattle(int battleId, User user, Ship ownShip, Ship enemyShip, int forcejoin) { 1297 Context context = ContextMap.getContext(); 1298 org.hibernate.Session db = context.getDB(); 1299 1300 Battle battle = (Battle)db.get(Battle.class, battleId); 1301 if( battle == null ) { 1302 db.createQuery("update Ship set battle=null where id>0 and battle=?") 1303 .setInteger(0, battleId) 1304 .executeUpdate(); 1305 1306 context.addError("Die Schlacht ist bereits zuende!"); 1307 return null; 1308 } 1309 1310 battle.load(user, ownShip, enemyShip, forcejoin); 1311 1312 return battle; 1313 } 1314 1315 /** 1316 * Laedt weitere Schlachtdaten aus der Datenbank 1317 * @param user Der aktive Spieler 1318 * @param ownShip Das auszuwaehlende eigene Schiff (oder <code>null</code>) 1319 * @param enemyShip Das auszuwaehlende gegnerische Schiff (oder <code>null</code>) 1272 1320 * @param forcejoin Die ID einer Seite (1 oder 2), welche als die eigene zu waehlen ist. Falls 0 wird automatisch eine gewaehlt 1273 1321 * 1274 1322 * @return <code>true</code>, falls die Schlacht erfolgreich geladen wurde 1275 1323 */ 1276 public boolean load( int battleID, int id, int ownShipID, int enemyShipID, int forcejoin ) {1324 public boolean load(User user, Ship ownShip, Ship enemyShip, int forcejoin ) { 1277 1325 Context context = ContextMap.getContext(); 1278 Database database = context.getDatabase();1279 1326 org.hibernate.Session db = context.getDB(); 1280 1327 … … 1284 1331 - Update der Schiffe, falls ein Spieler nicht mehr einer der beiden Seiten angehoert (und ggf auch update der Kommandanten) 1285 1332 */ 1286 SQLResultRow battledata = database.first( "SELECT * FROM battles WHERE id=",battleID); 1287 1288 if( battledata.isEmpty() ) { 1289 db.createQuery("update Ship set battle=null where id>0 and battle=?") 1290 .setInteger(0, battleID) 1291 .executeUpdate(); 1292 1293 context.addError("Die Schlacht ist bereits zuende!"); 1294 return false; 1295 } 1296 1297 this.id = battleID; 1298 this.ally[0] = battledata.getInt("ally1"); 1299 this.ally[1] = battledata.getInt("ally2"); 1300 this.commander[0] = battledata.getInt("commander1"); 1301 this.commander[1] = battledata.getInt("commander2"); 1302 this.x = battledata.getInt("x"); 1303 this.y = battledata.getInt("y"); 1304 this.system = battledata.getInt("system"); 1305 this.ready[0] = battledata.getBoolean("ready1"); 1306 this.ready[1] = battledata.getBoolean("ready2"); 1307 this.comMsg[0] = battledata.getString("com1Msg"); 1308 this.comMsg[1] = battledata.getString("com2Msg"); 1309 this.betak[0] = battledata.getBoolean("com1BETAK"); 1310 this.betak[1] = battledata.getBoolean("com2BETAK"); 1311 this.takeCommand[0] = battledata.getInt("takeCommand1"); 1312 this.takeCommand[1] = battledata.getInt("takeCommand2"); 1313 this.blockcount = battledata.getInt("blockcount"); 1314 this.lastturn = battledata.getInt("lastturn"); 1315 this.visibility = battledata.getString("visibility").length() == 0 ? null : battledata.getString("visibility"); 1316 this.quest = battledata.getInt("quest"); 1317 this.guest = false; 1318 this.flags = battledata.getInt("flags"); 1319 1320 this.addCommanders.add(0, new ArrayList<Integer>()); 1321 this.addCommanders.add(1, new ArrayList<Integer>()); 1322 1323 this.tableBuffer = battledata; 1324 1325 User auser = (User)context.getDB().get(User.class, id); 1326 1333 1327 1334 // 1328 1335 // Weitere Commander in Folge von Questschlachten feststellen 1329 1336 // 1330 if( (this.quest != 0) && !Common.inArray(id,this.commander) && ((this.commander[0] < 0) ^ (this.commander[1]< 0) ) ) {1331 if( auser.hasFlag(User.FLAG_QUEST_BATTLES) || auser.getAccessLevel() > 20 ) {1332 if( this.commander[0] < 0 ) {1333 this.addCommanders.get(0).add( id);1337 if( (this.quest != null) && !Common.inArray(user.getID(),this.commander) && ((this.commander[0].getID() < 0) ^ (this.commander[1].getID() < 0) ) ) { 1338 if( user.hasFlag(User.FLAG_QUEST_BATTLES) || user.getAccessLevel() > 20 ) { 1339 if( this.commander[0].getID() < 0 ) { 1340 this.addCommanders.get(0).add(user.getID()); 1334 1341 } 1335 1342 else { 1336 this.addCommanders.get(1).add( id);1343 this.addCommanders.get(1).add(user.getID()); 1337 1344 } 1338 1345 } … … 1346 1353 1347 1354 if( forcejoin == 0 ) { 1348 if( ( ( auser.getAlly() != null) && !Common.inArray(auser.getAlly().getId(),this.ally) && !this.isCommander(auser) ) ||1349 ( ( auser.getAlly() == null) && !this.isCommander(auser) ) ) {1355 if( ( (user.getAlly() != null) && !Common.inArray(user.getAlly().getId(),this.ally) && !this.isCommander(user) ) || 1356 ( (user.getAlly() == null) && !this.isCommander(user) ) ) { 1350 1357 1351 1358 // Hat der Spieler ein Schiff in der Schlacht 1352 BattleShip aship = (BattleShip)db.createQuery("from BattleShip where id>0 and ship.owner=? and battle id=?")1353 .setEntity(0, auser)1354 .set Integer(1, this.id)1359 BattleShip aship = (BattleShip)db.createQuery("from BattleShip where id>0 and ship.owner=? and battle=?") 1360 .setEntity(0, user) 1361 .setEntity(1, this) 1355 1362 .setMaxResults(1) 1356 1363 .uniqueResult(); … … 1361 1368 else { 1362 1369 //Mehr ueber den Spieler herausfinden 1363 if( auser.getAccessLevel() > 20 ) {1370 if( user.getAccessLevel() > 20 ) { 1364 1371 this.guest = true; 1365 1372 } 1366 else if( auser.hasFlag(User.FLAG_VIEW_BATTLES) ) {1373 else if( user.hasFlag(User.FLAG_VIEW_BATTLES) ) { 1367 1374 this.guest = true; 1368 1375 } … … 1371 1378 "where owner= :user and x= :x and y= :y and system= :sys and " + 1372 1379 "battle is null and shiptype.shipClass in (11,13)") 1373 .setEntity("user", auser)1380 .setEntity("user", user) 1374 1381 .setInteger("x", this.x) 1375 1382 .setInteger("y", this.y) … … 1395 1402 // 1396 1403 1397 if( ( auser.getAlly() != null && (auser.getAlly().getId() == this.ally[0])) || this.isCommander(auser,0) || this.guest || forceSide == 0 ) {1404 if( (user.getAlly() != null && (user.getAlly().getId() == this.ally[0])) || this.isCommander(user,0) || this.guest || forceSide == 0 ) { 1398 1405 this.ownSide = 0; 1399 1406 this.enemySide = 1; 1400 1407 } 1401 else if( (auser.getAlly() != null && (auser.getAlly().getId() == this.ally[1])) || this.isCommander(auser,1) || forceSide == 1 ) { 1408 1409 else if( (user.getAlly() != null && (user.getAlly().getId() == this.ally[1])) || this.isCommander(user,1) || forceSide == 1 ) { 1402 1410 this.ownSide = 1; 1403 1411 this.enemySide = 0; … … 1415 1423 1416 1424 List ships = db.createQuery("from BattleShip bs inner join fetch bs.ship as s " + 1417 "where s.id>0 and bs.battle id=? " +1425 "where s.id>0 and bs.battle=? " + 1418 1426 "order by s.shiptype,s.id") 1419 .set Integer(0, this.id)1427 .setEntity(0, this) 1420 1428 .list(); 1421 1429 … … 1454 1462 this.activeSOwn = 0; 1455 1463 1456 if( enemyShip ID != 0) {1464 if( enemyShip != null ) { 1457 1465 for( int i=0; i < enemyShips.size(); i++ ) { 1458 if( enemyShips.get(i).getId() == enemyShip ID) {1466 if( enemyShips.get(i).getId() == enemyShip.getId() ) { 1459 1467 this.activeSEnemy = i; 1460 1468 break; … … 1463 1471 } 1464 1472 1465 if( ownShip ID != 0) {1473 if( ownShip != null ) { 1466 1474 for( int i=0; i < ownShips.size(); i++ ) { 1467 if( ownShips.get(i).getId() == ownShip ID) {1475 if( ownShips.get(i).getId() == ownShip.getId() ) { 1468 1476 this.activeSOwn = i; 1469 1477 break; … … 1676 1684 1677 1685 if( (owncount == 0) && (enemycount == 0) ) { 1678 User user1 = (User)context.getDB().get(User.class, this.commander[this.enemySide]); 1679 User user2 = (User)context.getDB().get(User.class, this.commander[this.ownSide]); 1680 1681 PM.send(user1, this.commander[this.ownSide], "Schlacht unentschieden", "Die Schlacht bei "+this.system+" : "+this.x+"/"+this.y+" gegen "+user1.getName()+" wurde mit einem Unendschieden beendet!"); 1682 PM.send(user2, this.commander[this.enemySide], "Schlacht unentschieden", "Die Schlacht bei "+this.system+" : "+this.x+"/"+this.y+" gegen "+user2.getName()+" wurde mit einem Unendschieden beendet!"); 1686 PM.send(this.commander[this.enemySide], this.commander[this.ownSide].getID(), "Schlacht unentschieden", "Die Schlacht bei "+this.getLocation()+" gegen "+this.commander[this.enemySide].getName()+" wurde mit einem Unendschieden beendet!"); 1687 PM.send(this.commander[this.ownSide], this.commander[this.enemySide].getID(), "Schlacht unentschieden", "Die Schlacht bei "+this.getLocation()+" gegen "+this.commander[this.ownSide].getName()+" wurde mit einem Unendschieden beendet!"); 1683 1688 1684 1689 // Schlacht beenden - unendschieden … … 1689 1694 1690 1695 if( calledByUser ) { 1691 context.getResponse().getContent().append("Du hast die Schlacht gegen "+Common._title( user1.getName())+" mit einem Unendschieden beendet!");1696 context.getResponse().getContent().append("Du hast die Schlacht gegen "+Common._title( this.commander[this.enemySide].getName())+" mit einem Unendschieden beendet!"); 1692 1697 } 1693 1698 return false; 1694 1699 } 1695 1700 else if( owncount == 0 ) { 1696 User user1 = (User)context.getDB().get(User.class, this.commander[this.enemySide]); 1697
