Author Topic: Logging transfer of goods between various entities  (Read 394 times)

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Logging transfer of goods between various entities
« on: April 08, 2010, 07:53:33 AM »
There are 4 entities: Player, Faction, Alliance, Warparty. They can send to themselves one type of good (so only amount differs). They can send it in any combination (player to player, faction to player, warparty to alliance, etc (althrough I'm not sure if all of them will be really used in practice)).

How to make logging? At the moment I have 3 fields in logs table "from, to, amount". Which is enough for player to player sending. But now I want to add the remaining 3 entities. The most obvious would be to add "type" field with different number depending on the entity cominbation (but there woub be quite a few IFs then...) another one would be to make 2 fields "from_entity_type, to_entity_type".

Or I could make some limits on th combination number (like player has to send to faction and then faction can either send it to alliance or to the player, but direct alliance to/from player would be impossible).

Hard to decide...

Offline dsheroh

  • Level 21
  • *
  • Posts: 235
  • Reputation: +6/-0
  • Perl Vicar
    • View Profile
    • Psi Rangers
Re: Logging transfer of goods between various entities
« Reply #1 on: April 08, 2010, 10:30:30 AM »
There are 4 entities: Player, Faction, Alliance, Warparty. They can send to themselves one type of good (so only amount differs). They can send it in any combination (player to player, faction to player, warparty to alliance, etc (althrough I'm not sure if all of them will be really used in practice)).

How to make logging? At the moment I have 3 fields in logs table "from, to, amount". Which is enough for player to player sending. But now I want to add the remaining 3 entities. The most obvious would be to add "type" field with different number depending on the entity cominbation (but there woub be quite a few IFs then...) another one would be to make 2 fields "from_entity_type, to_entity_type".

Personally, I deal with that sort of thing by giving everything universally unique IDs.  e.g., If there's a Player with ID 1, there will never be a Faction, Alliance, or Warparty with ID 1 - ID 1 is a Player, period.

Implementation-wise, I tend to be pretty heavily OO in my coding style, so, if these four types of entities can all trade among themselves, I would have an abstract Entity class with Player, Faction, Alliance, and Warparty as subclasses of Entity.  Each Entity has its own ID, shared with no other Entity, and can trade with any other Entity without having to worry about what type of Entity it's trading with, thanks to the magic of polymorphism.  (In actual practice, Entity would itself probably be a subclass of a "Thing" class which would be responsible for handling IDs, loading objects within their correct classes, and not much more; everything else also descends from Thing, thus providing globally-unique IDs across all classes by way of Thing's ID generation method.)

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal