Classes

Concepts

Libraries

advertisement »

ambientSounds »

bitser »

contentPoints »

eventBoxText »

factValidity »

frameBuffer »

officeBuildingInserter »

priorityRenderer »

randomEvents »

scaling »

spritesheetParser »

statusIcons »

test3 »

util »

Objects

registerNew

Description

Registers a new trait.

Arguments

1 table data

the data to register.

2 string id

the ID of another trait to inherit.

Example

traits:registerNew({
	id = "bookworm",
	display = _T("BOOKWORM", "Bookworm"),
	quad = "trait_bookworm",
	selectableForPlayer = false,
	discoveryLevel = 4,
	experienceGainMultiplier = 1.1,
	driveLossMultiplier = 1.1, -- how much faster will this person lose drive if positioned within a room with no books

	description = _T("BOOKWORM_DESCRIPTION", "Books provide a greater boost in experience gained, but loses drive faster than usual if placed in a room with no books or empty bookshelves."),
	
	onEvent = function(self, target, event)
		self:evaluateRoom(target, target:getRoom())
	end,
	
	fillSuggestionList = function(self, employee, list, dialogueObject)
		local mult = employee:getSpecificDriveLossSpeedMultiplier(self.id)
		
		if mult and mult ~= 1 then
			table.insert(list, "developer_no_bookshelves_suggestion")
		end
	end,
		
	evaluateRoom = function(self, target, roomObject)
		local driveLossSpeedModifier = 1
		
		if roomObject then
			local found = false
			local objects = roomObject:getObjectsOfType("bookshelf")
			
			if objects then
				for key, object in ipairs(objects) do
					if #object:getStoredBooks() > 0 then
						found = true
						break
					end
				end
			end
			
			if not found then
				driveLossSpeedModifier = self.driveLossMultiplier
			end
		end
		
		target:setDriveLossSpeedMultiplier(self.id, driveLossSpeedModifier)
		
		if driveLossSpeedModifier == 1 then
			target:getAvatar():removeStatusIcon("no_books")
		else
			target:getAvatar():addStatusIcon("no_books")
		end
	end,
	
	formatDescriptionText = function(self, descBox, employee, wrapWidth, font)
		descBox:addSpaceToNextText(iconSpacing)
		descBox:addText(_format(_T("BOOKWORM_AFFECTOR_1", "MULT% more experience from books"), "MULT", math.round((self.experienceGainMultiplier - 1) * 100, 1)), font, game.UI_COLORS.LIGHT_BLUE, 0, wrapWidth, "increase", 22, 22)
		descBox:addText(_format(_T("BOOKWORM_AFFECTOR_2", "MULT% faster Drive loss when in room with no books"), "MULT", math.round((self.driveLossMultiplier - 1) * 100, 1)), font, game.UI_COLORS.RED, 0, wrapWidth, "decrease_red", 22, 22)
	end,
	
	onRoomChanged = function(self, target, roomObject)
		self:evaluateRoom(target, roomObject)
	end,
	
	assignTrait = function(self, target)
		target:setBookExperienceGainModifier(self.id, self.experienceGainMultiplier)
	end})