示例#1
0
    // Child override to set decoration
    protected override void _SetDecoration(string decoID, bool isPlacedFromDecoMode)
    {
        currDecoId = decoID;
        // Build the prefab from the id of the decoration
        string     strResource = DataLoaderItems.GetDecoItemPrefabName(decoID);
        GameObject goPrefab    = Resources.Load(strResource) as GameObject;

        if (decoGameObject != null)
        {
            Destroy(decoGameObject.gameObject);
            InventoryManager.Instance.AddItemToInventory(oldDecoId);
            DataManager.Instance.GameData.Decorations.PlacedDecorations.Remove(oldDecoId);
        }
        if (goPrefab)
        {
            decoGameObject = Instantiate(goPrefab) as GameObject;
            decoGameObject.transform.parent = placementNode;                // Put it in the hierachy of decorations in this room
            GameObjectUtils.ResetLocalPosition(decoGameObject);             // Reset all transforms
            DataManager.Instance.GameData.Decorations.PlacedDecorations.Remove(currDecoId);
            InventoryManager.Instance.UseDecoItem(currDecoId);
            oldDecoId = currDecoId;
            // If the object is a farm deco, init some variables
            FarmGenerator farmScript = decoGameObject.GetComponent <FarmGenerator>();
            if (farmScript != null)
            {
                farmScript.Initialize(decoID, isPlacedFromDecoMode);
            }
        }
        else
        {
            Debug.LogError("No such prefab for " + strResource);
        }
    }
示例#2
0
 protected virtual void ShowFoodPreferenceMessage()
 {
     if (!isFinishEating)
     {
         string preferredFoodID = MiniPetManager.Instance.GetFoodPreference(minipetId);
         Item   item            = DataLoaderItems.GetItem(preferredFoodID);
         miniPetSpeechAI.ShowFoodPreferenceMsg(item.TextureName);
     }
 }
示例#3
0
    public void SetDecoration(string itemID, bool isPlacedFromDecoMode)
    {
        // Do one last check
        if (!CanPlaceDecoration(itemID))
        {
            Debug.LogError("Illegal deco placement for " + itemID + " on node " + gameObject);
            return;
        }

        if (nodeType == DecorationTypes.Wallpaper)              // Wallpapers always needs to be removed
        {
            RemoveDecoration();
        }
        else if (HasDecoration())           // If there was already a decoration here, remove it
        {
            RemoveDecoration();
        }

        placedDecoID = itemID;

        // update the save data with the new decoration id
        DataManager.Instance.GameData.Decorations.PlacedDecorations[nodeID] = itemID;

        // Notify inventory logic that this item is being used
        InventoryManager.Instance.UsePetItem(itemID);

        _SetDecoration(itemID, isPlacedFromDecoMode);

        // Play a sound
        DecorationItem itemDeco = (DecorationItem)DataLoaderItems.GetItem(itemID);

        if (isPlacedFromDecoMode)
        {
            if (itemDeco.DecorationType == DecorationTypes.Poster || itemDeco.DecorationType == DecorationTypes.Wallpaper)
            {
                AudioManager.Instance.PlayClip("decoPlacePaper");
            }
            else
            {
                AudioManager.Instance.PlayClip("decoPlaceFurniture");
            }

            // play an FX
            Vector3 particlePos        = transform.position;
            string  particlePrefabName = Constants.GetConstant <string>("Deco_PlaceParticle");
            ParticleUtils.CreateParticle(particlePrefabName, particlePos);
        }

        //Check for badge unlock
        int totalNumOfDecorations = DataManager.Instance.GameData.Decorations.PlacedDecorations.Count;

        BadgeManager.Instance.CheckSeriesUnlockProgress(BadgeType.Decoration, totalNumOfDecorations, true);
    }
示例#4
0
    private bool CanPlaceDecoration(string itemID)
    {
        bool isPlaceable = true;            // Start optimistic

        // Compare the node type to the decoration type
        DecorationItem  itemDeco = (DecorationItem)DataLoaderItems.GetItem(itemID);
        DecorationTypes nodeType = GetDecoType();
        DecorationTypes decoType = itemDeco.DecorationType;

        isPlaceable = (nodeType == decoType);
        return(isPlaceable);
    }
示例#5
0
    public void BuyItem()
    {
        isItemBought = true;
        DataManager.Instance.GameData.MiniPets.SetItemBoughtInPP(MinipetId, true);
        InventoryManager.Instance.AddItemToInventory(secretMerchantItem.ItemId);

        int cost = DataLoaderItems.GetCost(secretMerchantItem.ItemId);

        StatsManager.Instance.ChangeStats(coinsDelta: cost * -1);

        MiniPetManager.Instance.IncreaseXp(MinipetId);
    }
示例#6
0
    /// <summary>
    /// Gets the inventory for item. Based on the item type of itemID, this function
    /// will return the proper inventory for it
    /// </summary>
    private Dictionary <string, InventoryItem> GetInventoryTypeForItem(string itemID)
    {
        switch (DataLoaderItems.GetItemType(itemID))
        {
        case ItemType.Decorations:
            return(DataManager.Instance.GameData.Inventory.DecorationItems);

        case ItemType.Accessories:
            return(DataManager.Instance.GameData.Inventory.AccessoryItems);

        default:                    // Foods and Usables
            return(DataManager.Instance.GameData.Inventory.InventoryItems);
        }
    }
    /// <summary>
    /// Child override to set decoration
    /// </summary>
    /// <param name="strID">decoID</param>
    protected override void _SetDecoration(string decoID, bool isPlacedFromDecoMode)
    {
        // build the prefab from the id of the decoration
        string   strResource = DataLoaderItems.GetDecoItemMaterialName(decoID);
        Material matPrefab   = Resources.Load(strResource) as Material;

        for (int i = 0; i < arrayObjects.Length; ++i)
        {
            GameObject go = arrayObjects[i];
            if (go.GetComponent <Renderer>())
            {
                go.GetComponent <Renderer>().material = matPrefab;
            }
        }
    }
示例#8
0
    // Show the updated inventory bar with new item and destroy the tweening sprite
    private void OnBuyAnimationDone(object obj)
    {
        string   itemID = ((GameObject)obj).name;
        ItemType type   = DataLoaderItems.GetItem(itemID).Type;

        if (type == ItemType.Foods || type == ItemType.Usables)
        {
            InventoryUIManager.Instance.PulseInventory();
            InventoryUIManager.Instance.RefreshPage();
        }
        else if (type == ItemType.Decorations)
        {
            DecoInventoryUIManager.Instance.PulseInventory();
            DecoInventoryUIManager.Instance.RefreshPage();
        }
        Destroy((GameObject)obj);
    }
示例#9
0
    /// <summary>
    /// Checks the store button pulse.
    /// This does all the check by itself so dont worry when calling this
    /// </summary>
    public void CheckStoreButtonPulse()
    {
        Item neededItem = DataLoaderItems.GetItem(MiniPetManager.Instance.GetFoodPreference(SelectedMiniPetID));
        bool isNeedItem = !DataManager.Instance.GameData.Inventory.InventoryItems.ContainsKey(neededItem.ID);
        bool isPetFed   = !DataManager.Instance.GameData.MiniPets.IsPetFinishedEating(SelectedMiniPetID);

        if (isNeedItem && IsOpen && isPetFed)
        {
            storeButtonPulseAnim.Play();
            storeButtonSunbeam.SetActive(true);
        }
        else
        {
            storeButtonPulseAnim.Stop();
            GameObjectUtils.ResetLocalScale(storeButtonPulseAnim.gameObject);
            storeButtonSunbeam.SetActive(false);
        }
    }
示例#10
0
    /// <summary>
    /// Returns a dictionary of stats info on the incoming item.  May return null.
    /// </summary>
    /// <returns>The stats dict.</returns>
    private Dictionary <StatType, int> GetStatsDict(string itemID)
    {
        Item item = DataLoaderItems.GetItem(itemID);
        Dictionary <StatType, int> dictStats = null;

        switch (item.Type)
        {
        case ItemType.Foods:
            FoodItem foodItem = (FoodItem)item;
            dictStats = foodItem.Stats;
            break;

        case ItemType.Usables:
            UsableItem usableItem = (UsableItem)item;
            dictStats = usableItem.Stats;
            break;
        }
        return(dictStats);
    }
示例#11
0
    //void OnGUI() {
    //	if(GUI.Button(new Rect(100, 100, 100, 100), "FIRE")){
    //		Debug.Log("Adding");
    //		AddItemToInventory("Usable1", 1);
    //		InventoryUIManager.Instance.RefreshPage();
    //	}
    //}

    public void AddItemToInventory(string itemID, int count = 1)
    {
        Dictionary <string, InventoryItem> specificTypeInventory = GetInventoryTypeForItem(itemID);
        Item itemData = DataLoaderItems.GetItem(itemID);

        InventoryItem invItem = null;

        // If item already in dictionary increment amount
        if (specificTypeInventory.ContainsKey(itemID))
        {
            // Only one allowed for wallpaper/accessory
            if (IsWallpaperBought(itemID) || IsAccessoryBought(itemID))
            {
                return;
            }

            specificTypeInventory[itemID].Amount += count;
        }
        else           //Add InventoryItem into dict if key doesn't exist
        {
            invItem = new InventoryItem(itemID, itemData.Type, itemData.TextureName);
            specificTypeInventory[itemID] = invItem;

            //special case: keep track of bought wallpaper in another list.
            if (itemData.Type == ItemType.Decorations)
            {
                DecorationItem decoItem = (DecorationItem)itemData;
                if (decoItem.DecorationType == DecorationTypes.Wallpaper)
                {
                    List <string> oneTimePurchasedInv = DataManager.Instance.GameData.Inventory.OneTimePurchasedItems;
                    oneTimePurchasedInv.Add(itemData.ID);
                }
            }
            //special case: keep track of all bought accessories in another list.
            if (itemData.Type == ItemType.Accessories)
            {
                List <string> oneTimePurchasedInv = DataManager.Instance.GameData.Inventory.OneTimePurchasedItems;
                oneTimePurchasedInv.Add(itemData.ID);
            }
        }

        // NOTE: No need to add items to UI here, the complete buy tween will refresh by itself
    }
示例#12
0
    private MiniPetMerchant merchantScript;         // Reference to minipet logic

    public void InitializeContent(string itemID, bool isBoughtAlready, ItemType itemType, MiniPetMerchant merchantScript)
    {
        this.merchantScript   = merchantScript;
        secretItem            = DataLoaderItems.GetItem(itemID);
        itemNameLabel.text    = secretItem.Name;
        descriptionLabel.text = secretItem.Description;
        itemImage.sprite      = SpriteCacheManager.GetItemSprite(secretItem.ID);

        cost.text = secretItem.Cost.ToString();

        if (isBoughtAlready)                                // Enable some game components here
        {
            buyButton.gameObject.SetActive(false);
        }

        if (itemType == ItemType.Decorations)
        {
            Invoke("ShowDecoInventoryHelper", 1f);              // NOTE: Special invoke delay needed for update position
        }

        HUDUIManager.Instance.ShowPanel();                  // Show the hud because we are buying stuff
    }
示例#13
0
    /// <summary>
    /// Sets the accessory node.
    /// IMPORTANT: Only to be changed from AccessoryNodeController!
    /// </summary>
    /// <param name="savedAccessoryKey">Saved accessory key.</param>
    public void SetAccessoryNode(string newAccessoryID)
    {
        // UNDONE Supporting one node as of now, adding multiple nodes would need to reflect with XML attribues(?) as well
//		foreach(GameObject spriteNode in spriteNodes){
//		}

        if (HasAccessory())
        {
            RemoveAccessoryNode();
        }

        if (newAccessoryID != null)
        {
            // Cache the new itemID
            placedAccessoryID = newAccessoryID;

            // Populate it in gamedata in placedAccessories
//			DataManager.Instance.GameData.Accessories.PlacedAccessories[accessoryNodeID] = placedAccessoryID;
//			DataManager.Instance.GameData.Accessories.SetAccessoryAtNode(accessoryNodeID, placedAccessoryID);

            // Load and place the actual accessory
            // build the prefab from the id of the decoration
            string     strResource = DataLoaderItems.GetAccessoryItemPrefabName(placedAccessoryID);
            GameObject goPrefab    = Resources.Load(strResource) as GameObject;

            if (goPrefab)
            {
                placedAccessoryObject = Instantiate(goPrefab, Vector3.zero, goPrefab.transform.rotation) as GameObject;
                placedAccessoryObject.transform.parent = transform;
                GameObjectUtils.ResetLocalTransform(placedAccessoryObject);                     // Zero out all local transforms
            }
            else
            {
                Debug.LogError("No such prefab for " + strResource);
            }
        }
    }
示例#14
0
    /// <summary>
    /// Gets the type of the accessory node.
    /// Given a accessory(ID), check the xml to see which type it is.
    /// </summary>
    /// <returns>The accessory node type.</returns>
    /// <param name="accessoryID">Accessory ID.</param>
    public string GetAccessoryNodeType(string accessoryID)
    {
        AccessoryItem itemDeco = (AccessoryItem)DataLoaderItems.GetItem(accessoryID);

        return(itemDeco.AccessoryType.ToString());
    }
示例#15
0
 public static Sprite GetItemSprite(string itemID)
 {
     return(Resources.Load <Sprite>(DataLoaderItems.GetItemTextureName(itemID)));
 }