-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomEnergyModProjectile.cs
More file actions
92 lines (80 loc) · 3.24 KB
/
Copy pathCustomEnergyModProjectile.cs
File metadata and controls
92 lines (80 loc) · 3.24 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
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using CoreLib;
using CoreLib.Components;
using Il2CppInterop.Runtime.InteropTypes.Fields;
using PugRP;
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;
namespace PainMod
{
public class CustomEnergyModProjectile : ModProjectile
{
public Il2CppReferenceField<Transform> directionTransform;
public Il2CppReferenceField<ParticleSystem> projectileFx;
public Il2CppReferenceField<ParticleSystem> fireballSmoke;
public Il2CppReferenceField<ParticleSystem> fireballFireTrail;
public Il2CppReferenceField<ParticleSystem> hit;
public Il2CppReferenceField<ManagedLight> fireLight;
private GCHandle tilesToCheckHandle;
private GCHandle alreadyHitEntitiesHandle;
public CustomEnergyModProjectile(IntPtr ptr) : base(ptr) { }
public override void OnOccupied()
{
this.CallBase<Projectile>(nameof(OnOccupied));
int health = currentHealth;
tilesToCheck = new Il2CppSystem.Collections.Generic.HashSet<int2>();
directionTransform.Value.gameObject.SetActive(health > 0);
if (health <= 0) return;
AudioManager.Sfx(SfxID.fireball, transform.position, 0.8f, 1, 0.1f);
AudioManager.Sfx(SfxID.anicentDevicePowerUp, transform.position, 0.6f, 0.7f, 0.1f);
ProjectileCD projectileCd = EntityUtility.GetComponentData<ProjectileCD>(entity, world);
Vector3 dir = projectileCd.direction * 0.3f;
Vector3 renderPos = ToRenderFromWorld(WorldPosition);
Vector3 puffPos = renderPos + directionTransform.Value.localPosition + dir;
Manager.effects.PlayPuff(PuffID.SmallFireExplosion, puffPos);
dir = directionTransform.Value.position + (Vector3)projectileCd.direction;
directionTransform.Value.transform.LookAt(dir, Vector3.up);
projectileFx.Value.Play();
if (fireballSmoke.Value != null)
fireballSmoke.Value.Play();
if (fireballFireTrail.Value != null)
fireballFireTrail.Value.Play();
fireLight.Value.gameObject.SetActive(true);
}
public override void OnDeath()
{
this.CallBase<Projectile>(nameof(OnDeath));
if (projectileFx.Value != null && hit.Value != null)
{
projectileFx.Value.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
if (fireballSmoke.Value != null)
fireballSmoke.Value.Stop();
if (fireballFireTrail.Value != null)
fireballFireTrail.Value.Stop();
hit.Value.Play();
}
fireLight.Value.gameObject.SetActive(false);
SpawnFadeOutLight(fireLight.Value.lightToOptimize);
}
public override bool Allocate()
{
bool shouldAlloc = base.Allocate();
if (shouldAlloc)
{
tilesToCheckHandle = GCHandle.Alloc(tilesToCheck);
_alreadyHitEntities ??= new Il2CppSystem.Collections.Generic.List<Entity>();
alreadyHitEntitiesHandle = GCHandle.Alloc(_alreadyHitEntities);
}
return base.Allocate();
}
public override void OnDestroy()
{
base.OnDestroy();
tilesToCheckHandle.Free();
alreadyHitEntitiesHandle.Free();
}
}
}