Readability and clarity changes
This commit is contained in:
parent
554e1c0dd3
commit
061010288a
@ -311,11 +311,14 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
|
|||||||
|
|
||||||
// IsOnGround() only is false if the player is moving downwards
|
// IsOnGround() only is false if the player is moving downwards
|
||||||
// TODO: Better damage increase, and check for enchantments (and use magic critical instead of plain)
|
// TODO: Better damage increase, and check for enchantments (and use magic critical instead of plain)
|
||||||
if (!Player->IsOnGround() && (a_TDI.DamageType == dtAttack || a_TDI.DamageType == dtArrowAttack))
|
if (!Player->IsOnGround())
|
||||||
|
{
|
||||||
|
if ((a_TDI.DamageType == dtAttack) || (a_TDI.DamageType == dtArrowAttack))
|
||||||
{
|
{
|
||||||
a_TDI.FinalDamage += 2;
|
a_TDI.FinalDamage += 2;
|
||||||
m_World->BroadcastEntityAnimation(*this, 4); // Critical hit
|
m_World->BroadcastEntityAnimation(*this, 4); // Critical hit
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Player->GetStatManager().AddValue(statDamageDealt, (StatValue)floor(a_TDI.FinalDamage * 10 + 0.5));
|
Player->GetStatManager().AddValue(statDamageDealt, (StatValue)floor(a_TDI.FinalDamage * 10 + 0.5));
|
||||||
}
|
}
|
||||||
|
@ -113,16 +113,13 @@ void cEntityEffect::OnTick(cPawn & a_Target)
|
|||||||
void cEntityEffectInstantHealth::OnActivate(cPawn & a_Target)
|
void cEntityEffectInstantHealth::OnActivate(cPawn & a_Target)
|
||||||
{
|
{
|
||||||
// Base amount = 6, doubles for every increase in intensity
|
// Base amount = 6, doubles for every increase in intensity
|
||||||
int amount = (int)(6 * std::pow(2.0, m_Intensity) * m_DistanceModifier);
|
int amount = (int)(6 * (1 << m_Intensity) * m_DistanceModifier);
|
||||||
|
|
||||||
if (a_Target.IsMob())
|
if (a_Target.IsMob() && ((cMonster &) a_Target).IsUndead())
|
||||||
{
|
|
||||||
if (((cMonster &) a_Target).IsUndead())
|
|
||||||
{
|
{
|
||||||
a_Target.TakeDamage(dtPotionOfHarming, NULL, amount, 0); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage
|
a_Target.TakeDamage(dtPotionOfHarming, NULL, amount, 0); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
a_Target.Heal(amount);
|
a_Target.Heal(amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,16 +133,13 @@ void cEntityEffectInstantHealth::OnActivate(cPawn & a_Target)
|
|||||||
void cEntityEffectInstantDamage::OnActivate(cPawn & a_Target)
|
void cEntityEffectInstantDamage::OnActivate(cPawn & a_Target)
|
||||||
{
|
{
|
||||||
// Base amount = 6, doubles for every increase in intensity
|
// Base amount = 6, doubles for every increase in intensity
|
||||||
int amount = (int)(6 * std::pow(2.0, m_Intensity) * m_DistanceModifier);
|
int amount = (int)(6 * (1 << m_Intensity) * m_DistanceModifier);
|
||||||
|
|
||||||
if (a_Target.IsMob())
|
if (a_Target.IsMob() && ((cMonster &) a_Target).IsUndead())
|
||||||
{
|
|
||||||
if (((cMonster &) a_Target).IsUndead())
|
|
||||||
{
|
{
|
||||||
a_Target.Heal(amount);
|
a_Target.Heal(amount);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
a_Target.TakeDamage(dtPotionOfHarming, NULL, amount, 0); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage
|
a_Target.TakeDamage(dtPotionOfHarming, NULL, amount, 0); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,18 +154,15 @@ void cEntityEffectRegeneration::OnTick(cPawn & a_Target)
|
|||||||
{
|
{
|
||||||
super::OnTick(a_Target);
|
super::OnTick(a_Target);
|
||||||
|
|
||||||
if (a_Target.IsMob())
|
if (a_Target.IsMob() && ((cMonster &) a_Target).IsUndead())
|
||||||
{
|
|
||||||
if (((cMonster &) a_Target).IsUndead())
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Regen frequency = 50 ticks, divided by potion level (Regen II = 25 ticks)
|
// Regen frequency = 50 ticks, divided by potion level (Regen II = 25 ticks)
|
||||||
int frequency = (int) std::floor(50.0 / (double)(m_Intensity + 1));
|
int frequency = (int) std::floor(50.0 / (double)(m_Intensity + 1));
|
||||||
|
|
||||||
if (m_Ticks % frequency != 0)
|
if ((m_Ticks % frequency) != 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -231,9 +222,9 @@ void cEntityEffectPoison::OnTick(cPawn & a_Target)
|
|||||||
cMonster & Target = (cMonster &) a_Target;
|
cMonster & Target = (cMonster &) a_Target;
|
||||||
|
|
||||||
// Doesn't effect undead mobs, spiders
|
// Doesn't effect undead mobs, spiders
|
||||||
if (Target.IsUndead()
|
if ((Target.IsUndead())
|
||||||
|| Target.GetMobType() == cMonster::mtSpider
|
|| (Target.GetMobType() == cMonster::mtSpider)
|
||||||
|| Target.GetMobType() == cMonster::mtCaveSpider)
|
|| (Target.GetMobType() == cMonster::mtCaveSpider))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -242,7 +233,7 @@ void cEntityEffectPoison::OnTick(cPawn & a_Target)
|
|||||||
// Poison frequency = 25 ticks, divided by potion level (Poison II = 12 ticks)
|
// Poison frequency = 25 ticks, divided by potion level (Poison II = 12 ticks)
|
||||||
int frequency = (int) std::floor(25.0 / (double)(m_Intensity + 1));
|
int frequency = (int) std::floor(25.0 / (double)(m_Intensity + 1));
|
||||||
|
|
||||||
if (m_Ticks % frequency == 0)
|
if ((m_Ticks % frequency) == 0)
|
||||||
{
|
{
|
||||||
// Cannot take poison damage when health is at 1
|
// Cannot take poison damage when health is at 1
|
||||||
if (a_Target.GetHealth() > 1)
|
if (a_Target.GetHealth() > 1)
|
||||||
@ -266,7 +257,7 @@ void cEntityEffectWither::OnTick(cPawn & a_Target)
|
|||||||
// Poison frequency = 40 ticks, divided by effect level (Wither II = 20 ticks)
|
// Poison frequency = 40 ticks, divided by effect level (Wither II = 20 ticks)
|
||||||
int frequency = (int) std::floor(25.0 / (double)(m_Intensity + 1));
|
int frequency = (int) std::floor(25.0 / (double)(m_Intensity + 1));
|
||||||
|
|
||||||
if (m_Ticks % frequency == 0)
|
if ((m_Ticks % frequency) == 0)
|
||||||
{
|
{
|
||||||
a_Target.TakeDamage(dtWither, NULL, 1, 0);
|
a_Target.TakeDamage(dtWither, NULL, 1, 0);
|
||||||
}
|
}
|
||||||
|
@ -11,33 +11,35 @@ class cItemPotionHandler:
|
|||||||
|
|
||||||
int GetPotionName(short a_ItemDamage)
|
int GetPotionName(short a_ItemDamage)
|
||||||
{
|
{
|
||||||
return a_ItemDamage & 63;
|
// First six bits (least significant)
|
||||||
|
return a_ItemDamage & 0x3F;
|
||||||
}
|
}
|
||||||
|
|
||||||
cEntityEffect::eType GetEntityEffectType(short a_ItemDamage)
|
cEntityEffect::eType GetEntityEffectType(short a_ItemDamage)
|
||||||
{
|
{
|
||||||
|
// First four bits (least significant)
|
||||||
// Potion effect bits are different from entity effect values
|
// Potion effect bits are different from entity effect values
|
||||||
// For reference: http://minecraft.gamepedia.com/Data_values#.22Potion_effect.22_bits
|
// For reference: http://minecraft.gamepedia.com/Data_values#.22Potion_effect.22_bits
|
||||||
switch (a_ItemDamage & 15)
|
switch (a_ItemDamage & 0xF)
|
||||||
{
|
{
|
||||||
case 1: return cEntityEffect::effRegeneration;
|
case 0x1: return cEntityEffect::effRegeneration;
|
||||||
case 2: return cEntityEffect::effSpeed;
|
case 0x2: return cEntityEffect::effSpeed;
|
||||||
case 3: return cEntityEffect::effFireResistance;
|
case 0x3: return cEntityEffect::effFireResistance;
|
||||||
case 4: return cEntityEffect::effPoison;
|
case 0x4: return cEntityEffect::effPoison;
|
||||||
case 5: return cEntityEffect::effInstantHealth;
|
case 0x5: return cEntityEffect::effInstantHealth;
|
||||||
case 6: return cEntityEffect::effNightVision;
|
case 0x6: return cEntityEffect::effNightVision;
|
||||||
case 8: return cEntityEffect::effWeakness;
|
case 0x8: return cEntityEffect::effWeakness;
|
||||||
case 9: return cEntityEffect::effStrength;
|
case 0x9: return cEntityEffect::effStrength;
|
||||||
case 10: return cEntityEffect::effSlowness;
|
case 0xA: return cEntityEffect::effSlowness;
|
||||||
case 12: return cEntityEffect::effInstantDamage;
|
case 0xC: return cEntityEffect::effInstantDamage;
|
||||||
case 13: return cEntityEffect::effWaterBreathing;
|
case 0xD: return cEntityEffect::effWaterBreathing;
|
||||||
case 14: return cEntityEffect::effInvisibility;
|
case 0xE: return cEntityEffect::effInvisibility;
|
||||||
|
|
||||||
// No effect potions
|
// No effect potions
|
||||||
case 0:
|
case 0x0:
|
||||||
case 7:
|
case 0x7:
|
||||||
case 11:
|
case 0xB: // Will be potion of leaping in 1.8
|
||||||
case 15:
|
case 0xF:
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -48,9 +50,8 @@ class cItemPotionHandler:
|
|||||||
|
|
||||||
short GetEntityEffectIntensity(short a_ItemDamage)
|
short GetEntityEffectIntensity(short a_ItemDamage)
|
||||||
{
|
{
|
||||||
// Level II potion if fifth bit is set
|
// Level II potion if fifth bit (from zero) is set
|
||||||
if (a_ItemDamage & 32) return 1;
|
return (a_ItemDamage & 0x20) ? 1 : 0;
|
||||||
else return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetEntityEffectDuration(short a_ItemDamage)
|
int GetEntityEffectDuration(short a_ItemDamage)
|
||||||
@ -91,8 +92,8 @@ class cItemPotionHandler:
|
|||||||
TierCoeff = (GetEntityEffectIntensity(a_ItemDamage) > 0) ? 0.5 : 1;
|
TierCoeff = (GetEntityEffectIntensity(a_ItemDamage) > 0) ? 0.5 : 1;
|
||||||
|
|
||||||
// If potion is extended, multiply duration by 8/3. If not, stays the same
|
// If potion is extended, multiply duration by 8/3. If not, stays the same
|
||||||
// Extended potion if sixth bit is set
|
// Extended potion if sixth bit (from zero) is set
|
||||||
ExtCoeff = (a_ItemDamage & 64) ? (8.0/3.0) : 1;
|
ExtCoeff = (a_ItemDamage & 0x40) ? (8.0/3.0) : 1;
|
||||||
|
|
||||||
// If potion is splash potion, multiply duration by 3/4. If not, stays the same
|
// If potion is splash potion, multiply duration by 3/4. If not, stays the same
|
||||||
SplashCoeff = IsDrinkable(a_ItemDamage) ? 1 : 0.75;
|
SplashCoeff = IsDrinkable(a_ItemDamage) ? 1 : 0.75;
|
||||||
@ -112,18 +113,26 @@ public:
|
|||||||
|
|
||||||
virtual bool IsDrinkable(short a_ItemDamage) override
|
virtual bool IsDrinkable(short a_ItemDamage) override
|
||||||
{
|
{
|
||||||
// Drinkable potion if 13th bit is set
|
// Drinkable potion if 13th bit (from zero) is set
|
||||||
// For reference: http://minecraft.gamepedia.com/Potions#Data_value_table
|
// For reference: http://minecraft.gamepedia.com/Potions#Data_value_table
|
||||||
return ((a_ItemDamage & 8192) != 0);
|
return ((a_ItemDamage & 0x2000) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override
|
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override
|
||||||
{
|
{
|
||||||
|
short PotionDamage = a_Item.m_ItemDamage;
|
||||||
|
|
||||||
|
// Only called when potion is a splash potion
|
||||||
|
if (IsDrinkable(PotionDamage))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Vector3d Pos = a_Player->GetThrowStartPos();
|
Vector3d Pos = a_Player->GetThrowStartPos();
|
||||||
Vector3d Speed = a_Player->GetLookVector() * 7;
|
Vector3d Speed = a_Player->GetLookVector() * 7;
|
||||||
|
|
||||||
short potion_damage = a_Item.m_ItemDamage;
|
cSplashPotionEntity *Projectile = new cSplashPotionEntity(a_Player, Pos.x, Pos.y, Pos.z, &Speed, GetEntityEffectType(PotionDamage), cEntityEffect(GetEntityEffectDuration(PotionDamage), GetEntityEffectIntensity(PotionDamage)), GetPotionName(PotionDamage));
|
||||||
cSplashPotionEntity *Projectile = new cSplashPotionEntity(a_Player, Pos.x, Pos.y, Pos.z, &Speed, GetEntityEffectType(potion_damage), cEntityEffect(GetEntityEffectDuration(potion_damage), GetEntityEffectIntensity(potion_damage)), GetPotionName(potion_damage));
|
|
||||||
if (Projectile == NULL)
|
if (Projectile == NULL)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@ -139,14 +148,20 @@ public:
|
|||||||
a_Player->GetInventory().RemoveOneEquippedItem();
|
a_Player->GetInventory().RemoveOneEquippedItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when potion is a splash potion
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
|
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
|
||||||
{
|
{
|
||||||
// Called when potion is a drinkable potion
|
short PotionDamage = a_Item->m_ItemDamage;
|
||||||
a_Player->AddEntityEffect(GetEntityEffectType(a_Item->m_ItemDamage), GetEntityEffectDuration(a_Item->m_ItemDamage), GetEntityEffectIntensity(a_Item->m_ItemDamage));
|
|
||||||
|
// Only called when potion is a drinkable potion
|
||||||
|
if (!IsDrinkable(a_Item->m_ItemDamage))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
a_Player->AddEntityEffect(GetEntityEffectType(PotionDamage), GetEntityEffectDuration(PotionDamage), GetEntityEffectIntensity(PotionDamage));
|
||||||
a_Player->GetInventory().RemoveOneEquippedItem();
|
a_Player->GetInventory().RemoveOneEquippedItem();
|
||||||
a_Player->GetInventory().AddItem(E_ITEM_GLASS_BOTTLE);
|
a_Player->GetInventory().AddItem(E_ITEM_GLASS_BOTTLE);
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user