Exemplo n.º 1
0
    public bool ItemControl(int id, int amount)
    {
        bool success = false, found = false;
        int  current = 0;

        foreach (item nowItem in overallData.gameData.ownedItems)
        {
            if (nowItem.id == id)
            {
                found = true;
                if (nowItem.count + amount < 0)
                {
                    Debug.LogError("Must Be exact 0 to remove this item type!");
                    success = false;
                    break;
                }
                else if (nowItem.count + amount == 0)
                {
                    Debug.Log("Removing Item Type");
                    overallData.gameData.ownedItems.RemoveAt(current);
                    success = true;
                    break;
                }
                else
                {
                    nowItem.count = nowItem.count + amount;
                    success       = true;
                    break;
                }
            }
        }
        if (!found && amount > 0)
        {
            Debug.Log("Item not found, adding item");
            for (int i = 0; i < overallData.gameData.ownedItems.Count; i++)
            {
                if (overallData.gameData.ownedItems[i].id > id)
                {
                    overallData.gameData.ownedItems.Insert(i, new item(id, amount));
                    success = true;
                    break;
                }
            }
            if (!success)
            {
                overallData.gameData.ownedItems.Add(new item(id, amount));
                success = true;
            }
        }
        if (success)
        {
            OnItemDataChanged.Invoke();
        }
        else
        {
            Debug.LogError("U DON FKED UP");
        }
        return(success);
    }
Exemplo n.º 2
0
    public void SubmitRecipe(int recipe_id)
    {
        if (overallData.gameData.isCrafting)
        {
            Debug.LogError("ALREADY CRAFTING!");
            return;
        }
        Debug.Log("Recipe Received");
        recipeData rD = CLD.GetRecipeByID(recipe_id);
        int        catToRemove = 0, itemToRemove = 0;

        changeMoney(rD.cost * -1);
        for (int i = 0; i < rD.cats.Count; i++)
        {
            if (i == 0 || rD.cats[i - 1] == rD.cats[i])
            {
                catToRemove++;
            }
            else
            {
                CatControl(rD.cats[i - 1], -catToRemove, CatControlType.count);
                catToRemove = 1;
            }

            if (i == rD.cats.Count - 1)
            {
                CatControl(rD.cats[i], -catToRemove, CatControlType.count);
            }
        }
        Debug.Log("Cat Removed");
        for (int i = 0; i < rD.items.Count; i++)
        {
            if (i == 0 || rD.items[i - 1] == rD.items[i])
            {
                itemToRemove++;
            }
            else
            {
                ItemControl(rD.items[i - 1], -itemToRemove);
                itemToRemove = 1;
            }
            if (i == rD.items.Count - 1)
            {
                ItemControl(rD.items[i], -itemToRemove);
            }
        }
        Debug.Log("Item Removed");
        overallData.gameData.isCrafting = true;
        overallData.gameData.craftID    = recipe_id;
        overallData.gameData.craftETC   = ConvertToUnixTimestamp(System.DateTime.Now) + CLD.GetRecipeTime(recipe_id);
        EventNotifier.Invoke("Crafting Start!");
        StartCoroutine(StartCraftingClock());
        OnCatDataChaged.Invoke();
        OnItemDataChanged.Invoke();
    }
Exemplo n.º 3
0
    //-----------
    // METHODS
    //-----------

    private void OnGameInitializehandler()      // invoke every data event
    {
        StopCoroutine("StartCraftingClock");
        OnCatDataChaged.Invoke();
        OnMoneyChanged.Invoke();
        OnItemDataChanged.Invoke();
        OnGroupDataChanged.Invoke();
        if (overallData.gameData.isCrafting)
        {
            StartCoroutine(StartCraftingClock());
        }
        foreach (exploreGroups eG in overallData.gameData.exploreGroups)
        {
            StartCoroutine(StartExploreClock(eG));
        }
    }
Exemplo n.º 4
0
    void CraftingEnded()
    {
        overallData.gameData.isCrafting = false;
        Ientity entity = CLD.GetEntityByRecipeID(overallData.gameData.craftID);

        if (entity.GetType() == typeof(catData))
        {
            Debug.Log("Added Cat:" + ((catData)entity).name + "  ID:" + ((catData)entity).id);
            CatControl(((catData)entity).id, 1, CatControlType.count);
            EventNotifier.Invoke("Crafted New Cat: " + ((catData)entity).name);
            OnCatDataChaged.Invoke();
        }
        else
        {
            ItemControl(((itemData)entity).id, 1);
            EventNotifier.Invoke("Crafted New Item: " + ((itemData)entity).name);
            OnItemDataChanged.Invoke();
        }
        OnCraftingEnded.Invoke();
    }