Difference between pages "Card Tips:Prisman" and "Module:Card/traits/implicit Normal and Effect"
(Difference between pages)
(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 1: | Line 1: | ||
− | + | -- 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 |
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