phpmmo

PHP textbased MMO game tasks organization


I am developing a php text based game. I am organizing tasks in games. Basically tasks increase the understanding of the game.

A task is a group of small actions in the game.

For example:

TASK Description: You are required to steal a bike, repair it and ship to another city.

It includes 3 actions.

  1. Steal a bike
  2. Repair the bike
  3. Ship it to another city (let say London)

These 3 actions are possible at single of different pages.

I created a table for TASK(task_id, title, description (TASK Description Above),STATUS), but I'm not sure how to store and execute actions of task.

I have one idea, to use a related table TASK_ACTIONS (task_id, action_id,action(?),done)

But I'm not sure in which form to store actions action(?):

An sql statement to check for actions Like following three points.

  1. Bike has been stolen or not. If yes, Mark action to DONE
  2. Bike has been repaired or still damaged. If repaired, Mark Action DONE
  3. Bike has been shipped to London or not. If shipped, Mark Action DONE

If all above marked DONE then mark TASK STATUS as COMPLETED, show next task.


Solution

  • A cheap way to do this would look like this:

    tasks
    {
        user_id
        has_theft_bike
        has_repaired_bike
        ... 
    }
    

    However, this is not easy to expand. A more correct way would be to define all actions in an actions table

     actions // defines all possible actions (also actions not part of a task)
     {
          action_id
          description
     }
    
     user_actions // has one record for every action a user commits
     {
          user_id
          action_id
          date // possible extra
     }
    
     tasks // all possible tasks
     {
         task_id
         name
     }
    
     task_actions // all actions linked to a task
     {
         task_id
         action_id
     }
    

    This way you log every action a user does. You could make a steal bike action and a repair bike action.

    Now you can for instance retrieve all actions you need to complete task 5 (steal a bike and repair it). Then if all those action id's are in the user_actions table for your current user. it means the user has completed the task.

    Just not that your user_actions table will grow really really really fast if you have a couple of users.