mirror of
https://github.com/neoStudiosLCE/neoLegacy.git
synced 2026-08-20 09:57:09 +00:00
Use Java 1.12 source code for loot table, clean up code.
This commit is contained in:
parent
c5a8e8b786
commit
97a82c20ef
|
|
@ -13,46 +13,31 @@ FishingHelper* FishingHelper::getInstance()
|
||||||
return &instance;
|
return &instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
FishingHelper::FishingHelper() :
|
FishingHelper::FishingHelper() : catchTypeArray(3), fishingFishArray(4), fishingJunkArray(12), fishingTreasuresArray(5)
|
||||||
random(new Random()), level0Array(3), level1Array(3), level2Array(3), level3Array(3),
|
|
||||||
fishingFishArray(4), fishingJunkArray(12), fishingTreasuresArray(5)
|
|
||||||
{
|
{
|
||||||
|
// Source: https://github.com/WangTingZheng/mcp940/tree/master/src/minecraft/assets/minecraft/loot_tables/gameplay
|
||||||
// Source: https://minecraft.wiki/w/Fishing
|
catchTypeArray[0] = new CatchTypeWeighedItem(CatchType::JUNK, -2, 10 );
|
||||||
level0Array[0] = new CatchTypeWeighedItem(CatchType::JUNK, 10 );
|
catchTypeArray[1] = new CatchTypeWeighedItem(CatchType::TREASURE, 2, 5 );
|
||||||
level0Array[1] = new CatchTypeWeighedItem(CatchType::TREASURE, 5 );
|
catchTypeArray[2] = new CatchTypeWeighedItem(CatchType::FISH, -1, 85);
|
||||||
level0Array[2] = new CatchTypeWeighedItem(CatchType::FISH, 85 );
|
|
||||||
|
|
||||||
level1Array[0] = new CatchTypeWeighedItem(CatchType::JUNK, 81 );
|
|
||||||
level1Array[1] = new CatchTypeWeighedItem(CatchType::TREASURE, 71 );
|
|
||||||
level1Array[2] = new CatchTypeWeighedItem(CatchType::FISH, 848 );
|
|
||||||
|
|
||||||
level2Array[0] = new CatchTypeWeighedItem(CatchType::JUNK, 61 );
|
|
||||||
level2Array[1] = new CatchTypeWeighedItem(CatchType::TREASURE, 92 );
|
|
||||||
level2Array[2] = new CatchTypeWeighedItem(CatchType::FISH, 847 );
|
|
||||||
|
|
||||||
level3Array[0] = new CatchTypeWeighedItem(CatchType::JUNK, 41 );
|
|
||||||
level3Array[1] = new CatchTypeWeighedItem(CatchType::TREASURE, 113 );
|
|
||||||
level3Array[2] = new CatchTypeWeighedItem(CatchType::FISH, 845 );
|
|
||||||
|
|
||||||
fishingTreasuresArray[0] = new CatchWeighedItem(Item::bow_Id, 1, 0, 1);
|
fishingTreasuresArray[0] = new CatchWeighedItem(Item::bow_Id, 1, 0, 1);
|
||||||
fishingTreasuresArray[1] = new CatchWeighedItem(Item::book_Id, 1, 0, 1);
|
fishingTreasuresArray[1] = new CatchWeighedItem(Item::book_Id, 1, 0, 1);
|
||||||
fishingTreasuresArray[2] = new CatchWeighedItem(Item::fishingRod_Id, 1, 0, 1);
|
fishingTreasuresArray[2] = new CatchWeighedItem(Item::fishingRod_Id, 1, 0, 1);
|
||||||
fishingTreasuresArray[3] = new CatchWeighedItem(Item::nameTag_Id, 1, 0, 2); // Doubled the chance of name tags to account for lack of nautilus shells.
|
fishingTreasuresArray[3] = new CatchWeighedItem(Item::nameTag_Id, 1, 0, 1);
|
||||||
fishingTreasuresArray[4] = new CatchWeighedItem(Item::saddle_Id, 1, 0, 1);
|
fishingTreasuresArray[4] = new CatchWeighedItem(Item::saddle_Id, 1, 0, 1);
|
||||||
|
fishingTreasuresArray[4] = new CatchWeighedItem(Tile::waterLily_Id, 1, 0, 1);
|
||||||
|
|
||||||
fishingFishArray[0] = new CatchWeighedItem(Item::fish_raw_Id, 1, 0, 60); // Fish
|
fishingFishArray[0] = new CatchWeighedItem(Item::fish_raw_Id, 1, 0, 60); // Fish
|
||||||
fishingFishArray[1] = new CatchWeighedItem(Item::fish_raw_Id, 1, 1, 25); // Salmon
|
fishingFishArray[1] = new CatchWeighedItem(Item::fish_raw_Id, 1, 1, 25); // Salmon
|
||||||
fishingFishArray[2] = new CatchWeighedItem(Item::fish_raw_Id, 1, 2, 2); // Clownfish
|
fishingFishArray[2] = new CatchWeighedItem(Item::fish_raw_Id, 1, 2, 2); // Clownfish
|
||||||
fishingFishArray[3] = new CatchWeighedItem(Item::fish_raw_Id, 1, 3, 13); // Pufferfish
|
fishingFishArray[3] = new CatchWeighedItem(Item::fish_raw_Id, 1, 3, 13); // Pufferfish
|
||||||
|
|
||||||
fishingJunkArray[0] = new CatchWeighedItem(Tile::waterLily_Id, 1, 0, 17);
|
|
||||||
fishingJunkArray[1] = new CatchWeighedItem(Item::bone_Id, 1, 0, 10);
|
|
||||||
fishingJunkArray[2] = new CatchWeighedItem(Item::bowl_Id, 1, 0, 10);
|
|
||||||
fishingJunkArray[3] = new CatchWeighedItem(Item::leather_Id, 1, 0, 10);
|
fishingJunkArray[3] = new CatchWeighedItem(Item::leather_Id, 1, 0, 10);
|
||||||
|
fishingJunkArray[1] = new CatchWeighedItem(Item::bone_Id, 1, 0, 10);
|
||||||
|
fishingJunkArray[6] = new CatchWeighedItem(Item::potion_Id, 1, 0, 10); // Water bottle
|
||||||
|
fishingJunkArray[2] = new CatchWeighedItem(Item::bowl_Id, 1, 0, 10);
|
||||||
fishingJunkArray[4] = new CatchWeighedItem(Item::boots_leather_Id, 1, 0, 10);
|
fishingJunkArray[4] = new CatchWeighedItem(Item::boots_leather_Id, 1, 0, 10);
|
||||||
fishingJunkArray[5] = new CatchWeighedItem(Item::rotten_flesh_Id, 1, 0, 10);
|
fishingJunkArray[5] = new CatchWeighedItem(Item::rotten_flesh_Id, 1, 0, 10);
|
||||||
fishingJunkArray[6] = new CatchWeighedItem(Item::potion_Id, 1, 0, 10); // Water bottle
|
|
||||||
fishingJunkArray[7] = new CatchWeighedItem(Tile::tripWireSource_Id, 1, 0, 10);
|
fishingJunkArray[7] = new CatchWeighedItem(Tile::tripWireSource_Id, 1, 0, 10);
|
||||||
fishingJunkArray[8] = new CatchWeighedItem(Item::stick_Id, 1, 0, 5);
|
fishingJunkArray[8] = new CatchWeighedItem(Item::stick_Id, 1, 0, 5);
|
||||||
fishingJunkArray[9] = new CatchWeighedItem(Item::string_Id, 1, 0, 5);
|
fishingJunkArray[9] = new CatchWeighedItem(Item::string_Id, 1, 0, 5);
|
||||||
|
|
@ -60,26 +45,14 @@ FishingHelper::FishingHelper() :
|
||||||
fishingJunkArray[11] = new CatchWeighedItem(Item::dye_powder_Id, 10, 0, 1); // 10 ink sacs
|
fishingJunkArray[11] = new CatchWeighedItem(Item::dye_powder_Id, 10, 0, 1); // 10 ink sacs
|
||||||
}
|
}
|
||||||
|
|
||||||
CatchType FishingHelper::getRandCatchType(int level)
|
CatchType FishingHelper::getRandCatchType(int luck, Random* random)
|
||||||
{
|
{
|
||||||
CatchTypeWeighedItem* catchTypeWeighedItem = nullptr;
|
CatchTypeWeighedItem* catchTypeWeighedItem = nullptr;
|
||||||
switch (level) {
|
catchTypeArray.calcWeights(luck); // Recalculate the weights based on the luck level of the player
|
||||||
case 0:
|
catchTypeWeighedItem = static_cast<CatchTypeWeighedItem *>(WeighedRandom::getRandomItem(random, catchTypeArray));
|
||||||
catchTypeWeighedItem = static_cast<CatchTypeWeighedItem *>(WeighedRandom::getRandomItem(random, level0Array));
|
|
||||||
return catchTypeWeighedItem->getType();
|
|
||||||
case 1:
|
|
||||||
catchTypeWeighedItem = static_cast<CatchTypeWeighedItem *>(WeighedRandom::getRandomItem(random, level1Array));
|
|
||||||
return catchTypeWeighedItem->getType();
|
|
||||||
case 2:
|
|
||||||
catchTypeWeighedItem = static_cast<CatchTypeWeighedItem *>(WeighedRandom::getRandomItem(random, level2Array));
|
|
||||||
return catchTypeWeighedItem->getType();
|
|
||||||
case 3:
|
|
||||||
catchTypeWeighedItem = static_cast<CatchTypeWeighedItem *>(WeighedRandom::getRandomItem(random, level3Array));
|
|
||||||
return catchTypeWeighedItem->getType();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CatchWeighedItem* FishingHelper::getRandCatch(CatchType catchType)
|
CatchWeighedItem* FishingHelper::getRandCatch(CatchType catchType, Random* random)
|
||||||
{
|
{
|
||||||
CatchWeighedItem* catchWeighedItem = nullptr;
|
CatchWeighedItem* catchWeighedItem = nullptr;
|
||||||
switch (catchType) {
|
switch (catchType) {
|
||||||
|
|
@ -92,7 +65,7 @@ CatchWeighedItem* FishingHelper::getRandCatch(CatchType catchType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<ItemInstance> FishingHelper::handleCatch(CatchWeighedItem* weighedCatch, CatchType catchType)
|
std::shared_ptr<ItemInstance> FishingHelper::handleCatch(CatchWeighedItem* weighedCatch, CatchType catchType, Random* random)
|
||||||
{
|
{
|
||||||
std::shared_ptr<ItemInstance> itemInstance = std::make_shared<ItemInstance>(
|
std::shared_ptr<ItemInstance> itemInstance = std::make_shared<ItemInstance>(
|
||||||
weighedCatch->getItemId(), weighedCatch->getCount(), weighedCatch->getAuxValue()
|
weighedCatch->getItemId(), weighedCatch->getCount(), weighedCatch->getAuxValue()
|
||||||
|
|
@ -102,12 +75,12 @@ std::shared_ptr<ItemInstance> FishingHelper::handleCatch(CatchWeighedItem* weigh
|
||||||
itemInstance->setAuxValue((int) (itemInstance->getMaxDamage() * ((double) random->nextInt(901) + 100.0) / 1000.0)); // 10% to 100% damage
|
itemInstance->setAuxValue((int) (itemInstance->getMaxDamage() * ((double) random->nextInt(901) + 100.0) / 1000.0)); // 10% to 100% damage
|
||||||
}
|
}
|
||||||
else if (itemInstance->id == Item::fishingRod_Id && catchType == CatchType::TREASURE) {
|
else if (itemInstance->id == Item::fishingRod_Id && catchType == CatchType::TREASURE) {
|
||||||
itemInstance->setAuxValue((int) (itemInstance->getMaxDamage() * ((double) random->nextInt(251) + 750.0) / 1000.0)); // 75% to 100% damage
|
itemInstance->setAuxValue((int)(itemInstance->getMaxDamage() * ((double)random->nextInt(251) / 1000.0)); // 0% to 25% damage
|
||||||
itemInstance = EnchantmentHelper::enchantItem(random, itemInstance, random->nextInt(9) + 22); // 22 to 30 enchantment level
|
itemInstance = EnchantmentHelper::enchantItem(random, itemInstance, 30);
|
||||||
}
|
}
|
||||||
else if (itemInstance->id == Item::bow_Id) {
|
else if (itemInstance->id == Item::bow_Id) {
|
||||||
itemInstance->setAuxValue((int) (itemInstance->getMaxDamage() * ((double) random->nextInt(251) + 750.0) / 1000.0)); // 75% to 100% damage
|
itemInstance->setAuxValue((int)(itemInstance->getMaxDamage() * ((double)random->nextInt(251) / 1000.0)); // 0% to 25% damage
|
||||||
itemInstance = EnchantmentHelper::enchantItem(random, itemInstance, random->nextInt(9) + 22); // 22 to 30 enchantment level
|
itemInstance = EnchantmentHelper::enchantItem(random, itemInstance, 30);
|
||||||
}
|
}
|
||||||
else if (itemInstance->id == Item::book_Id) {
|
else if (itemInstance->id == Item::book_Id) {
|
||||||
itemInstance = EnchantmentHelper::enchantItem(random, itemInstance, 30);
|
itemInstance = EnchantmentHelper::enchantItem(random, itemInstance, 30);
|
||||||
|
|
@ -115,3 +88,10 @@ std::shared_ptr<ItemInstance> FishingHelper::handleCatch(CatchWeighedItem* weigh
|
||||||
|
|
||||||
return itemInstance;
|
return itemInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<ItemInstance> FishingHelper::getCatch(int luck, Random* random)
|
||||||
|
{
|
||||||
|
CatchType catchType = getRandCatchType(luck, random);
|
||||||
|
CatchWeighedItem* catchWeighedItem = getRandCatch(catchType, random);
|
||||||
|
return handleCatch(catchWeighedItem, catchType, random);
|
||||||
|
}
|
||||||
|
|
@ -15,17 +15,40 @@ enum CatchType {
|
||||||
class CatchTypeWeighedItem : public WeighedRandomItem {
|
class CatchTypeWeighedItem : public WeighedRandomItem {
|
||||||
protected:
|
protected:
|
||||||
CatchType type;
|
CatchType type;
|
||||||
|
int quality;
|
||||||
|
int weight;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CatchTypeWeighedItem(CatchType type, int weight) : WeighedRandomItem(weight)
|
CatchTypeWeighedItem(CatchType type, int quality, int weight) : WeighedRandomItem(weight)
|
||||||
{
|
{
|
||||||
this->type = type;
|
this->type = type;
|
||||||
|
this->quality = quality;
|
||||||
|
this->weight = weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
CatchType getType()
|
CatchType getType()
|
||||||
{
|
{
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void calcWeight(int luck) {
|
||||||
|
int newWeight = this->weight + this->quality * luck;
|
||||||
|
if (newWeight < 0) {
|
||||||
|
newWeight = 0;
|
||||||
|
}
|
||||||
|
this->randomWeight = newWeight;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class CatchTypeWeighedItems : public WeighedRandomItemArray {
|
||||||
|
public:
|
||||||
|
using WeighedRandomItemArray::WeighedRandomItemArray;
|
||||||
|
void calcWeights(int luck) {
|
||||||
|
for (unsigned int i = 0; i < this->length; i++) {
|
||||||
|
CatchTypeWeighedItem* catchTypeWeighedItem = static_cast<CatchTypeWeighedItem *>(this->data[i]);
|
||||||
|
catchTypeWeighedItem->calcWeight(luck);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class CatchWeighedItem : public WeighedRandomItem {
|
class CatchWeighedItem : public WeighedRandomItem {
|
||||||
|
|
@ -59,12 +82,8 @@ class FishingHelper
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
FishingHelper();
|
FishingHelper();
|
||||||
Random* random;
|
|
||||||
|
|
||||||
WeighedRandomItemArray level0Array;
|
CatchTypeWeighedItems catchTypeArray;
|
||||||
WeighedRandomItemArray level1Array;
|
|
||||||
WeighedRandomItemArray level2Array;
|
|
||||||
WeighedRandomItemArray level3Array;
|
|
||||||
|
|
||||||
WeighedRandomItemArray fishingFishArray;
|
WeighedRandomItemArray fishingFishArray;
|
||||||
WeighedRandomItemArray fishingJunkArray;
|
WeighedRandomItemArray fishingJunkArray;
|
||||||
|
|
@ -74,8 +93,10 @@ class FishingHelper
|
||||||
FishingHelper(const FishingHelper&) = delete;
|
FishingHelper(const FishingHelper&) = delete;
|
||||||
FishingHelper& operator=(const FishingHelper&) = delete;
|
FishingHelper& operator=(const FishingHelper&) = delete;
|
||||||
static FishingHelper* getInstance();
|
static FishingHelper* getInstance();
|
||||||
|
std::shared_ptr<ItemInstance> getCatch(int luck, Random* random);
|
||||||
|
private:
|
||||||
|
CatchType getRandCatchType(int level, Random* random);
|
||||||
|
CatchWeighedItem* getRandCatch(CatchType catchType, Random* random);
|
||||||
|
std::shared_ptr<ItemInstance> handleCatch(CatchWeighedItem* weighedCatch, CatchType catchType, Random* random);
|
||||||
|
|
||||||
CatchType getRandCatchType(int level);
|
|
||||||
CatchWeighedItem* getRandCatch(CatchType catchType);
|
|
||||||
std::shared_ptr<ItemInstance> handleCatch(CatchWeighedItem* weighedCatch, CatchType catchType);
|
|
||||||
};
|
};
|
||||||
|
|
@ -461,18 +461,9 @@ int FishingHook::retrieve()
|
||||||
FishingHelper* helper = FishingHelper::getInstance();
|
FishingHelper* helper = FishingHelper::getInstance();
|
||||||
|
|
||||||
std::shared_ptr<ItemInstance> selectedItemSeaLuck = owner->getSelectedItem();
|
std::shared_ptr<ItemInstance> selectedItemSeaLuck = owner->getSelectedItem();
|
||||||
|
// TODO: Take into account luck potion effect when calculating luck level once it's implemented
|
||||||
int luckLevel = EnchantmentHelper::getEnchantmentLevel(65, selectedItemSeaLuck); // Luck of the sea
|
int luckLevel = EnchantmentHelper::getEnchantmentLevel(65, selectedItemSeaLuck); // Luck of the sea
|
||||||
CatchType type = helper->getRandCatchType(luckLevel);
|
std::shared_ptr<ItemInstance> fishingItemInstance = helper->getCatch(luckLevel, random);
|
||||||
CatchWeighedItem* caughtItem = helper->getRandCatch(type);
|
|
||||||
|
|
||||||
std::shared_ptr<ItemInstance> fishingItemInstance;
|
|
||||||
|
|
||||||
if (!caughtItem) {
|
|
||||||
// Fall back to default if caught item is a nullptr
|
|
||||||
fishingItemInstance = shared_ptr<ItemInstance>(new ItemInstance(Item::fish_raw));
|
|
||||||
} else {
|
|
||||||
fishingItemInstance = helper->handleCatch(caughtItem, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<ItemEntity> ie = std::make_shared<ItemEntity>(this->Entity::level, x, y, z, fishingItemInstance);
|
std::shared_ptr<ItemEntity> ie = std::make_shared<ItemEntity>(this->Entity::level, x, y, z, fishingItemInstance);
|
||||||
double xa = owner->x - x;
|
double xa = owner->x - x;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue