diff --git a/docs/FEATURE-AVA2-UNLOCK.md b/docs/FEATURE-AVA2-UNLOCK.md index 40c1939e..94fc3f7f 100644 --- a/docs/FEATURE-AVA2-UNLOCK.md +++ b/docs/FEATURE-AVA2-UNLOCK.md @@ -10,6 +10,7 @@ The 478 AVA2 drop items come from metin2-client `tools/server/ava2-items` (see F | P4 sash | 85004 领主 / 85008 大师 / 85014 王æœ� / 85018 皇家 披风 (`COSTUME_SASH`, grade 4) | done, not deployed | | P5 mounts | 71502 / 71505 / 71508 / 71511 å��骑时装 (`COSTUME_MOUNT`), 71234 / 71254 å��骑外观 (`COSTUME_MOUNT_SKIN`) + mobs 32012 / 32028 | done, not deployed | | P6 costume enchants | 54001–54078 时装 / å�‘型强化石, 54124–54174 å��骑外观强化石 (`USE_CHANGE_ATTRIBUTE`); weapon / sash-skin / effect ranges and 53996 stay locked | done, not deployed | +| P7 talismans | 护符 chains 9600–10950 (`ARMOR_PENDANT`, +0..+200 per element), 71301 / 71302 / 53996 / 53997 talisman attribute items | done, not deployed | ## P1: boxes and keys @@ -83,7 +84,7 @@ AVA2's `ENABLE_SPECIAL_COSTUME_ATTR`, in `game/src/port_costume_attr.cpp`. The i - 54001–54027 时装 (mask 2, body); - 54028–54078 å�‘åž‹ (4, hair); - 54124–54174 å��骑外观 (16, mount skin). -- Still locked, since the target systems don't exist here: 54079– weapon costume (8), 54175– sash skin (32), 54220– effect (64). 53996 (talisman) waits for P7. +- Still locked, since the target systems don't exist here: 54079– weapon costume (8), 54175– sash skin (32), 54220– effect (64). 53996 became a talisman item in P7. - `CItem::IsCostumeEnchant` (vnum 54001–54267 with a nonzero value2) is checked first in the change/add-attribute case of `UseItemEx`, before the 40250 costume refusal. So an enchant never reaches the reroll code, and dragged onto gear it is refused (`MTCATTR target`). - `CostumeEnchantUse` follows AVA2's checks: - target kind and mask (`target`); @@ -99,3 +100,24 @@ AVA2's `ENABLE_SPECIAL_COSTUME_ATTR`, in `game/src/port_costume_attr.cpp`. The i - renders `MTCATTR`. Test: `tests/features/test_costume_attr.py`. + +## P7: talismans + +AVA2's `ITEM_TALISMAN_EQUIPMENT` + `ELEMENT_NEW_BONUSES`, in `game/src/port_pendant.cpp`. + +- Item: `ITEM_ARMOR` / `ARMOR_PENDANT = 7` (ProtoReader `arSub2`, so **the db binary changes again**), worn in `WEAR_PENDANT = 27`. The AVA2 wear flag `WEAR_PENDANT` does not exist here: `FindEquipCell` sends every talisman to the slot before the wear-flag check. +- Six chains of 201 items (+0..+200), fire 9600, ice 9830, earth 10060, dark 10290, wind 10520, elect 10750. Each carries `APPLY_ENCHANT_` = its step; the level limit rises from 20 to 60 along the chain. + - Refine sets 440–499 (fragment 96001–96006 + 30031 + 33031 ×10, 50000 yang, 100 %) are SQL rows: metin2-client `tools/server/pendant` (`install.sh`, then restart the db). +- Applies `APPLY_ENCHANT_ELEC..DARK = 123..128` (AVA2 numbers; the db names are AVA2's, `APPLY_ENCHANT_ELECT` first) → `POINT_ENCHANT_* = 242..247`. +- Damage (battle.cpp `CalcAttBonus`): against a monster with `RACE_FLAG_ATT_`, attack +point %, so a +200 talisman triples the attack on those monsters (×(1+200/100)), which is AVA2's own balance. Each flag is its own `if`, as on AVA2. AVA2 leaves out ICE; we include it, since 203 has 83 ice monsters and an ice talisman chain. +- Attributes: + - The pool is AVA2's item_attr pendant column (20 rows, levels 1–5), kept in a table in `port_pendant.cpp` instead of a new item_attr column (that would change the db boot packet). + - `GetAttributeSetIndex` stays −1. So talismans drop without attributes, and the 40250 switchers, the switchbot and the attribute lock refuse them. + - 71302 rerolls all attributes (needs at least one; levels 0/10/40/35/15 %). 71301 adds one up to 5, always succeeding (levels 40/50/10 %). No duplicates. + - **Deviation:** AVA2's 53996 / 53997 are generic switcher / adder items, a free 40250 gear reroll. Here they work like 71302 / 71301, as their zh names (护符附魔é�“å…· / 护符加æŒ�é�“å…·) say. + - Not while worn (`equipped`), like the 40250 switcher. Any other attribute item dropped on a talisman, or a talisman item dropped on anything else, gets `target`. + - Messages: `MTPENDANT target|equipped|empty|changed|full|added` (client `mt_pendant`). `ItemLog PENDANT_CHANGE` / `PENDANT_ADD`. +- Not ported: AVA2's element target packet (`ELEMENT_TARGET`, the element icon over the target HP bar). +- Client: `ItemData.h` / `PythonItemModule` constants, `c_Equipment_Pendant`, apply texts, and `mt_pendant` (`PendantScript.inc`: the equipment slot under the earring, item drop targets, messages). + +Test: `tests/features/test_pendant.py`; `test_applies.py` covers the 123–128 numbering. diff --git a/src/server/common/item_length.h b/src/server/common/item_length.h index a7ddf9c0..523cac95 100755 --- a/src/server/common/item_length.h +++ b/src/server/common/item_length.h @@ -106,6 +106,7 @@ enum EArmorSubTypes ARMOR_FOOTS, ARMOR_NECK, ARMOR_EAR, + ARMOR_PENDANT, // 7 AVA2 talisman (ITEM_TALISMAN_EQUIPMENT), worn in WEAR_PENDANT ARMOR_NUM_TYPES }; diff --git a/src/server/common/length.h b/src/server/common/length.h index 136dc6df..bbd203cf 100755 --- a/src/server/common/length.h +++ b/src/server/common/length.h @@ -140,6 +140,7 @@ enum EWearPositions WEAR_COSTUME_SASH, // 24 : AVA2 sash WEAR_COSTUME_MOUNT, // 25 : AVA2 mount costume WEAR_COSTUME_MOUNT_SKIN, // 26 : AVA2 mount skin + WEAR_PENDANT, // 27 : AVA2 talisman (ARMOR_PENDANT) WEAR_MAX = 32 // }; @@ -443,6 +444,13 @@ enum EApplyTypes // PORT AVA2 bonus numbering (AVA2 common/length.h): 92-138 are AVA2 applies not ported yet, // kept free so later ports and the client item_proto keep AVA2's numbers. + // AVA2 ELEMENT_NEW_BONUSES: attack bonus % against monsters of the element (RACE_FLAG_ATT_*), on the talismans. + APPLY_ENCHANT_ELEC = 123, + APPLY_ENCHANT_FIRE = 124, + APPLY_ENCHANT_ICE = 125, + APPLY_ENCHANT_WIND = 126, + APPLY_ENCHANT_EARTH = 127, + APPLY_ENCHANT_DARK = 128, APPLY_ATTBONUS_STONE = 139, APPLY_ATTBONUS_BOSS = 140, diff --git a/src/server/db/src/ProtoReader.cpp b/src/server/db/src/ProtoReader.cpp index da592bd5..bcd49787 100755 --- a/src/server/db/src/ProtoReader.cpp +++ b/src/server/db/src/ProtoReader.cpp @@ -103,7 +103,7 @@ int get_Item_SubType_Value(int type_value, string inputString) static string arSub1[] = { "WEAPON_SWORD", "WEAPON_DAGGER", "WEAPON_BOW", "WEAPON_TWO_HANDED", "WEAPON_BELL", "WEAPON_FAN", "WEAPON_ARROW", "WEAPON_MOUNT_SPEAR"}; static string arSub2[] = { "ARMOR_BODY", "ARMOR_HEAD", "ARMOR_SHIELD", "ARMOR_WRIST", "ARMOR_FOOTS", - "ARMOR_NECK", "ARMOR_EAR", "ARMOR_NUM_TYPES"}; + "ARMOR_NECK", "ARMOR_EAR", "ARMOR_PENDANT", "ARMOR_NUM_TYPES"}; static string arSub3[] = { "USE_POTION", "USE_TALISMAN", "USE_TUNING", "USE_MOVE", "USE_TREASURE_BOX", "USE_MONEYBAG", "USE_BAIT", "USE_ABILITY_UP", "USE_AFFECT", "USE_CREATE_STONE", "USE_SPECIAL", "USE_POTION_NODELAY", "USE_CLEAR", "USE_INVISIBILITY", "USE_DETACHMENT", "USE_BUCKET", "USE_POTION_CONTINUE", "USE_CLEAN_SOCKET", @@ -397,8 +397,8 @@ int get_Item_ApplyType_Value(string inputString) "APPLY_RESERVED_92", "APPLY_RESERVED_93", "APPLY_RESERVED_94", "APPLY_RESERVED_95", "APPLY_RESERVED_96", "APPLY_RESERVED_97", "APPLY_RESERVED_98", "APPLY_RESERVED_99", "APPLY_RESERVED_100", "APPLY_RESERVED_101", "APPLY_RESERVED_102", "APPLY_RESERVED_103", "APPLY_RESERVED_104", "APPLY_RESERVED_105", "APPLY_RESERVED_106", "APPLY_RESERVED_107", "APPLY_RESERVED_108", "APPLY_RESERVED_109", "APPLY_RESERVED_110", "APPLY_RESERVED_111", "APPLY_RESERVED_112", "APPLY_RESERVED_113", "APPLY_RESERVED_114", "APPLY_RESERVED_115", - "APPLY_RESERVED_116", "APPLY_RESERVED_117", "APPLY_RESERVED_118", "APPLY_RESERVED_119", "APPLY_RESERVED_120", "APPLY_RESERVED_121", "APPLY_RESERVED_122", "APPLY_RESERVED_123", - "APPLY_RESERVED_124", "APPLY_RESERVED_125", "APPLY_RESERVED_126", "APPLY_RESERVED_127", "APPLY_RESERVED_128", "APPLY_RESERVED_129", "APPLY_RESERVED_130", "APPLY_RESERVED_131", + "APPLY_RESERVED_116", "APPLY_RESERVED_117", "APPLY_RESERVED_118", "APPLY_RESERVED_119", "APPLY_RESERVED_120", "APPLY_RESERVED_121", "APPLY_RESERVED_122", "APPLY_ENCHANT_ELECT", + "APPLY_ENCHANT_FIRE", "APPLY_ENCHANT_ICE", "APPLY_ENCHANT_WIND", "APPLY_ENCHANT_EARTH", "APPLY_ENCHANT_DARK", "APPLY_RESERVED_129", "APPLY_RESERVED_130", "APPLY_RESERVED_131", "APPLY_RESERVED_132", "APPLY_RESERVED_133", "APPLY_RESERVED_134", "APPLY_RESERVED_135", "APPLY_RESERVED_136", "APPLY_RESERVED_137", "APPLY_RESERVED_138", "APPLY_ATTBONUS_STONE", "APPLY_ATTBONUS_BOSS", }; diff --git a/src/server/game/src/Makefile b/src/server/game/src/Makefile index 18c75381..9fbf6323 100755 --- a/src/server/game/src/Makefile +++ b/src/server/game/src/Makefile @@ -61,7 +61,7 @@ CPPFILE = BattleArena.cpp FSM.cpp MarkConvert.cpp MarkImage.cpp MarkManager.cpp desc_client.cpp desc_manager.cpp desc_p2p.cpp dev_log.cpp dungeon.cpp empire_text_convert.cpp entity.cpp\ entity_view.cpp event.cpp event_queue.cpp exchange.cpp file_loader.cpp fishing.cpp gm.cpp guild.cpp\ guild_manager.cpp guild_war.cpp horse_rider.cpp horsename_manager.cpp input.cpp input_auth.cpp input_db.cpp\ - input_login.cpp input_main.cpp input_p2p.cpp port_boss_track.cpp port_attr_lock.cpp port_sash.cpp port_mount.cpp port_costume_attr.cpp input_teen.cpp input_udp.cpp ip_ban.cpp\ + input_login.cpp input_main.cpp input_p2p.cpp port_boss_track.cpp port_attr_lock.cpp port_sash.cpp port_mount.cpp port_costume_attr.cpp port_pendant.cpp input_teen.cpp input_udp.cpp ip_ban.cpp\ item.cpp item_addon.cpp item_attribute.cpp item_manager.cpp item_manager_idrange.cpp locale.cpp\ locale_service.cpp log.cpp login_data.cpp lzo_manager.cpp marriage.cpp matrix_card.cpp\ messenger_manager.cpp mining.cpp mob_manager.cpp monarch.cpp motion.cpp over9refine.cpp p2p.cpp packet_info.cpp\ diff --git a/src/server/game/src/battle.cpp b/src/server/game/src/battle.cpp index a4ef7e3b..e3f36941 100755 --- a/src/server/game/src/battle.cpp +++ b/src/server/game/src/battle.cpp @@ -287,6 +287,20 @@ int CalcAttBonus(LPCHARACTER pkAttacker, LPCHARACTER pkVictim, int iAtk) else if (pkVictim->IsRaceFlag(RACE_FLAG_TREE)) iAtk += (iAtk * pkAttacker->GetPoint(POINT_ATTBONUS_TREE)) / 100; + // PORT AVA2 ELEMENT_NEW_BONUSES (talisman enchant), each flag on its own like AVA2; AVA2 forgot ICE. + if (pkVictim->IsRaceFlag(RACE_FLAG_ATT_ELEC)) + iAtk += (iAtk * pkAttacker->GetPoint(POINT_ENCHANT_ELEC)) / 100; + if (pkVictim->IsRaceFlag(RACE_FLAG_ATT_FIRE)) + iAtk += (iAtk * pkAttacker->GetPoint(POINT_ENCHANT_FIRE)) / 100; + if (pkVictim->IsRaceFlag(RACE_FLAG_ATT_ICE)) + iAtk += (iAtk * pkAttacker->GetPoint(POINT_ENCHANT_ICE)) / 100; + if (pkVictim->IsRaceFlag(RACE_FLAG_ATT_WIND)) + iAtk += (iAtk * pkAttacker->GetPoint(POINT_ENCHANT_WIND)) / 100; + if (pkVictim->IsRaceFlag(RACE_FLAG_ATT_EARTH)) + iAtk += (iAtk * pkAttacker->GetPoint(POINT_ENCHANT_EARTH)) / 100; + if (pkVictim->IsRaceFlag(RACE_FLAG_ATT_DARK)) + iAtk += (iAtk * pkAttacker->GetPoint(POINT_ENCHANT_DARK)) / 100; + if (pkVictim->GetMobRank() >= MOB_RANK_BOSS && !pkVictim->IsStone()) iAtk += (iAtk * pkAttacker->GetPoint(POINT_ATTBONUS_BOSS)) / 100; int monsterBonus = pkAttacker->GetPoint(POINT_ATTBONUS_MONSTER); diff --git a/src/server/game/src/char.cpp b/src/server/game/src/char.cpp index 50e28ddf..27f28a24 100755 --- a/src/server/game/src/char.cpp +++ b/src/server/game/src/char.cpp @@ -3449,6 +3449,12 @@ void CHARACTER::PointChange(BYTE type, int amount, bool bAmount, bool bBroadcast // PORT AVA2 biology points case POINT_ATTBONUS_STONE: case POINT_ATTBONUS_BOSS: + case POINT_ENCHANT_ELEC: + case POINT_ENCHANT_FIRE: + case POINT_ENCHANT_ICE: + case POINT_ENCHANT_WIND: + case POINT_ENCHANT_EARTH: + case POINT_ENCHANT_DARK: case POINT_RESIST_HUMAN: case POINT_ATTBONUS_MONSTER: case POINT_ATTBONUS_SURA: @@ -3836,6 +3842,12 @@ void CHARACTER::ApplyPoint(BYTE bApplyType, int iVal) case APPLY_MAGIC_ATTBONUS_PER: // 85 ¸¶¹ý °ø°Ý·Â +x% case APPLY_ATTBONUS_STONE: case APPLY_ATTBONUS_BOSS: + case APPLY_ENCHANT_ELEC: + case APPLY_ENCHANT_FIRE: + case APPLY_ENCHANT_ICE: + case APPLY_ENCHANT_WIND: + case APPLY_ENCHANT_EARTH: + case APPLY_ENCHANT_DARK: case APPLY_MELEE_MAGIC_ATTBONUS_PER: // 86 ¸¶¹ý + ¹Ð¸® °ø°Ý·Â +x% PointChange(aApplyInfo[bApplyType].bPointType, iVal); break; diff --git a/src/server/game/src/char.h b/src/server/game/src/char.h index 10a8db3f..b2c2e093 100755 --- a/src/server/game/src/char.h +++ b/src/server/game/src/char.h @@ -279,6 +279,13 @@ enum EPointTypes // PORT AVA2 biology points, within the existing 255-point packet. POINT_ATTBONUS_STONE = 240, POINT_ATTBONUS_BOSS = 241, + // PORT AVA2 element enchant (talismans, APPLY_ENCHANT_*). + POINT_ENCHANT_ELEC = 242, + POINT_ENCHANT_FIRE = 243, + POINT_ENCHANT_ICE = 244, + POINT_ENCHANT_WIND = 245, + POINT_ENCHANT_EARTH = 246, + POINT_ENCHANT_DARK = 247, POINT_RESIST_HUMAN = 220, // Ãß°¡ ¼Ó¼º ÀúÇ× @@ -2100,6 +2107,7 @@ class CHARACTER : public CEntity, public CFSM, public CHorseRider void MountCostumeUnequipped(LPITEM item, bool bAlwaysSummon); void MountCostumeOnLogin(); bool CostumeEnchantUse(LPITEM item, LPITEM item2); + bool PendantScrollUse(LPITEM item, LPITEM item2); }; ESex GET_SEX(LPCHARACTER ch); diff --git a/src/server/game/src/char_item.cpp b/src/server/game/src/char_item.cpp index c4484b80..f768503f 100755 --- a/src/server/game/src/char_item.cpp +++ b/src/server/game/src/char_item.cpp @@ -4498,6 +4498,9 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell) if (item->IsCostumeEnchant()) return CostumeEnchantUse(item, item2); + if (item->GetPendantScrollKind() || item2->IsTalisman()) + return PendantScrollUse(item, item2); + if (item2->IsEquipped()) { BuffOnAttr_RemoveBuffsFromItem(item2); diff --git a/src/server/game/src/constants.cpp b/src/server/game/src/constants.cpp index 3c103878..122dbacf 100755 --- a/src/server/game/src/constants.cpp +++ b/src/server/game/src/constants.cpp @@ -946,12 +946,12 @@ const TApplyInfo aApplyInfo[MAX_APPLY_NUM] = { POINT_NONE }, // 120 { POINT_NONE }, // 121 { POINT_NONE }, // 122 - { POINT_NONE }, // 123 - { POINT_NONE }, // 124 - { POINT_NONE }, // 125 - { POINT_NONE }, // 126 - { POINT_NONE }, // 127 - { POINT_NONE }, // 128 + { POINT_ENCHANT_ELEC }, // APPLY_ENCHANT_ELEC 123 + { POINT_ENCHANT_FIRE }, // APPLY_ENCHANT_FIRE 124 + { POINT_ENCHANT_ICE }, // APPLY_ENCHANT_ICE 125 + { POINT_ENCHANT_WIND }, // APPLY_ENCHANT_WIND 126 + { POINT_ENCHANT_EARTH }, // APPLY_ENCHANT_EARTH 127 + { POINT_ENCHANT_DARK }, // APPLY_ENCHANT_DARK 128 { POINT_NONE }, // 129 { POINT_NONE }, // 130 { POINT_NONE }, // 131 @@ -1333,6 +1333,12 @@ TValueName c_aApplyTypeNames[] = { "ATTBONUS_STONE", APPLY_ATTBONUS_STONE }, { "ATTBONUS_BOSS", APPLY_ATTBONUS_BOSS }, + { "ENCHANT_ELEC", APPLY_ENCHANT_ELEC }, + { "ENCHANT_FIRE", APPLY_ENCHANT_FIRE }, + { "ENCHANT_ICE", APPLY_ENCHANT_ICE }, + { "ENCHANT_WIND", APPLY_ENCHANT_WIND }, + { "ENCHANT_EARTH", APPLY_ENCHANT_EARTH }, + { "ENCHANT_DARK", APPLY_ENCHANT_DARK }, { NULL, 0 } }; // from import_item_proto.c diff --git a/src/server/game/src/item.cpp b/src/server/game/src/item.cpp index e5d3bd99..75adb0e7 100755 --- a/src/server/game/src/item.cpp +++ b/src/server/game/src/item.cpp @@ -487,6 +487,9 @@ bool CItem::CanUsedBy(LPCHARACTER ch) int CItem::FindEquipCell(LPCHARACTER ch, int iCandidateCell) { + if (IsTalisman()) + return WEAR_PENDANT; + // ÄÚ½ºÃõ ¾ÆÀÌÅÛ(ITEM_COSTUME)Àº WearFlag ¾ø¾îµµ µÊ. (sub typeÀ¸·Î Âø¿ëÀ§Ä¡ ±¸ºÐ. ±ÍÂú°Ô ¶Ç wear flag ÁÙ Çʿ䰡 ÀÖ³ª..) // ¿ëÈ¥¼®(ITEM_DS, ITEM_SPECIAL_DS)µµ SUB_TYPEÀ¸·Î ±¸ºÐ. ½Å±Ô ¹ÝÁö, º§Æ®´Â ITEM_TYPEÀ¸·Î ±¸ºÐ -_- if ((0 == GetWearFlag() || ITEM_TOTEM == GetType()) && ITEM_COSTUME != GetType() && ITEM_DS != GetType() && ITEM_SPECIAL_DS != GetType() && ITEM_RING != GetType() && ITEM_BELT != GetType()) diff --git a/src/server/game/src/item.h b/src/server/game/src/item.h index 4c46a26b..408097c1 100755 --- a/src/server/game/src/item.h +++ b/src/server/game/src/item.h @@ -237,6 +237,8 @@ class CItem : public CEntity bool IsCostumeMount(); // AVA2 mount costume bool IsCostumeMountSkin(); bool IsCostumeEnchant(); // AVA2 costume enchant (port_costume_attr.cpp) + bool IsTalisman(); // AVA2 talisman (port_pendant.cpp) + int GetPendantScrollKind(); bool IsRamadanRing(); void ClearMountAttributeAndAffect(); diff --git a/src/server/game/src/port_pendant.cpp b/src/server/game/src/port_pendant.cpp new file mode 100644 index 00000000..f199a772 --- /dev/null +++ b/src/server/game/src/port_pendant.cpp @@ -0,0 +1,190 @@ +// AVA2 talisman (ITEM_TALISMAN_EQUIPMENT + ELEMENT_NEW_BONUSES): ITEM_ARMOR / ARMOR_PENDANT, worn in WEAR_PENDANT. +// A talisman's APPLY_ENCHANT_ (= its refine level, +0..+200) adds that % to attacks on monsters with the +// matching RACE_FLAG_ATT_* (battle.cpp). +// Its random attributes come from AVA2's item_attr "pendant" column. That column is not added to 203's item_attr +// table and ATTRIBUTE_SET_*, which would change the db -> game boot packet. Instead the pool lives here and +// GetAttributeSetIndex() stays -1, so the 40250 switchers, the switchbot and the attribute lock never touch a +// talisman, and drops carry no magic attributes. +// Only the talisman items change its attributes; AVA2 uses 71302 (reroll) and 71301 (add, up to 5). The +// imported 53996 / 53997 (AVA2 generic switcher / adder, which would be free 40250 gear rerolls) act as the same +// talisman reroll / add here, as their zh names say. Messages go to the client as "MTPENDANT " +// (rendered by the client's mt_pendant script) instead of AVA2's locale strings 1056 / 1057 / 1067. +#include "stdafx.h" +#include "constants.h" +#include "char.h" +#include "item.h" +#include "log.h" + +namespace +{ + struct PendantAttr + { + BYTE bApply; + DWORD dwProb; + short asValues[ITEM_ATTRIBUTE_MAX_LEVEL]; + }; + + // AVA2 player.item_attr rows whose pendant column is set (all with max level 5). + const PendantAttr s_aPendantAttr[] = + { + { APPLY_MAX_HP, 35, { 1500, 1500, 1500, 2000, 2000 } }, + { APPLY_MAX_SP, 35, { 50, 50, 50, 80, 80 } }, + { APPLY_CON, 11, { 8, 8, 8, 12, 12 } }, + { APPLY_INT, 11, { 8, 8, 8, 12, 12 } }, + { APPLY_STR, 11, { 8, 8, 8, 12, 12 } }, + { APPLY_DEX, 11, { 8, 8, 8, 12, 12 } }, + { APPLY_HP_REGEN, 60, { 20, 20, 20, 30, 30 } }, + { APPLY_SP_REGEN, 60, { 20, 20, 20, 30, 30 } }, + { APPLY_STEAL_HP, 50, { 5, 5, 5, 10, 10 } }, + { APPLY_STEAL_SP, 50, { 5, 5, 5, 10, 10 } }, + { APPLY_MANA_BURN_PCT, 18, { 5, 5, 5, 10, 10 } }, + { APPLY_DODGE, 15, { 8, 8, 8, 10, 10 } }, + { APPLY_POISON_REDUCE, 15, { 5, 5, 5, 8, 8 } }, + { APPLY_KILL_SP_RECOVER, 10, { 5, 5, 5, 10, 10 } }, + { APPLY_EXP_DOUBLE_BONUS, 10, { 10, 10, 10, 20, 20 } }, + { APPLY_GOLD_DOUBLE_BONUS, 10, { 10, 10, 10, 20, 20 } }, + { APPLY_ITEM_DROP_BONUS, 10, { 10, 10, 10, 20, 20 } }, + { APPLY_KILL_HP_RECOVER, 10, { 5, 5, 5, 10, 10 } }, + { APPLY_ANTI_CRITICAL_PCT, 10, { 4, 4, 4, 10, 10 } }, + { APPLY_ANTI_PENETRATE_PCT, 10, { 4, 4, 4, 10, 10 } }, + }; + + enum + { + PENDANT_MAX_ATTR = 5, // AVA2: 71301 adds while GetAttributeCount() < 5 + }; + + // 203 CItem::ChangeAttribute / AddAttribute level tables (AVA2 has the same). + const int s_aiChangeLevel[ITEM_ATTRIBUTE_MAX_LEVEL] = { 0, 10, 40, 35, 15 }; + const int s_aiAddLevel[ITEM_ATTRIBUTE_MAX_LEVEL] = { 40, 50, 10, 0, 0 }; + + int PendantLevel(const int * aiPercent) + { + int iPercent = number(1, 100); + int i; + + for (i = 0; i < ITEM_ATTRIBUTE_MAX_LEVEL - 1; ++i) + { + if (iPercent <= aiPercent[i]) + break; + + iPercent -= aiPercent[i]; + } + + return i; + } + + // CItem::PutAttributeWithLevel over the talisman pool. + void PendantPutAttribute(LPITEM item, const int * aiPercent) + { + DWORD dwTotal = 0; + + for (size_t i = 0; i < sizeof(s_aPendantAttr) / sizeof(s_aPendantAttr[0]); ++i) + if (!item->HasAttr(s_aPendantAttr[i].bApply)) + dwTotal += s_aPendantAttr[i].dwProb; + + if (!dwTotal) + return; + + DWORD dwProb = number(1, dwTotal); + + for (size_t i = 0; i < sizeof(s_aPendantAttr) / sizeof(s_aPendantAttr[0]); ++i) + { + const PendantAttr & r = s_aPendantAttr[i]; + + if (item->HasAttr(r.bApply)) + continue; + + if (dwProb <= r.dwProb) + { + item->AddAttribute(r.bApply, r.asValues[PendantLevel(aiPercent)]); + return; + } + + dwProb -= r.dwProb; + } + } +} + +bool CItem::IsTalisman() +{ + return GetType() == ITEM_ARMOR && GetSubType() == ARMOR_PENDANT; +} + +// 1 = reroll, 2 = add, 0 = not a talisman attribute item. +int CItem::GetPendantScrollKind() +{ + if (GetType() != ITEM_USE) + return 0; + + switch (GetVnum()) + { + case 71302: + case 53996: + return GetSubType() == USE_CHANGE_ATTRIBUTE ? 1 : 0; + + case 71301: + case 53997: + return GetSubType() == USE_ADD_ATTRIBUTE ? 2 : 0; + } + + return 0; +} + +bool CHARACTER::PendantScrollUse(LPITEM item, LPITEM item2) +{ + if (item2->IsExchanging()) + return false; + + const int kind = item->GetPendantScrollKind(); + + if (!kind || !item2->IsTalisman()) + { + ChatPacket(CHAT_TYPE_COMMAND, "MTPENDANT target"); + return false; + } + + // 40250 never changes the attributes of a worn item (the "Fix" in the switcher path). + if (item2->IsEquipped()) + { + ChatPacket(CHAT_TYPE_COMMAND, "MTPENDANT equipped"); + return false; + } + + char buf[21]; + snprintf(buf, sizeof(buf), "%u", item2->GetID()); + + if (kind == 1) + { + const int iCount = item2->GetAttributeCount(); + + if (!iCount) + { + ChatPacket(CHAT_TYPE_COMMAND, "MTPENDANT empty"); + return false; + } + + item2->ClearAttribute(); + + for (int i = 0; i < iCount; ++i) + PendantPutAttribute(item2, s_aiChangeLevel); + + LogManager::instance().ItemLog(this, item, "PENDANT_CHANGE", buf); + ChatPacket(CHAT_TYPE_COMMAND, "MTPENDANT changed"); + } + else + { + if (item2->GetAttributeCount() >= PENDANT_MAX_ATTR) + { + ChatPacket(CHAT_TYPE_COMMAND, "MTPENDANT full"); + return false; + } + + PendantPutAttribute(item2, s_aiAddLevel); + LogManager::instance().ItemLog(this, item, "PENDANT_ADD", buf); + ChatPacket(CHAT_TYPE_COMMAND, "MTPENDANT added"); + } + + item->SetCount(item->GetCount() - 1); + return true; +} diff --git a/src/server/game/src/port_switchbot.h b/src/server/game/src/port_switchbot.h index 972c0369..4a00e417 100644 --- a/src/server/game/src/port_switchbot.h +++ b/src/server/game/src/port_switchbot.h @@ -83,7 +83,7 @@ static LPITEM PortSwitchItem(LPCHARACTER ch,const PortSwitchbot& bot) { } static bool PortSwitchScroll(LPITEM scroll) { - return scroll && scroll->GetType()==ITEM_USE && scroll->GetSubType()==USE_CHANGE_ATTRIBUTE && !scroll->IsCostumeEnchant(); + return scroll && scroll->GetType()==ITEM_USE && scroll->GetSubType()==USE_CHANGE_ATTRIBUTE && !scroll->IsCostumeEnchant() && !scroll->GetPendantScrollKind(); } static void PortSwitchState(LPCHARACTER ch,const PortSwitchbot* bot,bool active,const char* reason) { diff --git a/tests/features/test_applies.py b/tests/features/test_applies.py index 1968ffcf..83581e5d 100644 --- a/tests/features/test_applies.py +++ b/tests/features/test_applies.py @@ -21,14 +21,21 @@ constants=source('game/src/constants.cpp') table=constants[constants.index('aApplyInfo[MAX_APPLY_NUM]'):] table=table[table.index('{')+1:table.index('};')] rows=re.findall(r'\{\s*(POINT_[A-Z_]+)',table) -assert len(rows)==141 and rows[139:]==['POINT_ATTBONUS_STONE','POINT_ATTBONUS_BOSS'] and set(rows[92:139])=={'POINT_NONE'},len(rows) +assert len(rows)==141 and rows[139:]==['POINT_ATTBONUS_STONE','POINT_ATTBONUS_BOSS'] and set(rows[92:123]+rows[129:139])=={'POINT_NONE'},len(rows) +ELEM=('ELEC','FIRE','ICE','WIND','EARTH','DARK') +# P7 talisman: APPLY_ENCHANT_* 123-128 (AVA2 names, ELECT for the db) -> POINT_ENCHANT_* 242-247 +assert rows[123:129]==['POINT_ENCHANT_'+e for e in ELEM],rows[123:129] +assert names[123:129]==['APPLY_ENCHANT_'+('ELECT' if e=='ELEC' else e) for e in ELEM],names[123:129] assert '"ATTBONUS_STONE",\tAPPLY_ATTBONUS_STONE' in constants and '"ATTBONUS_BOSS",\tAPPLY_ATTBONUS_BOSS' in constants char=source('game/src/char.cpp') apply=char[char.index('void CHARACTER::ApplyPoint('):char.index('void CHARACTER::MotionPacketEncode(')] +assert all('case APPLY_ENCHANT_%s:'%e in apply for e in ELEM) assert 'case APPLY_ATTBONUS_STONE:' in apply and 'case APPLY_ATTBONUS_BOSS:' in apply points=source('game/src/char.h') +assert all('POINT_ENCHANT_%s = %d,'%(e,242+i) in points for i,e in enumerate(ELEM)),'enchant points' assert 'POINT_ATTBONUS_STONE = 240,' in points and 'POINT_ATTBONUS_BOSS = 241,' in points battle=source('game/src/battle.cpp') +assert all('GetPoint(POINT_ENCHANT_%s)'%e in battle for e in ELEM) and 'RACE_FLAG_ATT_ICE' in battle assert 'GetPoint(POINT_ATTBONUS_STONE)' in battle and 'GetPoint(POINT_ATTBONUS_BOSS)' in battle print('PASS: stone/boss applies 139/140 in the db reader, aApplyInfo, apply names and ApplyPoint') diff --git a/tests/features/test_pendant.py b/tests/features/test_pendant.py new file mode 100755 index 00000000..7b2ee2e9 --- /dev/null +++ b/tests/features/test_pendant.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +"""AVA2 talisman (docs/FEATURE-AVA2-UNLOCK.md P7): ARMOR_PENDANT worn in WEAR_PENDANT, element enchant applies, +its own attribute pool changed only by 71301/71302/53996/53997, which are no switchbot scrolls.""" +from pathlib import Path +ROOT=Path(__file__).resolve().parents[2] +SRC=ROOT/'src/server' +def source(name):return (SRC/name).read_bytes().decode('latin1') + +il=source('common/item_length.h');assert il.index('ARMOR_EAR,')GetPendantScrollKind() || item2->IsTalisman())\n\t\t\t\t\t\t\t\treturn PendantScrollUse(item, item2);')GetPendantScrollKind()' in source('game/src/port_switchbot.h') +assert 'port_pendant.cpp' in source('game/src/Makefile') +port=source('game/src/port_pendant.cpp') +pool=port[port.index('s_aPendantAttr[] ='):];pool=pool[:pool.index('};')] +assert pool.count('{ APPLY_')==20 and 'APPLY_ATTBONUS' not in pool and 'APPLY_ENCHANT' not in pool +for text in ('PENDANT_MAX_ATTR = 5','{ 0, 10, 40, 35, 15 }','{ 40, 50, 10, 0, 0 }','case 71302:\n\t\tcase 53996:','case 71301:\n\t\tcase 53997:', + 'if (item->HasAttr(r.bApply))','item->SetCount(item->GetCount() - 1);'): + assert text in port,text +codes=('target','equipped','empty','changed','full','added') +for code in codes:assert '"MTPENDANT %s"'%code in port,code +assert port.index('"MTPENDANT equipped"')ClearAttribute()') +assert port.index('"MTPENDANT full"')=54001 && vnum<=54267 && value2;} + long value2=0;bool IsCostumeEnchant(){return vnum>=54001 && vnum<=54267 && value2;}int GetPendantScrollKind(){return vnum==71302||vnum==53996;} DWORD GetID(){return id;}DWORD GetVnum(){return vnum;}BYTE GetType(){return type;}BYTE GetSubType(){return subtype;} int GetAttributeSetIndex(){return set;}const TItemTable* GetProto(){return &proto;} const TPlayerItemAttribute& GetAttribute(int i){return attrs[i];}BYTE GetAttributeType(int i){return attrs[i].bType;}