Beispiel #1
0
func (n *Npc) OnCreatureMove(_creature pul.ICreature, _from pul.ITile, _to pul.ITile, _teleport bool) {
	// Check if _creature is a Player, otherwise return
	if _creature.GetType() != CTYPE_PLAYER {
		return
	}

	canSeeFromTile := CanSeePosition(n.GetPosition(), _from.GetPosition())
	canSeeToTile := CanSeePosition(n.GetPosition(), _to.GetPosition())

	if canSeeFromTile && !canSeeToTile { // Leaving viewport
		n.RemoveVisibleCreature(_creature)
		_creature.RemoveVisibleCreature(n)
	} else if canSeeToTile && !canSeeFromTile { // Entering viewport
		n.AddVisibleCreature(_creature)
		_creature.RemoveVisibleCreature(n)
	} else { // Moving inside viewport
		n.AddVisibleCreature(_creature)
		_creature.AddVisibleCreature(n)
	}
}
Beispiel #2
0
func (g *Game) internalCreatureTeleport(_creature pul.ICreature, _from pul.ITile, _to pul.ITile) (ret int) {
	ret = RET_NOERROR

	if _from == nil || _to == nil {
		ret = RET_NOTPOSSIBLE
	} else {
		// Move creature object to destination tile
		if ret = _from.RemoveCreature(_creature, true); ret == RET_NOTPOSSIBLE {
			return
		}

		if ret = _to.AddCreature(_creature, false); ret == RET_NOTPOSSIBLE {
			_from.AddCreature(_creature, false) // Something went wrong, put creature back on old tile
			return
		}

		_creature.SetTile(_to)

		// Tell creatures this creature has been teleported
		g.mutexCreatureList.RLock()
		defer g.mutexCreatureList.RUnlock()
		for _, value := range g.Creatures {
			if value != nil {
				value.OnCreatureMove(_creature, _from, _to, true)
			}
		}
	}

	// No error, played succesfully teleported
	if ret == RET_NOERROR {
		ret = RET_PLAYERISTELEPORTED
	}

	return
}
func (m *SendTilesMessage) AddTile(_tile pul.ITile) {
	m.Tiles[_tile.GetPosition().Hash()] = _tile
}