-
Notifications
You must be signed in to change notification settings - Fork 1
CalendarEventsModule
This module allows the creation and modifying of ingame events that are activated and deactivated automatically on the given date and time. The events can have multiple stages with different parameters. The editor provides the means to create and edit the events and event stage parameters, the server API grants the ability to check whether the event is currently active or the list of events by given type.
The calendar events editor module class is snipe.edit.modules.CalendarEditCore
. To register a new calendar event type, you can use the registerEvent()
method. It accepts an object with a big list of mostly optional parameters.
Name | Description |
---|---|
editPost | Function to output additional page blocks after main form on edit event page. Function arguments are: event ID, event parameters, request variables. |
inputs | Additional inputs for add/edit event form. |
listField | Function to output event data in event list. |
name | Event name. |
noEndDate | If enabled, event is active indefinitely. |
params | Add/update event parameters (supports <type>:<name> naming scheme). |
stageInputs | Form inputs for event stage parameters. |
stageParams | Event stage parameters. |
type | Event type. |
Here's the usage example:
server.coreCalendarModule.registerEvent({
name: 'paid battle price',
type: 'battle.price',
listField: function (id: Int, params: Dynamic) {
p('Price: ' + params.price + ' coins<br>');
},
inputs: [
{ title: "Price", name: "price", isParam: true },
],
params: [ 'price' ],
});
Let's suppose you are limiting the number of free battles per day for player. And if the player wants to have some more, he will have to pay for it. But to promote the additional battles feature you're having the price discounted for a period of time. This example sets the event type up. After you add the code to one of your editor modules the calendar events list page (the link to it is located in the top menu of the editor) will show the "add paid battle price" link on top of the event list. Clicking it will open the create event page where you can set the date/time and the new price.
That will be enough for the editor, the server code will come in the next section.
The slave server calendar events module is snipe.slave.modules.CalendarModuleCore
. It provides the API calls to get event structure, get the current event stage number, get the event stage parameters, get the event list by type, check if the calendar event is active and full events iterator.
Continuing with the example from the previous section, let's take a look at the battle module. The player makes the call to buy access to more battles.
public override function call(client: Client, type: String, params: Params): Dynamic
{
var response = null;
if (type == "battle.buyMore")
response = buyMore(client, params);
return response;
}
function buyMore(c: Client, params: Params): Dynamic
{
var price = server.coreVarsModule.getInt("battle.price");
var listEvents = server.coreCalendarModule.getEvents("battle.price");
for (ev in listEvents)
if (server.coreCalendarModule.isActive(ev, c.user.networktype, c.lang))
price = ev.params.price;
if (c.money < price)
return { errorCode: "notEnoughMoney" };
c.money -= price;
c.paidBattles += 10;
return {
errorCode: "ok",
paidBattles: paidBattles
};
}
We take the price from game variables and find the event that is currently active.
The cache server calendar events module has the same contents as the slave server one. It is called snipe.cache.modules.CalendarModuleCacheCore
.