Skip to content

Commit

Permalink
attr element + lua function
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoTKBR committed Nov 22, 2024
1 parent d35e4a8 commit cb2d327
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 9 deletions.
6 changes: 6 additions & 0 deletions data/scripts/talkactions/god/attributes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ local itemFunctions = {
return item:setAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE, target)
end,
},
["element"] = {
isActive = true,
targetFunction = function(item, target)
return item:setAttribute(ITEM_ATTRIBUTE_ELEMENT, target)
end,
},
["charge"] = {
isActive = true,
targetFunction = function(item, target)
Expand Down
1 change: 1 addition & 0 deletions src/enums/item_attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ enum class ItemAttribute_t : uint64_t {
STORE_INBOX_CATEGORY = 34,
OBTAINCONTAINER = 35,
AUGMENTS = 36,
ELEMENT = 37,
};

enum ItemDecayState_t : uint8_t {
Expand Down
1 change: 1 addition & 0 deletions src/items/functions/item/attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ItemAttributeHelper {
case ItemAttribute_t::ATTACK:
case ItemAttribute_t::DEFENSE:
case ItemAttribute_t::EXTRADEFENSE:
case ItemAttribute_t::ELEMENT:
case ItemAttribute_t::ARMOR:
case ItemAttribute_t::HITCHANCE:
case ItemAttribute_t::SHOOTRANGE:
Expand Down
29 changes: 24 additions & 5 deletions src/items/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,16 @@ Attr_ReadValue Item::readAttr(AttrTypes_t attr, PropStream &propStream) {
break;
}

case ATTR_ELEMENT: {
int32_t element;
if (!propStream.read<int32_t>(element)) {
return ATTR_READ_ERROR;
}

setAttribute(ItemAttribute_t::ELEMENT, element);
break;
}

case ATTR_IMBUEMENT_SLOT: {
int32_t imbuementSlot;
if (!propStream.read<int32_t>(imbuementSlot)) {
Expand Down Expand Up @@ -1038,6 +1048,11 @@ void Item::serializeAttr(PropWriteStream &propWriteStream) const {
propWriteStream.write<int32_t>(getAttribute<int32_t>(ItemAttribute_t::EXTRADEFENSE));
}

if (hasAttribute(ItemAttribute_t::ELEMENT)) {
propWriteStream.write<uint8_t>(ATTR_ELEMENT);
propWriteStream.write<int32_t>(getAttribute<int32_t>(ItemAttribute_t::ELEMENT));
}

if (hasAttribute(ItemAttribute_t::IMBUEMENT_SLOT)) {
propWriteStream.write<uint8_t>(ATTR_IMBUEMENT_SLOT);
propWriteStream.write<int32_t>(getAttribute<int32_t>(ItemAttribute_t::IMBUEMENT_SLOT));
Expand Down Expand Up @@ -1258,6 +1273,7 @@ Item::getDescriptions(const ItemType &it, const std::shared_ptr<Item> &item /*=
}

int32_t attack = item->getAttack();
int32_t element = item->getElementDamage();
if (it.isRanged()) {
bool separator = false;
if (attack != 0) {
Expand All @@ -1283,7 +1299,7 @@ Item::getDescriptions(const ItemType &it, const std::shared_ptr<Item> &item /*=
} else {
std::string attackDescription;
if (it.abilities && it.abilities->elementType != COMBAT_NONE && it.abilities->elementDamage != 0) {
attackDescription = fmt::format("{} {}", it.abilities->elementDamage, getCombatName(it.abilities->elementType));
attackDescription = fmt::format("{} {}", ((element > 0) ? element : it.abilities->elementDamage), getCombatName(it.abilities->elementType));
}

if (attack != 0 && !attackDescription.empty()) {
Expand Down Expand Up @@ -1682,6 +1698,7 @@ Item::getDescriptions(const ItemType &it, const std::shared_ptr<Item> &item /*=
}

int32_t attack = it.attack;
int32_t element = it.element;
if (it.isRanged()) {
bool separator = false;
if (attack != 0) {
Expand All @@ -1707,7 +1724,7 @@ Item::getDescriptions(const ItemType &it, const std::shared_ptr<Item> &item /*=
} else {
std::string attackDescription;
if (it.abilities && it.abilities->elementType != COMBAT_NONE && it.abilities->elementDamage != 0) {
attackDescription = fmt::format("{} {}", it.abilities->elementDamage, getCombatName(it.abilities->elementType));
attackDescription = fmt::format("{} {}", ((element > 0) ? element : it.abilities->elementDamage), getCombatName(it.abilities->elementType));
}

if (attack != 0 && !attackDescription.empty()) {
Expand Down Expand Up @@ -2726,15 +2743,17 @@ std::string Item::getDescription(const ItemType &it, int32_t lookDistance, const
} else if (it.weaponType != WEAPON_AMMO) {
bool begin = true;

int32_t attack, defense, extraDefense;
int32_t attack, defense, extraDefense, element;
if (item) {
attack = item->getAttack();
defense = item->getDefense();
extraDefense = item->getExtraDefense();
element = item->getElementDamage();
} else {
attack = it.attack;
defense = it.defense;
extraDefense = it.extraDefense;
element = it.element;
}

if (it.isContainer() || (item && item->getContainer())) {
Expand Down Expand Up @@ -2766,10 +2785,10 @@ std::string Item::getDescription(const ItemType &it, int32_t lookDistance, const
}

if (it.abilities && it.abilities->elementType != COMBAT_NONE && it.abilities->elementDamage != 0 && !begin) {
s << " physical + " << it.abilities->elementDamage << ' ' << getCombatName(it.abilities->elementType);
s << " physical + " << ((element > 0) ? element : it.abilities->elementDamage) << ' ' << getCombatName(it.abilities->elementType);
} else if (it.abilities && it.abilities->elementType != COMBAT_NONE && it.abilities->elementDamage != 0 && begin) {
begin = false;
s << " (" << it.abilities->elementDamage << ' ' << getCombatName(it.abilities->elementType);
s << " (" << ((element > 0) ? element : it.abilities->elementDamage) << ' ' << getCombatName(it.abilities->elementType);
}

if (defense != 0 || extraDefense != 0 || it.isMissile()) {
Expand Down
6 changes: 6 additions & 0 deletions src/items/item.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ class Item : virtual public Thing, public ItemProperties, public SharedObject {
}
return items[id].extraDefense;
}
int32_t getElementDamage() const {
if (hasAttribute(ItemAttribute_t::ELEMENT)) {
return getAttribute<int32_t>(ItemAttribute_t::ELEMENT);
}
return items[id].element;
}
std::vector<std::shared_ptr<AugmentInfo>> getAugments() const {
return items[id].augments;
}
Expand Down
1 change: 1 addition & 0 deletions src/items/items.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ class ItemType {
int32_t attack = 0;
int32_t defense = 0;
int32_t extraDefense = 0;
int32_t element = 0;
int32_t armor = 0;
int32_t rotateTo = 0;
int32_t runeMagLevel = 0;
Expand Down
1 change: 1 addition & 0 deletions src/items/items_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ enum AttrTypes_t {
ATTR_STORE_INBOX_CATEGORY = 42,
ATTR_OWNER = 43,
ATTR_OBTAINCONTAINER = 44,
ATTR_ELEMENT = 45,

// Always the last
ATTR_NONE = 0
Expand Down
8 changes: 4 additions & 4 deletions src/items/weapons/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,9 @@ int32_t WeaponMelee::getElementDamage(const std::shared_ptr<Player> &player, con
if (elementType == COMBAT_NONE) {
return 0;
}

const int32_t element = item->getElementDamage();
const int32_t attackSkill = player->getWeaponSkill(item);
const int32_t attackValue = elementDamage;
const int32_t attackValue = (element > 0) ? element : elementDamage;
const float attackFactor = player->getAttackFactor();
const uint32_t level = player->getLevel();

Expand Down Expand Up @@ -833,8 +833,8 @@ int32_t WeaponDistance::getElementDamage(const std::shared_ptr<Player> &player,
if (elementType == COMBAT_NONE) {
return 0;
}

int32_t attackValue = elementDamage;
int32_t element = item->getElementDamage();
int32_t attackValue = (element > 0) ? element : elementDamage;
if (item && player && item->getWeaponType() == WEAPON_AMMO) {
const auto &weapon = player->getWeapon(true);
if (weapon) {
Expand Down
3 changes: 3 additions & 0 deletions src/utils/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,9 @@ ItemAttribute_t stringToItemAttribute(const std::string &str) {
if (str == "extradefense") {
return ItemAttribute_t::EXTRADEFENSE;
}
if (str == "element") {
return ItemAttribute_t::ELEMENT;
}
if (str == "armor") {
return ItemAttribute_t::ARMOR;
}
Expand Down

0 comments on commit cb2d327

Please sign in to comment.