Thread: xStream - Loading Weapon Attack/Defence emotions

Results 1 to 2 of 2
  1. #1 xStream - Loading Weapon Attack/Defence emotions 
    🍥🍥🍥


    Join Date
    Dec 2008
    Age
    25
    Posts
    1,709
    Thanks given
    664
    Thanks received
    293
    Rep Power
    621
    Loads weapon attack and defence animations from an XML file using xStream

    Code:
    package org.hyperion.util.xstream;
    
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
    import org.hyperion.rs2.Constants;
    import org.hyperion.util.xstream.impl.CombatData;
    
    /**
     * Loads Combat Data
     * @author crystalcasltes
     */
    public class CombatDataLoader {
    
        private static Map<Integer, CombatData> combatData = new HashMap<Integer, CombatData>();
    
        /**
         * Looks up the Weapon data
         * @param id The weapon ID
         * @return The ID
         */
        public static CombatData lookup(int id) {
            return combatData.get(id);
        }
    
        /**
         * Loads the combat data XML
         * @throws FileNotFoundException File not found
         */
        @SuppressWarnings("unchecked")
        public static void init() throws FileNotFoundException {
            List<CombatData> data = (List<CombatData>) xStreamManager.load(new FileInputStream("./server_data/CombatData.xml"));
            Iterator<CombatData> it = data.iterator();
            while (it.hasNext()) {
                CombatData cdata = it.next();
                for (int id : cdata.getWeaponID()) {
                    combatData.put(id, cdata);
                }
            }
        }
    }
    Code:
    package org.hyperion.util.xstream.impl;
    
    /**
     * Handles all the Combat Data
     * @author vhince
     */
    public class CombatData {
    
        /**
         * The Weapon ID
         */
        private int[] WEAPON_ID;
        /**
         * The Attack Animation
         */
        private int ATTACK_ANIMATION;
        /**
         * The Defence Animation
         */
        private int DEFENCE_ANIMATION;
    
        /**
         * Combat Data
         * @param WEAPON_ID, the Weapon ID
         * @param ANIMATION_ID, the Attacking Animation
         * @param DEFENCE_ANIMATION, the Defence Animation
         */
        
        public CombatData(int[] WEAPON_ID, int ATTACK_ANIMATION, int DEFENCE_ANIMATION) {
            this.WEAPON_ID = WEAPON_ID;
            this.ATTACK_ANIMATION = ATTACK_ANIMATION;
            this.DEFENCE_ANIMATION = DEFENCE_ANIMATION;
        }
    
        /**
         * Gets the Weapon ID
         * @return The Weapon ID.
         */
        public int[] getWeaponID() {
            return WEAPON_ID;
        }
    
        /**
         * Gets the Attack Animation ID
         * @return The Attack Animation ID.
         */
        public int getAttackAnimation() {
            return ATTACK_ANIMATION;
        }
    
        /**
         * Gets the Defence Animation ID
         * @return The Defence Animation ID.
         */
        public int getDefenceAnimation() {
            return DEFENCE_ANIMATION;
        }
    }
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <!--
        Document   : CombatData.xml
        Created on : April 26, 2011, 12:15 AM
        Author     : vhince
        Description:
            Loads all Weapon Attack Animations and Defence Animations
    -->
    <list>
        <CombatData>
            <WEAPON_ID>
                <int>### here</int>
                <int>### Another Item here</int>
            </WEAPON_ID>
            <ATTACK_ANIMATION>#### Attack animation</ATTACK_ANIMATION>
            <DEFENCE_ANIMATION>#### Defence animation</DEFENCE_ANIMATION>
        </CombatData>
         
        <CombatData>
       <!-- To make a different weapon
        </CombatData>
    </list>
    Don't forget to load it
    Code:
    CombatDataLoader.init();
    And add this
    Code:
    xstream.alias("CombatData", CombatData.class);

    Usage:
    Code:
        public static int getAttackAnim(Entity entity) {
                Player player = (Player) entity;
                int id = player.getEquipment().get(Equipment.SLOT_WEAPON).getId();
                return CombatDataLoader.lookup(id).getAttackAnimation();
        }
    Reply With Quote  
     

  2. #2  
    Member
    Join Date
    Oct 2008
    Posts
    190
    Thanks given
    15
    Thanks received
    5
    Rep Power
    0
    First post, nice. I love jesus. Very nice though.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. XStream Saving/Loading XML
    By MoonShade in forum Help
    Replies: 4
    Last Post: 11-04-2009, 12:52 AM
  2. Replies: 4
    Last Post: 10-13-2009, 08:21 PM
  3. Loading using XML - xStream
    By Ultimate in forum Tutorials
    Replies: 29
    Last Post: 03-21-2009, 10:54 AM
  4. XStream loading XML files error...
    By Paketa in forum Help
    Replies: 1
    Last Post: 02-23-2009, 11:18 PM
  5. XStream - Loading
    By Ultimate in forum Help
    Replies: 7
    Last Post: 01-28-2009, 10:33 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •