Changeset ad0b63630c98d5dda12260a60f1f4a5ce8d63336

Show
Ignore:
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
  • src/net/driftingsouls/ds2/server/bases/Base.java

    rd230b2f rad0b636  
    4040import net.driftingsouls.ds2.server.Location; 
    4141import net.driftingsouls.ds2.server.cargo.Cargo; 
     42import net.driftingsouls.ds2.server.cargo.ResourceID; 
    4243import net.driftingsouls.ds2.server.cargo.Resources; 
     44import net.driftingsouls.ds2.server.cargo.Transfer; 
     45import net.driftingsouls.ds2.server.cargo.Transfering; 
    4346import net.driftingsouls.ds2.server.entities.User; 
    4447import net.driftingsouls.ds2.server.framework.Common; 
     
    6063@Entity 
    6164@Table(name="bases") 
    62 public class Base implements Cloneable, Lifecycle, Locatable
     65public class Base implements Cloneable, Lifecycle, Locatable, Transfering
    6366        @Id @GeneratedValue 
    6467        private int id; 
     
    715718                return new Location(this.getSystem(), this.getX(), this.getY()); 
    716719        } 
     720         
     721        public String transfer(Transfering to, ResourceID resource, long count) { 
     722                return new Transfer().transfer(this, to, resource, count); 
     723        } 
    717724} 
  • src/net/driftingsouls/ds2/server/scripting/ActionFunctions.java

    r34776f5 rad0b636  
    3232import net.driftingsouls.ds2.server.framework.ContextMap; 
    3333import net.driftingsouls.ds2.server.framework.db.Database; 
     34import net.driftingsouls.ds2.server.scripting.transfer.TransferStrategy; 
     35import net.driftingsouls.ds2.server.scripting.transfer.TransferStrategyFactory; 
    3436import net.driftingsouls.ds2.server.ships.RouteFactory; 
    3537import net.driftingsouls.ds2.server.ships.Ship; 
    36 import net.driftingsouls.ds2.server.ships.ShipTypeData; 
    3738import net.driftingsouls.ds2.server.ships.Waypoint; 
    3839import net.driftingsouls.ds2.server.tasks.Taskmanager; 
     
    5556                parser.registerCommand( "DOCK", new Dock(Ship.DockMode.DOCK, false), ScriptParser.Args.PLAIN_VARIABLE ); 
    5657                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 ); 
    5859                parser.registerCommand( "ATTACK", new Attack(), ScriptParser.Args.PLAIN_REG ); 
    5960                parser.registerCommand( "RESETSCRIPT", new ResetScript(), ScriptParser.Args.PLAIN_VARIABLE ); 
     
    291292        class TransferCargo implements SPFunction { 
    292293                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(); 
    299300                        scriptparser.log("way: "+way+"\n"); 
    300301                         
    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]); 
    308309                        scriptparser.log("count: "+count+"\n"); 
    309310                         
    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&ouml;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&ouml;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 &gt;"+way+"&lt; 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"); 
    330326                                return CONTINUE; 
    331327                        } 
    332328                         
    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); 
    366341                         
    367342                        return CONTINUE; 
  • src/net/driftingsouls/ds2/server/ships/Ship.java

    r9689aa5 rad0b636  
    4747import net.driftingsouls.ds2.server.cargo.Cargo; 
    4848import net.driftingsouls.ds2.server.cargo.ItemCargoEntry; 
     49import net.driftingsouls.ds2.server.cargo.ResourceID; 
    4950import net.driftingsouls.ds2.server.cargo.Resources; 
     51import net.driftingsouls.ds2.server.cargo.Transfer; 
     52import net.driftingsouls.ds2.server.cargo.Transfering; 
    5053import net.driftingsouls.ds2.server.cargo.modules.Module; 
    5154import net.driftingsouls.ds2.server.cargo.modules.Modules; 
     
    8588@Entity 
    8689@Table(name="ships") 
    87 public class Ship implements Loggable,Locatable
     90public class Ship implements Loggable,Locatable,Transfering
    8891        /** 
    8992         * Objekt mit Funktionsmeldungen 
     
    32183221                        .iterate().next()).intValue() != 0; 
    32193222        } 
     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        } 
    32203243}