예제 #1
0
func BaseItem(baseId int, Lua *lua.Lua) *Base_Item {

	var sign bool
	if Lua == nil {
		sign = true
		Lua, _ = lua.NewLua("conf/item.lua")
		defer Lua.Close()
	}

	Lua.L.DoString(fmt.Sprintf("name, desc, value, group, probability = item(%d)", baseId))
	name, desc, value, group, probability := Lua.GetString("name"), Lua.GetString("desc"), Lua.GetInt("value"), Lua.GetInt("group"), Lua.GetInt("probability")
	if name == "" {
		return nil
	}

	var coinList []int
	if sign {
		maxLevel := Lua.GetInt("max_level")

		for i := 0; i <= maxLevel; i++ {
			Lua.L.DoString(fmt.Sprintf("c = levelUpCoin(%d)", i))
			coinList = append(coinList, Lua.GetInt("c"))
		}
	}

	return &Base_Item{
		BaseId:      baseId,
		Name:        name,
		Desc:        desc,
		Value:       value,
		Group:       group,
		Probability: probability,
		LevelUpCoin: coinList}
}
예제 #2
0
func BaseGeneral(baseId int, Lua *lua.Lua) *Base_General {

	var sign bool
	if Lua == nil {
		sign = true
		Lua, _ = lua.NewLua("conf/general.lua")
		defer Lua.Close()
	}

	Lua.L.DoString(fmt.Sprintf("Name,Type,Atk,Def,Hp,Speed,Dex,Range,AtkRange,AtkGroup,DefGroup,HpGroup,SpeedGroup,DexGroup,RangeGroup,BuyDiamond,Desc,SkillAtk = baseGeneral(%d)", baseId))

	name := Lua.GetString("Name")
	if name == "" {
		return nil
	}

	result := &Base_General{
		BaseId:     baseId,
		Name:       name,
		Type:       Lua.GetInt("Type"),
		Atk:        Lua.GetInt("Atk"),
		Def:        Lua.GetInt("Def"),
		Hp:         Lua.GetInt("Hp"),
		Speed:      Lua.GetInt("Speed"),
		Dex:        Lua.GetInt("Dex"),
		Range:      Lua.GetInt("Range"),
		AtkRange:   Lua.GetInt("AtkRange"),
		AtkGroup:   Lua.GetInt("AtkGroup"),
		DefGroup:   Lua.GetInt("DefGroup"),
		HpGroup:    Lua.GetInt("HpGroup"),
		SpeedGroup: Lua.GetInt("SpeedGroup"),
		DexGroup:   Lua.GetInt("DexGroup"),
		RangeGroup: Lua.GetInt("RangeGroup"),
		BuyDiamond: Lua.GetInt("BuyDiamond"),
		Desc:       Lua.GetString("Desc"),
		SkillAtk:   Lua.GetInt("SkillAtk")}

	if sign {
		levelUpCoin := Lua.GetString("level_up_coin")
		for _, coin := range strings.Split(levelUpCoin, ",") {
			result.LevelUpCoin = append(result.LevelUpCoin, Atoi(coin))
		}
	}

	return result
}