Ejemplo n.º 1
0
        static bool HandleCharacterChangeAccountCommand(StringArguments args, CommandHandler handler)
        {
            string playerNameStr;
            string accountName;

            handler.ExtractOptFirstArg(args, out playerNameStr, out accountName);
            if (accountName.IsEmpty())
            {
                return(false);
            }

            ObjectGuid targetGuid;
            string     targetName;
            Player     playerNotUsed;

            if (!handler.ExtractPlayerTarget(new StringArguments(playerNameStr), out playerNotUsed, out targetGuid, out targetName))
            {
                return(false);
            }

            CharacterCacheEntry characterInfo = Global.CharacterCacheStorage.GetCharacterCacheByGuid(targetGuid);

            if (characterInfo == null)
            {
                handler.SendSysMessage(CypherStrings.PlayerNotFound);
                return(false);
            }

            uint oldAccountId = characterInfo.AccountId;
            uint newAccountId = oldAccountId;

            PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_ID_BY_NAME);

            stmt.AddValue(0, accountName);
            SQLResult result = DB.Login.Query(stmt);

            if (!result.IsEmpty())
            {
                newAccountId = result.Read <uint>(0);
            }
            else
            {
                handler.SendSysMessage(CypherStrings.AccountNotExist, accountName);
                return(false);
            }

            // nothing to do :)
            if (newAccountId == oldAccountId)
            {
                return(true);
            }

            uint charCount = Global.AccountMgr.GetCharactersCount(newAccountId);

            if (charCount != 0)
            {
                if (charCount >= WorldConfig.GetIntValue(WorldCfg.CharactersPerRealm))
                {
                    handler.SendSysMessage(CypherStrings.AccountCharacterListFull, accountName, newAccountId);
                    return(false);
                }
            }

            stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_ACCOUNT_BY_GUID);
            stmt.AddValue(0, newAccountId);
            stmt.AddValue(1, targetGuid.GetCounter());
            DB.Characters.DirectExecute(stmt);

            Global.WorldMgr.UpdateRealmCharCount(oldAccountId);
            Global.WorldMgr.UpdateRealmCharCount(newAccountId);

            Global.CharacterCacheStorage.UpdateCharacterAccountId(targetGuid, newAccountId);

            handler.SendSysMessage(CypherStrings.ChangeAccountSuccess, targetName, accountName);

            string       logString = $"changed ownership of player {targetName} ({targetGuid.ToString()}) from account {oldAccountId} to account {newAccountId}";
            WorldSession session   = handler.GetSession();

            if (session != null)
            {
                Player player = session.GetPlayer();
                if (player != null)
                {
                    Log.outCommand(session.GetAccountId(), $"GM {player.GetName()} (Account: {session.GetAccountId()}) {logString}");
                }
            }
            else
            {
                Log.outCommand(0, $"{handler.GetCypherString(CypherStrings.Console)} {logString}");
            }
            return(true);
        }
Ejemplo n.º 2
0
        public static void HandleLogout(ref PacketReader packet, ref WorldSession session)
        {
            var pl = session.GetPlayer();

            LogoutPlayer(pl, true);
        }
Ejemplo n.º 3
0
        public void ActivateTalentGroup(ChrSpecializationRecord spec)
        {
            if (GetActiveTalentGroup() == spec.OrderIndex)
            {
                return;
            }

            if (IsNonMeleeSpellCast(false))
            {
                InterruptNonMeleeSpells(false);
            }

            SQLTransaction trans = new();

            _SaveActions(trans);
            DB.Characters.CommitTransaction(trans);

            // TO-DO: We need more research to know what happens with warlock's reagent
            Pet pet = GetPet();

            if (pet)
            {
                RemovePet(pet, PetSaveMode.NotInSlot);
            }

            ClearAllReactives();
            UnsummonAllTotems();
            ExitVehicle();
            RemoveAllControlled();

            // remove single target auras at other targets
            var scAuras = GetSingleCastAuras();

            foreach (var aura in scAuras)
            {
                if (aura.GetUnitOwner() != this)
                {
                    aura.Remove();
                }
            }

            // Let client clear his current Actions
            SendActionButtons(2);
            foreach (var talentInfo in CliDB.TalentStorage.Values)
            {
                // unlearn only talents for character class
                // some spell learned by one class as normal spells or know at creation but another class learn it as talent,
                // to prevent unexpected lost normal learned spell skip another class talents
                if (talentInfo.ClassID != (int)GetClass())
                {
                    continue;
                }

                if (talentInfo.SpellID == 0)
                {
                    continue;
                }

                SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(talentInfo.SpellID, Difficulty.None);
                if (spellInfo == null)
                {
                    continue;
                }

                RemoveSpell(talentInfo.SpellID, true);

                // search for spells that the talent teaches and unlearn them
                foreach (SpellEffectInfo effect in spellInfo.GetEffects())
                {
                    if (effect != null && effect.TriggerSpell > 0 && effect.Effect == SpellEffectName.LearnSpell)
                    {
                        RemoveSpell(effect.TriggerSpell, true);
                    }
                }

                if (talentInfo.OverridesSpellID != 0)
                {
                    RemoveOverrideSpell(talentInfo.OverridesSpellID, talentInfo.SpellID);
                }
            }

            foreach (var talentInfo in CliDB.PvpTalentStorage.Values)
            {
                SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(talentInfo.SpellID, Difficulty.None);
                if (spellInfo == null)
                {
                    continue;
                }

                RemoveSpell(talentInfo.SpellID, true);

                // search for spells that the talent teaches and unlearn them
                foreach (SpellEffectInfo effect in spellInfo.GetEffects())
                {
                    if (effect != null && effect.TriggerSpell > 0 && effect.Effect == SpellEffectName.LearnSpell)
                    {
                        RemoveSpell(effect.TriggerSpell, true);
                    }
                }

                if (talentInfo.OverridesSpellID != 0)
                {
                    RemoveOverrideSpell(talentInfo.OverridesSpellID, talentInfo.SpellID);
                }
            }

            // Remove spec specific spells
            RemoveSpecializationSpells();

            foreach (uint glyphId in GetGlyphs(GetActiveTalentGroup()))
            {
                RemoveAurasDueToSpell(CliDB.GlyphPropertiesStorage.LookupByKey(glyphId).SpellID);
            }

            SetActiveTalentGroup(spec.OrderIndex);
            SetPrimarySpecialization(spec.Id);

            foreach (var talentInfo in CliDB.TalentStorage.Values)
            {
                // learn only talents for character class
                if (talentInfo.ClassID != (int)GetClass())
                {
                    continue;
                }

                if (talentInfo.SpellID == 0)
                {
                    continue;
                }

                if (HasTalent(talentInfo.Id, GetActiveTalentGroup()))
                {
                    LearnSpell(talentInfo.SpellID, false);      // add the talent to the PlayerSpellMap
                    if (talentInfo.OverridesSpellID != 0)
                    {
                        AddOverrideSpell(talentInfo.OverridesSpellID, talentInfo.SpellID);
                    }
                }
            }

            for (byte slot = 0; slot < PlayerConst.MaxPvpTalentSlots; ++slot)
            {
                PvpTalentRecord talentInfo = CliDB.PvpTalentStorage.LookupByKey(GetPvpTalentMap(GetActiveTalentGroup())[slot]);
                if (talentInfo == null)
                {
                    continue;
                }

                if (talentInfo.SpellID == 0)
                {
                    continue;
                }

                AddPvpTalent(talentInfo, GetActiveTalentGroup(), slot);
            }

            LearnSpecializationSpells();

            if (CanUseMastery())
            {
                for (uint i = 0; i < PlayerConst.MaxMasterySpells; ++i)
                {
                    uint mastery = spec.MasterySpellID[i];
                    if (mastery != 0)
                    {
                        LearnSpell(mastery, false);
                    }
                }
            }

            InitTalentForLevel();

            PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHARACTER_ACTIONS_SPEC);

            stmt.AddValue(0, GetGUID().GetCounter());
            stmt.AddValue(1, GetActiveTalentGroup());

            WorldSession mySess = GetSession();

            mySess.GetQueryProcessor().AddCallback(DB.Characters.AsyncQuery(stmt).WithCallback(result =>
            {
                // in case player logs out before db response (player would be deleted in that case)
                Player thisPlayer = mySess.GetPlayer();
                if (thisPlayer != null)
                {
                    thisPlayer.LoadActions(result);
                }
            }));

            UpdateDisplayPower();
            PowerType pw = GetPowerType();

            if (pw != PowerType.Mana)
            {
                SetPower(PowerType.Mana, 0); // Mana must be 0 even if it isn't the active power type.
            }
            SetPower(pw, 0);
            UpdateItemSetAuras(false);

            // update visible transmog
            for (byte i = EquipmentSlot.Start; i < EquipmentSlot.End; ++i)
            {
                Item equippedItem = GetItemByPos(InventorySlots.Bag0, i);
                if (equippedItem)
                {
                    SetVisibleItemSlot(i, equippedItem);
                }
            }

            foreach (uint glyphId in GetGlyphs(spec.OrderIndex))
            {
                CastSpell(this, CliDB.GlyphPropertiesStorage.LookupByKey(glyphId).SpellID, true);
            }

            ActiveGlyphs activeGlyphs = new();

            foreach (uint glyphId in GetGlyphs(spec.OrderIndex))
            {
                List <uint> bindableSpells = Global.DB2Mgr.GetGlyphBindableSpells(glyphId);
                foreach (uint bindableSpell in bindableSpells)
                {
                    if (HasSpell(bindableSpell) && !m_overrideSpells.ContainsKey(bindableSpell))
                    {
                        activeGlyphs.Glyphs.Add(new GlyphBinding(bindableSpell, (ushort)glyphId));
                    }
                }
            }

            activeGlyphs.IsFullUpdate = true;
            SendPacket(activeGlyphs);

            Item item = GetItemByEntry(PlayerConst.ItemIdHeartOfAzeroth, ItemSearchLocation.Everywhere);

            if (item != null)
            {
                AzeriteItem azeriteItem = item.ToAzeriteItem();
                if (azeriteItem != null)
                {
                    if (azeriteItem.IsEquipped())
                    {
                        ApplyAllAzeriteEmpoweredItemMods(false);
                        ApplyAzeritePowers(azeriteItem, false);
                    }

                    azeriteItem.SetSelectedAzeriteEssences(spec.Id);

                    if (azeriteItem.IsEquipped())
                    {
                        ApplyAzeritePowers(azeriteItem, true);
                        ApplyAllAzeriteEmpoweredItemMods(true);
                    }

                    azeriteItem.SetState(ItemUpdateState.Changed, this);
                }
            }

            var shapeshiftAuras = GetAuraEffectsByType(AuraType.ModShapeshift);

            foreach (AuraEffect aurEff in shapeshiftAuras)
            {
                aurEff.HandleShapeshiftBoosts(this, false);
                aurEff.HandleShapeshiftBoosts(this, true);
            }
        }
Ejemplo n.º 4
0
 public void LoadToys()
 {
     foreach (var pair in _toys)
     {
         _owner.GetPlayer().AddToy(pair.Key, (uint)pair.Value);
     }
 }
Ejemplo n.º 5
0
        public static void HandleMoveStartForward(ref PacketReader packet, ref WorldSession session)
        {
            Unit mover = session.GetPlayer();

            Player plrMover = mover.ToPlayer();

            var mi = new MovementInfo();

            mi.Pos = new ObjectPosition()
            {
                X = packet.ReadFloat(),
                Y = packet.ReadFloat(),
                Z = packet.ReadFloat()
            };

            byte[] mask = new byte[8];

            mask[5] = packet.GetBit();
            mask[4] = packet.GetBit();
            mi.Status.HasSplineElevation = !packet.ReadBit();
            mask[3] = packet.GetBit();
            mi.Status.HasTransportData = packet.ReadBit();
            mi.Status.HasOrientation   = !packet.ReadBit();
            bool Unknown = packet.ReadBit();

            mask[6] = packet.GetBit();
            mi.Status.HasMovementFlags2 = !packet.ReadBit();
            mask[0] = packet.GetBit();
            mask[2] = packet.GetBit();
            bool Unknown2 = packet.ReadBit();
            bool Unknown3 = packet.ReadBit();

            mask[7]           = packet.GetBit();
            mi.Status.IsAlive = !packet.ReadBit();
            uint counter = packet.GetBits <uint>(24);

            mask[1] = packet.GetBit();
            mi.Status.HasTimeStamp     = !packet.ReadBit();
            mi.Status.HasPitch         = !packet.ReadBit();
            mi.Status.HasMovementFlags = !packet.ReadBit();
            bool Unknown4 = packet.ReadBit();

            if (mi.Status.HasMovementFlags2)
            {
                mi.Flags2 = (MovementFlag2)packet.GetBits <uint>(13);
            }

            if (mi.Status.HasTransportData)
            {
            }

            if (mi.Status.HasFallData)
            {
                mi.Status.HasFallDirection = packet.ReadBit();
            }

            if (mi.Status.HasMovementFlags)
            {
                mi.Flags = (MovementFlag)packet.GetBits <uint>(30);
            }

            mi.Guid[1] = packet.ReadByteSeq(mask[1]);

            for (int i = 0; i < counter; i++)
            {
                packet.ReadUInt32();
            }

            mi.Guid[0] = packet.ReadByteSeq(mask[0]);
            mi.Guid[4] = packet.ReadByteSeq(mask[4]);
            mi.Guid[2] = packet.ReadByteSeq(mask[2]);
            mi.Guid[5] = packet.ReadByteSeq(mask[5]);
            mi.Guid[3] = packet.ReadByteSeq(mask[3]);
            mi.Guid[7] = packet.ReadByteSeq(mask[7]);
            mi.Guid[6] = packet.ReadByteSeq(mask[6]);

            if (mi.Status.HasTransportData)
            {
            }

            if (mi.Status.HasFallData)
            {
            }

            if (mi.Status.IsAlive)
            {
                mi.Time = packet.ReadUInt32();
            }

            if (mi.Status.HasOrientation)
            {
                mi.Pos.Orientation = packet.ReadFloat();
            }

            if (mi.Status.HasSplineElevation)
            {
                mi.SplineElevation = packet.ReadFloat();
            }

            if (mi.Status.HasTimeStamp)
            {
                mi.Time = packet.ReadUInt32();
            }

            if (mi.Status.HasPitch)
            {
                mi.Pitch = packet.ReadFloat();
            }

            HandleMoveUpdate(ref session, mi);
        }
Ejemplo n.º 6
0
 public static void HandleAttackStopOpcode(ref PacketReader packet, ref WorldSession session)
 {
     session.GetPlayer().AttackStop();
 }