Skip to content

Commit

Permalink
Added support to orangeSkull and the current frag system (brunominerv…
Browse files Browse the repository at this point in the history
…ino)

Added UnjustPanel Kills (brunominervino)
  • Loading branch information
mattyx14 committed Nov 29, 2016
1 parent 2da65e5 commit 43fb8ee
Show file tree
Hide file tree
Showing 13 changed files with 247 additions and 35 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
configHelp - How use all configFunctions from TFS / OTX "WIP"
- Added support for 8.54/58
- Added POSIX signal handling (djarek)
- Added UnjustPanel Kills (brunominervino)
- Added support to orangeSkull (brunominervino)
- Added support to current frag system (brunominervino)
- Fileloader refactor (djarek)
- Fix connectionLock on old protocols
- Fix potions onTarget
Expand Down
6 changes: 6 additions & 0 deletions path_10_9/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ whiteSkullTime = 15 * 60 * 1000
stairJumpExhaustion = 2 * 1000
experienceByKillingPlayers = false
expFromPlayersLevelRange = 75
dayKillsToRedSkull = 3
weekKillsToRedSkull = 5
monthKillsToRedSkull = 10
redSkullDuration = 30
blackSkullDuration = 45
orangeSkullDuration = 7

This comment has been minimized.

Copy link
@kito2

kito2 Nov 30, 2016

I have a question. This would mean to delete killsToRedSkull = 9 killsToBlackSkull = 15?

This comment has been minimized.

Copy link
@darkjav

darkjav Dec 5, 2016

@mattyx14 @kito2

The duration is in days or hours?

This comment has been minimized.

Copy link
@kito2

kito2 Dec 6, 2016

The duration is in days. Already tested them. @darkjav


-- Connection Config
-- NOTE: maxPlayers set to 0 means no limit
Expand Down
4 changes: 3 additions & 1 deletion path_10_9/data/migrations/24.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
function onUpdateDatabase()
return false
print("> Updating database to version 24 (Unjust Panel Kills)")
db.query("CREATE TABLE IF NOT EXISTS `player_kills` (`player_id` INT(11) NOT NULL , `time` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0' , `target` INT(11) NOT NULL , `unavenged` BOOLEAN NOT NULL DEFAULT FALSE, FOREIGN KEY (`player_id`) REFERENCES `players`(`id`) ON DELETE CASCADE ) ENGINE = InnoDB;")
return true
end
3 changes: 3 additions & 0 deletions path_10_9/data/migrations/25.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function onUpdateDatabase()
return false
end
6 changes: 6 additions & 0 deletions path_10_9/src/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ bool ConfigManager::load()
integer[MAX_PACKETS_PER_SECOND] = getGlobalNumber(L, "maxPacketsPerSecond", 25);
integer[STORE_COIN_PACKET] = getGlobalNumber(L, "coinPacketSize", 25);
integer[LIVE_CAST_PORT] = getGlobalNumber(L, "liveCastPort", 7173);
integer[DAY_KILLS_TO_RED] = getGlobalNumber(L, "dayKillsToRedSkull", 3);
integer[WEEK_KILLS_TO_RED] = getGlobalNumber(L, "weekKillsToRedSkull", 5);
integer[MONTH_KILLS_TO_RED] = getGlobalNumber(L, "monthKillsToRedSkull", 10);
integer[RED_SKULL_DURATION] = getGlobalNumber(L, "redSkullDuration", 30);
integer[BLACK_SKULL_DURATION] = getGlobalNumber(L, "blackSkullDuration", 45);
integer[ORANGE_SKULL_DURATION] = getGlobalNumber(L, "orangeSkullDuration", 7);

loaded = true;
lua_close(L);
Expand Down
6 changes: 6 additions & 0 deletions path_10_9/src/configmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ class ConfigManager
FREE_DEPOT_LIMIT,
PREMIUM_DEPOT_LIMIT,
DEPOT_BOXES,
DAY_KILLS_TO_RED,
WEEK_KILLS_TO_RED,
MONTH_KILLS_TO_RED,
RED_SKULL_DURATION,
BLACK_SKULL_DURATION,
ORANGE_SKULL_DURATION,

LAST_INTEGER_CONFIG /* this must be the last one */
};
Expand Down
32 changes: 32 additions & 0 deletions path_10_9/src/iologindata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,17 @@ bool IOLoginData::loadPlayer(Player* player, DBResult_ptr result)
//load inventory items
ItemMap itemMap;

query.str(std::string());
query << "SELECT `player_id`, `time`, `target`, `unavenged` FROM `player_kills` WHERE `player_id` = " << player->getGUID();
if ((result = db->storeQuery(query.str()))) {
do {
time_t killTime = result->getNumber<time_t>("time");
if ((time(nullptr) - killTime) <= 45 * 24 * 60 * 60) {
player->unjustifiedKills.emplace_back(result->getNumber<uint32_t>("target"), killTime, result->getNumber<bool>("unavenged"));
}
} while (result->next());
}

query.str(std::string());
query << "SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_items` WHERE `player_id` = " << player->getGUID() << " ORDER BY `sid` DESC";
if ((result = db->storeQuery(query.str()))) {
Expand Down Expand Up @@ -839,6 +850,27 @@ bool IOLoginData::savePlayer(Player* player)
return false;
}

//player kills
query.str(std::string());
query << "DELETE FROM `player_kills` WHERE `player_id` = " << player->getGUID();
if (!db->executeQuery(query.str())) {
return false;
}

query.str(std::string());

DBInsert killsQuery("INSERT INTO `player_kills` (`player_id`, `target`, `time`, `unavenged`) VALUES");
for (const auto& kill : player->unjustifiedKills) {
query << player->getGUID() << ',' << kill.target << ',' << kill.time << ',' << kill.unavenged;
if (!killsQuery.addRow(query)) {
return false;
}
}

if (!killsQuery.execute()) {
return false;
}

//item saving
query << "DELETE FROM `player_items` WHERE `player_id` = " << player->getGUID();
if (!db->executeQuery(query.str())) {
Expand Down
63 changes: 63 additions & 0 deletions path_10_9/src/luascript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,12 @@ void LuaScriptInterface::registerFunctions()
registerEnumIn("configKeys", ConfigManager::LIVE_CAST_PORT)
registerEnumIn("configKeys", ConfigManager::VERSION_MIN)
registerEnumIn("configKeys", ConfigManager::VERSION_MAX)
registerEnumIn("configKeys", ConfigManager::DAY_KILLS_TO_RED)
registerEnumIn("configKeys", ConfigManager::WEEK_KILLS_TO_RED)
registerEnumIn("configKeys", ConfigManager::MONTH_KILLS_TO_RED)
registerEnumIn("configKeys", ConfigManager::RED_SKULL_DURATION)
registerEnumIn("configKeys", ConfigManager::BLACK_SKULL_DURATION)
registerEnumIn("configKeys", ConfigManager::ORANGE_SKULL_DURATION)

// os
registerMethod("os", "mtime", LuaScriptInterface::luaSystemTime);
Expand Down Expand Up @@ -2163,6 +2169,9 @@ void LuaScriptInterface::registerFunctions()

registerMethod("Player", "getFreeCapacity", LuaScriptInterface::luaPlayerGetFreeCapacity);

registerMethod("Player", "getKills", LuaScriptInterface::luaPlayerGetKills);
registerMethod("Player", "setKills", LuaScriptInterface::luaPlayerSetKills);

registerMethod("Player", "getReward", LuaScriptInterface::luaPlayerGetReward);
registerMethod("Player", "removeReward", LuaScriptInterface::luaPlayerRemoveReward);
registerMethod("Player", "getRewardList", LuaScriptInterface::luaPlayerGetRewardList);
Expand Down Expand Up @@ -7857,6 +7866,60 @@ int LuaScriptInterface::luaPlayerGetFreeCapacity(lua_State* L)
return 1;
}

int LuaScriptInterface::luaPlayerGetKills(lua_State* L)
{
// player:getKills()
Player* player = getUserdata<Player>(L, 1);
if (!player) {
lua_pushnil(L);
return 1;
}

lua_createtable(L, player->unjustifiedKills.size(), 0);
int idx = 0;
for (const auto& kill : player->unjustifiedKills) {
lua_createtable(L, 3, 0);
lua_pushnumber(L, kill.target);
lua_rawseti(L, -2, 1);
lua_pushnumber(L, kill.time);
lua_rawseti(L, -2, 2);
pushBoolean(L, kill.unavenged);
lua_rawseti(L, -2, 3);
lua_rawseti(L, -2, ++idx);
}

return 1;
}

int LuaScriptInterface::luaPlayerSetKills(lua_State* L)
{
// player:setKills(kills)
Player* player = getUserdata<Player>(L, 1);
if (!player) {
lua_pushnil(L);
return 1;
}

luaL_checktype(L, 2, LUA_TTABLE);
std::vector<Kill> newKills;

lua_pushnil(L);
while (lua_next(L, 2) != 0) {
// -2 is index, -1 is value
luaL_checktype(L, -1, LUA_TTABLE);
lua_rawgeti(L, -1, 1); // push target
lua_rawgeti(L, -2, 2); // push time
lua_rawgeti(L, -3, 3); // push unavenged
newKills.emplace_back(luaL_checknumber(L, -3), luaL_checknumber(L, -2), getBoolean(L, -1));
lua_pop(L, 4);
}

player->unjustifiedKills = std::move(newKills);
player->sendUnjustifiedPoints();
pushBoolean(L, true);
return 1;
}

int LuaScriptInterface::luaPlayerGetReward(lua_State* L)
{
// player:getReward(rewardId[, autoCreate = false])
Expand Down
3 changes: 3 additions & 0 deletions path_10_9/src/luascript.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,9 @@ class LuaScriptInterface
static int luaPlayerGetCapacity(lua_State* L);
static int luaPlayerSetCapacity(lua_State* L);

static int luaPlayerGetKills(lua_State* L);
static int luaPlayerSetKills(lua_State* L);

static int luaPlayerGetFreeCapacity(lua_State* L);

static int luaPlayerGetReward(lua_State* L);
Expand Down
110 changes: 99 additions & 11 deletions path_10_9/src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3548,7 +3548,7 @@ void Player::onAttackedCreature(Creature* target)
if (!Combat::isInPvpZone(this, targetPlayer) && !isInWar(targetPlayer)) {
addAttacked(targetPlayer);

if (targetPlayer->getSkull() == SKULL_NONE && getSkull() == SKULL_NONE) {
if (targetPlayer->getSkull() == SKULL_NONE && getSkull() == SKULL_NONE && !targetPlayer->hasKilled(this)) {
setSkull(SKULL_WHITE);
}

Expand Down Expand Up @@ -3584,6 +3584,8 @@ void Player::onPlacedCreature()
if (!g_creatureEvents->playerLogin(this)) {
kickPlayer(true);
}

sendUnjustifiedPoints();
}

void Player::onAttackedCreatureDrainHealth(Creature* target, int32_t points)
Expand Down Expand Up @@ -3636,7 +3638,16 @@ bool Player::onKilledCreature(Creature* target, bool lastHit/* = true*/)
targetPlayer->setLossSkill(false);
} else if (!hasFlag(PlayerFlag_NotGainInFight) && !isPartner(targetPlayer)) {
if (!Combat::isInPvpZone(this, targetPlayer) && hasAttacked(targetPlayer) && !targetPlayer->hasAttacked(this) && !isGuildMate(targetPlayer) && targetPlayer != this) {
if (targetPlayer->getSkull() == SKULL_NONE && !isInWar(targetPlayer)) {
if (targetPlayer->hasKilled(this)) {
for (auto& kill : targetPlayer->unjustifiedKills) {
if (kill.target == getGUID() && kill.unavenged) {
kill.unavenged = false;
auto it = attackedSet.find(targetPlayer->guid);
attackedSet.erase(it);
break;
}
}
} else if (targetPlayer->getSkull() == SKULL_NONE && !isInWar(targetPlayer)) {
unjustified = true;
addUnjustifiedDead(targetPlayer);
}
Expand Down Expand Up @@ -3881,6 +3892,14 @@ Skulls_t Player::getSkullClient(const Creature* creature) const

const Player* player = creature->getPlayer();
if (player && player->getSkull() == SKULL_NONE) {
if (player == this) {
for (const auto& kill : unjustifiedKills) {
if (kill.unavenged && (time(nullptr) - kill.time) < g_config.getNumber(ConfigManager::ORANGE_SKULL_DURATION) * 24 * 60 * 60) {
return SKULL_ORANGE;
}
}
}

if (isInWar(player)) {
return SKULL_GREEN;
}
Expand All @@ -3889,6 +3908,10 @@ Skulls_t Player::getSkullClient(const Creature* creature) const
return SKULL_GREEN;
}

if (player->hasKilled(this)) {
return SKULL_ORANGE;
}

if (player->hasAttacked(this)) {
return SKULL_YELLOW;
}
Expand All @@ -3900,6 +3923,17 @@ Skulls_t Player::getSkullClient(const Creature* creature) const
return Creature::getSkullClient(creature);
}

bool Player::hasKilled(const Player* player) const
{
for (const auto& kill : unjustifiedKills) {
if (kill.target == player->getGUID() && (time(nullptr) - kill.time) < g_config.getNumber(ConfigManager::ORANGE_SKULL_DURATION) * 24 * 60 * 60 && kill.unavenged) {
return true;
}
}

return false;
}

bool Player::hasAttacked(const Player* attacked) const
{
if (hasFlag(PlayerFlag_NotGainInFight) || !attacked) {
Expand Down Expand Up @@ -3931,26 +3965,43 @@ void Player::addUnjustifiedDead(const Player* attacked)

sendTextMessage(MESSAGE_EVENT_ADVANCE, "Warning! The murder of " + attacked->getName() + " was not justified.");

skullTicks += g_config.getNumber(ConfigManager::FRAG_TIME);
unjustifiedKills.emplace_back(attacked->getGUID(), time(nullptr), true);

uint8_t dayKills = 0;
uint8_t weekKills = 0;
uint8_t monthKills = 0;

for (const auto& kill : unjustifiedKills) {
const auto diff = time(nullptr) - kill.time;
if (diff <= 24 * 60 * 60) {
dayKills += 1;
}
if (diff <= 7 * 24 * 60 * 60) {
weekKills += 1;
}
if (diff <= 30 * 24 * 60 * 60) {
monthKills += 1;
}
}

if (getSkull() != SKULL_BLACK) {
if (g_config.getNumber(ConfigManager::KILLS_TO_BLACK) != 0 && skullTicks > (g_config.getNumber(ConfigManager::KILLS_TO_BLACK) - 1) * static_cast<int64_t>(g_config.getNumber(ConfigManager::FRAG_TIME))) {
if (dayKills >= 2 * g_config.getNumber(ConfigManager::DAY_KILLS_TO_RED) || weekKills >= 2 * g_config.getNumber(ConfigManager::WEEK_KILLS_TO_RED) || monthKills >= 2 * g_config.getNumber(ConfigManager::MONTH_KILLS_TO_RED)) {
setSkull(SKULL_BLACK);
} else if (getSkull() != SKULL_RED && g_config.getNumber(ConfigManager::KILLS_TO_RED) != 0 && skullTicks > (g_config.getNumber(ConfigManager::KILLS_TO_RED) - 1) * static_cast<int64_t>(g_config.getNumber(ConfigManager::FRAG_TIME))) {
//start black skull time
skullTicks = static_cast<int64_t>(g_config.getNumber(ConfigManager::BLACK_SKULL_DURATION)) * 24 * 60 * 60 * 1000;
} else if (dayKills >= g_config.getNumber(ConfigManager::DAY_KILLS_TO_RED) || weekKills >= g_config.getNumber(ConfigManager::WEEK_KILLS_TO_RED) || monthKills >= g_config.getNumber(ConfigManager::MONTH_KILLS_TO_RED)) {
setSkull(SKULL_RED);
//reset red skull time
skullTicks = static_cast<int64_t>(g_config.getNumber(ConfigManager::RED_SKULL_DURATION)) * 24 * 60 * 60 * 1000;
}
}

if (!client) {
return;
}

client->sendSkullTime();
sendUnjustifiedPoints();
}

void Player::checkSkullTicks(int32_t ticks)
{
int32_t newTicks = skullTicks - ticks;
int64_t newTicks = skullTicks - ticks;
if (newTicks < 0) {
skullTicks = 0;
} else {
Expand Down Expand Up @@ -4196,6 +4247,43 @@ GuildEmblems_t Player::getGuildEmblem(const Player* player) const
return GUILDEMBLEM_NEUTRAL;
}

void Player::sendUnjustifiedPoints()
{
if (client) {
double dayKills = 0;
double weekKills = 0;
double monthKills = 0;

for (const auto& kill : unjustifiedKills) {
const auto diff = time(nullptr) - kill.time;
if (diff <= 24 * 60 * 60) {
dayKills += 1;
}
if (diff <= 7 * 24 * 60 * 60) {
weekKills += 1;
}
if (diff <= 30 * 24 * 60 * 60) {
monthKills += 1;
}
}

bool isRed = getSkull() == SKULL_RED;

auto dayMax = ((isRed ? 2 : 1) * g_config.getNumber(ConfigManager::DAY_KILLS_TO_RED));
auto weekMax = ((isRed ? 2 : 1) * g_config.getNumber(ConfigManager::WEEK_KILLS_TO_RED));
auto monthMax = ((isRed ? 2 : 1) * g_config.getNumber(ConfigManager::MONTH_KILLS_TO_RED));

uint8_t dayProgress = std::min(std::round(dayKills / dayMax * 100), 100.0);
uint8_t weekProgress = std::min(std::round(weekKills / weekMax * 100), 100.0);
uint8_t monthProgress = std::min(std::round(monthKills / monthMax * 100), 100.0);
uint8_t skullDuration = 0;
if (skullTicks != 0) {
skullDuration = std::floor<uint8_t>(skullTicks / (24 * 60 * 60 * 1000));
}
client->sendUnjustifiedPoints(dayProgress, std::max(dayMax - dayKills, 0.0), weekProgress, std::max(weekMax - weekKills, 0.0), monthProgress, std::max(monthMax - monthKills, 0.0), skullDuration);
}
}

uint8_t Player::getCurrentMount() const
{
int32_t value;
Expand Down

0 comments on commit 43fb8ee

Please sign in to comment.