You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
186 lines
5.4 KiB
186 lines
5.4 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class ShopManager : MonoBehaviour
|
|
{
|
|
public Inventory myBag;
|
|
public Text moneyText1;
|
|
public Text moneyText2;
|
|
public Text itemDescription;
|
|
public Text weaponDescription;
|
|
|
|
GameManager gameManager;
|
|
GameObject[] pieces;
|
|
Character maincharacter;
|
|
Character selected;
|
|
|
|
void Start()
|
|
{
|
|
gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
|
|
pieces = GameObject.FindGameObjectsWithTag("Pieces");
|
|
foreach (var piece in pieces)
|
|
{
|
|
if(piece.GetComponent<Character>().id == 0)
|
|
{
|
|
maincharacter = piece.GetComponent<Character>();
|
|
break;
|
|
}
|
|
}
|
|
if(gameManager.GetSelected() != null)
|
|
selected = gameManager.GetSelected();
|
|
else
|
|
selected = maincharacter;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
moneyText1.GetComponent<Text>().text = maincharacter.money.ToString();
|
|
moneyText2.GetComponent<Text>().text = maincharacter.money.ToString();
|
|
selected = gameManager.GetSelected();
|
|
}
|
|
|
|
public void ItemOnClicked(Item item)
|
|
{
|
|
itemDescription.text = item.itemInfo;
|
|
}
|
|
|
|
public void WeaponOnClicked(Item item)
|
|
{
|
|
weaponDescription.text = item.itemInfo;
|
|
}
|
|
|
|
public void ItemPurchase(Item item)
|
|
{
|
|
if (maincharacter.money < 5)
|
|
{
|
|
itemDescription.text = "角色金钱不足";
|
|
return;
|
|
}
|
|
|
|
if (!myBag.itemList.Contains(item))
|
|
{
|
|
for (int i = 0; i < myBag.itemList.Count; i++)
|
|
{
|
|
if (myBag.itemList[i] == null)
|
|
{
|
|
myBag.itemList[i] = item;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
item.itemHeld += 1;
|
|
}
|
|
InventoryManager.RefreshItem();
|
|
maincharacter.money -= 5;
|
|
}
|
|
|
|
public void WeaponLevelUp(Item item)
|
|
{
|
|
Debug.Log("character id : " + selected.id + " maximum:" + selected.weaponManager.maximum);
|
|
|
|
if(item.itemName == "knife")
|
|
{
|
|
if (maincharacter.money < 5)
|
|
{
|
|
weaponDescription.text = "角色金钱不足";
|
|
return;
|
|
}
|
|
|
|
for(int i = 0; i < selected.weaponManager.maximum; i++)
|
|
{
|
|
if(selected.weaponManager.weapons[i] != null)
|
|
{
|
|
if(selected.weaponManager.weapons[i].name == "knife")
|
|
{
|
|
selected.weaponManager.weapons[i].LevelUp();
|
|
maincharacter.money -= 5;
|
|
weaponDescription.text = "匕首已升级";
|
|
return;
|
|
}
|
|
}
|
|
|
|
}
|
|
weaponDescription.text = "选中角色无该物品";
|
|
}
|
|
|
|
if(item.itemName == "sword")
|
|
{
|
|
if (maincharacter.money < 8)
|
|
{
|
|
weaponDescription.text = "角色金钱不足";
|
|
return;
|
|
}
|
|
|
|
for(int i = 0; i < selected.weaponManager.maximum; i++)
|
|
{
|
|
if(selected.weaponManager.weapons[i] != null)
|
|
{
|
|
if(selected.weaponManager.weapons[i].name == "sword")
|
|
{
|
|
selected.weaponManager.weapons[i].LevelUp();
|
|
maincharacter.money -= 8;
|
|
weaponDescription.text = "长剑已升级";
|
|
return;
|
|
}
|
|
}
|
|
|
|
}
|
|
weaponDescription.text = "选中角色无该物品";
|
|
}
|
|
|
|
if(item.itemName == "greatsword")
|
|
{
|
|
if (maincharacter.money < 10)
|
|
{
|
|
weaponDescription.text = "角色金钱不足";
|
|
return;
|
|
}
|
|
|
|
for(int i = 0; i < selected.weaponManager.maximum; i++)
|
|
{
|
|
if(selected.weaponManager.weapons[i] != null)
|
|
{
|
|
if(selected.weaponManager.weapons[i].name == "greatsword")
|
|
{
|
|
selected.weaponManager.weapons[i].LevelUp();
|
|
maincharacter.money -= 10;
|
|
weaponDescription.text = "大剑已升级";
|
|
return;
|
|
}
|
|
}
|
|
|
|
}
|
|
weaponDescription.text = "选中角色无该物品";
|
|
}
|
|
|
|
if(item.itemName == "lance")
|
|
{
|
|
if (maincharacter.money < 10)
|
|
{
|
|
weaponDescription.text = "角色金钱不足";
|
|
return;
|
|
}
|
|
|
|
for(int i = 0; i < selected.weaponManager.maximum; i++)
|
|
{
|
|
if(selected.weaponManager.weapons[i] != null)
|
|
{
|
|
if(selected.weaponManager.weapons[i].name == "lance")
|
|
{
|
|
selected.weaponManager.weapons[i].LevelUp();
|
|
maincharacter.money -= 10;
|
|
weaponDescription.text = "长枪已升级";
|
|
return;
|
|
}
|
|
}
|
|
|
|
}
|
|
weaponDescription.text = "选中角色无该物品";
|
|
}
|
|
}
|
|
}
|