Esempio n. 1
0
 private void OnServerJoin(JoinEventArgs args)
 {
     try
     {
         Data.Job.GetJob(TShock.Players[args.Who].Name);
     }catch
     {
         Data.Job job = new Data.Job(Data.Job.JobType.白丁, 0, TShock.Players[args.Who].Name);
         job.Save();
     }
 }
Esempio n. 2
0
        private void RPG(CommandArgs args)
        {
            Data.Job job;
            try
            {
                job = Data.Job.GetJob(args.Player.Name);
            }
            catch
            {
                job = new Data.Job(Data.Job.JobType.白丁, 0, args.Player.Name);
                job.Save();
            }
            var config = Data.Config.GetConfig();
            var bank   = Shop.Data.GetBank(args.Player.Name);

            if (args.Parameters.Count() == 0 || args.Parameters[0] == "help")
            {
                args.Player.SendInfoMessage("您当前的职业为:" + job.jobType);
                args.Player.SendInfoMessage("您当前的余额为:" + bank.Money);
                if (job.jobType == Data.Job.JobType.白丁)
                {
                    args.Player.SendInfoMessage("输入/job choose 战士,并花费" + config.Player.DefaultLevelUp
                                                + "余额可升级到[战士lv1]");
                    args.Player.SendInfoMessage("输入/job choose 法师,并花费" + config.Player.DefaultLevelUp
                                                + "余额可升级到[法师lv1]");
                    args.Player.SendInfoMessage("输入/job choose 射手,并花费" + config.Player.DefaultLevelUp
                                                + "余额可升级到[射手lv1]");
                }
                else
                {
                    args.Player.SendInfoMessage("您可花费" + Data.GetNextLevelPrize(job.Level) + $"升级到[{job.jobType}lv{job.Level + 1}]" +
                                                $"您当前伤害加成为原伤害的{100 + job.Level * config.Player.DamageAdd}%,升级后可提升到" +
                                                $"{100 + (job.Level + 1) * config.Player.DamageAdd}");
                    args.Player.SendInfoMessage("输入/job lvup [等级],升级,不填写等级默认为升一级");
                    args.Player.SendInfoMessage($"若想转职,则必须先遗忘此职业,需花费" + Data.GetNextLevelPrize(job.Level)
                                                + "并输入/job 孟婆汤," +
                                                "遗忘职业后才能重新选职业");
                }
                if (args.Player.HasPermission("RPG.admin"))
                {
                    args.Player.SendInfoMessage("输入/job lv 等级 [玩家名字],更改玩家等级(不填为自己)");
                    args.Player.SendInfoMessage("输入/job type 战士/法师/射手/白丁 [玩家名字],更改玩家职业");
                    args.Player.SendInfoMessage("输入/job clear 玩家名字/all,清空指定玩家/所有数据");
                }
                return;
            }
            switch (args.Parameters[0])
            {
            case "clear":
                if (!args.Player.HasPermission("RPG.admin"))
                {
                    args.Player.SendErrorMessage("抱歉,您无权限操作");
                    return;
                }
                if (args.Parameters[1] == "all")
                {
                    Data.Command("delete from job");
                    foreach (var v in TShock.Players)
                    {
                        if (v == null)
                        {
                            continue;
                        }
                        Data.Job j = new Data.Job(Data.Job.JobType.白丁, 0, v.Name);
                        j.Save();
                    }
                    args.Player.SendSuccessMessage("删除成功,已清除所有数据");
                    return;
                }
                Data.Command($"delete from job where Name='{args.Parameters[1]}'");
                Data.Job b = new Data.Job(Data.Job.JobType.白丁, 0, args.Parameters[1]);
                b.Save();
                args.Player.SendSuccessMessage($"删除成功,已清除{args.Parameters[1]}的数据");
                break;

            case "type":
                if (!args.Player.HasPermission("RPG.admin"))
                {
                    args.Player.SendErrorMessage("抱歉,您无权限操作");
                    return;
                }
                var __job = args.Parameters.Count() == 3 ? Data.Job.GetJob(args.Parameters[2]) : job;
                switch (args.Parameters[1])
                {
                case "战士":
                    __job.jobType = Data.Job.JobType.战士;
                    __job.Save();
                    args.Player.SendSuccessMessage("修改成功," + (args.Parameters.Count() == 3 ?
                                                              args.Parameters[2] : "您") + "的职业已改为战士");
                    break;

                case "法师":
                    __job.jobType = Data.Job.JobType.法师;
                    __job.Save();
                    args.Player.SendSuccessMessage("修改成功," + (args.Parameters.Count() == 3 ?
                                                              args.Parameters[2] : "您") + "的职业已改为法师");
                    break;

                case "射手":
                    __job.jobType = Data.Job.JobType.射手;
                    __job.Save();
                    args.Player.SendSuccessMessage("修改成功," + (args.Parameters.Count() == 3 ?
                                                              args.Parameters[2] : "您") + "的职业已改为射手");
                    break;

                case "白丁":
                    __job.jobType = Data.Job.JobType.白丁;
                    __job.Save();
                    args.Player.SendSuccessMessage("修改成功," + (args.Parameters.Count() == 3 ?
                                                              args.Parameters[2] : "您") + "已变为白丁");
                    break;
                }
                break;

            case "lv":
                if (!args.Player.HasPermission("RPG.admin"))
                {
                    args.Player.SendErrorMessage("抱歉,您无权限操作");
                    return;
                }
                var _job = args.Parameters.Count() == 3 ? Data.Job.GetJob(args.Parameters[2]) : job;
                if (_job.jobType == Data.Job.JobType.白丁)
                {
                    args.Player.SendErrorMessage("抱歉,白丁的等级无法修改");
                    return;
                }
                int lv = int.Parse(args.Parameters[1]);
                if (lv <= 0)
                {
                    lv = 1;
                }
                _job.Level = lv;
                _job.Save();
                args.Player.SendSuccessMessage((args.Parameters.Count() == 3 ? args.Parameters[2] : "您") +
                                               "的等级已改为" + _job.Level);
                break;

            case "孟婆汤":
                if (job.jobType == Data.Job.JobType.白丁)
                {
                    args.Player.SendErrorMessage("抱歉,白丁无法遗忘职业,请先选择职业");
                    return;
                }
                var prize = Data.GetNextLevelPrize(job.Level);
                if (bank.Money < prize)
                {
                    args.Player.SendErrorMessage("抱歉,您没有足够的余额购买孟婆汤,遗忘职业失败");
                    return;
                }
                bank.Money -= prize;
                bank.Save();
                job.jobType = Data.Job.JobType.白丁;
                job.Level   = 0;
                job.Save();
                args.Player.SendSuccessMessage("购买成功!您现在为[白丁lv0]");
                break;

            case "lvup":
                if (job.jobType == Data.Job.JobType.白丁)
                {
                    args.Player.SendErrorMessage("抱歉,白丁无法升级,请先选择职业");
                    return;
                }
                long level = args.Parameters.Count == 1 ?1:int.Parse(args.Parameters[1]);
                if (level <= 0)
                {
                    args.Player.SendErrorMessage("等级不能<=0");
                    return;
                }
                long money = 0;
                for (int i = 0; i < level; i++)
                {
                    money += Data.GetNextLevelPrize(job.Level + i);
                }
                if (bank.Money < money)
                {
                    args.Player.SendErrorMessage($"抱歉,您没有足够的余额来升级,升级到[{job.jobType}lv{job.Level+level}]" +
                                                 $"需要花费{money}余额,您还差{money-bank.Money}余额");
                    return;
                }
                bank.Money -= money;
                bank.Save();
                job.Level += level;
                job.Save();
                args.Player.SendInfoMessage("升级成功,您现在为[" + job.jobType + "lv" + job.Level + "],您的余额为" + bank.Money);
                break;

            case "choose":
                if (job.jobType != Data.Job.JobType.白丁)
                {
                    args.Player.SendInfoMessage("请先购买孟婆汤遗忘职业才能重新选择职业");
                    return;
                }
                if (bank.Money < config.Player.DefaultLevelUp)
                {
                    args.Player.SendErrorMessage("您没有足够的余额选择职业");
                    return;
                }
                switch (args.Parameters[1])
                {
                case "战士":
                    job.jobType = Data.Job.JobType.战士;
                    job.Level   = 1;
                    job.Save();
                    bank.Money -= config.Player.DefaultLevelUp;
                    bank.Save();
                    args.Player.SendSuccessMessage("职业选择成功!您现在是[战士lv1]");
                    break;

                case "法师":
                    job.jobType = Data.Job.JobType.法师;
                    job.Level   = 1;
                    job.Save();
                    bank.Money -= config.Player.DefaultLevelUp;
                    bank.Save();
                    args.Player.SendSuccessMessage("职业选择成功!您现在是[法师lv1]");
                    break;

                case "射手":
                    job.jobType = Data.Job.JobType.射手;
                    job.Level   = 1;
                    job.Save();
                    bank.Money -= config.Player.DefaultLevelUp;
                    bank.Save();
                    args.Player.SendSuccessMessage("职业选择成功!您现在是[射手lv1]");
                    break;
                }
                break;
            }
        }