-
-
Notifications
You must be signed in to change notification settings - Fork 72
Add : Sum upgrade system #1476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add : Sum upgrade system #1476
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
| // | ||
| // | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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/>. | ||
|
|
||
|
|
@@ -84,6 +84,25 @@ private byte GetMaxSlot(NoscorePocketType pocket) | |
| return retItem; | ||
| } | ||
|
|
||
| public List<InventoryItemInstance?> LoadByVNumAndAmount(short vnum, short amount) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
|
@@ -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; | ||
|
|
@@ -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) || | ||
|
|
@@ -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?>(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
||
| 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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| } | ||
| } | ||
There was a problem hiding this comment.
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