Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework recruitment items to become datapacks #10342

Open
wants to merge 4 commits into
base: version/main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ public class CompatibilityManager implements ICompatibilityManager
*/
private final List<String> diseaseList = new ArrayList<>();

/**
* The items and weights of the recruitment.
*/
private final List<Tuple<Item, Integer>> recruitmentCostsWeights = new ArrayList<>();

/**
* Random obj.
*/
Expand Down Expand Up @@ -169,7 +164,6 @@ private void clear()
fuel.clear();
compostRecipes.clear();

recruitmentCostsWeights.clear();
diseases.clear();
diseaseList.clear();
monsters = ImmutableSet.of();
Expand All @@ -187,7 +181,6 @@ public void discover(@NotNull final RecipeManager recipeManager, final Level lev
clear();
discoverAllItems(level);

discoverRecruitCosts();
discoverDiseases();
discoverModCompat();

Expand Down Expand Up @@ -242,7 +235,6 @@ public void deserialize(@NotNull final FriendlyByteBuf buf, final ClientLevel le
discoverCompostRecipes(deserializeCompostRecipes(buf));

// the below are loaded from config files, which have been synched already by this point
discoverRecruitCosts();
discoverDiseases();
discoverModCompat();
}
Expand Down Expand Up @@ -478,12 +470,6 @@ public List<Disease> getDiseases()
return new ArrayList<>(diseases.values());
}

@Override
public List<Tuple<Item, Integer>> getRecruitmentCostsWeights()
{
return Collections.unmodifiableList(recruitmentCostsWeights);
}

@Override
public boolean isOre(final BlockState block)
{
Expand Down Expand Up @@ -765,43 +751,6 @@ private void discoverFood(final ItemStack stack)
}
}

/**
* Parses recruitment costs from config
*/
private void discoverRecruitCosts()
{
if (recruitmentCostsWeights.isEmpty())
{
for (final String itemString : MinecoloniesAPIProxy.getInstance().getConfig().getServer().configListRecruitmentItems.get())
{
final String[] split = itemString.split(";");
if (split.length < 2)
{
Log.getLogger().warn("Wrong configured recruitment cost: " + itemString);
continue;
}

final Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(split[0]));
if (item == null || item == Items.AIR)
{
Log.getLogger().warn("Invalid recruitment item: " + item);
continue;
}

try
{
final int rarity = Integer.parseInt(split[split.length - 1]);
recruitmentCostsWeights.add(new Tuple<>(item, rarity));
}
catch (final NumberFormatException ex)
{
Log.getLogger().warn("Invalid recruitment weight for: " + item);
}
}
}
Log.getLogger().info("Finished discovering recruitment costs");
}

/**
* Go through the disease config and setup all possible diseases.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,6 @@ public interface ICompatibilityManager
*/
List<Disease> getDiseases();

/**
* Gets the list of recruitment costs with weights
*
* @return list of costs
*/
List<Tuple<Item, Integer>> getRecruitmentCostsWeights();

/**
* Checks if a certain Block is an ore.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public class ServerConfiguration extends AbstractConfiguration
* -------------------------------------------------------------------------------- */

public final ForgeConfigSpec.ConfigValue<List<? extends String>> configListStudyItems;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> configListRecruitmentItems;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> diseases;
public final ForgeConfigSpec.BooleanValue auditCraftingTags;
public final ForgeConfigSpec.BooleanValue debugInventories;
Expand Down Expand Up @@ -198,23 +197,6 @@ protected ServerConfiguration(final ForgeConfigSpec.Builder builder)
("minecraft:paper;400;100", "minecraft:book;600;10"),
s -> s instanceof String);

configListRecruitmentItems = defineList(builder, "configlistrecruitmentitems",
Arrays.asList
("minecraft:hay_block;3",
"minecraft:book;2",
"minecraft:enchanted_book;9",
"minecraft:diamond;9",
"minecraft:emerald;8",
"minecraft:baked_potato;1",
"minecraft:gold_ingot;2",
"minecraft:redstone;2",
"minecraft:lapis_lazuli;2",
"minecraft:cake;11",
"minecraft:sunflower;5",
"minecraft:honeycomb;6",
"minecraft:quartz;3"),
s -> s instanceof String);

diseases = defineList(builder, "diseases",
Arrays.asList("Influenza,100,minecraft:carrot,minecraft:potato",
"Measles,10,minecraft:dandelion,minecraft:kelp,minecraft:poppy",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
import com.minecolonies.api.colony.interactionhandling.ChatPriority;
import com.minecolonies.api.sounds.TavernSounds;
import com.minecolonies.api.util.BlockPosUtil;
import com.minecolonies.api.util.Tuple;
import com.minecolonies.core.Network;
import com.minecolonies.core.client.gui.huts.WindowHutLiving;
import com.minecolonies.core.colony.buildings.views.LivingBuildingView;
import com.minecolonies.core.colony.eventhooks.citizenEvents.VisitorSpawnedEvent;
import com.minecolonies.core.colony.interactionhandling.RecruitmentInteraction;
import com.minecolonies.core.datalistener.CustomVisitorListener;
import com.minecolonies.core.datalistener.RecruitmentItemsListener;
import com.minecolonies.core.datalistener.RecruitmentItemsListener.RecruitCost;
import com.minecolonies.core.network.messages.client.colony.PlayMusicAtPosMessage;
import net.minecraft.world.entity.player.Player;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -53,10 +53,10 @@ public class TavernBuildingModule extends AbstractBuildingModule implements IDef
/**
* Skill levels
*/
private static final int LEATHER_SKILL_LEVEL = 20;
private static final int GOLD_SKILL_LEVEL = 25;
private static final int IRON_SKILL_LEVEL = 30;
private static final int DIAMOND_SKILL_LEVEL = 35;
public static final int LEATHER_SKILL_LEVEL = 20;
public static final int GOLD_SKILL_LEVEL = 25;
public static final int IRON_SKILL_LEVEL = 30;
public static final int DIAMOND_SKILL_LEVEL = 35;

/**
* Music interval
Expand Down Expand Up @@ -154,7 +154,7 @@ public void onColonyTick(@NotNull final IColony colony)

if (building.getBuildingLevel() > 0 && externalCitizens.size() < 3 * building.getBuildingLevel() && noVisitorTime <= 0)
{
spawnVisitor();
spawnVisitorInternal();
noVisitorTime =
colony.getWorld().getRandom().nextInt(3000) + (6000 / building.getBuildingLevel()) * colony.getCitizenManager().getCurrentCitizenCount() / colony.getCitizenManager()
.getMaxCitizens();
Expand All @@ -168,34 +168,59 @@ public void onUpgradeComplete(final int newlevel)
}

/**
* Spawns a recruitable visitor citizen.
* Spawns a visitor specifically for the tavern logic.
*/
private void spawnVisitor()
private void spawnVisitorInternal()
{
IVisitorData newCitizen = (IVisitorData) building.getColony().getVisitorManager().createAndRegisterCivilianData();
externalCitizens.add(newCitizen.getId());

newCitizen.setBedPos(building.getPosition());
newCitizen.setHomeBuilding(building);

int recruitLevel = building.getColony().getWorld().random.nextInt(10 * building.getBuildingLevel()) + 15;
List<com.minecolonies.api.util.Tuple<Item, Integer>> recruitCosts = IColonyManager.getInstance().getCompatibilityManager().getRecruitmentCostsWeights();
final IVisitorData visitorData = spawnVisitor();

if (newCitizen.getName().contains("Ray"))
if (!CustomVisitorListener.chanceCustomVisitors(visitorData))
{
newCitizen.setRecruitCosts(new ItemStack(Items.BAKED_POTATO, 64));
visitorData.triggerInteraction(new RecruitmentInteraction(Component.translatable(
"com.minecolonies.coremod.gui.chat.recruitstory" + (building.getColony().getWorld().random.nextInt(MAX_STORY) + 1), visitorData.getName().split(" ")[0]),
ChatPriority.IMPORTANT));
}
}

/**
* Spawns a visitor citizen that can be recruited.
*/
public IVisitorData spawnVisitor()
{
final int recruitLevel = building.getColony().getWorld().random.nextInt(10 * building.getBuildingLevel()) + 15;
final RecruitCost cost = RecruitmentItemsListener.getRandomRecruitCost(building.getColony().getWorld().getRandom(), recruitLevel);

final IVisitorData newCitizen = (IVisitorData) building.getColony().getVisitorManager().createAndRegisterCivilianData();
newCitizen.setBedPos(building.getPosition());
newCitizen.setHomeBuilding(building);
newCitizen.getCitizenSkillHandler().init(recruitLevel);
newCitizen.setRecruitCosts(cost.toItemStack(recruitLevel));

BlockPos spawnPos = BlockPosUtil.findSpawnPosAround(building.getColony().getWorld(), building.getPosition());
if (spawnPos == null)
{
spawnPos = building.getPosition();
}

Tuple<Item, Integer> cost = recruitCosts.get(building.getColony().getWorld().random.nextInt(recruitCosts.size()));
building.getColony().getVisitorManager().spawnOrCreateCivilian(newCitizen, building.getColony().getWorld(), spawnPos, true);
if (newCitizen.getEntity().isPresent())
{
newCitizen.getEntity().get().setItemSlot(EquipmentSlot.FEET, getBoots(recruitLevel));
}
building.getColony().getEventDescriptionManager().addEventDescription(new VisitorSpawnedEvent(spawnPos, newCitizen.getName()));

externalCitizens.add(newCitizen.getId());
return newCitizen;
}

/**
* Get the boots for the given recruit level.
*
* @param recruitLevel the input recruit level.
* @return the itemstack for the boots.
*/
private ItemStack getBoots(final int recruitLevel)
{
ItemStack boots = ItemStack.EMPTY;
if (recruitLevel > LEATHER_SKILL_LEVEL)
{
Expand All @@ -209,38 +234,15 @@ private void spawnVisitor()
}
if (recruitLevel > IRON_SKILL_LEVEL)
{
if (cost.getB() <= 2)
{
cost = recruitCosts.get(building.getColony().getWorld().random.nextInt(recruitCosts.size()));
}
// Iron
boots = new ItemStack(Items.IRON_BOOTS);
}
if (recruitLevel > DIAMOND_SKILL_LEVEL)
{
if (cost.getB() <= 3)
{
cost = recruitCosts.get(building.getColony().getWorld().random.nextInt(recruitCosts.size()));
}
// Diamond
boots = new ItemStack(Items.DIAMOND_BOOTS);
}

newCitizen.setRecruitCosts(new ItemStack(cost.getA(), (int) (recruitLevel * 3.0 / cost.getB())));

if (!CustomVisitorListener.chanceCustomVisitors(newCitizen))
{
newCitizen.triggerInteraction(new RecruitmentInteraction(Component.translatable(
"com.minecolonies.coremod.gui.chat.recruitstory" + (building.getColony().getWorld().random.nextInt(MAX_STORY) + 1), newCitizen.getName().split(" ")[0]),
ChatPriority.IMPORTANT));
}

building.getColony().getVisitorManager().spawnOrCreateCivilian(newCitizen, building.getColony().getWorld(), spawnPos, true);
if (newCitizen.getEntity().isPresent())
{
newCitizen.getEntity().get().setItemSlot(EquipmentSlot.FEET, boots);
}
building.getColony().getEventDescriptionManager().addEventDescription(new VisitorSpawnedEvent(spawnPos, newCitizen.getName()));
return boots;
}

@Override
Expand Down
Loading