public static JSON.Report ModelToJson(Scaffold.Report report) { var result = new JSON.Report(); result.ReportId = report.ReportId; result.OccurredAt = report.OccuredAt; result.Morale = report.Morale; result.Luck = report.Luck; result.AttackingPlayerId = report.AttackerPlayerId; result.AttackingVillageId = report.AttackerVillageId; result.AttackingArmy = ArmyConvert.ArmyToJson(report.AttackerArmy); result.AttackingArmyLosses = ArmyConvert.ArmyToJson(report.AttackerLossesArmy); result.DefendingPlayerId = report.DefenderPlayerId; result.DefendingVillageId = report.DefenderVillageId; result.DefendingArmy = ArmyConvert.ArmyToJson(report.DefenderArmy); result.DefendingArmyLosses = ArmyConvert.ArmyToJson(report.DefenderLossesArmy); result.TravelingTroops = ArmyConvert.ArmyToJson(report.DefenderTravelingArmy); result.BuildingLevels = BuildingConvert.ReportBuildingToJson(report.Building); return(result); }
public static Scaffold.CurrentVillageSupport ToModel( long sourceVillageId, short worldId, int accessGroupId, JSON.PlayerOutwardSupport.SupportedVillage villageData, DateTime currentTime, Scaffold.CurrentVillageSupport existingSupport = null, Scaffold.VaultContext context = null ) { if (existingSupport == null) { existingSupport = new Scaffold.CurrentVillageSupport(); existingSupport.WorldId = worldId; existingSupport.AccessGroupId = accessGroupId; if (context != null) { context.CurrentVillageSupport.Add(existingSupport); } } existingSupport.SourceVillageId = sourceVillageId; existingSupport.TargetVillageId = villageData.Id; existingSupport.LastUpdatedAt = currentTime; existingSupport.SupportingArmy = ArmyConvert.JsonToArmy(villageData.TroopCounts, worldId, existingSupport.SupportingArmy, context); return(existingSupport); }
public static Scaffold.Command JsonToModel(JSON.Command command, short worldId, int accessGroupId, Scaffold.Command existingCommand, DateTime currentTime, Scaffold.VaultContext context = null) { if (command == null) { if (existingCommand != null && context != null) { context.Remove(existingCommand); } return(null); } Scaffold.Command result; if (existingCommand != null) { result = existingCommand; } else { result = new Scaffold.Command(); result.CommandId = command.CommandId.Value; result.WorldId = worldId; result.AccessGroupId = accessGroupId; if (context != null) { context.Add(result); } } result.CommandId = command.CommandId.Value; result.UserLabel = result.UserLabel ?? command.UserLabel; // Don't overwrite existing labels result.SourcePlayerId = command.SourcePlayerId.Value; result.SourceVillageId = command.SourceVillageId.Value; result.TargetPlayerId = command.TargetPlayerId; result.TargetVillageId = command.TargetVillageId.Value; result.LandsAt = command.LandsAt.Value; result.FirstSeenAt = result.FirstSeenAt == DateTime.MinValue ? currentTime : result.FirstSeenAt; result.IsAttack = command.CommandType == JSON.CommandType.Attack; result.IsReturning = command.IsReturning.Value; result.Army = ArmyConvert.JsonToArmy(command.Troops, worldId, result.Army, context); if (result.TroopType == null) { result.TroopType = TroopTypeConvert.TroopTypeToString(command.TroopType); } else if (command.TroopType != null) { var currentType = result.TroopType.ToTroopType(); var updatedType = command.TroopType.Value; if (Native.ArmyStats.TravelSpeed[currentType] < Native.ArmyStats.TravelSpeed[updatedType]) { result.TroopType = updatedType.ToTroopString(); } } return(result); }
public static JSON.Command ModelToJson(Scaffold.Command command) { var result = new JSON.Command(); result.CommandId = command.CommandId; result.UserLabel = command.UserLabel; result.SourcePlayerId = command.SourcePlayerId; result.SourceVillageId = command.SourceVillageId; result.TargetPlayerId = command.TargetPlayerId; result.TargetVillageId = command.TargetVillageId; result.LandsAt = command.LandsAt; result.CommandType = command.IsAttack ? JSON.CommandType.Attack : JSON.CommandType.Support; result.IsReturning = command.IsReturning; result.TroopType = TroopTypeConvert.StringToTroopType(command.TroopType); result.Troops = ArmyConvert.ArmyToJson(command.Army); return(result); }
public static void JsonToModel(JSON.Report report, short worldId, Scaffold.Report target, Scaffold.VaultContext context = null) { target.WorldId = worldId; target.ReportId = report.ReportId.Value; target.OccuredAt = report.OccurredAt.Value; target.Morale = report.Morale.Value; target.Luck = report.Luck.Value; target.Loyalty = report.Loyalty; target.AttackerPlayerId = report.AttackingPlayerId; target.AttackerVillageId = report.AttackingVillageId.Value; target.AttackerArmy = ArmyConvert.JsonToArmy(report.AttackingArmy, worldId, target.AttackerArmy, context); target.AttackerLossesArmy = ArmyConvert.JsonToArmy(report.AttackingArmyLosses, worldId, target.AttackerLossesArmy, context, emptyIfNull: true); target.DefenderPlayerId = report.DefendingPlayerId; target.DefenderVillageId = report.DefendingVillageId.Value; target.DefenderArmy = ArmyConvert.JsonToArmy(report.DefendingArmy, worldId, target.DefenderArmy, context); target.DefenderLossesArmy = ArmyConvert.JsonToArmy(report.DefendingArmyLosses, worldId, target.DefenderLossesArmy, context); target.DefenderTravelingArmy = ArmyConvert.JsonToArmy(report.TravelingTroops, worldId, target.DefenderTravelingArmy, context); target.Building = BuildingConvert.JsonToReportBuilding(report.BuildingLevels, worldId, target.Building, context); }