PDA

View Full Version : CoreRPG CombatManager.nextActor()



Dire Weasel
August 13th, 2021, 22:14
I'm putting together a simple extension to support a skip turn effect.

Unfortunately, it looks like I'll need to replace CombatManager.nextActor(), which is pretty drastic and very fragile.
I'd obviously prefer a function I could hook.
How feasible would it be to call a function like shouldSkipActor() from nextActor() in CoreRPG's manager_combat.lua?

Something like:



function nextActor(bSkipBell, bNoRoundAdvance)
if not Session.IsHost then
return;
end

local nodeActive = CombatManager.getActiveCT();
local nIndexActive = 0;

-- Check the skip hidden NPC option
local bSkipHidden = OptionsManager.isOption("CTSH", "on");

-- Determine the next actor
local nodeNext = nil;
local nIndexNext = 0;
local aEntries = CombatManager.getSortedCombatantList();
local nEntriesCount = #aEntries
if nEntriesCount > 0 then
if nodeActive then
for i = 1, nEntriesCount do
if aEntries[i] == nodeActive then
nIndexActive = i;
break;
end
end
end
for i = nIndexActive + 1, nEntriesCount do
if not CombatManager.shouldSkipActor(aEntries[i], bSkipHidden) then
nodeNext = aEntries[i];
nIndexNext = i;
break;
end
end
end

-- If next actor available, advance effects, activate and start turn
if nodeNext then
-- Show turn message for skipped actors
for i = nIndexActive + 1, nIndexNext - 1 do
CombatManager.showTurnMessage(aEntries[i], false);
end

-- End turn for current actor
CombatManager.onTurnEndEvent(nodeActive);

-- Process effects in between current and next actors
if nodeActive then
CombatManager.onInitChangeEvent(nodeActive, nodeNext);
else
CombatManager.onInitChangeEvent(nil, nodeNext);
end

-- Start turn for next actor
CombatManager.requestActivation(nodeNext, bSkipBell);
CombatManager.onTurnStartEvent(nodeNext);
elseif not bNoRoundAdvance then
-- Show turn message for skipped actors
for i = nIndexActive + 1, nEntriesCount do
CombatManager.showTurnMessage(aEntries[i], false);
end

CombatManager.nextRound(1);
end
end

function shouldSkipActor(nodeCT, bSkipHidden)
return bSkipHidden and DB.getValue(nodeCT, "friendfoe", "") ~= "friend" and CombatManager.isCTHidden(nodeCT)
end

superteddy57
August 13th, 2021, 22:19
CombatManager is a global script, so any of the functions within the file are able to be called anywhere. For your question, it might be best to make a new function instead of using the one there as you would have to replace the function anyway. You can pull out the parts you want to use.

Dire Weasel
August 13th, 2021, 22:23
CombatManager is a global script, so any of the functions within the file are able to be called anywhere. For your question, it might be best to make a new function instead of using the one there as you would have to replace the function anyway. You can pull out the parts you want to use.

That's what my current implementation does. However, it will need to be aggressively maintained for changes to CoreRPG. Additionally, it wouldn't play well with other extensions replacing or hooking nextActor(). If a hook function was provided, it would be much more stable.

superteddy57
August 13th, 2021, 22:28
You can use an override that won't affect the normal CoreRPG version of the function. As an example with the code provided.

CombatManager.nextActor= nameOfnewNextactorFunction;

From there you define a new function with the variable on the right and build it how you see fit. This would be placed in the onInit of a global script. However, you might have to be careful of other functions that rely on CombatManager.nextActor

Dire Weasel
August 14th, 2021, 03:42
Other than Savage Worlds, the only ruleset I've found that replaces nextActor() is 2E.

It also replaces it to skip certain actors - in this case dead NPCs.