wip: created models dir, made some adjustments

wip, healing via item is not working the way it's supposed to
This commit is contained in:
2025-09-09 12:35:03 -04:00
parent 30c0ef4bf4
commit bb6f6b8498
2 changed files with 33 additions and 11 deletions

View File

@@ -4,6 +4,7 @@ using TShockAPI;
using TShockAPI.Hooks;
using TerrariaApi.Server;
using TerrariaHealingPlugin.Mappings;
using TerrariaHealingPlugin.Models;
namespace TerrariaHealingPlugin;
@@ -17,7 +18,7 @@ public class HealingPlugin : TerrariaPlugin
private DateTime _lastHealCheck = DateTime.UtcNow;
private DateTime _lastBuffCheck = DateTime.UtcNow;
private List<Player> _players = new List<Player>();
private List<ServerPlayer> _players = new List<ServerPlayer>();
private HealingMappings _healingItemMappings = new HealingMappings();
private EquipMappings _equipMappings = new EquipMappings();
@@ -98,8 +99,9 @@ public class HealingPlugin : TerrariaPlugin
short slot = args.Slot;
short newStack = args.Stack;
short itemType = args.Type;
var isHealingItem = IsHealingItem(itemType);
var isItemConsumed = IsItemBeingConsumed(player, slot, newStack);
bool isHealingItem = IsHealingItem(itemType);
bool isItemConsumed = IsItemBeingConsumed(player, slot, newStack);
if (isHealingItem && isItemConsumed)
{
@@ -110,9 +112,9 @@ public class HealingPlugin : TerrariaPlugin
player.Heal(enhancedHeal);
player.SendSuccessMessage($"Enhanced healing! Restored {enhancedHeal} HP (x{multiplier} multiplier)");
args.Handled = true;
}
args.Handled = true;
}
private bool IsHealingItem(int itemType)
@@ -132,8 +134,27 @@ public class HealingPlugin : TerrariaPlugin
private bool IsItemBeingConsumed(TSPlayer player, int slot, short newStack)
{
var item = player.TPlayer.inventory[slot];
return item.stack > newStack;
Terraria.Item item = player.TPlayer.inventory[slot];
bool isMouse = slot != 58; // is slot 58 the mouse?
bool isNewStackLessThanOld = item.stack > newStack;
bool isUseAction = player.TPlayer.ConsumeItem(item.netID);
Console.WriteLine($"Is the slot the mouse slot?: {!isMouse}");
Console.WriteLine($"Is the new stack of items less than the item stack?: {isNewStackLessThanOld}");
Console.WriteLine($"Is the action consuming an item?: {isUseAction}");
// return isMouse && isNewStackLessThanOld && isUseAction;
if (isNewStackLessThanOld && isUseAction)
{
return true;
}
if (slot < 58 && isNewStackLessThanOld)
{
return true;
}
return false;
}
private void OnSendNetData(SendDataEventArgs args)
@@ -182,8 +203,9 @@ public class HealingPlugin : TerrariaPlugin
var player = TShock.Players[args.Who];
if (player != null)
{
_players.Add(new Player(player));
_players.Add(new ServerPlayer(player));
TShock.Log.Info($"Player {player.Name} joined with IP: {player.IP}");
player.SendSuccessMessage($"Welcome {player.Name} to Sneefaria! Enjoy the regen buff!", Colors.RarityOrange);
}
}
}