123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- /*
- * Copyright (C) 2004-2015 L2J Server
- *
- * This file is part of L2J Server.
- *
- * L2J Server 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.
- *
- * L2J Server 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.conditions;
- import com.l2jserver.gameserver.model.actor.L2Character;
- import com.l2jserver.gameserver.model.items.L2Item;
- import com.l2jserver.gameserver.model.skills.Skill;
- /**
- * The Class Condition.
- * @author mkizub
- */
- public abstract class Condition implements ConditionListener
- {
- private ConditionListener _listener;
- private String _msg;
- private int _msgId;
- private boolean _addName = false;
- private boolean _result;
-
- /**
- * Sets the message.
- * @param msg the new message
- */
- public final void setMessage(String msg)
- {
- _msg = msg;
- }
-
- /**
- * Gets the message.
- * @return the message
- */
- public final String getMessage()
- {
- return _msg;
- }
-
- /**
- * Sets the message id.
- * @param msgId the new message id
- */
- public final void setMessageId(int msgId)
- {
- _msgId = msgId;
- }
-
- /**
- * Gets the message id.
- * @return the message id
- */
- public final int getMessageId()
- {
- return _msgId;
- }
-
- /**
- * Adds the name.
- */
- public final void addName()
- {
- _addName = true;
- }
-
- /**
- * Checks if is adds the name.
- * @return true, if is adds the name
- */
- public final boolean isAddName()
- {
- return _addName;
- }
-
- /**
- * Sets the listener.
- * @param listener the new listener
- */
- void setListener(ConditionListener listener)
- {
- _listener = listener;
- notifyChanged();
- }
-
- /**
- * Gets the listener.
- * @return the listener
- */
- final ConditionListener getListener()
- {
- return _listener;
- }
-
- public final boolean test(L2Character caster, L2Character target, Skill skill)
- {
- return test(caster, target, skill, null);
- }
-
- public final boolean test(L2Character caster, L2Character target, L2Item item)
- {
- return test(caster, target, null, null);
- }
-
- public final boolean test(L2Character caster, L2Character target, Skill skill, L2Item item)
- {
- boolean res = testImpl(caster, target, skill, item);
- if ((_listener != null) && (res != _result))
- {
- _result = res;
- notifyChanged();
- }
- return res;
- }
-
- /**
- * Test the condition.
- * @param effector the effector
- * @param effected the effected
- * @param skill the skill
- * @param item the item
- * @return {@code true} if successful, {@code false} otherwise
- */
- public abstract boolean testImpl(L2Character effector, L2Character effected, Skill skill, L2Item item);
-
- @Override
- public void notifyChanged()
- {
- if (_listener != null)
- {
- _listener.notifyChanged();
- }
- }
- }
|