func (gd *GlobalDataHelper) OnFrame() { if gd.dataset == nil || !gd.isServer { return } for _, client := range gd.globalclients { if client.disable { //没有开启 continue } if (client.status == STATUS_NONE || client.status == STATUS_VERSION_ERROR) && client.errcount < 3 { app := GetAppById(client.appid) if app == nil { continue } entityinfo, err := share.GetItemInfo(gd.dataset, true) if err != nil { panic(err) } client.dataversion = gd.dataversion if app.CallBack(nil, "GlobalHelper.CreateGlobalData", gd.OnCreateGlobalData, gd.dataCenter, entityinfo, gd.dataversion) != nil { client.errcount++ continue } client.status = STATUS_CREATE } } }
//传送到场景 func (t *TeleportHelper) teleport(app *RemoteApp, player datatype.Entityer, mailbox rpc.Mailbox, args ...interface{}) error { playerinfo, err := share.GetItemInfo(player, false) if err != nil { return err } infos := make([]interface{}, 0, len(args)+1) infos = append(infos, playerinfo) infos = append(infos, args) return app.CallBack(&mailbox, "Teleport.TeleportPlayerByBase", t.OnTeleportPlayerByBase, infos) }
//增加一个全局数据 func (gd *GlobalDataHelper) addData(name string, datatype string) error { if gd.dataset == nil { return fmt.Errorf("dataset is nil") } if gd.dataset.GetChildByName(name) != nil { return fmt.Errorf("global data(%s) exist", name) } data, err := core.Create(datatype) if err != nil { return fmt.Errorf("create global data(%s) failed", datatype) } //消除ERROR data.SetInBase(true) data.Set("Name", name) index, err := core.AddChild(gd.dataset.GetObjId(), data.GetObjId(), -1) if err == nil { entityinfo, err := share.GetItemInfo(data, false) if err != nil { return err } v := gd.dataChange() for _, client := range gd.globalclients { if client.disable || client.status == STATUS_NONE { //没有开启 continue } app := GetAppById(client.appid) if app == nil { continue } app.CallBack(nil, "GlobalHelper.GlobalDataAddData", gd.OnDataChanged, index, v, entityinfo) } } return err }