Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Usage:
# 1. Google Spread Sheet を開く
# https://docs.google.com/spreadsheets/d/1EKw-FI-zB_dPnIH-HM0OwlLwVkHluVlrGRyKIKtVMwg/edit?usp=sharing
# 2. Hero シートをコピーして hero.tsv に貼り付ける
# (TSV: Tab Separated Volume で)
# 3. Item シートをコピーして item.tsv に貼り付ける
# 4. Ability シートをコピーして ability.tsv に貼り付ける
# 5. TSV ファイルとこのスクリプトを同じフォルダに置いて python mkscript.py
# 6. stdout にスクリプトが表示されるのでコピペしてスプレッドシートの
# スクリプトエディタにペースト
#
import sys
import csv
import json
heroTSV = "hero.tsv"
itemTSV = "item.tsv"
abilityTSV = "ability.tsv"
def tsvtoarray(filename):
f = open(filename)
r = csv.reader(f, delimiter="\t")
rv = [ row for row in r ]
f.close()
return rv
def num(s):
if not s:
return 0.0
return float(s)
def parseHeroTSV(key):
offset = 1
width = 2
if key == "health":
offset = 1
elif key == "energy":
offset = 3
elif key == "armor":
offset = 5
elif key == "shield":
offset = 7
elif key == "weapon":
offset = 9
elif key == "weapon_crystal":
offset = 11
elif key == "weapon_crystal_ratio":
offset = 13
width = 1
elif key == "damage_ratio":
offset = 14
width = 1
elif key == "attack_speed":
offset = 15
elif key == "attack_cooldown":
offset = 17
width = 1
elif key == "attack_delay":
offset = 18
width = 1
elif key == "no_stutter":
offset = 19
width = 1
elif key == "spped_modifier":
offset = 20
width = 1
elif key == "move_speed":
offset = 22
width = 1
data = {}
for row in tsvtoarray(heroTSV)[1:]:
hero = row[0]
if width == 1:
data[hero] = float(row[offset])
else:
data[hero] = {
"min": float(row[offset]),
"max": float(row[offset + 1]),
}
return data
def mkHeroFunc1(funcname, key):
print """function %s(name, level) {
var data = %s;
return data[name];
}
""" % (funcname, parseHeroTSV(key))
def mkHeroFunc2(funcname, key):
print """function %s(name, level) {
var data = %s;
var hero = data[name];
var min = hero.min;
var max = hero.max;
var increase = (max - min) / 11;
return min + Math.round(increase * (level - 1));
}
""" % (funcname, parseHeroTSV(key))
def hero():
mkHeroFunc2("heroHealth", "health")
mkHeroFunc2("heroEnergy", "energy")
mkHeroFunc2("heroArmor", "armor")
mkHeroFunc2("heroShield", "shield")
mkHeroFunc2("heroWeaponDamage", "weapon")
mkHeroFunc2("heroCrystalDamage", "weapon_crystal")
mkHeroFunc1("heroCrystalRatio", "weapon_crystal_ratio")
mkHeroFunc1("heroDamageRatio", "damage_ratio")
mkHeroFunc2("heroAttackSpeed", "attack_speed")
mkHeroFunc1("heroAttackCooldown", "attack_cooldown")
mkHeroFunc1("heroAttackDelay", "attack_delay")
mkHeroFunc1("noStutterStepPenalty", "no_stutter")
mkHeroFunc1("attackSpeedModifier", "spped_modifier")
mkHeroFunc1("heroMoveSpeed", "move_speed")
def item():
data = {}
for row in tsvtoarray(itemTSV)[1:]:
name = row[0]
datum = {
"Price": num(row[2]),
"Weapon Power": num(row[3]),
"Attack Speed": num(row[4]),
"Critical Chance": num(row[5]),
"Critical Damage": num(row[6]),
"Armor Pierce": num(row[8]),
"Crystal Power": num(row[9]),
"Max Energy": num(row[10]),
"Energy Recharge": num(row[11]),
"Cooldown Speed": num(row[12]),
"Shield Pierce": num(row[13]),
"Max Health": num(row[15]),
"Shield": num(row[16]),
"Armor": num(row[17]),
"Move Speed": num(row[18]),
"Bonus Damage": num(row[19]),
}
data[name] = datum
data = json.dumps(data)
print """
function sumItems(items, stacks, key) {
var data = %s;
var rv = 0;
for (var i = 0; i < items.length; ++i) {
var name = items[i];
if (name) {
var stack = stacks[i] || 0;
switch (key) {
case 'Crystal Power Gain':
if (name == 'Clockwark') {
rv += 30;
}
break;
case 'Crystal Damage Gain':
if (name == 'Broken Myth') {
rv += Math.min(stack, 5) * 7;
}
break;
case 'Crystal Damage Ratio':
if (name == 'Alternating Current') {
rv += 70 / 2;
}
break;
case 'Armor Shred Ratio':
if (name == 'Bonesaw') {
rv += Math.min(stack, 8) * 6;
}
break;
case 'Weapon Burst Damage':
if (name == 'Tension Bow') {
rv += 180 / 6;
}
break;
default:
var datum = data[name];
if (datum) {
rv += datum[key];
if (name == 'Breaking Point' && key == 'weapon power') {
rv += Math.min(stack, 25) * 10;
}
}
break;
}
}
}
return rv;
}
""" % data
def ability():
data = {}
for row in tsvtoarray(abilityTSV)[2:]:
name = row[0]
typ = row[1]
if not data.has_key(name):
data[name] = { "A": [], "B": [], "C": [] }
datum = {
"Level": int(row[2]),
"Cooldown": num(row[3]),
"Charge": num(row[4]),
"Shield Pierce": num(row[5]),
"Armor Pierce": num(row[6]),
"Basic Attack Ratio": 0,
"Crystal Damage": [],
"Weapon Damage": [],
}
datum["Crystal Damage"].append({
"Damage": num(row[7]),
"Crystal Ratio": num(row[8]),
"Weapon Ratio": num(row[9]),
"Extra Damage Ratio": num(row[10]),
})
if row[11]:
datum["Crystal Damage"].append({
"Damage": num(row[11]),
"Crystal Ratio": num(row[12]),
"Weapon Ratio": num(row[13]),
"Extra Damage Ratio": num(row[14]),
})
if row[18]:
datum["Stack Damage"] = {
"Damage": num(row[15]),
"Crystal Ratio": num(row[16]),
"Weapon Ratio": num(row[17]),
"Max Stack": num(row[18]),
}
if row[19]:
datum["Basic Attack Ratio"] = num(row[19]) * num(row[20])
if row[21]:
datum["Weapon Damage"].append({
"Damage": num(row[21]),
"Crystal Ratio": num(row[22]),
"Weapon Ratio": num(row[23]),
})
if row[24]:
datum["Weapon Damage"].append({
"Damage": num(row[24]),
"Crystal Ratio": num(row[25]),
"Weapon Ratio": num(row[26]),
})
data[name][typ].append(datum)
data = json.dumps(data, indent=None)
print """
function sumAbility(key, name, typ, level, weapon, crystal, stack) {
if (level <= 0) {
return 0;
}
var data = %s;
var datum = data[name][typ][level-1];
switch (key) {
case "Crystal Power":
var power = 0;
for (var i = 0; i < datum["Crystal Damage"].length; ++i) {
var x = datum["Crystal Damage"][i];
var ex = 1 + x["Extra Damage Ratio"] / 100;
var p = (x["Damage"] +
(x["Crystal Ratio"] / 100) * crystal +
(x["Weapon Ratio"] / 100) * weapon) * ex;
power += p;
}
for (var i = 0; i < datum["Weapon Damage"].length; ++i) {
var x = datum["Weapon Damage"][i];
var p = (x["Crystal Ratio"] / 100) * crystal;
power += p;
}
var x = datum["Stack Damage"];
if (x) {
power += (x["Damage"] +
(x["Crystal Ratio"] / 100) * crystal +
(x["Weapon Ratio"] / 100) * weapon) * stack;
}
return power;
case "Weapon Power":
var power = 0;
for (var i = 0; i < datum["Weapon Damage"].length; ++i) {
var x = datum["Weapon Damage"][i];
var p = x["Damage"] + (x["Weapon Ratio"] / 100) * weapon;
power += p;
}
return power;
case "Cooldown":
case "Charge":
case "Shield Pierce":
case "Armor Pierce":
case "Basic Attack Ratio":
return datum[key];
}
}
""" % data
def main():
hero()
item()
ability()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment