Esempio n. 1
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /*
        The AIBuilder method creates a config for a AI enabled entity.
        Currently it psuedorandomly assigns stats, eventually options for chosen stats and weighted random stats
        will be added.
        The AIBuilder will require switch logic to pick a set of nonconflicting behaviors.
    */
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public AIConfig AIBuilder(string type, int rWeight)
    {
        if(rWeight > (maxStatValue * numOfStats)){
            Debug.LogError("Weight is too high for the number of stats given their maximums.");
            Debug.Break();
        }
        StatCollectionClass member = gameObject.GetComponent<StatCollectionClass>();
        decisionType = type;
        bool AImade = false;
        bool isMelee = false;
        bool isHybrid = false;
        bool isAggressive = false;
        bool isStalker = false;
        bool hasMagic = false;
        bool isCautious = false;

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /*
            We need to vary the stats based on weight.
            Look at the weight and see if the even split (average) is between the values is over statMax (our maximum
            normalized stat value).
            If it is, assign randomly from a range between statmin to statMax.
            Otherwise assign randomly statmin to the dividend of weight total with # of stats and add the modulus
            remainder. This will give stats that fairly equalized to the weight. Let AdjustStats fix any underages or
            overages.
        */
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        int[] split = new int[numOfStats];

        if ((rWeight / numOfStats) > maxStatValue) { //Upper bound on stats, might not be needed if things are weighted right.
            int remain = rWeight;
            for (int i = 0; i < numOfStats; i++) {
                split [i] = Random.Range (minStatValue, maxStatValue);
                //For Testing: print ("Random value for stat #" + i.ToString () + " : " + split [i].ToString ());
                remain = remain - split [i];
            }
        } else {
            for (int i = 0; i < numOfStats; i++) {
                split [i] = Random.Range (minStatValue, (rWeight / numOfStats) + rWeight % numOfStats);
                //For Testing: print ("Random value for stat #" + i.ToString () + " : " + split [i].ToString ());
            }
        }

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /*
         	Sum all the stats together to so we can compare it to weight.
         	Calculate the expected sum and actual sum diff for our AdjustStats call.
        */
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        int sumR;
        AdjustStats (split, rWeight);

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /*
             Finally check that the final sum is correct.
         	 If the sum is correct set AImade true and carry on!
             Otherwise throw nasty errors and annoy us.
             TODO Have this loop back to AdjustStats, error if it fails to properly adjust it again.(We should never
             hit this second call ideally.)
        */
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        //Testing
        //for(int j = 0; j < numOfStats; j++){
            //print("Final random stats" + split[j].ToString());
        //}
        //

        sumR = sumArray (split);
        //print ("The sum is " + sumR.ToString () + " It is supposed to be " + rWeight.ToString ());

        if (sumR == rWeight) {
            AImade = true;
        }

        if (AImade) {
            AssignStats(split);
        } else {
            Debug.LogError ("AIManager failed to create a proper AIBuild");
        }

        AIConfig config = new AIConfig ();

        #pragma warning disable
        BehaviorTypes assignBehavior = new BehaviorTypes ();
        #pragma warning restore

        switch(type){
        case "mob":
            if(member.health > 0){
                //Visual adjustments for health thresholds.
            }
            if(member.mana > 0){
                //Visual adjustments for mana thresholds.
                hasMagic = true;
            }
            if(member.strength > 6){
                isMelee = true;
                isAggressive = true;
                //Visual adjustments for being melee.
            }
            if(member.intellect > 6 && member.strength >= member.intellect){
                isCautious = true;
                isHybrid = true;
                //Visual adjustments for being cautious.
            }
            if(member.intellect > 6 && member.intellect >= member.strength){
                isStalker = true;
                //Visual adjustments for being a stalker.
            }

            config.isMelee = isMelee;
            config.isHybrid = isHybrid;
            config.hasMagic = hasMagic;
            config.isAggressive = isAggressive;
            config.isCautious = isCautious;
            config.isStalker = isStalker;

            if(isHybrid)
                config = assignBehavior.intializeHybridGeneric (config);
            else if(isMelee)
                config = assignBehavior.intializeMeleeGeneric (config);
            else
                config = assignBehavior.intializeRangedGeneric (config);

            AssignModifiers(config);
            config.isMade = AImade;
            break;
        case "npc":
            //Stuff might go here?
            break;
        case "boss":
            //Boss mechanics to be decided.
            break;
        default:
            Debug.LogError (type + ": is not a supported type.");
            break;
        }

        print(config.ToString ());

        return config;
    }
Esempio n. 2
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /*
     *      The AIBuilder method creates a config for a AI enabled entity.
     *      Currently it psuedorandomly assigns stats, eventually options for chosen stats and weighted random stats
     *      will be added.
     *      The AIBuilder will require switch logic to pick a set of nonconflicting behaviors.
     */
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    public AIConfig AIBuilder(string type, int rWeight)
    {
        if (rWeight > (maxStatValue * numOfStats))
        {
            Debug.LogError("Weight is too high for the number of stats given their maximums.");
            Debug.Break();
        }
        StatCollectionClass member = gameObject.GetComponent <StatCollectionClass>();

        decisionType = type;
        bool AImade       = false;
        bool isMelee      = false;
        bool isHybrid     = false;
        bool isAggressive = false;
        bool isStalker    = false;
        bool hasMagic     = false;
        bool isCautious   = false;

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        /*
         *      We need to vary the stats based on weight.
         *      Look at the weight and see if the even split (average) is between the values is over statMax (our maximum
         *      normalized stat value).
         *      If it is, assign randomly from a range between statmin to statMax.
         *      Otherwise assign randomly statmin to the dividend of weight total with # of stats and add the modulus
         *      remainder. This will give stats that fairly equalized to the weight. Let AdjustStats fix any underages or
         *      overages.
         */
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        int[] split = new int[numOfStats];

        if ((rWeight / numOfStats) > maxStatValue)           //Upper bound on stats, might not be needed if things are weighted right.
        {
            int remain = rWeight;
            for (int i = 0; i < numOfStats; i++)
            {
                split [i] = Random.Range(minStatValue, maxStatValue);
                //For Testing: print ("Random value for stat #" + i.ToString () + " : " + split [i].ToString ());
                remain = remain - split [i];
            }
        }
        else
        {
            for (int i = 0; i < numOfStats; i++)
            {
                split [i] = Random.Range(minStatValue, (rWeight / numOfStats) + rWeight % numOfStats);
                //For Testing: print ("Random value for stat #" + i.ToString () + " : " + split [i].ToString ());
            }
        }

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        /*
         *      Sum all the stats together to so we can compare it to weight.
         *      Calculate the expected sum and actual sum diff for our AdjustStats call.
         */
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        int sumR;

        AdjustStats(split, rWeight);

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        /*
         *       Finally check that the final sum is correct.
         *       If the sum is correct set AImade true and carry on!
         *       Otherwise throw nasty errors and annoy us.
         *       TODO Have this loop back to AdjustStats, error if it fails to properly adjust it again.(We should never
         *       hit this second call ideally.)
         */
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        //Testing
        //for(int j = 0; j < numOfStats; j++){
        //print("Final random stats" + split[j].ToString());
        //}
        //

        sumR = sumArray(split);
        //print ("The sum is " + sumR.ToString () + " It is supposed to be " + rWeight.ToString ());

        if (sumR == rWeight)
        {
            AImade = true;
        }


        if (AImade)
        {
            AssignStats(split);
        }
        else
        {
            Debug.LogError("AIManager failed to create a proper AIBuild");
        }

        AIConfig config = new AIConfig();

                #pragma warning disable
        BehaviorTypes assignBehavior = new BehaviorTypes();
                #pragma warning restore

        switch (type)
        {
        case "mob":
            if (member.health > 0)
            {
                //Visual adjustments for health thresholds.
            }
            if (member.mana > 0)
            {
                //Visual adjustments for mana thresholds.
                hasMagic = true;
            }
            if (member.strength > 6)
            {
                isMelee      = true;
                isAggressive = true;
                //Visual adjustments for being melee.
            }
            if (member.intellect > 6 && member.strength >= member.intellect)
            {
                isCautious = true;
                isHybrid   = true;
                //Visual adjustments for being cautious.
            }
            if (member.intellect > 6 && member.intellect >= member.strength)
            {
                isStalker = true;
                //Visual adjustments for being a stalker.
            }

            config.isMelee      = isMelee;
            config.isHybrid     = isHybrid;
            config.hasMagic     = hasMagic;
            config.isAggressive = isAggressive;
            config.isCautious   = isCautious;
            config.isStalker    = isStalker;

            if (isHybrid)
            {
                config = assignBehavior.intializeHybridGeneric(config);
            }
            else if (isMelee)
            {
                config = assignBehavior.intializeMeleeGeneric(config);
            }
            else
            {
                config = assignBehavior.intializeRangedGeneric(config);
            }


            AssignModifiers(config);
            config.isMade = AImade;
            break;

        case "npc":
            //Stuff might go here?
            break;

        case "boss":
            //Boss mechanics to be decided.
            break;

        default:
            Debug.LogError(type + ": is not a supported type.");
            break;
        }


        print(config.ToString());

        return(config);
    }
Esempio n. 3
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /*
        The AIBuilder method creates a config for a AI enabled entity.
        Currently it psuedorandomly assigns stats, eventually options for chosen stats and weighted random stats
        will be added.
        The AIBuilder will require switch logic to pick a set of nonconflicting behaviors.
    */
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
    public AIConfig AIBuilder(string type, int rWeight, int minStatValue, int maxStatValue)
    {
        if(rWeight > (maxStatValue * numOfStats)){
            Debug.LogError("Weight is too high for the number of stats given their maximums.");
            return default(AIConfig);
        }

        GameObject unitySucks = new GameObject ();

        AIConfig config = new AIConfig ();
        config.statExchange = unitySucks.AddComponent<StatCollectionClass> ();

        if (config.statExchange.Equals (null)) {
            Debug.LogError("Unity sucks");
        }

        bool AImade = false;
        bool isMelee = false;
        bool isHybrid = false;
        bool isAggressive = false;
        bool isStalker = false;
        bool hasMagic = false;
        bool isCautious = false;

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /*
            We need to vary the stats based on weight.
            Look at the weight and see if the even split (average) is between the values is over statMax (our maximum
            normalized stat value).
            If it is, assign randomly from a range between statmin to statMax.
            Otherwise assign randomly statmin to the dividend of weight total with # of stats and add the modulus
            remainder. This will give stats that fairly equalized to the weight. Let AdjustStats fix any underages or
            overages.
        */
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        int[] split = new int[numOfStats];

        if ((rWeight / numOfStats) > maxStatValue) { //Upper bound on stats, might not be needed if things are weighted right.
            int remain = rWeight;
            for (int i = 0; i < numOfStats; i++) {
                split [i] = Random.Range (minStatValue, maxStatValue);
                remain = remain - split [i];
            }
        } else {
            for (int i = 0; i < numOfStats; i++) {
                split [i] = Random.Range (minStatValue, (rWeight / numOfStats) + rWeight % numOfStats);
            }
        }

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /*
         	Sum all the stats together to so we can compare it to weight.
         	Calculate the expected sum and actual sum diff for our AdjustStats call.
        */
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        int sumR;
        AdjustStats (split, rWeight, minStatValue, maxStatValue);

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /*
             Finally check that the final sum is correct.
         	 If the sum is correct set AImade true and carry on!
             Otherwise throw nasty errors and annoy us.
             TODO Have this loop back to AdjustStats, error if it fails to properly adjust it again.(We should never
             hit this second call ideally.)
        */
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        sumR = sumArray (split);
        if (sumR == rWeight) {
            AImade = true;
        }

        if (AImade) {
            AssignStats(split, unitySucks.GetComponent<StatCollectionClass>());
        } else {
            Debug.LogError ("AIManager failed to create a proper AIBuild");
        }

        #pragma warning disable
        BehaviorTypes assignBehavior = new BehaviorTypes ();
        #pragma warning restore

        switch(type){
        case "mob":
            if(config.statExchange.health > 0){
            }
            if(config.statExchange.mana > 0){
                hasMagic = true;
            }
            if(config.statExchange.strength > 6){
                isMelee = true;
                isAggressive = true;
            }
            if(config.statExchange.intellect > 6 && config.statExchange.strength >= config.statExchange.intellect){
                isCautious = true;
                isHybrid = true;
            }
            if(config.statExchange.intellect > 6 && config.statExchange.intellect >= config.statExchange.strength){
                isStalker = true;
            }

            if(isMelee && !isHybrid){
                float str = config.statExchange.strength;
                float scale = (1.5f * (1f + str/50f));
                transform.localScale = new Vector3(scale, scale, 0);
                config.AIType = "Melee";
            }else if(isHybrid){
                transform.localScale = new Vector3(2f, 2f, 0);
                config.AIType = "Hybrid";
            }else{
                transform.localScale = new Vector3(1.8f, 1.8f, 0);
                config.AIType = "Ranged";
            }

            config.isMelee = isMelee;
            config.isHybrid = isHybrid;
            config.hasMagic = hasMagic;
            config.isAggressive = isAggressive;
            config.isCautious = isCautious;
            config.isStalker = isStalker;

            if(isHybrid)
                config = assignBehavior.intializeHybridGeneric(config);
            else if(isMelee)
                config = assignBehavior.intializeMeleeGeneric(config);
            else
                config = assignBehavior.intializeRangedGeneric(config);

            AssignModifiers(config);
            config.isMade = AImade;
            break;
        case "npc":
            //Stuff might go here?
            break;
        case "boss":
            if(config.statExchange.health > 0){
            }
            if(config.statExchange.mana > 0){
                hasMagic = true;
            }
            if(config.statExchange.strength > 6){
                isMelee = true;
                isAggressive = true;
            }
            if(config.statExchange.intellect > 6 && config.statExchange.strength >= config.statExchange.intellect){
                isCautious = true;
                isHybrid = true;
            }
            if(config.statExchange.intellect > 6 && config.statExchange.intellect >= config.statExchange.strength){
                isStalker = true;
            }

            if(isMelee && !isHybrid){
                float str = config.statExchange.strength;
                float scale = (1.5f * (1f + str/50f));
                transform.localScale = new Vector3(scale, scale, 0);
                config.AIType = "Melee";
            }else if(isHybrid){
                transform.localScale = new Vector3(2f, 2f, 0);
                config.AIType = "Hybrid";
            }else{
                transform.localScale = new Vector3(1.8f, 1.8f, 0);
                config.AIType = "Ranged";
            }
            config.isMelee = isMelee;
            config.isHybrid = isHybrid;
            config.hasMagic = hasMagic;
            config.isAggressive = isAggressive;
            config.isCautious = isCautious;
            config.isStalker = isStalker;

            if(isHybrid)
                config = assignBehavior.intializeHybridGeneric(config);
            else if(isMelee)
                config = assignBehavior.intializeMeleeGeneric(config);
            else
                config = assignBehavior.intializeRangedGeneric(config);

            AssignModifiers(config);
            config.isMade = AImade;
            break;
        default:
            Debug.LogError (type + ": is not a supported type.");
            break;
        }
        print(config.ToString ());

        StartCoroutine ("waitToDestroy", unitySucks);
        //Destroy (unitySucks);
        return config;
    }