L2JMobius

High Five Lucky Pig

tomalko · 2 · 2101

Online tomalko

  • Heir
  • **
    • Posts: 12
Do not judge strictly. redesigned script from l2j... When killing a monster, Lucky Pig comes out

game\data\stats\npcs\02500-02599.xml
Code: [Select]
<?xml version="1.0" encoding="UTF-8"?>
<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../xsd/npcs.xsd">
<npc id="2501" level="80" type="Npc" name="Lucky Pig" title="The Spirit of Fortune">
<!-- TODO: Must be confirmed -->
<sex>MALE</sex>
<stats str="10" int="10" dex="10" wit="10" con="10" men="10">
<vitals hp="2444" mp="2444.0" />
<attack physical="500" magical="500" attackSpeed="278" range="40" />
<defence physical="500" magical="500" />
<attribute>
<defence fire="20" water="20" wind="20" earth="20" holy="20" dark="20" />
</attribute>
<speed>
<walk ground="60" />
<run ground="160" />
</speed>
</stats>
<skillList>
<skill id="4416" level="3" /> <!-- Beasts -->
<skill id="23325" level="1" /> <!-- Enlarge - Luckpy -->
<skill id="23326" level="1" /> <!-- Reduce - Luckpy -->
</skillList>
<collision>
<radius normal="25" />
<height normal="18" />
</collision>
</npc>
<npc id="2502" level="80" type="Monster" name="Wingless Lucky Pig">
<!-- TODO: Must be confirmed -->
<sex>MALE</sex>
<stats str="10" int="10" dex="10" wit="10" con="10" men="10">
<vitals hp="2444" mp="2444.0" />
<attack physical="500" magical="500" attackSpeed="278" range="40" />
<defence physical="500" magical="500" />
<attribute>
<defence fire="20" water="20" wind="20" earth="20" holy="20" dark="20" />
</attribute>
<speed>
<walk ground="60" />
<run ground="160" />
</speed>
</stats>
<collision>
<radius normal="25" />
<height normal="18" />
</collision>
</npc>
<npc id="2503" level="80" type="Monster" name="Wingless Lucky Pig">
<!-- TODO: Must be confirmed -->
<sex>MALE</sex>
<stats str="10" int="10" dex="10" wit="10" con="10" men="10">
<vitals hp="2444" mp="2444.0" />
<attack physical="500" magical="500" attackSpeed="278" range="40" />
<defence physical="500" magical="500" />
<attribute>
<defence fire="20" water="20" wind="20" earth="20" holy="20" dark="20" />
</attribute>
<speed>
<walk ground="60" />
<run ground="160" />
</speed>
</stats>
<collision>
<radius normal="25" />
<height normal="18" />
</collision>
</npc>
</list>

game\data\scripts\ai\others\LuckyPig.java
Code: [Select]
/**
 * TomAlko
 */
package ai.others;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import ai.AbstractNpcAI;
import org.l2jmobius.commons.util.CommonUtil;

import org.l2jmobius.gameserver.ai.CtrlIntention;
import org.l2jmobius.gameserver.enums.ChatType;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.Location;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.events.AbstractScript;
import org.l2jmobius.gameserver.model.itemcontainer.Inventory;
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
import org.l2jmobius.gameserver.network.NpcStringId;
import org.l2jmobius.gameserver.network.serverpackets.NpcSay;

public final class LuckyPig extends AbstractNpcAI
{
// Lucky Pig IDs
private final int Lucky_Pig = 2501;
private final int Wingless_Lucky_Pig = 2502;
private final int Golden_Wingless_Lucky_Pig = 2503;

// Adena Map
private final Map<Integer, List<Long>> Adena;

private boolean isLuckyPigLevel52 = false;
private boolean isLuckyPigLevel70 = false;
private boolean isLuckyPigLevel80 = false;

   // Lucky Pig Spawn Chance
   private final int Lucky_Pig_Level_52_Spawn_Chance = 3;
   private final int Lucky_Pig_Level_70_Spawn_Chance = 3;
   private final int Lucky_Pig_Level_80_Spawn_Chance = 3;

   // Wingless Lucky Pig Drop Chance
   private final int Wingless_Lucky_Pig_Level_52_Drop_Chance = 99;
   private final int Wingless_Lucky_Pig_Level_70_Drop_Chance = 99;
   private final int Wingless_Lucky_Pig_Level_80_Drop_Chance = 99;
   
   // Golden Wingless Lucky Pig Drop Chance
   private final int Golden_Wingless_Lucky_Pig_Level_52_Drop_Chance = 99;
   private final int Golden_Wingless_Lucky_Pig_Level_70_Drop_Chance = 99;
   private final int Golden_Wingless_Lucky_Pig_Level_80_Drop_Chance = 99;

// Monsters IDs
private final int Lucky_Pig_Level_52[] =
{
// Enchanted Valley
20589,
20590,
20591,
20592,
20593,
20594,
20595,
20596,
20597,
20598,
20599
};

private final int Lucky_Pig_Level_70[] =
{
// Forest of the Dead
18119,
21555,
21556,
21547,
21553,
21548,
21557,
21559,
21560,
21561,
21562,
21563,
21564,
21565,
21566,
21568,
21567,
21596,
21572,
21573,
21571,
21570,
21574,
21576,
21599,
21580,
21581,
21579,
21582,
21578,
21586,
21587,
21583,
21585,
21590,
21593,
21588,

// Valley of Saints
21520,
21521,
21524,
21523,
21526,
21529,
21541,
21531,
21530,
21533,
21532,
21536,
21535,
21537,
21539,
21544
};

private final int Lucky_Pig_Level_80[] =
{
// Beast Farm
18873,
18880,
18887,
18894,
18906,
18907,
18874,
18875,
18876,
18877,
18878,
18879,
18881,
18882,
18883,
18884,
18885,
18886,
18888,
18889,
18890,
18891,
18892,
18893,
18895,
18896,
18897,
18898,
18899,
18900,

// Plains of the Lizardmen
22768,
22769,
22773,
22772,
22771,
22770,
22774,

// Sel Mahum Training Grounds
18908,
22780,
22782,
22784,
22781,
22783,
22785,
22776,
22786,
22787,
22788,
22775,
22777,
22778,

// Fields of Silence & Fields of Whispers
22651,
22654,
22650,
22655,
22652,
22658,
22659,

// Crypts of Disgrace
22704,
22703,
22705,

// Den of Evil
22701,
22691,
22698,
22695,
22694,
22696,
22692,
22693,
22699,
22698,
22697,
18807,
22702,

// Primeval Island
22196,
22197,
22198,
22218,
22223,
22203,
22204,
22205,
22220,
22225,
22743,
22745,
22200,
22201,
22202,
22219,
22224,
22742,
22744,
22199,
22212,
22213,
22222,
22211,
22227,
22208,
22209,
22210,
22221,
22226,
22214,

// Dragon Valley
22815,
22822,
22823,
22824,
22862,
22818,
22819,
22860,
22829,
22858,
22830,
22828,
22827,
22826,
22861,
22825
};

// Lucky Pig Droplist items IDs
private final int Wingless_Lucky_Pig_Level_52_Drop_Id = 8755; // Top-Grade Life Stone - Level 52

private final int Wingless_Lucky_Pig_Level_70_Drop_Id[] =
{
5577, // Red Soul Crystal - Stage 11
5578, // Green Soul Crystal - Stage 11
5579  // Blue Soul Crystal - Stage 11
};

private final int Wingless_Lucky_Pig_Level_80_Drop_Id[] =
{
9552, // Fire Crystal
9553, // Water Crystal
9554, // Earth Crystal
9555, // Wind Crystal
9556, // Dark Crystal
9557  // Holy Crystal
};

private static final NpcStringId[] NPC_STRINGS =
{
NpcStringId.YUM_YUM_YUM_YUM,
NpcStringId.MY_STOMACH_IS_EMPTY,
NpcStringId.I_FEEL_A_LITTLE_WOOZY,
NpcStringId.I_M_STILL_NOT_FULL,
NpcStringId.GIVE_ME_SOMETHING_TO_EAT,
NpcStringId.I_ALSO_NEED_A_DESSERT,
NpcStringId.I_M_STILL_HUNGRY,
NpcStringId.NOW_IT_S_TIME_TO_EAT       
};

@Override
public String onAdvEvent(String event, Npc npc, PlayerInstance player)
{
if (event.equals("checkForAdena"))
{
try
{
for (WorldObject object : World.getInstance().getVisibleObjects(npc, WorldObject.class))
{
if (!(object instanceof ItemInstance))
{
continue;
}

ItemInstance item = (ItemInstance) object;

if (item.getId() == Inventory.ADENA_ID)
{
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new Location(item.getX(), item.getY(), item.getZ(), 0));
World.getInstance().removeVisibleObject(item, item.getWorldRegion());
World.getInstance().removeObject(item);

startQuestTimer("startTalking", 500, npc, null);

if (Adena.containsKey(npc.getObjectId()))
{
Adena.get(npc.getObjectId()).add(item.getCount());

int feedTimes = getRandom(10);

if (Adena.get(npc.getObjectId()).size() > feedTimes)
{
long adenaCount = 0;

for (long adena : Adena.get(npc.getObjectId()))
{
adenaCount += adena;
}

if (adenaCount >= 1)
{
int x = npc.getX();
int y = npc.getY();
int z = npc.getZ();

npc.deleteMe();

if (isLuckyPigLevel52)
{
addSpawn(Wingless_Lucky_Pig, x, y, z, 0, true, 5 * 60 * 1000, true);
setLuckyPigLevel52(true);
}
else if (isLuckyPigLevel70)
{
addSpawn(Wingless_Lucky_Pig, x, y, z, 0, true, 5 * 60 * 1000, true);
setLuckyPigLevel70(true);
}
else if (isLuckyPigLevel80)
{
addSpawn(Wingless_Lucky_Pig, x, y, z, 0, true, 5 * 60 * 1000, true);
setLuckyPigLevel80(true);
}
}
else if (adenaCount >= 50000000)
{
int x = npc.getX();
int y = npc.getY();
int z = npc.getZ();

npc.deleteMe();

if (isLuckyPigLevel52)
{
addSpawn(Golden_Wingless_Lucky_Pig, x, y, z, 0, true, 5 * 60 * 1000, true);
setLuckyPigLevel52(true);
}
else if (isLuckyPigLevel70)
{
addSpawn(Golden_Wingless_Lucky_Pig, x, y, z, 0, true, 5 * 60 * 1000, true);
setLuckyPigLevel70(true);
}
else if (isLuckyPigLevel80)
{
addSpawn(Golden_Wingless_Lucky_Pig, x, y, z, 0, true, 5 * 60 * 1000, true);
setLuckyPigLevel80(true);
}
}

cancelQuestTimer("checkForAdena", npc, null);
}
}
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
else if (event.equals("startTalking"))
{
if (AbstractScript.getRandomBoolean())
{
npc.broadcastPacket(new NpcSay(npc.getObjectId(), ChatType.NPC_GENERAL, npc.getId(), NPC_STRINGS[0]));
}
else if (AbstractScript.getRandomBoolean())
{
npc.broadcastPacket(new NpcSay(npc.getObjectId(), ChatType.NPC_GENERAL, npc.getId(), NPC_STRINGS[1]));
}
else if (AbstractScript.getRandomBoolean())
{
npc.broadcastPacket(new NpcSay(npc.getObjectId(), ChatType.NPC_GENERAL, npc.getId(), NPC_STRINGS[2]));
}
else if (AbstractScript.getRandomBoolean())
{
npc.broadcastPacket(new NpcSay(npc.getObjectId(), ChatType.NPC_GENERAL, npc.getId(), NPC_STRINGS[3]));
}
else if (AbstractScript.getRandomBoolean())
{
npc.broadcastPacket(new NpcSay(npc.getObjectId(), ChatType.NPC_GENERAL, npc.getId(), NPC_STRINGS[4]));
}
else if (AbstractScript.getRandomBoolean())
{
npc.broadcastPacket(new NpcSay(npc.getObjectId(), ChatType.NPC_GENERAL, npc.getId(), NPC_STRINGS[5]));
}
else
{
npc.broadcastPacket(new NpcSay(npc.getObjectId(), ChatType.NPC_GENERAL, npc.getId(), NPC_STRINGS[6]));
}

cancelQuestTimer("startTalking", npc, null);
}
else if (event.equals("despawnLuckyPig"))
{
if (npc.getId() == Lucky_Pig)
{
npc.deleteMe();
}

cancelQuestTimer("despawnLuckyPig", npc, null);
}
else if (event.equals("despawnWinglessLuckyPig"))
{
if (npc.getId() == Wingless_Lucky_Pig)
{
npc.deleteMe();
}
else if (npc.getId() == Golden_Wingless_Lucky_Pig)
{
npc.deleteMe();
}

cancelQuestTimer("despawnWinglessLuckyPig", npc, null);
}

return super.onAdvEvent(event, npc, player);
}

@Override
public String onKill(Npc npc, PlayerInstance player, boolean isPet)
{
if (CommonUtil.contains(Lucky_Pig_Level_52, npc.getId()))
{
if (getRandom(0, 100) <= Lucky_Pig_Level_52_Spawn_Chance)
{
Npc luckyPig52 = addSpawn(Lucky_Pig, npc.getX() + 50, npc.getY() + 50, npc.getZ(), npc.getHeading(), true, 10 * 60 * 1000, true);
onSpawn(luckyPig52);
setLuckyPigLevel52(true);
}
}
else if (CommonUtil.contains(Lucky_Pig_Level_70, npc.getId()))
{
if (getRandom(0, 100) <= Lucky_Pig_Level_70_Spawn_Chance)
{
Npc luckyPig70 = addSpawn(Lucky_Pig, npc.getX() + 50, npc.getY() + 50, npc.getZ(), npc.getHeading(), true, 10 * 60 * 1000, true);
onSpawn(luckyPig70);
setLuckyPigLevel70(true);
}
}
else if (CommonUtil.contains(Lucky_Pig_Level_80, npc.getId()))
{
if (getRandom(0, 100) <= Lucky_Pig_Level_80_Spawn_Chance)
{
Npc luckyPig80 = addSpawn(Lucky_Pig, npc.getX() + 50, npc.getY() + 50, npc.getZ(), npc.getHeading(), true, 10 * 60 * 1000, true);
onSpawn(luckyPig80);
setLuckyPigLevel80(true);
}
}

if ((npc.getId() == Wingless_Lucky_Pig) && isLuckyPigLevel52)
{
if (getRandom(0, 100) <= Wingless_Lucky_Pig_Level_52_Drop_Chance)
{
int randomQuantity = getRandom(2);
npc.dropItem(player, Wingless_Lucky_Pig_Level_52_Drop_Id, randomQuantity);
setLuckyPigLevel52(false);
}
}
else if ((npc.getId() == Wingless_Lucky_Pig) && isLuckyPigLevel70)
{
if (getRandom(0, 100) <= Wingless_Lucky_Pig_Level_70_Drop_Chance)
{
Random rnd = new Random();
int randomDrop = rnd.nextInt(Wingless_Lucky_Pig_Level_70_Drop_Id.length);
int randomQuantity = getRandom(2);
npc.dropItem(player, Wingless_Lucky_Pig_Level_70_Drop_Id[randomDrop], randomQuantity);
setLuckyPigLevel70(false);
}
}
else if ((npc.getId() == Wingless_Lucky_Pig) && isLuckyPigLevel80)
{
if (getRandom(0, 100) <= Wingless_Lucky_Pig_Level_80_Drop_Chance)
{
Random rnd = new Random();
int randomDrop = rnd.nextInt(Wingless_Lucky_Pig_Level_80_Drop_Id.length);
int randomQuantity = getRandom(2);
npc.dropItem(player, Wingless_Lucky_Pig_Level_80_Drop_Id[randomDrop], randomQuantity);
setLuckyPigLevel80(false);
}
}
else if ((npc.getId() == Golden_Wingless_Lucky_Pig) && isLuckyPigLevel52)
{
if (getRandom(0, 100) <= Golden_Wingless_Lucky_Pig_Level_52_Drop_Chance)
{
npc.dropItem(player, 14678, 1); // Neolithic Crystal - B
setLuckyPigLevel52(false);
}
}
else if ((npc.getId() == Golden_Wingless_Lucky_Pig) && isLuckyPigLevel70)
{
if (getRandom(0, 100) <= Golden_Wingless_Lucky_Pig_Level_70_Drop_Chance)
{
npc.dropItem(player, 14679, 1); // Neolithic Crystal - A
setLuckyPigLevel70(false);
}
}
else if ((npc.getId() == Golden_Wingless_Lucky_Pig) && isLuckyPigLevel80)
{
if (getRandom(0, 100) <= Golden_Wingless_Lucky_Pig_Level_80_Drop_Chance)
{
npc.dropItem(player, 14680, 1); // Neolithic Crystal - S
setLuckyPigLevel80(false);
}
}

return super.onKill(npc, player, isPet);
}

@Override
public String onSpawn(Npc npc)
{
switch (npc.getId())
{
case Lucky_Pig:
List<Long> _Adena = new ArrayList<>();
Adena.put(npc.getObjectId(), _Adena);
startQuestTimer("checkForAdena", 1000, npc, null, true);
npc.broadcastPacket(new NpcSay(npc.getObjectId(), ChatType.NPC_GENERAL, npc.getId(), NPC_STRINGS[7]));
startQuestTimer("despawnLuckyPig", 600000, npc, null);
break;
case Wingless_Lucky_Pig:
startQuestTimer("despawnWinglessLuckyPig", 600000, npc, null);
break;
case Golden_Wingless_Lucky_Pig:
startQuestTimer("despawnWinglessLuckyPig", 600000, npc, null);
break;
}

return super.onSpawn(npc);
}

public void setLuckyPigLevel52(boolean luckyPigLevel52)
{
isLuckyPigLevel52 = luckyPigLevel52;
}

public boolean isLuckyPigLevel52()
{
return isLuckyPigLevel52;
}

public void setLuckyPigLevel70(boolean luckyPigLevel70)
{
isLuckyPigLevel70 = luckyPigLevel70;
}

public boolean isLuckyPigLevel70()
{
return isLuckyPigLevel70;
}

public void setLuckyPigLevel80(boolean luckyPigLevel80)
{
isLuckyPigLevel80 = luckyPigLevel80;
}

public boolean isLuckyPigLevel80()
{
return isLuckyPigLevel80;
}

private LuckyPig()
{
addKillId(Wingless_Lucky_Pig);
addKillId(Golden_Wingless_Lucky_Pig);

Adena = new HashMap<>();
registerMobs(Lucky_Pig_Level_52);
registerMobs(Lucky_Pig_Level_70);
registerMobs(Lucky_Pig_Level_80);
}

public static void main(String[] args)
{
new LuckyPig();
}
}


Offline jcerutti17

  • Vassal
  • *
    • Posts: 5
this code spawned 2 lucky pigs even before feeding adena to it.