Ejemplo n.º 1
0
        public static void StartPlayerRaid(this TeleportationPlugin plugin, CSteamID steamID)
        {
            if (plugin.RaidPlayers.TryGetValue(steamID.m_SteamID, out Timer timer))
            {
                if (timer.Enabled)
                {
                    timer.Enabled = false;
                }
                else
                {
                    UnturnedChat.Say(steamID, plugin.Translate("RaidStart"), plugin.MessageColor);
                }

                timer.Start();
            }
            else
            {
                timer = new Timer(plugin.Configuration.Instance.RaidDuration * 1000);
                plugin.RaidPlayers.Add(steamID.m_SteamID, timer);
                timer.AutoReset = false;
                timer.Elapsed  += (sender, e) =>
                {
                    TaskDispatcher.QueueOnMainThread(() => UnturnedChat.Say(steamID, plugin.Translate("RaidExpire"), plugin.MessageColor));
                };
                timer.Start();

                UnturnedChat.Say(steamID, plugin.Translate("RaidStart"), plugin.MessageColor);
            }
        }
        public static void SendTPARequest(this TeleportationPlugin plugin, UnturnedPlayer sender, UnturnedPlayer target)
        {
            if (sender.Id == target.Id)
            {
                UnturnedChat.Say(sender, plugin.Translate("TPAYourself"), plugin.MessageColor);
                return;
            }

            if (plugin.Cooldowns.TryGetValue(sender.CSteamID, out DateTime lastUse))
            {
                double secondsElapsed = (DateTime.Now - lastUse).TotalSeconds;
                double timeLeft       = Math.Round(plugin.Configuration.Instance.TPACooldown - secondsElapsed);
                if (secondsElapsed < plugin.Configuration.Instance.TPACooldown)
                {
                    UnturnedChat.Say(sender, plugin.Translate("TPACooldown", timeLeft), plugin.MessageColor);
                    return;
                }
            }

            if (plugin.TPRequests.Exists(x => x.Sender == sender.CSteamID && x.Target == target.CSteamID))
            {
                UnturnedChat.Say(sender, plugin.Translate("TPADuplicate"), plugin.MessageColor);
                return;
            }

            plugin.TPRequests.Add(new TPARequest(sender.CSteamID, target.CSteamID));
            plugin.Cooldowns[sender.CSteamID] = DateTime.Now;
            UnturnedChat.Say(sender, plugin.Translate("TPASent", target.DisplayName), plugin.MessageColor);
            UnturnedChat.Say(target, plugin.Translate("TPAReceive", sender.DisplayName), plugin.MessageColor);
        }
        public static void DenyTPARequest(this TeleportationPlugin plugin, UnturnedPlayer caller)
        {
            var request = plugin.TPRequests.FirstOrDefault(x => x.Target == caller.CSteamID);

            if (request != null)
            {
                UnturnedChat.Say(caller, plugin.Translate("TPADenied", request.SenderPlayer.DisplayName), plugin.MessageColor);
                plugin.TPRequests.Remove(request);
            }
            else
            {
                UnturnedChat.Say(caller, plugin.Translate("TPANoRequest"), plugin.MessageColor);
            }
        }
        public static void AcceptTPARequest(this TeleportationPlugin plugin, UnturnedPlayer caller)
        {
            var request = plugin.TPRequests.FirstOrDefault(x => x.Target == caller.CSteamID);

            if (request == null)
            {
                UnturnedChat.Say(caller, plugin.Translate("TPANoRequest"), plugin.MessageColor);
                return;
            }

            UnturnedChat.Say(caller, plugin.Translate("TPAAccepted", request.SenderPlayer.CharacterName, plugin.MessageColor));
            request.Execute(plugin.Configuration.Instance.TPADelay);
            plugin.TPRequests.Remove(request);
        }
 public static void StopPlayerRaid(this TeleportationPlugin plugin, CSteamID steamID)
 {
     if (plugin.RaidPlayers.TryGetValue(steamID, out Timer timer))
     {
         timer.Dispose();
         plugin.RaidPlayers.Remove(steamID);
         UnturnedChat.Say(steamID, plugin.Translate("RaidExpire"), plugin.MessageColor);
     }
 }