Exemple #1
0
func manageNpc(npc types.NPC) {
	eventChannel := events.Register(npc)

	go func() {
		defer events.Unregister(npc)

		for {
			event := <-eventChannel
			switch e := event.(type) {
			case events.TickEvent:
				if npc.GetRoaming() {
					room := model.GetRoom(npc.GetRoomId())
					exits := room.GetExits()
					exitToTake := utils.Random(0, len(exits)-1)
					model.MoveCharacter(npc, exits[exitToTake])
				}
			case events.CombatStartEvent:
				if npc == e.Defender {
					combat.StartFight(npc, nil, e.Attacker)
				}
			case events.CombatStopEvent:
				if npc == e.Defender {
					combat.StopFight(npc)
				}
			case events.DeathEvent:
				if npc == e.Character {
					model.DeleteCharacter(npc.GetId())
					return
				}
			}
		}
	}()
}
Exemple #2
0
			s.WriteLinef("Weight: %v/%v", model.CharacterWeight(s.pc), s.pc.GetCapacity())
		},
	},
	"help": {
		exec: func(s *Session, arg string) {
			s.WriteLine("HELP!")
		},
	},
	"ls": {
		exec: func(s *Session, arg string) {
			s.WriteLine("Where do you think you are?!")
		},
	},
	"stop": {
		exec: func(s *Session, arg string) {
			combat.StopFight(s.pc)
		},
	},
	"go": {
		exec: func(s *Session, arg string) {
			if arg == "" {
				s.printError("Usage: go <name>")
				return
			}

			links := s.GetRoom().GetLinks()
			linkNames := s.GetRoom().LinkNames()
			index := utils.BestMatch(arg, linkNames)

			if index == -2 {
				s.printError("Which one do you mean?")