// Script to handle baby horses inheriting
// their parent's color and scale properties
// There are many different color property inheritance functions,
// almost one for each horse,
// but it was done this way because many of the horse types
// have either a unique number of base_patterns
// (ie things would break if a unicorn, with 3 textures, inherited
// a rainbow horse's base_id of 10)
// or they have a unique way of handling inheritance
// (ie mule needs to inherit the parent's pattern,
// since donkey only has 1 texture and therefore no base_id)

// Author: InnerTri

// Imports
// Important Global Variables
import { system } from "@minecraft/server";


// Utility functions
import { getRandomInt, getRandomFloat, clamp, roundToInt, roundToDouble } from "./utility.js";

// Property arrays
// probably a better way to do this,
// but the best I could think of was an array of property arrays, per horse
// but calling that super-array down in the property assignments wouldn't be very clear,
// for example, blazehorse would be something like for property in horseProperties[13]
// eh maybe that's actually  not that bad...
import {
    horseColorProps, 
    // horseAttributeProps,
    horseScaleProps,

    // donkeyAttributeProps,
    donkeyScaleProps,


    unicornColorProps,
    rainbowColorProps,
    seahorseBigColorProps
} from "./horseProperties";



// Global Variables
// Chance of color property mutation
// 1 out of X
let colorMutateChance = 10;

// Chance of attribute property mutation
// 1 out of X
const attribUpChance = 2;
const attribDownChance = 4;





// Event Subscriptions

// There are multiple scriptEvent subscriptions across the various files
// I do not know if this is bad / frowned upon,
// but I wanted to keep ONLY cart-based things in the cart js file
system.afterEvents.scriptEventReceive.subscribe(
    event => {
        // first, check if the message is for us
        if (event.id === "cyn:hao") {
            // if it is check which "command" is being run
            switch (event.message) {

                // cyn horse born normally 
                // (same parents OR only way to be born)
                // unique property assignments
                // are handled within this function
				case "horseBorn_normal":
					horseBorn(event.sourceEntity, false);
				break;

                // special cases for horses that have multiple
                // ways of being born, for example pegasus:
                // two unicorns in special mode, or two pegasus in normal mode
                case "horseBorn_special":
					horseBorn(event.sourceEntity, true);
				break;
            }
        }
    }
);





// function for getting parents of the same typeId as the baby
function parentsSame(baby) {

	// filter only the nearest 2 horses of the same type as the 
    // newly-spawned cyn_horse, ignoring any baby horses
	let eqo = {
		type: baby.typeId,
		location: baby.location,
		closest: 2,
		excludeTags: [ "cyn_hao:baby_horse" ],
        excludeFamilies: [ "cyn_hao:baby_horse" ]
	};

	// return the parents
    return baby.dimension.getEntities(eqo);
}

// function for getting parents of the same ID as each other,
// but DIFFERENT from the baby
// can't use parentsDifferent since the two filters
// would find the same parent, since they check the same thing,
// and then the returned array would be one array of one parent, twice
function parentsDiffFromBaby(baby, parentType) {

	// filter only the nearest 2 horses of the type specified 
    // in the function parameters,
	// ignoring any baby horses
	let eqo = {
		type: parentType,
		location: baby.location,
		closest: 2,
		excludeTags: [ "cyn_hao:baby_horse" ]
	};

	// return the parents
    return baby.dimension.getEntities(eqo);
}

// function for getting parents with two differing typeIds
function parentsDifferent(baby, typeId1, typeId2) {

    let parents = [];
    let eqo = {};

    // get what is probably the first parent, ignoring any baby horses
	eqo = {
		type: typeId1,
		location: baby.location,
		closest: 1,
		excludeTags: [ "cyn_hao:baby_horse" ]
	};

    // add first parent to the array
    // since getEntities returns an array itself, just add it's element
    // to our array
    parents.push(baby.dimension.getEntities(eqo)[0]);

    // get what is probably the second parent, ignoring any baby horses
    eqo = {
		type: typeId2,
		location: baby.location,
		closest: 1,
		excludeTags: [ "cyn_hao:baby_horse" ]
	};

    // since getEntities returns an array itself, just add it's element
    // to our array
    parents.push(baby.dimension.getEntities(eqo)[0]);

	// return the parents
    return parents;
}



function getParents(baby, specialBirth) {
    // special cases that require 2 differing types of horses for parents
    switch (baby.typeId) {
        // hybrids, but not born of special breeding
        case "cyn_hao:mule":
        return parentsDifferent(baby, "cyn_hao:horse", "cyn_hao:donkey");

        case "cyn_hao:zonkey":
        return parentsDifferent(baby, "cyn_hao:zebra", "cyn_hao:donkey");

        case "cyn_hao:zorse":
        return parentsDifferent(baby, "cyn_hao:horse", "cyn_hao:zebra");


        // while not *practically* a special birth, 
        // alicorns will technically be a special birth,
        // just to make the inheritance easier
        case "cyn_hao:alicorn":
            // special case - unicorn + pegasus
            // normal case - two alicorns
            if (specialBirth) {
                return parentsDifferent(baby, "cyn_hao:unicorn", "cyn_hao:pegasus");
            }
            else {
                return parentsSame(baby);
            }
        return ;



        // born of special breeding
        // these horses have 2 valid SETS of parents, 
        // depending on if they were special-bred or not,
        // so we need to check which set to use
        case "cyn_hao:pegasus":
            // special case - two unicorns
            // normal case - two pegasus
            if (specialBirth) {
                return parentsDiffFromBaby(baby, "cyn_hao:unicorn");
            }
            else {
                return parentsSame(baby);
            }
        return ;

        case "cyn_hao:rainbow_horse":
            // special case - two horses
            // normal case - two rainbow horses
            if (specialBirth) {
                return parentsDiffFromBaby(baby, "cyn_hao:horse");
            }
            else {
                return parentsSame(baby);
            }
        return ;

        case "cyn_hao:fairy_horse":
            // special case - rainbow horse + pegasus
            // normal case - two fairy horses
            if (specialBirth) {
                return parentsDifferent(baby, "cyn_hao:rainbow_horse", "cyn_hao:pegasus");
            }
            else {
                return parentsSame(baby);
            }
        return ;

        // any types not specified above can ONLY come from
        // two parents that are the same type as the baby
        default:
        return parentsSame(baby);
    }
}



// Function that ALL horses run when they are born
// normal is whether or not it was a special birth
// unique property functions are defined below
function horseBorn(bornHorse, specialBirth) {

    // tag the baby so it won't be selected by the EQO
    // we have to use a tag because born horses don't quite
    // recieve their component groups yet,
    // and thus don't have the baby_horse tag from their
    // baby component group

    // NOTE that this tag is removed when a baby horse runs it's
    // cyn_hao:ageable_grow_up event, to ensure future breedings
    // don't use the baby, while it's a baby
    bornHorse.addTag("cyn_hao:baby_horse");

    // get the parents
    // typeIds of parents relative to child is handled in the function
    let parents = getParents(bornHorse, specialBirth);

    // DEBUG - teleport parents and child to their chambers for comparison
	// parents[0].tryTeleport({x: 16, y: -58, z: 10});
	// bornHorse.tryTeleport({x: 12, y: -58, z: 10});
	// parents[1].tryTeleport({x: 8, y: -58, z: 10});

    // make sure both parents are not null
    if((parents.length != 2) || (parents[0] == undefined) || (parents[1] == undefined)) {
        // since all cyn_horses are randomly assigned traits on spawn and we are simply overriding the default ones,
        // if something goes wrong (specifically, if a parent is null), 
        // just use the default randomly-assigned traits and print something saying so
        console.warn("A baby horse had an invalid parent at birth. Random traits will be used.");
        return;
    }

    // call the unique property function depending on the horse
    // only horses with special births use the specialBirth bool
    switch (bornHorse.typeId) {
        case "cyn_hao:horse":
            setHorseColorProperties(parents, bornHorse);
            setScaleProperties(parents, bornHorse, horseScaleProps);
        break;

        case "cyn_hao:donkey":
            // Donkeys have no color properties
            setScaleProperties(parents, bornHorse, donkeyScaleProps);
        break;

        case "cyn_hao:mule":
            setMuleColorProperties(parents, bornHorse);
            setScaleProperties(parents, bornHorse, horseScaleProps);
        break;

        case "cyn_hao:zebra":
            // Zebras have no color properties
            setScaleProperties(parents, bornHorse, donkeyScaleProps);
        break;

        case "cyn_hao:zonkey":
            // Zonkeys have no color properties
            setScaleProperties(parents, bornHorse, donkeyScaleProps);
        break;

        case "cyn_hao:zorse":
            setZorseColorProperties(parents, bornHorse);
            setScaleProperties(parents, bornHorse, horseScaleProps);
        break;

        case "cyn_hao:unicorn":
            setUnicornColorProperties(parents, bornHorse);
            setScaleProperties(parents, bornHorse, donkeyScaleProps);
        break;

        case "cyn_hao:pegasus":
            setPegasusColorProperties(parents, bornHorse);
            setScaleProperties(parents, bornHorse, donkeyScaleProps);
        break;

        case "cyn_hao:rainbow_horse":
            setRainbowColorProperties(parents, bornHorse, specialBirth);
            setScaleProperties(parents, bornHorse, horseScaleProps);
        break;

        case "cyn_hao:fairy_horse":
            setFairyColorProperties(parents, bornHorse, specialBirth);
            setScaleProperties(parents, bornHorse, horseScaleProps);
        break;

        case "cyn_hao:seahorse_big":
            setSeahorseColorProperties(parents, bornHorse, specialBirth);
            setScaleProperties(parents, bornHorse, donkeyScaleProps);
        break;

        case "cyn_hao:spider_horse":
            // Spider Horses have no Color Properties
            setScaleProperties(parents, bornHorse, horseScaleProps);
        break;
    }



    // inherit health, move speed, and jump height
    // EVERY horse does this the same way,
    // since it does this via component groups
    // since we can't just generate a random number
    // and set health to it, for example

    // otherwise, all other types inherit their parent's
    // attribute groups
    setAttributes(parents, bornHorse)
}



// Since we can't set attribute properties directly via script,
// (can only do currentValue, ie the horse's current health,
// but cannot affect it's max/min health - whatever it spawned with
// is it's immutable min and max health values)
// we have multiple groups of ranges
// babies will still choose a random value,
// but at least that random value will remain in
// "range" of the parents' average, breeding up
function setAttributes(parents, bornHorse) {

    // define what attributes we want to inherit
    // NOTE that we CANNOT *ACTUALLY* use the components;
    // currently, doing so for anything anything other than health
    // will completely crash minecraft
    // so instead we check the property we made that represents
    // a component group

    let inheritAttribs = [ "health", "speed", "jump" ];

    for (let attribName of inheritAttribs) {
        let propName = "cyn_hao:" + attribName + "_group_id";
        // console.warn(`
        //     ${parents[0].nameTag} ${attribName}: ${parents[0].getProperty(propName)}
        //     ${parents[1].nameTag} ${attribName}: ${parents[1].getProperty(propName)}
        //     ${parents[0].getProperty(propName)} + ${parents[1].getProperty(propName)} = ${parents[0].getProperty(propName) + parents[1].getProperty(propName)} / 2 = ${(parents[0].getProperty(propName) + parents[1].getProperty(propName))/2}
        //     Rounded: ${Math.round((parents[0].getProperty(propName) + parents[1].getProperty(propName))/2)}
        //     Baby Group Final: ${Math.round((parents[0].getProperty(propName) + parents[1].getProperty(propName)) /  2)}
        // `)

        // get the average of the groups the parents are in
        let babyGroup = Math.round((parents[0].getProperty(propName) + parents[1].getProperty(propName)) /  2);

        
        
        // NOTE:
        // I know it's bad to hard-code a max group value of 9 here,
        // but we're squeezing this system out on fumes
        // and even if we wanted to change the number of groups dynamically, 
        // there'd be no time to set that up anyway
        // maybe in a future update



        // there is a chance (defined at the top) that if the child is not already in the best group,
        //  the child gets bumped up a group
        if ((babyGroup < 9) && (getRandomInt(1, attribUpChance) == attribUpChance)) {
            // console.warn("Attribute " + attribName + " improved!")
            babyGroup = babyGroup + 1;
        }

        // if the stat did not improve, then OF THE "REMAINING" 50%,
        // there is a chance (defined at the top) that if the child is not already in the worst group,
        // the child gets knocked down a group
        else if ((babyGroup > 0) && (getRandomInt(1, attribDownChance) == attribDownChance)) {
            // console.warn("Attribute " + attribName + " got worse...")
            babyGroup = babyGroup - 1;
        }


        // otherwise, leave the baby's group as the (rounded) average of the parents'

        // If I'm understanding what I did correctly, the result is then:
        // 50% chance of the attribute improving
        // if not, OF THE 50% that it DIDN'T improve, 25% of it getting worse
        // so 25% of the 50%, so 12.5%
        // otherwise, it will stay the same,
        // so 100% - (50% + 12.5%) = 37.5% chance of it staying the same as the parents



        // else {
        //     console.warn("Attribute " + attribName + " stayed the same.")
        // }

        // save the group that the baby is in, for if this baby breeds
        bornHorse.setProperty(propName, babyGroup);
        
        // apply the attribute group
        bornHorse.triggerEvent("cyn_hao:event_" + attribName + "_group_" + babyGroup);
    }

}



// Failed attempt at dynamically setting horses (max) health
// Unfortunately, the extent of what we can do is set their CURRENT
// health, but this has no impact on the min or max possible health
// left in in case it suddenly becomes available

// // Function to set the attribute properties of a horse,
// // inherited from it's parents,
// // within the specified limits (Horse, Donkey, Etc.),
// // with up to 25% mutation
// function setAttributeProperties(parents, bornHorse, propLimitType) {

//     // Set attributes
//     // For a breakdown, see setScaleProperties function

//     let props = propLimitType;

//     // Calculate the baby's health attribute value
//     // Done outside the below loop since health MUST be an integer
//     // Get the health property, while removing it from the array
//     // that way the below for loop won't use it
//     let healthProp = props.shift();
//     console.warn(healthProp.componentName);

//     // This is all debug, final line is the one-line version
//     let parent0Value = parents[0].getComponent(healthProp.componentName).currentValue;
//     let parent1Value = parents[1].getComponent(healthProp.componentName).currentValue;
//     let added = parent0Value + parent1Value;
//     let average = Math.floor(( parent0Value + parent1Value) / 2);
//     let mutate = roundToDouble(getRandomFloat(0.75, 1.25));
//     let mutValue = Math.floor(clamp((average * mutate), (healthProp.min * 0.75), (healthProp.max * 1.25)));

//     console.warn("Setting " + healthProp.componentName + "\n" +
//         "Parent 1" + ": " + parent0Value + "\n" +
//         "Parent 2" + ": " + parent1Value + "\n" +
//         parent0Value + " + " + parent1Value + " = " + added + "\n" +
//         added + " / 2 = " + average + "\n" +
//         average + " * " + mutate + " = " + mutValue + "\n" + 
//         "Baby " + healthProp.componentName + " set to " + mutValue
//     )

//     bornHorse.getComponent(healthProp.componentName).setCurrentValue(100);
// }



// Function to set the scale properties of a horse,
// inherited from it's parents,
// within the specified limits (Horse, Donkey, Etc.),
// with up to 25% mutation
function setScaleProperties(parents, bornHorse, propLimitType) {
    // set scale properties to be the average of the parents 
    // multiplied by a random value between 0.75 and 1.25
    // resulting in the child being up to 25% different than THE AVERAGE
    // clamped since the mutation could result in a property that is
    // bigger or smaller than the bounds defined in the entity's property
    for (let property of propLimitType) {
        // // This is all debug, final line is the one-line version
        // let parent0Value = roundToDouble(parents[0].getProperty(property.name));
        // let parent1Value = roundToDouble(parents[1].getProperty(property.name));
        // let added = roundToDouble(parent0Value + parent1Value);
        // let average = roundToDouble(( parent0Value + parent1Value) / 2);
        // let mutate = roundToDouble(getRandomFloat(0.75, 1.25));
        // let mutValue = roundToDouble(clamp((average * mutate), (property.min * 0.75), (property.max * 1.25)));			

        // console.warn("Property: " + property.name + "\n" +
        // 	"Parent 1" + ": " + parent0Value + "\n" +
        // 	"Parent 2" + ": " + parent1Value + "\n" +
        // 	parent0Value + " + " + parent1Value + " = " + added + "\n" +
        // 	added + " / 2 = " + average + "\n" +
        // 	average + " * " + mutate + " = " + mutValue + "\n" + 
        // 	"Baby " + property.name + " set to " + mutValue
        // )

        // bornHorse.setProperty(property.name, mutValue);

        

        bornHorse.setProperty(property.name, 
            clamp(
                (
                    (
                        ( 
                            parents[0].getProperty(property.name)
                            +
                            parents[1].getProperty(property.name)
                        ) / 2
                    ) * getRandomFloat(0.75, 1.25)
                ), (property.min * 0.75), (property.max * 1.25)
            )
        );
    }
}



// Horse Color Property Assignment
// Sets the properties of the child to be randomly chosen from a parent,
// with a chance to mutate
function setHorseColorProperties(parents, bornHorse) {

    // go through each of this horse's color properties
    for (let property of horseColorProps) {

        // there is a chance that the child's property is random
        if (getRandomInt(1, colorMutateChance) == colorMutateChance) {
           // console.warn("Property " + property.name + " mutated!")
            bornHorse.setProperty(property.name, getRandomInt(property.min, property.max));
        }
        // otherwise inherit from a randomly-chosen parent
        else {
            let inherit = getRandomInt(0, 1);
            // console.warn("Property " + property.name + " used from " + parents[inherit].nameTag);
            bornHorse.setProperty(property.name, parents[inherit].getProperty(property.name));
        }
    }

    // set body properties to be the average of the parents 
    // multiplied by a random value between 0.75 and 1.25
    // resulting in the child being up to 25% different than THE AVERAGE
    // clamped since the mutation could result in a property that is
    // bigger or smaller than the bounds defined in the entity's property

    // Donkey Tame Limits are 1/2 of Horse Tame Limits
    for (let property of horseScaleProps) {
        // // This is all debug, final line is the one-line version
        // let parent0Value = roundToDouble(parents[0].getProperty(property.name));
        // let parent1Value = roundToDouble(parents[1].getProperty(property.name));
        // let added = roundToDouble(parent0Value + parent1Value);
        // let average = roundToDouble(( parent0Value + parent1Value) / 2);
        // let mutate = roundToDouble(getRandomFloat(0.75, 1.25));
        // let mutValue = roundToDouble(clamp((average * mutate), (property.min * 0.75), (property.max * 1.25)));			

        // console.warn("Property: " + property.name + "\n" +
        // 	"Parent 1" + ": " + parent0Value + "\n" +
        // 	"Parent 2" + ": " + parent1Value + "\n" +
        // 	parent0Value + " + " + parent1Value + " = " + added + "\n" +
        // 	added + " / 2 = " + average + "\n" +
        // 	average + " * " + mutate + " = " + mutValue + "\n" + 
        // 	"Baby " + property.name + " set to " + mutValue
        // )

        // bornHorse.setProperty(property.name, mutValue);


        bornHorse.setProperty(property.name, 
            clamp(
                (
                    (
                        ( 
                            parents[0].getProperty(property.name)
                            +
                            parents[1].getProperty(property.name)
                        ) / 2
                    ) * getRandomFloat(0.75, 1.25)
                ), (property.min * 0.75), (property.max * 1.25)
            )
        );
    }
	
}



// Donkey Color Property Assignment
// Donkeys have no color properties



// Mule Color Property Assignment
// Inherits it's base_coat from it's horse parent,
// with a chance of mutation
function setMuleColorProperties(parents, bornHorse) {

    // set mule body color to be inherited from it's parent horse
    // since only one parent has any variation
    // with a chance to mutate
    let property = horseColorProps[0];
    // there is a chance that the child's property is random
    if (getRandomInt(1, colorMutateChance) == colorMutateChance) {
        // console.warn("Property " + property.name + " mutated!")
        bornHorse.setProperty(property.name, getRandomInt(property.min, property.max));
    }
    // otherwise inherit from the cyn_horse parent
    else {
        let inherit = -1;

        // determine which parent is the cyn_horse
        if (parents[0].typeId == "cyn_hao:horse") {
            inherit = 0;
        }
        else if (parents[1].typeId == "cyn_hao:horse") {
            inherit = 1;
        }

        // if somehow neither is, print that and set it to be a random value
        else {
            console.warn("Neither parent of new baby cyn_hao:mule was a cyn_hao:horse. Setting random color.");
            bornHorse.setProperty(property.name, getRandomInt(property.min, property.max));
            return;
        }
        
        // console.warn("Property " + property.name + " used from " + parents[inherit].nameTag);
        bornHorse.setProperty(property.name, parents[inherit].getProperty(property.name));
    }
}



// Zebra Color Property Assignments
// Zebras have no color properties



// Zonkey Color Property Assignments
// Zonkeys have no color properties




// Zorse Color Property Assignment
// Similar to mule, but also has mane colors
function setZorseColorProperties(parents, bornHorse) {

    // set each inherited property to be inherited from it's parent horse
    // since only one parent has any variation
    // with a chance to mutate
    for (let property of [horseColorProps[0], horseColorProps[4]]) {

        // there is a chance that the child's property is random
        if (getRandomInt(1, colorMutateChance) == colorMutateChance) {
            // console.warn("Property " + property.name + " mutated!")
            bornHorse.setProperty(property.name, getRandomInt(property.min, property.max));
        }
        // otherwise inherit from the cyn_horse parent
        else {
            let inherit = -1;

            // determine which parent is the cyn_horse
            if (parents[0].typeId == "cyn_hao:horse") {
                inherit = 0;
            }
            else if (parents[1].typeId == "cyn_hao:horse") {
                inherit = 1;
            }

            // if somehow neither is, print that and set it to be a random value
            else {
                console.warn("Neither parent of new baby cyn_hao:zorse was a cyn_hao:horse. Setting random color.");
                bornHorse.setProperty(property.name, getRandomInt(property.min, property.max));
                return;
            }
            
            // console.warn("Property " + property.name + " used from " + parents[inherit].nameTag);
            bornHorse.setProperty(property.name, parents[inherit].getProperty(property.name));
        }
    }
}



// Unicorn Color Property Assignment
// similar to Mule, but with less base colors
// uses donkey scale variation
function setUnicornColorProperties(parents, bornHorse) {
    
    // go through each of this horse's color properties
    let property = unicornColorProps[0]
    // color is completely random
    // console.warn("Property " + property.name + " is always random for this horse.")
    bornHorse.setProperty(property.name, getRandomInt(property.min, property.max));
}



// Pegasus Color Property Assignment
// Pegasuses and unicorns have the same number of
// colors and their indices match (ALWAYS MAKE SURE OF THIS!),
// so the only difference between a normal and special birth
// is the parent type, which is handled in getParents()
// however, even in this special case, both parents are Unicorns
// In other words, Identical to Unicorn
function setPegasusColorProperties(parents, bornHorse) {
    setUnicornColorProperties(parents, bornHorse);
}



// Rainbow Horse Color Property Assignment
// If it was a normal birth, then parents were both color horses
// In this case, pick one of the parents with NO chance of mutation
// If it was a special birth, then parents were cyn_horses
// In this case, pick a completely random color
function setRainbowColorProperties(parents, bornHorse, specialBirth) {

    let property = rainbowColorProps[0];

    // if it was a normal birth
    if (specialBirth == false) {
        
        // rainbow horses will never mutate their color;
        // it is ALWAYS inherited from a randomly-chosen parent
        let inherit = getRandomInt(0, 1);
        // console.warn("Property " + property.name + " used from parent " + inherit + "");
        bornHorse.setProperty(property.name, parents[inherit].getProperty(property.name));
    }
    // if it was a special birth
    else {
        // color is completely random
        // console.warn("Property " + property.name + " is always random for this horse.")
        bornHorse.setProperty(property.name, getRandomInt(property.min, property.max));
    }	
}



// Fairy Horse Color Property Assignment
// If it was a normal birth, then parents were both color horses
// In this case, pick one of the parents with NO chance of mutation
// If it was a special birth, then one parent was a rainbow horse and one was a pegasus
// In this case, inherit base_coat from it's Rainbow Horse parent,
// with NO chance to mutate
function setFairyColorProperties(parents, bornHorse, specialBirth) {

    // set fairy body color to be inherited from it's parent rainbow horse
    // with NO chance to mutate
    let property = rainbowColorProps[0];

    // if it was a normal birth
    if (specialBirth == false) {
        // rainbow horses will never mutate their color;
        // it is ALWAYS inherited from a randomly-chosen parent
        let inherit = getRandomInt(0, 1);

        // console.warn("Property " + property.name + " used from " + parents[inherit].nameTag);
        bornHorse.setProperty(property.name, parents[inherit].getProperty(property.name));

    }

    // if it was a special birth
    else {
        // inherit from the rainbow_horse parent
        let inherit = -1;

        // determine which parent is the rainbow horse
        if (parents[0].typeId == "cyn_hao:rainbow_horse") {
            inherit = 0;
        }
        else if (parents[1].typeId == "cyn_hao:rainbow_horse") {
            inherit = 1;
        }

        // if somehow neither is, print that and set it to be a random value
        else {
            console.warn("Neither parent of new baby cyn_hao:fairy_horse was a cyn_hao:rainbow_horse. Setting random color.");
            bornHorse.setProperty(property.name, getRandomInt(property.min, property.max));
            return;
        }
        
        // console.warn("Property " + property.name + " used from " + parents[inherit].nameTag);
        bornHorse.setProperty(property.name, parents[inherit].getProperty(property.name));
    }
}




// Seahorse Color Property Assignment
// Similar to mule, but with less color options
// more colors than Unicorn, thus we cannot use unicorn's function
function setSeahorseColorProperties(parents, bornHorse) {

    // color is completely random
    let property = seahorseBigColorProps[0];
    
    // console.warn("Property " + property.name + " is always random for this horse.")
    bornHorse.setProperty(property.name, getRandomInt(property.min, property.max));
}



