Changeset 1a410f838ead72f7a7aa1511bd76834c65f540c3
- Timestamp:
- 08/05/07 11:14:29
(1 year ago)
- Author:
- Christopher Jung <bktheg@web.de>
- git-committer:
- Christopher Jung <bktheg@web.de> 1186305269 +0200
- git-parent:
[eca51daa0bf6310e3131f51567756e89ecc5c9c5]
- git-author:
- Christopher Jung <bktheg@web.de> 1186305269 +0200
- Message:
KS: Weitere Umstellungen auf Hibernate
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| rc5d039a |
r1a410f8 |
|
| 21 | 21 | import java.util.HashMap; |
|---|
| 22 | 22 | import java.util.HashSet; |
|---|
| | 23 | import java.util.Iterator; |
|---|
| 23 | 24 | import java.util.List; |
|---|
| 24 | 25 | import java.util.Map; |
|---|
| … | … | |
| 34 | 35 | import net.driftingsouls.ds2.server.config.Weapon; |
|---|
| 35 | 36 | import net.driftingsouls.ds2.server.config.Weapons; |
|---|
| | 37 | import net.driftingsouls.ds2.server.entities.Ammo; |
|---|
| 36 | 38 | import net.driftingsouls.ds2.server.entities.User; |
|---|
| 37 | 39 | import net.driftingsouls.ds2.server.framework.Common; |
|---|
| 38 | 40 | import net.driftingsouls.ds2.server.framework.Context; |
|---|
| 39 | 41 | import net.driftingsouls.ds2.server.framework.ContextMap; |
|---|
| 40 | | import net.driftingsouls.ds2.server.framework.db.Database; |
|---|
| 41 | | import net.driftingsouls.ds2.server.framework.db.SQLQuery; |
|---|
| 42 | 42 | import net.driftingsouls.ds2.server.ships.ShipTypeData; |
|---|
| 43 | 43 | import net.driftingsouls.ds2.server.ships.ShipTypes; |
|---|
| … | … | |
| 200 | 200 | |
|---|
| 201 | 201 | Context context = ContextMap.getContext(); |
|---|
| 202 | | Database db = context.getDatabase(); |
|---|
| | 202 | org.hibernate.Session db = context.getDB(); |
|---|
| 203 | 203 | |
|---|
| 204 | 204 | BattleShip ownShip = battle.getOwnShip(); |
|---|
| … | … | |
| 264 | 264 | Set<Integer> ammoids = new HashSet<Integer>(); |
|---|
| 265 | 265 | |
|---|
| 266 | | SQLQuery ammoid = db.query("SELECT id FROM ammo " + |
|---|
| 267 | | "WHERE type IN ('",Common.implode("','", Weapons.get().weapon(weapon).getAmmoType())+"')"); |
|---|
| 268 | | while( ammoid.next() ) { |
|---|
| 269 | | ammoids.add(ammoid.getInt("id")); |
|---|
| | 266 | Iterator ammoIter = db.createQuery("from Ammo " + |
|---|
| | 267 | "where type in ("+Common.implode("','", Weapons.get().weapon(weapon).getAmmoType())+"')") |
|---|
| | 268 | .iterate(); |
|---|
| | 269 | |
|---|
| | 270 | while( ammoIter.hasNext() ) { |
|---|
| | 271 | Ammo ammo = (Ammo)ammoIter.next(); |
|---|
| | 272 | ammoids.add(ammo.getId()); |
|---|
| 270 | 273 | } |
|---|
| 271 | | ammoid.free(); |
|---|
| 272 | 274 | |
|---|
| 273 | 275 | // Munition |
|---|
| r2c96489 |
r1a410f8 |
|
| 19 | 19 | package net.driftingsouls.ds2.server.modules.ks; |
|---|
| 20 | 20 | |
|---|
| | 21 | import java.util.Iterator; |
|---|
| | 22 | |
|---|
| 21 | 23 | import net.driftingsouls.ds2.server.ContextCommon; |
|---|
| 22 | 24 | import net.driftingsouls.ds2.server.battles.Battle; |
|---|
| … | … | |
| 25 | 27 | import net.driftingsouls.ds2.server.framework.Context; |
|---|
| 26 | 28 | import net.driftingsouls.ds2.server.framework.ContextMap; |
|---|
| 27 | | import net.driftingsouls.ds2.server.framework.db.Database; |
|---|
| 28 | | import net.driftingsouls.ds2.server.framework.db.SQLResultRow; |
|---|
| | 29 | import net.driftingsouls.ds2.server.ships.Ship; |
|---|
| 29 | 30 | |
|---|
| 30 | 31 | /** |
|---|
| … | … | |
| 45 | 46 | public int validate(Battle battle) { |
|---|
| 46 | 47 | BattleShip ownShip = battle.getOwnShip(); |
|---|
| 47 | | Database db = ContextMap.getContext().getDatabase(); |
|---|
| | 48 | org.hibernate.Session db = ContextMap.getContext().getDB(); |
|---|
| 48 | 49 | |
|---|
| 49 | | SQLResultRow dock = db.first("SELECT id FROM ships WHERE docked IN ('l ",ownShip.getId(),"','",ownShip.getId(),"')"); |
|---|
| 50 | | if( !dock.isEmpty() ) { |
|---|
| | 50 | boolean dock = db.createQuery("from Ship where docked in (?,?)") |
|---|
| | 51 | .setString(0, "l "+ownShip.getId()) |
|---|
| | 52 | .setString(1, Integer.toString(ownShip.getId())) |
|---|
| | 53 | .iterate().hasNext(); |
|---|
| | 54 | |
|---|
| | 55 | if( dock ) { |
|---|
| 51 | 56 | return RESULT_OK; |
|---|
| 52 | 57 | } |
|---|
| … | … | |
| 67 | 72 | |
|---|
| 68 | 73 | Context context = ContextMap.getContext(); |
|---|
| 69 | | Database db = context.getDatabase(); |
|---|
| | 74 | org.hibernate.Session db = context.getDB(); |
|---|
| 70 | 75 | BattleShip ownShip = battle.getOwnShip(); |
|---|
| 71 | 76 | |
|---|
| … | … | |
| 74 | 79 | ownShip.getShip().setBattleAction(true); |
|---|
| 75 | 80 | |
|---|
| 76 | | db.update("UPDATE ships SET docked='',battleAction=1 WHERE docked IN ('l ",ownShip.getId(),"','",ownShip.getId(),"')"); |
|---|
| | 81 | int counter = 0; |
|---|
| | 82 | |
|---|
| | 83 | final Iterator shipIter = db.createQuery("from Ship where docked in (?,?)") |
|---|
| | 84 | .setString(0, "l "+ownShip.getId()) |
|---|
| | 85 | .setString(1, Integer.toString(ownShip.getId())) |
|---|
| | 86 | .iterate(); |
|---|
| | 87 | while( shipIter.hasNext() ) { |
|---|
| | 88 | Ship aship = (Ship)shipIter.next(); |
|---|
| | 89 | |
|---|
| | 90 | if( aship.getDocked().charAt(0) == 'l' ) { |
|---|
| | 91 | ownShip.getShip().dock(Ship.DockMode.START, aship); |
|---|
| | 92 | } |
|---|
| | 93 | else { |
|---|
| | 94 | ownShip.getShip().dock(Ship.DockMode.UNDOCK, aship); |
|---|
| | 95 | } |
|---|
| | 96 | aship.setBattleAction(true); |
|---|
| | 97 | |
|---|
| | 98 | counter++; |
|---|
| | 99 | } |
|---|
| 77 | 100 | |
|---|
| 78 | | battle.logme(db.affectedRows()+" Schiffe wurden abgedockt"); |
|---|
| 79 | | battle.logenemy(db.affectedRows()+" Schiffe wurden von der "+Battle.log_shiplink(ownShip.getShip())+" abgedockt\n"); |
|---|
| | 101 | battle.logme(counter+" Schiffe wurden abgedockt"); |
|---|
| | 102 | battle.logenemy(counter+" Schiffe wurden von der "+Battle.log_shiplink(ownShip.getShip())+" abgedockt\n"); |
|---|
| 80 | 103 | |
|---|
| 81 | 104 | battle.setPoints(battle.getOwnSide(), battle.getPoints(battle.getOwnSide()) - 1); |
|---|