Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Additions to give skill XP when reading
- BookLearning = {};
- --Addition for skill configuration via lua, so it can be set from outside of this mod. You can make a simple list of items like "Farming", "Cooking" and such here
- BookLearning.allowedSkills = BookLearning.allowedSkills or {};
- --Add skill XP gain to book reading timed action
- BOOKLEARNING_ISReadABook_update = ISReadABook.update
- function ISReadABook:update()
- BOOKLEARNING_ISReadABook_update(self)
- local checkSuccess;
- local canLearn;
- checkSuccess, canLearn = pcall(BookLearning.checkIfCanLearn, self);
- if (checkSuccess and canLearn) then
- BookLearning.gainXP(self);
- end
- end
- --Sets o to true if the player can learn from this book
- BookLearning.checkIfCanLearn = function(self)
- local o = true;
- if (not (SkillBook[self.item:getSkillTrained()] ~= nil))
- or self.item:getLvlSkillTrained() > self.character:getPerkLevel(SkillBook[self.item:getSkillTrained()].perk) + 1
- or self.character:HasTrait("Illiterate")
- or self.item:getMaxLevelTrained() < self.character:getPerkLevel(SkillBook[self.item:getSkillTrained()].perk) + 1
- then
- o = false;
- end
- return o;
- end
- --Provides player XP for every page read.
- BookLearning.gainXP = function(self)
- local trainedStuff = SkillBook[self.item:getSkillTrained()];
- if trainedStuff then
- -- check if allowedSkills list exists, if so check if this is allowed
- if #BookLearning.allowedSkills > 0 then
- local isAllowed = false;
- for _,skill in ipairs(BookLearning.allowedSkills) do
- if tostring(trainedStuff.perk) == skill then
- isAllowed = true;
- break;
- end
- end
- if not isAllowed then
- return;
- end
- end
- -- end check
- local readPercent = (self.item:getAlreadyReadPages() / self.item:getNumberOfPages()) * 100;
- if readPercent > 100 then
- readPercent = 100;
- end
- local targetSkillLevel = self.item:getLvlSkillTrained() + self.item:getNumLevelsTrained() - 1;
- local bookMaxXP = 0;
- for i=1,targetSkillLevel do
- bookMaxXP = (bookMaxXP + BookLearning.xpByLevel[i]);
- end
- local targetXP = bookMaxXP * (readPercent / 100);
- local xpGained = math.ceil(targetXP - self.character:getXp():getXP(trainedStuff.perk));
- --Fix rounding error for XP on last page
- if readPercent == 100 then
- xpGained = xpGained + 0.1;
- end
- if xpGained > 0 then
- self.character:getXp():AddXP(trainedStuff.perk, xpGained);
- end
- end
- end
- --XP per skill level as of 41.50
- BookLearning.xpByLevel = {};
- BookLearning.xpByLevel[0] = 0;
- BookLearning.xpByLevel[1] = 75;
- BookLearning.xpByLevel[2] = 150;
- BookLearning.xpByLevel[3] = 300;
- BookLearning.xpByLevel[4] = 750;
- BookLearning.xpByLevel[5] = 1500;
- BookLearning.xpByLevel[6] = 3000;
- BookLearning.xpByLevel[7] = 4500;
- BookLearning.xpByLevel[8] = 6000;
- BookLearning.xpByLevel[9] = 7500;
- BookLearning.xpByLevel[10] = 9000;
Advertisement
Add Comment
Please, Sign In to add comment