Adding Book of Shiori function - kohashiwakaba/Pudding-Wakaba GitHub Wiki

As v103-Richer, Book of Shiori function got refactored using Isaac v1.7.9 standards. Modders can add Book of Shiori interactions by adding Callbacks.

ALL callbacks should be checked through two conditions:

if wakaba and wakaba.version then
	--do something
end

Keep in mind that Checking only wakaba varaible will NOT have full access for P&W functions.

Book of Shiori has two extra effects by using active items:

  • Primary effect is the extra effect that is activated along with original active item effect.
  • Secondary effect is the innate effect that is activated until Shiori uses another active item. Secondary can be invalidated, or kept intact with some items.

Adding primary Shiori effect.

For adding primary effect, Book of Shiori uses two callbacks for activation. One is from set flag, the other is from used item.

  • wakaba.Callback.POST_ACTIVATE_SHIORI_EFFECT : Called from ModCallbacks.MC_USE_ITEM, always activated from using actual item.
  • wakaba.Callback.POST_CHANGE_SHIORI_EFFECT : Called from ModCallbacks.MC_USE_ITEM, unlike POST_ACTIVATE_SHIORI_EFFECT, This will be activated from recently changed item, see Hijacking, or invalidating secondary Shiori effect.

This code adds Holy Mantle if player used The Bible with Book of Shiori.

function wakaba:Shiori_Bible(_, rng, player, useflag, slot, vardata)
	player:UseActiveItem(CollectibleType.COLLECTIBLE_HOLY_MANTLE)
end
wakaba:AddCallback(wakaba.Callback.POST_ACTIVATE_SHIORI_EFFECT, wakaba.Shiori_Bible, CollectibleType.COLLECTIBLE_BIBLE)

Parameters passed are same as ModCallbacks.MC_USE_ITEM.

Adding secondary Shiori effect.

Using Active items with Book of Shiori will automatically change secondary effect. To get current Book of Shiori effect, simply call this function:

wakaba:getShioriFlag(player) -- player:EntityPlayer, returns CollectibleType

Unlike primary effect, secondaries can be used within various callbacks. This code will remove all projectiles if any player has secondary effect for Book of Silence.

function wakaba:ProjectileUpdate_BookofShiori(tear)
	for i = 0, wakaba.G:GetNumPlayers()-1 do
		local player = Isaac.GetPlayer(i)
		if player:GetData().wakaba then
			local nextflag = wakaba:getShioriFlag(player)
			if nextflag == wakaba.Enums.Collectibles.BOOK_OF_SILENCE then
				tear:Remove()
			end
		end
	end
end
wakaba:AddCallback(ModCallbacks.MC_POST_PROJECTILE_UPDATE, wakaba.ProjectileUpdate_BookofShiori)

Parameters passed are same as ModCallbacks.MC_USE_ITEM.

Hijacking, or invalidating secondary Shiori effect.

Secondary Shiori effects can be invalidated from two cases, from callbacks, or from functions.

From Callbacks

wakaba.Callback.PRE_CHANGE_SHIORI_EFFECT is Called from ModCallbacks.MC_USE_ITEM before changing Shiori's secondary effect. It is also called from using Soul of Shiori. if non-nil value is returned, one of following values can be set for extra functionality:

  • true : Invalidates Secondary Shiori effect. Skips later callback executions AND all wakaba.Callback.POST_CHANGE_SHIORI_EFFECT callback functions.
  • false : Prevents changing Secondary Shiori effect. Skips later callback executions, wakaba.Callback.POST_CHANGE_SHIORI_EFFECT will be called as previous effect.
  • CollectibleType : Hijacks Secondary Shiori effect into different item. The last callback to return a valid return value wins out and overwrites previous callbacks' return values

This code invalidates secondary Shiori effect:

function wakaba:PreShiori_BookofFocus(_, rng, player, useflag, slot, vardata)
	-- Book of Focus disables secondary Shiori effect
	return true
end
wakaba:AddCallback(wakaba.Callback.PRE_CHANGE_SHIORI_EFFECT, wakaba.PreShiori_BookofFocus, wakaba.Enums.Collectibles.BOOK_OF_FOCUS)

From Functions

To change secondary Shiori effect, simply call this function:

wakaba:setShioriFlag(player, CollectibleType)

Setting CollectibleType param to nil will invalidate secondary effect.

Soul of Shiori

Adding one of wakaba.Callback.POST_ACTIVATE_SHIORI_EFFECT, wakaba.Callback.POST_CHANGE_SHIORI_EFFECT, wakaba.Callback.PRE_CHANGE_SHIORI_EFFECT will count as adding secondary Shiori effect for certain collectibleType.

wakaba.Callback.PRE_CHANGE_SHIORI_EFFECT and wakaba.Callback.PRE_EVALUATE_SOUL_OF_SHIORI callback checks whether the certain collectibleType should be used from Soul of Shiori. returning non-nil value other than false prevent to be selected as Soul of Shiori effect.

Legacy methods