Пример #1
0
func (n *Npc) OnCreatureDisappear(_creature pul.ICreature, _isLogout bool) {
	// Check if _creature is a Player, otherwise return
	if _creature.GetType() != CTYPE_PLAYER {
		return
	}

	n.RemoveVisibleCreature(_creature)
}
Пример #2
0
func (n *Npc) AddVisibleCreature(_creature pul.ICreature) {
	// Check if _creature is a Player, otherwise return
	if _creature.GetType() != CTYPE_PLAYER {
		return
	}

	if _, found := n.VisibleCreatures[_creature.GetUID()]; !found {
		n.VisibleCreatures[_creature.GetUID()] = _creature
	}
}
Пример #3
0
func (n *Npc) RemoveVisibleCreature(_creature pul.ICreature) {
	// Check if _creature is a Player, otherwise return
	if _creature.GetType() != CTYPE_PLAYER {
		return
	}

	// Check if the player was interacting with this npc
	if n.HasInteractingPlayer(_creature.(*Player)) {
		n.RemoveInteractingPlayer(_creature.(*Player))
	}

	// No need to check if the key actually exists because Go is awesome
	// http://golang.org/doc/effective_go.html#maps
	delete(n.VisibleCreatures, _creature.GetUID())
}
Пример #4
0
func (n *Npc) OnCreatureAppear(_creature pul.ICreature, _isLogin bool) {
	// Check if _creature is a Player, otherwise return
	if _creature.GetType() != CTYPE_PLAYER {
		return
	}

	canSeeCreature := CanSeeCreature(n, _creature)
	if !canSeeCreature {
		return
	}

	// We're checking the existence of _creature inside the AddVisibleCreature method
	// so no need to check here
	n.AddVisibleCreature(_creature)
	_creature.AddVisibleCreature(n)
}
Пример #5
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)
	}
}
Пример #6
0
func (g *Game) AddCreature(_creature pul.ICreature) {
	// TODO: Maybe only take the creatues from the area the new creature is in. This saves some extra iterating

	g.mutexCreatureList.Lock()
	defer g.mutexCreatureList.Unlock()
	for _, value := range g.Creatures {
		value.OnCreatureAppear(_creature, true)
	}

	g.Creatures[_creature.GetUID()] = _creature

	if _creature.GetType() == CTYPE_PLAYER {
		g.mutexPlayerList.Lock()
		defer g.mutexPlayerList.Unlock()
		g.Players[_creature.GetUID()] = _creature.(*Player)

		// Join default channels
		g.Chat.AddUserToChannel(_creature.(*Player), pnet.CHANNEL_WORLD)
		g.Chat.AddUserToChannel(_creature.(*Player), pnet.CHANNEL_TRADE)
	}
}
Пример #7
0
func (n *Npc) OnCreatureTurn(_creature pul.ICreature) {
	// Check if _creature is a Player, otherwise return
	if _creature.GetType() != CTYPE_PLAYER {
		return
	}
}
Пример #8
0
func (g *Game) checkForWildEncounter(_creature pul.ICreature) {
	if _creature.GetType() == CTYPE_PLAYER {
		// Do some checkin'
	}
}