Exemple #1
0
func (s *service) event(e exploration.Exploration, eventTime time.Time) (exploration.Exploration, error) {
	p, err := s.playerRepository.Resolve(e.PlayerID)
	if err != nil {
		return e, fmt.Errorf("player error %d: %s", e.PlayerID, err.Error())
	}

	activeEvents := []event.Event{}

	// 戦闘中ならevent抽選しない
	if e.IsEnemyBattle() {
		p = e.EnemyEncounter.Battle(p)
		activeEvents = append(activeEvents, e.EnemyEncounter.BuildEvents(e.PlayerID)...)
		// TODO: Battle結果反映 ここでlogs消すのいまいち...
		e.EnemyEncounter.Logs = []battle.BattleLog{}
	} else {
		ev := event.NoneEvent
		switch {
		case p.IsUseHPRecovery(): // HP回復アイテム消費イベント生成
			if itm, ok := p.Inventory.FindItemType(item.HPRecoverItemType); ok {
				ev = event.NewEvent(event.EventUseItem, event.SubIdentifier(itm.ID), itm.Value)
			}
		case p.IsUseMPRecovery(): // MP回復アイテム消費イベント生成
			if itm, ok := p.Inventory.FindItemType(item.MPRecoverItemType); ok {
				ev = event.NewEvent(event.EventUseItem, event.SubIdentifier(itm.ID), itm.Value)
			}
		}

		if ev == event.NoneEvent {
			// 探索行動イベント抽選
			ev = s.lotActionEvent(e.DungeonID, e.NowFloorNo())
		}

		// 探索に探索行動イベントを反映
		activeEvents = append(activeEvents, ev)

		// 探索行動イベントをプレイヤーにイベントを反映
		if isEffect := p.EffectEvent(ev); !isEffect {
			// もしerrorになった場合errorイベントを探索に反映する
			activeEvents = append(activeEvents, ev.BuildNotEvent())
		}
	}

	// プレイヤー力尽き判定
	if p.IsDown() {
		activeEvents = append(activeEvents, event.PlayerDownEvent)
	}

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

	return s.activeEvent(e, eventTime, activeEvents...)
}
Exemple #2
0
func (s *service) progress(e exploration.Exploration, eventTime time.Time) (exploration.Exploration, error) {
	var err error
	if e.IsNextFloor() {
		e, err = s.nextFloor(e, eventTime)
	} else {
		e, err = s.event(e, eventTime)
	}
	if err != nil {
		return e, err
	}

	return e, nil
}
Exemple #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
	}
}
Exemple #4
0
func (s *service) activeEvent(e exploration.Exploration, eventTime time.Time, evs ...event.Event) (exploration.Exploration, error) {
	if len(evs) == 0 {
		return e, nil
	}

	if ok, err := e.IsActive(); err != nil {
		return e, err
	} else if !ok {
		return e, nil
	}

	for _, ev := range evs {
		e.NowFloor().AddProgress(ev)
		e.NowFloor().AddEvent(ev, eventTime)

		switch {
		case ev.IsEnemyEncounter():
			e.EnemyEncounter = battle.New(s.enemyFactory.CreateEnemy(character.EnemyIdentifier(ev.SubID), ev.Num))
		case ev.IsPlayerDownEnd():
			e.DownEnd(eventTime)
		case ev.IsPlayerEscapeEnd():
			e.EscapeEnd(eventTime)
		case ev.IsPlayerClearEnd():
			e.ClearEnd(eventTime)
		}
	}

	return e, nil
}