PHP textbased MMO game tasks organization - php

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.
Steal a bike
Repair the bike
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.
Bike has been stolen or not. If yes, Mark action to DONE
Bike has been repaired or still damaged. If repaired, Mark Action DONE
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.

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.

Related

Is this good implementation of action-based user levelling system?

For now, the system should have 6 different user levels.
Each level will be gained upon user activity, for example:
Level 1 - When user register
Level 2 - When user completes a mission
Level 3 - When user completes more than one mission
Level 4 - When user donate > $X amount of money
Level 5 - When user write more than 50 comments in blog
Level 6 - When user complete quiz
And now... I'm wondering, what's the best database schema to achieve this? I should keep track of all actions related to user's activities, that's why I though about xp_events table... Something like this:
id # primary key
event # type of event, e.g. 'register', 'complete_quiz', etc.
user_id # id of user
delta # number of "exp" which will be gained after specific action
And... in users table I will keep record of current level and "exp" which each user has earned until now.
When user makes any activity, I will call a trigger which will check if user have new level unlocked.
But... I'm aware that in long term (e.g. if more levels are added), this isn't optimal solution.
Looking forward for any suggestions.
I see two obvious possibilities here.
One is to have an event table like you say, with a user ID, event ID, dollar amount (for donations), probably a date/time, maybe other data. If the only reason why you are keeping any of this data is to determine each user's level, this is simple and effective.
If you're keeping track of this data for other purposes also, you probably want to separate it into multiple tables. In such a case you would likely have other data you need to keep for each event. Like for a donation you would need dollar amounts, which I assume don't apply to comments and missions. For comments you likely need the text of the comment and some indication of the thread this comment is on or what it's subject is. For a mission -- I don't know what a "mission" is in this context, but you likely want some information about the type of mission and where it was or who they were supposed to kill or whatever. Most of this data would not be applicable to events of different types. A comment probably doesn't have a dollar amount, a mission doesn't have a thread, etc. So you'd end up with a lot of irrelevant data and bunches of null fields.

Event Page - ATTENDING OR NOT ATTENDING - How would I implement this?

I need to add these two buttons to the events pages of my website.
Basically, just like any other event page you might come across online, for example Facebook,
you get the option to say whether you are attending or not attending the event.
And there is a section on the page with a number of people attending etc.
I would like to know the best solution to tackle this.
I'm not asking you to code it for me, just to point me in the right direction.
I was thinking of something like, if the user clicks attending, their username or id is put into the database where the event exists and is added to an attending field in some kind of array format. Same for if they choose to not attend but in a notAttending field.
You're half way there, at least having the concept of a user and event entities - the only step of the puzzle that you're missing is the concept of an attendance entity that stores if the user has declined/is required/is attending/failed to turn up/etc. - so each user has an attendance for each event they're invited to; in database terms this is a many to many relationship (a user can be invited to many events, and an event can be attended by many users), so would typically live in a dedicated table.
Your idea sounds good. You could have a table named event_attendants having the columns event_id, user_id and status (don't forget the primary key). That's it. status could be a ternary property so you can have a facebook-like status yes, no and not sure or similar.
You can even do the button functionality with AJAX so it's a pretty quick UI.
I would create a table called rsvps or event_responses something to that effect.
It would have three columns:
user_id - pk value of the user.
event_id - pk value of the event.
attending - boolean.
attending should be NOT NULL. That way the only data in the table is generated in two situations:
User indicates they will attend event.
User indicates they will not attend event.
If a user has not responded, they will not be in the table for that event. That you way you can easily get a count for "Attending", "Not Attending" and "Yet to Respond".
UI
Using jQuery, add two buttons to the event page: "Attending" and "Not Attending". Bind a click event to each and fire off an AJAX request when clicked. That way the interface is responsive.

Which of these methods provides for the fastest page loading?

I am building a database in MySQL that will be accessed by PHP scripts. I have a table that is the activity stream. This includes everything that goes on on the website (following of many different things, liking, upvoting etc.). From this activity stream I am going to run an algorithm for each user depending on their activity and display relevant activity. Should I create another table that stores the activity for each user once the algorithm has been run on the activity or should I run the algorithm on the activity table every time the user accesses the site?
UPDATE:(this is what is above except rephrased hopefully in an easier to understand way)
I have a database table called activity. This table creates a new row every time an action is performed by a user on the website.
Every time a user logs in I am going to run an algorithm on the new rows (since the users last login) in the table (activity) that apply to them. For example if the user is following a user who upvoted a post in the activity stream that post will be displayed when the user logs in. I want the ability for the user to be able to access previous content applying to them. Would it be easiest to create another table that saved the rows that have already been run over with the algorithm except attached to individual users names? (a row can apply to multiple different users)
I would start with a single table and appropriate indexes. Using a union statement, you can perform several queries (using different indexes) and then mash all the results together.
As an example, lets assume that you are friends with user 37, 42, and 56, and you are interested in basketball and knitting. And, lets assume you have an index on user_id and an index on subject. This query should be quite performant.
SELECT * FROM activity WHERE user_id IN (37, 42, 56)
UNION DISTINCT
SELECT * FROM activity WHERE subject IN ("basketball", "knitting")
ORDER BY created
LIMIT 50
I would recommend tracking your user specific activities in a separate table and then upon login you could show all user activities that relate to them more easily. ie. So if a user is say big into baseball and hockey you could retrieve that from their recent activity, then got to your everything activities table and grab relevant items from it.

php reservation system

i m creating a project with php and html use.i would like to create a ticket reservation system for my university.Firstly,the user will choose a date and the number of persons that he wants to reserve tickets.Then,by pressing the next button,he could see the list of the events that are available in the date he checked in the previous step.this list will be static,so i think that i have to create a data base which will have this data and if the users selects ex monday,he could see the data events for monday.Could you please help me do this because i have no big experience with php?i have created the two screens with html and css but now i would like 1st to let me know how to create a data base with my data and secondly how to connect them with my day oprtions!
Thanks a lot!
Take a look at:
PHP 101: A Simple Seat Reservation System
It is not a simple task as you seem to think and explaining it is almost writing the software but I'll try :
Create database tables in the database engine of your choice
required tables
table [events] : colums{id Integer,event_date Date,title Varchar,tickets Integer, description Varchar}
/*
How many tickets are availble for that event, depending on the reservations Count you will show less and less available tickets and eventually you will stop the reservation
*/
table [users] : columns(id Integer,name Varchar,username Varchar,password Varchar)
table [reservations] :
columns(id Integer,
user_id Integer [foreign key to users],
event_id Integer [foreign key to events],
reserved_tickets Integer,
reserved_at Datetime}
/*
reserved tickets are used if you want a user to be able to reserve more than one ticket per person, for safety reasons you can limit that either by adding a new field in the event table where the event creator can choose how many tickets one person can have or either hardcode it in the code, but this is not so "fancy")
*/
Now you will need a lot of views interfaces:
User management interfaces :
1 List + 1 Add/Edit(administrator) +1 register (user can register them selves, this is optional) = 2 (3)
Event management interfaces:
1 List(administration) + 1 Add/Edit + 1 Event listing (in a calendar or something for reservations) = 3
Reservation management interfaces:
1 List(administration) + 1 Manage (Cancel/confirm the reservation of a user etc) = 2
You will need a login page, maybe a recover password/username, a screen where a user can see his reservation and cancel/confirm whatever.
These should be all html/flash etc eventually mixed or comunicating with code (PHP,JSP,ASP whatever)
Every html should have a control script "behind" it, meaning the actuall code that gets/sets info into/from the database, this is recommended to be in a separate file then the view (at least) and should be contained in a function or class methods and here are a lot of details to be said, to many.
I recommend that you try and understand CakePHP, it should fit you at this level and anyway to me it seems the simplest framework that one could use and understand empirically.
It's not an easy job as I said, this should take about 12-16 hours to be written from scratch to a professional programmer, and I think it will take you 5 times more even if you use CakePhp. (of course considering a modern interface,approach and functionality otherwise it would take a pro 6 hours at most)

How to model and track requirements towards a goal in PHP

I'm building a webapp using the Zend Framework, and I need to model logic or keep track of some logic that has to do with tracking progress towards a goal.
Let me illustrate with a sample goal.
USER Needs to Complete All Three of the following:
A) Activity One
B) Activity Two
C) Activity Three
USER Needs to Complete One of the following:
D) Activity Four
E) Activity Five
F) Activity Six
After completing all three from the first group and one from the second group the USER has completed that goal. How would I go about modeling this in PHP so that the webapp knows the goal has been completed and how would I store the data in the database?
To be clear, there will be many different types of goals like this, but all of them will be quite similar in nature.
Assuming that A, B & C and D, E, & F will always belong to a specific group within the goal, I would design it thus:
Goal::isComplete()
{
foreach (Group)
{
switch (Group::type())
{
case "all":
TRUE if all complete
break
case "any":
TRUE if any complete
break;
}
}
if all TRUE
return TRUE
}
Or in English...
You could then store all of your Activities within an Activities table and define the group they are a part of as a simple id reference to the Groups table. When an Activity is complete, it can be marked thus in the DB.
To check for completed goals, you simply need to look for each Group that is required for the Goal. Each group would either be "all" or "any" (or other such options, like "min-2"), and this would tell the script what to check for with the Activity completions. Each Group can then return TRUE or FALSE depending upon its Activities. Assuming that all Groups are required, the Goal would then easily be identified as Complete or not.
The database can look like:
Activities
- id
- group_id
- name
- completed
- [details about activitiy]
Groups
- id
- goal_id
- type (ENUM: 'any', 'all')
- completed
- [details about group]
Goals
- id
- completed
- [details about goal]
The Completed values within Groups and Goals would need to be actively updated whenever Activities is updated, or left out and their values always dynamically worked out.
Does this make sense and do what you are requiring?

Categories