Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spellcraft / Counterspell #100

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions cdtweaks/languages/english/spellcraft_counterspell.tra
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@1 = "Counterspell (Abjuration)"
@2 = "Counterspell (Conjuration)"
@3 = "Counterspell (Divination)"
@4 = "Counterspell (Enchantment/Charm)"
@5 = "Counterspell (Illusion/Phantasm)"
@6 = "Counterspell (Evocation)"
@7 = "Counterspell (Necromancy)"
@8 = "Counterspell (Alteration)"

@100 = "Counterspelling"
@101 = "Counterspell Mode"
@102 = "Counterspell Mode On"
@103 = "Counterspell Mode Off"

// NB.: the leading/trailing spaces are not a typo
@200 = "Spellcraft: "
@201 = " is about to cast "
10 changes: 10 additions & 0 deletions cdtweaks/languages/english/weidu.tra
Original file line number Diff line number Diff line change
Expand Up @@ -802,3 +802,13 @@ Use Baldur.lua options: a7_interval_ini
@504000 = ~Allow Yeslick to Use Axes~

@505000 = ~Ensure Shar-Teel Doesn't Die in the Original Challenge~

/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
///// \\\\\
///// NWN-ish feats collection \\\\\
///// \\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\

@600020 = "Spellcraft / Counterspell class feat for spellcasters [Luke]"
16 changes: 16 additions & 0 deletions cdtweaks/languages/italian/spellcraft_counterspell.tra
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@1 = "Controincantesimo (Scongiurazione)"
@2 = "Controincantesimo (Evocazione)"
@3 = "Controincantesimo (Divinazione)"
@4 = "Controincantesimo (Incantamento/Charme)"
@5 = "Controincantesimo (Illusione/Visione)"
@6 = "Controincantesimo (Apparizione)"
@7 = "Controincantesimo (Necromanzia)"
@8 = "Controincantesimo (Alterazione)"

@100 = "Controincantesimo"
@101 = "Modalità Controincantesimo"
@102 = "Modalità Controincantesimo Attivata"
@103 = "Modalità Controincantesimo Annullata"

@200 = "Sapienza Magica: "
@201 = " sta per lanciare "
10 changes: 10 additions & 0 deletions cdtweaks/languages/italian/weidu.tra
Original file line number Diff line number Diff line change
Expand Up @@ -718,3 +718,13 @@ Usa opzioni di Baldur.lua: a7_interval_ini
@504000 = ~Permettere a Yeslick di usare le asce~

@505000 = ~Assicura che Shar-Teel non muoia nella sfida iniziale~

/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
///// \\\\\
///// Raccolta di talenti in stile NWN \\\\\
///// \\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\

@600020 = "Aggiungi talento di classe Sapienza Magica / Controincantesimo per gli incantatori [Luke]"
18 changes: 18 additions & 0 deletions cdtweaks/lib/comp_6020.tpa
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
///// /////
///// Spellcraft / Counterspell class feat for spellcasters \\\\\
///// \\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////

WITH_SCOPE BEGIN
INCLUDE "cdtweaks\luke\misc.tph"
INCLUDE "cdtweaks\ardanis\functions.tph"
//
INCLUDE "cdtweaks\lib\spellcraft_counterspell.tph"
//
WITH_TRA "cdtweaks\languages\english\spellcraft_counterspell.tra" "cdtweaks\languages\%LANGUAGE%\spellcraft_counterspell.tra" BEGIN
LAF "SPELLCRAFT_COUNTERSPELL" END
END
END
105 changes: 105 additions & 0 deletions cdtweaks/lib/spellcraft_counterspell.tph
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
DEFINE_ACTION_FUNCTION "SPELLCRAFT_COUNTERSPELL"
BEGIN
LAF "GT_ADD_SPELL"
STR_VAR
"idsName" = "INNATE_COUNTERSPELL"
RET
"INNATE_COUNTERSPELL" = "resName"
END
//
LAF "ADD_EXTENDED_STAT" INT_VAR "max" = 25 STR_VAR "identifier" = "GT_IGNORE_ACTION_ADD_SPRITE_STARTED_ACTION_LISTENER" END
//
WITH_SCOPE BEGIN
ACTION_TO_LOWER "INNATE_COUNTERSPELL"
//
ACTION_CLEAR_ARRAY "cdtweaks_counterspell"
ACTION_DEFINE_ASSOCIATIVE_ARRAY "cdtweaks_counterspell" BEGIN
// mschool, casting sound => casting animation
1, "a", "CAS_M02" => 12 // ABJURER
2, "b", "CAS_M03" => 14 // CONJURER
3, "c", "CAS_M04" => 16 // DIVINER
4, "d", "CAS_M05" => 11 // ENCHANTER
5, "e", "CAS_M01" => 13 // ILLUSIONIST
6, "f", "CAS_M06" => 15 // INVOKER
7, "g", "CAS_M07" => 9 // NECROMANCER
8, "h", "CAS_M08" => 10 // TRANSMUTER
END
//
ACTION_PHP_EACH "cdtweaks_counterspell" AS "key" => "value" BEGIN
CREATE "spl" "%INNATE_COUNTERSPELL%%key_1%"
COPY_EXISTING "%INNATE_COUNTERSPELL%%key_1%.spl" "override"
WRITE_LONG NAME1 RESOLVE_STR_REF ((AT "%key%"))
WRITE_LONG UNIDENTIFIED_DESC "-1"
WRITE_LONG 0x18 (BIT9 BOR BIT10) // break sanctuary/invisibility
WRITE_SHORT 0x1C 4 // type: innate
WRITE_LONG 0x34 1 // level
WRITE_SHORT 0x22 "%value%" // casting animation
WRITE_BYTE 0x25 "%key%" // mschool
WRITE_ASCII 0x10 "%key_2%" #8 // casting sound
//
LPF "ADD_SPELL_HEADER" INT_VAR "range" = 30 END
//
LPF "ADD_SPELL_EFFECT" INT_VAR "opcode" = 402 "target" = 2 "parameter1" = 3 STR_VAR "resource" = "%INNATE_COUNTERSPELL%" END // invoke lua
BUT_ONLY
END
END
//
WITH_SCOPE BEGIN
ACTION_TO_LOWER "INNATE_COUNTERSPELL"
//
LAF "ADD_STATDESC_ENTRY" INT_VAR "description" = RESOLVE_STR_REF (@100) STR_VAR "bam_file" = "%INNATE_COUNTERSPELL%d" RET "feedback_icon" = "index" END
//
COPY "cdtweaks\luke\bam\spellcraft_counterspell\portrait_icon.bam" "override\%INNATE_COUNTERSPELL%d.bam"
COPY "cdtweaks\luke\bam\spellcraft_counterspell\spl_icon.bam" "override\%INNATE_COUNTERSPELL%b.bam"
//
CREATE "spl" "%INNATE_COUNTERSPELL%y"
COPY_EXISTING "%INNATE_COUNTERSPELL%y.spl" "override"
WRITE_LONG NAME1 RESOLVE_STR_REF (@101)
WRITE_LONG UNIDENTIFIED_DESC "-1"
WRITE_LONG 0x18 (BIT9 BOR BIT10 BOR BIT14) // break sanctuary/invisibility, ignore dead/wild magic
WRITE_SHORT 0x1C 4 // type: innate
WRITE_LONG 0x34 1 // level
WRITE_ASCII 0x3A "%INNATE_COUNTERSPELL%b" #8 // icon
//
LPF "ADD_SPELL_HEADER" INT_VAR "target" = 5 "range" = 30 STR_VAR "icon" = "%INNATE_COUNTERSPELL%b" END
//
LPF "ADD_SPELL_EFFECT" INT_VAR "opcode" = 138 "target" = 1 "parameter2" = 7 END // SEQ_READY
LPF "ADD_SPELL_EFFECT" INT_VAR "opcode" = 321 "target" = 1 "timing" = 1 STR_VAR "resource" = "%DEST_RES%" END // remove effects by resource
LPF "ADD_SPELL_EFFECT" INT_VAR "opcode" = 172 "target" = 1 "timing" = 1 STR_VAR "resource" = "%DEST_RES%" END // remove spell
LPF "ADD_SPELL_EFFECT" INT_VAR "opcode" = 139 "target" = 1 "parameter1" = RESOLVE_STR_REF (@102) "timing" = 1 END // feedback string
LPF "ADD_SPELL_EFFECT" INT_VAR "opcode" = 142 "target" = 1 "parameter2" = "%feedback_icon%" "timing" = 1 END // feedback icon
LPF "ADD_SPELL_EFFECT" INT_VAR "opcode" = 402 "target" = 1 "parameter1" = 1 STR_VAR "resource" = "%INNATE_COUNTERSPELL%" END // invoke lua
BUT_ONLY
//
CREATE "spl" "%INNATE_COUNTERSPELL%z"
COPY_EXISTING "%INNATE_COUNTERSPELL%z.spl" "override"
WRITE_LONG NAME1 RESOLVE_STR_REF (@103)
WRITE_LONG UNIDENTIFIED_DESC "-1"
WRITE_LONG 0x18 (BIT9 BOR BIT10 BOR BIT14) // break sanctuary/invisibility, ignore dead/wild magic
WRITE_SHORT 0x1C 4 // type: innate
WRITE_LONG 0x34 1 // level
WRITE_ASCII 0x3A "%INNATE_COUNTERSPELL%b" #8
//
LPF "ADD_SPELL_HEADER" INT_VAR "target" = 5 "range" = 30 STR_VAR "icon" = "%INNATE_COUNTERSPELL%b" END
//
LPF "ADD_SPELL_EFFECT" INT_VAR "opcode" = 402 "target" = 1 "parameter1" = 2 STR_VAR "resource" = "%INNATE_COUNTERSPELL%" END // invoke lua
BUT_ONLY
END
// lua
WITH_SCOPE BEGIN
OUTER_SET "feedback_strref_spellcraft" = RESOLVE_STR_REF (@200)
OUTER_SET "feedback_strref_isCasting" = RESOLVE_STR_REF (@201)
//
LAF "APPEND_LUA_FUNCTION" STR_VAR "description" = "Spellcraft / Counterspell class feat for spellcasters" "sourceFileSpec" = "cdtweaks\luke\lua\spellcraft_counterspell\utility.lua" "destRes" = "m_gtctsp" END
LAF "APPEND_LUA_FUNCTION" STR_VAR "description" = "Spellcraft / Counterspell class feat for spellcasters" "sourceFileSpec" = "cdtweaks\luke\lua\spellcraft_counterspell\gain_ability.lua" "destRes" = "m_gtctsp" END
LAF "APPEND_LUA_FUNCTION" STR_VAR "description" = "Spellcraft / Counterspell class feat for spellcasters" "sourceFileSpec" = "cdtweaks\luke\lua\spellcraft_counterspell\main.lua" "destRes" = "m_gtctsp" END
END
//
LAF "APPEND_LUA_FUNCTION" STR_VAR "description" = "Utility Functions / Listeners" "sourceFileSpec" = "cdtweaks\luke\lua\utility\decode_spell.lua" "destRes" = "m_gtutil" END
LAF "APPEND_LUA_FUNCTION" STR_VAR "description" = "Utility Functions / Listeners" "sourceFileSpec" = "cdtweaks\luke\lua\utility\effect_check.lua" "destRes" = "m_gtutil" END
LAF "APPEND_LUA_FUNCTION" STR_VAR "description" = "Lua Tools" "sourceFileSpec" = "cdtweaks\luke\lua\tools\wrap_userdata.lua" "destRes" = "m_gttool" END
//
ACTION_IF !(FILE_EXISTS_IN_GAME "m_gttbls.lua") BEGIN
COPY "cdtweaks\luke\lua\m_gttbls.lua" "override"
END
END
1 change: 1 addition & 0 deletions cdtweaks/lib/spontaneous_casting.tph
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ BEGIN
END
//
LAF "APPEND_LUA_FUNCTION" STR_VAR "description" = "Functions to be invoked via op214" "sourceFileSpec" = "cdtweaks\luke\lua\spontaneous_casting\custom_214.lua" "destRes" = "m_gt#214" END
LAF "APPEND_LUA_FUNCTION" STR_VAR "description" = "Utility Functions / Listeners" "sourceFileSpec" = "cdtweaks\luke\lua\utility\decode_spell.lua" "destRes" = "m_gtutil" END
//
ACTION_IF !(FILE_EXISTS_IN_GAME "m_gttbls.lua") BEGIN
COPY "cdtweaks\luke\lua\m_gttbls.lua" "override"
Expand Down
Binary file not shown.
Binary file not shown.
70 changes: 70 additions & 0 deletions cdtweaks/luke/lua/spellcraft_counterspell/gain_ability.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
-- cdtweaks: NWN-ish Spellcraft / Counterspell class feat for spellcasters --

EEex_Opcode_AddListsResolvedListener(function(sprite)
-- internal function that grants the actual feat
local gain = function()
-- Mark the creature as 'feat granted'
sprite:setLocalInt("cdtweaksSpellcraft", 1)
--
sprite:applyEffect({
["effectID"] = 172, -- Remove spell
["durationType"] = 1,
["res"] = "%INNATE_COUNTERSPELL%Y",
["sourceID"] = sprite.m_id,
["sourceTarget"] = sprite.m_id,
})
sprite:applyEffect({
["effectID"] = 171, -- Give spell
["durationType"] = 1,
["res"] = "%INNATE_COUNTERSPELL%Y",
["sourceID"] = sprite.m_id,
["sourceTarget"] = sprite.m_id,
})
end
-- Check creature's class / flags
local spriteClassStr = GT_Resource_IDSToSymbol["class"][sprite.m_typeAI.m_Class]
--
local spriteFlags = sprite.m_baseStats.m_flags
-- since ``EEex_Opcode_AddListsResolvedListener`` is running after the effect lists have been evaluated, ``m_bonusStats`` has already been added to ``m_derivedStats`` by the engine
local spriteLevel1 = sprite.m_derivedStats.m_nLevel1
local spriteLevel2 = sprite.m_derivedStats.m_nLevel2
-- Check if spellcaster class -- single/multi/(complete)dual
local gainAbility = spriteClassStr == "BARD" or spriteClassStr == "MAGE" or spriteClassStr == "CLERIC" or spriteClassStr == "DRUID" or spriteClassStr == "FIGHTER_MAGE_THIEF" or spriteClassStr == "FIGHTER_MAGE_CLERIC" or spriteClassStr == "CLERIC_MAGE"
or (spriteClassStr == "FIGHTER_MAGE" and (EEex_IsBitUnset(spriteFlags, 0x4) or spriteLevel1 > spriteLevel2))
or (spriteClassStr == "FIGHTER_CLERIC" and (EEex_IsBitUnset(spriteFlags, 0x5) or spriteLevel1 > spriteLevel2))
or (spriteClassStr == "MAGE_THIEF" and (EEex_IsBitUnset(spriteFlags, 0x4) or spriteLevel2 > spriteLevel1))
or (spriteClassStr == "CLERIC_THIEF" and (EEex_IsBitUnset(spriteFlags, 0x5) or spriteLevel2 > spriteLevel1))
or (spriteClassStr == "FIGHTER_DRUID" and (EEex_IsBitUnset(spriteFlags, 0x7) or spriteLevel1 > spriteLevel2))
or (spriteClassStr == "CLERIC_RANGER" and (EEex_IsBitUnset(spriteFlags, 0x5) or spriteLevel2 > spriteLevel1))
--
if sprite:getLocalInt("cdtweaksSpellcraft") == 0 then
if gainAbility then
gain()
end
else
if gainAbility then
-- do nothing
else
-- Mark the creature as 'feat removed'
sprite:setLocalInt("cdtweaksSpellcraft", 0)
--
if sprite:getLocalInt("cdtweaksCounterspell") == 1 then
sprite:applyEffect({
["effectID"] = 146, -- Cast spell
["dwFlags"] = 1, -- instant/ignore level
["res"] = "%INNATE_COUNTERSPELL%Z",
["sourceID"] = sprite.m_id,
["sourceTarget"] = sprite.m_id,
})
end
--
sprite:applyEffect({
["effectID"] = 172, -- Remove spell
["durationType"] = 1,
["res"] = "%INNATE_COUNTERSPELL%Y",
["sourceID"] = sprite.m_id,
["sourceTarget"] = sprite.m_id,
})
end
end
end)
Loading