Files
metin2-server/tests/features/test_point_drop.py
T
shenandshen 65db9fc365 feat: add account point rewards and extended item storage
Implement configurable kill rewards with account-wide daily limits, transactional deduplication, and game-to-db retries. Add the approved wide rules and tested isolation tooling.

Stage wear40 equipment and persistent extra item metadata with an explicit migration plan and client revision gate. Track all 168 remaining offers; sixteen have staged data/assets, while live acceptance and other systems remain incomplete. This commit is not a production deployment.
2026-10-19 18:30:19 -07:00

50 lines
2.0 KiB
Python

"""Compile the shipping eligibility/cap arithmetic, including boundary and overflow cases."""
import json
from pathlib import Path
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[2]
class PointDrop(unittest.TestCase):
def test_approved_rules_and_cap(self):
flags = json.loads((ROOT/'tools/ava2-itemshop/points-wide.json').read_text())
entries = ','.join('{"%s",%d}' % entry for entry in flags.items())
source = r'''
#include "src/server/common/point_drop.h"
#include <map>
#include <cassert>
int main() {
std::map<std::string,int> flags={ENTRIES};
auto lookup=[&](const std::string& key){return flags[key];};
auto mob=PortPointRule(lookup,false),stone=PortPointRule(lookup,true);
assert(mob.chance==500 && mob.minimum==1 && mob.maximum==1);
assert(stone.chance==10000 && stone.minimum==3 && stone.maximum==8);
assert(mob.eligible(105,120));assert(!mob.eligible(104,120));
assert(stone.eligible(120,1));assert(!stone.eligible(0,1));
assert(!stone.eligible(120,0));
assert(PortPointDropAmount(8,498,500)==2);
assert(PortPointDropAmount(8,500,500)==0);
assert(PortPointDropAmount(8,UINT64_MAX,500)==0);
assert(PortPointDropAmount(8,UINT64_MAX,0)==8);
flags["points_mob_chance"]=0;assert(!PortPointRule(lookup,false).eligible(105,120));
flags["points_stone_chance"]=10001;assert(!PortPointRule(lookup,true).valid());
flags["points_stone_chance"]=10000;flags["points_stone_min"]=-1;
assert(!PortPointRule(lookup,true).valid());
flags["points_stone_min"]=9;flags["points_stone_max"]=3;
assert(!PortPointRule(lookup,true).valid());
}
'''.replace('ENTRIES', entries)
with tempfile.TemporaryDirectory() as tmp:
src = Path(tmp)/'test.cpp'
exe = Path(tmp)/'test'
src.write_text(source)
subprocess.run(['c++', '-std=c++17', '-I'+str(ROOT), str(src), '-o', str(exe)], check=True)
subprocess.run([str(exe)], check=True)
if __name__ == '__main__':
unittest.main()