테스트

aion-server 4.8

Gitteol
최고관리자 · 1 · 💬 0 클론/새로받기
 4.8 61f661d · 1 commits 새로받기(Pull)
game-server/src/com/aionemu/gameserver/ai/handler/ShoutEventHandler.java
package com.aionemu.gameserver.ai.handler;

import java.util.ArrayList;
import java.util.List;

import com.aionemu.commons.utils.Rnd;
import com.aionemu.gameserver.ai.NpcAI;
import com.aionemu.gameserver.ai.poll.AIQuestion;
import com.aionemu.gameserver.dataholders.DataManager;
import com.aionemu.gameserver.model.gameobjects.Creature;
import com.aionemu.gameserver.model.gameobjects.Npc;
import com.aionemu.gameserver.model.gameobjects.player.Player;
import com.aionemu.gameserver.model.templates.npcshout.NpcShout;
import com.aionemu.gameserver.model.templates.npcshout.ShoutEventType;
import com.aionemu.gameserver.model.templates.walker.WalkerTemplate;
import com.aionemu.gameserver.services.NpcShoutsService;

/**
 * @author Rolandas, Neon
 */
public final class ShoutEventHandler {

	public static void onSee(NpcAI npcAI, Creature target) {
		if (target instanceof Player && npcAI.ask(AIQuestion.CAN_SHOUT)) {
			Npc npc = npcAI.getOwner();
			List<NpcShout> shouts = DataManager.NPC_SHOUT_DATA.getNpcShouts(npc.getPosition().getMapId(), npc.getNpcId(), ShoutEventType.SEE);
			NpcShoutsService.getInstance().shoutRandom(npc, (Player) target, shouts, 0);
		}
	}

	public static void onSpawn(NpcAI npcAI) {
		if (npcAI.ask(AIQuestion.CAN_SHOUT)) {
			Npc npc = npcAI.getOwner();
			NpcShoutsService.getInstance().registerShoutTask(npc);
		}
	}

	public static void onBeforeDespawn(NpcAI npcAI) {
		if (npcAI.ask(AIQuestion.CAN_SHOUT)) {
			Npc npc = npcAI.getOwner();
			List<NpcShout> shouts = DataManager.NPC_SHOUT_DATA.getNpcShouts(npc.getPosition().getMapId(), npc.getNpcId(), ShoutEventType.BEFORE_DESPAWN);
			NpcShoutsService.getInstance().shoutRandom(npc, null, shouts, 0);
			NpcShoutsService.getInstance().removeShoutCooldown(npc);
		}
	}

	public static void onReachedWalkPoint(NpcAI npcAI) {
		if (npcAI.ask(AIQuestion.CAN_SHOUT)) {
			Npc npc = npcAI.getOwner();
			String walkerId = npc.getSpawn().getWalkerId();
			if (walkerId == null)
				return;
			ShoutEventType shoutType = npc.getMoveController().isChangingDirection() ? ShoutEventType.WALK_DIRECTION : ShoutEventType.WALK_WAYPOINT;
			List<NpcShout> shouts = DataManager.NPC_SHOUT_DATA.getNpcShouts(npc.getPosition().getMapId(), npc.getNpcId(), shoutType);
			if (shouts == null || shouts.isEmpty()) {
				WalkerTemplate tp = DataManager.WALKER_DATA.getWalkerTemplate(walkerId);
				int stepCount = tp.getRouteSteps().size();
				if (Rnd.nextInt(stepCount) < 2) {
					if (npc.getTarget() instanceof Player)
						NpcShoutsService.getInstance().shoutRandom(npc, (Player) npc.getTarget(), shouts, 0);
					else
						NpcShoutsService.getInstance().shoutRandom(npc, null, shouts, 0);
				}
			}
		}
	}

	public static void onSwitchedTarget(NpcAI npcAI, Creature target) {
		if (target instanceof Player && npcAI.ask(AIQuestion.CAN_SHOUT)) {
			Npc npc = npcAI.getOwner();
			List<NpcShout> shouts = DataManager.NPC_SHOUT_DATA.getNpcShouts(npc.getPosition().getMapId(), npc.getNpcId(), ShoutEventType.SWITCH_TARGET);
			NpcShoutsService.getInstance().shoutRandom(npc, (Player) target, shouts, 0);
		}
	}

	public static void onDied(NpcAI npcAI) {
		if (npcAI.ask(AIQuestion.CAN_SHOUT)) {
			Npc npc = npcAI.getOwner();
			List<NpcShout> shouts = DataManager.NPC_SHOUT_DATA.getNpcShouts(npc.getPosition().getMapId(), npc.getNpcId(), ShoutEventType.DIED);
			NpcShoutsService.getInstance().shoutRandom(npc, null, shouts, 0);
		}
	}

	/**
	 * Called on Aggro when NPC is ready to attack
	 */
	public static void onAttackBegin(NpcAI npcAI) {
		if (npcAI.ask(AIQuestion.CAN_SHOUT)) {
			Npc npc = npcAI.getOwner();
			List<NpcShout> shouts = DataManager.NPC_SHOUT_DATA.getNpcShouts(npc.getPosition().getMapId(), npc.getNpcId(), ShoutEventType.ATTACK_BEGIN);
			NpcShoutsService.getInstance().shoutRandom(npc, null, shouts, 0);
		}
	}

	/**
	 * Handle NPC attacked event (when damage was received or not)
	 */
	public static void onEnemyAttack(NpcAI npcAI, Creature attacker) {
		// TODO: [RR] change AI or randomize behavior for "cowards" and "fanatics" ???
		// TODO: Figure out what the difference between ATTACK_BEGIN and HELP; HELPCALL should make NPC run
		if (npcAI.ask(AIQuestion.CAN_SHOUT)) {
			Npc npc = npcAI.getOwner();
			if (attacker.getActingCreature() instanceof Player) {
				if (npc.getAttackedCount() == 0) {
					List<NpcShout> shouts = DataManager.NPC_SHOUT_DATA.getNpcShouts(npc.getPosition().getMapId(), npc.getNpcId(), ShoutEventType.ATTACKED);
					if (shouts != null && !shouts.isEmpty()) {
						NpcShoutsService.getInstance().shoutRandom(npc, (Player) attacker.getActingCreature(), shouts, 0);
						return;
					}
					shouts = DataManager.NPC_SHOUT_DATA.getNpcShouts(npc.getPosition().getMapId(), npc.getNpcId(), ShoutEventType.HELPCALL);
					NpcShoutsService.getInstance().shoutRandom(npc, (Player) attacker.getActingCreature(), shouts, 0);
				}
			} else {
				List<NpcShout> shouts = DataManager.NPC_SHOUT_DATA.getNpcShouts(npc.getPosition().getMapId(), npc.getNpcId(), ShoutEventType.ATTACKED);
				if (shouts != null && !shouts.isEmpty()) {
					NpcShout shout = Rnd.get(shouts);
					NpcShoutsService.getInstance().shout(npc, null, shout, shout.getPollDelay() / 1000);
				}
			}
		}
	}

	public static void onCast(NpcAI npcAI, Creature firstTarget) {
		if (firstTarget instanceof Player && npcAI.ask(AIQuestion.CAN_SHOUT))
			handleNumericEvent(npcAI, (Player) firstTarget, ShoutEventType.CAST_K);
	}

	/**
	 * Handle target attacked events
	 */
	public static void onAttack(NpcAI npcAI, Creature attacked) {
		if (attacked instanceof Player && npcAI.ask(AIQuestion.CAN_SHOUT))
			handleNumericEvent(npcAI, (Player) attacked, ShoutEventType.ATTACK_K);
	}

	private static void handleNumericEvent(NpcAI npcAI, Player creature, ShoutEventType eventType) {
		Npc npc = npcAI.getOwner();
		List<NpcShout> shouts = DataManager.NPC_SHOUT_DATA.getNpcShouts(npc.getPosition().getMapId(), npc.getNpcId(), eventType);
		if (shouts == null || shouts.isEmpty())
			return;

		List<NpcShout> validShouts = new ArrayList<>();
		List<NpcShout> nonNumberedShouts = new ArrayList<>();
		for (NpcShout shout : shouts) {
			if (shout.getSkillNo() == 0)
				nonNumberedShouts.add(shout);
			else if (shout.getSkillNo() == npc.getSkillNumber())
				validShouts.add(shout);
		}

		NpcShoutsService.getInstance().shoutRandom(npc, creature, !validShouts.isEmpty() ? validShouts : nonNumberedShouts, 0);
	}

	public static void onAttackEnd(NpcAI npcAI) {
		if (npcAI.ask(AIQuestion.CAN_SHOUT)) {
			Npc npc = npcAI.getOwner();
			List<NpcShout> shouts = DataManager.NPC_SHOUT_DATA.getNpcShouts(npc.getPosition().getMapId(), npc.getNpcId(), ShoutEventType.ATTACK_END);
			NpcShoutsService.getInstance().shoutRandom(npc, null, shouts, 0);
		}
	}
}

📎 첨부파일

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