Browse Source

Consistently send network messages when monsters are damaged

pull/5209/head
staphen 4 years ago committed by Anders Jenbo
parent
commit
f9e01f25c4
  1. 11
      Source/missiles.cpp
  2. 64
      Source/monster.cpp
  3. 2
      Source/monster.h
  4. 4
      Source/player.cpp

11
Source/missiles.cpp

@ -238,7 +238,7 @@ bool MonsterMHit(int pnum, int monsterId, int mindam, int maxdam, int dist, miss
dam >>= 2;
if (&player == MyPlayer)
monster.hitPoints -= dam;
ApplyMonsterDamage(monster, dam);
if ((gbIsHellfire && HasAnyOf(player._pIFlags, ItemSpecialEffect::NoHealOnMonsters)) || (!gbIsHellfire && HasAnyOf(player._pIFlags, ItemSpecialEffect::FireArrows)))
monster.flags |= MFLAG_NOHEAL;
@ -246,6 +246,7 @@ bool MonsterMHit(int pnum, int monsterId, int mindam, int maxdam, int dist, miss
if (monster.hitPoints >> 6 <= 0) {
M_StartKill(monster, player);
} else if (resist) {
monster.tag(player);
PlayEffect(monster, MonsterSound::Hit);
} else {
if (monster.mode != MonsterMode::Petrified && MissilesData[t].mType == 0 && HasAnyOf(player._pIFlags, ItemSpecialEffect::Knockback))
@ -876,9 +877,8 @@ bool MonsterTrapHit(int monsterId, int mindam, int maxdam, int dist, missile_id
if (!shift)
dam <<= 6;
if (resist)
monster.hitPoints -= dam / 4;
else
monster.hitPoints -= dam;
dam /= 4;
ApplyMonsterDamage(monster, dam);
#ifdef _DEBUG
if (DebugGodMode)
monster.hitPoints = 0;
@ -888,7 +888,6 @@ bool MonsterTrapHit(int monsterId, int mindam, int maxdam, int dist, missile_id
} else if (resist) {
PlayEffect(monster, MonsterSound::Hit);
} else if (monster.type().type != MT_GOLEM) {
PlayEffect(monster, MonsterSound::Hit);
M_StartHit(monster, dam);
}
return true;
@ -2186,7 +2185,7 @@ void AddGolem(Missile &missile, const AddMissileParameter &parameter)
Monster &golem = Monsters[playerId];
if (golem.position.tile != GolemHoldingCell && &player == MyPlayer)
M_StartKill(golem, player);
KillMyGolem();
ConsumeSpell(player, SPL_GOLEM);

64
Source/monster.cpp

@ -1063,21 +1063,6 @@ bool MonsterWalk(Monster &monster, MonsterMode variant)
return isAnimationEnd;
}
void ApplyMonsterDamage(Monster &monster, int damage)
{
monster.hitPoints -= damage;
if (monster.hitPoints >> 6 <= 0) {
delta_kill_monster(monster, monster.position.tile, *MyPlayer);
NetSendCmdLocParam1(false, CMD_MONSTDEATH, monster.position.tile, monster.getId());
return;
}
delta_monster_hp(monster, *MyPlayer);
NetSendCmdMonDmg(false, monster.getId(), damage);
PlayEffect(monster, MonsterSound::Hit);
}
void MonsterAttackMonster(Monster &attacker, Monster &target, int hper, int mind, int maxd)
{
if (!target.isPossibleToHit())
@ -1112,14 +1097,14 @@ void MonsterAttackMonster(Monster &attacker, Monster &target, int hper, int mind
}
}
void CheckReflect(Monster &monster, Player &player, int dam)
void CheckReflect(Monster &monster, Player &player, int &dam)
{
player.wReflections--;
if (player.wReflections <= 0)
NetSendCmdParam1(true, CMD_SETREFLECT, 0);
// reflects 20-30% damage
int mdam = dam * (GenerateRnd(10) + 20L) / 100;
monster.hitPoints -= mdam;
ApplyMonsterDamage(monster, mdam);
dam = std::max(dam - mdam, 0);
if (monster.hitPoints >> 6 <= 0)
M_StartKill(monster, player);
@ -1198,7 +1183,7 @@ void MonsterAttackPlayer(Monster &monster, Player &player, int hit, int minDam,
// Reflect can also kill a monster, so make sure the monster is still alive
if (HasAnyOf(player._pIFlags, ItemSpecialEffect::Thorns) && monster.mode != MonsterMode::Death) {
int mdam = (GenerateRnd(3) + 1) << 6;
monster.hitPoints -= mdam;
ApplyMonsterDamage(monster, mdam);
if (monster.hitPoints >> 6 <= 0)
M_StartKill(monster, player);
else
@ -3587,6 +3572,20 @@ void AddDoppelganger(Monster &monster)
}
}
void ApplyMonsterDamage(Monster &monster, int damage)
{
monster.hitPoints -= damage;
if (monster.hitPoints >> 6 <= 0) {
delta_kill_monster(monster, monster.position.tile, *MyPlayer);
NetSendCmdLocParam1(false, CMD_MONSTDEATH, monster.position.tile, monster.getId());
return;
}
delta_monster_hp(monster, *MyPlayer);
NetSendCmdMonDmg(false, monster.getId(), damage);
}
bool M_Talker(const Monster &monster)
{
return IsAnyOf(monster.ai, AI_LAZARUS, AI_WARLORD, AI_GARBUD, AI_ZHAR, AI_SNOTSPIL, AI_LACHDAN, AI_LAZHELP);
@ -3629,6 +3628,8 @@ void M_GetKnockback(Monster &monster)
void M_StartHit(Monster &monster, int dam)
{
PlayEffect(monster, MonsterSound::Hit);
if (IsAnyOf(monster.type().type, MT_SNEAK, MT_STALKER, MT_UNSEEN, MT_ILLWEAV) || dam >> 6 >= monster.level + 3) {
if (monster.type().type == MT_BLINK) {
Teleport(monster);
@ -3646,10 +3647,6 @@ void M_StartHit(Monster &monster, int dam)
void M_StartHit(Monster &monster, const Player &player, int dam)
{
monster.tag(player);
if (&player == MyPlayer) {
delta_monster_hp(monster, *MyPlayer);
NetSendCmdMonDmg(false, monster.getId(), dam);
}
if (IsAnyOf(monster.type().type, MT_SNEAK, MT_STALKER, MT_UNSEEN, MT_ILLWEAV) || dam >> 6 >= monster.level + 3) {
monster.enemy = player.getId();
monster.enemyPosition = player.position.future;
@ -3657,7 +3654,6 @@ void M_StartHit(Monster &monster, const Player &player, int dam)
monster.direction = GetMonsterDirection(monster);
}
PlayEffect(monster, MonsterSound::Hit);
M_StartHit(monster, dam);
}
@ -3702,18 +3698,16 @@ void StartMonsterDeath(Monster &monster, const Player &player, bool sendmsg)
MonsterDeath(monster, md, sendmsg);
}
void M_StartKill(Monster &monster, const Player &player)
void KillMyGolem()
{
if (&player == MyPlayer) {
delta_kill_monster(monster, monster.position.tile, *MyPlayer);
size_t monsterId = monster.getId();
if (monsterId != player.getId()) {
NetSendCmdLocParam1(false, CMD_MONSTDEATH, monster.position.tile, monsterId);
} else {
NetSendCmdLoc(MyPlayerId, false, CMD_KILLGOLEM, monster.position.tile);
}
}
Monster &golem = Monsters[MyPlayerId];
delta_kill_monster(golem, golem.position.tile, *MyPlayer);
NetSendCmdLoc(MyPlayerId, false, CMD_KILLGOLEM, golem.position.tile);
M_StartKill(golem, *MyPlayer);
}
void M_StartKill(Monster &monster, const Player &player)
{
StartMonsterDeath(monster, player, true);
}
@ -4331,10 +4325,6 @@ void MissToMonst(Missile &missile, Point position)
monster.direction = static_cast<Direction>(missile._mimfnum);
monster.position.tile = position;
M_StartStand(monster, monster.direction);
if ((monster.flags & MFLAG_TARGETS_MONSTER) == 0)
PlayEffect(monster, MonsterSound::Hit);
else
ApplyMonsterDamage(monster, 0);
M_StartHit(monster, 0);
if (monster.type().type == MT_GLOOM)

2
Source/monster.h

@ -383,6 +383,7 @@ void InitMonsters();
void SetMapMonsters(const uint16_t *dunData, Point startPosition);
Monster *AddMonster(Point position, Direction dir, size_t mtype, bool inMap);
void AddDoppelganger(Monster &monster);
void ApplyMonsterDamage(Monster &monster, int damage);
bool M_Talker(const Monster &monster);
void M_StartStand(Monster &monster, Direction md);
void M_ClearSquares(const Monster &monster);
@ -391,6 +392,7 @@ void M_StartHit(Monster &monster, int dam);
void M_StartHit(Monster &monster, const Player &player, int dam);
void StartMonsterDeath(Monster &monster, const Player &player, bool sendmsg);
void MonsterDeath(Monster &monster, Direction md, bool sendmsg);
void KillMyGolem();
void M_StartKill(Monster &monster, const Player &player);
void M_SyncStartKill(Monster &monster, Point position, const Player &player);
void M_UpdateRelations(const Monster &monster);

4
Source/player.cpp

@ -821,7 +821,7 @@ bool PlrHitMonst(Player &player, Monster &monster, bool adjacentDamage = false)
}
dam *= 2;
}
monster.hitPoints -= dam;
ApplyMonsterDamage(monster, dam);
}
int skdam = 0;
@ -3063,7 +3063,7 @@ void RemovePlrMissiles(const Player &player)
if (leveltype != DTYPE_TOWN && &player == MyPlayer) {
Monster &golem = Monsters[MyPlayerId];
if (golem.position.tile.x != 1 || golem.position.tile.y != 0) {
M_StartKill(golem, player);
KillMyGolem();
AddCorpse(golem.position.tile, golem.type().corpseId, golem.direction);
int mx = golem.position.tile.x;
int my = golem.position.tile.y;

Loading…
Cancel
Save