-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from jonathan-robertson/dev
Improve Performance, Reduce Overhead
- Loading branch information
Showing
11 changed files
with
107 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
Key,File,Type,UsedInMainMenu,NoTranslate,english,Context / Alternate Text,german,latam,french,italian,japanese,koreana,polish,brazilian,russian,turkish,schinese,tchinese,spanish | ||
buffDaysRemainingVendingExpirationFormat,UI,XUI,,?,{0:0} Days,,{0:0} Tage,{0:0} Días,{0:0} Jours,{0:0} Giorni,{0:0} 日,{0:0} 일,{0:0} Dni,{0:0} Dias,{0:0} Дней,{0:0} Gün,{0:0} 天数,{0:0} 天,{0:0} Días | ||
buffDaysRemainingVendingExpirationName,buffs,Buff,,x,Vending Machine,,Automat,Máquina expendedora,Distributeur automatique,Distributore automatico,自動販売機,자판기,Automat sprzedający,Máquina de Vendas,Торговый автомат,Otomat,自动贩卖机,自動販賣機,Máquina expendedora | ||
buffDaysRemainingVendingExpirationDesc,buffs,Buff,,x,Your vending machine rental will expire in [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] days.,,Ihre Automatenmiete läuft in [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] Tagen ab.,El alquiler de su máquina expendedora caducará en [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] días.,Votre location de distributeur expirera dans [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] jours.,Il noleggio del tuo distributore automatico scadrà tra [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] giorni.,自動販売機のレンタルは [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] 日後に期限切れになります.,자판기 대여가 [007fff]{cvar(daysRemainingVendingExpiration:0)}일 후에 만료됩니다.,Wypożyczenie automatu wygaśnie za [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] dni.,O aluguel da máquina de venda automática expira em [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] dias.,Срок аренды вашего торгового автомата истекает через [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] дней.,Otomat kiralama süreniz [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] gün içinde sona erecek.,您的自动售货机租赁将在 [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] 天后到期.,您的自動售貨機租賃將在 [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] 天后到期.,El alquiler de su máquina expendedora caducará en [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] días. | ||
buffDaysRemainingVendingExpirationTooltip,buffs,Buff,,x,Your vending machine rental will expire in [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] days.,,Ihre Automatenmiete läuft in [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] Tagen ab.,El alquiler de su máquina expendedora caducará en [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] días.,Votre location de distributeur expirera dans [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] jours.,Il noleggio del tuo distributore automatico scadrà tra [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] giorni.,自動販売機のレンタルは [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] 日後に期限切れになります.,자판기 대여가 [007fff]{cvar(daysRemainingVendingExpiration:0)}일 후에 만료됩니다.,Wypożyczenie automatu wygaśnie za [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] dni.,O aluguel da máquina de venda automática expira em [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] dias.,Срок аренды вашего торгового автомата истекает через [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] дней.,Otomat kiralama süreniz [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] gün içinde sona erecek.,您的自动售货机租赁将在 [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] 天后到期.,您的自動售貨機租賃將在 [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] 天后到期.,El alquiler de su máquina expendedora caducará en [007fff]{cvar(daysRemainingVendingExpiration:0)}[-] días. | ||
buffDaysRemainingVendingExpirationDesc,buffs,Buff,,x,Your vending machine rental will expire in [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] days.,,Ihre Automatenmiete läuft in [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] Tagen ab.,El alquiler de su máquina expendedora caducará en [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] días.,Votre location de distributeur expirera dans [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] jours.,Il noleggio del tuo distributore automatico scadrà tra [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] giorni.,自動販売機のレンタルは [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] 日後に期限切れになります.,자판기 대여가 [ffff00]{cvar(daysRemainingVendingExpiration:0)}일 후에 만료됩니다.,Wypożyczenie automatu wygaśnie za [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] dni.,O aluguel da máquina de venda automática expira em [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] dias.,Срок аренды вашего торгового автомата истекает через [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] дней.,Otomat kiralama süreniz [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] gün içinde sona erecek.,您的自动售货机租赁将在 [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] 天后到期.,您的自動售貨機租賃將在 [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] 天后到期.,El alquiler de su máquina expendedora caducará en [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] días. | ||
buffDaysRemainingVendingExpirationTooltip,buffs,Buff,,x,Your vending machine rental will expire in [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] days.,,Ihre Automatenmiete läuft in [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] Tagen ab.,El alquiler de su máquina expendedora caducará en [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] días.,Votre location de distributeur expirera dans [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] jours.,Il noleggio del tuo distributore automatico scadrà tra [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] giorni.,自動販売機のレンタルは [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] 日後に期限切れになります.,자판기 대여가 [ffff00]{cvar(daysRemainingVendingExpiration:0)}일 후에 만료됩니다.,Wypożyczenie automatu wygaśnie za [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] dni.,O aluguel da máquina de venda automática expira em [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] dias.,Срок аренды вашего торгового автомата истекает через [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] дней.,Otomat kiralama süreniz [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] gün içinde sona erecek.,您的自动售货机租赁将在 [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] 天后到期.,您的自動售貨機租賃將在 [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] 天后到期.,El alquiler de su máquina expendedora caducará en [ffff00]{cvar(daysRemainingVendingExpiration:0)}[-] días. |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using DaysRemaining.Patches; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DaysRemaining.Utilities | ||
{ | ||
internal class DayMonitor | ||
{ | ||
private const string CVAR_VENDING_EXPIRATION = "daysRemainingVendingExpiration"; | ||
private const string BUFF_VENDING_EXPIRATION = "buffDaysRemainingVendingExpiration"; | ||
|
||
internal static int CurrentDay { get; private set; } = -1; | ||
|
||
private static readonly ModLog<DayMonitor> _log = new ModLog<DayMonitor>(); | ||
|
||
internal static void OnGameUpdate() | ||
{ | ||
if (IsNewDay(out var day)) | ||
{ | ||
CurrentDay = day; | ||
SetExpirationDaysRemaining(); | ||
} | ||
} | ||
|
||
internal static void SetExpirationDaysRemaining() | ||
{ | ||
var players = GameManager.Instance.World.Players.list; | ||
for (var i = 0; i < players.Count; i++) | ||
{ | ||
if (Helpers.TryGetClientInfo(players[i].entityId, out var clientInfo)) | ||
{ | ||
SetExpirationDaysRemaining(clientInfo, players[i]); | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Call this to update the player's client-side data related to vending expiration date. | ||
/// </summary> | ||
/// <param name="clientInfo">ClientInfo containing the current rental information.</param> | ||
/// <param name="player">EntityPlayer to update.</param> | ||
/// <remarks>Would've loved to use rentalEndTime here, but it isn't reported to the server (just rentalEndDay). Maybe rentalEndTime is deprecated?</remarks> | ||
internal static void SetExpirationDaysRemaining(ClientInfo clientInfo, EntityPlayer player) | ||
{ | ||
if (clientInfo == null || player == null) | ||
{ | ||
_log.Warn($"ClientInfo and EntityPlayer params must not be null; ClientInfo {(clientInfo != null ? "exists" : "does not exist")}, EntityPlayer {(player != null ? "exists" : "does not exist")}."); | ||
return; | ||
} | ||
|
||
if (clientInfo.latestPlayerData.rentedVMPosition == Vector3i.zero) | ||
{ | ||
return; // player does not have a vending machine rental | ||
} | ||
var daysRemaining = Math.Max(clientInfo.latestPlayerData.rentalEndDay - GameUtils.WorldTimeToDays(GameManager.Instance.World.worldTime), 0); | ||
if (daysRemaining != player.GetCVar(CVAR_VENDING_EXPIRATION)) | ||
{ | ||
player.SetCVar(CVAR_VENDING_EXPIRATION, daysRemaining); | ||
_ = player.Buffs.AddBuff(BUFF_VENDING_EXPIRATION); | ||
} | ||
} | ||
|
||
private static bool IsNewDay(out int day) | ||
{ | ||
day = GameUtils.WorldTimeToDays(GameManager.Instance.World.worldTime); | ||
return day != CurrentDay; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
using System; | ||
|
||
namespace DaysRemaining | ||
namespace DaysRemaining.Utilities | ||
{ | ||
internal class ModLog<T> | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters