# 签到系统

# 一、介绍

  1. 概述 签到系统用于记录用户每日签到。使用该模块需要先由游戏策划配置签到配置,可配置多组签到任务。 签到系统同时还提供补签服务。使用补签服务时需要先由游戏策划配置补签配置

  2. 签到

签到系统中签到之后,签到配置会对应一个奖励池id,奖励池配置中会对该奖励池中有什么物品奖励,可配置多个,并且该物品奖励获取的概率是多少,如果配置100,则该奖励物品在签到之后,可以百分之一百领取到。

# 二、使用

1. 获取签到组

signInSystem提供signInSystem.signInTaskGroups获取一开始在签到配置补签配置中配置的签到组信息。

// 导入账号模块
import { signInSystem } from '@timi/mogs-sdk';
// ...
// 获取账号相关信息
const groupList = await (await signInSystem).signInTaskGroups;
const signList = groupList.find((item) => item.id === data.groupId);
1
2
3
4
5
6

2. 签到,补签

signInSystem在获取到签到组之后,使用signInSystem.signInsignInSystem.supplementarySignIn进行签到或补签,以下为玩家签到的例子,groupid为上面获取签到组接口返回的其中一个组的id。

// 头部引入signInSystem
import mogs, { signInSystem } from "@timi/mogs-sdk";

...
// 调用签到
signInSystem.signIn({
    groupId: groupid,
    signInNo: id,
    success(res) {
        mogs.showToast({
        icon: "none",
        title: "签到成功",
    });
    },
    fail(res) {
        mogs.showToast({
            icon: "none",
            title: "签到失败",
        });
    },
});

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

3. 签到事件更新事件监听

signInSystem同时提供了玩家签到的更新事件监听:signInSystem.offSignInTaskChangesignInSystem.offAttributeUpdate

以下为监听属性更新例子:

// 导入属性模块
import { signInSystem } from '@timi/mogs-sdk';
// ...
// 定义一个事件
const handler: AttributeUpdateEventHandler = (event) => {
  console.log(event.previousValue, event.currentValue);
};
//开始监听 Attributes 改变事件
signInSystem.onAttributeUpdate(handler);
// ...
// 移除刚刚添加的事件处理函数
signInSystem.offAttributeUpdate(handler);

1
2
3
4
5
6
7
8
9
10
11
12
13

TIP

更多签到模块的 api 请参考签到模块