Advertisement
Draco18s

Perk Problem

Apr 9th, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. function OnMsg.ModsLoaded()
  2. local anyAdded = false
  3. if not DataInstances.Trait.SelfTaught then
  4. local SelfTaught = Trait:new()
  5. SelfTaught.name = "SelfTaught"
  6. SelfTaught.display_name = "Self-Taught"
  7. SelfTaught.description = "Slowly learns a new specialization by working. Can retain multiple specializations, but it takes a workshift to switch."
  8. SelfTaught.category = "Positive"
  9. SelfTaught.weight = 30
  10. SelfTaught.rare = true
  11. SelfTaught.auto = true
  12. SelfTaught.show_in_traits_ui = true
  13. SelfTaught.hidden_on_start = true
  14. SelfTaught.add_interest = ""
  15. SelfTaught.initial_filter = false
  16. SelfTaught.incompatible = "JackAllTrades"
  17. DataInstances.Trait.SelfTaught = SelfTaught
  18. anyAdded = true
  19. end
  20. if anyAdded then
  21. ModLog("Adding traits")
  22. Msg("DataLoaded")
  23. end
  24. end
  25.  
  26.  
  27. function Workplace:OnChangeWorkshift(old, new)
  28. if old then
  29. local martianborn_resilience = self.city:IsTechResearched("MartianbornResilience")
  30. local dark_penalty = IsDarkHour(self.city.hour - 4) and -g_Consts.WorkDarkHoursSanityDecrease
  31. local overtime = self.overtime[old]
  32. local outside_sanity_decrease = -g_Consts.OutsideWorkplaceSanityDecrease
  33. local is_outside_building = self:IsKindOf("OutsideHumanBuilding")
  34. for _, worker in ipairs(self.workers[old]) do
  35. local traits = worker.traits
  36. if dark_penalty then
  37. worker:ChangeSanity(dark_penalty, "work in dark hours")
  38. end
  39. if overtime and worker:IsWorking() and not traits.Workaholic then
  40. worker:ChangeHealth(-g_Consts.WorkOvertimeHealth, "overtime")
  41. worker:ChangeSanity(-g_Consts.WorkOvertimeSanityDecrease, "overtime")
  42. end
  43. if is_outside_building and (not martianborn_resilience or not traits.Martianborn) then
  44. worker:ChangeSanity(outside_sanity_decrease, "outside workplace")
  45. end
  46. --ModLog("Self Taught check: " .. tostring(traits.SelfTaught) .. ", building " .. self.specialist)
  47. if traits.SelfTaught and self.specialist ~= worker.specialist and self.specialist ~= "none" then
  48. local martianborn_adaptability = self.city:IsTechResearched("MartianbornAdaptability") and TechDef.MartianbornAdaptability.param1
  49. local gain_point = 20
  50. if martianborn_adaptability and traits.Martianborn then
  51. gain_point = gain_point + MulDivRound(martianborn_adaptability, gain_point, 100)
  52. end
  53. --ModLog(" gain_point " .. tostring(gain_point))
  54. gain_point = gain_point + MulDivRound(worker.performance, gain_point, 100)
  55. --ModLog(" gain_point " .. tostring(gain_point))
  56. worker.training_points = worker.training_points or {}
  57. worker.training_points["SelfTaught_" .. self.specialist] = (worker.training_points["SelfTaught_" .. self.specialist] or 0) + MulDivRound(gain_point, 3, g_Consts.WorkingHours)
  58. --ModLog("Senior age: " .. tostring(worker.MinAge_Senior))
  59. ModLog(" Self training progress: " .. tostring(worker.training_points["SelfTaught_" .. self.specialist]))
  60. if (worker.training_points and worker.training_points["SelfTaught_" .. self.specialist] or 0) >= 100 then
  61. worker.training_points["SelfTaught_" .. self.specialist] = 100
  62. worker:SetSpecialization(self.specialist)
  63. end
  64. end
  65. worker:InterruptVisit()
  66. end
  67. end
  68. RebuildInfopanel(self)
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement