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.1.tar.gz (144.4 kB view details)

Uploaded Source

Built Distributions

rpze-0.1.1-cp312-cp312-win_amd64.whl (150.7 kB view details)

Uploaded CPython 3.12 Windows x86-64

rpze-0.1.1-cp311-cp311-win_amd64.whl (151.3 kB view details)

Uploaded CPython 3.11 Windows x86-64

File details

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

File metadata

  • Download URL: rpze-0.1.1.tar.gz
  • Upload date:
  • Size: 144.4 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.1.tar.gz
Algorithm Hash digest
SHA256 5c8280533b91a65175516abea4e935aeaded2026cec84f8d7a09340262724db9
MD5 764f845a4bff97840fdaf4aaf51c2d28
BLAKE2b-256 bb7d19917781bd8b9f9dad7158a384994c84bfffc6c09123d643edf03c06d0a1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rpze-0.1.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 150.7 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.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 953a091cd0c5e650e5d8336ffb36b90416f5a9d8d25781d40110afebb96ef22c
MD5 df27451d63507ea028ede1c1522a7831
BLAKE2b-256 6c185d53813c78afc9bd920f1f4156ff4ee400c391f138cbe0476424a49aa655

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rpze-0.1.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 151.3 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.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a7ef6b555244533c2e51a821cb83381a4a2cbc340616fa4426bdee84754c749b
MD5 603fa6af09e68b133b4f3c22c31a6672
BLAKE2b-256 d33765c30fd536b0b70f2a1a80fafd25d150f28c088be0d92d1daafbb444dac9

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