Exemplo n.º 1
0
        private static void ProcessUseSkill(IRealmClient client, byte targetType, short skillId, ushort targetId)
        {
            Unit target = (Unit)null;

            switch (targetType)
            {
            case 0:
                target = (Unit)client.ActiveCharacter.Map.GetNpcByUniqMapId(targetId);
                break;

            case 1:
                target = (Unit)World.GetCharacterBySessionId(targetId);
                break;

            default:
                client.ActiveCharacter.SendSystemMessage(string.Format(
                                                             "Unknown skill target type {0}. SkillId {1}. Please report to developers.", (object)targetType,
                                                             (object)skillId));
                break;
            }

            if (target == null)
            {
                Asda2SpellHandler.SendUseSkillResultResponse(client.ActiveCharacter, skillId,
                                                             Asda2UseSkillResult.ChooseATarget);
            }
            else
            {
                if (targetType == (byte)1)
                {
                    Character characterBySessionId = World.GetCharacterBySessionId(targetId);
                    if ((int)characterBySessionId.Asda2FactionId == (int)client.ActiveCharacter.Asda2FactionId &&
                        client.ActiveCharacter.IsAsda2BattlegroundInProgress &&
                        characterBySessionId.IsAsda2BattlegroundInProgress)
                    {
                        Asda2SpellHandler.SendUseSkillResultResponse(client.ActiveCharacter, skillId,
                                                                     Asda2UseSkillResult.YouCannotUseSkillToTargetYet);
                        return;
                    }

                    if (characterBySessionId == null)
                    {
                        Asda2SpellHandler.SendUseSkillResultResponse(client.ActiveCharacter, skillId,
                                                                     Asda2UseSkillResult.ChooseATarget);
                        return;
                    }
                }

                Spell spellByRealId = client.ActiveCharacter.Spells.GetSpellByRealId(skillId);
                if (spellByRealId == null)
                {
                    return;
                }
                switch (client.ActiveCharacter.SpellCast.Start(spellByRealId, target))
                {
                case SpellFailedReason.OutOfRange:
                    Asda2MovmentHandler.MoveToSelectedTargetAndAttack(client.ActiveCharacter);
                    break;

                case SpellFailedReason.Ok:
                    if (spellByRealId.LearnLevel >= (byte)10)
                    {
                        if (spellByRealId.LearnLevel < (byte)30)
                        {
                            if (client.ActiveCharacter.GreenCharges < (byte)10)
                            {
                                ++client.ActiveCharacter.GreenCharges;
                            }
                        }
                        else if (spellByRealId.LearnLevel < (byte)50)
                        {
                            if (client.ActiveCharacter.BlueCharges < (byte)10)
                            {
                                ++client.ActiveCharacter.BlueCharges;
                            }
                            if (client.ActiveCharacter.GreenCharges < (byte)10)
                            {
                                ++client.ActiveCharacter.GreenCharges;
                            }
                        }
                        else
                        {
                            if (client.ActiveCharacter.RedCharges < (byte)10)
                            {
                                ++client.ActiveCharacter.RedCharges;
                            }
                            if (client.ActiveCharacter.BlueCharges < (byte)10)
                            {
                                ++client.ActiveCharacter.BlueCharges;
                            }
                            if (client.ActiveCharacter.GreenCharges < (byte)10)
                            {
                                ++client.ActiveCharacter.GreenCharges;
                            }
                        }
                    }

                    AchievementProgressRecord progressRecord =
                        client.ActiveCharacter.Achievements.GetOrCreateProgressRecord(6U);
                    switch (++progressRecord.Counter)
                    {
                    case 50:
                        client.ActiveCharacter.DiscoverTitle(Asda2TitleId.Skilled44);
                        break;

                    case 100:
                        client.ActiveCharacter.GetTitle(Asda2TitleId.Skilled44);
                        break;
                    }

                    progressRecord.SaveAndFlush();
                    Asda2SpellHandler.SendSetSkiillPowersStatsResponse(client.ActiveCharacter, true, skillId);
                    break;
                }
            }
        }