2014-06-07 19:32:37 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../Entities/EntityEffects.h"
|
2014-06-08 00:56:01 -04:00
|
|
|
#include "../Entities/SplashPotionEntity.h"
|
2014-06-07 19:32:37 -04:00
|
|
|
|
|
|
|
class cItemPotionHandler:
|
2014-06-08 00:56:01 -04:00
|
|
|
public cItemHandler
|
2014-06-07 19:32:37 -04:00
|
|
|
{
|
|
|
|
typedef cItemHandler super;
|
|
|
|
|
2014-06-08 00:56:01 -04:00
|
|
|
int GetPotionName(short a_ItemDamage)
|
|
|
|
{
|
|
|
|
return a_ItemDamage & 63;
|
|
|
|
}
|
|
|
|
|
2014-06-07 19:32:37 -04:00
|
|
|
cEntityEffect::eType GetEntityEffectType(short a_ItemDamage)
|
|
|
|
{
|
|
|
|
// Potion effect bits are different from entity effect values
|
|
|
|
// For reference: http://minecraft.gamepedia.com/Data_values#.22Potion_effect.22_bits
|
|
|
|
switch (a_ItemDamage & 15)
|
|
|
|
{
|
2014-06-08 06:27:22 -04:00
|
|
|
case 1: return cEntityEffect::effRegeneration;
|
|
|
|
case 2: return cEntityEffect::effSpeed;
|
|
|
|
case 3: return cEntityEffect::effFireResistance;
|
|
|
|
case 4: return cEntityEffect::effPoison;
|
|
|
|
case 5: return cEntityEffect::effInstantHealth;
|
|
|
|
case 6: return cEntityEffect::effNightVision;
|
|
|
|
case 8: return cEntityEffect::effWeakness;
|
|
|
|
case 9: return cEntityEffect::effStrength;
|
|
|
|
case 10: return cEntityEffect::effSlowness;
|
|
|
|
case 12: return cEntityEffect::effInstantDamage;
|
|
|
|
case 13: return cEntityEffect::effWaterBreathing;
|
|
|
|
case 14: return cEntityEffect::effInvisibility;
|
2014-06-07 19:32:37 -04:00
|
|
|
|
|
|
|
// No effect potions
|
|
|
|
case 0:
|
|
|
|
case 7:
|
|
|
|
case 11:
|
|
|
|
case 15:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-08 06:27:22 -04:00
|
|
|
return cEntityEffect::effNoEffect;
|
2014-06-07 19:32:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
short GetEntityEffectIntensity(short a_ItemDamage)
|
|
|
|
{
|
|
|
|
// Level II potion if fifth bit is set
|
|
|
|
if (a_ItemDamage & 32) return 1;
|
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetEntityEffectDuration(short a_ItemDamage)
|
|
|
|
{
|
|
|
|
// Base duration in ticks
|
|
|
|
int base = 0;
|
|
|
|
double tier_multi = 1, ext_multi = 1, splash_multi = 1;
|
|
|
|
|
|
|
|
switch (GetEntityEffectType(a_ItemDamage))
|
|
|
|
{
|
2014-06-08 06:27:22 -04:00
|
|
|
case cEntityEffect::effRegeneration:
|
|
|
|
case cEntityEffect::effPoison:
|
2014-06-07 19:32:37 -04:00
|
|
|
{
|
|
|
|
base = 900;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-06-08 06:27:22 -04:00
|
|
|
case cEntityEffect::effSpeed:
|
|
|
|
case cEntityEffect::effFireResistance:
|
|
|
|
case cEntityEffect::effNightVision:
|
|
|
|
case cEntityEffect::effStrength:
|
|
|
|
case cEntityEffect::effWaterBreathing:
|
|
|
|
case cEntityEffect::effInvisibility:
|
2014-06-07 19:32:37 -04:00
|
|
|
{
|
|
|
|
base = 3600;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-06-08 06:27:22 -04:00
|
|
|
case cEntityEffect::effWeakness:
|
|
|
|
case cEntityEffect::effSlowness:
|
2014-06-07 19:32:37 -04:00
|
|
|
{
|
|
|
|
base = 1800;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If potion is level 2, half the duration. If not, stays the same
|
|
|
|
tier_multi = GetEntityEffectIntensity(a_ItemDamage) > 0 ? 0.5 : 1;
|
|
|
|
|
|
|
|
// If potion is extended, multiply duration by 8/3. If not, stays the same
|
|
|
|
// Extended potion if sixth bit is set
|
|
|
|
ext_multi = a_ItemDamage & 64 ? (8.0/3.0) : 1;
|
|
|
|
|
|
|
|
// If potion is splash potion, multiply duration by 3/4. If not, stays the same
|
|
|
|
splash_multi = !IsDrinkable(a_ItemDamage) ? 0.75 : 1;
|
|
|
|
|
|
|
|
// For reference: http://minecraft.gamepedia.com/Data_values#.22Tier.22_bit
|
|
|
|
// http://minecraft.gamepedia.com/Data_values#.22Extended_duration.22_bit
|
|
|
|
// http://minecraft.gamepedia.com/Data_values#.22Splash_potion.22_bit
|
|
|
|
|
|
|
|
return base * tier_multi * ext_multi * splash_multi;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsDrinkable(short a_ItemDamage)
|
|
|
|
{
|
|
|
|
// Drinkable potion if 13th bit is set
|
|
|
|
// For reference: http://minecraft.gamepedia.com/Potions#Data_value_table
|
|
|
|
return a_ItemDamage & 8192;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
cItemPotionHandler():
|
|
|
|
super(E_ITEM_POTIONS)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool IsDrinkable(const cItem * a_Item) override
|
|
|
|
{
|
|
|
|
return IsDrinkable(a_Item->m_ItemDamage);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2014-06-08 00:56:01 -04:00
|
|
|
Vector3d Speed = a_Player->GetLookVector() * 10;
|
|
|
|
|
|
|
|
short potion_damage = a_Item.m_ItemDamage;
|
2014-06-08 06:27:22 -04:00
|
|
|
cSplashPotionEntity * Projectile = new cSplashPotionEntity(a_Player,
|
|
|
|
(double)a_BlockX,
|
|
|
|
(double)a_BlockY,
|
|
|
|
(double)a_BlockZ,
|
|
|
|
&Speed,
|
|
|
|
GetEntityEffectType(potion_damage),
|
|
|
|
cEntityEffect(GetEntityEffectDuration(potion_damage),
|
|
|
|
GetEntityEffectIntensity(potion_damage),
|
|
|
|
a_Player),
|
|
|
|
GetPotionName(potion_damage));
|
2014-06-08 00:56:01 -04:00
|
|
|
if (Projectile == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!Projectile->Initialize(*a_World))
|
|
|
|
{
|
|
|
|
delete Projectile;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!a_Player->IsGameModeCreative())
|
|
|
|
{
|
|
|
|
a_Player->GetInventory().RemoveOneEquippedItem();
|
|
|
|
}
|
|
|
|
|
2014-06-07 19:32:37 -04:00
|
|
|
// Called when potion is a splash potion
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
|
|
|
|
{
|
|
|
|
// Called when potion is a drinkable potion
|
|
|
|
short potion_damage = a_Item->m_ItemDamage;
|
|
|
|
a_Player->AddEntityEffect(GetEntityEffectType(potion_damage),
|
|
|
|
cEntityEffect(GetEntityEffectDuration(potion_damage),
|
|
|
|
GetEntityEffectIntensity(potion_damage),
|
|
|
|
a_Player));
|
|
|
|
a_Player->GetInventory().RemoveOneEquippedItem();
|
|
|
|
a_Player->GetInventory().AddItem(E_ITEM_GLASS_BOTTLE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|