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

mod: allow gameserver set happy hours experience multiplier #396

Open
wants to merge 2 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
1 change: 1 addition & 0 deletions src/Domain/Entities/GameServers/GameServerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ public class GameServerConfig : AuditableEntity
public int? Crpg_reward_tick { get; set; } // Sets the reward tick duration in seconds for Conquest/Siege/Team Deatmatch.
public bool? Crpg_team_balance_once { get; set; } // Sets if the team balancer should balance only after warmup.
public TimeSpan? Crpg_happy_hours { get; set; } // Sets the happy hours. Format: HH:MM-HH:MM,TZ
public float? Crpg_happy_hours_experience_multiplier { get; set; } // Sets the happy hours experience multipliers.
public bool? Crpg_apply_harmony_patches { get; set; } // Apply Harmony patches
}
18 changes: 18 additions & 0 deletions src/Module.Server/Common/CrpgServerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static void Init()
public static int ControlledBotsCount { get; private set; } = 0;
public static int BaseNakedEquipmentValue { get; private set; } = 10000;
public static Tuple<TimeSpan, TimeSpan, TimeZoneInfo>? HappyHours { get; private set; }
public static float HappyHoursExperienceMultiplier { get; private set; } = 0.5f;

[UsedImplicitly]
[ConsoleCommandMethod("crpg_team_balancer_clan_group_size_penalty", "Apply a rating increase to members of the same clan that are playing in the same team")]
Expand Down Expand Up @@ -166,6 +167,23 @@ private static void SetHappyHours(string? happHoursStr)
Debug.Print($"Set happy hours from {startTime} to {endTime} in time zone {timeZone.Id}");
}

[UsedImplicitly]
[ConsoleCommandMethod("crpg_happy_hours_experience_multiplier", "Sets the happy hours experience multiplier. Range: 0f - 2f")]
private static void SetHappyHoursExperienceMultiplier(string? happyMultiplierStr)
{
if (happyMultiplierStr == null
|| !float.TryParse(happyMultiplierStr, out float happyMultiplier)
|| happyMultiplier < 0f
|| happyMultiplier > 2f)
{
Debug.Print($"Invalid happy hours experience multiplier: {happyMultiplierStr}");
return;
}

HappyHoursExperienceMultiplier = happyMultiplier;
Debug.Print($"Set happy hours experience multiplier to {happyMultiplier}");
}

[UsedImplicitly]
[ConsoleCommandMethod("crpg_apply_harmony_patches", "Apply Harmony patches")]
private static void ApplyHarmonyPatches()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<string id="YTubwz4z" text="{COUNT} 位玩家转移到防守方{newline}" />
<string id="ymrAOIug" text="{COUNT} 位新玩家加入了防守方{newline}" />
<string id="YFfWaWqk" text="{COUNT} 位新玩家加入了攻击方{newline}" />
<string id="TWpiAeFe" text="现在是欢乐时光!经验获取增加了50%。" />
<string id="TWpiAeFe" text="现在是欢乐时光!经验获取增加了{XPMULTIPLIER}。" />
<string id="KoqNpPLa" text="欢乐时光结束!" />
<string id="sXF7LsGO" text="晋升指挥官" />
<string id="JDAtTV9K" text="降职指挥官" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<string id="YTubwz4z" text="{COUNT} игроков перешли в команду защитников{newline}" />
<string id="ymrAOIug" text="{COUNT} новых игроков присоединились к команде защитников{newline}" />
<string id="YFfWaWqk" text="{COUNT} новых игроков присоединились к команде атакующих{newline}" />
<string id="TWpiAeFe" text="Наступило счастливые часы! Опыт увеличен на 50%." />
<string id="TWpiAeFe" text="Наступило счастливые часы! Опыт увеличен на {XPMULTIPLIER}." />
<string id="KoqNpPLa" text="Счастливые часы окончены!" />
<string id="sXF7LsGO" text="Назначить командира" />
<string id="JDAtTV9K" text="Отстранить командира" />
Expand Down
5 changes: 4 additions & 1 deletion src/Module.Server/Rewards/CrpgRewardClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ private void HandleRewardError(CrpgRewardError message)
private void HandleRewardHappyHour(CrpgRewardHappyHour message)
{
var textObject = message.Started
? new TextObject("{=TWpiAeFe}It's happy hours time! Experience gain is increased by 50%.")
? new TextObject("{=TWpiAeFe}It's happy hours time! Experience gain is increased by {XPMULTIPLIER}.", new Dictionary<string, object>
{
["XPMULTIPLIER"] = $"{message.ExpMultiplier * 100:F0}%",
})
: new TextObject("{=KoqNpPLa}Happy hours ended!");
InformationManager.AddSystemNotification(textObject.ToString());
}
Expand Down
5 changes: 4 additions & 1 deletion src/Module.Server/Rewards/CrpgRewardHappyHour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ namespace Crpg.Module.Rewards;
internal sealed class CrpgRewardHappyHour : GameNetworkMessage
{
public bool Started { get; set; }
public float ExpMultiplier { get; set; }

protected override void OnWrite()
{
WriteBoolToPacket(Started);
WriteFloatToPacket(ExpMultiplier, new CompressionInfo.Float(0f, 2f, 8));
}

protected override bool OnRead()
{
bool bufferReadValid = true;
Started = ReadBoolFromPacket(ref bufferReadValid);
ExpMultiplier = ReadFloatFromPacket(new CompressionInfo.Float(0f, 2f, 8), ref bufferReadValid);
return bufferReadValid;
}

Expand All @@ -27,6 +30,6 @@ protected override MultiplayerMessageFilter OnGetLogFilter()

protected override string OnGetLogFormat()
{
return nameof(CrpgRewardHappyHour);
return $"{nameof(CrpgRewardHappyHour)}: Started={Started}, ExpMultiplier={ExpMultiplier}";
}
}
6 changes: 3 additions & 3 deletions src/Module.Server/Rewards/CrpgRewardServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ private void SetRewardForConnectedPlayer(
int? constantMultiplier)
{
float serverXpMultiplier = CrpgServerConfiguration.ServerExperienceMultiplier;
serverXpMultiplier *= IsHappyHour() ? 1.5f : 1f;
serverXpMultiplier *= (IsHappyHour() ? CrpgServerConfiguration.HappyHoursExperienceMultiplier : 0f) + 1f;
userUpdate.Reward = new CrpgUserReward
{
Experience = (int)(serverXpMultiplier * durationRewarded * (_constants.BaseExperienceGainPerSecond
Expand Down Expand Up @@ -562,7 +562,7 @@ private bool IsHappyHour()
if (_lastRewardDuringHappyHours)
{
GameNetwork.BeginBroadcastModuleEvent();
GameNetwork.WriteMessage(new CrpgRewardHappyHour { Started = false });
GameNetwork.WriteMessage(new CrpgRewardHappyHour { Started = false, ExpMultiplier = CrpgServerConfiguration.HappyHoursExperienceMultiplier });
GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.None);
}

Expand All @@ -573,7 +573,7 @@ private bool IsHappyHour()
if (!_lastRewardDuringHappyHours)
{
GameNetwork.BeginBroadcastModuleEvent();
GameNetwork.WriteMessage(new CrpgRewardHappyHour { Started = true });
GameNetwork.WriteMessage(new CrpgRewardHappyHour { Started = true, ExpMultiplier = CrpgServerConfiguration.HappyHoursExperienceMultiplier });
GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.None);
}

Expand Down