Search in sources :

Example 21 with Person

use of objects.Person in project ultimate-java by pantinor.

the class Utils method getPeople.

/**
 * Read the ULT file and parse the people
 *
 * @param fname
 * @return
 */
public static List<Person> getPeople(String fname, Maps map, TileSet ts) {
    byte[] bytes;
    try {
        InputStream is = new FileInputStream("assets/data/" + fname);
        bytes = IOUtils.toByteArray(is);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    Person[] people = new Person[32];
    int MAX_PEOPLE = 32;
    int MAP_WIDTH = 32;
    int startOffset = MAP_WIDTH * MAP_WIDTH;
    int end = startOffset + MAX_PEOPLE;
    int count = 0;
    for (int i = startOffset; i < end; i++) {
        int index = bytes[i] & 0xff;
        if (index == 0) {
            count++;
            continue;
        }
        Person p = new Person();
        p.setId(count);
        p.setTileIndex(index);
        if (ts != null) {
            Tile t = ts.getTileByIndex(index);
            if (t == null) {
                System.err.printf("tile index %s could not be found.\n", index);
            }
            p.setTile(t);
        }
        people[count] = p;
        count++;
    }
    startOffset = MAP_WIDTH * MAP_WIDTH + MAX_PEOPLE * 1;
    end = startOffset + MAX_PEOPLE;
    count = 0;
    for (int i = startOffset; i < end; i++) {
        int start_x = bytes[i] & 0xff;
        Person p = people[count];
        if (p == null) {
            count++;
            continue;
        }
        p.setStart_x(start_x);
        count++;
    }
    startOffset = MAP_WIDTH * MAP_WIDTH + MAX_PEOPLE * 2;
    end = startOffset + MAX_PEOPLE;
    count = 0;
    for (int i = startOffset; i < end; i++) {
        int start_y = bytes[i] & 0xff;
        Person p = people[count];
        if (p == null) {
            count++;
            continue;
        }
        p.setStart_y(start_y);
        count++;
    }
    startOffset = MAP_WIDTH * MAP_WIDTH + MAX_PEOPLE * 6;
    end = startOffset + MAX_PEOPLE;
    count = 0;
    for (int i = startOffset; i < end; i++) {
        int m = bytes[i] & 0xff;
        Person p = people[count];
        if (p == null) {
            count++;
            continue;
        }
        if (m == 0) {
            p.setMovement(ObjectMovementBehavior.FIXED);
        } else if (m == 1) {
            p.setMovement(ObjectMovementBehavior.WANDER);
        } else if (m == 0x80) {
            p.setMovement(ObjectMovementBehavior.FOLLOW_AVATAR);
        } else if (m == 0xFF) {
            p.setMovement(ObjectMovementBehavior.ATTACK_AVATAR);
        }
        count++;
    }
    startOffset = MAP_WIDTH * MAP_WIDTH + MAX_PEOPLE * 7;
    end = startOffset + MAX_PEOPLE;
    count = 0;
    for (int i = startOffset; i < end; i++) {
        int id = bytes[i] & 0xff;
        Person p = people[count];
        if (p == null) {
            count++;
            continue;
        }
        p.setDialogId(id);
        count++;
    }
    List<Person> peeps = new ArrayList<>();
    for (int i = 0; i < people.length; i++) {
        if (people[i] != null) {
            peeps.add(people[i]);
            if (map == Maps.CASTLE_OF_LORD_BRITISH_2 && people[i].getId() == 31) {
                people[i].setConversation(new LordBritishConversation());
            }
            if (map == Maps.CASTLE_OF_LORD_BRITISH_1 && people[i].getId() == 29) {
                people[i].setConversation(new HawkwindConversation());
            }
            if (map == Maps.SKARABRAE && people[i].getId() == 10) {
                // isaac
                people[i].setRemovedFromMap(true);
            }
        }
    }
    return peeps;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) LordBritishConversation(objects.LordBritishConversation) ArrayList(java.util.ArrayList) DungeonTile(ultima.Constants.DungeonTile) Tile(objects.Tile) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) HawkwindConversation(objects.HawkwindConversation) Person(objects.Person) FileInputStream(java.io.FileInputStream)

Example 22 with Person

use of objects.Person in project ultimate-java by pantinor.

the class VendorTest method printVendors.

// @Test
public void printVendors() throws Exception {
    File file2 = new File("target/classes/xml/tileset-base.xml");
    JAXBContext jaxbContext = JAXBContext.newInstance(TileSet.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    TileSet ts = (TileSet) jaxbUnmarshaller.unmarshal(file2);
    ts.setMaps();
    File file3 = new File("target/classes/xml/maps.xml");
    jaxbContext = JAXBContext.newInstance(MapSet.class);
    jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    MapSet ms = (MapSet) jaxbUnmarshaller.unmarshal(file3);
    ms.init(ts);
    ArrayList<Holder> tm = new ArrayList<>();
    for (BaseMap map : ms.getMaps()) {
        if (map.getCity() == null) {
            continue;
        }
        for (Person p : map.getCity().getPeople()) {
            if (p != null && p.getRole() != null && p.getRole().getInventoryType() != null) {
                tm.add(new Holder(p.getRole().getInventoryType(), p, Maps.get(map.getId())));
                System.out.println("type=\"" + p.getRole().getInventoryType() + "\" personId=\"" + p.getId() + "\" " + Maps.get(map.getId()));
            }
        }
    }
    Collections.sort(tm, new MyComparator());
    for (Holder h : tm) {
    // System.out.println("type=\"" +h.t+ "\" personId=\"" + h.p.getId() + "\" " + h.map);
    }
}
Also used : MapSet(objects.MapSet) ArrayList(java.util.ArrayList) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File) TileSet(objects.TileSet) Person(objects.Person) BaseMap(objects.BaseMap)

Example 23 with Person

use of objects.Person in project ultimate-java by pantinor.

the class SecondaryInputProcessor method keyUp.

@Override
public boolean keyUp(int keycode) {
    Direction dir = Direction.NORTH;
    int x = currentX, y = currentY;
    if (keycode == Keys.UP) {
        dir = Direction.NORTH;
        y = y - 1;
    } else if (keycode == Keys.DOWN) {
        dir = Direction.SOUTH;
        y = y + 1;
    } else if (keycode == Keys.LEFT) {
        dir = Direction.WEST;
        x = x - 1;
    } else if (keycode == Keys.RIGHT) {
        dir = Direction.EAST;
        x = x + 1;
    }
    if (screen.scType == ScreenType.MAIN) {
        Window dialog = null;
        if (initialKeyCode == Keys.T) {
            screen.logAppend(dir.toString());
            Tile tile = bm.getTile(x, y);
            if (tile.getRule() == TileRule.signs) {
                // talking to vendor so get the vendor on other side of sign
                switch(dir) {
                    case NORTH:
                        y = y - 1;
                        break;
                    case SOUTH:
                        y = y + 1;
                        break;
                    case EAST:
                        x = x + 1;
                        break;
                    case WEST:
                        x = x - 1;
                        break;
                }
            }
            City city = bm.getCity();
            if (city != null) {
                Person p = city.getPersonAt(x, y);
                if (p != null && (p.getConversation() != null || p.getRole() != null)) {
                    Gdx.input.setInputProcessor(stage);
                    if (p.getRole() != null && p.getRole().getInventoryType() != null && p.getRole().getInventoryType() == InventoryType.TINKER) {
                        dialog = new TinkerDialog(screen.context.getParty(), (GameScreen) screen, stage, Ultima4.skin).show();
                    } else {
                        dialog = new ConversationDialog(p, (GameScreen) screen, stage).show(stage);
                    }
                } else {
                    screen.log("Funny, no response! ");
                }
            } else {
                screen.log("Funny, no response! ");
            }
        } else if (initialKeyCode == Keys.O) {
            screen.logAppend(dir.toString());
            if (bm.openDoor(x, y)) {
                screen.log("Opened!");
            } else {
                screen.log("Can't!");
            }
        } else if (initialKeyCode == Keys.J) {
            screen.logAppend(dir.toString());
            if (screen.context.getParty().getSaveGame().keys > 0 && bm.unlockDoor(x, y)) {
                screen.log("Unlocked!");
                screen.context.getParty().getSaveGame().keys--;
            } else {
                screen.log("Can't!");
            }
        } else if (initialKeyCode == Keys.R) {
            if (keycode >= Keys.NUM_1 && keycode <= Keys.NUM_8) {
                Gdx.input.setInputProcessor(new ReadyWearInputAdapter(screen.context.getParty().getMember(keycode - 7 - 1), true));
                return false;
            }
        } else if (initialKeyCode == Keys.W) {
            if (keycode >= Keys.NUM_1 && keycode <= Keys.NUM_8) {
                Gdx.input.setInputProcessor(new ReadyWearInputAdapter(screen.context.getParty().getMember(keycode - 7 - 1), false));
                return false;
            }
        } else if (initialKeyCode == Keys.G) {
            if (keycode >= Keys.NUM_1 && keycode <= Keys.NUM_8) {
                GameScreen gameScreen = (GameScreen) screen;
                gameScreen.getChest(keycode - 7 - 1, x, y);
            }
        } else if (initialKeyCode == Keys.A) {
            screen.logAppend(dir.toString());
            GameScreen gameScreen = (GameScreen) screen;
            for (Creature c : bm.getCreatures()) {
                if (c.currentX == x && c.currentY == y) {
                    Maps cm = screen.context.getCombatMap(c, bm, x, y, currentX, currentY);
                    gameScreen.attackAt(cm, c);
                    return false;
                }
            }
        }
        if (dialog == null) {
            Gdx.input.setInputProcessor(new InputMultiplexer(screen, stage));
        } else {
            return false;
        }
    } else if (screen.scType == ScreenType.SHRINE) {
        ShrineScreen shrineScreen = (ShrineScreen) screen;
        if (keycode >= Keys.NUM_0 && keycode <= Keys.NUM_3) {
            shrineScreen.meditate(keycode - 7);
        } else {
            screen.log("For how many Cycles (0-3)?");
            return false;
        }
        Gdx.input.setInputProcessor(new InputMultiplexer(screen, stage));
        return false;
    } else if (screen.scType == ScreenType.COMBAT) {
        CombatScreen combatScreen = (CombatScreen) screen;
        if (initialKeyCode == Keys.A) {
            screen.log("Attack > " + dir.toString());
            PartyMember attacker = combatScreen.party.getActivePartyMember();
            WeaponType wt = attacker.getPlayer().weapon;
            if (rangeInputModeDirection != null) {
                switch(rangeInputModeDirection) {
                    case NORTH:
                        y = y - 1;
                        break;
                    case SOUTH:
                        y = y + 1;
                        break;
                    case EAST:
                        x = x + 1;
                        break;
                    case WEST:
                        x = x - 1;
                        break;
                }
                if (keycode >= Keys.NUM_0 && keycode <= Keys.NUM_9) {
                    Sounds.play(Sound.PC_ATTACK);
                    Utils.animateAttack(stage, combatScreen, attacker, rangeInputModeDirection, x, y, keycode - 7);
                } else {
                    screen.log("Invalid range!");
                }
                rangeInputModeDirection = null;
            } else {
                if (wt.getWeapon().getChoosedistance()) {
                    rangeInputModeDirection = dir;
                    screen.log("Throw Range:");
                    return false;
                }
                Sounds.play(Sound.PC_ATTACK);
                int range = wt.getWeapon().getRange();
                Utils.animateAttack(stage, combatScreen, attacker, dir, x, y, range);
            }
            Gdx.input.setInputProcessor(new InputMultiplexer(screen, stage));
            return false;
        } else if (initialKeyCode == Keys.U) {
            if (keycode == Keys.ENTER) {
                if (buffer.length() < 1) {
                    return false;
                }
                String useItem = buffer.toString();
                screen.log(useItem);
                if (useItem.startsWith("stone")) {
                    screen.log("There are holes for 4 stones.");
                    screen.log("What colors?");
                    screen.log("1: ");
                    buffer = new StringBuilder();
                    StoneColorsInputAdapter scia = new StoneColorsInputAdapter(combatScreen);
                    Gdx.input.setInputProcessor(scia);
                } else if (useItem.startsWith("mask")) {
                    if (combatScreen.party.getSaveGame().moves - combatScreen.party.getSaveGame().lastmask >= 4) {
                        screen.log("Use Mask of Minax!");
                        PartyMember attacker = combatScreen.party.getActivePartyMember();
                        SpellUtil.useMaskOfMinax(combatScreen, attacker);
                        combatScreen.party.getSaveGame().lastmask = combatScreen.party.getSaveGame().moves;
                    } else {
                        screen.log("no effect!");
                    }
                    Gdx.input.setInputProcessor(new InputMultiplexer(screen, stage));
                } else if (useItem.startsWith("rage")) {
                    if (combatScreen.party.getSaveGame().moves - combatScreen.party.getSaveGame().lastrage >= 6) {
                        screen.log("Use Rage of God!");
                        PartyMember attacker = combatScreen.party.getActivePartyMember();
                        SpellUtil.useRageOfGod(combatScreen, attacker);
                        combatScreen.party.getSaveGame().lastrage = combatScreen.party.getSaveGame().moves;
                    } else {
                        screen.log("no effect!");
                    }
                    Gdx.input.setInputProcessor(new InputMultiplexer(screen, stage));
                } else {
                    screen.log("Not a usable item!");
                    Gdx.input.setInputProcessor(new InputMultiplexer(screen, stage));
                    combatScreen.finishPlayerTurn();
                }
            } else if (keycode == Keys.BACKSPACE) {
                if (buffer.length() > 0) {
                    buffer.deleteCharAt(buffer.length() - 1);
                    screen.logDeleteLastChar();
                }
            } else if (keycode >= 29 && keycode <= 54) {
                buffer.append(Keys.toString(keycode).toLowerCase());
                screen.logAppend(Keys.toString(keycode).toLowerCase());
            }
            return false;
        }
    } else if (screen.scType == ScreenType.DUNGEON) {
        DungeonScreen dngScreen = (DungeonScreen) screen;
        if (initialKeyCode == Keys.S) {
            switch(dngTile) {
                case FOUNTAIN_PLAIN:
                case FOUNTAIN_HEAL:
                case FOUNTAIN_ACID:
                case FOUNTAIN_CURE:
                case FOUNTAIN_POISON:
                    if (keycode >= Keys.NUM_1 && keycode <= Keys.NUM_8) {
                        dngScreen.dungeonDrinkFountain(dngTile, keycode - 7 - 1);
                    }
                    break;
                case ORB:
                    if (keycode >= Keys.NUM_1 && keycode <= Keys.NUM_8) {
                        dngScreen.dungeonTouchOrb(keycode - 7 - 1);
                    }
                    break;
                default:
                    break;
            }
        } else if (initialKeyCode == Keys.G) {
            if (keycode >= Keys.NUM_1 && keycode <= Keys.NUM_8) {
                dngScreen.getChest(keycode - 7 - 1, currentX, currentY);
            }
        } else if (initialKeyCode == Keys.R) {
            if (keycode >= Keys.NUM_1 && keycode <= Keys.NUM_8) {
                Gdx.input.setInputProcessor(new ReadyWearInputAdapter(screen.context.getParty().getMember(keycode - 7 - 1), true));
                return false;
            }
        } else if (initialKeyCode == Keys.W) {
            if (keycode >= Keys.NUM_1 && keycode <= Keys.NUM_8) {
                Gdx.input.setInputProcessor(new ReadyWearInputAdapter(screen.context.getParty().getMember(keycode - 7 - 1), false));
                return false;
            }
        }
        Gdx.input.setInputProcessor(new InputMultiplexer(screen, stage));
    } else if (screen.scType == ScreenType.TMXDUNGEON) {
        StaticGeneratedDungeonScreen dngScreen = (StaticGeneratedDungeonScreen) screen;
        if (initialKeyCode == Keys.S) {
            switch(dngTile) {
                case FOUNTAIN_PLAIN:
                case FOUNTAIN_HEAL:
                case FOUNTAIN_ACID:
                case FOUNTAIN_CURE:
                case FOUNTAIN_POISON:
                    if (keycode >= Keys.NUM_1 && keycode <= Keys.NUM_8) {
                        dngScreen.dungeonDrinkFountain(dngTile, keycode - 7 - 1);
                    }
                    break;
                case ORB:
                    if (keycode >= Keys.NUM_1 && keycode <= Keys.NUM_8) {
                        dngScreen.dungeonTouchOrb(keycode - 7 - 1);
                    }
                    break;
                default:
                    break;
            }
        } else if (initialKeyCode == Keys.G) {
            if (keycode >= Keys.NUM_1 && keycode <= Keys.NUM_8) {
                dngScreen.getChest(keycode - 7 - 1, currentX, currentY);
            }
        } else if (initialKeyCode == Keys.R) {
            if (keycode >= Keys.NUM_1 && keycode <= Keys.NUM_8) {
                Gdx.input.setInputProcessor(new ReadyWearInputAdapter(screen.context.getParty().getMember(keycode - 7 - 1), true));
                return false;
            }
        } else if (initialKeyCode == Keys.W) {
            if (keycode >= Keys.NUM_1 && keycode <= Keys.NUM_8) {
                Gdx.input.setInputProcessor(new ReadyWearInputAdapter(screen.context.getParty().getMember(keycode - 7 - 1), false));
                return false;
            }
        }
        Gdx.input.setInputProcessor(new InputMultiplexer(screen, stage));
    }
    screen.finishTurn(currentX, currentY);
    return false;
}
Also used : Window(com.badlogic.gdx.scenes.scene2d.ui.Window) Creature(objects.Creature) PartyMember(objects.Party.PartyMember) Tile(objects.Tile) City(objects.City) StaticGeneratedDungeonScreen(generator.StaticGeneratedDungeonScreen) StaticGeneratedDungeonScreen(generator.StaticGeneratedDungeonScreen) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) TinkerDialog(vendor.TinkerDialog) Person(objects.Person)

Example 24 with Person

use of objects.Person in project jbpm by kiegroup.

the class IntermediateEventTest method testConditionalBoundaryEventOnTaskActiveOnStartup.

@Test
public void testConditionalBoundaryEventOnTaskActiveOnStartup() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-BoundaryConditionalEventOnTask.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new TestWorkItemHandler());
    ProcessInstance processInstance = ksession.startProcess("BoundarySignalOnTask");
    Person person = new Person();
    person.setName("john");
    ksession.insert(person);
    assertProcessInstanceCompleted(processInstance);
    assertNodeTriggered(processInstance.getId(), "StartProcess", "User Task", "Boundary event", "Condition met", "End2");
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Person(org.jbpm.bpmn2.objects.Person) Test(org.junit.Test)

Example 25 with Person

use of objects.Person in project jbpm by kiegroup.

the class IntermediateEventTest method testEventBasedSplit3.

@Test
public void testEventBasedSplit3() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-EventBasedSplit3.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    Person jack = new Person();
    jack.setName("Jack");
    // Yes
    ProcessInstance processInstance = ksession.startProcess("com.sample.test");
    assertProcessInstanceActive(processInstance);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    ksession.signalEvent("Yes", "YesValue", processInstance.getId());
    assertProcessInstanceFinished(processInstance, ksession);
    // Condition
    processInstance = ksession.startProcess("com.sample.test");
    assertProcessInstanceActive(processInstance);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    ksession.insert(jack);
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : KieBase(org.kie.api.KieBase) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Person(org.jbpm.bpmn2.objects.Person) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)32 Person (org.jbpm.bpmn2.objects.Person)29 KieBase (org.kie.api.KieBase)28 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)22 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)21 HashMap (java.util.HashMap)10 Person (objects.Person)8 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)8 ArrayList (java.util.ArrayList)6 Tile (objects.Tile)4 Ignore (org.junit.Ignore)4 KieSession (org.kie.api.runtime.KieSession)4 BaseMap (objects.BaseMap)3 DoNothingWorkItemHandler (org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler)3 FileHandle (com.badlogic.gdx.files.FileHandle)2 Region (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region)2 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)2 TiledMap (com.badlogic.gdx.maps.tiled.TiledMap)2 TiledMapTileLayer (com.badlogic.gdx.maps.tiled.TiledMapTileLayer)2 StaticTiledMapTile (com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile)2