【求助】玩家存档丢失的问题

[复制链接]
399 |7
温柔的败退 发表于 2024-11-27 11:14:23 | 显示全部楼层 |阅读模式
本帖最后由 温柔的败退 于 2024-11-27 13:51 编辑

使用了subdata,具体情况是这样的,在退出游戏短时间内再进存档是正常的,但是过段时间再进的话存档是会没有的。不知道是不是房间服务器关闭了会导致这种情况。
回复

使用道具 举报

丸子 发表于 2024-11-28 09:21:46 | 显示全部楼层
能看一下你存档那一块的代码逻辑不嘞
回复

使用道具 举报

丸子 发表于 2024-11-28 09:28:31 | 显示全部楼层
丸子 发表于 2024-11-28 09:21
能看一下你存档那一块的代码逻辑不嘞

可以看看 DataStorage 有没有设置 setTemporaryStorage 为 false,如果没有的话可以这样写
DataStorage.setTemporaryStorage(SystemUtil.isPIE);
回复

使用道具 举报

温柔的败退楼主 发表于 2024-11-28 09:51:35 | 显示全部楼层
本帖最后由 温柔的败退 于 2024-11-28 09:52 编辑
丸子 发表于 2024-11-28 09:21
能看一下你存档那一块的代码逻辑不嘞
请问一下需要的是那一部分,subdata的可以么

export default class PlayerData extends Subdata {
    @Decorator.persistence()
    skinList: number[];

    @Decorator.persistence()
    skinItemList: number[];

    @Decorator.persistence()
    loginDays: number;

    @Decorator.persistence()
    lastLoginTime: number;

    @Decorator.persistence()
    lastSevenDayCheckInTime: number;

    @Decorator.persistence()
    lastHalloweenCheckInTime: number;

    @Decorator.persistence()
    sevenDayCheckInDays: number;

    @Decorator.persistence()
    halloweenCheckInDays: number;

    @Decorator.persistence()
    diamonds: number;

    @Decorator.persistence()
    isDressingId: string;

    // 新增礼物列表变量
    @Decorator.persistence()
    giftList: number[];

    @Decorator.persistence()
    winCount: number[];

    @Decorator.persistence()
    onlineDurationToday: number;

    @Decorator.persistence()
    lastCheckInTime: number;

    protected initDefaultData(): void {
        this.skinList = new Array(20).fill(0);
        this.skinItemList = new Array(20).fill(0);
        this.loginDays = 0;
        this.lastLoginTime = 0;
        this.lastSevenDayCheckInTime = 0;
        this.lastHalloweenCheckInTime = 0;
        this.sevenDayCheckInDays = 0;
        this.halloweenCheckInDays = 0;
        this.diamonds = 500;
        this.isDressingId = "";
        this.giftList = new Array(20).fill(0);
        this.winCount = [0, 0, 0, 0];

        this.onlineDurationToday = 0;
    }

    public resetOnlineDuration(): void {
        this.onlineDurationToday = 0;
        this.save(true);
    }

    public setOnlineDuration(duration: number): void {
        this.onlineDurationToday = duration;
        this.save(true);
    }

    public getOnlineDurationToday(): number {
        return this.onlineDurationToday;
    }

    public getLastLoginTime(): number {
        return this.lastLoginTime;
    }

    public setLastLoginTime(now: number): void {
        this.lastLoginTime = now;
        this.save(true);
    }

    public setIsDressingId(dressId: string): void {
        this.isDressingId = dressId;
        this.save(true);
    }

    public getIsDressingId(): string {
        return this.isDressingId;
    }

    public addSevenDayCheckInDays(): void {
        this.sevenDayCheckInDays += 1;
        this.save(true);
    }

    public addHalloweenCheckInDays(): void {
        this.halloweenCheckInDays += 1;
        this.save(true);
    }

    // 增加钻石数量
    public addDiamonds(amount: number): void {
        this.diamonds += amount;
        this.save(true);
    }

    // 减少钻石数量
    public subtractDiamonds(amount: number): void {
        if (this.diamonds >= amount) {
            this.diamonds -= amount;
            this.save(true);
        } else {
            console.error("Not enough diamonds to subtract");
        }
    }

    // 获取当前钻石数量
    public getDiamonds(): number {
        return this.diamonds;
    }

    public addOwnSkin(skinId: number): void {
        console.log(this.skinList);
        this.skinList[skinId - 1] = 1;
        this.save(true);
        console.log(this.skinList);
    }

    public addOwnSkinItem(skinItemId: number): void {
        this.skinItemList[skinItemId - 1] = 1;
        this.save(true);
    }

    // 增加礼物
    public addGift(giftId: number): void {
        this.giftList[giftId] += 1;
        this.save(true);
    }

    public useGift(giftId: number): void {
        this.giftList[giftId] -= 1;
        this.save(true);
    }

    // 获取礼物列表
    public getGiftList(): number[] {
        return this.giftList;
    }

    public setLastHalloweenCheckInTime(now: number): void {
        this.lastHalloweenCheckInTime = now;
    }
}

回复

使用道具 举报

温柔的败退楼主 发表于 2024-11-28 09:53:34 | 显示全部楼层
丸子 发表于 2024-11-28 09:28
可以看看 DataStorage 有没有设置 setTemporaryStorage 为 false,如果没有的话可以这样写
DataStorage.s ...

好的谢谢,我先试一试
回复

使用道具 举报

丸子 发表于 2024-11-28 09:56:56 | 显示全部楼层
在你游戏开始的脚本onStart里面添加上 DataStorage.setTemporaryStorage(SystemUtil.isPIE);
image.png
回复

使用道具 举报

温柔的败退楼主 发表于 2024-11-28 09:59:43 | 显示全部楼层
丸子 发表于 2024-11-28 09:56
在你游戏开始的脚本onStart里面添加上 DataStorage.setTemporaryStorage(SystemUtil.isPIE);

...

嗯嗯好的,我试一下
回复

使用道具 举报

温柔的败退楼主 发表于 2024-11-28 10:11:36 | 显示全部楼层
丸子 发表于 2024-11-28 09:56
在你游戏开始的脚本onStart里面添加上 DataStorage.setTemporaryStorage(SystemUtil.isPIE);

...

谢谢大佬,好像确实是补上这个就好了
回复

使用道具 举报

热门版块
快速回复 返回顶部 返回列表