Project update.
This commit is contained in:
@ -0,0 +1,218 @@
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.model.items.enchant;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.gameserver.datatables.ItemTable;
|
||||
import com.l2jmobius.gameserver.model.StatsSet;
|
||||
import com.l2jmobius.gameserver.model.items.L2Item;
|
||||
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
|
||||
import com.l2jmobius.gameserver.model.items.type.CrystalType;
|
||||
import com.l2jmobius.gameserver.model.items.type.EtcItemType;
|
||||
import com.l2jmobius.gameserver.model.items.type.ItemType;
|
||||
import com.l2jmobius.gameserver.util.Util;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public abstract class AbstractEnchantItem
|
||||
{
|
||||
protected static final Logger _log = Logger.getLogger(AbstractEnchantItem.class.getName());
|
||||
|
||||
private static final ItemType[] ENCHANT_TYPES = new ItemType[]
|
||||
{
|
||||
EtcItemType.ANCIENT_CRYSTAL_ENCHANT_AM,
|
||||
EtcItemType.ANCIENT_CRYSTAL_ENCHANT_WP,
|
||||
EtcItemType.BLESS_SCRL_ENCHANT_AM,
|
||||
EtcItemType.BLESS_SCRL_ENCHANT_WP,
|
||||
EtcItemType.SCRL_ENCHANT_AM,
|
||||
EtcItemType.SCRL_ENCHANT_WP,
|
||||
EtcItemType.SCRL_INC_ENCHANT_PROP_AM,
|
||||
EtcItemType.SCRL_INC_ENCHANT_PROP_WP,
|
||||
EtcItemType.BLESS_SCRL_INC_ENCHANT_PROP_AM,
|
||||
EtcItemType.BLESS_SCRL_INC_ENCHANT_PROP_WP,
|
||||
EtcItemType.GIANT_SCRL_ENCHANT_AM,
|
||||
EtcItemType.GIANT_SCRL_ENCHANT_WP,
|
||||
EtcItemType.GIANT_SCRL_INC_ENCHANT_PROP_AM,
|
||||
EtcItemType.GIANT_SCRL_INC_ENCHANT_PROP_WP,
|
||||
EtcItemType.GIANT_SCRL_BLESS_INC_ENCHANT_PROP_AM,
|
||||
EtcItemType.GIANT_SCRL_BLESS_INC_ENCHANT_PROP_WP,
|
||||
EtcItemType.SCRL_BLESS_INC_ENCHANT_PROP_AM,
|
||||
EtcItemType.SCRL_BLESS_INC_ENCHANT_PROP_WP,
|
||||
EtcItemType.BLESS_DROP_SCRL_INC_ENCHANT_PROP_AM,
|
||||
EtcItemType.BLESS_DROP_SCRL_INC_ENCHANT_PROP_WP,
|
||||
EtcItemType.GIANT2_SCRL_BLESS_INC_ENCHANT_PROP_AM,
|
||||
EtcItemType.GIANT2_SCRL_BLESS_INC_ENCHANT_PROP_WP,
|
||||
EtcItemType.SCRL_ENCHANT_HR
|
||||
};
|
||||
|
||||
private final int _id;
|
||||
private final CrystalType _grade;
|
||||
private final int _minEnchantLevel;
|
||||
private final int _maxEnchantLevel;
|
||||
private final int _maxEnchantLevelFighter;
|
||||
private final int _maxEnchantLevelMagic;
|
||||
private final double _bonusRate;
|
||||
|
||||
public AbstractEnchantItem(StatsSet set)
|
||||
{
|
||||
_id = set.getInt("id");
|
||||
if (getItem() == null)
|
||||
{
|
||||
throw new NullPointerException();
|
||||
}
|
||||
else if (!Util.contains(ENCHANT_TYPES, getItem().getItemType()))
|
||||
{
|
||||
throw new IllegalAccessError();
|
||||
}
|
||||
_grade = set.getEnum("targetGrade", CrystalType.class, CrystalType.NONE);
|
||||
_minEnchantLevel = set.getInt("minEnchant", 0);
|
||||
_maxEnchantLevel = set.getInt("maxEnchant", 127);
|
||||
_maxEnchantLevelFighter = set.getInt("maxEnchantFighter", 127);
|
||||
_maxEnchantLevelMagic = set.getInt("maxEnchantMagic", 127);
|
||||
_bonusRate = set.getDouble("bonusRate", 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return id of current item
|
||||
*/
|
||||
public final int getId()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bonus chance that would be added
|
||||
*/
|
||||
public final double getBonusRate()
|
||||
{
|
||||
return _bonusRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@link L2Item} current item/scroll
|
||||
*/
|
||||
public final L2Item getItem()
|
||||
{
|
||||
return ItemTable.getInstance().getTemplate(_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return grade of the item/scroll.
|
||||
*/
|
||||
public final CrystalType getGrade()
|
||||
{
|
||||
return _grade;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if scroll is for weapon, {@code false} for armor
|
||||
*/
|
||||
public abstract boolean isWeapon();
|
||||
|
||||
/**
|
||||
* @return the minimum enchant level that this scroll/item can be used with
|
||||
*/
|
||||
public int getMinEnchantLevel()
|
||||
{
|
||||
return _minEnchantLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the maximum enchant level that this scroll/item can be used with
|
||||
*/
|
||||
public int getMaxEnchantLevel()
|
||||
{
|
||||
return _maxEnchantLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the maximum enchant level that fighter weapon can be enchanted with this scroll
|
||||
*/
|
||||
public int getMaxEnchantLevelFighter()
|
||||
{
|
||||
return _maxEnchantLevelFighter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the maximum enchant level that magic weapon can be enchanted with this scroll
|
||||
*/
|
||||
public int getMaxEnchantLevelMagic()
|
||||
{
|
||||
return _maxEnchantLevelMagic;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemToEnchant the item to be enchanted
|
||||
* @param supportItem
|
||||
* @return {@code true} if this support item can be used with the item to be enchanted, {@code false} otherwise
|
||||
*/
|
||||
public boolean isValid(L2ItemInstance itemToEnchant, EnchantSupportItem supportItem)
|
||||
{
|
||||
if (itemToEnchant == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (itemToEnchant.isEnchantable() == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (!isValidItemType(itemToEnchant.getItem().getType2()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ((_minEnchantLevel != 0) && (itemToEnchant.getEnchantLevel() < _minEnchantLevel))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ((_maxEnchantLevel != 0) && (itemToEnchant.getEnchantLevel() >= _maxEnchantLevel))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ((_maxEnchantLevelFighter != 0) && !itemToEnchant.getItem().isMagicWeapon() && (itemToEnchant.getEnchantLevel() >= _maxEnchantLevelFighter))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ((_maxEnchantLevelMagic != 0) && itemToEnchant.getItem().isMagicWeapon() && (itemToEnchant.getEnchantLevel() >= _maxEnchantLevelMagic))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (_grade != itemToEnchant.getItem().getCrystalTypePlus())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type2
|
||||
* @return {@code true} if current type2 is valid to be enchanted, {@code false} otherwise
|
||||
*/
|
||||
private final boolean isValidItemType(int type2)
|
||||
{
|
||||
if (type2 == L2Item.TYPE2_WEAPON)
|
||||
{
|
||||
return isWeapon();
|
||||
}
|
||||
else if ((type2 == L2Item.TYPE2_SHIELD_ARMOR) || (type2 == L2Item.TYPE2_ACCESSORY))
|
||||
{
|
||||
return !isWeapon();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.model.items.enchant;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.gameserver.model.holders.RangeChanceHolder;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public final class EnchantItemGroup
|
||||
{
|
||||
private static final Logger _log = Logger.getLogger(EnchantItemGroup.class.getName());
|
||||
private final List<RangeChanceHolder> _chances = new ArrayList<>();
|
||||
private final String _name;
|
||||
|
||||
public EnchantItemGroup(String name)
|
||||
{
|
||||
_name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return name of current enchant item group.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param holder
|
||||
*/
|
||||
public void addChance(RangeChanceHolder holder)
|
||||
{
|
||||
_chances.add(holder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param index
|
||||
* @return chance for success rate for current enchant item group.
|
||||
*/
|
||||
public double getChance(int index)
|
||||
{
|
||||
if (!_chances.isEmpty())
|
||||
{
|
||||
for (RangeChanceHolder holder : _chances)
|
||||
{
|
||||
if ((holder.getMin() <= index) && (holder.getMax() >= index))
|
||||
{
|
||||
return holder.getChance();
|
||||
}
|
||||
}
|
||||
_log.log(Level.WARNING, getClass().getSimpleName() + ": Couldn't match proper chance for item group: " + _name, new IllegalStateException());
|
||||
return _chances.get(_chances.size() - 1).getChance();
|
||||
}
|
||||
_log.log(Level.WARNING, getClass().getSimpleName() + ": item group: " + _name + " doesn't have any chances!");
|
||||
return -1;
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.model.items.enchant;
|
||||
|
||||
import com.l2jmobius.gameserver.model.items.L2Item;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public final class EnchantRateItem
|
||||
{
|
||||
private final String _name;
|
||||
private int _itemId;
|
||||
private int _slot;
|
||||
private Boolean _isMagicWeapon = null;
|
||||
|
||||
public EnchantRateItem(String name)
|
||||
{
|
||||
_name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return name of enchant group.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds item id verification.
|
||||
* @param id
|
||||
*/
|
||||
public void setItemId(int id)
|
||||
{
|
||||
_itemId = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds body slot verification.
|
||||
* @param slot
|
||||
*/
|
||||
public void addSlot(int slot)
|
||||
{
|
||||
_slot |= slot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds magic weapon verification.
|
||||
* @param magicWeapon
|
||||
*/
|
||||
public void setMagicWeapon(boolean magicWeapon)
|
||||
{
|
||||
_isMagicWeapon = magicWeapon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param item
|
||||
* @return {@code true} if item can be used with this rate group, {@code false} otherwise.
|
||||
*/
|
||||
public boolean validate(L2Item item)
|
||||
{
|
||||
if ((_itemId != 0) && (_itemId != item.getId()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ((_slot != 0) && ((item.getBodyPart() & _slot) == 0))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ((_isMagicWeapon != null) && (item.isMagicWeapon() != _isMagicWeapon))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.model.items.enchant;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public enum EnchantResultType
|
||||
{
|
||||
ERROR,
|
||||
SUCCESS,
|
||||
FAILURE
|
||||
}
|
@ -0,0 +1,248 @@
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.model.items.enchant;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.l2jmobius.gameserver.data.xml.impl.EnchantItemGroupsData;
|
||||
import com.l2jmobius.gameserver.model.StatsSet;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.model.items.L2Item;
|
||||
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
|
||||
import com.l2jmobius.gameserver.model.items.type.EtcItemType;
|
||||
import com.l2jmobius.gameserver.model.items.type.ItemType;
|
||||
import com.l2jmobius.gameserver.network.Debug;
|
||||
import com.l2jmobius.gameserver.util.Util;
|
||||
import com.l2jmobius.util.Rnd;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public final class EnchantScroll extends AbstractEnchantItem
|
||||
{
|
||||
private final boolean _isWeapon;
|
||||
private final boolean _isBlessed;
|
||||
private final boolean _isSafe;
|
||||
private final boolean _isGiant;
|
||||
private final boolean _isHair;
|
||||
private final int _scrollGroupId;
|
||||
private Set<Integer> _items;
|
||||
|
||||
public EnchantScroll(StatsSet set)
|
||||
{
|
||||
super(set);
|
||||
_scrollGroupId = set.getInt("scrollGroupId", 0);
|
||||
|
||||
final ItemType type = getItem().getItemType();
|
||||
_isWeapon = (type == EtcItemType.GIANT_SCRL_ENCHANT_WP) || (type == EtcItemType.ANCIENT_CRYSTAL_ENCHANT_WP) || (type == EtcItemType.BLESS_SCRL_ENCHANT_WP) || (type == EtcItemType.SCRL_ENCHANT_WP);
|
||||
_isBlessed = (type == EtcItemType.BLESS_SCRL_ENCHANT_AM) || (type == EtcItemType.BLESS_SCRL_ENCHANT_WP);
|
||||
_isSafe = (type == EtcItemType.ANCIENT_CRYSTAL_ENCHANT_AM) || (type == EtcItemType.ANCIENT_CRYSTAL_ENCHANT_WP);
|
||||
_isGiant = (type == EtcItemType.GIANT_SCRL_ENCHANT_AM) || (type == EtcItemType.GIANT_SCRL_ENCHANT_WP);
|
||||
_isHair = (type == EtcItemType.SCRL_ENCHANT_HR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWeapon()
|
||||
{
|
||||
return _isWeapon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} for blessed scrolls (enchanted item will remain on failure), {@code false} otherwise
|
||||
*/
|
||||
public boolean isBlessed()
|
||||
{
|
||||
return _isBlessed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} for safe-enchant scrolls (enchant level will remain on failure), {@code false} otherwise
|
||||
*/
|
||||
public boolean isSafe()
|
||||
{
|
||||
return _isSafe;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} for giant scrolls (enchant attempts has a chance of increasing the enchant value between +1 and +3 randomly), {@code false} otherwise
|
||||
*/
|
||||
public boolean isGiant()
|
||||
{
|
||||
return _isGiant;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} for hair enchant scrolls, {@code false} otherwise
|
||||
*/
|
||||
public boolean isHair()
|
||||
{
|
||||
return _isHair;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return id of scroll group that should be used
|
||||
*/
|
||||
public int getScrollGroupId()
|
||||
{
|
||||
return _scrollGroupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enforces current scroll to use only those items as possible items to enchant
|
||||
* @param itemId
|
||||
*/
|
||||
public void addItem(int itemId)
|
||||
{
|
||||
if (_items == null)
|
||||
{
|
||||
_items = new HashSet<>();
|
||||
}
|
||||
_items.add(itemId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemToEnchant the item to be enchanted
|
||||
* @param supportItem the support item used when enchanting (can be null)
|
||||
* @return {@code true} if this scroll can be used with the specified support item and the item to be enchanted, {@code false} otherwise
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid(L2ItemInstance itemToEnchant, EnchantSupportItem supportItem)
|
||||
{
|
||||
if ((_items != null) && !_items.contains(itemToEnchant.getId()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (isHair() && (itemToEnchant.getItem().getBodyPart() != L2Item.SLOT_HAIR) && (itemToEnchant.getItem().getBodyPart() != L2Item.SLOT_HAIR2) && (itemToEnchant.getItem().getBodyPart() != L2Item.SLOT_HAIRALL))
|
||||
{
|
||||
_log.info("bodypart: " + itemToEnchant.getItem().getBodyPart());
|
||||
return false;
|
||||
}
|
||||
else if ((supportItem != null))
|
||||
{
|
||||
if (isBlessed() && (supportItem.getItem().getItemType() != EtcItemType.BLESS_SCRL_INC_ENCHANT_PROP_WP) && (supportItem.getItem().getItemType() != EtcItemType.BLESS_SCRL_INC_ENCHANT_PROP_AM) && (supportItem.getItem().getItemType() != EtcItemType.BLESS_DROP_SCRL_INC_ENCHANT_PROP_WP) && (supportItem.getItem().getItemType() != EtcItemType.BLESS_DROP_SCRL_INC_ENCHANT_PROP_AM))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (isGiant() && (supportItem.getItem().getItemType() != EtcItemType.GIANT_SCRL_INC_ENCHANT_PROP_WP) && (supportItem.getItem().getItemType() != EtcItemType.GIANT_SCRL_INC_ENCHANT_PROP_AM) && (supportItem.getItem().getItemType() != EtcItemType.GIANT_SCRL_BLESS_INC_ENCHANT_PROP_WP) && (supportItem.getItem().getItemType() != EtcItemType.GIANT_SCRL_BLESS_INC_ENCHANT_PROP_AM) && (supportItem.getItem().getItemType() != EtcItemType.GIANT2_SCRL_BLESS_INC_ENCHANT_PROP_AM) && (supportItem.getItem().getItemType() != EtcItemType.GIANT2_SCRL_BLESS_INC_ENCHANT_PROP_WP))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (!isBlessed() && !isGiant() && (supportItem.getItem().getItemType() != EtcItemType.SCRL_INC_ENCHANT_PROP_WP) && (supportItem.getItem().getItemType() != EtcItemType.SCRL_INC_ENCHANT_PROP_AM) && (supportItem.getItem().getItemType() != EtcItemType.SCRL_BLESS_INC_ENCHANT_PROP_WP) && (supportItem.getItem().getItemType() != EtcItemType.SCRL_BLESS_INC_ENCHANT_PROP_AM))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (!supportItem.isValid(itemToEnchant, supportItem))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (supportItem.isWeapon() != isWeapon())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return super.isValid(itemToEnchant, supportItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* @param enchantItem
|
||||
* @return the chance of current scroll's group.
|
||||
*/
|
||||
public double getChance(L2PcInstance player, L2ItemInstance enchantItem)
|
||||
{
|
||||
if (EnchantItemGroupsData.getInstance().getScrollGroup(_scrollGroupId) == null)
|
||||
{
|
||||
_log.log(Level.WARNING, getClass().getSimpleName() + ": Unexistent enchant scroll group specified for enchant scroll: " + getId());
|
||||
return -1;
|
||||
}
|
||||
|
||||
final EnchantItemGroup group = EnchantItemGroupsData.getInstance().getItemGroup(enchantItem.getItem(), _scrollGroupId);
|
||||
if (group == null)
|
||||
{
|
||||
_log.log(Level.WARNING, getClass().getSimpleName() + ": Couldn't find enchant item group for scroll: " + getId() + " requested by: " + player);
|
||||
return -1;
|
||||
}
|
||||
return group.getChance(enchantItem.getEnchantLevel());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* @param enchantItem
|
||||
* @param supportItem
|
||||
* @return the total chance for success rate of this scroll
|
||||
*/
|
||||
public EnchantResultType calculateSuccess(L2PcInstance player, L2ItemInstance enchantItem, EnchantSupportItem supportItem)
|
||||
{
|
||||
if (!isValid(enchantItem, supportItem))
|
||||
{
|
||||
return EnchantResultType.ERROR;
|
||||
}
|
||||
|
||||
final double chance = getChance(player, enchantItem);
|
||||
if (chance == -1)
|
||||
{
|
||||
return EnchantResultType.ERROR;
|
||||
}
|
||||
|
||||
final double bonusRate = getBonusRate();
|
||||
final double supportBonusRate = (supportItem != null) ? supportItem.getBonusRate() : 0;
|
||||
final double finalChance = Math.min(chance + bonusRate + supportBonusRate, 100);
|
||||
|
||||
final double random = 100 * Rnd.nextDouble();
|
||||
final boolean success = (random < finalChance);
|
||||
|
||||
if (player.isDebug())
|
||||
{
|
||||
final EnchantItemGroup group = EnchantItemGroupsData.getInstance().getItemGroup(enchantItem.getItem(), _scrollGroupId);
|
||||
final StatsSet set = new StatsSet();
|
||||
if (isBlessed())
|
||||
{
|
||||
set.set("isBlessed", isBlessed());
|
||||
}
|
||||
if (isSafe())
|
||||
{
|
||||
set.set("isSafe", isSafe());
|
||||
}
|
||||
if (isGiant())
|
||||
{
|
||||
set.set("isGiant", isGiant());
|
||||
}
|
||||
if (isHair())
|
||||
{
|
||||
set.set("isHair", isHair());
|
||||
}
|
||||
set.set("chance", Util.formatDouble(chance, "#.##"));
|
||||
if (bonusRate > 0)
|
||||
{
|
||||
set.set("bonusRate", Util.formatDouble(bonusRate, "#.##"));
|
||||
}
|
||||
if (supportBonusRate > 0)
|
||||
{
|
||||
set.set("supportBonusRate", Util.formatDouble(supportBonusRate, "#.##"));
|
||||
}
|
||||
set.set("finalChance", Util.formatDouble(finalChance, "#.##"));
|
||||
set.set("random", Util.formatDouble(random, "#.##"));
|
||||
set.set("success", success);
|
||||
set.set("item group", group.getName());
|
||||
set.set("scroll group", _scrollGroupId);
|
||||
Debug.sendItemDebug(player, enchantItem, set);
|
||||
}
|
||||
return success ? EnchantResultType.SUCCESS : EnchantResultType.FAILURE;
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.model.items.enchant;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.l2jmobius.gameserver.model.items.L2Item;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public final class EnchantScrollGroup
|
||||
{
|
||||
private final int _id;
|
||||
private List<EnchantRateItem> _rateGroups;
|
||||
|
||||
public EnchantScrollGroup(int id)
|
||||
{
|
||||
_id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return id of current enchant scroll group.
|
||||
*/
|
||||
public int getId()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new rate group.
|
||||
* @param group
|
||||
*/
|
||||
public void addRateGroup(EnchantRateItem group)
|
||||
{
|
||||
if (_rateGroups == null)
|
||||
{
|
||||
_rateGroups = new ArrayList<>();
|
||||
}
|
||||
_rateGroups.add(group);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code List} of all enchant rate items, Empty list if none.
|
||||
*/
|
||||
public List<EnchantRateItem> getRateGroups()
|
||||
{
|
||||
return _rateGroups != null ? _rateGroups : Collections.<EnchantRateItem> emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param item
|
||||
* @return {@link EnchantRateItem}, {@code NULL} in case non of rate items can be used with.
|
||||
*/
|
||||
public EnchantRateItem getRateGroup(L2Item item)
|
||||
{
|
||||
for (EnchantRateItem group : getRateGroups())
|
||||
{
|
||||
if (group.validate(item))
|
||||
{
|
||||
return group;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.model.items.enchant;
|
||||
|
||||
import com.l2jmobius.gameserver.model.StatsSet;
|
||||
import com.l2jmobius.gameserver.model.items.type.EtcItemType;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public final class EnchantSupportItem extends AbstractEnchantItem
|
||||
{
|
||||
private final boolean _isWeapon;
|
||||
|
||||
public EnchantSupportItem(StatsSet set)
|
||||
{
|
||||
super(set);
|
||||
if ((getItem().getItemType() == EtcItemType.SCRL_INC_ENCHANT_PROP_WP) || (getItem().getItemType() == EtcItemType.BLESS_SCRL_INC_ENCHANT_PROP_WP) || (getItem().getItemType() == EtcItemType.GIANT_SCRL_INC_ENCHANT_PROP_WP) || (getItem().getItemType() == EtcItemType.GIANT_SCRL_BLESS_INC_ENCHANT_PROP_WP) || (getItem().getItemType() == EtcItemType.SCRL_BLESS_INC_ENCHANT_PROP_WP) || (getItem().getItemType() == EtcItemType.BLESS_DROP_SCRL_INC_ENCHANT_PROP_WP) || (getItem().getItemType() == EtcItemType.GIANT2_SCRL_BLESS_INC_ENCHANT_PROP_WP))
|
||||
{
|
||||
_isWeapon = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_isWeapon = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWeapon()
|
||||
{
|
||||
return _isWeapon;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user