Skip to content

Objects and classes

7Soul edited this page Nov 22, 2020 · 52 revisions

Index

Champion

Champions' attributes, skills, traits, conditions and other statistics can be accessed through this class. Champion objects can only be accessed through PartyComponent methods, for example:

party.party:getChampion(1)

Methods

  • Champion:addSkillPoints(amount)
  • Champion:addStatModifier(name, amount)
    Known stat modifier names:
    strength, dexterity, vitality, willpower, protection, evasion,
    max_load, food_rate, exp_rate, cooldown_rate
    resist_fire, resist_cold, resist_poison, resist_shock
    max_health, max_energy, health_regeneration_rate, energy_regeneration_rate
  • Champion:addTrait(name)
    See List of traits
  • Champion:attack(handSlot, specialAttack)
    Arguments: handSlot = 1(left hand) or 2(right hand). specialAttack = true or false
  • Champion:carriedItems()
    Function returns an iterator (like ipairs). 1st value is the ItemSlot number where the item is carried. 2nd number is the ItemCmponent of the item in that slot.
  • Champion:castSpell(number)
    "number" is the gesture number representing the icons you would use to cast the spell. Example, castSpell(1236), will cast Fireball.
  • Champion:consumeFood(amount)
  • Champion:damage(dmg, damageType)
  • Champion:gainExp(xp)
  • Champion:getArmorSetPiecesEquipped(name)
  • Champion:getBaseStat(name)
  • Champion:getClass()
  • Champion:getConditionValue(name)
  • Champion:getCurrentStat(name)
  • Champion:getDualClass()
  • Champion:getEnabled()
  • Champion:getEnergy()
  • Champion:getEvasion()
  • Champion:getExp()
  • Champion:getFood()
  • Champion:getHealth()
  • Champion:getItem(slot)
    Item Slot Reference
  • Champion:getLevel()
  • Champion:getLoad()
  • Champion:getMaxEnergy()
  • Champion:getMaxHealth()
  • Champion:getMaxLoad()
  • Champion:getName()
  • Champion:getOrdinal()
    Champions' position in the party can change when party formation is changed, however champions' ordinal number never changes.
  • Champion:getOtherHandItem(slot)
  • Champion:getProtection()
  • Champion:getRace()
  • Champion:getResistance(element)
  • Champion:getSex()
  • Champion:getSkillLevel(name)
  • Champion:getSkillPoints()
  • Champion:hasCondition(name)
  • Champion:hasTrait(name)
  • Champion:insertItem(slot, item)
  • Champion:isAlive()
  • Champion:isArmorSetEquipped(name)
  • Champion:isBodyPartWounded(slot)
  • Champion:isDualWielding()
  • Champion:isReadyToAttack(number)
  • Champion:levelUp()
  • Champion:modifyBaseStat(name, value)
  • Champion:modifyFood(amount)
  • Champion:playDamageSound()
  • Champion:playHealingIndicator()
  • Champion:playSound(name)
  • Champion:regainEnergy(amount)
  • Champion:regainHealth(amount)
  • Champion:removeCondition(name)
  • Champion:removeItem(item)
  • Champion:removeItemFromSlot(slot)
  • Champion:removeTrait(name)
  • Champion:resetExp() Beta 2.2.3
  • Champion:setBaseStat(name, value
  • Champion:setClass(class)
  • Champion:setCondition(name)
    See the Conditions page for a list of conditions.
  • Champion:setConditionValue(name, value)
  • Champion:setEnabled(enabled)
  • Champion:setEnergy(amount)
  • Champion:setFood(amount)
  • Champion:setHealth(amount)
  • Champion:setName(name)
  • Champion:setPortrait(filename)
    This method can cause memory leaks. If at all possible, use the PartyComponent.onGetPortrait hook instead, which has similar functionality and better performance.
  • Champion:setRace(race)
  • Champion:setSex(sex)
  • Champion:setSkillPoints(amount)
  • Champion:showAttackResult(string, GuiItem)
    GuiItem string such as "HitSplash"
  • Champion:swapItems(slot1, slot2)
  • Champion:swapWeaponSets()
  • Champion:trainSkill(name, times, boolean)
    If boolean is set to false, the character won't spend a skill point
  • Champion:upgradeBaseStat(name, value)

Config

  • Config.getKeyBinding(action)
  • Config.getRenderingQuality()

Console

  • Console.suppressWarnings(suppress)
  • Console.warn(message)

DamageFlags

Helper object for damageTile function.

Usage example:

 local flags = DamageFlags.Impact + DamageFlags.CameraShake + DamageFlags.Champion1
 local target = herder_1
 damageTile(target.level, target.x, target.y, target.direction, target.elevation, flags, "physical", 10)
  • DamageFlags.Impact = 1
    If the Impact flag is present, monsters damaged will not flinch. There may be other effects.
  • DamageFlags.OngoingDamage = 2
  • DamageFlags.Champion1 = 4
  • DamageFlags.Champion2 = 8
  • DamageFlags.Champion3 = 16
  • DamageFlags.Champion4 = 32
  • DamageFlags.IgnoreImmunities = 64
    This flag has no effect in Grimrock 2 (it is a holdover from the original Legend of Grimrock).
  • DamageFlags.HalveBackRowDamage = 128
  • DamageFlags.CameraShake = 256
  • DamageFlags.NoLingeringEffects = 512
    If the NoLingeringEffects flag is present, monsters hit by the attack will not play the standard particle effects when hit by physical, fire, and shock damage.
  • DamageFlags.DamageSourceIceShards = 1024

Dungeon

  • Dungeon.getMap(index)
  • Dungeon.getMaxLevels()

Editor

  • Editor.isRunning()

GameMode

  • GameMode.advanceTime(amount)
  • GameMode.completeGame(filename)
  • GameMode.fadeIn(color, length)
  • GameMode.fadeOut(color, length)
  • GameMode.getEnableControls()
  • GameMode.getTimeMultiplier()
  • GameMode.getTimeOfDay()
  • GameMode.playStream(name)
  • GameMode.playVideo(filename)
  • GameMode.setCamera(camera)
  • GameMode.setEnableControls(boolean)
    If enable controls is false, then the player cannot move, use mouse look, pick up or throw items using the mouse, open or close champion windows, or use keyboard shortcuts in general. The player can freely interact with champion windows that are already open.
  • GameMode.setMaxStatistic(stat, max)
  • GameMode.setStatistic(stat)
  • GameMode.setTimeMultiplier(number) Set the current timescale. The amount of game time that passes every frame is multiplied by the time multiplier, so setting it to 2 makes 2 in-game seconds pass in 1 real-time second. Setting the time multiplier to 0 will freeze time. Setting the time multiplier to NaN or infinity will cause the game to hang, so don't do that. Setting the time multiplier to a negative value is not recommended.

The time multiplier is usually 1 by default. However, resting sets the time multiplier to 10 while the party is asleep, and sets it to 1 when they wake up. Using a DiggingToolComponent or RopeToolComponent sets the time multiplier to 2 while the party is digging/climbing, and sets it to 1 when they finish or are interrupted. The time multiplier affects virtually everything in the game world, but does NOT affect Time.systemTime() or the play_time statistic.

Remember that no matter how high the time multiplier is, some things can only happen once per frame, such as TimerComponents activating and conditions ticking.

Warning: setting the time multiplier to very high values can have unintended consequences, such as projectiles passing through things they should collide with, or monsters behaving in strange ways.

  • GameMode.setTimeOfDay(time)
    The time is a number between 0 and 1.99. 0 represents the break of dawn, 0.5 is noon, 1.0 is dusk, 1.5 is midnight.
  • GameMode.showImage(filename)
  • GameMode.unlockAchievement(name)
    This will unlock a Steam achievement for Grimrock 2. The achievement name does not directly correspond to what it is called in Steam. (Added for completeness - modders shouldn't, and probably can't, use this function.)
  • GameMode.setGameFlag(flag, value) Beta 2.2.4
  • GameMode.getGameFlag(flag) (possible flags are PauseGame, HideGui, DisableMovement, DisableMouseLook, DisableMonsterAI and DisableKeyboardShortcuts)

GameObject

GameObject is a container for Components. A GameObject has a position and orientation in the world.

Properties

  • name: returns the name of the entity
  • id: returns the unique identifier of the entity
  • x: returns the x-coordinate of the entity on the map
  • y: returns the y-coordinate of the entity on the map
  • elevation: returns the elevation of the entity on the map (0 = ground level)
  • facing: returns the facing of the entity (0=north, 1=east, 2=south, 3=west)
  • level: returns the dungeon level index of the entity
  • map: returns the Map object representing the dungeon level where the entity is
  • xyz: returns the component named “xyz” (or nil if no such component exists)

Methods

  • GameObject:componentIterator()
  • GameObject:createComponent(string)
  • GameObject:destroy()
  • GameObject:destroyDelayed()
  • GameObject:getComponent(name)
  • GameObject:getElevation()
  • GameObject:getFullId()
    This will return the same value as "id" except when the object is in a SurfaceComponent, ContainerItemComponent or even MonsterComponent (like an alcove, beach puzzle statue...). In that case, it returns the id of the surface, container(s) or monster prepended to the id. Example: chest_23.gold_key_1. NOTE: Items in ContainerComponets or MonsterComponents (like a sack for example) cannot be referenced directly by the item's ID (it is no longer in the map). You need to keep a reference to the item on your own if you want to access it or any of its functions like this one.
  • GameObject:getPosition()
  • GameObject:getSubtileOffset()
  • GameObject:getWorldForward()
  • GameObject:getWorldPosition()
    Returns 3 values, X, Y and Z for the world position of the object. World position coordinates have Y-axis as up/down, X-axis is east/west, Z-axis is north/south. The cube that represent one game square is (3.0 x 3.0 x 3.0) world position units in size.
  • GameObject:getWorldPositionY()
  • GameObject:getWorldRotation()
  • GameObject:playSound(name)
  • GameObject:removeAllComponents()
  • GameObject:removeComponent(component)
  • GameObject:setPosition(x, y, facing, elevation, level)
  • GameObject:setSubtileOffset(x, y)
  • GameObject:setWorldPosition(vec)
  • GameObject:setWorldPositionY(y)
  • GameObject:setWorldRotation(...)
  • GameObject:setWorldRotationAngles(x, y, z)
  • GameObject:setWorldRotationAnglesWithOrder(x, y, z, order)
  • GameObject:spawn(name)
    Spawns a new object with the same position and orientation as this object.

GraphicsContext

  • GraphicsContext.button(id, x, y, width, height)
    Returns two values indicating if the mouse cursor is inside, outside, entering, or exiting a specific area on the screen.
  • GraphicsContext.color(r, g, b, a)
    Changes the color of succeeding drawing operations. The values must be numbers between 0 and 255.
  • GraphicsContext.drawImage(filename, x, y)
    Draws an image (without resizing) on the screen.
  • GraphicsContext.drawImage2(filename, x, y, srcX, srcY, srcWidth, srcHeight, destWidth, destHeight)
    Draws part of an image on the screen, scaling it as needed to make it fit inside a rectangle.
  • GraphicsContext.drawParagraph(text, x, y, width)
    Draws a text which wraps at specified width.
  • GraphicsContext.drawRect(x, y, width, height)
  • GraphicsContext.drawText(text, x, y)
  • GraphicsContext.font(font)
    Known valid values for font are: "tiny", "small", "medium", "large"
  • GraphicsContext.keyDown(key)
  • GraphicsContext.mouseDown(button)
    Button values: 0 (left), 1 (middle), 2 (right), 3 (left, single click), 4 (middle, single click), 5 (right, single click)
  • GraphicsContext.width
  • GraphicsContext.height
  • GraphicsContext.mouseX
  • GraphicsContext.mouseY
  • GraphicsContext.getLineHeight() Beta 2.2.4
  • GraphicsContext.getTextWidth(string) Beta 2.2.4
  • GraphicsContext.translate() Beta 2.2.4
  • GraphicsContext.scale(amount) Scales all afterwards drawn images(not texts) by amount. Sane values are between 0 and 1 Beta 2.2.4
  • GraphicsContext.resetTransform() Beta 2.2.4
  • GraphicsContext.transformPoint() Beta 2.2.4
  • GraphicsContext.transformVector() Beta 2.2.4
  • GraphicsContext.inverseTransformPoint() Beta 2.2.4
  • GraphicsContext.inverseTransformVector() Beta 2.2.4
  • GraphicsContext.drawGuiItem(item, x, y) Beta 2.2.4
  • GraphicsContext.drawGuiItem2(item, x, y, srcX, srcY, srcWidth, srcHeight, width, height) Beta 2.2.4 See the list of GuiItems

ItemSlot

  • ItemSlot.Weapon = 1
  • ItemSlot.OffHand = 2
  • ItemSlot.Head = 3
  • ItemSlot.Chest = 4
  • ItemSlot.Legs = 5
  • ItemSlot.Feet = 6
  • ItemSlot.Cloak = 7
  • ItemSlot.Necklace = 8
  • ItemSlot.Gloves = 9
  • ItemSlot.Bracers = 10
  • ItemSlot.Weapon2 = 11
  • ItemSlot.OffHand2 = 12
  • ItemSlot.BackpackFirst = 13
  • ItemSlot.BackpackLast = 32
  • ItemSlot.MaxSlots = 32

Map

Contains all entities (also known as GameObjects) of a dungeon level. Map size is currently always 32 by 32.

  • Map:allEntities()
    Returns values for iterating over all entities in the map like this: for entity in Dungeon.getMap(1):allEntities() do ... end
  • Map:checkLineOfFire(x1, y1, x2, y2, elevation)
    This function returns true if an entity can traverse between the two points at a given elevation. Note, only one elevation is used, therefore, line of sight will only be calculated across squares of the same elevation.
  • Map:checkLineOfSight(x1, y1, x2, y2, elevation)
    This function returns true if an entity can see between the two points at a given elevation. Note, only one elevation is used, therefore, line of sight will only be calculated across squares of the same elevation.
  • Map:checkObstacle(GameObject, facing)
    Can return "door", "dynamic_obstacle", "obstacle", "wall" or nil.
  • Map:checkObstacle2(GameObject, x, y, facing, elevation)
  • Map:entitiesAt(x, y)
  • Map:getAdjacentLevel(x, y, z)
    The coordinates are relative.
  • Map:getAutomapTile(x, y)
  • Map:getCeilingElevation(x, y)
  • Map:getElevation(x, y)
  • Map:getHeight()
  • Map:getLevel() Beta 2.2.1
  • Map:getLevelCoord()
  • Map:getModuleHeight()
  • Map:getName()
  • Map:getWidth()
  • Map:isBlocked(x, y, elevation)
  • Map:isObstacle(x, y, elevation)
  • Map:isVisited()
  • Map:isWall(x, y)
  • Map:mapToWorld(x, y)
  • Map:setAutomapTile(x, y, tileNumber)
    The tile number can be 0 (ground), 1 (grassy_ground), 2 (water), 3 (wall), 4 (rocky_wall), 5 (trees) or 6 (chasm).
  • Map:worldToMap(vec)

MersenneTwister

  • MersenneTwister.create(seed)
    Returns an instance of MersenneTwister required to generate random numbers. Seed is a number.
    e.g. local random = MersenneTwister.create(Time.systemTime())
  • MersenneTwister.random()
    Generates a random real number between 0 and 1.
    e.g. local n = random:random()
  • MersenneTwister.randomInt(min, max)
    Generates a random integer between the given numbers min and max.
    e.g. local n = random:randomInt(1, 10) produces a random integer from 1 to 10
    e.g. MersenneTwister.randomInt(MersenneTwister.create(Time.systemTime()), 1, 10) will also return a random integer from 1 to 10

MaterialEx

Holds parameters of a rendering material. Materials can only be accessed from material definition’s onUpdate hooks.

  • MaterialEx:setParam(string, number)
  • MaterialEx:setTexcoordScaleOffset(number, number, number, number)
  • MaterialEx:setTexture(string, string)

Time

  • Time.currentTime()
    Returns the current game time in seconds. Game time is multiplied by the time multiplier. Note that game time continues to elapse while the game is paused. Game time is specific to the dungeon and is saved in savegames.
  • Time.deltaTime()
    Returns the amount of game time in seconds for the current update. For example, at 60 FPS with a time multiplier of 1, Time.deltaTime() will return 1/60. The maximum value of Time.deltaTime() is 0.1*[current time multiplier]; this is why the game physics slow down at extremely low framerates.
  • Time.systemTime()
    Returns the time in seconds elapsed since the game executable was started. System time is not affected by the time multiplier and continues to elapse while the game is paused and even while loading dungeons.

To track the elapsed in-game time excluding time spent paused, you can call Time.deltaTime() once every frame. You can do this easily by adding a TimerComponent to the party. For example:

defineObject{
  name = "party",
  baseObject = "party",
  components = {
    {
      class = "Timer",
      name = "frametimer",
      timerInterval = 0, -- will activate exactly once per frame
      onActivate = function(self)
        self.go.counter:setValue(self.go.counter:getValue()+Time.deltaTime())
      end,
    },
    {
      class = "Counter",
      name = "gametime",
    },
  },
}

Once you add these two components, you can get the elapsed game time excluding paused time with party.gametime:getValue(). This gives you the "true" time spent in the dungeon, accounting for pauses and the time multipliers for resting and digging.

Note: if you do NOT want to account for time multipliers, but do want to exclude time spent with the game paused, you can get the number of real-time seconds elapsed since starting the dungeon by simply calling GameMode.getStatistic("play_time").