From 62963b342476789baf79add54d0d035ef1cdb2fa Mon Sep 17 00:00:00 2001 From: ErikasKontenis Date: Wed, 14 Apr 2021 22:52:30 +0300 Subject: [PATCH] introduce random stat values for quest items --- data/actions/scripts/misc/chests.lua | 45 +++++++++++++++++++++++++++- src/item.cpp | 24 +++++++-------- 2 files changed, 56 insertions(+), 13 deletions(-) diff --git a/data/actions/scripts/misc/chests.lua b/data/actions/scripts/misc/chests.lua index ce54d9a..b94751a 100644 --- a/data/actions/scripts/misc/chests.lua +++ b/data/actions/scripts/misc/chests.lua @@ -45,7 +45,50 @@ function onUse(player, item, fromPosition, target, toPosition) end player:sendTextMessage(MESSAGE_INFO_DESCR, "You have found " .. rewardName .. ".") - player:addItemEx(reward:clone(), true) + + local attackAttribute = math.random(-2, 5) + local rewardClone = reward:clone() + if rewardClone:getType():getAttack() > 0 then + rewardClone:setAttribute(ITEM_ATTRIBUTE_ATTACK, rewardClone:getType():getAttack() + attackAttribute) + local description = rewardClone:hasAttribute(ITEM_ATTRIBUTE_DESCRIPTION) and rewardClone:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION) or rewardClone:getType():getDescription() + if attackAttribute == 5 then + if description == nil or description == '' then + rewardClone:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, description .. "Enchanted with perfect attack.") + else + rewardClone:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, description .. ". Enchanted with perfect attack.") + end + end + end + local defenseAttribute = math.random(-2, 5) + if rewardClone:getType():getDefense() > 0 then + rewardClone:setAttribute(ITEM_ATTRIBUTE_DEFENSE, rewardClone:getType():getDefense() + defenseAttribute) + local description = rewardClone:hasAttribute(ITEM_ATTRIBUTE_DESCRIPTION) and rewardClone:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION) or rewardClone:getType():getDescription() + if defenseAttribute == 5 then + if attackAttribute == 5 and rewardClone:getType():getAttack() > 0 then + rewardClone:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, description .. " Enchanted with perfect defense.") + else + if description == nil or description == '' then + rewardClone:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, description .. "Enchanted with perfect defense.") + else + rewardClone:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, description .. ". Enchanted with perfect defense.") + end + end + end + end + local armorAttribute = math.random(-1, 2) + if rewardClone:getType():getArmor() > 0 then + rewardClone:setAttribute(ITEM_ATTRIBUTE_ARMOR, rewardClone:getType():getArmor() + armorAttribute) + local description = rewardClone:hasAttribute(ITEM_ATTRIBUTE_DESCRIPTION) and rewardClone:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION) or rewardClone:getType():getDescription() + if armorAttribute == 2 then + if description == nil or description == '' then + rewardClone:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, description .. "Enchanted with perfect armor protection.") + else + rewardClone:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, description .. ". Enchanted with perfect armor protection.") + end + end + end + + player:addItemEx(rewardClone, true) player:setStorageValue(chestQuestNumber, 1) return true end diff --git a/src/item.cpp b/src/item.cpp index 509c79f..929f22c 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -881,28 +881,28 @@ std::string Item::getDescription(const ItemType& it, int32_t lookDistance, } else if (it.weaponType != WEAPON_NONE) { if (it.weaponType == WEAPON_DISTANCE && it.ammoType != AMMO_NONE) { - if (it.attack != 0) { - s << ", Atk" << std::showpos << it.attack << std::noshowpos; + if (item->getAttack() != 0) { + s << ", Atk" << std::showpos << item->getAttack() << std::noshowpos; } } - else if (it.weaponType != WEAPON_WAND && (it.attack != 0 || it.defense != 0)) { + else if (it.weaponType != WEAPON_WAND && (item->getAttack() != 0 || item->getDefense() != 0)) { s << " ("; - if (it.attack != 0) { - s << "Atk:" << static_cast(it.attack); + if (item->getAttack() != 0) { + s << "Atk:" << static_cast(item->getAttack()); } - if (it.defense != 0) { - if (it.attack != 0) + if (item->getDefense() != 0) { + if (item->getAttack() != 0) s << " "; - s << "Def:" << static_cast(it.defense); + s << "Def:" << static_cast(item->getDefense()); } s << ")"; } s << "."; } - else if (it.armor != 0 || (it.abilities && it.abilities->speed != 0)) { + else if (item->getArmor() != 0 || (it.abilities && it.abilities->speed != 0)) { if (it.charges > 0) { if (subType > 1) { s << " that has " << static_cast(subType) << " charges left"; @@ -913,11 +913,11 @@ std::string Item::getDescription(const ItemType& it, int32_t lookDistance, } s << " ("; - if (it.armor > 0) { - s << "Arm:" << it.armor; + if (item->getArmor() > 0) { + s << "Arm:" << item->getArmor(); } if (it.abilities && it.abilities->speed > 0) { - if (it.armor > 0) { + if (item->getArmor() > 0) { s << ", "; } s << "Speed +" << it.abilities->speed;