func InitCreatureMgr() { tc, _ := db.Main.InitTable(Creature{}) tblCreature = db.NewTableCached(tc, &db.CacheParams{2048, time.Minute * 30}) tblPlayer.AddChildTable(tblCreature, "CreatureIds", &db.CacheParams{1024, time.Minute * 30}) ts, _ := db.Main.InitTable(CreatureSlot{}) tblSlots = db.NewTableCached(ts, nil) tblSlotsIdx = tblCreature.AddChildTable(tblSlots, "Slots", &db.CacheParams{1024, time.Minute * 30}) ttCreature := techTree.Get("Creature") levelCount, _ := ttCreature.Get("LevelCount").Int() if levelCount < 1 { log.Println("Error LevelCount must be > 0") return } levelXP := ttCreature.Get("LevelXP").String() hpMax := ttCreature.Get("HPMax").String() hpRegen := ttCreature.Get("HPRegen").String() damage := ttCreature.Get("Damage").String() expLX, err := expression.CreateExpressionFunc(levelXP) if err != nil { log.Println("LevelXP", err) return } expHM, err := expression.CreateExpressionFunc(hpMax) if err != nil { log.Println("HPMax", err) return } expHR, err := expression.CreateExpressionFunc(hpRegen) if err != nil { log.Println("HPRegen", err) return } expDmg, err := expression.CreateExpressionFunc(damage) if err != nil { log.Println("Damage", err) return } crLevels = make([]CreatureLevel, levelCount) for i := 0; i < levelCount; i++ { lvl := float64(i + 1) crLevels[i].XP = int64(expLX(float64(i))) crLevels[i].HPMax = int64(expHM(lvl)) crLevels[i].HPRegen = int64(expHR(lvl)) crLevels[i].Damage = int64(expDmg(lvl)) } }
func InitPlayerMgr() { InitConfigDB() qtPlayers = geom.NewQuadTree(-180, 180, -90, 90) lcPlayers = cache.NewLRUCache(&cache.LRUOptions{Capacity: 0, MaxAge: time.Minute * 5, NoAgeCheck: true}) go PlayersPosHandleRem() tp, _ := db.Main.InitTable(Player{}) tblPlayer = db.NewTableCached(tp, &db.CacheParams{1024, time.Minute * 30}) //tblInvItem, _ = db.Main.InitTable(InvItem{}) var err error techTree, err = util.LoadConfigFile("techtree.cfg") if err != nil { log.Println("Error: Invalid Config File:", err) return } InitResourceMgr() InitCreatureMgr() InitPOIs() InitFights() err = db.Main.ApplyRebuilds() if err != nil { panic(err) } }
func InitResourceMgr() { tr, _ := db.Main.InitTable(Resource{}) tblResource = db.NewTableCached(tr, nil) tblResourceIdx = tblPlayer.AddChildTable(tblResource, "Resources", &db.CacheParams{1024, time.Minute * 30}) ttRsc := techTree.Get("Resource") RscLvlCount, _ = ttRsc.Get("LevelCount").Int() ExchangeCircle, _ = ttRsc.Get("ExchangeCircle").Int() exchangeUp := ttRsc.Get("ExchangeUp").String() var err error ExprExchangeUp, err = expression.CreateExpressionFunc(exchangeUp) if err != nil { log.Println("ExchangeUp", err) return } exchangeDn := ttRsc.Get("ExchangeDn").String() ExprExchangeDn, err = expression.CreateExpressionFunc(exchangeDn) if err != nil { log.Println("ExchangeDn", err) return } ttRscInfo, _ := techTree.Get("Resources").Array() RSC = make([]RscInfo, len(ttRscInfo)) for i, rsc := range ttRscInfo { rscInfo := rsc.(map[string]interface{}) RSC[i].Name = rscInfo["Name"].(string) } }
func InitPOIs() { mt, _ := db.Main.InitTable(MapTile{}) tblMapTile = db.NewTableCached(mt, &db.CacheParams{1024, time.Minute * 30}) pt, _ := db.Main.InitTable(POI{}) tblPOI = db.NewTableCached(pt, &db.CacheParams{}) tblMapTile.AddChildTable(tblPOI, "Pois", &db.CacheParams{1024, time.Minute * 30}) poi_max_respawn = 0 poi_infoName = make(map[string]*POI_Info) poi_infoType = make(map[string]*POI_Info) poi_infos = make([]*POI_Info, 1) pois, _ := techTree.Get("POIs").Map() for key, value := range pois { poi := value.(map[string]interface{}) poiInfo := &POI_Info{} poiInfo.Types = strings.Split(poi["Types"].(string), ",") poiInfo.Name = key poiInfo.Resource = poi["Resource"].(string) poiInfo.Level = int(poi["Level"].(float64)) poiInfo.Respawn = int(poi["Respawn"].(float64)) if poiInfo.Respawn > poi_max_respawn { poi_max_respawn = poiInfo.Respawn } poi_infos = append(poi_infos, poiInfo) for _, typ := range poiInfo.Types { poi_infoType[typ] = poiInfo } poi_infoName[poiInfo.Name] = poiInfo //log.Println(poiInfo) } poi_infos[0] = &POI_Info{} //dummy/none poiFarmCache = cache.NewLRUCache(&cache.LRUOptions{MaxAge: time.Minute * time.Duration(poi_max_respawn), NoMoveGet: true}) MapTileScanner() ttpoi := techTree.Get("POI") POIScanVer, _ = ttpoi.Get("ScanVer").Int64() FarmItemsMin, _ = ttpoi.Get("FarmItemsMin").Int() FarmItemsMax, _ = ttpoi.Get("FarmItemsMax").Int() FarmLevelMax, _ = ttpoi.Get("FarmLevelMax").Int() }
func InitConfigDB() { ct, _ := db.Main.InitTableName(ConfigEntry{}, "config") tblConfigDB = db.NewTableCached(ct, &db.CacheParams{1024, time.Minute * 30}) }