當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ICreature.GetPosition方法代碼示例

本文整理匯總了Golang中gameserver/interfaces.ICreature.GetPosition方法的典型用法代碼示例。如果您正苦於以下問題:Golang ICreature.GetPosition方法的具體用法?Golang ICreature.GetPosition怎麽用?Golang ICreature.GetPosition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gameserver/interfaces.ICreature的用法示例。


在下文中一共展示了ICreature.GetPosition方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: internalCreatureMove

func internalCreatureMove(_creature interfaces.ICreature, _direction uint16) world.ReturnValue {
	ret := world.RET_NOTPOSSIBLE

	if _creature.CanMove() {
		sourcePosition := _creature.GetPosition()
		destinationPosition := _creature.GetPosition()

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

		// Current TilePointLayer
		srcTpl, retValue := world.GetTilePointLayer(sourcePosition.MapId, sourcePosition.X, sourcePosition.Y, sourcePosition.Z)
		if retValue != world.RET_NOERROR {
			log.Debug("Game", "internalCreatureMove", "Source '[%d] %s' not found!", sourcePosition.MapId, sourcePosition.String())
			return retValue
		}

		// Destination TilePointLayer
		dstTpl, retValue := world.GetTilePointLayer(destinationPosition.MapId, destinationPosition.X, destinationPosition.Y, destinationPosition.Z)
		if retValue != world.RET_NOERROR {
			log.Debug("Game", "internalCreatureMove", "Destination '[%d] %s' not found!", destinationPosition.MapId, destinationPosition.String())
			return retValue
		}

		// Move creature to destination tile
		if ret = srcTpl.RemoveCreature(_creature, true); ret == world.RET_NOTPOSSIBLE {
			return ret
		}

		if ret = dstTpl.AddCreature(_creature, true); ret == world.RET_NOTPOSSIBLE {
			srcTpl.AddCreature(_creature, false) // Something went wrong. Put creature back on src TilePoint
			_creature.SetPosition(sourcePosition)
			return ret
		}

		if ret == world.RET_NOERROR {
			_creature.SetPosition(destinationPosition)
			finalDestination := _creature.GetPosition()

			// Get list of creatures who're "new"
			visibleCreatures := world.GetVisibleCreaturesInDirection(finalDestination.MapId, finalDestination.X, finalDestination.Y, finalDestination.Z, _direction)

			for _, value := range visibleCreatures {
				if value != nil {
					_creature.AddVisibleCreature(value)
				}
			}

			// Tell Creature he has moved
			_creature.Walk(sourcePosition, destinationPosition, false, _direction)
		}
	}

	return ret
}
開發者ID:toophy,項目名稱:go-gameserver,代碼行數:63,代碼來源:Game.go


注:本文中的gameserver/interfaces.ICreature.GetPosition方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。