Skip to content

Instantly share code, notes, and snippets.

@abner-math
Last active November 23, 2023 23:17
Show Gist options
  • Save abner-math/1f3dfe2b6684f3208d03890413ca27de to your computer and use it in GitHub Desktop.
Save abner-math/1f3dfe2b6684f3208d03890413ca27de to your computer and use it in GitHub Desktop.
ninpou2_simulator
from enum import Enum
# DOTA Constraints
MAX_LEVEL = 50
HP_PER_TAI = 22.0
CHAKRA_PER_GEN = 12
STARTING_MAGIC_RESIST = 0.25
MAGIC_RESIST_PER_GEN = 0.001
XP_REQUIRED = [0, 0]
for i in range(1, MAX_LEVEL):
XP_REQUIRED.append(XP_REQUIRED[i - 1] + i * 75)
class Item:
def __init__(self, tai=0, nin=0, gen=0, hp=0, chakra=0, magicResist=0, damageAmplifier=0):
self.tai = tai
self.nin = nin
self.gen = gen
self.hp = hp
self.chakra = chakra
self.magicResist = magicResist
self.damageAmplifier = damageAmplifier
# Items
SANNIN_ARMOR = Item(tai=25, nin=25, gen=25, magicResist=0.25)
KAGE_ARMOR = Item(tai=50, nin=50, gen=50, magicResist=0.5)
RIKUUDOU_MIRROR = Item(tai=30, nin=30, gen=30, magicResist=0.1)
LEGENDARY_KUNAI = Item(tai=100, chakra=1500, damageAmplifier=0.2)
LEGENDARY_SHURIKEN = Item(nin=100, hp=1500, damageAmplifier=0.2)
LEGENDARY_SENBONS = Item(gen=100, hp=1500, damageAmplifier=0.2)
class SkillType(Enum):
FARMING = 0
BASIC = 1
UTILITY = 2
SEMI = 3
ULTIMATE = 4
class Hero:
def __init__(self, tai, nin, gen, taiLvl, ninLvl, genLvl, lvl):
self.tai = tai
self.nin = nin
self.gen = gen
self.taiLvl = taiLvl
self.ninLvl = ninLvl
self.genLvl = genLvl
self.lvl = 1
self.xp = 0
self.hp = tai * HP_PER_TAI
self.chakra = gen * CHAKRA_PER_GEN
self.magicResist = STARTING_MAGIC_RESIST + gen * MAGIC_RESIST_PER_GEN
self.magicResistModifiers = {}
self.damageAmplifier = 0
self.skillLvls = {SkillType.FARMING: 0, SkillType.BASIC: 0, SkillType.UTILITY: 0, SkillType.SEMI: 0, SkillType.ULTIMATE: 0}
self.lvlUp(lvl)
self.currentHp = self.hp
self.currentChakra = self.chakra
def lvlUp(self, count=1):
for i in range(count):
if self.lvl == MAX_LEVEL:
return
self.tai += self.taiLvl
self.nin += self.ninLvl
self.gen += self.genLvl
self.hp += self.taiLvl * HP_PER_TAI
self.chakra += self.genLvl * CHAKRA_PER_GEN
self.magicResist += self.genLvl * MAGIC_RESIST_PER_GEN
self.xp += XP_REQUIRED[self.lvl + 1]
self.lvl += 1
if self.lvl == 10 or self.lvl == 15:
self.skillLvls[SkillType.SEMI] += 1
elif self.lvl == 35:
self.skillLvls[SkillType.ULTIMATE] += 1
if self.lvl % 2 == 1 and self.skillLvls[SkillType.FARMING] < 10:
self.skillLvls[SkillType.FARMING] += 1
elif self.lvl % 2 == 0 and self.skillLvls[SkillType.BASIC] < 10:
self.skillLvls[SkillType.BASIC] += 1
elif self.skillLvls[SkillType.UTILITY] < 10:
self.skillLvls[SkillType.UTILITY] += 1
def getFinalMagicResist(self):
damageMultiplier = (1 - self.magicResist)
modifiers = 1
for modifier in self.magicResistModifiers.values():
modifiers *= (1 - modifier)
return 1 - (damageMultiplier * modifiers)
def takeDmg(self, amount):
self.currentHp -= amount * (1 - self.magicResist)
if self.currentHp < 0:
self.currentHp = 0
def chakraCost(self, skillType):
lvl = self.skillLvls[skillType]
if skillType == SkillType.FARMING:
return 40 + 20 * lvl
elif skillType == SkillType.BASIC:
return 20 + 20 * lvl
elif skillType == SkillType.UTILITY:
return 100
elif skillType == SkillType.SEMI:
return 400 - 100 * lvl
elif skillType == SkillType.ULTIMATE:
return 500
def useSkill(self, hero, skillType):
hero.takeDmg(self.skillDamage(skillType) * (1 + self.damageAmplifier))
self.currentChakra -= self.chakraCost(skillType)
def equip(self, item):
self.tai += item.tai
self.nin += item.nin
self.gen += item.gen
self.hp += item.hp
self.chakra += item.chakra
if item.magicResist > 0:
self.magicResistModifiers[item] = item.magicResist
def unequip(self, item):
self.tai -= item.tai
self.nin -= item.nin
self.gen -= item.gen
self.hp -= item.hp
self.chakra -= item.chakra
if item.magicResist > 0:
del self.magicResistModifiers[item]
def reset(self):
self.currentHp = self.hp
self.currentChakra = self.chakra
def __str__(self):
return '{ hp: %d/%d chakra: %d/%d tai: %d nin: %d gen: %d resist: %.2f }' % (self.currentHp, self.hp, self.currentChakra, self.chakra, self.tai, self.nin, self.gen, self.getFinalMagicResist())
class TaijutsuHero(Hero):
def __init__(self, lvl=1):
super().__init__(tai=24, nin=20, gen=14, taiLvl=3.3, ninLvl=2.4, genLvl=1.5, lvl=lvl)
def skillDamage(self, skillType):
lvl = self.skillLvls[skillType]
if skillType == SkillType.FARMING:
return 80 * lvl
elif skillType == SkillType.BASIC:
return self.tai * lvl
elif skillType == SkillType.SEMI:
return (600 + 2.5 * self.tai) * lvl
elif skillType == SkillType.ULTIMATE:
return 12 * self.tai
return 0
class NinjutsuHero(Hero):
def __init__(self, lvl=1):
super().__init__(tai=20, nin=24, gen=14, taiLvl=2.4, ninLvl=3.3, genLvl=1.5, lvl=lvl)
def skillDamage(self, skillType):
lvl = self.skillLvls[skillType]
if skillType == SkillType.FARMING:
return 80 * lvl
elif skillType == SkillType.BASIC:
return self.nin * lvl
elif skillType == SkillType.SEMI:
return (800 + 3.0 * self.nin) * lvl
elif skillType == SkillType.ULTIMATE:
return 15 * self.nin
return 0
class GenjutsuHero(Hero):
def __init__(self, lvl=1):
super().__init__(tai=14, nin=20, gen=24, taiLvl=1.5, ninLvl=2.4, genLvl=3.3, lvl=lvl)
def skillDamage(self, skillType):
lvl = self.skillLvls[skillType]
if skillType == SkillType.FARMING:
return 80 * lvl
elif skillType == SkillType.BASIC:
return self.gen * lvl
elif skillType == SkillType.SEMI:
return (600 + 5.0 * self.gen) * lvl
elif skillType == SkillType.ULTIMATE:
return 13 * self.gen
return 0
hero1 = TaijutsuHero(50)
hero2 = NinjutsuHero(50)
hero2.equip(KAGE_ARMOR)
hero1.useSkill(hero2, SkillType.BASIC)
print(hero1)
print(hero2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment