-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathPlayerHooks.cs
More file actions
63 lines (58 loc) · 2.14 KB
/
Copy pathPlayerHooks.cs
File metadata and controls
63 lines (58 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TShockAPI;
using TShockAPI.DB;
using Terraria;
namespace RegionFlags
{
class PlayerHooks
{
private FlaggedRegionManager regionManager;
public PlayerHooks(FlaggedRegionManager region)
{
regionManager = region;
}
public void OnItemDrop(object sender, TShockAPI.GetDataHandlers.ItemDropEventArgs args)
{
var reg =
TShock.Regions.GetTopRegion(TShock.Regions.InAreaRegion((int)args.Position.X / 16, (int)args.Position.Y / 16));
if (reg != null)
{
var freg = regionManager.getRegion(reg.Name);
if (freg != null && freg.getFlags().Contains(Flags.NOITEM))
{
Main.item[args.ID].SetDefaults(0);
args.Handled = true;
}
}
}
public void OnDamage( object sender, TShockAPI.GetDataHandlers.PlayerDamageEventArgs args )
{
Region r = TShock.Regions.GetTopRegion(
TShock.Regions.InAreaRegion((int)Main.player[args.ID].position.X / 16, (int)Main.player[args.ID].position.Y / 16));
if( r != null )
{
FlaggedRegion reg = regionManager.getRegion(r.Name);
if (reg != null)
{
List<Flags> flags = reg.getFlags();
if( flags.Contains( Flags.HEALONDAMAGE ) )
{
int heal = 0;
int damage = Math.Max(args.Damage*(args.Critical ? 2 : 1) -
(int)(Math.Round(Main.player[args.ID].statDefense * .5)), 1);
var items = TShock.Utils.GetItemByIdOrName("heart");
while(heal < damage)
{
Utilities.GiveItem(items[0].name, (int)Main.player[args.ID].position.X, (int)Main.player[args.ID].position.Y, items[0].width,
items[0].height, items[0].type, 1, items[0].prefix, args.ID, Main.player[args.ID].velocity);
heal += 20;
}
}
}
}
}
}
}