Skip to content

Make Corrupted Sentries Enemies #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Uchu.StandardScripts/VentureExplorer/BrokenConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Uchu.StandardScripts.VentureExplorer
/// LUA Reference: l_ag_ship_player_shock_server.lua
/// </summary>
[ZoneSpecific(1000)]
[ZoneSpecific(1001)]
public class BrokenConsole : NativeScript
{
private const string ScriptName = "l_ag_ship_player_shock_server.lua";
Expand Down
38 changes: 38 additions & 0 deletions Uchu.StandardScripts/VentureExplorer/CorruptedSentry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Threading.Tasks;
using Uchu.World;
using Uchu.World.Scripting.Native;

namespace Uchu.StandardScripts.VentureExplorer
{
[ZoneSpecific(1001)]
public class CorruptedSentry : NativeScript
{
/// <summary>
/// Loads the script.
/// </summary>
public override Task LoadAsync()
{
foreach (var obj in Zone.Objects)
{
InitializeCorruptedSentry(obj);
}
Listen(Zone.OnObject, InitializeCorruptedSentry);

return Task.CompletedTask;
}

/// <summary>
/// Initializes the faction and enemies of the
/// corrupted sentry.
/// </summary>
/// <param name="obj">Corrupted sentry game object to initialize.</param>
private void InitializeCorruptedSentry(Object obj)
{
if (!(obj is GameObject gameObject)) return;
if (gameObject.Lot != 8433) return;
if (!gameObject.TryGetComponent<DestroyableComponent>(out var destroyableComponent)) return;
destroyableComponent.Factions = new[] {4};
destroyableComponent.Enemies = new[] {1};
}
}
}
2 changes: 2 additions & 0 deletions Uchu.World/Objects/Components/DestroyableComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ private void CollectObjectStats()
);

if (stats == default) return;
HasStats = true;

var rawHealth = stats.Life ?? 0;
var rawArmor = (int) (stats.Armor ?? 0);
Expand All @@ -341,6 +342,7 @@ private void CollectObjectStats()
private void CollectPlayerStats()
{
if (!(GameObject is Player)) return;
HasStats = true;

using var ctx = new UchuContext();

Expand Down
1 change: 0 additions & 1 deletion Uchu.World/Objects/GameObjects/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ public async Task LoadAsync(IRakConnection connection)
AddComponent<PossessableOccupantComponent>();

controllablePhysics.HasPosition = true;
stats.HasStats = true;

// Server Components
var inventoryManager = AddComponent<InventoryManagerComponent>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Uchu.World.Scripting.Native
{
[AttributeUsage(AttributeTargets.Class)]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class ZoneSpecificAttribute : Attribute
{
public readonly ZoneId ZoneId;
Expand Down
9 changes: 5 additions & 4 deletions Uchu.World/Scripting/Native/NativeScriptPack.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Uchu.Core;
using Uchu.World.Scripting.Native;

namespace Uchu.World.Scripting.Native
{
Expand Down Expand Up @@ -32,11 +34,10 @@ internal void ReadAssembly()
{
if (type.BaseType != typeof(NativeScript)) return;

var zoneSpecific = type.GetCustomAttribute<ZoneSpecificAttribute>();

if (zoneSpecific != null)
var zoneSpecific = type.GetCustomAttributes<ZoneSpecificAttribute>().ToArray();
if (zoneSpecific.Length > 0)
{
if (zoneSpecific.ZoneId != Zone.ZoneId) continue;
if (zoneSpecific.FirstOrDefault(zoneSpecificEntry => zoneSpecificEntry.ZoneId == Zone.ZoneId) == default) continue;
}

var instance = (NativeScript) Activator.CreateInstance(type);
Expand Down