Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] adding preliminary calcs for allegiance passup xp realtime and gametime factors #2345

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions Source/ACE.Server/Entity/AllegianceNode.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ACE.Common;
using ACE.Entity;
using ACE.Server.Managers;
using ACE.Server.WorldObjects;
Expand Down Expand Up @@ -117,5 +118,67 @@ public void OnLevelUp()
vassal.Player.ExistedBeforeAllegianceXpChanges = true;
}
}

/// <summary>
/// Returns the amount of realtime sworn to patron
/// </summary>
public TimeSpan CalculateRealTime()
{
if (Patron == null)
return TimeSpan.Zero;

// TODO: figure out better handling for legacy players
// with AllegianceSwearTimestamp null
var now = Time.GetUnixTime();
var timestamp = Player.AllegianceSwearTimestamp ?? now;

return TimeSpan.FromSeconds(now - timestamp);
}

/// <summary>
/// Returns the amount of gametime sworn to patron
/// </summary>
public TimeSpan CalculateGameTime()
{
if (Patron == null)
return TimeSpan.Zero;

// TODO: figure out better handling for legacy players
// with AllegianceSwearAge null
var current_age = Player.Age ?? 0;
var swear_age = Player.AllegianceSwearAge ?? current_age;

return TimeSpan.FromSeconds(current_age - swear_age);
}

/// <summary>
/// Returns the average amount of realtime vassals sworn
/// </summary>
public TimeSpan CalculateRealTime_VassalAvg()
{
if (!HasVassals)
return TimeSpan.Zero;

var total = TimeSpan.Zero;
foreach (var vassal in Vassals.Values)
total += vassal.CalculateRealTime();

return total / Vassals.Count;
}

/// <summary>
/// Returns the average amount of gametime vassals sworn
/// </summary>
public TimeSpan CalculateGameTime_VassalAvg()
{
if (!HasVassals)
return TimeSpan.Zero;

var total = TimeSpan.Zero;
foreach (var vassal in Vassals.Values)
total += vassal.CalculateGameTime();

return total / Vassals.Count;
}
}
}
6 changes: 6 additions & 0 deletions Source/ACE.Server/Entity/IPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ public interface IPlayer

int? HouseRentTimestamp { get; set; }

int? Age { get; set; }

int? AllegianceSwearAge { get; set; }

double? AllegianceSwearTimestamp { get; set; }


uint GetCurrentLoyalty();

Expand Down
19 changes: 19 additions & 0 deletions Source/ACE.Server/Entity/OfflinePlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,25 @@ public int? AllegianceOfficerRank
set { if (!value.HasValue) RemoveProperty(PropertyInt.AllegianceOfficerRank); else SetProperty(PropertyInt.AllegianceOfficerRank, value.Value); }
}

public int? Age
{
get => GetProperty(PropertyInt.Age);
set { if (!value.HasValue) RemoveProperty(PropertyInt.Age); else SetProperty(PropertyInt.Age, value.Value); }
}

public int? AllegianceSwearAge
{
get => GetProperty(PropertyInt.AllegianceSwearTimestamp);
set { if (!value.HasValue) RemoveProperty(PropertyInt.AllegianceSwearTimestamp); else SetProperty(PropertyInt.AllegianceSwearTimestamp, value.Value); }
}

public double? AllegianceSwearTimestamp
{
get => GetProperty(PropertyFloat.AllegianceSwearTimestamp);
set { if (!value.HasValue) RemoveProperty(PropertyFloat.AllegianceSwearTimestamp); else SetProperty(PropertyFloat.AllegianceSwearTimestamp, value.Value); }

}

/// <summary>
/// This flag indicates if a player can pass up allegiance XP
/// </summary>
Expand Down
32 changes: 22 additions & 10 deletions Source/ACE.Server/Managers/AllegianceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,16 @@ public static void RemoveCache(Allegiance allegiance)
public static float SkillCap = 291.0f;

/// <summary>
/// The maximum amount of realtime hours sworn to patron
/// The maximum amount of realtime sworn to patron
/// before reaching cap (retail default: 730 days / 2 years)
/// </summary>
public static float RealCap = 730.0f;
public static TimeSpan RealCap = TimeSpan.FromDays(730);

/// <summary>
/// The maximum amount of in-game hours sworn to patron
/// The maximum amount of gametime sworn to patron
/// before reaching cap (retail default: 720 hours / 1 month)
/// </summary>
public static float GameCap = 720.0f;
public static TimeSpan GameCap = TimeSpan.FromHours(720);

public static void PassXP(AllegianceNode vassalNode, ulong amount, bool direct)
{
Expand Down Expand Up @@ -246,19 +248,29 @@ public static void PassXP(AllegianceNode vassalNode, ulong amount, bool direct)
var loyalty = Math.Min(vassal.GetCurrentLoyalty(), SkillCap);
var leadership = Math.Min(patron.GetCurrentLeadership(), SkillCap);

var timeReal = Math.Min(RealCap, RealCap);
var timeGame = Math.Min(GameCap, GameCap);
//var realtime = vassalNode.CalculateRealTime();
//var gametime = vassalNode.CalculateGameTime();
var realtime = RealCap;
var gametime = GameCap;

var timeRealAvg = Math.Min(RealCap, RealCap);
var timeGameAvg = Math.Min(GameCap, GameCap);
var timeReal = Math.Min(realtime.TotalDays, RealCap.TotalDays);
var timeGame = Math.Min(gametime.TotalHours, GameCap.TotalHours);

//var realtime_vassal = patronNode.CalculateRealTime_VassalAvg();
//var gametime_vassal = patronNode.CalculateGameTime_VassalAvg();
var realtime_vassal = RealCap;
var gametime_vassal = GameCap;

var timeRealAvg = Math.Min(realtime_vassal.TotalDays, RealCap.TotalDays);
var timeGameAvg = Math.Min(gametime_vassal.TotalHours, GameCap.TotalHours);

var vassalFactor = Math.Min(0.25f * patronNode.TotalVassals, 1.0f);

var factor1 = direct ? 50.0f : 16.0f;
var factor2 = direct ? 22.5f : 8.0f;

var generated = (factor1 + factor2 * (loyalty / SkillCap) * (1.0f + (timeReal / RealCap) * (timeGame / GameCap))) * 0.01f;
var received = (factor1 + factor2 * (leadership / SkillCap) * (1.0f + vassalFactor * (timeRealAvg / RealCap) * (timeGameAvg / GameCap))) * 0.01f;
var generated = (factor1 + factor2 * (loyalty / SkillCap) * (1.0f + (timeReal / RealCap.TotalDays) * (timeGame / GameCap.TotalHours))) * 0.01f;
var received = (factor1 + factor2 * (leadership / SkillCap) * (1.0f + vassalFactor * (timeRealAvg / RealCap.TotalDays) * (timeGameAvg / GameCap.TotalHours))) * 0.01f;
var passup = generated * received;

var generatedAmount = (uint)(amount * generated);
Expand Down
24 changes: 24 additions & 0 deletions Source/ACE.Server/WorldObjects/Player_Allegiance.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;

using ACE.Common;
using ACE.Database.Models.Shard;
using ACE.Entity;
using ACE.Entity.Enum;
Expand Down Expand Up @@ -60,6 +61,26 @@ public bool ExistedBeforeAllegianceXpChanges
set { if (value) RemoveProperty(PropertyBool.ExistedBeforeAllegianceXpChanges); else SetProperty(PropertyBool.ExistedBeforeAllegianceXpChanges, value); }
}

/// <summary>
/// The timestamp when the player swore allegiance
/// Used to calculate realtime sworn to patron
/// </summary>
public double? AllegianceSwearTimestamp
{
get => GetProperty(PropertyFloat.AllegianceSwearTimestamp);
set { if (!value.HasValue) RemoveProperty(PropertyFloat.AllegianceSwearTimestamp); else SetProperty(PropertyFloat.AllegianceSwearTimestamp, value.Value); }
}

/// <summary>
/// The player age when they swore allegiance
/// Used to calculate gametime sworn to patron
/// </summary>
public int? AllegianceSwearAge
{
get => GetProperty(PropertyInt.AllegianceSwearTimestamp);
set { if (!value.HasValue) RemoveProperty(PropertyInt.AllegianceSwearTimestamp); else SetProperty(PropertyInt.AllegianceSwearTimestamp, value.Value); }
}

/// <summary>
/// Called when a player tries to Swear Allegiance to a target
/// </summary>
Expand Down Expand Up @@ -125,6 +146,9 @@ public void SwearAllegiance(uint targetGuid, bool success, bool confirmed = fals
AllegianceXPGenerated = 0;
AllegianceOfficerRank = null;

AllegianceSwearTimestamp = Time.GetUnixTime();
AllegianceSwearAge = Age;

// refresh ui panel
Session.Network.EnqueueSend(new GameEventAllegianceUpdate(Session, Allegiance, AllegianceNode), new GameEventAllegianceAllegianceUpdateDone(Session));

Expand Down