테스트

aion-server 4.8

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

import java.lang.reflect.Field;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.LoggerFactory;

import com.aionemu.gameserver.ai.*;
import com.aionemu.gameserver.ai.event.AIEventLog;
import com.aionemu.gameserver.ai.event.AIEventType;
import com.aionemu.gameserver.configs.main.AIConfig;
import com.aionemu.gameserver.model.animations.ObjectDeleteAnimation;
import com.aionemu.gameserver.model.gameobjects.Creature;
import com.aionemu.gameserver.model.gameobjects.VisibleObject;
import com.aionemu.gameserver.model.gameobjects.player.Player;
import com.aionemu.gameserver.network.aion.serverpackets.SM_SYSTEM_MESSAGE;
import com.aionemu.gameserver.utils.PacketSendUtility;
import com.aionemu.gameserver.utils.chathandlers.AdminCommand;
import com.aionemu.gameserver.world.World;

/**
 * @author ATracer, Neon
 */
public class Ai extends AdminCommand {

	public Ai() {
		super("ai", "Modifies and shows AI details.");

		// @formatter:off
		setSyntaxInfo(
			"<info> - Show AI info for your target.",
			"<set> <aiName> - Changes the AI of your target.",
			"<state> <stateName> [substateName] - Changes the AI state.",
			"<event> <eventName> - Fires the AI event for the given name.",
			"<event2> <eventName> <creatureObjId> - Fires the creature AI event for the given name and creature.",
			"<events> - Shows last AI events for your target.",
			"<log> - Toggles AI logging for your target on and off.",
			"<createlog|eventlog|movelog> - Toggles logging on and off.",
			"<marker> [text] - Prints a marker with the optional text in log."
		);
		// @formatter:on
	}

	@Override
	public void execute(Player admin, String... params) {
		if (params.length == 0) {
			sendInfo(admin);
			return;
		}

		if (params[0].equalsIgnoreCase("createlog")) {
			AIConfig.ONCREATE_DEBUG = !AIConfig.ONCREATE_DEBUG;
			sendInfo(admin, "New createlog value: " + AIConfig.ONCREATE_DEBUG);
		} else if (params[0].equalsIgnoreCase("eventlog")) {
			AIConfig.EVENT_DEBUG = !AIConfig.EVENT_DEBUG;
			sendInfo(admin, "New eventlog value: " + AIConfig.EVENT_DEBUG);
		} else if (params[0].equalsIgnoreCase("movelog")) {
			AIConfig.MOVE_DEBUG = !AIConfig.MOVE_DEBUG;
			sendInfo(admin, "New movelog value: " + AIConfig.MOVE_DEBUG);
		} else if (params[0].equalsIgnoreCase("marker")) {
			if (params.length > 1)
				LoggerFactory.getLogger(AILogger.class).info("[AI] marker: " + StringUtils.join(params, ' ', 1, params.length));
			else
				LoggerFactory.getLogger(AILogger.class).info("[AI] marker");
		} else {
			VisibleObject target = admin.getTarget();
			if (target == null || !(target instanceof Creature)) {
				PacketSendUtility.sendPacket(admin, SM_SYSTEM_MESSAGE.STR_INVALID_TARGET());
				return;
			}
			Creature npc = (Creature) target;

			if (params[0].equalsIgnoreCase("info")) {
				sendInfo(admin,
					"[AI info]\n\tName: " + npc.getAi().getName() + "\n\tState: " + npc.getAi().getState() + "\n\tSubstate: " + npc.getAi().getSubState());
			} else if (params[0].equalsIgnoreCase("log")) {
				boolean oldValue = npc.getAi().isLogging();
				npc.getAi().setLogging(!oldValue);
				sendInfo(admin, "New log value: " + !oldValue);
			} else if (params[0].equalsIgnoreCase("events")) {
				AIEventLog eventLog = npc.getAi().getEventLog();
				if (eventLog == null || eventLog.isEmpty()) {
					sendInfo(admin, "No events logged" + (AIConfig.EVENT_DEBUG ? "" : " (enable event logging via eventlog parameter)"));
				} else {
					for (AIEventType eventType : eventLog) {
						sendInfo(admin, "EVENT: " + eventType.name());
					}
				}
			} else if (params.length > 1) {
				String param1 = params[1];
				if (params[0].equalsIgnoreCase("set")) {
					String aiName = param1;
					try {
						AI newAi = AIEngine.getInstance().newAI(aiName, npc);
						try {
							Field aiField = npc.getClass().getSuperclass().getDeclaredField("ai");
							aiField.setAccessible(true);
							World.getInstance().despawn(npc, ObjectDeleteAnimation.NONE);
							aiField.set(npc, newAi);
							World.getInstance().spawn(npc); // properly init AI states
						} catch (NoSuchFieldException | SecurityException | IllegalAccessException e) {
							LoggerFactory.getLogger(Ai.class).error("", e);
						}
						if (npc.getAi() == newAi)
							sendInfo(admin, "Npc now has AI " + newAi.getClass().getSimpleName());
						else
							sendInfo(admin, "Error changing AI (see logs)");
					} catch (IllegalArgumentException e) {
						sendInfo(admin, e.getMessage());
					}
				} else if (params[0].equalsIgnoreCase("event")) {
					try {
						AIEventType eventType = AIEventType.valueOf(param1.toUpperCase());
						npc.getAi().onGeneralEvent(eventType);
					} catch (IllegalArgumentException e) {
						sendInfo(admin, "Found no event with that name");
					}
				} else if (params[0].equalsIgnoreCase("event2")) {
					Creature creature = params.length < 3 ? null : (Creature) World.getInstance().findVisibleObject(Integer.valueOf(params[2]));
					if (creature == null)
						sendInfo(admin, "Please provide a valid creature object ID");
					else {
						try {
							AIEventType eventType = AIEventType.valueOf(param1.toUpperCase());
							npc.getAi().onCreatureEvent(eventType, creature);
						} catch (IllegalArgumentException e) {
							sendInfo(admin, "Found no event with that name");
						}
					}
				} else if (params[0].equalsIgnoreCase("state")) {
					AIState state = null;
					try {
						state = AIState.valueOf(param1.toUpperCase());
						npc.getAi().setStateIfNot(state);
						if (params.length > 2) {
							AISubState substate = AISubState.valueOf(params[2]);
							npc.getAi().setSubStateIfNot(substate);
						}
					} catch (IllegalArgumentException e) {
						sendInfo(admin, "Found no " + (state == null ? "state" : "substate") + " with that name");
					}
				}
			} else {
				sendInfo(admin);
			}
		}
	}

}

📎 첨부파일

댓글 작성 권한이 없습니다.
🏆 포인트 랭킹 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