Skip to content

Commit

Permalink
Add persistence to /backupstyle
Browse files Browse the repository at this point in the history
Added `NpcStyleComponent`, `PlayerStyleComponent` classes.
  • Loading branch information
bm01 committed Nov 7, 2024
1 parent 46b3cb6 commit 9fbc727
Show file tree
Hide file tree
Showing 9 changed files with 403 additions and 295 deletions.
2 changes: 1 addition & 1 deletion CoreBase/Network/BaseServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void FreeBufferPosition()
catch (SocketException e)
{
if (log.IsDebugEnabled)
log.Error($"Socket exception on UDP receive (Code: {e.SocketErrorCode})");
log.Debug($"Socket exception on UDP receive (Code: {e.SocketErrorCode})");
}
catch (Exception e)
{
Expand Down
101 changes: 47 additions & 54 deletions CoreDatabase/Tables/DbCoreCharacter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ public class DbCoreCharacter : DataObject
private int m_mithril;
private int m_currentModel;

private int m_constitution = 0;
private int m_dexterity = 0;
private int m_strength = 0;
private int m_quickness = 0;
private int m_intelligence = 0;
private int m_piety = 0;
private int m_empathy = 0;
private int m_charisma = 0;
private int m_constitution;
private int m_dexterity;
private int m_strength;
private int m_quickness;
private int m_intelligence;
private int m_piety;
private int m_empathy;
private int m_charisma;

//This needs to be uint and ushort!
private int m_xpos;
Expand Down Expand Up @@ -130,19 +130,19 @@ public class DbCoreCharacter : DataObject
private bool m_isLevelRespecUsed;
private int m_respecBought; // /respec buy
private bool m_safetyFlag;
private int m_craftingPrimarySkill = 0;
private int m_craftingPrimarySkill;
private bool m_cancelStyle;
private bool m_isAnonymous;

private byte m_customisationStep = 1;
private byte m_customisationStep;

private byte m_eyesize = 0;
private byte m_lipsize = 0;
private byte m_eyecolor = 0;
private byte m_hairColor = 0;
private byte m_facetype = 0;
private byte m_hairstyle = 0;
private byte m_moodtype = 0;
private byte m_eyesize;
private byte m_lipsize;
private byte m_eyecolor;
private byte m_hairColor;
private byte m_facetype;
private byte m_hairstyle;
private byte m_moodtype;

private bool m_gainXP;
private bool m_gainRP;
Expand All @@ -167,15 +167,15 @@ public class DbCoreCharacter : DataObject
private bool m_mlGranted;

// Should this player stats be ignored when tabulating statistics?
private bool m_ignoreStatistics = false;
private bool m_ignoreStatistics;

// What should the Herald display of this character?
private byte m_notDisplayedInHerald = 0;
private byte m_notDisplayedInHerald;

// Should we hide the detailed specialization of this player in the APIs?
private bool m_hideSpecializationAPI;

private byte m_activeSaddleBags = 0;
private byte m_activeSaddleBags;

private DateTime m_lastLevelUp;

Expand All @@ -188,46 +188,28 @@ public class DbCoreCharacter : DataObject
private bool m_receiveROG; // toggle receiving ROGs for the player
private bool m_boosted; // set to true if player has used a free level/rr NPC

// Controls automation
private ushort _automaticBackupStyleId;

/// <summary>
/// Create the character row in table
/// </summary>
public DbCoreCharacter()
{
m_creationDate = DateTime.Now;
m_concentration = 100;
m_exp = 0;
m_bntyPts = 0;
m_realmPts = 0;

m_lastPlayed = DateTime.Now; // Prevent /played crash.
m_playedTime = 0; // /played startup
m_deathTime = long.MinValue;
m_respecAmountAllSkill = 0;
m_respecAmountSingleSkill = 0;
m_respecAmountRealmSkill = 0;
m_respecAmountDOL = 0;
m_respecBought = 0;

m_isLevelRespecUsed = true;
m_safetyFlag = true;
m_craftingPrimarySkill = 0;
m_usedLevelCommand = false;
m_spellQueue = true;
m_gainXP = true;
m_gainRP = true;
m_autoloot = true;
m_showXFireInfo = false;
m_noHelp = false;
m_showGuildLogins = false;
m_roleplay = false;
m_ignoreStatistics = false;
{
m_creationDate = DateTime.Now;
m_concentration = 100;
m_lastPlayed = DateTime.Now; // Prevent /played crash.
m_deathTime = long.MinValue;
m_isLevelRespecUsed = true;
m_customisationStep = 1;
m_safetyFlag = true;
m_spellQueue = true;
m_gainXP = true;
m_gainRP = true;
m_autoloot = true;
m_lastLevelUp = DateTime.Now;
m_playedTimeSinceLevel = 0;
m_receiveROG = true;
m_hardcore = false;
m_hardcoreCompleted = false;
m_boosted = false;
}
}

/// <summary>
/// Gets/sets if this character has xp in a gravestone
Expand Down Expand Up @@ -2249,6 +2231,17 @@ public bool isBoosted
}
}

[DataElement(AllowDbNull = false)]
public ushort AutomaticBackupStyleId
{
get => _automaticBackupStyleId;
set
{
Dirty = true;
_automaticBackupStyleId = value;
}
}

/// <summary>
/// Do we ignore all statistics for this player?
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion GameServer/ECS-Components/Actions/NpcAttackAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected override bool PrepareMeleeAttack()
}
}

_combatStyle = StyleComponent.NPCGetStyleToUse();
_combatStyle = StyleComponent.GetStyleToUse();

if (!base.PrepareMeleeAttack())
return false;
Expand Down
86 changes: 86 additions & 0 deletions GameServer/ECS-Components/NpcStyleComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using DOL.GS.ServerProperties;
using DOL.GS.Styles;

namespace DOL.GS
{
public class NpcStyleComponent : StyleComponent
{
private GameNPC _npcOwner;

public NpcStyleComponent(GameNPC npcOwner) : base(npcOwner)
{
_npcOwner = npcOwner;
}

public override Style GetStyleToUse()
{
if (_npcOwner.Styles == null || _npcOwner.Styles.Count < 1 || _npcOwner.TargetObject == null)
return null;

AttackData lastAttackData = _npcOwner.attackComponent.attackAction.LastAttackData;

// Chain and defensive styles are excluded from the chance roll because they would almost never happen otherwise.
// For example, an NPC blocks 10% of the time, so the default 20% style chance effectively means the defensive
// style would only actually occur during 2% of of a mob's attacks. In comparison, a style chain would only happen
// 0.4% of the time.
if (_npcOwner.StylesChain != null && _npcOwner.StylesChain.Count > 0)
{
foreach (Style style in _npcOwner.StylesChain)
{
if (StyleProcessor.CanUseStyle(lastAttackData, _npcOwner, style, _npcOwner.ActiveWeapon))
return style;
}
}

if (_npcOwner.StylesDefensive != null && _npcOwner.StylesDefensive.Count > 0)
{
foreach (Style style in _npcOwner.StylesDefensive)
{
if (StyleProcessor.CanUseStyle(lastAttackData, _npcOwner, style, _npcOwner.ActiveWeapon) && _npcOwner.CheckStyleStun(style)) // Make sure we don't spam stun styles like Brutalize
return style;
}
}

if (Util.Chance(Properties.GAMENPC_CHANCES_TO_STYLE))
{
// All of the remaining lists are randomly picked from,
// as this creates more variety with each combat result.
// For example, a mob with both Pincer and Ice Storm
// styles could potentially use one or the other with
// each attack roll that succeeds.

// First, check positional styles (in order of back, side, front)
// in case the defender is facing another direction
if (_npcOwner.StylesBack != null && _npcOwner.StylesBack.Count > 0)
{
Style style = _npcOwner.StylesBack[Util.Random(0, _npcOwner.StylesBack.Count - 1)];

if (StyleProcessor.CanUseStyle(lastAttackData, _npcOwner, style, _npcOwner.ActiveWeapon))
return style;
}

if (_npcOwner.StylesSide != null && _npcOwner.StylesSide.Count > 0)
{
Style style = _npcOwner.StylesSide[Util.Random(0, _npcOwner.StylesSide.Count - 1)];

if (StyleProcessor.CanUseStyle(lastAttackData, _npcOwner, style, _npcOwner.ActiveWeapon))
return style;
}

if (_npcOwner.StylesFront != null && _npcOwner.StylesFront.Count > 0)
{
Style style = _npcOwner.StylesFront[Util.Random(0, _npcOwner.StylesFront.Count - 1)];

if (StyleProcessor.CanUseStyle(lastAttackData, _npcOwner, style, _npcOwner.ActiveWeapon))
return style;
}

// Pick a random anytime style
if (_npcOwner.StylesAnytime != null && _npcOwner.StylesAnytime.Count > 0)
return _npcOwner.StylesAnytime[Util.Random(0, _npcOwner.StylesAnytime.Count - 1)];
}

return null;
}
}
}
Loading

0 comments on commit 9fbc727

Please sign in to comment.