示例#1
0
        private void SavePlayerSkill(BasePlayer player, Skill skill)
        {
            if (player == null || !playerSkills.ContainsKey(player.userID))
            {
                return;
            }

            PlayerSkill pskill = playerSkills[player.userID];
            PlayerInfo  info   = playerInfo[player.userID];

            MQuery(MBuild("SELECT id FROM skills WHERE user_id=@0 AND skill=@1 LIMIT 1;", info.id, skill.code), records =>
            {
                if (records.Count == 0)
                {
                    MInsert(MBuild("INSERT INTO skills (user_id, skill, level, xp) VALUES (@0, @1, @2, @3);",
                                   info.id,
                                   skill.code,
                                   pskill.GetLevel(skill.code),
                                   pskill.GetXp(skill.code)));
                }
                else
                {
                    MNonQuery(MBuild("UPDATE skills SET level=@0, xp=@1 WHERE user_id=@2 AND skill=@3 LIMIT 1;",
                                     pskill.GetLevel(skill.code),
                                     pskill.GetXp(skill.code),
                                     info.id,
                                     skill.code));
                }
            });
        }
        private void LevelHandler(BasePlayer player, Item item, Skill skill)
        {
            if (player == null || !skills.ContainsKey(player.userID))
            {
                return;
            }

            PlayerSkill pskill = skills[player.userID];

            int  xpProc = GetExperiencePercent(player, skill);
            long level  = pskill.GetLevel(skill.code);
            long xp     = pskill.GetXp(skill.code);

            item.amount = Mathf.CeilToInt((float)(item.amount * (1 + 1 * 0.1 * (level - 1))));

            xp += 5;

            if (xp > GetLevelXp(level + 1))
            {
                level = GetXpLevel(xp);

                player.ChatMessage($"<color=\"#DD32AA\">{skill.name}</color> level up! { ((((1 + 1 * 0.1 * (level - 1)) * 100) - 100).ToString("0.##"))}% bonus");
            }

            pskill.SetLevel(skill.code, level);
            pskill.SetXp(skill.code, xp);

            var newXp = GetExperiencePercent(player, skill);

            if (newXp != xpProc)
            {
                UpdateUI(player, skill);
            }
        }