Search in sources :

Example 1 with Person

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

the class TestJaxb method parseTlkFiles.

// @Test
public void parseTlkFiles() throws Exception {
    TileSet baseTileSet = (TileSet) Utils.loadXml("tileset-base.xml", TileSet.class);
    baseTileSet.setMaps();
    MapSet maps = (MapSet) Utils.loadXml("maps.xml", MapSet.class);
    for (BaseMap map : maps.getMaps()) {
        if (map.getCity() == null || map.getCity().getTlk_fname() == null) {
            continue;
        }
        List<Person> people;
        try {
            people = Utils.getPeople(map.getFname(), Maps.get(map.getId()), null);
        } catch (Exception e) {
            continue;
        }
        List<Conversation> cons = Utils.getDialogs(map.getCity().getTlk_fname());
        if (people == null) {
            continue;
        }
        for (Person p : people) {
            if (p != null) {
                for (Conversation c : cons) {
                    if (c.getIndex() == p.getDialogId()) {
                        p.setConversation(c);
                    }
                }
            }
        }
        for (Person p : people) {
        // System.out.println(p);
        }
        for (Conversation c : cons) {
            System.out.println(c.toXMLString(Maps.get(map.getId())));
        }
        for (Conversation c : cons) {
            Person per = null;
            for (Person p : people) {
                if (c.getIndex() == p.getDialogId()) {
                    per = p;
                }
            }
            if (per == null) {
            // System.out.println("Extra Dialog: " + c);
            }
        }
    }
// System.out.printf("Latitude [%s' %s]", (char) ((int) 54 / 16 + 'A'), (char) ((int) 54 % 16 + 'A'));
// System.out.printf(" Longitude [%s' %s]\n", (char) ((int) 182 / 16 + 'A'), (char) ((int) 182 % 16 + 'A'));
}
Also used : MapSet(objects.MapSet) Conversation(objects.Conversation) TileSet(objects.TileSet) Person(objects.Person) BaseMap(objects.BaseMap)

Example 2 with Person

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

the class UltMapTmxConvert method create.

@Override
public void create() {
    try {
        File file2 = new File("assets/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("assets/xml/maps.xml");
        jaxbContext = JAXBContext.newInstance(MapSet.class);
        jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        MapSet ms = (MapSet) jaxbUnmarshaller.unmarshal(file3);
        ms.init(ts);
        // load the atlas and determine the tile indexes per tilemap position
        FileHandle f = new FileHandle("assets/tilemaps/latest-atlas.txt");
        TextureAtlasData atlas = new TextureAtlasData(f, f.parent(), false);
        int png_grid_width = 24;
        Tile[] mapTileIds = new Tile[png_grid_width * Constants.tilePixelWidth + 1];
        for (Region r : atlas.getRegions()) {
            int x = r.left / r.width;
            int y = r.top / r.height;
            int i = x + (y * png_grid_width) + 1;
            mapTileIds[i] = ts.getTileByName(r.name);
        }
        for (BaseMap map : ms.getMaps()) {
            if (!map.getFname().endsWith("ult")) {
                continue;
            }
            FileInputStream is = new FileInputStream("assets/data/" + map.getFname());
            byte[] bytes = IOUtils.toByteArray(is);
            Tile[] tiles = new Tile[map.getWidth() * map.getHeight()];
            int pos = 0;
            for (int y = 0; y < map.getHeight(); y++) {
                for (int x = 0; x < map.getWidth(); x++) {
                    // convert a byte to an unsigned int value
                    int index = bytes[pos] & 0xff;
                    pos++;
                    Tile tile = ts.getTileByIndex(index);
                    if (tile == null) {
                        System.out.println("Tile index cannot be found: " + index + " using index 129 for black space.");
                        tile = ts.getTileByIndex(129);
                    }
                    tiles[x + y * map.getWidth()] = tile;
                }
            }
            // map layer
            StringBuilder data = new StringBuilder();
            int count = 1;
            int total = 1;
            for (int i = 0; i < tiles.length; i++) {
                Tile t = tiles[i];
                data.append(findTileMapId(mapTileIds, t.getName())).append(",");
                count++;
                total++;
                if (count > 32) {
                    data.append("\n");
                    count = 1;
                }
            }
            String d = data.toString();
            d = d.substring(0, d.length() - 2);
            List<Person> people = map.getCity().getPeople();
            StringBuilder peopleBuffer = new StringBuilder();
            if (people != null) {
                for (int y = 0; y < map.getHeight(); y++) {
                    for (int x = 0; x < map.getWidth(); x++) {
                        Person p = findPersonAtCoords(people, x, y);
                        if (p == null) {
                            peopleBuffer.append("0,");
                        } else {
                            peopleBuffer.append(findTileMapId(mapTileIds, p.getTile().getName())).append(",");
                        }
                    }
                    peopleBuffer.append("\n");
                }
            }
            String p = peopleBuffer.toString();
            if (p == null || p.length() < 1) {
                count = 1;
                // make empty
                for (int i = 0; i < map.getWidth() * map.getHeight(); i++) {
                    peopleBuffer.append("0,");
                    count++;
                    if (count > map.getWidth()) {
                        peopleBuffer.append("\n");
                        count = 1;
                    }
                }
                p = peopleBuffer.toString();
            }
            p = p.substring(0, p.length() - 2);
            Formatter c = new Formatter(map.getFname(), "latest.png", map.getWidth(), map.getHeight(), Constants.tilePixelWidth, Constants.tilePixelWidth, d, p, people);
            String tmxFName = String.format("tmx/map_%s_%s.tmx", map.getId(), map.getCity().getName().replace(" ", ""));
            FileUtils.writeStringToFile(new File(tmxFName), c.toString());
            System.out.printf("Wrote: %s\n", tmxFName);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("DONE");
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) Tile(objects.Tile) JAXBContext(javax.xml.bind.JAXBContext) TileSet(objects.TileSet) BaseMap(objects.BaseMap) FileInputStream(java.io.FileInputStream) TextureAtlasData(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData) MapSet(objects.MapSet) Region(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File) Person(objects.Person)

Example 3 with Person

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

the class CombatScreen method holeUp.

public static void holeUp(Maps contextMap, final int x, final int y, final BaseScreen rs, final Context context, CreatureSet cs, final TextureAtlas sa, boolean inn) {
    Ultima4.hud.add("Hole up & Camp!");
    if (!inn && context.getCurrentMap().getCity() != null) {
        Ultima4.hud.add("Only outside or in the dungeon!");
        return;
    }
    if (context.getTransportContext() != TransportContext.FOOT) {
        Ultima4.hud.add("Only on foot!");
        return;
    }
    // make sure everyone's asleep
    for (int i = 0; i < context.getParty().getMembers().size(); i++) {
        context.getParty().getMember(i).putToSleep();
    }
    Ultima4.hud.add("Resting");
    final Maps campMap;
    TiledMap tmap;
    if (contextMap == Maps.WORLD) {
        campMap = Maps.CAMP_CON;
    } else if (inn) {
        campMap = Maps.INN_CON;
    } else {
        campMap = Maps.CAMP_DNG;
    }
    tmap = new UltimaTiledMapLoader(campMap, sa, campMap.getMap().getWidth(), campMap.getMap().getHeight(), tilePixelWidth, tilePixelHeight).load();
    context.setCurrentTiledMap(tmap);
    final CombatScreen sc = new CombatScreen(rs, context, contextMap, campMap.getMap(), tmap, null, cs, sa);
    mainGame.setScreen(sc);
    final int CAMP_HEAL_INTERVAL = 5;
    Random rand = new XORShiftRandom();
    SequenceAction seq = Actions.action(SequenceAction.class);
    for (int i = 0; i < CAMP_HEAL_INTERVAL; i++) {
        seq.addAction(Actions.delay(1f));
        seq.addAction(Actions.run(new Runnable() {

            public void run() {
                Ultima4.hud.append(" .");
            }
        }));
    }
    if (!inn && rand.nextInt(8) == 0) {
        seq.addAction(Actions.run(new Runnable() {

            public void run() {
                Ultima4.hud.add("Ambushed!");
                sc.setAmbushingMonsters(rs, x, y, sa);
            }
        }));
    } else {
        seq.addAction(Actions.run(new Runnable() {

            @Override
            public void run() {
                for (int i = 0; i < context.getParty().getMembers().size(); i++) {
                    context.getParty().getMember(i).wakeUp();
                }
                /* Make sure we've waited long enough for camping to be effective */
                boolean healed = false;
                if (((context.getParty().getSaveGame().moves / CAMP_HEAL_INTERVAL) >= 0x10000) || (((context.getParty().getSaveGame().moves / CAMP_HEAL_INTERVAL) & 0xffff) != context.getParty().getSaveGame().lastcamp)) {
                    for (int i = 0; i < context.getParty().getMembers().size(); i++) {
                        PartyMember m = context.getParty().getMember(i);
                        m.getPlayer().mp = m.getPlayer().getMaxMp();
                        if ((m.getPlayer().hp < m.getPlayer().hpMax) && m.heal(HealType.CAMPHEAL)) {
                            healed = true;
                        }
                    }
                }
                Ultima4.hud.add(healed ? "Party Healed!" : "No effect.");
                context.getParty().getSaveGame().lastcamp = (context.getParty().getSaveGame().moves / 5) & 0xffff;
                sc.end();
            }
        }));
        if (inn && contextMap == Maps.SKARABRAE && rand.nextInt(3) == 0) {
            // show isaac
            for (Person p : context.getCurrentMap().getCity().getPeople()) {
                if (p.getId() == 10) {
                    p.setRemovedFromMap(false);
                    p.setStart_x(27);
                    p.setX(27);
                    p.setStart_y(12);
                    p.setY(12);
                    p.setMovement(ObjectMovementBehavior.WANDER);
                }
            }
        }
    }
    sc.getStage().addAction(seq);
}
Also used : Random(java.util.Random) XORShiftRandom(util.XORShiftRandom) PartyMember(objects.Party.PartyMember) UltimaTiledMapLoader(util.UltimaTiledMapLoader) XORShiftRandom(util.XORShiftRandom) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap) Person(objects.Person) SequenceAction(com.badlogic.gdx.scenes.scene2d.actions.SequenceAction)

Example 4 with Person

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

the class UltimaMapRenderer method renderTileLayer.

@Override
public void renderTileLayer(TiledMapTileLayer layer) {
    stateTime += Gdx.graphics.getDeltaTime();
    Color batchColor = batch.getColor();
    // Color.toFloatBits(batchColor.r, batchColor.g, batchColor.b, batchColor.a * layer.getOpacity());
    float color = 0;
    int layerWidth = layer.getWidth();
    int layerHeight = layer.getHeight();
    int layerTileWidth = (int) (layer.getTileWidth() * unitScale);
    int layerTileHeight = (int) (layer.getTileHeight() * unitScale);
    float[] vertices = this.vertices;
    int col1 = Math.max(0, (int) (viewBounds.x / layerTileWidth));
    int col2 = Math.min(layerWidth, (int) ((viewBounds.x + viewBounds.width + layerTileWidth) / layerTileWidth));
    int row1 = Math.max(0, (int) (viewBounds.y / layerTileHeight));
    int row2 = Math.min(layerHeight, (int) ((viewBounds.y + viewBounds.height + layerTileHeight) / layerTileHeight));
    if (bm.getBorderbehavior() == MapBorderBehavior.wrap) {
        col1 = (int) (viewBounds.x / layerTileWidth);
        col2 = (int) ((viewBounds.x + viewBounds.width + layerTileWidth) / layerTileWidth);
        row1 = (int) (viewBounds.y / layerTileHeight);
        row2 = (int) ((viewBounds.y + viewBounds.height + layerTileHeight) / layerTileHeight);
    }
    float y = row2 * layerTileHeight;
    float startX = col1 * layerTileWidth;
    for (int row = row2; row >= row1; row--) {
        float x = startX;
        for (int col = col1; col < col2; col++) {
            TiledMapTileLayer.Cell cell = null;
            if (bm.getBorderbehavior() == MapBorderBehavior.wrap) {
                int cx = col;
                boolean wrapped = false;
                if (col < 0) {
                    cx = layerWidth + col;
                    wrapped = true;
                } else if (col >= layerWidth) {
                    cx = col - layerWidth;
                    wrapped = true;
                }
                int cy = row;
                if (row < 0) {
                    cy = layerHeight + row;
                    wrapped = true;
                } else if (row >= layerHeight) {
                    cy = row - layerHeight;
                    wrapped = true;
                }
                cell = layer.getCell(cx, cy);
                color = wrapped ? getColor(batchColor, -1, -1) : getColor(batchColor, cx, layerHeight - cy - 1);
            } else {
                cell = layer.getCell(col, row);
                color = getColor(batchColor, col, layerHeight - row - 1);
            }
            if (cell == null) {
                x += layerTileWidth;
                continue;
            }
            TiledMapTile tile = cell.getTile();
            if (tile != null) {
                TextureRegion region = tile.getTextureRegion();
                DoorStatus ds = bm.getDoor(col, layerHeight - row - 1);
                if (ds != null) {
                    region = door;
                    if (ds.locked) {
                        region = locked_door;
                    }
                    if (bm.isDoorOpen(ds)) {
                        region = brick_floor;
                    }
                }
                float x1 = x + tile.getOffsetX() * unitScale;
                float y1 = y + tile.getOffsetY() * unitScale;
                float x2 = x1 + region.getRegionWidth() * unitScale;
                float y2 = y1 + region.getRegionHeight() * unitScale;
                float u1 = region.getU();
                float v1 = region.getV2();
                float u2 = region.getU2();
                float v2 = region.getV();
                vertices[X1] = x1;
                vertices[Y1] = y1;
                vertices[C1] = color;
                vertices[U1] = u1;
                vertices[V1] = v1;
                vertices[X2] = x1;
                vertices[Y2] = y2;
                vertices[C2] = color;
                vertices[U2] = u1;
                vertices[V2] = v2;
                vertices[X3] = x2;
                vertices[Y3] = y2;
                vertices[C3] = color;
                vertices[U3] = u2;
                vertices[V3] = v2;
                vertices[X4] = x2;
                vertices[Y4] = y1;
                vertices[C4] = color;
                vertices[U4] = u2;
                vertices[V4] = v1;
                batch.draw(region.getTexture(), vertices, 0, 20);
            }
            x += layerTileWidth;
        }
        y -= layerTileHeight;
    }
    if (bm.getCity() != null) {
        for (Person p : bm.getCity().getPeople()) {
            if (p == null || p.isRemovedFromMap()) {
                continue;
            }
            if (p.getAnim() != null) {
                draw(p.getAnim().getKeyFrame(stateTime, true), p.getCurrentPos().x, p.getCurrentPos().y, p.getX(), p.getY());
            } else {
                draw(p.getTextureRegion(), p.getCurrentPos().x, p.getCurrentPos().y, p.getX(), p.getY());
            }
        }
    }
    List<Creature> crs = bm.getCreatures();
    if (crs.size() > 0) {
        for (Creature cr : crs) {
            if (cr.currentPos == null || !cr.getVisible()) {
                continue;
            }
            if (cr.getTile() == CreatureType.pirate_ship) {
                TextureRegion tr = cr.getAnim().getKeyFrames()[cr.sailDir.getVal() - 1];
                draw(tr, cr.currentPos.x, cr.currentPos.y, cr.currentX, cr.currentY);
            } else {
                draw(cr.getAnim().getKeyFrame(stateTime, true), cr.currentPos.x, cr.currentPos.y, cr.currentX, cr.currentY);
            }
        }
    }
}
Also used : Creature(objects.Creature) Color(com.badlogic.gdx.graphics.Color) DoorStatus(objects.BaseMap.DoorStatus) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) TiledMapTile(com.badlogic.gdx.maps.tiled.TiledMapTile) Person(objects.Person)

Example 5 with Person

use of org.jbpm.bpmn2.objects.Person in project jbpm by kiegroup.

the class CaseServiceImplTest method testStartExpressionCaseWithCaseFile.

@Test
public void testStartExpressionCaseWithCaseFile() {
    Map<String, Object> data = new HashMap<>();
    data.put("person", new Person("john"));
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EXPRESSION_CASE_P_ID, data);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EXPRESSION_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(FIRST_CASE_ID, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
        assertNotNull(cInstance);
        assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
        assertNotNull(cInstance.getCaseFile());
        assertEquals("john", ((Person) cInstance.getCaseFile().getData("person")).getName());
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        Map<String, Object> taskInputs = userTaskService.getTaskInputContentByTaskId(tasks.get(0).getId());
        Object personName = taskInputs.get("personName");
        assertEquals("john", personName);
        caseService.cancelCase(caseId);
        caseId = null;
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
    }
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) HashMap(java.util.HashMap) TaskSummary(org.kie.api.task.model.TaskSummary) QueryContext(org.kie.api.runtime.query.QueryContext) Person(org.jbpm.bpmn2.objects.Person) CaseCommentNotFoundException(org.jbpm.casemgmt.api.CaseCommentNotFoundException) AdHocFragmentNotFoundException(org.jbpm.casemgmt.api.AdHocFragmentNotFoundException) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) CaseActiveException(org.jbpm.casemgmt.api.CaseActiveException) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) 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