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

Combat - Basic syncing #652

Merged
merged 82 commits into from
Mar 9, 2024
Merged

Combat - Basic syncing #652

merged 82 commits into from
Mar 9, 2024

Conversation

starfi5h
Copy link
Collaborator

@starfi5h starfi5h commented Feb 10, 2024

This is a branch for combat framework and basic unit syncing.
Video demo: Ground Unit Syncing

The roadmap can be found here. The work includes in this PR:

Initial handshake

  • Sync battle settings
  • Rework the joining process to let the client load SpaceSector data from the host as it is imported from the save
  • Send SkillSystem data without projectiles during handshake to prevent error (CombatManager.SerializeOverwrite)

Basic syncing

  • Sync DF ground enemy create/destroy events (factory.enemyPool)
  • Sync DF ground units activate/deactivate event
  • Sync DF space enemy create/destroy events (spaceSector.enemyPool)
  • Sync DF space units activate/deactivate events
  • Sync DF planet base exp level and threat
  • Sync DF space hive exp level and threat
  • Sync loot and loot filter table

Mecha

  • Sync mecha shooting weapons
  • Sync mecha bombing
  • Sync mecha death and respawn animation
  • Sync mecha personal shield to block projectiles

Ground

DF aggro

  • Sync DF base awake events (player lock with weapon, player nearby, under attack)
  • Sync DF base threat and launch assault event
  • Patch DF unit to search for nearest alive mecha (sensor range)
  • Patch DF turret to search for nearest alive mecha (attack when within attack range or counterattack)
  • Sync the hatred targets changes so DF units are attacking the same target

DF/Building interaction

  • Sync building repair drone (not perfect)
  • Sync building kill event (server fully authorized)
  • Sync building reconstruct event

Space

  • Handle DFRelayComponent.RealizePlanetBase
  • Sync DFRelay ArriveBase/ArriveDock/LeaveBase/LeaveDock events
  • Sync Remove base pit event
  • Sync TryCreateNewHive, DispatchFromHive events
  • Sync Realize and open/close hive preview events

DF aggro

  • Sync DF hive awake events (player lock with weapon, player nearby, under attack)
  • Sync DF hive threat level and launch assault event
  • Patch DF unit to search for nearest alive mecha (sensor range)
  • Patch DF turret to search for nearest alive mecha (attack when within attack range or counterattack)

Temporarily Disable

  • Dark Fog communicator

Implement Detail

Dark Fog Ground Unit syncing

The goal is to let PlanetFactory.enemyPool stay in sync. So every function that call PlanetFactory.AddEnemyDataWithComponents and PlanetFactory.RemoveEnemyWithComponents need to approve by the server first.

For example, when a client sees an enemy reduce HP to 0, it will set the enemy to a frozen state and request the server to kill it. When the server receives the valid request, it will broadcast the kill event to clients. After receiving the event, the client will kill it and process the following effect.

Dark Fog Space Unit syncing

Similar to the ground unit, let SpaceSector.enemyPool stay in sync.

Here are patch to functions:

  • yellow check means it will broadcast in server and intercept in client.
  • orange block means it's disabled in multiplayer game.
  • prefix CSE_ is just for demo so they can be ignored.
    AddEnemyDataWithComponents
    RemoveEnemyWithComponents

Dark Fog Planetary Base Exp and Threat

The client doesn't update exp level and threat locally. It will wait for the server to send DFGUpdateBaseStatusPacket every 5s to update those values. The LaunchAsssult event is trigger by the server too.

Mecha

RemotePlayerModel.PlayerInstance now has controller member to use more vanilla properties.
The weapon is client triggered, that local will fire first then broadcast to other players.

CombatManager

This stores some players' variables that are frequently used in combat systems. For example, PlayerPosition cache the player position and states.
The positions of other players are using the delayed interpolated position therefore they may cause some distortion.

EnemyMananger

This stores the status of Dark Fog bases and hive, and sends updates to clients every 5 seconds.
Also, it has the common functions that will try to pre-assign the enemyId before creating the enemy.

Skill System

This system in the game manages all kinds of projectiles and stores the properties of the player.
The default player id is 1. In multiplayer it is changed to playerId. The local playerId will be Multiplayer.Session.LocalPlayer.Id.

Rework

GlobalGameDataRequest/GlobalGameDataResponse

When client join, after the initial handshake, it will now request the global data from the server first (History, SpaceSector, MilestoneSystem, TrashSystem). After those binary data are collected, the client will then proceed DSPGame.StartGameSkipPrologue to start the game loader sequence. Before GameData.NewGame, the client will import those binary data.

TrashSystem

Now trash will be separated into two types: Those that have lifetime (Dark Fog drop), and those that have no lifetime (normal). The Dark Fog drop are now partially syncing for clients to only sync on the drop on the local planet.

@starfi5h starfi5h changed the title Combat - Basic ground battle syncing Combat - Basic syncing Feb 28, 2024
Copy link
Contributor

@mmjr-x mmjr-x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it to file 116 of 152 however have to sleep soon so I will submit this as the first part.

Code looks good overall! Added a bunch of comments only almost everything are minor nitpicks, so take them with a grain of salt :)

var num10 = ((__instance.hatred.max.targetType == ETargetType.Player) ? 1f : 0.8f);
if (num9 < (double)(num2 * num10))
{
var num11 = Maths.Clamp01(((double)num2 - num9) / (double)(num2 - 5500f)) * 15.0 + 3.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nitpick, might be nice to note where these magic numbers 5500f, 15.0 and 3.0 come form (or put them into constants)?

if (num9 < (double)(num2 * num10))
{
var num11 = Maths.Clamp01(((double)num2 - num9) / (double)(num2 - 5500f)) * 15.0 + 3.0;
var num12 = Maths.Clamp01(((double)num3 - num5) / (double)(num3 - 1500f));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nitpick, might be nice to note where this magic number comes form (or put it into a constant)?

var magnitude = (vectorLF * (__instance.orbitRadius / num14) + __instance.starData.uPosition - uPos).magnitude;
if (magnitude < (double)num2)
{
var num16 = Maths.Clamp01(((double)num2 - magnitude) / (double)(num2 - 5500f)) * 15.0 + 3.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nitpick, might be nice to note where these magic numbers 5500f, 15.0 and 3.0 come form (or put them into constants)?

if (magnitude < (double)num2)
{
var num16 = Maths.Clamp01(((double)num2 - magnitude) / (double)(num2 - 5500f)) * 15.0 + 3.0;
var num17 = Maths.Clamp01(((double)num3 - num15) / (double)(num3 - 1500f));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nitpick, might be nice to note where this magic number comes form (or put it into a constant)?

{
var num16 = Maths.Clamp01(((double)num2 - magnitude) / (double)(num2 - 5500f)) * 15.0 + 3.0;
var num17 = Maths.Clamp01(((double)num3 - num15) / (double)(num3 - 1500f));
var num18 = __instance.sector.skillSystem.maxHatredSpaceTmp * num17 * num16 * 0.6;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nitpick, might be nice to note where this magic number comes form (or put it into a constant)?

Copy link
Contributor

@mmjr-x mmjr-x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finished the second part of my review :) I opted not to make comments about the magic numbers since I don't think there that relevant. Again mostly nitpicky stuff.

One thing I did notice is that there might be some prefix and postfix patches that could potentially be turned into transpiler patches. I did not comment about them explicitly, however if you want I could go through them again after the weekend and add a comment to them?

NebulaPatcher/Patches/Dynamic/EnemyUnitComponent_Patch.cs Outdated Show resolved Hide resolved
NebulaPatcher/Patches/Dynamic/EnemyUnitComponent_Patch.cs Outdated Show resolved Hide resolved
NebulaPatcher/Patches/Dynamic/EnemyUnitComponent_Patch.cs Outdated Show resolved Hide resolved
NebulaPatcher/Patches/Dynamic/EnemyUnitComponent_Patch.cs Outdated Show resolved Hide resolved
NebulaPatcher/Patches/Dynamic/EnemyUnitComponent_Patch.cs Outdated Show resolved Hide resolved
NebulaWorld/Combat/CombatManager.cs Outdated Show resolved Hide resolved
NebulaWorld/Combat/EnemyManager.cs Outdated Show resolved Hide resolved
NebulaWorld/Combat/EnemyManager.cs Outdated Show resolved Hide resolved
NebulaWorld/Trash/TrashManager.cs Outdated Show resolved Hide resolved
NebulaWorld/Warning/WarningManager.cs Outdated Show resolved Hide resolved
starfi5h and others added 3 commits March 1, 2024 09:31
Copy link
Collaborator

@sp00ktober sp00ktober left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the great work on this and all the time you put into it!

@starfi5h starfi5h merged commit 94cb2bc into master Mar 9, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants