56 lines
2.3 KiB
CoffeeScript
56 lines
2.3 KiB
CoffeeScript
@roundHalfDown = (number) ->
|
|
Math.ceil(number - .5)
|
|
|
|
@typeEffectiveness = (userType, againstTypes, options = {}) ->
|
|
userType = Type[userType]
|
|
effectiveness = 1
|
|
for subtype in againstTypes
|
|
targetType = Type[subtype]
|
|
multiplier = typeChart[userType][targetType]
|
|
multiplier = 1 if multiplier == 0 && options.ignoreImmunities
|
|
multiplier = 2 if options.superEffectiveAgainst == subtype
|
|
effectiveness *= multiplier
|
|
effectiveness
|
|
|
|
@Type = Type =
|
|
Normal : 0
|
|
Fire : 1
|
|
Water : 2
|
|
Electric : 3
|
|
Grass : 4
|
|
Ice : 5
|
|
Fighting : 6
|
|
Poison : 7
|
|
Ground : 8
|
|
Flying : 9
|
|
Psychic : 10
|
|
Bug : 11
|
|
Rock : 12
|
|
Ghost : 13
|
|
Dragon : 14
|
|
Dark : 15
|
|
Steel : 16
|
|
"???" : 17
|
|
|
|
typeChart = [
|
|
# Nor Fir Wat Ele Gra Ice Fig Poi Gro Fly Psy Bug Roc Gho Dra Dar Ste ???
|
|
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, .5, 0, 1, 1, .5, 1 ], # Nor
|
|
[ 1, .5, .5, 1, 2, 2, 1, 1, 1, 1, 1, 2, .5, 1, .5, 1, 2, 1 ], # Fir
|
|
[ 1, 2, .5, 1, .5, 1, 1, 1, 2, 1, 1, 1, 2, 1, .5, 1, 1, 1 ], # Wat
|
|
[ 1, 1, 2, .5, .5, 1, 1, 1, 0, 2, 1, 1, 1, 1, .5, 1, 1, 1 ], # Ele
|
|
[ 1, .5, 2, 1, .5, 1, 1, .5, 2, .5, 1, .5, 2, 1, .5, 1, .5, 1 ], # Gra
|
|
[ 1, .5, .5, 1, 2, .5, 1, 1, 2, 2, 1, 1, 1, 1, 2, 1, .5, 1 ], # Ice
|
|
[ 2, 1, 1, 1, 1, 2, 1, .5, 1, .5, .5, .5, 2, 0, 1, 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