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


Golang interfaces.ICreature类代码示例

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


在下文中一共展示了ICreature类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: KnowsVisibleCreature

func (c *Creature) KnowsVisibleCreature(_creature interfaces.ICreature) bool {
	c.visibleCreaturesMutex.RLock()
	defer c.visibleCreaturesMutex.RUnlock()

	_, found := c.visibleCreatures[_creature.GetUID()]
	return found
}
开发者ID:toophy,项目名称:go-gameserver,代码行数:7,代码来源:Creature.go

示例2: AddCreature

func (t *TilePointLayer) AddCreature(_creature interfaces.ICreature, _checkEvents bool) ReturnValue {
	ret := RET_NOERROR

	/*if _checkEvents && t.Events.Len() > 0 {
		for e := t.events.Front(); e != nil; e = e.Next() {
			event, valid := e.Value.(pulogic.ITileEvent)
			if valid {
				ret = event.OnCreatureEnter(_creature, ret)
			}

			if ret == RET_NOTPOSSIBLE {
				return
			}
		}
	}*/

	t.creaturesMutex.Lock()
	defer t.creaturesMutex.Unlock()
	_, found := t.creatures[_creature.GetUID()]
	if !found {
		t.creatures[_creature.GetUID()] = _creature
	}

	return ret
}
开发者ID:toophy,项目名称:go-gameserver,代码行数:25,代码来源:TilePointLayer.go

示例3: OnCreatureTurn

func (p *Player) OnCreatureTurn(_creature interfaces.ICreature) {
	p.Creature.OnCreatureTurn(_creature)

	// Do nothing is creature is me
	if p.GetUID() == _creature.GetUID() {
		return
	}

	p.netSendCreatureTurn(_creature)
}
开发者ID:toophy,项目名称:go-gameserver,代码行数:10,代码来源:Player.go

示例4: internalAddCreature

/***********************
	Private Methods
************************/
func internalAddCreature(_creature interfaces.ICreature) bool {
	_, found := g.creatures[_creature.GetUID()]

	if !found {
		g.creatures[_creature.GetUID()] = _creature
	} else {
		log.Warning("Game", "AddCreature", "Could not add creature. Creature with UID '%d' already exists", _creature.GetUID())
	}

	return !found
}
开发者ID:toophy,项目名称:go-gameserver,代码行数:14,代码来源:Game.go

示例5: RemoveVisibleCreature

func (c *Creature) RemoveVisibleCreature(_creature interfaces.ICreature) bool {
	if _creature.GetUID() != c.GetUID() {
		c.visibleCreaturesMutex.Lock()
		defer c.visibleCreaturesMutex.Unlock()

		delete(c.visibleCreatures, _creature.GetUID())

		return true
	}

	return false
}
开发者ID:toophy,项目名称:go-gameserver,代码行数:12,代码来源:Creature.go

示例6: OnCreatureMove

func (p *Player) OnCreatureMove(_creature interfaces.ICreature, _from position.Position, _to position.Position, _teleport bool) {
	// Call base function
	p.Creature.OnCreatureMove(_creature, _from, _to, _teleport)

	// Do nothing is creature is me
	if p.GetUID() == _creature.GetUID() {
		return
	}

	canSeeFromPosition := p.CanSeePosition(_from)
	canSeeToPosition := p.CanSeePosition(_to)

	if canSeeFromPosition && canSeeToPosition {
		// We can see both from and to positions, meaning the creature is moving inside the viewport
		p.netSendCreatureMove(_creature, _from, _to, _teleport)
	} else if canSeeFromPosition && !canSeeToPosition {
		// We can see the from position but not the to positioin, meaning the creature is leaving our viewport
		// Send CreatureMove message to client before removing the creature from the visible creatures list
		p.netSendCreatureMove(_creature, _from, _to, _teleport)

		p.RemoveVisibleCreature(_creature)
		_creature.RemoveVisibleCreature(p)
	} else if !canSeeFromPosition && canSeeToPosition {
		// We can't see the from position but we can see the to position, meaning the creature is entering our viewport
		// First add the creature to our visible creature list before sending the CreatureMove message to the client
		p.AddVisibleCreature(_creature)
		_creature.AddVisibleCreature(p)

		p.netSendCreatureMove(_creature, _from, _to, _teleport)
	} else {
		// Somehow it's impossible to see the creature, may this ever happen somehow
		p.RemoveVisibleCreature(_creature)
		_creature.RemoveVisibleCreature(p)
	}
}
开发者ID:toophy,项目名称:go-gameserver,代码行数:35,代码来源:Player.go

示例7: AddVisibleCreature

// Methods for all creatures who need to see other creatures
func (c *Creature) AddVisibleCreature(_creature interfaces.ICreature) bool {
	if _creature.GetUID() != c.GetUID() {
		c.visibleCreaturesMutex.Lock()
		defer c.visibleCreaturesMutex.Unlock()

		if _, found := c.visibleCreatures[_creature.GetUID()]; !found {
			c.visibleCreatures[_creature.GetUID()] = _creature

			return true
		}
	}

	return false
}
开发者ID:toophy,项目名称:go-gameserver,代码行数:15,代码来源:Creature.go

示例8: OnCreatureMove

// Methods for all moving creatures
func (c *Creature) OnCreatureMove(_creature interfaces.ICreature, _from position.Position, _to position.Position, _teleport bool) {
	if _creature.GetUID() == c.GetUID() {
		c.lastStep = interfaces.PUSYS_TIME()
	}
}
开发者ID:toophy,项目名称:go-gameserver,代码行数:6,代码来源:Creature.go

示例9: 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

示例10: OnCreatureTurn

func OnCreatureTurn(_creature interfaces.ICreature, _direction uint16) {
	if _direction != _creature.GetDirection() {
		_creature.Turn(_direction)
	}
}
开发者ID:toophy,项目名称:go-gameserver,代码行数:5,代码来源:Game.go

示例11: netSendCreatureTurn

func (p *Player) netSendCreatureTurn(_creature interfaces.ICreature) {
	msg := netmsg.NewTurnMessage(_creature)
	msg.AddDirection(_creature.GetDirection())

	p.txChan <- msg
}
开发者ID:toophy,项目名称:go-gameserver,代码行数:6,代码来源:Player.go


注:本文中的gameserver/interfaces.ICreature类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。