/**
* @author PointerRage
*
*/
public final class ThroneObject extends StaticActor {
private final Lock lock = new PrimitiveAtomicLock();
private WeakReference<L2PcInstance> sitter;
public ThroneObject(int objectId, CharacterTemplate template, int staticId) {
super(objectId, template, staticId);
}
@Override
public void onAction(L2PcInstance player) {
if (player.getTarget() != this) {
player.setTarget(this);
player.sendPacket(new MyTargetSelected(getObjectId(), 0));
return;
}
player.sendPacket(new MyTargetSelected(getObjectId(), 0));
if (!player.isInsideRadius(this, getInteractionDistance(), false, false)) {
player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
player.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
lock.lock();
try {
L2PcInstance actualSitter = sitter != null ? sitter.get() : null;
if(actualSitter != null && actualSitter.getSittingObject() == this) {
player.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
if(!isAllowSitting(player)) {
player.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
sitter = player.getWeakReference();
} finally {
lock.unlock();
}
player.sitDown(false, this);
player.broadcastPacket(new CharSit(player, getStaticId()));
}
private boolean isAllowSitting(L2PcInstance player) {
Castle throneCastle = CastleManager.getInstance().getCastle(this);
if(throneCastle == null) {
return true;
}
L2Clan clan = player.getClan();
if(clan == null) {
return false;
}
Castle playerCastle = CastleManager.getInstance().getCastleById(clan.getHasCastle());
if(playerCastle != throneCastle) {
return false;
}
if(Config.ONLY_CLANLEADER_CAN_SIT_ON_THRONE && !player.isClanLeader()) {
return false;
}
return true;
}
@Override
public boolean isThrone() {
return true;
}
@Override
public ThroneObject getThrone() {
return this;
}
@SuppressWarnings("unchecked")
@Override
public WeakReference<ThroneObject> getWeakReference() {
if(weakReference == null)
weakReference = new WeakReference<StaticActor>(this);
return (WeakReference<ThroneObject>) weakReference;
}
@SuppressWarnings("unchecked")
@Override
public SoftReference<ThroneObject> getSoftReference() {
if(softReference == null)
softReference = new SoftReference<ThroneObject>(this);
return (SoftReference<ThroneObject>) softReference;
}
}