Example #1
0
					target = s.pc
				} else {
					charList := model.CharactersIn(s.pc.GetRoomId())
					index := utils.BestMatch(targetName, charList.Names())

					if index == -1 {
						s.printError("Target not found")
					} else if index == -2 {
						s.printError("Which target do you mean?")
					} else {
						target = charList[index]
					}
				}

				if target != nil {
					s.WriteLineColor(types.ColorRed, "Casting %s on %s", skill.GetName(), target.GetName())
					combat.StartFight(s.pc, skill, target)
				}
			}
		},
	},
	"sb": aAlias("skillbook"),
	"skillbook": {
		exec: func(s *Session, arg string) {
			utils.ExecMenu("Skill Book", s, func(menu *utils.Menu) {
				menu.AddAction("a", "Add", func() bool {
					utils.ExecMenu("Select a skill to add", s, func(menu *utils.Menu) {
						for i, skill := range model.GetAllSkills() {
							sk := skill
							menu.AddActionI(i, skill.GetName(), func() bool {
								s.pc.AddSkill(sk.GetId())
Example #2
0
func MoveCharacter(character types.Character, direction types.Direction) error {
	room := GetRoom(character.GetRoomId())

	if room == nil {
		return errors.New("Character doesn't appear to be in any room")
	}

	if !room.HasExit(direction) {
		return errors.New("Attempted to move through an exit that the room does not contain")
	}

	if room.IsLocked(direction) {
		return errors.New("That way is locked")
	}

	newLocation := room.NextLocation(direction)
	newRoom := GetRoomByLocation(newLocation, room.GetZoneId())

	if newRoom == nil {
		zone := GetZone(room.GetZoneId())
		fmt.Printf("No room found at location %v %v, creating a new one (%s)\n", zone.GetName(), newLocation, character.GetName())

		var err error
		newRoom, err = CreateRoom(GetZone(room.GetZoneId()), newLocation)
		newRoom.SetTitle(room.GetTitle())
		newRoom.SetDescription(room.GetDescription())

		if err != nil {
			return err
		}

		switch direction {
		case types.DirectionNorth:
			newRoom.SetExitEnabled(types.DirectionSouth, true)
		case types.DirectionNorthEast:
			newRoom.SetExitEnabled(types.DirectionSouthWest, true)
		case types.DirectionEast:
			newRoom.SetExitEnabled(types.DirectionWest, true)
		case types.DirectionSouthEast:
			newRoom.SetExitEnabled(types.DirectionNorthWest, true)
		case types.DirectionSouth:
			newRoom.SetExitEnabled(types.DirectionNorth, true)
		case types.DirectionSouthWest:
			newRoom.SetExitEnabled(types.DirectionNorthEast, true)
		case types.DirectionWest:
			newRoom.SetExitEnabled(types.DirectionEast, true)
		case types.DirectionNorthWest:
			newRoom.SetExitEnabled(types.DirectionSouthEast, true)
		case types.DirectionUp:
			newRoom.SetExitEnabled(types.DirectionDown, true)
		case types.DirectionDown:
			newRoom.SetExitEnabled(types.DirectionUp, true)
		default:
			panic("Unexpected code path")
		}
	}

	MoveCharacterToRoom(character, newRoom)
	return nil
}