Skip to content

Instantly share code, notes, and snippets.

@tiniodfluflu
Created October 20, 2013 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tiniodfluflu/7065877 to your computer and use it in GitHub Desktop.
Save tiniodfluflu/7065877 to your computer and use it in GitHub Desktop.
class ThermInfraCostPlugin < Plugin
# return a help string when the bot is asked for help on this plugin
def help(plugin, topic="")
return "infracost <infra> <amount> <resources> => returns cost to purchase <amount> infra starting at <infra> with resources <resources>. Assumes you have factories and construction."
end
# tells you cost of <amount> infra starting at <infra>
def privmsg(m)
# m.params contains the rest of the message, m.plugin contains the first
# word (useful because it's possible to register for multiple commands)
unless(m.params)
m.reply "incorrect usage. " + help(m.plugin)
end
words = m.params.scan(/\w+/)
cost = infracosth(words[0],words[1],words[2..words.length])
m.reply "cost is #{cost}"
end
def infracosth(start,amount,resources)
input = [start,amount]
input[0] = input[0].to_i
input[1] = input[1].to_i
const = [12,15,20,25,30,40,60,70,80]
cost = 0
inframult = 0
buyamount = 0
currentinfra = input[0];
while(currentinfra<input[0]+input[1])
if(currentinfra < 100)
inframult = const[0]
elsif (currentinfra < 200)
inframult = const[1]
elsif (currentinfra < 1000)
inframult = const[2]
elsif (currentinfra < 3000)
inframult = const[3]
elsif (currentinfra < 4000)
inframult = const[4]
elsif (currentinfra < 5000)
inframult = const[5]
elsif (currentinfra < 8000)
inframult = const[6]
elsif (currentinfra < 15000)
inframult = const[7]
else
inframult = const[8]
end
buyamount = 99 - currentinfra%100
if (buyamount == 0)
buyamount = 100
end
resourcemods = resourcemod(resources)
cost += buyamount * (inframult * currentinfra + 100) * resourcemods
currentinfra += buyamount
end
return cost
end
def resourcemod(resources)
mod = 0.6 * 0.94 * 0.95 * 0.93 * 0.90 * 0.95
for i in 0..resources.length
if (resources[i] == "sdc" || resources[i] == "SDC")
mod *= 0.8333333333
elsif (resources[i] == "rubber" || resources[i] == "RUBBER")
mod *= 0.97
elsif (resources[i] == "coal" || resources[i] == "COAL")
mod *= 0.96*0.98
elsif (resources[i] == "gov" || resources[i] == "govt" || resources[i] == "GOV" || resources[i] == "GOVT" )
mod *= 0.95
elsif (resources[i] == "iss" || resources[i] == "ISS")
mod *= 0.92
end
end
return mod
end
end
plugin = ThermInfraCostPlugin.new
plugin.register("infracost")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment