<commit_before>package engine.shop;

import java.util.ArrayList;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import engine.game.Player;
import engine.gameobject.GameObject;
import engine.gameobject.weapon.upgradetree.upgradebundle.UpgradeBundle;
import engine.prototype.Prototype;
import engine.shop.tag.GameObjectTag;
import engine.shop.tag.PriceTag;
import gameworld.GameWorld;


/**
 * Manages the maps containing the purchasable prototypes. Assumes all given Prototypes contain a
 * PriceTag, and are therefore available for purchase.
 * 
 * @author <NAME>
 *
 */
public class ShopModelSimple implements ShopModel {
    private Player currentPlayer;
    private GameWorld myGameWorld;
    private Map<String, Prototype<GameObject>> prototypeMap;
    private Map<String, UpgradeBundle> upgradeMap;
    private final double markup;
    private GameObject currentGameObject;

    public ShopModelSimple (List<Prototype<GameObject>> prototypes,
                            GameWorld currentGameWorld,
                            Player currentPlayer, double markup) {
        this.markup = markup;
        this.currentPlayer = currentPlayer;
        prototypeMap = new HashMap<String, Prototype<GameObject>>();
        upgradeMap = new HashMap<String, UpgradeBundle>();
        prototypes.forEach(prototype -> addPrototype(prototype));
    }

    public void addPrototype (Prototype<GameObject> prototype) {
        prototypeMap.put(prototype.getTag().getName(), prototype);
    }

    @Override
    public List<ItemGraphic> getItemGraphics () {
        List<ItemGraphic> items = new ArrayList<ItemGraphic>();
        prototypeMap.values().forEach(prototype -> items.add(new ItemGraphic(prototype.getTag()
                .getName(), ((PriceTag) prototype.getTag())
                .getShopGraphic(), new TransitionOnClicked(this, prototype
                .getTag().getName()))));
        return items;
    }

    public List<ItemGraphic> getUpgradeGraphics (GameObject gameObject) {
        currentGameObject = gameObject;
        List<UpgradeBundle> bundles = gameObject.getWeapon().getNextUpgrades();
        List<ItemGraphic> upgradeGraphics = new ArrayList<ItemGraphic>();
        upgradeMap.clear();
        bundles.forEach(bundle -> {
            upgradeMap.put(bundle.getTag().getName(), bundle);
            upgradeGraphics.add(new ItemGraphic(bundle.getTag().getName(), bundle.getTag()
                    .getShopGraphic(), new BuyOnClicked(this, bundle.getTag().getName())));
        });
        return upgradeGraphics;
    }

    /**
     * Purchases and item and places it at the selected position on the screen
     * 
     * @param transitionGameObject
     */
    public void purchaseGameObject (String name, double x, double y) {
        myGameWorld.addObject(prototypeMap.get(name).clone());
        currentPlayer.getWallet().withdraw(getPrice(name));
    }

    /**
     * Applies an upgrade to the given GameObject and subtracts the appropriate amount from the
     * player's wallet.
     * 
     * @param itemGraphic
     */
    @Override
    public void purchaseUpgrade (String name) {
        currentPlayer.getWallet().withdraw(getPrice(name));
        currentGameObject.getWeapon().applyUpgrade(upgradeMap.get(name));
        getUpgradeGraphics(currentGameObject);
    }

    public boolean canPurchase (String name) {
        return currentPlayer.getWallet().getBalance() >= getPrice(name);
    }

    public double getPrice (String name) {
        return getPriceTag(name).getValue() * markup;
    }

    @Override
    public TransitionGameObject getTransitionGameObject (String name) {
        Prototype<GameObject> prototype = prototypeMap.get(name);
        return new TransitionGameObject(prototype.getTag().getName(),
                                        ((GameObjectTag) prototype.getTag()).getGraphic(),
                                        prototype.getRange());
    }

    @Override
    public Map<ItemInfo, String> getInfo (String name) {
        Map<ItemInfo, String> info = new EnumMap<ItemInfo, String>(ItemInfo.class);
        info.put(ItemInfo.NAME, name);
        info.put(ItemInfo.DESCRIPTION, getPriceTag(name).getDescription());
        info.put(ItemInfo.PRICE, Double.toString(getPrice(name)));
        return info;
    }

    //TODO: account for the possibility of a "name" not in either map
    private PriceTag getPriceTag (String name) {
        if (prototypeMap.containsKey(name)) {
            return (PriceTag) prototypeMap.get(name).getTag();
        }
        else {
            return upgradeMap.get(name).getTag();
        }
    }

    public enum ItemInfo {
        NAME, DESCRIPTION, PRICE
    }

}<commit_msg>Added checkPlacement method to ShopModel<commit_after>package engine.shop;

import java.util.ArrayList;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javafx.geometry.Point2D;
import engine.game.Player;
import engine.gameobject.GameObject;
import engine.gameobject.weapon.upgradetree.upgradebundle.UpgradeBundle;
import engine.prototype.Prototype;
import engine.shop.tag.GameObjectTag;
import engine.shop.tag.PriceTag;
import gameworld.GameWorld;


/**
 * Manages the maps containing the purchasable prototypes. Assumes all given Prototypes contain a
 * PriceTag, and are therefore available for purchase.
 * 
 * @author <NAME>
 *
 */
public class ShopModelSimple implements ShopModel {
    private Player currentPlayer;
    private GameWorld myGameWorld;
    private Map<String, Prototype<GameObject>> prototypeMap;
    private Map<String, UpgradeBundle> upgradeMap;
    private final double markup;
    private GameObject currentGameObject;

    public ShopModelSimple (List<Prototype<GameObject>> prototypes,
                            GameWorld currentGameWorld,
                            Player currentPlayer, double markup) {
        this.markup = markup;
        this.currentPlayer = currentPlayer;
        prototypeMap = new HashMap<String, Prototype<GameObject>>();
        upgradeMap = new HashMap<String, UpgradeBundle>();
        prototypes.forEach(prototype -> addPrototype(prototype));
    }

    public void addPrototype (Prototype<GameObject> prototype) {
        prototypeMap.put(prototype.getTag().getName(), prototype);
    }

    @Override
    public List<ItemGraphic> getItemGraphics () {
        List<ItemGraphic> items = new ArrayList<ItemGraphic>();
        prototypeMap.values().forEach(prototype -> items.add(new ItemGraphic(prototype.getTag()
                .getName(), ((PriceTag) prototype.getTag())
                .getShopGraphic(), new TransitionOnClicked(this, prototype
                .getTag().getName()))));
        return items;
    }

    public List<ItemGraphic> getUpgradeGraphics (GameObject gameObject) {
        currentGameObject = gameObject;
        List<UpgradeBundle> bundles = gameObject.getWeapon().getNextUpgrades();
        List<ItemGraphic> upgradeGraphics = new ArrayList<ItemGraphic>();
        upgradeMap.clear();
        bundles.forEach(bundle -> {
            upgradeMap.put(bundle.getTag().getName(), bundle);
            upgradeGraphics.add(new ItemGraphic(bundle.getTag().getName(), bundle.getTag()
                    .getShopGraphic(), new BuyOnClicked(this, bundle.getTag().getName())));
        });
        return upgradeGraphics;
    }

    /**
     * Purchases and item and places it at the selected position on the screen
     * 
     * @param transitionGameObject
     */
    public void purchaseGameObject (String name, double x, double y) {
        myGameWorld.addObject(prototypeMap.get(name).clone());
        currentPlayer.getWallet().withdraw(getPrice(name));
    }

    /**
     * Applies an upgrade to the given GameObject and subtracts the appropriate amount from the
     * player's wallet.
     * 
     * @param itemGraphic
     */
    @Override
    public void purchaseUpgrade (String name) {
        currentPlayer.getWallet().withdraw(getPrice(name));
        currentGameObject.getWeapon().applyUpgrades(upgradeMap.get(name));
        getUpgradeGraphics(currentGameObject);
    }

    public boolean canPurchase (String name) {
        return currentPlayer.getWallet().getBalance() >= getPrice(name);
    }

    public double getPrice (String name) {
        return getPriceTag(name).getValue() * markup;
    }

    @Override
    public TransitionGameObject getTransitionGameObject (String name) {
        Prototype<GameObject> prototype = prototypeMap.get(name);
        return new TransitionGameObject(prototype.getTag().getName(),
                                        ((GameObjectTag) prototype.getTag()).getGraphic(),
                                        prototype.getRange());
    }

    @Override
    public Map<ItemInfo, String> getInfo (String name) {
        Map<ItemInfo, String> info = new EnumMap<ItemInfo, String>(ItemInfo.class);
        info.put(ItemInfo.NAME, name);
        info.put(ItemInfo.DESCRIPTION, getPriceTag(name).getDescription());
        info.put(ItemInfo.PRICE, Double.toString(getPrice(name)));
        return info;
    }

    //TODO: account for the possibility of a "name" not in either map
    private PriceTag getPriceTag (String name) {
        if (prototypeMap.containsKey(name)) {
            return (PriceTag) prototypeMap.get(name).getTag();
        }
        else {
            return upgradeMap.get(name).getTag();
        }
    }

    public enum ItemInfo {
        NAME, DESCRIPTION, PRICE
    }
    
    public boolean checkPlacement (String name, Point2D location) {
        return myGameWorld.isPlacable(prototypeMap.get(name).getTag().getGraphic().getNode(), location);
    }

}
{'fraction_non_alphanumeric': 0.10395631568102205, 'fraction_numerical': 0.000206058108386565, 'mean_word_length': 2.9379310344827587, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6328040', 'n_tokens_mistral': 2589, 'n_tokens_neox': 2530, 'n_words': 594}