feat: Added DamageDescription class
+ Added onPlayerDamage event
This commit is contained in:
@@ -5,5 +5,6 @@ from g2o.events import event
|
|||||||
from g2o.events import removeEventHandler
|
from g2o.events import removeEventHandler
|
||||||
|
|
||||||
from g2o.packets import Packet
|
from g2o.packets import Packet
|
||||||
|
from g2o.damage import DamageDescription
|
||||||
|
|
||||||
from sqg2oconst import *
|
from sqg2oconst import *
|
||||||
58
g2o/damage.py
Normal file
58
g2o/damage.py
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import sqg2o
|
||||||
|
|
||||||
|
class DamageDescription(sqg2o.DamageDescription):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
return super().__init__()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def item_instance(self):
|
||||||
|
return super().item_instance
|
||||||
|
|
||||||
|
@property
|
||||||
|
def flags(self):
|
||||||
|
return super().flags
|
||||||
|
|
||||||
|
@flags.setter
|
||||||
|
def flags(self, value):
|
||||||
|
super().flags = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def damage(self):
|
||||||
|
return super().damage
|
||||||
|
|
||||||
|
@damage.setter
|
||||||
|
def damage(self, value):
|
||||||
|
super().damage = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def distance(self):
|
||||||
|
return super().distance
|
||||||
|
|
||||||
|
@distance.setter
|
||||||
|
def distance(self, value):
|
||||||
|
super().distance = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def spell_id(self):
|
||||||
|
return super().spell_id
|
||||||
|
|
||||||
|
@spell_id.setter
|
||||||
|
def spell_id(self, value):
|
||||||
|
super().spell_id = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def spell_level(self):
|
||||||
|
return super().spell_level
|
||||||
|
|
||||||
|
@spell_level.setter
|
||||||
|
def spell_level(self, value):
|
||||||
|
super().spell_level = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def node(self):
|
||||||
|
return super().node
|
||||||
|
|
||||||
|
@node.setter
|
||||||
|
def node(self, value):
|
||||||
|
super().node = value
|
||||||
@@ -138,6 +138,7 @@ addEvent('onPlayerChangeWeaponMode')
|
|||||||
addEvent('onPlayerChangeWorld')
|
addEvent('onPlayerChangeWorld')
|
||||||
|
|
||||||
addEvent('onPlayerCommand')
|
addEvent('onPlayerCommand')
|
||||||
|
addEvent('onPlayerDamage')
|
||||||
addEvent('onPlayerDead')
|
addEvent('onPlayerDead')
|
||||||
addEvent('onPlayerDisconnect')
|
addEvent('onPlayerDisconnect')
|
||||||
addEvent('onPlayerEnterWorld')
|
addEvent('onPlayerEnterWorld')
|
||||||
|
|||||||
21
src/bind.cpp
21
src/bind.cpp
@@ -1,10 +1,12 @@
|
|||||||
#include <pybind11/embed.h>
|
#include <pybind11/embed.h>
|
||||||
#include "classes/py/Packet.h"
|
#include "classes/py/Packet.h"
|
||||||
|
#include "classes/py/DamageDescription.h"
|
||||||
#include <NoNut/core/Constant.h>
|
#include <NoNut/core/Constant.h>
|
||||||
|
|
||||||
namespace py = pybind11;
|
namespace py = pybind11;
|
||||||
|
|
||||||
PYBIND11_EMBEDDED_MODULE(sqg2o, m) {
|
PYBIND11_EMBEDDED_MODULE(sqg2o, m) {
|
||||||
|
|
||||||
py::class_<PyPacket>(m, "Packet")
|
py::class_<PyPacket>(m, "Packet")
|
||||||
.def(py::init<>())
|
.def(py::init<>())
|
||||||
.def("reset", &PyPacket::reset)
|
.def("reset", &PyPacket::reset)
|
||||||
@@ -30,6 +32,21 @@ PYBIND11_EMBEDDED_MODULE(sqg2o, m) {
|
|||||||
.def("readString", &PyPacket::readString)
|
.def("readString", &PyPacket::readString)
|
||||||
.def("__del__", &PyPacket::del)
|
.def("__del__", &PyPacket::del)
|
||||||
|
|
||||||
.def_property_readonly("bitsUsed", &PyPacket::getBitsUsed)
|
.def_property_readonly("bitsUsed", &PyPacket::getBitsUsed)
|
||||||
.def_property_readonly("bytesUsed", &PyPacket::getBytesUsed);
|
.def_property_readonly("bytesUsed", &PyPacket::getBytesUsed);
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
|
py::class_<PyDamageDescription>(m, "DamageDescription")
|
||||||
|
.def(py::init<>())
|
||||||
|
.def("__del__", &PyDamageDescription::del)
|
||||||
|
|
||||||
|
.def_property_readonly("item_instance", &PyDamageDescription::getItemInstance)
|
||||||
|
|
||||||
|
.def_property("flags", &PyDamageDescription::getFlags, &PyDamageDescription::setFlags, py::return_value_policy::reference_internal)
|
||||||
|
.def_property("damage", &PyDamageDescription::getDamage, &PyDamageDescription::setDamage, py::return_value_policy::reference_internal)
|
||||||
|
.def_property("distance", &PyDamageDescription::getDistance, &PyDamageDescription::setDistance, py::return_value_policy::reference_internal)
|
||||||
|
.def_property("spell_id", &PyDamageDescription::getSpellId, &PyDamageDescription::setSpellId, py::return_value_policy::reference_internal)
|
||||||
|
.def_property("spell_level", &PyDamageDescription::getSpellLevel, &PyDamageDescription::setSpellLevel, py::return_value_policy::reference_internal)
|
||||||
|
.def_property("node", &PyDamageDescription::getNode, &PyDamageDescription::setNode, py::return_value_policy::reference_internal);
|
||||||
}
|
}
|
||||||
33
src/classes/py/DamageDescription.h
Normal file
33
src/classes/py/DamageDescription.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#ifndef _PYDAMAGEDESCRIPTION_H
|
||||||
|
#define _PYDAMAGEDESCRIPTION_H
|
||||||
|
|
||||||
|
#include <classes/sq/DamageDescription.h>
|
||||||
|
|
||||||
|
class PyDamageDescription
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
nonut::DamageDescription *sqobj;
|
||||||
|
|
||||||
|
public:
|
||||||
|
PyDamageDescription() { sqobj = new nonut::DamageDescription(); };
|
||||||
|
PyDamageDescription(SQObject obj) { sqobj = new nonut::DamageDescription(obj); }
|
||||||
|
|
||||||
|
nonut::Int getFlags() { return sqobj->flags; }
|
||||||
|
nonut::Int getDamage() { return sqobj->damage; }
|
||||||
|
nonut::String getItemInstance() { return sqobj->item_instance; }
|
||||||
|
nonut::Int getDistance() { return sqobj->distance; }
|
||||||
|
nonut::Int getSpellId() { return sqobj->spell_id; }
|
||||||
|
nonut::Int getSpellLevel() { return sqobj->spell_level; }
|
||||||
|
nonut::String getNode() { return sqobj->node; }
|
||||||
|
|
||||||
|
void setFlags(nonut::Int value) { sqobj->flags = value; }
|
||||||
|
void setDamage(nonut::Int value) { sqobj->damage = value; }
|
||||||
|
void setDistance(nonut::Int value) { sqobj->distance = value; }
|
||||||
|
void setSpellId(nonut::Int value) { sqobj->spell_id = value; }
|
||||||
|
void setSpellLevel(nonut::Int value) { sqobj->spell_level = value; }
|
||||||
|
void setNode(nonut::String value) { sqobj->node = value; }
|
||||||
|
|
||||||
|
void del() { delete sqobj; }
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef _PYPACKET_H_
|
#ifndef _PYPACKET_H_
|
||||||
#define _PYPACKET_
|
#define _PYPACKET_H_
|
||||||
|
|
||||||
#include <classes/sq/Packet.h>
|
#include <classes/sq/Packet.h>
|
||||||
|
|
||||||
|
|||||||
32
src/classes/sq/DamageDescription.cpp
Normal file
32
src/classes/sq/DamageDescription.cpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#include <NoNut/core/CommonHeader.h>
|
||||||
|
#include "DamageDescription.h"
|
||||||
|
|
||||||
|
namespace nonut
|
||||||
|
{
|
||||||
|
DamageDescription::DamageDescription() :
|
||||||
|
Class("DamageDescription"),
|
||||||
|
|
||||||
|
PROPERTY_CTOR(flags),
|
||||||
|
PROPERTY_CTOR(damage),
|
||||||
|
PROPERTY_CTOR(item_instance),
|
||||||
|
PROPERTY_CTOR(distance),
|
||||||
|
PROPERTY_CTOR(spell_id),
|
||||||
|
PROPERTY_CTOR(spell_level),
|
||||||
|
PROPERTY_CTOR(node)
|
||||||
|
{
|
||||||
|
classCtor();
|
||||||
|
}
|
||||||
|
|
||||||
|
DamageDescription::DamageDescription(SQObject object) :
|
||||||
|
Class("DamageDescription", object),
|
||||||
|
|
||||||
|
PROPERTY_CTOR(flags),
|
||||||
|
PROPERTY_CTOR(damage),
|
||||||
|
PROPERTY_CTOR(item_instance),
|
||||||
|
PROPERTY_CTOR(distance),
|
||||||
|
PROPERTY_CTOR(spell_id),
|
||||||
|
PROPERTY_CTOR(spell_level),
|
||||||
|
PROPERTY_CTOR(node)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
27
src/classes/sq/DamageDescription.h
Normal file
27
src/classes/sq/DamageDescription.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef _DAMAGEDESCRIPTION_H_
|
||||||
|
#define _DAMAGEDESCRIPTION_H_
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <NoNut/core/Class.h>
|
||||||
|
#include <NoNut/core/CustomTypes.h>
|
||||||
|
|
||||||
|
namespace nonut
|
||||||
|
{
|
||||||
|
class DamageDescription : public Class
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DamageDescription();
|
||||||
|
explicit DamageDescription(SQObject object);
|
||||||
|
|
||||||
|
// Properties
|
||||||
|
Property<Int> flags;
|
||||||
|
Property<Int> damage;
|
||||||
|
Property<String> item_instance;
|
||||||
|
Property<Int> distance;
|
||||||
|
Property<Int> spell_id;
|
||||||
|
Property<Int> spell_level;
|
||||||
|
Property<String> node;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef NONUT_G2O_SERVER_CLASS_PACKET
|
#ifndef _PACKET_H_
|
||||||
#define NONUT_G2O_SERVER_CLASS_PACKET
|
#define _PACKET_H_
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <NoNut/core/Class.h>
|
#include <NoNut/core/Class.h>
|
||||||
@@ -13,7 +13,6 @@ namespace nonut
|
|||||||
Packet();
|
Packet();
|
||||||
explicit Packet(SQObject object);
|
explicit Packet(SQObject object);
|
||||||
|
|
||||||
// Methods
|
|
||||||
Function<void> reset;
|
Function<void> reset;
|
||||||
Function<void, Int, Int> send;
|
Function<void, Int, Int> send;
|
||||||
Function<void, Int> sendToAll;
|
Function<void, Int> sendToAll;
|
||||||
@@ -36,10 +35,9 @@ namespace nonut
|
|||||||
Function<Float> readFloat;
|
Function<Float> readFloat;
|
||||||
Function<String> readString;
|
Function<String> readString;
|
||||||
|
|
||||||
// Properties
|
|
||||||
Property<Int> bitsUsed;
|
Property<Int> bitsUsed;
|
||||||
Property<Int> bytesUsed;
|
Property<Int> bytesUsed;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // NONUT_G2O_SERVER_CLASS_PACKET
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ void registerSquirrelEvents()
|
|||||||
addEventHandler("onPlayerChangeWorld", sq_onPlayerChangeWorld, 0);
|
addEventHandler("onPlayerChangeWorld", sq_onPlayerChangeWorld, 0);
|
||||||
|
|
||||||
addEventHandler("onPlayerCommand", sq_onPlayerCommand, 0);
|
addEventHandler("onPlayerCommand", sq_onPlayerCommand, 0);
|
||||||
|
addEventHandler("onPlayerDamage", sq_onPlayerDamage, 0);
|
||||||
addEventHandler("onPlayerDead", sq_onPlayerDead, 0);
|
addEventHandler("onPlayerDead", sq_onPlayerDead, 0);
|
||||||
addEventHandler("onPlayerDisconnect", sq_onPlayerDisconnect, 0);
|
addEventHandler("onPlayerDisconnect", sq_onPlayerDisconnect, 0);
|
||||||
addEventHandler("onPlayerEnterWorld", sq_onPlayerEnterWorld, 0);
|
addEventHandler("onPlayerEnterWorld", sq_onPlayerEnterWorld, 0);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ SQInteger sq_onPlayerChangeMaxMana(HSQUIRRELVM);
|
|||||||
SQInteger sq_onPlayerChangeWeaponMode(HSQUIRRELVM);
|
SQInteger sq_onPlayerChangeWeaponMode(HSQUIRRELVM);
|
||||||
SQInteger sq_onPlayerChangeWorld(HSQUIRRELVM);
|
SQInteger sq_onPlayerChangeWorld(HSQUIRRELVM);
|
||||||
SQInteger sq_onPlayerCommand(HSQUIRRELVM);
|
SQInteger sq_onPlayerCommand(HSQUIRRELVM);
|
||||||
|
SQInteger sq_onPlayerDamage(HSQUIRRELVM);
|
||||||
SQInteger sq_onPlayerDead(HSQUIRRELVM);
|
SQInteger sq_onPlayerDead(HSQUIRRELVM);
|
||||||
SQInteger sq_onPlayerDisconnect(HSQUIRRELVM);
|
SQInteger sq_onPlayerDisconnect(HSQUIRRELVM);
|
||||||
SQInteger sq_onPlayerEnterWorld(HSQUIRRELVM);
|
SQInteger sq_onPlayerEnterWorld(HSQUIRRELVM);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <sqapi.h>
|
#include <sqapi.h>
|
||||||
#include <pybind11/embed.h>
|
#include <pybind11/embed.h>
|
||||||
#include "NoNut/core/Utils.h"
|
#include "NoNut/core/Utils.h"
|
||||||
|
#include <classes/py/DamageDescription.h>
|
||||||
#include "sqevents.h"
|
#include "sqevents.h"
|
||||||
|
|
||||||
namespace py = pybind11;
|
namespace py = pybind11;
|
||||||
@@ -141,6 +142,21 @@ SQInteger sq_onPlayerCommand(HSQUIRRELVM vm)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SQInteger sq_onPlayerDamage(HSQUIRRELVM vm)
|
||||||
|
{
|
||||||
|
SQInteger playerid, killerid;
|
||||||
|
HSQOBJECT sqobj;
|
||||||
|
|
||||||
|
nonut::sqGetValue(vm, 2, &playerid);
|
||||||
|
nonut::sqGetValue(vm, 3, &killerid);
|
||||||
|
nonut::sqGetValue(vm, 4, &sqobj);
|
||||||
|
|
||||||
|
py::dict kwargs = py::dict("playerid"_a=playerid, "killerid"_a=killerid, "description"_a=PyDamageDescription(sqobj));
|
||||||
|
callEvent("onPlayerDamage", kwargs);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
SQInteger sq_onPlayerDead(HSQUIRRELVM vm)
|
SQInteger sq_onPlayerDead(HSQUIRRELVM vm)
|
||||||
{
|
{
|
||||||
SQInteger playerid, killerid;
|
SQInteger playerid, killerid;
|
||||||
|
|||||||
Reference in New Issue
Block a user