【PE】超 后 置十二炮 腳本
2023-01-29 21:40 作者:--Reisen-- | 我要投稿

可以自由使用,但請注明來源,遵守 License。
AvZ 版本:AvZ2 2.1.0
邏輯十分抽象,還沒有注釋。將就著看吧。
腳本不直接或間接地讀取刷新倒計(jì)時(shí)等畫面不顯示信息。
/*
MIT License
Copyright (c) 2023 Reisen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <algorithm>
#include <cstdint>
#include <functional>
#include <set>
#include <vector>
#include "avz.h"
#include "AvZDSL/AvZDSL.h"
#include "fodder/fodder.h"
#include "legacy/SetZombiesPlus.h"
using namespace std;
APvzBase* pb;
AMainObject* mo;
class : AStateHook {
? ?void _BeforeScript() override {
? ? ? ?pb = AGetPvzBase();
? ? ? ?mo = AGetMainObject();
? ?}
} _mo_initializer;
vector<APlant*> ACard(const vector<APlantType>& ps, int row, int col) {
? ?vector<APlant*> out;
? ?for(auto p : ps)
? ? ? ?out.push_back(ACard(p, row, col));
? ?return out;
}
vector<APlant*> ACard(const vector<APlantType>& ps, const vector<APosition>& lst) {
? ?vector<APlant*> out;
? ?for(auto p : ps)
? ? ? ?out.push_back(ACard(p, lst));
? ?return out;
}
#define CardR(...) AMkRelOp(ACard(__VA_ARGS__))
template <typename... Ts>
ARelOp ShovelR(Ts... args) {
? ?return AMkRelOp(AShovel(args...));
}
ARelOp IceDayR() {
? ?ARelTime t = rand() % 2 ? 298 : 299;
? ?return -t[
? ? ? ?AMkRelOp(aIceFiller.Coffee()),
? ? ? ?AMkRelOp(AIce3(int(t)))
? ?];
}
ARelOp UseIceR(int row, int col) {
? ?return -100_cs[
? ? ? ?AMkRelOp(ACard(AICE_SHROOM, row, col))
? ?];
}
ARelOp UseImitatorIceR(int row, int col) {
? ?ARelTime t = rand() % 2 ? 419 : 420; // 模仿者生效時(shí)間可能取 319 或 320
? ?return -t[
? ? ? ?CardR(AM_ICE_SHROOM, row, col),
? ? ? ?AMkRelOp(AIce3(int(t)))
? ?];
}
ARelOp IceNightR(int row, int col) {
? ?return -420_cs[AMkRelOp(
? ? ? ?int idx = AGetSeedIndex(AICE_SHROOM, true);
? ? ? ?if(idx != -1 && AGetMainObject()->SeedArray()[idx].IsUsable()) // 復(fù)制冰可用
? ? ? ? ? ?ANow + 420_cs[UseImitatorIceR(row, col)];
? ? ? ?else
? ? ? ? ? ?ANow + 420_cs[UseIceR(row, col)];
? ?)];
}
ARelOp FireR(int row, float col, bool wait_until_recover = false) {
? ?vector<APosition> pos;
? ?while(row) {
? ? ? ?pos.push_back({row % 10, col});
? ? ? ?row /= 10;
? ?}
? ?reverse(pos.begin(), pos.end());
? ?if(wait_until_recover)
? ? ? ?return -373_cs[AMkRelOp(aCobManager.RecoverFire(pos))];
? ?else
? ? ? ?return -373_cs[AMkRelOp(aCobManager.Fire(pos))];
}
ARelOp FireR(const vector<APosition>& pos, bool wait_until_recover = false) {
? ?auto out = AMkRelOp();
? ?for(auto [r, c] : pos)
? ? ? ?out += FireR(r, c, wait_until_recover);
? ?return out;
}
class MaidCheatsR {
public:
? ?static ARelOp CallPartner() {
? ? ? ?return AMkRelOp(AMaidCheats::CallPartner());
? ?}
? ?static ARelOp Dancing() {
? ? ? ?return AMkRelOp(AMaidCheats::Dancing());
? ?}
? ?static ARelOp Move() {
? ? ? ?return AMkRelOp(AMaidCheats::Move());
? ?}
? ?static ARelOp Stop() {
? ? ? ?return AMkRelOp(AMaidCheats::Stop());
? ?}
};
ALogger<APvzGui> l;
template <typename... Ts>
ARelOp InfoR(Ts... args) {
? ?return AMkRelOp(l.Info(args...));
}
// PropFilter(&AZombie::Hp, greater(), 3000)
template <typename T, typename Value>
AAliveFilter<T> PropFilter(Value (T::* prop)(), auto&& op, auto v) {
? ?return AAliveFilter<T>([=](T* x){ return op((x->*prop)(), v); });
}
// PropFilter(&AZombie::Type, AGIGA_GARGANTUAR)
template <typename T, typename Value>
AAliveFilter<T> PropFilter(Value (T::* prop)(), auto v) {
? ?return PropFilter(prop, equal_to(), v);
}
// ----------------------------------------------------------------
FodderR f({APUFF_SHROOM, AM_PUFF_SHROOM, ASUN_SHROOM, ASCAREDY_SHROOM, AFLOWER_POT, ASUNFLOWER, AGARLIC});
int next_fire_1, last_fodder;
ATimeConnectHandle upper_fodder;
void fire();
struct {
? ?int countdown = 0;
? ?void run(){
? ? ? ?if(countdown == 0)
? ? ? ? ? ?return;
? ? ? ?if(ANowTime(ANowWave()) == 15 || countdown == 1) {
? ? ? ? ? ?countdown = 0;
? ? ? ? ? ?fire();
? ? ? ?} else
? ? ? ? ? ?countdown--;
? ?}
} smart_fire;
void fire() {
? ?auto t = PropFilter(&AZombie::Row, less_equal(), 2);
? ?if(t.begin() == t.end())
? ? ? ?return;
? ?aCobManager.Fire(2, 8.75);
? ?upper_fodder = AConnect(ANowDelayTime(373 - 194), f({1, 2}, 100))[0];
? ?next_fire_1 = mo->GameClock() + 373;
? ?AConnect(ANowDelayTime(588), []{
? ? ? ?smart_fire.countdown = 50;
? ?});
}
void try_card(APlantType p, int r, int c) {
? ?int idx = AGetCardIndex(p);
? ?if(idx != -1 && mo->SeedArray()[idx].IsUsable())
? ? ? ?ACard(p, r, c);
}
void fodder_func() {
? ?int min_x = 800;
? ?for(auto& z : PropFilter(&AZombie::Type, AGIGA_GARGANTUAR))
? ? ? ?if(z.Row() >= 3)
? ? ? ? ? ?min_x = min(min_x, int(z.Abscissa()));
? ?if(mo->GameClock() - last_fodder < 751 || min_x >= 500)
? ? ? ?return;
? ?bool col_6_available = true;
? ?for(auto& z : PropFilter(&AZombie::Type, AZOMBONI))
? ? ? ?if(int(z.Abscissa()) <= 485)
? ? ? ? ? ?col_6_available = false;
? ?if(col_6_available) {
? ? ? ?AConnect(ANowTime(), f({5, 6}, -1, 6));
? ? ? ?last_fodder = mo->GameClock();
? ?}
}
void AUpdateZombiesPreview();
void AScript() {
? ?ASetReloadMode(AReloadMode::MAIN_UI);
? ?AConnect(AKey('Q'), []{ throw AException(""); });
? ?AConnect(AKey('W'), []{ aIceFiller.Coffee(); });
? ?AConnect(AKey('E'), []{ ACard(AGARLIC, 6, 5); });
? ?//ASetGameSpeed(1);
? ?SetZombiesPlus({AZOMBIE, ACONEHEAD_ZOMBIE, APOLE_VAULTING_ZOMBIE, ADANCING_ZOMBIE, AZOMBONI, AJACK_IN_THE_BOX_ZOMBIE, AFOOTBALL_ZOMBIE, ALADDER_ZOMBIE, APOGO_ZOMBIE, ABUNGEE_ZOMBIE, AGARGANTUAR, AGIGA_GARGANTUAR});
? ?AUpdateZombiesPreview();
? ?ASelectCards({AICE_SHROOM, ACOFFEE_BEAN, APUFF_SHROOM, AM_PUFF_SHROOM, ASUN_SHROOM, ASCAREDY_SHROOM, AFLOWER_POT, ASUNFLOWER, AGARLIC, APUMPKIN});
? ?*(uint16_t*)0x46d672 = 0x9700; // 取消引信延遲
? ?aPlantFixer.Start(APUMPKIN, {}, 1333);
? ?aIceFiller.Start({{4, 3}});
? ?AGetInternalLogger()->SetLevel({ALogLevel::ERROR});
? ?last_fodder = 0;
? ?AConnect([]{ return true; }, []{ smart_fire.run(); });
? ?AConnect(ATime(1, 0), []{ smart_fire.countdown = 40; });
? ?auto fodder_handle = AConnect([]{ return true; }, fodder_func);
? ?AConnect([]{ return ANowTime(1) % 695 == 0; }, [=]{
? ? ? ?aCobManager.Fire(5, 4.675);
? ? ? ?AConnect(ANowDelayTime(373 - 1), [=]{ AConnectHandle(fodder_handle).Pause(); });
? ? ? ?AConnect(ANowDelayTime(373 + 30), [=]{ AConnectHandle(fodder_handle).GoOn(); });
? ?});
? ?for(int w = 1; w <= 20; w++)
? ? ? ?AConnect(ATime(w, 16), [=]{
? ? ? ? ? ?if(next_fire_1 < mo->GameClock() - 16 + 359) {
? ? ? ? ? ? ? ?if(next_fire_1 <= mo->GameClock() - 16 + 318)
? ? ? ? ? ? ? ? ? ?upper_fodder.Stop();
? ? ? ? ? ? ? ?AConnect(ANowDelayTime(max(next_fire_1 - mo->GameClock() + 588 - 373, 0)), []{
? ? ? ? ? ? ? ? ? ?smart_fire.countdown = 0;
? ? ? ? ? ? ? ?});
? ? ? ? ? ? ? ?int time = next_fire_1 - (mo->GameClock() - 16);
? ? ? ? ? ? ? ?AConnect(ATime(w, max(time + 344, 389) - 373), fire);
? ? ? ? ? ?}
? ? ? ?});
? ?for(int w : {10, 20})
? ? ? ?AConnect(ATime(w, 395), IceDayR());
? ?AConnect(ATime(20, 240), FireR(4, 7.5));
}
標(biāo)簽: