Excellia - Trading & Player State Listeners
by, 17 August 2011 at 12:44 AM (8354 Views)
As mentioned in the previous post, I was going to work on trading. Well I've done so and I must say that the results are quite satisfying. I haven't been working on Excellia a lot for the past days, and when I was I often got distracted by other activities (whether they were related to Excellia or not).But I've managed to get myself back on track, and have created an almost complete trading system. The only things that I still have to do is fix some minor bugs and add request expiration functionality.Here's a small list of the functions it has;
- Player can send a trade request to other player.
- If any of the player's incoming trade requests contains one with the requested player, the trade window opens.
- Player can offer items for as long as they have any, and the other player's inventory would have enough space to hold them.
- If any of the items change while the player had already accepted, he will have to accept again.
- Once in confirmation stage, it is in no way possible to edit the offers. Only possible actions are to accept or decline (either by the 'Decline' button, the 'Close window' button, by walking away or logging out).
Any state of the players in trade is covered. So say the player walks away or get disconnected for some reason, the trade will safely revert all made actions. Which brings me to my next subject.
Player state listeners
While I was working on trading, I eventually came to a point where I had to have control over certain states or actions a player makes whilst in trade. This made me create a new interface called PlayerStateListener. Classes which implement this interface can perform any actions whatsoever when a player e.g. walks away, closes an interface or gets disconnected. And because the player class manages her listeners concurrently, there is no harm in e.g. making a listener remove itself while the player is iterating over it.
So now when there are certain moments where extra actions would have to be taken when a player e.g. logs out, you can temporarily add another PlayerStateListener to that player. Think of duelling battles, mini games, etc.
As a last word, I want to say that the trading system has been made in an extensible way. Seeing as the duelling condition negatiation stage is quite similar to the trade's, there is already a small base to duelling.
Now, I will fix the remaining trade bugs and another bug I noticed in the player updating process. While doing that I shall figure my next steps, so when the time comes you'll see what I've been working on.
Thanks for reading, and please ask any questions you might have!