Search in sources :

Example 1 with VendorClassSet

use of vendor.VendorClassSet in project ultimate-java by pantinor.

the class VendorTest method testReagentVendor.

// @Test
public void testReagentVendor() throws Exception {
    File file = new File("assets/xml/vendor.xml");
    JAXBContext jaxbContext = JAXBContext.newInstance(VendorClassSet.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    VendorClassSet vcs = (VendorClassSet) jaxbUnmarshaller.unmarshal(file);
    vcs.init();
    SaveGame sg = new SaveGame();
    SaveGame.SaveGamePlayerRecord rec = sg.new SaveGamePlayerRecord();
    rec.name = "avatar";
    rec.hp = 200;
    Party party = new Party(sg);
    Context context = new Context();
    context.setParty(party);
    party.addMember(rec);
    sg.gold = 500;
    BaseVendor v = new ReagentService(vcs.getVendor(InventoryType.REAGENT, Maps.PAWS), context);
    while (true) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        if (!v.nextDialog()) {
            break;
        }
        String input = br.readLine();
        if (input != null && input.equals("bye")) {
            break;
        }
        v.setResponse(input);
    }
    System.err.println("sg gold = " + sg.gold);
}
Also used : Context(ultima.Context) JAXBContext(javax.xml.bind.JAXBContext) BaseVendor(vendor.BaseVendor) InputStreamReader(java.io.InputStreamReader) SaveGame(objects.SaveGame) JAXBContext(javax.xml.bind.JAXBContext) Party(objects.Party) ReagentService(vendor.ReagentService) BufferedReader(java.io.BufferedReader) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File) VendorClassSet(vendor.VendorClassSet)

Example 2 with VendorClassSet

use of vendor.VendorClassSet in project ultimate-java by pantinor.

the class VendorTest method testWeaponVendor.

// @Test
public void testWeaponVendor() throws Exception {
    File file = new File("target/classes/xml/vendor.xml");
    JAXBContext jaxbContext = JAXBContext.newInstance(VendorClassSet.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    VendorClassSet vcs = (VendorClassSet) jaxbUnmarshaller.unmarshal(file);
    vcs.init();
    SaveGame sg = new SaveGame();
    SaveGame.SaveGamePlayerRecord rec = sg.new SaveGamePlayerRecord();
    rec.name = "avatar";
    rec.hp = 200;
    Party party = new Party(sg);
    Context context = new Context();
    context.setParty(party);
    party.addMember(rec);
    sg.gold = 25;
    sg.food = 200;
    party.getSaveGame().weapons[WeaponType.SLING.ordinal()] = 5;
    party.getSaveGame().weapons[WeaponType.MAGICAXE.ordinal()] = 5;
    BaseVendor v = new WeaponVendor(vcs.getVendor(InventoryType.WEAPON, Maps.BRITAIN), context);
    while (true) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        if (!v.nextDialog()) {
            break;
        }
        String input = br.readLine();
        if (input != null && input.equals("bye")) {
            break;
        }
        v.setResponse(input);
    }
    System.err.println("sg gold = " + sg.gold);
    for (WeaponType wt : WeaponType.values()) {
        System.err.println(wt.toString() + " count=" + sg.weapons[wt.ordinal()]);
    }
}
Also used : Context(ultima.Context) JAXBContext(javax.xml.bind.JAXBContext) BaseVendor(vendor.BaseVendor) InputStreamReader(java.io.InputStreamReader) SaveGame(objects.SaveGame) JAXBContext(javax.xml.bind.JAXBContext) Party(objects.Party) WeaponVendor(vendor.WeaponVendor) WeaponType(ultima.Constants.WeaponType) BufferedReader(java.io.BufferedReader) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File) VendorClassSet(vendor.VendorClassSet)

Example 3 with VendorClassSet

use of vendor.VendorClassSet in project ultimate-java by pantinor.

the class VendorTest method testFoodVendor.

// @Test
public void testFoodVendor() throws Exception {
    File file = new File("assets/xml/vendor.xml");
    JAXBContext jaxbContext = JAXBContext.newInstance(VendorClassSet.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    VendorClassSet vcs = (VendorClassSet) jaxbUnmarshaller.unmarshal(file);
    vcs.init();
    SaveGame sg = new SaveGame();
    SaveGame.SaveGamePlayerRecord rec = sg.new SaveGamePlayerRecord();
    rec.name = "avatar";
    rec.hp = 200;
    Party party = new Party(sg);
    Context context = new Context();
    context.setParty(party);
    party.addMember(rec);
    sg.gold = 20;
    BaseVendor v = new GuildVendor(vcs.getVendor(InventoryType.GUILDITEM, Maps.BUCCANEERS_DEN), context);
    while (true) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        if (!v.nextDialog()) {
            break;
        }
        String input = br.readLine();
        if (input != null && input.equals("bye")) {
            break;
        }
        v.setResponse(input);
    }
    System.err.println("sg gold = " + sg.gold);
}
Also used : Context(ultima.Context) JAXBContext(javax.xml.bind.JAXBContext) BaseVendor(vendor.BaseVendor) InputStreamReader(java.io.InputStreamReader) SaveGame(objects.SaveGame) JAXBContext(javax.xml.bind.JAXBContext) Party(objects.Party) BufferedReader(java.io.BufferedReader) GuildVendor(vendor.GuildVendor) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File) VendorClassSet(vendor.VendorClassSet)

Example 4 with VendorClassSet

use of vendor.VendorClassSet in project ultimate-java by pantinor.

the class TestJaxb method testScript.

// @Test
public void testScript() throws Exception {
    File file = new File("target/classes/xml/vendor.xml");
    JAXBContext jaxbContext = JAXBContext.newInstance(VendorClassSet.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    VendorClassSet ss = (VendorClassSet) jaxbUnmarshaller.unmarshal(file);
    for (VendorClass s : ss.getVendorClasses()) {
        System.out.println(s);
    }
}
Also used : VendorClass(vendor.VendorClass) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File) VendorClassSet(vendor.VendorClassSet)

Example 5 with VendorClassSet

use of vendor.VendorClassSet in project ultimate-java by pantinor.

the class VendorTest method testHorseVendor.

// @Test
public void testHorseVendor() throws Exception {
    File file = new File("assets/xml/vendor.xml");
    JAXBContext jaxbContext = JAXBContext.newInstance(VendorClassSet.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    VendorClassSet vcs = (VendorClassSet) jaxbUnmarshaller.unmarshal(file);
    vcs.init();
    SaveGame sg = new SaveGame();
    SaveGame.SaveGamePlayerRecord rec = sg.new SaveGamePlayerRecord();
    rec.name = "avatar";
    rec.hp = 200;
    Party party = new Party(sg);
    Context context = new Context();
    context.setParty(party);
    party.addMember(rec);
    sg.gold = 500;
    BaseVendor v = new HorseService(vcs.getVendor(InventoryType.HORSE, Maps.PAWS), context);
    while (true) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        if (!v.nextDialog()) {
            break;
        }
        String input = br.readLine();
        if (input != null && input.equals("bye")) {
            break;
        }
        v.setResponse(input);
    }
    System.err.println("sg gold = " + sg.gold);
}
Also used : Context(ultima.Context) JAXBContext(javax.xml.bind.JAXBContext) BaseVendor(vendor.BaseVendor) InputStreamReader(java.io.InputStreamReader) SaveGame(objects.SaveGame) JAXBContext(javax.xml.bind.JAXBContext) Party(objects.Party) BufferedReader(java.io.BufferedReader) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File) VendorClassSet(vendor.VendorClassSet) HorseService(vendor.HorseService)

Aggregations

File (java.io.File)7 JAXBContext (javax.xml.bind.JAXBContext)7 Unmarshaller (javax.xml.bind.Unmarshaller)7 VendorClassSet (vendor.VendorClassSet)7 BufferedReader (java.io.BufferedReader)6 InputStreamReader (java.io.InputStreamReader)6 Party (objects.Party)6 SaveGame (objects.SaveGame)6 Context (ultima.Context)6 BaseVendor (vendor.BaseVendor)6 WeaponType (ultima.Constants.WeaponType)1 GuildVendor (vendor.GuildVendor)1 HealerService (vendor.HealerService)1 HorseService (vendor.HorseService)1 InnService (vendor.InnService)1 ReagentService (vendor.ReagentService)1 VendorClass (vendor.VendorClass)1 WeaponVendor (vendor.WeaponVendor)1