当前位置: 首页>>代码示例>>Golang>>正文


Golang ICreature.Walk方法代码示例

本文整理汇总了Golang中gameserver/interfaces.ICreature.Walk方法的典型用法代码示例。如果您正苦于以下问题:Golang ICreature.Walk方法的具体用法?Golang ICreature.Walk怎么用?Golang ICreature.Walk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gameserver/interfaces.ICreature的用法示例。


在下文中一共展示了ICreature.Walk方法的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.Walk方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。