Beispiel #1
0
	public void LoadCharacterData(){
		if(playerNew == null){
			playerNew = GameObject.FindGameObjectWithTag ("Player").GetComponent<PlayerNew>();
		}
		
		if(PlayerPrefs.GetInt("Player_SaveLoad_Slot",1000) == 1000){
			Debug.LogError ("No saveload slot");
			PlayerPrefs.SetInt("Player_SaveLoad_Slot",0);
			return;
		}	
		
		SaveLoadSlot = PlayerPrefs.GetInt("Player_SaveLoad_Slot",1000).ToString() + "_";
		Debug.Log ("Loading save: " + PlayerPrefs.GetInt("Player_SaveLoad_Slot",1000).ToString());
		//Load Name
		playerNew.Name = PlayerPrefs.GetString(SaveLoadSlot+"Player_Name","");
		playerNew.playerClass = (PlayerClass)PlayerPrefs.GetInt(SaveLoadSlot+"Player_Class",0);
		
		//Load Attribute
		for(int cnt=0;cnt<Enum.GetValues(typeof(AttributeName)).Length;cnt++){
			playerNew.GetAttribute(cnt).BaseValue = PlayerPrefs.GetInt (SaveLoadSlot+"Player_Atr_"+((AttributeName)cnt)+"_Value",0);
		}
		//Load Vitals
		
		for(int cnt=0;cnt<Enum.GetValues(typeof(VitalName)).Length;cnt++){
			playerNew.GetVital(cnt).MaxValue = PlayerPrefs.GetInt (SaveLoadSlot+"Player_Vital_"+((VitalName)cnt).ToString ()+"_Value",100);
			playerNew.GetVital(cnt).CurValue = PlayerPrefs.GetInt (SaveLoadSlot+"Player_Vital_"+((VitalName)cnt).ToString ()+"_CurValue",100);
		}
		
		playerNew.Exp = PlayerPrefs.GetInt (SaveLoadSlot+"Player_Exp",0);
		playerNew.ExpToLevel  = PlayerPrefs.GetInt (SaveLoadSlot+"Player_ExpToLevel",100);
		playerNew.Level = PlayerPrefs.GetInt (SaveLoadSlot+"Player_Level",1);
		
		playerNew.Gold = PlayerPrefs.GetInt (SaveLoadSlot+"Player_Gold",0);
		
		LoadQuestsAndAchievements();
		LoadAllItems();
		playerNew.UpdateStats();
	}
    public void InventoryDo(string method, int cnt)
    {
        if (method == "DropItem")
        {
            if (_pc.Inventory[cnt].CanBeDropped)
            {
                _pc.Inventory.RemoveAt(cnt);
            }
            else
            {
                Debug.Log("Can't destroy this item!");
            }
        }
        else if (method == "UseItem")
        {
            if (_pc.Inventory[cnt].ItemType == ItemEquipType.Clothing ||
                _pc.Inventory[cnt].ItemType == ItemEquipType.Weapon)
            {
                if (_pc.playerState == PlayerState.Normal)
                {
                    GUIHandler.EquipAnItem(cnt);
                }
                else
                {
                    Debug.Log("Can't equip item right now.");
                }
            }
            else if (_pc.Inventory[cnt].ItemType == ItemEquipType.Consumable)
            {
                //IEnumerator for cooldown of using potions
                Consumable c       = _pc.Inventory[cnt] as Consumable;
                bool       usedPot = _pc.UseConsumable((int)c.VitalToRestore, c.AmountToHeal);
                if (usedPot)
                {
                    if (c.CurStacks == 1)
                    {
                        _pc.Inventory.RemoveAt(cnt);
                    }
                    else
                    {
                        c.CurStacks -= 1;
                    }
                }
                else
                {
                    Debug.Log("Using pots on cooldown");
                }
            }
            else if (_pc.Inventory[cnt].ItemType == ItemEquipType.Socket)
            {
                MyGUI.itemIsPickedUp         = true;
                MyGUI.itemPickedUpIcon       = _pc.Inventory[cnt].Icon;
                MyGUI.itemIsForUse           = true;
                MyGUI.pickedUpItemIdentifier = string.Format("Inventory{0}", cnt);
            }
            else
            {
                Debug.Log("Unknown : This is a " + _pc.Inventory[cnt].Name);
            }
        }
        else
        {
            if (_pc.Inventory.Count < _maxInventorySpace)
            {
                switch (method)
                {
                //Returning Equipped Items
                case "ReturnEquippedWeapon":
                    _pc.AddItem(_pc.EquipedWeapon);
                    _pc.EquipedWeapon = null;
                    break;

                case "ReturnEquippedArmorHead":
                    _pc.AddItem(_pc.EquipedArmorHead);
                    _pc.EquipedArmorHead = null;
                    break;

                case "ReturnEquippedArmorChest":
                    _pc.AddItem(_pc.EquipedArmorChest);
                    _pc.EquipedArmorChest = null;
                    break;

                case "ReturnEquippedArmorGloves":
                    _pc.AddItem(_pc.EquipedArmorGloves);
                    _pc.EquipedArmorGloves = null;
                    break;

                case "ReturnEquippedArmorLegs":
                    _pc.AddItem(_pc.EquipedArmorLegs);
                    _pc.EquipedArmorLegs = null;
                    break;

                case "ReturnEquippedArmorFeet":
                    _pc.AddItem(_pc.EquipedArmorFeet);
                    _pc.EquipedArmorFeet = null;
                    break;

                case "ReturnEquippedArmorBack":
                    _pc.AddItem(_pc.EquipedArmorBack);
                    _pc.EquipedArmorBack = null;
                    break;
                }
            }
            else
            {
                Debug.Log("Inventory is full");
                Debug.Log("Your Inventory is full.");
            }
        }

        _pc.UpdateStats();
    }
Beispiel #3
0
    private void InventoryToCharacterWindow(string targetIdentifier)
    {
        string origItemLocation = pickedUpItemIdentifier;
        int    targetLocation   = FindInventorySpot(origItemLocation);

        Item temp = player.EquipedWeapon;

        switch (targetIdentifier)
        {
        //Returning Equipped Items
        case "EquipedWeapon":
            temp = player.EquipedWeapon;
            break;

        case "EquipedArmorHead":
            temp = player.EquipedArmorHead;
            break;

        case "EquipedArmorChest":
            temp = player.EquipedArmorChest;
            break;

        case "EquipedArmorGloves":
            temp = player.EquipedArmorGloves;
            break;

        case "EquipedArmorLegs":
            temp = player.EquipedArmorLegs;
            break;

        case "EquipedArmorFeet":
            temp = player.EquipedArmorFeet;
            break;

        case "EquipedArmorBack":
            temp = player.EquipedArmorBack;
            break;
        }

        bool success    = EquipAnItem(targetLocation);
        bool removeItem = true;

        if (success)
        {
            switch (targetIdentifier)
            {
            //Returning Equipped Items
            case "EquipedWeapon":
                if (player.EquipedWeapon == temp)
                {
                    removeItem = false;
                }
                break;

            case "EquipedArmorHead":
                if (player.EquipedArmorHead == temp)
                {
                    removeItem = false;
                }
                break;

            case "EquipedArmorChest":
                if (player.EquipedArmorChest == temp)
                {
                    removeItem = false;
                }
                break;

            case "EquipedArmorGloves":
                if (player.EquipedArmorGloves == temp)
                {
                    removeItem = false;
                }
                break;

            case "EquipedArmorLegs":
                if (player.EquipedArmorLegs == temp)
                {
                    removeItem = false;
                }
                break;

            case "EquipedArmorFeet":
                if (player.EquipedArmorFeet == temp)
                {
                    removeItem = false;
                }
                break;

            case "EquipedArmorBack":
                if (player.EquipedArmorBack == temp)
                {
                    removeItem = false;
                }
                break;
            }

            if (removeItem)
            {
                if (temp != null)
                {
                    player.Inventory[targetLocation] = temp;
                }
            }
        }
        else
        {
            Debug.Log("Can't Equip this!");
        }

        player.UpdateStats();
        itemIsPickedUp         = false;
        pickedUpItemIdentifier = "";
    }