jpcsupplies / Economy_mod

Basic Economy System for Space Engineers
13 stars 12 forks source link

X2 -style ship-initiated trade support #172

Open jpcsupplies opened 6 years ago

jpcsupplies commented 6 years ago

Add the ability for /ships/ to initiate trade transactions via PBs, timers and Autopilots.

Suggested logic: add additional keyword to LCDs (eg [trade]) and have these LCD blocks checked for buy or sell commands, execute the command then delete the command from the text (unless the command is recurrent - in which case power down the LCD after execution to prevent further execution)

  1. LCDs with the [trade] tag are checked periodically for text in the text entry box such as buy or sell, and if the block is turned on.
  2. if such a keyword is found, check if the block is set no-share, if so then convert keyword into a valid economy transaction and execute it on behalf of the owner of the block but use the ship inventory for the transaction
  3. example "Buy 1000 ice" if the block is owned by "Bob" and the ship is majority owned by himself or his faction (cargo in particular) then attempt to purchase 1000 ice using Bobs money from whatever the nearest trade zone is the ship finds itself in, and store the ice in this ship's cargo or "sell 1000 ice" removes 1000 ice from cargo and sells it to the nearest trade zone
  4. Possibly allow it to initiate "sell 1000 ice player price" and send buy/sell offers to a player as well?

Security considerations: Owner of PB must have access via ownership or faction sharing of cargo on that ship - PB must be set to "no share" this prevents hacked ships stealing items and money from other players. For theft to occur the ship needs to be pirated like capturing a NPC trader ship which disables the auto buy from working except as the pirate players transaction (which requires them hacking/owning the LCD and cargo)

Purpose of feature: Allows players to create self trading ships (use PB to add buy/sell commands (allowing intelligent trading scripts?) or power on/off with timers and waypoint actions to have ship initiate trades on reaching a location) Because ships will be storing purchases in cargo - it allows pirates the opportunity to steal the cargo during the flight back which is awesome.

Keyword structure: {recurrent} buy ## "item" XX Y# {recurrent} sell ## "item" XX Y#

Examples: recurrent buy 1000 ice (buys 1000 ice then turns the LCD off, leaving the buy order text intact) buy 1000 ice (buys 1000 ice, then deletes the buy 1000 ice line, leaving LCD turned on) sell 1000 ice mary 1 (creates a sell offer to mary for 1000 ice at $1 a unit - as long as she is near the ship ~2000metres)

In game examples: Example 1 - Intelligent Trade ship PB script Player "Einstein" creates a PB script that somehow checks the price of goods (perhaps parsing the text from a pricelist LCD) it decides to buy some cheap ice. The script adds the text "buy 10000 ice" to the [trade] LCD and triggers the autopilot. Economy script purchases 10000 ice using "Einsteins"'s cash and places it in the ships inventory. Autopilot flies ship back to another trade zone and sells the ice.. rinse repeat.

Example 2 - Trade ships for dummies using Waypoint events and timers. Player "Potato" creates a [trade] LCD with the command "recurrent buy 5000 ice" and another [trade] LCD with the command "recurrent sell 5000 ice". He builds an auto pilot with 2 way points. NPC station 1 and npc station 2. On reaching station 2, the waypoint action is to "turn on" the first [trade] lcd, start a timer block, then turn off the autopilot. Economy sees the LCD and buys 5000 ice using "Potato"'s money into ship inventory, then turns LCD off. The timer waits 30 seconds then turns on the autopilot again. The autopilot flies to station 1. The waypoint action here is to turn on the second [trade] lcd, start a timer, then turn off autopilot. Economy sees the LCD and sells off 5000 ice, then turns the LCD off again. The timer waits 2 minutes (in case the owner or passengers want to hop on board) then turns on the autopilot again.

jpcsupplies commented 6 years ago

This also allows PB scripts on the workshop to act as "trader plugins" for drone trading ships! So i guess it fits in with the plugin framework project..