Changeset 13940572ed2de0bc7430440f97209d8cf11f5a65

Show
Ignore:
Timestamp:
08/25/07 23:09:06 (1 year ago)
Author:
Christopher Jung <bktheg@web.de>
git-committer:
Christopher Jung <bktheg@web.de> 1188076146 +0200
git-parent:

[dcfb5315d65cdc5545249c53703df58d0cd2fe6d]

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

Weitere Anpassungen an Hibernate

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/net/driftingsouls/ds2/server/modules/ItemInfoController.java

    r4f02618 r1394057  
    2020 
    2121import java.util.HashMap; 
     22import java.util.Iterator; 
    2223import java.util.List; 
    2324import java.util.Map; 
    2425import java.util.Map.Entry; 
    2526 
     27import net.driftingsouls.ds2.server.bases.Base; 
    2628import net.driftingsouls.ds2.server.cargo.Cargo; 
    2729import net.driftingsouls.ds2.server.cargo.ItemCargoEntry; 
     
    4446import net.driftingsouls.ds2.server.entities.Ammo; 
    4547import net.driftingsouls.ds2.server.entities.Forschung; 
     48import net.driftingsouls.ds2.server.entities.StatItemLocations; 
     49import net.driftingsouls.ds2.server.entities.StatUserCargo; 
    4650import net.driftingsouls.ds2.server.entities.User; 
    4751import net.driftingsouls.ds2.server.framework.Common; 
    4852import net.driftingsouls.ds2.server.framework.Configuration; 
    4953import net.driftingsouls.ds2.server.framework.Context; 
    50 import net.driftingsouls.ds2.server.framework.db.Database; 
    51 import net.driftingsouls.ds2.server.framework.db.SQLQuery; 
    52 import net.driftingsouls.ds2.server.framework.db.SQLResultRow; 
    5354import net.driftingsouls.ds2.server.framework.pipeline.generators.DSGenerator; 
    5455import net.driftingsouls.ds2.server.framework.templates.TemplateEngine; 
     
    698699                TemplateEngine t = getTemplateEngine(); 
    699700                User user = (User)getUser(); 
    700                 Database db = getDatabase(); 
    701                  
    702                 SQLResultRow ownCargoRow = db.first("SELECT cargo FROM stats_user_cargo WHERE user_id=",user.getID()); 
     701                org.hibernate.Session db = getDB(); 
     702                 
     703                StatUserCargo ownCargoRow = (StatUserCargo)db.get(StatUserCargo.class, user.getID()); 
    703704                Cargo owncargo = null; 
    704                 if( !ownCargoRow.isEmpty() ) { 
    705                         owncargo = new Cargo( Cargo.Type.STRING, ownCargoRow.getString("cargo")); 
     705                if( ownCargoRow != null ) { 
     706                        owncargo = new Cargo(ownCargoRow.getCargo()); 
    706707                } 
    707708                else { 
     
    714715                 
    715716                Map<Integer,String[]> reslocations = new HashMap<Integer,String[]>(); 
    716                 SQLQuery amodule = db.query("SELECT item_id,locations FROM stats_module_locations WHERE user_id=",user.getID()); 
    717                 while( amodule.next() ) { 
    718                                 reslocations.put(amodule.getInt("item_id"), StringUtils.split(amodule.getString("locations"),';')); 
    719                 } 
    720                 amodule.free(); 
     717                List modules = db.createQuery("from StatItemLocations where user=?") 
     718                        .setEntity(0, user) 
     719                        .list(); 
     720                for( Iterator iter=modules.iterator(); iter.hasNext(); ) { 
     721                        StatItemLocations amodule = (StatItemLocations)iter.next(); 
     722                        reslocations.put(amodule.getItemId(), StringUtils.split(amodule.getLocations(),';')); 
     723                } 
    721724                 
    722725                final String shipimage = "<td class='noBorderX' style='text-align:right'><img style='vertical-align:middle' src='"+Configuration.getSetting("URL")+"data/interface/schiffe/"+user.getRace()+"/icon_schiff.gif' alt='' title='Schiff' /></td>"; 
    723726                final String baseimage = "<td class='noBorderX' style='text-align:right'><img style='vertical-align:middle;width:15px;height:15px' src='"+Configuration.getSetting("URL")+"data/starmap/asti/asti.png' alt='' title='Asteroid' /></td>"; 
    724                  
    725                 Map<Integer,SQLResultRow> basecache = new HashMap<Integer,SQLResultRow>(); 
    726                 Map<Integer,String> shipnamecache = new HashMap<Integer,String>(); 
    727                  
     727 
    728728                for( Item aitem : Items.get() ) { 
    729729                        int itemid = aitem.getID(); 
     
    755755                                        tooltiptext.append("<tr>"); 
    756756                                        switch( alocation.charAt(0) ) { 
    757                                         case 's': 
    758                                                 if( !shipnamecache.containsKey(objectid) ) { 
    759                                                         shipnamecache.put(objectid, Common._plaintitle(db.first("SELECT name FROM ships WHERE id=",objectid).getString("name"))); 
    760                                                 } 
    761                                                 tooltiptext.append(shipimage+"<td class='noBorderX'><a style='font-size:14px' class='forschinfo' href='"+Common.buildUrl("default", "module", "schiff", "ship", objectid)+"'>"+shipnamecache.get(objectid)+" ("+objectid+")</a></td>"); 
     757                                        case 's': { 
     758                                                Ship ship = (Ship)db.get(Ship.class, objectid); 
     759                                                tooltiptext.append(shipimage+"<td class='noBorderX'><a style='font-size:14px' class='forschinfo' href='"+Common.buildUrl("default", "module", "schiff", "ship", objectid)+"'>"+ship.getName()+" ("+ship.getId()+")</a></td>"); 
    762760                                                break; 
    763                                         case 'b': 
    764                                                 if( !basecache.containsKey(objectid) ) { 
    765                                                         basecache.put(objectid, db.first("SELECT name,x,y,system FROM bases WHERE id=",objectid)); 
    766                                                         basecache.get(objectid).put("name", Common._plaintitle(basecache.get(objectid).getString("name"))); 
    767                                                 } 
    768                                                 tooltiptext.append(baseimage+"<td class='noBorderX'><a style='font-size:14px' class='forschinfo' href='"+Common.buildUrl("default", "module", "base", "col", objectid)+"'>"+basecache.get(objectid).getString("name")+" - "+basecache.get(objectid).getInt("system")+":"+basecache.get(objectid).getInt("x")+"/"+basecache.get(objectid).getInt("y")+"</a></td>"); 
     761                                        } 
     762                                        case 'b': { 
     763                                                Base base = (Base)db.get(Base.class, objectid); 
     764                                                tooltiptext.append(baseimage+"<td class='noBorderX'><a style='font-size:14px' class='forschinfo' href='"+Common.buildUrl("default", "module", "base", "col", objectid)+"'>"+base.getName()+" - "+base.getLocation()+"</a></td>"); 
    769765                                                break; 
    770                                         case 'g': 
    771                                                 if( !shipnamecache.containsKey(objectid) ) { 
    772                                                         shipnamecache.put(objectid, Common._plaintitle(db.first("SELECT name FROM ships WHERE id=",objectid).getString("name"))); 
    773                                                 } 
    774                                                 tooltiptext.append("<td colspan='2' class='noBorderX' style='font-size:14px'>"+shipnamecache.get(objectid)+"</td>"); 
     766                                        } 
     767                                        case 'g': { 
     768                                                Ship ship = (Ship)db.get(Ship.class, objectid); 
     769                                                tooltiptext.append("<td colspan='2' class='noBorderX' style='font-size:14px'>"+ship.getName()+"</td>"); 
    775770                                                break; 
     771                                        } 
    776772                                        default: 
    777773                                                tooltiptext.append("<td colspan='2' class='noBorderX' style='font-size:14px'>Unbekanntes Objekt "+alocation+"</td>"); 
  • src/net/driftingsouls/ds2/server/modules/ScanController.java

    re1b01c8 r1394057  
    2525 
    2626import net.driftingsouls.ds2.server.Location; 
     27import net.driftingsouls.ds2.server.MutableLocation; 
    2728import net.driftingsouls.ds2.server.config.Rassen; 
    2829import net.driftingsouls.ds2.server.config.Systems; 
     30import net.driftingsouls.ds2.server.entities.Nebel; 
    2931import net.driftingsouls.ds2.server.entities.User; 
    3032import net.driftingsouls.ds2.server.framework.Common; 
     
    5052 */ 
    5153public class ScanController extends DSGenerator { 
    52         private SQLResultRow ship = null; 
     54        private Ship ship = null; 
    5355        private int range = 0; 
    5456        private boolean admin = false; 
     
    7173        @Override 
    7274        protected boolean validateAndPrepare(String action) { 
    73                 Database db = getDatabase(); 
     75                org.hibernate.Session db = getDB(); 
    7476                admin = getInteger("admin") != 0 && getUser().getAccessLevel() >= 30; 
    7577                int shipID = -1; 
     
    7880                        shipID = getInteger("ship"); 
    7981                         
    80                         SQLResultRow ship = db.first("SELECT id,x,y,system,sensors,crew,type,status FROM ships WHERE owner='",getUser().getID(),"' AND id>0 AND id=",shipID); 
    81          
    82                         if( ship.isEmpty() ) { 
     82                        Ship ship = (Ship)db.get(Ship.class, shipID); 
     83         
     84                        if( (ship == null) || (ship.getOwner().getID() != getUser().getID()) || (ship.getId() < 0) ) { 
    8385                                addError("Das angegebene Schiff existiert nicht oder geh&ouml;rt ihnen nicht", Common.buildUrl("default", "module", "schiffe") ); 
    8486                                 
     
    8688                        } 
    8789                         
    88                         ShipTypeData shiptype = Ship.getShipType( ship ); 
     90                        ShipTypeData shiptype = ship.getTypeData(); 
    8991                        int range = shiptype.getSensorRange(); 
    9092         
    9193                        // Sollte das Schiff in einem Nebel stehen -> halbe Scannerreichweite 
    92                         SQLResultRow nebel = db.first("SELECT * FROM nebel WHERE x=",ship.getInt("x")," AND y=",ship.getInt("y")," AND system=",ship.getInt("system")); 
    93                         if( !nebel.isEmpty() ) { 
    94                                 switch( nebel.getInt("type") ) { 
     94                        Nebel nebel = (Nebel)db.get(Nebel.class, new MutableLocation(ship)); 
     95                        if( nebel != null ) { 
     96                                switch( nebel.getType() ) { 
    9597                                // Norm. Deut, DMG 
    9698                                case 0: 
     
    116118                        } 
    117119         
    118                         if( ship.getInt("crew") < shiptype.getCrew()/3 ) { 
     120                        if( ship.getCrew() < shiptype.getCrew()/3 ) { 
    119121                                addError("Es werden mindestens "+shiptype.getCrew()/3+" Crewmitglieder ben&ouml;tigt", Common.buildUrl("default", "module", "schiff", "ship", shipID)); 
    120122                                 
     
    122124                        } 
    123125                         
    124                         range = (int)Math.round(range*(ship.getInt("sensors")/100d)); 
     126                        range = (int)Math.round(range*(ship.getSensors()/100d)); 
    125127                         
    126128                        this.range = range; 
     
    130132                        this.range = getInteger("range"); 
    131133                        Location loc = Location.fromString(getString("baseloc")); 
    132                         this.ship = new SQLResultRow(); 
    133                         this.ship.put("x", loc.getX()); 
    134                         this.ship.put("y", loc.getY()); 
    135                         this.ship.put("system", loc.getSystem()); 
     134                        this.ship = new Ship(); 
     135                        this.ship.setX(loc.getX()); 
     136                        this.ship.setY(loc.getY()); 
     137                        this.ship.setSystem(loc.getSystem()); 
    136138                         
    137139                        this.getTemplateEngine().set_var(        
     
    143145                this.getTemplateEngine().set_var(       "global.ship.id",       shipID, 
    144146                                                                                        "global.range",         this.range+1, 
    145                                                                                         "global.scan.x",        ship.getInt("x"), 
    146                                                                                         "global.scan.y",        ship.getInt("y") ); 
     147                                                                                        "global.scan.x",        ship.getX(), 
     148                                                                                        "global.scan.y",        ship.getY() ); 
    147149                 
    148150                return true;     
     
    166168                int scany = getInteger("scany"); 
    167169                 
    168                 final int system = this.ship.getInt("system"); 
     170                final int system = this.ship.getSystem(); 
    169171                 
    170172                t.set_var("global.scansector",1); 
     
    178180                } 
    179181                 
    180                 if( Math.round(Math.sqrt(Math.pow(scany-this.ship.getInt("y"),2)+Math.pow(scanx-this.ship.getInt("x"),2))) > this.range ) { 
     182                if( Math.round(Math.sqrt(Math.pow(scany-this.ship.getY(),2)+Math.pow(scanx-this.ship.getX(),2))) > this.range ) { 
    181183                        return; 
    182184                } 
     
    327329                         
    328330                        // Falls nicht im Admin-Modus und nicht das aktuelle Feld gescannt wird: Liste der kleinen Schiffe generieren 
    329                         if( !this.admin && (scanx != this.ship.getInt("x")) || (scany != this.ship.getInt("y")) ) { 
     331                        if( !this.admin && (scanx != this.ship.getX()) || (scany != this.ship.getY()) ) { 
    330332                                SQLQuery stid = db.query("SELECT id FROM ship_types WHERE LOCATE('",ShipTypes.SF_SEHR_KLEIN,"',flags)"); 
    331333                                while( stid.next() ) { 
     
    347349                                 
    348350                                // Falls nicht im Admin-Modus: Nur sehr kleine Schiffe im Feld des scannenden Schiffes anzeigen 
    349                                 if( !this.admin && ((scanx != this.ship.getInt("x")) || (scany != this.ship.getInt("y"))) && 
     351                                if( !this.admin && ((scanx != this.ship.getX()) || (scany != this.ship.getY())) && 
    350352                                        shiptype.hasFlag(ShipTypes.SF_SEHR_KLEIN) ) { 
    351353                                        continue;        
     
    398400                */ 
    399401                 
    400                 String rangesql = "system="+this.ship.getInt("system")+" AND " + 
    401                                         "(x BETWEEN "+(this.ship.getInt("x")-this.range)+" AND "+(this.ship.getInt("x")+this.range)+") AND " + 
    402                                         "(y BETWEEN "+(this.ship.getInt("y")-this.range)+" AND "+(this.ship.getInt("y")+this.range)+")"; 
     402                String rangesql = "system="+this.ship.getSystem()+" AND " + 
     403                                        "(x BETWEEN "+(this.ship.getX()-this.range)+" AND "+(this.ship.getX()+this.range)+") AND " + 
     404                                        "(y BETWEEN "+(this.ship.getY()-this.range)+" AND "+(this.ship.getY()+this.range)+")"; 
    403405 
    404406                // Nebel 
     
    407409                SQLQuery nebelRow = db.query("SELECT x,y,type FROM nebel WHERE ",rangesql); 
    408410                while( nebelRow.next() ) { 
    409                         nebelmap.put(new Location(ship.getInt("system"), nebelRow.getInt("x"), nebelRow.getInt("y")), nebelRow.getInt("type")); 
     411                        nebelmap.put(new Location(this.ship.getSystem(), nebelRow.getInt("x"), nebelRow.getInt("y")), nebelRow.getInt("type")); 
    410412                } 
    411413                nebelRow.free(); 
     
    416418                SQLQuery nodeRow = db.query("SELECT id,x,y FROM jumpnodes WHERE ",rangesql); 
    417419                while( nodeRow.next() ) { 
    418                         nodemap.put(new Location(ship.getInt("system"), nodeRow.getInt("x"), nodeRow.getInt("y")), true); 
     420                        nodemap.put(new Location(this.ship.getSystem(), nodeRow.getInt("x"), nodeRow.getInt("y")), true); 
    419421                } 
    420422                nodeRow.free(); 
     
    448450                        } 
    449451                         
    450                         Location loc = new Location(ship.getInt("system"), sRow.getInt("x"), sRow.getInt("y")); 
     452                        Location loc = new Location(this.ship.getSystem(), sRow.getInt("x"), sRow.getInt("y")); 
    451453                        if( !shipmap.containsKey(loc) ) { 
    452454                                shipmap.put(loc, new ArrayList<SQLResultRow>()); 
     
    467469                SQLQuery bRow = db.query("SELECT t1.id,t1.owner,t1.x,t1.y,t1.klasse,t1.size,t2.ally " , 
    468470                                                                "FROM bases t1 JOIN users t2 ON t1.owner=t2.id " , 
    469                                                                 "WHERE t1.system=",this.ship.getInt("system")," AND " , 
    470                                                                         "(FLOOR(SQRT(POW(t1.x-",this.ship.getInt("x"),",2)+POW(t1.y-",this.ship.getInt("y"),",2)))-CAST(t1.size AS SIGNED) <= ",this.range,") AND t1.owner=t2.id " , 
     471                                                                "WHERE t1.system=",this.ship.getSystem()," AND " , 
     472                                                                        "(FLOOR(SQRT(POW(t1.x-",this.ship.getX(),",2)+POW(t1.y-",this.ship.getY(),",2)))-CAST(t1.size AS SIGNED) <= ",this.range,") AND t1.owner=t2.id " , 
    471473                                                                "ORDER BY size"); 
    472474                                                 
    473475                while( bRow.next() ) { 
    474476                        int imgcount = 0; 
    475                         Location centerLoc = new Location(this.ship.getInt("system"), bRow.getInt("x"), bRow.getInt("y")); 
     477                        Location centerLoc = new Location(this.ship.getSystem(), bRow.getInt("x"), bRow.getInt("y")); 
    476478                        for( int by=bRow.getInt("y")-bRow.getInt("size"); by <= bRow.getInt("y")+bRow.getInt("size"); by++ ) { 
    477479                                for( int bx=bRow.getInt("x")-bRow.getInt("size"); bx <= bRow.getInt("x")+bRow.getInt("size"); bx++ ) { 
    478                                         Location loc = new Location(this.ship.getInt("system"), bx, by); 
     480                                        Location loc = new Location(this.ship.getSystem(), bx, by); 
    479481                                         
    480482                                        if( !centerLoc.sameSector( 0, loc, bRow.getInt("size") ) ) { 
     
    501503                t.set_block("_SCAN", "mapborder.listitem", "mapborder.list"); 
    502504                 
    503                 for( int x = this.ship.getInt("x")-this.range; x <= this.ship.getInt("x")+this.range; x++ ) { 
    504                         if( (x > 0) && (x <= Systems.get().system(this.ship.getInt("system")).getWidth()) ) { 
     505                for( int x = this.ship.getX()-this.range; x <= this.ship.getX()+this.range; x++ ) { 
     506                        if( (x > 0) && (x <= Systems.get().system(this.ship.getSystem()).getWidth()) ) { 
    505507                                t.set_var("mapborder.x", x); 
    506508                                t.parse("mapborder.list", "mapborder.listitem", true); 
     
    515517                t.set_block("map.rowitem", "map.listitem", "map.list"); 
    516518                 
    517                 for( int y = this.ship.getInt("y")-this.range; y <= this.ship.getInt("y")+this.range; y++ ) { 
    518                         if( (y < 1) || (y > Systems.get().system(this.ship.getInt("system")).getHeight()) ) { 
     519                for( int y = this.ship.getY()-this.range; y <= this.ship.getY()+this.range; y++ ) { 
     520                        if( (y < 1) || (y > Systems.get().system(this.ship.getSystem()).getHeight()) ) { 
    519521                                continue; 
    520522                        } 
     
    524526         
    525527                        // Einen einzelnen Sektor ausgeben 
    526                         for( int x = this.ship.getInt("x")-this.range; x <= this.ship.getInt("x")+this.range; x++ ) { 
    527                                 if( (x < 1) || (x > Systems.get().system(this.ship.getInt("system")).getWidth()) ) { 
     528                        for( int x = this.ship.getX()-this.range; x <= this.ship.getX()+this.range; x++ ) { 
     529                                if( (x < 1) || (x > Systems.get().system(this.ship.getSystem()).getWidth()) ) { 
    528530                                        continue; 
    529531                                } 
    530                                 Location loc = new Location(this.ship.getInt("system"), x, y); 
     532                                Location loc = new Location(this.ship.getSystem(), x, y); 
    531533                                 
    532534                                t.start_record(); 
     
    534536                                String cssClass = ""; 
    535537                                 
    536                                 if( (x != this.ship.getInt("x")) || (y != this.ship.getInt("y")) ) { 
     538                                if( (x != this.ship.getX()) || (y != this.ship.getY()) ) { 
    537539                                        cssClass = "class=\"starmap\""; 
    538540                                } 
    539541                                 
    540                                 if( Math.round(Math.sqrt(Math.pow(y-this.ship.getInt("y"),2)+Math.pow(x-this.ship.getInt("x"),2))) <= this.range ) {                           
     542                                if( Math.round(Math.sqrt(Math.pow(y-this.ship.getY(),2)+Math.pow(x-this.ship.getX(),2))) <= this.range ) {                             
    541543                                        t.set_var(      "map.x",                        x, 
    542544                                                                "map.y",                        y, 
  • src/net/driftingsouls/ds2/server/modules/SchiffController.java

    r1a265e5 r1394057  
    204204                int alarm = getInteger("alarm"); 
    205205                 
    206                 Database db = getDatabase(); 
    207                  
    208206                if( (alarm >= 0) && (alarm <= 1) ) {  
    209                         db.update("UPDATE ships SET alarm=",alarm," WHERE id>0 AND id=",ship.getId()); 
     207                        ship.setAlarm(alarm); 
    210208                         
    211209                        getTemplateEngine().set_var("ship.message", "Alarmstufe erfolgreich ge&auml;ndert<br />"); 
     
    677675         */ 
    678676        public void scriptAction() { 
    679                 Database db = getDatabase(); 
    680677                TemplateEngine t = getTemplateEngine(); 
    681678                 
     
    687684                 
    688685                if( !script.trim().equals("") ) { 
    689                         String resetsql = ""; 
    690686                        if( reset != 0 ) { 
    691                                 resetsql = ",scriptexedata=NULL"; 
    692                         } 
    693          
    694                         db.prepare("UPDATE ships SET script= ? ",resetsql," WHERE id>0 AND id= ? ").update(script, ship.getId()); 
     687                                ship.setScriptExeData(null); 
     688                        } 
     689                        ship.setScript(script); 
    695690                } 
    696691                else { 
    697                         db.update("UPDATE ships SET script=NULL,scriptexedata=NULL WHERE id>0 AND id='",ship.getId(),"'");               
     692                        ship.setScriptExeData(null); 
     693                        ship.setScript(null);            
    698694                } 
    699695                 
  • src/net/driftingsouls/ds2/server/modules/SchiffInfoController.java

    r4f02618 r1394057  
    3131import net.driftingsouls.ds2.server.config.Weapons; 
    3232import net.driftingsouls.ds2.server.entities.Forschung; 
     33import net.driftingsouls.ds2.server.entities.OrderShip; 
    3334import net.driftingsouls.ds2.server.entities.User; 
    3435import net.driftingsouls.ds2.server.framework.Common; 
     
    186187        @Override 
    187188        public void defaultAction() { 
    188                 Database db = getDatabase(); 
     189                org.hibernate.Session db = getDB(); 
    189190                User user = (User)getUser(); 
    190191                TemplateEngine t = getTemplateEngine(); 
     
    196197                        for( int i=1; i <= 3; i++ ) { 
    197198                                if( shipBuildData.getRes(i) != 0 ) { 
    198                                         SQLResultRow research = db.first("SELECT visibility,req1,req2,req3 FROM forschungen WHERE id=",shipBuildData.getRes(i)); 
     199                                        Forschung research = Forschung.getInstance(shipBuildData.getRes(i)); 
    199200                                         
    200                                         if( (research.getInt("visibility") != 1) &&  
    201                                                 (user == null || !user.hasResearched(research.getInt("req1")) ||  
    202                                                  !user.hasResearched(research.getInt("req2")) || !user.hasResearched(research.getInt("req3")) ) ) { 
     201                                        if( !research.isVisibile() &&  
     202                                                (user == null || !user.hasResearched(research.getRequiredResearch(1)) ||  
     203                                                 !user.hasResearched(research.getRequiredResearch(2)) ||  
     204                                                 !user.hasResearched(research.getRequiredResearch(3)) ) ) { 
    203205                                                         
    204206                                                visible = shipBuildData.getRes(i); 
     
    218220 
    219221                if( (user != null) && (user.getAccessLevel() >= 10) ) { 
    220                         SQLResultRow order = db.first("SELECT cost FROM orders_ships WHERE type=",shipID); 
    221                          
    222                         if( !order.isEmpty() ) { 
     222                        OrderShip order = (OrderShip)db.get(OrderShip.class, shipID); 
     223                         
     224                        if( order != null ) { 
    223225                                t.set_var(      "shiptype.showorderable",       1, 
    224                                                         "shiptype.ordercost",           order.getInt("cost") ); 
     226                                                        "shiptype.ordercost",           order.getCost() ); 
    225227                        } 
    226228                } 
  • src/net/driftingsouls/ds2/server/ships/Ship.java

    r80763d8 r1394057  
    6060import net.driftingsouls.ds2.server.entities.JumpNode; 
    6161import net.driftingsouls.ds2.server.entities.Nebel; 
     62import net.driftingsouls.ds2.server.entities.Sector; 
    6263import net.driftingsouls.ds2.server.entities.User; 
    6364import net.driftingsouls.ds2.server.entities.UserFlagschiffLocation; 
     
    6970import net.driftingsouls.ds2.server.framework.Loggable; 
    7071import net.driftingsouls.ds2.server.framework.db.Database; 
    71 import net.driftingsouls.ds2.server.framework.db.SQLQuery; 
    7272import net.driftingsouls.ds2.server.framework.db.SQLResultRow; 
    7373import net.driftingsouls.ds2.server.scripting.Quests; 
     
    18451845 
    18461846                org.hibernate.Session db = ContextMap.getContext().getDB(); 
    1847                 Database database = ContextMap.getContext().getDatabase(); 
    18481847 
    18491848                if( (this.lock != null) && (this.lock.length() != 0) ) { 
     
    19321931 
    19331932                        // Alle potentiell relevanten Sektoren (ok..und ein wenig ueberfluessiges Zeug bei schraegen Bewegungen) auslesen 
    1934                         Map<Location,SQLResultRow> sectorlist = new HashMap<Location,SQLResultRow>(); 
    1935                         SQLQuery sectorRow = database.query("SELECT * FROM sectors " , 
    1936                                         "WHERE system IN (",this.system,",-1) AND (x='-1' OR ",xbetween,") AND (y='-1' OR ",ybetween,") ORDER BY system DESC"); 
    1937  
    1938                         while( sectorRow.next() ) { 
    1939                                 SQLResultRow row = sectorRow.getRow(); 
    1940                                 sectorlist.put(Location.fromResult(row), row); 
    1941                         } 
    1942                         sectorRow.free(); 
     1933                        Map<Location,Sector> sectorlist = new HashMap<Location,Sector>(); 
     1934                        List sectors = db.createQuery("from Sector " + 
     1935                                        "where system in (?,-1) and (x=-1 or "+xbetween+") AND (y=-1 or "+ybetween+") order by system desc") 
     1936                                        .setInteger(0, this.system) 
     1937                                        .list(); 
     1938 
     1939                        for( Iterator iter=sectors.iterator(); iter.hasNext(); ) { 
     1940                                Sector sector = (Sector)iter.next(); 
     1941                                sectorlist.put(sector.getLocation(), sector); 
     1942                        } 
    19431943 
    19441944                        // Alle potentiell relevanten Sektoren mit Schiffen auf rotem Alarm (ok..und ein wenig ueberfluessiges Zeug bei schraegen Bewegungen) auslesen 
     
    19541954                                redalertlist.put(aship.getLocation(), Boolean.TRUE); 
    19551955                        } 
    1956                         sectorRow.free(); 
    19571956 
    19581957                        // Alle potentiell relevanten Sektoren mit EMP-Nebeln (ok..und ein wenig ueberfluessiges Zeug bei schraegen Bewegungen) auslesen 
     
    19671966                                nebulaemplist.put(nebel.getLocation(), Boolean.TRUE); 
    19681967                        } 
    1969                         sectorRow.free(); 
    19701968 
    19711969                        if( (waypoint.distance > 1) && nebulaemplist.containsKey(this.getLocation()) ) { 
     
    20372035                                                        } 
    20382036 
    2039                                                         SQLQuery sector = database.query("SELECT * FROM sectors " , 
    2040                                                                         "WHERE system IN (",this.system,",-1) AND (x='-1' OR ",(this.x+tmpxoff),") AND (y='-1' OR ",(this.x+tmpyoff),")  ORDER BY system DESC"); 
    2041                                                         while( sector.next() ) { 
    2042                                                                 SQLResultRow row = sector.getRow(); 
    2043                                                                 sectorlist.put(Location.fromResult(row), row); 
     2037                                                        sectors = db.createQuery("from Sector "+ 
     2038                                                                        "where system in (?,-1) AND (x=-1 or ?) and (y=-1 or ?) order by system desc") 
     2039                                                                        .setInteger(0, this.system) 
     2040                                                                        .setInteger(1, this.x+tmpxoff) 
     2041                                                                        .setInteger(2, this.y+tmpyoff) 
     2042                                                                        .list(); 
     2043                                                        for( Iterator iter=sectors.iterator(); iter.hasNext(); ) { 
     2044                                                                Sector sector = (Sector)iter.next(); 
     2045                                                                sectorlist.put(sector.getLocation(), sector); 
    20442046                                                        } 
    2045                                                         sector.free(); 
    20462047 
    20472048                                                        Iterator rasectListIter = db.createQuery("from Ship " + 
    20482049                                                        "where owner!=? AND alarm='1' AND system=? AND x=? AND y=?") 
    2049                                                         .setEntity(0, this.owner) 
    2050                                                         .setInteger(1, this.system) 
    2051                                                         .setInteger(2, this.x+tmpxoff) 
    2052                                                         .setInteger(3, this.y+tmpyoff) 
    2053                                                         .iterate(); 
     2050                                                               .setEntity(0, this.owner) 
     2051                                                               .setInteger(1, this.system) 
     2052                                                               .setInteger(2, this.x+tmpxoff) 
     2053                                                               .setInteger(3, this.y+tmpyoff) 
     2054                                                               .iterate(); 
    20542055 
    20552056                                                        if( rasectListIter.hasNext() ) { 
     
    20822083                                                Location loc = this.getLocation(); 
    20832084 
    2084                                                 SQLResultRow sector = sectorlist.get(new Location(loc.getSystem(), -1, -1)); 
     2085                                                Sector sector = sectorlist.get(new Location(loc.getSystem(), -1, -1)); 
    20852086                                                if( sectorlist.containsKey(loc) ) { 
    20862087                                                        sector = sectorlist.get(loc); 
     
    20932094                                                } 
    20942095 
    2095                                                 if( !sector.isEmpty() && sector.getString("onenter").length() > 0 ) { 
     2096                                                if( (sector != null) && sector.getOnEnter().length() > 0 ) { 
    20962097                                                        this.docked = ""; 
    20972098                                                        if( docked != 0 ) { 
    20982099                                                                db.createQuery("update Ship set x=? ,y=?, system=? where id>0 and docked in (?,?)") 
     2100                                                                        .setInteger(0, this.x) 
     2101                                                                        .setInteger(1, this.y) 
     2102                                                                        .setInteger(2, this.system) 
     2103                                                                        .setString(3, "l "+this.id) 
     2104                                                                        .setString(4, Integer.toString(this.id)) 
     2105                                                                        .executeUpdate(); 
     2106                                                        } 
     2107                                                        this.recalculateShipStatus(); 
     2108                                                        saveFleetShips(); 
     2109 
     2110                                                        ScriptParser scriptparser = ContextMap.getContext().get(ContextCommon.class).getScriptParser(ScriptParser.NameSpace.QUEST); 
     2111                                                        scriptparser.setShip(this); 
     2112                                                        if( !user.hasFlag(User.FLAG_SCRIPT_DEBUGGING) ) { 
     2113                                                                scriptparser.setLogFunction(ScriptParser.LOGGER_NULL); 
     2114                                                        } 
     2115 
     2116                                                        scriptparser.setRegister("SECTOR", loc.toString() ); 
     2117 
     2118                                                        Quests.currentEventURL.set("&action=onenter"); 
     2119 
     2120                                                        db.refresh(this); 
     2121 
     2122                                                        if( docked != 0 ) { 
     2123                                                                db.createQuery("update Ship set x=? ,y=?, system=? where id>0 and docked in (?,?)") 
     2124                                                                        .setInteger(0, this.x) 
     2125                                                                        .setInteger(1, this.y) 
     2126                                                                        .setInteger(2, this.system) 
     2127                                                                        .setString(3, "l "+this.id) 
     2128                                                                        .setString(4, Integer.toString(this.id)) 
     2129                                                                        .executeUpdate(); 
     2130                                                        } 
     2131 
     2132                                                        if( Quests.executeEvent(scriptparser, sector.getOnEnter(), this.owner.getID(), "" ) ) { 
     2133                                                                if( scriptparser.getContext().getOutput().length()!= 0 ) {                                                       
     2134                                                                        waypoint.distance = 0; 
     2135                                                                } 
     2136                                                        } 
     2137                                                } 
     2138                                        } 
     2139 
     2140                                        if( redalertlist.containsKey(this.getLocation()) ) { 
     2141                                                this.docked = ""; 
     2142                                                if( docked != 0 ) { 
     2143                                                        db.createQuery("update Ship set x=? ,y=?, system=? where id>0 and docked in (?,?)") 
    20992144                                                                .setInteger(0, this.x) 
    21002145                                                                .setInteger(1, this.y) 
     
    21032148                                                                .setString(4, Integer.toString(this.id)) 
    21042149                                                                .executeUpdate(); 
    2105                                                       &n