Registers a random event related to player platforms.
Registers a random event related to player platforms.
1 table data
the data to register.
2 string inherit
the ID of another random event to inherit.
playerPlatform.EVENTS.POWER_OUTAGE = "platform_power_outage" local powerOutage = { id = "power_outage", cooldown = timeline.DAYS_IN_MONTH * 6, -- how often can this event happen? occurChance = 0.2, -- the base chance of occurence affectorRange = {0.3, 0.7}, -- the rolled affector value of sales affectorDropPerWeek = 0.03, -- how much does the affector drop by every week? devStage = playerPlatform.FINISHED_STAGE, addToList = true, canStart = function(self, platObj) if not platObj:isReleased() then return false end return platObj:isReleased() and math.random() * 100 <= self.occurChance end, setupAffectorCategory = function(self, catObj, elemW) local boost = gui.create("GradientIconPanel", nil) boost:setIcon("generic_electricity") boost:setBaseSize(elemW, 0) boost:setIconSize(20, nil, 22) boost:setFont("bh20") boost:setTextColor(game.UI_COLORS.RED) boost:setGradientColor(game.UI_COLORS.RED) boost:setText(_format(_T("PLATFORM_SALE_DECREASE_POWER_OUTAGE_SHORT", "-DEC% sales (power outage)"), "DEC", math.round(self.curAffector * 100, 1))) catObj:addItem(boost) end, onNewWeek = function(self, platObj) self.curAffector = math.max(0, self.curAffector - self.affectorDropPerWeek) if self.curAffector <= 0 then platObj:setSaleAffector(self.id, nil) platObj:setEventCooldown(self.id, timeline.curTime + self.cooldown) platObj:stopRandomEvent(self) else platObj:setSaleAffector(self.id, -self.curAffector) end end, occur = function(self, platObj) local range = self.affectorRange self.curAffector = math.randomf(range[1], range[2]) platObj:setSaleAffector(self.id, -self.curAffector) local popup = gui.create("DescboxPopup") popup:setWidth(500) popup:setFont("pix24") popup:setTitle(_T("PLATFORM_POWER_OUTAGE_TITLE", "Power Outage")) popup:setTextFont("pix20") popup:setText(_format(_T("PLATFORM_POWER_OUTAGE_DESCRIPTION", "There has been a power outage at the manufacturing facility of your 'PLATFORM' game console, which has delayed the manufacturing process, resulting in reduced production capacity for sale."), "PLATFORM", platObj:getName())) popup:setShowSound("bad_jingle") popup:hideCloseButton() local left, right, extra = popup:getDescboxes() extra:addSpaceToNextText(10) extra:addTextLine(popup.w - _S(20), game.UI_COLORS.RED, nil, "weak_gradient_horizontal") extra:addText(_format(_T("PLATFORM_SALE_DECREASE", "Sales decreased by DECREASE%"), "DECREASE", math.round(self.curAffector * 100, 1)), "bh20", game.UI_COLORS.RED, 0, popup.rawW - 20, "exclamation_point_red", 22, 22) extra:addTextLine(popup.w - _S(20), game.UI_COLORS.IMPORTANT_1, nil, "weak_gradient_horizontal") extra:addText(_T("PLATFORM_POWER_OUTAGE_RESTORE", "The manufacturing speed will eventually restore back to 100%."), "bh20", nil, 0, popup.rawW - 20, "question_mark_yellow", 22, 22) popup:addOKButton("pix20") popup:center() frameController:push(popup) conversations:addTopicToTalkAbout(playerPlatform.CONVERSATION_POWER_OUTAGE, platObj:getID()) events:fire(playerPlatform.EVENTS.POWER_OUTAGE, platObj) end } function powerOutage:save() local saved = self.baseClass.save(self) saved.curAffector = self.curAffector return saved end function powerOutage:load(data, platObj) powerOutage.baseClass.load(self, data) self.curAffector = data.curAffector platObj:setSaleAffector(self.id, self.curAffector) end playerPlatform:registerRandomEvent(powerOutage)