Exemplo n.º 1
0
        public static void HandleRequestActionSetChanges(WorldSession session, ClientRequestActionSetChanges requestActionSetChanges)
        {
            // TODO: check for client validity, e.g. Level & Spell4TierRequirements

            ActionSet actionSet = session.Player.SpellManager.GetActionSet(requestActionSetChanges.ActionSetIndex);

            List <ActionSetShortcut> shortcuts = actionSet.Actions.ToList();

            for (UILocation i = 0; i < (UILocation)requestActionSetChanges.Actions.Count; i++)
            {
                ActionSetShortcut shortcut = actionSet.GetShortcut(i);
                if (shortcut != null)
                {
                    actionSet.RemoveShortcut(i);
                }

                uint spell4BaseId = requestActionSetChanges.Actions[(int)i];
                if (spell4BaseId != 0u)
                {
                    ActionSetShortcut existingShortcut = shortcuts.SingleOrDefault(s => s.ObjectId == spell4BaseId);
                    byte tier = existingShortcut?.Tier ?? 1;
                    actionSet.AddShortcut(i, ShortcutType.Spell, spell4BaseId, tier);
                }
            }

            foreach (ClientRequestActionSetChanges.ActionTier actionTier in requestActionSetChanges.ActionTiers)
            {
                session.Player.SpellManager.UpdateSpell(actionTier.Action, actionTier.Tier, requestActionSetChanges.ActionSetIndex);
            }

            session.EnqueueMessageEncrypted(actionSet.BuildServerActionSet());
            if (requestActionSetChanges.ActionTiers.Count > 0)
            {
                session.Player.SpellManager.SendServerAbilityPoints();
            }

            // only new AMP can be added with this packet, filter out existing ones
            List <ushort> newAmps = requestActionSetChanges.Amps
                                    .Except(actionSet.Amps
                                            .Select(a => (ushort)a.Entry.Id))
                                    .ToList();

            if (newAmps.Count > 0)
            {
                foreach (ushort id in newAmps)
                {
                    actionSet.AddAmp(id);
                }

                session.EnqueueMessageEncrypted(actionSet.BuildServerAmpList());
            }
        }