Skip to content

Commit da224bd

Browse files
Merge pull request #213 from UchuServer/enhancement/corrupted-sentries
Make Corrupted Sentries Enemies
2 parents 35d3bc7 + e2da385 commit da224bd

File tree

6 files changed

+47
-6
lines changed

6 files changed

+47
-6
lines changed

Uchu.StandardScripts/VentureExplorer/BrokenConsole.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Uchu.StandardScripts.VentureExplorer
99
/// LUA Reference: l_ag_ship_player_shock_server.lua
1010
/// </summary>
1111
[ZoneSpecific(1000)]
12+
[ZoneSpecific(1001)]
1213
public class BrokenConsole : NativeScript
1314
{
1415
private const string ScriptName = "l_ag_ship_player_shock_server.lua";
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Threading.Tasks;
2+
using Uchu.World;
3+
using Uchu.World.Scripting.Native;
4+
5+
namespace Uchu.StandardScripts.VentureExplorer
6+
{
7+
[ZoneSpecific(1001)]
8+
public class CorruptedSentry : NativeScript
9+
{
10+
/// <summary>
11+
/// Loads the script.
12+
/// </summary>
13+
public override Task LoadAsync()
14+
{
15+
foreach (var obj in Zone.Objects)
16+
{
17+
InitializeCorruptedSentry(obj);
18+
}
19+
Listen(Zone.OnObject, InitializeCorruptedSentry);
20+
21+
return Task.CompletedTask;
22+
}
23+
24+
/// <summary>
25+
/// Initializes the faction and enemies of the
26+
/// corrupted sentry.
27+
/// </summary>
28+
/// <param name="obj">Corrupted sentry game object to initialize.</param>
29+
private void InitializeCorruptedSentry(Object obj)
30+
{
31+
if (!(obj is GameObject gameObject)) return;
32+
if (gameObject.Lot != 8433) return;
33+
if (!gameObject.TryGetComponent<DestroyableComponent>(out var destroyableComponent)) return;
34+
destroyableComponent.Factions = new[] {4};
35+
destroyableComponent.Enemies = new[] {1};
36+
}
37+
}
38+
}

Uchu.World/Objects/Components/DestroyableComponent.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ private void CollectObjectStats()
324324
);
325325

326326
if (stats == default) return;
327+
HasStats = true;
327328

328329
var rawHealth = stats.Life ?? 0;
329330
var rawArmor = (int) (stats.Armor ?? 0);
@@ -341,6 +342,7 @@ private void CollectObjectStats()
341342
private void CollectPlayerStats()
342343
{
343344
if (!(GameObject is Player)) return;
345+
HasStats = true;
344346

345347
using var ctx = new UchuContext();
346348

Uchu.World/Objects/GameObjects/Player.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ public async Task LoadAsync(IRakConnection connection)
164164
AddComponent<PossessableOccupantComponent>();
165165

166166
controllablePhysics.HasPosition = true;
167-
stats.HasStats = true;
168167

169168
// Server Components
170169
var inventoryManager = AddComponent<InventoryManagerComponent>();

Uchu.World/Scripting/Native/Attributes/ZoneSpecificAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Uchu.World.Scripting.Native
55
{
6-
[AttributeUsage(AttributeTargets.Class)]
6+
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
77
public class ZoneSpecificAttribute : Attribute
88
{
99
public readonly ZoneId ZoneId;

Uchu.World/Scripting/Native/NativeScriptPack.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.Linq;
45
using System.Reflection;
56
using System.Threading.Tasks;
67
using Uchu.Core;
8+
using Uchu.World.Scripting.Native;
79

810
namespace Uchu.World.Scripting.Native
911
{
@@ -32,11 +34,10 @@ internal void ReadAssembly()
3234
{
3335
if (type.BaseType != typeof(NativeScript)) return;
3436

35-
var zoneSpecific = type.GetCustomAttribute<ZoneSpecificAttribute>();
36-
37-
if (zoneSpecific != null)
37+
var zoneSpecific = type.GetCustomAttributes<ZoneSpecificAttribute>().ToArray();
38+
if (zoneSpecific.Length > 0)
3839
{
39-
if (zoneSpecific.ZoneId != Zone.ZoneId) continue;
40+
if (zoneSpecific.FirstOrDefault(zoneSpecificEntry => zoneSpecificEntry.ZoneId == Zone.ZoneId) == default) continue;
4041
}
4142

4243
var instance = (NativeScript) Activator.CreateInstance(type);

0 commit comments

Comments
 (0)