Esempio n. 1
0
func Initialize() {
	dir, err := os.Open(config.DataFilePath)
	if err != nil {
		panic(err)
	}

	fi, err := dir.Readdir(0)
	if err != nil {
		panic(err)
	}

	for _, info := range fi {
		if info.IsDir() {
			continue
		}

		if strings.HasSuffix(info.Name(), ".smp") {
			smp, err := data.ReadSMP(path.Join(config.DataFilePath, info.Name()))
			if err != nil {
				log.Infof("加载SMP地图文件失败:%s, error: %s\n", info.Name(), err)
				continue
			}
			// log.Debugf("%s: %#v\n", info.Name(), smp)

			ssiFile := strings.Replace(info.Name(), ".smp", ".ssi", 0)
			ssi, err := data.ReadSSI(path.Join(config.DataFilePath, ssiFile))
			if err != nil {
				log.Infof("加载SSI地图文件失败:%s, error: %s\n", info.Name(), err)
				continue
			}

			if smp.ZoneID == 0 {
				// 暂时不加载自己改的的图,像L3 L4 L5 塔1 塔2
				continue
			}

			scene, err := NewScene(smp, ssi)
			if err != nil {
				log.Warnf("加载地图失败:%s, error:%s\n", info.Name(), err.Error())
				continue
			}

			err = scene.Init()
			if err != nil {
				log.Warnf("地图初始化失败:%s, error:%s\n", info.Name(), err.Error())
				continue
			}

			go scene.Loop()
			g_Scenes[scene.ZoneID] = scene
			log.Infof("加载地图%d成功:%s", scene.ZoneID, info.Name())
		}
	}
}
Esempio n. 2
0
func (tile *Tile) deleteItem() {
	if !tile.hasItem() {
		log.Warnf("no item to delete in deleteItem")
		return
	}

	// delete(tile.Objects, )
	tile.Flags &^= (1 << TILE_ITEM)
}
Esempio n. 3
0
func (r *Reader) Read(reader io.Reader) (ret Packet, err error) {
	var id PacketID
	var sz uint32
	var seq uint8

	err = ReadHeader(reader, &id, &sz, &seq)
	if err != nil {
		return
	}
	r.Seq = seq

	log.Debugln("packet header:", id, sz, seq)
	if id >= PACKET_MAX {
		err = errors.New("packet id too large!")
		return
	}

	ret = packetTable[id]
	if ret == nil {
		log.Debugln("reading a not implement packet:", id)
		var buf [500]byte
		raw := RawPacket{
			Id:  id,
			Seq: seq,
		}
		if sz > uint32(len(buf)) {
			err = errors.New("too large raw packet")
			return
		}
		_, err = reader.Read(buf[:sz])
		if err != nil {
			return
		}
		copy(raw.Data, buf[:sz])
		err = NotImplementError{}
		return
	}

	err = ret.Read(reader, r.Code)
	if ret.PacketSize() != sz {
		log.Warnf("packet not read clean: id=%d, sz=%d, read=%d", id, sz, ret.PacketSize())
	}
	return
}
Esempio n. 4
0
func (tile *Tile) deleteCreature(id ObjectID_t) {
	var object ObjectInterface
	object, ok := tile.Objects[id]
	if !ok {
		log.Warnf("object not exist in tile! id=%d tile=%#v\n", id, tile)
		return
	}

	delete(tile.Objects, id)

	var creature *Creature
	switch raw := object.(type) {
	case *Agent:
		creature = raw.CreatureInstance()
	case *Monster:
		creature = raw.CreatureInstance()
	default:
		log.Errorln(raw)
		panic("不对")
	}
	tile.Flags &^= (1 << (TILE_WALKING_CREATURE + creature.MoveMode))
	tile.Flags &^= (1 << (TILE_GROUND_BLOCKED + creature.MoveMode))
}
Esempio n. 5
0
func (zone *Zone) addItem(item ItemInterface, x ZoneCoord_t, y ZoneCoord_t) {
	iclass := item.ItemClass()

	tile := zone.Tile(int(x), int(y))
	tile.addItem(item)

	if iclass == ITEM_CLASS_CORPSE {
		switch corpse := item.(type) {
		case *MonsterCorpse:
			zone.broadcastPacket(x, y, &packet.GCAddMonsterCorpse{
				ObjectID:      corpse.ObjectID,
				MonsterType:   corpse.MonsterType,
				MonsterName:   corpse.Name,
				X:             Coord_t(x),
				Y:             Coord_t(y),
				HasHead:       corpse.HasHead,
				TreasureCount: corpse.TreasureCount,
				LastKiller:    corpse.LastKiller,
			}, nil)
		default:
			log.Warnf("未实现的addItem %#v\n", corpse)
		}
	}
}