Пример #1
0
func (e *Warp) OnCreatureEnter(_creature pul.ICreature, _prevRet int) (ret int) {
	currentTile := _creature.GetTile()
	destinationTile, found := g_map.GetTileFromPosition(e.destination)

	if found {
		ret = g_game.internalCreatureTeleport(_creature, currentTile, destinationTile)
	} else {
		ret = RET_NOTPOSSIBLE
	}

	return
}
Пример #2
0
func (g *Game) OnPlayerMove(_creature pul.ICreature, _direction int, _sendMap bool) {
	ret := g.OnCreatureMove(_creature, _direction)

	player := _creature.(*Player)
	if ret == RET_NOTPOSSIBLE {
		player.sendCreatureMove(_creature, _creature.GetTile(), _creature.GetTile())
	} else if ret == RET_PLAYERISTELEPORTED {
		player.sendPlayerWarp()
		player.sendMapData(DIR_NULL)
	} else {
		player.sendMapData(_direction)
	}
}
Пример #3
0
func (g *Game) OnCreatureMove(_creature pul.ICreature, _direction int) (ret int) {
	ret = RET_NOTPOSSIBLE

	if !CreatureCanMove(_creature) {
		return
	}

	currentTile := _creature.GetTile()
	destinationPosition := currentTile.GetPosition()

	switch _direction {
	case DIR_NORTH:
		destinationPosition.Y -= 1
	case DIR_SOUTH:
		destinationPosition.Y += 1
	case DIR_WEST:
		destinationPosition.X -= 1
	case DIR_EAST:
		destinationPosition.X += 1
	}

	// Check if destination tile exists
	destinationTile, ok := g_map.GetTileFromPosition(destinationPosition)
	if !ok {
		return
	}

	// Check if we can move to the destination tile
	if ret = destinationTile.CheckMovement(_creature, _direction); ret == RET_NOTPOSSIBLE {
		return
	}

	// Update position
	_creature.SetTile(destinationTile)

	// fmt.Printf("[%v] From (%v,%v) To (%v,%v)\n", _creature.GetName(), currentTile.Position.X, currentTile.Position.Y, destinationPosition.X, destinationPosition.Y)

	// Tell creatures this creature has moved
	g.mutexCreatureList.RLock()
	defer g.mutexCreatureList.RUnlock()
	for _, value := range g.Creatures {
		if value != nil {
			value.OnCreatureMove(_creature, currentTile, destinationTile, false)
		}
	}

	// Move creature object to destination tile
	if ret = currentTile.RemoveCreature(_creature, true); ret == RET_NOTPOSSIBLE {
		return
	}
	if ret = destinationTile.AddCreature(_creature, true); ret == RET_NOTPOSSIBLE {
		currentTile.AddCreature(_creature, false) // Something went wrong, put creature back on old tile
		_creature.SetTile(currentTile)
		return
	}

	// If ICreature is a player type we can check for wild encounter
	g.checkForWildEncounter(_creature)

	return
}