2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2012-09-23 16:53:08 -04:00
|
|
|
#include "Slime.h"
|
2014-07-17 16:32:23 -04:00
|
|
|
#include "FastRandom.h"
|
|
|
|
#include "World.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-01 06:39:56 -04:00
|
|
|
cSlime::cSlime(int a_Size) :
|
2014-07-17 17:32:01 -04:00
|
|
|
super("Slime",
|
|
|
|
mtSlime,
|
|
|
|
Printf("mob.slime.%s", GetSizeName(a_Size).c_str()),
|
|
|
|
Printf("mob.slime.%s", GetSizeName(a_Size).c_str()),
|
|
|
|
0.6 * a_Size,
|
|
|
|
0.6 * a_Size
|
|
|
|
),
|
2013-07-01 06:39:56 -04:00
|
|
|
m_Size(a_Size)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-07-17 16:32:23 -04:00
|
|
|
SetMaxHealth(a_Size * a_Size);
|
|
|
|
SetAttackDamage(a_Size);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-01 06:39:56 -04:00
|
|
|
void cSlime::GetDrops(cItems & a_Drops, cEntity * a_Killer)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2015-05-19 14:32:10 -04:00
|
|
|
unsigned int LootingLevel = 0;
|
2014-10-20 16:55:07 -04:00
|
|
|
if (a_Killer != nullptr)
|
2014-02-23 13:44:58 -05:00
|
|
|
{
|
|
|
|
LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting);
|
|
|
|
}
|
2014-07-17 16:32:23 -04:00
|
|
|
|
2014-07-18 10:55:28 -04:00
|
|
|
// Only slimes with the size 1 can drop slimeballs.
|
|
|
|
if (m_Size == 1)
|
2014-02-23 13:44:58 -05:00
|
|
|
{
|
|
|
|
AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SLIMEBALL);
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 16:32:23 -04:00
|
|
|
|
2015-11-08 07:44:17 -05:00
|
|
|
bool cSlime::Attack(std::chrono::milliseconds a_Dt)
|
2014-07-17 16:32:23 -04:00
|
|
|
{
|
2014-07-18 17:20:42 -04:00
|
|
|
if (m_Size > 1)
|
2014-07-17 16:32:23 -04:00
|
|
|
{
|
2014-07-18 17:20:42 -04:00
|
|
|
// Only slimes larger than size 1 attack a player.
|
2015-11-08 07:44:17 -05:00
|
|
|
return super::Attack(a_Dt);
|
2014-07-17 16:32:23 -04:00
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-11-08 07:44:17 -05:00
|
|
|
return false;
|
2014-07-17 16:32:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cSlime::KilledBy(TakeDamageInfo & a_TDI)
|
|
|
|
{
|
|
|
|
if (GetHealth() > 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_Size != 1)
|
|
|
|
{
|
|
|
|
cFastRandom Random;
|
|
|
|
int SpawnAmount = 2 + Random.NextInt(3);
|
|
|
|
|
|
|
|
for (int i = 0; i < SpawnAmount; ++i)
|
|
|
|
{
|
|
|
|
double AddX = (i % 2 - 0.5) * m_Size / 4.0;
|
|
|
|
double AddZ = (i / 2 - 0.5) * m_Size / 4.0;
|
|
|
|
|
|
|
|
cSlime * NewSlime = new cSlime(m_Size / 2);
|
|
|
|
NewSlime->SetPosition(GetPosX() + AddX, GetPosY() + 0.5, GetPosZ() + AddZ);
|
2014-07-17 17:32:01 -04:00
|
|
|
NewSlime->SetYaw(Random.NextFloat(1.0f) * 360.0f);
|
2014-07-17 16:32:23 -04:00
|
|
|
m_World->SpawnMobFinalize(NewSlime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
super::KilledBy(a_TDI);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-08 20:50:05 -04:00
|
|
|
AString cSlime::GetSizeName(int a_Size)
|
2014-07-17 16:32:23 -04:00
|
|
|
{
|
|
|
|
if (a_Size > 1)
|
|
|
|
{
|
|
|
|
return "big";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return "small";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|