2021-03-13 22:55:16 +00:00
|
|
|
#include "Combat.hpp"
|
2020-08-27 20:16:52 +00:00
|
|
|
#include "PlayerManager.hpp"
|
2020-10-02 21:03:11 +00:00
|
|
|
#include "NanoManager.hpp"
|
2020-08-27 20:16:52 +00:00
|
|
|
#include "NPCManager.hpp"
|
2020-08-28 16:25:03 +00:00
|
|
|
#include "ItemManager.hpp"
|
2020-09-10 16:40:38 +00:00
|
|
|
#include "MissionManager.hpp"
|
2020-10-04 23:54:08 +00:00
|
|
|
#include "GroupManager.hpp"
|
2020-10-12 19:03:18 +00:00
|
|
|
#include "TransportManager.hpp"
|
2020-12-28 15:41:29 +00:00
|
|
|
#include "RacingManager.hpp"
|
2021-03-13 20:22:29 +00:00
|
|
|
#include "Abilities.hpp"
|
2020-08-27 20:16:52 +00:00
|
|
|
|
2020-08-28 16:25:03 +00:00
|
|
|
#include <assert.h>
|
2020-08-27 20:16:52 +00:00
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
std::map<int32_t, MobDropChance> Combat::MobDropChances;
|
|
|
|
std::map<int32_t, MobDrop> Combat::MobDrops;
|
2020-11-12 00:46:53 +00:00
|
|
|
/// Player Id -> Bullet Id -> Bullet
|
2021-03-13 22:55:16 +00:00
|
|
|
std::map<int32_t, std::map<int8_t, Bullet>> Combat::Bullets;
|
2020-10-07 18:38:32 +00:00
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
void Combat::init() {
|
2020-09-26 22:16:15 +00:00
|
|
|
REGISTER_SHARD_TIMER(playerTick, 2000);
|
2020-09-22 19:31:08 +00:00
|
|
|
|
2020-08-27 20:16:52 +00:00
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_ATTACK_NPCs, pcAttackNpcs);
|
|
|
|
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_COMBAT_BEGIN, combatBegin);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_COMBAT_END, combatEnd);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_DOT_DAMAGE_ONOFF, dotDamageOnOff);
|
2020-09-22 15:30:49 +00:00
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_ATTACK_CHARs, pcAttackChars);
|
2020-10-07 18:38:32 +00:00
|
|
|
|
2020-11-12 00:46:53 +00:00
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_GRENADE_STYLE_FIRE, grenadeFire);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_ROCKET_STYLE_FIRE, rocketFire);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_ROCKET_STYLE_HIT, projectileHit);
|
2020-08-27 20:16:52 +00:00
|
|
|
}
|
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
void Combat::pcAttackNpcs(CNSocket *sock, CNPacketData *data) {
|
2020-08-27 20:16:52 +00:00
|
|
|
sP_CL2FE_REQ_PC_ATTACK_NPCs* pkt = (sP_CL2FE_REQ_PC_ATTACK_NPCs*)data->buf;
|
2020-08-28 20:01:49 +00:00
|
|
|
Player *plr = PlayerManager::getPlayer(sock);
|
2020-08-27 20:16:52 +00:00
|
|
|
|
2020-08-28 14:09:26 +00:00
|
|
|
// sanity check
|
|
|
|
if (!validInVarPacket(sizeof(sP_CL2FE_REQ_PC_ATTACK_NPCs), pkt->iNPCCnt, sizeof(int32_t), data->size)) {
|
|
|
|
std::cout << "[WARN] bad sP_CL2FE_REQ_PC_ATTACK_NPCs packet size\n";
|
2020-08-27 20:16:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-08-28 14:09:26 +00:00
|
|
|
|
2020-08-27 20:16:52 +00:00
|
|
|
int32_t *pktdata = (int32_t*)((uint8_t*)data->buf + sizeof(sP_CL2FE_REQ_PC_ATTACK_NPCs));
|
|
|
|
|
2020-12-31 05:54:57 +00:00
|
|
|
// rapid fire anti-cheat
|
|
|
|
time_t currTime = getTime();
|
|
|
|
if (currTime - plr->lastShot < plr->fireRate * 80)
|
|
|
|
plr->suspicionRating += plr->fireRate * 100 + plr->lastShot - currTime; // gain suspicion for rapid firing
|
|
|
|
else if (currTime - plr->lastShot < plr->fireRate * 180 && plr->suspicionRating > 0)
|
|
|
|
plr->suspicionRating += plr->fireRate * 100 + plr->lastShot - currTime; // lose suspicion for delayed firing
|
|
|
|
|
|
|
|
plr->lastShot = currTime;
|
|
|
|
|
|
|
|
if (pkt->iNPCCnt > 3) // 3+ targets should never be possible
|
|
|
|
plr->suspicionRating += 10000;
|
|
|
|
|
|
|
|
if (plr->suspicionRating > 10000) // kill the socket when the player is too suspicious
|
|
|
|
sock->kill();
|
|
|
|
|
2021-03-04 18:48:02 +00:00
|
|
|
/*
|
|
|
|
* Due to the possibility of multiplication overflow (and regular buffer overflow),
|
|
|
|
* both incoming and outgoing variable-length packets must be validated, at least if
|
|
|
|
* the number of trailing structs isn't well known (ie. it's from the client).
|
|
|
|
*/
|
|
|
|
if (!validOutVarPacket(sizeof(sP_FE2CL_PC_ATTACK_NPCs_SUCC), pkt->iNPCCnt, sizeof(sAttackResult))) {
|
|
|
|
std::cout << "[WARN] bad sP_FE2CL_PC_ATTACK_NPCs_SUCC packet size\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-27 20:16:52 +00:00
|
|
|
// initialize response struct
|
|
|
|
size_t resplen = sizeof(sP_FE2CL_PC_ATTACK_NPCs_SUCC) + pkt->iNPCCnt * sizeof(sAttackResult);
|
2020-09-09 19:08:31 +00:00
|
|
|
uint8_t respbuf[CN_PACKET_BUFFER_SIZE];
|
2020-08-28 14:09:26 +00:00
|
|
|
|
2020-08-27 20:16:52 +00:00
|
|
|
memset(respbuf, 0, resplen);
|
2020-08-28 14:09:26 +00:00
|
|
|
|
2020-08-27 20:16:52 +00:00
|
|
|
sP_FE2CL_PC_ATTACK_NPCs_SUCC *resp = (sP_FE2CL_PC_ATTACK_NPCs_SUCC*)respbuf;
|
|
|
|
sAttackResult *respdata = (sAttackResult*)(respbuf+sizeof(sP_FE2CL_PC_ATTACK_NPCs_SUCC));
|
|
|
|
|
|
|
|
resp->iNPCCnt = pkt->iNPCCnt;
|
|
|
|
|
|
|
|
for (int i = 0; i < pkt->iNPCCnt; i++) {
|
2021-03-13 22:55:16 +00:00
|
|
|
if (MobAI::Mobs.find(pktdata[i]) == MobAI::Mobs.end()) {
|
2020-08-27 20:16:52 +00:00
|
|
|
// not sure how to best handle this
|
|
|
|
std::cout << "[WARN] pcAttackNpcs: mob ID not found" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2021-03-13 22:55:16 +00:00
|
|
|
Mob *mob = MobAI::Mobs[pktdata[i]];
|
2020-08-27 20:16:52 +00:00
|
|
|
|
2020-09-27 01:53:03 +00:00
|
|
|
std::pair<int,int> damage;
|
|
|
|
|
|
|
|
if (pkt->iNPCCnt > 1)
|
2020-10-09 00:01:35 +00:00
|
|
|
damage.first = plr->groupDamage;
|
2020-09-27 01:53:03 +00:00
|
|
|
else
|
2020-10-09 00:01:35 +00:00
|
|
|
damage.first = plr->pointDamage;
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-09 00:01:35 +00:00
|
|
|
int difficulty = (int)mob->data["m_iNpcLevel"];
|
2020-10-21 05:24:51 +00:00
|
|
|
damage = getDamage(damage.first, (int)mob->data["m_iProtection"], true, (plr->batteryW > 6 + difficulty), NanoManager::nanoStyle(plr->activeNano), (int)mob->data["m_iNpcStyle"], difficulty);
|
|
|
|
|
|
|
|
if (plr->batteryW >= 6 + difficulty)
|
|
|
|
plr->batteryW -= 6 + difficulty;
|
|
|
|
else
|
|
|
|
plr->batteryW = 0;
|
2020-09-27 01:53:03 +00:00
|
|
|
|
|
|
|
damage.first = hitMob(sock, mob, damage.first);
|
2020-09-16 23:43:48 +00:00
|
|
|
|
|
|
|
respdata[i].iID = mob->appearanceData.iNPC_ID;
|
2020-09-27 01:53:03 +00:00
|
|
|
respdata[i].iDamage = damage.first;
|
2020-09-16 23:43:48 +00:00
|
|
|
respdata[i].iHP = mob->appearanceData.iHP;
|
2020-09-27 01:53:03 +00:00
|
|
|
respdata[i].iHitFlag = damage.second; // hitscan, not a rocket or a grenade
|
2020-08-27 20:16:52 +00:00
|
|
|
}
|
|
|
|
|
2020-09-27 06:58:33 +00:00
|
|
|
resp->iBatteryW = plr->batteryW;
|
2020-08-27 20:16:52 +00:00
|
|
|
sock->sendPacket((void*)respbuf, P_FE2CL_PC_ATTACK_NPCs_SUCC, resplen);
|
2020-08-28 20:01:49 +00:00
|
|
|
|
2020-09-09 19:08:31 +00:00
|
|
|
// a bit of a hack: these are the same size, so we can reuse the response packet
|
2020-08-28 20:01:49 +00:00
|
|
|
assert(sizeof(sP_FE2CL_PC_ATTACK_NPCs_SUCC) == sizeof(sP_FE2CL_PC_ATTACK_NPCs));
|
|
|
|
sP_FE2CL_PC_ATTACK_NPCs *resp1 = (sP_FE2CL_PC_ATTACK_NPCs*)respbuf;
|
|
|
|
|
|
|
|
resp1->iPC_ID = plr->iID;
|
|
|
|
|
|
|
|
// send to other players
|
2020-09-17 22:45:43 +00:00
|
|
|
PlayerManager::sendToViewable(sock, (void*)respbuf, P_FE2CL_PC_ATTACK_NPCs, resplen);
|
2020-08-27 20:16:52 +00:00
|
|
|
}
|
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
void Combat::npcAttackPc(Mob *mob, time_t currTime) {
|
2020-09-24 01:18:41 +00:00
|
|
|
Player *plr = PlayerManager::getPlayer(mob->target);
|
|
|
|
|
|
|
|
const size_t resplen = sizeof(sP_FE2CL_PC_ATTACK_NPCs_SUCC) + sizeof(sAttackResult);
|
|
|
|
assert(resplen < CN_PACKET_BUFFER_SIZE - 8);
|
|
|
|
uint8_t respbuf[CN_PACKET_BUFFER_SIZE];
|
|
|
|
memset(respbuf, 0, resplen);
|
|
|
|
|
|
|
|
sP_FE2CL_NPC_ATTACK_PCs *pkt = (sP_FE2CL_NPC_ATTACK_PCs*)respbuf;
|
|
|
|
sAttackResult *atk = (sAttackResult*)(respbuf + sizeof(sP_FE2CL_NPC_ATTACK_PCs));
|
|
|
|
|
2020-11-16 03:13:40 +00:00
|
|
|
auto damage = getDamage(450 + (int)mob->data["m_iPower"], plr->defense, false, false, -1, -1, 0);
|
2020-12-01 20:34:14 +00:00
|
|
|
|
|
|
|
if (!(plr->iSpecialState & CN_SPECIAL_STATE_FLAG__INVULNERABLE))
|
|
|
|
plr->HP -= damage.first;
|
2020-09-24 01:18:41 +00:00
|
|
|
|
|
|
|
pkt->iNPC_ID = mob->appearanceData.iNPC_ID;
|
|
|
|
pkt->iPCCnt = 1;
|
|
|
|
|
|
|
|
atk->iID = plr->iID;
|
2020-09-27 01:53:03 +00:00
|
|
|
atk->iDamage = damage.first;
|
2020-09-24 01:18:41 +00:00
|
|
|
atk->iHP = plr->HP;
|
2020-09-27 01:53:03 +00:00
|
|
|
atk->iHitFlag = damage.second;
|
2020-09-24 01:18:41 +00:00
|
|
|
|
|
|
|
mob->target->sendPacket((void*)respbuf, P_FE2CL_NPC_ATTACK_PCs, resplen);
|
2020-09-26 22:16:15 +00:00
|
|
|
PlayerManager::sendToViewable(mob->target, (void*)respbuf, P_FE2CL_NPC_ATTACK_PCs, resplen);
|
2020-09-24 01:18:41 +00:00
|
|
|
|
|
|
|
if (plr->HP <= 0) {
|
|
|
|
mob->target = nullptr;
|
|
|
|
mob->state = MobState::RETREAT;
|
2021-03-13 22:55:16 +00:00
|
|
|
if (!MobAI::aggroCheck(mob, currTime)) {
|
|
|
|
MobAI::clearDebuff(mob);
|
2020-12-30 22:07:10 +00:00
|
|
|
if (mob->groupLeader != 0)
|
2021-03-13 22:55:16 +00:00
|
|
|
MobAI::groupRetreat(mob);
|
2020-12-30 22:07:10 +00:00
|
|
|
}
|
2020-09-24 01:18:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
void Combat::giveReward(CNSocket *sock, Mob* mob, int rolledBoosts, int rolledPotions,
|
2020-12-31 02:30:43 +00:00
|
|
|
int rolledCrate, int rolledCrateType, int rolledEvent) {
|
2020-08-27 20:16:52 +00:00
|
|
|
Player *plr = PlayerManager::getPlayer(sock);
|
|
|
|
|
2020-08-28 16:25:03 +00:00
|
|
|
const size_t resplen = sizeof(sP_FE2CL_REP_REWARD_ITEM) + sizeof(sItemReward);
|
2020-09-08 01:01:47 +00:00
|
|
|
assert(resplen < CN_PACKET_BUFFER_SIZE - 8);
|
2020-08-28 16:25:03 +00:00
|
|
|
// we know it's only one trailing struct, so we can skip full validation
|
|
|
|
|
|
|
|
uint8_t respbuf[resplen]; // not a variable length array, don't worry
|
|
|
|
sP_FE2CL_REP_REWARD_ITEM *reward = (sP_FE2CL_REP_REWARD_ITEM *)respbuf;
|
|
|
|
sItemReward *item = (sItemReward *)(respbuf + sizeof(sP_FE2CL_REP_REWARD_ITEM));
|
|
|
|
|
|
|
|
// don't forget to zero the buffer!
|
|
|
|
memset(respbuf, 0, resplen);
|
|
|
|
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
// sanity check
|
|
|
|
if (MobDrops.find(mob->dropType) == MobDrops.end()) {
|
|
|
|
std::cout << "[WARN] Drop Type " << mob->dropType << " was not found" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// find correct mob drop
|
2020-10-17 23:19:05 +00:00
|
|
|
MobDrop& drop = MobDrops[mob->dropType];
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
|
|
|
|
plr->money += drop.taros;
|
2020-11-23 23:42:34 +00:00
|
|
|
// money nano boost
|
|
|
|
if (plr->iConditionBitFlag & CSB_BIT_REWARD_CASH) {
|
|
|
|
int boost = 0;
|
|
|
|
if (NanoManager::getNanoBoost(plr)) // for gumballs
|
|
|
|
boost = 1;
|
|
|
|
plr->money += drop.taros * (5 + boost) / 25;
|
|
|
|
}
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
// formula for scaling FM with player/mob level difference
|
|
|
|
// TODO: adjust this better
|
|
|
|
int levelDifference = plr->level - mob->level;
|
|
|
|
int fm = drop.fm;
|
|
|
|
if (levelDifference > 0)
|
|
|
|
fm = levelDifference < 10 ? fm - (levelDifference * fm / 10) : 0;
|
2020-11-23 23:42:34 +00:00
|
|
|
// scavenger nano boost
|
|
|
|
if (plr->iConditionBitFlag & CSB_BIT_REWARD_BLOB) {
|
|
|
|
int boost = 0;
|
|
|
|
if (NanoManager::getNanoBoost(plr)) // for gumballs
|
|
|
|
boost = 1;
|
|
|
|
fm += fm * (5 + boost) / 25;
|
|
|
|
}
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
|
|
|
|
MissionManager::updateFusionMatter(sock, fm);
|
|
|
|
|
|
|
|
// give boosts 1 in 3 times
|
|
|
|
if (drop.boosts > 0) {
|
2020-12-31 02:30:43 +00:00
|
|
|
if (rolledPotions % 3 == 0)
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
plr->batteryN += drop.boosts;
|
2020-12-31 02:30:43 +00:00
|
|
|
if (rolledBoosts % 3 == 0)
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
plr->batteryW += drop.boosts;
|
|
|
|
}
|
2020-11-08 02:51:16 +00:00
|
|
|
// caps
|
|
|
|
if (plr->batteryW > 9999)
|
|
|
|
plr->batteryW = 9999;
|
|
|
|
if (plr->batteryN > 9999)
|
|
|
|
plr->batteryN = 9999;
|
2020-08-27 20:16:52 +00:00
|
|
|
|
2020-08-28 16:25:03 +00:00
|
|
|
// simple rewards
|
|
|
|
reward->m_iCandy = plr->money;
|
|
|
|
reward->m_iFusionMatter = plr->fusionmatter;
|
2020-09-27 06:58:33 +00:00
|
|
|
reward->m_iBatteryN = plr->batteryN;
|
|
|
|
reward->m_iBatteryW = plr->batteryW;
|
2020-08-28 16:25:03 +00:00
|
|
|
reward->iFatigue = 100; // prevents warning message
|
|
|
|
reward->iFatigue_Level = 1;
|
|
|
|
reward->iItemCnt = 1; // remember to update resplen if you change this
|
|
|
|
|
|
|
|
int slot = ItemManager::findFreeSlot(plr);
|
2020-10-17 23:19:05 +00:00
|
|
|
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
bool awardDrop = false;
|
2020-10-17 23:19:05 +00:00
|
|
|
MobDropChance *chance = nullptr;
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
// sanity check
|
2020-10-17 23:19:05 +00:00
|
|
|
if (MobDropChances.find(drop.dropChanceType) == MobDropChances.end()) {
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
std::cout << "[WARN] Unknown Drop Chance Type: " << drop.dropChanceType << std::endl;
|
2020-10-17 23:19:05 +00:00
|
|
|
return; // this also prevents holiday crate drops, but oh well
|
|
|
|
} else {
|
|
|
|
chance = &MobDropChances[drop.dropChanceType];
|
2020-12-31 02:30:43 +00:00
|
|
|
awardDrop = (rolledCrate % 1000 < chance->dropChance);
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// no drop
|
|
|
|
if (slot == -1 || !awardDrop) {
|
2020-08-28 16:25:03 +00:00
|
|
|
// no room for an item, but you still get FM and taros
|
2020-09-09 19:08:31 +00:00
|
|
|
reward->iItemCnt = 0;
|
2020-08-28 16:25:03 +00:00
|
|
|
sock->sendPacket((void*)respbuf, P_FE2CL_REP_REWARD_ITEM, sizeof(sP_FE2CL_REP_REWARD_ITEM));
|
|
|
|
} else {
|
|
|
|
// item reward
|
2020-12-31 02:30:43 +00:00
|
|
|
getReward(&item->sItem, &drop, chance, rolledCrateType);
|
2020-08-28 16:25:03 +00:00
|
|
|
item->iSlotNum = slot;
|
|
|
|
item->eIL = 1; // Inventory Location. 1 means player inventory.
|
|
|
|
|
|
|
|
// update player
|
|
|
|
plr->Inven[slot] = item->sItem;
|
|
|
|
|
|
|
|
sock->sendPacket((void*)respbuf, P_FE2CL_REP_REWARD_ITEM, resplen);
|
|
|
|
}
|
2020-09-23 19:44:27 +00:00
|
|
|
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
// event crates
|
|
|
|
if (settings::EVENTMODE != 0)
|
2020-12-31 02:30:43 +00:00
|
|
|
giveEventReward(sock, plr, rolledEvent);
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
}
|
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
void Combat::getReward(sItemBase *reward, MobDrop* drop, MobDropChance* chance, int rolled) {
|
2020-10-17 23:19:05 +00:00
|
|
|
reward->iType = 9;
|
|
|
|
reward->iOpt = 1;
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
|
|
|
|
int total = 0;
|
|
|
|
for (int ratio : chance->cratesRatio)
|
|
|
|
total += ratio;
|
|
|
|
|
|
|
|
// randomizing a crate
|
2020-12-31 02:30:43 +00:00
|
|
|
int randomNum = rolled % total;
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
int i = 0;
|
|
|
|
int sum = 0;
|
|
|
|
do {
|
2020-10-17 23:19:05 +00:00
|
|
|
reward->iID = drop->crateIDs[i];
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
sum += chance->cratesRatio[i];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
while (sum<=randomNum);
|
|
|
|
}
|
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
void Combat::giveEventReward(CNSocket* sock, Player* player, int rolled) {
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
// random drop chance
|
|
|
|
if (rand() % 100 > settings::EVENTCRATECHANCE)
|
|
|
|
return;
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-17 23:19:05 +00:00
|
|
|
// no slot = no reward
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
int slot = ItemManager::findFreeSlot(player);
|
|
|
|
if (slot == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const size_t resplen = sizeof(sP_FE2CL_REP_REWARD_ITEM) + sizeof(sItemReward);
|
|
|
|
assert(resplen < CN_PACKET_BUFFER_SIZE - 8);
|
|
|
|
|
2020-10-17 23:19:05 +00:00
|
|
|
uint8_t respbuf[resplen];
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
sP_FE2CL_REP_REWARD_ITEM* reward = (sP_FE2CL_REP_REWARD_ITEM*)respbuf;
|
|
|
|
sItemReward* item = (sItemReward*)(respbuf + sizeof(sP_FE2CL_REP_REWARD_ITEM));
|
|
|
|
|
|
|
|
// don't forget to zero the buffer!
|
|
|
|
memset(respbuf, 0, resplen);
|
|
|
|
|
|
|
|
// leave everything here as it is
|
|
|
|
reward->m_iCandy = player->money;
|
|
|
|
reward->m_iFusionMatter = player->fusionmatter;
|
|
|
|
reward->m_iBatteryN = player->batteryN;
|
|
|
|
reward->m_iBatteryW = player->batteryW;
|
|
|
|
reward->iFatigue = 100; // prevents warning message
|
|
|
|
reward->iFatigue_Level = 1;
|
|
|
|
reward->iItemCnt = 1; // remember to update resplen if you change this
|
|
|
|
|
|
|
|
// which crate to drop
|
|
|
|
int crateId;
|
2020-10-19 17:26:14 +00:00
|
|
|
switch (settings::EVENTMODE) {
|
|
|
|
// knishmas
|
|
|
|
case 1: crateId = 1187; break;
|
|
|
|
// halloween
|
|
|
|
case 2: crateId = 1181; break;
|
|
|
|
// spring
|
|
|
|
case 3: crateId = 1126; break;
|
|
|
|
// what
|
|
|
|
default:
|
|
|
|
std::cout << "[WARN] Unknown event Id " << settings::EVENTMODE << std::endl;
|
|
|
|
return;
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
}
|
2020-10-17 23:19:05 +00:00
|
|
|
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
item->sItem.iType = 9;
|
|
|
|
item->sItem.iID = crateId;
|
|
|
|
item->sItem.iOpt = 1;
|
|
|
|
item->iSlotNum = slot;
|
|
|
|
item->eIL = 1; // Inventory Location. 1 means player inventory.
|
|
|
|
|
|
|
|
// update player
|
|
|
|
player->Inven[slot] = item->sItem;
|
|
|
|
sock->sendPacket((void*)respbuf, P_FE2CL_REP_REWARD_ITEM, resplen);
|
2020-08-27 20:16:52 +00:00
|
|
|
}
|
2020-09-16 23:43:48 +00:00
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
int Combat::hitMob(CNSocket *sock, Mob *mob, int damage) {
|
2020-10-17 23:19:05 +00:00
|
|
|
// cannot kill mobs multiple times; cannot harm retreating mobs
|
|
|
|
if (mob->state != MobState::ROAMING && mob->state != MobState::COMBAT) {
|
|
|
|
return 0; // no damage
|
|
|
|
}
|
2020-09-25 00:00:26 +00:00
|
|
|
|
2020-11-25 08:10:05 +00:00
|
|
|
if (mob->skillStyle >= 0)
|
|
|
|
return 0; // don't hurt a mob casting corruption
|
|
|
|
|
2020-10-17 23:19:05 +00:00
|
|
|
if (mob->state == MobState::ROAMING) {
|
|
|
|
assert(mob->target == nullptr);
|
2021-03-13 22:55:16 +00:00
|
|
|
MobAI::enterCombat(sock, mob);
|
2020-11-16 03:13:40 +00:00
|
|
|
|
|
|
|
if (mob->groupLeader != 0)
|
2021-03-13 22:55:16 +00:00
|
|
|
MobAI::followToCombat(mob);
|
2020-10-17 23:19:05 +00:00
|
|
|
}
|
2020-09-25 00:00:26 +00:00
|
|
|
|
2020-10-17 23:19:05 +00:00
|
|
|
mob->appearanceData.iHP -= damage;
|
2020-09-25 00:00:26 +00:00
|
|
|
|
2020-10-21 05:24:51 +00:00
|
|
|
// wake up sleeping monster
|
|
|
|
if (mob->appearanceData.iConditionBitFlag & CSB_BIT_MEZ) {
|
|
|
|
mob->appearanceData.iConditionBitFlag &= ~CSB_BIT_MEZ;
|
2020-10-17 17:26:09 +00:00
|
|
|
|
2020-10-21 05:24:51 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_CHAR_TIME_BUFF_TIME_OUT, pkt1);
|
|
|
|
pkt1.eCT = 2;
|
|
|
|
pkt1.iID = mob->appearanceData.iNPC_ID;
|
|
|
|
pkt1.iConditionBitFlag = mob->appearanceData.iConditionBitFlag;
|
|
|
|
NPCManager::sendToViewable(mob, &pkt1, P_FE2CL_CHAR_TIME_BUFF_TIME_OUT, sizeof(sP_FE2CL_CHAR_TIME_BUFF_TIME_OUT));
|
|
|
|
}
|
2020-09-25 00:00:26 +00:00
|
|
|
|
2020-10-17 23:19:05 +00:00
|
|
|
if (mob->appearanceData.iHP <= 0)
|
|
|
|
killMob(mob->target, mob);
|
2020-09-25 00:00:26 +00:00
|
|
|
|
2020-10-17 23:19:05 +00:00
|
|
|
return damage;
|
2020-09-25 00:00:26 +00:00
|
|
|
}
|
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
void Combat::killMob(CNSocket *sock, Mob *mob) {
|
2020-09-16 23:43:48 +00:00
|
|
|
mob->state = MobState::DEAD;
|
2020-09-24 01:18:41 +00:00
|
|
|
mob->target = nullptr;
|
2020-09-22 20:22:10 +00:00
|
|
|
mob->appearanceData.iConditionBitFlag = 0;
|
2020-11-28 14:12:02 +00:00
|
|
|
mob->skillStyle = -1;
|
2020-10-28 21:05:01 +00:00
|
|
|
mob->unbuffTimes.clear();
|
2020-09-16 23:43:48 +00:00
|
|
|
mob->killedTime = getTime(); // XXX: maybe introduce a shard-global time for each step?
|
2020-10-17 23:19:05 +00:00
|
|
|
|
2020-09-22 15:30:49 +00:00
|
|
|
// check for the edge case where hitting the mob did not aggro it
|
|
|
|
if (sock != nullptr) {
|
2020-10-09 00:01:35 +00:00
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
2020-10-17 23:19:05 +00:00
|
|
|
|
2020-12-31 02:30:43 +00:00
|
|
|
int rolledBoosts = rand();
|
|
|
|
int rolledPotions = rand();
|
|
|
|
int rolledCrate = rand();
|
|
|
|
int rolledCrateType = rand();
|
|
|
|
int rolledEvent = rand();
|
|
|
|
int rolledQItem = rand();
|
|
|
|
|
2020-10-19 17:26:14 +00:00
|
|
|
if (plr->groupCnt == 1 && plr->iIDGroup == plr->iID) {
|
2020-12-31 02:30:43 +00:00
|
|
|
giveReward(sock, mob, rolledBoosts, rolledPotions, rolledCrate, rolledCrateType, rolledEvent);
|
|
|
|
MissionManager::mobKilled(sock, mob->appearanceData.iNPCType, rolledQItem);
|
2020-10-09 00:01:35 +00:00
|
|
|
} else {
|
2020-12-01 19:18:01 +00:00
|
|
|
Player* otherPlayer = PlayerManager::getPlayerFromID(plr->iIDGroup);
|
2020-10-09 00:01:35 +00:00
|
|
|
|
2020-12-01 19:18:01 +00:00
|
|
|
if (otherPlayer == nullptr)
|
2020-10-09 00:01:35 +00:00
|
|
|
return;
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-12-01 19:18:01 +00:00
|
|
|
for (int i = 0; i < otherPlayer->groupCnt; i++) {
|
|
|
|
CNSocket* sockTo = PlayerManager::getSockFromID(otherPlayer->groupIDs[i]);
|
2020-12-27 19:52:37 +00:00
|
|
|
if (sockTo == nullptr)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Player *otherPlr = PlayerManager::getPlayer(sockTo);
|
|
|
|
|
|
|
|
// only contribute to group members' kills if they're close enough
|
|
|
|
int dist = std::hypot(plr->x - otherPlr->x + 1, plr->y - otherPlr->y + 1);
|
|
|
|
if (dist > 5000)
|
|
|
|
continue;
|
|
|
|
|
2020-12-31 02:30:43 +00:00
|
|
|
giveReward(sockTo, mob, rolledBoosts, rolledPotions, rolledCrate, rolledCrateType, rolledEvent);
|
|
|
|
MissionManager::mobKilled(sockTo, mob->appearanceData.iNPCType, rolledQItem);
|
2020-10-09 00:01:35 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-22 15:30:49 +00:00
|
|
|
}
|
2020-09-16 23:43:48 +00:00
|
|
|
|
2020-10-13 19:44:43 +00:00
|
|
|
// delay the despawn animation
|
2020-09-21 22:21:43 +00:00
|
|
|
mob->despawned = false;
|
2020-10-13 19:44:43 +00:00
|
|
|
|
2020-12-15 22:16:18 +00:00
|
|
|
// fire any triggered events
|
|
|
|
for (NPCEvent& event : NPCManager::NPCEvents)
|
|
|
|
if (event.trigger == ON_KILLED && event.npcType == mob->appearanceData.iNPCType)
|
|
|
|
event.handler(sock, mob);
|
|
|
|
|
2020-10-13 19:44:43 +00:00
|
|
|
auto it = TransportManager::NPCQueues.find(mob->appearanceData.iNPC_ID);
|
|
|
|
if (it == TransportManager::NPCQueues.end() || it->second.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// rewind or empty the movement queue
|
|
|
|
if (mob->staticPath) {
|
|
|
|
/*
|
|
|
|
* This is inelegant, but we wind forward in the path until we find the point that
|
|
|
|
* corresponds with the Mob's spawn point.
|
|
|
|
*
|
|
|
|
* IMPORTANT: The check in TableData::loadPaths() must pass or else this will loop forever.
|
|
|
|
*/
|
|
|
|
auto& queue = it->second;
|
|
|
|
for (auto point = queue.front(); point.x != mob->spawnX || point.y != mob->spawnY; point = queue.front()) {
|
|
|
|
queue.pop();
|
|
|
|
queue.push(point);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
TransportManager::NPCQueues.erase(mob->appearanceData.iNPC_ID);
|
|
|
|
}
|
2020-09-16 23:43:48 +00:00
|
|
|
}
|
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
void Combat::combatBegin(CNSocket *sock, CNPacketData *data) {
|
2020-09-26 22:16:15 +00:00
|
|
|
Player *plr = PlayerManager::getPlayer(sock);
|
2020-09-28 18:11:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
plr->inCombat = true;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
// HACK: make sure the player has the right weapon out for combat
|
|
|
|
INITSTRUCT(sP_FE2CL_PC_EQUIP_CHANGE, resp);
|
|
|
|
|
|
|
|
resp.iPC_ID = plr->iID;
|
|
|
|
resp.iEquipSlotNum = 0;
|
|
|
|
resp.EquipSlotItem = plr->Equip[0];
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
PlayerManager::sendToViewable(sock, (void*)&resp, P_FE2CL_PC_EQUIP_CHANGE, sizeof(sP_FE2CL_PC_EQUIP_CHANGE));
|
2020-09-26 22:16:15 +00:00
|
|
|
}
|
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
void Combat::combatEnd(CNSocket *sock, CNPacketData *data) {
|
2020-09-26 22:16:15 +00:00
|
|
|
Player *plr = PlayerManager::getPlayer(sock);
|
2020-09-28 18:11:13 +00:00
|
|
|
|
2020-10-21 05:24:51 +00:00
|
|
|
if (plr != nullptr) {
|
2020-09-28 18:11:13 +00:00
|
|
|
plr->inCombat = false;
|
2020-10-21 05:24:51 +00:00
|
|
|
plr->healCooldown = 4000;
|
|
|
|
}
|
2020-09-26 22:16:15 +00:00
|
|
|
}
|
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
void Combat::dotDamageOnOff(CNSocket *sock, CNPacketData *data) {
|
2020-09-26 22:16:15 +00:00
|
|
|
sP_CL2FE_DOT_DAMAGE_ONOFF *pkt = (sP_CL2FE_DOT_DAMAGE_ONOFF*)data->buf;
|
|
|
|
Player *plr = PlayerManager::getPlayer(sock);
|
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
if ((plr->iConditionBitFlag & CSB_BIT_INFECTION) != (bool)pkt->iFlag)
|
|
|
|
plr->iConditionBitFlag ^= CSB_BIT_INFECTION;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_PC_BUFF_UPDATE, pkt1);
|
|
|
|
|
2020-10-19 17:26:14 +00:00
|
|
|
pkt1.eCSTB = ECSB_INFECTION; // eCharStatusTimeBuffID
|
|
|
|
pkt1.eTBU = 1; // eTimeBuffUpdate
|
|
|
|
pkt1.eTBT = 0; // eTimeBuffType 1 means nano
|
2020-11-13 03:20:51 +00:00
|
|
|
pkt1.iConditionBitFlag = plr->iConditionBitFlag;
|
2020-10-04 23:54:08 +00:00
|
|
|
|
|
|
|
sock->sendPacket((void*)&pkt1, P_FE2CL_PC_BUFF_UPDATE, sizeof(sP_FE2CL_PC_BUFF_UPDATE));
|
2020-09-26 22:16:15 +00:00
|
|
|
}
|
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
void Combat::dealGooDamage(CNSocket *sock, int amount) {
|
2020-09-26 22:16:15 +00:00
|
|
|
size_t resplen = sizeof(sP_FE2CL_CHAR_TIME_BUFF_TIME_TICK) + sizeof(sSkillResult_DotDamage);
|
|
|
|
assert(resplen < CN_PACKET_BUFFER_SIZE - 8);
|
2020-09-26 23:00:31 +00:00
|
|
|
uint8_t respbuf[CN_PACKET_BUFFER_SIZE];
|
2020-10-04 23:54:08 +00:00
|
|
|
Player *plr = PlayerManager::getPlayer(sock);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-09-26 22:16:15 +00:00
|
|
|
memset(respbuf, 0, resplen);
|
|
|
|
|
|
|
|
sP_FE2CL_CHAR_TIME_BUFF_TIME_TICK *pkt = (sP_FE2CL_CHAR_TIME_BUFF_TIME_TICK*)respbuf;
|
|
|
|
sSkillResult_DotDamage *dmg = (sSkillResult_DotDamage*)(respbuf + sizeof(sP_FE2CL_CHAR_TIME_BUFF_TIME_TICK));
|
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
if (plr->iConditionBitFlag & CSB_BIT_PROTECT_INFECTION) {
|
|
|
|
amount = -2; // -2 is the magic number for "Protected" to appear as the damage number
|
|
|
|
dmg->bProtected = 1;
|
2020-09-28 18:11:13 +00:00
|
|
|
|
2020-11-23 23:42:34 +00:00
|
|
|
// eggs allow protection without nanos
|
|
|
|
if (plr->activeNano != -1 && (plr->iSelfConditionBitFlag & CSB_BIT_PROTECT_INFECTION))
|
2020-10-04 23:54:08 +00:00
|
|
|
plr->Nanos[plr->activeNano].iStamina -= 3;
|
|
|
|
} else {
|
|
|
|
plr->HP -= amount;
|
|
|
|
}
|
|
|
|
|
2020-12-04 16:59:53 +00:00
|
|
|
if (plr->activeNano != 0) {
|
2020-10-04 23:54:08 +00:00
|
|
|
dmg->iStamina = plr->Nanos[plr->activeNano].iStamina;
|
|
|
|
|
|
|
|
if (plr->Nanos[plr->activeNano].iStamina <= 0) {
|
|
|
|
dmg->bNanoDeactive = 1;
|
|
|
|
plr->Nanos[plr->activeNano].iStamina = 0;
|
2020-11-29 18:06:11 +00:00
|
|
|
NanoManager::summonNano(PlayerManager::getSockFromID(plr->iID), -1, true);
|
2020-10-04 23:54:08 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-26 22:16:15 +00:00
|
|
|
|
|
|
|
pkt->iID = plr->iID;
|
|
|
|
pkt->eCT = 1; // player
|
|
|
|
pkt->iTB_ID = ECSB_INFECTION; // sSkillResult_DotDamage
|
|
|
|
|
|
|
|
dmg->eCT = 1;
|
|
|
|
dmg->iID = plr->iID;
|
|
|
|
dmg->iDamage = amount;
|
|
|
|
dmg->iHP = plr->HP;
|
2020-11-13 03:20:51 +00:00
|
|
|
dmg->iConditionBitFlag = plr->iConditionBitFlag;
|
2020-09-26 22:16:15 +00:00
|
|
|
|
|
|
|
sock->sendPacket((void*)&respbuf, P_FE2CL_CHAR_TIME_BUFF_TIME_TICK, resplen);
|
|
|
|
PlayerManager::sendToViewable(sock, (void*)&respbuf, P_FE2CL_CHAR_TIME_BUFF_TIME_TICK, resplen);
|
|
|
|
}
|
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
std::pair<int,int> Combat::getDamage(int attackPower, int defensePower, bool shouldCrit,
|
2020-10-12 19:03:18 +00:00
|
|
|
bool batteryBoost, int attackerStyle,
|
|
|
|
int defenderStyle, int difficulty) {
|
2020-10-09 00:01:35 +00:00
|
|
|
std::pair<int,int> ret = {0, 1};
|
|
|
|
if (attackPower + defensePower * 2 == 0)
|
|
|
|
return ret;
|
2020-09-27 01:53:03 +00:00
|
|
|
|
2020-10-13 19:44:43 +00:00
|
|
|
// base calculation
|
2020-10-09 00:01:35 +00:00
|
|
|
int damage = attackPower * attackPower / (attackPower + defensePower);
|
2020-12-16 04:47:07 +00:00
|
|
|
damage = std::max(10 + attackPower / 10, damage - (defensePower - attackPower / 6) * difficulty / 100);
|
2020-10-09 00:01:35 +00:00
|
|
|
damage = damage * (rand() % 40 + 80) / 100;
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-13 19:44:43 +00:00
|
|
|
// Adaptium/Blastons/Cosmix
|
2020-10-09 00:01:35 +00:00
|
|
|
if (attackerStyle != -1 && defenderStyle != -1 && attackerStyle != defenderStyle) {
|
2020-11-13 23:06:18 +00:00
|
|
|
if (attackerStyle - defenderStyle == 2)
|
|
|
|
defenderStyle += 3;
|
|
|
|
if (defenderStyle - attackerStyle == 2)
|
|
|
|
defenderStyle -= 3;
|
|
|
|
if (attackerStyle < defenderStyle)
|
2020-12-16 04:47:07 +00:00
|
|
|
damage = damage * 5 / 4;
|
2020-10-09 00:01:35 +00:00
|
|
|
else
|
2020-12-16 04:47:07 +00:00
|
|
|
damage = damage * 4 / 5;
|
2020-10-09 00:01:35 +00:00
|
|
|
}
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-13 19:44:43 +00:00
|
|
|
// weapon boosts
|
2020-10-09 00:01:35 +00:00
|
|
|
if (batteryBoost)
|
|
|
|
damage = damage * 5 / 4;
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-09 00:01:35 +00:00
|
|
|
ret.first = damage;
|
2020-09-27 01:53:03 +00:00
|
|
|
ret.second = 1;
|
|
|
|
|
|
|
|
if (shouldCrit && rand() % 20 == 0) {
|
2020-09-27 02:28:06 +00:00
|
|
|
ret.first *= 2; // critical hit
|
2020-09-27 01:53:03 +00:00
|
|
|
ret.second = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2020-09-27 18:29:26 +00:00
|
|
|
}
|
2020-09-22 15:30:49 +00:00
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
void Combat::pcAttackChars(CNSocket *sock, CNPacketData *data) {
|
2020-09-22 15:30:49 +00:00
|
|
|
sP_CL2FE_REQ_PC_ATTACK_CHARs* pkt = (sP_CL2FE_REQ_PC_ATTACK_CHARs*)data->buf;
|
|
|
|
Player *plr = PlayerManager::getPlayer(sock);
|
|
|
|
|
2021-01-01 20:38:03 +00:00
|
|
|
// only GMs can use this this variant
|
|
|
|
if (plr->accountLevel > 30)
|
|
|
|
return;
|
|
|
|
|
2020-09-22 15:30:49 +00:00
|
|
|
// Unlike the attack mob packet, attacking players packet has an 8-byte trail (Instead of 4 bytes).
|
|
|
|
if (!validInVarPacket(sizeof(sP_CL2FE_REQ_PC_ATTACK_CHARs), pkt->iTargetCnt, sizeof(int32_t) * 2, data->size)) {
|
|
|
|
std::cout << "[WARN] bad sP_CL2FE_REQ_PC_ATTACK_CHARs packet size\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t *pktdata = (int32_t*)((uint8_t*)data->buf + sizeof(sP_CL2FE_REQ_PC_ATTACK_CHARs));
|
|
|
|
|
|
|
|
if (!validOutVarPacket(sizeof(sP_FE2CL_PC_ATTACK_CHARs_SUCC), pkt->iTargetCnt, sizeof(sAttackResult))) {
|
|
|
|
std::cout << "[WARN] bad sP_FE2CL_PC_ATTACK_CHARs_SUCC packet size\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// initialize response struct
|
|
|
|
size_t resplen = sizeof(sP_FE2CL_PC_ATTACK_CHARs_SUCC) + pkt->iTargetCnt * sizeof(sAttackResult);
|
|
|
|
uint8_t respbuf[CN_PACKET_BUFFER_SIZE];
|
|
|
|
|
|
|
|
memset(respbuf, 0, resplen);
|
|
|
|
|
|
|
|
sP_FE2CL_PC_ATTACK_CHARs_SUCC *resp = (sP_FE2CL_PC_ATTACK_CHARs_SUCC*)respbuf;
|
|
|
|
sAttackResult *respdata = (sAttackResult*)(respbuf+sizeof(sP_FE2CL_PC_ATTACK_CHARs_SUCC));
|
|
|
|
|
|
|
|
resp->iTargetCnt = pkt->iTargetCnt;
|
|
|
|
|
|
|
|
for (int i = 0; i < pkt->iTargetCnt; i++) {
|
|
|
|
if (pktdata[i*2+1] == 1) { // eCT == 1; attack player
|
|
|
|
Player *target = nullptr;
|
|
|
|
|
|
|
|
for (auto& pair : PlayerManager::players) {
|
2020-11-17 23:16:16 +00:00
|
|
|
if (pair.second->iID == pktdata[i*2]) {
|
|
|
|
target = pair.second;
|
2020-09-22 15:30:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target == nullptr) {
|
|
|
|
// you shall not pass
|
|
|
|
std::cout << "[WARN] pcAttackChars: player ID not found" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-09-29 21:27:48 +00:00
|
|
|
std::pair<int,int> damage;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-09-29 21:27:48 +00:00
|
|
|
if (pkt->iTargetCnt > 1)
|
2020-10-09 00:01:35 +00:00
|
|
|
damage.first = plr->groupDamage;
|
2020-09-29 21:27:48 +00:00
|
|
|
else
|
2020-10-09 00:01:35 +00:00
|
|
|
damage.first = plr->pointDamage;
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-11-16 03:13:40 +00:00
|
|
|
damage = getDamage(damage.first, target->defense, true, (plr->batteryW > 6 + plr->level), -1, -1, 0);
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-21 05:24:51 +00:00
|
|
|
if (plr->batteryW >= 6 + plr->level)
|
|
|
|
plr->batteryW -= 6 + plr->level;
|
|
|
|
else
|
|
|
|
plr->batteryW = 0;
|
2020-09-22 15:30:49 +00:00
|
|
|
|
2020-09-29 21:27:48 +00:00
|
|
|
target->HP -= damage.first;
|
2020-09-22 15:30:49 +00:00
|
|
|
|
|
|
|
respdata[i].eCT = pktdata[i*2+1];
|
|
|
|
respdata[i].iID = target->iID;
|
2020-09-29 21:27:48 +00:00
|
|
|
respdata[i].iDamage = damage.first;
|
2020-09-22 15:30:49 +00:00
|
|
|
respdata[i].iHP = target->HP;
|
2020-09-29 21:27:48 +00:00
|
|
|
respdata[i].iHitFlag = damage.second; // hitscan, not a rocket or a grenade
|
2020-09-22 15:30:49 +00:00
|
|
|
} else { // eCT == 4; attack mob
|
2021-03-13 22:55:16 +00:00
|
|
|
if (MobAI::Mobs.find(pktdata[i*2]) == MobAI::Mobs.end()) {
|
2020-09-22 15:30:49 +00:00
|
|
|
// not sure how to best handle this
|
|
|
|
std::cout << "[WARN] pcAttackNpcs: mob ID not found" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2021-03-13 22:55:16 +00:00
|
|
|
Mob *mob = MobAI::Mobs[pktdata[i*2]];
|
2020-09-22 15:30:49 +00:00
|
|
|
|
|
|
|
std::pair<int,int> damage;
|
|
|
|
|
|
|
|
if (pkt->iTargetCnt > 1)
|
2020-10-09 00:01:35 +00:00
|
|
|
damage.first = plr->groupDamage;
|
2020-09-22 15:30:49 +00:00
|
|
|
else
|
2020-10-09 00:01:35 +00:00
|
|
|
damage.first = plr->pointDamage;
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-09 00:01:35 +00:00
|
|
|
int difficulty = (int)mob->data["m_iNpcLevel"];
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-21 05:24:51 +00:00
|
|
|
damage = getDamage(damage.first, (int)mob->data["m_iProtection"], true, (plr->batteryW > 6 + difficulty),
|
2020-10-12 19:03:18 +00:00
|
|
|
NanoManager::nanoStyle(plr->activeNano), (int)mob->data["m_iNpcStyle"], difficulty);
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-21 05:24:51 +00:00
|
|
|
if (plr->batteryW >= 6 + difficulty)
|
|
|
|
plr->batteryW -= 6 + difficulty;
|
|
|
|
else
|
|
|
|
plr->batteryW = 0;
|
2020-09-22 15:30:49 +00:00
|
|
|
|
|
|
|
damage.first = hitMob(sock, mob, damage.first);
|
|
|
|
|
|
|
|
respdata[i].eCT = pktdata[i*2+1];
|
|
|
|
respdata[i].iID = mob->appearanceData.iNPC_ID;
|
|
|
|
respdata[i].iDamage = damage.first;
|
|
|
|
respdata[i].iHP = mob->appearanceData.iHP;
|
|
|
|
respdata[i].iHitFlag = damage.second; // hitscan, not a rocket or a grenade
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sock->sendPacket((void*)respbuf, P_FE2CL_PC_ATTACK_CHARs_SUCC, resplen);
|
|
|
|
|
|
|
|
// a bit of a hack: these are the same size, so we can reuse the response packet
|
2020-10-09 00:01:35 +00:00
|
|
|
assert(sizeof(sP_FE2CL_PC_ATTACK_CHARs_SUCC) == sizeof(sP_FE2CL_PC_ATTACK_CHARs));
|
2020-09-22 15:30:49 +00:00
|
|
|
sP_FE2CL_PC_ATTACK_CHARs *resp1 = (sP_FE2CL_PC_ATTACK_CHARs*)respbuf;
|
|
|
|
|
|
|
|
resp1->iPC_ID = plr->iID;
|
|
|
|
|
|
|
|
// send to other players
|
|
|
|
PlayerManager::sendToViewable(sock, (void*)respbuf, P_FE2CL_PC_ATTACK_CHARs, resplen);
|
|
|
|
}
|
2020-09-29 21:27:48 +00:00
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
void Combat::grenadeFire(CNSocket* sock, CNPacketData* data) {
|
2020-11-12 00:46:53 +00:00
|
|
|
sP_CL2FE_REQ_PC_GRENADE_STYLE_FIRE* grenade = (sP_CL2FE_REQ_PC_GRENADE_STYLE_FIRE*)data->buf;
|
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
|
|
|
|
|
|
|
INITSTRUCT(sP_FE2CL_REP_PC_GRENADE_STYLE_FIRE_SUCC, resp);
|
|
|
|
resp.iToX = grenade->iToX;
|
|
|
|
resp.iToY = grenade->iToY;
|
|
|
|
resp.iToZ = grenade->iToZ;
|
|
|
|
|
|
|
|
resp.iBulletID = addBullet(plr, true);
|
|
|
|
resp.iBatteryW = plr->batteryW;
|
|
|
|
|
|
|
|
// 1 means grenade
|
|
|
|
resp.Bullet.iID = 1;
|
|
|
|
sock->sendPacket(&resp, P_FE2CL_REP_PC_GRENADE_STYLE_FIRE_SUCC, sizeof(sP_FE2CL_REP_PC_GRENADE_STYLE_FIRE_SUCC));
|
|
|
|
|
|
|
|
// send packet to nearby players
|
|
|
|
INITSTRUCT(sP_FE2CL_PC_GRENADE_STYLE_FIRE, toOthers);
|
|
|
|
toOthers.iPC_ID = plr->iID;
|
|
|
|
toOthers.iToX = resp.iToX;
|
|
|
|
toOthers.iToY = resp.iToY;
|
|
|
|
toOthers.iToZ = resp.iToZ;
|
|
|
|
toOthers.iBulletID = resp.iBulletID;
|
|
|
|
toOthers.Bullet.iID = resp.Bullet.iID;
|
|
|
|
|
|
|
|
PlayerManager::sendToViewable(sock, &toOthers, P_FE2CL_PC_GRENADE_STYLE_FIRE, sizeof(sP_FE2CL_PC_GRENADE_STYLE_FIRE));
|
|
|
|
}
|
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
void Combat::rocketFire(CNSocket* sock, CNPacketData* data) {
|
2020-11-12 00:46:53 +00:00
|
|
|
sP_CL2FE_REQ_PC_ROCKET_STYLE_FIRE* rocket = (sP_CL2FE_REQ_PC_ROCKET_STYLE_FIRE*)data->buf;
|
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
|
|
|
|
|
|
|
// We should be sending back rocket succ packet, but it doesn't work, and this one works
|
|
|
|
INITSTRUCT(sP_FE2CL_REP_PC_GRENADE_STYLE_FIRE_SUCC, resp);
|
|
|
|
resp.iToX = rocket->iToX;
|
|
|
|
resp.iToY = rocket->iToY;
|
|
|
|
// rocket->iToZ is broken, this seems like a good height
|
|
|
|
resp.iToZ = plr->z + 100;
|
|
|
|
|
|
|
|
resp.iBulletID = addBullet(plr, false);
|
|
|
|
// we have to send it weapon id
|
|
|
|
resp.Bullet.iID = plr->Equip[0].iID;
|
|
|
|
resp.iBatteryW = plr->batteryW;
|
|
|
|
|
|
|
|
sock->sendPacket(&resp, P_FE2CL_REP_PC_GRENADE_STYLE_FIRE_SUCC, sizeof(sP_FE2CL_REP_PC_GRENADE_STYLE_FIRE_SUCC));
|
|
|
|
|
|
|
|
// send packet to nearby players
|
|
|
|
INITSTRUCT(sP_FE2CL_PC_GRENADE_STYLE_FIRE, toOthers);
|
|
|
|
toOthers.iPC_ID = plr->iID;
|
|
|
|
toOthers.iToX = resp.iToX;
|
|
|
|
toOthers.iToY = resp.iToY;
|
|
|
|
toOthers.iToZ = resp.iToZ;
|
|
|
|
toOthers.iBulletID = resp.iBulletID;
|
|
|
|
toOthers.Bullet.iID = resp.Bullet.iID;
|
|
|
|
|
|
|
|
PlayerManager::sendToViewable(sock, &toOthers, P_FE2CL_PC_GRENADE_STYLE_FIRE, sizeof(sP_FE2CL_PC_GRENADE_STYLE_FIRE));
|
|
|
|
}
|
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
int8_t Combat::addBullet(Player* plr, bool isGrenade) {
|
2020-11-12 00:46:53 +00:00
|
|
|
|
|
|
|
int8_t findId = 0;
|
|
|
|
if (Bullets.find(plr->iID) != Bullets.end()) {
|
|
|
|
// find first free id
|
|
|
|
for (; findId < 127; findId++)
|
|
|
|
if (Bullets[plr->iID].find(findId) == Bullets[plr->iID].end())
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// sanity check
|
|
|
|
if (findId == 127) {
|
|
|
|
std::cout << "[WARN] Player has more than 127 active projectiles?!" << std::endl;
|
|
|
|
findId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bullet toAdd;
|
|
|
|
toAdd.pointDamage = plr->pointDamage;
|
|
|
|
toAdd.groupDamage = plr->groupDamage;
|
|
|
|
// for grenade we need to send 1, for rocket - weapon id
|
|
|
|
toAdd.bulletType = isGrenade ? 1 : plr->Equip[0].iID;
|
|
|
|
|
|
|
|
// temp solution Jade fix plz
|
2020-11-12 08:28:12 +00:00
|
|
|
toAdd.weaponBoost = plr->batteryW > 0;
|
2020-11-12 00:46:53 +00:00
|
|
|
if (toAdd.weaponBoost) {
|
|
|
|
int boostCost = rand() % 11 + 20;
|
|
|
|
plr->batteryW = boostCost > plr->batteryW ? 0 : plr->batteryW - boostCost;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bullets[plr->iID][findId] = toAdd;
|
|
|
|
return findId;
|
|
|
|
}
|
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
void Combat::projectileHit(CNSocket* sock, CNPacketData* data) {
|
2020-11-12 00:46:53 +00:00
|
|
|
sP_CL2FE_REQ_PC_ROCKET_STYLE_HIT* pkt = (sP_CL2FE_REQ_PC_ROCKET_STYLE_HIT*)data->buf;
|
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
|
|
|
|
|
|
|
if (pkt->iTargetCnt == 0) {
|
|
|
|
Bullets[plr->iID].erase(pkt->iBulletID);
|
|
|
|
// no targets hit, don't send response
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// sanity check
|
|
|
|
if (!validInVarPacket(sizeof(sP_CL2FE_REQ_PC_ROCKET_STYLE_HIT), pkt->iTargetCnt, sizeof(int64_t), data->size)) {
|
|
|
|
std::cout << "[WARN] bad sP_CL2FE_REQ_PC_ROCKET_STYLE_HIT packet size\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// client sends us 8 byters, where last 4 bytes are mob ID,
|
|
|
|
// we use int64 pointer to move around but have to remember to cast it to int32
|
|
|
|
int64_t* pktdata = (int64_t*)((uint8_t*)data->buf + sizeof(sP_CL2FE_REQ_PC_ROCKET_STYLE_HIT));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Due to the possibility of multiplication overflow (and regular buffer overflow),
|
|
|
|
* both incoming and outgoing variable-length packets must be validated, at least if
|
|
|
|
* the number of trailing structs isn't well known (ie. it's from the client).
|
|
|
|
*/
|
|
|
|
if (!validOutVarPacket(sizeof(sP_FE2CL_PC_GRENADE_STYLE_HIT), pkt->iTargetCnt, sizeof(sAttackResult))) {
|
|
|
|
std::cout << "[WARN] bad sP_FE2CL_PC_GRENADE_STYLE_HIT packet size\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-31 05:54:57 +00:00
|
|
|
// rapid fire anti-cheat
|
|
|
|
time_t currTime = getTime();
|
|
|
|
if (currTime - plr->lastShot < plr->fireRate * 80)
|
|
|
|
plr->suspicionRating += plr->fireRate * 100 + plr->lastShot - currTime; // gain suspicion for rapid firing
|
|
|
|
else if (currTime - plr->lastShot < plr->fireRate * 180 && plr->suspicionRating > 0)
|
|
|
|
plr->suspicionRating += plr->fireRate * 100 + plr->lastShot - currTime; // lose suspicion for delayed firing
|
|
|
|
|
|
|
|
plr->lastShot = currTime;
|
|
|
|
|
|
|
|
if (plr->suspicionRating > 10000) // kill the socket when the player is too suspicious
|
|
|
|
sock->kill();
|
|
|
|
|
2020-11-12 08:31:55 +00:00
|
|
|
/*
|
|
|
|
* initialize response struct
|
|
|
|
* rocket style hit doesn't work properly, so we're always sending this one
|
|
|
|
*/
|
|
|
|
|
2020-11-12 00:46:53 +00:00
|
|
|
size_t resplen = sizeof(sP_FE2CL_PC_GRENADE_STYLE_HIT) + pkt->iTargetCnt * sizeof(sAttackResult);
|
|
|
|
uint8_t respbuf[CN_PACKET_BUFFER_SIZE];
|
|
|
|
|
|
|
|
memset(respbuf, 0, resplen);
|
|
|
|
|
|
|
|
sP_FE2CL_PC_GRENADE_STYLE_HIT* resp = (sP_FE2CL_PC_GRENADE_STYLE_HIT*)respbuf;
|
|
|
|
sAttackResult* respdata = (sAttackResult*)(respbuf + sizeof(sP_FE2CL_PC_GRENADE_STYLE_HIT));
|
|
|
|
|
|
|
|
resp->iTargetCnt = pkt->iTargetCnt;
|
|
|
|
if (Bullets.find(plr->iID) == Bullets.end() || Bullets[plr->iID].find(pkt->iBulletID) == Bullets[plr->iID].end()) {
|
|
|
|
std::cout << "[WARN] projectileHit: bullet not found" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Bullet* bullet = &Bullets[plr->iID][pkt->iBulletID];
|
|
|
|
|
|
|
|
for (int i = 0; i < pkt->iTargetCnt; i++) {
|
2021-03-13 22:55:16 +00:00
|
|
|
if (MobAI::Mobs.find(pktdata[i]) == MobAI::Mobs.end()) {
|
2020-11-12 00:46:53 +00:00
|
|
|
// not sure how to best handle this
|
|
|
|
std::cout << "[WARN] projectileHit: mob ID not found" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
Mob* mob = MobAI::Mobs[pktdata[i]];
|
2020-11-12 00:46:53 +00:00
|
|
|
std::pair<int, int> damage;
|
|
|
|
|
|
|
|
damage.first = pkt->iTargetCnt > 1 ? bullet->groupDamage : bullet->pointDamage;
|
|
|
|
|
|
|
|
int difficulty = (int)mob->data["m_iNpcLevel"];
|
|
|
|
damage = getDamage(damage.first, (int)mob->data["m_iProtection"], true, bullet->weaponBoost, NanoManager::nanoStyle(plr->activeNano), (int)mob->data["m_iNpcStyle"], difficulty);
|
|
|
|
|
|
|
|
damage.first = hitMob(sock, mob, damage.first);
|
|
|
|
|
|
|
|
respdata[i].iID = mob->appearanceData.iNPC_ID;
|
|
|
|
respdata[i].iDamage = damage.first;
|
|
|
|
respdata[i].iHP = mob->appearanceData.iHP;
|
|
|
|
respdata[i].iHitFlag = damage.second;
|
|
|
|
}
|
|
|
|
|
|
|
|
resp->iPC_ID = plr->iID;
|
|
|
|
resp->iBulletID = pkt->iBulletID;
|
|
|
|
resp->Bullet.iID = bullet->bulletType;
|
|
|
|
sock->sendPacket((void*)respbuf, P_FE2CL_PC_GRENADE_STYLE_HIT, resplen);
|
|
|
|
PlayerManager::sendToViewable(sock, (void*)respbuf, P_FE2CL_PC_GRENADE_STYLE_HIT, resplen);
|
|
|
|
|
|
|
|
Bullets[plr->iID].erase(resp->iBulletID);
|
|
|
|
}
|
2020-11-16 03:13:40 +00:00
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
void Combat::playerTick(CNServer *serv, time_t currTime) {
|
|
|
|
static time_t lastHealTime = 0;
|
2020-11-25 02:51:17 +00:00
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
for (auto& pair : PlayerManager::players) {
|
|
|
|
CNSocket *sock = pair.first;
|
|
|
|
Player *plr = pair.second;
|
|
|
|
bool transmit = false;
|
2020-12-30 22:07:10 +00:00
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
// group ticks
|
|
|
|
if (plr->groupCnt > 1)
|
|
|
|
GroupManager::groupTickInfo(plr);
|
2020-12-30 22:07:10 +00:00
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
// do not tick dead players
|
|
|
|
if (plr->HP <= 0)
|
2020-12-30 22:07:10 +00:00
|
|
|
continue;
|
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
// fm patch/lake damage
|
|
|
|
if ((plr->iConditionBitFlag & CSB_BIT_INFECTION)
|
|
|
|
&& !(plr->iSpecialState & CN_SPECIAL_STATE_FLAG__INVULNERABLE))
|
|
|
|
dealGooDamage(sock, PC_MAXHEALTH(plr->level) * 3 / 20);
|
2020-12-30 22:07:10 +00:00
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
// heal
|
|
|
|
if (currTime - lastHealTime >= 4000 && !plr->inCombat && plr->HP < PC_MAXHEALTH(plr->level)) {
|
|
|
|
if (currTime - lastHealTime - plr->healCooldown >= 4000) {
|
|
|
|
plr->HP += PC_MAXHEALTH(plr->level) / 5;
|
|
|
|
if (plr->HP > PC_MAXHEALTH(plr->level))
|
|
|
|
plr->HP = PC_MAXHEALTH(plr->level);
|
|
|
|
transmit = true;
|
|
|
|
} else
|
|
|
|
plr->healCooldown -= 4000;
|
|
|
|
}
|
2020-12-01 18:58:34 +00:00
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
if (plr->activeNano != 0 && plr->equippedNanos[i] == plr->activeNano) { // spend stamina
|
|
|
|
plr->Nanos[plr->activeNano].iStamina -= 1 + plr->nanoDrainRate / 5;
|
2020-11-25 08:10:05 +00:00
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
if (plr->Nanos[plr->activeNano].iStamina <= 0)
|
|
|
|
NanoManager::summonNano(sock, -1, true); // unsummon nano silently
|
2020-11-25 08:10:05 +00:00
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
transmit = true;
|
|
|
|
} else if (plr->Nanos[plr->equippedNanos[i]].iStamina < 150) { // regain stamina
|
|
|
|
sNano& nano = plr->Nanos[plr->equippedNanos[i]];
|
|
|
|
nano.iStamina += 1;
|
2020-11-25 08:10:05 +00:00
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
if (nano.iStamina > 150)
|
|
|
|
nano.iStamina = 150;
|
2020-11-25 08:10:05 +00:00
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
transmit = true;
|
2020-11-25 08:10:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
// check if the player has fallen out of the world
|
|
|
|
if (plr->z < -30000) {
|
|
|
|
INITSTRUCT(sP_FE2CL_PC_SUDDEN_DEAD, dead);
|
2020-11-25 08:10:05 +00:00
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
dead.iPC_ID = plr->iID;
|
|
|
|
dead.iDamage = plr->HP;
|
|
|
|
dead.iHP = plr->HP = 0;
|
2020-11-25 08:10:05 +00:00
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
sock->sendPacket((void*)&dead, P_FE2CL_PC_SUDDEN_DEAD, sizeof(sP_FE2CL_PC_SUDDEN_DEAD));
|
|
|
|
PlayerManager::sendToViewable(sock, (void*)&dead, P_FE2CL_PC_SUDDEN_DEAD, sizeof(sP_FE2CL_PC_SUDDEN_DEAD));
|
2020-11-25 08:10:05 +00:00
|
|
|
}
|
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
if (transmit) {
|
|
|
|
INITSTRUCT(sP_FE2CL_REP_PC_TICK, pkt);
|
2020-11-25 08:10:05 +00:00
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
pkt.iHP = plr->HP;
|
|
|
|
pkt.iBatteryN = plr->batteryN;
|
2020-12-01 20:34:14 +00:00
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
pkt.aNano[0] = plr->Nanos[plr->equippedNanos[0]];
|
|
|
|
pkt.aNano[1] = plr->Nanos[plr->equippedNanos[1]];
|
|
|
|
pkt.aNano[2] = plr->Nanos[plr->equippedNanos[2]];
|
2020-11-25 08:10:05 +00:00
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
sock->sendPacket((void*)&pkt, P_FE2CL_REP_PC_TICK, sizeof(sP_FE2CL_REP_PC_TICK));
|
2020-11-25 08:10:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-13 22:55:16 +00:00
|
|
|
// if this was a heal tick, update the counter outside of the loop
|
|
|
|
if (currTime - lastHealTime >= 4000)
|
|
|
|
lastHealTime = currTime;
|
2021-01-09 13:16:29 +00:00
|
|
|
}
|