private bool Compare(PlayerHeldItem a, PlayerHeldItem b) { if (a is PlayerItem pi1) { if (b is PlayerItem pi2) { return(pi1.BaseRecord == pi2.BaseRecord && pi1.PrefixRecord == pi2.PrefixRecord && pi1.Seed == pi2.Seed && pi1.SuffixRecord == pi2.SuffixRecord); } } else if (a is BuddyItem bi1) { if (b is BuddyItem bi2) { return(bi1.BaseRecord == bi2.BaseRecord && bi1.PrefixRecord == bi2.PrefixRecord && bi1.Seed == bi2.Seed && bi1.SuffixRecord == bi2.SuffixRecord); } } else if (a is RecipeItem ri1) { if (b is RecipeItem ri2) { return(ri1.BaseRecord == ri2.BaseRecord); } } return(false); }
public override bool Equals(object obj) { PlayerHeldItem that = obj as PlayerHeldItem; if (that != null) { return(this.BaseRecord.Equals(that.BaseRecord)); } return(base.Equals(obj)); }
private void parseCPMMOItem(CPMMOItem cPMMOItem) { if (cPMMOItem is PlayerHeldItem) { PlayerHeldItem playerHeldItem = (PlayerHeldItem)cPMMOItem; InvitationalItemData invitationalItemData = Service.Get <JsonService>().Deserialize <InvitationalItemData>(playerHeldItem.Properties); if (invitationalItemData != null) { AvailableItemQuantity = invitationalItemData.actionCount; } } }
private void onCPMMOItemChanged(CPMMOItem cPMMOItem) { PlayerHeldItem playerHeldItem = cPMMOItem as PlayerHeldItem; if (playerHeldItem != null) { ItemData itemData = Service.Get <JsonService>().Deserialize <ItemData>(playerHeldItem.Properties); if (itemData != null && itemData.actionCount == 0) { onPropUsed(cPMMOItem.CreatorId, playerHeldItem.Type, cPMMOItem.Id.Id.ToString(), Vector3.zero); } } }
public virtual int CompareTo(object obj) { PlayerHeldItem item = obj as PlayerHeldItem; if (item != null) { if (Name != null && item.Name != null) { return(Name.CompareTo(item.Name)); } return(Id.CompareTo(item.Id)); } return(0); }
private bool onServerObjectItemAdded(DataEntityEvents.ComponentAddedEvent <ServerObjectItemData> evt) { Vector3 zero = Vector3.zero; if (evt.Component.Item.Id.Parent == CPMMOItemId.CPMMOItemParent.WORLD) { if (evt.Component.Item is ConsumableItem) { new ServerObjectTracker(this, evt.Handle, evt.Component); } if (userIdToPropUser.ContainsKey(evt.Component.Item.CreatorId)) { PropUser propUser = userIdToPropUser[evt.Component.Item.CreatorId]; if (propUser.PendingExperienceId == evt.Component.Item.Id.Id) { propUser.PendingExperienceId = -1L; } } } PlayerHeldItem playerHeldItem = evt.Component.Item as PlayerHeldItem; if (playerHeldItem != null) { string type = playerHeldItem.Type; if (!Props.ContainsKey(type)) { throw new InvalidOperationException("There is no prop definition for " + type); } if (Props[type].ServerAddedItem) { DHeldObject dHeldObject = new DHeldObject(); dHeldObject.ObjectId = type; DataEntityHandle dataEntityHandle = ((!dataEntityCollection.IsLocalPlayer(evt.Component.Item.CreatorId)) ? dataEntityCollection.FindEntity <SessionIdData, long>(evt.Component.Item.CreatorId) : dataEntityCollection.LocalPlayerHandle); if (!dataEntityHandle.IsNull) { dataEntityCollection.GetComponent <HeldObjectsData>(dataEntityHandle).HeldObject = dHeldObject; evt.Component.ItemChanged += onCPMMOItemChanged; } } else { onPropUsed(evt.Component.Item.CreatorId, playerHeldItem.Type, evt.Component.Item.Id.Id.ToString(), zero); } } return(false); }
private int CompareToMinimumLevel(PlayerHeldItem itemA, PlayerHeldItem itemB) { if (itemA != null && itemB != null) { var order = itemA.MinimumLevel.CompareTo(itemB.MinimumLevel); if (order == 0) { return(itemA.CompareTo(itemB)); } else { return(order); } } return(0); }
public override void HandleInteraction(LocomotionActionEvent action) { if (action.Type == LocomotionAction.Interact && action.Object.type == ObjectType.PLAYER) { actionCount--; if (actionCount <= 0) { client.DequipeHeldObject(); return; } PlayerHeldItem playerHeldItem = new PlayerHeldItem(); playerHeldItem.Id = new CPMMOItemId(client.clubPenguinClient.PlayerSessionId, CPMMOItemId.CPMMOItemParent.PLAYER); playerHeldItem.CreatorId = playerHeldItem.Id.Id; playerHeldItem.Type = type; playerHeldItem.Properties = "{\"actionCount\":" + actionCount + "}"; client.processEvent(GameServerEvent.SERVER_ITEM_CHANGED, playerHeldItem); } }
private bool onItemRemoved(DataEntityEvents.ComponentRemovedEvent evt) { ServerObjectItemData serverObjectItemData = evt.Component as ServerObjectItemData; if (serverObjectItemData != null) { PlayerHeldItem playerHeldItem = serverObjectItemData.Item as PlayerHeldItem; if (playerHeldItem != null) { string type = playerHeldItem.Type; if (Props[type].ServerAddedItem) { onItemRemoved(serverObjectItemData.Item.CreatorId); } } } return(false); }
public override IEnumerator Consume(int partialCount, string type, object properties) { base.type = type; if (partialCount > 0) { actionCount = partialCount; } else { actionCount = startingActionAcount; } PlayerHeldItem item = new PlayerHeldItem(); item.Id = new CPMMOItemId(client.clubPenguinClient.PlayerSessionId, CPMMOItemId.CPMMOItemParent.PLAYER); item.CreatorId = item.Id.Id; item.Type = type; item.Properties = "{\"actionCount\":" + actionCount + "}"; yield return(null); client.processEvent(GameServerEvent.SERVER_ITEM_ADDED, item); }
private static string GetUniqueIdentifier(PlayerHeldItem item) { switch (item) { case PlayerItem pi: return($"PI/{pi.Id}/{pi.CloudId}"); case BuddyItem bi: // TODO: Remove this, buddy items are never transferable. Gotta provide a better unique id. return($"BI/{bi.BuddyId}/{bi.RemoteItemId}"); case RecipeItem _: return($"RI/{item.BaseRecord}"); case AugmentationItem _: return($"AI/{item.BaseRecord}"); default: return($"UK/{item.BaseRecord}"); } }
private void loadExistingPlayerHeldExperiences(long playerId) { DataEntityHandle[] entitiesByType = dataEntityCollection.GetEntitiesByType <ServerObjectItemData>(); foreach (DataEntityHandle handle in entitiesByType) { ServerObjectItemData component = dataEntityCollection.GetComponent <ServerObjectItemData>(handle); if (component.Item.Id.Parent != 0) { continue; } CPMMOItem item = component.Item; if (!(item is PlayerHeldItem)) { continue; } PlayerHeldItem playerHeldItem = (PlayerHeldItem)item; if (playerHeldItem.CreatorId != playerId) { continue; } DHeldObject dHeldObject = new DHeldObject(); dHeldObject.ObjectId = playerHeldItem.Type; DataEntityHandle dataEntityHandle = ((!dataEntityCollection.IsLocalPlayer(playerId)) ? dataEntityCollection.FindEntity <SessionIdData, long>(playerId) : dataEntityCollection.LocalPlayerHandle); if (!dataEntityHandle.IsNull) { HeldObjectsData component2 = dataEntityCollection.GetComponent <HeldObjectsData>(dataEntityHandle); PrefabContentKey propExperiencePathFromPropId = getPropExperiencePathFromPropId(playerHeldItem.Type); if (propExperiencePathFromPropId != null && !string.IsNullOrEmpty(propExperiencePathFromPropId.Key)) { component2.IsInvitationalExperience = true; CoroutineRunner.Start(loadPlayerHeldExperience(playerHeldItem), this, "loadPlayerHeldExperience"); } component2.HeldObject = dHeldObject; if (propExperiencePathFromPropId != null && !string.IsNullOrEmpty(propExperiencePathFromPropId.Key)) { component2.IsInvitationalExperience = true; } } } }
private void onItemRemoved() { CPDataEntityCollection cPDataEntityCollection = Service.Get <CPDataEntityCollection>(); DHeldObject dHeldObject = null; if (isInvitationLocalPlayer) { dHeldObject = cPDataEntityCollection.GetComponent <HeldObjectsData>(cPDataEntityCollection.LocalPlayerHandle).HeldObject; } else { DataEntityHandle dataEntityHandle = cPDataEntityCollection.FindEntity <SessionIdData, long>(invitingPlayerId); if (!dataEntityHandle.IsNull) { dHeldObject = Service.Get <CPDataEntityCollection>().GetComponent <HeldObjectsData>(dataEntityHandle).HeldObject; } } if (dHeldObject != null) { string text = ""; PlayerHeldItem playerHeldItem = ((serverObjectData == null) ? null : (serverObjectData.Item as PlayerHeldItem)); if (playerHeldItem != null) { text = playerHeldItem.Type; } if (text == dHeldObject.ObjectId) { if (isInvitationLocalPlayer) { cPDataEntityCollection.GetComponent <HeldObjectsData>(cPDataEntityCollection.LocalPlayerHandle).HeldObject = null; } else { DataEntityHandle dataEntityHandle = cPDataEntityCollection.FindEntity <SessionIdData, long>(invitingPlayerId); Service.Get <CPDataEntityCollection>().GetComponent <HeldObjectsData>(dataEntityHandle).HeldObject = null; } } } destroySelf(); }
private IEnumerator loadPlayerHeldExperience(PlayerHeldItem playerHeldItem) { AssetRequest <GameObject> assetRequest = Content.LoadAsync(getPropExperiencePathFromPropId(playerHeldItem.Type)); yield return(assetRequest); GameObject experience = UnityEngine.Object.Instantiate(assetRequest.Asset); PropExperience spawnedExperience = experience.GetComponent <PropExperience>(); if (spawnedExperience != null) { spawnedExperience.InstanceId = playerHeldItem.CreatorId.ToString(); spawnedExperience.OwnerId = playerHeldItem.CreatorId; spawnedExperience.IsOwnerLocalPlayer = dataEntityCollection.LocalPlayerSessionId == playerHeldItem.CreatorId; spawnedExperience.PropDef = Props[playerHeldItem.Type]; GameObject playerObject = getPlayerObject(playerHeldItem.CreatorId); if (!(playerObject == null)) { spawnedExperience.transform.SetParent(playerObject.transform, worldPositionStays: false); spawnedExperience.StartExperience(); } } }
private static JsonItem GetJsonItem(PlayerHeldItem item) { // TODO: Modifiers object[] id = { item.Id, "", "", "", "" }; PlayerItem pi = item as PlayerItem; if (pi != null) { id = new object[] { pi.Id, pi.BaseRecord, pi.PrefixRecord, pi.SuffixRecord, pi.MateriaRecord }; } int type; if (item.IsRecipe) { type = 0; } else if (!string.IsNullOrEmpty(item.Stash)) { type = 1; } else { type = 2; } var json = new JsonItem { BaseRecord = item.BaseRecord, URL = id, Icon = item.Bitmap, Name = PureItemName(item.Name), Quality = item.Rarity, Level = item.MinimumLevel, Socket = GetSocketFromItem(item?.Name), NumItems = item.Count, PetStats = item.PetStats.Select(m => new JsonStat { Label = m.ToString(), Extras = m.Extra?.ToString() }).ToList(), BodyStats = item.BodyStats.Select(m => new JsonStat { Label = m.ToString(), Extras = m.Extra?.ToString() }).ToList(), HeaderStats = item.HeaderStats.Select(m => new JsonStat { Label = m.ToString(), Extras = m.Extra?.ToString() }).ToList(), Type = type, HasRecipe = item.HasRecipe, Buddies = item.Buddies.ToArray(), Skill = item.Skill != null?GetJsonSkill(item.Skill) : null, GreenRarity = item.PrefixRarity }; var modifiedSkills = item.ModifiedSkills; foreach (var modifiedSkill in modifiedSkills) { var translated = modifiedSkill.Translated; foreach (var translatedStat in translated) { json.BodyStats.Add(new JsonStat { Label = translatedStat.ToString(), Extras = translatedStat.Extra?.ToString() }); } if (translated.Count == 0) { Logger.Debug($"Could not translate skill-modifier stats for \"{item.Name}\""); } } return(json); }
private void broadcastUserVariables(User user, ArrayList changedVars = null) { bool flag = getSessionId(user) == mt.ClubPenguinClient.PlayerSessionId; if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.PROTOTYPE.GetKey())) && user.ContainsVariable(SocketUserVars.PROTOTYPE.GetKey())) { PrototypeState prototypeState = default(PrototypeState); prototypeState.id = getSessionId(user); prototypeState.data = JsonMapper.ToObject(user.GetVariable(SocketUserVars.PROTOTYPE.GetKey()).GetStringValue()); mt.triggerEvent(GameServerEvent.PROTOTYPE_STATE, prototypeState); } if (changedVars == null || changedVars.Contains(SocketUserVars.EQUIPPED_OBJECT.GetKey())) { UserVariable variable = user.GetVariable(SocketUserVars.EQUIPPED_OBJECT.GetKey()); UserVariable variable2 = user.GetVariable(SocketUserVars.EQUIPPED_OBJECT_PROPERTIES.GetKey()); if (variable == null) { if (changedVars != null && changedVars.Contains(SocketUserVars.EQUIPPED_OBJECT_PROPERTIES.GetKey()) && variable2 == null) { mt.triggerEvent(GameServerEvent.SERVER_ITEM_REMOVED, new CPMMOItemId(getSessionId(user), CPMMOItemId.CPMMOItemParent.PLAYER)); } else { mt.triggerEvent(GameServerEvent.HELD_OBJECT_DEQUIPPED, getSessionId(user)); } } else { EquippedObject equippedObject = EquippedObject.FromSFSData(variable.GetSFSObjectValue()); if (variable2 != null) { PlayerHeldItem playerHeldItem = new PlayerHeldItem(); playerHeldItem.Id = new CPMMOItemId(getSessionId(user), CPMMOItemId.CPMMOItemParent.PLAYER); playerHeldItem.CreatorId = playerHeldItem.Id.Id; playerHeldItem.Type = equippedObject.EquippedObjectId; playerHeldItem.Properties = variable2.GetStringValue(); mt.triggerEvent(GameServerEvent.SERVER_ITEM_ADDED, playerHeldItem); } else if (!flag || (flag && equippedObject.isPartyGame())) { HeldObjectEvent heldObjectEvent = default(HeldObjectEvent); heldObjectEvent.SessionId = getSessionId(user); heldObjectEvent.Type = equippedObject.EquippedObjectId; if (equippedObject.IsConsumable()) { mt.triggerEvent(GameServerEvent.CONSUMABLE_EQUIPPED, heldObjectEvent); } else if (equippedObject.IsDispensable()) { mt.triggerEvent(GameServerEvent.DISPENSABLE_EQUIPPED, heldObjectEvent); } else if (equippedObject.IsDurable()) { mt.triggerEvent(GameServerEvent.DURABLE_EQUIPPED, heldObjectEvent); } else if (equippedObject.isPartyGame()) { mt.triggerEvent(GameServerEvent.PARTYGAME_EQUIPPED, heldObjectEvent); } } } } else if (changedVars.Contains(SocketUserVars.EQUIPPED_OBJECT_PROPERTIES.GetKey())) { UserVariable variable3 = user.GetVariable(SocketUserVars.EQUIPPED_OBJECT.GetKey()); if (variable3 != null && variable3.Type == VariableType.OBJECT) { PlayerHeldItem playerHeldItem = new PlayerHeldItem(); playerHeldItem.Id = new CPMMOItemId(getSessionId(user), CPMMOItemId.CPMMOItemParent.PLAYER); playerHeldItem.CreatorId = playerHeldItem.Id.Id; playerHeldItem.Type = EquippedObject.FromSFSData(variable3.GetSFSObjectValue()).EquippedObjectId; playerHeldItem.Properties = user.GetVariable(SocketUserVars.EQUIPPED_OBJECT_PROPERTIES.GetKey()).GetStringValue(); mt.triggerEvent(GameServerEvent.SERVER_ITEM_CHANGED, playerHeldItem); } } if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.LOCOMOTION_STATE.GetKey()))) { UserVariable variable4 = user.GetVariable(SocketUserVars.LOCOMOTION_STATE.GetKey()); PlayerLocomotionStateEvent playerLocomotionStateEvent = default(PlayerLocomotionStateEvent); playerLocomotionStateEvent.SessionId = getSessionId(user); if (variable4 == null || variable4.IsNull()) { playerLocomotionStateEvent.State = LocomotionState.Default; } else { playerLocomotionStateEvent.State = (LocomotionState)variable4.GetIntValue(); } mt.triggerEvent(GameServerEvent.USER_LOCO_STATE_CHANGED, playerLocomotionStateEvent); } if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.OUTFIT.GetKey())) && user.ContainsVariable(SocketUserVars.OUTFIT.GetKey())) { PlayerOutfitDetails playerOutfitDetails = mt.JsonService.Deserialize <PlayerOutfitDetails>(user.GetVariable(SocketUserVars.OUTFIT.GetKey()).GetStringValue()); playerOutfitDetails.sessionId = getSessionId(user); mt.triggerEvent(GameServerEvent.USER_OUTFIT_CHANGED, playerOutfitDetails); } if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.PROFILE.GetKey())) && user.ContainsVariable(SocketUserVars.PROFILE.GetKey())) { ProfileEvent profileEvent = default(ProfileEvent); profileEvent.SessionId = getSessionId(user); profileEvent.Profile = new Profile(); profileEvent.Profile.colour = user.GetVariable(SocketUserVars.PROFILE.GetKey()).GetIntValue(); mt.triggerEvent(GameServerEvent.USER_PROFILE_CHANGED, profileEvent); } if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.AIR_BUBBLE.GetKey()))) { UserVariable variable5 = user.GetVariable(SocketUserVars.AIR_BUBBLE.GetKey()); PlayerAirBubbleEvent playerAirBubbleEvent = default(PlayerAirBubbleEvent); playerAirBubbleEvent.SessionId = getSessionId(user); if (variable5 == null || variable5.IsNull()) { playerAirBubbleEvent.AirBubble = new AirBubble(); } else { playerAirBubbleEvent.AirBubble = AirBubble.FromSFSData(variable5.GetSFSObjectValue()); } mt.triggerEvent(GameServerEvent.AIR_BUBBLE_UPDATE, playerAirBubbleEvent); } if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.ON_QUEST.GetKey()))) { UserVariable variable4 = user.GetVariable(SocketUserVars.ON_QUEST.GetKey()); OnQuestState onQuestState = default(OnQuestState); onQuestState.SessionId = getSessionId(user); if (!(variable4?.IsNull() ?? true)) { onQuestState.MascotName = variable4.GetStringValue(); } mt.triggerEvent(GameServerEvent.ON_QUEST, onQuestState); } if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.SELECTED_TUBE.GetKey())) && user.ContainsVariable(SocketUserVars.SELECTED_TUBE.GetKey())) { SelectedTubeEvent selectedTubeEvent = default(SelectedTubeEvent); selectedTubeEvent.SessionId = getSessionId(user); selectedTubeEvent.TubeId = user.GetVariable(SocketUserVars.SELECTED_TUBE.GetKey()).GetIntValue(); mt.triggerEvent(GameServerEvent.SELECTED_TUBE_CHANGED, selectedTubeEvent); } if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.TEMPORARY_HEAD_STATUS.GetKey())) && user.ContainsVariable(SocketUserVars.TEMPORARY_HEAD_STATUS.GetKey())) { TemporaryHeadStatusEvent temporaryHeadStatusEvent = default(TemporaryHeadStatusEvent); temporaryHeadStatusEvent.SessionId = getSessionId(user); temporaryHeadStatusEvent.Type = user.GetVariable(SocketUserVars.TEMPORARY_HEAD_STATUS.GetKey()).GetIntValue(); mt.triggerEvent(GameServerEvent.TEMPORARY_HEAD_STATUS_CHANGED, temporaryHeadStatusEvent); } if (flag || (changedVars != null && !changedVars.Contains(SocketUserVars.AWAY_FROM_KEYBOARD.GetKey()))) { return; } UserVariable variable6 = user.GetVariable(SocketUserVars.AWAY_FROM_KEYBOARD.GetKey()); if (variable6 == null || variable6.IsNull()) { EquippedObject equippedObject2 = null; UserVariable variable7 = user.GetVariable(SocketUserVars.EQUIPPED_OBJECT.GetKey()); if (variable7 != null) { equippedObject2 = EquippedObject.FromSFSData(variable7.GetSFSObjectValue()); } mt.triggerEvent(GameServerEvent.AWAY_FROM_KEYBOARD_STATE_CHANGED, new AFKEvent(getSessionId(user), 0, equippedObject2)); } else { mt.triggerEvent(GameServerEvent.AWAY_FROM_KEYBOARD_STATE_CHANGED, new AFKEvent(getSessionId(user), variable6.GetIntValue(), null)); } }
private bool IsBuddyItem(PlayerHeldItem item) { return(!string.IsNullOrEmpty(item.Stash) && !item.IsRecipe); }
private static JsonItem GetJsonItem(PlayerHeldItem item) { // TODO: Modifiers bool isCloudSynced = false; object[] id = { item.Id, "", "", "", "" }; if (item is PlayerItem pi) { id = new object[] { pi.Id, pi.BaseRecord, pi.PrefixRecord, pi.SuffixRecord, pi.MateriaRecord }; isCloudSynced = !string.IsNullOrWhiteSpace(pi.AzureUuid); } ItemTypeDto type; string extras = string.Empty; if (item.IsRecipe) { type = ItemTypeDto.Recipe; } else if (!string.IsNullOrEmpty(item.Stash)) { type = ItemTypeDto.Buddy; } else if (item is PlayerItem) { type = ItemTypeDto.Player; } else if (item is AugmentationItem) { type = ItemTypeDto.Augmentation; extras = ItemOperationsUtility.TranslateFaction( GlobalSettings.Language, ((AugmentationItem)item).Tags.FirstOrDefault(m => m.Stat == "factionSource")?.TextValue ?? string.Empty ); } else { type = ItemTypeDto.Unknown; } var json = new JsonItem { BaseRecord = item.BaseRecord ?? string.Empty, URL = id, Icon = item.Bitmap ?? string.Empty, Name = PureItemName(item.Name) ?? string.Empty, Quality = item.Rarity ?? string.Empty, Level = item.MinimumLevel, Socket = GetSocketFromItem(item?.Name) ?? string.Empty, NumItems = item.Count, PetStats = item.PetStats.Select(m => new JsonStat { Label = m.ToString(), Extras = m.Extra?.ToString() }).ToList(), BodyStats = item.BodyStats.Select(m => new JsonStat { Label = m.ToString(), Extras = m.Extra?.ToString() }).ToList(), HeaderStats = item.HeaderStats.Select(m => new JsonStat { Label = m.ToString(), Extras = m.Extra?.ToString() }).ToList(), Type = type, HasRecipe = item.HasRecipe, Buddies = item.Buddies.ToArray(), Skill = item.Skill != null?GetJsonSkill(item.Skill) : null, GreenRarity = item.PrefixRarity, HasCloudBackup = isCloudSynced, Slot = SlotTranslator.Translate(GlobalSettings.Language, item.Slot ?? ""), Extras = extras }; var modifiedSkills = item.ModifiedSkills; foreach (var modifiedSkill in modifiedSkills) { var translated = modifiedSkill.Translated; foreach (var translatedStat in translated) { json.BodyStats.Add(new JsonStat { Label = translatedStat.ToString(), Extras = translatedStat.Extra?.ToString() }); } if (translated.Count == 0) { Logger.Debug($"Could not translate skill-modifier stats for \"{item.Name}\""); } } return(json); }
public static JsonItem GetJsonItem(PlayerHeldItem item) { // TODO: Modifiers bool isCloudSynced = false; object[] transferUrl = { "", "", "", "" }; string uniqueIdentifier; if (item is PlayerItem pi) { transferUrl = new object[] { pi.BaseRecord, pi.PrefixRecord, pi.SuffixRecord, pi.MateriaRecord }; isCloudSynced = pi.IsCloudSynchronized; uniqueIdentifier = $"PI/{pi.Id}/{pi.CloudId}"; } else if (item is BuddyItem bi) { // TODO: Remove this, buddy items are never transferable. Gotta provide a better unique id. uniqueIdentifier = $"BI/{bi.BuddyId}/{bi.RemoteItemId}"; } else if (item is RecipeItem) { uniqueIdentifier = $"RI/{item.BaseRecord}"; } else if (item is AugmentationItem) { uniqueIdentifier = $"AI/{item.BaseRecord}"; } else { uniqueIdentifier = $"UK/{item.BaseRecord}"; } ItemTypeDto type; string extras = string.Empty; if (item.IsRecipe) { type = ItemTypeDto.Recipe; } else if (!string.IsNullOrEmpty(item.Stash)) { type = ItemTypeDto.Buddy; } else if (item is PlayerItem) { type = ItemTypeDto.Player; } else if (item is AugmentationItem augmentationItem) { type = ItemTypeDto.Augmentation; extras = ItemOperationsUtility.TranslateFaction( RuntimeSettings.Language, augmentationItem.Tags.FirstOrDefault(m => m.Stat == "factionSource")?.TextValue ?? string.Empty ); } else { type = ItemTypeDto.Unknown; } var json = new JsonItem { UniqueIdentifier = uniqueIdentifier, BaseRecord = item.BaseRecord ?? string.Empty, URL = transferUrl, Icon = item.Bitmap ?? string.Empty, Name = PureItemName(item.Name) ?? string.Empty, Quality = item.Rarity ?? string.Empty, Level = item.MinimumLevel, Socket = GetSocketFromItem(item?.Name) ?? string.Empty, NumItems = (uint)item.Count, InitialNumItems = (uint)item.Count, PetStats = item.PetStats.Select(ToJsonStat).ToHashSet().ToList(), BodyStats = item.BodyStats.Select(ToJsonStat).ToHashSet().ToList(), HeaderStats = item.HeaderStats.Select(ToJsonStat).ToHashSet().ToList(), Type = type, HasRecipe = item.HasRecipe, Buddies = item.Buddies.ToArray(), Skill = item.Skill != null?GetJsonSkill(item.Skill) : null, GreenRarity = (int)item.PrefixRarity, HasCloudBackup = isCloudSynced, Slot = SlotTranslator.Translate(RuntimeSettings.Language, item.Slot ?? ""), Extras = extras, IsMonsterInfrequent = item.ModifiedSkills.Any(s => s.IsMonsterInfrequent), }; var modifiedSkills = item.ModifiedSkills; foreach (var modifiedSkill in modifiedSkills) { var translated = modifiedSkill.Translated; foreach (var stat in translated.Select(ToJsonStat)) { json.BodyStats.Add(stat); } if (translated.Count == 0 && !(modifiedSkill.Class == null || modifiedSkill.Tier == null)) { string[] uri = json.URL.Select(o => o.ToString()).ToArray(); var error = $@"Could not translate skill-modifier on: '{item.Name}', {json.BaseRecord} - {string.Join(";", uri)}"; ExceptionReporter.ReportIssue(error); Logger.Debug($"Could not translate skill-modifier stats for \"{item.Name}\""); } } return(json); }
private static JsonItem GetJsonItem(PlayerHeldItem item) { // TODO: Modifiers bool isHardcore = false; bool isCloudSynced = false; object[] transferUrl = { "", "", "", "" }; string uniqueIdentifier = GetUniqueIdentifier(item); List <ItemStatInfo> replicaStats = null; var mergeIdentifier = item.BaseRecord ?? string.Empty; if (item is PlayerItem pi) { transferUrl = new object[] { pi.BaseRecord, pi.PrefixRecord, pi.SuffixRecord, pi.MateriaRecord, pi.Mod, pi.IsHardcore }; isCloudSynced = pi.IsCloudSynchronized; isHardcore = pi.IsHardcore; if (!string.IsNullOrEmpty(pi.ReplicaInfo)) { replicaStats = JsonConvert.DeserializeObject <List <ItemStatInfo> >(pi.ReplicaInfo); } mergeIdentifier += (pi.PrefixRecord ?? string.Empty) + (pi.SuffixRecord ?? string.Empty); } else if (item is BuddyItem bi) { mergeIdentifier += (bi.PrefixRecord ?? string.Empty) + (bi.SuffixRecord ?? string.Empty); if (!string.IsNullOrEmpty(bi.ReplicaInfo)) { replicaStats = JsonConvert.DeserializeObject <List <ItemStatInfo> >(bi.ReplicaInfo); } } ItemTypeDto type; string extras = item.Stash; if (item.IsRecipe) { type = ItemTypeDto.Recipe; } else if (!string.IsNullOrEmpty(item.Stash)) { type = ItemTypeDto.Buddy; } else if (item is PlayerItem) { type = ItemTypeDto.Player; } else if (item is AugmentationItem augmentationItem) { type = ItemTypeDto.Augmentation; extras = ItemOperationsUtility.TranslateFaction( RuntimeSettings.Language, augmentationItem.Tags.FirstOrDefault(m => m.Stat == "factionSource")?.TextValue ?? string.Empty ); } else { type = ItemTypeDto.Unknown; } bool skipStats = replicaStats != null; var replicaBodyStats = new List <JsonStat>(0); if (skipStats) { // Add skillz replicaBodyStats = item.BodyStats .Where(m => m.Extra != null) .Select(ToJsonStat) .ToHashSet() .ToList(); } var json = new JsonItem { UniqueIdentifier = uniqueIdentifier, MergeIdentifier = mergeIdentifier, BaseRecord = item.BaseRecord ?? string.Empty, URL = transferUrl, Icon = item.Bitmap ?? string.Empty, Name = PureItemName(item.Name) ?? string.Empty, Quality = item.Rarity ?? string.Empty, Level = item.MinimumLevel, Socket = GetSocketFromItem(item?.Name) ?? string.Empty, PetStats = skipStats ? new List <JsonStat>() : item.PetStats.Select(ToJsonStat).ToHashSet().ToList(), BodyStats = skipStats ? replicaBodyStats : item.BodyStats.Select(ToJsonStat).ToHashSet().ToList(), HeaderStats = skipStats ? new List <JsonStat>() : item.HeaderStats.Select(ToJsonStat).ToHashSet().ToList(), Type = type, HasRecipe = item.HasRecipe, Skill = (item.Skill != null && !skipStats) ? GetJsonSkill(item.Skill) : null, GreenRarity = (int)item.PrefixRarity, HasCloudBackup = isCloudSynced, Slot = SlotTranslator.Translate(RuntimeSettings.Language, item.Slot ?? ""), Extras = extras, IsMonsterInfrequent = item.ModifiedSkills.Any(s => s.IsMonsterInfrequent), IsHardcore = isHardcore, ReplicaStats = replicaStats, }; if (!skipStats) { var modifiedSkills = item.ModifiedSkills; foreach (var modifiedSkill in modifiedSkills) { var translated = modifiedSkill.Translated; foreach (var stat in translated.Select(ToJsonStat)) { json.BodyStats.Add(stat); } } } return(json); }