L2TpFlagInstance
[SRC="java"]/*
* 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 com.l2jserver.gameserver.model.actor.instance;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.logging.Logger;
import com.l2jserver.L2DatabaseFactory;
import com.l2jserver.gameserver.Announcements;
import com.l2jserver.gameserver.ai.CtrlIntention;
import com.l2jserver.gameserver.datatables.ItemTable;
import com.l2jserver.gameserver.datatables.NpcTable;
import com.l2jserver.gameserver.idfactory.IdFactory;
import com.l2jserver.gameserver.model.L2ItemInstance;
import com.l2jserver.gameserver.model.L2Skill;
import com.l2jserver.gameserver.model.actor.L2Character;
import com.l2jserver.gameserver.model.actor.L2Npc;
import com.l2jserver.gameserver.model.entity.FactionMaps;
import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
import com.l2jserver.gameserver.network.serverpackets.MyTargetSelected;
import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
import com.l2jserver.gameserver.network.serverpackets.ValidateLocation;
import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
import com.l2jserver.gameserver.util.Broadcast;
public class L2TpFlagInstance extends L2Npc
{
private final static Logger _log = Logger.getLogger(L2FactTeleporterInstance.class.getName());
private int _faction=0;
private int _occupayable=0;
private String _title = "";
private String _flagPlace = "";
public L2TpFlagInstance(int objectId, L2NpcTemplate template)
{
super(objectId, template);
}
public static void spawnFlags()
{
Connection con = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("SELECT * FROM faction_crystals WHERE mapId=?");
statement.setInt(1, FactionMaps.getMapId());
ResultSet rset = statement.executeQuery();
while (rset.next())
{
String _titlea = "Neutral";
if (rset.getInt("factionId") == 1)
_titlea = "Blue";
else if (rset.getInt("factionId") == 2)
_titlea = "Red";
L2TpFlagInstance flag = new L2TpFlagInstance(IdFactory.getInstance().getNextId(),NpcTable.getInstance().getTemplate(36600));
flag.setTitle(_titlea);
flag.setCurrentHpMp(flag.getMaxHp(), flag.getMaxMp());
flag.setHeading(0);
flag.setName(rset.getString("flagName"));
flag.setFlagName(rset.getString("flagName"));
flag.setFlagFactionId(rset.getInt("factionId"));
flag.spawnMe(rset.getInt("x"),rset.getInt("y"),rset.getInt("z") + 50);
if (rset.getInt("factionId") != 0)
{
if (rset.getInt("factionId") == 1)
L2FactTeleporterInstance._tpBlueFlags.add(flag);
else
L2FactTeleporterInstance._tpRedFlags.add(flag);
flag.setIsUnoccupayable(1);
}
_log.info("Spawned crystal: " + rset.getString("flagName"));
}
rset.close();
statement.close();
}
catch (Exception e)
{
_log.warning("Something error with:" + e);
}
finally
{
try {con.close();} catch (Exception e){}
}
Announcements.getInstance().announceToAll("Spawned faction map: " + FactionMaps.getMapName());
}
public void setFlagName(String a)
{
_flagPlace = a;
}
public String getFlagName()
{
return _flagPlace;
}
@Override
public boolean isAttackable()
{
return true;
}
@Override
public boolean isAutoAttackable(L2Character attacker)
{
return true;
}
@Override
public boolean doDie(L2Character killer)
{
if (!super.doDie(killer))
return false;
if (getFlagFactionId() == 1)
L2FactTeleporterInstance._tpBlueFlags.remove(this);
else if (getFlagFactionId() == 2)
L2FactTeleporterInstance._tpRedFlags.remove(this);
L2PcInstance player = null;
int _faktjon = 0;
String _name = "Neutral";
if (killer instanceof L2PcInstance)
player = (L2PcInstance) killer;
else if (killer instanceof L2SummonInstance)
player = ((L2SummonInstance) killer).getOwner();
_faktjon = player.getFactionId();
if (_faktjon == 1)
_title = "Blue";
else
_title = "Red";
L2TpFlagInstance flag = new L2TpFlagInstance(IdFactory.getInstance().getNextId(),NpcTable.getInstance().getTemplate(36600));
_name = this.getName();
flag.setTitle(_title);
flag.setCurrentHpMp(flag.getMaxHp(), flag.getMaxMp());
flag.setHeading(0);
flag.setName(_name);
flag.setFlagName(_name);
flag.setIsUnoccupayable(0);
flag.setFlagFactionId(_faktjon);
flag.spawnMe(this.getX(), this.getY(), this.getZ());
deleteMe();
if (_faktjon == 1)
L2FactTeleporterInstance._tpBlueFlags.add(flag);
else
L2FactTeleporterInstance._tpRedFlags.add(flag);
Broadcast.sendMessToAllFactionPlayers(_title + " faction member " + player.getName() + " has occupied " + _flagPlace + " crystal.");
return true;
}
@Override
public void onForcedAttack(L2PcInstance player)
{
onAction(player);
}
public void setIsUnoccupayable(int a)
{
_occupayable = a;
}
public int isUnoccupayable()
{
return _occupayable;
}
@Override
public void onAction(L2PcInstance player)
{
if (player == null || !canTarget(player))
return;
// Check if the L2PcInstance already target the L2NpcInstance
if (this != player.getTarget()/* && player.inWorld() == 1*/)
{
// Set the target of the L2PcInstance player
player.setTarget(this);
// Send a Server->Client packet MyTargetSelected to the L2PcInstance player
MyTargetSelected my = new MyTargetSelected(getObjectId(), player.getLevel() - getLevel());
player.sendPacket(my);
// Send a Server->Client packet StatusUpdate of the L2NpcInstance to the L2PcInstance to update its HP bar
StatusUpdate su = new StatusUpdate(getObjectId());
su.addAttribute(StatusUpdate.CUR_HP, (int)getStatus().getCurrentHp() );
su.addAttribute(StatusUpdate.MAX_HP, getMaxHp() );
player.sendPacket(su);
// Send a Server->Client packet ValidateLocation to correct the L2NpcInstance position and heading on the client
player.sendPacket(new ValidateLocation(this));
}
else
{
if (isAutoAttackable(player) && Math.abs(player.getZ() - getZ()) < 100)
player.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, this);
else
{
// Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
player.sendPacket(ActionFailed.STATIC_PACKET);
}
}
}
public int getFlagFactionId()
{
return _faction;
}
public void setFlagFactionId(int i)
{
_faction = i;
}
@Override
public void reduceCurrentHp(double damage, L2Character attacker, L2Skill skill)
{
L2PcInstance plajor = null;
boolean cord = false;
if (attacker instanceof L2PcInstance)
plajor = (L2PcInstance) attacker;
else if (attacker instanceof L2SummonInstance)
plajor = ((L2SummonInstance) attacker).getOwner();
if (plajor.getFactionId() != getFlagFactionId())
cord = true;
if (cord)
super.reduceCurrentHp(damage, attacker, skill);
}
}[/SRC]
* 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 com.l2jserver.gameserver.model.actor.instance;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.logging.Logger;
import com.l2jserver.L2DatabaseFactory;
import com.l2jserver.gameserver.Announcements;
import com.l2jserver.gameserver.ai.CtrlIntention;
import com.l2jserver.gameserver.datatables.ItemTable;
import com.l2jserver.gameserver.datatables.NpcTable;
import com.l2jserver.gameserver.idfactory.IdFactory;
import com.l2jserver.gameserver.model.L2ItemInstance;
import com.l2jserver.gameserver.model.L2Skill;
import com.l2jserver.gameserver.model.actor.L2Character;
import com.l2jserver.gameserver.model.actor.L2Npc;
import com.l2jserver.gameserver.model.entity.FactionMaps;
import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
import com.l2jserver.gameserver.network.serverpackets.MyTargetSelected;
import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
import com.l2jserver.gameserver.network.serverpackets.ValidateLocation;
import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
import com.l2jserver.gameserver.util.Broadcast;
public class L2TpFlagInstance extends L2Npc
{
private final static Logger _log = Logger.getLogger(L2FactTeleporterInstance.class.getName());
private int _faction=0;
private int _occupayable=0;
private String _title = "";
private String _flagPlace = "";
public L2TpFlagInstance(int objectId, L2NpcTemplate template)
{
super(objectId, template);
}
public static void spawnFlags()
{
Connection con = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("SELECT * FROM faction_crystals WHERE mapId=?");
statement.setInt(1, FactionMaps.getMapId());
ResultSet rset = statement.executeQuery();
while (rset.next())
{
String _titlea = "Neutral";
if (rset.getInt("factionId") == 1)
_titlea = "Blue";
else if (rset.getInt("factionId") == 2)
_titlea = "Red";
L2TpFlagInstance flag = new L2TpFlagInstance(IdFactory.getInstance().getNextId(),NpcTable.getInstance().getTemplate(36600));
flag.setTitle(_titlea);
flag.setCurrentHpMp(flag.getMaxHp(), flag.getMaxMp());
flag.setHeading(0);
flag.setName(rset.getString("flagName"));
flag.setFlagName(rset.getString("flagName"));
flag.setFlagFactionId(rset.getInt("factionId"));
flag.spawnMe(rset.getInt("x"),rset.getInt("y"),rset.getInt("z") + 50);
if (rset.getInt("factionId") != 0)
{
if (rset.getInt("factionId") == 1)
L2FactTeleporterInstance._tpBlueFlags.add(flag);
else
L2FactTeleporterInstance._tpRedFlags.add(flag);
flag.setIsUnoccupayable(1);
}
_log.info("Spawned crystal: " + rset.getString("flagName"));
}
rset.close();
statement.close();
}
catch (Exception e)
{
_log.warning("Something error with:" + e);
}
finally
{
try {con.close();} catch (Exception e){}
}
Announcements.getInstance().announceToAll("Spawned faction map: " + FactionMaps.getMapName());
}
public void setFlagName(String a)
{
_flagPlace = a;
}
public String getFlagName()
{
return _flagPlace;
}
@Override
public boolean isAttackable()
{
return true;
}
@Override
public boolean isAutoAttackable(L2Character attacker)
{
return true;
}
@Override
public boolean doDie(L2Character killer)
{
if (!super.doDie(killer))
return false;
if (getFlagFactionId() == 1)
L2FactTeleporterInstance._tpBlueFlags.remove(this);
else if (getFlagFactionId() == 2)
L2FactTeleporterInstance._tpRedFlags.remove(this);
L2PcInstance player = null;
int _faktjon = 0;
String _name = "Neutral";
if (killer instanceof L2PcInstance)
player = (L2PcInstance) killer;
else if (killer instanceof L2SummonInstance)
player = ((L2SummonInstance) killer).getOwner();
_faktjon = player.getFactionId();
if (_faktjon == 1)
_title = "Blue";
else
_title = "Red";
L2TpFlagInstance flag = new L2TpFlagInstance(IdFactory.getInstance().getNextId(),NpcTable.getInstance().getTemplate(36600));
_name = this.getName();
flag.setTitle(_title);
flag.setCurrentHpMp(flag.getMaxHp(), flag.getMaxMp());
flag.setHeading(0);
flag.setName(_name);
flag.setFlagName(_name);
flag.setIsUnoccupayable(0);
flag.setFlagFactionId(_faktjon);
flag.spawnMe(this.getX(), this.getY(), this.getZ());
deleteMe();
if (_faktjon == 1)
L2FactTeleporterInstance._tpBlueFlags.add(flag);
else
L2FactTeleporterInstance._tpRedFlags.add(flag);
Broadcast.sendMessToAllFactionPlayers(_title + " faction member " + player.getName() + " has occupied " + _flagPlace + " crystal.");
return true;
}
@Override
public void onForcedAttack(L2PcInstance player)
{
onAction(player);
}
public void setIsUnoccupayable(int a)
{
_occupayable = a;
}
public int isUnoccupayable()
{
return _occupayable;
}
@Override
public void onAction(L2PcInstance player)
{
if (player == null || !canTarget(player))
return;
// Check if the L2PcInstance already target the L2NpcInstance
if (this != player.getTarget()/* && player.inWorld() == 1*/)
{
// Set the target of the L2PcInstance player
player.setTarget(this);
// Send a Server->Client packet MyTargetSelected to the L2PcInstance player
MyTargetSelected my = new MyTargetSelected(getObjectId(), player.getLevel() - getLevel());
player.sendPacket(my);
// Send a Server->Client packet StatusUpdate of the L2NpcInstance to the L2PcInstance to update its HP bar
StatusUpdate su = new StatusUpdate(getObjectId());
su.addAttribute(StatusUpdate.CUR_HP, (int)getStatus().getCurrentHp() );
su.addAttribute(StatusUpdate.MAX_HP, getMaxHp() );
player.sendPacket(su);
// Send a Server->Client packet ValidateLocation to correct the L2NpcInstance position and heading on the client
player.sendPacket(new ValidateLocation(this));
}
else
{
if (isAutoAttackable(player) && Math.abs(player.getZ() - getZ()) < 100)
player.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, this);
else
{
// Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
player.sendPacket(ActionFailed.STATIC_PACKET);
}
}
}
public int getFlagFactionId()
{
return _faction;
}
public void setFlagFactionId(int i)
{
_faction = i;
}
@Override
public void reduceCurrentHp(double damage, L2Character attacker, L2Skill skill)
{
L2PcInstance plajor = null;
boolean cord = false;
if (attacker instanceof L2PcInstance)
plajor = (L2PcInstance) attacker;
else if (attacker instanceof L2SummonInstance)
plajor = ((L2SummonInstance) attacker).getOwner();
if (plajor.getFactionId() != getFlagFactionId())
cord = true;
if (cord)
super.reduceCurrentHp(damage, attacker, skill);
}
}[/SRC]
Теперь вопрос как сделать всем кто атаковал дать 1 адену?