internal static HirelingDiff GetDiff(HirelingDiff curr, HirelingDiff prev) { if (prev == null && curr == null) { return(null); } if (prev == null || curr == null) { return(curr); } var diff = new HirelingDiff(); var hasDiff = false; var itemsDiff = DiffUtil.ItemsDiff(curr.Items, prev.Items); diff.AddedItems = itemsDiff.Item1; diff.RemovedItems = itemsDiff.Item2; if (!DiffUtil.ListsEqual(prev.SkillIds, curr.SkillIds)) { diff.SkillIds = curr.SkillIds; } foreach (string propertyName in AutocompareProps) { var property = typeof(HirelingDiff).GetProperty(propertyName); var prevValue = property.GetValue(prev); var newValue = property.GetValue(curr); if (!DiffUtil.ObjectsEqual(prevValue, newValue)) { hasDiff = true; property.SetValue(diff, newValue); } } hasDiff = hasDiff || diff.AddedItems != null || diff.RemovedItems != null || diff.SkillIds != null; return(hasDiff ? diff : null); }
public static RequestBody GetDiff( RequestBody curr, RequestBody prev ) { var diff = new RequestBody() { Name = curr.Name, Guid = curr.Guid, }; // TODO: while this check is correct, D2DataReader should probably // provide the information about 'new char or not' directly // in a property of the DataReadEventArgs if (curr.CharCount > 0 && !curr.CharCount.Equals(prev.CharCount)) { diff.NewCharacter = true; prev = new RequestBody(); } if (!curr.GameCount.Equals(prev.GameCount)) { prev = new RequestBody(); } var hasDiff = false; foreach (string propertyName in AutocompareProps) { var property = typeof(RequestBody).GetProperty(propertyName); var prevValue = property.GetValue(prev); var newValue = property.GetValue(curr); if (!DiffUtil.ObjectsEqual(prevValue, newValue)) { hasDiff = true; property.SetValue(diff, newValue); } } var itemsDiff = DiffUtil.ItemsDiff(curr.Items, prev.Items); diff.AddedItems = itemsDiff.Item1; diff.RemovedItems = itemsDiff.Item2; diff.CompletedQuests = DiffUtil.CompletedQuestsDiff( curr.Quests, prev.Quests ); diff.Hireling = HirelingDiff.GetDiff( curr.Hireling, prev.Hireling ); if (curr.KilledMonsters != null && curr.KilledMonsters.Count > 0) { diff.KilledMonsters = curr.KilledMonsters; } hasDiff = hasDiff || diff.AddedItems != null || diff.RemovedItems != null || diff.CompletedQuests != null || diff.Hireling != null || diff.KilledMonsters != null; if (hasDiff) { // always send application info, if something is sent diff.DIApplicationInfo = curr.DIApplicationInfo; // always send d2 info, if something is sent diff.D2ProcessInfo = curr.D2ProcessInfo; return(diff); } return(null); }