Changeset ad0b63630c98d5dda12260a60f1f4a5ce8d63336
- Timestamp:
- 08/19/07 11:26:13
(1 year ago)
- Author:
- Christopher Jung <bktheg@web.de>
- git-committer:
- Christopher Jung <bktheg@web.de> 1187515573 +0200
- git-parent:
[c0c68870c30c436a3997bad6ea4593bf675c54d3]
- git-author:
- Sebastian Gift <Madison@gt-knm.de> 1187515573 +0200
- Message:
\!TRANSFERCARGO verbessert sowie generelles System zum Resourcentransfer eingebaut
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| rd230b2f |
rad0b636 |
|
| 40 | 40 | import net.driftingsouls.ds2.server.Location; |
|---|
| 41 | 41 | import net.driftingsouls.ds2.server.cargo.Cargo; |
|---|
| | 42 | import net.driftingsouls.ds2.server.cargo.ResourceID; |
|---|
| 42 | 43 | import net.driftingsouls.ds2.server.cargo.Resources; |
|---|
| | 44 | import net.driftingsouls.ds2.server.cargo.Transfer; |
|---|
| | 45 | import net.driftingsouls.ds2.server.cargo.Transfering; |
|---|
| 43 | 46 | import net.driftingsouls.ds2.server.entities.User; |
|---|
| 44 | 47 | import net.driftingsouls.ds2.server.framework.Common; |
|---|
| … | … | |
| 60 | 63 | @Entity |
|---|
| 61 | 64 | @Table(name="bases") |
|---|
| 62 | | public class Base implements Cloneable, Lifecycle, Locatable { |
|---|
| | 65 | public class Base implements Cloneable, Lifecycle, Locatable, Transfering { |
|---|
| 63 | 66 | @Id @GeneratedValue |
|---|
| 64 | 67 | private int id; |
|---|
| … | … | |
| 715 | 718 | return new Location(this.getSystem(), this.getX(), this.getY()); |
|---|
| 716 | 719 | } |
|---|
| | 720 | |
|---|
| | 721 | public String transfer(Transfering to, ResourceID resource, long count) { |
|---|
| | 722 | return new Transfer().transfer(this, to, resource, count); |
|---|
| | 723 | } |
|---|
| 717 | 724 | } |
|---|
| r34776f5 |
rad0b636 |
|
| 32 | 32 | import net.driftingsouls.ds2.server.framework.ContextMap; |
|---|
| 33 | 33 | import net.driftingsouls.ds2.server.framework.db.Database; |
|---|
| | 34 | import net.driftingsouls.ds2.server.scripting.transfer.TransferStrategy; |
|---|
| | 35 | import net.driftingsouls.ds2.server.scripting.transfer.TransferStrategyFactory; |
|---|
| 34 | 36 | import net.driftingsouls.ds2.server.ships.RouteFactory; |
|---|
| 35 | 37 | import net.driftingsouls.ds2.server.ships.Ship; |
|---|
| 36 | | import net.driftingsouls.ds2.server.ships.ShipTypeData; |
|---|
| 37 | 38 | import net.driftingsouls.ds2.server.ships.Waypoint; |
|---|
| 38 | 39 | import net.driftingsouls.ds2.server.tasks.Taskmanager; |
|---|
| … | … | |
| 55 | 56 | parser.registerCommand( "DOCK", new Dock(Ship.DockMode.DOCK, false), ScriptParser.Args.PLAIN_VARIABLE ); |
|---|
| 56 | 57 | parser.registerCommand( "GETRESOURCE", new GetResource(), ScriptParser.Args.PLAIN_REG, ScriptParser.Args.PLAIN_REG ); |
|---|
| 57 | | parser.registerCommand( "TRANSFERCARGO", new TransferCargo(), ScriptParser.Args.PLAIN_REG, ScriptParser.Args.PLAIN_REG, ScriptParser.Args.PLAIN_REG, ScriptParser.Args.PLAIN_REG, ScriptParser.Args.PLAIN_REG ); |
|---|
| | 58 | parser.registerCommand( "TRANSFERCARGO", new TransferCargo(), ScriptParser.Args.PLAIN_REG, ScriptParser.Args.PLAIN_REG, ScriptParser.Args.PLAIN_REG, ScriptParser.Args.PLAIN_REG, ScriptParser.Args.PLAIN_REG, ScriptParser.Args.PLAIN_REG ); |
|---|
| 58 | 59 | parser.registerCommand( "ATTACK", new Attack(), ScriptParser.Args.PLAIN_REG ); |
|---|
| 59 | 60 | parser.registerCommand( "RESETSCRIPT", new ResetScript(), ScriptParser.Args.PLAIN_VARIABLE ); |
|---|
| … | … | |
| 291 | 292 | class TransferCargo implements SPFunction { |
|---|
| 292 | 293 | public boolean[] execute( Database database, ScriptParser scriptparser, String[] command ) { |
|---|
| 293 | | org.hibernate.Session db = ContextMap.getContext().getDB(); |
|---|
| 294 | | |
|---|
| 295 | | int shipid1 = Integer.parseInt(command[1]); |
|---|
| 296 | | scriptparser.log("shipid1: "+shipid1+"\n"); |
|---|
| 297 | | |
|---|
| 298 | | String way = command[2].toLowerCase(); |
|---|
| | 294 | String transferType = command[1].toLowerCase(); |
|---|
| | 295 | |
|---|
| | 296 | int idOne = Integer.parseInt(command[2]); |
|---|
| | 297 | scriptparser.log("shipid1: "+idOne+"\n"); |
|---|
| | 298 | |
|---|
| | 299 | String way = command[3].toLowerCase(); |
|---|
| 299 | 300 | scriptparser.log("way: "+way+"\n"); |
|---|
| 300 | 301 | |
|---|
| 301 | | int shipid2 = Integer.parseInt(command[3]); |
|---|
| 302 | | scriptparser.log("shipid2: "+shipid2+"\n"); |
|---|
| 303 | | |
|---|
| 304 | | ResourceID resid = Resources.fromString(command[4]); |
|---|
| 305 | | scriptparser.log("resid: "+resid+"\n"); |
|---|
| 306 | | |
|---|
| 307 | | long count = Value.Long(command[5]); |
|---|
| | 302 | int idTwo = Integer.parseInt(command[4]); |
|---|
| | 303 | scriptparser.log("shipid2: "+idTwo+"\n"); |
|---|
| | 304 | |
|---|
| | 305 | ResourceID resource = Resources.fromString(command[5]); |
|---|
| | 306 | scriptparser.log("resid: "+resource+"\n"); |
|---|
| | 307 | |
|---|
| | 308 | long count = Value.Long(command[6]); |
|---|
| 308 | 309 | scriptparser.log("count: "+count+"\n"); |
|---|
| 309 | 310 | |
|---|
| 310 | | Ship ship1 = scriptparser.getShip(); |
|---|
| 311 | | |
|---|
| 312 | | if( shipid1 > 0 ) { |
|---|
| 313 | | Ship ship = scriptparser.getShip(); |
|---|
| 314 | | User owner = ship.getOwner(); |
|---|
| 315 | | ship1 = (Ship)db.get(Ship.class, shipid1); |
|---|
| 316 | | if( (ship1 == null) || (ship1.getId() < 0) || (ship.getOwner() != owner) ) { |
|---|
| 317 | | scriptparser.log("FEHLER: Das angegebene Schiff (Schiff1) existiert nicht oder gehört nicht diesem Spieler\n"); |
|---|
| 318 | | return CONTINUE; |
|---|
| 319 | | } |
|---|
| 320 | | } |
|---|
| 321 | | |
|---|
| 322 | | Ship ship2 = (Ship)db.get(Ship.class, shipid2); |
|---|
| 323 | | if( (ship2 == null) || (ship2.getId() < 0) || (ship2.getOwner() != ship1.getOwner()) ) { |
|---|
| 324 | | scriptparser.log("FEHLER: Das angegebene Schiff (Schiff2) existiert nicht oder gehört nicht diesem Spieler\n"); |
|---|
| 325 | | return CONTINUE; |
|---|
| 326 | | } |
|---|
| 327 | | |
|---|
| 328 | | if( !way.equals("from") && !way.equals("to") ) { |
|---|
| 329 | | scriptparser.log("FEHLER: Der angegebene Transfermodus >"+way+"< existiert nicht\n"); |
|---|
| | 311 | int from = idOne; |
|---|
| | 312 | int to = idTwo; |
|---|
| | 313 | |
|---|
| | 314 | boolean reversed = false; |
|---|
| | 315 | if( way.equals("to") ) { |
|---|
| | 316 | from = idOne; |
|---|
| | 317 | to = idTwo; |
|---|
| | 318 | } |
|---|
| | 319 | else if( way.equals("from") ) { |
|---|
| | 320 | from = idTwo; |
|---|
| | 321 | to = idOne; |
|---|
| | 322 | reversed = true; |
|---|
| | 323 | } |
|---|
| | 324 | else { |
|---|
| | 325 | scriptparser.log("FEHLER: Transferweg darf nur from/to sein - war aber:"+way+"\n"); |
|---|
| 330 | 326 | return CONTINUE; |
|---|
| 331 | 327 | } |
|---|
| 332 | 328 | |
|---|
| 333 | | if( way.equals("from") ) { |
|---|
| 334 | | Ship tmps = ship1; |
|---|
| 335 | | ship1 = ship2; |
|---|
| 336 | | ship2 = tmps; |
|---|
| 337 | | } |
|---|
| 338 | | |
|---|
| 339 | | Cargo cargo1 = ship1.getCargo(); |
|---|
| 340 | | Cargo cargo2 = ship2.getCargo(); |
|---|
| 341 | | |
|---|
| 342 | | if( count < 0 ) { |
|---|
| 343 | | count = cargo1.getResourceCount( resid ) - count; |
|---|
| 344 | | } |
|---|
| 345 | | |
|---|
| 346 | | if( count > cargo1.getResourceCount( resid ) ) { |
|---|
| 347 | | count = cargo1.getResourceCount( resid ); |
|---|
| 348 | | } |
|---|
| 349 | | |
|---|
| 350 | | ShipTypeData shiptype2 = ship2.getTypeData(); |
|---|
| 351 | | if( count > shiptype2.getCargo() - cargo2.getMass() ) { |
|---|
| 352 | | count = shiptype2.getCargo() - cargo2.getMass(); |
|---|
| 353 | | } |
|---|
| 354 | | |
|---|
| 355 | | scriptparser.log("Transferiere "+count+"x"+resid+"\n"); |
|---|
| 356 | | |
|---|
| 357 | | if( count > 0 ) { |
|---|
| 358 | | cargo2.addResource(resid, count); |
|---|
| 359 | | cargo1.substractResource(resid, count); |
|---|
| 360 | | |
|---|
| 361 | | ship1.setCargo(cargo1); |
|---|
| 362 | | ship2.setCargo(cargo2); |
|---|
| 363 | | |
|---|
| 364 | | scriptparser.setShip(ship1); |
|---|
| 365 | | } |
|---|
| | 329 | |
|---|
| | 330 | TransferStrategy transferStrategy = TransferStrategyFactory.getStrategy(transferType, reversed, from, to); |
|---|
| | 331 | |
|---|
| | 332 | |
|---|
| | 333 | if( transferStrategy == null ) { |
|---|
| | 334 | scriptparser.log("FEHLER: Konnte Transfertyp nicht identifizieren.\n Unterstuetzt werden Schiff zu Schiff (sts), Schiff zu Basis (stb), Basis zu Schiff (bts), Basis zu Basis (btb)\n"); |
|---|
| | 335 | return CONTINUE; |
|---|
| | 336 | } |
|---|
| | 337 | |
|---|
| | 338 | String answer = transferStrategy.transfer(resource, count); |
|---|
| | 339 | |
|---|
| | 340 | scriptparser.log(answer); |
|---|
| 366 | 341 | |
|---|
| 367 | 342 | return CONTINUE; |
|---|
| r9689aa5 |
rad0b636 |
|
| 47 | 47 | import net.driftingsouls.ds2.server.cargo.Cargo; |
|---|
| 48 | 48 | import net.driftingsouls.ds2.server.cargo.ItemCargoEntry; |
|---|
| | 49 | import net.driftingsouls.ds2.server.cargo.ResourceID; |
|---|
| 49 | 50 | import net.driftingsouls.ds2.server.cargo.Resources; |
|---|
| | 51 | import net.driftingsouls.ds2.server.cargo.Transfer; |
|---|
| | 52 | import net.driftingsouls.ds2.server.cargo.Transfering; |
|---|
| 50 | 53 | import net.driftingsouls.ds2.server.cargo.modules.Module; |
|---|
| 51 | 54 | import net.driftingsouls.ds2.server.cargo.modules.Modules; |
|---|
| … | … | |
| 85 | 88 | @Entity |
|---|
| 86 | 89 | @Table(name="ships") |
|---|
| 87 | | public class Ship implements Loggable,Locatable { |
|---|
| | 90 | public class Ship implements Loggable,Locatable,Transfering { |
|---|
| 88 | 91 | /** |
|---|
| 89 | 92 | * Objekt mit Funktionsmeldungen |
|---|
| … | … | |
| 3218 | 3221 | .iterate().next()).intValue() != 0; |
|---|
| 3219 | 3222 | } |
|---|
| | 3223 | |
|---|
| | 3224 | /** |
|---|
| | 3225 | * Transfers resources to another object. |
|---|
| | 3226 | * |
|---|
| | 3227 | * @param to Any object that can transfer/accept transfers. |
|---|
| | 3228 | * @param resource Resource that should be transfered. |
|---|
| | 3229 | * @param count Amout to be transfered. |
|---|
| | 3230 | * @return Informations about the outcome. |
|---|
| | 3231 | */ |
|---|
| | 3232 | public String transfer(Transfering to, ResourceID resource, long count) { |
|---|
| | 3233 | return new Transfer().transfer(this, to, resource, count); |
|---|
| | 3234 | } |
|---|
| | 3235 | |
|---|
| | 3236 | /** |
|---|
| | 3237 | * Gibt den maximalen Cargo, den das Schiff aufnehmen kann, zurueck |
|---|
| | 3238 | * @return Der maximale Cargo |
|---|
| | 3239 | */ |
|---|
| | 3240 | public long getMaxCargo() { |
|---|
| | 3241 | return getTypeData().getCargo(); |
|---|
| | 3242 | } |
|---|
| 3220 | 3243 | } |
|---|