2017-11-21 06:06:32 +04:00
|
|
|
|
// i2_bot – Instinct PokememBro Bot
|
|
|
|
|
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
|
|
|
|
|
|
|
|
|
package pokedexer
|
|
|
|
|
|
|
|
|
|
import (
|
2018-01-21 23:28:53 +04:00
|
|
|
|
"git.wtfteam.pro/fat0troll/i2_bot/lib/dbmapping"
|
2018-01-29 23:50:25 +04:00
|
|
|
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
2017-11-21 06:06:32 +04:00
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
2018-02-07 15:00:04 +04:00
|
|
|
|
// AdvicePokememesList shows list for catching
|
|
|
|
|
// It may be list of best or most valuable pokememes
|
|
|
|
|
func (p *Pokedexer) AdvicePokememesList(update *tgbotapi.Update, playerRaw *dbmapping.Player) string {
|
2018-02-07 15:59:28 +04:00
|
|
|
|
pokememes, ok := p.getAdvicePokememes(playerRaw.ID, update.Message.Command())
|
|
|
|
|
if !ok {
|
|
|
|
|
c.Log.Error("Cannot get pokememes from getter!")
|
|
|
|
|
return "fail"
|
2017-11-21 06:06:32 +04:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-30 02:26:47 +04:00
|
|
|
|
profileRaw, err := c.DataCache.GetProfileByPlayerID(playerRaw.ID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.Log.Error(err.Error())
|
|
|
|
|
return "fail"
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-07 15:00:04 +04:00
|
|
|
|
message := ""
|
2018-02-07 15:59:28 +04:00
|
|
|
|
switch update.Message.Command() {
|
|
|
|
|
case "best":
|
|
|
|
|
message += "*Пять топовых покемемов для поимки*\n\n"
|
|
|
|
|
case "advice":
|
|
|
|
|
message += "*Пять самых дорогих покемемов*\n\n"
|
|
|
|
|
case "best_all":
|
|
|
|
|
message += "*Все топовые покемемы для твоего уровня*\n\n"
|
|
|
|
|
case "advice_all":
|
|
|
|
|
message += "*Все самые дорогие покемемы для твоего уровня*\n\n"
|
|
|
|
|
case "best_nofilter":
|
|
|
|
|
message += "*Пять топовых покемемов для поимки без фильтра по элементам*\n\n"
|
2018-02-07 15:00:04 +04:00
|
|
|
|
}
|
2018-02-07 14:05:08 +04:00
|
|
|
|
for i := range pokememes {
|
2017-11-21 06:06:32 +04:00
|
|
|
|
pk := pokememes[i].Pokememe
|
|
|
|
|
pkL := pokememes[i].Locations
|
|
|
|
|
pkE := pokememes[i].Elements
|
|
|
|
|
message += strconv.Itoa(pk.Grade) + "⃣ "
|
|
|
|
|
message += pk.Name + " (⚔"
|
|
|
|
|
message += c.Statistics.GetPrintablePoints(pk.Attack)
|
|
|
|
|
message += ", 🛡" + c.Statistics.GetPrintablePoints(pk.Defence) + ")"
|
|
|
|
|
for i := range pkE {
|
|
|
|
|
message += pkE[i].Symbol
|
|
|
|
|
}
|
2018-01-30 02:26:47 +04:00
|
|
|
|
message += " /pk" + strconv.Itoa(pk.ID) + "\nЛокации: "
|
2017-11-21 06:06:32 +04:00
|
|
|
|
for i := range pkL {
|
|
|
|
|
message += pkL[i].Symbol + pkL[i].Name
|
2018-01-30 02:26:47 +04:00
|
|
|
|
_, balls := c.Statistics.PossibilityRequiredPokeballs(pkL[i].ID, pk.Grade, profileRaw.LevelID)
|
|
|
|
|
message += " ⭕" + strconv.Itoa(balls)
|
2017-11-21 06:06:32 +04:00
|
|
|
|
if i+1 < len(pkL) {
|
|
|
|
|
message += ", "
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
message += "\nКупить: "
|
|
|
|
|
if pk.Purchaseable {
|
|
|
|
|
message += "💲" + c.Statistics.GetPrintablePoints(pk.Price*3)
|
|
|
|
|
} else {
|
|
|
|
|
message += "Нельзя"
|
|
|
|
|
}
|
2018-02-07 15:59:28 +04:00
|
|
|
|
if update.Message.Command() == "advice" || update.Message.Command() == "advice_all" {
|
2018-02-07 15:00:04 +04:00
|
|
|
|
message += "\nСтоимость продажи: 💲" + c.Statistics.GetPrintablePoints(pk.Price)
|
|
|
|
|
}
|
2018-02-07 15:59:28 +04:00
|
|
|
|
if len(message) > 4000 {
|
2018-01-30 02:26:47 +04:00
|
|
|
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
|
|
|
|
msg.ParseMode = "Markdown"
|
|
|
|
|
|
|
|
|
|
c.Bot.Send(msg)
|
|
|
|
|
|
|
|
|
|
message = ""
|
|
|
|
|
} else {
|
|
|
|
|
message += "\n\n"
|
|
|
|
|
}
|
2017-11-21 06:06:32 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
|
|
|
|
msg.ParseMode = "Markdown"
|
|
|
|
|
|
|
|
|
|
c.Bot.Send(msg)
|
|
|
|
|
|
|
|
|
|
return "ok"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PokememesList lists all known pokememes
|
|
|
|
|
func (p *Pokedexer) PokememesList(update *tgbotapi.Update) {
|
|
|
|
|
pageNumber := strings.Replace(update.Message.Text, "/pokedex", "", 1)
|
|
|
|
|
pageNumber = strings.Replace(pageNumber, "/pokedeks", "", 1)
|
|
|
|
|
page, _ := strconv.Atoi(pageNumber)
|
|
|
|
|
if page == 0 {
|
|
|
|
|
page = 1
|
|
|
|
|
}
|
2018-01-29 23:50:25 +04:00
|
|
|
|
pokememesArray := c.DataCache.GetAllPokememes()
|
|
|
|
|
p.pokememesListing(update, page, pokememesArray)
|
2017-11-21 06:06:32 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PokememeInfo shows information about single pokememe based on internal ID
|
|
|
|
|
func (p *Pokedexer) PokememeInfo(update *tgbotapi.Update, playerRaw *dbmapping.Player) string {
|
|
|
|
|
pokememeNumber := strings.Replace(update.Message.Text, "/pk", "", 1)
|
|
|
|
|
var calculatePossibilites = true
|
2018-01-29 23:50:25 +04:00
|
|
|
|
profileRaw, err := c.DataCache.GetProfileByPlayerID(playerRaw.ID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.Log.Error(err.Error())
|
2017-11-21 06:06:32 +04:00
|
|
|
|
calculatePossibilites = false
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-29 23:50:25 +04:00
|
|
|
|
pokememeID, _ := strconv.Atoi(pokememeNumber)
|
|
|
|
|
pokememe, err := c.DataCache.GetPokememeByID(pokememeID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.Log.Error(err.Error())
|
2017-11-21 06:06:32 +04:00
|
|
|
|
return "fail"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pk := pokememe.Pokememe
|
|
|
|
|
|
|
|
|
|
message := strconv.Itoa(pk.Grade) + "⃣ *" + pk.Name + "*\n"
|
|
|
|
|
message += pk.Description + "\n\n"
|
|
|
|
|
message += "Элементы:"
|
|
|
|
|
for i := range pokememe.Elements {
|
|
|
|
|
message += " " + pokememe.Elements[i].Symbol
|
|
|
|
|
}
|
|
|
|
|
message += "\n⚔ Атака: *" + c.Statistics.GetPrintablePoints(pk.Attack)
|
|
|
|
|
message += "*\n❤️ HP: *" + c.Statistics.GetPrintablePoints(pk.HP)
|
|
|
|
|
message += "*\n💙 MP: *" + c.Statistics.GetPrintablePoints(pk.MP)
|
|
|
|
|
if pk.Defence != pk.Attack {
|
|
|
|
|
message += "*\n🛡Защита: *" + c.Statistics.GetPrintablePoints(pk.Defence) + "* _(сопротивляемость покемема к поимке)_"
|
|
|
|
|
} else {
|
|
|
|
|
message += "*"
|
|
|
|
|
}
|
|
|
|
|
message += "\nСтоимость: *" + c.Statistics.GetPrintablePoints(pk.Price)
|
|
|
|
|
message += "*\nКупить: *"
|
|
|
|
|
if pk.Purchaseable {
|
|
|
|
|
message += "Можно"
|
|
|
|
|
} else {
|
|
|
|
|
message += "Нельзя"
|
|
|
|
|
}
|
|
|
|
|
message += "*\nОбитает:"
|
|
|
|
|
for i := range pokememe.Locations {
|
|
|
|
|
message += " *" + pokememe.Locations[i].Name + "*"
|
|
|
|
|
if (i + 1) < len(pokememe.Locations) {
|
|
|
|
|
message += ","
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if calculatePossibilites {
|
|
|
|
|
if (pk.Grade < profileRaw.LevelID+2) && (pk.Grade > profileRaw.LevelID-3) {
|
|
|
|
|
message += "\nВероятность поимки:"
|
|
|
|
|
for i := range pokememe.Locations {
|
|
|
|
|
percentile, pokeballs := c.Statistics.PossibilityRequiredPokeballs(pokememe.Locations[i].ID, pk.Grade, profileRaw.LevelID)
|
|
|
|
|
message += "\n" + pokememe.Locations[i].Name + " – "
|
|
|
|
|
message += strconv.FormatFloat(percentile, 'f', 2, 64) + "% или "
|
|
|
|
|
message += strconv.Itoa(pokeballs) + "⭕"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
message += "\n" + pk.ImageURL
|
|
|
|
|
|
|
|
|
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
|
|
|
|
keyboard := tgbotapi.InlineKeyboardMarkup{}
|
|
|
|
|
for i := range pokememe.Locations {
|
|
|
|
|
var row []tgbotapi.InlineKeyboardButton
|
|
|
|
|
btn := tgbotapi.NewInlineKeyboardButtonSwitch(pokememe.Locations[i].Symbol+pokememe.Locations[i].Name, pokememe.Locations[i].Symbol+pokememe.Locations[i].Name)
|
|
|
|
|
row = append(row, btn)
|
|
|
|
|
keyboard.InlineKeyboard = append(keyboard.InlineKeyboard, row)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
msg.ReplyMarkup = keyboard
|
|
|
|
|
msg.ParseMode = "Markdown"
|
|
|
|
|
|
|
|
|
|
c.Bot.Send(msg)
|
|
|
|
|
|
|
|
|
|
return "ok"
|
|
|
|
|
}
|