Latest game update reflections
Added ``pokememes_wealth`` in profiles, because we now can retrieve it from profiles. Removed ``pokememe_lvl`` from profile pokememes due to latest game update, where level calculating become almost impossible (or hard enough to throw it away). Added ``pokememe_attack`` for profile pokememes, which will be used instead of level.
This commit is contained in:
parent
c99648b72a
commit
88c9853c77
@ -12,7 +12,7 @@ import (
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
const VERSION = "0.295"
|
||||
const VERSION = "0.297"
|
||||
|
||||
// DatabaseConnection handles database connection settings in config.yaml
|
||||
type DatabaseConnection struct {
|
||||
|
@ -17,6 +17,7 @@ type Profile struct {
|
||||
LevelID int `db:"level_id"`
|
||||
Pokeballs int `db:"pokeballs"`
|
||||
Wealth int `db:"wealth"`
|
||||
PokememesWealth int `db:"pokememes_wealth"`
|
||||
Exp int `db:"exp"`
|
||||
EggExp int `db:"egg_exp"`
|
||||
Power int `db:"power"`
|
||||
|
@ -13,7 +13,7 @@ type ProfilePokememe struct {
|
||||
ID int `db:"id"`
|
||||
ProfileID int `db:"profile_id"`
|
||||
PokememeID int `db:"pokememe_id"`
|
||||
PokememeLevel int `db:"pokememe_lvl"`
|
||||
PokememeAttack int `db:"pokememe_attack"`
|
||||
PokememeRarity string `db:"pokememe_rarity"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
}
|
||||
|
37
lib/migrations/17_change_profile_pokememes_columns.go
Normal file
37
lib/migrations/17_change_profile_pokememes_columns.go
Normal file
@ -0,0 +1,37 @@
|
||||
// i2_bot – Instinct PokememBro Bot
|
||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func ChangeProfilePokememesColumnsUp(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("ALTER TABLE `profiles_pokememes` ADD COLUMN `pokememe_attack` INT(11) NOT NULL DEFAULT 0 COMMENT 'Атака покемема' AFTER `pokememe_id`;;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = tx.Exec("ALTER TABLE `profiles_pokememes` DROP COLUMN `pokememe_lvl`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ChangeProfilePokememesColumnsDown(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("ALTER TABLE `profiles_pokememes` ADD COLUMN `pokememe_lvl` INT(11) NOT NULL DEFAULT 0 COMMENT 'Уровень покемема' AFTER `pokememe_id`;;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = tx.Exec("ALTER TABLE `profiles_pokememes` DROP COLUMN `pokememe_attack`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
27
lib/migrations/18_add_pokememes_wealth.go
Normal file
27
lib/migrations/18_add_pokememes_wealth.go
Normal file
@ -0,0 +1,27 @@
|
||||
// i2_bot – Instinct PokememBro Bot
|
||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func AddPokememesWealthUp(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("ALTER TABLE `profiles` ADD COLUMN `pokememes_wealth` INT(11) NOT NULL DEFAULT 0 COMMENT 'Стоимость покемонов на руках' AFTER `wealth`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func AddPokememesWealthDown(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("ALTER TABLE `profiles` DROP COLUMN `pokememes_wealth`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -31,6 +31,8 @@ func (m *Migrations) Init() {
|
||||
goose.AddNamedMigration("14_fix_time_element.go", FixTimeElementUp, FixTimeElementDown)
|
||||
goose.AddNamedMigration("15_create_chats.go", CreateChatsUp, CreateChatsDown)
|
||||
goose.AddNamedMigration("16_change_chat_type_column.go", ChangeChatTypeColumnUp, ChangeChatTypeColumnDown)
|
||||
goose.AddNamedMigration("17_change_profile_pokememes_columns.go", ChangeProfilePokememesColumnsUp, ChangeProfilePokememesColumnsDown)
|
||||
goose.AddNamedMigration("18_add_pokememes_wealth.go", AddPokememesWealthUp, AddPokememesWealthDown)
|
||||
}
|
||||
|
||||
func (m *Migrations) Migrate() error {
|
||||
|
@ -25,20 +25,13 @@ func (p *Parsers) fillProfilePokememe(profileID int, meme string, attack string,
|
||||
log.Println(err)
|
||||
} else {
|
||||
attackInt := p.getPoints(attack)
|
||||
// Improve it. Game's precision is unstable
|
||||
origAttack := float64(spkRaw.Attack)
|
||||
if rarity == "rare" {
|
||||
origAttack = origAttack * 1.1
|
||||
}
|
||||
level := int(float64(attackInt) / origAttack)
|
||||
|
||||
ppk := dbmapping.ProfilePokememe{}
|
||||
ppk.ProfileID = profileID
|
||||
ppk.PokememeID = spkRaw.ID
|
||||
ppk.PokememeLevel = level
|
||||
ppk.PokememeAttack = attackInt
|
||||
ppk.PokememeRarity = rarity
|
||||
ppk.CreatedAt = time.Now().UTC()
|
||||
_, err2 := c.Db.NamedExec("INSERT INTO `profiles_pokememes` VALUES(NULL, :profile_id, :pokememe_id, :pokememe_lvl, :pokememe_rarity, :created_at)", &ppk)
|
||||
_, err2 := c.Db.NamedExec("INSERT INTO `profiles_pokememes` VALUES(NULL, :profile_id, :pokememe_id, :pokememe_attack, :pokememe_rarity, :created_at)", &ppk)
|
||||
if err2 != nil {
|
||||
log.Println(err2)
|
||||
}
|
||||
@ -72,6 +65,8 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, playerRaw dbmapping.Playe
|
||||
pokeballsInt := 0
|
||||
wealth := ""
|
||||
wealthInt := 0
|
||||
pokememesWealth := ""
|
||||
pokememesWealthInt := 0
|
||||
crystalls := ""
|
||||
crystallsInt := 0
|
||||
weapon := ""
|
||||
@ -151,13 +146,15 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, playerRaw dbmapping.Playe
|
||||
}
|
||||
|
||||
if strings.HasPrefix(currentString, "🐱Покемемы: ") {
|
||||
pkmnumRx := regexp.MustCompile("\\d+")
|
||||
pkmnumRx := regexp.MustCompile(`(\d+)(\d|K|M|)`)
|
||||
pkNumArray := pkmnumRx.FindAllString(currentString, -1)
|
||||
if len(pkNumArray) < 2 {
|
||||
if len(pkNumArray) < 3 {
|
||||
log.Println("Pokememes count broken")
|
||||
return "fail"
|
||||
}
|
||||
pokememesCount, _ := strconv.Atoi(pkNumArray[0])
|
||||
pokememesWealth = pkNumArray[2]
|
||||
pokememesWealthInt = p.getPoints(pokememesWealth)
|
||||
if pokememesCount > 0 {
|
||||
for pi := 0; pi < pokememesCount; pi++ {
|
||||
pokememeString := string(profileRunesArray[i+1+pi])
|
||||
@ -192,6 +189,8 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, playerRaw dbmapping.Playe
|
||||
log.Println(crystallsInt)
|
||||
log.Printf("Weapon: " + weapon)
|
||||
if len(pokememes) > 0 {
|
||||
log.Printf("Hand cost: " + pokememesWealth)
|
||||
log.Println(pokememesWealthInt)
|
||||
for meme, attack := range pokememes {
|
||||
log.Printf(meme + ": " + attack)
|
||||
}
|
||||
@ -242,6 +241,7 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, playerRaw dbmapping.Playe
|
||||
profileRaw.LevelID = levelInt
|
||||
profileRaw.Pokeballs = pokeballsInt
|
||||
profileRaw.Wealth = wealthInt
|
||||
profileRaw.PokememesWealth = pokememesWealthInt
|
||||
profileRaw.Exp = expInt
|
||||
profileRaw.EggExp = eggexpInt
|
||||
profileRaw.Power = powerInt
|
||||
@ -249,7 +249,7 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, playerRaw dbmapping.Playe
|
||||
profileRaw.Crystalls = crystallsInt
|
||||
profileRaw.CreatedAt = time.Now().UTC()
|
||||
|
||||
_, err3 := c.Db.NamedExec("INSERT INTO `profiles` VALUES(NULL, :player_id, :nickname, :telegram_nickname, :level_id, :pokeballs, :wealth, :exp, :egg_exp, :power, :weapon_id, :crystalls, :created_at)", &profileRaw)
|
||||
_, err3 := c.Db.NamedExec("INSERT INTO `profiles` VALUES(NULL, :player_id, :nickname, :telegram_nickname, :level_id, :pokeballs, :wealth, :pokememes_wealth, :exp, :egg_exp, :power, :weapon_id, :crystalls, :created_at)", &profileRaw)
|
||||
if err3 != nil {
|
||||
log.Println(err3)
|
||||
return "fail"
|
||||
@ -275,6 +275,18 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, playerRaw dbmapping.Playe
|
||||
rarity = "rare"
|
||||
meme = strings.Replace(meme, "🔸", "", 1)
|
||||
}
|
||||
if strings.HasPrefix(meme, "🔶") {
|
||||
rarity = "super rare"
|
||||
meme = strings.Replace(meme, "🔶", "", 1)
|
||||
}
|
||||
if strings.HasPrefix(meme, "🔹") {
|
||||
rarity = "liber"
|
||||
meme = strings.Replace(meme, "🔹", "", 1)
|
||||
}
|
||||
if strings.HasPrefix(meme, "🔷") {
|
||||
rarity = "super liber"
|
||||
meme = strings.Replace(meme, "🔷", "", 1)
|
||||
}
|
||||
p.fillProfilePokememe(profileRaw.ID, meme, attack, rarity)
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
func (t *Talkers) pokememesListing(update tgbotapi.Update, page int, pokememesArray []dbmapping.PokememeFull) {
|
||||
message := "*Известные боту покемемы*\n"
|
||||
message += "Список отсортирован по грейду и алфавиту.\n"
|
||||
message += "Покедекс: " + strconv.Itoa(len(pokememesArray)) + " / 206\n"
|
||||
message += "Покедекс: " + strconv.Itoa(len(pokememesArray)) + " / 219\n"
|
||||
message += "Отображаем покемемов с " + strconv.Itoa(((page-1)*50)+1) + " по " + strconv.Itoa(page*50) + "\n"
|
||||
if len(pokememesArray) > page*50 {
|
||||
message += "Переход на следующую страницу: /pokedeks" + strconv.Itoa(page+1)
|
||||
|
@ -52,12 +52,8 @@ func (t *Talkers) ProfileMessage(update tgbotapi.Update, playerRaw dbmapping.Pla
|
||||
for i := range profilePokememes {
|
||||
for j := range pokememes {
|
||||
if profilePokememes[i].PokememeID == pokememes[j].ID {
|
||||
singleAttack := float64(pokememes[j].Attack)
|
||||
singleAttack = singleAttack * float64(profilePokememes[i].PokememeLevel)
|
||||
if profilePokememes[i].PokememeRarity == "rare" {
|
||||
singleAttack = singleAttack * 1.15
|
||||
}
|
||||
attackPokememes += int(singleAttack)
|
||||
singleAttack := profilePokememes[i].PokememeAttack
|
||||
attackPokememes += singleAttack
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -81,18 +77,13 @@ func (t *Talkers) ProfileMessage(update tgbotapi.Update, playerRaw dbmapping.Pla
|
||||
for i := range profilePokememes {
|
||||
for j := range pokememes {
|
||||
if profilePokememes[i].PokememeID == pokememes[j].ID {
|
||||
singleAttack := float64(pokememes[j].Attack)
|
||||
singleAttack = singleAttack * float64(profilePokememes[i].PokememeLevel)
|
||||
if profilePokememes[i].PokememeRarity == "rare" {
|
||||
singleAttack = singleAttack * 1.15
|
||||
}
|
||||
|
||||
message += "\n" + strconv.Itoa(pokememes[j].Grade)
|
||||
message += "⃣ " + pokememes[j].Name
|
||||
message += " +" + c.Parsers.ReturnPoints(int(singleAttack)) + "⚔"
|
||||
message += " +" + c.Parsers.ReturnPoints(profilePokememes[i].PokememeAttack) + "⚔"
|
||||
}
|
||||
}
|
||||
}
|
||||
message += "\nСтоимость покемемов на руках: " + c.Parsers.ReturnPoints(profileRaw.PokememesWealth) + "$"
|
||||
message += "\n\n💳" + strconv.Itoa(playerRaw.TelegramID)
|
||||
message += "\n⏰Последнее обновление профиля: " + profileRaw.CreatedAt.Format("02.01.2006 15:04:05")
|
||||
message += "\n\nНе забывай обновляться, это важно для получения актуальной информации.\n\n"
|
||||
|
Reference in New Issue
Block a user