Example #1
0
    public bool ChangeJob(List <CharMovement> gameObjectArray, UnitTypes unitTypes)
    {
        CharMovement target = null;
        bool         result = false;

        switch (unitTypes)
        {
        // Prioritizes lower HP unit to be free
        case UnitTypes.Free:
            for (int i = 0; i < gameObjectArray.Count; ++i)
            {
                if (target != null)
                {
                    if (gameObjectArray[i].hp < target.hp && gameObjectArray[i].currentJob != UnitTypes.Free)
                    {
                        target = gameObjectArray[i];
                    }
                }
                else if (gameObjectArray[i].currentJob != UnitTypes.Free)
                {
                    target = gameObjectArray[i];
                }
            }

            if (target != null)
            {
                target.changeJob(unitTypes);
                result = true;
            }
            break;

        // Prioritizes low health units, 2nd priority being free units, 3rd priority being any unit other than healer
        case UnitTypes.Healer:
            for (int i = 0; i < gameObjectArray.Count; ++i)
            {
                if (target != null)
                {
                    if (gameObjectArray[i].hp < target.hp && gameObjectArray[i].currentJob == UnitTypes.Free)
                    {
                        target = gameObjectArray[i];
                    }
                }
                else if (gameObjectArray[i].currentJob == UnitTypes.Free)
                {
                    target = gameObjectArray[i];
                }
            }

            if (target != null)
            {
                target.changeJob(unitTypes);
                result = true;
            }
            break;

        case UnitTypes.Harvester:
            for (int i = 0; i < gameObjectArray.Count; ++i)
            {
                if (gameObjectArray[i].currentJob == UnitTypes.Free)
                {
                    target = gameObjectArray[i];
                    target.changeJob(unitTypes);
                    result = true;
                    break;
                }
            }
            break;

        case UnitTypes.Attacker:
            for (int i = 0; i < gameObjectArray.Count; ++i)
            {
                if (target != null)
                {
                    if (gameObjectArray[i].hp > target.hp && gameObjectArray[i].currentJob == UnitTypes.Free)
                    {
                        target = gameObjectArray[i];
                    }
                }
                else if (gameObjectArray[i].currentJob == UnitTypes.Free && gameObjectArray[i].hp >= 20)
                {
                    target = gameObjectArray[i];
                }
            }

            if (target != null)
            {
                target.changeJob(unitTypes);
                result = true;
            }
            break;
        }

        if (result)
        {
            RearrangeList(gameObjectArray, target);
        }
        return(false);
    }