1
0

Fixed Formatting, Added DropChance attributes to Monsters

This commit is contained in:
TheJumper 2014-02-23 18:13:49 +01:00
parent beba3e55d7
commit 1afcc255bf
10 changed files with 247 additions and 34 deletions

View File

@ -81,6 +81,11 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString
, m_AttackDamage(1)
, m_AttackRange(2)
, m_AttackInterval(0)
, m_DropChanceWeapon(0.085)
, m_DropChanceHelmet(0.085)
, m_DropChanceChestplate(0.085)
, m_DropChanceLeggings(0.085)
, m_DropChanceBoots(0.085)
, m_SightDistance(25)
, m_BurnsInDaylight(false)
{
@ -912,22 +917,22 @@ 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 (r1.randInt() % 200 < ((m_DropChanceHelmet * 200) + (a_LootingLevel * 2)))
{
if (!GetEquippedHelmet().IsEmpty()) a_Drops.push_back(GetEquippedHelmet());
}
if (r1.randInt() % 200 < (17 + (a_LootingLevel * 2)))
if (r1.randInt() % 200 < ((m_DropChanceChestplate * 200) + (a_LootingLevel * 2)))
{
if (!GetEquippedChestplate().IsEmpty()) a_Drops.push_back(GetEquippedChestplate());
}
if (r1.randInt() % 200 < (17 + (a_LootingLevel * 2)))
if (r1.randInt() % 200 < ((m_DropChanceLeggings * 200) + (a_LootingLevel * 2)))
{
if (!GetEquippedLeggings().IsEmpty()) a_Drops.push_back(GetEquippedLeggings());
}
if (r1.randInt() % 200 < (17 + (a_LootingLevel * 2)))
if (r1.randInt() % 200 < ((m_DropChanceBoots * 200) + (a_LootingLevel * 2)))
{
if (!GetEquippedBoots().IsEmpty()) a_Drops.push_back(GetEquippedBoots());
}
@ -937,6 +942,19 @@ void cMonster::AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel)
void cMonster::AddRandomWeaponDropItem(cItems & a_Drops, short a_LootingLevel)
{
MTRand r1;
if (r1.randInt() % 200 < ((m_DropChanceWeapon * 200) + (a_LootingLevel * 2)))
{
if (!GetEquippedWeapon().IsEmpty()) a_Drops.push_back(GetEquippedWeapon());
}
}
void cMonster::HandleDaylightBurning(cChunk & a_Chunk)
{
if (!m_BurnsInDaylight)

View File

@ -119,6 +119,17 @@ public:
void SetAttackDamage(int a_AttackDamage) { m_AttackDamage = a_AttackDamage; }
void SetSightDistance(int a_SightDistance) { m_SightDistance = a_SightDistance; }
float GetDropChanceWeapon() { return m_DropChanceWeapon; };
float GetDropChanceHelmet() { return m_DropChanceHelmet; };
float GetDropChanceChestplate() { return m_DropChanceChestplate; };
float GetDropChanceLeggings() { return m_DropChanceLeggings; };
float GetDropChanceBoots() { return m_DropChanceBoots; };
void SetDropChanceWeapon(float a_DropChanceWeapon) { m_DropChanceWeapon = a_DropChanceWeapon; };
void SetDropChanceHelmet(float a_DropChanceHelmet) { m_DropChanceHelmet = a_DropChanceHelmet; };
void SetDropChanceChestplate(float a_DropChanceChestplate) { m_DropChanceChestplate = a_DropChanceChestplate; };
void SetDropChanceLeggings(float a_DropChanceLeggings) { m_DropChanceLeggings = a_DropChanceLeggings; };
void SetDropChanceBoots(float a_DropChanceBoots) { m_DropChanceBoots = a_DropChanceBoots; };
/// Sets whether the mob burns in daylight. Only evaluated at next burn-decision tick
void SetBurnsInDaylight(bool a_BurnsInDaylight) { m_BurnsInDaylight = a_BurnsInDaylight; }
@ -221,6 +232,12 @@ protected:
float m_AttackInterval;
int m_SightDistance;
float m_DropChanceWeapon;
float m_DropChanceHelmet;
float m_DropChanceChestplate;
float m_DropChanceLeggings;
float m_DropChanceBoots;
void HandleDaylightBurning(cChunk & a_Chunk);
bool m_BurnsInDaylight;
@ -236,6 +253,9 @@ protected:
/** 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);
/** Adds weapon that is equipped with the chance of 8,5% (Looting 3: 11,5%) to the drop*/
void AddRandomWeaponDropItem(cItems & a_Drops, short a_LootingLevel);
} ; // tolua_export

View File

@ -39,34 +39,35 @@ void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer)
void cMooshroom::OnRightClicked(cPlayer & a_Player)
{
if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_BUCKET))
switch (a_Player.GetEquippedItem().m_ItemType)
{
if (!a_Player.IsGameModeCreative())
case E_ITEM_BUCKET:
{
a_Player.GetInventory().RemoveOneEquippedItem();
a_Player.GetInventory().AddItem(E_ITEM_MILK);
}
}
if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_BOWL))
{
if (!a_Player.IsGameModeCreative())
if (!a_Player.IsGameModeCreative())
{
a_Player.GetInventory().RemoveOneEquippedItem();
a_Player.GetInventory().AddItem(E_ITEM_MILK);
}
} break;
case E_ITEM_BOWL:
{
a_Player.GetInventory().RemoveOneEquippedItem();
a_Player.GetInventory().AddItem(E_ITEM_MUSHROOM_SOUP);
}
}
if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_SHEARS)
{
if (!a_Player.IsGameModeCreative())
if (!a_Player.IsGameModeCreative())
{
a_Player.GetInventory().RemoveOneEquippedItem();
a_Player.GetInventory().AddItem(E_ITEM_MUSHROOM_SOUP);
}
} break;
case E_ITEM_SHEARS:
{
a_Player.UseEquippedItem();
}
if (!a_Player.IsGameModeCreative())
{
a_Player.UseEquippedItem();
}
cItems Drops;
Drops.push_back(cItem(E_BLOCK_RED_MUSHROOM, 5, 0));
m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10);
cItems Drops;
Drops.push_back(cItem(E_BLOCK_RED_MUSHROOM, 5, 0));
m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10);
} break;
}
}

View File

@ -27,19 +27,19 @@ void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer)
}
if (IsWither())
{
AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE);
AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_COAL);
cItems RareDrops;
RareDrops.Add(cItem(E_ITEM_HEAD, 1, 1));
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);
AddRandomArmorDropItem(a_Drops, LootingLevel);
}
AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE);
AddRandomArmorDropItem(a_Drops, LootingLevel);
AddRandomWeaponDropItem(a_Drops, LootingLevel);
}

View File

@ -39,9 +39,7 @@ void cWitch::GetDrops(cItems & a_Drops, cEntity * a_Killer)
case 6: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SUGAR); break;
}
}
cItems RareDrops;
if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon());
AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel);
AddRandomWeaponDropItem(a_Drops, LootingLevel);
}

View File

@ -35,6 +35,7 @@ void cZombie::GetDrops(cItems & a_Drops, cEntity * a_Killer)
RareDrops.Add(cItem(E_ITEM_POTATO));
AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel);
AddRandomArmorDropItem(a_Drops, LootingLevel);
AddRandomWeaponDropItem(a_Drops, LootingLevel);
}

View File

@ -31,6 +31,7 @@ void cZombiePigman::GetDrops(cItems & a_Drops, cEntity * a_Killer)
RareDrops.Add(cItem(E_ITEM_GOLD));
AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel);
AddRandomArmorDropItem(a_Drops, LootingLevel);
AddRandomWeaponDropItem(a_Drops, LootingLevel);
}

View File

@ -407,6 +407,14 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster)
}
} // switch (payload)
m_Writer.BeginList("DropChances", TAG_Float);
m_Writer.AddFloat("", a_Monster->GetDropChanceWeapon());
m_Writer.AddFloat("", a_Monster->GetDropChanceHelmet());
m_Writer.AddFloat("", a_Monster->GetDropChanceChestplate());
m_Writer.AddFloat("", a_Monster->GetDropChanceLeggings());
m_Writer.AddFloat("", a_Monster->GetDropChanceBoots());
m_Writer.EndList();
m_Writer.BeginCompound("");
AddBasicEntity(a_Monster, EntityClass);
switch (a_Monster->GetMobType())

View File

@ -1485,6 +1485,11 @@ void cWSSAnvil::LoadBatFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1500,6 +1505,11 @@ void cWSSAnvil::LoadBlazeFromNBT(cEntityList & a_Entities, const cParsedNBT & a_
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1515,6 +1525,11 @@ void cWSSAnvil::LoadCaveSpiderFromNBT(cEntityList & a_Entities, const cParsedNBT
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1530,6 +1545,11 @@ void cWSSAnvil::LoadChickenFromNBT(cEntityList & a_Entities, const cParsedNBT &
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1545,6 +1565,11 @@ void cWSSAnvil::LoadCowFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1560,6 +1585,11 @@ void cWSSAnvil::LoadCreeperFromNBT(cEntityList & a_Entities, const cParsedNBT &
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1575,6 +1605,11 @@ void cWSSAnvil::LoadEnderDragonFromNBT(cEntityList & a_Entities, const cParsedNB
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1591,6 +1626,11 @@ void cWSSAnvil::LoadEndermanFromNBT(cEntityList & a_Entities, const cParsedNBT &
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1606,6 +1646,11 @@ void cWSSAnvil::LoadGhastFromNBT(cEntityList & a_Entities, const cParsedNBT & a_
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1620,6 +1665,11 @@ void cWSSAnvil::LoadGiantFromNBT(cEntityList & a_Entities, const cParsedNBT & a_
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1646,6 +1696,11 @@ void cWSSAnvil::LoadHorseFromNBT(cEntityList & a_Entities, const cParsedNBT & a_
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1661,6 +1716,11 @@ void cWSSAnvil::LoadIronGolemFromNBT(cEntityList & a_Entities, const cParsedNBT
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1682,6 +1742,11 @@ void cWSSAnvil::LoadMagmaCubeFromNBT(cEntityList & a_Entities, const cParsedNBT
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1697,6 +1762,11 @@ void cWSSAnvil::LoadMooshroomFromNBT(cEntityList & a_Entities, const cParsedNBT
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1712,6 +1782,11 @@ void cWSSAnvil::LoadOcelotFromNBT(cEntityList & a_Entities, const cParsedNBT & a
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1727,6 +1802,11 @@ void cWSSAnvil::LoadPigFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1748,6 +1828,11 @@ void cWSSAnvil::LoadSheepFromNBT(cEntityList & a_Entities, const cParsedNBT & a_
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1763,6 +1848,11 @@ void cWSSAnvil::LoadSilverfishFromNBT(cEntityList & a_Entities, const cParsedNBT
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1784,6 +1874,11 @@ void cWSSAnvil::LoadSkeletonFromNBT(cEntityList & a_Entities, const cParsedNBT &
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1805,6 +1900,11 @@ void cWSSAnvil::LoadSlimeFromNBT(cEntityList & a_Entities, const cParsedNBT & a_
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1820,6 +1920,11 @@ void cWSSAnvil::LoadSnowGolemFromNBT(cEntityList & a_Entities, const cParsedNBT
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1835,6 +1940,11 @@ void cWSSAnvil::LoadSpiderFromNBT(cEntityList & a_Entities, const cParsedNBT & a
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1850,6 +1960,11 @@ void cWSSAnvil::LoadSquidFromNBT(cEntityList & a_Entities, const cParsedNBT & a_
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1871,6 +1986,11 @@ void cWSSAnvil::LoadVillagerFromNBT(cEntityList & a_Entities, const cParsedNBT &
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1886,6 +2006,11 @@ void cWSSAnvil::LoadWitchFromNBT(cEntityList & a_Entities, const cParsedNBT & a_
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1901,6 +2026,11 @@ void cWSSAnvil::LoadWitherFromNBT(cEntityList & a_Entities, const cParsedNBT & a
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1916,6 +2046,10 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
int OwnerIdx = a_NBT.FindChildByName(a_TagIdx, "Owner");
if (OwnerIdx > 0)
{
@ -1964,6 +2098,11 @@ void cWSSAnvil::LoadZombieFromNBT(cEntityList & a_Entities, const cParsedNBT & a
{
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -1980,6 +2119,11 @@ void cWSSAnvil::LoadPigZombieFromNBT(cEntityList & a_Entities, const cParsedNBT
return;
}
if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
a_Entities.push_back(Monster.release());
}
@ -2023,6 +2167,25 @@ bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_N
bool LoadMonsterBaseFromNBT(cMonster & a_Monster, const cParsedNBT & a_NBT, int a_TagIdx)
{
float DropChance[5];
if (!LoadDoublesListFromNBT(DropChance, 5, a_NBT, a_NBT.FindChildByName(a_TagIdx, "DropChance")))
{
return false;
}
a_Monster.SetDropChanceWeapon(DropChance[0]);
a_Monster.SetDropChanceHelmet(DropChance[1]);
a_Monster.SetDropChanceChestplate(DropChance[2]);
a_Monster.SetDropChanceLeggings(DropChance[3]);
a_Monster.SetDropChanceBoots(DropChance[4]);
return true;
}
bool cWSSAnvil::LoadProjectileBaseFromNBT(cProjectileEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx)
{
if (!LoadEntityBaseFromNBT(a_Entity, a_NBT, a_TagIdx))

View File

@ -194,6 +194,9 @@ protected:
/// Loads entity common data from the NBT compound; returns true if successful
bool LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx);
/// Loads monster common data from the NBT compound; returns true if successful
bool LoadMonsterBaseFromNBT(cMonster & a_Monster, const cParsedNBT & a_NBT, int a_TagIdx);
/// Loads projectile common data from the NBT compound; returns true if successful
bool LoadProjectileBaseFromNBT(cProjectileEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIx);