Difference between revisions of "Module:Card/traits/implicit Normal and Effect"
(First array element is indexed as 1 not 0.) |
(make `isNormalMonster(card)` and `isEffectMonster(card)` local functions. (Need to define them before the function that invokes them for them to work this way.)) |
||
Line 9: | Line 9: | ||
-- Take a copy of the original `Card` object before this makes changes to it. | -- Take a copy of the original `Card` object before this makes changes to it. | ||
local Parent = mw.clone(Card) | local Parent = mw.clone(Card) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Line 29: | Line 14: | ||
-- ------------------------------------ | -- ------------------------------------ | ||
-- Custom methods | -- Custom methods | ||
+ | -- Methods that are only to be used within this module | ||
-- ------------------------------------ | -- ------------------------------------ | ||
-- Check if the card is a Normal Monster | -- Check if the card is a Normal Monster | ||
-- @param card Card | -- @param card Card | ||
-- @return bool | -- @return bool | ||
− | function isNormalMonster(card) | + | local function isNormalMonster(card) |
-- Not a monster, can't be a Normal Monster | -- Not a monster, can't be a Normal Monster | ||
if (not card.isMonster) then return false end | if (not card.isMonster) then return false end | ||
Line 58: | Line 44: | ||
-- @param card Card | -- @param card Card | ||
-- @return bool | -- @return bool | ||
− | function isEffectMonster(card) | + | local function isEffectMonster(card) |
-- Not a monster, can't be an Effect Monster | -- Not a monster, can't be an Effect Monster | ||
if (not card.isMonster) then return false end | if (not card.isMonster) then return false end | ||
Line 73: | Line 59: | ||
return false | return false | ||
+ | end | ||
+ | |||
+ | |||
+ | |||
+ | -- ------------------------------------ | ||
+ | -- Override methods | ||
+ | -- These methods exist in the original `Card` module | ||
+ | -- And are having their behavior modified here. | ||
+ | -- ------------------------------------ | ||
+ | -- Override the `setData` method to change its Normal/Effect-checking logic | ||
+ | function Card:setData(args) | ||
+ | -- Call the original `setData` function | ||
+ | Parent.setData(self, args) | ||
+ | |||
+ | -- Set the "Normal" and "Effect" checks based on the logic in this module | ||
+ | self.isNormalMonster = isNormalMonster(self) | ||
+ | self.isEffectMonster = isEffectMonster(self) | ||
end | end | ||
return Card | return Card |
Latest revision as of 22:14, 28 December 2023
-- Trait for games that don't explicitely put "Normal"
-- and don't necessarily put "Effect" next to a card's Type.
-- For testing purposes, make sure this is defined.
if not Card then
Card = require('Module:Card')
end
-- Take a copy of the original `Card` object before this makes changes to it.
local Parent = mw.clone(Card)
-- ------------------------------------
-- Custom methods
-- Methods that are only to be used within this module
-- ------------------------------------
-- Check if the card is a Normal Monster
-- @param card Card
-- @return bool
local function isNormalMonster(card)
-- Not a monster, can't be a Normal Monster
if (not card.isMonster) then return false end
-- If the Types contain an Effect, Summon or ability Type, it is not a Normal Monster
for _, type in pairs(card.types) do
if (TableTools.inArray({ 'Effect', 'Summon', 'Ability' }, type.category)) then
return false
end
end
-- If the card has an Effect type, it is not a Normal Monster
if (#card.effectTypes > 0) then return false end
-- If the card is a God card, it is not a Normal Monster
if (#card.attributes and card.attributes[1].link == 'DIVINE') then
return false
end
return true
end
-- Check if the card is an Effect Monster
-- @param card Card
-- @return bool
local function isEffectMonster(card)
-- Not a monster, can't be an Effect Monster
if (not card.isMonster) then return false end
-- If the Types contain an Effect or ability Type, it is an Effect Monster
for _, type in pairs(card.types) do
if (TableTools.inArray({ 'Effect', 'Ability' }, type.category)) then
return true
end
end
-- If the card has an Effect type, it is an Effect Monster
if (#card.effectTypes > 0) then return true end
return false
end
-- ------------------------------------
-- Override methods
-- These methods exist in the original `Card` module
-- And are having their behavior modified here.
-- ------------------------------------
-- Override the `setData` method to change its Normal/Effect-checking logic
function Card:setData(args)
-- Call the original `setData` function
Parent.setData(self, args)
-- Set the "Normal" and "Effect" checks based on the logic in this module
self.isNormalMonster = isNormalMonster(self)
self.isEffectMonster = isEffectMonster(self)
end
return Card