private void OnPlayerChat(PlayerChatEventArgs e)
        {
            //don't check commands
            if (e.RawText.StartsWith(Commands.Specifier))
            {
                return;
            }

            if (!e.Player.HasPermission(SkillPermission))
            {
                return;
            }

            var session = Session.GetOrCreateSession(e.Player);

            if (session.TriggerWordsToSkillDefinitions.Count > 0)
            {
                foreach (var kvp in session.TriggerWordsToSkillDefinitions)
                {
                    var triggerWord = kvp.Key;
                    var definition  = kvp.Value;

                    if (e.RawText.Contains(triggerWord))
                    {
                        //can we use this skill?
                        if (definition.PermissionsToUse != null && !PlayerFunctions.PlayerHasPermission(e.Player, definition.PermissionsToUse))
                        {
                            continue;
                        }

                        if (!session.IsSkillReady(definition.Name))
                        {
                            continue;
                        }

                        if (session.PlayerSkillInfos.TryGetValue(definition.Name, out var playerSkillInfo))
                        {
                            CustomSkillRunner.AddActiveSkill(e.Player, definition, playerSkillInfo.CurrentLevel);
                            return;
                        }
                    }
                }
            }

            //Debug.Print($"Chat: raw: {e.RawText}");
            //Debug.Print($"Chat: formatted: {e.TShockFormattedText}");
        }
Example #2
0
        private void SkillSubCommand(TSPlayer player, string skillName, string categoryName = null)
        {
            if (!GetCategoryAndSkill(player, skillName, categoryName, out var category, out var definition))
            {
                return;
            }

            var session = Session.GetOrCreateSession(player);

            if (!session.HasLearned(skillName))
            {
                player.SendErrorMessage($"You have not learned {skillName}.");
                return;
            }

            //are we allowed to use this skill?
            if (definition.PermissionsToUse != null && !PlayerFunctions.PlayerHasPermission(player, definition.PermissionsToUse))
            {
                player.SendInfoMessage($"You are not allowed to use {skillName}.");
                return;
            }

            //do we have enough "funds" to use this skill?
            if (!session.CanAffordCastingSkill(skillName))
            {
                player.SendInfoMessage($"You cannot afford to use {skillName}.");
                return;
            }

            if (!session.IsSkillReady(definition.Name))
            {
                player.SendInfoMessage($"{skillName} is not ready yet.");
                return;
            }

            session.PlayerSkillInfos.TryGetValue(skillName, out var playerSkillInfo);

            var skillAdded = CustomSkillRunner.AddActiveSkill(player, definition, playerSkillInfo.CurrentLevel);

            if (!skillAdded)
            {
                player.SendInfoMessage($"You cannot use {skillName} right now.");
                return;
            }
        }