Skip to main content

rpze: Remote Python, Zombie: Endless

Project description

rpze

Remote Python, Zombie Endless(or endless rp?)

一个远程Python的Plants vs. Zombies TAS及ize测试框架.

主库位于GitHub.

结构

总体分成五个包:

  • rp_extend: 对控制pvz游戏本地运作的基本操作的封装
  • basic: DLL注入, 游戏启动, 汇编代码等基础功能
  • structs: PvZ内数据结构以及部分method的的封装
  • flow: coroutine-like测试编写相关的函数, 和以此实现的IzTest测试功能
  • examples: 上述的测试功能的编写例子

其中, 若仅对Python的pvz框架感兴趣则只需关注前三个包, 对ize测试感兴趣则着重模仿examples并大致了解structs的成员(PlantsZombies).

例子

生物钟

一个生物钟一二路卡相位的例子.

from rpze.basic import InjectedGame
from rpze.flow import *

with InjectedGame(r"your\game\path") as game:
    game.enter_level(70)  # 打开编号为70的关卡, 即ize关卡
    iz_test = IzTest(game.controller).init_by_str('''
        1000 -1
        1-2
        zs_j5
        cptoh
        .....
        .....
        .....
        lz 
        0 
        2-6''')  # 大家熟悉的izt测试

    @iz_test.flow_factory.add_flow()
    async def place_zombie(_):
        plist = iz_test.game_board.plant_list
        flower = plist["2-5"]
        await until(lambda _: flower.hp <= 4)
        place("cg 2-6")  # 2-5花死前一瞬放撑杆
        star = plist["1-5"]  # 1-5杨桃
        await until_plant_last_shoot(star).after(151 - 96)
        await repeat("xg 1-6")  # 星星最后一发攻击发出后1双鬼

    iz_test.start_test(jump_frame=False, speed_rate=5)

从有@的那句话开始一句一句看下去:

  • @iz_test.flow_factory.add_flow(): 一句格式代码, 作用是让测试时执行你下面定义的place_zombie. 抄下来就行.
  • async def place_zombie(_): 同样是格式代码.
    此处, 可以认为async def定义一个非常类似于函数的place_zombie, 这个类似函数的东西接受一个FlowManager类型的参数(在大部分场合用不到, 这里用_表示我用不到)
    不能不写async! place_zombie一定要是有且仅有一个参数的函数!
  • plist = iz_test.game_board.plant_list:
    • game_board是游戏中当前运行的关卡界面的代名词, 关卡上的所有植物, 僵尸, 你的大多操作都通过透过它进行.
    • plant_list是游戏中存放植物对象的数组, 其中有当前对象数量, 最大数量等等信息.
      plant_list类型为PlantList, 继承于ObjList[Plant], 提供了使用[int | slice]索引, ~plist遍历等功能.
  • flower = plist["2-5"]: [f"{row}-{col}"]PlantList特有的方法, 获取在1-1的植物.
  • await until(lambda _: flower.hp <= 4): 意为等待2-5花的血量 $\leq$ 4时往下执行.
    简单的说, 只需要写await until(lambda _: 你希望满足xx条件时再往下执行)即可.
    具体格式为await until(FlowManager -> bool). 和上面的place_zombie一样, 这里忽略FlowManager参数.
  • place("cg 2-6"): 在2-6放撑杆, 非常简单. 这个函数会返回你刚放下来的僵尸, 有需要的话可以用
  • await until_plant_last_shoot(star).after(151 - 96): 在星星最后一次攻击结束后再过(151 - 96)帧往下执行
    • until_plant_last_shoot(plant): 卡相位函数. 相当于until(lambda _: plant攻击后第一次打不出子弹)
    • until(...).after(time) 指等到前面的条件后再过time帧再往下执行.
  • await repeat("xg 1-6") 1-6双小鬼.
    • repeat代表连放僵尸, 默认delay20放两个(大家都是这么做的!), 如想delay30放三个则是repeat("xg 1-6", 2, 30)
    • await必须有. 直观理解, 这里前面有await的理由是repeat函数要等放完了才能往后执行.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rpze-0.1.2.tar.gz (146.3 kB view details)

Uploaded Source

Built Distributions

rpze-0.1.2-cp312-cp312-win_amd64.whl (152.2 kB view details)

Uploaded CPython 3.12 Windows x86-64

rpze-0.1.2-cp311-cp311-win_amd64.whl (153.0 kB view details)

Uploaded CPython 3.11 Windows x86-64

File details

Details for the file rpze-0.1.2.tar.gz.

File metadata

  • Download URL: rpze-0.1.2.tar.gz
  • Upload date:
  • Size: 146.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for rpze-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e4d62aa5d68ceb36ae2bd4c9eb65e47ba32047a52d922a259c1d5328fcb01e8c
MD5 d19329315ec34d96b25fc74549716ab8
BLAKE2b-256 49b3feea9b55d2f84e57dbe76b1d2e97e48e3e483af16c8215cdf2ccb25c2960

See more details on using hashes here.

File details

Details for the file rpze-0.1.2-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: rpze-0.1.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 152.2 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for rpze-0.1.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 fa4eada402301b5b8a5f530a96ed5f82cb972e55c58915cf937fda56435ddd0d
MD5 8aea6072cb459bb1f058a982cdd71c16
BLAKE2b-256 40580f77e5a4faee67946a5567a3d1437adcf3333a1d8a674b868a939fa52cd8

See more details on using hashes here.

File details

Details for the file rpze-0.1.2-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: rpze-0.1.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 153.0 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for rpze-0.1.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1a2c10672b71a7f76f145e50a3810d482564d518b01dbce38a07acb42102e128
MD5 0f643e35e0cdba90a53de8c19c0b779d
BLAKE2b-256 c2d0af3fbdb5685fae23986cbc6463c2ae6b481946942722701a0c437d474312

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page