EDCD / EDDI

Companion application for Elite Dangerous
Other
437 stars 81 forks source link

Cargo/Commodity Transfer event #2621

Closed Darkcyde13 closed 1 month ago

Darkcyde13 commented 1 month ago

What happens now

When transferring cargo between your ship and carrier, or ship and SRV, there seems to be no event/script in EDDI to handle this.

What I'd like to happen

An event be added to EDDI, so that users can have a report of transferred cargo/commodities. Personally, I'd also find it useful for reporting corrosive cargo, if you're transferring Thargoid items to your ship without Corrosion Resistant Cargo Racks.

How it can happen

There is an event entry in the game Journal for transferring between Ship and Carrier. I've not (currently) looked for one between Ship and SRV, but I imagine it will be practically identical (I'll update here when I can try it).

{ "timestamp":"2024-06-15T10:56:31Z", "event":"CargoTransfer", "Transfers":[ { "Type":"metaalloys", "Type_Localised":"Meta-Alloys", "Count":2, "Direction":"toship" }, { "Type":"thargoidheart", "Type_Localised":"Thargoid Heart", "Count":1, "Direction":"toship" }, { "Type":"unknownartifact", "Type_Localised":"Thargoid Sensor", "Count":1, "Direction":"toship" } ] }
{ "timestamp":"2024-06-16T00:58:29Z", "event":"CargoTransfer", "Transfers":[ { "Type":"metaalloys", "Type_Localised":"Meta-Alloys", "Count":2, "Direction":"tocarrier" }, { "Type":"thargoidheart", "Type_Localised":"Thargoid Heart", "Count":1, "Direction":"tocarrier" }, { "Type":"unknownartifact", "Type_Localised":"Thargoid Sensor", "Count":1, "Direction":"tocarrier" } ] }

You could use objects like event.toship, event.tocarrier, and event.tosrv to hold the lists of commodities transferred, with each indicating the direction of the transfer. Each can have properties as listed in the Journal event: name, invariantName, and amount.

I've quickly drafted a script to handle this:


{_ Cargo transfer _}
{_ Triggered when you transfer cargo between your ship, carrier, or SRV _}

{if event.toship:
    {set toShip to []}
    {for cargo in event.toship:
        {set item to "{cargo.amount} {if cargo.amount = 1: tonne |else: tonnes} of {cargo.name}"}
        {set toShip to cat(toShip, [item])}
    }
}

{if event.tocarrier:
    {set toCarrier to []}
    {for cargo in event.tocarrier:
        {set item to "{cargo.amount} {if cargo.amount = 1: tonne |else: tonnes} of {cargo.name}"}
        {set toCarrier to cat(toCarrier, [item])}
    }
}

{if event.tosrv:
    {set toSRV to []}
    {for cargo in event.tosrv:
        {set item to "{cargo.amount} {if cargo.amount = 1: tonne |else: tonnes} of {cargo.name}"}
        {set toSRV to cat(toSRV, [item])}
    }
}

You have transferred

{if len(toShip) > 0:
    {List(toShip)} to {OneOf(ship.name, "your ship")}
}

{if len(toCarrier) > 0:
    {if len(toSRV) = 0: and |elif len(toShip) > 0:, }
    {List(toCarrier)} to {OneOf(carrier.name, "your carrier")}
    {_ Can you only transfer to your carrier? Or to others? _}
}

{if len(toSRV) > 0:
    {if len(toShip) > 0 && len(toCarrier) > 0:, }   {_ Oxford comma ;) _}
    {if len(toCarrier) > 0:and }
    {List(toSRV)} to your SRV
}.

My plan is, I'd be able to update this with some code I'm working on based on some scripts by CMDR Yianniv for reporting corrosive cargo. CMDR Yianniv contacted me and asked if I'd like to add his code to my EDDI personality, which I do, and while looking into how I can integrate it, I realised that there is no way to report if corrosive cargo is transferred between your ship/carrier/SRV. So this is the main reason I'm making this request.

Note: In my investigation into adding Yianniv's code, I seem to have found a bug where 'inventory' is empty/blank/void(?) during the 'Location' event, but I'll open a proper issue for that.

EDDI Version

v4.0.4-b2

Darkcyde13 commented 1 month ago

..and I've realised I got some code wrong at the end. 😅

Update the last two code blocks to:

{if len(toCarrier) > 0:
    {if len(toShip) > 0: and}
    {List(toCarrier)} to {OneOf(carrier.name, "your carrier")}
    {_ Can you only transfer to your carrier? Or to others? _}
}

{if len(toSRV) > 0:
    {if len(toShip) > 0: and}
    {List(toSRV)} to your SRV
}.

You'll only be able to transfer between your ship and carrier, OR ship and SRV, not all three at the same time!

Tkael commented 1 month ago

There was some internal discussion about implementing this event after it was introduced. The conclusion at the time was that the CargoTransfer event is followed by a Cargo event which is more complete. In particular, I believe the CargoTransfer event includes missionID information but seems to exclude information about whether the cargo was legally obtained (which is important information that the Cargo Monitor needs to be able to track).

In contrast, the Cargo event only captures the cargo for the current vehicle (ship or SRV) and doesn't tell us where cargo - just that it is no longer attached to the current vehicle. Neither event alone gives us quite everything we would want. :-)

It would introduce some additional complexity but one potential solution would be to capture and delay the CargoTransfer event until after we see the Cargo event then handle both events concurrently (though you can see that this adds some complexity). 🤔

Darkcyde13 commented 1 month ago

Hmm, I've looked at some Cargo events this evening, but they have practically no information at all...

{ "timestamp":"2024-06-17T21:30:58Z", "event":"CargoTransfer", "Transfers":[ { "Type":"metaalloys", "Type_Localised":"Meta-Alloys", "Count":2, "Direction":"tocarrier" } ] }
{ "timestamp":"2024-06-17T21:31:01Z", "event":"Cargo", "Vessel":"Ship", "Count":0 }
{ "timestamp":"2024-06-17T21:26:23Z", "event":"CargoTransfer", "Transfers":[ { "Type":"metaalloys", "Type_Localised":"Meta-Alloys", "Count":2, "Direction":"toship" } ] }
{ "timestamp":"2024-06-17T21:26:25Z", "event":"Cargo", "Vessel":"Ship", "Count":2 }
{ "timestamp":"2024-06-16T16:33:25Z", "event":"CargoTransfer", "Transfers":[ { "Type":"ancientrelictg", "Type_Localised":"Unclassified Relic", "Count":1, "Direction":"toship" }, { "Type":"thargoidtissuesampletype5", "Type_Localised":"Thargoid Orthrus Tissue Sample", "Count":1, "Direction":"toship" }, { "Type":"thargoidtissuesampletype6", "Type_Localised":"Thargoid Glaive Tissue Sample", "Count":2, "Direction":"toship" }, { "Type":"thargoidheart", "Type_Localised":"Thargoid Heart", "Count":1, "Direction":"toship" }, { "Type":"unknownartifact", "Type_Localised":"Thargoid Sensor", "Count":1, "Direction":"toship" }, { "Type":"thargoidtissuesampletype9b", "Type_Localised":"Titan Tissue Sample", "Count":1, "Direction":"toship" } ] }
{ "timestamp":"2024-06-16T16:33:28Z", "event":"Cargo", "Vessel":"Ship", "Count":7 }

It seems that the CargoTransfer entry has much more information. Granted, it doesn't appear to give much more than the name of the commodity, the amount, and the direction it goes to, but the Cargo entry only gives the total amount, nothing else.

How about adding it, but have no default script, just leave it blank like several others in the default personality? That way, it won't be noticed by users who don't modify scripts, and those who know what they're doing, will understand its limitations.

Tkael commented 1 month ago

The cargo event signals that cargo.json has been updated (written to the same location as your player journals). You need to read that file to get the full benefit from the cargo event. :-)

Darkcyde13 commented 1 month ago

The cargo event signals that cargo.json has been updated (written to the same location as your player journals). You need to read that file to get the full benefit from the cargo event. :-)

Doh! Of course! Sorry about that, I keep forgetting there are other files, other than the Journal.

Well, I mainly wanted it so I could use it as a trigger to run the new 'Corrosive Cargo' script that Yianniv and myself have been working on, but I thought it would be a nice addition for others too, especially when doing a 'transfer all' to get a readout of what was moved. In my case, it would seem to definitely benefit from being delayed until after the Cargo event, otherwise the cargo readout would probably be inaccurate.

For now, I'll just leave the trigger for our script to the Liftoff and Undocked events. Thinking about it, they will be just as good there, as it will still give a player time to re-dock to fix it, or carry on regardless.

Still, if it does get added at a later date, I'll be able to look again at this. Thanks anyway! 🙂