internal static PlayerClusterViewModel BuildClusterViewModelForPlayer(ArkClusterContext context, ArkCloudInventory cloudInventory, DemoMode demoMode, bool incCreaturesCloud) { var vm = new PlayerClusterViewModel(); if (incCreaturesCloud) { foreach (var c in cloudInventory.Dinos) { var aliases = ArkSpeciesAliases.Instance.GetAliasesByClassName(c.ClassName); var vmc = new CloudCreatureViewModel { Name = demoMode?.GetCreatureName(c.Id1, c.Id2, aliases?.FirstOrDefault()) ?? c.Name, ClassName = c.ClassName, Species = aliases?.FirstOrDefault(), Aliases = aliases?.Skip(2).ToArray() ?? new string[] { }, //skip primary name and class name Level = c.Level }; vm.Creatures.Add(vmc); } } return(vm); }
internal static List <TamedCreatureViewModel> BuildCreatureViewModelsForPlayerId(ArkServerContext context, IConfig config, int playerId, DemoMode demoMode, bool incBaseStats = false) { var result = new List <TamedCreatureViewModel>(); if (context.TamedCreatures != null) { var player = context.Players?.FirstOrDefault(x => x.Id == playerId); var playercreatures = context.NoRafts.Where(x => x.TargetingTeam == playerId || x.OwningPlayerId.HasValue && x.OwningPlayerId == playerId).ToArray(); var playercreatures_cryo = player?.Items?.OfType <ArkItemCryopod>().Where(x => x.Dino != null).Select(x => x.Dino).ToArray() ?? new ArkTamedCreature[] { }; var tribe = player != null ? player.Tribe : context.Tribes?.FirstOrDefault(x => x.MemberIds.Contains(playerId)); var tribecreatures = tribe != null?context.NoRafts.Where(x => x.TargetingTeam == tribe.Id && !playercreatures.Any(y => y.Id == x.Id)).ToArray() : new ArkTamedCreature[] { }; var tribecreatures_cryo = tribe?.Items?.OfType <ArkItemCryopod>().Where(x => x.Dino != null).Select(x => x.Dino).ToArray() ?? new ArkTamedCreature[] { }; foreach (var item in playercreatures.Select(x => new { c = x, o = "player", cryo = false }) .Concat(playercreatures_cryo.Select(x => new { c = x, o = "player", cryo = true })) .Concat(tribecreatures.Select(x => new { c = x, o = "tribe", cryo = false })) .Concat(tribecreatures_cryo.Select(x => new { c = x, o = "tribe", cryo = true }))) { var currentFood = item.c.CurrentStatusValues?.Length > 4 ? item.c.CurrentStatusValues[4] : null; var maxFood = item.c.BaseStats?.Length > 4 && item.c.TamedStats?.Length > 4 ? ArkDataHelper.CalculateMaxStat( ArkSpeciesStatsData.Stat.Food, item.c.ClassName, true, item.c.BaseStats[4], item.c.TamedStats[4], (decimal)(item.c.DinoImprintingQuality ?? 0f), (decimal)(item.c.TamedIneffectivenessModifier ?? 0f)) : null; //baby food formula: max * 0.1 + (max - (max * 0.1)) * age if (maxFood.HasValue && item.c.BabyAge.HasValue) { maxFood = maxFood.Value * 0.1 + (maxFood.Value - maxFood.Value * 0.1) * item.c.BabyAge.Value; } var foodStatus = currentFood.HasValue && maxFood.HasValue ? currentFood.Value / (float)maxFood.Value : (float?)null; if (foodStatus.HasValue && foodStatus > 1f) { foodStatus = 1f; } //baby fully grown var babyFullyGrownTimeApprox = (DateTime?)null; if (item.c.IsBaby && item.c.BabyAge.HasValue && context.SaveState.GameTime.HasValue) { var babyFullyGrown = ArkDataHelper.CalculateBabyFullyGrown(item.c.ClassName, item.c.BabyAge.Value, context.Config.ArkMultipliers); babyFullyGrownTimeApprox = context.SaveState.GetApproxDateTimeOf(context.SaveState.GameTime.Value + babyFullyGrown); } var aliases = ArkSpeciesAliases.Instance.GetAliasesByClassName(item.c.ClassName); var vmc = new TamedCreatureViewModel { Id1 = item.c.Id1, Id2 = item.c.Id2, Name = demoMode?.GetCreatureName(item.c.Id1, item.c.Id2, aliases?.FirstOrDefault()) ?? item.c.Name, ClassName = item.c.ClassName, Species = aliases?.FirstOrDefault(), Aliases = aliases?.Skip(2).ToArray() ?? new string[] { }, //skip primary name and class name Gender = item.c.Gender.ToString(), BaseLevel = item.c.BaseLevel, Level = item.c.Level, Experience = item.c.ExperiencePoints ?? 0f, BabyAge = item.c.IsBaby ? item.c.BabyAge : null, Imprint = item.c.DinoImprintingQuality, FoodStatus = foodStatus, Latitude = item.cryo ? null : item.c.Location?.Latitude, Longitude = item.cryo ? null : item.c.Location?.Longitude, TopoMapX = item.cryo ? null : item.c.Location?.TopoMapX, TopoMapY = item.cryo ? null : item.c.Location?.TopoMapY, NextMating = !item.c.IsBaby && item.c.Gender == ArkCreatureGender.Female ? item.c.NextAllowedMatingTimeApprox : null, BabyFullyGrown = babyFullyGrownTimeApprox, BabyNextCuddle = item.c.BabyNextCuddleTimeApprox, OwnerType = item.o, InCryopod = item.cryo, Parents = item.c.DinoAncestors?.Length > 0 && item.c.DinoAncestorsMale?.Length > 0 ? new CreatureParentsViewModel { Female = new CreatureIdViewModel { Id1 = item.c.DinoAncestors.First().FemaleId1, Id2 = item.c.DinoAncestors.First().FemaleId2 }, Male = new CreatureIdViewModel { Id1 = item.c.DinoAncestorsMale.First().MaleId1, Id2 = item.c.DinoAncestorsMale.First().MaleId2 } } : null, RandomMutationsFemale = item.c.RandomMutationsFemale, RandomMutationsMale = item.c.RandomMutationsMale, }; if (incBaseStats) { //0: health //1: stamina //2: torpor //3: oxygen //4: food //5: water //6: temperature //7: weight //8: melee damage //9: movement speed //10: fortitude //11: crafting speed vmc.BaseStats = new CreatureStatsViewModel { Health = item.c.BaseStats[0], Stamina = item.c.BaseStats[1], Oxygen = item.c.BaseStats[3], Food = item.c.BaseStats[4], Weight = item.c.BaseStats[7], Melee = item.c.BaseStats[8], MovementSpeed = item.c.BaseStats[9] }; vmc.TamedStats = new CreatureStatsViewModel { Health = item.c.TamedStats[0], Stamina = item.c.TamedStats[1], Oxygen = item.c.TamedStats[3], Food = item.c.TamedStats[4], Weight = item.c.TamedStats[7], Melee = item.c.TamedStats[8], MovementSpeed = item.c.TamedStats[9] }; var statValues = ArkSpeciesStats.Instance.Data.GetStatValues(item.c); vmc.StatValues = new CreatureStatValuesViewModel { Tamed = statValues.tamed, TamedNoImprint = statValues.tamedNoImprint, Wild = statValues.wild, }; } result.Add(vmc); } } return(result); }