private void OnServerKnightUpdate(ClientServerKnightUpdate packet) { Logger.Info(this, $"Received ServerKnightUpdate data for ID: {packet.Id}"); ClientPlayerData player = _playerManager.GetPlayer(packet.Id); if (player != null) { _serverKnightsManager.OnServerKnightUpdate(player, packet.Id, packet.Skin, packet.Emote); } }
private void ToggleBodyDamage(ClientPlayerData playerData, bool enabled) { var playerObject = playerData.PlayerObject; // We need to move the player object to the correct layer so it can interact with nail swings etc. // Also toggle the enabled state of the DamageHero component if (enabled) { playerObject.layer = 11; playerObject.GetComponent <DamageHero>().enabled = true; } else { playerObject.layer = 9; playerObject.GetComponent <DamageHero>().enabled = false; } }
public void SpawnPlayer( ushort id, string name, Math.Vector2 position, bool scale, Team team, byte skinId ) { if (_playerData.ContainsKey(id)) { Logger.Get().Warn(this, $"We already have created a player object for ID {id}"); return; } // Create a player container var playerContainer = new GameObject($"Player Container {id}"); playerContainer.transform.position = new Vector3(position.X, position.Y); playerContainer.AddComponent <PositionInterpolation>(); // Instantiate the player object from the prefab in the player container var playerObject = Object.Instantiate( _playerPrefab, playerContainer.transform ); Object.DontDestroyOnLoad(playerObject); SetPlayerObjectBoolScale(playerObject, scale); // Set object and children to active playerObject.SetActive(true); playerObject.SetActiveChildren(true); // Now we need to copy over a lot of variables from the local player object var localPlayerObject = HeroController.instance.gameObject; // Obtain colliders from both objects var collider = playerObject.GetComponent <BoxCollider2D>(); var localCollider = localPlayerObject.GetComponent <BoxCollider2D>(); // Copy collider offset and size collider.isTrigger = true; collider.offset = localCollider.offset; collider.size = localCollider.size; collider.enabled = true; // Copy collider bounds var bounds = collider.bounds; var localBounds = localCollider.bounds; bounds.min = localBounds.min; bounds.max = localBounds.max; // Disable DamageHero component unless pvp is enabled if (_gameSettings.IsPvpEnabled && _gameSettings.IsBodyDamageEnabled) { playerObject.layer = 11; playerObject.GetComponent <DamageHero>().enabled = true; } else { playerObject.layer = 9; playerObject.GetComponent <DamageHero>().enabled = false; } // Copy over mesh filter variables var meshFilter = playerObject.GetComponent <MeshFilter>(); var mesh = meshFilter.mesh; var localMesh = localPlayerObject.GetComponent <MeshFilter>().sharedMesh; mesh.vertices = localMesh.vertices; mesh.normals = localMesh.normals; mesh.uv = localMesh.uv; mesh.triangles = localMesh.triangles; mesh.tangents = localMesh.tangents; // Copy mesh renderer material var meshRenderer = playerObject.GetComponent <MeshRenderer>(); meshRenderer.material = new Material(localPlayerObject.GetComponent <MeshRenderer>().material); // Disable non bouncer component var nonBouncer = playerObject.GetComponent <NonBouncer>(); nonBouncer.active = false; // Copy over animation library var spriteAnimator = playerObject.GetComponent <tk2dSpriteAnimator>(); // Make a smart copy of the sprite animator library so we can // modify the animator without having to worry about other player objects spriteAnimator.Library = CopyUtil.SmartCopySpriteAnimation( localPlayerObject.GetComponent <tk2dSpriteAnimator>().Library, playerObject ); AddNameToPlayer(playerContainer, name, team); // Let the SkinManager update the skin _skinManager.UpdatePlayerSkin(playerObject, skinId); // Store the player data in the mapping _playerData[id] = new ClientPlayerData( playerContainer, playerObject, team ); // Set whether this player should have body damage // Only if: // PvP is enabled and body damage is enabled AND // (the teams are not equal or if either doesn't have a team) ToggleBodyDamage( _playerData[id], _gameSettings.IsPvpEnabled && _gameSettings.IsBodyDamageEnabled && (team != LocalPlayerTeam || team.Equals(Team.None) || LocalPlayerTeam.Equals(Team.None)) ); }