Code summon

  • Автор темы Автор темы lBrazza
  • Дата начала Дата начала

lBrazza

Знаменитый
Местный
Сообщения
48
Розыгрыши
0
Репутация
0
Реакции
20
Баллы
1 298
I'm creating a system to summon items for my server from an NPC, this is a fraction of the code, I would like validation and what I can improve and I would also like to know a method of canceling the cast using the "Esc" key " or by debuffs, I've tried some metrics but it doesn't work.

@Override
public String onFirstTalk(L2Npc npc, L2PcInstance player)
{
if (!bauConfigs.containsKey(npc.getId()))
{
return null;
}
final BauConfig config = bauConfigs.get(npc.getId());

// If the player is already casting, ignore the interaction
if (player.isCastingNow() || player.isCastingSimultaneouslyNow())
{
return null;
}

// Reposition the player close to the chest, if necessary
// (This part can be adjusted or removed depending on the desired behavior)
int npcX = npc.getX(), npcY = npc.getY(), npcZ = npc.getZ();
int distance = 50;
int newX = npcX + (int) (distance * Math.cos(Math.toRadians(player.getHeading())));
int newY = npcY + (int) (distance * Math.sin(Math.toRadians(player.getHeading())));
player.moveToLocation(newX, newY, npcZ, 0);

// Obtains the summon skill (ID 246, level 1) and starts the player cast
final L2Skill summonSkill = SkillData.getInstance().getSkill(246, 1);
if (summonSkill == null)
{
LOGGER.warning("Summoning skill (246, 1) not found!");
return null;
}
player.getAI().setIntention(CtrlIntention.AI_INTENTION_CAST, summonSkill, npc);
player.setIsCastingNow(true);

// Triggers skill animation for NPC and player
npc.broadcastPacket(new MagicSkillUse(npc, npc, 246, 1, 8000, 0));
player.broadcastPacket(new MagicSkillUse(player, player, 246, 1, 8000, 0));

ThreadPoolManager.getInstance().scheduleGeneral(() ->
{
if ((player.getTarget() == null) || !player.getTarget().equals(npc))
{
cancelCast(player);
}
} , 1000); // Check every second

// Schedule discard processing after 8 seconds (cast time)
ThreadPoolManager.getInstance().scheduleGeneral(() ->
{
if (player.isCastingNow())
{
player.setIsCastingNow(false);
processDrop(npc, player, config);

}
} , 8000);

// Returns null to not display standard HTML
return null;
}
 
Назад
Сверху