Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/NosCore.Data/Enumerations/I18N/LanguageKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
// | \| |/__\ /' _/ / _//__\| _ \ __|
// | | ' | \/ |`._`.| \_| \/ | v / _|
// |_|\__|\__/ |___/ \__/\__/|_|_\___|
//
//
// Copyright (C) 2019 - NosCore
//
//
// NosCore is a free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

Expand Down Expand Up @@ -166,7 +166,8 @@ public enum LogLanguageKey
CHARACTER_SELECTION_FAILED,
ALREADY_CONNECTED,
PACKET_HANDLING_ERROR,
MFA_INCORRECT
MFA_INCORRECT,
UPGRADE_PACKET_SLOT2_NULL
}

[SuppressMessage("ReSharper", "InconsistentNaming")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
// | \| |/__\ /' _/ / _//__\| _ \ __|
// | | ' | \/ |`._`.| \_| \/ | v / _|
// |_|\__|\__/ |___/ \__/\__/|_|_\___|
//
//
// Copyright (C) 2019 - NosCore
//
//
// NosCore is a free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

Expand All @@ -29,19 +29,28 @@ public interface IInventoryService : IDictionary<Guid, InventoryItemInstance>
Dictionary<NoscorePocketType, byte> Expensions { get; set; }

List<InventoryItemInstance>? AddItemToPocket(InventoryItemInstance newItem);

List<InventoryItemInstance>? AddItemToPocket(InventoryItemInstance newItem, NoscorePocketType? type);

List<InventoryItemInstance>?
AddItemToPocket(InventoryItemInstance newItem, NoscorePocketType? type, short? slot);

bool CanAddItem(short itemVnum);

int CountItem(int itemVNum);

int CountItemInAnPocket(NoscorePocketType inv);

InventoryItemInstance? DeleteById(Guid id);

InventoryItemInstance? DeleteFromTypeAndSlot(NoscorePocketType type, short slot);

InventoryItemInstance? LoadByItemInstanceId(Guid id);

InventoryItemInstance? LoadBySlotAndType(short slot, NoscorePocketType type);

List<InventoryItemInstance?> LoadByVNumAndAmount(short vnum, short amount);

InventoryItemInstance? MoveInPocket(short sourceSlot, NoscorePocketType sourceType,
NoscorePocketType targetType);

Expand All @@ -52,6 +61,9 @@ bool TryMoveItem(NoscorePocketType sourcetype, short sourceSlot, short amount, s
out InventoryItemInstance? sourcePocket, out InventoryItemInstance? destinationPocket);

bool EnoughPlace(List<IItemInstance> itemInstances, NoscorePocketType type);

InventoryItemInstance? RemoveItemAmountFromInventory(short amount, Guid id);

List<InventoryItemInstance?> RemoveItemAmountFromInventory(short amount, short vnum);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don’t need that if you have the load by vnum and amount

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
// | \| |/__\ /' _/ / _//__\| _ \ __|
// | | ' | \/ |`._`.| \_| \/ | v / _|
// |_|\__|\__/ |___/ \__/\__/|_|_\___|
//
//
// Copyright (C) 2019 - NosCore
//
//
// NosCore is a free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All those comment change make it harder to review

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

Expand Down Expand Up @@ -84,6 +84,25 @@ private byte GetMaxSlot(NoscorePocketType pocket)
return retItem;
}

public List<InventoryItemInstance?> LoadByVNumAndAmount(short vnum, short amount)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if we need the amount getting all the item for a vnum is perfectly fine

{
var result = new List<InventoryItemInstance?>();
if (CountItem(vnum) < amount)
{
return result;
}
foreach (var item in this.Select(s => s.Value).OrderByDescending(o => o.Slot).Where(w => w.ItemInstance!.ItemVNum == vnum).ToList())
{
result.Add(item);
amount -= item.ItemInstance!.Amount;
if (amount <= 0)
{
break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return instead of break

}
}
return result;
}

public bool CanAddItem(short itemVnum)
{
var type = _items.Find(item => item.VNum == itemVnum)?.Type;
Expand Down Expand Up @@ -369,6 +388,7 @@ public bool TryMoveItem(NoscorePocketType sourcetype, short sourceSlot, short am
case null when sourcePocket.ItemInstance.Amount == amount:
sourcePocket.Slot = destinationSlot;
break;

case null:
var itemDest = (IItemInstance)sourcePocket.ItemInstance.Clone();
sourcePocket.ItemInstance.Amount -= amount;
Expand All @@ -384,6 +404,7 @@ public bool TryMoveItem(NoscorePocketType sourcetype, short sourceSlot, short am
ItemInstanceId = itemDest.Id
}, sourcetype, destinationSlot);
break;

default:
if ((destinationPocket.ItemInstance?.ItemVNum == sourcePocket.ItemInstance.ItemVNum)
&& ((sourcePocket.ItemInstance.Item!.Type == NoscorePocketType.Main) ||
Expand Down Expand Up @@ -486,6 +507,23 @@ public bool EnoughPlace(List<IItemInstance> itemInstances, NoscorePocketType typ
return null;
}

public List<InventoryItemInstance?> RemoveItemAmountFromInventory(short amount, short vnum)
{
var result = new List<InventoryItemInstance?>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole thing is useless

if (CountItem(vnum) < amount)
{
return result;
}
while (amount != 0)
{
var item = this.OrderByDescending(o => o.Value.Slot).Where(w => w.Value.ItemInstance!.ItemVNum == vnum).FirstOrDefault();
var removedItem = RemoveItemAmountFromInventory(amount, item.Key);
amount -= removedItem != null ? amount : (short)(item.Value.ItemInstance!.Amount + amount);
result.Add(removedItem);
}
return result;
}

private short? GetFreeSlot(NoscorePocketType type)
{
var itemInstanceSlotsByType = this.Select(s => s.Value).Where(i => i.Type == type).OrderBy(i => i.Slot)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
// | \| |/__\ /' _/ / _//__\| _ \ __|
// | | ' | \/ |`._`.| \_| \/ | v / _|
// |_|\__|\__/ |___/ \__/\__/|_|_\___|
//
//
// Copyright (C) 2019 - NosCore
//
//
// NosCore is a free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

Expand All @@ -37,6 +37,7 @@ public class ItemGenerationService : IItemGenerationService
private readonly IEventLoaderService<Item.Item, Tuple<InventoryItemInstance, UseItemPacket>>? _runner;
private readonly List<ItemDto> _items;
private readonly ILogger _logger;

public ItemGenerationService(List<ItemDto> items, ILogger logger)
{
_items = items;
Expand Down Expand Up @@ -126,20 +127,47 @@ public IItemInstance Generate(short itemToCreateVNum, short amount, sbyte rare,
Design = design,
Upgrade = upgrade
};

case ItemType.Box:
return new BoxInstance(itemToCreate)
{
Amount = amount,
Upgrade = upgrade,
Design = design
};

default:
var wear = new WearableInstance(itemToCreate, _logger)
{
Amount = amount,
Rare = rare,
Upgrade = upgrade,
Design = design
Design = design,
Ammo = itemToCreate.MaximumAmmo,
Cellon = itemToCreate.CellonLvl,
CloseDefence = itemToCreate.CloseDefence,
Concentrate = itemToCreate.Concentrate,
CriticalLuckRate = itemToCreate.CriticalLuckRate,
CriticalRate = itemToCreate.CriticalRate,
DamageMaximum = itemToCreate.DamageMaximum,
DamageMinimum = itemToCreate.DamageMinimum,
DarkElement = itemToCreate.DarkElement,
DarkResistance = itemToCreate.DarkResistance,
DefenceDodge = itemToCreate.DefenceDodge,
DistanceDefence = itemToCreate.DistanceDefence,
DistanceDefenceDodge = itemToCreate.DistanceDefenceDodge,
ElementRate = itemToCreate.ElementRate,
FireElement = itemToCreate.FireElement,
FireResistance = itemToCreate.FireResistance,
HitRate = itemToCreate.HitRate,
Hp = itemToCreate.Hp,
LightElement = itemToCreate.LightElement,
LightResistance = itemToCreate.LightResistance,
MagicDefence = itemToCreate.MagicDefence,
MaxElementRate = itemToCreate.MaxElementRate,
Mp = itemToCreate.Mp,
WaterElement = itemToCreate.WaterElement,
WaterResistance = itemToCreate.WaterResistance
};
if (wear.Rare > 0)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using NosCore.GameObject.ComponentEntities.Interfaces;
using NosCore.GameObject.Networking.ClientSession;
using NosCore.Packets.ClientPackets.Npcs;
using NosCore.Packets.Enumerations;
using NosCore.Packets.ServerPackets.UI;
using System;
using System.Threading.Tasks;

namespace NosCore.GameObject.Services.NRunService.Handlers
{
public class ProbabilityUIHandler : INrunEventHandler
{
public bool Condition(Tuple<IAliveEntity, NrunPacket> datas)
{
return datas.Item2.Runner == NrunRunnerType.ProbabilityUIs;
}

public Task ExecuteAsync(RequestData<Tuple<IAliveEntity, NrunPacket>> requestData)
{
return requestData.ClientSession.SendPacketAsync(
new WopenPacket
{
Type = (WindowType)(requestData.Data.Item2.Type ?? 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we just want a simple cast we might check it’s defined also not sure 0 is a good fallback value we should maybe log an error and return

});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// __ _ __ __ ___ __ ___ ___
// | \| |/__\ /' _/ / _//__\| _ \ __|
// | | ' | \/ |`._`.| \_| \/ | v / _|
// |_|\__|\__/ |___/ \__/\__/|_|_\___|
//
// Copyright (C) 2019 - NosCore
//
// NosCore is a free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using NosCore.GameObject.Networking.ClientSession;
using NosCore.GameObject.Services.InventoryService;
using NosCore.Packets.Interfaces;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace NosCore.GameObject.Services.UpgradeService
{
public interface ISumUpgradeService
{
Task<List<IPacket>> SumItemInstanceAsync(ClientSession session, InventoryItemInstance? sourceSlot, InventoryItemInstance? targetSlot);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn’t need a client session also it should return a new InventoryItemInstance not a packet

}
}
Loading