jpcsupplies / Economy_mod

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

ENH: register (to trade) command for factions or traders #44

Open jpcsupplies opened 8 years ago

jpcsupplies commented 8 years ago

Have re-specced this see later posts.

In order to facilitate trade between factions, or simply with a particular trader individual - we should ponder a "register" command in order for them to "register" the region in which they intend for other players to be able to trade with them.

I am getting ahead of myself a bit here, as this feature will probably be a milestone after the alpha milestone.. but if we know where we are headed we can design accordingly towards it.

Example - If we build the NPC trader to behave like a player or faction - they will automatically "register" their trade territory as 0,0,0 on the map. Anyone within 5kms (small antenna range limit) will then be permitted to interact with the trade market located in that region; regardless of faction or alliances.

The only difference between a player and the "NPC" is the NPC trader will trade all products, (master product table prices) with all players, and any player will be permitted to post "offer to buy or sell" prices in that market.

While players or factions will only trade items they have posted sell offers, or buy requests on. (requiring a trade table for each "registered" trader) On registering other players need to be within 5kms of their "registered" location to interact with that market.

Issues: Ideally multiple overlapping trade regions should be ok.. at least morally. But should all detected overlapping trade regions be included when generating a market "price list"... or should we set the command to simply list the traders and discriminate - forcing a player to specify the market they wish to interact with?

Further gameplay enhancement - many 4x games have an extra "charge" to request price lists from distant markets - perhaps we should permit players with a big enough antenna range to "request" the price list for a given market, even if they are not allowed to buy and sell until they are in that area.

This may promote construction strategies like building a centrally located base, and installing antenna relays to link it to all the nearby markets in order to allow them to browse the prices in them all before loading up a ship and hauling some cargo over to trade.

Logical considerations: For simplicity we could simply generate a trade table for each faction or player who registers for a trade licence. prefix factionID or player UID

If we decide not to allow overlapping regions the register command could respond: Trade License denied, this territory is already provisioned/registered(or similar wording)

For a true price driven global market (instead of simply "merchant shops") we would probably have to create an additional table to record: item to sell, price to sell, qty to sell, uid of seller item to buy, price to buy at, qty to buy, uid of buyer

this table should permit duplicate offers by the same seller at different prices or different sellers at the same price; and be sorted by product and price when displayed to the end user.. for brevity - we could limit such price lists to the top or bottom 5 or 10 prices.

for "trading licences" perhaps a registration fee should be applied to minimise frivilous markets being created.. this would require a licenced trader table to be stored on the server - location of territory, type of trader, uid eg: 1000:5000:6000, faction, UFP
2000:8000:123, player, 1234567890987654321 (only leaders of faction can terminate the license, but all members/allies can post offers or buy/sell there) (player traders can terminate their license, and anyone can buy/sell, but only the trader can post offers? the offers themself constructing their price table)

Some method of displaying trade regions such as automatically generating a gps point when someone enters the region should also be considered.

The blacklist system could be expanded to cover items not listed in a given market. Eg: the item you wish to trade is not available in this market

Suggested Databases: config (partial - we have consts atm) bank balances (done) pricetable (done) faction/player price table (essentially a prefixed clone of pricetable with only requested offers in it) register of registered traders (gps locations of registered trader regions) global orderbook (offers to sell or buy qtys at prices in 0.0.0 region) faction/player orderbook (offers to sell/buy qtys at price in other regions)

Alternate configurations: use a common orderbook and merge traders register with global orderbook eg item to sell, price to sell, qty to sell, uid of seller, trader type, market location (eg 1000:4500:3400) item to buy, price to buy at, qty to buy, uid of buyer, trader type, market location

our existing bank file could also be expanded to store faction balances too just add a type field, and use UID for faction name?

we could merge the price table as well by adding a uid there too, but given that file is meant to allow admins to tweak "default" prices may be best to keep that seperate

Thoughts ?

midspace commented 8 years ago

I would allow any online player to trade with any other online player. (Unless range is a factor for communications).

jpcsupplies commented 8 years ago

yes, i benchmarked the "5km" range thing from small ship antenna range. If we can hook into antenna ranges available to players, we could simply use the range of whatever antenna the player happened to have access to when he traded instead of the arbitrary 5kms. But for simplicity (given i have no idea how to access antennas in modapi) i figured calculate x5km to be the easier short term logic.

midspace commented 8 years ago

We can look up the cube definition, and get the max range of an antenna. Otherwise, there is an API called GetPlayerRelayedBroadcasters. I haven't tried it, but it looks to check if one player can broadcast to another, along a relay network if need be.

jpcsupplies commented 8 years ago

ooh now that sounds pretty funky.. at this rate our mod has a good chance of either being a featured mod in an update.. or keen steals the idea like in FTL lol.. Using relay networks would definitely fit the realism model... and space trade gives the game a pretty good side aim to go with it. I once built a 80km relay network on the void server.. frustratingly tho remote control didnt work, only cameras.. but that was still pretty cool... with this mod it means we can pull down prices and initiate trades.. sounds fun

jpcsupplies commented 8 years ago

This topic may be superseded in part or complimented by #71

jpcsupplies commented 8 years ago

To begin with - raw basics - Create a market zone, default to all items black listed. Need a set price and blacklist command that can only be used by owner of market. They can only put carried or stored items into this market. Market bank file? Should it use players money, or should we allocate a money pool a player can use to limit purchases; and draw on/contribute to as needed.

Bonus points:
Allow them to add items to market by dropping items into a special crate, not just command line commands. #71 - can the market follow a players ship? #93 - allow players to manage their trade zone location? Some way to flag the market as player only or faction. Faction allows founder/leaders to add/remove stock and adjust pricing. Should we allow a faction market /and/ a individual player market, or just flag a market as faction to allow leaders to help manage the founders market?

jpcsupplies commented 8 years ago

User configurable options:

midspace commented 8 years ago

Just a thought, that availability (neutral, allied) might be set on a per item basis, rather than the market.

jpcsupplies commented 8 years ago

That' a good idea (sorry i thought i replied to this already.. must have been one of the times my internet dropped).

Will our databases require much to cater for that scenario? More to the point will this require much extra code to implement?

I suppose best baby steps strategy to start with is allow the placeholders in the database, but create just a basic register command for players at this stage. We can add a flag to it later that allows members/leaders/owner of the market founders faction to maintain the market as well.

The reason i suggest this approach is we can just draw from the players bank balance, instead of needing to maintain a parallel balance.

Logic:

midspace commented 8 years ago

The factional settings in the data store are easy. The difficulty is always in how to represent it to the user, and in having the user make changes. Editing 1 item at a time is tedious. I think this is where an editable dialog would kick the solution for a goal.

Example, a command that was /editmarketplace and it brought that player's own marketplace in a full text dialog, with 2 buttons (ok and cancel)....

-- Blacklisted (Y/N), Buy, Sell, Restriction (All/Neutral/Allied), Item
-- Ores
N 1 1.10 All Ice
Y 1 1.10 All Uranium Ore
Y 1 1.10 All Iron Ore
Y 1 1.10 All Silicon Ore
-- Ingots
N 2 2.20 All Uranium Ingot
N 2 2.20 All Iron Ingot
N 2 2.20 All Silicon Wafer
-- Components
N 5 5.50 All Steel Plate
N 8 8.80 All Metal Grid
-- Ammo
N 200 220 Neutral 5.56x45mm NATO magazine
N 1 1 Allied 25x184mm NATO ammo container
N 1 1 Allied 200mm missile container

The text could be formatting and displayed to the user ready for editing. The user simply has to make adjustments and hit the OK button.

Interpreting the content is easy enough with RegEx, and we can push back errors to the user to correct.

ie.,

-- Blacklisted (Y/N), Buy, Sell, Restriction (All/Neutral/Allied), Item
-- Ores
N 1 1.10 All Ice
Y11.10 All Uranium Ore        ### Cannot read line.
Y 1 1.10 All Iro Ore          ### Cannot find item name.
Y 1 1.10 All Silicon Ore
Y 1 1.30 All Silicon Ore      ### Duplicate item.
X 1 1.30 All Gold Ore         ### Invalid options.

I think we need to lean on Keen for the Editable dialog, and add a second button.

jpcsupplies commented 8 years ago

Although interesting makes mod too difficult for players to use scrap this one.

We can use the basic behaviour of NPC markets, just have grouping categories for mass blacklist toggling short term. As for an interactive input -

Any API way to force the LCD text edit box up ? ie spawn invisible lcd, propogate the text field, pop it up on screen

Not relevent here but the api also appears able to catch if a player hits the "X" in top right corner, or the "ok" button on message boxes.

how flexible is the SESE wrapper ? presumably it cant be used to force a dialog minus the need for an lcd?

Either that or we integrate with a switch panel and an lcd.. eg LCD: -- Ingots =[ N 2 2.20 All Uranium Ingot ]= =[ THIS ]= is moved with up/down N 2 2.20 All Iron Ingot N 2 2.20 All Silicon Wafer

SWITCH PANEL: [ up ] [ down ] [ select next] [ toggle option ]

Press select/next

=[ {N} 2 2.20 All Uranium Ingot ]= { THIS } is moved with "select/next"
pressing "toggle" would make it flip from Y to N If we choose a price field capture the next chat input ?

Without a proper screen text output facilitiy not much else we can do?

jpcsupplies commented 8 years ago

Suggested commands /shop /trade /market /tradezone (/tz abbreviated)? /tz register name range - eg /tz register "K Mart" 1000 Allows player to request that a market by the name "k mart" with a trade range of 1000 be registered from their current location. (or we can target a block? eg lcd/beacon/cargo crate etc) This will calculate the registration/taxation fee and prompt the player - It will cost 10000 credits to register a trade zone here of radius 1000, and 1% tax on every sale, continue /yes /no ?

eg 10 credits per metre radius, and 0.001% tax per metre (configurable by admin) other factors such as distance from middle of map too could effect price.

/tz unregister name - eg /tz unregister "K mart" remove the market transfer all stock into current player storage (should we message faction leaders if its a faction shop?)

/tz move name - eg /tz move "K mart" move the market to their current location - charge a fee for this.. eg 1000 ? or 100 per km moved ? It follows beacon Now.

/tz factionmode on | off | company (\ coop might be better flag name) - sets if it is a faction market - ie (on) faction owners/leaders can manage stock. or (company) if all faction members can manage stock (ie faction is a company) or (off) only the person registering can manage stock (default)

The owner can buy/sell into their own market for free and without tax (since it uses their bank balance anyway)

If it is set "company" all faction members buy and sell at the cost price (except market owner) but the owners and leaders can add or remove stock for free. When selling into the market tax is deducted before paying the staff member selling into the market. Eg sell 1 explosive for 100, 100 is deducted from the market owners balance, and 99 is paid to the staff member, and 1 is paid to the server npc. if it is set "on" faction owner and leaders can add or remove stock at no cost like market owner(or the load/unload commands could be used, and the buy/sell at cost behavior carries to them too), but faction members buy and sell at normal buy and sell prices. if it is set "on" profits get divided evenly between owners and leaders?? (not sure how this should work - perhaps a per sale basis, subtract difference between buy and sell price and divide equally between the "board of directors" - should company mode pay non leaders? or maybe company mode trigger an extra wages/commission system under the proposed mission system?)

/tz buy/sell/blacklist/restrict set various options on items eg /tz buy grid 30, /tz sell grid 40, /tz restrict grid U, /tz blacklist grid N

/tz unload # item - (only available if faction or company set.??) Same as sell command but no money changes hands. Transfers amount # of item from inventory into the current market. Sends a message to owners/leaders of market that player X unloaded X amount of item into market. Can later be integrated with mission system for restock missions.

/tz load player # item - only available to market/faction owners/leaders. Transfers from market stock quantity # of item to "player" inventory. Receiving player gets confirmation to accept or reject. Must be in market zone. Sends message to owner/leader/player that amount # of item has been transferred to their inventory. Can be used on self if you are owner/leader.

/tz restrict all|class U|S|F|A|N set all items to specified restrict setting eg /tz restrict ingots F

/tz blacklist all|class Y|N sets all items or of specified class (eg ore, tool, ingot, component, ammo, gas) to be tradeable or not. eg /tz blacklist ore N

Editable? we could have a [tradezone] tag for lcds, and use them for configuring the black list? eg list all items in table Blacklist | Item name | buy | sell | restrict
N | Iron Ore | 0.005 | 0.01 | U (U= unrestricted trade with all) Y | stone | 0.00001 | 0.1 | S (s=trade with self only, same as Y blacklisted) N | magnesium | 1 | 2 | F (f=trade with own faction only) N | rifle | 10 | 30 | A (A=trade with faction and allies only) N | drill | 10 | 15 | N (n= trade with neutral, allied or faction only)

By default all are set to Y and N (yes blacklisted, restricted to neutral)

Alternate config - remove blacklst entirely and just use restrict flag (since S works like blacklisted anyway)

jpcsupplies commented 8 years ago

I am thinking we should also add an "upper limit" option too - ie set stone to be buy and sellable, but refuse to buy any more over 10000 stock

..And the buy only sell only option too maybe.. this can be achieved by making restriction flag for both buy and sell not just trade in general.

Data structures: Player market list: Market Name, Owner, location, radius, faction flag

Raw stock list: market name, item name, blacklisted, restriction buy, restriction sell, buy price, sell price, stock, buy limit.

buy/sell Restriction flags: U= unrestricted trade with all (including enemies) s=trade with self only, same as blacklisted f=trade with own faction only A=trade with faction and allies only n= trade with neutral, allied or faction only

Faction flags: Y=yes its a faction shared market - leaders of faction can control it too and share profits N=no its an independent trader - only you can control it C=company faction - faction is treated like a trade company and all members are staff, leaders share profits

Additional admin configurable settings - range limit (maximum market radius) eg 5000 - grid size of station could also be used to increase or decrease limit slightly minimum stations grid size (eg how big a station needs to be before you can register a market?) Register charge per metre radius eg 10 Tax rate per metre radius eg 0.001% can be turned off by setting 0

\ can possibly live without blacklist entirely since restriction buy/sell performs same task in more detail

*\ separating market owner/market name from market item will allow a market to be sold off to another player if we decided to add such a feature

**\ restrictions market must not overlap, market must contain a space station owned by player of minimum size X, market must not have the same name as another market

***\ a trade zone set as non-faction can still restrict the sale of certain items to members of that players faction only.

****\ outlaw status - items blacklisted by the main NPC market could be considered illegal goods if traded by player stations? Or should we add something new for this later. Or should we create an additional secret faction mode flag for this purpose.

midspace commented 8 years ago

I'm not sure of the correct issue to put this under, but further work still needs to be completed for player controlled trade zones.

Thoughts on using an Lcd for management of the market. I've considered these commands. /tz load "My market name" and /tz save "My market name" To be carried out while pointing at an LCD.

Load, will take details from the specified market name the player has, and place it into the Private text field of the LCD. This is to allow the player to see all details of the items in their market (or copy the text and use a text editor). This will allow them to make changes to all items in one go, instead of trying to use a command for each and every item in their market. Once a player has finished with changes, they will use the save command, which will update the market they specify. They can reuse the same details on a second market (at any range), to update other markets to have the same details. Items that are blacklisted by the server will not appear in the Load, and will be ignored during save. Any issues during the save step will update text LCD text with descriptive information about which line that failed and why it failed.

Details to be displayed include the item name, current stocks, blacklist, limits, sell price and buy price.

The only details that can be edited are, Item blacklist, Item limits, Item sell price, and buy price.

Detail in the LCD should appears as such:

# Any text behind the # will be ignored. They may be removed.
# Items will be displayed in alphabetical order.
# The values are:
# Limit/Quantity | Sell/Buy | Restriction | "Name"
# Do not modify the name as this is used to identify the item.
# Do not modify the Quantity. It will have no effect.
# A limit of -1 means it is blacklisted.
# A limit of 0 or more, means your market will not not allow you stock any more items above that value (no one can sell you more), but it will sell any items it has in stock. You can overstock your own market if you wish, but no one else can.
# Sell Price, is the price you sell at, which another player will pay to buy from you.
# Buy price, is the price you buy at, which another player will receive in credits to sell to you.
# The keyword RESET will reset the buy and sell price to that of the default market as set by the server.
# The % used in either of the buy or sell price, will apply that % based on the other value.
# Ie., a buy price of 3.73, and a sell price of 5% will apply a 5% markup to the buy and become 3.9165
# a sell price of 3.9 and a buy price of 5%, will apply a 5% markdown to the sell and become 3.705
# Restriction flags are not yet implemented and are placeholders for how to trade with faction members, allies, neutral players and enemies.
#
# Limit/Quantity | Sell/Buy | Restriction | "Name"

## Ores
-1/0 | 0.13/0.12 | U | "Stone"
1000000/12.956 | 0.07/0.06 | A | "Uranium Ore"

## Ingots
-1/0 | 0.19/0.17 | U | "Gravel"
10000/0 | RESET | U | "Gold Ingot"
1000000/5500 | 12.36/10.99 | A | "Uranium Ingot"

## Components
10000000/9888 | 5%/3.73 | U | "Steel Plate"

## Ammo

## Tools
10/10 | 10.73/0.65 | A | "Automatic Rifle"
100/0 | 15.94/5.28 | A | "Elite Automatic Rifle"
10/10 | 12.68/1.20 | U | "MyObjectBuilder_PhysicalGunObject/WelderItem" (Welder)
jpcsupplies commented 8 years ago

I agree with all you suggest BTW - although i would be more inclined to use our search logic instead of exposing the raw object builder ids, everything else is a yes i agree.

I just realized this also resolves one aspect of requests for price automation. If they set their sell price the % will auto reset the buy price too. Nice.

midspace commented 8 years ago

I wish there was a way of not using the raw object builder ids, but it's the only guaranteed way of identifying the item. Currently there are a bunch of items in the game which are trees, but their description shows up as "Welder". All of them. Currently there is no way to determine one object from another if they have the same description.

I'll be amending the text above as I go along.

midspace commented 8 years ago

Looking back at earlier comments, using the proper name reads better, so I may have to look at using some more smarts in the code to check for non-unique names, and fall back to the object builder ids gracefully.

jpcsupplies commented 8 years ago

actually that edit you did above breaking it up into categories looks like a good way to do it.. switch a category to an object builder id? they dont see the id, but we still get the benefit backend. also makes it easier for shopkeepers to find the types of item they want to edit faster