Package ru.webcrafter.core.entities

Examples of ru.webcrafter.core.entities.User


            // HACKZZZ
            final String userName = principal.getName();
            UserAuth userAuth = userService.getUser(userName);
            if (userAuth != null) {
                long userId = userAuth.getUserId();
                User craftUser = service.getUser(userId);
                map.put("userCrafter", craftUser);
            }
        }

        return "craft";
View Full Code Here


        userAuth.setActive(true);
        Md5PasswordEncoder enc = new Md5PasswordEncoder();
        userAuth.setPasswordHash(enc.encodePassword(userAuth.getPasswordHash(), null));
        userService.createUser(userAuth);
        User user = new User();
        user.setId(userAuth.getUserId());
        service.addUser(user);

        return "redirect:/index";
    }
View Full Code Here

    public void addUser(User user) {
        hibernateTemplate.save(user);
    }

    public User getUser(long id) {
        User user = hibernateTemplate.get(User.class, id);
        return user;
    }
View Full Code Here

    public void updateUser(User user) {
        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);
        }
        user.setItems(items);

        updateUser(user);

    }
View Full Code Here

        updateUser(user);

    }

    public void userBuyItem(long id, String itemId) {
        User user = getUser(id);
        ItemTemplate itemTemplate = getItemTemplate(itemId);

        Long amount = user.getAmount();
        if (amount < itemTemplate.getCost()) {
            return;
        }
        user.setAmount(amount - itemTemplate.getCost());
        Map<String, Long> items = user.getItems();
        if (items.containsKey(itemId)) {
            items.put(itemId, items.get(itemId) + 1);
        } else {
            items.put(itemId, 1L);
        }
        user.setItems(items);

        updateUser(user);

    }
View Full Code Here

    }

    @Transactional
    public void userSellItem(long id, String itemId) {
        User user = getUser(id);

        Map<String, Long> items = user.getItems();
        if (!items.containsKey(itemId)) {
            return;
        }
        Long cnt = items.get(itemId);
        cnt--;
        if (cnt == 0L) {
            items.remove(itemId);
        } else {
            items.put(itemId, cnt);
        }
        user.setItems(items);
        ItemTemplate itemTemplate = getItemTemplate(itemId);
        user.setAmount(user.getAmount() + itemTemplate.getCost());

        updateUser(user);

    }
View Full Code Here

TOP

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

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.