Changeset 22f424c190a129e67cc3e513f13bb7e9dd26e43c
- Timestamp:
- 01/13/08 23:04:21 (9 months ago)
- git-parent:
- Files:
-
- db/updates.xml (modified) (1 diff)
- src/net/driftingsouls/ds2/server/entities/SellLimit.java (added)
- src/net/driftingsouls/ds2/server/modules/TradeController.java (modified) (6 diffs)
- templates/trade.html (modified) (1 diff)
- web/WEB-INF/cfg/hibernatemappings.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
db/updates.xml
r953ed23 r22f424c 434 434 ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 435 435 ]]></update> 436 <update type="structure" datum="2008-01-10"><![CDATA[ 437 CREATE TABLE `tradepost_sell` ( 438 `shipid` int(11) NOT NULL, 439 `resourceid` int(11) NOT NULL, 440 `price` int(11) NOT NULL, 441 `limit` int(11) NOT NULL, 442 PRIMARY KEY (`shipid`,`resourceid`) 443 ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 444 445 ALTER TABLE tradepost_sell ADD CONSTRAINT tradepost_sell_fk_ships FOREIGN KEY (shipid) REFERENCES ships(id); 446 ]]></update> 436 447 </updates> src/net/driftingsouls/ds2/server/modules/TradeController.java
r327b751 r22f424c 19 19 package net.driftingsouls.ds2.server.modules; 20 20 21 import java.math.BigInteger; 22 21 23 import net.driftingsouls.ds2.server.ContextCommon; 22 24 import net.driftingsouls.ds2.server.cargo.Cargo; … … 25 27 import net.driftingsouls.ds2.server.entities.GtuWarenKurse; 26 28 import net.driftingsouls.ds2.server.entities.ResourceLimit; 29 import net.driftingsouls.ds2.server.entities.SellLimit; 27 30 import net.driftingsouls.ds2.server.entities.StatVerkaeufe; 28 31 import net.driftingsouls.ds2.server.entities.User; … … 116 119 return true; 117 120 } 121 122 /** 123 * Kauft die angegebenen Waren vom Handelsposten. 124 */ 125 @Action(ActionType.DEFAULT) 126 public void buyAction() { 127 org.hibernate.Session db = getDB(); 128 129 ResourceList resourceList = this.posten.getCargo().getResourceList(); 130 Cargo tradepostCargo = this.posten.getCargo(); 131 User user = (User)getUser(); 132 BigInteger moneyOfBuyer = user.getKonto(); 133 long totalRE = 0; 134 135 for(ResourceEntry resource: resourceList) { 136 parameterNumber(resource.getId()+"from"); 137 long amountToBuy = getInteger(resource.getId()+"from"); 138 139 //Preis und Minimum holen 140 ResourceLimitKey resourceLimitKey = new ResourceLimitKey(posten, resource.getId()); 141 SellLimit limit = (SellLimit)db.get(SellLimit.class, resourceLimitKey); 142 143 //Ware wird nicht verkauft 144 if(limit == null) { 145 continue; 146 } 147 148 long amountOnPost = tradepostCargo.getResourceCount(resource.getId()) - limit.getMinimum(); 149 if(amountToBuy > amountOnPost) { 150 amountToBuy = amountOnPost; 151 } 152 153 long resourceMass = Cargo.getResourceMass(resource.getId(), 1); 154 long neededSpace = amountToBuy * resourceMass; 155 long freeSpaceOnShip = ship.getMaxCargo() - shipCargo.getMass(); 156 157 if(neededSpace > freeSpaceOnShip) { 158 amountToBuy = freeSpaceOnShip / resourceMass; 159 } 160 161 long price = amountToBuy * limit.getPrice(); 162 //Nicht genug Geld da 163 if( moneyOfBuyer.compareTo(BigInteger.valueOf(price)) < 0 ) { 164 amountToBuy = moneyOfBuyer.divide(BigInteger.valueOf(price)).longValue(); 165 price = amountToBuy * limit.getPrice(); 166 } 167 totalRE += price; 168 moneyOfBuyer.subtract(BigInteger.valueOf(price)); 169 170 assert amountToBuy >= 0: "AmountToBuy darf keine negative Zahl sein"; 171 172 if(amountToBuy == 0) { 173 continue; 174 } 175 176 this.posten.transfer(this.ship, resource.getId(), amountToBuy); 177 this.shipCargo = this.ship.getCargo(); 178 } 179 180 this.ship.recalculateShipStatus(); 181 this.posten.recalculateShipStatus(); 182 this.posten.getOwner().transferMoneyFrom(user.getID(), totalRE, "Warenkauf Handelsposten bei "+this.posten.getLocation(), false, User.TRANSFER_SEMIAUTO); 183 redirect(); 184 } 118 185 119 186 /** … … 220 287 } 221 288 222 private boolean isFull() 223 { 289 private boolean isFull() { 224 290 return posten.getTypeData().getCargo() <= posten.getCargo().getMass(); 225 291 } … … 232 298 public void defaultAction() { 233 299 TemplateEngine t = getTemplateEngine(); 300 org.hibernate.Session db = getDB(); 234 301 235 302 t.setVar("error.none",1); … … 267 334 "res.msg", "Dieser Handelsposten ist voll. Bitte beehre uns zu einem spÀteren Zeitpunkt erneut."); 268 335 } 336 337 t.setBlock("_TRADE","resbuy.listitem","resbuy.list"); 338 339 ResourceList buyList = this.posten.getCargo().getResourceList(); 340 for(ResourceEntry resource: buyList) { 341 ResourceLimitKey resourceLimitKey = new ResourceLimitKey(posten, resource.getId()); 342 SellLimit limit = (SellLimit)db.get(SellLimit.class, resourceLimitKey); 343 344 if(limit == null) { 345 continue; 346 } 347 348 t.setVar( "resbuy.img", resource.getImage(), 349 "resbuy.id", resource.getId(), 350 "resbuy.name", resource.getName(), 351 "resbuy.cargo", this.posten.getCargo().getResourceCount(resource.getId()), 352 "resbuy.re", limit.getPrice() ); 353 t.parse("resbuy.list","resbuy.listitem",true); 354 } 269 355 } 270 356 } templates/trade.html
re194c56 r22f424c 45 45 </form> 46 46 {!table_end} 47 {if resbuy.list} 48 {!table_begin 430,center} 49 <form action="./ds" method="post"> 50 <table class="noBorderX" cellpadding="2" width="100%"> 51 <tr> 52 <td colspan="4" class="noBorderX"> 53 <span style="font-weight:bold">Waren kaufen:</span> 54 </td> 55 </tr> 56 <!-- BEGIN resbuy.listitem --> 57 <tr> 58 <td class="noBorderX"><img src="{resbuy.img}"alt="" />{resbuy.name}</td> 59 <td class="noBorderX">{resbuy.cargo}</td> 60 <td class="noBorderX"><input name="{resbuy.id}from" type="text" size="3" value="0" /></td> 61 <td class="noBorderX">{resbuy.re}</td> 62 </tr> 63 <!-- END resbuy.listitem --> 64 <tr> 65 <td class="noBorderX" colspan="4"> 66 <hr noshade="noshade" size="1" style="color:#cccccc" /> 67 </td> 68 </tr> 69 <tr> 70 <td class="noBorderX" colspan="4" align="center"> 71 {!form_create_hidden buy, ship:$global.shipid, tradepost:$global.tradepost} 72 <input type="submit" value="kaufen" style="width:200px" /> 73 </td> 74 </tr> 75 </table> 76 </form> 77 {!table_end} 78 {/endif} 47 79 <br /> 48 80 {!link_to zurück, default, css_class:back, module:schiff, ship:$global.shipid} web/WEB-INF/cfg/hibernatemappings.xml
r64aabad r22f424c 83 83 <mapping class="net.driftingsouls.ds2.server.tasks.Task" /> 84 84 <mapping class="net.driftingsouls.ds2.server.entities.ResourceLimit" /> 85 <mapping class="net.driftingsouls.ds2.server.comm.PM" /> 85 <mapping class="net.driftingsouls.ds2.server.entities.SellLimit" /> 86 <mapping class="net.driftingsouls.ds2.server.comm.PM" /> 86 87 <mapping class="net.driftingsouls.ds2.server.entities.User" /> 87 88 <!-- user_f -->
