Package com.l2jfrozen.gameserver.skills.l2skills

Source Code of com.l2jfrozen.gameserver.skills.l2skills.L2SkillCreateItem

/* 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 2, 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* http://www.gnu.org/copyleft/gpl.html
*/
package com.l2jfrozen.gameserver.skills.l2skills;

import com.l2jfrozen.gameserver.idfactory.IdFactory;
import com.l2jfrozen.gameserver.model.L2Character;
import com.l2jfrozen.gameserver.model.L2Object;
import com.l2jfrozen.gameserver.model.L2Skill;
import com.l2jfrozen.gameserver.model.actor.instance.L2ItemInstance;
import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
import com.l2jfrozen.gameserver.network.SystemMessageId;
import com.l2jfrozen.gameserver.network.serverpackets.ItemList;
import com.l2jfrozen.gameserver.network.serverpackets.SystemMessage;
import com.l2jfrozen.gameserver.templates.StatsSet;
import com.l2jfrozen.util.random.Rnd;

/**
* @author Nemesiss
*/
public class L2SkillCreateItem extends L2Skill
{
  private final int[] _createItemId;
  private final int _createItemCount;
  private final int _randomCount;

  public L2SkillCreateItem(StatsSet set)
  {
    super(set);
    _createItemId = set.getIntegerArray("create_item_id");
    _createItemCount = set.getInteger("create_item_count", 0);
    _randomCount = set.getInteger("random_count", 1);
  }

  /**
   * @see com.l2jfrozen.gameserver.model.L2Skill#useSkill(com.l2jfrozen.gameserver.model.L2Character,
   *      com.l2jfrozen.gameserver.model.L2Object[])
   */
  @Override
  public void useSkill(L2Character activeChar, L2Object[] targets)
  {
    if(activeChar.isAlikeDead())
      return;
    if(_createItemId == null || _createItemCount == 0)
    {
      activeChar.sendPacket(new SystemMessage(SystemMessageId.SKILL_NOT_AVAILABLE));
      return;
    }
    L2PcInstance player = (L2PcInstance) activeChar;
    if(activeChar instanceof L2PcInstance)
    {
      int count = _createItemCount * (Rnd.nextInt(_randomCount)+1);
      int rndid = Rnd.nextInt(_createItemId.length);
      giveItems(player, _createItemId[rndid], count);
    }
  }

  /**
   * @param activeChar
   * @param itemId
   * @param count
   */
  public void giveItems(L2PcInstance activeChar, int itemId, int count)
  {
    L2ItemInstance item = new L2ItemInstance(IdFactory.getInstance().getNextId(), itemId);
    //if(item == null)
    //  return;
   
    item.setCount(count);
    activeChar.getInventory().addItem("Skill", item, activeChar, activeChar);

    if(count > 1)
    {
      SystemMessage smsg = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
      smsg.addItemName(item.getItemId());
      smsg.addNumber(count);
      activeChar.sendPacket(smsg);
    }
    else
    {
      SystemMessage smsg = new SystemMessage(SystemMessageId.EARNED_ITEM);
      smsg.addItemName(item.getItemId());
      activeChar.sendPacket(smsg);
    }
    ItemList il = new ItemList(activeChar, false);
    activeChar.sendPacket(il);
  }
}
TOP

Related Classes of com.l2jfrozen.gameserver.skills.l2skills.L2SkillCreateItem

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.