Hello everyone, here is the working AI for PlainsOfDion, works almost as I saw on the PTS.
PlainsOfDion.java
Also pay attention to our project has a nuance with the work of the AI, at 1 start of the server if the player is in the location where the AI operates then the full working capacity of the AI will come after 1 death of each monster, if it's easier until you kill all the monsters at least 1 time AI will work as it should.
PlainsOfDion.java
- Code:
/*
* Copyright (C) 2004-2015 L2J DataPack
*
* This file is part of L2J DataPack.
*
* L2J DataPack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* L2J DataPack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package ai.group_template;
import net.sf.l2j.gameserver.ai.CtrlIntention;
import net.sf.l2j.gameserver.geoengine.GeoData;
import net.sf.l2j.gameserver.model.L2Character;
import net.sf.l2j.gameserver.model.L2Object;
import net.sf.l2j.gameserver.model.L2Skill;
import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
import net.sf.l2j.gameserver.model.actor.instance.L2MonsterInstance;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
import net.sf.l2j.gameserver.model.quest.Quest;
import net.sf.l2j.gameserver.util.Util;
import net.sf.l2j.util.Rnd;
/**
* AI for mobs in Plains of Dion (near Floran Village).
* for L2jLisvus
*/
public final class PlainsOfDion extends Quest
{
private static final int DELU_LIZARDMEN[] =
{
1104, // Delu Lizardman Supplier
1105, // Delu Lizardman Special Agent
1107, // Delu Lizardman Commander
};
private static final String[] MONSTERS_MSG =
{
"$s1! How dare you interrupt our fight ? Hey guys help!",
"$s1! Hey, we are having a duel here!",
"The duel is over, attack!!",
"Foul, kill the coward!",
"How dare you interrupt a sacred duel? You must be taught a lesson!"
};
private static final String[] MONSTERS_ASSIST_MSG =
{
"Die, you coward!",
"Kill the coward!",
"What are you looking at?!"
};
private PlainsOfDion()
{
super(-1, "plainsofdion", "ai/group_template");
registerMobs(DELU_LIZARDMEN);
}
@Override
public String onSpawn(L2NpcInstance npc)
{
if (npc.getScriptValue() > 0)
{
npc.setScriptValue(0);
}
return super.onSpawn(npc);
}
@Override
public String onAttack(L2NpcInstance npc, L2PcInstance player, int damage, boolean isPet)
{
if (npc.getScriptValue() == 0)
{
if (Rnd.get(100) <= 15)
{
final int i = Rnd.get(5);
if (i < 2)
{
npc.broadcastPacket(new CreatureSay(npc.getObjectId(), 0, npc.getName(), MONSTERS_MSG[i], player.getName()));
}
else
{
npc.broadcastPacket(new CreatureSay(npc.getObjectId(), 0, npc.getName(), MONSTERS_MSG[i]));
}
for (L2Character obj : npc.getKnownList().getKnownCharactersInRadius(300))
{
if (obj == null || !(obj instanceof L2MonsterInstance))
continue;
if (Util.contains(DELU_LIZARDMEN, npc.getNpcId()) && !obj.isAttackingNow() && !obj.isDead() && GeoData.getInstance().canSeeTarget(npc, obj))
{
final L2MonsterInstance monster = (L2MonsterInstance) obj;
monster.setRunning();
monster.addDamageHate(player, 0, 100);
monster.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, player);
monster.broadcastPacket(new CreatureSay(monster.getObjectId(), 0, monster.getName(), (MONSTERS_ASSIST_MSG[Rnd.get(3)])));
}
}
}
npc.setScriptValue(1);
}
return super.onAttack(npc, player, damage, isPet);
}
@Override
public String onSkillSee(L2NpcInstance npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isPet)
{
if (skill.isOffensive() && targets[0] == npc && npc.getScriptValue() == 0)
{
if (Rnd.get(100) <= 15)
{
final int i = Rnd.get(5);
if (i < 2)
{
npc.broadcastPacket(new CreatureSay(npc.getObjectId(), 0, npc.getName(), MONSTERS_MSG[i], caster.getName()));
}
else
{
npc.broadcastPacket(new CreatureSay(npc.getObjectId(), 0, npc.getName(), MONSTERS_MSG[i]));
}
for (L2Character obj : npc.getKnownList().getKnownCharactersInRadius(300))
{
if (obj == null || !(obj instanceof L2MonsterInstance))
continue;
if (Util.contains(DELU_LIZARDMEN, npc.getNpcId()) && !obj.isAttackingNow() && !obj.isDead() && GeoData.getInstance().canSeeTarget(npc, obj))
{
final L2MonsterInstance monster = (L2MonsterInstance) obj;
monster.setRunning();
monster.addDamageHate(caster, 0, 100);
monster.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, caster);
monster.broadcastPacket(new CreatureSay(monster.getObjectId(), 0, monster.getName(), (MONSTERS_ASSIST_MSG[Rnd.get(3)])));
}
}
}
npc.setScriptValue(1);
}
return super.onSkillSee(npc, caster, skill, targets, isPet);
}
public static void main(String[] args)
{
new PlainsOfDion();
}
}
Also pay attention to our project has a nuance with the work of the AI, at 1 start of the server if the player is in the location where the AI operates then the full working capacity of the AI will come after 1 death of each monster, if it's easier until you kill all the monsters at least 1 time AI will work as it should.
Last edited by xlinkinx on 23rd July 2019, 13:33; edited 1 time in total