Changeset 8b5930c4a8e83d234eabfc344dc065fe18225e01

Show
Ignore:
Timestamp:
01/01/07 16:30:07 (2 years ago)
Author:
Christopher Jung <bktheg@web.de>
git-committer:
Christopher Jung <bktheg@web.de> 1167665407 +0100
git-parent:

[5c543f001f919169bbf0d7061b41bcb97c58c70e]

git-author:
Christopher Jung <bktheg@web.de> 1167665407 +0100
Message:

Waffen implementiert

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/net/driftingsouls/ds2/server/config/Weapon.java

    rae09dfe r8b5930c  
    1919package net.driftingsouls.ds2.server.config; 
    2020 
     21import org.w3c.dom.Node; 
     22import org.w3c.dom.NodeList; 
     23 
    2124import net.driftingsouls.ds2.server.framework.db.SQLResultRow; 
     25import net.driftingsouls.ds2.server.framework.xml.XMLUtils; 
    2226 
    2327/** 
     
    5761                } 
    5862                 
     63                /** 
     64                 * Gibt das zum Flag gehoerende Bitmuster zurueck 
     65                 * @return Das Bitmuster 
     66                 */ 
    5967                public int getBits() { 
    6068                        return this.bit; 
     
    6270                 
    6371        } 
    64         protected Weapon() { 
    65                 throw new RuntimeException("STUB"); 
    66         } 
    67          
     72         
     73        private String name = ""; 
     74         
     75        private int defTrefferWS = 50; 
     76        private int defSmallTrefferWS = 0; 
     77        private double defTorpTrefferWS = 0; 
     78        private int defSubWS = 0; 
     79         
     80        private int apCost = 1; 
     81        private int eCost = 1; 
     82         
     83        private int baseDamage = 0; 
     84        private int shieldDamage = 0; 
     85        private int areaDamage = 0; 
     86        private int subDamage = 0; 
     87         
     88        private String munition = "none"; 
     89        private int singleshots = 1; 
     90        private boolean destroyable = false; 
     91         
     92        private int flags = 0; 
     93         
     94        /** 
     95         * Konstruktor 
     96         * @param node Der zu landende XML-Knoten 
     97         * @throws Exception 
     98         */ 
     99        public Weapon(Node node) throws Exception { 
     100                this.name = XMLUtils.getStringByXPath(node, "name/text()"); 
     101                 
     102                Node trefferws = XMLUtils.firstNodeByTagName(node, "treffer-ws"); 
     103                if( trefferws != null ) { 
     104                        String defTrefferWS = XMLUtils.getStringAttribute(trefferws, "default"); 
     105                        if( defTrefferWS != null ) { 
     106                                this.defTrefferWS = Integer.parseInt(defTrefferWS); 
     107                        } 
     108                         
     109                        String smallTrefferWS = XMLUtils.getStringAttribute(trefferws, "small"); 
     110                        if( smallTrefferWS != null ) { 
     111                                this.defSmallTrefferWS = Integer.parseInt(smallTrefferWS); 
     112                        } 
     113                         
     114                        String torpTrefferWS = XMLUtils.getStringAttribute(trefferws, "torpedo"); 
     115                        if( torpTrefferWS != null ) { 
     116                                this.defTorpTrefferWS = Double.parseDouble(torpTrefferWS); 
     117                        } 
     118                         
     119                        String subTrefferWS = XMLUtils.getStringAttribute(trefferws, "sub"); 
     120                        if( subTrefferWS != null ) { 
     121                                this.defSubWS = Integer.parseInt(subTrefferWS); 
     122                        } 
     123                } 
     124                 
     125                Node cost = XMLUtils.firstNodeByTagName(node, "cost"); 
     126                if( cost != null ) { 
     127                        String apCost = XMLUtils.getStringAttribute(cost, "ap"); 
     128                        if( apCost != null ) { 
     129                                this.apCost = Integer.parseInt(apCost); 
     130                        } 
     131                         
     132                        String eCost = XMLUtils.getStringAttribute(cost, "e"); 
     133                        if( eCost != null ) { 
     134                                this.eCost = Integer.parseInt(eCost); 
     135                        } 
     136                } 
     137                 
     138                Node damage = XMLUtils.firstNodeByTagName(node, "damage"); 
     139                if( damage != null ) { 
     140                        String hull = XMLUtils.getStringAttribute(damage, "hull"); 
     141                        if( hull != null ) { 
     142                                this.baseDamage = Integer.parseInt(hull); 
     143                        } 
     144                         
     145                        String shields = XMLUtils.getStringAttribute(damage, "shields"); 
     146                        if( shields != null ) { 
     147                                this.shieldDamage = Integer.parseInt(shields); 
     148                        } 
     149                         
     150                        String area = XMLUtils.getStringAttribute(damage, "area"); 
     151                        if( area != null ) { 
     152                                this.areaDamage = Integer.parseInt(area); 
     153                        } 
     154                         
     155                        String sub = XMLUtils.getStringAttribute(damage, "sub"); 
     156                        if( sub != null ) { 
     157                                this.subDamage = Integer.parseInt(sub); 
     158                        } 
     159                } 
     160                 
     161                Node shots = XMLUtils.firstNodeByTagName(node, "shots"); 
     162                if( shots != null ) { 
     163                        String single = XMLUtils.getStringAttribute(shots, "single"); 
     164                        if( single != null ) { 
     165                                this.singleshots = Integer.parseInt(single); 
     166                        } 
     167                         
     168                        String munition = XMLUtils.getStringAttribute(shots, "munition"); 
     169                        if( munition != null ) { 
     170                                this.munition = munition; 
     171                        } 
     172                         
     173                        String destroyable = XMLUtils.getStringAttribute(shots, "destroyable"); 
     174                        if( destroyable != null ) { 
     175                                this.destroyable = Boolean.parseBoolean(destroyable); 
     176                        } 
     177                } 
     178                 
     179                Node flags = XMLUtils.firstNodeByTagName(node, "flags"); 
     180                if( flags != null ) { 
     181                        NodeList flagList = flags.getChildNodes(); 
     182                        for( int i=0; i < flagList.getLength(); i++ ) { 
     183                                if( flagList.item(i).getNodeType() != Node.ELEMENT_NODE ) { 
     184                                        continue; 
     185                                } 
     186                                if( !flagList.item(i).getNodeName().equals("flag") ) { 
     187                                        continue; 
     188                                } 
     189                                 
     190                                this.flags |= Flags.valueOf( XMLUtils.getStringAttribute(flagList.item(i), "id") ).getBits();  
     191                        } 
     192                } 
     193        } 
     194         
     195        /** 
     196         * Gibt den Namen der Waffe zurueck 
     197         * @return Der Name 
     198         */ 
    68199        public String getName() { 
    69                 throw new RuntimeException("STUB"); 
    70         } 
    71          
     200                return this.name; 
     201        } 
     202         
     203        /** 
     204         * Gibt die zum Abfeuern benoetigten AP zurueck 
     205         * @return Die AP-Kosten 
     206         */ 
    72207        public int getAPCost() { 
    73                 throw new RuntimeException("STUB"); 
    74         } 
    75          
     208                return this.apCost; 
     209        } 
     210         
     211        /** 
     212         * Gibt die zum Abfeuern benoetigte Energie zurueck  
     213         * @return Die Energie-Kosten 
     214         */ 
    76215        public int getECost() { 
    77                 throw new RuntimeException("STUB"); 
    78         } 
    79          
     216                return this.eCost; 
     217        } 
     218         
     219        /** 
     220         * Gibt den Schaden der Waffe gegenueber der Schiffshuelle zurueck 
     221         * @param ownShipType Der Schiffstyp des feuernden Schiffes 
     222         * @return Der Schaden an der Huelle 
     223         */ 
    80224        public int getBaseDamage(SQLResultRow ownShipType) { 
    81                 throw new RuntimeException("STUB"); 
    82         } 
    83          
     225                return this.baseDamage; 
     226        } 
     227         
     228        /** 
     229         * Gibt den Multiplikationsfaktor fuer den Schaden in Abhaengigkeit vom getroffenen Schiffstyp zurueck 
     230         * @param enemyShipType Der Typ des Schiffes, auf welches gefeuert werden soll 
     231         * @return Der Multiplikationsfaktor 
     232         */ 
    84233        public int getBaseDamageModifier(SQLResultRow enemyShipType) { 
    85                 throw new RuntimeException("STUB"); 
    86         } 
    87          
     234                return 1; 
     235        } 
     236         
     237        /** 
     238         * Gibt den Schaden der Waffe gegenueber den Schilden zurueck 
     239         * @param ownShipType Der Schiffstyp des feuernden Schiffes 
     240         * @return Der Schaden an den Schilden 
     241         */ 
    88242        public int getShieldDamage(SQLResultRow ownShipType) { 
    89                 throw new RuntimeException("STUB"); 
    90         } 
    91          
     243                return this.shieldDamage; 
     244        } 
     245         
     246        /** 
     247         * Gibt den Schaden der Waffe gegenueber den Subsystemen zurueck 
     248         * @param ownShipType Der Schiffstyp des feuernden Schiffes 
     249         * @return Der Schaden an den Subsystemen 
     250         */ 
    92251        public int getSubDamage(SQLResultRow ownShipType) { 
    93                 throw new RuntimeException("STUB"); 
    94         } 
    95          
     252                return this.subDamage; 
     253        } 
     254         
     255        /** 
     256         * Gibt die Trefferwahrscheinlichkeit gegenueber normalen Schiffen zurueck 
     257         * @return Die Trefferwahrscheinlichkeit gegenueber normalen Schiffen 
     258         */ 
    96259        public int getDefTrefferWS() { 
    97                 throw new RuntimeException("STUB"); 
    98         } 
    99          
     260                return this.defTrefferWS; 
     261        } 
     262         
     263        /** 
     264         * Gibt die Trefferwahrscheinlichkeit gegenueber kleinen Schiffen zurueck 
     265         * @return Die Trefferwahrscheinlichkeit gegenueber kleinen Schiffen 
     266         */ 
    100267        public int getDefSmallTrefferWS() { 
    101                 throw new RuntimeException("STUB"); 
    102         } 
    103          
    104         public int getTorpTrefferWS() { 
    105                 throw new RuntimeException("STUB"); 
    106         } 
    107          
     268                return this.defSmallTrefferWS; 
     269        } 
     270         
     271        /** 
     272         * Gibt die Trefferwahrscheinlichkeit gegenueber anfliegenden Torpedos (und anderen zerstoerbaren Waffen) zurueck 
     273         * @return Die Trefferwahrscheinlichkeit gegenueber Torpedos (und anderen zerstoerbaren Waffen) 
     274         */ 
     275        public double getTorpTrefferWS() { 
     276                return this.defTorpTrefferWS; 
     277        } 
     278         
     279        /** 
     280         * Gibt die Trefferwahrscheinlichkeit gegenueber Subsystemen zurueck 
     281         * @return Die Trefferwahrscheinlichkeit gegenueber Subsystemen 
     282         */ 
    108283        public int getDefSubWS() { 
    109                 throw new RuntimeException("STUB"); 
    110         } 
    111          
     284                return this.defSubWS; 
     285        } 
     286         
     287        /** 
     288         * Berechnet Aenderungen an den Schiffstypen 
     289         * @param ownShipType Der Typ des feuernden Schiffes 
     290         * @param enemyShipType Der Typ des getroffenen Schiffes 
     291         * @return Wurden Aenderungen vorgenommen (<code>true</code>) 
     292         */ 
    112293        public boolean calcShipTypes(SQLResultRow ownShipType, SQLResultRow enemyShipType) { 
    113                 throw new RuntimeException("STUB"); 
    114         } 
    115          
     294                return false; 
     295        } 
     296         
     297        /** 
     298         * Gibt den benoetigten Munitionstyp zurueck. Falls keine Munition verwendet wird, so wird <code>none</code> 
     299         * zurueckgegeben. 
     300         * @return Der benoetigte Munitionstyp oder <code>none</code> 
     301         */ 
    116302        public String getAmmoType() { 
    117                 throw new RuntimeException("STUB"); 
    118         } 
    119          
     303                return this.munition; 
     304        } 
     305         
     306        /** 
     307         * Gibt die Anzahl der Einzelschuesse pro abgefeuertem Schuss zurueck 
     308         * @return Die Anzahl der Einzelschuesse pro abgefeuertem Schiff  
     309         */ 
    120310        public int getSingleShots() { 
    121                 throw new RuntimeException("STUB"); 
    122         } 
    123          
     311                return this.singleshots; 
     312        } 
     313         
     314        /** 
     315         * Gibt die Reichweite des Schadens gegenueber der Umgebung des getroffenen Schiffes zurueck 
     316         * @return Der Umgebungsschaden 
     317         */ 
    124318        public int getAreaDamage() { 
    125                 throw new RuntimeException("STUB"); 
    126         } 
    127          
     319                return this.areaDamage; 
     320        } 
     321         
     322        /** 
     323         * Gibt zurueck, ob das Geschoss durch Abwehrfeuer zerstoerbar ist 
     324         * @return <code>true</code>, falls das Geschoss durch Abwehrfeuer zerstoerbar ist 
     325         */ 
    128326        public boolean getDestroyable() { 
    129                 throw new RuntimeException("STUB"); 
    130         } 
    131          
     327                return this.destroyable; 
     328        } 
     329         
     330        /** 
     331         * Prueft, ob die Waffe ueber das angegebene Flag verfuegt 
     332         * @param flag Das Flag 
     333         * @return <code>true</code>, falls die Waffe das Flag besitzt 
     334         */ 
    132335        public boolean hasFlag(Flags flag) { 
    133                 throw new RuntimeException("STUB")
     336                return (this.flags & flag.getBits()) != 0
    134337        } 
    135338} 
  • src/net/driftingsouls/ds2/server/config/Weapons.java

    r92860eb r8b5930c  
    1919package net.driftingsouls.ds2.server.config; 
    2020 
     21import java.lang.reflect.Constructor; 
    2122import java.util.ArrayList; 
    2223import java.util.HashMap; 
     
    2728 
    2829import net.driftingsouls.ds2.server.framework.Common; 
     30import net.driftingsouls.ds2.server.framework.Configuration; 
     31import net.driftingsouls.ds2.server.framework.Loggable; 
     32import net.driftingsouls.ds2.server.framework.xml.XMLUtils; 
    2933 
    3034import org.apache.commons.lang.StringUtils; 
     35import org.w3c.dom.Document; 
     36import org.w3c.dom.Node; 
     37import org.w3c.dom.NodeList; 
    3138 
    3239/** 
     
    3643 * 
    3744 */ 
    38 public class Weapons implements Iterable<Weapon>
     45public class Weapons implements Iterable<Weapon>,Loggable
    3946        private Map<String, Weapon> list = new LinkedHashMap<String, Weapon>(); 
    4047        private static Weapons instance = new Weapons(); 
     
    102109         
    103110        static { 
    104                 // TODO 
    105                 Common.stub(); 
     111                /* 
     112                 * items.xml parsen 
     113                 */ 
     114                try { 
     115                        final Class<Weapon> wpnClass = Weapon.class; 
     116                         
     117                        Document doc = XMLUtils.readFile(Configuration.getSetting("configdir")+"weapons.xml"); 
     118                        NodeList nodes = XMLUtils.getNodesByXPath(doc, "weapons/weapon"); 
     119                        for( int i=0; i < nodes.getLength(); i++ ) { 
     120                                Node node = nodes.item(i); 
     121                                 
     122                                String id = XMLUtils.getStringAttribute(node, "id"); 
     123                                String cls = XMLUtils.getStringAttribute(node, "handler"); 
     124                                 
     125                                Class<? extends Weapon> concreteClass = wpnClass; 
     126                                 
     127                                if( cls != null ) { 
     128                                        concreteClass = Class.forName(cls).asSubclass(Weapon.class); 
     129                                } 
     130                                 
     131                                Constructor<? extends Weapon> constr = concreteClass.getConstructor(Node.class); 
     132                                Weapon wpn = constr.newInstance(node); 
     133                                 
     134                                instance.list.put(id, wpn); 
     135                        } 
     136                } 
     137                catch( Exception e ) { 
     138                        LOG.fatal("FAILED: Kann Waffen nicht laden",e); 
     139                } 
    106140        } 
    107141} 
  • src/net/driftingsouls/ds2/server/framework/xml/XMLUtils.java

    rb92e3fe r8b5930c  
    119119                return node.getAttributes().getNamedItem(attr).getNodeValue(); 
    120120        } 
     121         
     122        /** 
     123         * Gibt das erste Element mit einem bestimmten Tag-Namen unterhalb eines Knotens zurueck. 
     124         * Wenn kein Element mit dem Tag direkt unter dem angegebenen Knoten gefunden wird, so wird <code>null</code> 
     125         * zurueckgegeben. 
     126         *   
     127         * @param node Der Knoten unter dem gesucht werden soll 
     128         * @param name Der Name des zu suchenden Elements 
     129         * @return Das erste Element mit dem Namen oder <code>null</code> 
     130         */ 
     131        public static Node firstNodeByTagName(Node node, String name) { 
     132                NodeList list = node.getChildNodes(); 
     133                for( int i=0; i < list.getLength(); i++ ) { 
     134                        if( list.item(i).getNodeType() != Node.ELEMENT_NODE ) { 
     135                                continue; 
     136                        } 
     137                        if( list.item(i).getNodeName().equals(name) ) { 
     138                                return list.item(i); 
     139                        } 
     140                } 
     141                 
     142                return null; 
     143        } 
    121144}