content: /**
   * This file is part of Aion-Lightning <aion-lightning.org>.
   *
   *  Aion-Lightning 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.
   *
   *  Aion-Lightning 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 Aion-Lightning.
   *  If not, see <http://www.gnu.org/licenses/>.
   */
  package ai.instance.battlefields;
  
  import java.util.List;
  
  import com.aionemu.gameserver.ai2.AIName;
  import com.aionemu.gameserver.ai2.NpcAI2;
  import com.aionemu.gameserver.dataholders.DataManager;
  import com.aionemu.gameserver.model.gameobjects.Npc;
  import com.aionemu.gameserver.model.gameobjects.player.Player;
  import com.aionemu.gameserver.model.templates.windstreams.Location2D;
  import com.aionemu.gameserver.model.templates.windstreams.WindstreamTemplate;
  import com.aionemu.gameserver.network.aion.serverpackets.SM_WINDSTREAM_ANNOUNCE;
  import com.aionemu.gameserver.utils.PacketSendUtility;
  import com.aionemu.gameserver.utils.ThreadPoolManager;
  import com.aionemu.gameserver.world.knownlist.Visitor;
  
  /**
   * @author Rinzler
   */
  @AIName("WindStream_04_Li") // 220972
  public class WindStream_04_LiAI2 extends NpcAI2 {
  
  	@Override
  	protected void handleSpawned() {
  		super.handleSpawned();
  		Npc npc = getOwner();
  		startWindStream(npc);
  		windStreamAnnounce(getOwner(), 0);
  	}
  
  	private void startWindStream(final Npc npc) {
  		ThreadPoolManager.getInstance().schedule(new Runnable() {
  
  			@Override
  			public void run() {
  				Npc npc2 = (Npc) spawn(302200000, 220970, 1455.0000f, 1511.5394f, 573.43011f, (byte) 0, 0, 1);
  				windStreamAnnounce(npc2, 1);
  				despawnNpc(220972);
  				spawn(220970, 1455.0000f, 1511.5394f, 573.43011f, (byte) 0, 749);
  				PacketSendUtility.broadcastPacket(npc2, new SM_WINDSTREAM_ANNOUNCE(1, 302200000, 359, 1));
  				if (npc2 != null) {
  					npc2.getController().onDelete();
  				}
  				if (npc != null) {
  					npc.getController().onDelete();
  				}
  			}
  		}, 5000);
  	}
  
  	private void windStreamAnnounce(final Npc npc, final int state) {
  		WindstreamTemplate template = DataManager.WINDSTREAM_DATA.getStreamTemplate(npc.getPosition().getMapId());
  		for (Location2D wind : template.getLocations().getLocation()) {
  			if (wind.getId() == 359) {
  				wind.setState(state);
  				break;
  			}
  		}
  		npc.getPosition().getWorld().doOnAllPlayers(new Visitor<Player>() {
  
  			@Override
  			public void visit(Player player) {
  				PacketSendUtility.sendPacket(player, new SM_WINDSTREAM_ANNOUNCE(1, 302200000, 359, state));
  			}
  		});
  	}
  
  	private void despawnNpc(int npcId) {
  		if (getPosition().getWorldMapInstance().getNpcs(npcId) != null) {
  			List<Npc> npcs = getPosition().getWorldMapInstance().getNpcs(npcId);
  			for (Npc npc : npcs) {
  				npc.getController().onDelete();
  			}
  		}
  	}
  }
  