MARS Trading System
From Multiverse
| MARS |
| Mob Server |
| Object Manager |
|
Objects • Trading System • Adding Consumable Items |
| Combat Server |
|
Abilities and Combat Plugin • Combat Statistics • Extending the MARS Combat System • Group System • Trainer Plug-in • Professions • Experience System |
| Tutorials |
| Other Examples |
|
Triggering an Action with a Mouseclick • Scheduled Execution • Working with Sound • Creating a Teleporter |
Contents |
Overview
The MARS trading system allows two players or mobs to trade items with each other. Both parties update their offers and after both have accepted the trade, the inventory plugin transfers the items. When either offer changes, the accepted flags are cleared so both traders must accept the final transaction.
To begin a trade, target the player or NPC you want to trade with and use the "/trade" command. The trade window will open and you will be able to drag and drop items from your inventory into the right pane of the trade window. Items offered by the other player will appear in the left pane. When you are satisfied with the two offers, click the "Accept" button and once both players have accepted the trade, it will be completed.
NOTE: to drag items, click on them, but do not hold the mouse button down; then you'll be able to drag them to the trade window.
See also MarsTrade, the client-side example implementation of the trading system in Sampleworld.
Files
The MARS secure trading system requires both client and server code and some UI files. All these files are included in the Sampleworld asset repository.
Client
The Client requires some UI files and script files. Add the following files from the Sampleworld asset repository to your asset repository:
- FrameXML file
MvSecureTrade.xml - UI script fle
MvSecureTrade.py - Imageset
MvButtons, and the corresponding imagefileMvButtons.tga. - The
MarsTradescripting class in the MARS Client Scripting Library.
You must add MvSecureTrade.xml to the theme (.toc) file that defines your UI.
Server
By default, the MARS trading system runs in the object manager plug-in process, which loads multiverse.mars.plugins.MarsInventoryPlugin. This is the default behavior using the standard server start script (multiverse.sh or start-multiverse.bat).
Make sure your config/common/proxy.py has the the TradeStartCommand command handler.
Messaging
The trading system uses five messages defined in multiverse.mars.plugins.MarsInventoryClient, described in the following table.
| Message | Sent by | Description |
|---|---|---|
| TradeStartReqMessage | Trader | Request to start a new trading session |
| TradeOfferReqMessage | Trader | Request to update or cancel a trade offer |
| TradeStartMessage | Inventory plugin | Notification that a new trading session has started |
| TradeCompleteMessage | Inventory plugin | Notification that a trading session has finished |
| TradeOfferUpdateMessage | Inventory plugin | Notification that a trading session has changed |
API
Two methods in multiverse.mars.plugins.MarsInventoryClient help conduct trades. The tradeStart() method starts a trade between requesterOid and partnerOid:
public static void tradeStart(Long requesterOid,
Long partnerOid);
The tradeUpdate() method updates a trade session with a new offer and accepted flag. If cancelled is true, the trade session is cancelled.
public static void tradeUpdate(Long requesterOid,
Long partnerOid,
LinkedList<Long> offerItems,
boolean accepted,
boolean cancelled);
The TradeStartCommand method in multiverse/config/common/proxy.py calls the tradeStart() method>
class TradeStartCommand (ProxyPlugin.CommandParser):
def parse(self, cmdEvent):
playerOid = cmdEvent.getObjectOid()
targetOid = cmdEvent.getTarget()
MarsInventoryClient.tradeStart(playerOid, targetOid)
Events
When the TradeStartCommand method is called, it triggers the event multiverse.mars.events.TradeStartReqEvent.
evtSvr.registerEventId(33, "multiverse.mars.events.TradeStartReqEvent")

