Skip to content
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

Add PoC of encounters, treat thumper as one #50

Merged
merged 2 commits into from
Sep 29, 2024
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 UdpHosts/GameServer/Entities/BaseEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public BaseEntity(IShard shard, ulong id)

public InteractionComponent Interaction { get; set; }
public ScopingComponent Scoping { get; set; }
public EncounterComponent Encounter { get; set; }

public virtual bool IsInteractable()
{
Expand Down
9 changes: 9 additions & 0 deletions UdpHosts/GameServer/Entities/EncounterComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using GameServer.Systems.Encounters;

namespace GameServer.Entities;

public class EncounterComponent
{
public ulong EncounterId { get; set; }
public IEncounter Instance { get; set; }
}
71 changes: 53 additions & 18 deletions UdpHosts/GameServer/Entities/Thumper/ThumperEntity.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using AeroMessages.Common;
using AeroMessages.GSS.V66;
using AeroMessages.GSS.V66.ResourceNode;
using AeroMessages.GSS.V66.ResourceNode.View;
using GameServer.Aptitude;
using GameServer.Data.SDB.Records.aptfs;
using GameServer.Entities.Character;
using GameServer.Enums;

namespace GameServer.Entities.Thumper;

public class ThumperEntity : BaseAptitudeEntity, IAptitudeTarget
{
public ThumperEntity(IShard shard, ulong eid, uint nodeType, uint beaconType)
public ThumperEntity(
IShard shard,
ulong eid,
uint nodeType,
Vector3 position,
BaseEntity owner,
ResourceNodeBeaconCalldownCommandDef commandDef)
: base(shard, eid)
{
AeroEntityId = new EntityId() { Backing = EntityId, ControllerId = Controller.ResourceNode };
NodeType = nodeType;
BeaconType = beaconType;
BeaconType = commandDef.ResourceNodeBeaconId;
Scoping = new ScopingComponent() { Global = true };
Position = position;
Owner = owner;
LandedAbility = commandDef.LandedAbility;
CompletedAbility = commandDef.CompletedAbility;
CalldownTimeMs = commandDef.CalldownTimeMs;
MaxHealth = (uint)commandDef.Health;
Interaction = new InteractionComponent()
{
Type = InteractionType.GenericHold,
CompletedAbilityId = CompletedAbility,
};
InitFields();
InitViews();
}
Expand All @@ -33,7 +49,7 @@ public ThumperEntity(IShard shard, ulong eid, uint nodeType, uint beaconType)

public uint NodeType { get; set; }
public uint BeaconType { get; set; }
public float Progress { get; set; } = 0.01f;
public float Progress { get; set; } = 0.00f;
public ThumpingCharacterInfoStruct ThumpingCharacterInfo { get; set; }
public StateInfoStruct StateInfo { get; set; }
public ScopeBubbleInfoData ScopeBubble { get; set; } = new ScopeBubbleInfoData()
Expand All @@ -42,6 +58,11 @@ public ThumperEntity(IShard shard, ulong eid, uint nodeType, uint beaconType)
Unk2 = 1
};

public uint LandedAbility { get; set; } = 0;
public uint CompletedAbility { get; set; } = 0;
public uint CalldownTimeMs { get; set; } = 0;
public uint MaxHealth { get; set; } = 0;

public ushort StatusEffectsChangeTime_0 { get; set; }
public ushort StatusEffectsChangeTime_1 { get; set; }
public ushort StatusEffectsChangeTime_2 { get; set; }
Expand Down Expand Up @@ -133,38 +154,52 @@ public override void ClearStatusEffect(byte index, ushort time, uint debugEffect
ResourceNode_ObserverView.GetType().GetProperty($"StatusEffects_{index}Prop").SetValue(ResourceNode_ObserverView, null, null);
}

public void SetPosition(Vector3 newPosition)
public void SetProgress(float newProgress)
{
Progress = newProgress;
ResourceNode_ObserverView.ProgressProp = Progress;
}

public void TransitionToState(ThumperState newState, uint? countdownOverride = null)
{
Position = newPosition;
ResourceNode_ObserverView.PositionProp = Position;
var countdownTime = countdownOverride ?? newState.CountdownTime();
StateInfo = new StateInfoStruct()
{
State = (byte)newState,
Time = Shard.CurrentTime,
CountdownTime = Shard.CurrentTime + countdownTime,
};
ResourceNode_ObserverView.StateInfoProp = StateInfo;
}

public override bool IsInteractable()
{
return Interaction != null ? Interaction.Type != 0 : false;
return StateInfo.State is (byte)ThumperState.THUMPING or (byte)ThumperState.COMPLETED;
}

public override bool CanBeInteractedBy(IEntity other)
{
return IsInteractable();
return IsInteractable()
&& other is CharacterEntity character
&& Encounter.Instance.Participants.Contains(character.Player);
}

private void InitFields()
{
Position = new Vector3();
var charOwner = (CharacterEntity)Owner;
HostilityInfo = new HostilityInfoData { Flags = 0 | HostilityInfoData.HostilityFlags.Faction, FactionId = 1 };
ThumpingCharacterInfo = new ThumpingCharacterInfoStruct
{
OwnerId1 = Owner?.AeroEntityId ?? new EntityId { Backing = 0 },
OwnerId2 = Owner?.AeroEntityId ?? new EntityId { Backing = 0 },
Owner = string.Empty,
OwnerId1 = Owner.AeroEntityId,
OwnerId2 = Owner.AeroEntityId,
Owner = charOwner.ToString(),
Unk = 0f,
};
StateInfo = new StateInfoStruct
{
State = (byte)ThumperState.THUMPING,
State = (byte)ThumperState.LANDING,
Time = Shard.CurrentTime,
CountdownTime = Shard.CurrentTime + (60 * 1000)
CountdownTime = Shard.CurrentTime + CalldownTimeMs
};
}

Expand All @@ -178,7 +213,7 @@ private void InitViews()
ThumpingCharacterInfoProp = ThumpingCharacterInfo,
StateInfoProp = StateInfo,
CurrentHealthPctProp = 100,
MaxHealthProp = 10000,
MaxHealthProp = MaxHealth,
ProgressProp = Progress,
HostilityInfoProp = HostilityInfo,
PersonalFactionStanceProp = null,
Expand Down
16 changes: 16 additions & 0 deletions UdpHosts/GameServer/Enums/ThumperState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,19 @@ public enum ThumperState : byte
DESTROYED = 8,
RESERVED = 9
}

public static class ThumperStateExtension
{
public static uint CountdownTime(this ThumperState state)
{
return state switch
{
ThumperState.WARMINGUP => 10_000,
ThumperState.THUMPING => 300_000,
ThumperState.CLOSING => 6_000,
ThumperState.COMPLETED => 120_000,
ThumperState.LEAVING => 12_000,
_ => 0,
};
}
}
3 changes: 3 additions & 0 deletions UdpHosts/GameServer/IShard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using GameServer.Entities;
using GameServer.Entities.Outpost;
using GameServer.Physics;
using GameServer.Systems.Encounters;
using Serilog;
using Shared.Udp;

Expand All @@ -15,11 +16,13 @@ public interface IShard : IPacketSender
ulong InstanceId { get; }
IDictionary<uint, INetworkPlayer> Clients { get; }
IDictionary<ulong, IEntity> Entities { get; }
IDictionary<ulong, IEncounter> Encounters { get; }
IDictionary<uint, IDictionary<uint, OutpostEntity>> Outposts { get; }
PhysicsEngine Physics { get; }
AIEngine AI { get; }
MovementRelay Movement { get; }
EntityManager EntityMan { get; }
EncounterManager EncounterMan { get; }
AbilitySystem Abilities { get; }
ProjectileSim ProjectileSim { get; }
WeaponSim WeaponSim { get; }
Expand Down
6 changes: 6 additions & 0 deletions UdpHosts/GameServer/Shard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using GameServer.Entities;
using GameServer.Entities.Outpost;
using GameServer.Physics;
using GameServer.Systems.Encounters;
using Microsoft.Extensions.Logging;
using Serilog;
using Shared.Common;
Expand All @@ -36,12 +37,14 @@ public Shard(double gameTickRate, ulong instanceId, GameServerSettings settings,
Logger = logger;
Clients = new ConcurrentDictionary<uint, INetworkPlayer>();
Entities = new ConcurrentDictionary<ulong, IEntity>();
Encounters = new ConcurrentDictionary<ulong, IEncounter>();
Outposts = new ConcurrentDictionary<uint, IDictionary<uint, OutpostEntity>>();
Physics = new PhysicsEngine(this);
AI = new AIEngine();
Movement = new MovementRelay(this);
Abilities = new AbilitySystem(this);
EntityMan = new EntityManager(this);
EncounterMan = new EncounterManager(this);
WeaponSim = new WeaponSim(this);
ProjectileSim = new ProjectileSim(this);
Chat = new ChatService(this);
Expand All @@ -51,12 +54,14 @@ public Shard(double gameTickRate, ulong instanceId, GameServerSettings settings,

public DateTime StartTime => DateTimeExtensions.Epoch.AddSeconds(_startTime);
public IDictionary<ulong, IEntity> Entities { get; protected set; }
public IDictionary<ulong, IEncounter> Encounters { get; protected set; }
public IDictionary<uint, IDictionary<uint, OutpostEntity>> Outposts { get; protected set; }
public IDictionary<uint, INetworkPlayer> Clients { get; }
public PhysicsEngine Physics { get; }
public AIEngine AI { get; }
public MovementRelay Movement { get; }
public EntityManager EntityMan { get; }
public EncounterManager EncounterMan { get; }
public AbilitySystem Abilities { get; }
public ProjectileSim ProjectileSim { get; }
public WeaponSim WeaponSim { get; }
Expand Down Expand Up @@ -93,6 +98,7 @@ public bool Tick(double deltaTime, ulong currentTime, CancellationToken ct)
AI.Tick(deltaTime, currentTime, ct);
Physics.Tick(deltaTime, currentTime, ct);
EntityMan.Tick(deltaTime, currentTime, ct);
EncounterMan.Tick(deltaTime, currentTime, ct);
Abilities.Tick(deltaTime, currentTime, ct);

WeaponSim.Tick(deltaTime, currentTime, ct);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,9 @@
},
{
"id": 93747,
"comment": "Triggered by Effect 154 "
"comment": "Triggered by Effect 154, part of Thumper.CompletedAbility",
"effect_id": 2260,
"remove_from_self": true
},
{
"id": 95466,
Expand Down Expand Up @@ -5631,7 +5633,9 @@
},
{
"id": 818991,
"comment": "Triggered by Effect 1723 "
"comment": "Triggered by Effect 1723, ThumpIntro",
"effect_id": 2260,
"remove_from_self": true
},
{
"id": 821894,
Expand Down
5 changes: 5 additions & 0 deletions UdpHosts/GameServer/Systems/Aptitude/AbilitySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ public void HandleActivateAbility(IShard shard, IAptitudeTarget initiator, uint
});
}

public void HandleActivateAbility(IShard shard, IAptitudeTarget initiator, uint abilityId)
{
HandleActivateAbility(shard, initiator, abilityId, Shard.CurrentTime, new AptitudeTargets());
}

public void HandleTargetAbility()
{
throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using GameServer.Data.SDB.Records.aptfs;
using GameServer.Entities;

namespace GameServer.Aptitude;

Expand All @@ -18,11 +19,10 @@ public bool Execute(Context context)
var request = context.Abilities.TryConsumeResourceNodeBeaconCalldownRequest(caller.EntityId);
if (request != null)
{
var entityMan = context.Shard.EntityMan;
var encounterMan = context.Shard.EncounterMan;
uint nodeType = 20; // TODO: Figure out how to use and determine these
var beaconType = Params.ResourceNodeBeaconId;
var position = request.Position;
entityMan.SpawnThumper(nodeType, beaconType, position);
encounterMan.CreateThumper(nodeType, position, (BaseEntity)caller, Params);
return true;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using GameServer.Entities;
using GameServer.Entities.Character;
using GameServer.Entities.Deployable;
using GameServer.Systems.Encounters;

namespace GameServer.Aptitude;

Expand Down Expand Up @@ -36,7 +37,15 @@ public bool Execute(Context context)
}

var interactionEntity = context.Targets.Peek();
var hack = interactionEntity as BaseEntity;
var hack = (BaseEntity)interactionEntity;

if (hack.Encounter is { Instance: IInteractionHandler encounter })
{
encounter.OnInteraction(hack);

return true;
}

var abilityId = hack.Interaction.CompletedAbilityId;
if (abilityId != 0)
{
Expand Down
56 changes: 56 additions & 0 deletions UdpHosts/GameServer/Systems/Encounters/BaseEncounter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using Aero.Gen;
using AeroMessages.Common;
using AeroMessages.GSS.V66.Generic;

namespace GameServer.Systems.Encounters;

public abstract class BaseEncounter : IEncounter
{
protected static readonly Random Rng = new();

protected BaseEncounter(IShard shard, ulong entityId, HashSet<INetworkPlayer> participants)
{
Shard = shard;
EntityId = entityId;
AeroEntityId = new EntityId() { Backing = EntityId, ControllerId = Controller.Encounter };
Participants = participants;
}

public IShard Shard { get; protected set; }
public ulong EntityId { get; }
public EntityId AeroEntityId { get; protected set; }

public HashSet<INetworkPlayer> Participants { get; }
public virtual IAeroEncounter View => null;

public virtual void OnUpdate(ulong currentTime)
{
}

public virtual void OnSignal()
{
}

public virtual void OnSuccess()
{
// todo rewards
Shard.EncounterMan.Remove(this);
}

public virtual void OnFailure()
{
Shard.EncounterMan.Remove(this);
}

protected void PlayDialog(uint id)
{
var msg = new PlayDialogScriptMessage() { DialogId = id, Unk1 = new ulong[] { 0 } };

foreach (var p in Participants)
{
p.NetChannels[ChannelType.ReliableGss].SendMessage(msg, p.CharacterEntity.EntityId);
}
}
}
Loading
Loading