User Tools

Site Tools


mr:backstab_spell

Backstab Spell - Code References

This page contains raw code references and configuration excerpts for the Backstab spell entity.

Entity Kind

  • Spell Type: Rogue Affinity Spell (Lua implementation)
  • Targeting: self (targets nearest enemy within 1 tile)

Java Implementation

  • No dedicated Java class for this spell
  • Spell is implemented entirely in Lua

Lua Script

Lua Script Content

local RPD                 = require "scripts/lib/commonClasses"
local spell               = require "scripts/lib/spell"
 
local distracted          = {}
distracted["PASSIVE"]     = true
distracted["SLEEPING"]    = true
distracted["FLEEING"]     = true
distracted["HORRIFIED"]   = true
distracted["RUNNINGAMOK"] = true
 
return spell.init{
    desc  = function ()
        return {
            image         = 2,
            imageFile     = "spellsIcons/rogue.png",
            name          = "Backstab_Name",
            info          = "Backstab_Info",
            magicAffinity = "Rogue",
            targetingType = "self",
            level         = 2,
            castTime      = 1,
            spellCost     = 2
        }
    end,
 
    cast = function(self, spell, caster)
 
        local level = caster:level()
        local ownPos = caster:getPos()
 
        local victim = caster:getNearestEnemy()
 
        if victim == nil or level:distance(ownPos, victim:getPos()) > 1 then
            RPD.glogn("Backstab_TooFar")
            return false
        end
 
        if not distracted[victim:getState():getTag()] and not victim:isParalysed() then
            RPD.glogn("Backstab_Aware")
            return false
        end
 
        victim:showStatus(0xff2030,"backstab")
 
        local weapon = caster:getBelongings().weapon
        local secondaryWeapon = caster:getBelongings().leftHand
        local damage = math.sqrt(caster:skillLevel()) * (weapon:damageRoll(caster) + secondaryWeapon:damageRoll(caster))
 
        victim:damage(damage, caster)
        RPD.Sfx.Wound:hit(victim)
 
        return true
    end
}

Key Properties from Code

  • Magic Affinity: Rogue
  • Targeting: self (auto-targets nearest enemy within 1 tile)
  • Level: 2
  • Mana Cost: 2
  • Cast Time: 1 turn
  • Damage Formula: sqrt(caster's skill level) * (main weapon damage roll + secondary weapon damage roll)
  • Conditions: Only works on distracted enemies (PASSIVE, SLEEPING, FLEEING, HORRIFIED, RUNNINGAMOK) or paralyzed targets
  • Range: 1 tile distance from caster

String Resources

<string name="Backstab_Name">Backstab</string>
<string name="Backstab_Info">Silent hit in the back. Dishonest, but extremely effective, backstab damage will grow with performer skill level.\n\nSuccessful backstab will completely ignore victim armor or special defense abilities.</string>
<string name="Backstab_TooFar">Victim too far for successful hit.</string>
<string name="Backstab_Aware">Victim shouldn't be aware of you for a good backstab.</string>

JSON Configuration

This entity does not use JSON configuration.

Code Behavior

  • Implemented as Lua spell using the spell library
  • Checks if nearest enemy is within 1 tile distance
  • Requires target to be distracted (PASSIVE, SLEEPING, FLEEING, HORRIFIED, RUNNINGAMOK) or paralyzed
  • Calculates damage using both main hand and off-hand weapon damage rolls
  • Damage scales with square root of caster's skill level
  • Ignores victim's armor completely when successful
  • Shows visual status effect (0xff2030 “backstab”) on victim
  • Plays Wound sound effect after attack

Spell Registration

mr/backstab_spell.txt · Last modified: by 127.0.0.1