Changeset 13940572ed2de0bc7430440f97209d8cf11f5a65
- 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
| r4f02618 |
r1394057 |
|
| 20 | 20 | |
|---|
| 21 | 21 | import java.util.HashMap; |
|---|
| | 22 | import java.util.Iterator; |
|---|
| 22 | 23 | import java.util.List; |
|---|
| 23 | 24 | import java.util.Map; |
|---|
| 24 | 25 | import java.util.Map.Entry; |
|---|
| 25 | 26 | |
|---|
| | 27 | import net.driftingsouls.ds2.server.bases.Base; |
|---|
| 26 | 28 | import net.driftingsouls.ds2.server.cargo.Cargo; |
|---|
| 27 | 29 | import net.driftingsouls.ds2.server.cargo.ItemCargoEntry; |
|---|
| … | … | |
| 44 | 46 | import net.driftingsouls.ds2.server.entities.Ammo; |
|---|
| 45 | 47 | import net.driftingsouls.ds2.server.entities.Forschung; |
|---|
| | 48 | import net.driftingsouls.ds2.server.entities.StatItemLocations; |
|---|
| | 49 | import net.driftingsouls.ds2.server.entities.StatUserCargo; |
|---|
| 46 | 50 | import net.driftingsouls.ds2.server.entities.User; |
|---|
| 47 | 51 | import net.driftingsouls.ds2.server.framework.Common; |
|---|
| 48 | 52 | import net.driftingsouls.ds2.server.framework.Configuration; |
|---|
| 49 | 53 | import 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; |
|---|
| 53 | 54 | import net.driftingsouls.ds2.server.framework.pipeline.generators.DSGenerator; |
|---|
| 54 | 55 | import net.driftingsouls.ds2.server.framework.templates.TemplateEngine; |
|---|
| … | … | |
| 698 | 699 | TemplateEngine t = getTemplateEngine(); |
|---|
| 699 | 700 | 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()); |
|---|
| 703 | 704 | 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()); |
|---|
| 706 | 707 | } |
|---|
| 707 | 708 | else { |
|---|
| … | … | |
| 714 | 715 | |
|---|
| 715 | 716 | 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 | } |
|---|
| 721 | 724 | |
|---|
| 722 | 725 | 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>"; |
|---|
| 723 | 726 | 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 | |
|---|
| 728 | 728 | for( Item aitem : Items.get() ) { |
|---|
| 729 | 729 | int itemid = aitem.getID(); |
|---|
| … | … | |
| 755 | 755 | tooltiptext.append("<tr>"); |
|---|
| 756 | 756 | 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>"); |
|---|
| 762 | 760 | 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>"); |
|---|
| 769 | 765 | 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>"); |
|---|
| 775 | 770 | break; |
|---|
| | 771 | } |
|---|
| 776 | 772 | default: |
|---|
| 777 | 773 | tooltiptext.append("<td colspan='2' class='noBorderX' style='font-size:14px'>Unbekanntes Objekt "+alocation+"</td>"); |
|---|
| re1b01c8 |
r1394057 |
|
| 25 | 25 | |
|---|
| 26 | 26 | import net.driftingsouls.ds2.server.Location; |
|---|
| | 27 | import net.driftingsouls.ds2.server.MutableLocation; |
|---|
| 27 | 28 | import net.driftingsouls.ds2.server.config.Rassen; |
|---|
| 28 | 29 | import net.driftingsouls.ds2.server.config.Systems; |
|---|
| | 30 | import net.driftingsouls.ds2.server.entities.Nebel; |
|---|
| 29 | 31 | import net.driftingsouls.ds2.server.entities.User; |
|---|
| 30 | 32 | import net.driftingsouls.ds2.server.framework.Common; |
|---|
| … | … | |
| 50 | 52 | */ |
|---|
| 51 | 53 | public class ScanController extends DSGenerator { |
|---|
| 52 | | private SQLResultRow ship = null; |
|---|
| | 54 | private Ship ship = null; |
|---|
| 53 | 55 | private int range = 0; |
|---|
| 54 | 56 | private boolean admin = false; |
|---|
| … | … | |
| 71 | 73 | @Override |
|---|
| 72 | 74 | protected boolean validateAndPrepare(String action) { |
|---|
| 73 | | Database db = getDatabase(); |
|---|
| | 75 | org.hibernate.Session db = getDB(); |
|---|
| 74 | 76 | admin = getInteger("admin") != 0 && getUser().getAccessLevel() >= 30; |
|---|
| 75 | 77 | int shipID = -1; |
|---|
| … | … | |
| 78 | 80 | shipID = getInteger("ship"); |
|---|
| 79 | 81 | |
|---|
| 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) ) { |
|---|
| 83 | 85 | addError("Das angegebene Schiff existiert nicht oder gehört ihnen nicht", Common.buildUrl("default", "module", "schiffe") ); |
|---|
| 84 | 86 | |
|---|
| … | … | |
| 86 | 88 | } |
|---|
| 87 | 89 | |
|---|
| 88 | | ShipTypeData shiptype = Ship.getShipType( ship ); |
|---|
| | 90 | ShipTypeData shiptype = ship.getTypeData(); |
|---|
| 89 | 91 | int range = shiptype.getSensorRange(); |
|---|
| 90 | 92 | |
|---|
| 91 | 93 | // 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() ) { |
|---|
| 95 | 97 | // Norm. Deut, DMG |
|---|
| 96 | 98 | case 0: |
|---|
| … | … | |
| 116 | 118 | } |
|---|
| 117 | 119 | |
|---|
| 118 | | if( ship.getInt("crew") < shiptype.getCrew()/3 ) { |
|---|
| | 120 | if( ship.getCrew() < shiptype.getCrew()/3 ) { |
|---|
| 119 | 121 | addError("Es werden mindestens "+shiptype.getCrew()/3+" Crewmitglieder benötigt", Common.buildUrl("default", "module", "schiff", "ship", shipID)); |
|---|
| 120 | 122 | |
|---|
| … | … | |
| 122 | 124 | } |
|---|
| 123 | 125 | |
|---|
| 124 | | range = (int)Math.round(range*(ship.getInt("sensors")/100d)); |
|---|
| | 126 | range = (int)Math.round(range*(ship.getSensors()/100d)); |
|---|
| 125 | 127 | |
|---|
| 126 | 128 | this.range = range; |
|---|
| … | … | |
| 130 | 132 | this.range = getInteger("range"); |
|---|
| 131 | 133 | 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()); |
|---|
| 136 | 138 | |
|---|
| 137 | 139 | this.getTemplateEngine().set_var( |
|---|
| … | … | |
| 143 | 145 | this.getTemplateEngine().set_var( "global.ship.id", shipID, |
|---|
| 144 | 146 | "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() ); |
|---|
| 147 | 149 | |
|---|
| 148 | 150 | return true; |
|---|
| … | … | |
| 166 | 168 | int scany = getInteger("scany"); |
|---|
| 167 | 169 | |
|---|
| 168 | | final int system = this.ship.getInt("system"); |
|---|
| | 170 | final int system = this.ship.getSystem(); |
|---|
| 169 | 171 | |
|---|
| 170 | 172 | t.set_var("global.scansector",1); |
|---|
| … | … | |
| 178 | 180 | } |
|---|
| 179 | 181 | |
|---|
| 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 ) { |
|---|
| 181 | 183 | return; |
|---|
| 182 | 184 | } |
|---|
| … | … | |
| 327 | 329 | |
|---|
| 328 | 330 | // 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()) ) { |
|---|
| 330 | 332 | SQLQuery stid = db.query("SELECT id FROM ship_types WHERE LOCATE('",ShipTypes.SF_SEHR_KLEIN,"',flags)"); |
|---|
| 331 | 333 | while( stid.next() ) { |
|---|
| … | … | |
| 347 | 349 | |
|---|
| 348 | 350 | // 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())) && |
|---|
| 350 | 352 | shiptype.hasFlag(ShipTypes.SF_SEHR_KLEIN) ) { |
|---|
| 351 | 353 | continue; |
|---|
| … | … | |
| 398 | 400 | */ |
|---|
| 399 | 401 | |
|---|
| 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)+")"; |
|---|
| 403 | 405 | |
|---|
| 404 | 406 | // Nebel |
|---|
| … | … | |
| 407 | 409 | SQLQuery nebelRow = db.query("SELECT x,y,type FROM nebel WHERE ",rangesql); |
|---|
| 408 | 410 | 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")); |
|---|
| 410 | 412 | } |
|---|
| 411 | 413 | nebelRow.free(); |
|---|
| … | … | |
| 416 | 418 | SQLQuery nodeRow = db.query("SELECT id,x,y FROM jumpnodes WHERE ",rangesql); |
|---|
| 417 | 419 | 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); |
|---|
| 419 | 421 | } |
|---|
| 420 | 422 | nodeRow.free(); |
|---|
| … | … | |
| 448 | 450 | } |
|---|
| 449 | 451 | |
|---|
| 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")); |
|---|
| 451 | 453 | if( !shipmap.containsKey(loc) ) { |
|---|
| 452 | 454 | shipmap.put(loc, new ArrayList<SQLResultRow>()); |
|---|
| … | … | |
| 467 | 469 | SQLQuery bRow = db.query("SELECT t1.id,t1.owner,t1.x,t1.y,t1.klasse,t1.size,t2.ally " , |
|---|
| 468 | 470 | "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 " , |
|---|
| 471 | 473 | "ORDER BY size"); |
|---|
| 472 | 474 | |
|---|
| 473 | 475 | while( bRow.next() ) { |
|---|
| 474 | 476 | 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")); |
|---|
| 476 | 478 | for( int by=bRow.getInt("y")-bRow.getInt("size"); by <= bRow.getInt("y")+bRow.getInt("size"); by++ ) { |
|---|
| 477 | 479 | 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); |
|---|
| 479 | 481 | |
|---|
| 480 | 482 | if( !centerLoc.sameSector( 0, loc, bRow.getInt("size") ) ) { |
|---|
| … | … | |
| 501 | 503 | t.set_block("_SCAN", "mapborder.listitem", "mapborder.list"); |
|---|
| 502 | 504 | |
|---|
| 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()) ) { |
|---|
| 505 | 507 | t.set_var("mapborder.x", x); |
|---|
| 506 | 508 | t.parse("mapborder.list", "mapborder.listitem", true); |
|---|
| … | … | |
| 515 | 517 | t.set_block("map.rowitem", "map.listitem", "map.list"); |
|---|
| 516 | 518 | |
|---|
| 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()) ) { |
|---|
| 519 | 521 | continue; |
|---|
| 520 | 522 | } |
|---|
| … | … | |
| 524 | 526 | |
|---|
| 525 | 527 | // 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()) ) { |
|---|
| 528 | 530 | continue; |
|---|
| 529 | 531 | } |
|---|
| 530 | | Location loc = new Location(this.ship.getInt("system"), x, y); |
|---|
| | 532 | Location loc = new Location(this.ship.getSystem(), x, y); |
|---|
| 531 | 533 | |
|---|
| 532 | 534 | t.start_record(); |
|---|
| … | … | |
| 534 | 536 | String cssClass = ""; |
|---|
| 535 | 537 | |
|---|
| 536 | | if( (x != this.ship.getInt("x")) || (y != this.ship.getInt("y")) ) { |
|---|
| | 538 | if( (x != this.ship.getX()) || (y != this.ship.getY()) ) { |
|---|
| 537 | 539 | cssClass = "class=\"starmap\""; |
|---|
| 538 | 540 | } |
|---|
| 539 | 541 | |
|---|
| 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 ) { |
|---|
| 541 | 543 | t.set_var( "map.x", x, |
|---|
| 542 | 544 | "map.y", y, |
|---|
| r1a265e5 |
r1394057 |
|
| 204 | 204 | int alarm = getInteger("alarm"); |
|---|
| 205 | 205 | |
|---|
| 206 | | Database db = getDatabase(); |
|---|
| 207 | | |
|---|
| 208 | 206 | if( (alarm >= 0) && (alarm <= 1) ) { |
|---|
| 209 | | db.update("UPDATE ships SET alarm=",alarm," WHERE id>0 AND id=",ship.getId()); |
|---|
| | 207 | ship.setAlarm(alarm); |
|---|
| 210 | 208 | |
|---|
| 211 | 209 | getTemplateEngine().set_var("ship.message", "Alarmstufe erfolgreich geändert<br />"); |
|---|
| … | … | |
| 677 | 675 | */ |
|---|
| 678 | 676 | public void scriptAction() { |
|---|
| 679 | | Database db = getDatabase(); |
|---|
| 680 | 677 | TemplateEngine t = getTemplateEngine(); |
|---|
| 681 | 678 | |
|---|
| … | … | |
| 687 | 684 | |
|---|
| 688 | 685 | if( !script.trim().equals("") ) { |
|---|
| 689 | | String resetsql = ""; |
|---|
| 690 | 686 | 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); |
|---|
| 695 | 690 | } |
|---|
| 696 | 691 | 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); |
|---|
| 698 | 694 | } |
|---|
| 699 | 695 | |
|---|
| r4f02618 |
r1394057 |
|
| 31 | 31 | import net.driftingsouls.ds2.server.config.Weapons; |
|---|
| 32 | 32 | import net.driftingsouls.ds2.server.entities.Forschung; |
|---|
| | 33 | import net.driftingsouls.ds2.server.entities.OrderShip; |
|---|
| 33 | 34 | import net.driftingsouls.ds2.server.entities.User; |
|---|
| 34 | 35 | import net.driftingsouls.ds2.server.framework.Common; |
|---|
| … | … | |
| 186 | 187 | @Override |
|---|
| 187 | 188 | public void defaultAction() { |
|---|
| 188 | | Database db = getDatabase(); |
|---|
| | 189 | org.hibernate.Session db = getDB(); |
|---|
| 189 | 190 | User user = (User)getUser(); |
|---|
| 190 | 191 | TemplateEngine t = getTemplateEngine(); |
|---|
| … | … | |
| 196 | 197 | for( int i=1; i <= 3; i++ ) { |
|---|
| 197 | 198 | 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)); |
|---|
| 199 | 200 | |
|---|
| 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)) ) ) { |
|---|
| 203 | 205 | |
|---|
| 204 | 206 | visible = shipBuildData.getRes(i); |
|---|
| … | … | |
| 218 | 220 | |
|---|
| 219 | 221 | 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 ) { |
|---|
| 223 | 225 | t.set_var( "shiptype.showorderable", 1, |
|---|
| 224 | | "shiptype.ordercost", order.getInt("cost") ); |
|---|
| | 226 | "shiptype.ordercost", order.getCost() ); |
|---|
| 225 | 227 | } |
|---|
| 226 | 228 | } |
|---|
| r80763d8 |
r1394057 |
|
| 60 | 60 | import net.driftingsouls.ds2.server.entities.JumpNode; |
|---|
| 61 | 61 | import net.driftingsouls.ds2.server.entities.Nebel; |
|---|
| | 62 | import net.driftingsouls.ds2.server.entities.Sector; |
|---|
| 62 | 63 | import net.driftingsouls.ds2.server.entities.User; |
|---|
| 63 | 64 | import net.driftingsouls.ds2.server.entities.UserFlagschiffLocation; |
|---|
| … | … | |
| 69 | 70 | import net.driftingsouls.ds2.server.framework.Loggable; |
|---|
| 70 | 71 | import net.driftingsouls.ds2.server.framework.db.Database; |
|---|
| 71 | | import net.driftingsouls.ds2.server.framework.db.SQLQuery; |
|---|
| 72 | 72 | import net.driftingsouls.ds2.server.framework.db.SQLResultRow; |
|---|
| 73 | 73 | import net.driftingsouls.ds2.server.scripting.Quests; |
|---|
| … | … | |
| 1845 | 1845 | |
|---|
| 1846 | 1846 | org.hibernate.Session db = ContextMap.getContext().getDB(); |
|---|
| 1847 | | Database database = ContextMap.getContext().getDatabase(); |
|---|
| 1848 | 1847 | |
|---|
| 1849 | 1848 | if( (this.lock != null) && (this.lock.length() != 0) ) { |
|---|
| … | … | |
| 1932 | 1931 | |
|---|
| 1933 | 1932 | // 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 | } |
|---|
| 1943 | 1943 | |
|---|
| 1944 | 1944 | // Alle potentiell relevanten Sektoren mit Schiffen auf rotem Alarm (ok..und ein wenig ueberfluessiges Zeug bei schraegen Bewegungen) auslesen |
|---|
| … | … | |
| 1954 | 1954 | redalertlist.put(aship.getLocation(), Boolean.TRUE); |
|---|
| 1955 | 1955 | } |
|---|
| 1956 | | sectorRow.free(); |
|---|
| 1957 | 1956 | |
|---|
| 1958 | 1957 | // Alle potentiell relevanten Sektoren mit EMP-Nebeln (ok..und ein wenig ueberfluessiges Zeug bei schraegen Bewegungen) auslesen |
|---|
| … | … | |
| 1967 | 1966 | nebulaemplist.put(nebel.getLocation(), Boolean.TRUE); |
|---|
| 1968 | 1967 | } |
|---|
| 1969 | | sectorRow.free(); |
|---|
| 1970 | 1968 | |
|---|
| 1971 | 1969 | if( (waypoint.distance > 1) && nebulaemplist.containsKey(this.getLocation()) ) { |
|---|
| … | … | |
| 2037 | 2035 | } |
|---|
| 2038 | 2036 | |
|---|
| 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); |
|---|
| 2044 | 2046 | } |
|---|
| 2045 | | sector.free(); |
|---|
| 2046 | 2047 | |
|---|
| 2047 | 2048 | Iterator rasectListIter = db.createQuery("from Ship " + |
|---|
| 2048 | 2049 | "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(); |
|---|
| 2054 | 2055 | |
|---|
| 2055 | 2056 | if( rasectListIter.hasNext() ) { |
|---|
| … | … | |
| 2082 | 2083 | Location loc = this.getLocation(); |
|---|
| 2083 | 2084 | |
|---|
| 2084 | | SQLResultRow sector = sectorlist.get(new Location(loc.getSystem(), -1, -1)); |
|---|
| | 2085 | Sector sector = sectorlist.get(new Location(loc.getSystem(), -1, -1)); |
|---|
| 2085 | 2086 | if( sectorlist.containsKey(loc) ) { |
|---|
| 2086 | 2087 | sector = sectorlist.get(loc); |
|---|
| … | … | |
| 2093 | 2094 | } |
|---|
| 2094 | 2095 | |
|---|
| 2095 | | if( !sector.isEmpty() && sector.getString("onenter").length() > 0 ) { |
|---|
| | 2096 | if( (sector != null) && sector.getOnEnter().length() > 0 ) { |
|---|
| 2096 | 2097 | this.docked = ""; |
|---|
| 2097 | 2098 | if( docked != 0 ) { |
|---|
| 2098 | 2099 | 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 (?,?)") |
|---|
| 2099 | 2144 | .setInteger(0, this.x) |
|---|
| 2100 | 2145 | .setInteger(1, this.y) |
|---|
| … | … | |
| 2103 | 2148 | .setString(4, Integer.toString(this.id)) |
|---|
| 2104 | 2149 | .executeUpdate(); |
|---|
| 2105 | | &n |
|---|