Skip to content

Instantly share code, notes, and snippets.

@invokr
Created August 24, 2015 17:57
Show Gist options
  • Save invokr/73b9f7e68ab318d46550 to your computer and use it in GitHub Desktop.
Save invokr/73b9f7e68ab318d46550 to your computer and use it in GitHub Desktop.
#ifndef _HANDLER_COMBATLOG_HPP_
#define _HANDLER_COMBATLOG_HPP_
#include <sstream>
#include <alice/handler.hpp>
#include <alice/dota_gcmessages_common.pb.h>
#include <alice/netmessages.pb.h>
#include <alice/networkbasetypes.pb.h>
#include "handler.hpp"
using namespace dota;
/**
Name: type Type: 5
Name: sourcename Type: 4
Name: targetname Type: 4
Name: attackername Type: 4
Name: inflictorname Type: 4
Name: attackerillusion Type: 6
Name: targetillusion Type: 6
Name: value Type: 4
Name: health Type: 4
Name: timestamp Type: 2
Name: targetsourcename Type: 4
Name: timestampraw Type: 2
Name: attackerhero Type: 6
Name: targethero Type: 6
Name: ability_toggle_on Type: 6
Name: ability_toggle_off Type: 6
Name: ability_level Type: 4
Name: gold_reason Type: 4
Name: xp_reason Type: 4
*/
/** Contains a single combatlog entry */
struct combatlog_entry {
/** Type of the combat log entry, e.g. damage */
uint8_t type;
/** ID of the owner of the entity performing the action */
int32_t sourcename;
/** ID of the target*/
int32_t targetname;
/** ID of the attacker */
int32_t attackername;
/** ID of the buf / debug inflicted*/
int32_t inflictorname;
/** is attacker an illusion */
bool attackerillusion;
/** is target an illusion */
bool targetillusion;
/** hp lost / gained*/
int32_t value;
/** hp after the action was made*/
int32_t health;
/** time this occured */
float timestamp;
/** owner id of the target entity*/
int32_t targetsourcename;
/** raw timestamp? */
float timestampraw;
/** is hero attacking */
bool hero_damage;
/** is hero targeted */
bool hero_damaged;
/** ability toggled on */
bool ability_t_on;
/** ability toggled off */
bool ability_t_off;
/** ability level */
int32_t ability_level;
/** gold reason ? */
int32_t gold_reason;
/** xp reason ? */
int32_t xp_reason;
};
/** This handler keeps track of all combatlog entries. */
class handler_combatlog : public t_handler {
public:
/** Constructor, takes the handler */
handler_combatlog(parser* p) : p(p), h(p->getHandler()), cmb_event(0) {
handlerRegisterCallback(h, msgNet, svc_GameEvent, handler_combatlog, handleEvent);
}
/** Gets called once all flattables have been parsed */
void handleEvent(handlerCbType(msgNet) msg) {
CSVCMsg_GameEvent* event = msg->get<CSVCMsg_GameEvent>();
// make sure to only handle combat log events
if (cmb_event == 0) {
if (p->getEventDescriptor(event->eventid())->name == "dota_combatlog") {
cmb_event = event->eventid();
} else {
return;
}
} else if (cmb_event != event->eventid()) {
return;
}
cmb_entries.push_back({
static_cast<uint8_t>(event->keys(0).val_byte()), // type, 5 (byte)
event->keys(1).val_short(), // sourcename, 4 (short)
event->keys(2).val_short(), // targetname, 4 (short)
event->keys(3).val_short(), // attackername, 4 (short)
event->keys(4).val_short(), // inflictorname, 4 (short)
event->keys(5).val_bool(), // attackerillusion, 6 (bool)
event->keys(6).val_bool(), // targetillusion, 6 (bool)
event->keys(7).val_short(), // value, 4 (short)
event->keys(8).val_short(), // health, 4 (short)
event->keys(9).val_float(), // timestamp, 2 (float)
event->keys(10).val_short(), // targetsource name, 4 (short)
event->keys(11).val_float(), // timestampraw, 2 (float)
event->keys(12).val_bool(), // herodamage, 6 (bool)
event->keys(13).val_bool(), // herodamaged, 6 (bool)
event->keys(14).val_bool(), // ability_t_on, 6 (bool)
event->keys(15).val_bool(), // ability_t_off, 6 (bool)
event->keys(16).val_short(), // ability_level, 4 (short)
event->keys(17).val_short(), // gold reason, 4 (short)
event->keys(18).val_short() // xp reason, 4 (short)
});
}
/** Returns handler name */
std::string getName() {
return "combatlog";
}
private:
/** Pointer to the parser */
parser* p;
/** Pointer to the handler */
handler_t* h;
/** The combatlog event id */
int32_t cmb_event;
/** List of all combatlog entries */
std::vector<combatlog_entry> cmb_entries;
};
#endif /* _HANDLER_COMBATLOG_HPP_ */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment