Exemplo n.º 1
0
    public bool TryCastSpell(out float coolDownDuration)
    {
        if (!BookInCoolDown)
        {
            newSpellCast = spellsGrid.ReturnMouseQuad(mousePath);
            mousePath.Clear();

            float[] percenteges = new float[spellBook.Length];
            float   max;

            for (int i = 0; i < spellBook.Length; i++)
            {
                percenteges[i] = QuadsDrawing.CompareSpells(newSpellCast, spellBook[i].drawing);
            }
            max = percenteges.Max();
            //print(newSpellCast.ReturnQuadsID());
            //print(max);
            if (max >= spellSensitivity)
            {
                return(SpellEffect(Array.IndexOf(percenteges, max), out coolDownDuration));
            }
        }
        coolDownDuration = 0;
        return(false);
    }
Exemplo n.º 2
0
    void Awake()
    {
        PatternSingletonAwake();

        mouseTrail.FollowingMouse = false;
        delegateHaSubs            = false;
        spellsGrid   = DrawingGrid.GetGrid(3);
        newSpellCast = new QuadsDrawing();
        mousePath    = new List <Vector3>();
        states.PlayerStatesInitializer();
        charController = GetComponent <CharacterController>();
    }
Exemplo n.º 3
0
    /// <summary>
    /// Pega o traçado que o mouse fez,
    /// escala ele no mesmo tamanha que um quadrado de "Spell",
    /// centraliza ele, e checa por quais quadrantes ele passou;
    /// </summary>
    /// <returns>Retorna uma "Spell" onde o mouse passou sobre;</returns>
    public QuadsDrawing ReturnMouseQuad(List <Vector3> mouseTrajectory)
    {
        QuadsDrawing returnSpell = new QuadsDrawing();
        float        originX, originY;
        float        quadX, quadY;
        float        mouseX, mouseY;
        float        quadsSize;
        float        medium;
        float        largerX  = mouseTrajectory.Max(v => v.x);
        float        largerY  = mouseTrajectory.Max(v => v.y);
        float        smallerX = mouseTrajectory.Min(v => v.x);
        float        smallerY = mouseTrajectory.Min(v => v.y);
        float        sizeX    = largerX - smallerX;
        float        sizeY    = largerY - smallerY;


        if (sizeX >= sizeY)
        {
            quadsSize = sizeX;
            medium    = (largerY + smallerY) / 2;
            originX   = smallerX;
            originY   = medium - (quadsSize / 2);
        }
        else
        {
            quadsSize = sizeY;
            medium    = (largerX + smallerX) / 2;
            originY   = smallerY;
            originX   = medium - (quadsSize / 2);
        }
        if (quadsSize <= 0)
        {
            return(new QuadsDrawing());
        }

        for (int i = 0; i < mouseTrajectory.Count; i++)
        {
            mouseX = mouseTrajectory[i].x - originX;
            mouseY = mouseTrajectory[i].y - originY;
            quadX  = (mouseX == quadsSize ? mouseX : (mouseX + (quadsSize / gridSize))) / (quadsSize / gridSize);
            quadY  = (mouseY == quadsSize ? mouseY : (mouseY + (quadsSize / gridSize))) / (quadsSize / gridSize);

            Quad newQuad = new Quad((int)quadX, (int)quadY);

            if (!returnSpell.IsQuadInSpell(newQuad))
            {
                returnSpell.AddQuad(newQuad);
            }
        }
        //Debug.Log("retornou spell");
        return(returnSpell);
    }
Exemplo n.º 4
0
    /// <summary>
    /// Compara um "spell" com outro "spell",
    /// e retorna a porcentagem de similaridade entre os dois
    /// </summary>
    /// <param name="x">"spell" 2</param>
    /// <param name="y">"spell" 1</param>
    /// <returns>porcentagem de similaridade</returns>
    public static float CompareSpells(QuadsDrawing x, QuadsDrawing y)
    {
        int  similarQuads = 0;
        int  smallerSize;
        int  largestSize;
        bool yIsLarger;

        x.ConvertToTrueSpell();
        y.ConvertToTrueSpell();

        //Debug.Log(x.ReturnQuadsID() + "nova spell");
        //Debug.Log(y.ReturnQuadsID() + "spell book");

        if (x.SpellLength <= y.SpellLength)
        {
            smallerSize = x.SpellLength;
            largestSize = y.SpellLength;
            yIsLarger   = true;
        }
        else
        {
            smallerSize = y.SpellLength;
            largestSize = x.SpellLength;
            yIsLarger   = false;
        }
        for (int a = 0; a < smallerSize; a++)
        {
            if (yIsLarger)
            {
                if (y.IsQuadInSpell(x.GetSpellQuad(a)))
                {
                    similarQuads++;
                }
            }
            else
            {
                if (x.IsQuadInSpell(y.GetSpellQuad(a)))
                {
                    similarQuads++;
                }
            }
        }
        return((100 * similarQuads) / largestSize);
    }