Player event export plus lua_object api

This commit is contained in:
KimLS 2013-06-03 16:49:47 -07:00
parent bc82bff4b4
commit 85c7e1b059
7 changed files with 397 additions and 72 deletions

View File

@ -151,6 +151,7 @@ SET(zone_headers
lua_iteminst.h
lua_mob.h
lua_npc.h
lua_object.h
lua_parser.h
lua_parser_events.h
lua_ptr.h

View File

@ -6,11 +6,217 @@
#include "object.h"
#include "lua_object.h"
void Lua_Object::Depop() {
Lua_Safe_Call_Void();
self->Depop();
}
void Lua_Object::Repop() {
Lua_Safe_Call_Void();
self->Repop();
}
void Lua_Object::SetModelName(const char *name) {
Lua_Safe_Call_Void();
self->SetModelName(name);
}
const char *Lua_Object::GetModelName() {
Lua_Safe_Call_String();
return self->GetModelName();
}
float Lua_Object::GetX() {
Lua_Safe_Call_Real();
return self->GetX();
}
float Lua_Object::GetY() {
Lua_Safe_Call_Real();
return self->GetY();
}
float Lua_Object::GetZ() {
Lua_Safe_Call_Real();
return self->GetZ();
}
float Lua_Object::GetHeading() {
Lua_Safe_Call_Real();
float h = 0.0f;
self->GetHeading(&h);
return h;
}
void Lua_Object::SetX(float x) {
Lua_Safe_Call_Void();
self->SetX(x);
}
void Lua_Object::SetY(float y) {
Lua_Safe_Call_Void();
self->SetY(y);
}
void Lua_Object::SetZ(float z) {
Lua_Safe_Call_Void();
self->SetZ(z);
}
void Lua_Object::SetHeading(float h) {
Lua_Safe_Call_Void();
self->SetHeading(h);
}
void Lua_Object::SetLocation(float x, float y, float z) {
Lua_Safe_Call_Void();
self->SetLocation(x, y, z);
}
void Lua_Object::SetItemID(uint32 item_id) {
Lua_Safe_Call_Void();
self->SetItemID(item_id);
}
uint32 Lua_Object::GetItemID() {
Lua_Safe_Call_Int();
return self->GetItemID();
}
void Lua_Object::SetIcon(uint32 icon) {
Lua_Safe_Call_Void();
self->SetIcon(icon);
}
uint32 Lua_Object::GetIcon() {
Lua_Safe_Call_Int();
return self->GetIcon();
}
void Lua_Object::SetType(uint32 type) {
Lua_Safe_Call_Void();
self->SetType(type);
}
uint32 Lua_Object::GetType() {
Lua_Safe_Call_Int();
return self->GetType();
}
uint32 Lua_Object::GetDBID() {
Lua_Safe_Call_Int();
return self->GetDBID();
}
void Lua_Object::ClearUser() {
Lua_Safe_Call_Void();
self->ClearUser();
}
void Lua_Object::SetID(int user) {
Lua_Safe_Call_Void();
self->SetID(user);
}
int Lua_Object::GetID() {
Lua_Safe_Call_Int();
return self->GetID();
}
bool Lua_Object::Save() {
Lua_Safe_Call_Int();
return self->Save();
}
uint32 Lua_Object::VarSave() {
Lua_Safe_Call_Int();
return self->VarSave();
}
void Lua_Object::DeleteItem(int index) {
Lua_Safe_Call_Void();
self->DeleteItem(index);
}
void Lua_Object::StartDecay() {
Lua_Safe_Call_Void();
self->StartDecay();
}
void Lua_Object::Delete() {
Lua_Safe_Call_Void();
self->Delete();
}
void Lua_Object::Delete(bool reset_state) {
Lua_Safe_Call_Void();
self->Delete(reset_state);
}
bool Lua_Object::IsGroundSpawn() {
Lua_Safe_Call_Int();
return self->IsGroundSpawn();
}
void Lua_Object::Close() {
Lua_Safe_Call_Void();
self->Close();
}
const char *Lua_Object::GetEntityVariable(const char *name) {
Lua_Safe_Call_String();
return self->GetEntityVariable(name);
}
void Lua_Object::SetEntityVariable(const char *name, const char *value) {
Lua_Safe_Call_Void();
self->SetEntityVariable(name, value);
}
bool Lua_Object::EntityVariableExists(const char *name) {
Lua_Safe_Call_Int();
return self->EntityVariableExists(name);
}
luabind::scope lua_register_object() {
return luabind::class_<Lua_Object, Lua_Entity>("Object")
.def(luabind::constructor<>())
.property("null", &Lua_Object::Null)
.property("valid", &Lua_Object::Valid);
.property("valid", &Lua_Object::Valid)
.def("Depop", (void(Lua_Object::*)(void))&Lua_Object::Depop)
.def("Repop", (void(Lua_Object::*)(void))&Lua_Object::Repop)
.def("SetModelName", (void(Lua_Object::*)(const char*))&Lua_Object::SetModelName)
.def("GetModelName", (const char*(Lua_Object::*)(void))&Lua_Object::GetModelName)
.def("GetX", (float(Lua_Object::*)(void))&Lua_Object::GetX)
.def("GetY", (float(Lua_Object::*)(void))&Lua_Object::GetY)
.def("GetZ", (float(Lua_Object::*)(void))&Lua_Object::GetZ)
.def("GetHeading", (float(Lua_Object::*)(void))&Lua_Object::GetHeading)
.def("SetX", (void(Lua_Object::*)(float))&Lua_Object::SetX)
.def("SetY", (void(Lua_Object::*)(float))&Lua_Object::SetY)
.def("SetZ", (void(Lua_Object::*)(float))&Lua_Object::SetZ)
.def("SetHeading", (void(Lua_Object::*)(float))&Lua_Object::SetHeading)
.def("SetLocation", (void(Lua_Object::*)(float,float,float))&Lua_Object::SetLocation)
.def("SetItemID", (void(Lua_Object::*)(uint32))&Lua_Object::SetItemID)
.def("GetItemID", (uint32(Lua_Object::*)(void))&Lua_Object::GetItemID)
.def("SetIcon", (void(Lua_Object::*)(uint32))&Lua_Object::SetIcon)
.def("GetIcon", (uint32(Lua_Object::*)(void))&Lua_Object::GetIcon)
.def("SetType", (void(Lua_Object::*)(uint32))&Lua_Object::SetType)
.def("GetType", (uint32(Lua_Object::*)(void))&Lua_Object::GetType)
.def("GetDBID", (uint32(Lua_Object::*)(void))&Lua_Object::GetDBID)
.def("ClearUser", (void(Lua_Object::*)(void))&Lua_Object::ClearUser)
.def("SetID", (void(Lua_Object::*)(int))&Lua_Object::SetID)
.def("GetID", (int(Lua_Object::*)(void))&Lua_Object::GetID)
.def("Save", (bool(Lua_Object::*)(void))&Lua_Object::Save)
.def("VarSave", (uint32(Lua_Object::*)(void))&Lua_Object::VarSave)
.def("DeleteItem", (void(Lua_Object::*)(int))&Lua_Object::DeleteItem)
.def("StartDecay", (void(Lua_Object::*)(void))&Lua_Object::StartDecay)
.def("Delete", (void(Lua_Object::*)(void))&Lua_Object::Delete)
.def("Delete", (void(Lua_Object::*)(bool))&Lua_Object::Delete)
.def("IsGroundSpawn", (bool(Lua_Object::*)(void))&Lua_Object::IsGroundSpawn)
.def("Close", (void(Lua_Object::*)(void))&Lua_Object::Close)
.def("GetEntityVariable", (const char*(Lua_Object::*)(const char*))&Lua_Object::GetEntityVariable)
.def("SetEntityVariable", (void(Lua_Object::*)(const char*,const char*))&Lua_Object::SetEntityVariable)
.def("EntityVariableExists", (bool(Lua_Object::*)(const char*))&Lua_Object::EntityVariableExists);
}
#endif

View File

@ -28,6 +28,41 @@ public:
return nullptr;
}
void Depop();
void Repop();
void SetModelName(const char *name);
const char *GetModelName();
float GetX();
float GetY();
float GetZ();
float GetHeading();
void SetX(float x);
void SetY(float y);
void SetZ(float z);
void SetHeading(float h);
void SetLocation(float x, float y, float z);
void SetItemID(uint32 item_id);
uint32 GetItemID();
void SetIcon(uint32 icon);
uint32 GetIcon();
void SetType(uint32 type);
uint32 GetType();
uint32 GetDBID();
void ClearUser();
void SetID(int user);
int GetID();
bool Save();
uint32 VarSave();
void DeleteItem(int index);
void StartDecay();
void Delete();
void Delete(bool reset_state);
bool IsGroundSpawn();
void Close();
const char *GetEntityVariable(const char *name);
void SetEntityVariable(const char *name, const char *value);
bool EntityVariableExists(const char *name);
};
#endif

View File

@ -138,6 +138,26 @@ LuaParser::LuaParser() {
NPCArgumentDispatch[EVENT_TIMER] = handle_npc_timer;
NPCArgumentDispatch[EVENT_DEATH] = handle_npc_death;
PlayerArgumentDispatch[EVENT_SAY] = handle_player_say;
PlayerArgumentDispatch[EVENT_DEATH] = handle_player_death;
PlayerArgumentDispatch[EVENT_TIMER] = handle_player_timer;
PlayerArgumentDispatch[EVENT_DISCOVER_ITEM] = handle_player_discover_item;
PlayerArgumentDispatch[EVENT_FISH_SUCCESS] = handle_player_fish_forage_success;
PlayerArgumentDispatch[EVENT_FORAGE_SUCCESS] = handle_player_fish_forage_success;
PlayerArgumentDispatch[EVENT_CLICK_OBJECT] = handle_player_click_object;
PlayerArgumentDispatch[EVENT_CLICK_DOOR] = handle_player_click_door;
PlayerArgumentDispatch[EVENT_SIGNAL] = handle_player_signal;
PlayerArgumentDispatch[EVENT_POPUP_RESPONSE] = handle_player_popup_response;
PlayerArgumentDispatch[EVENT_PLAYER_PICKUP] = handle_player_pick_up;
PlayerArgumentDispatch[EVENT_CAST] = handle_player_cast;
PlayerArgumentDispatch[EVENT_TASK_FAIL] = handle_player_task_fail;
PlayerArgumentDispatch[EVENT_ZONE] = handle_player_zone;
PlayerArgumentDispatch[EVENT_DUEL_WIN] = handle_player_duel_win;
PlayerArgumentDispatch[EVENT_DUEL_LOSE] = handle_player_duel_loss;
PlayerArgumentDispatch[EVENT_LOOT] = handle_player_loot;
PlayerArgumentDispatch[EVENT_TASK_STAGE_COMPLETE] = handle_player_task_stage_complete;
PlayerArgumentDispatch[EVENT_TASK_COMPLETE] = handle_player_task_complete;
L = nullptr;
}
@ -463,10 +483,16 @@ int LuaParser::_EventSpell(std::string package_name, QuestEventID evt, NPC* npc,
lua_createtable(L, 0, 0);
//always push self
Lua_Spell l_spell(&spells[spell_id]);
luabind::object l_spell_o = luabind::object(L, l_spell);
l_spell_o.push(L);
//always push self even if invalid
if(IsValidSpell(spell_id)) {
Lua_Spell l_spell(&spells[spell_id]);
luabind::object l_spell_o = luabind::object(L, l_spell);
l_spell_o.push(L);
} else {
Lua_Spell l_spell(nullptr);
luabind::object l_spell_o = luabind::object(L, l_spell);
l_spell_o.push(L);
}
lua_setfield(L, -2, "self");
auto arg_function = SpellArgumentDispatch[evt];

View File

@ -189,68 +189,6 @@ void handle_npc_death(QuestInterface *parse, lua_State* L, NPC* npc, Mob *init,
void handle_npc_null(QuestInterface *parse, lua_State* L, NPC* npc, Mob *init, std::string data, uint32 extra_data) {
}
/*switch(evt) {
case EVENT_FISH_SUCCESS:
case EVENT_FORAGE_SUCCESS: {
lua_pushinteger(L, extra_data);
arg_count += 1;
break;
}
case EVENT_CLICK_OBJECT:
case EVENT_CLICK_DOOR:
case EVENT_SIGNAL:
case EVENT_POPUP_RESPONSE:
case EVENT_PLAYER_PICKUP:
case EVENT_CAST:
case EVENT_TASK_FAIL:
case EVENT_ZONE: {
lua_pushinteger(L, std::stoi(data));
arg_count += 1;
break;
}
case EVENT_DUEL_WIN:
case EVENT_DUEL_LOSE: {
lua_pushstring(L, data.c_str());
lua_pushinteger(L, extra_data);
arg_count += 2;
break;
}
case EVENT_LOOT: {
Seperator sep(data.c_str());
lua_pushinteger(L, std::stoi(sep.arg[0]));
lua_pushinteger(L, std::stoi(sep.arg[1]));
lua_pushstring(L, sep.arg[2]);
arg_count += 3;
break;
}
case EVENT_TASK_STAGE_COMPLETE: {
Seperator sep(data.c_str());
lua_pushinteger(L, std::stoi(sep.arg[0]));
lua_pushinteger(L, std::stoi(sep.arg[1]));
arg_count += 2;
break;
}
case EVENT_TASK_COMPLETE: {
Seperator sep(data.c_str());
lua_pushinteger(L, std::stoi(sep.arg[0]));
lua_pushinteger(L, std::stoi(sep.arg[1]));
lua_pushinteger(L, std::stoi(sep.arg[2]));
arg_count += 3;
break;
}
}*/
//Player
void handle_player_say(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data) {
lua_pushstring(L, data.c_str());
@ -260,7 +198,6 @@ void handle_player_say(QuestInterface *parse, lua_State* L, Client* client, std:
lua_setfield(L, -2, "language");
}
void handle_player_death(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data) {
Seperator sep(data.c_str());
@ -295,7 +232,7 @@ void handle_player_timer(QuestInterface *parse, lua_State* L, Client* client, st
lua_setfield(L, -2, "timer");
}
void handle_discover_item(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data) {
void handle_player_discover_item(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data) {
const Item_Struct *item = database.GetItem(extra_data);
if(item) {
Lua_Item l_item(item);
@ -310,6 +247,110 @@ void handle_discover_item(QuestInterface *parse, lua_State* L, Client* client, s
}
}
void handle_player_fish_forage_success(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data) {
lua_pushinteger(L, extra_data);
lua_setfield(L, -2, "item_id");
}
void handle_player_click_object(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data) {
lua_pushinteger(L, std::stoi(data));
lua_setfield(L, -2, "object_id");
}
void handle_player_click_door(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data) {
lua_pushinteger(L, std::stoi(data));
lua_setfield(L, -2, "door_id");
}
void handle_player_signal(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data) {
lua_pushinteger(L, std::stoi(data));
lua_setfield(L, -2, "signal");
}
void handle_player_popup_response(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data) {
lua_pushinteger(L, std::stoi(data));
lua_setfield(L, -2, "popup_id");
}
void handle_player_pick_up(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data) {
lua_pushinteger(L, std::stoi(data));
lua_setfield(L, -2, "picked_up_id");
}
void handle_player_cast(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data) {
int spell_id = std::stoi(data);
if(IsValidSpell(spell_id)) {
Lua_Spell l_spell(&spells[spell_id]);
luabind::object l_spell_o = luabind::object(L, l_spell);
l_spell_o.push(L);
} else {
Lua_Spell l_spell(nullptr);
luabind::object l_spell_o = luabind::object(L, l_spell);
l_spell_o.push(L);
}
lua_setfield(L, -2, "spell");
}
void handle_player_task_fail(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data) {
lua_pushinteger(L, std::stoi(data));
lua_setfield(L, -2, "task_id");
}
void handle_player_zone(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data) {
lua_pushinteger(L, std::stoi(data));
lua_setfield(L, -2, "zone_id");
}
void handle_player_duel_win(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data) {
lua_pushstring(L, data.c_str());
lua_setfield(L, -2, "loser_character_name");
lua_pushinteger(L, extra_data);
lua_setfield(L, -2, "loser_character_id");
}
void handle_player_duel_loss(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data) {
lua_pushstring(L, data.c_str());
lua_setfield(L, -2, "winner_character_name");
lua_pushinteger(L, extra_data);
lua_setfield(L, -2, "winner_character_id");
}
void handle_player_loot(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data) {
Seperator sep(data.c_str());
lua_pushinteger(L, std::stoi(sep.arg[0]));
lua_setfield(L, -2, "looted_id");
lua_pushinteger(L, std::stoi(sep.arg[1]));
lua_setfield(L, -2, "looted_charges");
lua_pushstring(L, sep.arg[2]);
lua_setfield(L, -2, "corpse");
}
void handle_player_task_stage_complete(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data) {
Seperator sep(data.c_str());
lua_pushinteger(L, std::stoi(sep.arg[0]));
lua_setfield(L, -2, "task_id");
lua_pushinteger(L, std::stoi(sep.arg[1]));
lua_setfield(L, -2, "activity_id");
}
void handle_player_task_complete(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data) {
Seperator sep(data.c_str());
lua_pushinteger(L, std::stoi(sep.arg[0]));
lua_setfield(L, -2, "done_count");
lua_pushinteger(L, std::stoi(sep.arg[1]));
lua_setfield(L, -2, "activity_id");
lua_pushinteger(L, std::stoi(sep.arg[2]));
lua_setfield(L, -2, "task_id");
}
void handle_player_null(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data) {
}

View File

@ -23,6 +23,24 @@ void handle_npc_death(QuestInterface *parse, lua_State* L, NPC* npc, Mob *init,
void handle_npc_null(QuestInterface *parse, lua_State* L, NPC* npc, Mob *init, std::string data, uint32 extra_data);
//Player
void handle_player_say(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data);
void handle_player_death(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data);
void handle_player_timer(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data);
void handle_player_discover_item(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data);
void handle_player_fish_forage_success(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data);
void handle_player_click_object(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data);
void handle_player_click_door(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data);
void handle_player_signal(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data);
void handle_player_popup_response(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data);
void handle_player_pick_up(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data);
void handle_player_cast(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data);
void handle_player_task_fail(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data);
void handle_player_zone(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data);
void handle_player_duel_win(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data);
void handle_player_duel_loss(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data);
void handle_player_loot(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data);
void handle_player_task_stage_complete(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data);
void handle_player_task_complete(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data);
void handle_player_null(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data);
//Item

View File

@ -426,7 +426,7 @@ void Merc::AddItemBonuses(const Item_Struct *item, StatBonuses* newbon) {
if(item->Attack > 0) {
int cap = RuleI(Character, ItemATKCap);
unsigned int cap = RuleI(Character, ItemATKCap);
cap += itembonuses.ItemATKCap + spellbonuses.ItemATKCap + aabonuses.ItemATKCap;
if((newbon->ATK + item->Attack) > cap)
@ -2284,7 +2284,6 @@ bool Merc::AICastSpell(int8 iChance, int32 iSpellTypes) {
else {
for( int i = 0; i < MAX_GROUP_MEMBERS; i++) {
if(g->members[i]) {
int32 oDontDoAgainBefore;
Mob* tar = g->members[i];
if( !tar->IsImmuneToSpell(selectedMercSpell.spellid, this)
@ -2463,7 +2462,6 @@ bool Merc::AICastSpell(int8 iChance, int32 iSpellTypes) {
if(castedSpell) {
if(IsGroupSpell(selectedMercSpell.spellid)){
Group *g;
if(this->HasGroup()) {
Group *g = this->GetGroup();