public void GenerateArtifacts() { var runningMissionArtifactTargets = _player.MissionHandler.GetArtifactTargets().Where(t => t.MyTarget.ZoneId == _zone.Id).ToArray(); var typesAlreadyCreated = new int[0]; if (runningMissionArtifactTargets.Length > 0) { var artifactTypes = runningMissionArtifactTargets.Select(m => (int)m.GetArtifactType()).ArrayToString(); var cmd = $"select artifacttype from artifacts where zoneid = @zoneId and characterid = @characterId and artifacttype in ({artifactTypes})"; typesAlreadyCreated = Db.Query().CommandText(cmd) .SetParameter("@zoneId", _zone.Id) .SetParameter("@characterId", _player.Character.Id) .Execute() .Select(r => r.GetValue <int>(0)).ToArray(); } var artifactTypesToDelete = _nonPersistentIds.Value.Except(typesAlreadyCreated).ToArray(); if (!artifactTypesToDelete.IsNullOrEmpty()) { var cmd = $"delete from artifacts where zoneid = @zoneId and characterid = @characterId and artifacts.artifacttype in ({artifactTypesToDelete.ArrayToString()})"; var count = Db.Query().CommandText(cmd) .SetParameter("@zoneId", _zone.Id) .SetParameter("@characterId", _player.Character.Id) .ExecuteNonQuery(); Logger.Info($"[Artifact] Non active mission artifact deleted. zone:{_zone.Id} player:{_player.InfoString} count:{count}"); } foreach (var missionTargetFindArtifact in runningMissionArtifactTargets.Where(m => !typesAlreadyCreated.Contains((int)m.GetArtifactType()))) { var artifactType = missionTargetFindArtifact.GetArtifactType(); var position = missionTargetFindArtifact.GetPosition(); var range = missionTargetFindArtifact.GetRange(); var artifactTypeInfo = _repository.GetArtifactInfo(artifactType); if (artifactTypeInfo == null) { continue; } range = range - artifactTypeInfo.goalRange; var resultPosition = _zone.FindPassablePointInRadius(position, range); var artifact = new Artifact(artifactTypeInfo, resultPosition, _player.Character); _repository.InsertArtifact(artifact); Logger.Info($"[Artifact] Created for mission. zone:{_zone.Id} id:{missionTargetFindArtifact.MyZoneMissionInProgress.missionId} player:{_player.InfoString}"); } }
public void GenerateArtifacts() { var artifactType = _target.GetArtifactType(); var artifactInfo = _repository.GetArtifactInfo(artifactType); if (!_repository.GetArtifacts().Where(a => a.MissionGuid == _target.MyZoneMissionInProgress.missionGuid && artifactInfo == a.Info).IsNullOrEmpty()) { return; } var position = _target.GetPosition(); var range = _target.GetRange(); var resultPosition = _target.Zone.FindPassablePointInRadius(position, range); var artifact = new Artifact(artifactInfo, resultPosition, _target.Player.Character) { MissionGuid = _target.MyZoneMissionInProgress.missionGuid }; _repository.InsertArtifact(artifact); }
public ArtifactLootItems GenerateLoot(Artifact artifact) { var artifactType = artifact.Info.type; var info = _artifactRepository.GetArtifactInfo(artifactType); if (info == null) { return(null); } var result = new List <LootItem>(); var loots = _artifactRepository.GetArtifactLoots(artifactType).ToArray(); if (loots.Length <= 0) { return(null); } do { foreach (var loot in loots) { var chance = FastRandom.NextDouble(); if (chance > loot.Chance) { continue; } var builder = loot.GetLootItemBuilder(); var lootItem = builder.Build(); result.Add(lootItem); } } while (result.Count < info.minimumLoot); return(new ArtifactLootItems(artifact.Position, result)); }