player.setAppearanceStone(null);
player.setAppearanceExtractItem(null);
return;
}
AppearanceStone appearanceStone = EnchantItemHolder.getInstance().getAppearanceStone(stone.getItemId());
if(appearanceStone == null)
{
player.sendPacket(ExShapeShiftingResult.FAIL);
player.setAppearanceStone(null);
player.setAppearanceExtractItem(null);
return;
}
if(appearanceStone.getType() != ShapeType.RESTORE && targetItem.getVisualId() > 0 || appearanceStone.getType() == ShapeType.RESTORE && targetItem.getVisualId() == 0)
{
player.sendPacket(ExShapeShiftingResult.FAIL);
player.setAppearanceStone(null);
player.setAppearanceExtractItem(null);
return;
}
if(!targetItem.isOther() && targetItem.getTemplate().getItemGrade() == Grade.NONE)
{
player.sendPacket(ExShapeShiftingResult.FAIL);
player.setAppearanceStone(null);
player.setAppearanceExtractItem(null);
return;
}
Grade[] stoneGrades = appearanceStone.getGrades();
if(stoneGrades != null && stoneGrades.length > 0)
{
if(!ArrayUtils.contains(stoneGrades, targetItem.getTemplate().getItemGrade()))
{
player.sendPacket(ExShapeShiftingResult.FAIL);
player.setAppearanceStone(null);
player.setAppearanceExtractItem(null);
return;
}
}
ShapeTargetType[] targetTypes = appearanceStone.getTargetTypes();
if(targetTypes == null || targetTypes.length == 0)
{
player.sendPacket(ExShapeShiftingResult.FAIL);
player.setAppearanceStone(null);
player.setAppearanceExtractItem(null);
return;
}
if(!ArrayUtils.contains(targetTypes, ShapeTargetType.ALL))
{
if(targetItem.isWeapon())
{
if(!ArrayUtils.contains(targetTypes, ShapeTargetType.WEAPON))
{
player.sendPacket(ExShapeShiftingResult.FAIL);
player.setAppearanceStone(null);
player.setAppearanceExtractItem(null);
return;
}
}
else if(targetItem.isArmor())
{
if(!ArrayUtils.contains(targetTypes, ShapeTargetType.ARMOR))
{
player.sendPacket(ExShapeShiftingResult.FAIL);
player.setAppearanceStone(null);
player.setAppearanceExtractItem(null);
return;
}
}
else
{
if(!ArrayUtils.contains(targetTypes, ShapeTargetType.ACCESSORY))
{
player.sendPacket(ExShapeShiftingResult.FAIL);
player.setAppearanceStone(null);
player.setAppearanceExtractItem(null);
return;
}
}
}
ExItemType[] itemTypes = appearanceStone.getItemTypes();
if(itemTypes != null && itemTypes.length > 0)
{
if(!ArrayUtils.contains(itemTypes, targetItem.getExItemType()))
{
player.sendPacket(ExShapeShiftingResult.FAIL);
player.setAppearanceStone(null);
player.setAppearanceExtractItem(null);
return;
}
}
ItemInstance extracItem = player.getAppearanceExtractItem();
int extracItemId = 0;
if(appearanceStone.getType() != ShapeType.RESTORE && appearanceStone.getType() != ShapeType.FIXED)
{
if(extracItem == null)
{
player.sendPacket(ExShapeShiftingResult.FAIL);
player.setAppearanceStone(null);
player.setAppearanceExtractItem(null);
return;
}
if(!extracItem.canBeAppearance())
{
player.sendPacket(ExShapeShiftingResult.FAIL);
player.setAppearanceStone(null);
player.setAppearanceExtractItem(null);
return;
}
if(extracItem.getLocation() != ItemInstance.ItemLocation.INVENTORY && extracItem.getLocation() != ItemInstance.ItemLocation.PAPERDOLL)
{
player.sendPacket(ExShapeShiftingResult.FAIL);
player.setAppearanceStone(null);
player.setAppearanceExtractItem(null);
return;
}
/*if(!extracItem.isOther() && extracItem.getGrade() == ItemGrade.NONE)
{
player.sendPacket(ExShapeShiftingResult.FAIL);
player.setAppearanceStone(null);
player.setAppearanceExtractItem(null);
return;
}*/
if(!extracItem.isOther() && targetItem.getTemplate().getItemGrade().ordinal() <= extracItem.getTemplate().getItemGrade().ordinal())
{
player.sendPacket(ExShapeShiftingResult.FAIL);
player.setAppearanceStone(null);
player.setAppearanceExtractItem(null);
return;
}
if(extracItem.getVisualId() > 0)
{
player.sendPacket(ExShapeShiftingResult.FAIL);
player.setAppearanceStone(null);
player.setAppearanceExtractItem(null);
return;
}
if(targetItem.getExItemType() != extracItem.getExItemType())
{
player.sendPacket(ExShapeShiftingResult.FAIL);
player.setAppearanceStone(null);
player.setAppearanceExtractItem(null);
return;
}
if(extracItem.getOwnerId() != player.getObjectId())
{
player.sendPacket(ExShapeShiftingResult.FAIL);
player.setAppearanceStone(null);
player.setAppearanceExtractItem(null);
return;
}
extracItemId = extracItem.getItemId();
}
if(targetItem.getOwnerId() != player.getObjectId())
{
player.sendPacket(ExShapeShiftingResult.FAIL);
player.setAppearanceStone(null);
player.setAppearanceExtractItem(null);
return;
}
inventory.writeLock();
try
{
long cost = appearanceStone.getCost();
if(cost > player.getAdena())
{
player.sendPacket(SystemMsg.YOU_CANNOT_MODIFY_AS_YOU_DO_NOT_HAVE_ENOUGH_ADENA);
player.sendPacket(ExShapeShiftingResult.FAIL);
player.setAppearanceStone(null);
player.setAppearanceExtractItem(null);
return;
}
if(stone.getCount() < 1L)
{
player.sendPacket(ExShapeShiftingResult.FAIL);
player.setAppearanceStone(null);
player.setAppearanceExtractItem(null);
return;
}
if(appearanceStone.getType() == ShapeType.NORMAL)
{
if(!inventory.destroyItem(extracItem, 1L))
{
player.sendPacket(ExShapeShiftingResult.FAIL);
player.setAppearanceStone(null);
player.setAppearanceExtractItem(null);
return;
}
}
inventory.destroyItem(stone, 1L);
player.reduceAdena(cost);
boolean equipped = false;
if(equipped = targetItem.isEquipped())
{
inventory.isRefresh = true;
inventory.unEquipItem(targetItem);
}
switch(appearanceStone.getType())
{
case RESTORE:
targetItem.setVisualId(0);
break;
case NORMAL:
targetItem.setVisualId(extracItem.getItemId());
break;
case BLESSED:
targetItem.setVisualId(extracItem.getItemId());
break;
case FIXED:
targetItem.setVisualId(appearanceStone.getExtractItemId());
break;
default:
break;
}