Skip to content

Commit

Permalink
Implement costume display in avatar library
Browse files Browse the repository at this point in the history
  • Loading branch information
Crypto137 committed Feb 16, 2024
1 parent f67198a commit 5c08ff9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
48 changes: 32 additions & 16 deletions src/MHServerEmu/Billing/BillingService.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System.Text.Json;
using Gazillion;
using Gazillion;
using MHServerEmu.Billing.Catalogs;
using MHServerEmu.Common.Config;
using MHServerEmu.Common.Helpers;
using MHServerEmu.Common.Logging;
using MHServerEmu.Frontend;
using MHServerEmu.Games.Entities.Avatars;
using MHServerEmu.Games.GameData;
using MHServerEmu.Games.GameData.Prototypes;
using MHServerEmu.Games.Properties;
using MHServerEmu.Networking;
using MHServerEmu.PlayerManagement.Accounts.DBModels;

namespace MHServerEmu.Billing
{
Expand Down Expand Up @@ -102,24 +103,39 @@ private void OnBuyItemFromCatalog(FrontendClient client, NetMessageBuyItemFromCa
Logger.Trace(buyItemFromCatalog.ToString());

// HACK: change costume when a player "buys" a costume
DBAvatar currentAvatar = client.Session.Account.CurrentAvatar;

CatalogEntry entry = _catalog.GetEntry(buyItemFromCatalog.SkuId);
if (entry != null && entry.GuidItems.Length > 0)
if (entry == null && entry.GuidItems.Length == 0) return;

var costumePrototype = entry.GuidItems[0].ItemPrototypeRuntimeIdForClient.As<CostumePrototype>();
if (costumePrototype == null || costumePrototype.UsableBy != (PrototypeId)currentAvatar.Prototype)
{
string prototypePath = GameDatabase.GetPrototypeName(entry.GuidItems[0].ItemPrototypeRuntimeIdForClient);
if (prototypePath.Contains("Entity/Items/Costumes/Prototypes/"))
{
// Get replication id for the client avatar
ulong replicationId = (ulong)client.Session.Account.Player.Avatar.ToPropertyCollectionReplicationId();
client.SendMessage(MuxChannel, new(NetMessageBuyItemFromCatalogResponse.CreateBuilder()
.SetDidSucceed(false)
.SetCurrentCurrencyBalance(ConfigManager.Billing.CurrencyBalance)
.SetErrorcode(BuyItemResultErrorCodes.BUY_RESULT_ERROR_UNKNOWN)
.SetSkuId(buyItemFromCatalog.SkuId)
.Build()));
return;
}

// Update account data
client.Session.Account.CurrentAvatar.Costume = (ulong)entry.GuidItems[0].ItemPrototypeRuntimeIdForClient;
// Get replication id for the client avatar
ulong replicationId = (ulong)currentAvatar.Prototype.ToPropertyCollectionReplicationId();

// Send NetMessageSetProperty message with a CostumeCurrent property for the purchased costume
client.SendMessage(MuxChannel, new(
Property.ToNetMessageSetProperty(replicationId, new(PropertyEnum.CostumeCurrent), entry.GuidItems[0].ItemPrototypeRuntimeIdForClient)
));
}
}
currentAvatar.Costume = (ulong)costumePrototype.DataRef;

// Send NetMessageSetProperty message with a CostumeCurrent property for the purchased costume
client.SendMessage(MuxChannel, new(
Property.ToNetMessageSetProperty(replicationId, new(PropertyEnum.CostumeCurrent), entry.GuidItems[0].ItemPrototypeRuntimeIdForClient)
));

// Update library
int enumValue = GameDatabase.DataDirectory.GetPrototypeEnumValue(
(PrototypeId)currentAvatar.Prototype, (BlueprintId)719040976634384588); // Avatar.blueprint

client.SendMessage(MuxChannel, new(
Property.ToNetMessageSetProperty(9078332, new(PropertyEnum.AvatarLibraryCostume, 0, enumValue), costumePrototype.DataRef)));

client.SendMessage(MuxChannel, new(NetMessageBuyItemFromCatalogResponse.CreateBuilder()
.SetDidSucceed(true)
Expand Down
9 changes: 8 additions & 1 deletion src/MHServerEmu/Games/Game.Loading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,19 @@ private GameMessage[] LoadPlayerEntityMessages(DBAccount account)
case PropertyEnum.AvatarLibraryLevel: // Set all avatar levels to 60
player.PropertyCollection[property.Id] = 60;
break;
case PropertyEnum.AvatarLibraryCostume: // Reset the costume to default
//case PropertyEnum.AvatarLibraryCostume: // Reset the costume to default
case PropertyEnum.AvatarLibraryTeamUp: // Clean up team ups
player.PropertyCollection[property.Id] = 0ul;
break;
}
}

// Set library costumes according to account data
foreach (var accountAvatar in account.Avatars)
{
int enumValue = GameDatabase.DataDirectory.GetPrototypeEnumValue((PrototypeId)accountAvatar.Prototype, (BlueprintId)719040976634384588); // Avatar.blueprint
player.PropertyCollection[PropertyEnum.AvatarLibraryCostume, 0, enumValue] = (PrototypeId)accountAvatar.Costume;
}

CommunityMember friend = player.Community.CommunityMemberList[0];
friend.MemberName = "DavidBrevik";
Expand Down

0 comments on commit 5c08ff9

Please sign in to comment.