Skip to content

Instantly share code, notes, and snippets.

@YellowAfterlife
Last active February 15, 2016 00:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YellowAfterlife/1edaa4060191823ee366 to your computer and use it in GitHub Desktop.
Save YellowAfterlife/1edaa4060191823ee366 to your computer and use it in GitHub Desktop.
A TerraPatcher plugin for tweaking item stats.
using System;
using System.Collections.Generic;
using PluginLoader;
using Terraria;
/// Updated July 24, 2015
/// Updates: https://gist.github.com/YellowAfterlife/1edaa4060191823ee366
namespace YellowAfterlifePlugins {
/// Item modification rules are defined as following:
/// [item3507]
/// name=Copper Sword Plus
/// damage=20
/// A list of possible fields can be seen below.
/// "string" is text
/// "float" is any number
/// "int" is "rounded" number (1,2,3,...)
/// "bool" is toggle ("true"/"false")
public class ItemConfRule {
public string name;
//
/// aka "auto-swing" for weapons
public bool? autoReuse;
public int? damage;
public float? knockback;
public int? crit;
public int? defense;
/// item "use time"/cooldown, in frames
public int? useTime;
/// secondary use time (used by weapons with two attacks)
public int? useTime2;
//
public int? holdStyle;
public int? useStyle;
//
public int? maxStack;
/// size (1.0 is normal)
public float? scale;
public string toolTip;
public string toolTip2;
public ItemConfRule() { }
}
public class ItemConf : IPluginItemSetDefaults {
Dictionary<int, ItemConfRule> rules;
const string confPath = "plugins/ItemConf.ini";
const int confSize = 255;
private string loadString(string section, string field) {
string s = IniAPI.ReadIni(section, field, "", confSize, confPath);
return s != "" ? s : null;
}
private int? loadInt(string section, string field) {
string s = IniAPI.ReadIni(section, field, "", confSize, confPath);
if (s != "") {
return int.Parse(s);
} else return null;
}
private float? loadFloat(string section, string field) {
string s = IniAPI.ReadIni(section, field, "", confSize, confPath);
if (s != "") {
return float.Parse(s);
} else return null;
}
private bool? loadBool(string section, string field) {
string s = IniAPI.ReadIni(section, field, "", confSize, confPath);
if (s != "") {
s = s.ToLower();
return (s == "1" || s == "true" || s == "yes");
} else return null;
}
public ItemConf() {
rules = new Dictionary<int, ItemConfRule>();
IniAPI.ReadIni("header", "hint",
"Add rules below; See ItemConf.cs for instructions.",
255, confPath, true);
foreach (string section in IniAPI.GetIniSections(confPath)) {
if (section.ToLower().StartsWith("item")) {
int id = int.Parse(section.Substring(4));
ItemConfRule r = new ItemConfRule();
//
r.name = loadString(section, "name");
r.autoReuse = loadBool(section, "autoReuse");
r.damage = loadInt(section, "damage");
r.knockback = loadFloat(section, "knockback");
r.crit = loadInt(section, "crit");
r.defense = loadInt(section, "defense");
r.useTime = loadInt(section, "useTime");
r.useTime2 = loadInt(section, "useTime2");
//
r.holdStyle = loadInt(section, "holdStyle");
r.useStyle = loadInt(section, "useStyle");
//
r.maxStack = loadInt(section, "maxStack");
r.scale = loadFloat(section, "scale");
r.toolTip = loadString(section, "toolTip");
r.toolTip2 = loadString(section, "toolTip2");
//
rules[id] = r;
}
}
}
public void OnItemSetDefaults(Item item) {
if (rules.ContainsKey(item.type)) {
ItemConfRule r = rules[item.type];
if (r.name != null) item.name = r.name;
if (r.autoReuse != null) item.autoReuse = (bool)r.autoReuse;
if (r.damage != null) item.damage = (int)r.damage;
if (r.knockback != null) item.knockBack = (float)r.knockback;
if (r.crit != null) item.crit = (int)r.crit - 4;
if (r.defense != null) item.defense = (int)r.defense;
if (r.useTime != null) item.useAnimation = (int)r.useTime;
if (r.useTime2 != null) item.useTime = (int)r.useTime2;
//
if (r.holdStyle != null) item.holdStyle = (int)r.holdStyle;
if (r.useStyle != null) item.useStyle = (int)r.useStyle;
//
if (r.maxStack != null) item.maxStack = (int)r.maxStack;
if (r.scale != null) item.scale = (float)r.scale;
if (r.toolTip != null) item.toolTip = r.toolTip;
if (r.toolTip2 != null) item.toolTip2 = r.toolTip2;
}
}
}
}
@Meowordie
Copy link

How to use?

@Meowordie
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment