查看: 328| 回复: 2
收起左侧

【新人求米】 分享一下给farming游戏写脚本

Nostalgib_ | 显示全部楼层
本楼:   👍  0
0%
0%
0   👎
全局:   136
68%
32%
64

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x

玩一个养成类游戏,凡游戏涉及养成和pvp,其本质必然演变为compete to pay for time, 即pay2win。
游戏内容是打怪收集资源建造主城,训练兵力攻击别人。我一开始很致力于维护服务器和平不要打人,但是有个大佬冲了大概三四万刀,到处惹事,别人抱怨,他说:
This is a game for me to pay for fun.  Bullying you f2p (free to play) players is exactly the service that I paid a car for. You do not have the ability to earn a spare car to pay Evony (the game's name) so you deserve to be bullied..
我现在觉得他说得话简直是游戏的本质和真理,但是当时情绪上接受不了。我就自己学习了机器学习写脚本把地图上的怪打打完。
大佬抱怨没有怪打,我回答:
You do not have the brain to write a script so you deserve to have no monster to attack.
人家是大佬,有能力赚钱玩游戏的人,领悟能力也不会差。他很快就意识到script = d$/dt,其中$表示充钱,t为时间。
现在他是我队友了


写脚本主要用三个包:
pyautogui,模拟键鼠
opencv 图像识别
pytesseract 文字识别


pytesseract很简单,看一下说明就会。
主要用的函数有locate_pattern 和check_in_page.
在某个界面上,如果找到某个按钮,就将其截图保存为template,使用locate_pattern找到。 点击(pyautogui.click)这个按钮之后,将你预想的新界面截图并存放另一个template,然后用check_in_page来检测你的click有没有生效




#locate position of template in image. return y (list) and x(list) of all matched positions
def locate_pattern(image,template, threshold = 0.73, returnthresh = False, check = True):
    w,h = template.shape[::-1]
    res = cv2.matchTemplate(image,template,cv2.TM_CCOEFF_NORMED)
    if returnthresh:
        return np.max(res)
    loc = np.where(res > threshold)
    newy = loc[0] + h//2
    newx = loc[1] + w//2
    return newy, newx




    # after a click, check whether the click go through, and the new template that you want after the click has appeared.
    def check_in_page(self,template,ntries = 0,interval = 0.35,box = None,**kw):
        if box is None:
            box = self.box
        screenshot = pyautogui.screenshot(region = box)
        try:
            for temp1 in glob.iglob(template):
                temp = cv2.imread(temp1)
                temp = locate_pattern(screenshot,temp,**kw)
                if len(temp[0]) > 0:
                    return 1
            else:
                if ntries >= 1:
                    return 0
                time.sleep(interval)
                return self.check_in_page(template,ntries+1,interval,box)
        except:
            return 0



评分

参与人数 1大米 +1 收起 理由
Thestral + 1 赞一个

查看全部评分


上一篇:hpc 高性能计算
下一篇:给开源软件做贡献有什么好处
rumblewarrior 2024-10-13 22:37:56 | 显示全部楼层
本楼:   👍  0
0%
0%
0   👎
全局:   285
98%
2%
7
请问是什么游戏啊?
回复

使用道具 举报

zhuxin666 2024-10-22 13:02:05 | 显示全部楼层
本楼:   👍  0
0%
0%
0   👎
全局:   98
92%
8%
8
这是国内dnf工作室那一套吧?只是美国好像不兴工作室这些的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

Advertisement
>
快速回复 返回顶部 返回列表