Skip to content

Commit

Permalink
buffs can now be set to >100 days in length
Browse files Browse the repository at this point in the history
  • Loading branch information
nymda committed Oct 24, 2020
1 parent 437c8c5 commit 76e2582
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 17 deletions.
20 changes: 16 additions & 4 deletions WinTerrEdit/entry.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion WinTerrEdit/entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ public void loadData(string path)
extCounter = 0;
}
}
nudDur.Value = playerBuffs[0].duration;
}

//buff data has been found
Expand Down Expand Up @@ -603,6 +604,7 @@ private void btnLoad_Click(object sender, EventArgs e)
gbItems.Enabled = true;
gbBuffs.Enabled = true;
btnReload.Enabled = true;
updateInvDisplay();
}
catch(Exception ex)
{
Expand Down Expand Up @@ -842,7 +844,6 @@ private void item_Click(object sender, EventArgs e)
nudDur.Value = playerBuffs[invSelectedIndex].duration;
cbBuffs.SelectedItem = playerBuffs[invSelectedIndex].buff.name;
gb_slot_buff.Text = "Buff slot " + (invSelectedIndex + 1);
playerBuffs[invSelectedIndex].duration = (int)nudDur.Value;
break;

}
Expand Down
39 changes: 27 additions & 12 deletions WinTerrEdit/itemHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,31 @@ public int resolveEncodedData(int b1, int b2)
{
return b1 + (256 * b2);
}
public int resolveBuff(int b1, int b2, int b3)
{
List<byte> bytes = new List<byte> { (byte)b1, (byte)b2, (byte)b3, 0x00 };
return BitConverter.ToInt32(bytes.ToArray(), 0);
}
public List<int> encodeData(int inp)
{
if(inp >= 0)
{
return new List<int> { inp % 256, inp / 256 };
}
else
{
return new List<int> { 0, 0 };
}
byte[] tmp = BitConverter.GetBytes(inp);
return new List<int> { tmp[0], tmp[1] };

//if (inp >= 0)
//{
// return new List<int> { inp % 256, inp / 256 };
//}
//else
//{
// return new List<int> { 0, 0 };
//}

}
public List<int> encodeBuffs(int inp)
{
byte[] tmp = BitConverter.GetBytes(inp);
return new List<int> { tmp[0], tmp[1], tmp[2] };
}
public baseItem searchItemByID(int id)
{
var res = globalTerrariaItems.Where(baseItem => baseItem.ID == id);
Expand Down Expand Up @@ -142,23 +155,26 @@ public playerBuff(List<int> terrData, itemHandler handler)
{
int id = handler.resolveEncodedData(terrData[0], terrData[1]);
buff = handler.searchBuffById(id);
duration = handler.resolveEncodedData(terrData[4], terrData[5]);
duration = handler.resolveBuff(terrData[4], terrData[5], terrData[6]);
duration = duration / 60;
Console.WriteLine("LOADED DURATION: " + duration);
}

//returns the inventory item as a set of 10 bytes for reinserting into raw data
public List<Byte> recompile(itemHandler handler)
{
List<Byte> final = new List<Byte> { };
List<int> encodedItem = handler.encodeData(buff.ID);
List<int> encodedDuration = handler.encodeData(duration);
List<int> encodedDuration = handler.encodeBuffs(duration * 60);
Console.WriteLine("SAVED DURATION: " + duration * 60);
//bytes 2, 3, 6, 7 and 9 seem to make the item dissapear if they are anything other than 0x00
final.Add((byte)encodedItem[0]);
final.Add((byte)encodedItem[1]);
final.Add(0x00);
final.Add(0x00);
final.Add((byte)encodedDuration[0]);
final.Add((byte)encodedDuration[1]);
final.Add(0x00);
final.Add((byte)encodedDuration[2]);
final.Add(0x00);
return final;
}
Expand All @@ -173,7 +189,6 @@ public class baseItem
public baseItem(string[] insertion)
{
//loads item data from array
Console.WriteLine(insertion[0]);
this.ID = Int32.Parse(insertion[0]);
this.name = insertion[1];
this.name_internal = insertion[2];
Expand Down

0 comments on commit 76e2582

Please sign in to comment.