Skip to content

Instantly share code, notes, and snippets.

@nonom
Last active June 28, 2017 23:36
Show Gist options
  • Save nonom/01ae7ad474dc0534fac1 to your computer and use it in GitHub Desktop.
Save nonom/01ae7ad474dc0534fac1 to your computer and use it in GitHub Desktop.
/*
* 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.npc.LevelBurners;
import ai.npc.AbstractNpcAI;
import com.l2jserver.gameserver.datatables.SpawnTable;
import com.l2jserver.gameserver.model.L2Spawn;
import com.l2jserver.gameserver.model.Location;
import com.l2jserver.gameserver.model.actor.L2Npc;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.network.NpcStringId;
import com.l2jserver.gameserver.network.clientpackets.Say2;
/**
* Monastery Level Burners AI (not done)
* @author nonom
*/
public class LevelBurners extends AbstractNpcAI
{
private static final int LEVEL_BURNER = 18913;
private static final int DIVINE_PROTECTOR = 22798;
private static final int DIVINE_FIGHTER = 22799;
private static final int DIVINE_MAGICIAN = 22800;
private final Room _rooms[] = new Room[8];
// @formatter:off
private final int[][] SPAWN_QUANTY =
{
{2,2,2}, // Balanced
{7,1,1}, // Protection
{1,7,1}, // Will
{1,1,7}, // Magic
};
private final int[][][] ROOM_COORDINATES =
{
//TODO: Get coordinates of each room
{{X,Y,Z},{X,Y,Z}}, // Room 1
{{X,Y,Z},{X,Y,Z}}, // Room 2
{{X,Y,Z},{X,Y,Z}}, // Room 3
{{X,Y,Z},{X,Y,Z}}, // Room 4
{{X,Y,Z},{X,Y,Z}}, // Room 5
{{X,Y,Z},{X,Y,Z}}, // Room 6
{{X,Y,Z},{X,Y,Z}}, // Room 7
{{X,Y,Z},{X,Y,Z}}, // Room 8
};
// @formatter:on
public LevelBurners(String name, String descr)
{
super(name, descr);
addStartNpc(LEVEL_BURNER);
addSpawnId(LEVEL_BURNER);
addAttackId(LEVEL_BURNER);
Burner[] burners = new Burner[4];
int i = 0;
int j = 0;
for (L2Spawn spawn : SpawnTable.getInstance().getSpawns(LEVEL_BURNER))
{
Burner burner = new Burner(spawn.getLastSpawn(), j, 0, SPAWN_QUANTY[i]);
burner.setMode(1);
burner.setStatus(0);
burner.getNpc().setAutoAttackable(true);
if (j < 3)
{
if (j == 1)
{
burnMe(burner);
}
burners[j] = burner;
j++;
}
else
{
_rooms[i] = new Room(i, burners, ROOM_COORDINATES[i]);
i++;
j = 0;
break;
}
}
}
@Override
public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
{
final Burner burner = getBurner(npc);
switch (event)
{
case "burn":
{
burnMe(burner);
startQuestTimer("off", 2000, burner.getNpc(), null);
break;
}
case "off":
{
burner.turnOff();
break;
}
case "check_time_announce":
{
broadcastNpcSay(burner.getNpc(), Say2.NPC_ALL, NpcStringId.DIVINE_ENERGY_IS_BEGINNING_TO_ENCIRCLE);
startQuestTimer("check_time", 15 * 1000, burner.getNpc(), null);
break;
}
case "check_time_announce2":
{
broadcastNpcSay(burner.getNpc(), Say2.NPC_ALL, NpcStringId.DIVINE_ENERGY_IS_BEGINNING_TO_ENCIRCLE);
startQuestTimer("check_time", 15 * 1000, burner.getNpc(), null);
break;
}
case "check_time":
{
spawnRoom(burner);
startQuestTimer("dspawn_time", 1 * 1000, burner.getNpc(), null);
break;
}
case "dspawn_time":
{
burner.getNpc().decayMe();
startQuestTimer("spawn_time", 60 * 60 * 1000, burner.getNpc(), null);
break;
}
case "spawn_time":
{
burner.getNpc().spawnMe();
break;
}
}
return null;
}
@Override
public String onAttack(L2Npc npc, L2PcInstance player, int damage, boolean isSummon)
{
Burner burner = getBurner(npc);
startQuestTimer("burn", 60 * 1000, npc, null);
if (burner.getStatus() != 1)
{
cancelQuestTimer("check_time_announce", npc, null);
burner.setStatus(1);
startQuestTimer("check_time_announce2", 1 * 100, npc, null);
}
return super.onAttack(npc, player, damage, isSummon);
}
private void burnMe(Burner burner)
{
burner.getNpc().setDisplayEffect(1);
burner.getNpc().setIsRunning(false);
Room room = getRoom(burner);
final Burner[] siblings = room.getBurners();
for (Burner sibling : siblings)
{
if (burner != sibling)
{
sibling.getNpc().setDisplayEffect(2);
sibling.getNpc().setIsRunning(false);
}
}
}
private Room getRoom(Burner burner)
{
for (int i = 0; i <= 7; i++)
{
for (Burner b : _rooms[i].getBurners())
{
if (burner == b)
{
return _rooms[i];
}
}
}
return null;
}
// TODO Fix that
private void spawnRoom(Burner burner)
{
// TODO Check mode here
for (int i = 1; i < 3; i++)
{
for (int q = 0; q < burner.getSpawnQuantity()[i]; q++)
{
// TODO Check also for Magicians and Fighters
addSpawn(DIVINE_PROTECTOR, getRoom(burner).getRandomLocation(), true, 0);
}
}
}
private Burner getBurner(L2Npc npc)
{
for (int i = 0; i <= 7; i++)
{
for (Burner burner : _rooms[i].getBurners())
{
if (npc == burner.getNpc())
{
return burner;
}
}
}
return null;
}
private class Room
{
private final int _id;
private final Burner[] _burners;
private final int[][] _coordinates;
public Room(int id, Burner[] burners, int[][] coordinates)
{
_id = id;
_burners = burners;
_coordinates = coordinates;
}
public int[][] getCoordinates()
{
return _coordinates;
}
public Burner[] getBurners()
{
return _burners;
}
public int getId()
{
return _id;
}
public Location getRandomLocation()
{
int x1 = getCoordinates()[0][0];
int y1 = getCoordinates()[0][1];
int z1 = getCoordinates()[0][2];
int x2 = getCoordinates()[1][0];
int y2 = getCoordinates()[1][1];
int z2 = getCoordinates()[1][2];
return new Location(getRandom(x1, x2), getRandom(y1, y2), getRandom(z1, z2));
}
}
private class Burner
{
private final L2Npc _npc;
private int _status;
private int _mode = 0;
private final int[] _spawnQuantity;
public Burner(L2Npc npc, int number, int status, int[] spawnQuantity)
{
_npc = npc;
_status = status;
_spawnQuantity = spawnQuantity;
}
public int[] getSpawnQuantity()
{
return _spawnQuantity;
}
public void turnOff()
{
getNpc().setDisplayEffect(2);
getNpc().setIsRunning(false);
}
public L2Npc getNpc()
{
return _npc;
}
public int getStatus()
{
return _status;
}
public void setStatus(int status)
{
_status = status;
}
public int getMode()
{
return _mode;
}
public void setMode(int mode)
{
_mode = mode;
}
}
public static void main(String[] args)
{
new LevelBurners(LevelBurners.class.getSimpleName(), "ai/npc");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment