-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackableBuff.cs
More file actions
128 lines (106 loc) · 3.97 KB
/
Copy pathStackableBuff.cs
File metadata and controls
128 lines (106 loc) · 3.97 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RandomBuff.Core.Buff;
using RandomBuffUtils;
using RWCustom;
using UnityEngine;
namespace BuffTemplate.Buffs
{
internal class StackableBuffData : BuffData
{
public override BuffID ID => BuffEnums.StackableBuff;
}
internal class StackableBuff : Buff<StackableBuff,StackableBuffData>
{
public override BuffID ID => BuffEnums.StackableBuff;
public StackableBuff()
{
if (BuffCustom.TryGetGame(out var game))
{
foreach (var player in game.Players.Select(i => i.realizedCreature as Player))
{
if(player == null || player.room == null)
continue;
player.room.AddObject(new SimpleShield(player.room, player, Data.StackLayer));
}
}
}
}
internal class StackableBuffHook
{
public static void HookOn()
{
On.Player.NewRoom += Player_NewRoom;
}
private static void Player_NewRoom(On.Player.orig_NewRoom orig, Player self, Room newRoom)
{
orig(self, newRoom);
newRoom.AddObject(new SimpleShield(newRoom, self, StackableBuff.Instance.Data.StackLayer));
}
}
internal class SimpleShield : CosmeticSprite
{
public SimpleShield(Room room,Player player, int stackLayer)
{
this.room = room;
this.player = player;
this.stackLayer = stackLayer + 2;
}
public override void InitiateSprites(RoomCamera.SpriteLeaser sLeaser, RoomCamera rCam)
{
FContainer shieldContainer = new FContainer();
for (int i = 0; i < stackLayer; i++)
{
FSprite sprite = new FSprite("Futile_White");
sprite.scale = 0.5f;
sprite.SetPosition(Custom.DegToVec(i * 360f / stackLayer) * 70);
shieldContainer.AddChild(sprite);
}
sLeaser.sprites = Array.Empty<FSprite>();
sLeaser.containers = new[] { shieldContainer };
AddToContainer(sLeaser, rCam, null);
}
public override void AddToContainer(RoomCamera.SpriteLeaser sLeaser, RoomCamera rCam, FContainer newContatiner)
{
if (newContatiner == null)
newContatiner = rCam.ReturnFContainer("Foreground");
newContatiner.AddChild(sLeaser.containers[0]);
}
public override void DrawSprites(RoomCamera.SpriteLeaser sLeaser, RoomCamera rCam, float timeStacker, Vector2 camPos)
{
base.DrawSprites(sLeaser, rCam, timeStacker, camPos);
sLeaser.containers[0].SetPosition(Vector2.Lerp(lastPos, pos, timeStacker) - camPos);
sLeaser.containers[0].rotation = Mathf.Lerp(lastRotation, rotation, timeStacker);
}
public override void Update(bool eu)
{
base.Update(eu);
pos = player.mainBodyChunk.pos;
lastPos = player.mainBodyChunk.lastPos;
lastRotation = rotation;
rotation += 0.25f * 360 / 40;
foreach (var crit in room.updateList.OfType<Creature>())
{
if(crit is Player) continue;
for (int i = 0; i < stackLayer; i++)
{
if (crit.bodyChunks.Any(chunk =>
Custom.DistLess(chunk.pos, pos + Custom.DegToVec((i * 360f / stackLayer) + rotation) * 70, 12)))
{
crit.Stun(50);
break;
}
}
}
if(StackableBuff.Instance == null || player.room != room)
Destroy();
}
private readonly Player player;
private readonly int stackLayer;
private float lastRotation;
private float rotation;
}
}