Пример #1
0
    /**
     * Change the spell held in given hand to the spell
     * according to element(s) in queue
     *
     * Example call:
     * ConfirmSpell(Hands.left)
     **/
    void ConfirmSpell(Hands.handEnum hand)
    {
        if (elemsSelected.isNonePair())
        {
            Debug.Log("[SpellController][ConfirmSpell] no elements are chosen");
            return;
        }


        RemoveElementsFromHand(hand); // first reset hand's current selection

        // todo: may want to sort? - Shaun
        if (hand == Hands.handEnum.left)
        {
            leftHandElementsPair.clear();
            leftHandElementsPair.pushIfPossibleElseClearAndPush(elemsSelected.First);
            leftHandElementsPair.pushIfPossibleElseClearAndPush(elemsSelected.Second);
        }
        else if (hand == Hands.handEnum.right)
        {
            rightHandElementsPair.clear();
            rightHandElementsPair.pushIfPossibleElseClearAndPush(elemsSelected.First);
            rightHandElementsPair.pushIfPossibleElseClearAndPush(elemsSelected.Second);
        }
        else
        {
            Debug.Log("ConfirmSpell was given an invalid hand.");
        }
        updateHandElementsSelectionSprite(hand);

        clearCurrentSelectedElements();
    }
Пример #2
0
 // Used to reset hand's elements selection
 public void RemoveElementsFromHand(Hands.handEnum hand)
 {
     if (hand == Hands.handEnum.left)
     {
         leftHandElementsPair.clear();
     }
     else if (hand == Hands.handEnum.right)
     {
         rightHandElementsPair.clear();
     }
     updateHandElementsSelectionSprite(hand);
 }
Пример #3
0
 /**
  * Update the specified hand sprite with current element
  */
 void updateHandElementsSelectionSprite(Hands.handEnum hand)
 {
     if (hand == Hands.handEnum.left)
     {
         ChangeImage(LeftHandElement1, elementToHandSpriteDict[leftHandElementsPair.First]);
         ChangeImage(LeftHandElement2, elementToHandSpriteDict[leftHandElementsPair.Second]);
     }
     else if (hand == Hands.handEnum.right)
     {
         ChangeImage(RightHandElement1, elementToHandSpriteDict[rightHandElementsPair.First]);
         ChangeImage(RightHandElement2, elementToHandSpriteDict[rightHandElementsPair.Second]);
     }
 }
Пример #4
0
    private void CastSpell(Hands.handEnum hand)
    {
        ElementsPair elementPair;
        GameObject   bulletPoint;

        if (hand == Hands.handEnum.left)
        {
            elementPair           = spellController.LeftHandElementsPair;
            bulletPoint           = LeftBulletPoint;
            nextSpellCooldownLeft = Time.time + 0.5f;
        }
        else if (hand == Hands.handEnum.right)
        {
            elementPair            = spellController.RightHandElementsPair;
            bulletPoint            = RightBulletPoint;
            nextSpellCooldownRight = Time.time + 0.5f;
        }
        else
        {
            Debug.Log("[CastingControl][CastSpell] Error: inappropriate hand is provided - " + hand);
            return;
        }

        if (elementPair.isNonePair())
        {
            return;
        }


        Spells.spellEnum    spellEnum   = Spells.elementsPairToSpellEnum[elementPair];
        Spells.SpellDetails spellDetail = spellEnumToSpellDetails[spellEnum];

        bool shouldCreateBullet = spellController;
        // === setup done. shoot out bullet

        Vector3 pos      = bulletPoint.transform.position;
        Vector3 rotation = new Vector3(0, 0, 0);

        prefabScript = spellDetail.spellObject.GetComponent <FireConstantBaseScript>();

        if (prefabScript == null)
        {
            // temporary effect, like a fireball
            prefabScript = spellDetail.spellObject.GetComponent <FireBaseScript>();
            if (spellDetail.spellObject.GetComponent <FireBaseScript>().IsProjectile)
            {
                // set the start point near the hand
                rotation = cam.transform.rotation.eulerAngles;
            }
        }
        else
        {
            // TODO: Not sure if this way of checking for spell type is good idea. Maybe it is better to add "isProjectile" variable to Spells, but w/e
            // set the start point in front of the player a ways, rotated the same way as the player
            RaycastHit hit;

            pos        = bulletPoint.transform.position;
            rotation   = cam.transform.rotation.eulerAngles;
            rotation.x = 0; // this sets the spell up virtically
            pos.y      = 0.0f;

            Physics.Raycast(bulletPoint.transform.position, cam.transform.forward, out hit, 9000000f, laycastLayerMask);
            if (hit.collider == null)
            {
                shouldCreateBullet = false;
            }

            pos = hit.point;
        }

        if (shouldCreateBullet && spellController.hasEnoughResourceToCast(elementPair, spellDetail.firstElementCost, spellDetail.secondElementCost))
        {
            var spellPrefab = GameObject.Instantiate(spellDetail.spellObject, pos, Quaternion.Euler(rotation));

            Elements.elemEnum curSecondElement = elementPair.Second; // this is because "DecrementElement" may modify this
            spellController.DecrementElement(elementPair.First, spellDetail.firstElementCost);
            spellController.DecrementElement(curSecondElement, spellDetail.secondElementCost);
        }
    }