테스트

aion-server 4.8

Gitteol
최고관리자 · 1 · 💬 0 클론/새로받기
 4.8 61f661d · 1 commits 새로받기(Pull)
game-server/data/handlers/ai/ConquestOfferingPortalAI.java
package ai;

import java.util.List;
import java.util.stream.Collectors;

import com.aionemu.commons.utils.Rnd;
import com.aionemu.gameserver.ai.AIName;
import com.aionemu.gameserver.dataholders.DataManager;
import com.aionemu.gameserver.model.TaskId;
import com.aionemu.gameserver.model.animations.TeleportAnimation;
import com.aionemu.gameserver.model.gameobjects.Npc;
import com.aionemu.gameserver.model.gameobjects.player.Player;
import com.aionemu.gameserver.model.templates.spawns.SpawnGroup;
import com.aionemu.gameserver.model.templates.spawns.SpawnTemplate;
import com.aionemu.gameserver.services.teleport.TeleportService;
import com.aionemu.gameserver.utils.PositionUtil;
import com.aionemu.gameserver.utils.ThreadPoolManager;

/**
 * @author Yeats, Sykra
 */
@AIName("conquest_offering_portal")
public class ConquestOfferingPortalAI extends ActionItemNpcAI {

	private SpawnTemplate targetLocation;

	public ConquestOfferingPortalAI(Npc owner) {
		super(owner);
	}

	@Override
	public void handleSpawned() {
		super.handleSpawned();
		targetLocation = findTargetLocation();
		getOwner().getController().addTask(TaskId.DESPAWN, ThreadPoolManager.getInstance().schedule(() -> getOwner().getController().delete(), 65000));
	}

	@Override
	protected void handleUseItemFinish(Player player) {
		if (targetLocation != null)
			TeleportService.teleportTo(player, targetLocation.getWorldId(), targetLocation.getX(), targetLocation.getY(), targetLocation.getZ(),
				targetLocation.getHeading(), TeleportAnimation.FADE_OUT_BEAM);
	}

	private SpawnTemplate findTargetLocation() {
		int npcId = getNpcId() == 833018 ? 856412 : 856433;
		SpawnGroup spawnGroup = Rnd.get(DataManager.SPAWNS_DATA.getSpawnsForNpc(getOwner().getWorldId(), npcId));
		if (spawnGroup != null) {
			SpawnTemplate targetLocation = null;
			Npc creator = findCreatorNpc();
			if (creator != null) {
				SpawnTemplate creatorTemplate = creator.getSpawn();
				// exclude all teleport templates within a 50m range around the creator spawn template
				// to prevent teleportation to the killed conquest npc (creator of this npc)
				List<SpawnTemplate> spawnTemplates = spawnGroup.getSpawnTemplates().stream()
					.filter(teleportTemplate -> !PositionUtil.isInRange(teleportTemplate.getX(), teleportTemplate.getY(), teleportTemplate.getZ(),
						creatorTemplate.getX(), creatorTemplate.getY(), creatorTemplate.getZ(), 50))
					.collect(Collectors.toList());
				targetLocation = Rnd.get(spawnTemplates);
			}
			if (targetLocation != null)
				return targetLocation;
			return Rnd.get(spawnGroup.getSpawnTemplates());
		}
		return null;
	}

	private Npc findCreatorNpc() {
		if (getCreatorId() != 0 && getPosition().getWorldMapInstance().getObject(getCreatorId()) instanceof Npc npc)
			return npc;
		return null;
	}

}

📎 첨부파일

댓글 작성 권한이 없습니다.
🏆 포인트 랭킹 TOP 10
순위 닉네임 포인트
1 no_profile 타키야겐지쪽지보내기 자기소개 아이디로 검색 전체게시물 100,792
2 no_profile 동가리쪽지보내기 자기소개 아이디로 검색 전체게시물 58,079
3 no_profile 라프텔쪽지보내기 자기소개 아이디로 검색 전체게시물 51,771
4 no_profile 불멸의행복쪽지보내기 자기소개 아이디로 검색 전체게시물 36,923
5 서번트쪽지보내기 자기소개 아이디로 검색 전체게시물 35,011
6 no_profile 보거스쪽지보내기 자기소개 아이디로 검색 전체게시물 29,969
7 no_profile 닥터스쪽지보내기 자기소개 아이디로 검색 전체게시물 29,470
8 no_profile 검은고양이쪽지보내기 자기소개 아이디로 검색 전체게시물 29,077
9 no_profile Revolution쪽지보내기 자기소개 아이디로 검색 전체게시물 28,199
10 no_profile 호롤롤로쪽지보내기 자기소개 아이디로 검색 전체게시물 17,020
알림 0