Beispiel #1
0
func DeleteObject(id types.Id) {
	object := datastore.Get(id)
	datastore.Remove(object)

	object.Destroy()

	c := getCollectionOfObject(object)
	utils.HandleError(c.RemoveId(object.GetId()))
}
Beispiel #2
0
func Retrieve(id types.Id, typ types.ObjectType) types.Object {
	if datastore.ContainsId(id) {
		return datastore.Get(id)
	}

	var object types.Object

	switch typ {
	case types.PcType:
		object = &Pc{}
	case types.NpcType:
		object = &Npc{}
	case types.SpawnerType:
		object = &Spawner{}
	case types.UserType:
		object = &User{}
	case types.ZoneType:
		object = &Zone{}
	case types.AreaType:
		object = &Area{}
	case types.RoomType:
		object = &Room{}
	case types.TemplateType:
		object = &Template{}
	case types.ItemType:
		object = &Item{}
	case types.SkillType:
		object = &Skill{}
	case types.StoreType:
		object = &Store{}
	case types.WorldType:
		object = &World{}
	default:
		panic(fmt.Sprintf("unrecognized object type: %v", typ))
	}

	c := getCollectionOfObject(object)
	err := c.FindId(id).One(object)

	if err != nil || object == nil {
		return nil
	}

	datastore.Set(object)
	return object
}
Beispiel #3
0
func commitObject(id types.Id) {
	object := datastore.Get(id)

	if object == nil || object.IsDestroyed() {
		return
	}

	c := getCollectionOfObject(object)

	object.ReadLock()
	err := c.UpsertId(object.GetId(), object)
	object.ReadUnlock()

	if err != nil {
		fmt.Println("Update failed", object.GetId())
	}

	utils.HandleError(err)
}