use of com.minecolonies.coremod.colony.interactionhandling.RecruitmentInteraction in project minecolonies by ldtteam.
the class TavernBuildingModule method spawnVisitor.
/**
* Spawns a recruitable visitor citizen.
*/
private void spawnVisitor() {
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();
if (newCitizen.getName().contains("Ray")) {
newCitizen.setRecruitCosts(new ItemStack(Items.BAKED_POTATO, 64));
}
newCitizen.getCitizenSkillHandler().init(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()));
ItemStack boots = ItemStack.EMPTY;
if (recruitLevel > LEATHER_SKILL_LEVEL) {
// Leather
boots = new ItemStack(Items.LEATHER_BOOTS);
}
if (recruitLevel > GOLD_SKILL_LEVEL) {
// Gold
boots = new ItemStack(Items.GOLDEN_BOOTS);
}
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(new TranslationTextComponent("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(EquipmentSlotType.FEET, boots);
}
building.getColony().getEventDescriptionManager().addEventDescription(new VisitorSpawnedEvent(spawnPos, newCitizen.getName()));
}
use of com.minecolonies.coremod.colony.interactionhandling.RecruitmentInteraction in project minecolonies by ldtteam.
the class EventHandler method onEntityConverted.
/**
* Gets called when a Hoglin, Pig, Piglin, Villager, or ZombieVillager gets converted to something else.
*
* @param event the event to handle.
*/
@SubscribeEvent
public static void onEntityConverted(@NotNull final LivingConversionEvent.Pre event) {
LivingEntity entity = event.getEntityLiving();
if (entity instanceof ZombieVillagerEntity && event.getOutcome() == EntityType.VILLAGER) {
final World world = entity.getCommandSenderWorld();
final IColony colony = IColonyManager.getInstance().getIColony(world, entity.blockPosition());
if (colony != null && colony.hasBuilding("tavern", 1, false)) {
event.setCanceled(true);
if (ForgeEventFactory.canLivingConvert(entity, ModEntities.VISITOR, null)) {
IVisitorData visitorData = (IVisitorData) colony.getVisitorManager().createAndRegisterCivilianData();
BlockPos tavernPos = colony.getBuildingManager().getRandomBuilding(b -> !b.getModules(TavernBuildingModule.class).isEmpty());
IBuilding tavern = colony.getBuildingManager().getBuilding(tavernPos);
visitorData.setHomeBuilding(tavern);
visitorData.setBedPos(tavernPos);
tavern.getModules(TavernBuildingModule.class).forEach(mod -> mod.getExternalCitizens().add(visitorData.getId()));
int recruitLevel = world.random.nextInt(10 * tavern.getBuildingLevel()) + 15;
List<com.minecolonies.api.util.Tuple<Item, Integer>> recruitCosts = IColonyManager.getInstance().getCompatibilityManager().getRecruitmentCostsWeights();
visitorData.getCitizenSkillHandler().init(recruitLevel);
colony.getVisitorManager().spawnOrCreateCivilian(visitorData, world, entity.blockPosition(), false);
colony.getEventDescriptionManager().addEventDescription(new VisitorSpawnedEvent(entity.blockPosition(), visitorData.getName()));
if (visitorData.getEntity().isPresent()) {
AbstractEntityCitizen visitorEntity = visitorData.getEntity().get();
for (EquipmentSlotType slotType : EquipmentSlotType.values()) {
ItemStack itemstack = entity.getItemBySlot(slotType);
if (slotType.getType() == EquipmentSlotType.Group.ARMOR && !itemstack.isEmpty()) {
visitorEntity.setItemSlot(slotType, itemstack);
}
}
}
if (!entity.isSilent()) {
world.levelEvent((PlayerEntity) null, 1027, entity.blockPosition(), 0);
}
entity.remove();
Tuple<Item, Integer> cost = recruitCosts.get(world.random.nextInt(recruitCosts.size()));
visitorData.setRecruitCosts(new ItemStack(cost.getA(), (int) (recruitLevel * 3.0 / cost.getB())));
visitorData.triggerInteraction(new RecruitmentInteraction(new TranslationTextComponent("com.minecolonies.coremod.gui.chat.recruitstorycured", visitorData.getName().split(" ")[0]), ChatPriority.IMPORTANT));
}
}
}
}
use of com.minecolonies.coremod.colony.interactionhandling.RecruitmentInteraction in project minecolonies by Minecolonies.
the class EventHandler method onEntityConverted.
/**
* Gets called when a Hoglin, Pig, Piglin, Villager, or ZombieVillager gets converted to something else.
*
* @param event the event to handle.
*/
@SubscribeEvent
public static void onEntityConverted(@NotNull final LivingConversionEvent.Pre event) {
LivingEntity entity = event.getEntityLiving();
if (entity instanceof ZombieVillagerEntity && event.getOutcome() == EntityType.VILLAGER) {
final World world = entity.getCommandSenderWorld();
final IColony colony = IColonyManager.getInstance().getIColony(world, entity.blockPosition());
if (colony != null && colony.hasBuilding("tavern", 1, false)) {
event.setCanceled(true);
if (ForgeEventFactory.canLivingConvert(entity, ModEntities.VISITOR, null)) {
IVisitorData visitorData = (IVisitorData) colony.getVisitorManager().createAndRegisterCivilianData();
BlockPos tavernPos = colony.getBuildingManager().getRandomBuilding(b -> !b.getModules(TavernBuildingModule.class).isEmpty());
IBuilding tavern = colony.getBuildingManager().getBuilding(tavernPos);
visitorData.setHomeBuilding(tavern);
visitorData.setBedPos(tavernPos);
tavern.getModules(TavernBuildingModule.class).forEach(mod -> mod.getExternalCitizens().add(visitorData.getId()));
int recruitLevel = world.random.nextInt(10 * tavern.getBuildingLevel()) + 15;
List<com.minecolonies.api.util.Tuple<Item, Integer>> recruitCosts = IColonyManager.getInstance().getCompatibilityManager().getRecruitmentCostsWeights();
visitorData.getCitizenSkillHandler().init(recruitLevel);
colony.getVisitorManager().spawnOrCreateCivilian(visitorData, world, entity.blockPosition(), false);
colony.getEventDescriptionManager().addEventDescription(new VisitorSpawnedEvent(entity.blockPosition(), visitorData.getName()));
if (visitorData.getEntity().isPresent()) {
AbstractEntityCitizen visitorEntity = visitorData.getEntity().get();
for (EquipmentSlotType slotType : EquipmentSlotType.values()) {
ItemStack itemstack = entity.getItemBySlot(slotType);
if (slotType.getType() == EquipmentSlotType.Group.ARMOR && !itemstack.isEmpty()) {
visitorEntity.setItemSlot(slotType, itemstack);
}
}
}
if (!entity.isSilent()) {
world.levelEvent((PlayerEntity) null, 1027, entity.blockPosition(), 0);
}
entity.remove();
Tuple<Item, Integer> cost = recruitCosts.get(world.random.nextInt(recruitCosts.size()));
visitorData.setRecruitCosts(new ItemStack(cost.getA(), (int) (recruitLevel * 3.0 / cost.getB())));
visitorData.triggerInteraction(new RecruitmentInteraction(new TranslationTextComponent("com.minecolonies.coremod.gui.chat.recruitstorycured", visitorData.getName().split(" ")[0]), ChatPriority.IMPORTANT));
}
}
}
}
use of com.minecolonies.coremod.colony.interactionhandling.RecruitmentInteraction in project minecolonies by Minecolonies.
the class TavernBuildingModule method spawnVisitor.
/**
* Spawns a recruitable visitor citizen.
*/
private void spawnVisitor() {
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();
if (newCitizen.getName().contains("Ray")) {
newCitizen.setRecruitCosts(new ItemStack(Items.BAKED_POTATO, 64));
}
newCitizen.getCitizenSkillHandler().init(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()));
ItemStack boots = ItemStack.EMPTY;
if (recruitLevel > LEATHER_SKILL_LEVEL) {
// Leather
boots = new ItemStack(Items.LEATHER_BOOTS);
}
if (recruitLevel > GOLD_SKILL_LEVEL) {
// Gold
boots = new ItemStack(Items.GOLDEN_BOOTS);
}
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(new TranslationTextComponent("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(EquipmentSlotType.FEET, boots);
}
building.getColony().getEventDescriptionManager().addEventDescription(new VisitorSpawnedEvent(spawnPos, newCitizen.getName()));
}
Aggregations