Changeset 97a8ccbe5d550dd1a412d87f6536b1ca693284b9

Show
Ignore:
Timestamp:
06/17/07 11:06:55 (1 year ago)
Author:
Christopher Jung <bktheg@web.de>
git-committer:
Christopher Jung <bktheg@web.de> 1182071215 +0200
git-parent:

[59c2dd0c6381876fa119b4c740931f0e843d5218]

git-author:
Christopher Jung <bktheg@web.de> 1182071215 +0200
Message:

Weitere Funktionen von Ships nach Ship verschoben

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/net/driftingsouls/ds2/server/ships/Ship.java

    r59c2dd0 r97a8ccb  
    3939import net.driftingsouls.ds2.server.Location; 
    4040import net.driftingsouls.ds2.server.Offizier; 
     41import net.driftingsouls.ds2.server.bases.Base; 
    4142import net.driftingsouls.ds2.server.cargo.Cargo; 
    4243import net.driftingsouls.ds2.server.cargo.ItemCargoEntry; 
     
    4647import net.driftingsouls.ds2.server.config.Item; 
    4748import net.driftingsouls.ds2.server.config.ItemEffect; 
     49import net.driftingsouls.ds2.server.config.Rassen; 
     50import net.driftingsouls.ds2.server.entities.JumpNode; 
    4851import net.driftingsouls.ds2.server.entities.User; 
    4952import net.driftingsouls.ds2.server.entities.UserFlagschiffLocation; 
    5053import net.driftingsouls.ds2.server.framework.Common; 
    5154import net.driftingsouls.ds2.server.framework.Configuration; 
     55import net.driftingsouls.ds2.server.framework.Context; 
    5256import net.driftingsouls.ds2.server.framework.ContextLocalMessage; 
    5357import net.driftingsouls.ds2.server.framework.ContextMap; 
    5458import net.driftingsouls.ds2.server.framework.Loggable; 
    5559import net.driftingsouls.ds2.server.framework.db.Database; 
     60import net.driftingsouls.ds2.server.framework.db.SQLQuery; 
    5661import net.driftingsouls.ds2.server.framework.db.SQLResultRow; 
    5762import net.driftingsouls.ds2.server.ships.Ships.DockMode; 
     
    11851190         
    11861191        /** 
     1192         * <p>Laesst das Schiff durch einen Sprungpunkt springen. 
     1193         * Der Sprungpunkt kann entweder ein normaler Sprungpunkt 
     1194         * oder ein "Knossos"-Sprungpunkt (als ein mit einem Schiff verbundener 
     1195         * Sprungpunkt) sein.</p> 
     1196         * <p>Bei letzterem kann der Sprung scheitern, wenn keine Sprungberechtigung 
     1197         * vorliegt.</p> 
     1198         *  
     1199         * @param nodeID Die ID des Sprungpunkts/Des Schiffes mit dem Sprungpunkt 
     1200         * @param knode <code>true</code>, falls es sich um einen "Knossos"-Sprungpunkt handelt 
     1201         * @return <code>true</code>, falls ein Fehler aufgetreten ist 
     1202         */ 
     1203        public boolean jump(int nodeID, boolean knode) { 
     1204                Context context = ContextMap.getContext(); 
     1205                org.hibernate.Session db = context.getDB(); 
     1206                 
     1207                StringBuilder outputbuffer = MESSAGE.get(); 
     1208                          
     1209                String nodetypename = ""; 
     1210                String nodetarget = ""; 
     1211                 
     1212                User user = this.owner; 
     1213                 
     1214                // 
     1215                // Daten der Sprungpunkte laden 
     1216                // 
     1217                 
     1218                Location nodeLoc = null; 
     1219                Location outLoc = null; 
     1220                Object nodeObj = null; 
     1221                 
     1222                if( !knode ) { 
     1223                        JumpNode node = (JumpNode)db.get(JumpNode.class, nodeID); 
     1224                        nodetypename = "Der Sprungpunkt"; 
     1225                         
     1226                        if( node == null ) { 
     1227                                outputbuffer.append("Fehler: Der angegebene Sprungpunkt existiert nicht<br />\n"); 
     1228                                return true; 
     1229                        } 
     1230                         
     1231                        nodetarget = node.getName()+" ("+node.getSystemOut()+")"; 
     1232                         
     1233                        if( (user.getID() > 0) && node.isGcpColonistBlock() && Rassen.get().rasse(user.getRace()).isMemberIn( 0 ) && !user.hasFlag(User.FLAG_NO_JUMPNODE_BLOCK) ) { 
     1234                                outputbuffer.append("<span style=\"color:red\">Die GCP hat diesen Sprungpunkt f&uuml;r Kolonisten gesperrt</span><br />\n"); 
     1235                                return true; 
     1236                        } 
     1237                         
     1238                        nodeLoc = new Location(node.getSystem(), node.getX(), node.getY()); 
     1239                        outLoc = new Location(node.getSystemOut(), node.getXOut(), node.getYOut()); 
     1240                         
     1241                        nodeObj = node; 
     1242                } 
     1243                else { 
     1244                        /* Behandlung Knossosportale: 
     1245                         * 
     1246                         * Ziel wird mit ships.jumptarget festgelegt - Format: art|koords/id|user/ally/gruppe 
     1247                         * Beispiele:  
     1248                         * fix|2:35/35|all: 
     1249                         * ship|id:10000|ally:1 
     1250                         * base|id:255|group:-15,455,1200 
     1251                         * fix|8:20/100|default <--- diese Einstellung entspricht der bisherigen Praxis 
     1252                         */ 
     1253                        nodetypename = "Knossosportal"; 
     1254                         
     1255                        Ship shipNode = (Ship)db.get(Ship.class, nodeID); 
     1256                        if( shipNode == null ) { 
     1257                                outputbuffer.append("Fehler: Der angegebene Sprungpunkt existiert nicht<br />\n"); 
     1258                                return true; 
     1259                        } 
     1260                         
     1261                        nodetypename = shipNode.getTypeData().getNickname(); 
     1262                         
     1263                        /*  
     1264                         * Ermittlung der Zielkoordinaten 
     1265                         * geprueft wird bei Schiffen und Basen das Vorhandensein der Gegenstation 
     1266                         * existiert keine, findet kein Sprung statt 
     1267                         */ 
     1268                                                 
     1269                        String[] target = StringUtils.split(shipNode.getJumpTarget(), '|'); 
     1270                        if( target[0].equals("fix") ) { 
     1271                                outLoc = Location.fromString(target[1]); 
     1272                                                                 
     1273                                nodetarget = target[1]; 
     1274                        }  
     1275                        else if( target[0].equals("ship") ) { 
     1276                                String[] shiptarget = StringUtils.split(target[1], ':'); 
     1277                                Ship jmptarget = (Ship)db.get(Ship.class, Integer.valueOf(shiptarget[1])); 
     1278                                if( jmptarget == null ) { 
     1279                                        outputbuffer.append("<span style=\"color:red\">Die Empfangsstation existiert nicht!</span><br />\n"); 
     1280                                        return true; 
     1281                                } 
     1282                                 
     1283                                outLoc = new Location(jmptarget.getSystem(), jmptarget.getX(), jmptarget.getY()); 
     1284                                nodetarget = outLoc.toString(); 
     1285                        }        
     1286                        else if( target[0].equals("base") ) { 
     1287                                String[] shiptarget = StringUtils.split(target[1], ':'); 
     1288                                Base jmptarget = (Base)db.get(Base.class, Integer.valueOf(shiptarget[1])); 
     1289                                if( jmptarget == null ) { 
     1290                                        outputbuffer.append("<span style=\"color:red\">Die Empfangsbasis existiert nicht!</span><br />\n"); 
     1291                                        return true; 
     1292                                } 
     1293                                 
     1294                                outLoc = new Location(jmptarget.getSystem(), jmptarget.getX(), jmptarget.getY()); 
     1295                                nodetarget = outLoc.toString(); 
     1296                        } 
     1297                         
     1298                        // Einmalig das aktuelle Schiff ueberpruefen.  
     1299                        // Evt vorhandene Schiffe in einer Flotte werden spaeter separat gecheckt 
     1300                        if( shipNode.getId() == this.id ) { 
     1301                                outputbuffer.append("<span style=\"color:red\">Sie k&ouml;nnen nicht mit dem "+nodetypename+" durch sich selbst springen</span><br />\n"); 
     1302                                return true; 
     1303                        } 
     1304                         
     1305                        /*  
     1306                         * Ermittlung der Sprungberechtigten 
     1307                         */ 
     1308                        String[] jmpnodeuser = StringUtils.split(target[2], ':'); // Format art:ids aufgespalten 
     1309                         
     1310                        if( jmpnodeuser[0].equals("all") ) { 
     1311                                // Keine Einschraenkungen 
     1312                        } 
     1313                        // die alte variante  
     1314                        else if( jmpnodeuser[0].equals("default") || jmpnodeuser[0].equals("ownally") ){ 
     1315                                if( ( (user.getAlly() != null) && (shipNode.getOwner().getAlly() != user.getAlly()) ) ||  
     1316                                        ( user.getAlly() == null && (shipNode.getOwner() != user) ) ) { 
     1317                                        outputbuffer.append("<span style=\"color:red\">Sie k&ouml;nnen kein fremdes "+nodetypename+" benutzen - default</span><br />\n"); 
     1318                                        return true; 
     1319                                } 
     1320                        } 
     1321                        // user:$userid 
     1322                        else if ( jmpnodeuser[0].equals("user") ){ 
     1323                                if( Integer.parseInt(jmpnodeuser[1]) != user.getID() )  { 
     1324                                        outputbuffer.append("<span style=\"color:red\">Sie k&ouml;nnen kein fremdes "+nodetypename+" benutzen - owner</span><br />\n"); 
     1325                                        return true; 
     1326                                } 
     1327                        } 
     1328                        // ally:$allyid 
     1329                        else if ( jmpnodeuser[0].equals("ally") ){ 
     1330                                if( (user.getAlly() == null) || (Integer.parseInt(jmpnodeuser[1]) != user.getAlly().getId()) )  { 
     1331                                        outputbuffer.append("<span style=\"color:red\">Sie k&ouml;nnen kein fremdes "+nodetypename+" benutzen - ally</span><br />\n"); 
     1332                                        return true; 
     1333                                } 
     1334                        } 
     1335                        // group:userid1,userid2, ...,useridn 
     1336                        else if ( jmpnodeuser[0].equals("group") ){ 
     1337                                Integer[] userlist = Common.explodeToInteger(",", jmpnodeuser[1]); 
     1338                                if( !Common.inArray(user.getID(), userlist) )  { 
     1339                                        outputbuffer.append("<span style=\"color:red\">Sie k&ouml;nnen kein fremdes "+nodetypename+" benutzen - group</span><br />\n"); 
     1340                                        return true; 
     1341                                } 
     1342                        } 
     1343 
     1344                        nodeLoc = new Location(shipNode.getSystem(), shipNode.getX(), shipNode.getY()); 
     1345                } 
     1346                 
     1347                Location shipLoc = new Location(this.system, this.x, this.y); 
     1348                 
     1349                if( !shipLoc.sameSector(0, nodeLoc, 0) ) { 
     1350                        outputbuffer.append("<span style=\"color:red\">Fehler: "+nodetypename+" befindet sich nicht im selben Sektor wie das Schiff</span><br />\n"); 
     1351                        return true; 
     1352                } 
     1353                 
     1354                // 
     1355                // Liste der Schiffe ermitteln, welche springen sollen 
     1356                // 
     1357                 
     1358                List<Ship> shiplist = new ArrayList<Ship>(); 
     1359                // Falls vorhanden die Schiffe der Flotte einfuegen 
     1360                if( this.fleet != null ) { 
     1361                        List fleetships = db.createQuery("from Ship where id>0 and fleet=? AND x=? AND y=? AND system=? and docked=''") 
     1362                                .setEntity(0, this.fleet) 
     1363                                .setInteger(1, this.x) 
     1364                                .setInteger(2, this.y) 
     1365                                .setInteger(3, this.system) 
     1366                                .list(); 
     1367                         
     1368                        for( Iterator iter=fleetships.iterator(); iter.hasNext(); ) { 
     1369                                Ship fleetship = (Ship)iter.next(); 
     1370                                 
     1371                                // Bei Knossossprungpunkten darauf achten, dass das Portal nicht selbst mitspringt 
     1372                                if( knode && (fleetship.getId() == nodeID) ) { 
     1373                                        continue; 
     1374                                } 
     1375                                 
     1376                                shiplist.add(fleetship); 
     1377                        } 
     1378                } 
     1379                // Keine Flotte -> nur das aktuelle Schiff einfuegen 
     1380                else { 
     1381                        shiplist.add(this); 
     1382                } 
     1383                         
     1384                // 
     1385                // Jedes Schiff in der Liste springen lassen 
     1386                // 
     1387                for( Ship ship : shiplist ) { 
     1388                        if( (this.lock != null) && (this.lock.length() > 0) ) { 
     1389                                outputbuffer.append("<span style=\"color:red\">"+ship.getName()+" ("+ship.getId()+"): Das Schiff ist an ein Quest gebunden</span><br />\n"); 
     1390                                return true; 
     1391                        } 
     1392                         
     1393                        ShipTypeData shiptype = ship.getTypeData(); 
     1394                         
     1395                        // Liste der gedockten Schiffe laden 
     1396                        List<Ship> docked = new ArrayList<Ship>(); 
     1397                        if( (shiptype.getADocks() > 0) || (shiptype.getJDocks() > 0) ) {  
     1398                                List line = db.createQuery("from Ship where id>0 and docked in (?,?)") 
     1399                                        .setString(0, Integer.toString(ship.getId())) 
     1400                                        .setString(0, "l "+ship.getId()) 
     1401                                        .list(); 
     1402                                for( Iterator iter=line.iterator(); iter.hasNext(); ) { 
     1403                                        Ship aship = (Ship)iter.next(); 
     1404                                        docked.add(aship); 
     1405                                } 
     1406                        } 
     1407                         
     1408                        if( !knode ) { 
     1409                                JumpNode node = (JumpNode)nodeObj; 
     1410                 
     1411                                if( node.isWeaponBlock() && !user.hasFlag(User.FLAG_MILITARY_JUMPS) ) { 
     1412                                        //Schiff ueberprfen 
     1413                                        if( shiptype.isMilitary() ) { 
     1414                                                outputbuffer.append("<span style=\"color:red\">"+ship.getName()+" ("+ship.getId()+"): Die GCP verwehrt ihrem Kriegsschiff den Einflug nach "+node.getName()+"</span><br />\n"); 
     1415                                                return true; 
     1416                                        } 
     1417                 
     1418                                        //Angedockte Schiffe ueberprfen 
     1419                                        if( shiptype.getADocks()>0 || shiptype.getJDocks()>0 ) { 
     1420                                                boolean wpnfound = false; 
     1421                                                for( Ship aship : docked ) { 
     1422                                                        ShipTypeData checktype = aship.getTypeData(); 
     1423                                                        if( checktype.isMilitary() ) { 
     1424                                                                wpnfound = true; 
     1425                                                                break;   
     1426                                                        } 
     1427                                                } 
     1428                                                         
     1429                                                if(     wpnfound ) { 
     1430                                                        outputbuffer.append("<span style=\"color:red\">"+ship.getName()+" ("+ship.getId()+"): Die GCP verwehrt einem/mehreren ihrer angedockten Kriegsschiffe den Einflug nach "+node.getName()+"</span><br />\n"); 
     1431                                                        return true; 
     1432                                                } 
     1433                                        } 
     1434                                } 
     1435                        } 
     1436         
     1437                        if( ship.getEnergy() < 5 ) { 
     1438                                outputbuffer.append("<span style=\"color:red\">"+ship.getName()+" ("+ship.getId()+"): Zuwenig Energie zum Springen</span><br />\n"); 
     1439                                return true; 
     1440                        } 
     1441                                                         
     1442                        outputbuffer.append(ship.getName()+" ("+ship.getId()+") springt nach "+nodetarget+"<br />\n"); 
     1443                        ship.setSystem(outLoc.getSystem()); 
     1444                        ship.setX(outLoc.getX()); 
     1445                        ship.setY(outLoc.getY()); 
     1446                        ship.setEnergy(ship.getEnergy()-5); 
     1447                         
     1448                        for( Ship aship : docked ) { 
     1449                                aship.setX(outLoc.getX()); 
     1450                                aship.setY(outLoc.getY()); 
     1451                                aship.setSystem(outLoc.getSystem()); 
     1452                        } 
     1453                         
     1454                        ship.recalculateShipStatus(); 
     1455                } 
     1456         
     1457                return false; 
     1458        } 
     1459         
     1460        /** 
     1461         * Schiffe an/abdocken sowie Jaeger landen/starten. Der Dockvorgang wird mit den Berechtigungen 
     1462         * des Schiffsbesitzers ausgefuehrt 
     1463         * @param mode Der Dock-Modus (Andocken, Abdocken usw) 
     1464         * @param dockships eine Liste mit Schiffen, welche (ab)docken oder landen/starten sollen. Keine Angabe bewirkt das alle Schiffe abgedockt/gestartet werden 
     1465         * @return <code>true</code>, falls ein Fehler aufgetreten ist 
     1466         */ 
     1467        public boolean dock(DockMode mode, Ship ... dockships) { 
     1468                StringBuilder outputbuffer = MESSAGE.get(); 
     1469                 
     1470                Context context = ContextMap.getContext(); 
     1471                org.hibernate.Session db = context.getDB(); 
     1472                 
     1473                User owner = this.owner; 
     1474                 
     1475                ShipTypeData shiptype = this.getTypeData(); 
     1476         
     1477                // Alle bereits angedockten Schiffe laden 
     1478                List<Ship> docked = new ArrayList<Ship>(); 
     1479                if( (mode == DockMode.UNDOCK || mode == DockMode.DOCK) && (shiptype.getADocks() > 0) ) { 
     1480                        List line = db.createQuery("from Ship where id>0 and docked=?") 
     1481                                .setString(0, Integer.toString(this.id)) 
     1482                                .list(); 
     1483                        for( Iterator iter=line.iterator(); iter.hasNext(); ) { 
     1484                                Ship aship = (Ship)iter.next(); 
     1485                                docked.add(aship); 
     1486                        } 
     1487                } 
     1488                 
     1489                List<Ship> jdocked = new ArrayList<Ship>(); 
     1490                if( (mode == DockMode.LAND || mode == DockMode.START) && (shiptype.getJDocks() > 0) ) { 
     1491                        List line = db.createQuery("from Ship where id>0 and docked=?") 
     1492                                .setString(0, "l "+this.id) 
     1493                                .list(); 
     1494                        for( Iterator iter=line.iterator(); iter.hasNext(); ) { 
     1495                                Ship aship = (Ship)iter.next(); 
     1496                                jdocked.add(aship); 
     1497                        } 
     1498                } 
     1499         
     1500         
     1501                boolean superdock = false; 
     1502                if( mode == DockMode.DOCK ) { 
     1503                        superdock = owner.hasFlag(User.FLAG_SUPER_DOCK); 
     1504                } 
     1505         
     1506                List<Ship> targetships = null; 
     1507                 
     1508                if( (dockships != null) && (dockships.length > 0) ) { 
     1509                        targetships = new ArrayList<Ship>(); 
     1510                        for( int i=0; i < dockships.length; i++ ) { 
     1511                                if( dockships[i].getId() <  0 ) { 
     1512                                        continue; 
     1513                                } 
     1514                                targetships.add(dockships[i]); 
     1515                        } 
     1516                }  
     1517                else { 
     1518                        if( mode == DockMode.LAND || mode == DockMode.START ) {  
     1519                                targetships = jdocked; 
     1520                        } else { 
     1521                                targetships = docked; 
     1522                        } 
     1523                } 
     1524                 
     1525                if(targetships.size() == 0 ) { 
     1526                        outputbuffer.append("<span style=\"color:red\">Fehler: Es wurden keine passenden Schiffe gefunden</span><br />\n"); 
     1527                        return false; 
     1528                } 
     1529                 
     1530                Location shipLoc = new Location(this.system, this.x, this.y); 
     1531                 
     1532                for( Ship tarShip : targetships ) { 
     1533                        if( (mode == DockMode.DOCK) || (mode == DockMode.LAND) ) { 
     1534                                if( !shipLoc.sameSector(0, new Location(tarShip.getSystem(), tarShip.getX(), tarShip.getY()), 0) ) { 
     1535                                        outputbuffer.append("<span style=\"color:red\">Fehler: Die Schiffe befinden sich nicht im selben Sektor</span><br />\n"); 
     1536                                        return true; 
     1537                                } 
     1538                                 
     1539                                if( (tarShip.getLock() != null) && tarShip.getLock().length() > 0 ) { 
     1540                                        outputbuffer.append("<span style=\"color:red\">Fehler: Das Schiff ist an ein Quest gebunden</span><br />\n"); 
     1541                                        return true; 
     1542                                } 
     1543                 
     1544                                if( (mode == DockMode.DOCK) && !superdock && (tarShip.getOwner() != owner) ) { 
     1545                                        outputbuffer.append("<span style=\"color:red\">Fehler: Eines der aufzuladendenden Schiffe geh&ouml;rt nicht ihnen</span><br />\n"); 
     1546                                        return true; 
     1547                                } 
     1548                                 
     1549                                if( (mode == DockMode.DOCK) && (tarShip.getDocked().length() != 0) ) { 
     1550                                        outputbuffer.append("<span style=\"color:red\">Fehler: Eines der aufzuladendenden Schiffe ist bereits gedockt</span><br />\n"); 
     1551                                        return true; 
     1552                                } 
     1553                                 
     1554                                if( (mode == DockMode.LAND) && (tarShip.getOwner() != owner) ) { 
     1555                                        outputbuffer.append("<span style=\"color:red\">Fehler: Eines der zu landenden Schiffe geh&ouml;rt nicht ihnen</span><br />\n"); 
     1556                                        return true; 
     1557                                } 
     1558                                         
     1559                                ShipTypeData tarShipType = tarShip.getTypeData(); 
     1560                 
     1561                                if( (mode == DockMode.DOCK) && !superdock && (tarShipType.getSize() > 2 ) ) { 
     1562                                        outputbuffer.append("<span style=\"color:red\">Fehler: Eines der aufzuladendenden Schiffe ist zu gro&szlig;</span><br />\n"); 
     1563                                        return true; 
     1564                                } 
     1565                                 
     1566                                if( (mode == DockMode.LAND) && !tarShipType.hasFlag(ShipTypes.SF_JAEGER) ) { 
     1567                                        outputbuffer.append("<span style=\"color:red\">Fehler: Eines der zu landenden Schiffe ist kein J&auml;ger</span><br />\n"); 
     1568                                        return true; 
     1569                                } 
     1570                        } 
     1571                } 
     1572                         
     1573                if( (mode == DockMode.DOCK) && (shiptype.getADocks() < docked.size()+targetships.size())  ) { 
     1574                        outputbuffer.append("<span style=\"color:red\">Fehler: Nicht gen&uuml;gend freier Andockplatz vorhanden</span><br />\n"); 
     1575                        return true; 
     1576                } 
     1577                else if( (mode == DockMode.LAND) && (shiptype.getJDocks() < jdocked.size()+targetships.size())  ) { 
     1578                        outputbuffer.append("<span style=\"color:red\">Fehler: Nicht gen&uuml;gend freier Landepl&auml;tze vorhanden</span><br />\n"); 
     1579                        return true; 
     1580                } 
     1581                 
     1582                //Namensliste bauen 
     1583                StringBuilder tarNameList = new StringBuilder(targetships.size()*10); 
     1584                for( int i=0; i < targetships.size(); i++ ) { 
     1585                        if( tarNameList.length() > 0 ) { 
     1586                                tarNameList.append(", "); 
     1587                        } 
     1588                        Ship aship = targetships.get(i); 
     1589                         
     1590                        tarNameList.append("<a class=\"forschinfo\" style=\"font-size:12pt\" " + 
     1591                                        "href=\"./ds?module=schiff&sess="+context.getSession()+"&ship="+aship.getId()+"\">"+ 
     1592                                        aship.getName()+"</a> ("+aship.getId()+")"); 
     1593                } 
     1594         
     1595                //Schiff aufladen 
     1596                if( mode == DockMode.DOCK ) { 
     1597                        outputbuffer.append(this.name+" ("+this.id+") l&auml;dt "+tarNameList+" auf<br />\n"); 
     1598                        for( Ship aship : targetships ) { 
     1599                                aship.setDocked(Integer.toString(this.id)); 
     1600                        } 
     1601 
     1602                        Cargo cargo = this.cargo; 
     1603                         
     1604                        final Cargo emptycargo = new Cargo(); 
     1605         
     1606                        for( int i=0; i < targetships.size(); i++ ) { 
     1607                                Ship aship = targetships.get(i); 
     1608                                ShipTypeData type = aship.getTypeData(); 
     1609                                 
     1610                                if( type.getShipClass() != ShipClasses.CONTAINER.ordinal() ) { 
     1611                                        continue; 
     1612                                } 
     1613                                 
     1614                                Cargo dockcargo = aship.getCargo(); 
     1615                                cargo.addCargo( dockcargo ); 
     1616                                 
     1617                                if( !dockcargo.isEmpty() ) { 
     1618                                        aship.setCargo(emptycargo); 
     1619                                } 
     1620                                 
     1621                                aship.addModule( 0, Modules.MODULE_CONTAINER_SHIP, aship.getId()+"_"+(-type.getCargo()) ); 
     1622                                this.addModule( 0, Modules.MODULE_CONTAINER_SHIP, aship.getId()+"_"+type.getCargo() ); 
     1623                        } 
     1624                         
     1625                        this.cargo = cargo; 
     1626                } 
     1627                //Schiff abladen 
     1628                else if( mode == DockMode.UNDOCK ) { 
     1629                        outputbuffer.append(this.name+" ("+this.id+") l&auml;dt "+tarNameList+" ab<br />\n"); 
     1630                        for( Ship aship : targetships ) { 
     1631                                aship.setDocked(""); 
     1632                        } 
     1633 
     1634                        boolean gotmodule = false; 
     1635                         
     1636                        for( int i=0; i < targetships.size(); i++ ) { 
     1637                                Ship aship = targetships.get(i); 
     1638                                ShipTypeData type = aship.getTypeData(); 
     1639 
     1640                                if( type.getShipClass() != ShipClasses.CONTAINER.ordinal() ) { 
     1641                                        continue; 
     1642                                } 
     1643                                gotmodule = true; 
     1644                                 
     1645                                aship.removeModule( 0, Modules.MODULE_CONTAINER_SHIP, Integer.toString(aship.getId()) );                 
     1646                                this.removeModule( 0, Modules.MODULE_CONTAINER_SHIP, Integer.toString(aship.getId()) ); 
     1647                        } 
     1648                         
     1649                        if( gotmodule ) { 
     1650                                Cargo cargo = this.cargo; 
     1651                         
     1652                                // Schiffstyp neu abholen, da sich der Maxcargo geaendert hat 
     1653                                shiptype = this.getTypeData(); 
     1654                                 
     1655                                Cargo newcargo = cargo; 
     1656                                if( cargo.getMass() > shiptype.getCargo() ) { 
     1657                                        newcargo = cargo.cutCargo( shiptype.getCargo() );        
     1658                                } 
     1659                                else { 
     1660                                        cargo = new Cargo();     
     1661                                } 
     1662                         
     1663                                for( int i=0; i < targetships.size() && cargo.getMass() > 0; i++ ) { 
     1664                                        Ship aship = targetships.get(i); 
     1665                                        ShipTypeData ashiptype = aship.getTypeData(); 
     1666                                                                                         
     1667                                        if( (ashiptype.getShipClass() == ShipClasses.CONTAINER.ordinal()) && (cargo.getMass() > 0) ) { 
     1668                                                Cargo acargo = cargo.cutCargo( ashiptype.getCargo() ); 
     1669                                                if( !acargo.isEmpty() ) { 
     1670                                                        aship.setCargo(acargo); 
     1671                                                }        
     1672                                        } 
     1673                                } 
     1674                                 
     1675                                this.cargo = newcargo; 
     1676                        } 
     1677                } 
     1678                //Schiff landen 
     1679                else if( mode == DockMode.LAND ) { 
     1680                        outputbuffer.append(tarNameList+" lande"+(targetships.size()>1?"n":"t")+" auf "+this.name+" ("+this.id+")<br />\n"); 
     1681                        for( Ship aship : targetships ) { 
     1682                                aship.setDocked("l "+this.id); 
     1683                        } 
     1684                } 
     1685                 
     1686                //Schiff abladen 
     1687                else if( mode == DockMode.START ) { 
     1688                        outputbuffer.append(tarNameList+" starte"+(targetships.size()>1?"n":"t")+" von "+this.name+" ("+this.id+")<br />\n"); 
     1689                        for( Ship aship : targetships ) { 
     1690                                aship.setDocked(""); 
     1691                        } 
     1692                } 
     1693         
     1694                this.recalculateShipStatus(); 
     1695         
     1696                return false; 
     1697        } 
     1698         
     1699        /** 
    11871700         * Generiert ein Truemmerteil mit Loot fuer das Schiff unter Beruecksichtigung desjenigen, 
    11881701         * der es zerstoert hat. Wenn fuer das Schiff kein Loot existiert oder keiner generiert wurde (Zufall spielt eine 
     
    13211834                // Ist das Schiff selbst gedockt? -> Abdocken 
    13221835                if( !this.docked.equals("") && (this.docked.charAt(0) != 'l') ) { 
    1323                         Ships.dock( DockMode.UNDOCK, this.owner.getID(), Integer.parseInt(this.docked), new int[] {this.id} ); 
     1836                        Ship docked = (Ship)db.get(Ship.class, Integer.parseInt(this.docked)); 
     1837                        docked.dock( DockMode.UNDOCK, this ); 
    13241838                } 
    13251839         
     
    13321846                ShipTypeData type = this.getTypeData(); 
    13331847                if( type.getADocks() != 0 ) { 
    1334                         Ships.dock( DockMode.UNDOCK, this.owner.getID(), this.id, null );      
     1848                        this.dock( DockMode.UNDOCK );  
    13351849                } 
    13361850                if( type.getJDocks() != 0 ) { 
    1337                         Ships.dock( DockMode.START, this.owner.getID(), this.id, null );       
     1851                        this.dock( DockMode.START );   
    13381852                } 
    13391853                 
     
    14521966                        boolean tmp = aship.consign(newowner, testonly ); 
    14531967                        if( tmp && !testonly ) { 
    1454                                 Ships.dock( (aship.getDocked().charAt(0) == 'l' ? DockMode.START : DockMode.UNDOCK), newowner.getID(),this.id, new int[] {aship.getId()});                     
     1968                                this.dock( aship.getDocked().charAt(0) == 'l' ? DockMode.START : DockMode.UNDOCK, aship);                      
    14551969                        } 
    14561970                         
  • src/net/driftingsouls/ds2/server/ships/Ships.java

    r59c2dd0 r97a8ccb  
    2929import net.driftingsouls.ds2.server.Offizier; 
    3030import net.driftingsouls.ds2.server.battles.Battle; 
    31 import net.driftingsouls.ds2.server.cargo.Cargo; 
    32 import net.driftingsouls.ds2.server.cargo.modules.Modules; 
    33 import net.driftingsouls.ds2.server.config.Rassen; 
    3431import net.driftingsouls.ds2.server.config.StarSystem; 
    3532import net.driftingsouls.ds2.server.config.Systems; 
     
    170167         
    171168        private static void handleRedAlert( SQLResultRow ship ) { 
    172                 Integer[] attackers = redAlertCheck( ship, false ); 
     169                User owner = (User)ContextMap.getContext().getDB().get(User.class, ship.getInt("owner")); 
     170                Integer[] attackers = redAlertCheck( owner, Location.fromResult(ship), false ); 
    173171                 
    174172                Database db = ContextMap.getContext().getDatabase(); 
     
    216214        } 
    217215         
    218         private static Integer[] redAlertCheck( SQLResultRow ship, boolean checkonly ) { 
     216        private static Integer[] redAlertCheck( User user, Location loc, boolean checkonly ) { 
    219217                Context context = ContextMap.getContext(); 
    220218                Database db = context.getDatabase(); 
    221219         
    222                 User owner = (User)context.getDB().get(User.class, ship.getInt("owner")); 
    223                 User.Relations relationlist = owner.getRelations(); 
     220                User.Relations relationlist = user.getRelations(); 
    224221         
    225222                List<Integer> attackers = new ArrayList<Integer>(); 
    226223                 
    227                 SQLQuery aowner = db.query("SELECT DISTINCT owner FROM ships WHERE id>0 AND x=",ship.getInt("x")," AND y=",ship.getInt("y")," ", 
    228                                                         "AND system=",ship.getInt("system")," AND e>0 AND owner!=",ship.getInt("owner")," AND alarm=1 AND `lock` IS NULL AND docked='' AND !LOCATE('nocrew',status) "); 
     224                SQLQuery aowner = db.query("SELECT DISTINCT owner FROM ships WHERE id>0 AND x=",loc.getX()," AND y=",loc.getY()," ", 
     225                                                        "AND system=",loc.getSystem()," AND e>0 AND owner!=",user.getID()," AND alarm=1 AND `lock` IS NULL AND docked='' AND !LOCATE('nocrew',status) "); 
    229226                while( aowner.next() ) { 
    230227                        User auser = (User)context.getDB().get(User.class, aowner.getInt("owner")); 
     
    255252         */ 
    256253        public static boolean getRedAlertStatus( int userid, int system, int x, int y ) { 
    257                 SQLResultRow ship = new SQLResultRow(); 
    258                 ship.put("owner", userid); 
    259                 ship.put("system", system); 
    260                 ship.put("x", x); 
    261                 ship.put("y", y); 
    262                                  
    263                 Integer[] attackers = redAlertCheck(ship, true); 
     254                org.hibernate.Session db = ContextMap.getContext().getDB(); 
     255                                 
     256                Integer[] attackers = redAlertCheck((User)db.get(User.class, userid),  
     257                                new Location(system, x, y), true); 
    264258 
    265259                if( attackers.length > 0 ) { 
     
    719713                                        newship.put("x", newship.getInt("x") + xoffset); 
    720714                                        newship.put("y", newship.getInt("y") + yoffset); 
    721                                         Integer[] attackers = redAlertCheck(newship, false); 
     715                                        Integer[] attackers = redAlertCheck(user, Location.fromResult(newship), false); 
    722716                                        if( attackers.length != 0 ) { 
    723717                                                out.append("<span style=\"color:#ff0000\">Feindliche Schiffe in Alarmbereitschaft im n&auml;chsten Sektor geortet</span><br />\n"); 
     
    888882        } 
    889883         
    890         private static boolean fleetJump( SQLResultRow ship, int nodeId, boolean knode ) { 
    891                 boolean firstentry = true; 
    892                  
    893                 String kprotectstr = ""; 
    894                 StringBuilder outputbuffer = MESSAGE.get();; 
    895                 boolean error = false; 
    896                  
    897                 Context context = ContextMap.getContext(); 
    898                 Database db = context.getD