Comments (5)
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.
You can open a PR and reference this issue if there are no logic errors.
from statbooster.
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.
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.
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)
- Optimize the analyze function. HOT 3
- Populate DB with enchants HOT 3
- Add mask column for weapon & armor for enchants
- Add subclass mask column
- Memory Leaks HOT 1
- Move readme note section to github wiki.
- Move scoring to database HOT 1
- Question about stats. HOT 2
- Each server recompile your sql try to apply again on starting server so error appear and server not start. HOT 1
- crash servera HOT 2
- Add more fields for the scoring table. HOT 2
- Some Enchants broke interface addons which show buffs durations. HOT 1
- Can only add one enchantment? HOT 2
- IlvlMin and ilvlMax not working HOT 6
- Hotlinked items do not show as enchanted. HOT 1
- [Fix Included] Populated Enchantment DB
- [Feature Requests] 1) Rarity tweaks. 2) Decimal place. 3) Multiple enchants. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from statbooster.