Beispiel #1
0
//传送回base
func (t *TeleportHelper) teleportToBase(app *RemoteApp, object datatype.Entityer, mailbox rpc.Mailbox, args ...interface{}) error {
	sd := object.GetSceneData()
	infos := make([]interface{}, 0, len(args)+1)
	infos = append(infos, sd)
	infos = append(infos, args)
	return app.CallBack(&mailbox, "Teleport.SyncBaseWithSceneData", t.OnSyncBaseWithSceneData, infos)
}
Beispiel #2
0
func GetSaveData(ent datatype.Entityer) *DbSave {
	data := &DbSave{}
	data.Data = GetEntityData(ent, false, 0)
	roleinfo := ent.GetExtraData("roleinfo")
	if roleinfo != nil {
		data.RoleInfo = roleinfo.(string)
	}
	return data
}
Beispiel #3
0
//释放对象,如果有子对象一并释放
func (p *Pool) FreeObj(e datatype.Entityer) {
	chds := e.GetChilds()
	for _, ch := range chds {
		if ch != nil {
			p.FreeObj(ch)
		}
	}
	e.ClearChilds()
	p.Free(e)
}
Beispiel #4
0
func (ts *TableSync) SyncTable(player datatype.Entityer) {

	recs := player.GetRecNames()
	for _, r := range recs {
		rec := player.GetRec(r)
		if !rec.IsVisible() {
			continue
		}

		out := tt.SyncTable(rec)
		if out == nil {
			continue
		}
		err := MailTo(nil, &ts.mailbox, "Entity.RecordInfo", out)
		if err != nil {
			log.LogError(err)
		}
	}
}
Beispiel #5
0
func (gd *GlobalDataHelper) RecClear(self datatype.Entityer, rec datatype.Recorder) {
	if !gd.isServer {
		return
	}
	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.GlobalDataRecClear", gd.OnDataChanged, self.GetIndex(), v, rec.GetName())
	}
}
Beispiel #6
0
//数据属性变动同步
func (gd *GlobalDataHelper) Update(self datatype.Entityer, index int16, value interface{}) {
	if !gd.isServer {
		return
	}
	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.GlobalDataUpdate", gd.OnDataChanged, self.GetIndex(), v, index, datatype.NewAny(0, value))
	}
}
Beispiel #7
0
//释放一个具体对象,如果池中有空间,则回收,如果空闲的超过一定数量,则不回收,直接删除
func (p *Pool) Free(e datatype.Entityer) {
	if l, exist := p.pool[e.ObjTypeName()]; exist {
		if l.Len() <= MAX_POOL_FREE {
			e.Reset()
			l.PushBack(e)
		}
	} else {
		l := list.New()
		e.Reset()
		l.PushBack(e)
		p.pool[e.ObjTypeName()] = l
	}
}
Beispiel #8
0
func (gd *GlobalDataHelper) OnRemove(self datatype.Entityer, sender datatype.Entityer, index int) int {
	if !gd.isServer {
		return 1
	}
	sender.SetPropSyncer(nil)
	recs := sender.GetRecNames()
	for _, v := range recs {
		rec := sender.GetRec(v)
		if rec.IsVisible() {
			rec.SetSyncer(nil)
		}
	}
	return 1
}
Beispiel #9
0
func GetEntityData(ent datatype.Entityer, base bool, depth int) *SaveEntity {
	if !base && !ent.IsSave() {
		return nil
	}
	s := &SaveEntity{}
	ent.SyncToDb()
	s.Typ = ent.ObjTypeName()
	s.DBId = ent.GetDbId()
	s.Obj = ent.GetSaveLoader()
	s.Index = ent.GetIndex()
	if ent.Base() != nil {
		s.Base = GetEntityData(ent.Base(), true, depth)
	}
	if base {
		return s
	}
	if depth > 1 {
		return s
	}

	clds := ent.GetChilds()
	l := len(clds)
	if l > 0 {
		s.Childs = make([]*SaveEntity, 0, l)
		for _, e := range clds {
			if e != nil {
				if child := GetEntityData(e, false, depth+1); child != nil {
					s.Childs = append(s.Childs, child)
				}
			}
		}
	}

	return s
}
Beispiel #10
0
func GetItemInfo(obj datatype.Entityer, syncchild bool) (*datatype.EntityInfo, error) {
	item := &datatype.EntityInfo{}
	buffer := new(bytes.Buffer)
	enc := gob.NewEncoder(buffer)
	err := enc.Encode(obj)
	if err != nil {
		log.LogError("encode ", obj.ObjTypeName(), "error,", err)
		return nil, err
	}
	item.Type = obj.ObjTypeName()
	item.Caps = obj.GetCapacity()
	item.DbId = obj.GetDbId()
	item.ObjId = obj.GetObjId()
	item.Index = obj.GetIndex()
	item.Data = buffer.Bytes()

	if syncchild {
		ls := obj.GetChilds()
		if len(ls) > 0 {
			item.Childs = make([]*datatype.EntityInfo, 0, len(ls))
		}
		for _, c := range ls {
			if c != nil {
				child, err := GetItemInfo(c, syncchild)
				if err != nil {
					return nil, err
				}
				item.Childs = append(item.Childs, child)
			}
		}
	}

	return item, nil
}