Archived
1
This repository has been archived on 2022-11-04. You can view files and clone it, but cannot push or open issues or pull requests.
i2_bot/lib/datacache/weapons.go
Vladimir Hodakov c9855116da Move rarely changed data to datamappings, fix profile updating
As result of profile format change, introduced in game update yesterday we need to change profile regexp.

As result of some refactoring, rarely changed data removed from database and added to sources of bot.
2018-03-31 08:34:27 +04:00

63 lines
2.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// i2_bot Instinct PokememBro Bot
// Copyright (c) 2018 Vladimir "fat0troll" Hodakov
package datacache
import (
"errors"
"source.wtfteam.pro/i2_bot/i2_bot/lib/datamapping"
"strconv"
"strings"
)
func (dc *DataCache) initWeapons() {
c.Log.Info("Initializing Weapons storage...")
dc.weapons = make(map[int]*datamapping.Weapon)
}
func (dc *DataCache) loadWeapons() {
c.Log.Info("Load current Weapons data to DataCache...")
weapons := dc.getWeapons()
for i := range weapons {
dc.weapons[weapons[i].ID] = &weapons[i]
}
c.Log.Info("Loaded weapon types in DataCache: " + strconv.Itoa(len(dc.weapons)))
}
func (dc *DataCache) getWeapons() []datamapping.Weapon {
weapons := []datamapping.Weapon{}
weapons = append(weapons, datamapping.Weapon{1, "Бита", 2, 5})
weapons = append(weapons, datamapping.Weapon{2, "Стальная бита", 10, 40})
weapons = append(weapons, datamapping.Weapon{3, "Чугунная бита", 200, 500})
weapons = append(weapons, datamapping.Weapon{4, "Титановая бита", 2000, 10000})
weapons = append(weapons, datamapping.Weapon{5, "Алмазная бита", 10000, 100000})
weapons = append(weapons, datamapping.Weapon{6, "Криптонитовая бита", 100000, 500000})
weapons = append(weapons, datamapping.Weapon{5, "Буханка из пятёры", 1000000, 5000000})
return weapons
}
// External functions
// GetWeaponTypeByID returns weapon type from datacache by given ID
func (dc *DataCache) GetWeaponTypeByID(weaponID int) (*datamapping.Weapon, error) {
if dc.weapons[weaponID] != nil {
c.Log.Debug("DataCache: found weapon type with ID = " + strconv.Itoa(weaponID))
return dc.weapons[weaponID], nil
}
return nil, errors.New("There is no weapon type with ID = " + strconv.Itoa(weaponID))
}
// GetWeaponTypeByName returns weapon type from datacache by weapon name
func (dc *DataCache) GetWeaponTypeByName(name string) (*datamapping.Weapon, error) {
for i := range dc.weapons {
if strings.HasPrefix(dc.weapons[i].Name, name) {
return dc.weapons[i], nil
}
}
return nil, errors.New("There is no weapon type with name = " + name)
}