Exemplo n.º 1
0
    IEnumerator DealWithSwap(Gem g1, Gem g2, Vector3Int _fallDirection)
    {
        CurrentChain = 0;

        controllerIsLocked = true;

        Dictionary <Vector3Int, Gem> fakeWorld = new Dictionary <Vector3Int, Gem>(sm.addressBook);
        List <Gem> removeList = new List <Gem>(SpaceMaker.DimentionsCube);

        //set hypothetical swap
        fakeWorld[g1.Address] = g2;
        fakeWorld[g2.Address] = g1;

        //change this to only check the rays on which the gems actually sit
        // no, we need to check all rays that either gem sits on
        Checker.instance.CheckWorldForMatch3(fakeWorld, removeList, new List <List <Vector3Int> >(), true);

        if (removeList.Contains(g1) || removeList.Contains(g2))
        {
            //update positions
            sm.addressBook[g1.Address] = g2;
            sm.addressBook[g2.Address] = g1;

            //update addresses to match positions
            Vector3Int swapAddress = g1.Address;
            g1.Address = g2.Address;
            g2.Address = swapAddress;

            //swap model locations
            yield return(StartCoroutine(Gem.AnimateDoubleSwap(g1, g2, true)));

            //run chains!
            yield return(StartCoroutine(RunChain(sm.addressBook, true, _fallDirection)));
        }
        else
        {
            //swap
            yield return(StartCoroutine(Gem.AnimateDoubleSwap(g1, g2, false)));//this should swap

            FireSounds.PlaySound(FireSounds.Unswap);
            //swap again because the first one was bad
            yield return(StartCoroutine(Gem.AnimateDoubleSwap(g1, g2, true)));//this should swap
        }
        controllerIsLocked = false;
    }