Rewards and Drops
What the players get when they defeat an enemy (experience, items on the floor or in the inventory, and modifiers) and the reward events like the daily login reward. Both are part of the rewards feature (enabled in Features).
Enemy rewards
The Rewards > Rewards rows define what an object gives when a player defeats it. Each row is rolled on its own and every winning row is given:
- Object ID - the object that gives the reward. The rewards are loaded for the objects spawned by a respawn area, so use the multiple object of the enemies (see Enemy Respawn Flow).
- Experience - experience for the player.
- Item ID and Drop Quantity - the item and how many units the player gets.
- Modifier ID - a Rewards Modifiers row applied to the player, for example a stat bonus (see Rewards Modifiers Entity).
- Drop Rate - the chance in percent, 100 always and 0 never.
- Is Unique - the reward is given only once in the whole game: the first time it is won Was Given is checked and nobody gets it again.
- Has Drop Body - the item is dropped on the floor instead of going directly to the inventory, see Drops below.
A row with Drop Quantity 0 is ignored, also when it only gives experience: keep it at 1 or more. In the sample data every forest enemy gives tree branches with a drop rate of 100 (3 branches for the aggressive enemies, 1 for the others) and from 10 to 90 experience points depending on the forest level:
When the player is in a team the rewards are shared with the members, see "Rewards sharing" in Teams and Clans.
Drops on the floor
An item reward with Has Drop Body is dropped on the floor when the item has a Rewards > Drops Animations row, otherwise it goes directly to the player inventory:
- Each unit of the Drop Quantity is a separate object placed on a free tile around the defeated enemy.
- The players click a drop to pick it up when they are close enough (the server/objects/drops/interactionsDistance config, or the NPCs interaction distance when it is missing). With server/objects/drops/autoPickUpOnHit at 1 walking over the drop picks it up.
- The drops disappear after server/objects/drops/disappearTime milliseconds (1800000, 30 minutes, in the basic config; 0 keeps them until they are picked up).
A Drops Animations row has the Item ID, the Asset Key, the File (the spritesheet, uploaded to the theme assets/custom/sprites folder) and the Extra Params with the frames and the size, for example {"start":0,"end":2,"repeat":-1,"frameWidth":32,"frameHeight":32,"depthByPlayer":"above"}:
Reward events: daily login rewards
The reward events are rewards for the player activity. The rewards icon opens the Rewards box with every active event: the ones the player can claim are highlighted, and a click on them gives the items and shows the confirmation.
The sample data has two login events, checked when the player joins a room:
- Daily Login - {"action":"dailyLogin","items":{"coins":1}}: one coin, once per day.
- 2 Days Login - {"action":"straightDaysLogin","days":2,"items":{"coins":10}}: ten coins after logging in two days in a row.
To add one, open Rewards > Rewards Events and create a row:
- Label and Description - the texts or translation keys shown in the box (%loginCount is replaced by the days).
- Handler Key login and Event Key reldens.joinRoomEnd.
- Event Data - the action (dailyLogin or straightDaysLogin with days) and the items as item key and quantity. Optionally rewardImage (an image of the theme assets/custom/rewards folder, default-reward.png by default).
- Position (the order in the box), Enabled, and the optional Active From / Active To dates for limited time events.
The events are loaded when the server starts. The progress of each player is saved in Rewards Events State as JSON (ready, complete and the claim date), and the guests do not get login rewards (the server/rewards/avoidGuestRewardsOnLogin config, true by default).
Code integration (advanced)
- Server: RewardsPlugin (lib/rewards/server/plugin.js) loads the object rewards on reldens.afterRunAdditionalRespawnSetup, gives them on reldens.battleEnded through RewardsSubscriber and creates the drops with WorldDropHandler on reldens.afterGiveRewards.
- Events to change the flow: reldens.beforeGiveRewards (set continueEvent to false to cancel), reldens.afterGiveRewards and reldens.beforeRemovingDroppedReward.
- The reward events are handled by RewardsEventsHandler, which listens to the Event Key of each row and runs the handler of its Handler Key (LoginStateHandler for login); the claim is processed by RewardsEventsMessageActions.
- Client: lib/rewards/client/plugin.js, the box templates are assets/features/rewards/templates/ui-rewards.html and ui-rewards-list.html.
reldens