1
0
Fork 0
cuberite-2a/src/Mobs/Slime.cpp

107 lines
1.7 KiB
C++
Raw Normal View History

#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Slime.h"
#include "../FastRandom.h"
#include "../World.h"
cSlime::cSlime(int a_Size) :
2020-04-13 16:38:06 +00:00
Super("Slime",
2014-07-17 21:32:01 +00:00
mtSlime,
2017-02-15 05:05:24 +00:00
Printf("entity.%sslime.hurt", GetSizeName(a_Size).c_str()),
Printf("entity.%sslime.death", GetSizeName(a_Size).c_str()),
2020-03-22 15:50:34 +00:00
"",
2021-04-06 15:09:16 +00:00
0.51f * a_Size,
0.51f * a_Size
2014-07-17 21:32:01 +00:00
),
m_Size(a_Size)
{
2019-09-27 15:51:44 +00:00
SetMaxHealth(static_cast<float>(a_Size * a_Size));
SetAttackDamage(a_Size);
}
void cSlime::GetDrops(cItems & a_Drops, cEntity * a_Killer)
{
unsigned int LootingLevel = 0;
2014-10-20 20:55:07 +00:00
if (a_Killer != nullptr)
{
LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting);
}
// Only slimes with the size 1 can drop slimeballs.
if (m_Size == 1)
{
AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SLIMEBALL);
}
}
fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'master' into cavespider-attack fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack
2015-11-08 12:44:17 +00:00
bool cSlime::Attack(std::chrono::milliseconds a_Dt)
{
2014-07-18 21:20:42 +00:00
if (m_Size > 1)
{
2014-07-18 21:20:42 +00:00
// Only slimes larger than size 1 attack a player.
2020-04-13 16:38:06 +00:00
return Super::Attack(a_Dt);
}
2016-02-05 21:45:45 +00:00
fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'master' into cavespider-attack fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack
2015-11-08 12:44:17 +00:00
return false;
}
void cSlime::KilledBy(TakeDamageInfo & a_TDI)
{
if (GetHealth() > 0)
{
return;
}
if (m_Size != 1)
{
2017-06-13 19:35:30 +00:00
auto & Random = GetRandomProvider();
int SpawnAmount = Random.RandInt(2, 4);
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;
auto NewSlime = std::make_unique<cSlime>(m_Size / 2);
NewSlime->SetPosition(GetPosX() + AddX, GetPosY() + 0.5, GetPosZ() + AddZ);
2017-06-13 19:35:30 +00:00
NewSlime->SetYaw(Random.RandReal(360.0f));
m_World->SpawnMobFinalize(std::move(NewSlime));
}
}
2020-04-13 16:38:06 +00:00
Super::KilledBy(a_TDI);
}
AString cSlime::GetSizeName(int a_Size)
{
2017-02-15 05:05:24 +00:00
if (a_Size == 1)
{
2017-02-15 05:05:24 +00:00
return "small_";
}
2017-02-15 05:05:24 +00:00
return "";
}