29988122 / Fate-Grand-Order_Lua

Fate Grand Order auto battle script - no root needed, for Android use only
MIT License
291 stars 95 forks source link

Discussion with my collaborator #21

Open 29988122 opened 6 years ago

29988122 commented 6 years ago

Having a new discussion thread seemed like the fastest way for us to discuss non-commit and non-PR related issue. @ryuga93

I can't figure out the function calling here:

function menu()
    atkround = 1
    npClicked = 0
    turnCounter = {0, 0, 0, 0, 0}
    click(Location(1900,400))
    wait(1.5)
    if Refill_or_Not == 1 and stoneused < How_Many then
        refillstamina()
    end
    click(Location(1900,500))
    wait(1.5)
    click(Location(2400,1350))
    wait(8)
end

function refillstamina()
    if StaminaRegion:exists("stamina.png", 0) then
        if Use_Stone == 1 then
            click(StoneClick)
            click(Location(1650,1120))
            stoneused = stoneused + 1
        else
            click(AppleClick)
            click(Location(1650,1120))
            stoneused = stoneused + 1
        end
    wait(1.5)
    menu()
    end
end

The 3rd line from last memu() called inside refillstamina() was the one you recently added. Wouldn't it caused a lot of wait(1.5)?

1.Every time when refillstamina() was called but game's not currently at AP refill window. 2.Every time memu() was called).

Or I got the whole function calling inside function concept wrong?

ryuga93 commented 5 years ago

Give me a full anime series + bring FGO Arcade to PC and I'll be happy

29988122 commented 5 years ago

Looking forward to having a Chapter 5.6.7 anime series...But it couldn't be as bad as Fate Extra Last Encore.

By the way

我看到這段真的要笑尿了兄弟

梶田: 拜此所賜,對第一次看到的BOSS用手上所有的Servant找出攻略方法這點 ,也是FGO的一大魅力呢。 只是另一方面,當攻略方法被開發出來以後之後就是機械式的重複選卡 的周回動作了。試誤的快樂與周回的反差實在是很激烈呢..... 奈須: 謹聽高見... 梶田: 如果今後想要在這一點改善的話,FGO有一個巨大的弱點必須消除吧, 現在並沒有能夠SKIP戰鬥的功能,加速也只能調兩倍速。我對這一點 一直有著疑問,已經被攻略摸熟的關卡需要手動不斷打的理由究竟是否 存在呢? 

AND

梶田:
玩家也不只是想追求輕鬆而以。以現實問題來說,手機遊戲的周回就像
奈須桑說的「不斷糾纏的工作」那樣,繼續累積下去的話是很危險的,
還有動力的時候是沒關係,只要哪天緊繃的線斷裂的話就會失去對這個
遊戲的執著,自己不想看到FGO有那樣的結果,實在太浪費了。

奈須:
說的好...老是不掉的素材之類的,我自己也常常在例會中質問著「這
到底是怎樣?」....。不會減損Servant的魅力,同時也讓遊玩的感覺
變好.... 以那樣的改動為目標,跟Delightworks會一起努力的。

梶田:
我們作為玩家也是,想愛著那樣的FGO。作為手機遊戲,要跟玩得舒服
取得平衡是很難...但是追求著更好的解答這樣的態度一定能傳達的!

笑到不知道該說什麼,你們自己也知道周回無聊到讓人會崩潰啊 -..-

ryuga93 commented 5 years ago

To 奈須: 别管DW了,答案就在这里~

XD

Fate Extra Last Encore made my head spin even with the knowledge from the PSP game, and they say it's beginner friendly lol

potchy commented 5 years ago

image

I'm dead. http://ankulua.boards.net/thread/7/settings#autoGameArea http://ankulua.boards.net/thread/7/settings#getGameArea http://ankulua.boards.net/thread/7/settings#setGameArea

If we replace getRealScreenSize() for autoGameArea(true) and getGameArea() the script should work in devices with notches. Later we can also replace ApplyOffsetsToTable and ApplyOffsetsToLocationOrRegion for setGameArea(region). I'm totally dead.

29988122 commented 5 years ago

For those games, we can use setGameArea() to include only the game area and excluding the black area on left and right. We can then keep other parts of the script unchanged and make the script working on both devices.

THOSE GAMES

other parts of the script unchanged

sigh

ryuga93 commented 5 years ago

Well at least they "listened". Btw I think I saw the exact same screenshot of those game before, not sure where, could be my imagination XD

potchy commented 5 years ago

@29988122 seriously, I think we should get rid of the "releases" tab, because we always forget to update it and people are always using outdated versions x_x

29988122 commented 5 years ago

OK I'll just add a line in readme, tell them to zip the repo...(Clone or Download button)

29988122 commented 5 years ago

Done, easier than what I've expected.

Now release section's only for major version and changelog... XD

29988122 commented 5 years ago

OOOOOOOOOOK, they're blocking emus again. Bye my consecutive login bonus, I don't even bother login via my phone. (no event currently in JP server, yay)

Magisk hide working as always, tho.

ryuga93 commented 5 years ago

So are we still proceeding with the observer design thing? Just wanna know the current status.

@29988122 Dayum, I was thinking of interfacing to Project Pendragon Alter and test it on Nox :(

29988122 commented 5 years ago

@ryuga93 See if @TryBane has something to say / to do about the observer thing.

We've already done most of the refactoring I'd say. Here's our current progress: https://github.com/29988122/Fate-Grand-Order_Lua/projects/6#column-4037905

TryBane commented 5 years ago

A lot of the refactoring was already accomplished by potchy. The only thing left for me is to get the observer pattern taken care of but I can do that here soon. I have Saturday and Sunday off this week and my work is cutting my hours down. This is a bonus for me, cause it means I can work more on articles for Gamepress and also work on this project at the same time :D

Anyways, I'll work on getting that observer pattern setup this weekend if you guys don't mind the wait.

ryuga93 commented 5 years ago

@TryBane Thanks bro and no worries, we can wait 👍 .

29988122 commented 5 years ago

No worries +1

We're just a bunch of volunteers after all, do it as you please XD

ryuga93 commented 5 years ago

Do you guys know any servant database that has command card sprite, at every stage of accession? I could only managed to find this https://kazemai.github.io/fgo-vz/, but they are cropped from the card types, and only 3 images available train the Pendragon AI.

If I could get all the cards which include card types I would have 9 images to work with.

29988122 commented 5 years ago

@ryuga93 我剛好最近在做android逆向...雖然一點毛關係都木有

我是覺得你的best shot就是模擬器打開fgo,點選設定內的下載所有檔案,然後去

/data/data/com.aniplex.fategrandorder/files/

在那之下會有一個特別大的...好像是assets資料夾? 裡面就是幾乎所有的素材檔案了。

檔案拉出來之後,你再研究下格式,然後寫個解包吧。


當然我們不要重複發明輪子

或者可以試試你有空的時候,去問那些data mining解包大佬,加個群交流交流也是可以的 - 他們應該很樂意協助,都是碼猴,自己人自己人

ryuga93 commented 5 years ago

谢谢你的建议,但感觉太多东西要弄很麻烦所以已暂时放弃了Orz,在弄到素材档案之前得先弄个可以传输档案的http GET/POST。 pokeguys (#75) 提过Ankulua本身的httpGet()/ httpPost() 可以做到,但我还得研究一下。

除此之外,我想先让LUA更详细地认识战斗画面,写个半自动、不需要完整command的Autoskill再继续也不迟。因为现在的Pendragon Alter只懂最好的出卡顺序和brave chain,我们的LUA再改一下就可以知道brave chain了,根本不需要AI lolz。至少当LUA懂得战斗画面的大部分情况,就可以让AI发挥真正的自动战斗,在特殊情况下可以如人类般找出不一样的答案。

其实LUA也可以做到真正的自动战斗,只是可能没AI那样全面,写法也比较单调、花时间。我想到的方法是写个servant的object然后extend至每一个servant,花时间的是必须自己把所有的技能和宝具写进去。不过也许有更好的方法吧。

话说逆向蛮好玩 :3。记得以前玩神女控时不小心(?)把触摸精灵给破解了呵呵@@

29988122 commented 5 years ago

http get / post

Yeah...troublesome especially when I / we're not really familiar with http protocol.

autoskill without the hassle of manually assigning parameters

Absolutely. I read a little about the recent starcraft 2 AI, but the level's too high for me apparently. I "believe"(wish, to be honest) that there must be a better way other than manually inputting data of every servant - it's not scalable nor feasible.

破解觸摸精靈 XD 你壞壞 我想到之前無意間發現網上其實有人在逆向ankulua,不過我有知會ankulua作者那個blog write-up的存在,後來blog作者好像將其撤下了。

雖說內容看起來其實也不難....(咦

ryuga93 commented 5 years ago

It might be doable if we can get the servant data from the FGO database websites available and use them in our code. Then, we can delegate the scalability to the websites.

嗯,其实破解思路并不难,主要障碍是解开“暗号”,找到对的地方下手。

29988122 commented 5 years ago

ryuga93

XD, indeed. But I wonder if the resolution's enough for us.

Just FYI: I asked if someday Ankulua would provide support of functions added in sikulix 1.1.4 such as: https://sikulix-2014.readthedocs.io/en/latest/pattern.html

And he said that he will look into it after Lunar New Year. Finally we have a way to deal with irregular/non-rectangle shape...XD

PokeGuys commented 5 years ago

@ryuga93 For how to transfer file through Ankulua function.

Steps

  1. Read file in hex
  2. Send request with file content in hex.
  3. Done.
function readFile(fileName)
    local file = io.open(Config.runtimePath .. fileName, 'rb')
    local t = ''
    repeat
        local str = file:read(4 * 1024)
        for c in (str or ''):gmatch'.' do
            t = t .. string.format('%02X', c:byte())
        end
    until not str
    file:close()
    return t
end

function fetchAPI(method, endpoint, data)
    if (not isString(method)) then
        scriptExit('[fetchAPI] Method Not a String')
    end
    if (not isString(endpoint)) then
        scriptExit('[fetchAPI] Endpoint Not a String')
    end
    if (not isTable(data)) then
        scriptExit('[fetchAPI] Data Not a Table')
    end
    if (method:upper() == 'GET') then
        return httpGet(Config.API_URL..endpoint)
    else
        return httpPost(Config.API_URL..endpoint, data)
    end
end

function OCR(endpoint, reg)
    screenshot(reg, 'tmp.png')
    return fetchAPI('POST', endpoint, { hex=readFile('tmp.png'), token=getDeviceID() })
end

Issue

Each time you create a new request through the function, it will log the action and store it into a variable. At the end of the script, it will show up as an alert box to tell the user which URL are being requested.

But there is a small issue in Ankulua behavior. When the file is too large / too many request, the app itself will quit silently. This issue has been reported but the author of Ankulua refused to add a proper way to perform file upload or remove the logging stuff (which turn out is total meaningless and can be bypass).

Summary

  1. Ankulua author fix the request logging function.
  2. Ankulua author implement a better way to upload file.
  3. Build a fully customized HTTP lib in Lua.

Ref: HTTP library (Using busybox as cURL / Android NDK build a cURL binary)

  1. API.lua
  2. vendor/http.lua
  3. vendor/response.lua
  4. vendor/json.lua
PokeGuys commented 5 years ago

After applying API, we can add some useful features like Servant current NP, Servant Skill Level, Player current AP etc. Those features required pre-processing and turn into binarized image, otherwise it cannot apply to tesseract and extract the number/string in the image.

ryuga93 commented 5 years ago

@PokeGuys thanks! Will try it and see what I can cook up.

29988122 commented 5 years ago

Although I won't be available within at least 3 months...

http://ankulua-tw.boards.net/thread/149/ Recent update of AnkuLua.

Here's the deal: https://sikulix-2014.readthedocs.io/en/latest/pattern.html#Pattern.mask We can greatly improve image recognition, overcome cropping restraints, by implementing the masking function.

29988122 commented 4 years ago

@reconman this thread can be used for general discussion/chitchat btw.

https://github.com/29988122/Fate-Grand-Order_Lua/projects https://github.com/29988122/Fate-Grand-Order_Lua/wiki

These two links are some todos/documentations I wrote about half a year ago. Feel free to modify them if you feel the need to. Also, Project Pendragon by PokeGuys/ryugawa is another ongoing project bringing ML/AI in FGO automation script. WIP.

Just a FYI; thank you for your contribution!

reconman commented 4 years ago

@29988122 I've seen this issue and the 2 linked pages already.

Currently there are 3 places of documentation:

  1. In the code
  2. In the README
  3. In the Wiki

How should things be handled in the future? Update all 3 at the same time on every change?

29988122 commented 4 years ago

I've been taught that you should only put code logic in code comments (sometimes write comments even when the code itself is self-evident), and any design/business logic in documentations.

Also README should be SIGNIFICANTLY SHORTER, cause it's for end users not for devs.

As you can see, I did not do them very well. Just a n00b coder and n00b tech documentation writer. I also tackled the doc/comment/readme sync issue myself a year ago, cause I've encountered this issue so many times in this repo alone. However I got limited results.

Not enough experience/no mentor caused this, I guess.


At the moment, I think you can do the coding style/comments/documentation cleanup as you wish - it's better if we follow one style from now on. (ask potchy first maybe)

reconman commented 4 years ago

Is the logic of choosing the danger servant before doing SkillCommand intentional?

Some more info on what I mean: onTurnStarted() chooses the target automatically, and then after that performBattle() will apply the SkillCommand.

29988122 commented 4 years ago

Intentional.

I (we) can't quite figure out how to merge the choosing target (and user config) into SkillCommand. Currently I just point that to the enemy with probably most health (hence danger/servant).

Feel free to modify that part of the logic, to see if you can figure out how to combine target choosing/card chaining/skill using and make them run more smoothly!

29988122 commented 3 years ago

In case anyone needs this: https://github.com/lsq5i5j/Fgo_teamup Readme in Chinese https://bbs.nga.cn/read.php?tid=21054760

Basically a battle emu....should be useful for NP % calculate/ML DL card selection use.

The latest version should be downloaded here, not on Github https://mega.nz/folder/yDQ1SKTJ#ZgCcQN6sGqisXkrOAKxVGQ