Seperated AI for mobs inside Ant Nest (Incubator).
Going to get rid of "polymorphing_onAttack.py"
Going to get rid of "polymorphing_onAttack.py"
- Code:
Index: polymorphing_onAttack.py
===================================================================
--- polymorphing_onAttack.py (revision 627)
+++ polymorphing_onAttack.py (working copy)
@@ -9,12 +9,7 @@
self.MobSpawns ={
1261: [1262, 100, 20], #Ol Mahum Transcender 1st stage
1262: [1263, 100, 10], #Ol Mahum Transcender 2st stage
1263: [1264, 100, 5], #Ol Mahum Transcender 3rd stage
- 1265: [1271, 100, 33], #Cave Ant Larva -> Cave Ant
- 1266: [1269, 100, 100], #Cave Ant Larva -> Cave Ant (always polymorphs)
- 1267: [1270, 100, 100], #Cave Ant Larva -> Cave Ant Soldier (always polymorphs)
- 1271: [1272, 66, 10], #Cave Ant -> Cave Ant Soldier
- 1272: [1273, 33, 5] #Cave Ant Soldier -> Cave Noble Ant
}
# finally, don't forget to call the parent constructor to prepare the event triggering
# mechanisms etc.
- Code:
/*
* This program 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.
*
* This program 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 java.util.HashMap;
import java.util.Map;
import net.sf.l2j.gameserver.ai.CtrlIntention;
import net.sf.l2j.gameserver.model.L2Attackable;
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.L2PcInstance;
import net.sf.l2j.gameserver.model.quest.Quest;
import net.sf.l2j.util.Rnd;
/**
* @author Karakan
*
*/
public class AntNest extends Quest
{
private static final Map<Integer,Integer[]> POLYMORPHING_ANTS = new HashMap<>();
static
{
POLYMORPHING_ANTS.put(1265, new Integer[]{1271, 33}); // Cave Ant Larva -> Cave Ant
POLYMORPHING_ANTS.put(1266, new Integer[]{1269, 100}); // Cave Ant Larva -> Cave Ant (always polymorphs)
POLYMORPHING_ANTS.put(1267, new Integer[]{1270, 100}); // Cave Ant Larva -> Cave Ant Soldier (always polymorphs)
POLYMORPHING_ANTS.put(1271, new Integer[]{1272, 10}); // Cave Ant -> Cave Ant Soldier
POLYMORPHING_ANTS.put(1272, new Integer[]{1273, 5}); // Cave Ant Soldier -> Cave Noble Ant
}
public AntNest (int questId, String name, String descr)
{
super(questId, name, descr);
int[] mobs =
{
1265, 1266, 1267, 1271, 1272
};
registerMobs(mobs);
}
@Override
public String onSpawn(L2NpcInstance npc)
{
if (npc.getScriptValue() > 0)
{
npc.setScriptValue(0);
}
return super.onSpawn(npc);
}
@Override
public String onSkillSee(L2NpcInstance npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isPet)
{
if (skill.isOffensive() && targets[0] == npc)
{
Integer[] spawnData = POLYMORPHING_ANTS.get(npc.getNpcId());
if (POLYMORPHING_ANTS.containsKey(npc.getNpcId()) && Rnd.get(100) <= spawnData[1] && npc.getCurrentHp() / npc.getMaxHp() < 0.5)
{
npc.onDecay();
L2Attackable newNpc = (L2Attackable) addSpawn (spawnData[0], npc.getX(), npc.getY(), npc.getZ(), npc.getHeading(), false, 0);
if (caster.getTarget() == npc)
{
newNpc.onAction(caster);
}
newNpc.setRunning();
L2Character originalCaster = isPet ? caster.getPet() : caster;
if (originalCaster != null)
{
newNpc.addDamageHate(originalCaster, 0, 100);
newNpc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, originalCaster);
}
}
}
return super.onSkillSee(npc, caster, skill, targets, isPet);
}
@Override
public String onAttack (L2NpcInstance npc, L2PcInstance attacker, int damage, boolean isPet)
{
Integer[] spawnData = POLYMORPHING_ANTS.get(npc.getNpcId());
if (POLYMORPHING_ANTS.containsKey(npc.getNpcId()) && Rnd.get(100) <= spawnData[1] && npc.getCurrentHp() / npc.getMaxHp() < 0.5)
{
npc.onDecay();
L2Attackable newNpc = (L2Attackable) addSpawn (spawnData[0], npc.getX(), npc.getY(), npc.getZ(), npc.getHeading(), false, 0);
if (attacker.getTarget() == npc)
{
newNpc.onAction(attacker);
}
newNpc.setRunning();
L2Character originalAttacker = isPet ? attacker.getPet() : attacker;
if (originalAttacker != null)
{
newNpc.addDamageHate(originalAttacker, 0, 100);
newNpc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, originalAttacker);
}
}
return super.onAttack(npc, attacker, damage, isPet);
}
public static void main(String[] args)
{
// Quest class and state definition
new AntNest(-1, "antnest", "ai/group_template");
}
}