Example #1
0
            public void HandlePacket(GameClient client, GSPacketIn packet)
            {
                if (!DOL.GS.ServerProperties.Properties.ALLOW_TRAIN_ANYWHERE && client.Account.PrivLevel == (int)ePrivLevel.Player)
                {
                    GameTrainer trainer = client.Player.TargetObject as DOL.GS.GameTrainer;
                    if (trainer == null || (trainer.CanTrain(client.Player) == false && trainer.CanTrainChampionLevels(client.Player) == false))
                    {
                        client.Out.SendMessage("You must select a valid trainer for your class.", eChatType.CT_Important, eChatLoc.CL_ChatWindow);
                        return;
                    }
                }

                client.Out.SendTrainerWindow();
            }
Example #2
0
        public void OnCommand(GameClient client, string[] args)
        {
            if (!automated && IsSpammingCommand(client.Player, "train"))
            {
                return;
            }

            if (!ServerProperties.Properties.CUSTOM_TRAIN)
            {
                client.Out.SendTrainerWindow();
                return;
            }

            GameTrainer trainer = client.Player.TargetObject as GameTrainer;

            // Make sure the player is at a trainer.
            if (client.Account.PrivLevel == (int)ePrivLevel.Player && (trainer == null || trainer.CanTrain(client.Player) == false))
            {
                client.Out.SendMessage("You have to be at your trainer to use this command.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                return;
            }

            // Make sure the user gave us atleast the specialization line and the level to train it to.
            if (args.Length < 3)
            {
                DisplaySyntax(client);
                return;
            }

            // Get the level to train the specialization line to.
            int level;

            if (!int.TryParse(args[args.Length - 1], out level))
            {
                DisplaySyntax(client);
                return;
            }

            // Get the specialization line.
            string line = string.Join(" ", args, 1, args.Length - 2);

            line = GameServer.Database.Escape(line);

            var dbSpec = GameServer.Database.SelectObjects <DBSpecialization>("`KeyName` LIKE @KeyName", new QueryParameter("@KeyName", string.Format("{0}%", line))).FirstOrDefault();

            Specialization spec = null;

            if (dbSpec != null)
            {
                spec = client.Player.GetSpecializationByName(dbSpec.KeyName);
            }
            else
            {
                // if this is a custom line it might not be in the db so search for exact match on player
                spec = client.Player.GetSpecializationByName(line);
            }

            if (spec == null)
            {
                client.Out.SendMessage("The provided skill could not be found.", eChatType.CT_System, eChatLoc.CL_SystemWindow);

                return;
            }

            // Make sure the player can actually train the given specialization.
            int currentSpecLevel = spec.Level;

            if (currentSpecLevel >= client.Player.BaseLevel)
            {
                client.Out.SendMessage(CantTrainSpec, eChatType.CT_System, eChatLoc.CL_SystemWindow);

                return;
            }

            if (level <= currentSpecLevel)
            {
                client.Out.SendMessage("You have already trained the skill to this amount!", eChatType.CT_System,
                                       eChatLoc.CL_SystemWindow);

                return;
            }

            // Calculate the points to remove for training the specialization.
            level -= currentSpecLevel;
            ushort skillSpecialtyPoints = 0;
            int    specLevel            = 0;
            bool   changed          = false;
            bool   canAutotrainSpec = client.Player.GetAutoTrainPoints(spec, 4) != 0;
            int    autotrainPoints  = client.Player.GetAutoTrainPoints(spec, 3);

            for (int i = 0; i < level; i++)
            {
                if (spec.Level + specLevel >= client.Player.BaseLevel)
                {
                    client.Out.SendMessage(CantTrainSpec, eChatType.CT_System, eChatLoc.CL_SystemWindow);

                    break;
                }

                // graveen: /train now match 1.87 autotrain rules
                if ((client.Player.SkillSpecialtyPoints + autotrainPoints) - skillSpecialtyPoints >= (spec.Level + specLevel) + 1)
                {
                    changed = true;
                    skillSpecialtyPoints += (ushort)((spec.Level + specLevel) + 1);

                    if (spec.Level + specLevel < client.Player.Level / 4 && canAutotrainSpec)
                    {
                        skillSpecialtyPoints -= (ushort)((spec.Level + specLevel) + 1);
                    }

                    specLevel++;
                }
                else
                {
                    var sb = new StringBuilder();
                    sb.AppendLine("That specialization costs " + (spec.Level + 1) + " specialization points!");
                    sb.AppendLine(NotEnoughPointsLeft);

                    client.Out.SendMessage(sb.ToString(), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                    break;
                }
            }

            if (changed)
            {
                // tolakram - add some additional error checking to avoid overflow error
                if (client.Player.SkillSpecialtyPoints >= skillSpecialtyPoints)
                {
                    spec.Level += specLevel;

                    client.Player.OnSkillTrained(spec);

                    client.Out.SendUpdatePoints();
                    client.Out.SendTrainerWindow();

                    client.Out.SendMessage("Training complete!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                }
                else
                {
                    var sb = new StringBuilder();
                    sb.AppendLine("That specialization costs " + (spec.Level + 1) + " specialization points!");
                    sb.AppendLine(NotEnoughPointsLeft);

                    client.Out.SendMessage(sb.ToString(), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                }
            }
        }
Example #3
0
        public void OnCommand(GameClient client, string[] args)
        {
            if (args.Length < 2)
            {
                if (ServerProperties.Properties.FREE_RESPEC)
                {
                    DisplayMessage(client, "Target any trainer and use:");
                    DisplayMessage(client, "/respec ALL or /respec DOL to respec all skills");
                    DisplayMessage(client, "/respec <line name> to respec a single skill line");
                    DisplayMessage(client, "/respec REALM to respec realm abilities");
                    DisplayMessage(client, "/respec CHAMPION to respec champion abilities");
                    return;
                }

                // Check for respecs.
                if (client.Player.RespecAmountAllSkill < 1 &&
                    client.Player.RespecAmountSingleSkill < 1 &&
                    client.Player.RespecAmountDOL < 1 &&
                    client.Player.RespecAmountRealmSkill < 1)
                {
                    DisplayMessage(client, "You don't seem to have any respecs available.");
                    DisplayMessage(client, "Use /respec buy to buy an single-line respec.");
                    return;
                }

                if (client.Player.RespecAmountAllSkill > 0)
                {
                    DisplayMessage(client, "You have " + client.Player.RespecAmountAllSkill + " full skill respecs available.");
                    DisplayMessage(client, "Target any trainer and use /respec ALL");
                }
                if (client.Player.RespecAmountSingleSkill > 0)
                {
                    DisplayMessage(client, "You have " + client.Player.RespecAmountSingleSkill + " single-line respecs available.");
                    DisplayMessage(client, "Target any trainer and use /respec <line name>");
                }
                if (client.Player.RespecAmountRealmSkill > 0)
                {
                    DisplayMessage(client, "You have " + client.Player.RespecAmountRealmSkill + " realm skill respecs available.");
                    DisplayMessage(client, "Target any trainer and use /respec REALM");
                }
                if (client.Player.RespecAmountDOL > 0)
                {
                    DisplayMessage(client, "You have " + client.Player.RespecAmountDOL + " DOL ( full skill ) respecs available.");
                    DisplayMessage(client, "Target any trainer and use /respec DOL");
                }
                DisplayMessage(client, "Use /respec buy to buy an single-line respec.");
                return;
            }

            GameTrainer trainer = client.Player.TargetObject as GameTrainer;

            // Player must be speaking with trainer to respec.  (Thus have trainer targeted.) Prevents losing points out in the wild.
            if (args[1].ToLower() != "buy" && (trainer == null || !trainer.CanTrain(client.Player)))
            {
                DisplayMessage(client, "You must be speaking with your trainer to respec.");
                return;
            }

            switch (args[1].ToLower())
            {
            case "buy":
            {
                if (ServerProperties.Properties.FREE_RESPEC)
                {
                    return;
                }

                // Buy respec
                if (client.Player.CanBuyRespec == false || client.Player.RespecCost < 0)
                {
                    DisplayMessage(client, "You can't buy a respec on this level again.");
                    return;
                }

                long mgold = client.Player.RespecCost;
                if ((client.Player.Gold + 1000 * client.Player.Platinum) < mgold)
                {
                    DisplayMessage(client, "You don't have enough money! You need " + mgold + " gold!");
                    return;
                }
                client.Out.SendCustomDialog("It costs " + mgold + " gold. Want you really buy?", new CustomDialogResponse(RespecDialogResponse));
                client.Player.TempProperties.setProperty(BUY_RESPEC, true);
                break;
            }

            case "all":
            {
                // Check for full respecs.
                if (client.Player.RespecAmountAllSkill < 1 &&
                    !ServerProperties.Properties.FREE_RESPEC)
                {
                    DisplayMessage(client, "You don't seem to have any full skill respecs available.");
                    return;
                }

                client.Out.SendCustomDialog("CAUTION: All respec changes are final with no second chance. Proceed carefully!", new CustomDialogResponse(RespecDialogResponse));
                client.Player.TempProperties.setProperty(ALL_RESPEC, true);
                break;
            }

            case "dol":
            {
                // Check for DOL respecs.
                if (client.Player.RespecAmountDOL < 1 &&
                    !ServerProperties.Properties.FREE_RESPEC)
                {
                    DisplayMessage(client, "You don't seem to have any DOL respecs available.");
                    return;
                }

                client.Out.SendCustomDialog("CAUTION: All respec changes are final with no second chance. Proceed carefully!", new CustomDialogResponse(RespecDialogResponse));
                client.Player.TempProperties.setProperty(DOL_RESPEC, true);
                break;
            }

            case "realm":
            {
                if (client.Player.RespecAmountRealmSkill < 1 &&
                    !ServerProperties.Properties.FREE_RESPEC)
                {
                    DisplayMessage(client, "You don't seem to have any realm skill respecs available.");
                    return;
                }

                client.Out.SendCustomDialog("CAUTION: All respec changes are final with no second chance. Proceed carefully!", new CustomDialogResponse(RespecDialogResponse));
                client.Player.TempProperties.setProperty(RA_RESPEC, true);
                break;
            }

            case "champion":
            {
                if (ServerProperties.Properties.FREE_RESPEC)
                {
                    client.Out.SendCustomDialog("CAUTION: All respec changes are final with no second chance. Proceed carefully!", new CustomDialogResponse(RespecDialogResponse));
                    client.Player.TempProperties.setProperty(CHAMP_RESPEC, true);
                    break;
                }
                return;
            }

            default:
            {
                // Check for single-line respecs.
                if (client.Player.RespecAmountSingleSkill < 1 &&
                    !ServerProperties.Properties.FREE_RESPEC)
                {
                    DisplayMessage(client, "You don't seem to have any single-line respecs available.");
                    return;
                }

                string         lineName = string.Join(" ", args, 1, args.Length - 1);
                Specialization specLine = client.Player.GetSpecializationByName(lineName, false);
                if (specLine == null)
                {
                    DisplayMessage(client, "No line with name '" + lineName + "' found.");
                    return;
                }
                if (specLine.Level < 2)
                {
                    DisplayMessage(client, "Level of " + specLine.Name + " line is less than 2. ");
                    return;
                }

                client.Out.SendCustomDialog("CAUTION: All respec changes are final with no second chance. Proceed carefully!", new CustomDialogResponse(RespecDialogResponse));
                client.Player.TempProperties.setProperty(LINE_RESPEC, specLine);
                break;
            }
            }
        }
Example #4
0
        public void HandlePacket(GameClient client, GSPacketIn packet)
        {
            if (!DOL.GS.ServerProperties.Properties.ALLOW_TRAIN_ANYWHERE && client.Account.PrivLevel == (int)ePrivLevel.Player)
            {
                GameTrainer trainer = client.Player.TargetObject as DOL.GS.GameTrainer;
                if (trainer == null || (trainer.CanTrain(client.Player) == false && trainer.CanTrainChampionLevels(client.Player) == false))
                {
                    client.Out.SendMessage("You must select a valid trainer for your class.", eChatType.CT_Important, eChatLoc.CL_ChatWindow);
                    return;
                }
            }

            uint x          = packet.ReadInt();
            uint y          = packet.ReadInt();
            int  idLine     = packet.ReadByte();
            int  unk        = packet.ReadByte();
            int  row        = packet.ReadByte();
            int  skillIndex = packet.ReadByte();

            // idline not null so this is a Champion level training window
            if (idLine > 0)
            {
                if (row > 0 && skillIndex > 0)
                {
                    // Get Player CL Spec
                    var clspec = client.Player.GetSpecList().Where(sp => sp is LiveChampionsSpecialization).Cast <LiveChampionsSpecialization>().FirstOrDefault();

                    // check if the tree can be used
                    List <Tuple <MiniLineSpecialization, List <Tuple <Skill, byte> > > > tree = null;
                    if (clspec != null)
                    {
                        tree = clspec.GetTrainerTreeDisplay(client.Player, clspec.RetrieveTypeForIndex(idLine));
                    }

                    if (tree != null)
                    {
                        Tuple <byte, MiniLineSpecialization> skillstatus = clspec.GetSkillStatus(tree, row - 1, skillIndex - 1);

                        if (skillstatus.Item1 == 1)
                        {
                            client.Out.SendMessage("You already have that ability!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                            return;
                        }
                        if (skillstatus.Item1 != 2)
                        {
                            client.Out.SendMessage("You do not meet the requirements for that ability!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                            return;
                        }
                        if (client.Player.ChampionSpecialtyPoints < 1)
                        {
                            client.Out.SendMessage("You do not have enough champion specialty points for that ability!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                            return;
                        }

                        skillstatus.Item2.Level++;
                        client.Player.AddSpecialization(skillstatus.Item2);
                        client.Player.RefreshSpecDependantSkills(false);
                        client.Player.Out.SendUpdatePlayer();
                        client.Player.Out.SendUpdatePoints();
                        client.Player.Out.SendUpdatePlayerSkills();
                        client.Player.UpdatePlayerStatus();
                        client.Player.Out.SendChampionTrainerWindow(idLine);

                        return;
                    }
                    else
                    {
                        client.Out.SendMessage("Could not find Champion Spec!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                        log.ErrorFormat("Could not find Champion Spec idline {0}, row {1}, skillindex {2}", idLine, row, skillIndex);
                    }
                }
            }
            else
            {
                // Trainable Specs or RA's
                IList <Specialization> speclist = client.Player.GetSpecList().Where(e => e.Trainable).ToList();

                if (skillIndex < speclist.Count)
                {
                    Specialization spec = (Specialization)speclist[skillIndex];
                    if (spec.Level >= client.Player.BaseLevel)
                    {
                        client.Out.SendMessage("You can't train in this specialization again this level!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                        return;
                    }

                    // Graveen - autotrain 1.87 - allow players to train their AT specs even if no pts left
                    int temp = client.Player.SkillSpecialtyPoints + client.Player.GetAutoTrainPoints(spec, 2);

                    if (temp >= spec.Level + 1)
                    {
                        spec.Level++;
                        client.Player.OnSkillTrained(spec);

                        client.Out.SendUpdatePoints();
                        client.Out.SendTrainerWindow();
                        return;
                    }
                    else
                    {
                        client.Out.SendMessage("That specialization costs " + (spec.Level + 1) + " specialization points!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                        client.Out.SendMessage("You don't have that many specialization points left for this level.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                        return;
                    }
                }
                else if (skillIndex >= 100)
                {
                    // Realm Abilities
                    var raList = SkillBase.GetClassRealmAbilities(client.Player.CharacterClass.ID).Where(ra => !(ra is RR5RealmAbility));
                    if (skillIndex < raList.Count() + 100)
                    {
                        RealmAbility ra = raList.ElementAtOrDefault(skillIndex - 100);
                        if (ra != null)
                        {
                            ra.Level = client.Player.GetAbilityLevel(ra.KeyName);
                            int cost = ra.CostForUpgrade(ra.Level);
                            ra.Level++;

                            if (client.Player.RealmSpecialtyPoints < cost)
                            {
                                client.Out.SendMessage(ra.Name + " costs " + (cost) + " realm ability points!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                                client.Out.SendMessage("You don't have that many realm ability points left to get this.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                                return;
                            }
                            if (!ra.CheckRequirement(client.Player))
                            {
                                client.Out.SendMessage("You are not experienced enough to get " + ra.Name + " now. Come back later.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                                return;
                            }

                            client.Player.AddRealmAbility(ra, true);
                            client.Out.SendUpdatePoints();
                            client.Out.SendUpdatePlayer();
                            client.Out.SendUpdatePlayerSkills();
                            client.Out.SendTrainerWindow();
                        }
                        else
                        {
                            client.Out.SendMessage("Unfortunately your training failed. Please report that to admins or game master. Thank you.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                            log.Error("Realm Ability " + ra.Name + "(" + ra.KeyName + ") unexpected not found");
                        }
                    }
                }

                if (log.IsErrorEnabled)
                {
                    log.Error("Player <" + client.Player.Name + "> requested to train incorrect skill index");
                }
            }
        }
Example #5
0
        public void HandlePacket(GameClient client, GSPacketIn packet)
        {
            if (!DOL.GS.ServerProperties.Properties.ALLOW_TRAIN_ANYWHERE && client.Account.PrivLevel == (int)ePrivLevel.Player)
            {
                // A trainer of the appropriate class must be around (or global trainer, with TrainedClass = eCharacterClass.Unknow
                GameTrainer trainer = client.Player.TargetObject as DOL.GS.GameTrainer;
                if (trainer == null || (trainer.CanTrain(client.Player) == false && trainer.CanTrainChampionLevels(client.Player) == false))
                {
                    client.Out.SendMessage("You must select a valid trainer for your class.", eChatType.CT_Important, eChatLoc.CL_ChatWindow);
                    return;
                }
            }

            //Specializations - 8 trainable specs max
            uint                    size     = 8;
            long                    position = packet.Position;
            IList <uint>            skills   = new List <uint>();
            Dictionary <uint, uint> amounts  = new Dictionary <uint, uint>();
            bool                    stop     = false;

            for (uint i = 0; i < size; i++)
            {
                uint code = packet.ReadInt();
                if (!stop)
                {
                    if (code == 0xFFFFFFFF)
                    {
                        stop = true;
                    }
                    else
                    {
                        if (!skills.Contains(code))
                        {
                            skills.Add(code);
                        }
                    }
                }
            }

            foreach (uint code in skills)
            {
                uint val = packet.ReadInt();

                if (!amounts.ContainsKey(code) && val > 1)
                {
                    amounts.Add(code, val);
                }
            }

            IList <Specialization> specs = client.Player.GetSpecList().Where(e => e.Trainable).ToList();
            uint           skillcount    = 0;
            IList <string> done          = new List <string>();
            bool           trained       = false;

            // Graveen: the trainline command is called
            foreach (Specialization spec in specs)
            {
                if (amounts.ContainsKey(skillcount))
                {
                    if (spec.Level < amounts[skillcount])
                    {
                        TrainCommandHandler train = new TrainCommandHandler(true);
                        train.OnCommand(client, new string[] { "&trainline", spec.KeyName, amounts[skillcount].ToString() });
                        trained = true;
                    }
                }
                skillcount++;
            }

            //RealmAbilities
            packet.Seek(position + 64, System.IO.SeekOrigin.Begin);
            size = 50;            //50 RA's max?
            amounts.Clear();
            for (uint i = 0; i < size; i++)
            {
                uint val = packet.ReadInt();

                if (val > 0 && !amounts.ContainsKey(i))
                {
                    amounts.Add(i, val);
                }
            }

            if (amounts != null && amounts.Count > 0)
            {
                // Realm Abilities
                var raList = SkillBase.GetClassRealmAbilities(client.Player.CharacterClass.ID).Where(ra => !(ra is RR5RealmAbility));
                foreach (var kv in amounts)
                {
                    RealmAbility ra = raList.ElementAtOrDefault((int)kv.Key);
                    if (ra != null)
                    {
                        RealmAbility playerRA = (RealmAbility)client.Player.GetAbility(ra.KeyName);

                        if (playerRA != null && (playerRA.Level >= ra.MaxLevel || playerRA.Level >= kv.Value))
                        {
                            continue;
                        }

                        int cost = 0;
                        for (int i = playerRA != null ? playerRA.Level : 0; i < kv.Value; i++)
                        {
                            cost += ra.CostForUpgrade(i);
                        }

                        if (client.Player.RealmSpecialtyPoints < cost)
                        {
                            client.Out.SendMessage(ra.Name + " costs " + (cost) + " realm ability points!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                            client.Out.SendMessage("You don't have that many realm ability points left to get this.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                            continue;
                        }

                        if (!ra.CheckRequirement(client.Player))
                        {
                            client.Out.SendMessage("You are not experienced enough to get " + ra.Name + " now. Come back later.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                            continue;
                        }

                        bool valid = false;
                        if (playerRA != null)
                        {
                            playerRA.Level = (int)kv.Value;
                            valid          = true;
                        }
                        else
                        {
                            ra.Level = (int)kv.Value;
                            valid    = true;
                            client.Player.AddRealmAbility(ra, false);
                        }

                        if (valid)
                        {
                            client.Out.SendUpdatePoints();
                            client.Out.SendUpdatePlayer();
                            client.Out.SendCharResistsUpdate();
                            client.Out.SendCharStatsUpdate();
                            client.Out.SendUpdatePlayerSkills();
                            client.Out.SendTrainerWindow();
                            trained = true;
                        }
                        else
                        {
                            client.Out.SendMessage("Unfortunately your training failed. Please report that to admins or game master. Thank you.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                        }
                    }
                    else
                    {
                        client.Out.SendMessage("Unfortunately your training failed. Please report that to admins or game master. Thank you.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                    }
                }
            }
            if (trained)
            {
                client.Player.SaveIntoDatabase();
            }
        }