NebulaModTeam / nebula

A multiplayer mod for the game Dyson Sphere Program
GNU General Public License v3.0
820 stars 125 forks source link

Combat - Basic syncing #652

Closed starfi5h closed 4 months ago

starfi5h commented 4 months ago

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

Basic syncing

Mecha

Ground

DF aggro

DF/Building interaction

Space

DF aggro

Temporarily Disable

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:

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.