suriyun-production / mmorpg-kit-docs

This is document for MMORPG KIT project (https://www.assetstore.unity3d.com/#!/content/110188?aid=1100lGeN)
https://suriyun-production.github.io/mmorpg-kit-docs
49 stars 11 forks source link

[Question]Queued Workbench #2305

Closed moepi2k closed 11 months ago

moepi2k commented 11 months ago

Hello, i try to modify the Queued Workbench so that the queue list is only for local player instead of global, so it wont block other players to use the workbench.

can u lead me in the right direction to do it? i assume in the CraftingQueueSourceExtensions.cs

i need to modify the

public static bool AppendCraftingQueueItem(this ICraftingQueueSource source, IPlayerCharacterData crafter, uint crafterId, int dataId, int amount, out UITextKeys errorMessage)
{
    errorMessage = UITextKeys.NONE;
    if (!source.CanCraft)
        return false;
    ItemCraftFormula itemCraftFormula;
    if (!GameInstance.ItemCraftFormulas.TryGetValue(dataId, out itemCraftFormula))
        return false;
    if (!itemCraftFormula.ItemCraft.CanCraft(crafter, out errorMessage))
        return false;
    if (source.QueueItems.Count >= source.MaxQueueSize)
        return false;
    source.QueueItems.Add(new CraftingQueueItem()
    {
        crafterId = crafterId,
        dataId = dataId,
        amount = amount,
        craftRemainsDuration = itemCraftFormula.CraftDuration,
    });
    return true;
}

to eg something like this?

public static bool AppendCraftingQueueItem(this ICraftingQueueSource source, IPlayerCharacterData crafter, uint crafterId, int dataId, int amount, out UITextKeys errorMessage)
{
    errorMessage = UITextKeys.NONE;
    if (!source.CanCraft)
        return false;
    ItemCraftFormula itemCraftFormula;
    if (!GameInstance.ItemCraftFormulas.TryGetValue(dataId, out itemCraftFormula))
        return false;
    if (!itemCraftFormula.ItemCraft.CanCraft(crafter, out errorMessage))
        return false;

    // Check if the player already has a queue, if not, create one
    if (!source.PlayerSpecificQueues.ContainsKey(crafterId))
        source.PlayerSpecificQueues[crafterId] = new List<CraftingQueueItem>();

    var playerQueue = source.PlayerSpecificQueues[crafterId];
    if (playerQueue.Count >= source.MaxQueueSize)
        return false;

    playerQueue.Add(new CraftingQueueItem()
    {
        crafterId = crafterId,
        dataId = dataId,
        amount = amount,
        craftRemainsDuration = itemCraftFormula.CraftDuration,
    });
    return true;
}
LordPhrozen commented 11 months ago

That would be fantastic.

insthync commented 11 months ago

Create a new component which implements ICraftingQueueSource and will be attached to player entity, you may look at the PlayerCharacterCraftingComponent as an example, might have to change queueItems by interacting building.

Did you think about the situation when the player stop interacting with building or change interacting building? should the queueItems be reset when the player stop interacting or not, did you think something like that?

moepi2k commented 11 months ago

yes thought about that too. actually the function should be same like it is right now. just that the queue list is not synced via players. because a player always block the workbench. and its bad to place 10 workbench next to each other so player can craft

insthync commented 11 months ago

Did you think about the situation when the player stop interacting with building or change interacting building? should the queueItems be reset when the player stop interacting or not, did you think something like that?

insthync commented 11 months ago

How it should works?

moepi2k commented 11 months ago

yes that what im saying, from the function. queue list is only for owning player. so when player stop interacting or move away, the queue list cancel/reset. same like it is for right now. only diffrence should be that other player can also use the workbench at same time without seeing what other player crafting atm. actually at first i thought it is like this, since alot of players pm me and asked to change this since the workbench is always blocked be queue list of other players.

i not messed with it for now. i just asking where i need to look to change that before starting.

insthync commented 11 months ago

I've added public queue setting to the building entity, turn it off then when crafting it will use player's crafting source for queueing and updating

moepi2k commented 11 months ago

niiiice, thank u very much. i will send u some coffee :)