mirror of
https://git.neolegacy.dev/neoStudiosLCE/neoLegacy.git
synced 2026-11-20 12:36:42 +01:00
Co-authored-by: DrPerkyLegit <116128211+DrPerkyLegit@users.noreply.github.com> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Anaël <60509176+Bakoubak@users.noreply.github.com> Reviewed-on: https://git.neolegacy.dev/neoStudiosLCE/neoLegacy/pulls/4205
445 lines
12 KiB
C++
445 lines
12 KiB
C++
#include "stdafx.h"
|
|
#include "net.minecraft.world.item.enchantment.h"
|
|
#include "net.minecraft.world.item.h"
|
|
#include "Enchantment.h"
|
|
|
|
#include "WaterWalkerEnchantment.h"
|
|
#include "FrostWalkerEnchantment.h"
|
|
#include "MendingEnchantment.h"
|
|
#include "LuckOfTheSeaEnchantment.h"
|
|
#include "LureEnchantment.h"
|
|
|
|
//Enchantment *Enchantment::enchantments[256];
|
|
EnchantmentArray Enchantment::enchantments = EnchantmentArray( 256 );
|
|
vector<Enchantment *> Enchantment::validEnchantments;
|
|
|
|
Enchantment *Enchantment::allDamageProtection = nullptr;
|
|
Enchantment *Enchantment::fireProtection = nullptr;
|
|
Enchantment *Enchantment::fallProtection = nullptr;
|
|
Enchantment *Enchantment::explosionProtection = nullptr;
|
|
Enchantment *Enchantment::projectileProtection = nullptr;
|
|
Enchantment *Enchantment::drownProtection = nullptr;
|
|
Enchantment *Enchantment::waterWorker = nullptr;
|
|
Enchantment *Enchantment::waterWalker = nullptr;
|
|
Enchantment *Enchantment::frostWalker = nullptr;
|
|
Enchantment *Enchantment::thorns = nullptr;
|
|
|
|
// weapon
|
|
Enchantment *Enchantment::damageBonus = nullptr;
|
|
Enchantment *Enchantment::damageBonusUndead = nullptr;
|
|
Enchantment *Enchantment::damageBonusArthropods = nullptr;
|
|
Enchantment *Enchantment::knockback = nullptr;
|
|
Enchantment *Enchantment::fireAspect = nullptr;
|
|
Enchantment *Enchantment::lootBonus = nullptr;
|
|
|
|
// digger
|
|
Enchantment *Enchantment::diggingBonus = nullptr;
|
|
Enchantment *Enchantment::untouching = nullptr;
|
|
Enchantment *Enchantment::digDurability = nullptr;
|
|
Enchantment *Enchantment::resourceBonus = nullptr;
|
|
|
|
// bows
|
|
Enchantment *Enchantment::arrowBonus = nullptr;
|
|
Enchantment *Enchantment::arrowKnockback = nullptr;
|
|
Enchantment *Enchantment::arrowFire = nullptr;
|
|
Enchantment *Enchantment::arrowInfinite = nullptr;
|
|
|
|
// fishing rod
|
|
Enchantment *Enchantment::lure = nullptr;
|
|
Enchantment *Enchantment::luckOfTheSea = nullptr;
|
|
|
|
// misc / treasure
|
|
Enchantment *Enchantment::mending = nullptr;
|
|
|
|
void Enchantment::staticCtor()
|
|
{
|
|
allDamageProtection = new ProtectionEnchantment(0, FREQ_COMMON, ProtectionEnchantment::ALL);
|
|
fireProtection = new ProtectionEnchantment(1, FREQ_UNCOMMON, ProtectionEnchantment::FIRE);
|
|
fallProtection = new ProtectionEnchantment(2, FREQ_UNCOMMON, ProtectionEnchantment::FALL);
|
|
explosionProtection = new ProtectionEnchantment(3, FREQ_RARE, ProtectionEnchantment::EXPLOSION);
|
|
projectileProtection = new ProtectionEnchantment(4, FREQ_UNCOMMON, ProtectionEnchantment::PROJECTILE);
|
|
drownProtection = new OxygenEnchantment(5, FREQ_RARE);
|
|
waterWorker = new WaterWorkerEnchantment(6, FREQ_RARE);
|
|
waterWalker = new WaterWalkerEnchantment(8, FREQ_RARE);
|
|
frostWalker = new FrostWalkerEnchantment(9, FREQ_RARE);
|
|
thorns = new ThornsEnchantment(7, FREQ_VERY_RARE);
|
|
|
|
// weapon
|
|
damageBonus = new DamageEnchantment(16, FREQ_COMMON, DamageEnchantment::ALL);
|
|
damageBonusUndead = new DamageEnchantment(17, FREQ_UNCOMMON, DamageEnchantment::UNDEAD);
|
|
damageBonusArthropods = new DamageEnchantment(18, FREQ_UNCOMMON, DamageEnchantment::ARTHROPODS);
|
|
knockback = new KnockbackEnchantment(19, FREQ_UNCOMMON);
|
|
fireAspect = new FireAspectEnchantment(20, FREQ_RARE);
|
|
lootBonus = new LootBonusEnchantment(21, FREQ_RARE, EnchantmentCategory::weapon);
|
|
|
|
// digger
|
|
diggingBonus = new DiggingEnchantment(32, FREQ_COMMON);
|
|
untouching = new UntouchingEnchantment(33, FREQ_VERY_RARE);
|
|
digDurability = new DigDurabilityEnchantment(34, FREQ_UNCOMMON);
|
|
resourceBonus = new LootBonusEnchantment(35, FREQ_RARE, EnchantmentCategory::digger);
|
|
|
|
// bows
|
|
arrowBonus = new ArrowDamageEnchantment(48, FREQ_COMMON);
|
|
arrowKnockback = new ArrowKnockbackEnchantment(49, FREQ_RARE);
|
|
arrowFire = new ArrowFireEnchantment(50, FREQ_RARE);
|
|
arrowInfinite = new ArrowInfiniteEnchantment(51, FREQ_VERY_RARE);
|
|
|
|
// fishing rod
|
|
lure = new LureEnchantment(64, FREQ_RARE);
|
|
luckOfTheSea = new LuckOfTheSeaEnchantment(65, FREQ_RARE);
|
|
|
|
// misc / treasure
|
|
mending = new MendingEnchantment(70, FREQ_RARE);
|
|
|
|
for(unsigned int i = 0; i < 256; ++i)
|
|
{
|
|
Enchantment *enchantment = enchantments[i];
|
|
if (enchantment != nullptr && !enchantment->isTreasureOnly())
|
|
{
|
|
validEnchantments.push_back(enchantment);
|
|
}
|
|
}
|
|
}
|
|
|
|
void Enchantment::_init(int id)
|
|
{
|
|
if (enchantments[id] != nullptr)
|
|
{
|
|
app.DebugPrintf("Duplicate enchantment id!");
|
|
#ifndef _CONTENT_PACKAGE
|
|
DEBUG_BREAK();
|
|
#endif
|
|
//throw new IllegalArgumentException("Duplicate enchantment id!");
|
|
}
|
|
enchantments[id] = this;
|
|
}
|
|
|
|
Enchantment::Enchantment(int id, int frequency, const EnchantmentCategory *category) : id(id), frequency(frequency), category(category)
|
|
{
|
|
_init(id);
|
|
}
|
|
|
|
Enchantment::Enchantment(int id) : id(id), frequency(FREQ_COMMON), category(EnchantmentCategory::all)
|
|
{
|
|
_init(id);
|
|
}
|
|
|
|
int Enchantment::getFrequency()
|
|
{
|
|
return frequency;
|
|
}
|
|
|
|
int Enchantment::getMinLevel()
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
int Enchantment::getMaxLevel()
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
int Enchantment::getMinCost(int level)
|
|
{
|
|
return 1 + level * 10;
|
|
}
|
|
|
|
int Enchantment::getMaxCost(int level)
|
|
{
|
|
return getMinCost(level) + 5;
|
|
}
|
|
|
|
int Enchantment::getDamageProtection(int level, DamageSource *source)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
float Enchantment::getDamageBonus(int level, shared_ptr<LivingEntity> target)
|
|
{
|
|
return 0.0f;
|
|
}
|
|
|
|
bool Enchantment::isCompatibleWith(Enchantment *other) const
|
|
{
|
|
return this != other;
|
|
}
|
|
|
|
Enchantment *Enchantment::setDescriptionId(int id)
|
|
{
|
|
descriptionId = id;
|
|
return this;
|
|
}
|
|
|
|
int Enchantment::getDescriptionId()
|
|
{
|
|
return descriptionId;
|
|
}
|
|
|
|
HtmlString Enchantment::getFullname(int level)
|
|
{
|
|
wchar_t formatted[256];
|
|
swprintf(formatted, 256, L"%ls %ls", app.GetString(getDescriptionId()), getLevelString(level).c_str());
|
|
|
|
return HtmlString(formatted, eHTMLColor_f);
|
|
}
|
|
|
|
bool Enchantment::canEnchant(shared_ptr<ItemInstance> item)
|
|
{
|
|
return category->canEnchant(item->getItem());
|
|
}
|
|
|
|
std::wstring Enchantment::integerToRoman(int n)
|
|
{
|
|
// Arrays holding Roman numeral symbols and their respective values
|
|
std::wstring str_romans[] = {L"M", L"CM", L"D", L"CD", L"C", L"XC", L"L", L"XL", L"X", L"IX", L"V", L"IV", L"I"};
|
|
int values[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
|
|
|
|
std::wstring result = L"";
|
|
|
|
for (auto i = 0; i < 13; ++i)
|
|
{
|
|
while(n - values[i] >= 0)
|
|
{
|
|
result += str_romans[i];
|
|
n -= values[i];
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
// 4J Added
|
|
wstring Enchantment::getLevelString(int level)
|
|
{
|
|
return integerToRoman(level);
|
|
}
|
|
|
|
std::wstring Enchantment::getEnchantmentName(Enchantment *e, int level)
|
|
{
|
|
if (e == nullptr)
|
|
{
|
|
return L"Unknown";
|
|
}
|
|
std::wstring name = L"Enchantment";
|
|
if (e == Enchantment::allDamageProtection)
|
|
{
|
|
name = L"Protection";
|
|
}
|
|
else if (e == Enchantment::fireProtection)
|
|
{
|
|
name = L"Fire Protection";
|
|
}
|
|
else if (e == Enchantment::fallProtection)
|
|
{
|
|
name = L"Feather Falling";
|
|
}
|
|
else if (e == Enchantment::explosionProtection)
|
|
{
|
|
name = L"Blast Protection";
|
|
}
|
|
else if (e == Enchantment::projectileProtection)
|
|
{
|
|
name = L"Projectile Protection";
|
|
}
|
|
else if (e == Enchantment::damageBonus)
|
|
{
|
|
name = L"Sharpness";
|
|
}
|
|
else if (e == Enchantment::damageBonusUndead)
|
|
{
|
|
name = L"Smite";
|
|
}
|
|
else if (e == Enchantment::damageBonusArthropods)
|
|
{
|
|
name = L"Bane of Arthropods";
|
|
}
|
|
else if (e == Enchantment::knockback)
|
|
{
|
|
name = L"Knockback";
|
|
}
|
|
else if (e == Enchantment::fireAspect)
|
|
{
|
|
name = L"Fire Aspect";
|
|
}
|
|
else if (e == Enchantment::lootBonus)
|
|
{
|
|
name = L"Looting";
|
|
}
|
|
else if (e == Enchantment::diggingBonus)
|
|
{
|
|
name = L"Efficiency";
|
|
}
|
|
else if (e == Enchantment::untouching)
|
|
{
|
|
name = L"Silk Touch";
|
|
}
|
|
else if (e == Enchantment::digDurability)
|
|
{
|
|
name = L"Unbreaking";
|
|
}
|
|
else if (e == Enchantment::resourceBonus)
|
|
{
|
|
name = L"Fortune";
|
|
}
|
|
else if (e == Enchantment::arrowBonus)
|
|
{
|
|
name = L"Power";
|
|
}
|
|
else if (e == Enchantment::arrowKnockback)
|
|
{
|
|
name = L"Punch";
|
|
}
|
|
else if (e == Enchantment::arrowFire)
|
|
{
|
|
name = L"Flame";
|
|
}
|
|
else if (e == Enchantment::arrowInfinite)
|
|
{
|
|
name = L"Infinity";
|
|
}
|
|
else if (e == Enchantment::luckOfTheSea)
|
|
{
|
|
name = L"Luck of the Sea";
|
|
}
|
|
else if (e == Enchantment::lure)
|
|
{
|
|
name = L"Lure";
|
|
}
|
|
else if (e == Enchantment::mending)
|
|
{
|
|
name = L"Mending";
|
|
}
|
|
else if (e == Enchantment::frostWalker)
|
|
{
|
|
name = L"Frost Walker";
|
|
}
|
|
std::wstring levelStr = e->getLevelString(level);
|
|
return name + (levelStr.empty() ? L"" : L" " + levelStr);
|
|
}
|
|
|
|
int Enchantment::getEnchantmentIdByCanonicalName(const std::wstring &name)
|
|
{
|
|
std::wstring lower = name;
|
|
for (auto &c : lower)
|
|
{
|
|
c = towlower(c);
|
|
}
|
|
|
|
// clean up the minecraft: prefix (i don't know if it should be done here or in PlayerConnection.cpp, i'll leave that here i guess)
|
|
if (lower.find(L"minecraft:") == 0)
|
|
{
|
|
lower = lower.substr(10);
|
|
}
|
|
|
|
if (lower == L"protection")
|
|
{
|
|
return Enchantment::allDamageProtection ? Enchantment::allDamageProtection->id : 0;
|
|
}
|
|
if (lower == L"fire_protection")
|
|
{
|
|
return Enchantment::fireProtection ? Enchantment::fireProtection->id : 1;
|
|
}
|
|
if (lower == L"feather_falling")
|
|
{
|
|
return Enchantment::fallProtection ? Enchantment::fallProtection->id : 2;
|
|
}
|
|
if (lower == L"blast_protection")
|
|
{
|
|
return Enchantment::explosionProtection ? Enchantment::explosionProtection->id : 3;
|
|
}
|
|
if (lower == L"projectile_protection")
|
|
{
|
|
return Enchantment::projectileProtection ? Enchantment::projectileProtection->id : 4;
|
|
}
|
|
if (lower == L"respiration")
|
|
{
|
|
return Enchantment::drownProtection ? Enchantment::drownProtection->id : 5;
|
|
}
|
|
if (lower == L"aqua_affinity")
|
|
{
|
|
return Enchantment::waterWorker ? Enchantment::waterWorker->id : 6;
|
|
}
|
|
if (lower == L"thorns")
|
|
{
|
|
return Enchantment::thorns ? Enchantment::thorns->id : 7;
|
|
}
|
|
if (lower == L"depth_strider")
|
|
{
|
|
return Enchantment::waterWalker ? Enchantment::waterWalker->id : 8;
|
|
}
|
|
if (lower == L"frost_walker")
|
|
{
|
|
return Enchantment::frostWalker ? Enchantment::frostWalker->id : 9;
|
|
}
|
|
if (lower == L"sharpness")
|
|
{
|
|
return Enchantment::damageBonus ? Enchantment::damageBonus->id : 16;
|
|
}
|
|
if (lower == L"smite")
|
|
{
|
|
return Enchantment::damageBonusUndead ? Enchantment::damageBonusUndead->id : 17;
|
|
}
|
|
if (lower == L"bane_of_arthropods")
|
|
{
|
|
return Enchantment::damageBonusArthropods ? Enchantment::damageBonusArthropods->id : 18;
|
|
}
|
|
if (lower == L"knockback")
|
|
{
|
|
return Enchantment::knockback ? Enchantment::knockback->id : 19;
|
|
}
|
|
if (lower == L"fire_aspect")
|
|
{
|
|
return Enchantment::fireAspect ? Enchantment::fireAspect->id : 20;
|
|
}
|
|
if (lower == L"looting")
|
|
{
|
|
return Enchantment::lootBonus ? Enchantment::lootBonus->id : 21;
|
|
}
|
|
if (lower == L"efficiency")
|
|
{
|
|
return Enchantment::diggingBonus ? Enchantment::diggingBonus->id : 32;
|
|
}
|
|
if (lower == L"silk_touch")
|
|
{
|
|
return Enchantment::untouching ? Enchantment::untouching->id : 33;
|
|
}
|
|
if (lower == L"unbreaking")
|
|
{
|
|
return Enchantment::digDurability ? Enchantment::digDurability->id : 34;
|
|
}
|
|
if (lower == L"fortune")
|
|
{
|
|
return Enchantment::resourceBonus ? Enchantment::resourceBonus->id : 35;
|
|
}
|
|
if (lower == L"power")
|
|
{
|
|
return Enchantment::arrowBonus ? Enchantment::arrowBonus->id : 48;
|
|
}
|
|
if (lower == L"punch")
|
|
{
|
|
return Enchantment::arrowKnockback ? Enchantment::arrowKnockback->id : 49;
|
|
}
|
|
if (lower == L"flame")
|
|
{
|
|
return Enchantment::arrowFire ? Enchantment::arrowFire->id : 50;
|
|
}
|
|
if (lower == L"infinity")
|
|
{
|
|
return Enchantment::arrowInfinite ? Enchantment::arrowInfinite->id : 51;
|
|
}
|
|
if (lower == L"luck_of_the_sea")
|
|
{
|
|
return Enchantment::luckOfTheSea ? Enchantment::luckOfTheSea->id : 61;
|
|
}
|
|
if (lower == L"lure")
|
|
{
|
|
return Enchantment::lure ? Enchantment::lure->id : 62;
|
|
}
|
|
if (lower == L"mending")
|
|
{
|
|
return Enchantment::mending ? Enchantment::mending->id : 70;
|
|
}
|
|
|
|
return -1;
|
|
}
|