Exemple #1
0
        private static void OnModuleUseFeat()
        {
            NWPlayer pc     = Object.OBJECT_SELF;
            int      featID = NWNXEvents.OnFeatUsed_GetFeatID();

            if (featID != (int)CustomFeatType.ChatCommandTargeter)
            {
                return;
            }

            var    target         = NWNXEvents.OnFeatUsed_GetTarget();
            var    targetLocation = NWNXEvents.OnFeatUsed_GetTargetLocation();
            string command        = pc.GetLocalString("CHAT_COMMAND");
            string args           = pc.GetLocalString("CHAT_COMMAND_ARGS");

            if (string.IsNullOrWhiteSpace(command))
            {
                pc.SendMessage("Please enter a chat command and then use this feat. Type /help to learn more about the available chat commands.");
                return;
            }

            IChatCommand chatCommand = GetChatCommandHandler(command);

            ProcessChatCommand(chatCommand, pc, target, targetLocation, args);

            pc.DeleteLocalString("CHAT_COMMAND");
            pc.DeleteLocalString("CHAT_COMMAND_ARGS");
        }
        /// <summary>
        /// Retrieves feat user stats. Data is retrieved differently based on whether user is a player or NPC.
        /// </summary>
        /// <returns>The stats of the user</returns>
        private static UserStats GetUserStats(NWGameObject user, NWGameObject target, Feat feat)
        {
            var ability        = AbilityRegistry.Get(feat);
            var targetLocation = GetIsObjectValid(target) ? GetLocation(target) : NWNXEvents.OnFeatUsed_GetTargetLocation();

            var stats = new UserStats
            {
                User = user,
                AbilityDefinition = ability,
                Target            = target,
                TargetLocation    = targetLocation,
                CastingPosition   = GetPosition(user),
                MPCost            = ability.MP(user),
                Feat = feat
            };

            // Players - retrieve from DB
            if (GetIsPlayer(user))
            {
                var playerID = GetGlobalID(user);
                var player   = PlayerRepo.Get(playerID);
                var cooldown = CooldownRepo.Get(playerID, feat);
                stats.MP             = player.MP;
                stats.CooldownUnlock = cooldown.DateUnlocked;
            }
            // NPCs - retrieve from local variables
            else if (GetIsNPC(user))
            {
                stats.MP = GetLocalInt(user, "MP_CURRENT");

                var cooldown = GetLocalString(user, $"ABILITY_COOLDOWN_{feat}");
                if (string.IsNullOrWhiteSpace(cooldown))
                {
                    stats.CooldownUnlock = DateTime.UtcNow;
                }
                else
                {
                    stats.CooldownUnlock = DateTime.ParseExact(cooldown, "yyyy-MM-dd hh:mm:ss", CultureInfo.InvariantCulture);
                }
            }

            stats.Now = DateTime.UtcNow;

            return(stats);
        }