From 90574d083da08ccd6699bdad403601e282d73b89 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sat, 22 Feb 2014 22:57:40 +0100 Subject: Changed formatting, encapsuled armor drop, introduced better static Enchantment IDs --- src/BlockID.h | 32 -------------------------------- src/Enchantments.h | 32 ++++++++++++++++++++++++++++++++ src/Mobs/Blaze.cpp | 2 +- src/Mobs/Cavespider.cpp | 2 +- src/Mobs/Monster.cpp | 28 ++++++++++++++++++++++++++++ src/Mobs/Monster.h | 8 +++++++- src/Mobs/Skeleton.cpp | 10 ++-------- src/Mobs/Witch.cpp | 14 +++++++------- src/Mobs/Zombie.cpp | 6 +----- src/Mobs/Zombiepigman.cpp | 2 +- 10 files changed, 80 insertions(+), 56 deletions(-) diff --git a/src/BlockID.h b/src/BlockID.h index e23a0f82a..740c5fc90 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -392,38 +392,6 @@ enum ENUM_ITEM_ID -// ENCHANTMENT IDS -enum -{ - E_ENCHANTMENT_PROTECTION = 0, - E_ENCHANTMENT_FIRE_PROTECTION = 1, - E_ENCHANTMENT_FEATHER_FALLING = 2, - E_ENCHANTMENT_BLAST_PROTECTION = 3, - E_ENCHANTMENT_PROJECTILE_PROTECTION= 4, - E_ENCHANTMENT_RESPIRATION = 5, - E_ENCHANTMENT_AQUA_AFFINITY = 6, - E_ENCHANTMENT_THORNS = 7, - E_ENCHANTMENT_SHARPNESS = 16, - E_ENCHANTMENT_SMITE = 17, - E_ENCHANTMENT_BANE_OF_ARTHROPODS = 18, - E_ENCHANTMENT_KNOCKBACK = 19, - E_ENCHANTMENT_FIREASPECT = 20, - E_ENCHANTMENT_LOOTING = 21, - E_ENCHANTMENT_EFFICIENCY = 32, - E_ENCHANTMENT_SILKTOUCH = 33, - E_ENCHANTMENT_UNBREAKING = 34, - E_ENCHANTMENT_FORTUNE = 35, - E_ENCHANTMENT_POWER = 48, - E_ENCHANTMENT_PUNCH = 49, - E_ENCHANTMENT_FLAME = 50, - E_ENCHANTMENT_INFINITY = 51, - E_ENCHANTMENT_LUCKOFTHESEA = 61, - E_ENCHANTMENT_LURE = 62, -}; - - - - enum { diff --git a/src/Enchantments.h b/src/Enchantments.h index e984df92e..14a900e19 100644 --- a/src/Enchantments.h +++ b/src/Enchantments.h @@ -21,6 +21,38 @@ class cParsedNBT; +// ENCHANTMENT IDS +enum +{ + E_ENCHANTMENT_PROTECTION = 0, + E_ENCHANTMENT_FIRE_PROTECTION = 1, + E_ENCHANTMENT_FEATHER_FALLING = 2, + E_ENCHANTMENT_BLAST_PROTECTION = 3, + E_ENCHANTMENT_PROJECTILE_PROTECTION= 4, + E_ENCHANTMENT_RESPIRATION = 5, + E_ENCHANTMENT_AQUA_AFFINITY = 6, + E_ENCHANTMENT_THORNS = 7, + E_ENCHANTMENT_SHARPNESS = 16, + E_ENCHANTMENT_SMITE = 17, + E_ENCHANTMENT_BANE_OF_ARTHROPODS = 18, + E_ENCHANTMENT_KNOCKBACK = 19, + E_ENCHANTMENT_FIREASPECT = 20, + E_ENCHANTMENT_LOOTING = 21, + E_ENCHANTMENT_EFFICIENCY = 32, + E_ENCHANTMENT_SILKTOUCH = 33, + E_ENCHANTMENT_UNBREAKING = 34, + E_ENCHANTMENT_FORTUNE = 35, + E_ENCHANTMENT_POWER = 48, + E_ENCHANTMENT_PUNCH = 49, + E_ENCHANTMENT_FLAME = 50, + E_ENCHANTMENT_INFINITY = 51, + E_ENCHANTMENT_LUCKOFTHESEA = 61, + E_ENCHANTMENT_LURE = 62, +}; + + + + /** Class that stores item enchantments or stored-enchantments The enchantments may be serialized to a stringspec and read back from such stringspec. diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index fb97ea3c4..cd5437d97 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -19,7 +19,7 @@ cBlaze::cBlaze(void) : void cBlaze::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - if (a_Killer != NULL && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) + if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) { int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_BLAZE_ROD); diff --git a/src/Mobs/Cavespider.cpp b/src/Mobs/Cavespider.cpp index a2678744b..4ef80e5f0 100644 --- a/src/Mobs/Cavespider.cpp +++ b/src/Mobs/Cavespider.cpp @@ -37,7 +37,7 @@ void cCavespider::GetDrops(cItems & a_Drops, cEntity * a_Killer) LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); - if (a_Killer != NULL && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) + if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) { AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); } diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 777b78c63..c81f46d6a 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -909,6 +909,34 @@ void cMonster::AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a +void cMonster::AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel) +{ + MTRand r1; + if (r1.randInt() % 200 < (17 + (a_LootingLevel * 2))) + { + if (!GetEquippedHelmet().IsEmpty()) a_Drops.push_back(GetEquippedHelmet()); + } + + if (r1.randInt() % 200 < (17 + (a_LootingLevel * 2))) + { + if (!GetEquippedChestplate().IsEmpty()) a_Drops.push_back(GetEquippedChestplate()); + } + + if (r1.randInt() % 200 < (17 + (a_LootingLevel * 2))) + { + if (!GetEquippedLeggings().IsEmpty()) a_Drops.push_back(GetEquippedLeggings()); + } + + if (r1.randInt() % 200 < (17 + (a_LootingLevel * 2))) + { + if (!GetEquippedBoots().IsEmpty()) a_Drops.push_back(GetEquippedBoots()); + } +} + + + + + void cMonster::HandleDaylightBurning(cChunk & a_Chunk) { if (!m_BurnsInDaylight) diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 670e899c5..6f7352b52 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -5,6 +5,7 @@ #include "../Defines.h" #include "../BlockID.h" #include "../Item.h" +#include "../Enchantments.h" @@ -225,11 +226,16 @@ protected: /** Adds a random number of a_Item between a_Min and a_Max to itemdrops a_Drops*/ void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0); - /** Adds a item a_Item with the chance of a_Chance to itemdrops a_Drops*/ + + /** Adds a item a_Item with the chance of a_Chance (in percent) to itemdrops a_Drops*/ void AddRandomUncommonDropItem(cItems & a_Drops, float a_Chance, short a_Item, short a_ItemHealth = 0); + /** Adds one rare item out of the list of rare items a_Items modified by the looting level a_LootingLevel(I-III or custom) to the itemdrop a_Drops*/ void AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a_LootingLevel); + /** Adds armor that is equipped with the chance of 8,5% (Looting 3: 11,5%) to the drop*/ + void AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel); + } ; // tolua_export diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index 7c62de9cf..c941ae521 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -31,20 +31,14 @@ void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer) AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_COAL); cItems RareDrops; RareDrops.Add(cItem(E_ITEM_HEAD, 1, 1)); - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomArmorDropItem(a_Drops, LootingLevel); } else { AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ARROW); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); - cItems RareDrops; - if (!GetEquippedHelmet().IsEmpty()) RareDrops.Add(GetEquippedHelmet()); - if (!GetEquippedChestplate().IsEmpty()) RareDrops.Add(GetEquippedChestplate()); - if (!GetEquippedLeggings().IsEmpty()) RareDrops.Add(GetEquippedLeggings()); - if (!GetEquippedBoots().IsEmpty()) RareDrops.Add(GetEquippedBoots()); - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); - AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomArmorDropItem(a_Drops, LootingLevel); } } diff --git a/src/Mobs/Witch.cpp b/src/Mobs/Witch.cpp index f9025afe3..a278a1964 100644 --- a/src/Mobs/Witch.cpp +++ b/src/Mobs/Witch.cpp @@ -30,13 +30,13 @@ void cWitch::GetDrops(cItems & a_Drops, cEntity * a_Killer) int DropType = r1.randInt() % 7; switch (DropType) { - case 0: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLASS_BOTTLE); - case 1: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLOWSTONE_DUST); - case 2: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); - case 3: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_REDSTONE_DUST); - case 4: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SPIDER_EYE); - case 5: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STICK); - case 6: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SUGAR); + case 0: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLASS_BOTTLE); break; + case 1: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLOWSTONE_DUST); break; + case 2: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); break; + case 3: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_REDSTONE_DUST); break; + case 4: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SPIDER_EYE); break; + case 5: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STICK); break; + case 6: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SUGAR); break; } } cItems RareDrops; diff --git a/src/Mobs/Zombie.cpp b/src/Mobs/Zombie.cpp index 61cf49c14..5facf085e 100644 --- a/src/Mobs/Zombie.cpp +++ b/src/Mobs/Zombie.cpp @@ -33,12 +33,8 @@ void cZombie::GetDrops(cItems & a_Drops, cEntity * a_Killer) RareDrops.Add(cItem(E_ITEM_IRON)); RareDrops.Add(cItem(E_ITEM_CARROT)); RareDrops.Add(cItem(E_ITEM_POTATO)); - if (!GetEquippedHelmet().IsEmpty()) RareDrops.Add(GetEquippedHelmet()); - if (!GetEquippedChestplate().IsEmpty()) RareDrops.Add(GetEquippedChestplate()); - if (!GetEquippedLeggings().IsEmpty()) RareDrops.Add(GetEquippedLeggings()); - if (!GetEquippedBoots().IsEmpty()) RareDrops.Add(GetEquippedBoots()); - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomArmorDropItem(a_Drops, LootingLevel); } diff --git a/src/Mobs/Zombiepigman.cpp b/src/Mobs/Zombiepigman.cpp index 5492068c9..3ecc65fed 100644 --- a/src/Mobs/Zombiepigman.cpp +++ b/src/Mobs/Zombiepigman.cpp @@ -29,8 +29,8 @@ void cZombiePigman::GetDrops(cItems & a_Drops, cEntity * a_Killer) cItems RareDrops; RareDrops.Add(cItem(E_ITEM_GOLD)); - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomArmorDropItem(a_Drops, LootingLevel); } -- cgit v1.2.3