Jump to content
  • 0

How To Make It Random? Instance


Question

Posted

Hello guys! i have been working on my custom instance, its kamaloka like, but using Tower of insolence, i need help to make "random spawns".

Red letter are the moobs ids declaration and their spawn use, i want to make a list where i declare them and use Random get to spawn. i tried but i failed several times, trust me i spend maaany time on it.

 

Well here is my full code:

package instances.RaidTower;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.logging.Level;

import com.l2jserver.gameserver.datatables.SkillData;
import com.l2jserver.gameserver.instancemanager.InstanceManager;
import com.l2jserver.gameserver.model.L2Party;
import com.l2jserver.gameserver.model.L2Spawn;
import com.l2jserver.gameserver.model.L2World;
import com.l2jserver.gameserver.model.Location;
import com.l2jserver.gameserver.model.actor.L2Character;
import com.l2jserver.gameserver.model.actor.L2Npc;
import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.entity.Instance;
import com.l2jserver.gameserver.model.instancezone.InstanceWorld;
import com.l2jserver.gameserver.model.quest.Quest;
import com.l2jserver.gameserver.model.skills.BuffInfo;
import com.l2jserver.gameserver.model.skills.Skill;
import com.l2jserver.gameserver.network.SystemMessageId;
import com.l2jserver.gameserver.network.serverpackets.SystemMessage;

public final class RaidTower extends Quest
{
	/*
	 * Reset time for all RaidTower Default: 6:30AM on server time
	 */
	private static final int RESET_HOUR = 6;
	private static final int RESET_MIN = 30;
	
	/*
	 * Time after which instance without players will be destroyed Default: 5 minutes
	 */
	private static final int EMPTY_DESTROY_TIME = 5;
	
	/*
	 * Time to destroy instance (and eject players away) after boss defeat Default: 5 minutes
	 */
	private static final int EXIT_TIME = 5;
	
	/*
	 * Maximum level difference between players level and RaidTower level Default: 5
	 */
	private static final int MAX_LEVEL_DIFFERENCE = 5;
	
	/*
	 * If true shaman in the first room will have same npcId as other mobs, making radar useless Default: true (but not retail like)
	 */
	private static final boolean STEALTH_SHAMAN = true;
	// Template IDs for RaidTower
	// @formatter:off
	private static final int[] TEMPLATE_IDS =
	{
		1000, 1001, 1002, 1003, 1004
	};
	// Level of the RaidTower
	private static final int[] LEVEL =
	{
		26, 46, 66, 76, 86
	};
	// Duration of the instance, minutes
	private static final int[] DURATION =
	{
		45, 45, 45, 45, 45
	};
	// Maximum party size for the instance
	private static final int[] MAX_PARTY_SIZE =
	{
		2, 2, 2, 2, 2
	};
	
	/**
	 * List of buffs NOT removed on enter from player and pet<br>
	 * On retail only newbie guide buffs not removed<br>
	 * CAUTION: array must be sorted in ascension order!
	 */
	protected static final int[] BUFFS_WHITELIST =
	{
		4322, 4323, 4324, 4325, 4326, 4327, 4328, 4329, 4330, 4331, 5632, 5637, 5950
	};
	// @formatter:on
	// Teleport points into instances x, y, z
	private static final Location[] TELEPORTS =
	{
		new Location(114674, 11458, -5125),
		new Location(114674, 11458, -5125),
		new Location(114674, 11458, -5125), // -76280, -185540, -10936
		new Location(114674, 11458, -5125),
		new Location(114674, 11458, -5125),
	};
	
	// Respawn delay for the mobs in the first room, seconds Default: 25
	private static final int FIRST_ROOM_RESPAWN_DELAY = 25;
	
	/**
	 * First room information, null if room not spawned.<br>
	 * Skill is casted on the boss when shaman is defeated and mobs respawn stopped<br>
	 * Default: 5699 (decrease pdef)<br>
	 * shaman npcId, minions npcId, skillId, skillLvl
	 */
	private static final int[][] FIRST_ROOM =
	{
		{
			22485,
			22486,
			5699,
			1
		},
		{
			22485,
			22486,
			5699,
			1
		},
		{
			22485,
			22486,
			5699,
			1
		},
		{
			22485,
			22486,
			5699,
			1
		},
		{
			22485,
			22486,
			5699,
			1
		},
	};
	
	/*
	 * First room spawns, null if room not spawned x, y, z
	 */
	private static final int[][][] FIRST_ROOM_SPAWNS =
	{
		/* instancia 26 */
		{
			{
				114636,
				15532,
				-5100
			},
			{
				114711,
				15536,
				-5100
			},
			{
				114567,
				15539,
				-5100
			},
			{
				114485,
				15700,
				-5100
			},
			{
				114638,
				15719,
				-5100
			},
			{
				112965,
				17291,
				-4378
			},
			{
				112890,
				17380,
				-4378
			},
			{
				113096,
				17179,
				-4378
			},
			{
				112759,
				16815,
				-4378
			}
		},
		
		/* instancia 46 */
		{
			{
				114636,
				15532,
				-5100
			},
			{
				114711,
				15536,
				-5100
			},
			{
				114567,
				15539,
				-5100
			},
			{
				114485,
				15700,
				-5100
			},
			{
				114638,
				15719,
				-5100
			},
			{
				112965,
				17291,
				-4378
			},
			{
				112890,
				17380,
				-4378
			},
			{
				113096,
				17179,
				-4378
			},
			{
				112759,
				16815,
				-4378
			}
		},
		
		/* instancia 66 */
		{
			{
				114636,
				15532,
				-5100
			},
			{
				114711,
				15536,
				-5100
			},
			{
				114567,
				15539,
				-5100
			},
			{
				114485,
				15700,
				-5100
			},
			{
				114638,
				15719,
				-5100
			},
			{
				112965,
				17291,
				-4378
			},
			{
				112890,
				17380,
				-4378
			},
			{
				113096,
				17179,
				-4378
			},
			{
				112759,
				16815,
				-4378
			}
		},
		
		/* instancia 76 */
		{
			{
				114636,
				15532,
				-5100
			},
			{
				114711,
				15536,
				-5100
			},
			{
				114567,
				15539,
				-5100
			},
			{
				114485,
				15700,
				-5100
			},
			{
				114638,
				15719,
				-5100
			},
			{
				112965,
				17291,
				-4378
			},
			{
				112890,
				17380,
				-4378
			},
			{
				113096,
				17179,
				-4378
			},
			{
				112759,
				16815,
				-4378
			}
		},
		
		/* instancia 86 */
		{
			{
				114636,
				15532,
				-5100
			},
			{
				114711,
				15536,
				-5100
			},
			{
				114567,
				15539,
				-5100
			},
			{
				114485,
				15700,
				-5100
			},
			{
				114638,
				15719,
				-5100
			},
			{
				112965,
				17291,
				-4378
			},
			{
				112890,
				17380,
				-4378
			},
			{
				113096,
				17179,
				-4378
			},
			{
				112759,
				16815,
				-4378
			}
		}
	};
	
	/*
	 * Second room information, null if room not spawned Skill is casted on the boss when all mobs are defeated Default: 5700 (decrease mdef) npcId, skillId, skillLvl
	 */
	private static final int[][] SECOND_ROOM =
	{
		{
			22487,
			5700,
			1
		},
		{
			22490,
			5700,
			2
		},
		{
			22493,
			5700,
			3
		},
		{
			22496,
			5700,
			4
		},
		{
			22499,
			5700,
			5
		}
	};
	
	/*
	 * Spawns for second room, null if room not spawned x, y, z
	 */
	private static final int[][][] SECOND_ROOM_SPAWNS =
	{
		/*instancia 26 */
		{
			{
				114637,
				16223,
				-2127
			},
			{
				114543,
				16083,
				-2127
			},
			{
				114833,
				16099,
				-2127
			},
			{
				114618,
				15848,
				-2127
			},
			{
				114627,
				15637,
				-2127
			},
			{
				116230,
				14822,
				-1414
			},
			{
				116460,
				14922,
				-1417
			},
			{
				116303,
				14973,
				-1414
			},
			{
				116598,
				15466,
				-1414
			}
		},
		/*instancia 46 */
		{
			{
				114637,
				16223,
				-2127
			},
			{
				114543,
				16083,
				-2127
			},
			{
				114833,
				16099,
				-2127
			},
			{
				114618,
				15848,
				-2127
			},
			{
				114627,
				15637,
				-2127
			},
			{
				116230,
				14822,
				-1414
			},
			{
				116460,
				14922,
				-1417
			},
			{
				116303,
				14973,
				-1414
			},
			{
				116598,
				15466,
				-1414
			}
		},
		/*instancia 66 */
		{
			{
				114637,
				16223,
				-2127
			},
			{
				114543,
				16083,
				-2127
			},
			{
				114833,
				16099,
				-2127
			},
			{
				114618,
				15848,
				-2127
			},
			{
				114627,
				15637,
				-2127
			},
			{
				116230,
				14822,
				-1414
			},
			{
				116460,
				14922,
				-1417
			},
			{
				116303,
				14973,
				-1414
			},
			{
				116598,
				15466,
				-1414
			}
		},
		/*instancia 76 */
		{
			{
				114637,
				16223,
				-2127
			},
			{
				114543,
				16083,
				-2127
			},
			{
				114833,
				16099,
				-2127
			},
			{
				114618,
				15848,
				-2127
			},
			{
				114627,
				15637,
				-2127
			},
			{
				116230,
				14822,
				-1414
			},
			{
				116460,
				14922,
				-1417
			},
			{
				116303,
				14973,
				-1414
			},
			{
				116598,
				15466,
				-1414
			}
		},
		/*instancia 86 */
		{
			{
				114637,
				16223,
				-2127
			},
			{
				114543,
				16083,
				-2127
			},
			{
				114833,
				16099,
				-2127
			},
			{
				114618,
				15848,
				-2127
			},
			{
				114627,
				15637,
				-2127
			},
			{
				116230,
				14822,
				-1414
			},
			{
				116460,
				14922,
				-1417
			},
			{
				116303,
				14973,
				-1414
			},
			{
				116598,
				15466,
				-1414
			}
		}
	};
	
	// miniboss info
	// skill is casted on the boss when miniboss is defeated
	// npcId, x, y, z, skill id, skill level
	/*
	 * Miniboss information, null if miniboss not spawned Skill is casted on the boss when miniboss is defeated Default: 5701 (decrease patk) npcId, x, y, z, skillId, skillLvl
	 */
	private static final int[][] MINIBOSS =
	{
		/*intancia 26 */
		{
			25616,
			115376,
			16225,
			-645,
			5701,
			1
		},
		/*intancia 46 */
		{
			25616,
			115376,
			16225,
			-645,
			5701,
			1
		},
		/*intancia 66 */
		{
			25616,
			115376,
			16225,
			-645,
			5701,
			1
		},
		/*intancia 76 */
		{
			25616,
			115376,
			16225,
			-645,
			5701,
			1
		},
		/*intancia 86 */
		{
			25616,
			115376,
			16225,
			-645,
			5701,
			1
		}
	};
	
	/*
	 * Bosses of the RaidTower Instance ends when boss is defeated npcId, x, y, z
	 */
	private static final int[][] BOSS =
	{
		/*intancia 26 */
		{
			18554,
			114671,
			16976,
			928
		},
		/*intancia 46 */
		{
			18555,
			114671,
			16976,
			928
		},
		/*intancia 66 */
		{
			29129,
			114671,
			16976,
			928
		},
		/*intancia 76 */
		{
			18558,
			114671,
			16976,
			928
		},
		/*intancia 86 */
		{
			18559,
			114671,
			16976,
			928
		}
	};
	
	/*
	 * Escape telepoters spawns, null if not spawned x, y, z
	 */
	private static final int[][] TELEPORTERS =
	{
		/*intancia 26 */
		{
			114649,
			17642,
			925
		},
		/*intancia 46 */
		{
			114649,
			17642,
			925
		},
		/*intancia 66 */
		{
			114649,
			17642,
			925
		},
		/*intancia 76 */
		{
			114649,
			17642,
			925
		},
		/*intancia 86 */
		{
			114649,
			17642,
			925
		}
	};
	
	/*
	 * Escape teleporter npcId
	 */
	private static final int TELEPORTER = 80026;
	
	/** RaidTower captains (start npc's) npcIds. */
	private static final int[] CAPTAINS =
	{
		80020,
		80021,
		80022,
		80023,
		80024,
		80026
	};
	
	protected class RaidTowerWorld extends InstanceWorld
	{
		public int index; // 0-18 index of the Raid type in arrays
		public int shaman = 0; // objectId of the shaman
		public List<L2Spawn> firstRoom; // list of the spawns in the first room (excluding shaman)
		public List<Integer> secondRoom;// list of objectIds mobs in the second room
		public int miniBoss = 0; // objectId of the miniboss
		public L2Npc boss = null; // boss
	}
	
	private RaidTower()
	{
		super(-1, RaidTower.class.getSimpleName(), "instances");
		addFirstTalkId(TELEPORTER);
		addTalkId(TELEPORTER);
		for (int cap : CAPTAINS)
		{
			addStartNpc(cap);
			addTalkId(cap);
		}
		for (int[] mob : FIRST_ROOM)
		{
			if (mob != null)
			{
				if (STEALTH_SHAMAN)
				{
					addKillId(mob[1]);
				}
				else
				{
					addKillId(mob[0]);
				}
			}
		}
		for (int[] mob : SECOND_ROOM)
		{
			if (mob != null)
			{
				addKillId(mob[0]);
			}
		}
		for (int[] mob : MINIBOSS)
		{
			if (mob != null)
			{
				addKillId(mob[0]);
			}
		}
		for (int[] mob : BOSS)
		{
			addKillId(mob[0]);
		}
	}
	
	/**
	 * Check if party with player as leader allowed to enter
	 * @param player party leader
	 * @param index (0-18) index of the RaidTower in arrays
	 * @return true if party allowed to enter
	 */
	private static final boolean checkConditions(L2PcInstance player, int index)
	{
		final L2Party party = player.getParty();
		// player must be in party
		if (party == null)
		{
			player.sendPacket(SystemMessageId.NOT_IN_PARTY_CANT_ENTER);
			return false;
		}
		// ...and be party leader
		if (party.getLeader() != player)
		{
			player.sendPacket(SystemMessageId.ONLY_PARTY_LEADER_CAN_ENTER);
			return false;
		}
		// party must not exceed max size for selected instance
		if (party.getMemberCount() > MAX_PARTY_SIZE[index])
		{
			player.sendPacket(SystemMessageId.PARTY_EXCEEDED_THE_LIMIT_CANT_ENTER);
			return false;
		}
		
		// get level of the instance
		final int level = LEVEL[index];
		// and client name
		final String instanceName = InstanceManager.getInstance().getInstanceIdName(TEMPLATE_IDS[index]);
		
		Map<Integer, Long> instanceTimes;
		// for each party member
		for (L2PcInstance partyMember : party.getMembers())
		{
			// player level must be in range
			if (Math.abs(partyMember.getLevel() - level) > MAX_LEVEL_DIFFERENCE)
			{
				SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_LEVEL_REQUIREMENT_NOT_SUFFICIENT);
				sm.addPcName(partyMember);
				player.sendPacket(sm);
				return false;
			}
			// player must be near party leader
			if (!partyMember.isInsideRadius(player, 1000, true, true))
			{
				SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_LOCATION_THAT_CANNOT_BE_ENTERED);
				sm.addPcName(partyMember);
				player.sendPacket(sm);
				return false;
			}
			// get instances reenter times for player
			instanceTimes = InstanceManager.getInstance().getAllInstanceTimes(partyMember.getObjectId());
			if (instanceTimes != null)
			{
				for (int id : instanceTimes.keySet())
				{
					// find instance with same name (RaidTower or labyrinth)
					// TODO: Zoey76: Don't use instance name, use other system.
					if (!instanceName.equals(InstanceManager.getInstance().getInstanceIdName(id)))
					{
						continue;
					}
					// if found instance still can't be reentered - exit
					if (System.currentTimeMillis() < instanceTimes.get(id))
					{
						SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_MAY_NOT_REENTER_YET);
						sm.addPcName(partyMember);
						player.sendPacket(sm);
						return false;
					}
				}
			}
		}
		return true;
	}
	
	/**
	 * Removing all buffs from player and pet except BUFFS_WHITELIST
	 * @param ch player
	 */
	private static final void removeBuffs(L2Character ch)
	{
		Function<BuffInfo, Boolean> removeBuffs = info ->
		{
			if ((info != null) && !info.getSkill().isStayAfterDeath() && (Arrays.binarySearch(BUFFS_WHITELIST, info.getSkill().getId()) < 0))
			{
				info.getEffected().getEffectList().stopSkillEffects(true, info.getSkill());
			}
			return true;
		};
		
		ch.getEffectList().forEach(removeBuffs, false);
		
		if (ch.hasSummon())
		{
			ch.getSummon().getEffectList().forEach(removeBuffs, false);
		}
	}
	
	/**
	 * Handling enter of the players into RaidTower
	 * @param player party leader
	 * @param index (0-18) RaidTower index in arrays
	 */
	private final synchronized void enterInstance(L2PcInstance player, int index)
	{
		int templateId;
		try
		{
			templateId = TEMPLATE_IDS[index];
		}
		catch (ArrayIndexOutOfBoundsException e)
		{
			throw e;
		}
		
		// check for existing instances for this player
		InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
		// player already in the instance
		if (world != null)
		{
			// but not in RaidTower
			if (!(world instanceof RaidTowerWorld) || (world.getTemplateId() != templateId))
			{
				player.sendPacket(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER);
				return;
			}
			// check for level difference again on reenter
			if (Math.abs(player.getLevel() - LEVEL[((RaidTowerWorld) world).index]) > MAX_LEVEL_DIFFERENCE)
			{
				SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_LEVEL_REQUIREMENT_NOT_SUFFICIENT);
				sm.addPcName(player);
				player.sendPacket(sm);
				return;
			}
			// check what instance still exist
			Instance inst = InstanceManager.getInstance().getInstance(world.getInstanceId());
			if (inst != null)
			{
				removeBuffs(player);
				teleportPlayer(player, TELEPORTS[index], world.getInstanceId());
			}
			return;
		}
		// Creating new RaidTower instance
		if (!checkConditions(player, index))
		{
			return;
		}
		
		// Creating dynamic instance without template
		final int instanceId = InstanceManager.getInstance().createDynamicInstance(null);
		final Instance inst = InstanceManager.getInstance().getInstance(instanceId);
		// set name for the RaidTower
		inst.setName(InstanceManager.getInstance().getInstanceIdName(templateId));
		// set return location
		inst.setSpawnLoc(new Location(player));
		// disable summon friend into instance
		inst.setAllowSummon(false);
		// set duration and empty destroy time
		inst.setDuration(DURATION[index] * 60000);
		inst.setEmptyDestroyTime(EMPTY_DESTROY_TIME * 60000);
		
		// Creating new instanceWorld, using our instanceId and templateId
		world = new RaidTowerWorld();
		world.setInstanceId(instanceId);
		world.setTemplateId(templateId);
		// set index for easy access to the arrays
		((RaidTowerWorld) world).index = index;
		InstanceManager.getInstance().addWorld(world);
		world.setStatus(0);
		// spawn npcs
		spawnRaidTower((RaidTowerWorld) world);
		
		// and finally teleport party into instance
		final L2Party party = player.getParty();
		for (L2PcInstance partyMember : party.getMembers())
		{
			world.addAllowed(partyMember.getObjectId());
			removeBuffs(partyMember);
			teleportPlayer(partyMember, TELEPORTS[index], instanceId);
		}
		return;
	}
	
	/**
	 * Called on instance finish and handles reenter time for instance
	 * @param world instanceWorld
	 */
	private static final void finishInstance(InstanceWorld world)
	{
		if (world instanceof RaidTowerWorld)
		{
			Calendar reenter = Calendar.getInstance();
			reenter.set(Calendar.MINUTE, RESET_MIN);
			// if time is >= RESET_HOUR - roll to the next day
			if (reenter.get(Calendar.HOUR_OF_DAY) >= RESET_HOUR)
			{
				reenter.add(Calendar.DATE, 1);
			}
			reenter.set(Calendar.HOUR_OF_DAY, RESET_HOUR);
			
			SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.INSTANT_ZONE_S1_RESTRICTED);
			sm.addInstanceName(world.getTemplateId());
			
			// set instance reenter time for all allowed players
			for (int objectId : world.getAllowed())
			{
				L2PcInstance obj = L2World.getInstance().getPlayer(objectId);
				if ((obj != null) && obj.isOnline())
				{
					InstanceManager.getInstance().setInstanceTime(objectId, world.getTemplateId(), reenter.getTimeInMillis());
					obj.sendPacket(sm);
				}
			}
			
			// destroy instance after EXIT_TIME
			Instance inst = InstanceManager.getInstance().getInstance(world.getInstanceId());
			inst.setDuration(EXIT_TIME * 60000);
			inst.setEmptyDestroyTime(0);
		}
	}
	
	/**
	 * Spawn all NPCs in RaidTower
	 * @param world instanceWorld
	 */
	@SuppressWarnings("all")
	private final void spawnRaidTower(RaidTowerWorld world)
	{
		int[] npcs;
		int[][] spawns;
		L2Npc npc;
		final int index = world.index;
		
		// first room
		npcs = FIRST_ROOM[index];
		spawns = FIRST_ROOM_SPAWNS[index];
		if (npcs != null)
		{
			world.firstRoom = new ArrayList<L2Spawn>(spawns.length - 1);
			int shaman = getRandom(spawns.length); // random position for shaman
			
			for (int i = 0; i < spawns.length; i++)
			{
				if (i == shaman)
				{
					// stealth shaman use same npcId as other mobs
					npc = addSpawn(STEALTH_SHAMAN ? npcs[1] : npcs[0], spawns[i][0], spawns[i][1], spawns[i][2], 0, false, 0, false, world.getInstanceId());
					world.shaman = npc.getObjectId();
				}
				else
				{
					npc = addSpawn(npcs[1], spawns[i][0], spawns[i][1], spawns[i][2], 0, false, 0, false, world.getInstanceId());
					L2Spawn spawn = npc.getSpawn();
					spawn.setRespawnDelay(FIRST_ROOM_RESPAWN_DELAY);
					spawn.setAmount(1);
					spawn.startRespawn();
					world.firstRoom.add(spawn); // store mobs spawns
				}
				npc.setIsNoRndWalk(true);
			}
		}
		
		// second room
		npcs = SECOND_ROOM[index];
		spawns = SECOND_ROOM_SPAWNS[index];
		if (npcs != null)
		{
			world.secondRoom = new ArrayList<Integer>(spawns.length);
			
			for (int[] spawn : spawns)
			{
				npc = addSpawn(npcs[0], spawn[0], spawn[1], spawn[2], 0, false, 0, false, world.getInstanceId());
				npc.setIsNoRndWalk(true);
				world.secondRoom.add(npc.getObjectId());
			}
		}
		
		// miniboss
		if (MINIBOSS[index] != null)
		{
			npc = addSpawn(MINIBOSS[index][0], MINIBOSS[index][1], MINIBOSS[index][2], MINIBOSS[index][3], 0, false, 0, false, world.getInstanceId());
			npc.setIsNoRndWalk(true);
			world.miniBoss = npc.getObjectId();
		}
		
		// escape teleporter
		if (TELEPORTERS[index] != null)
		{
			addSpawn(TELEPORTER, TELEPORTERS[index][0], TELEPORTERS[index][1], TELEPORTERS[index][2], 0, false, 0, false, world.getInstanceId());
		}
		
		// boss
		npc = addSpawn(BOSS[index][0], BOSS[index][1], BOSS[index][2], BOSS[index][3], 0, false, 0, false, world.getInstanceId());
		((L2MonsterInstance) npc).setOnKillDelay(100);
		world.boss = npc;
	}
	
	/**
	 * Handles only player's enter, single parameter - integer RaidTower index
	 */
	@Override
	public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
	{
		if (npc == null)
		{
			return "";
		}
		
		try
		{
			enterInstance(player, Integer.parseInt(event));
		}
		catch (Exception e)
		{
			_log.log(Level.WARNING, "", e);
		}
		return "";
	}
	
	/**
	 * Talk with captains and using of the escape teleporter
	 */
	@Override
	public final String onTalk(L2Npc npc, L2PcInstance player)
	{
		final int npcId = npc.getId();
		
		if (npcId == TELEPORTER)
		{
			final L2Party party = player.getParty();
			// only party leader can talk with escape teleporter
			if ((party != null) && party.isLeader(player))
			{
				final InstanceWorld world = InstanceManager.getInstance().getWorld(npc.getInstanceId());
				if (world instanceof RaidTowerWorld)
				{
					// party members must be in the instance
					if (world.isAllowed(player.getObjectId()))
					{
						Instance inst = InstanceManager.getInstance().getInstance(world.getInstanceId());
						
						// teleports entire party away
						for (L2PcInstance partyMember : party.getMembers())
						{
							if ((partyMember != null) && (partyMember.getInstanceId() == world.getInstanceId()))
							{
								teleportPlayer(partyMember, inst.getSpawnLoc(), 0);
							}
						}
					}
				}
			}
		}
		else
		{
			return npcId + ".htm";
		}
		
		return "";
	}
	
	/**
	 * Only escape teleporters first talk handled
	 */
	@Override
	public final String onFirstTalk(L2Npc npc, L2PcInstance player)
	{
		if (npc.getId() == TELEPORTER)
		{
			if (player.isInParty() && player.getParty().isLeader(player))
			{
				return "80026.htm";
			}
			return "80026-no.htm";
		}
		return "";
	}
	
	@Override
	public final String onKill(L2Npc npc, L2PcInstance player, boolean isSummon)
	{
		final InstanceWorld tmpWorld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
		if (tmpWorld instanceof RaidTowerWorld)
		{
			final RaidTowerWorld world = (RaidTowerWorld) tmpWorld;
			final int objectId = npc.getObjectId();
			
			// first room was spawned ?
			if (world.firstRoom != null)
			{
				// is shaman killed ?
				if ((world.shaman != 0) && (world.shaman == objectId))
				{
					world.shaman = 0;
					// stop respawn of the minions
					for (L2Spawn spawn : world.firstRoom)
					{
						if (spawn != null)
						{
							spawn.stopRespawn();
						}
					}
					world.firstRoom.clear();
					world.firstRoom = null;
					
					if (world.boss != null)
					{
						final int skillId = FIRST_ROOM[world.index][2];
						final int skillLvl = FIRST_ROOM[world.index][3];
						if ((skillId != 0) && (skillLvl != 0))
						{
							final Skill skill = SkillData.getInstance().getSkill(skillId, skillLvl);
							if (skill != null)
							{
								skill.applyEffects(world.boss, world.boss);
							}
						}
					}
					
					return super.onKill(npc, player, isSummon);
				}
			}
			
			// second room was spawned ?
			if (world.secondRoom != null)
			{
				boolean all = true;
				// check for all mobs in the second room
				for (int i = 0; i < world.secondRoom.size(); i++)
				{
					// found killed now mob
					if (world.secondRoom.get(i) == objectId)
					{
						world.secondRoom.set(i, 0);
					}
					else if (world.secondRoom.get(i) != 0)
					{
						all = false;
					}
				}
				// all mobs killed ?
				if (all)
				{
					world.secondRoom.clear();
					world.secondRoom = null;
					
					if (world.boss != null)
					{
						final int skillId = SECOND_ROOM[world.index][1];
						final int skillLvl = SECOND_ROOM[world.index][2];
						if ((skillId != 0) && (skillLvl != 0))
						{
							final Skill skill = SkillData.getInstance().getSkill(skillId, skillLvl);
							if (skill != null)
							{
								skill.applyEffects(world.boss, world.boss);
							}
						}
					}
					
					return super.onKill(npc, player, isSummon);
				}
			}
			
			// miniboss spawned ?
			if ((world.miniBoss != 0) && (world.miniBoss == objectId))
			{
				world.miniBoss = 0;
				
				if (world.boss != null)
				{
					final int skillId = MINIBOSS[world.index][4];
					final int skillLvl = MINIBOSS[world.index][5];
					if ((skillId != 0) && (skillLvl != 0))
					{
						final Skill skill = SkillData.getInstance().getSkill(skillId, skillLvl);
						if (skill != null)
						{
							skill.applyEffects(world.boss, world.boss);
						}
					}
				}
				
				return super.onKill(npc, player, isSummon);
			}
			
			// boss was killed, finish instance
			if ((world.boss != null) && (world.boss == npc))
			{
				world.boss = null;
				finishInstance(world);
			}
		}
		return super.onKill(npc, player, isSummon);
	}
	
	public static void main(String[] args)
	{
		new RaidTower();
	}
}

And parts that i think i should do changes...

private static final int[][] FIRST_ROOM =
	{
		{
			22485,
			22486,
			5699,
			1
		},
		{
			22485,
			22486,
			5699,
			1
		},
		{
			22485,
			22486,
			5699,
			1
		},
		{
			22485,
			22486,
			5699,
			1
		},
		{
			22485,
			22486,
			5699,
			1
		},
	};

_____________________________

private static final int[][] SECOND_ROOM =
	{
		{
			22487,
			5700,
			1
		},
		{
			22490,
			5700,
			2
		},
		{
			22493,
			5700,
			3
		},
		{
			22496,
			5700,
			4
		},
		{
			22499,
			5700,
			5
		}
	};

________________________________________

private static final int[][] MINIBOSS =
	{
		/*intancia 26 */
		{
			25616,
			115376,
			16225,
			-645,
			5701,
			1
		},
		/*intancia 46 */
		{
			25616,
			115376,
			16225,
			-645,
			5701,
			1
		},
		/*intancia 66 */
		{
			25616,
			115376,
			16225,
			-645,
			5701,
			1
		},
		/*intancia 76 */
		{
			25616,
			115376,
			16225,
			-645,
			5701,
			1
		},
		/*intancia 86 */
		{
			25616,
			115376,
			16225,
			-645,
			5701,
			1
		}
	};
	
	/*
	 * Bosses of the RaidTower Instance ends when boss is defeated npcId, x, y, z
	 */
	private static final int[][] BOSS =
	{
		/*intancia 26 */
		{
			18554,
			114671,
			16976,
			928
		},
		/*intancia 46 */
		{
			18555,
			114671,
			16976,
			928
		},
		/*intancia 66 */
		{
			29129,
			114671,
			16976,
			928
		},
		/*intancia 76 */
		{
			18558,
			114671,
			16976,
			928
		},
		/*intancia 86 */
		{
			18559,
			114671,
			16976,
			928
		}
	};
	
	/*
	 * Escape telepoters spawns, null if not spawned x, y, z
	 */
	private static final int[][] TELEPORTERS =
	{
		/*intancia 26 */
		{
			114649,
			17642,
			925
		},
		/*intancia 46 */
		{
			114649,
			17642,
			925
		},
		/*intancia 66 */
		{
			114649,
			17642,
			925
		},
		/*intancia 76 */
		{
			114649,
			17642,
			925
		},
		/*intancia 86 */
		{
			114649,
			17642,
			925
		}
	};

Spawn thing

private final void spawnRaidTower(RaidTowerWorld world)
	{
		int[] npcs;
		int[][] spawns;
		L2Npc npc;
		final int index = world.index;
		
		// first room
		npcs = FIRST_ROOM[index];
		spawns = FIRST_ROOM_SPAWNS[index];
		if (npcs != null)
		{
			world.firstRoom = new ArrayList<L2Spawn>(spawns.length - 1);
			int shaman = getRandom(spawns.length); // random position for shaman
			
			for (int i = 0; i < spawns.length; i++)
			{
				if (i == shaman)
				{
					// stealth shaman use same npcId as other mobs
					npc = addSpawn(STEALTH_SHAMAN ? npcs[1] : npcs[0], spawns[i][0], spawns[i][1], spawns[i][2], 0, false, 0, false, world.getInstanceId());
					world.shaman = npc.getObjectId();
				}
				else
				{
					npc = addSpawn(npcs[1], spawns[i][0], spawns[i][1], spawns[i][2], 0, false, 0, false, world.getInstanceId());
					L2Spawn spawn = npc.getSpawn();
					spawn.setRespawnDelay(FIRST_ROOM_RESPAWN_DELAY);
					spawn.setAmount(1);
					spawn.startRespawn();
					world.firstRoom.add(spawn); // store mobs spawns
				}
				npc.setIsNoRndWalk(true);
			}
		}
		
		// second room
		npcs = SECOND_ROOM[index];
		spawns = SECOND_ROOM_SPAWNS[index];
		if (npcs != null)
		{
			world.secondRoom = new ArrayList<Integer>(spawns.length);
			
			for (int[] spawn : spawns)
			{
				npc = addSpawn(npcs[0], spawn[0], spawn[1], spawn[2], 0, false, 0, false, world.getInstanceId());
				npc.setIsNoRndWalk(true);
				world.secondRoom.add(npc.getObjectId());
			}
		}
		
		// miniboss
		if (MINIBOSS[index] != null)
		{
			npc = addSpawn(MINIBOSS[index][0], MINIBOSS[index][1], MINIBOSS[index][2], MINIBOSS[index][3], 0, false, 0, false, world.getInstanceId());
			npc.setIsNoRndWalk(true);
			world.miniBoss = npc.getObjectId();
		}
		
		// escape teleporter
		if (TELEPORTERS[index] != null)
		{
			addSpawn(TELEPORTER, TELEPORTERS[index][0], TELEPORTERS[index][1], TELEPORTERS[index][2], 0, false, 0, false, world.getInstanceId());
		}
		
		// boss
		npc = addSpawn(BOSS[index][0], BOSS[index][1], BOSS[index][2], BOSS[index][3], 0, false, 0, false, world.getInstanceId());
		((L2MonsterInstance) npc).setOnKillDelay(100);
		world.boss = npc;
	}

Thanks in advance... i have maaany ideas but my java skills are killing meh... i learn so fcking slow

13 answers to this question

Recommended Posts

  • 0
Posted (edited)

Can't understand very clearly that "random spawns"..

 

as u can see there is listed every npc to each room:

 

/**

     * First room information, null if room not spawned.<br>

     * Skill is casted on the boss when shaman is defeated and mobs respawn stopped<br>

     * Default: 5699 (decrease pdef)<br>

     * shaman npcId, minions npcId, skillId, skillLvl

     */

private static final int[][] FIRST_ROOM =

    {

        {                                                            THIS IS FOR instance lvl 26

            22485,

            22486,

            5699,

            1

        },

        {                                                            THIS IS FOR instance lvl 36

            22485,

            22486,

            5699,

            1

        },

 

so i want to change it to 3 or 4 npcs, and when instance start spawns just take 1 of these 4 npc's ids

 

live this

 

{                                                            THIS IS FOR instance lvl 26

            22485, 22486, 5699,1;

            22585, 22586, 5699,1;

            22685, 22686, 5699,1;

        },

        {                                                            THIS IS FOR instance lvl 36

            22485, 22486, 5699,1;

            22585, 22586, 5699,1;

            22685, 22686, 5699,1;

        },

Edited by Rsx - HellaFlush
  • 0
Posted (edited)

Use multiple XML template.

 

You can manage different spawn from there with the same name.

 

You can also spawn any group define in here with 2 lines of code instead of managing ugly array in java.

Edited by Sdw
  • 0
Posted

Small hint, if you really want to use arrays:

import java.util.Random;

public class Test {

	private static final int[][][] FIRST_ROOM =
	{
		{
			{22485, 22486, 5699,1},
			{22585, 22586, 5699,1},
			{22685, 22686, 5699,1}
		},
		{
			{22785, 22786, 5699,1},
			{22885, 22886, 5699,1},
			{22985, 22986, 5699,1}
		}
	};
	
	
	public static void main(String[] args) {
		
		System.out.printf("element[%d] = %s%n", 0, FIRST_ROOM[0][randomTemplate(0, FIRST_ROOM[0].length - 1)][0]);
	}
	
	
	public static int randomTemplate(int min, int max)
	{
	    Random rand = new Random();

	    int randomNum = rand.nextInt((max - min) + 1) + min;

	    return randomNum;
	}
}
  • 0
Posted

Just don't do that :|

 

It's less messier, easier to read, whatever you want to do 2 XML templates and based on which version he wants just load the proper xml.

 

Then having groups like this in his templates :

		<group name="my_first_room_whatever">
			<!-- Krakia Bathus -->
			<spawn npcId="27437" x="-107726" y="209248" z="-10872" heading="49536" respawn="0" allowRandomWalk="false"  />
			<spawn npcId="27437" x="-107926" y="209248" z="-10872" heading="49536" respawn="0" allowRandomWalk="false"  />
			<spawn npcId="27437" x="-108096" y="209248" z="-10872" heading="49536" respawn="0" allowRandomWalk="false"  />
		</group>

with shared names for the first room, he can spawn them using :

final Instance inst = InstanceManager.getInstance().getInstance(world.getInstanceId());
final List<L2Npc> spawnedNpcs = inst.spawnGroup("my_first_room_whatever");
  • 0
Posted (edited)
final Instance inst = InstanceManager.getInstance().getInstance(world.getInstanceId());
final List<L2Npc> spawnedNpcs = inst.spawnGroup("my_first_room_whatever");

 

lmao, you really felt that you had to include the final even in the damn example

Edited by drake2wow
  • 0
Posted (edited)

Or I just made a copy paste

 

Thats an acceptable excuse but the point is, do you and the l2j guys know that final vars inside methods have no performance impact or whatsoever? They are just used for code readability and on rare cases as precompile info for the compiler when in rare cases it will ignore dead code

Edited by drake2wow
  • 0
Posted

We do know what assumed final is, but it's oftenly used for readability in company world. Why not here ?

  • 0
Posted

We do know what assumed final is, but it's oftenly used for readability in company world. Why not here ?

 

I remember back in some l2j refactoring era, they really felt like they had to set everything final

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Posts

    • hello everyone! I am wanting to save the files (Ini. - Data - ) of the EP5 Client: Salvation... But they generate the error "corrupt files"... I tried several versions of L2FileEditor without good results. I need help! Thank you!
    • Opening December 6th at 19:00 (GMT +3)! Open Beta Test from November 30th!   https://l2soe.com/   🌟 Introducing L2 Saga of Eternia: A Revolution in Lineage 2 High Five! 🌟   Dear Lineage 2 enthusiasts, Prepare to witness the future of private servers! L2 Saga of Eternia is not just another High Five project—it’s a game-changing experience designed to compete with the giants of the Lineage 2 private server scene. Built for the community, by the community, we’re here to raise the bar in quality, innovation, and longevity. What Sets Us Apart? 💎 No Wipes, Ever Say goodbye to the fear of losing your progress. Our server is built to last and will never close. Stability and consistency are our promises to you. ⚔️ Weekly New Content Our dedicated development team ensures fresh challenges, events, and updates every week. From custom quests to exclusive features, there will always be something exciting to explore. 💰 No Pay-to-Win Skill and strategy matter most here. Enjoy a balanced gameplay environment where your achievements come from effort, not your wallet. 🌍 A Massive Community With 2000+ players expected, join a vibrant and active community of like-minded adventurers ready to conquer the world of Aden. 🏆 Fair and Competitive Gameplay Our systems are designed to promote healthy competition while avoiding abusive mechanics and exploits. 🔧 Professional Development From advanced bug fixes to carefully curated content, we pride ourselves on smooth performance, no lag, and unparalleled server quality. Key Features Chronicle: High Five with unique interface Rate: Dynamic x10 rates Class Balance: Carefully fine-tuned for a fair experience PvP Focused: PvP Ranking & aura display effect for 3 Top PvPers every week Custom Events: Seasonal and permanent events to keep you engaged Additional Features:   Custom Endgame Content: Introduce unique dungeons, raids, or zones unavailable in other servers. Player-Driven Economy: Implement a strong market system and avoid overinflated drops or rewards. Epic Siege Battles: Announce special large-scale sieges and PvP events. Incentives for Streamers and Clans: Attract influencers and big clans to boost server publicity. Roadmap Transparency: Share a public roadmap of planned updates to build trust and excitemen   Here you can read all the features: https://l2soe.com/features   Video preview: Join the Revolution! This is your chance to be part of something legendary. L2 Saga of Eternia is not just a server; it’s a movement to redefine what Lineage 2 can be. Whether you’re a seasoned veteran or a newcomer to the world of Aden, we invite you to experience Lineage 2 at its finest.   Official Launch Date: December 6th 2024 Website: https://l2soe.com/ Facebook: https://www.facebook.com/l2soe Discord: https://discord.com/invite/l2eternia   Let’s build the ultimate Lineage 2 experience together. See you in-game! 🎮
    • That's like a tutorial on how to run l2 on MacOS Xd but good job for the investigation. 
    • small update: dc robe set sold   wts adena 1kk = 1.5$ 
    • DISCORD : utchiha_market telegram : https://t.me/utchiha_market SELLIX STORE : https://utchihamkt.mysellix.io/ Join our server for more products : https://discord.gg/hood-services https://campsite.bio/utchihaamkt
  • Topics

×
×
  • Create New...