Changeset 5fa248011061e1436ae212075879aeed6634c0d9
- Timestamp:
- 06/17/07 17:23:21
(1 year ago)
- Author:
- Christopher Jung <bktheg@web.de>
- git-committer:
- Christopher Jung <bktheg@web.de> 1182093801 +0200
- git-parent:
[3a4d21b128e99eca998913a19f89740275988fd2]
- git-author:
- Christopher Jung <bktheg@web.de> 1182093801 +0200
- Message:
Erster Teil des Modul 'Schiff' auf die neue Schiffsklasse umgestellt
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r3924571 |
r5fa2480 |
|
| 25 | 25 | import net.driftingsouls.ds2.server.framework.xml.XMLUtils; |
|---|
| 26 | 26 | |
|---|
| | 27 | import org.hibernate.Hibernate; |
|---|
| 27 | 28 | import org.hibernate.Session; |
|---|
| 28 | 29 | import org.hibernate.SessionFactory; |
|---|
| 29 | 30 | import org.hibernate.cfg.AnnotationConfiguration; |
|---|
| | 31 | import org.hibernate.dialect.function.StandardSQLFunction; |
|---|
| 30 | 32 | import org.hibernate.stat.Statistics; |
|---|
| 31 | 33 | import org.w3c.dom.Document; |
|---|
| … | … | |
| 46 | 48 | conf = new AnnotationConfiguration(); |
|---|
| 47 | 49 | conf.configure(new File(Configuration.getSetting("configdir")+"hibernate.xml")); |
|---|
| | 50 | conf.addSqlFunction("pow", new StandardSQLFunction("pow", Hibernate.DOUBLE)); |
|---|
| | 51 | conf.addSqlFunction("floor", new StandardSQLFunction("floor", Hibernate.LONG)); |
|---|
| 48 | 52 | |
|---|
| 49 | 53 | try { |
|---|
| r283e6c7 |
r5fa2480 |
|
| 85 | 85 | if( (lastcoords == null) || !lastcoords.sameSector(0, Location.fromResult(ship), 0) ) { |
|---|
| 86 | 86 | t.set_var( "ship.newcoords", 1, |
|---|
| 87 | | "ship.location", Ships.getLocationText(ship, false), |
|---|
| | 87 | "ship.location", Ships.getLocationText(Location.fromResult(ship), false), |
|---|
| 88 | 88 | "ship.newcoords.break", lastcoords != null ); |
|---|
| 89 | 89 | |
|---|
| r23d6d8b |
r5fa2480 |
|
| 23 | 23 | import java.util.ArrayList; |
|---|
| 24 | 24 | import java.util.HashMap; |
|---|
| | 25 | import java.util.Iterator; |
|---|
| 25 | 26 | import java.util.LinkedHashMap; |
|---|
| 26 | 27 | import java.util.List; |
|---|
| … | … | |
| 28 | 29 | |
|---|
| 29 | 30 | import net.driftingsouls.ds2.server.ContextCommon; |
|---|
| 30 | | import net.driftingsouls.ds2.server.Location; |
|---|
| 31 | 31 | import net.driftingsouls.ds2.server.Offizier; |
|---|
| 32 | 32 | import net.driftingsouls.ds2.server.cargo.Cargo; |
|---|
| … | … | |
| 55 | 55 | import net.driftingsouls.ds2.server.ships.Ship; |
|---|
| 56 | 56 | import net.driftingsouls.ds2.server.ships.ShipClasses; |
|---|
| | 57 | import net.driftingsouls.ds2.server.ships.ShipFleet; |
|---|
| 57 | 58 | import net.driftingsouls.ds2.server.ships.ShipTypeData; |
|---|
| 58 | 59 | import net.driftingsouls.ds2.server.ships.ShipTypes; |
|---|
| … | … | |
| 70 | 71 | */ |
|---|
| 71 | 72 | public class SchiffController extends DSGenerator implements Loggable { |
|---|
| 72 | | private SQLResultRow ship = null; |
|---|
| | 73 | private Ship ship = null; |
|---|
| 73 | 74 | private ShipTypeData shiptype = null; |
|---|
| 74 | 75 | private Offizier offizier = null; |
|---|
| … | … | |
| 122 | 123 | User user = (User)getUser(); |
|---|
| 123 | 124 | TemplateEngine t = getTemplateEngine(); |
|---|
| 124 | | Database db = getDatabase(); |
|---|
| | 125 | org.hibernate.Session db = getDB(); |
|---|
| 125 | 126 | |
|---|
| 126 | 127 | t.set_var( "user.tooltips", user.getUserValue("TBLORDER/schiff/tooltips") ); |
|---|
| … | … | |
| 128 | 129 | int shipid = getInteger("ship"); |
|---|
| 129 | 130 | |
|---|
| 130 | | ship = db.first("SELECT * FROM ships WHERE id>0 AND owner='",user.getID(),"' AND id=",shipid); |
|---|
| 131 | | if( ship.isEmpty() ) { |
|---|
| | 131 | ship = (Ship)db.get(Ship.class, shipid); |
|---|
| | 132 | if( (ship == null) || (ship.getId() < 0) || (ship.getOwner() != user) ) { |
|---|
| 132 | 133 | addError("Das angegebene Schiff existiert nicht", Common.buildUrl(getContext(),"default", "module", "schiffe") ); |
|---|
| 133 | 134 | return false; |
|---|
| 134 | 135 | } |
|---|
| 135 | 136 | |
|---|
| 136 | | if( ship.getInt("battle") > 0 ) { |
|---|
| 137 | | addError("Das Schiff ist in einen Kampf verwickelt (hier klicken um zu diesem zu gelangen)!", Common.buildUrl(getContext(), "default", "module", "angriff", "battle", ship.getInt("battle"), "ship", shipid) ); |
|---|
| | 137 | if( ship.getBattle() > 0 ) { |
|---|
| | 138 | addError("Das Schiff ist in einen Kampf verwickelt (hier klicken um zu diesem zu gelangen)!", Common.buildUrl(getContext(), "default", "module", "angriff", "battle", ship.getBattle(), "ship", shipid) ); |
|---|
| 138 | 139 | return false; |
|---|
| 139 | 140 | } |
|---|
| 140 | 141 | |
|---|
| 141 | 142 | |
|---|
| 142 | | shiptype = Ship.getShipType(ship); |
|---|
| 143 | | |
|---|
| 144 | | offizier = Offizier.getOffizierByDest('s', ship.getInt("id")); |
|---|
| 145 | | |
|---|
| 146 | | if( !action.equals("communicate") && !action.equals("onmove") && !action.equals("onenter") && !ship.getString("lock").equals("") ) { |
|---|
| | 143 | shiptype = ship.getTypeData(); |
|---|
| | 144 | |
|---|
| | 145 | offizier = Offizier.getOffizierByDest('s', ship.getId()); |
|---|
| | 146 | |
|---|
| | 147 | if( !action.equals("communicate") && !action.equals("onmove") && !action.equals("onenter") && (ship.getLock() != null) && !ship.getLock().equals("") ) { |
|---|
| 147 | 148 | ScriptParser scriptparser = getContext().get(ContextCommon.class).getScriptParser( ScriptParser.NameSpace.QUEST ); |
|---|
| 148 | 149 | scriptparser.setShip(ship); |
|---|
| … | … | |
| 151 | 152 | } |
|---|
| 152 | 153 | |
|---|
| 153 | | Quests.executeLock(scriptparser, ship.getString("lock"), user); |
|---|
| | 154 | Quests.executeLock(scriptparser, ship.getLock(), user); |
|---|
| 154 | 155 | } |
|---|
| 155 | 156 | |
|---|
| … | … | |
| 205 | 206 | |
|---|
| 206 | 207 | if( (alarm >= 0) && (alarm <= 1) ) { |
|---|
| 207 | | db.update("UPDATE ships SET alarm=",alarm," WHERE id>0 AND id=",ship.getInt("id")); |
|---|
| | 208 | db.update("UPDATE ships SET alarm=",alarm," WHERE id>0 AND id=",ship.getId()); |
|---|
| 208 | 209 | |
|---|
| 209 | 210 | getTemplateEngine().set_var("ship.message", "Alarmstufe erfolgreich geändert<br />"); |
|---|
| 210 | 211 | } |
|---|
| 211 | 212 | |
|---|
| 212 | | Ships.recalculateShipStatus(ship.getInt("id")); |
|---|
| | 213 | Ships.recalculateShipStatus(ship.getId()); |
|---|
| 213 | 214 | |
|---|
| 214 | 215 | redirect(); |
|---|
| … | … | |
| 222 | 223 | */ |
|---|
| 223 | 224 | public void consignAction() { |
|---|
| 224 | | Database db = getDatabase(); |
|---|
| | 225 | org.hibernate.Session db = getDB(); |
|---|
| 225 | 226 | TemplateEngine t = getTemplateEngine(); |
|---|
| 226 | 227 | User user = (User)getUser(); |
|---|
| … | … | |
| 229 | 230 | int newownerID = getInteger("newowner"); |
|---|
| 230 | 231 | |
|---|
| 231 | | User newowner = (User)getDB().get(User.class, newownerID); |
|---|
| | 232 | User newowner = (User)db.get(User.class, newownerID); |
|---|
| 232 | 233 | |
|---|
| 233 | 234 | parameterNumber("conf"); |
|---|
| … | … | |
| 235 | 236 | |
|---|
| 236 | 237 | if( conf == 0 ) { |
|---|
| 237 | | String text = "<span style=\"color:white\">Wollen sie das Schiff "+Common._plaintitle(ship.getString("name"))+" ("+ship.getInt("id")+") wirklich an "+newowner.getProfileLink()+" übergeben?</span><br />"; |
|---|
| 238 | | text += "<a class=\"ok\" href=\""+Common.buildUrl(getContext(), "consign", "ship", ship.getInt("id"), "conf" , 1, "newowner" , newowner.getID())+"\">Übergeben</a></span><br />"; |
|---|
| | 238 | String text = "<span style=\"color:white\">Wollen sie das Schiff "+Common._plaintitle(ship.getName())+" ("+ship.getId()+") wirklich an "+newowner.getProfileLink()+" übergeben?</span><br />"; |
|---|
| | 239 | text += "<a class=\"ok\" href=\""+Common.buildUrl(getContext(), "consign", "ship", ship.getId(), "conf" , 1, "newowner" , newowner.getID())+"\">Übergeben</a></span><br />"; |
|---|
| 239 | 240 | t.set_var( "ship.message", text ); |
|---|
| 240 | 241 | |
|---|
| … | … | |
| 243 | 244 | } |
|---|
| 244 | 245 | |
|---|
| 245 | | int fleet = ship.getInt("fleet"); |
|---|
| 246 | | |
|---|
| 247 | | boolean result = Ships.consign(user, ship, newowner, false ); |
|---|
| | 246 | ShipFleet fleet = ship.getFleet(); |
|---|
| | 247 | |
|---|
| | 248 | boolean result = ship.consign(newowner, false); |
|---|
| 248 | 249 | |
|---|
| 249 | 250 | if( result ) { |
|---|
| … | … | |
| 253 | 254 | } |
|---|
| 254 | 255 | else { |
|---|
| 255 | | String msg = "Ich habe dir die "+ship.getString("name")+" ("+ship.getInt("id")+"), ein Schiff der "+shiptype.getNickname()+"-Klasse, übergeben\nSie steht bei "+ship.getInt("system")+":"+ship.getInt("x")+"/"+ship.getInt("y"); |
|---|
| | 256 | String msg = "Ich habe dir die "+ship.getName()+" ("+ship.getId()+"), ein Schiff der "+shiptype.getNickname()+"-Klasse, übergeben\nSie steht bei "+ship.getSystem()+":"+ship.getX()+"/"+ship.getY(); |
|---|
| 256 | 257 | PM.send(getContext(), user.getID(), newowner.getID(), "Schiff übergeben", msg); |
|---|
| 257 | 258 | |
|---|
| … | … | |
| 259 | 260 | t.set_var("ship.message", (!consMessage.equals("") ? consMessage+"<br />" : "")+"<span style=\"color:green\">Das Schiff wurde erfolgreich an "+newowner.getProfileLink()+" übergeben</span><br />"); |
|---|
| 260 | 261 | |
|---|
| 261 | | if( fleet != 0 ) { |
|---|
| 262 | | int fleetcount = db.first("SELECT count(*) count FROM ships WHERE id>0 AND fleet="+fleet).getInt("count"); |
|---|
| | 262 | if( fleet != null ) { |
|---|
| | 263 | int fleetcount = (Integer)db.createQuery("select count(*) from Ship where id>0 and fleet=?") |
|---|
| | 264 | .setEntity(0, fleet) |
|---|
| | 265 | .iterate().next(); |
|---|
| 263 | 266 | |
|---|
| 264 | 267 | if( fleetcount < 3 ) { |
|---|
| 265 | | db.update("UPDATE ships SET fleet=null WHERE id>0 AND fleet="+fleet); |
|---|
| 266 | | db.update("DELETE FROM ship_fleets WHERE id>0 AND id="+fleet); |
|---|
| | 268 | db.createQuery("update Ship set fleet=null where id>0 and fleet=?") |
|---|
| | 269 | .setEntity(0, fleet) |
|---|
| | 270 | .executeUpdate(); |
|---|
| | 271 | |
|---|
| | 272 | db.delete(fleet); |
|---|
| 267 | 273 | } |
|---|
| 268 | 274 | } |
|---|
| … | … | |
| 279 | 285 | TemplateEngine t = getTemplateEngine(); |
|---|
| 280 | 286 | |
|---|
| 281 | | if( !ship.getString("lock").equals("") ) { |
|---|
| | 287 | if( (ship.getLock() != null) && (ship.getLock().length() > 0) ) { |
|---|
| 282 | 288 | t.set_var("ship.message", "<span style=\"color:red\">Dieses Schiff kann sich nicht selbstzerstören, da es in ein Quest eingebunden ist</span><br />"); |
|---|
| 283 | 289 | redirect(); |
|---|
| … | … | |
| 289 | 295 | |
|---|
| 290 | 296 | if( conf == 0 ) { |
|---|
| 291 | | String text = "<span style=\"color:white\">Wollen sie Selbstzerstörung des Schiffes "+Common._plaintitle(ship.getString("name"))+" ("+ship.getInt("id")+") wirklich ausführen?</span><br />\n"; |
|---|
| 292 | | text += "<a class=\"error\" href=\""+Common.buildUrl(getContext(), "destroy", "ship", ship.getInt("id"), "conf", 1)+"\">Selbstzerstörung</a></span><br />"; |
|---|
| | 297 | String text = "<span style=\"color:white\">Wollen sie Selbstzerstörung des Schiffes "+Common._plaintitle(ship.getName())+" ("+ship.getId()+") wirklich ausführen?</span><br />\n"; |
|---|
| | 298 | text += "<a class=\"error\" href=\""+Common.buildUrl(getContext(), "destroy", "ship", ship.getId(), "conf", 1)+"\">Selbstzerstörung</a></span><br />"; |
|---|
| 293 | 299 | t.set_var("ship.message", text); |
|---|
| 294 | 300 | |
|---|
| … | … | |
| 297 | 303 | } |
|---|
| 298 | 304 | |
|---|
| 299 | | Ships.destroy( ship.getInt("id") ); |
|---|
| | 305 | Ships.destroy( ship.getId() ); |
|---|
| 300 | 306 | |
|---|
| 301 | 307 | t.set_var("ship.message", "<span style=\"color:white\">Das Schiff hat sich selbstzerstört</span><br />"); |
|---|
| … | … | |
| 311 | 317 | TemplateEngine t = getTemplateEngine(); |
|---|
| 312 | 318 | |
|---|
| 313 | | if( (shiptype.getCost() == 0) || (ship.getInt("engine") == 0) ) { |
|---|
| | 319 | if( (shiptype.getCost() == 0) || (ship.getEngine() == 0) ) { |
|---|
| 314 | 320 | redirect(); |
|---|
| 315 | 321 | return; |
|---|
| … | … | |
| 320 | 326 | |
|---|
| 321 | 327 | if( node != 0 ) { |
|---|
| 322 | | Ships.jump(ship.getInt("id"), node, false); |
|---|
| | 328 | Ships.jump(ship.getId(), node, false); |
|---|
| 323 | 329 | t.set_var("ship.message", Ships.MESSAGE.getMessage()); |
|---|
| 324 | 330 | } |
|---|
| … | … | |
| 335 | 341 | TemplateEngine t = getTemplateEngine(); |
|---|
| 336 | 342 | |
|---|
| 337 | | if( (shiptype.getCost() == 0) || (ship.getInt("engine") == 0) ) { |
|---|
| | 343 | if( (shiptype.getCost() == 0) || (ship.getEngine() == 0) ) { |
|---|
| 338 | 344 | redirect(); |
|---|
| 339 | 345 | return; |
|---|
| … | … | |
| 344 | 350 | |
|---|
| 345 | 351 | if( knode != 0 ) { |
|---|
| 346 | | Ships.jump(ship.getInt("id"), knode, true); |
|---|
| | 352 | Ships.jump(ship.getId(), knode, true); |
|---|
| 347 | 353 | t.set_var("ship.message", Ships.MESSAGE.getMessage()); |
|---|
| 348 | 354 | } |
|---|
| … | … | |
| 357 | 363 | */ |
|---|
| 358 | 364 | public void renameAction() { |
|---|
| 359 | | Database db = getDatabase(); |
|---|
| 360 | 365 | TemplateEngine t = getTemplateEngine(); |
|---|
| 361 | 366 | |
|---|
| … | … | |
| 363 | 368 | String newname = getString("newname"); |
|---|
| 364 | 369 | |
|---|
| 365 | | db.prepare("UPDATE ships SET name= ? WHERE id= ?").update(newname, ship.getInt("id")); |
|---|
| | 370 | ship.setName(newname); |
|---|
| 366 | 371 | t.set_var("ship.message", "Name zu "+Common._plaintitle(newname)+" geändert<br />"); |
|---|
| 367 | | ship.put("name", newname); |
|---|
| 368 | 372 | |
|---|
| 369 | 373 | redirect(); |
|---|
| … | … | |
| 421 | 425 | int[] shiplist = Common.explodeToInt("|",shipIdList); |
|---|
| 422 | 426 | |
|---|
| 423 | | Ships.dock(Ships.DockMode.LAND, user.getID(), ship.getInt("id"), shiplist); |
|---|
| | 427 | Ships.dock(Ships.DockMode.LAND, user.getID(), ship.getId(), shiplist); |
|---|
| 424 | 428 | t.set_var("ship.message", Ships.MESSAGE.getMessage()); |
|---|
| 425 | 429 | |
|---|
| … | … | |
| 446 | 450 | int[] shiplist = Common.explodeToInt("|",shipIdList); |
|---|
| 447 | 451 | |
|---|
| 448 | | Ships.dock(Ships.DockMode.START, user.getID(), ship.getInt("id"), shiplist); |
|---|
| | 452 | Ships.dock(Ships.DockMode.START, user.getID(), ship.getId(), shiplist); |
|---|
| 449 | 453 | t.set_var("ship.message", Ships.MESSAGE.getMessage()); |
|---|
| 450 | 454 | |
|---|
| … | … | |
| 487 | 491 | } |
|---|
| 488 | 492 | |
|---|
| 489 | | Ships.dock(Ships.DockMode.DOCK, user.getID(), ship.getInt("id"), shiplist); |
|---|
| | 493 | Ships.dock(Ships.DockMode.DOCK, user.getID(), ship.getId(), shiplist); |
|---|
| 490 | 494 | t.set_var("ship.message", Ships.MESSAGE.getMessage()); |
|---|
| 491 | 495 | |
|---|
| … | … | |
| 512 | 516 | int[] shiplist = Common.explodeToInt("|",shipIdList); |
|---|
| 513 | 517 | |
|---|
| 514 | | Ships.dock(Ships.DockMode.UNDOCK, user.getID(), ship.getInt("id"), shiplist); |
|---|
| | 518 | Ships.dock(Ships.DockMode.UNDOCK, user.getID(), ship.getId(), shiplist); |
|---|
| 515 | 519 | t.set_var("ship.message", Ships.MESSAGE.getMessage()); |
|---|
| 516 | 520 | |
|---|
| … | … | |
| 524 | 528 | */ |
|---|
| 525 | 529 | public void joinAction() { |
|---|
| 526 | | Database db = getDatabase(); |
|---|
| | 530 | org.hibernate.Session db = getDB(); |
|---|
| 527 | 531 | TemplateEngine t = getTemplateEngine(); |
|---|
| 528 | 532 | User user = (User)getUser(); |
|---|
| … | … | |
| 531 | 535 | int join = getInteger("join"); |
|---|
| 532 | 536 | |
|---|
| 533 | | SQLResultRow fleetship = db.first("SELECT name,x,y,system,owner,fleet,`lock` FROM ships WHERE id>0 AND id=",join); |
|---|
| | 537 | Ship fleetship = (Ship)db.get(Ship.class, join); |
|---|
| | 538 | if( (fleetship == null) || (fleetship.getId() < 0) ) { |
|---|
| | 539 | redirect(); |
|---|
| | 540 | return; |
|---|
| | 541 | } |
|---|
| 534 | 542 | |
|---|
| 535 | 543 | // Austreten |
|---|
| 536 | | if( (join == 0) && ship.getString("lock").equals("") ) { |
|---|
| 537 | | Ships.removeFromFleet(ship); |
|---|
| 538 | | ship.put("fleet", 0); |
|---|
| | 544 | if( (join == 0) && (ship.getLock() == null) && (ship.getLock().length() == 0) ) { |
|---|
| | 545 | ship.removeFromFleet(); |
|---|
| 539 | 546 | |
|---|
| 540 | 547 | t.set_var("ship.message", "<span style=\"color:green\">"+Ships.MESSAGE.getMessage()+"</span><br />"); |
|---|
| … | … | |
| 545 | 552 | // Beitreten |
|---|
| 546 | 553 | else { |
|---|
| 547 | | SQLResultRow fleet = db.first("SELECT id,name FROM ship_fleets WHERE id='",fleetship.getInt("fleet"),"'"); |
|---|
| 548 | | |
|---|
| 549 | | if( !fleetship.getString("lock").equals("") || !ship.getString("lock").equals("") ) { |
|---|
| | 554 | ShipFleet fleet = fleetship.getFleet(); |
|---|
| | 555 | |
|---|
| | 556 | if( fleet == null ) { |
|---|
| | 557 | t.set_var("ship.message", "<span style=\"color:red\">Sie müssen erst eine Flotte erstellen</span><br />"); |
|---|
| | 558 | redirect(); |
|---|
| | 559 | return; |
|---|
| | 560 | } |
|---|
| | 561 | |
|---|
| | 562 | if( ((fleetship.getLock() != null) && (fleetship.getLock().length() > 0)) || ((ship.getLock() != null) && (ship.getLock().length() > 0)) ) { |
|---|
| 550 | 563 | t.set_var("ship.message", "<span style=\"color:red\">Sie können der Flotte nicht beitreten, solange entweder das Schiff oder die Flotte in ein Quest eingebunden ist</span><br />"); |
|---|
| 551 | 564 | redirect(); |
|---|
| … | … | |
| 554 | 567 | } |
|---|
| 555 | 568 | |
|---|
| 556 | | if( !Location.fromResult(ship).sameSector(0, Location.fromResult(fleetship), 0) || ( fleetship.getInt("owner") != user.getID() ) || (fleet.getInt("id") != fleetship.getInt("fleet")) ) { |
|---|
| 557 | | t.set_var("ship.message", "<span style=\"color:red\">Beitritt zur Flotte ""+Common._plaintitle(fleet.getString("name"))+"" nicht möglich</span><br />"); |
|---|
| | 569 | if( !ship.getLocation().sameSector(0, fleetship.getLocation(), 0) || ( fleetship.getOwner() != user ) ) { |
|---|
| | 570 | t.set_var("ship.message", "<span style=\"color:red\">Beitritt zur Flotte ""+Common._plaintitle(fleet.getName())+"" nicht möglich</span><br />"); |
|---|
| 558 | 571 | } |
|---|
| 559 | 572 | else { |
|---|
| 560 | | if( fleetship.getInt("fleet") == 0 ) { |
|---|
| 561 | | t.set_var("ship.message", "<span style=\"color:red\">Sie müssen erst eine Flotte erstellen</span><br />"); |
|---|
| 562 | | redirect(); |
|---|
| 563 | | return; |
|---|
| 564 | | } |
|---|
| 565 | | |
|---|
| 566 | | db.update("UPDATE ships SET fleet=",fleetship.getInt("fleet")," WHERE id>0 AND id=",ship.getInt("id")); |
|---|
| 567 | | t.set_var("ship.message", "<span style=\"color:green\">Flotte ""+Common._plaintitle(fleet.getString("name"))+"" beigetreten</span><br />"); |
|---|
| | 573 | ship.setFleet(fleet); |
|---|
| | 574 | t.set_var("ship.message", "<span style=\"color:green\">Flotte ""+Common._plaintitle(fleet.getName())+"" beigetreten</span><br />"); |
|---|
| 568 | 575 | } |
|---|
| 569 | 576 | } |
|---|
| … | … | |
| 578 | 585 | */ |
|---|
| 579 | 586 | public void shupAction() { |
|---|
| 580 | | Database db = getDatabase(); |
|---|
| 581 | 587 | TemplateEngine t = getTemplateEngine(); |
|---|
| 582 | 588 | |
|---|
| … | … | |
| 589 | 595 | } |
|---|
| 590 | 596 | |
|---|
| 591 | | if( shup > (shiptype.getShields() - ship.getInt("shields"))/shieldfactor ) { |
|---|
| 592 | | shup = (shiptype.getShields() - ship.getInt("shields"))/shieldfactor; |
|---|
| 593 | | } |
|---|
| 594 | | if( shup > ship.getInt("e") ) { |
|---|
| 595 | | shup = ship.getInt("e"); |
|---|
| | 597 | if( shup > (shiptype.getShields() - ship.getShields())/shieldfactor ) { |
|---|
| | 598 | shup = (shiptype.getShields() - ship.getShields())/shieldfactor; |
|---|
| | 599 | } |
|---|
| | 600 | if( shup > ship.getEnergy() ) { |
|---|
| | 601 | shup = ship.getEnergy(); |
|---|
| 596 | 602 | } |
|---|
| 597 | 603 | |
|---|
| 598 | 604 | t.set_var("ship.message", "Schilde +"+(shup*shieldfactor)+"<br />"); |
|---|
| 599 | 605 | |
|---|
| 600 | | int oldshields = ship.getInt("shields"); |
|---|
| 601 | | ship.put("shields", ship.getInt("shields") + shup*shieldfactor); |
|---|
| 602 | | if( ship.getInt("shields") > shiptype.getShields() ) { |
|---|
| 603 | | ship.put("shields", shiptype.getShields()); |
|---|
| 604 | | } |
|---|
| 605 | | |
|---|
| 606 | | int olde = ship.getInt("e"); |
|---|
| 607 | | ship.put("e", ship.getInt("e") - shup); |
|---|
| 608 | | |
|---|
| 609 | | db.update("UPDATE ships SET e=",ship.getInt("e"),",shields=",ship.getInt("shields")," WHERE id=",ship.getInt("id")," AND e='",olde,"' AND shields='",oldshields,"'"); |
|---|
| 610 | | |
|---|
| 611 | | Ships.recalculateShipStatus(ship.getInt("id")); |
|---|
| | 606 | ship.setShields(ship.getShields() + shup*shieldfactor); |
|---|
| | 607 | if( ship.getShields() > shiptype.getShields() ) { |
|---|
| | 608 | ship.setShields(shiptype.getShields()); |
|---|
| | 609 | } |
|---|
| | 610 | |
|---|
| | 611 | ship.setEnergy(ship.getEnergy() - shup); |
|---|
| | 612 | |
|---|
| | 613 | Ships.recalculateShipStatus(ship.getId()); |
|---|
| 612 | 614 | |
|---|
| 613 | 615 | redirect(); |
|---|
| … | … | |
| 637 | 639 | } |
|---|
| 638 | 640 | |
|---|
| 639 | | db.prepare("UPDATE ships SET script= ? ",resetsql," WHERE id>0 AND id= ? ").update(script, ship.getInt("id")); |
|---|
| | 641 | db.prepare("UPDATE ships SET script= ? ",resetsql," WHERE id>0 AND id= ? ").update(script, ship.getId()); |
|---|
| 640 | 642 | } |
|---|
| 641 | 643 | else { |
|---|
| 642 | | db.update("UPDATE ships SET script=NULL,scriptexedata=NULL WHERE id>0 AND id='",ship.getInt("id"),"'"); |
|---|
| | 644 | db.update("UPDATE ships SET script=NULL,scriptexedata=NULL WHERE id>0 AND id='",ship.getId(),"'"); |
|---|
| 643 | 645 | } |
|---|
| 644 | 646 | |
|---|
| … | … | |
| 655 | 657 | */ |
|---|
| 656 | 658 | public void communicateAction() { |
|---|
| 657 | | Database db = getDatabase(); |
|---|
| | 659 | org.hibernate.Session db = getDB(); |
|---|
| 658 | 660 | TemplateEngine t = getTemplateEngine(); |
|---|
| 659 | 661 | User user = (User)getUser(); |
|---|
| … | … | |
| 662 | 664 | int communicate = getInteger("communicate"); |
|---|
| 663 | 665 | |
|---|
| 664 | | String[] lock = StringUtils.split(ship.getString("lock"), ':'); |
|---|
| 665 | | |
|---|
| 666 | | if( (lock.length > 2) && !lock[2].equals(Quests.EVENT_ONCOMMUNICATE) ) { |
|---|
| | 666 | String[] lock = StringUtils.split(ship.getLock(), ':'); |
|---|
| | 667 | |
|---|
| | 668 | if( (lock == null) || ((lock.length > 2) && !lock[2].equals(Quests.EVENT_ONCOMMUNICATE)) ) { |
|---|
| 667 | 669 | redirect(); |
|---|
| 668 | 670 | |
|---|
| … | … | |
| 690 | 692 | } |
|---|
| 691 | 693 | |
|---|
| 692 | | SQLResultRow targetship = db.first("SELECT x,y,system,oncommunicate FROM ships WHERE id>0 AND id='",communicate,"'"); |
|---|
| 693 | | if( !Location.fromResult(targetship).sameSector(0, Location.fromResult(ship), 0) ) { |
|---|
| | 694 | Ship targetship = (Ship)db.get(Ship.class, communicate); |
|---|
| | 695 | if( (targetship.getId() < 0) || !targetship.getLocation().sameSector(0, ship.getLocation(), 0) ) { |
|---|
| 694 | 696 | t.set_var("ship.message", "<span style=\"color:red\">Sie können nur mit Schiffen im selben Sektor kommunizieren</span><br />"); |
|---|
| 695 | 697 | redirect(); |
|---|
| 696 | 698 | return; |
|---|
| 697 | 699 | } |
|---|
| 698 | | Quests.executeEvent( scriptparser, targetship.getString("oncommunicate"), user.getID(), execparameter ); |
|---|
| | 700 | Quests.executeEvent( scriptparser, targetship.getOnCommunicate(), user.getID(), execparameter ); |
|---|
| 699 | 701 | |
|---|
| 700 | 702 | redirect(); |
|---|
| … | … | |
| 710 | 712 | User user = (User)getUser(); |
|---|
| 711 | 713 | |
|---|
| 712 | | String[] lock = StringUtils.split(ship.getString("lock"), ':'); |
|---|
| 713 | | |
|---|
| 714 | | if( (lock.length > 2) && !lock[2].equals(Quests.EVENT_ONMOVE) ) { |
|---|
| | 714 | String[] lock = StringUtils.split(ship.getLock(), ':'); |
|---|
| | 715 | |
|---|
| | 716 | if( (lock == null) || ((lock.length > 2) && !lock[2].equals(Quests.EVENT_ONMOVE)) ) { |
|---|
| 715 | 717 | redirect(); |
|---|
| 716 | 718 | |
|---|
| … | … | |
| 736 | 738 | } |
|---|
| 737 | 739 | |
|---|
| 738 | | if( ship.getString("onmove").equals("") ) { |
|---|
| | 740 | if( (ship.getOnMove() == null) || ship.getOnMove().equals("") ) { |
|---|
| 739 | 741 | t.set_var("ship.message", "<span style=\"color:red\">Das angegebene Schiff verfügt nicht über dieses Ereigniss</span><br />"); |
|---|
| 740 | 742 | redirect(); |
|---|
| … | … | |
| 742 | 744 | } |
|---|
| 743 | 745 | |
|---|
| 744 | | Quests.executeEvent( scriptparser, ship.getString("onmove"), user.getID(), execparameter ); |
|---|
| | 746 | Quests.executeEvent( scriptparser, ship.getOnMove(), user.getID(), execparameter ); |
|---|
| 745 | 747 | |
|---|
| 746 | 748 | redirect(); |
|---|
| … | … | |
| 753 | 755 | */ |
|---|
| 754 | 756 | public void onenterAction() { |
|---|
| 755 | | Database db = getDatabase(); |
|---|
| 756 | 757 | TemplateEngine t = getTemplateEngine(); |
|---|
| 757 | 758 | User user = (User)getUser(); |
|---|
| 758 | 759 | |
|---|
| 759 | | String[] lock = StringUtils.split(ship.getString("lock"), ':'); |
|---|
| 760 | | |
|---|
| 761 | | if( (lock.length > 2) && !lock[2].equals(Quests.EVENT_ONENTER) ) { |
|---|
| | 760 | String[] lock = StringUtils.split(ship.getLock(), ':'); |
|---|
| | 761 | |
|---|
| | 762 | if( (lock == null) || ((lock.length > 2) && !lock[2].equals(Quests.EVENT_ONENTER)) ) { |
|---|
| 762 | 763 | redirect(); |
|---|
| 763 | 764 | |
|---|
| … | … | |
| 784 | 785 | |
|---|
| 785 | 786 | if( !usescript.equals("-1") ) { |
|---|
| | 787 | Database database = getDatabase(); |
|---|
| | 788 | |
|---|
| 786 | 789 | parameterString("execparameter"); |
|---|
| 787 | 790 | String execparameter = getString( "execparameter" ); |
|---|
| … | … | |
| 792 | 795 | Quests.currentEventURL.set("&action=onenter"); |
|---|
| 793 | 796 | |
|---|
| 794 | | SQLQuery runningdata = db.query("SELECT id,execdata FROM quests_running WHERE id='",rquestid,"'"); |
|---|
| | 797 | SQLQuery runningdata = database.query("SELECT id,execdata FROM quests_running WHERE id='",rquestid,"'"); |
|---|
| 795 | 798 | Blob execdata = null; |
|---|
| 796 | 799 | |
|---|
| … | … | |
| 805 | 808 | } |
|---|
| 806 | 809 | catch( Exception e ) { |
|---|
| 807 | | LOG.warn("Setting Script-ExecData failed (Ship: "+ship.getInt("id")+": ",e); |
|---|
| | 810 | LOG.warn("Setting Script-ExecData failed (Ship: "+ship.getId()+": ",e); |
|---|
| 808 | 811 | return; |
|---|
| 809 | 812 | } |
|---|
| … | … | |
| 816 | 819 | } |
|---|
| 817 | 820 | |
|---|
| 818 | | String script = db.first("SELECT script FROM scripts WHERE id='",usescript,"'").getString("script"); |
|---|
| | 821 | String script = database.first("SELECT script FROM scripts WHERE id='",usescript,"'").getString("script"); |
|---|
| 819 | 822 | scriptparser.setRegister("USER", Integer.toString(user.getID())); |
|---|
| 820 | 823 | if( !usequest.equals("") ) { |
|---|
| … | … | |
| 822 | 825 | } |
|---|
| 823 | 826 | scriptparser.setRegister("SCRIPT", usescript); |
|---|
| 824 | | scriptparser.setRegister("SECTOR", Location.fromResult(ship).toString()); |
|---|
| | 827 | scriptparser.setRegister("SECTOR", ship.getLocation().toString()); |
|---|
| 825 | 828 | if( (lock.length > 2) ) { |
|---|
| 826 | 829 | scriptparser.setRegister("LOCKEXEC", "1"); |
|---|
| 827 | 830 | } |
|---|
| 828 | 831 | |
|---|
| 829 | | scriptparser.executeScript(db, script, execparameter); |
|---|
| | 832 | scriptparser.executeScript(database, script, execparameter); |
|---|
| 830 | 833 | |
|---|
| 831 | 834 | usequest = scriptparser.getRegister("QUEST"); |
|---|
| … | … | |
| 834 | 837 | try { |
|---|
| 835 | 838 | scriptparser.getContext().toStream(execdata.setBinaryStream(1)); |
|---|
| 836 | | db.prepare("UPDATE quests_running SET execdata=? WHERE id=? ") |
|---|
| | 839 | database.prepare("UPDATE quests_running SET execdata=? WHERE id=? ") |
|---|
| 837 | 840 | .update(execdata, runningdata.getInt("id")); |
|---|
| 838 | 841 | } |
|---|
| 839 | 842 | catch( Exception e ) { |
|---|
| 840 | | LOG.warn("Writing back Script-ExecData failed (Ship: "+ship.getInt("id")+": ",e); |
|---|
| | 843 | LOG.warn("Writing back Script-ExecData failed (Ship: "+ship.getId()+": ",e); |
|---|
| 841 | 844 | return; |
|---|
| 842 | 845 | } |
|---|
| … | … | |
| 991 | 994 | } |
|---|
| 992 | 995 | |
|---|
| 993 | | int negdata = db.first("SELECT id FROM ships WHERE id='",(-ship.getInt("id")),"'").getInt("id"); |
|---|
| | 996 | int negdata = db.first("SELECT id FROM ships WHERE id='",(-ship.getId()),"'").getInt("id"); |
|---|
| 994 | 997 | if( negdata < 0 ) { |
|---|
| 995 | | deleteRespawnEntry(ship.getInt("id")); |
|---|
| 996 | | |
|---|
| 997 | | SQLQuery sid = db.query("SELECT id FROM ships WHERE id>0 AND docked IN ('",ship.getInt("id"),"','l ",ship.getInt("id"),"')"); |
|---|
| | 998 | deleteRespawnEntry(ship.getId()); |
|---|
| | 999 | |
|---|
| | 1000 | SQLQuery sid = db.query("SELECT id FROM ships WHERE id>0 AND docked IN ('",ship.getId(),"','l ",ship.getId(),"')"); |
|---|
| 998 | 1001 | while( sid.next() ) { |
|---|
| 999 | 1002 | deleteRespawnEntry(sid.getInt("id")); |
|---|
| … | … | |
| 1007 | 1010 | int respawntime = getInteger("respawntime"); |
|---|
| 1008 | 1011 | |
|---|
| 1009 | | createRespawnEntry(ship.getInt("id"), respawntime); |
|---|
| 1010 | | |
|---|
| 1011 | | SQLQuery sid = db.query("SELECT id FROM ships WHERE id>0 AND docked IN ('",ship.getInt("id"),"','l ",ship.getInt("id"),"')"); |
|---|
| | 1012 | createRespawnEntry(ship.getId(), respawntime); |
|---|
| | 1013 | |
|---|
| | 1014 | SQLQuery sid = db.query("SELECT id FROM ships WHERE id>0 AND docked IN ('",ship.getId(),"','l ",ship.getId(),"')"); |
|---|
| 1012 | 1015 | while( sid.next() ) { |
|---|
| 1013 | 1016 | createRespawnEntry(sid.getInt("id"),respawntime); |
|---|
| … | … | |
| 1026 | 1029 | */ |
|---|
| 1027 | 1030 | public void inselAction() { |
|---|
| 1028 | | Database db = getDatabase(); |
|---|
| 1029 | 1031 | TemplateEngine t = getTemplateEngine(); |
|---|
| 1030 | 1032 | User user = (User)getUser(); |
|---|
| … | … | |
| 1035 | 1037 | } |
|---|
| 1036 | 1038 | |
|---|
| 1037 | | db.update("UPDATE ships SET x='10',y='10',system='99' WHERE id='",ship.getInt("id"),"'"); |
|---|
| | 1039 | ship.setX(10); |
|---|
| | 1040 | ship.setY(10); |
|---|
| | 1041 | ship.setSystem(99); |
|---|
| | 1042 | |
|---|
| 1038 | 1043 | t.set_var("ship.message", "<span style=\"color:green\">Willkommen auf der Insel <img align=\"middle\" src=\""+Configuration.getSetting("SMILIE_PATH")+"/icon_smile.gif\" alt=\":)\" /></span><br />"); |
|---|
| 1039 | 1044 | |
|---|
| … | … | |
| 1075 | 1080 | User user = (User)getUser(); |
|---|
| 1076 | 1081 | TemplateEngine t = getTemplateEngine(); |
|---|
| 1077 | | Database db = getDatabase(); |
|---|
| 1078 | | |
|---|
| 1079 | | ship = db.first("SELECT * FROM ships WHERE id>0 AND owner='",user.getID(),"' AND id=",ship.getInt("id")); |
|---|
| 1080 | | if( ship.isEmpty() ) { |
|---|
| 1081 | | addError("Das Schiff existiert nicht mehr oder gehört nicht mehr ihnen"); |
|---|
| 1082 | | return; |
|---|
| 1083 | | } |
|---|
| 1084 | | |
|---|
| 1085 | | shiptype = Ship.getShipType(ship); |
|---|
| 1086 | | |
|---|
| | 1082 | org.hibernate.Session db = getDB(); |
|---|
| | 1083 | |
|---|
| | 1084 | db.flush(); |
|---|
| | 1085 | db.refresh(ship); |
|---|
| | 1086 | |
|---|
| 1087 | 1087 | ScriptParser scriptparser = getContext().get(ContextCommon.class).getScriptParser( ScriptParser.NameSpace.QUEST ); |
|---|
| 1088 | | if( ship.isEmpty() ) { |
|---|
| | 1088 | if( ship == null ) { |
|---|
| 1089 | 1089 | if( (scriptparser != null) && (scriptparser.getContext().getOutput().length() != 0) ) { |
|---|
| 1090 | 1090 | t.set_var("ship.scriptparseroutput", |
|---|
| 1091 | 1091 | scriptparser.getContext().getOutput().replace("{{var.sessid}}", getString("sess")) ); |
|---|
| 1092 | 1092 | } |
|---|
| 1093 | | |
|---|
| | 1093 | else { |
|---|
| | 1094 | addError("Das Schiff existiert nicht mehr oder gehört nicht mehr ihnen"); |
|---|
| | 1095 | } |
|---|
| 1094 | 1096 | return; |
|---|
| 1095 | 1097 | } |
|---|
| 1096 | 1098 | |
|---|
| 1097 | | if( ship.getInt("battle") > 0 ) { |
|---|
| | 1099 | shiptype = ship.getTypeData(); |
|---|
| | 1100 | |
|---|
| | 1101 | if( ship.getBattle() > 0 ) { |
|---|
| 1098 | 1102 | if( (scriptparser != null) && (scriptparser.getContext().getOutput().length() > 0) ) { |
|---|
| 1099 | 1103 | t.set_var("ship.scriptparseroutput", |
|---|
| … | … | |
| 1101 | 1105 | } |
|---|
| 1102 | 1106 | |
|---|
| 1103 | | addError("Das Schiff ist in einen Kampf verwickelt (hier klicken um zu diesem zu gelangen)!", Common.buildUrl(getContext(), "default", "module", "angriff", "battle", ship.getString("battle"), "ship", ship.getInt("id")) ); |
|---|
| | 1107 | addError("Das Schiff ist in einen Kampf verwickelt (hier klicken um zu diesem zu gelangen)!", Common.buildUrl(getContext(), "default", "module", "angriff", "battle", ship.getBattle(), "ship", ship.getId()) ); |
|---|
| 1104 | 1108 | return; |
|---|
| 1105 | 1109 | } |
|---|
| 1106 | 1110 | |
|---|
| 1107 | | offizier = Offizier.getOffizierByDest('s', ship.getInt("id")); |
|---|
| | 1111 | offizier = Offizier.getOffizierByDest('s', ship.getId()); |
|---|
| 1108 | 1112 | |
|---|
| 1109 | 1113 | StringBuilder tooltiptext = new StringBuilder(100); |
|---|
| 1110 | 1114 | tooltiptext.append(Common.tableBegin(340, "center").replace('"', '\'') ); |
|---|
| 1111 | | tooltiptext.append("<iframe src='"+Common.buildUrl(getContext(), "default", "module", "impobjects", "system", ship.getInt("system"))+"' name='sector' width='320' height='300' scrolling='auto' marginheight='0' marginwidth='0' frameborder='0'>Ihr Browser unterstützt keine iframes</iframe>"); |
|---|
| | 1115 | tooltiptext.append("<iframe src='"+Common.buildUrl(getContext(), "default", "module", "impobjects", "system", ship.getSystem())+"' name='sector' width='320' height='300' scrolling='auto' marginheight='0' marginwidth='0' frameborder='0'>Ihr Browser unterstützt keine iframes</iframe>"); |
|---|
| 1112 | 1116 | tooltiptext.append(Common.tableEnd().replace('"', '\'') ); |
|---|
| 1113 | 1117 | String tooltiptextStr = StringEscapeUtils.escapeJavaScript(tooltiptext.toString().replace(">", ">").replace("<", "<")); |
|---|
| 1114 | 1118 | |
|---|
| 1115 | 1119 | t.set_var( "ship.showui", 1, |
|---|
| 1116 | | "ship.id", ship.getInt("id"), |
|---|
| 1117 | | "ship.name", Common._plaintitle(ship.getString("name")), |
|---|
| 1118 | | "ship.location", Ships.getLocationText(ship, false), |
|---|
| 1119 | | "ship.type", ship.getInt("type"), |
|---|
| | 1120 | "ship.id", ship.getId(), |
|---|
| | 1121 | "ship.name", Common._plaintitle(ship.getName()), |
|---|
| | 1122 | "ship.location", Ships.getLocationText(ship.getLocation(), false), |
|---|
| | 1123 | "ship.type", ship.getType(), |
|---|
| 1120 | 1124 | "shiptype.picture", shiptype.getPicture(), |
|---|
| 1121 | 1125 | "shiptype.name", shiptype.getNickname(), |
|---|
| 1122 | | "ship.hull.color", genSubColor(ship.getInt("hull"), shiptype.getHull()), |
|---|
| 1123 | | "ship.hull", Common.ln(ship.getInt("hull")), |
|---|
| | 1126 | "ship.hull.color", genSubColor(ship.getHull(), shiptype.getHull()), |
|---|
| | 1127 | "ship.hull", Common.ln(ship.getHull()), |
|---|
| 1124 | 1128 | "shiptype.hull", Common.ln(shiptype.getHull()) |
|---|