Changeset ae27f31c209666431d2bb6c69fca39c2317d5ac6
- Timestamp:
- 11/01/07 14:24:36 (1 year ago)
- git-parent:
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/net/driftingsouls/ds2/server/entities/OrderShip.java
r6422552 rae27f31 20 20 21 21 import javax.persistence.Entity; 22 import javax.persistence.FetchType; 22 23 import javax.persistence.Id; 24 import javax.persistence.OneToOne; 25 import javax.persistence.PrimaryKeyJoinColumn; 23 26 import javax.persistence.Table; 27 28 import net.driftingsouls.ds2.server.ships.ShipType; 24 29 25 30 import org.hibernate.annotations.Immutable; … … 36 41 @Id 37 42 private int type; 43 @OneToOne(fetch=FetchType.LAZY) 44 @PrimaryKeyJoinColumn 45 private ShipType shipType; 38 46 private int cost; 39 47 … … 58 66 * @return Der Schiffstyp 59 67 */ 60 public int getType() {61 return t ype;68 public ShipType getShipType() { 69 return this.shipType; 62 70 } 63 71 64 72 /** 73 * Gibt die ID des Eintrags zurueck 74 * @return Die ID 75 */ 76 public int getId() { 77 return this.type; 78 } 65 79 } src/net/driftingsouls/ds2/server/modules/NPCOrderController.java
r7375108 rae27f31 8 8 import net.driftingsouls.ds2.server.ContextCommon; 9 9 import net.driftingsouls.ds2.server.Location; 10 import net.driftingsouls.ds2.server.bases.Base; 10 11 import net.driftingsouls.ds2.server.comm.PM; 11 12 import net.driftingsouls.ds2.server.config.Faction; … … 14 15 import net.driftingsouls.ds2.server.config.Rassen; 15 16 import net.driftingsouls.ds2.server.entities.FactionShopOrder; 17 import net.driftingsouls.ds2.server.entities.Order; 18 import net.driftingsouls.ds2.server.entities.OrderOffizier; 19 import net.driftingsouls.ds2.server.entities.OrderShip; 16 20 import net.driftingsouls.ds2.server.entities.User; 17 21 import net.driftingsouls.ds2.server.framework.Common; 18 22 import net.driftingsouls.ds2.server.framework.Configuration; 19 23 import net.driftingsouls.ds2.server.framework.Context; 20 import net.driftingsouls.ds2.server.framework.db.Database;21 import net.driftingsouls.ds2.server.framework.db.SQLQuery;22 import net.driftingsouls.ds2.server.framework.db.SQLResultRow;23 24 import net.driftingsouls.ds2.server.framework.pipeline.generators.Action; 24 25 import net.driftingsouls.ds2.server.framework.pipeline.generators.ActionType; … … 363 364 @Action(ActionType.DEFAULT) 364 365 public void changeOrderLocationAction() { 365 Database db = getDatabase();366 org.hibernate.Session db = getDB(); 366 367 TemplateEngine t = this.getTemplateEngine(); 367 368 User user = (User)this.getUser(); … … 374 375 String ordermessage = ""; 375 376 376 SQLResultRow ships = db.first("SELECT s.id FROM ships s JOIN ship_types st ON s.type=st.id " + 377 "WHERE st.class="+ShipClasses.STATION.ordinal()+" AND s.id>0 " + 378 "AND s.x="+loc.getX()+" AND s.y="+loc.getY()+" AND s.system="+loc.getSystem()+" AND s.owner="+user.getID()); 379 380 SQLResultRow bases = db.first("SELECT id FROM bases WHERE owner="+user.getID()+" AND " + 381 "s.x="+loc.getX()+" AND s.y="+loc.getY()+" AND s.system="+loc.getSystem()); 382 383 if( !bases.isEmpty() || !ships.isEmpty() ) { 377 Ship ship = (Ship)db.createQuery("from Ship as s " + 378 "where s.shiptype.shipClass= :cls AND s.id>0 " + 379 "and s.x= :x and s.y= :y and s.system= :sys and s.owner= :user") 380 .setInteger("cls", ShipClasses.STATION.ordinal()) 381 .setEntity("user", user) 382 .setInteger("x", loc.getX()) 383 .setInteger("y", loc.getY()) 384 .setInteger("sys", loc.getSystem()) 385 .setMaxResults(1) 386 .uniqueResult(); 387 388 Base base = (Base)db.createQuery("from Base where owner= :user and " + 389 "x= :x and y= :y and system= :sys") 390 .setEntity("user", user) 391 .setInteger("x", loc.getX()) 392 .setInteger("y", loc.getY()) 393 .setInteger("sys", loc.getSystem()) 394 .setMaxResults(1) 395 .uniqueResult(); 396 397 if( (base != null) || (ship != null) ) { 384 398 user.setNpcOrderLocation(loc.toString()); 385 399 … … 403 417 @Action(ActionType.DEFAULT) 404 418 public void orderAction() { 405 Database db = getDatabase();419 org.hibernate.Session db = getDB(); 406 420 TemplateEngine t = this.getTemplateEngine(); 407 421 User user = (User)this.getUser(); … … 420 434 421 435 if( order > 0 ) { 422 costs = count*db.first("SELECT cost FROM orders_ships WHERE type=",order).getInt("cost"); 436 OrderShip orderShip = (OrderShip)db.get(OrderShip.class, order); 437 costs = count*orderShip.getCost(); 423 438 } 424 439 else if( order < 0 ) { 425 costs = count*db.first("SELECT cost FROM orders_offiziere WHERE id=",(-order)).getInt("cost"); 440 OrderOffizier orderOffi = (OrderOffizier)db.get(OrderOffizier.class, -order); 441 costs = count*orderOffi.getCost(); 426 442 } 427 443 … … 440 456 } 441 457 for( int i=0; i < count; i++ ) { 442 db.update("INSERT INTO orders (type,tick,user) VALUES (",order,",3,",user.getID(),")"); 458 Order orderObj = new Order(user.getID(), order); 459 orderObj.setTick(3); 460 db.persist(orderObj); 443 461 } 444 462 … … 461 479 @Action(ActionType.DEFAULT) 462 480 public void defaultAction() { 463 Database db = getDatabase();481 org.hibernate.Session db = getDB(); 464 482 TemplateEngine t = this.getTemplateEngine(); 465 483 User user = (User)this.getUser(); … … 469 487 t.setVar( "npcorder.ordermenu", 1 ); 470 488 471 SQLQuery order = db.query("SELECT type FROM orders WHERE user=",user.getID()); 472 while( order.next() ) { 473 Common.safeIntInc(orders, order.getInt("type")); 474 } 475 order.free(); 489 List orderList = db.createQuery("from Order where user= :user") 490 .setInteger("user", user.getID()) 491 .list(); 492 for( Iterator iter=orderList.iterator(); iter.hasNext(); ) { 493 Order order = (Order)iter.next(); 494 Common.safeIntInc(orders, order.getType()); 495 } 476 496 477 497 /* … … 483 503 t.setBlock("_NPCORDER", "ships.listitem", "ships.list"); 484 504 485 SQLQuery ship = db.query("SELECT t1.*,t2.nickname name,t2.class FROM orders_ships t1 JOIN ship_types t2 ON t1.type=t2.id ORDER BY t2.class,t1.type"); 486 while( ship.next() ) { 505 List shipOrders = db.createQuery("from OrderShip order by shipType.shipClass,shipType").list(); 506 for( Iterator iter=shipOrders.iterator(); iter.hasNext(); ) { 507 OrderShip ship = (OrderShip)iter.next(); 508 487 509 t.start_record(); 488 510 489 if( ship.get Int("class") != oldclass ) {511 if( ship.getShipType().getShipClass() != oldclass ) { 490 512 t.setVar( "ship.newclass", 1, 491 "ship.newclass.name", ShipTypes.getShipClass(ship.get Int("class")).getSingular() );513 "ship.newclass.name", ShipTypes.getShipClass(ship.getShipType().getShipClass()).getSingular() ); 492 514 493 oldclass = ship.get Int("class");494 } 495 496 if( orders.containsKey(ship.getInt("type")) ) {497 orders.put(ship.getI nt("type"), 0);498 } 499 500 t.setVar( "ship.name", ship.getS tring("name"),501 "ship.type", ship.getI nt("type"),502 "ship.cost", ship.get Int("cost"),503 "ship.ordercount", orders.get(ship.getI nt("type")) );515 oldclass = ship.getShipType().getShipClass(); 516 } 517 518 if( !orders.containsKey(ship.getId()) ) { 519 orders.put(ship.getId(), 0); 520 } 521 522 t.setVar( "ship.name", ship.getShipType().getNickname(), 523 "ship.type", ship.getId(), 524 "ship.cost", ship.getCost(), 525 "ship.ordercount", orders.get(ship.getId()) ); 504 526 505 527 t.parse("ships.list", "ships.listitem", true); … … 508 530 t.clear_record(); 509 531 } 510 ship.free();511 532 512 533 /* … … 516 537 t.setBlock("_NPCORDER", "offiziere.listitem", "offiziere.list"); 517 538 518 SQLQuery offizier = db.query("SELECT * FROM orders_offiziere WHERE cost > 0 ORDER BY id"); 519 while( offizier.next() ) { 520 if( orders.containsKey(-offizier.getInt("id")) ) { 521 orders.put(-offizier.getInt("id"), 0); 522 } 523 524 t.setVar( "offizier.name", offizier.getString("name"), 525 "offizier.rang", offizier.getInt("rang"), 526 "offizier.cost", offizier.getInt("cost"), 527 "offizier.id", -offizier.getInt("id"), 528 "offizier.ordercount", orders.get(offizier.getInt("id")) ); 539 List offizierOrders = db.createQuery("from OrderOffizier where cost > 0 order by id").list(); 540 for( Iterator iter=offizierOrders.iterator(); iter.hasNext(); ) { 541 OrderOffizier offizier = (OrderOffizier)iter.next(); 542 543 if( !orders.containsKey(-offizier.getId()) ) { 544 orders.put(-offizier.getId(), 0); 545 } 546 547 t.setVar( "offizier.name", offizier.getName(), 548 "offizier.rang", offizier.getRang(), 549 "offizier.cost", offizier.getCost(), 550 "offizier.id", -offizier.getId(), 551 "offizier.ordercount", orders.get(offizier.getId()) ); 529 552 530 553 t.parse("offiziere.list", "offiziere.listitem", true); 531 554 } 532 offizier.free();533 555 } 534 556 }
