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

Make Rancor +1 a bit more reliable #73

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions cdtweaks/languages/english/weidu.tra
Expand Up @@ -743,6 +743,8 @@ Use Baldur.lua options: a7_interval_ini
@419700 = ~Also Color the PC's Name: Yellow~
@419800 = ~Also Color the PC's Name: Orange~

@420000 = "Make Rancor +1 a bit more reliable"

/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
///// \\\\\
Expand Down
12 changes: 12 additions & 0 deletions cdtweaks/lib/comp_4200.tpa
@@ -0,0 +1,12 @@
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
///// \\\\\
///// Make Rancor +1 a bit more reliable \\\\\
///// \\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\

WITH_SCOPE BEGIN
INCLUDE "cdtweaks\lib\dorns_sword.tph"
LAF "DORNS_SWORD" END
END
59 changes: 59 additions & 0 deletions cdtweaks/lib/dorns_sword.tph
@@ -0,0 +1,59 @@
DEFINE_ACTION_FUNCTION "DORNS_SWORD"
BEGIN
<<<<<<<< .../cdtweaks-inlined/empty
>>>>>>>>
// update weapon
COPY_EXISTING "sw2hd1.itm" "override" // Rancor +1
LPF "DELETE_EFFECT" INT_VAR "match_opcode" = 232 STR_VAR "match_resource" = "ohdsw2" END // not needed
BUT_ONLY
// update main SPL file
COPY_EXISTING "ohdsw1.spl" "override"
LPF "ADD_SPELL_EFFECT" INT_VAR "insert_point" = 0 "opcode" = 402 "target" = 1 STR_VAR "resource" = "GTDRNSW2" END // Invoke lua
LPF "ALTER_EFFECT" INT_VAR "silent" = 1 "match_opcode" = 221 "opcode" = 321 "parameter1" = 0 "parameter2" = 0 STR_VAR "resource" = "%DEST_RES%" END // Remove effects by resource
BUT_ONLY
// update scripts
COPY_EXISTING "dorn.bcs" "override"
"dorn25.bcs" "override"
DECOMPILE_AND_PATCH BEGIN
SET "found" = INDEX_BUFFER (CASE_INSENSITIVE EXACT_MATCH ~!HasItemEquipedReal("sw2hd1",Myself)~)
PATCH_IF ("%found%" >= 0) BEGIN
SET "start" = RINDEX_BUFFER (CASE_SENSITIVE EVALUATE_REGEXP "^IF$" "%found%")
SET "end" = INDEX_BUFFER (CASE_SENSITIVE EVALUATE_REGEXP "^END$" "%found%") + STRING_LENGTH "END"
DELETE_BYTES "%start%" ("%end%" - "%start%")
END
SET "found" = INDEX_BUFFER (CASE_INSENSITIVE EXACT_MATCH ~ApplySpellRES("ohdsw3",Myself)~)
PATCH_IF ("%found%" >= 0) BEGIN
SET "start" = RINDEX_BUFFER (CASE_SENSITIVE EVALUATE_REGEXP "^IF$" "%found%")
SET "end" = INDEX_BUFFER (CASE_SENSITIVE EVALUATE_REGEXP "^END$" "%found%") + STRING_LENGTH "END"
DELETE_BYTES "%start%" ("%end%" - "%start%")
END
END
BUT_ONLY IF_EXISTS
// update CREs
COPY_EXISTING "dorn.cre" "override"
"dorn2.cre" "override"
"dorn4.cre" "override"
"dorn6.cre" "override"
"dorn7.cre" "override"
//
"dorn8.cre" "override"
"dorn9.cre" "override"
"dorn10.cre" "override"
"dorn12.cre" "override"
"dorn14.cre" "override"
"ohb2dorn.cre" "override"
LPF "DELETE_EFFECT" INT_VAR "match_opcode" = 206 STR_VAR "match_resource" = "ohdsw2" END
LPF "ADD_CRE_EFFECT" INT_VAR "opcode" = 402 "target" = 1 "timing" = 9 STR_VAR "resource" = "GTDRNSW1" END // Invoke lua
BUT_ONLY IF_EXISTS
// lua magic
ACTION_IF !(FILE_EXISTS_IN_GAME "m_gt#402.lua") BEGIN
COPY ".../cdtweaks-inlined/empty" "override\m_gt#402.lua"
DELETE_BYTES 0x0 BUFFER_LENGTH
INSERT_BYTES 0x0 STRING_LENGTH "-- Functions to be invoked via op402 --%WNL%%WNL%"
WRITE_ASCII 0x0 "-- Functions to be invoked via op402 --%WNL%%WNL%"
BUT_ONLY_IF_IT_CHANGES
END
COPY_EXISTING "m_gt#402.lua" "override"
APPEND_FILE TEXT "cdtweaks\luke\lua\dorns_sword.lua"
BUT_ONLY UNLESS "^function GTDRNSW[1-2]"
END
41 changes: 41 additions & 0 deletions cdtweaks/luke/lua/dorns_sword.lua
@@ -0,0 +1,41 @@
-- cdtweaks, Rancor +1 (Dorn's sword): remove thac0 bonus when unequipped --

function GTDRNSW1(CGameEffect, CGameSprite)
local equipment = CGameSprite.m_equipment -- CGameSpriteEquipment
local selectedItem = equipment.m_items:get(equipment.m_selectedWeapon) -- CItem
local itemResRef = selectedItem.pRes.resref:get() -- We need to use :get() to export a CResRef field as a Lua string!
-- if Dorn is not wielding Rancor +1, then remove bonus ...
if itemResRef ~= "SW2HD1" then
if EEex_Sprite_GetLocalInt(CGameSprite, "ohdornsw") ~= 0 then
EEex_Sprite_SetLocalInt(CGameSprite, "ohdornsw", 0)
--
EEex_GameObject_ApplyEffect(CGameSprite,
{
["effectID"] = 146, -- Cast spell
["durationType"] = 1,
["dwFlags"] = 1, -- Cast instantly (caster level)
["res"] = "OHDSW0",
["sourceID"] = CGameEffect.m_sourceId, -- Certain opcodes (see f.i. op326) use this field internally... it's probably a good idea to always specify it...
["sourceTarget"] = CGameEffect.m_sourceTarget, -- Certain opcodes (see f.i. op326) use this field internally... it's probably a good idea to always specify it...
})
end
end
end

-- cdtweaks, Rancor +1 (Dorn's sword): Check if the wielder is Dorn --

function GTDRNSW2(CGameEffect, CGameSprite)
local parentResRef = CGameEffect.m_sourceRes:get() -- We need to use :get() to export a CResRef field as a Lua string!
local spriteScriptName = EEex_CastUD(CGameSprite.m_scriptName, "CResRef"):get() -- certain engine types are nonsensical. We usually create fixups for the bindings whenever we run into them. We'll need to cast the value to properly read them
--
if string.upper(spriteScriptName) ~= "DORN" then
EEex_GameObject_ApplyEffect(CGameSprite,
{
["effectID"] = 206, -- Protection from spell
["effectAmount"] = -1, -- no feedback
["res"] = parentResRef,
["sourceID"] = CGameEffect.m_sourceId, -- Certain opcodes (see f.i. op326) use this field internally... it's probably a good idea to always specify it...
["sourceTarget"] = CGameEffect.m_sourceTarget, -- Certain opcodes (see f.i. op326) use this field internally... it's probably a good idea to always specify it...
})
end
end
9 changes: 8 additions & 1 deletion cdtweaks/readme-cdtweaks.html
Expand Up @@ -995,7 +995,7 @@ <h3> <a id="contents_rules" name="contents_rules"></a>Rule Changes </h3>
<p> <strong>Weapon Finesse [Luke]</strong><br />
<em><abbr title="Enhanced Edition">EEex</abbr></em>
<p> This component aims at implementing 3E Weapon Finesse feat for Thieves.<br>
As a result, after installing it, every time a Thief is wielding a small blade (f.i. daggers, short swords, wakizashis, etc...), his/her THAC0 will scale with Dexterity (as per the <code>MISSILE</code> column of <a href="https://gibberlings3.github.io/iesdp/files/2da/2da_bgee/dexmod.htm"><code>dexmod.2da</code></a>) instead of Strength.<br>
As a result, after installing it, every time a Thief is wielding a small blade (f.i. daggers, short swords, wakizashis, etc...) or a club/mace, his/her THAC0 will scale with Dexterity (as per the <code>MISSILE</code> column of <a href="https://gibberlings3.github.io/iesdp/files/2da/2da_bgee/dexmod.htm"><code>dexmod.2da</code></a>) instead of Strength.<br>
As a completely artificial example, suppose a Thief has 9 Strength and 18 Dexterity. Upon equipping a dagger, he/she will gain a THAC0 bonus of <code>2</code> (instead of <code>0</code>). Note that nothing happens if the bonus from Strength is better (or equal) than the bonus from Dexterity.
</p>
<p> <strong>Dual-Wield feat for Rangers [Luke]</strong><br />
Expand Down Expand Up @@ -1346,6 +1346,13 @@ <h3> <a id="contents_npc" name="contents_npc"></a>Joinable <abbr title="Non-Play
<p> <strong>Removable <abbr title="Non-Player Character">NPC</abbr> Items</strong><br />
<em><abbr title="Baldur's Gate: Enhanced Edition">BGEE</abbr>, <abbr title="Baldur's Gate II: Enhanced Edition">BG2EE</abbr>, <abbr title="Enhanced Edition Trilogy">EET</abbr>, <abbr title="Baldur's Gate">BG</abbr>, <abbr title="Baldur's Gate II">BG2</abbr>, <abbr title="Baldur's Gate Trilogy">BGT</abbr>, Tutu</em> </p>
<p> Alora, Edwin, Hexxat, and Nalia all have jewelry that cannot be removed. Except for Hexxat, this component allows you to remove these items (though they still cannot be used by other characters) so that you can use other items in these slots. Hexxat&#39;s Amulet is fairly integral to her powers and abilities and so she is not altered by this component. Note that while Edwin&#39;s amulet is actually the source of his extra spell slots, these effects are now applied directly to him so that you can remove his amulet without penalty. </p>

<p> <strong>Make Rancor +1 a bit more reliable [Luke]</strong><br />
<em><abbr title="Baldur's Gate: Enhanced Edition">EEex</abbr></em></p>
<p> Internally, Dorn's sword (Rancor +1) relies upon scripting. As modders know, items should not rely upon scripting to work correctly, since it is unreliable and may quickly become messy.
This component simply removes scripting from this weapon (the upshot of which is that the weapon should become a bit more reliable).
</p>

</div>
<div class="ribbon_rectangle_h2"> <a id="Contact" name="Contact"></a>
<h2> Contact Information </h2>
Expand Down
14 changes: 14 additions & 0 deletions cdtweaks/setup-cdtweaks.tp2
Expand Up @@ -4605,3 +4605,17 @@ SUBCOMPONENT @419000 // Color NPC Names in Dialogues, Journal Entries, Etc.
GROUP @0
REQUIRE_PREDICATE GAME_IS ~bgee bg2ee iwdee eet~ @25
LABEL ~cd_tweaks_color_npc_names_pc_orange~

/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
///// \\\\\
///// Make Rancor +1 a bit more reliable \\\\\
///// \\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\

BEGIN @420000 DESIGNATED 4200
GROUP @0
REQUIRE_PREDICATE GAME_IS ~bgee bg2ee eet~ @25
REQUIRE_PREDICATE MOD_IS_INSTALLED "EEex.tp2" 0 @29
LABEL ~cd_tweaks_dorns_sword~