コード例 #1
0
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)
	}
}
コード例 #2
0
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))
	}
}