Commit e0695de2 authored by nanahira's avatar nanahira

new

parent ae6acaa6
Duel.LoadScript("underscore.lua")
local function grantAll(e,tg,r)
local e3=Effect.GlobalEffect()
e3:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_GRANT)
e3:SetProperty((r and 0 or EFFECT_FLAG_IGNORE_RANGE)+EFFECT_FLAG_IGNORE_IMMUNE+EFFECT_FLAG_SET_AVAILABLE)
local tr=r or 0xff
e3:SetTargetRange(tr,tr)
e3:SetLabelObject(e)
if tg then
e3:SetTarget(tg)
end
Duel.RegisterEffect(e3,0)
end
local function grantDecktop(e)
local e3=Effect.GlobalEffect()
e3:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_GRANT)
e3:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE+EFFECT_FLAG_SET_AVAILABLE)
e3:SetTargetRange(LOCATION_DECK,LOCATION_DECK)
e3:SetTarget(function(e,c)
local tp=c:GetControler()
local dg=Duel.GetFieldGroup(tp,LOCATION_DECK,0)
local g=dg:GetMinGroup(Card.GetSequence)
return g:GetFirst()==c
end)
e3:SetLabelObject(e)
Duel.RegisterEffect(e3,0)
end
local function fieldEffect(r)
local e1=Effect.GlobalEffect()
e1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
e1:SetCode(EVENT_FREE_CHAIN)
e1:SetProperty(EFFECT_FLAG_SET_AVAILABLE)
e1:SetRange(r)
return e1
end
local function deckEffect()
return fieldEffect(LOCATION_DECK)
end
function Auxiliary.PreloadUds()
--deck effects for card
local e1=deckEffect()
e1:SetDescription(1105)
e1:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
local g=Duel.SelectMatchingCard(tp,nil,tp,0xff-LOCATION_DECK,0xff,1,99,nil)
if #g>0 then
local pos=Duel.SelectPosition(tp,g:GetFirst(),POS_ATTACK)
Duel.SendtoDeck(g,tp,pos==POS_FACEUP_ATTACK and 0 or 1,REASON_RULE)
end
end)
grantDecktop(e1)
local e1=deckEffect()
e1:SetDescription(1104)
e1:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
local g=Duel.SelectMatchingCard(tp,nil,tp,0xff-LOCATION_HAND,0xff,1,99,nil)
if #g>0 then
Duel.SendtoHand(g,tp,REASON_RULE)
end
end)
grantDecktop(e1)
local e1=deckEffect()
e1:SetDescription(1103)
e1:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
local g=Duel.SelectMatchingCard(tp,nil,tp,0xff-LOCATION_GRAVE,0,1,99,nil)
if #g>0 then
Duel.SendtoGrave(g,REASON_RULE)
end
end)
grantDecktop(e1)
local e1=deckEffect()
e1:SetDescription(1102)
e1:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
local g=Duel.SelectMatchingCard(tp,nil,tp,0xff-LOCATION_REMOVED,0,1,99,nil)
if #g>0 then
local pos=Duel.SelectPosition(tp,g:GetFirst(),POS_ATTACK)
Duel.Remove(g,pos,REASON_RULE)
end
end)
grantDecktop(e1)
local e1=deckEffect()
e1:SetDescription(1118)
e1:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
local g=Duel.SelectMatchingCard(tp,nil,tp,0xff-LOCATION_MZONE,0xff-LOCATION_MZONE,1,99,nil)
if #g>0 then
Duel.SpecialSummon(g,0,tp,tp,true,true,POS_FACEUP+POS_FACEDOWN)
end
end)
grantDecktop(e1)
local e1=deckEffect()
e1:SetDescription(1159)
e1:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
local g=Duel.SelectMatchingCard(tp,nil,tp,0xff-LOCATION_SZONE,0xff,1,1,nil)
if #g>0 then
local tc=g:GetFirst()
local loc=LOCATION_SZONE
if tc:IsType(TYPE_FIELD) then
loc=LOCATION_FZONE
elseif tc:IsType(TYPE_PENDULUM) then
loc=LOCATION_PZONE
end
local pos=Duel.SelectPosition(tp,tc,POS_ATTACK)
Duel.MoveToField(tc,tp,tp,loc,pos,true)
end
end)
grantDecktop(e1)
local e1=deckEffect()
e1:SetDescription(1111)
e1:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
local g=Duel.SelectMatchingCard(tp,nil,tp,LOCATION_ONFIELD,0,1,1,nil)
if #g>0 then
local tc=g:GetFirst()
local pos=Duel.SelectPosition(tp,tc,POS_FACEUP+POS_FACEDOWN)
Duel.ChangePosition(tc,pos)
end
end)
grantDecktop(e1)
--deck effects for global
local e1=deckEffect()
e1:SetDescription(1297)
e1:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
Duel.ShuffleDeck(tp)
Duel.ShuffleHand(tp)
end)
grantDecktop(e1)
local e1=deckEffect()
e1:SetDescription(1123)
e1:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
local acs={}
for i=-2000,2000,100 do
if i~=0 then
_.push(acs,i)
end
end
local _,_ac=Duel.AnnounceNumber(tp,table.unpack(acs))
local ac=acs[_ac+1]
if ac>0 then
Duel.Recover(tp,ac,REASON_RULE)
elseif ac<0 then
Duel.Damage(tp,-ac,REASON_RULE)
end
end)
grantDecktop(e1)
local e1=deckEffect()
e1:SetDescription(1108)
e1:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
local ac=Duel.AnnounceNumber(tp,1,2,3,4,5,6,7,8,9,10,11,12)
Duel.Draw(tp,ac,REASON_RULE)
end)
grantDecktop(e1)
local e1=deckEffect()
e1:SetDescription(1119)
e1:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
local ac=Duel.AnnounceCard(tp)
local tc=Duel.CreateToken(tp,ac)
Duel.SpecialSummon(tc,0,tp,tp,true,true,POS_FACEUP)
end)
grantDecktop(e1)
--single card effects
local e1=fieldEffect(LOCATION_ONFIELD)
e1:SetDescription(1111)
e1:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
local c=e:GetHandler()
local pos=Duel.SelectPosition(tp,c,POS_FACEUP+POS_FACEDOWN)
Duel.ChangePosition(c,pos)
end)
grantAll(e1,nil,LOCATION_ONFIELD)
local e1=fieldEffect(LOCATION_MZONE)
e1:SetDescription(1112)
e1:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
local c=e:GetHandler()
Duel.GetControl(c,1-tp)
end)
grantAll(e1,nil,LOCATION_MZONE)
local e1=fieldEffect(LOCATION_MZONE)
e1:SetDescription(1113)
e1:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
local c=e:GetHandler()
local acs={}
for i=-2000,2000,100 do
if i~=0 then
_.push(acs,i)
end
end
local _,_ac=Duel.AnnounceNumber(tp,table.unpack(acs))
local ac=acs[_ac+1]
local ex=Effect.CreateEffect(c)
ex:SetType(EFFECT_TYPE_SINGLE)
ex:SetCode(EFFECT_UPDATE_ATTACK)
ex:SetValue(ac)
ex:SetReset(0x1fe1000)
Card.RegisterEffect(c,ex,true)
local ex=Effect.CreateEffect(c)
ex:SetType(EFFECT_TYPE_SINGLE)
ex:SetCode(EFFECT_UPDATE_DEFENSE)
ex:SetValue(ac)
ex:SetReset(0x1fe1000)
Card.RegisterEffect(c,ex,true)
end)
grantAll(e1,nil,LOCATION_MZONE)
local e1=fieldEffect(LOCATION_MZONE)
e1:SetDescription(1113)
e1:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
local c=e:GetHandler()
local g=Duel.SelectMatchingCard(tp,nil,tp,0xff,0xff,1,99,c)
local og=g:Filter(Card.IsLocation,nil,LOCATION_OVERLAY)
g:Sub(og)
local tog=Group.CreateGroup()
for tc in Auxiliary.Next(g) do
for oc in Auxiliary.Next(tc:GetOverlayGroup()) do
if og:IsContains(oc) then
og:RemoveCard(oc)
tog:AddCard(oc)
end
end
end
Duel.Overlay(c,tog)
Duel.SendtoGrave(og,REASON_RULE)
Duel.Overlay(tc,g)
end)
grantAll(e1,function(e,c) return c:IsType(TYPE_XYZ) end,LOCATION_MZONE)
local loc=LOCATION_HAND+LOCATION_ONFIELD
local e1=fieldEffect(loc)
e1:SetDescription(1105)
e1:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
local g=Group.FromCards(e:GetHandler())
if #g>0 then
local pos=Duel.SelectPosition(tp,g:GetFirst(),POS_ATTACK)
Duel.SendtoDeck(g,tp,pos==POS_FACEUP_ATTACK and 0 or 1,REASON_RULE)
end
end)
grantAll(e1,nil,loc)
local loc=LOCATION_ONFIELD
local e1=fieldEffect(loc)
e1:SetDescription(1104)
e1:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
local g=Group.FromCards(e:GetHandler())
if #g>0 then
Duel.SendtoHand(g,tp,REASON_RULE)
end
end)
grantAll(e1,nil,loc)
local loc=LOCATION_HAND+LOCATION_ONFIELD
local e1=fieldEffect(loc)
e1:SetDescription(1103)
e1:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
local g=Group.FromCards(e:GetHandler())
if #g>0 then
Duel.SendtoGrave(g,REASON_RULE)
end
end)
grantAll(e1,nil,loc)
local loc=LOCATION_HAND+LOCATION_ONFIELD
local e1=fieldEffect(loc)
e1:SetDescription(1102)
e1:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
local g=Group.FromCards(e:GetHandler())
if #g>0 then
local pos=Duel.SelectPosition(tp,g:GetFirst(),POS_ATTACK)
Duel.Remove(g,pos,REASON_RULE)
end
end)
grantAll(e1,nil,loc)
local loc=LOCATION_HAND+LOCATION_SZONE
local e1=fieldEffect(loc)
e1:SetDescription(1118)
e1:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
local g=Group.FromCards(e:GetHandler())
if #g>0 then
Duel.SpecialSummon(g,0,tp,tp,true,true,POS_FACEUP+POS_FACEDOWN)
end
end)
grantAll(e1,nil,loc)
local loc=LOCATION_HAND+LOCATION_MZONE
local e1=fieldEffect(loc)
e1:SetDescription(1159)
e1:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
local g=Group.FromCards(e:GetHandler())
if #g>0 then
local tc=g:GetFirst()
local loc=LOCATION_SZONE
if tc:IsType(TYPE_FIELD) then
loc=LOCATION_FZONE
elseif tc:IsType(TYPE_PENDULUM) then
loc=LOCATION_PZONE
end
local pos=Duel.SelectPosition(tp,tc,POS_ATTACK)
Duel.MoveToField(tc,tp,tp,loc,pos,true)
end
end)
grantAll(e1,nil,loc)
--spells and traps
local e1=Effect.GlobalEffect()
e1:SetType(EFFECT_TYPE_ACTIVATE)
e1:SetCode(EVENT_FREE_CHAIN)
e1:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
local c=e:GetHandler()
c:CancelToGrave()
end)
grantAll(e1,function(e,c) return c:IsType(TYPE_SPELL+TYPE_TRAP+TYPE_PENDULUM) end)
local e1=Effect.GlobalEffect()
e1:SetType(EFFECT_TYPE_FIELD)
e1:SetCode(EFFECT_SPSUMMON_PROC)
e1:SetRange(LOCATION_DECK+LOCATION_HAND+LOCATION_GRAVE+LOCATION_EXTRA)
e1:SetCondition(function(e,c)
if c==nil then return true end
local tp=c:GetControler()
if c:IsLocation(LOCATION_EXTRA) then
return Duel.GetLocationCountFromEx(tp,tp,nil,c)>0
else
return Duel.GetLocationCount(tp,LOCATION_MZONE)>0
end
end)
grantAll(e1,function(e,c) return c:IsType(TYPE_MONSTER) end,LOCATION_DECK+LOCATION_HAND+LOCATION_GRAVE+LOCATION_EXTRA)
--effect codes
for code,value in pairs({
[EFFECT_QP_ACT_IN_NTPHAND]=1,
[EFFECT_QP_ACT_IN_SET_TURN]=1,
[EFFECT_TRAP_ACT_IN_HAND]=1,
[EFFECT_TRAP_ACT_IN_SET_TURN]=1,
[EFFECT_DEFENSE_ATTACK]=1,
[EFFECT_EXTRA_ATTACK]=99,
}) do
local e1=Effect.GlobalEffect()
e1:SetType(EFFECT_TYPE_SINGLE)
e1:SetCode(code)
e1:SetValue(value)
e1:SetProperty(EFFECT_FLAG_SET_AVAILABLE)
end
grantAll(e1)
for tc in aux.Next(Duel.GetFieldGroup(0,0xff,0xff)) do
local mt=getmetatable(tc)
mt.initial_effect=Auxiliary.NULL
end
end
-- Copyright (c) 2009 Marcus Irven
--
-- Permission is hereby granted, free of charge, to any person
-- obtaining a copy of this software and associated documentation
-- files (the "Software"), to deal in the Software without
-- restriction, including without limitation the rights to use,
-- copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the
-- Software is furnished to do so, subject to the following
-- conditions:
--
-- The above copyright notice and this permission notice shall be
-- included in all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-- OTHER DEALINGS IN THE SOFTWARE.
--- Underscore is a set of utility functions for dealing with
-- iterators, arrays, tables, and functions.
local Underscore = { funcs = {} }
Underscore.__index = Underscore
function Underscore.__call(_, value)
return Underscore:new(value)
end
function Underscore:new(value, chained)
return setmetatable({ _val = value, chained = chained or false }, self)
end
function Underscore.iter(list_or_iter)
if type(list_or_iter) == "function" then return list_or_iter end
return coroutine.wrap(function()
for i=1,#list_or_iter do
coroutine.yield(list_or_iter[i])
end
end)
end
function Underscore.range(start_i, end_i, step)
if end_i == nil then
end_i = start_i
start_i = 1
end
step = step or 1
local range_iter = coroutine.wrap(function()
for i=start_i, end_i, step do
coroutine.yield(i)
end
end)
return Underscore:new(range_iter)
end
--- Identity function. This function looks useless, but is used throughout Underscore as a default.
-- @name _.identity
-- @param value any object
-- @return value
-- @usage _.identity("foo")
-- => "foo"
function Underscore.identity(value)
return value
end
-- chaining
function Underscore:chain()
self.chained = true
return self
end
function Underscore:value()
return self._val
end
-- iter
function Underscore.funcs.each(list, func)
for i in Underscore.iter(list) do
func(i)
end
return list
end
function Underscore.funcs.map(list, func)
local mapped = {}
for i in Underscore.iter(list) do
mapped[#mapped+1] = func(i)
end
return mapped
end
function Underscore.funcs.reduce(list, memo, func)
for i in Underscore.iter(list) do
memo = func(memo, i)
end
return memo
end
function Underscore.funcs.detect(list, func)
for i in Underscore.iter(list) do
if func(i) then return i end
end
return nil
end
function Underscore.funcs.select(list, func)
local selected = {}
for i in Underscore.iter(list) do
if func(i) then selected[#selected+1] = i end
end
return selected
end
function Underscore.funcs.reject(list, func)
local selected = {}
for i in Underscore.iter(list) do
if not func(i) then selected[#selected+1] = i end
end
return selected
end
function Underscore.funcs.all(list, func)
func = func or Underscore.identity
-- TODO what should happen with an empty list?
for i in Underscore.iter(list) do
if not func(i) then return false end
end
return true
end
function Underscore.funcs.any(list, func)
func = func or Underscore.identity
-- TODO what should happen with an empty list?
for i in Underscore.iter(list) do
if func(i) then return true end
end
return false
end
function Underscore.funcs.include(list, value)
for i in Underscore.iter(list) do
if i == value then return true end
end
return false
end
function Underscore.funcs.invoke(list, function_name, ...)
local args = {...}
Underscore.funcs.each(list, function(i) i[function_name](i, unpack(args)) end)
return list
end
function Underscore.funcs.pluck(list, propertyName)
return Underscore.funcs.map(list, function(i) return i[propertyName] end)
end
function Underscore.funcs.min(list, func)
func = func or Underscore.identity
return Underscore.funcs.reduce(list, { item = nil, value = nil }, function(min, item)
if min.item == nil then
min.item = item
min.value = func(item)
else
local value = func(item)
if value < min.value then
min.item = item
min.value = value
end
end
return min
end).item
end
function Underscore.funcs.max(list, func)
func = func or Underscore.identity
return Underscore.funcs.reduce(list, { item = nil, value = nil }, function(max, item)
if max.item == nil then
max.item = item
max.value = func(item)
else
local value = func(item)
if value > max.value then
max.item = item
max.value = value
end
end
return max
end).item
end
function Underscore.funcs.to_array(list)
local array = {}
for i in Underscore.iter(list) do
array[#array+1] = i
end
return array
end
function Underscore.funcs.reverse(list)
local reversed = {}
for i in Underscore.iter(list) do
table.insert(reversed, 1, i)
end
return reversed
end
function Underscore.funcs.sort(iter, comparison_func)
local array = iter
if type(iter) == "function" then
array = Underscore.funcs.to_array(iter)
end
table.sort(array, comparison_func)
return array
end
-- arrays
function Underscore.funcs.first(array, n)
if n == nil then
return array[1]
else
local first = {}
n = math.min(n,#array)
for i=1,n do
first[i] = array[i]
end
return first
end
end
function Underscore.funcs.rest(array, index)
index = index or 2
local rest = {}
for i=index,#array do
rest[#rest+1] = array[i]
end
return rest
end
function Underscore.funcs.slice(array, start_index, length)
local sliced_array = {}
start_index = math.max(start_index, 1)
local end_index = math.min(start_index+length-1, #array)
for i=start_index, end_index do
sliced_array[#sliced_array+1] = array[i]
end
return sliced_array
end
function Underscore.funcs.flatten(array)
local all = {}
for ele in Underscore.iter(array) do
if type(ele) == "table" then
local flattened_element = Underscore.funcs.flatten(ele)
Underscore.funcs.each(flattened_element, function(e) all[#all+1] = e end)
else
all[#all+1] = ele
end
end
return all
end
function Underscore.funcs.push(array, item)
table.insert(array, item)
return array
end
function Underscore.funcs.pop(array)
return table.remove(array)
end
function Underscore.funcs.shift(array)
return table.remove(array, 1)
end
function Underscore.funcs.unshift(array, item)
table.insert(array, 1, item)
return array
end
function Underscore.funcs.join(array, separator)
return table.concat(array, separator)
end
-- objects
function Underscore.funcs.keys(obj)
local keys = {}
for k,v in pairs(obj) do
keys[#keys+1] = k
end
return keys
end
function Underscore.funcs.values(obj)
local values = {}
for k,v in pairs(obj) do
values[#values+1] = v
end
return values
end
function Underscore.funcs.extend(destination, source)
for k,v in pairs(source) do
destination[k] = v
end
return destination
end
function Underscore.funcs.is_empty(obj)
return next(obj) == nil
end
-- Originally based on penlight's deepcompare() -- http://luaforge.net/projects/penlight/
function Underscore.funcs.is_equal(o1, o2, ignore_mt)
local ty1 = type(o1)
local ty2 = type(o2)
if ty1 ~= ty2 then return false end
-- non-table types can be directly compared
if ty1 ~= 'table' then return o1 == o2 end
-- as well as tables which have the metamethod __eq
local mt = getmetatable(o1)
if not ignore_mt and mt and mt.__eq then return o1 == o2 end
local is_equal = Underscore.funcs.is_equal
for k1,v1 in pairs(o1) do
local v2 = o2[k1]
if v2 == nil or not is_equal(v1,v2, ignore_mt) then return false end
end
for k2,v2 in pairs(o2) do
local v1 = o1[k2]
if v1 == nil then return false end
end
return true
end
-- functions
function Underscore.funcs.compose(...)
local function call_funcs(funcs, ...)
if #funcs > 1 then
return funcs[1](call_funcs(_.rest(funcs), ...))
else
return funcs[1](...)
end
end
local funcs = {...}
return function(...)
return call_funcs(funcs, ...)
end
end
function Underscore.funcs.wrap(func, wrapper)
return function(...)
return wrapper(func, ...)
end
end
function Underscore.funcs.curry(func, argument)
return function(...)
return func(argument, ...)
end
end
function Underscore.functions()
return Underscore.keys(Underscore.funcs)
end
-- add aliases
Underscore.methods = Underscore.functions
Underscore.funcs.for_each = Underscore.funcs.each
Underscore.funcs.collect = Underscore.funcs.map
Underscore.funcs.inject = Underscore.funcs.reduce
Underscore.funcs.foldl = Underscore.funcs.reduce
Underscore.funcs.filter = Underscore.funcs.select
Underscore.funcs.every = Underscore.funcs.all
Underscore.funcs.some = Underscore.funcs.any
Underscore.funcs.head = Underscore.funcs.first
Underscore.funcs.tail = Underscore.funcs.rest
local function wrap_functions_for_oo_support()
local function value_and_chained(value_or_self)
local chained = false
if getmetatable(value_or_self) == Underscore then
chained = value_or_self.chained
value_or_self = value_or_self._val
end
return value_or_self, chained
end
local function value_or_wrap(value, chained)
if chained then value = Underscore:new(value, true) end
return value
end
for fn, func in pairs(Underscore.funcs) do
Underscore[fn] = function(obj_or_self, ...)
local obj, chained = value_and_chained(obj_or_self)
return value_or_wrap(func(obj, ...), chained)
end
end
end
wrap_functions_for_oo_support()
_ = Underscore:new()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment