Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: attr element function #3149

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
498228c
Update login.lua
LeoTKBR Oct 4, 2023
e492edf
Create autosync.yml
LeoTKBR Nov 1, 2023
b312e75
Update autosync.yml
LeoTKBR Nov 1, 2023
13c7799
Update autosync.yml
LeoTKBR Nov 1, 2023
abcc3a2
Update autosync.yml
LeoTKBR Nov 1, 2023
a383e95
Update autosync.yml
LeoTKBR Nov 1, 2023
e0b9d70
Update autosync.yml
LeoTKBR Nov 1, 2023
467fe4e
Update autosync.yml
LeoTKBR Nov 1, 2023
ae7e3ec
Update autosync.yml
LeoTKBR Nov 1, 2023
40f9d9e
Update autosync.yml
LeoTKBR Nov 1, 2023
430c489
Update autosync.yml
LeoTKBR Nov 1, 2023
965160d
Merge branch 'opentibiabr:main' into main
LeoTKBR Nov 4, 2023
708239f
Update autosync.yml
LeoTKBR Nov 4, 2023
203fa21
Merge branch 'opentibiabr:main' into main
LeoTKBR Nov 4, 2023
6927683
Merge branch 'main' of https://github.com/LeoTKBR/canary
LeoTKBR Nov 5, 2023
6dbe8ea
Merge branch 'opentibiabr:main' into main
LeoTKBR Nov 7, 2023
bfaef08
Merge branch 'opentibiabr:main' into main
LeoTKBR Nov 9, 2023
eabbcc5
Merge branch 'opentibiabr:main' into main
LeoTKBR Nov 16, 2023
61541d4
Merge branch 'opentibiabr:main' into main
LeoTKBR Nov 19, 2023
82c3ebf
Merge branch 'opentibiabr:main' into main
LeoTKBR Nov 23, 2023
67f7a9a
Merge branch 'opentibiabr:main' into main
LeoTKBR Nov 30, 2023
65f4896
Merge branch 'opentibiabr:main' into main
LeoTKBR Dec 5, 2023
45c764f
Merge branch 'opentibiabr:main' into main
LeoTKBR Sep 17, 2024
9c2f4db
Merge branch 'opentibiabr:main' into main
LeoTKBR Nov 7, 2024
d35e4a8
Merge branch 'opentibiabr:main' into main
LeoTKBR Nov 21, 2024
cb2d327
attr element + lua function
LeoTKBR Nov 22, 2024
869a503
Delete .github/workflows/autosync.yml
LeoTKBR Nov 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading