Add feature query protocol and scheduled event drop gates
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
// Run on FreeBSD against the project's real Lua 5.0 library and installed compiled quest states.
|
||||
// No game process, DB, network or live state is modified.
|
||||
#include <cassert>
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
extern "C" {
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
}
|
||||
#define __QUEST_PC_H
|
||||
#define CHAT_TYPE_COMMAND 5
|
||||
namespace quest {
|
||||
struct PC {
|
||||
bool loaded=true,running=false;std::map<std::string,int> flags;
|
||||
bool IsLoaded(){return loaded;}bool IsRunning(){return running;}
|
||||
int GetFlag(const std::string& key){return flags[key];}
|
||||
};
|
||||
struct CQuestManager {
|
||||
lua_State* L=nullptr;PC pc;std::map<std::string,int> events;int currentPlayer=98765;
|
||||
static CQuestManager& instance(){static CQuestManager q;return q;}
|
||||
lua_State* GetLuaState(){return L;}
|
||||
PC* GetPCForce(unsigned id){assert(id==123);return &pc;}
|
||||
int GetEventFlag(const std::string& name){return events[name];}
|
||||
unsigned GetQuestIndexByName(const std::string&){return 1;}
|
||||
int GetQuestStateIndex(const std::string&,const std::string&){
|
||||
const int top=lua_gettop(L);lua_getglobal(L,"dragon_lair_weekly");lua_pushstring(L,"hunt_item");lua_rawget(L,-2);
|
||||
int result=int(lua_tonumber(L,-1));lua_settop(L,top);return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
struct ITEM_MANAGER {
|
||||
static ITEM_MANAGER& instance(){static ITEM_MANAGER m;return m;}
|
||||
void* GetTable(unsigned vnum){return vnum==30179?this:nullptr;}
|
||||
};
|
||||
static long long now=1700000000;static long long get_global_time(){return now;}
|
||||
struct Character {
|
||||
std::vector<std::string> messages;
|
||||
unsigned GetPlayerID(){return 123;}int CountSpecifyItem(unsigned){return 7;}
|
||||
void ChatPacket(int,const char* format,...) {
|
||||
char out[1024];va_list args;va_start(args,format);vsnprintf(out,sizeof(out),format,args);va_end(args);messages.emplace_back(out);
|
||||
}
|
||||
};
|
||||
using LPCHARACTER=Character*;
|
||||
#include "port_dungeons.h"
|
||||
static int eventFlag(lua_State* L) {
|
||||
lua_pushnumber(L,quest::CQuestManager::instance().GetEventFlag(lua_tostring(L,1)));return 1;
|
||||
}
|
||||
static bool contains(const Character& c,const char* text){for(auto& s:c.messages)if(s.find(text)!=std::string::npos)return true;return false;}
|
||||
int main(int argc,char** argv){
|
||||
assert(argc==3);auto& q=quest::CQuestManager::instance();q.L=lua_open();assert(q.L);
|
||||
lua_newtable(q.L);lua_pushstring(q.L,"get_event_flag");lua_pushcfunction(q.L,eventFlag);lua_rawset(q.L,-3);lua_setglobal(q.L,"game");
|
||||
assert(luaL_loadfile(q.L,argv[1])==0 && lua_pcall(q.L,0,0,0)==0);
|
||||
assert(luaL_loadfile(q.L,argv[2])==0 && lua_pcall(q.L,0,0,0)==0);
|
||||
q.events["dragon_lair_time"]=now-100;q.events["dragon_lair_alive"]=1;
|
||||
q.pc.flags["dragon_lair_weekly.lasttime"]=now-1000;
|
||||
q.pc.flags["dragon_lair_weekly.__status"]=q.GetQuestStateIndex("dragon_lair_weekly","hunt_item");
|
||||
Character ch;const int top=lua_gettop(q.L);PortDungeonQuery(&ch,1);
|
||||
assert(contains(ch,"lair_tickets 3") && contains(ch,"lair_phase 1") && contains(ch,"weekly_active 1"));
|
||||
assert(contains(ch,"weekly_end 1700560600") && contains(ch,"lair_owned 7"));
|
||||
assert(q.currentPlayer==98765 && lua_gettop(q.L)==top);
|
||||
q.events["dragon_lair_amount"]=-1;ch.messages.clear();PortDungeonQuery(&ch,2);assert(contains(ch,"lair_tickets 0"));
|
||||
q.events["dragon_lair_amount"]=5;ch.messages.clear();PortDungeonQuery(&ch,3);assert(contains(ch,"lair_tickets 5"));
|
||||
now+=3500;ch.messages.clear();PortDungeonQuery(&ch,4);assert(contains(ch,"lair_phase 2"));
|
||||
++now;ch.messages.clear();PortDungeonQuery(&ch,5);assert(contains(ch,"lair_phase 0"));
|
||||
q.pc.running=true;ch.messages.clear();PortDungeonQuery(&ch,6);assert(ch.messages.back()=="MTF1 error 6 busy");q.pc.running=false;
|
||||
lua_pushnil(q.L);lua_setglobal(q.L,"dragon_lair_access");ch.messages.clear();PortDungeonQuery(&ch,7);assert(ch.messages.back()=="MTF1 error 7 unsupported");
|
||||
assert(lua_gettop(q.L)==top && q.currentPlayer==98765);
|
||||
lua_close(q.L);puts("PASS: installed quest settings in real Lua 5.0; shared/personal deadlines, ticket overrides, boundaries, stack/context, busy/missing");
|
||||
}
|
||||
Reference in New Issue
Block a user