Ejemplo n.º 1
0
    private List <AnimalItem> GetHorizaontalMatch(AnimalItem item)
    {
        List <AnimalItem> matchList = new List <AnimalItem>();

        matchList.Add(item);
        for (int i = item.x - 1; i >= 0; i--)
        {
            if (gridAnimalItems[i, item.y].GetRenderer().sprite == item.GetRenderer().sprite)
            {
                matchList.Add(gridAnimalItems[i, item.y]);
            }
            else
            {
                break;
            }
        }
        for (int i = item.x + 1; i < xSize; i++)
        {
            if (gridAnimalItems[i, item.y].GetRenderer().sprite == item.GetRenderer().sprite)
            {
                matchList.Add(gridAnimalItems[i, item.y]);
            }
            else
            {
                break;
            }
        }
        return(matchList);
    }
Ejemplo n.º 2
0
    private List <AnimalItem> GetVerticalMatch(AnimalItem item)
    {
        List <AnimalItem> matchList = new List <AnimalItem>();

        matchList.Add(item);
        for (int i = item.y - 1; i >= 0; i--)
        {
            if (gridAnimalItems[item.x, i].GetRenderer().sprite == item.GetRenderer().sprite)
            {
                matchList.Add(gridAnimalItems[item.x, i]);
            }
            else
            {
                break;
            }
        }
        for (int i = item.y + 1; i < ySize; i++)
        {
            if (gridAnimalItems[item.x, i].GetRenderer().sprite == item.GetRenderer().sprite)
            {
                matchList.Add(gridAnimalItems[item.x, i]);
            }
            else
            {
                break;
            }
        }
        return(matchList);
    }
Ejemplo n.º 3
0
    private void InitGrid(float offsetX, float offsetY)
    {
        float startX = transform.position.x;
        float startY = transform.position.y;

        for (int x = 0; x < xSize; x++)
        {
            for (int y = 0; y < ySize; y++)
            {
                AnimalItem newItem = null;
                if (!gridAnimalItems[x, y])
                {
                    newItem = Instantiate(tile, new Vector3(startX + (offsetX * x), startY + (offsetY * y), transform.position.z), tile.transform.rotation);
                }
                else
                {
                    newItem = gridAnimalItems[x, y];
                }
                gridAnimalItems[x, y]   = newItem;
                gridAnimalItems[x, y].x = x;
                gridAnimalItems[x, y].y = y;
                newItem.transform.SetParent(transform);
                newItem.GetRenderer().sprite = itemSprites[Random.Range(0, itemSprites.Count)];
                while (isNeedFix(newItem))
                {
                    newItem.GetRenderer().sprite = itemSprites[Random.Range(0, itemSprites.Count)];
                }
            }
        }
    }
Ejemplo n.º 4
0
    AnimalItem CreateItem(int idx)
    {
        GameObject go      = Instantiate(m_prefabItem, m_scrollrect.content) as GameObject;
        AnimalItem kAnimal = go.GetComponent <AnimalItem>();

        kAnimal.transform.localScale = new Vector3(1, 1, 1);
        kAnimal.initialize(idx, animallist[idx]);
        return(kAnimal);
    }
Ejemplo n.º 5
0
    private void CheckBoard()
    {
        AnimalItem item = HelpFind();

        while (!item)
        {
            MixBoard();
            item = HelpFind();
        }
    }
Ejemplo n.º 6
0
 public void OnItemClick(AnimalItem item)
 {
     if (activeMode && !shiftAnimalItems)
     {
         if (firstItemSelected != null && firstItemSelected != item)
         {
             SwapAnimal(item);
         }
         else
         {
             Select(item);
         }
     }
 }
Ejemplo n.º 7
0
    private void HelpTime()
    {
        AnimalItem item = HelpFind();

        if (item)
        {
            StartCoroutine(RotateForHelp(item));
            SfxPlayHandler(SfxEffect.Help);
            timerHelp = 0;
        }
        else
        {
            CheckBoard();
        }
    }
 public static bool CanGetMeatFrom(FarmAnimal farmAnimal)
 {
     if (farmAnimal.type.Value == "Dinosaur" && !DataLoader.ModConfig.DisableMeatFromDinosaur)
     {
         return(true);
     }
     try
     {
         AnimalItem animalItem = GetAnimalItem(farmAnimal);
         return((animalItem is MeatAnimalItem meatAnimalItem) && meatAnimalItem.MaximumNumberOfMeat > 0);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 9
0
 private void SwapAnimal(AnimalItem item)
 {
     if (IsNeighbor(item))
     {
         Sprite swapSprite = firstItemSelected.GetRenderer().sprite;
         firstItemSelected.GetRenderer().sprite = item.GetRenderer().sprite;
         item.GetRenderer().sprite           = swapSprite;
         List <List <AnimalItem> > matchList = new List <List <AnimalItem> >();
         matchList.Add(GetVerticalMatch(firstItemSelected));
         matchList.Add(GetHorizaontalMatch(firstItemSelected));
         matchList.Add(GetVerticalMatch(item));
         matchList.Add(GetHorizaontalMatch(item));
         bool foundMatch = false;
         for (int i = 0; i < matchList.Count; i++)
         {
             if (matchList[i].Count >= minMatch)
             {
                 foundMatch = true;
                 ClearMatches(matchList[i]);
             }
         }
         if (foundMatch)
         {
             if (helpItemIsActive)
             {
                 StopAllCoroutines();
                 ReRotateItem(helpAnimalItem);
                 helpItemIsActive = false;
             }
             FillingBoard();
             timerHelp = 0;
         }
         else
         {
             SfxPlayHandler(SfxEffect.CantSwap);
             swapSprite = firstItemSelected.GetRenderer().sprite;
             firstItemSelected.GetRenderer().sprite = item.GetRenderer().sprite;
             item.GetRenderer().sprite = swapSprite;
         }
         Deselect(firstItemSelected);
     }
     else
     {
         SfxPlayHandler(SfxEffect.CantSwap);
         Deselect(firstItemSelected);
     }
 }
Ejemplo n.º 10
0
    private bool CanSwap(AnimalItem item, AnimalItem item2)
    {
        bool   can        = false;
        Sprite swapSprite = item2.GetRenderer().sprite;

        item2.GetRenderer().sprite = item.GetRenderer().sprite;
        item.GetRenderer().sprite  = swapSprite;
        if (GetVerticalMatch(item).Count >= minMatch || GetHorizaontalMatch(item).Count >= minMatch || GetHorizaontalMatch(item2).Count >= minMatch || GetVerticalMatch(item2).Count >= minMatch)
        {
            can = true;
        }
        else
        {
            can = false;
        }
        swapSprite = item2.GetRenderer().sprite;
        item2.GetRenderer().sprite = item.GetRenderer().sprite;
        item.GetRenderer().sprite  = swapSprite;
        return(can);
    }
Ejemplo n.º 11
0
    private bool isNeedFix(AnimalItem item)
    {
        bool fix = false;
        int  x   = item.x;
        int  y   = item.y;

        if (x > 1)
        {
            if (gridAnimalItems[x - 1, y].GetRenderer().sprite == gridAnimalItems[x - 2, y].GetRenderer().sprite&& gridAnimalItems[x - 2, y].GetRenderer().sprite == gridAnimalItems[x, y].GetRenderer().sprite)
            {
                fix = true;
            }
        }
        if (y > 1)
        {
            if (gridAnimalItems[x, y - 1].GetRenderer().sprite == gridAnimalItems[x, y - 2].GetRenderer().sprite&& gridAnimalItems[x, y - 2].GetRenderer().sprite == gridAnimalItems[x, y].GetRenderer().sprite)
            {
                fix = true;
            }
        }

        return(fix);
    }
Ejemplo n.º 12
0
    IEnumerator RotateForHelp(AnimalItem item)
    {
        helpAnimalItem   = item;
        helpItemIsActive = true;
        float deltaAngle = 5f;
        float maxAngle   = 20f;

        for (float angle = 0; angle <= maxAngle; angle += deltaAngle)
        {
            item.GetRenderer().transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
            yield return(new WaitForSeconds(.05f));
        }
        for (float angle = maxAngle; angle >= -maxAngle; angle -= deltaAngle)
        {
            item.GetRenderer().transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
            yield return(new WaitForSeconds(.05f));
        }
        for (float angle = -maxAngle; angle <= 0; angle += deltaAngle)
        {
            item.GetRenderer().transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
            yield return(new WaitForSeconds(.05f));
        }
        helpItemIsActive = false;
    }
Ejemplo n.º 13
0
        public static List<Item> CreateMeat(FarmAnimal farmAnimal)
        {
            List<Item> itemsToReturn = new List<Item>();

            Animal animal;
            Animal? foundAnimal = AnimalExtension.GetAnimalFromType(farmAnimal.type.Value);
            if (foundAnimal == null || !CanGetMeatFrom(farmAnimal))
            {
                return itemsToReturn;
            }
            else
            {
                animal = (Animal)foundAnimal;
            }

            AnimalItem animalItem = DataLoader.AnimalData.GetAnimalItem(farmAnimal);
            int minimumNumberOfMeat;
            int maxNumberOfMeat;
            int meatPrice;
            int debrisType;
            if (animal == Animal.Dinosaur)
            {
                if (DataLoader.ModConfig.DisableMeatFromDinosaur)
                {
                    return itemsToReturn;
                }
                var meats = Enum.GetValues(typeof(Meat));
                Meat meat = ((Meat)meats.GetValue(new Random((int)farmAnimal.myID.Value).Next(meats.Length)));
                meatPrice = DataLoader.MeatData.getMeatItem(meat).Price;
                minimumNumberOfMeat = 1;
                maxNumberOfMeat = 1 + (1300 / meatPrice);
                debrisType = (int)meat;
            }
            else if (animal == Animal.CustomAnimal)
            {
                MeatAnimalItem meatAnimalItem = (MeatAnimalItem) animalItem;
                debrisType = farmAnimal.meatIndex.Value;
                if (Enum.IsDefined(typeof(Meat), debrisType))
                {
                    meatPrice = DataLoader.MeatData.getMeatItem((Meat)debrisType).Price;
                }
                else
                {
                    var objects = DataLoader.Helper.Content.Load<Dictionary<int, string>>("Data\\ObjectInformation", ContentSource.GameContent);
                    meatPrice = Convert.ToInt32(objects[debrisType].Split('/')[1]);
                }
                minimumNumberOfMeat = meatAnimalItem.MinimalNumberOfMeat;
                maxNumberOfMeat = meatAnimalItem.MaximumNumberOfMeat;
            }
            else
            {
                MeatAnimalItem meatAnimalItem = (MeatAnimalItem) animalItem;
                Meat meat = animal.GetMeat();
                meatPrice = DataLoader.MeatData.getMeatItem(meat).Price;
                minimumNumberOfMeat = meatAnimalItem.MinimalNumberOfMeat;
                maxNumberOfMeat = meatAnimalItem.MaximumNumberOfMeat;
                debrisType = (int)meat;
            }
            var numberOfMeat = minimumNumberOfMeat;

            numberOfMeat += (int)((farmAnimal.getSellPrice() / ((double)farmAnimal.price.Value) - 0.3) * (maxNumberOfMeat - minimumNumberOfMeat));

            Random random = new Random((int)farmAnimal.myID.Value * 10000 + (int)Game1.stats.DaysPlayed);
            int[] quality = { 0, 0, 0, 0, 0 };
            for (int i = 0; i < numberOfMeat; i++)
            {
                var produceQuality = ProduceQuality(random, farmAnimal);
                quality[produceQuality]++;
            }

            var tempTotal = meatPrice * quality[0] + meatPrice * quality[1] * 1.25 + meatPrice * quality[2] * 1.5 + meatPrice * quality[4] * 2;
            while (tempTotal < farmAnimal.getSellPrice() && quality[4] != numberOfMeat)
            {
                if (numberOfMeat < maxNumberOfMeat)
                {
                    numberOfMeat++;
                    quality[0]++;
                    tempTotal += meatPrice;
                }
                else if (quality[0] > 0)
                {
                    quality[0]--;
                    quality[1]++;
                    tempTotal += meatPrice * 0.25;
                }
                else if ((quality[1] > 0))
                {
                    quality[1]--;
                    quality[2]++;
                    tempTotal += meatPrice * 0.25;
                }
                else if ((quality[2] > 0))
                {
                    quality[2]--;
                    quality[4]++;
                    tempTotal += meatPrice * 0.50;
                }
            }

            for (; numberOfMeat > 0; --numberOfMeat)
            {
                Object newItem = new Object(Vector2.Zero, debrisType, 1);
                newItem.Quality = quality[4] > 0 ? 4 : quality[2] > 0 ? 2 : quality[1] > 0 ? 1 : 0;
                quality[newItem.Quality]--;

                itemsToReturn.Add(newItem);
            }

            if (animalItem is WoolAnimalItem woolAnimalItem)
            {
                int numberOfWools = farmAnimal.currentProduce.Value > 0 ? 1 : 0;
                numberOfWools += (int)(woolAnimalItem.MinimumNumberOfExtraWool + (farmAnimal.getSellPrice() / ((double)farmAnimal.price.Value) - 0.3) * (woolAnimalItem.MaximumNumberOfExtraWool - woolAnimalItem.MinimumNumberOfExtraWool));

                for (; numberOfWools > 0; --numberOfWools)
                {
                    Object newItem = new Object(Vector2.Zero, farmAnimal.defaultProduceIndex.Value, 1);
                    newItem.Quality = ProduceQuality(random, farmAnimal);
                    itemsToReturn.Add(newItem);
                }
            }

            if (animalItem is FeatherAnimalItem featherAnimalItem)
            {
                int numberOfFeather = (int)(featherAnimalItem.MinimumNumberOfFeatherChances + (farmAnimal.getSellPrice() / ((double)farmAnimal.price.Value) - 0.3) * (featherAnimalItem.MaximumNumberOfFeatherChances - featherAnimalItem.MinimumNumberOfFeatherChances));
                float num1 = (int)farmAnimal.happiness.Value > 200 ? (float)farmAnimal.happiness.Value * 1.5f : ((int)farmAnimal.happiness.Value <= 100 ? (float)((int)farmAnimal.happiness.Value - 100) : 0.0f);
                for (; numberOfFeather > 0; --numberOfFeather)
                {
                    if (random.NextDouble() < (double)farmAnimal.happiness.Value / 150.0)
                    {
                        if (random.NextDouble() < ((double)farmAnimal.friendshipTowardFarmer.Value + (double)num1) / 5000.0 + Game1.player.DailyLuck + (double)Game1.player.LuckLevel * 0.01)
                        {
                            Object newItem = new Object(Vector2.Zero, farmAnimal.deluxeProduceIndex.Value, 1);
                            newItem.Quality = ProduceQuality(random, farmAnimal);
                            itemsToReturn.Add(newItem);
                        }
                    }
                }
            }

            if (animalItem is FeetAnimalItem feetAnimalItem)
            {
                int numberOfFeet = (int)(feetAnimalItem.MinimumNumberOfFeetChances + (farmAnimal.getSellPrice() / ((double)farmAnimal.price.Value) - 0.3) * (feetAnimalItem.MaximumNumberOfFeetChances - feetAnimalItem.MinimumNumberOfFeetChances));
                float num1 = (int)farmAnimal.happiness.Value > 200 ? (float)farmAnimal.happiness.Value * 1.5f : ((int)farmAnimal.happiness.Value <= 100 ? (float)((int)farmAnimal.happiness.Value - 100) : 0.0f);
                for (; numberOfFeet > 0; --numberOfFeet)
                {
                    if (random.NextDouble() < (double)farmAnimal.happiness.Value / 150.0)
                    {
                        if (random.NextDouble() < ((double)farmAnimal.friendshipTowardFarmer.Value + (double)num1) / 5000.0 + Game1.player.DailyLuck + (double)Game1.player.LuckLevel * 0.01)
                        {
                            Object newItem = new Object(Vector2.Zero, farmAnimal.deluxeProduceIndex.Value, 1);
                            newItem.Quality = ProduceQuality(random, farmAnimal);
                            itemsToReturn.Add(newItem);
                        }
                    }
                }
            }
            if (AnimalContestController.CanChangeParticipant(farmAnimal))
            {
                AnimalContestController.RemoveAnimalParticipant(farmAnimal);
                itemsToReturn.Add(ToolsFactory.GetParticipantRibbon());
            }

            return itemsToReturn;
        }
Ejemplo n.º 14
0
 private void Select(AnimalItem item)
 {
     item.GetRenderer().color = selectedColor;
     firstItemSelected = item;
     SfxPlayHandler(SfxEffect.Select);
 }
Ejemplo n.º 15
0
 private void Deselect(AnimalItem item)
 {
     item.GetRenderer().color = Color.white;
     firstItemSelected = null;
 }
Ejemplo n.º 16
0
 private void ReRotateItem(AnimalItem item)
 {
     item.GetRenderer().transform.rotation = Quaternion.identity;
 }
Ejemplo n.º 17
0
 private bool IsNeighbor(AnimalItem item)
 {
     return((item.y == firstItemSelected.y || item.x == firstItemSelected.x) && Mathf.Abs(item.y - firstItemSelected.y) <= 1 && Mathf.Abs(item.x - firstItemSelected.x) <= 1);
 }