public bool AddInRangeCharacter(Character character) { try { if (character == null || InRangeCharacters.ContainsKey(character.Id) || character.Destroyed || character.Id == Id || character.Spacemap.Id != Spacemap.Id) { return(false); } var success = InRangeCharacters.TryAdd(character.Id, character); if (success) { InRangeCharacterAdded?.Invoke(this, new CharacterArgs(character)); if (this is Player player) { short relationType = character.Clan.Id != 0 && Clan.Id != 0 ? Clan.GetRelation(character.Clan) : (short)0; if (character is Player) { var otherPlayer = character as Player; player.SendCommand(otherPlayer.GetShipCreateCommand(player, relationType)); if (otherPlayer.Title != "" && !EventManager.JackpotBattle.InEvent(otherPlayer)) { player.SendPacket($"0|n|t|{otherPlayer.Id}|1|{otherPlayer.Title}"); } player.SendPacket(otherPlayer.DroneManager.GetDronesPacket()); player.SendCommand(DroneFormationChangeCommand.write(otherPlayer.Id, DroneManager.GetSelectedFormationId(otherPlayer.Settings.InGameSettings.selectedFormation))); } else if (character is Pet) { var pet = character as Pet; if (pet == player.Pet) { player.SendCommand(PetHeroActivationCommand.write(pet.Owner.Id, pet.Id, 22, 3, pet.Name, (short)pet.Owner.FactionId, pet.Owner.Clan.Id, 15, pet.Owner.Clan.Tag, pet.Position.X, pet.Position.Y, pet.Speed, new class_11d(class_11d.DEFAULT))); } else { player.SendCommand(PetActivationCommand.write(pet.Owner.Id, pet.Id, 22, 3, pet.Name, (short)pet.Owner.FactionId, pet.Owner.Clan.Id, 15, pet.Owner.Clan.Tag, new ClanRelationModule(relationType), pet.Position.X, pet.Position.Y, pet.Speed, false, true, new class_11d(class_11d.DEFAULT))); } } else { player.SendCommand(character.GetShipCreateCommand()); } var timeElapsed = (DateTime.Now - character.MovementStartTime).TotalMilliseconds; player.SendCommand(MoveCommand.write(character.Id, character.Destination.X, character.Destination.Y, (int)(character.MovementTime - timeElapsed))); } } return(success); } catch (Exception e) { Out.WriteLine("AddInRangeCharacter void exception " + e, "Character.cs"); Logger.Log("error_log", $"- [Character.cs] AddInRangeCharacter void exception: {e}"); return(false); } }
public bool AddInRangeCharacter(Character character) { if (character.Spacemap != Spacemap || IsInRangeCharacter(character) || character.Destroyed) { return(false); } if (character == this) { return(false); } var success = InRangeCharacters.TryAdd(character.Id, character); if (success) { InRangeCharacterAdded?.Invoke(this, new CharacterArgs(character)); if (this is Player player) { short relationType = character.Clan != null && Clan != null?Clan.GetRelation(character.Clan) : (short)0; bool sameClan = character.Clan != null && Clan != null ? Clan == character.Clan : false; if (character is Player) { var otherPlayer = character as Player; player.SendCommand(otherPlayer.GetShipCreateCommand(player.RankId == 21 ? true : false, relationType, sameClan, (EventManager.JackpotBattle.Active && player.Spacemap == EventManager.JackpotBattle.Spacemap && otherPlayer.Spacemap == EventManager.JackpotBattle.Spacemap))); player.SendPacket($"0|n|INV|{otherPlayer.Id}|{Convert.ToInt32(otherPlayer.Invisible)}"); if (otherPlayer.Title != "" && !EventManager.JackpotBattle.Active && player.Spacemap != EventManager.JackpotBattle.Spacemap && otherPlayer.Spacemap != EventManager.JackpotBattle.Spacemap) { player.SendPacket($"0|n|t|{otherPlayer.Id}|1|{otherPlayer.Title}"); } player.CheckAbilities(otherPlayer); otherPlayer.DroneManager.UpdateDrones(); player.SendPacket(otherPlayer.DroneManager.GetDronesPacket()); player.SendCommand(DroneFormationChangeCommand.write(otherPlayer.Id, otherPlayer.SettingsManager.SelectedFormation)); } else if (character is Pet) { var pet = character as Pet; if (pet == player.Pet) { player.SendCommand(PetHeroActivationCommand.write(pet.Owner.Id, pet.Id, 22, 3, pet.Name, (short)pet.Owner.FactionId, pet.Owner.GetClanId(), 15, pet.Owner.GetClanTag(), pet.Position.X, pet.Position.Y, pet.Speed)); } else { player.SendCommand(PetActivationCommand.write(pet.Owner.Id, pet.Id, 22, 3, pet.Name, (short)pet.Owner.FactionId, pet.Owner.GetClanId(), 15, pet.Owner.GetClanTag(), new ClanRelationModule(relationType), pet.Position.X, pet.Position.Y, pet.Speed, false, true)); player.SendPacket($"0|n|INV|{pet.Id}|{Convert.ToInt32(pet.Invisible)}"); } } else if (character is Spaceball) { var spaceball = character as Spaceball; player.SendCommand(spaceball.GetShipCreateCommand()); } } } return(success); }