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:
@@ -4,6 +4,7 @@ using TShockAPI;
|
|||||||
using TShockAPI.Hooks;
|
using TShockAPI.Hooks;
|
||||||
using TerrariaApi.Server;
|
using TerrariaApi.Server;
|
||||||
using TerrariaHealingPlugin.Mappings;
|
using TerrariaHealingPlugin.Mappings;
|
||||||
|
using TerrariaHealingPlugin.Models;
|
||||||
|
|
||||||
namespace TerrariaHealingPlugin;
|
namespace TerrariaHealingPlugin;
|
||||||
|
|
||||||
@@ -17,7 +18,7 @@ public class HealingPlugin : TerrariaPlugin
|
|||||||
|
|
||||||
private DateTime _lastHealCheck = DateTime.UtcNow;
|
private DateTime _lastHealCheck = DateTime.UtcNow;
|
||||||
private DateTime _lastBuffCheck = 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 HealingMappings _healingItemMappings = new HealingMappings();
|
||||||
private EquipMappings _equipMappings = new EquipMappings();
|
private EquipMappings _equipMappings = new EquipMappings();
|
||||||
@@ -98,8 +99,9 @@ public class HealingPlugin : TerrariaPlugin
|
|||||||
short slot = args.Slot;
|
short slot = args.Slot;
|
||||||
short newStack = args.Stack;
|
short newStack = args.Stack;
|
||||||
short itemType = args.Type;
|
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)
|
if (isHealingItem && isItemConsumed)
|
||||||
{
|
{
|
||||||
@@ -110,9 +112,9 @@ public class HealingPlugin : TerrariaPlugin
|
|||||||
|
|
||||||
player.Heal(enhancedHeal);
|
player.Heal(enhancedHeal);
|
||||||
player.SendSuccessMessage($"Enhanced healing! Restored {enhancedHeal} HP (x{multiplier} multiplier)");
|
player.SendSuccessMessage($"Enhanced healing! Restored {enhancedHeal} HP (x{multiplier} multiplier)");
|
||||||
|
|
||||||
args.Handled = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
args.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsHealingItem(int itemType)
|
private bool IsHealingItem(int itemType)
|
||||||
@@ -132,8 +134,27 @@ public class HealingPlugin : TerrariaPlugin
|
|||||||
|
|
||||||
private bool IsItemBeingConsumed(TSPlayer player, int slot, short newStack)
|
private bool IsItemBeingConsumed(TSPlayer player, int slot, short newStack)
|
||||||
{
|
{
|
||||||
var item = player.TPlayer.inventory[slot];
|
Terraria.Item item = player.TPlayer.inventory[slot];
|
||||||
return item.stack > newStack;
|
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)
|
private void OnSendNetData(SendDataEventArgs args)
|
||||||
@@ -182,8 +203,9 @@ public class HealingPlugin : TerrariaPlugin
|
|||||||
var player = TShock.Players[args.Who];
|
var player = TShock.Players[args.Who];
|
||||||
if (player != null)
|
if (player != null)
|
||||||
{
|
{
|
||||||
_players.Add(new Player(player));
|
_players.Add(new ServerPlayer(player));
|
||||||
TShock.Log.Info($"Player {player.Name} joined with IP: {player.IP}");
|
TShock.Log.Info($"Player {player.Name} joined with IP: {player.IP}");
|
||||||
|
player.SendSuccessMessage($"Welcome {player.Name} to Sneefaria! Enjoy the regen buff!", Colors.RarityOrange);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,15 +1,15 @@
|
|||||||
using Terraria.ID;
|
using Terraria.ID;
|
||||||
using TShockAPI;
|
using TShockAPI;
|
||||||
|
|
||||||
namespace TerrariaHealingPlugin
|
namespace TerrariaHealingPlugin.Models
|
||||||
{
|
{
|
||||||
public class Player
|
public class ServerPlayer
|
||||||
{
|
{
|
||||||
public TSPlayer player { get; set; }
|
public TSPlayer player { get; set; }
|
||||||
public int healAmount { get; set; } = 0;
|
public int healAmount { get; set; } = 0;
|
||||||
public int healItem { get; set; } = ItemID.None;
|
public int healItem { get; set; } = ItemID.None;
|
||||||
|
|
||||||
public Player(TSPlayer player)
|
public ServerPlayer(TSPlayer player)
|
||||||
{
|
{
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
Reference in New Issue
Block a user