Changeset 22f424c190a129e67cc3e513f13bb7e9dd26e43c

Show
Ignore:
Timestamp:
01/13/08 23:04:21 (9 months ago)
Author:
Christopher Jung <bktheg@web.de>
git-committer:
Christopher Jung <bktheg@web.de> 1200261861 +0100
git-parent:

[95c122891a96ea07830b4cdaf7ad5f9c317b32c4]

git-author:
Sebastian Gift <Madison@gt-knm.de> 1200261861 +0100
Message:

Spieler koennen nun Waren an Handelsposten ankaufen.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • db/updates.xml

    r953ed23 r22f424c  
    434434                ) ENGINE=InnoDB DEFAULT CHARSET=utf8;  
    435435        ]]></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> 
    436447</updates> 
  • src/net/driftingsouls/ds2/server/modules/TradeController.java

    r327b751 r22f424c  
    1919package net.driftingsouls.ds2.server.modules; 
    2020 
     21import java.math.BigInteger; 
     22 
    2123import net.driftingsouls.ds2.server.ContextCommon; 
    2224import net.driftingsouls.ds2.server.cargo.Cargo; 
     
    2527import net.driftingsouls.ds2.server.entities.GtuWarenKurse; 
    2628import net.driftingsouls.ds2.server.entities.ResourceLimit; 
     29import net.driftingsouls.ds2.server.entities.SellLimit; 
    2730import net.driftingsouls.ds2.server.entities.StatVerkaeufe; 
    2831import net.driftingsouls.ds2.server.entities.User; 
     
    116119                return true; 
    117120        } 
     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        } 
    118185 
    119186        /** 
     
    220287        } 
    221288         
    222         private boolean isFull() 
    223         { 
     289        private boolean isFull() { 
    224290                return posten.getTypeData().getCargo() <= posten.getCargo().getMass(); 
    225291        } 
     
    232298        public void defaultAction() { 
    233299                TemplateEngine t = getTemplateEngine(); 
     300                org.hibernate.Session db = getDB(); 
    234301                 
    235302                t.setVar("error.none",1); 
     
    267334                                                "res.msg",              "Dieser Handelsposten ist voll. Bitte beehre uns zu einem spÀteren Zeitpunkt erneut."); 
    268335                } 
     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                } 
    269355        } 
    270356} 
  • templates/trade.html

    re194c56 r22f424c  
    4545        </form> 
    4646{!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} 
    4779<br /> 
    4880{!link_to zur&uuml;ck, default, css_class:back, module:schiff, ship:$global.shipid} 
  • web/WEB-INF/cfg/hibernatemappings.xml

    r64aabad r22f424c  
    8383        <mapping class="net.driftingsouls.ds2.server.tasks.Task" /> 
    8484        <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" /> 
    8687        <mapping class="net.driftingsouls.ds2.server.entities.User" /> 
    8788        <!-- user_f -->