Ejemplo n.º 1
0
Archivo: ai.go Proyecto: sguzwf/ouster
func (ai *MonsterAI) useSkill(pEnemy CreatureInterface, SkillType SkillType_t, ratio int) int {
	// enemy := pEnemy.CreatureInstance()
	// ex := enemy.X
	// ey := enemy.Y
	// dist := ai.Body.getDistance(ex, ey)

	if rand.Intn(100) >= ratio {
		// return SKILL_FAILED_RATIO
		return -1
	}

	if ai.Body.isFlag(EFFECT_CLASS_HIDE) {
		SkillType = SKILL_UN_BURROW
	} else if ai.Body.isFlag(EFFECT_CLASS_TRANSFORM_TO_BAT) {
		SkillType = SKILL_UN_TRANSFORM
	} else if ai.Body.isFlag(EFFECT_CLASS_INVISIBILITY) {
		SkillType = SKILL_UN_INVISIBILITY
	}

	skill, ok := skillTable[SkillType]
	if !ok {
		log.Errorf("技能%d的handler没有实现!!", SkillType)
		return 0
	}

	switch handler := skill.(type) {
	case SkillToObjectInterface:
		// 移动计算,以闭包形式发到agent的goroutine中运行
		if agent, ok := pEnemy.(*Agent); ok {
			closure := func() {
				handler.ExecuteToObject(ai.Body, pEnemy)
			}
			agent.computation <- closure
		} else {
			log.Errorln("怪物打怪物还没实现")
		}

		ai.LastAction = LAST_ACTION_SKILL
	default:
		log.Warnln("skill handler没有实现", SkillType)
	}

	return 0
}
Ejemplo n.º 2
0
func serve(conn net.Conn) {
	defer conn.Close()

	reader := packet.NewReader()
	writer := packet.NewWriter()

	for {
		pkt, err := reader.Read(conn)
		if err != nil {
			if _, ok := err.(packet.NotImplementError); !ok {
				log.Errorln("read packet error in loginserver's serve:", err)
				return
			}
		}

		log.Debugln("read a packet: ", pkt.PacketID())

		switch pkt.PacketID() {
		case packet.PACKET_CL_GET_WORLD_LIST:
			writer.Write(conn, packet.LCWorldListPacket{})
		case packet.PACKET_CL_LOGIN:
			writer.Write(conn, packet.LCLoginOKPacket{})
		case packet.PACKET_CL_SELECT_SERVER:
			writer.Write(conn, &packet.LCPCListPacket{})
		case packet.PACKET_CL_SELECT_WORLD:
			writer.Write(conn, &packet.LCServerListPacket{})
		case packet.PACKET_CL_VERSION_CHECK:
			writer.Write(conn, packet.LCVersionCheckOKPacket{})
		case packet.PACKET_CL_SELECT_PC:
			reconnect := &packet.LCReconnectPacket{
				Ip:   config.GameServerIP,
				Port: 9998,
				Key:  82180,
			}
			writer.Write(conn, reconnect)
			return
		default:
			log.Errorf("get a unknow packet: %d\n", pkt.PacketID())
		}
	}
}
Ejemplo n.º 3
0
func (r *Reader) ReadRaw(reader io.Reader, raw *RawPacket, buf []byte) error {
	var sz uint32
	err := ReadHeader(reader, &raw.Id, &sz, &raw.Seq)
	if err != nil {
		return err
	}

	if sz > uint32(len(buf)) {
		log.Errorf("read a packet id = %d, sz = %d\n", raw.Id, sz)
		return errors.New("packet size too large")
	}

	n, err := io.ReadFull(reader, buf[:sz])
	if err != nil {
		return err
	}
	if n != int(sz) {
		err = errors.New("read get less data than needed")
		return err
	}

	raw.Data = buf[:sz]
	return nil
}