Example #1
0
func (s *service) Progress(explorationID exploration.Identifier, nowTime time.Time) (int, error) {
	e, err := s.explorationRepository.Resolve(explorationID)
	if err != nil {
		return 0, err
	}

	d := dungeon.ResolveDungeon(e.DungeonID)

	progressCount := int(nowTime.Sub(e.StartTime) / d.ProgressTime)
	nowProgress := progressCount - e.ProgressCount
	progress := 0
	for i := 0; i < nowProgress; i++ {
		if e.IsEnd() {
			break
		}

		eventTime := e.StartTime.Add(d.ProgressTime * time.Duration(e.ProgressCount+(i+1)))
		e, err = s.progress(e, eventTime)
		if err != nil {
			return progress, err
		}

		progress++
	}
	e.ProgressCount += progress

	return progress, s.explorationRepository.Store(e)
}
Example #2
0
func (s *service) EventLog(explorationID exploration.Identifier) []string {
	message := []string{}

	e, err := s.explorationRepository.Resolve(explorationID)
	if err != nil {
		return message
	}

	d := dungeon.ResolveDungeon(e.DungeonID)
	message = append(message, fmt.Sprintf("%s : %s の探検を開始した。", e.StartTime.Format("2006-01-02 15:04:05"), d.Name))

	for _, ef := range e.Floors {
		message = append(message, fmt.Sprintf("%s : %d 階に到達した。", ef.StartTime.Format("2006-01-02 15:04:05"), ef.FloorNo))

		for _, ee := range ef.Events {
			message = append(message, s.messageFactory.BuildMessage(ee)...)
		}
	}

	return message
}
Example #3
0
func (s *service) nextFloor(e exploration.Exploration, eventTime time.Time) (exploration.Exploration, error) {
	floorNo := e.NextFloorNo()
	ef := exploration.NewFloor(floorNo, eventTime)
	e.Floors = append(e.Floors, ef)

	p, err := s.playerRepository.Resolve(e.PlayerID)
	if err != nil {
		return e, fmt.Errorf("player error %d: %s", e.PlayerID, err.Error())
	}
	p.AddExp(calcNextFloorExp(floorNo))

	if err := s.playerRepository.Store(p); err != nil {
		return e, fmt.Errorf("player store error %d: %s", e.PlayerID, err.Error())
	}

	// Clear判定
	if dungeon.ResolveDungeon(e.DungeonID).IsClear(e.NowFloorNo()) {
		return s.activeEvent(e, eventTime, event.PlayerClearEvent)
	} else {
		return e, nil
	}
}