Package ru.webcrafter.core.entities

Examples of ru.webcrafter.core.entities.Recipe


            ItemTemplate coal = service.getItemTemplate("Coal");
            if (coal == null) {
                coal = new ItemTemplate("Coal");
                service.addItemTemplate(coal);
            }
            Recipe makeWoodCoal = service.getRecipe("Coal");
            if (makeWoodCoal == null) {
                List<ItemTemplate> ingredients = new ArrayList<ItemTemplate>();
                ingredients.add(wood);
                ingredients.add(fire);
                makeWoodCoal = new Recipe("Coal", ingredients, coal);
                service.addRecipe(makeWoodCoal);
            }
            System.out.println(makeWoodCoal.getId());
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
    }
View Full Code Here


    }

    @RequestMapping("/admin")
    public String onAdminPageLoaded(Map<String, Object> map) {
        map.put("newItemTemplate", new ItemTemplate());
        map.put("newRecipe", new Recipe());

        map.put("itemTemplateList", service.getAllItemTemplates());
        map.put("recipeList", service.getAllRecipes());

        return "admin";
View Full Code Here

        userDAO.updateUser(user);
    }

    public void userCraft(long id, String recipeId) {
        User user = getUser(id);
        Recipe recipe = getRecipe(recipeId);

        List<ItemTemplate> ingredients = recipe.getIngredients();
        List<String> ingrNames = new ArrayList<String>();
        for (ItemTemplate item : ingredients) {
            ingrNames.add(item.getId());
        }
        // check that user has all ingredients
        Set<String> itemKeys = user.getItems().keySet();
        if (!itemKeys.containsAll(ingrNames)) {
            return;
        }

        // apply craft
        Map<String, Long> items = user.getItems();
        for (ItemTemplate ingr : ingredients) {
            Long cnt = items.get(ingr.getId());
            cnt--;
            if (cnt == 0L) {
                items.remove(ingr.getId());
            } else {
                items.put(ingr.getId(), cnt);
            }
        }
        ItemTemplate res = recipe.getResult();
        if (items.containsKey(res.getId())) {
            items.put(res.getId(), items.get(res.getId()) + 1);
        } else {
            items.put(res.getId(), 1L);
        }
View Full Code Here

TOP

Related Classes of ru.webcrafter.core.entities.Recipe

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.