Skip to content

Commit

Permalink
Fix target combat
Browse files Browse the repository at this point in the history
  • Loading branch information
negrifelipe committed Jan 31, 2022
1 parent a9ca787 commit 387dc1a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
25 changes: 19 additions & 6 deletions Feli.OpenMod.Teleporting/Services/TeleportsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,29 @@ private async Task<bool> ValidateRequest(Tuple<UnturnedUser, UnturnedUser> reque

if (!_configuration.GetSection("tpaOptions:combat:allow").Get<bool>())
{
var combat = GetLastCombat(sender);
var senderCombat = GetLastCombat(sender);
var targetCombat = GetLastCombat(target);

var combatTime = combat.AddSeconds(_configuration.GetSection("tpaOptions:combat:time").Get<double>());
var time = _configuration.GetSection("teleportOptions:combat:time").Get<double>();

if (combatTime > DateTime.Now)
var senderCombatTime = senderCombat.AddSeconds(time);
var targetCombatTime = targetCombat.AddSeconds(time);

if (senderCombatTime > DateTime.Now)
{
var waitTime = (combatTime - DateTime.Now).TotalSeconds;
var waitTime = (senderCombatTime - DateTime.Now).TotalSeconds;

await Say(sender, _stringLocalizer["tpaValidation:combat:self", Math.Round(waitTime)]);
await Say(target, _stringLocalizer["tpaValidation:combat:other", sender.DisplayName]);

return false;
}
else if (targetCombatTime > DateTime.Now)
{
var waitTime = (targetCombatTime - DateTime.Now).TotalSeconds;

await Say(sender, _stringLocalizer["tpaValidation:combat:sender", Math.Round(waitTime)]);
await Say(target, _stringLocalizer["tpaValidation:combat:target", sender.DisplayName]);
await Say(target, _stringLocalizer["tpaValidation:combat:self", Math.Round(waitTime)]);
await Say(sender, _stringLocalizer["tpaValidation:combat:other", target.DisplayName]);

return false;
}
Expand Down
4 changes: 2 additions & 2 deletions Feli.OpenMod.Teleporting/translations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ tpaValidation:
target: "The teleport was cancelled because {0} moved"

combat:
sender: "The teleport was cancelled because you are in combat. The combat mode expires in {0} seconds"
target: "The teleport was cancelled because {0} is in combat"
self: "The teleport was cancelled because you are in combat. The combat mode expires in {0} seconds"
other: "The teleport was cancelled because {0} is in combat"

balance:
sender: "You dont have enough balance to teleport. Teleport cost: {0}"
Expand Down
6 changes: 3 additions & 3 deletions Feli.RocketMod.Teleporting/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected override void Load()
? new ExperienceEconomyProvider() as IEconomyProvider
: new UconomyEconomyProvider();

Logger.Log($"Teleporting plugin v1.6.2 loaded !");
Logger.Log($"Teleporting plugin v1.6.3 loaded !");
Logger.Log("Do you want more cool plugins? Join now: https://discord.gg/4FF2548 !");
Logger.Log($"Economy Provider: {EconomyProvider.GetType().Name}");
}
Expand Down Expand Up @@ -62,8 +62,8 @@ protected override void Unload()
{"TpaValidation:Leave", "The teleport was cancelled because {0} left the server"},
{"TpaValidation:Move:Sender", "The teleport was cancelled because your moved"},
{"TpaValidation:Move:Target", "The teleport was cancelled because {0} moved"},
{"TpaValidation:Combat:Sender", "The teleport was cancelled because you are in combat. The combat mode expires in {0} seconds"},
{"TpaValidation:Combat:Target", "The teleport was cancelled because {0} is in combat"},
{"TpaValidation:Combat:Selft", "The teleport was cancelled because you are in combat. The combat mode expires in {0} seconds"},
{"TpaValidation:Combat:Other", "The teleport was cancelled because {0} is in combat"},
{"TpaValidation:Balance:Sender", "You dont have enough balance to teleport. Teleport cost: {0}"},
{"TpaValidation:Balance:Target", "The teleport was cancelled because {0} does not have enough balance"},
{"TpaValidation:Dead:Alive", "The teleport was cancelled because {0} is dead" },
Expand Down
25 changes: 18 additions & 7 deletions Feli.RocketMod.Teleporting/TeleportsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,21 +223,32 @@ private bool ValidateRequest(Tuple<UnturnedPlayer, UnturnedPlayer> request)

if (!_configuration.TeleportCombatAllowed)
{
var combat = GetLastCombat(sender);
var senderCombat = GetLastCombat(sender);
var targetCombat = GetLastCombat(target);

var combatTime = combat.AddSeconds(_configuration.TeleportCombatTime);
var senderCombatTime = senderCombat.AddSeconds(_configuration.TeleportCombatTime);
var targetCombatTime = targetCombat.AddSeconds(_configuration.TeleportCombatTime);

if (combatTime > DateTime.Now)
if(senderCombatTime > DateTime.Now)
{
var waitTime = (combatTime - DateTime.Now).TotalSeconds;
var waitTime = (senderCombatTime - DateTime.Now).TotalSeconds;

Say(sender, _plugin.Translate("TpaValidation:Combat:Sender", Math.Round(waitTime)), _messageColor, _messageIcon);
Say(target, _plugin.Translate("TpaValidation:Combat:Target", sender.DisplayName), _messageColor, _messageIcon);
Say(sender, _plugin.Translate("TpaValidation:Combat:Self", Math.Round(waitTime)), _messageColor, _messageIcon);
Say(target, _plugin.Translate("TpaValidation:Combat:Other", sender.DisplayName), _messageColor, _messageIcon);

return false;
}
else if(targetCombatTime > DateTime.Now)
{
var waitTime = (targetCombatTime - DateTime.Now).TotalSeconds;

Say(target, _plugin.Translate("TpaValidation:Combat:Self", Math.Round(waitTime)), _messageColor, _messageIcon);
Say(sender, _plugin.Translate("TpaValidation:Combat:Other", target.DisplayName), _messageColor, _messageIcon);

return false;
}
}

return true;
}

Expand Down

0 comments on commit 387dc1a

Please sign in to comment.