[Character] Record character stats to character_stats_record table (#3522)

* [Character] Record character stats to

* Record stats on disconnect as well

* Record later in connect process

* Move enter zone code path so we're after bonuses

* Ok this spot for real

* Adjust recording

* Update client_packet.cpp

* Timestamps

* Update database_update_manifest.cpp

* Update client_packet.cpp

* Fix stat bonuses
This commit is contained in:
Chris Miles 2023-08-05 12:55:59 -05:00 committed by GitHub
parent e24d82f0fe
commit 714b474d2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 1294 additions and 1 deletions

View File

@ -4845,6 +4845,93 @@ UPDATE data_buckets SET bot_id = SUBSTRING_INDEX(SUBSTRING_INDEX( `key`, '-', 2
ADD COLUMN `marked_npc_3_instance_id` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `marked_npc_3_zone_id`;
)"
},
ManifestEntry{
.version = 9235,
.description = "2023_07_31_character_stats_record.sql",
.check = "SHOW TABLES LIKE 'character_stats_record'",
.condition = "empty",
.match = "",
.sql = R"(
CREATE TABLE `character_stats_record` (
`character_id` int NULL,
`name` varchar(100) NULL,
`status` int NULL DEFAULT 0,
`level` int NULL DEFAULT 0,
`class` int NULL DEFAULT 0,
`race` int NULL DEFAULT 0,
`aa_points` int NULL DEFAULT 0,
`hp` bigint NULL DEFAULT 0,
`mana` bigint NULL DEFAULT 0,
`endurance` bigint NULL DEFAULT 0,
`ac` int NULL DEFAULT 0,
`strength` int NULL DEFAULT 0,
`stamina` int NULL DEFAULT 0,
`dexterity` int NULL DEFAULT 0,
`agility` int NULL DEFAULT 0,
`intelligence` int NULL DEFAULT 0,
`wisdom` int NULL DEFAULT 0,
`charisma` int NULL DEFAULT 0,
`magic_resist` int NULL DEFAULT 0,
`fire_resist` int NULL DEFAULT 0,
`cold_resist` int NULL DEFAULT 0,
`poison_resist` int NULL DEFAULT 0,
`disease_resist` int NULL DEFAULT 0,
`corruption_resist` int NULL DEFAULT 0,
`heroic_strength` int NULL DEFAULT 0,
`heroic_stamina` int NULL DEFAULT 0,
`heroic_dexterity` int NULL DEFAULT 0,
`heroic_agility` int NULL DEFAULT 0,
`heroic_intelligence` int NULL DEFAULT 0,
`heroic_wisdom` int NULL DEFAULT 0,
`heroic_charisma` int NULL DEFAULT 0,
`heroic_magic_resist` int NULL DEFAULT 0,
`heroic_fire_resist` int NULL DEFAULT 0,
`heroic_cold_resist` int NULL DEFAULT 0,
`heroic_poison_resist` int NULL DEFAULT 0,
`heroic_disease_resist` int NULL DEFAULT 0,
`heroic_corruption_resist` int NULL DEFAULT 0,
`haste` int NULL DEFAULT 0,
`accuracy` int NULL DEFAULT 0,
`attack` int NULL DEFAULT 0,
`avoidance` int NULL DEFAULT 0,
`clairvoyance` int NULL DEFAULT 0,
`combat_effects` int NULL DEFAULT 0,
`damage_shield_mitigation` int NULL DEFAULT 0,
`damage_shield` int NULL DEFAULT 0,
`dot_shielding` int NULL DEFAULT 0,
`hp_regen` int NULL DEFAULT 0,
`mana_regen` int NULL DEFAULT 0,
`endurance_regen` int NULL DEFAULT 0,
`shielding` int NULL DEFAULT 0,
`spell_damage` int NULL DEFAULT 0,
`spell_shielding` int NULL DEFAULT 0,
`strikethrough` int NULL DEFAULT 0,
`stun_resist` int NULL DEFAULT 0,
`backstab` int NULL DEFAULT 0,
`wind` int NULL DEFAULT 0,
`brass` int NULL DEFAULT 0,
`string` int NULL DEFAULT 0,
`percussion` int NULL DEFAULT 0,
`singing` int NULL DEFAULT 0,
`baking` int NULL DEFAULT 0,
`alchemy` int NULL DEFAULT 0,
`tailoring` int NULL DEFAULT 0,
`blacksmithing` int NULL DEFAULT 0,
`fletching` int NULL DEFAULT 0,
`brewing` int NULL DEFAULT 0,
`jewelry` int NULL DEFAULT 0,
`pottery` int NULL DEFAULT 0,
`research` int NULL DEFAULT 0,
`alcohol` int NULL DEFAULT 0,
`fishing` int NULL DEFAULT 0,
`tinkering` int NULL DEFAULT 0,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`character_id`)
);
)"
},
// -- template; copy/paste this when you need to create a new entry
// ManifestEntry{

View File

@ -66,6 +66,7 @@ namespace DatabaseSchema {
{"character_potionbelt", "id"},
{"character_skills", "id"},
{"character_spells", "id"},
{"character_stats_record", "character_id"},
{"character_task_timers", "character_id"},
{"character_tasks", "charid"},
{"character_tribute", "character_id"},

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,50 @@
#ifndef EQEMU_CHARACTER_STATS_RECORD_REPOSITORY_H
#define EQEMU_CHARACTER_STATS_RECORD_REPOSITORY_H
#include "../database.h"
#include "../strings.h"
#include "base/base_character_stats_record_repository.h"
class CharacterStatsRecordRepository: public BaseCharacterStatsRecordRepository {
public:
/**
* This file was auto generated and can be modified and extended upon
*
* Base repository methods are automatically
* generated in the "base" version of this repository. The base repository
* is immutable and to be left untouched, while methods in this class
* are used as extension methods for more specific persistence-layer
* accessors or mutators.
*
* Base Methods (Subject to be expanded upon in time)
*
* Note: Not all tables are designed appropriately to fit functionality with all base methods
*
* InsertOne
* UpdateOne
* DeleteOne
* FindOne
* GetWhere(std::string where_filter)
* DeleteWhere(std::string where_filter)
* InsertMany
* All
*
* Example custom methods in a repository
*
* CharacterStatsRecordRepository::GetByZoneAndVersion(int zone_id, int zone_version)
* CharacterStatsRecordRepository::GetWhereNeverExpires()
* CharacterStatsRecordRepository::GetWhereXAndY()
* CharacterStatsRecordRepository::DeleteWhereXAndY()
*
* Most of the above could be covered by base methods, but if you as a developer
* find yourself re-using logic for other parts of the code, its best to just make a
* method that can be re-used easily elsewhere especially if it can use a base repository
* method and encapsulate filters there
*/
// Custom extended repository methods here
};
#endif //EQEMU_CHARACTER_STATS_RECORD_REPOSITORY_H

View File

@ -42,7 +42,7 @@
* Manifest: https://github.com/EQEmu/Server/blob/master/utils/sql/db_update_manifest.txt
*/
#define CURRENT_BINARY_DATABASE_VERSION 9234
#define CURRENT_BINARY_DATABASE_VERSION 9235
#define CURRENT_BINARY_BOTS_DATABASE_VERSION 9039

View File

@ -6458,3 +6458,8 @@ int64 Mob::GetManaRegen() const
{
return mana_regen;
}
int64 Mob::GetEnduranceRegen() const
{
return 0; // not implemented
}

View File

@ -233,6 +233,7 @@ public:
~Client();
void ReconnectUCS();
void RecordStats();
void SetDisplayMobInfoWindow(bool display_mob_info_window);
bool GetDisplayMobInfoWindow() const;

View File

@ -62,6 +62,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "../common/repositories/account_repository.h"
#include "../common/events/player_event_logs.h"
#include "../common/repositories/character_stats_record_repository.h"
extern QueryServ* QServ;
extern Zone* zone;
@ -915,6 +916,8 @@ void Client::CompleteConnect()
heroforge_wearchange_timer.Start(250);
RecordStats();
// enforce some rules..
if (!CanEnterZone()) {
LogInfo("Kicking character [{}] from zone, not allowed here (missing requirements)", GetCleanName());
@ -16392,3 +16395,91 @@ void Client::Handle_OP_RaidClearNPCMarks(const EQApplicationPacket* app)
r->RaidClearNPCMarks(this);
}
}
void Client::RecordStats()
{
auto r = CharacterStatsRecordRepository::FindOne(
database,
CharacterID()
);
r.status = Admin();
r.name = GetCleanName();
r.aa_points = GetAAPoints() + GetSpentAA();
r.level = GetLevel();
r.class_ = GetBaseClass();
r.race = GetBaseRace();
r.hp = GetMaxHP() - GetSpellBonuses().HP;
r.mana = GetMaxMana() - GetSpellBonuses().Mana;
r.endurance = GetMaxEndurance() - GetSpellBonuses().Endurance;
r.ac = GetDisplayAC() - GetSpellBonuses().AC;
r.strength = GetSTR() - GetSpellBonuses().STR;
r.stamina = GetSTA() - GetSpellBonuses().STA;
r.dexterity = GetDEX() - GetSpellBonuses().DEX;
r.agility = GetAGI() - GetSpellBonuses().AGI;
r.intelligence = GetINT() - GetSpellBonuses().INT;
r.wisdom = GetWIS() - GetSpellBonuses().WIS;
r.charisma = GetCHA() - GetSpellBonuses().CHA;
r.magic_resist = GetMR() - GetSpellBonuses().MR;
r.fire_resist = GetFR() - GetSpellBonuses().FR;
r.cold_resist = GetCR() - GetSpellBonuses().CR;
r.poison_resist = GetPR() - GetSpellBonuses().PR;
r.disease_resist = GetDR() - GetSpellBonuses().DR;
r.corruption_resist = GetCorrup() - GetSpellBonuses().Corrup;
r.heroic_strength = GetHeroicSTR() - GetSpellBonuses().HeroicSTR;
r.heroic_stamina = GetHeroicSTA() - GetSpellBonuses().HeroicSTA;
r.heroic_dexterity = GetHeroicDEX() - GetSpellBonuses().HeroicDEX;
r.heroic_agility = GetHeroicAGI() - GetSpellBonuses().HeroicAGI;
r.heroic_intelligence = GetHeroicINT() - GetSpellBonuses().HeroicINT;
r.heroic_wisdom = GetHeroicWIS() - GetSpellBonuses().HeroicWIS;
r.heroic_charisma = GetHeroicCHA() - GetSpellBonuses().HeroicCHA;
r.heroic_magic_resist = GetHeroicMR() - GetSpellBonuses().HeroicMR;
r.heroic_fire_resist = GetHeroicFR() - GetSpellBonuses().HeroicFR;
r.heroic_cold_resist = GetHeroicCR() - GetSpellBonuses().HeroicCR;
r.heroic_poison_resist = GetHeroicPR() - GetSpellBonuses().HeroicPR;
r.heroic_disease_resist = GetHeroicDR() - GetSpellBonuses().HeroicDR;
r.heroic_corruption_resist = GetHeroicCorrup() - GetSpellBonuses().HeroicCorrup;
r.haste = GetHaste();
r.accuracy = GetAccuracy() - GetSpellBonuses().Accuracy[EQ::skills::HIGHEST_SKILL + 1];
r.attack = GetTotalATK() - GetSpellBonuses().ATK;
r.avoidance = GetAvoidance() - GetSpellBonuses().AvoidMeleeChance;
r.clairvoyance = GetClair() - GetSpellBonuses().Clairvoyance;
r.combat_effects = GetCombatEffects() - GetSpellBonuses().ProcChance;
r.damage_shield_mitigation = GetDSMit() - GetSpellBonuses().DSMitigation;
r.damage_shield = GetDS() - GetSpellBonuses().DamageShield;
r.dot_shielding = GetDoTShield() - GetSpellBonuses().DoTShielding;
r.hp_regen = GetHPRegen() - GetSpellBonuses().HPRegen;
r.mana_regen = GetManaRegen() - GetSpellBonuses().ManaRegen;
r.endurance_regen = GetEnduranceRegen() - GetSpellBonuses().EnduranceRegen;
r.shielding = GetShielding() - GetSpellBonuses().MeleeMitigation;
r.spell_damage = GetSpellDmg() - GetSpellBonuses().SpellDmg;
r.spell_shielding = GetSpellShield() - GetSpellBonuses().SpellShield;
r.strikethrough = GetStrikeThrough() - GetSpellBonuses().StrikeThrough;
r.stun_resist = GetStunResist() - GetSpellBonuses().StunResist;
r.backstab = 0;
r.wind = GetWindMod();
r.brass = GetBrassMod();
r.string = GetStringMod();
r.percussion = GetPercMod();
r.singing = GetSingMod();
r.baking = GetSkill(EQ::skills::SkillType::SkillBaking);
r.alchemy = GetSkill(EQ::skills::SkillType::SkillAlchemy);
r.jewelry = GetSkill(EQ::skills::SkillType::SkillJewelryMaking);
r.tailoring = GetSkill(EQ::skills::SkillType::SkillTailoring);
r.blacksmithing = GetSkill(EQ::skills::SkillType::SkillBlacksmithing);
r.fletching = GetSkill(EQ::skills::SkillType::SkillFletching);
r.brewing = GetSkill(EQ::skills::SkillType::SkillBrewing);
r.fishing = GetSkill(EQ::skills::SkillType::SkillFishing);
r.pottery = GetSkill(EQ::skills::SkillType::SkillPottery);
r.alcohol = GetSkill(EQ::skills::SkillType::SkillAlcoholTolerance);
r.tinkering = GetSkill(EQ::skills::SkillType::SkillTinkering);
r.updated_at = std::time(nullptr);
if (r.character_id > 0) {
CharacterStatsRecordRepository::UpdateOne(database, r);
} else {
r.character_id = CharacterID();
r.created_at = std::time(nullptr);
CharacterStatsRecordRepository::InsertOne(database, r);
}
}

View File

@ -741,6 +741,8 @@ void Client::OnDisconnect(bool hard_disconnect) {
parse->EventPlayer(EVENT_DISCONNECT, this, "", 0);
}
RecordStats();
Disconnect();
}

View File

@ -1402,6 +1402,7 @@ public:
int64 GetHPRegen() const;
int64 GetHPRegenPerSecond() const;
int64 GetManaRegen() const;
int64 GetEnduranceRegen() const;
bool CanOpenDoors() const;
void SetCanOpenDoors(bool can_open);