Giter Club home page Giter Club logo

Comments (5)

Glucius-TM avatar Glucius-TM commented on May 19, 2024

The return statements within each case already cause execution to exit the switch and return the corresponding value. Therefore, no additional break statements are needed in this case. Cleaned up the code a bit.

StatBoostMgr::StatType StatBoostMgr::GetStatTypeFromSubClass(Item* item)
{
    const ItemTemplate* itemTemplate = item->GetTemplate();
    if (itemTemplate->Class == ITEM_CLASS_WEAPON)
    {
        switch (itemTemplate->SubClass)
        {
            case ITEM_SUBCLASS_WEAPON_MACE2:
            case ITEM_SUBCLASS_WEAPON_POLEARM:
            case ITEM_SUBCLASS_WEAPON_SPEAR:
            case ITEM_SUBCLASS_WEAPON_GUN:
            case ITEM_SUBCLASS_WEAPON_BOW:
            case ITEM_SUBCLASS_WEAPON_CROSSBOW:
            {
                int random = urand(0, 2);
                return (random == 0) ? STAT_TYPE_TANK :
                    (random == 1) ? STAT_TYPE_PHYS :
                    STAT_TYPE_HYBRID;
            }
            case ITEM_SUBCLASS_WEAPON_THROWN:
                return STAT_TYPE_PHYS;
            case ITEM_SUBCLASS_WEAPON_DAGGER:
            {
                int random = urand(0, 2);
                return (random == 0) ? STAT_TYPE_PHYS :
                    (random == 1) ? STAT_TYPE_HYBRID :
                    STAT_TYPE_SPELL;
            }
            case ITEM_SUBCLASS_WEAPON_STAFF:
            {
                int random = urand(0, 3);
                return (random == 0) ? STAT_TYPE_TANK :
                    (random == 1) ? STAT_TYPE_PHYS :
                    (random == 2) ? STAT_TYPE_HYBRID :
                    STAT_TYPE_SPELL;
            }
            case ITEM_SUBCLASS_WEAPON_AXE:
            case ITEM_SUBCLASS_WEAPON_AXE2:
            case ITEM_SUBCLASS_WEAPON_MACE:
            case ITEM_SUBCLASS_WEAPON_SWORD:
            case ITEM_SUBCLASS_WEAPON_SWORD2:
            case ITEM_SUBCLASS_WEAPON_FIST:
            {
                int random = urand(0, 1);
                return (random == 0) ? STAT_TYPE_TANK :
                    STAT_TYPE_PHYS;
            }
            case ITEM_SUBCLASS_WEAPON_WAND:
                return STAT_TYPE_SPELL;
        }
    }
    else if (itemTemplate->Class == ITEM_CLASS_ARMOR)
    {
        switch (itemTemplate->SubClass)
        {
            case ITEM_SUBCLASS_ARMOR_CLOTH:
            {
                switch (itemTemplate->InventoryType)
                {
                    case INVTYPE_CLOAK:
                    {
                        int random = urand(0, 3);
                        return (random == 0) ? STAT_TYPE_TANK :
                            (random == 1) ? STAT_TYPE_PHYS :
                            (random == 2) ? STAT_TYPE_HYBRID :
                            STAT_TYPE_SPELL;
                    }
                    default:
                        return STAT_TYPE_SPELL;
                }
            }
            case ITEM_SUBCLASS_ARMOR_LEATHER:
            case ITEM_SUBCLASS_ARMOR_MAIL:
            case ITEM_SUBCLASS_ARMOR_PLATE:
            {
                int random = urand(0, 3);
                return (random == 0) ? STAT_TYPE_TANK :
                    (random == 1) ? STAT_TYPE_PHYS :
                    (random == 2) ? STAT_TYPE_HYBRID :
                    STAT_TYPE_SPELL;
            }
            case ITEM_SUBCLASS_ARMOR_BUCKLER:
            case ITEM_SUBCLASS_ARMOR_SHIELD:
            {
                int random = urand(0, 1);
                return (random == 0) ? STAT_TYPE_TANK :
                    STAT_TYPE_SPELL;
            }
        }
    }
    return STAT_TYPE_NONE;
}

from statbooster.

AnchyDev avatar AnchyDev commented on May 19, 2024

You can open a PR and reference this issue if there are no logic errors.

from statbooster.

Glucius-TM avatar Glucius-TM commented on May 19, 2024

Without the break statement, the flow of execution would continue through the subsequent cases without doing any additional checking. This is known as fall-through, and can lead to unexpected behavior and logic errors in your code. Then it would be necessary to add the break after each switch. Sorry for the mistake, I'm learning :S

from statbooster.

AnchyDev avatar AnchyDev commented on May 19, 2024

Without the break statement, the flow of execution would continue through the subsequent cases without doing any additional checking. This is known as fall-through, and can lead to unexpected behavior and logic errors in your code. Then it would be necessary to add the break after each switch. Sorry for the mistake, I'm learning :S

Just getting back to this but it's no problem. We are all learning and I bet you know a lot more now than you did when this was posted. 😄

from statbooster.

AnchyDev avatar AnchyDev commented on May 19, 2024

I am going to close this issue as it's not really an issue and will come naturally as I commit changes.

from statbooster.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.