117 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			117 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| /*
 | |
|  * This file is part of the L2J Mobius project.
 | |
|  * 
 | |
|  * 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 handlers.effecthandlers;
 | |
| 
 | |
| import com.l2jmobius.gameserver.model.StatsSet;
 | |
| import com.l2jmobius.gameserver.model.actor.L2Character;
 | |
| import com.l2jmobius.gameserver.model.effects.AbstractEffect;
 | |
| import com.l2jmobius.gameserver.model.effects.EffectFlag;
 | |
| import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
 | |
| import com.l2jmobius.gameserver.model.skills.Skill;
 | |
| 
 | |
| /**
 | |
|  * Modify vital effect implementation.
 | |
|  * @author malyelfik
 | |
|  */
 | |
| public final class ModifyVital extends AbstractEffect
 | |
| {
 | |
| 	// Modify types
 | |
| 	enum ModifyType
 | |
| 	{
 | |
| 		DIFF,
 | |
| 		SET,
 | |
| 		PER;
 | |
| 	}
 | |
| 	
 | |
| 	// Effect parameters
 | |
| 	private final ModifyType _type;
 | |
| 	private final int _hp;
 | |
| 	private final int _mp;
 | |
| 	private final int _cp;
 | |
| 	
 | |
| 	public ModifyVital(StatsSet params)
 | |
| 	{
 | |
| 		_type = params.getEnum("type", ModifyType.class);
 | |
| 		if (!_type.equals(ModifyType.SET))
 | |
| 		{
 | |
| 			_hp = params.getInt("hp", 0);
 | |
| 			_mp = params.getInt("mp", 0);
 | |
| 			_cp = params.getInt("cp", 0);
 | |
| 		}
 | |
| 		else
 | |
| 		{
 | |
| 			_hp = params.getInt("hp", -1);
 | |
| 			_mp = params.getInt("mp", -1);
 | |
| 			_cp = params.getInt("cp", -1);
 | |
| 		}
 | |
| 	}
 | |
| 	
 | |
| 	@Override
 | |
| 	public boolean isInstant()
 | |
| 	{
 | |
| 		return true;
 | |
| 	}
 | |
| 	
 | |
| 	@Override
 | |
| 	public void instant(L2Character effector, L2Character effected, Skill skill, L2ItemInstance item)
 | |
| 	{
 | |
| 		if (effected.isDead())
 | |
| 		{
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		if (effector.isPlayer() && effected.isPlayer() && effected.isAffected(EffectFlag.FACEOFF) && (effected.getActingPlayer().getAttackerObjId() != effector.getObjectId()))
 | |
| 		{
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		switch (_type)
 | |
| 		{
 | |
| 			case DIFF:
 | |
| 			{
 | |
| 				effected.setCurrentCp(effected.getCurrentCp() + _cp);
 | |
| 				effected.setCurrentHp(effected.getCurrentHp() + _hp);
 | |
| 				effected.setCurrentMp(effected.getCurrentMp() + _mp);
 | |
| 				break;
 | |
| 			}
 | |
| 			case SET:
 | |
| 			{
 | |
| 				if (_cp >= 0)
 | |
| 				{
 | |
| 					effected.setCurrentCp(_cp);
 | |
| 				}
 | |
| 				if (_hp >= 0)
 | |
| 				{
 | |
| 					effected.setCurrentHp(_hp);
 | |
| 				}
 | |
| 				if (_mp >= 0)
 | |
| 				{
 | |
| 					effected.setCurrentMp(_mp);
 | |
| 				}
 | |
| 				break;
 | |
| 			}
 | |
| 			case PER:
 | |
| 			{
 | |
| 				effected.setCurrentCp(effected.getCurrentCp() + (effected.getMaxCp() * (_cp / 100)));
 | |
| 				effected.setCurrentHp(effected.getCurrentHp() + (effected.getMaxHp() * (_hp / 100)));
 | |
| 				effected.setCurrentMp(effected.getCurrentMp() + (effected.getMaxMp() * (_mp / 100)));
 | |
| 				break;
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| }
 | 
