Skip to content

Commit

Permalink
Add logic for crafting items from shops
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Apr 5, 2022
1 parent 89f6d9a commit bbd72f1
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 48 deletions.
107 changes: 61 additions & 46 deletions EndlessClient/Dialogs/ShopDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,55 +350,70 @@ void ConfirmAndExecuteTrade(int amount)

private void CraftItem(object sender, EventArgs e)
{
var listItemIndex = ((ListDialogItem)sender).Index;
if (_state != ShopState.Crafting)
return;

var listItemIndex = ((ListDialogItem)sender).Index + _scrollBar.ScrollOffset;

if (listItemIndex >= _craftItems.Count)
return;

// todo: move some of this stuff into a controller class?
var craftItem = _craftItems[listItemIndex];
var data = _eifFileProvider.EIFFile[craftItem.ID];

//if (m_state != ShopState.Crafting)
// return;

//var craftItemRec = OldWorld.Instance.EIF[item.ID];
//// ReSharper disable once LoopCanBeConvertedToQuery
//foreach (var ingredient in item.Ingredients)
//{
// if (OldWorld.Instance.MainPlayer.ActiveCharacter.Inventory.FindIndex(_item => _item.ItemID == ingredient.Item1 && _item.Amount >= ingredient.Item2) < 0)
// {
// string _message = OldWorld.GetString(EOResourceID.DIALOG_SHOP_CRAFT_MISSING_INGREDIENTS) + "\n\n";
// foreach (var ingred in item.Ingredients)
// {
// var localRec = OldWorld.Instance.EIF[ingred.Item1];
// _message += $"+ {ingred.Item2} {localRec.Name}\n";
// }
// string _caption =
// $"{OldWorld.GetString(EOResourceID.DIALOG_SHOP_CRAFT_INGREDIENTS)} {OldWorld.GetString(EOResourceID.DIALOG_WORD_FOR)} {craftItemRec.Name}";
// EOMessageBox.Show(_message, _caption, EODialogButtons.Cancel, EOMessageBoxStyle.LargeDialogSmallHeader);
// return;
// }
//}

//if (!EOGame.Instance.Hud.InventoryFits((short)item.ID))
//{
// EOMessageBox.Show(OldWorld.GetString(EOResourceID.DIALOG_TRANSFER_NOT_ENOUGH_SPACE),
// OldWorld.GetString(EOResourceID.STATUS_LABEL_TYPE_WARNING),
// EODialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader);
// return;
//}

//string _message2 = OldWorld.GetString(EOResourceID.DIALOG_SHOP_CRAFT_PUT_INGREDIENTS_TOGETHER) + "\n\n";
//foreach (var ingred in item.Ingredients)
//{
// var localRec = OldWorld.Instance.EIF[ingred.Item1];
// _message2 += $"+ {ingred.Item2} {localRec.Name}\n";
//}
//string _caption2 =
// $"{OldWorld.GetString(EOResourceID.DIALOG_SHOP_CRAFT_INGREDIENTS)} {OldWorld.GetString(EOResourceID.DIALOG_WORD_FOR)} {craftItemRec.Name}";
//EOMessageBox.Show(_message2, _caption2, EODialogButtons.OkCancel, EOMessageBoxStyle.LargeDialogSmallHeader, (o, e) =>
//{
// if (e.Result == XNADialogResult.OK && !m_api.CraftItem((short)item.ID))
// {
// EOGame.Instance.DoShowLostConnectionDialogAndReturnToMainMenu();
// }
//});
// todo: move this stuff into a validator class?
foreach (var ingredient in craftItem.Ingredients)
{
if (!_characterInventoryProvider.ItemInventory.Any(x => x.ItemID == ingredient.ID && x.Amount >= ingredient.Amount))
{
var message = BuildMessage(EOResourceID.DIALOG_SHOP_CRAFT_MISSING_INGREDIENTS);
var caption = BuildCaption(EOResourceID.DIALOG_SHOP_CRAFT_INGREDIENTS);

var dlg = _messageBoxFactory.CreateMessageBox(message, caption, EODialogButtons.Cancel, EOMessageBoxStyle.LargeDialogSmallHeader);
dlg.ShowDialog();

return;
}
}

if (!_inventorySpaceValidator.ItemFits(data.Size))
{
var msg = _messageBoxFactory.CreateMessageBox(EOResourceID.DIALOG_TRANSFER_NOT_ENOUGH_SPACE, EOResourceID.STATUS_LABEL_TYPE_WARNING);
msg.ShowDialog();
return;
}

var message2 = BuildMessage(EOResourceID.DIALOG_SHOP_CRAFT_PUT_INGREDIENTS_TOGETHER);
var caption2 = BuildCaption(EOResourceID.DIALOG_SHOP_CRAFT_INGREDIENTS);

var dlg2 = _messageBoxFactory.CreateMessageBox(message2, caption2, EODialogButtons.OkCancel, EOMessageBoxStyle.LargeDialogSmallHeader);
dlg2.DialogClosing += (o, e) =>
{
if (e.Result == XNADialogResult.Cancel)
return;

_shopActions.CraftItem((short)craftItem.ID);
};
dlg2.ShowDialog();

string BuildMessage(EOResourceID resource)
{
var message = _localizedStringFinder.GetString(resource) + "\n\n";

foreach (var ingred in craftItem.Ingredients)
{
var ingredData = _eifFileProvider.EIFFile[ingred.ID];
message += $"+ {ingred.Amount} {ingredData.Name}\n";
}

return message;
}

string BuildCaption(EOResourceID resource)
{
return $"{_localizedStringFinder.GetString(resource)} {_localizedStringFinder.GetString(EOResourceID.DIALOG_WORD_FOR)} {data.Name}";
}
}
}
}
2 changes: 1 addition & 1 deletion EndlessClient/EndlessClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@
<PackageReference Include="Monogame.Content.Builder.Task" Version="3.8.0.1641" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="6.0.0" />
<PackageReference Include="XNAControls" Version="1.3.4" />
<PackageReference Include="XNAControls" Version="1.3.5" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Ethan Moffat
Copyright (c) 2014-2022 Ethan Moffat

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down

0 comments on commit bbd72f1

Please sign in to comment.