[Client] Compare crimeTime and deathTime when NPCs forgive player crimes

Previously, all crime witnesses stopped being hostile to a respawning player for as long as the player's diedSinceArrestAttempt was true. That meant that, in an area with no guards to arrest the player, crime witnesses did not enage in combat with the player at all ever again until diedSinceArrestAttempt became false.

This commit makes it so the time of the last crime is recorded for each witness, and that is then compared with the time of the LocalPlayer's last death for a one-time crime forgiveness during that player's current life.

This is essentially a gameplay adjustment for "singleplayer with respawns," and will have to be reworked to make sense for every player in multiplayer, though that requires reworking the crime system as a whole and is thus on hold.
0.6.3
David Cernat 7 years ago
parent c23fc3446f
commit 4b30a44816

@ -1197,16 +1197,22 @@ namespace MWMechanics
/* /*
Start of tes3mp addition Start of tes3mp addition
If the player has died, stop combat with them as though they had If the player has died since their crime was committed, stop combat
paid their bounty with them as though they have paid their bounty
*/ */
else if (mwmp::Main::get().getLocalPlayer()->diedSinceArrestAttempt) else if (mwmp::Main::get().getLocalPlayer()->diedSinceArrestAttempt && creatureStats.getAiSequence().isInCombat(player))
{ {
if (creatureStats.getAiSequence().isInCombat(player)) if (difftime(mwmp::Main::get().getLocalPlayer()->deathTime, npcStats.getCrimeTime()))
{ {
creatureStats.getAiSequence().stopCombat(); creatureStats.getAiSequence().stopCombat();
creatureStats.setAttacked(false); creatureStats.setAttacked(false);
creatureStats.setAlarmed(false); creatureStats.setAlarmed(false);
creatureStats.setAiSetting(CreatureStats::AI_Fight, ptr.getClass().getBaseFightRating(ptr));
npcStats.setCrimeId(-1);
npcStats.setCrimeTime(time(0));
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "NPC %s %i-%i has forgiven player's crimes after the player's death",
ptr.getCellRef().getRefId().c_str(), ptr.getCellRef().getRefNum().mIndex, ptr.getCellRef().getMpNum());
} }
} }
/* /*

@ -324,6 +324,25 @@ void MWMechanics::NpcStats::setSkillIncrease(int attribute, int value)
End of tes3mp addition End of tes3mp addition
*/ */
/*
Start of tes3mp addition
Make it possible to get and set the time of the last crime witnessed by the NPC,
used to stop combat with a player after that player dies and is resurrected
*/
std::time_t MWMechanics::NpcStats::getCrimeTime()
{
return mCrimeTime;
}
void MWMechanics::NpcStats::setCrimeTime(std::time_t crimeTime)
{
mCrimeTime = crimeTime;
}
/*
End of tes3mp addition
*/
void MWMechanics::NpcStats::levelUp() void MWMechanics::NpcStats::levelUp()
{ {
const MWWorld::Store<ESM::GameSetting> &gmst = const MWWorld::Store<ESM::GameSetting> &gmst =
@ -412,6 +431,17 @@ int MWMechanics::NpcStats::getCrimeId() const
void MWMechanics::NpcStats::setCrimeId(int id) void MWMechanics::NpcStats::setCrimeId(int id)
{ {
mCrimeId = id; mCrimeId = id;
/*
Start of tes3mp addition
Record this as the time of the last crime witnessed by this NPC
*/
if (id != -1)
setCrimeTime(time(0));
/*
End of tes3mp addition
*/
} }
bool MWMechanics::NpcStats::hasSkillsForRank (const std::string& factionId, int rank) const bool MWMechanics::NpcStats::hasSkillsForRank (const std::string& factionId, int rank) const

@ -6,6 +6,16 @@
#include <string> #include <string>
#include <vector> #include <vector>
/*
Start of tes3mp addition
Include additional headers for multiplayer purposes
*/
#include <time.h>
/*
End of tes3mp addition
*/
#include "creaturestats.hpp" #include "creaturestats.hpp"
namespace ESM namespace ESM
@ -26,6 +36,16 @@ namespace MWMechanics
int mReputation; int mReputation;
int mCrimeId; int mCrimeId;
/*
Start of tes3mp addition
Add a variable used to track the time of the most recent crime by a player
*/
time_t mCrimeTime = time(0);
/*
End of tes3mp addition
*/
// ----- used by the player only, maybe should be moved at some point ------- // ----- used by the player only, maybe should be moved at some point -------
int mBounty; int mBounty;
int mWerewolfKills; int mWerewolfKills;
@ -97,6 +117,18 @@ namespace MWMechanics
End of tes3mp addition End of tes3mp addition
*/ */
/*
Start of tes3mp addition
Make it possible to get and set the time of the last crime witnessed by the NPC,
used to stop combat with a player after that player dies and is resurrected
*/
time_t getCrimeTime();
void setCrimeTime(time_t crimeTime);
/*
End of tes3mp addition
*/
int getLevelupAttributeMultiplier(int attribute) const; int getLevelupAttributeMultiplier(int attribute) const;
int getSkillIncreasesForSpecialization(int spec) const; int getSkillIncreasesForSpecialization(int spec) const;

@ -44,6 +44,8 @@ using namespace std;
LocalPlayer::LocalPlayer() LocalPlayer::LocalPlayer()
{ {
deathTime = time(0);
charGenState.currentStage = 0; charGenState.currentStage = 0;
charGenState.endStage = 1; charGenState.endStage = 1;
charGenState.isFinished = false; charGenState.isFinished = false;
@ -800,6 +802,9 @@ void LocalPlayer::resurrect()
// Record that the player has died since the last attempt was made to arrest them, // Record that the player has died since the last attempt was made to arrest them,
// used to make guards lenient enough to attempt an arrest again // used to make guards lenient enough to attempt an arrest again
diedSinceArrestAttempt = true; diedSinceArrestAttempt = true;
deathTime = time(0);
LOG_APPEND(Log::LOG_INFO, "- diedSinceArrestAttempt is now true"); LOG_APPEND(Log::LOG_INFO, "- diedSinceArrestAttempt is now true");
// Record that we are no longer a known werewolf, to avoid being attacked infinitely // Record that we are no longer a known werewolf, to avoid being attacked infinitely

@ -15,6 +15,8 @@ namespace mwmp
LocalPlayer(); LocalPlayer();
virtual ~LocalPlayer(); virtual ~LocalPlayer();
time_t deathTime;
void update(); void update();
bool processCharGen(); bool processCharGen();

Loading…
Cancel
Save