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...) }
func (s *service) lotActionEvent(dungeonID dungeon.Identifier, floorNo int) event.Event { var lotEvent event.Event // ダンジョン内の移動(探索)を選択したときの抽選 lotEventID := s.lotteryFactory.LotEvent(dungeonID, floorNo) switch lotEventID { case event.EventGetItem: itemID, num := s.lotteryFactory.LotItem(dungeonID, floorNo) lotEvent = event.NewEvent(lotEventID, event.SubIdentifier(itemID), num) case event.EventEnemyEncounter: enemyID, level := s.lotteryFactory.LotEnemy(dungeonID, floorNo) lotEvent = event.NewEvent(lotEventID, event.SubIdentifier(enemyID), level) case event.EventTrap: trapID, num := s.lotteryFactory.LotTrap(dungeonID, floorNo) lotEvent = event.NewEvent(lotEventID, event.SubIdentifier(trapID), num) default: lotEvent = event.NoneEvent } return lotEvent }
func (b *Encounter) BuildEvents(playerID character.PlayerIdentifier) []event.Event { resultEvents := []event.Event{} for _, l := range b.Logs { // playerのステータス更新とenemyのステータス更新 switch l.ActionType { case EnemyDown: e := event.NewEvent(event.EventBattleWin, event.SubIdentifier(b.Enemy.ID), l.Value) resultEvents = append(resultEvents, e) case PlayerDown: e := event.NewEvent(event.EventBattleLose, event.SubIdentifier(playerID), l.Value) resultEvents = append(resultEvents, e) case PlayerAttack: e := event.NewEvent(event.EventBattleAttack, event.SubIdentifier(b.Enemy.ID), l.Value) resultEvents = append(resultEvents, e) case EnemyAttack: e := event.NewEvent(event.EventBattleDamage, event.SubIdentifier(playerID), l.Value) resultEvents = append(resultEvents, e) default: panic("not found case " + l.ActionType) } } return resultEvents }