Ejemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        ArmorType = GameObject.Find("Armor Stats").GetComponent <Text>();

        player = GameObject.FindGameObjectWithTag("Player");


        db = new DataBaseSmi();


        button   = GameObject.FindGameObjectsWithTag("Button");
        listItem = db.getAllArmors();
        foreach (Items item in listItem) //Assign the name, price and defense to the button
        {
            button[item.id - 1].GetComponentInChildren <Text>().text = item.name + " " + item.price + "gp  +" + item.damage_defense;
        }

        ArmorType.text = db.getItemName(player.GetComponent <Player>().equipement.getArmor(), "armor");//Show the name of the current armor
    }
Ejemplo n.º 2
0
    // Start is called before the first frame update
    void Start()
    {
        SwordType = GameObject.Find("Sword Stats").GetComponent <Text>();

        player = GameObject.FindGameObjectWithTag("Player");
        money  = player.GetComponent <Player>().stats.getGold();


        db = new DataBaseSmi();
        //Set the shop scene to be active
        //GameObject.Find("BlacksmithShop").SetActive(true);


        button = GameObject.FindGameObjectsWithTag("Button");


        listItem = db.getAllMaterials();
        foreach (Items item in listItem)//Assign the name, price and damage to the button
        {
            button[item.id - 1].GetComponentInChildren <Text>().text = item.name + " " + item.price + "gp  +" + item.damage_defense;
        }

        SwordType.text = db.getItemName(player.GetComponent <Player>().equipement.getWeapon(), "material"); //Show the name of the current sword
    }
Ejemplo n.º 3
0
    public void BuySword()
    {
        shop      = new Shop();
        textm     = GameObject.Find("Current Money").GetComponent <Text>();
        player    = GameObject.FindGameObjectWithTag("Player");
        errorText = GameObject.Find("Error").GetComponent <Text>();
        errorText.GetComponent <Text>().text = "";


        db = new DataBaseSmi();
        float money = player.GetComponent <Player>().stats.getGold();

        //Blacksmith shop
        if (GameObject.Find("Blacksmith").transform.Find("Shop").gameObject.activeSelf == true)
        {
            bsShopIsOpen = true;
            price        = db.getPrice(id, "material");
            itemMaterial = player.GetComponent <Player>().equipement.getWeapon();
            itemMaterial++;
        }
        else
        //Armor shop
        {
            price        = db.getPrice(id, "armor");
            itemMaterial = player.GetComponent <Player>().equipement.getArmor();
            itemMaterial++;
        }
        if (itemMaterial == id)
        //Item is already bought
        {
            errorText.GetComponent <Text>().text = "You already have this item";
        }
        else if (money >= price)
        {
            if (bsShopIsOpen == true)
            //Blacksmith shop
            {
                equipementType = GameObject.Find("Sword Stats").GetComponent <Text>();

                //remove gold
                player.GetComponent <Player>().stats.changeGoldByValue(price * -1);

                //Set player weapon and damage
                player.GetComponent <Player>().equipement.setWeapon(id - 1);
                player.GetComponent <Player>().stats.setAttackBonus(db.getMaterialDamage(id - 1));

                //show gold amount
                textm.text = (money - price).ToString();

                //show current sword
                equipementType.text = db.getItemName(id - 1, "material");
            }
            else
            //Armor shop
            {
                equipementType = GameObject.Find("Armor Stats").GetComponent <Text>();

                //remove gold
                player.GetComponent <Player>().stats.changeGoldByValue(price * -1);

                //Change armor and defense
                player.GetComponent <Player>().equipement.setArmor(id - 1);
                player.GetComponent <Player>().stats.setArmorClass(db.getArmorDefense(id - 1));

                //Show new gold amount
                textm.text = (money - price).ToString();

                //Show current armor
                equipementType.text = db.getItemName(id - 1, "armor");
            }
        }
        else
        {
            errorText.GetComponent <Text>().text = "You don't have enough money to buy this";
        }
        //Call the function to change the sprite of the player
        GameObject.FindGameObjectWithTag("Player").GetComponent <Player>().GetComponentInChildren <PlayerChangeEquipment>().ChangeEquipement();
    }