Ejemplo n.º 1
0
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
		}
	}
}
Ejemplo n.º 2
0
//传送到场景
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)
}
Ejemplo n.º 3
0
//增加一个全局数据
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
}