private void SetTarget(MatchCharacter player) { if (currentMode == ViewMode.firstPerson) { currentTarget?.HideFirstPersonModel(true); player?.HideFirstPersonModel(false); } currentTarget = player; orbitController.target = currentTarget.transform; firstPersonController.target = currentTarget.transform; playerNameLabel.text = currentTarget.playerNameLabel.text; }
private void UpdateCharacters() { //charactersPool.ReturnAll(); #region Return models that are not being used anymore (possibly disconnected or bot or something) List <int> keysToRemove = new List <int>(); foreach (var characterModel in characterModels) { if (!demoParser.PlayingParticipants.Any(player => player.EntityID == characterModel.Key)) { if (characterModel.Value != null) { keysToRemove.Add(characterModel.Key); } } } foreach (int key in keysToRemove) { charactersPool.Return(characterModels[key]); characterModels[key] = null; } #endregion //for (int i = 0; i < demoParser.PlayingParticipants.Count(); i++) foreach (var player in demoParser.PlayingParticipants) { //var player = demoParser.PlayingParticipants.ElementAt(i); //I removed the foreach since I got an error that the enumerable was modified during the loop MatchCharacter character = null; if (!characterModels.ContainsKey(player.EntityID)) { characterModels[player.EntityID] = null; } character = characterModels[player.EntityID]; if (player.IsAlive) { if (character == null) { character = charactersPool.Get(); } characterModels[player.EntityID] = character; character.entityId = player.EntityID; Vector3 worldPosition = new Vector3(player.Position.X, player.Position.Z, player.Position.Y); Vector2 worldDirection = new Vector2(player.ViewDirectionY, -(player.ViewDirectionX + characterRotationXOffset)); character.SetPosition(worldPosition); character.SetColor(GetIsHurt(player.EntityID) ? Color.red : (player.Team == Team.CounterTerrorist ? counterTerroristColor : (player.Team == Team.Terrorist ? terroristColor : spectatorColor))); character.SetRotation(worldDirection); character.SetCrouching(player.IsDucking); character.SetVelocity(new Vector3(player.Velocity.X, player.Velocity.Z, player.Velocity.Y)); character.SetName(player.Name); character.SetGunShotVisibility(GetIsFiring(player.EntityID)); if (player.ActiveWeapon != null) { character.SetWeapon(player.ActiveWeapon.Weapon); } character.SetAnimationPlaying(play); } else { if (characterModels[player.EntityID] != null) { charactersPool.Return(characterModels[player.EntityID]); characterModels[player.EntityID] = null; } } } }
public async Task <Set> Update(int setID, IReadOnlyList <MatchForm> matchForms) { var set = await dbContext.Sets .Include(s => s.Player1) .Include(s => s.Player2) .Include(s => s.Matches).ThenInclude(m => m.MatchCharacters) .FirstOrDefaultAsync(s => s.ID == setID); if (set == null) { throw new NotFoundException(typeof(Set), setID); } if (set.Matches.Count > 0) { dbContext.RemoveRange(set.Matches.SelectMany(m => m.MatchCharacters)); dbContext.RemoveRange(set.Matches); await dbContext.SaveChangesAsync(); set.Matches.Clear(); } else { set.Player1.SetCount++; set.Player2.SetCount++; } dbContext.Sets.Update(set); set.IsComplete = true; set.Player1Score = set.Player2Score = 0; for (var i = 0; i < matchForms.Count; i++) { var matchForm = matchForms[i]; var match = new Match(setID, i, matchForm.Player1Score, matchForm.Player2Score, matchForm.StageID); dbContext.Matches.Add(match); for (var j = 0; j < matchForm.Player1Characters.Length; j++) { AddCharacter(match, matchForm.Player1Characters[j], set.Player1ID); AddCharacter(match, matchForm.Player2Characters[j], set.Player2ID); } if (matchForm.Player1Score > matchForm.Player2Score) { ++set.Player1Score; } else { ++set.Player2Score; } } await dbContext.SaveChangesAsync(); if (set.SeasonID != null) { await seasonService.UpdateStandings(setID); } return(set); void AddCharacter(Match match, int characterID, int playerID) { var character = new MatchCharacter(match.ID, characterID, playerID); dbContext.MatchCharacters.Add(character); } }