public void GainElementSpecPoints(Elements.ElementType ElementToGainPoints, int pointValue)
    {
        switch (ElementToGainPoints)
        {
        case Elements.ElementType.Air:
            AirPoints += pointValue;
            break;

        case Elements.ElementType.Earth:
            EarthPoints += pointValue;
            break;

        case Elements.ElementType.Fire:
            FirePoints += pointValue;
            break;

        case Elements.ElementType.Nature:
            NaturePoints += pointValue;
            break;

        case Elements.ElementType.Water:
            WaterPoints += pointValue;
            break;

        case Elements.ElementType.NonElemental:
            Debug.Log("Cant gain points in non-elemental. This does nothing.");
            break;

        default:
            Debug.Log("ERROR! Element not recongized");
            break;
        }
        // Update UI
        if (!InBattleMode)
        {
            GameManagerRef.GetComponent <GameManager>().UpdateText_AllElements(AirPoints.ToString(), EarthPoints.ToString(), FirePoints.ToString(),
                                                                               NaturePoints.ToString(), WaterPoints.ToString());
        }
    }
    Elements.ElementType CalculateNewTypeForEvolution()
    {
        Elements.ElementType typeToReturn = Elements.ElementType.NonElemental;

        // Choose type based on type with highest points
        int[] typePoints             = { AirPoints, EarthPoints, FirePoints, NaturePoints, WaterPoints };
        Elements.ElementType[] types = { Elements.ElementType.Air, Elements.ElementType.Earth, Elements.ElementType.Fire, Elements.ElementType.Nature, Elements.ElementType.Water };
        int highestPoint             = 0;

        // Loop through all element points and find biggest
        for (int i = 0; i < typePoints.Length; i++)
        {
            if (typePoints[i] > highestPoint) // Is new point higher than the last?
            {
                highestPoint = typePoints[i]; // Update highest point
                typeToReturn = types[i];      // Set type to return to corresponding type
            }
        }

        // Reset all spec points to 0
        AirPoints = 0; EarthPoints = 0; FirePoints = 0; NaturePoints = 0; WaterPoints = 0;

        return(typeToReturn);
    }
Beispiel #3
0
    internal void BuildEnemy()
    {
        // Parent object
        EnemyRef     = new GameObject(EnemyName);
        EnemyRef.tag = "Enemy";

        Vector3[] PartVectorShape = ChooseEnemyShape();

        // Choose element type
        EnemyType = ChooseEnemyType();

        // Body
        Body = CreateMesh(PartName[1], PartVectorShape);

        // Add Enemy script to body object
        Body.AddComponent <Enemy>();

        // Add Enemy tag
        Body.tag = "Enemy";

        // Set Enemy Stats
        int EvolutionCount = 1;

        Body.GetComponent <Enemy>().Level = 1;


        Body.GetComponent <Enemy>().CharactersElementTypes.Add(EnemyType);

        // Adjust scale multiplier and seperation multiplier to factor in evolution
        if (EvolutionCount > 0)
        {
            ScaleMultiplier     *= EvolutionCount;
            SeperationMultipler *= EvolutionCount;
        }
        else // Hasnt evolved yet
        {
            ScaleMultiplier     *= 0.8f;
            SeperationMultipler *= 0.8f;
        }

        // Define Part seperation offset
        Vector3 baseSize             = Body.GetComponent <Renderer>().bounds.size;
        float   PartSeperationOffset = (((baseSize.x * baseSize.y) / 2) * SeperationMultipler); // Get average of x and y axis then * by scale multipler

        // Scale Body size down
        Body.transform.localScale *= (2 * ScaleMultiplier);

        // Set parent
        Body.transform.parent = EnemyRef.transform;

        // Add capsule collider to body
        Body.AddComponent <CapsuleCollider>();
        Body.GetComponent <CapsuleCollider>().radius = baseSize.x / 4;
        Body.GetComponent <CapsuleCollider>().height = baseSize.y * 2;

        // Face
        Face = CreateMesh(PartName[0], PartVectorShape);
        // Scale size down
        Face.transform.localScale *= ScaleMultiplier;
        // Add cube collider
        Face.AddComponent <BoxCollider>();
        // Move face up
        Face.transform.position = new Vector3(Face.transform.position.x, Face.transform.position.y + (4 * PartSeperationOffset), Face.transform.position.z);
        // Set parent
        Face.transform.parent = EnemyRef.transform;


        // Arm1
        Arm1 = CreateMesh(PartName[2], PartVectorShape);
        // Scale size down
        Arm1.transform.localScale *= (ScaleMultiplier / 1.5f);
        // Move arm left and up
        Arm1.transform.position = new Vector3(Arm1.transform.position.x - (2 * PartSeperationOffset), Arm1.transform.position.y + (2 * PartSeperationOffset), Arm1.transform.position.z);
        // Set parent
        Arm1.transform.parent = EnemyRef.transform;

        // Arm2
        Arm2 = CreateMesh(PartName[3], PartVectorShape);
        // Scale size down
        Arm2.transform.localScale *= (ScaleMultiplier / 1.5f);
        // Move arm right and up
        Arm2.transform.position = new Vector3(Arm2.transform.position.x + (2 * PartSeperationOffset), Arm2.transform.position.y + (2 * PartSeperationOffset), Arm2.transform.position.z);
        // Set parent
        Arm2.transform.parent = EnemyRef.transform;

        // Leg1
        Leg1 = CreateMesh(PartName[4], PartVectorShape);
        // Scale size down
        Leg1.transform.localScale *= (ScaleMultiplier / 1.5f);
        // Move leg left and down
        Leg1.transform.position = new Vector3(Leg1.transform.position.x - PartSeperationOffset, Leg1.transform.position.y - (2 * PartSeperationOffset), Leg1.transform.position.z);
        // Set parent
        Leg1.transform.parent = EnemyRef.transform;

        // Load Leg2
        Leg2 = CreateMesh(PartName[5], PartVectorShape);
        // Scale size down
        Leg2.transform.localScale *= (ScaleMultiplier / 1.5f);
        // Move leg right and down
        Leg2.transform.position = new Vector3(Leg2.transform.position.x + PartSeperationOffset, Leg2.transform.position.y - (2 * PartSeperationOffset), Leg2.transform.position.z);
        // Set parent
        Leg2.transform.parent = EnemyRef.transform;

        // Set up rididbodies and character joints
        SetUpCharacterAsRagdoll(Body, Face, Arm1, Arm2, Leg1, Leg2);

        // Spawn above ground and to the right
        EnemyRef.transform.position += EnemySpawnOffset;

        // Set player ref
        Body.GetComponent <Enemy>().PlayerRef = PlayerRef;
    }
    public void GainExp(int expPoints)
    {
        Experience += expPoints;

        if (Experience > ExpToLevelUp)
        {
            // Level up
            Level++;
            LevelUpStats();                                             // Increase stats
            GameManagerRef.GetComponent <GameManager>().FlashLevelUp(); // Flash level up UI

            Experience   = Experience - ExpToLevelUp;                   // Carry over leftover exp
            ExpToLevelUp = ExpNeededForNextLevel();                     // Increase exp needed to lvl up

            // Evolve
            for (int i = 0; i < LevelsToEvolveAt.Length; i++) // Loop through levels to evolve at to search for a match
            {
                if (Level == LevelsToEvolveAt[i])             // Lvl is an evolution lvl
                {
                    // Detach from balloons
                    DetachFromAllBalloons();

                    // Increase count of evolutions
                    CurrentEvolutionStage++;

                    if (CurrentEvolutionStage == 1)                                       // First evolution
                    {
                        CharactersElementTypes.Remove(Elements.ElementType.NonElemental); // Remove non-elemental
                    }

                    // Add new type based on spec points
                    Elements.ElementType newType = CalculateNewTypeForEvolution();
                    CharactersElementTypes.Add(newType);

                    // Add new move based on type to evolve to
                    Elements.ElementalMoves newMove = Elements.ElementalMoves.EmptyMoveSlot;

                    switch (newType)
                    {
                    case Elements.ElementType.Air:
                        newMove = Elements.ElementalMoves.AirStrike;
                        break;

                    case Elements.ElementType.Earth:
                        newMove = Elements.ElementalMoves.EarthQuake;
                        break;

                    case Elements.ElementType.Fire:
                        newMove = Elements.ElementalMoves.FireBlaze;
                        break;

                    case Elements.ElementType.Nature:
                        newMove = Elements.ElementalMoves.NaturesWrath;
                        break;

                    case Elements.ElementType.Water:
                        newMove = Elements.ElementalMoves.WaterBlast;
                        break;

                    default:
                        Debug.Log("Error choosing move based on type " + newType);
                        break;
                    }

                    // Chose move slot based on evolution count
                    switch (CurrentEvolutionStage)
                    {
                    case 1:
                        // Add new move to slot 2
                        MoveSlots[1] = newMove;
                        break;

                    case 2:
                        // Add new move to slot 3
                        MoveSlots[2] = newMove;
                        break;

                    case 3:
                    case 4:
                    case 5:
                        // Add new move to slot 1
                        MoveSlots[0] = newMove;
                        break;

                    default:
                        Debug.Log("Error adding new move to move slot");
                        break;
                    }

                    // Reset spec points
                    AirPoints    = 0; EarthPoints = 0; FirePoints = 0;
                    NaturePoints = 0; WaterPoints = 0;

                    // Save evolution and reload
                    ThisCharacterIsActive = false;                              // Dont interact with anything else
                    Notify(gameObject, Observer.Events.Evolve);                 // Evolved event notification
                    GameManagerRef.GetComponent <GameManager>().FlashEvolved(); // Flash evolved UI
                    GameManagerRef.GetComponent <GameManager>().EvolveToNextStage(gameObject);
                    return;
                }
            }
        }
        // Update UI
        if (!InBattleMode)
        {
            GameManagerRef.GetComponent <GameManager>().Update_Exp(Experience, ExpToLevelUp);
            GameManagerRef.GetComponent <GameManager>().UpdateText_Level(Level.ToString());
            GameManagerRef.GetComponent <GameManager>().UpdateText_AllElements(AirPoints.ToString(), EarthPoints.ToString(), FirePoints.ToString(),
                                                                               NaturePoints.ToString(), WaterPoints.ToString());
        }
    }