Table of Contents

Backstab Spell - Code References

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

Entity Kind

Java Implementation

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

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

Spell Registration