Beispiel #1
0
// Hell function that turns bullshit into magic
func createMatch(player ols.Player, game goriot.Game) {
	match, err := goriot.MatchByMatchID("na", true, game.GameID)
	participants := map[int]*ols.Participant{} // championid -> participant
	participants[game.ChampionID] = &ols.Participant{Id: player.Id}
	if err != nil {
		log.Println("Match with id: ", game.GameID, " had an error:", err.Error())
		return
	}

	// Connect participants of an anonymous game to one of a recent game...
	for _, fellowPlayer := range game.FellowPlayers {
		participants[fellowPlayer.ChampionID] = &ols.Participant{Id: fellowPlayer.SummonerID}
	}

	// All info is connected now!
	for _, matchPlayer := range match.Participants {
		participant := participants[matchPlayer.ChampionID]
		participant.ParticipantId = matchPlayer.ParticipantID
	}

	var matchParticipants []ols.Participant
	for _, participant := range participants {
		matchParticipants = append(matchParticipants, *participant)
	}
	///////////////////////
	blueTeam := getTeamName(game, BLUE_TEAM)
	redTeam := getTeamName(game, RED_TEAM)
	winnerTeam := blueTeam

	if game.Statistics.Win && game.TeamID == RED_TEAM {
		winnerTeam = redTeam
	}
	week := ols.GetMatchesDAO().LoadWeekForMatch(blueTeam, redTeam)
	olsMatch := ols.Match{
		Participants: matchParticipants,
		BlueTeam:     blueTeam,
		RedTeam:      redTeam,
		Played:       true,
		Week:         week,
		Winner:       winnerTeam,
		Id:           game.GameID,
	}
	log.Println("Match found! ", olsMatch)
	ols.GetMatchesDAO().Save(olsMatch)
}
Beispiel #2
0
func UpdateMatches() {
	matches := ols.GetMatchesDAO().All()
	for _, match := range matches {
		matchInfo, err := goriot.MatchByMatchID("na", false, match.Id)
		for _, participant := range match.Participants {
			participant.ChampionId = getParticipantChampionId(matchInfo, participant.ChampionId)
		}
		ols.GetMatchesDAO().Save(*match)
		if err != nil {
			log.Println("Error: ", err)
		} else {
			log.Println("saved: ", match.BlueTeam, " vs ", match.RedTeam)
			if !ols.GetMatchesDAO().IsLeagueGameSaved(matchInfo) {
				ols.GetMatchesDAO().SaveLeagueGame(matchInfo)
			}

		}

	}
}