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} }
func signProto(day int) []*protodata.RewardData { var result []*protodata.RewardData Lua, _ := lua.NewLua("conf/sign_reward.lua") begin := day/7 - 1 if begin < 0 { begin = 0 } begin = begin*7 + 1 for i := begin; i <= begin+7; i++ { //Lua.L.GetGlobal("signReward") Lua.L.DoString(fmt.Sprintf("coin, diamond, action, generalId = signReward(%d)", i)) coin := Lua.GetInt("coin") diamond := Lua.GetInt("diamond") action := Lua.GetInt("action") generalId := Lua.GetInt("generalId") temp := new(protodata.RewardData) temp.RewardCoin = proto.Int32(int32(coin)) temp.RewardDiamond = proto.Int32(int32(diamond)) temp.Stamina = proto.Int32(int32(action)) if generalId > 0 { config := models.BaseGeneral(generalId, nil) temp.General = generalProto(new(models.GeneralData), config) } result = append(result, temp) } Lua.Close() return result }
func ConfigItemList() []*ConfigItem { var result []*ConfigItem Lua, _ := lua.NewLua("conf/item.lua") var coinList []int //升级需要的金币 levelUpCoin := Lua.GetString("level_up_coin") for _, val := range strings.Split(levelUpCoin, ",") { coinList = append(coinList, Atoi(val)) } var i int for { i++ itemStr := Lua.GetString(fmt.Sprintf("item_%d", i)) if itemStr == "" { break } array := strings.Split(itemStr, "\\,") result = append(result, &ConfigItem{ ConfigId: Atoi(array[0]), Name: array[1], Desc: array[2], Value: Atoi(array[3]), Group: Atoi(array[4]), Probability: Atoi(array[5]), LevelUpCoin: coinList}) } Lua.Close() return result }
func BaseItemList() []*Base_Item { var result []*Base_Item Lua, _ := lua.NewLua("conf/item.lua") //Lua.L.GetGlobal("item") //Lua.L.GetGlobal("levelUpCoin") maxLevel := Lua.GetInt("max_level") var coinList []int for i := 0; i <= maxLevel; i++ { Lua.L.DoString(fmt.Sprintf("c = levelUpCoin(%d)", i)) coinList = append(coinList, Lua.GetInt("c")) } indexStr := Lua.GetString("index") indexArr := strings.Split(indexStr, ",") for _, index := range indexArr { baseId := Atoi(index) item := BaseItem(baseId, Lua) item.LevelUpCoin = coinList result = append(result, item) } Lua.Close() return result }
func ConfigCoinDiamondList() []*ConfigCoinDiamond { var result []*ConfigCoinDiamond Lua, _ := lua.NewLua("conf/coin_diamond.lua") var i int for { i++ itemStr := Lua.GetString(fmt.Sprintf("coin_diamond_%d", i)) if itemStr == "" { break } array := strings.Split(itemStr, "\\,") result = append(result, &ConfigCoinDiamond{ Index: i, Name: array[0], Coin: Atoi(array[1]), Diamond: Atoi(array[2]), Desc: array[3]}) } Lua.Close() return result }
func ConfigDuplicateList() []*ConfigDuplicate { var result []*ConfigDuplicate Lua, _ := lua.NewLua("conf/duplicate.lua") var i int for { i++ duplicateStr := Lua.GetString(fmt.Sprintf("duplicate_%d", i)) if duplicateStr == "" { break } array := strings.Split(duplicateStr, "\\,") result = append(result, &ConfigDuplicate{ ConfigId: i, Chapter: Atoi(array[0]), Section: Atoi(array[1]), ChapterName: array[2], SectionName: array[3], Value: array[4], GenId: Atoi(array[5])}) } Lua.Close() return result }
func ConfigGeneralMap() map[int]*ConfigGeneral { result := make(map[int]*ConfigGeneral) Lua, _ := lua.NewLua("conf/general.lua") var coinList []int //升级需要的金币 levelUpCoin := Lua.GetString("level_up_coin") for _, val := range strings.Split(levelUpCoin, ",") { coinList = append(coinList, Atoi(val)) } var i int for { i++ itemStr := Lua.GetString(fmt.Sprintf("general_%d", i)) if itemStr == "" { break } array := strings.Split(itemStr, "\\,") result[Atoi(array[0])] = genByStr(array) result[Atoi(array[0])].LevelUpCoin = coinList } Lua.Close() return result }
// 充值商店 func ConfigPayCenterList() []*Config_Pay_Center { var result []*Config_Pay_Center Lua, _ := lua.NewLua("conf/pay_center.lua") var i int for { i++ itemStr := Lua.GetString(fmt.Sprintf("pay_center_%d", i)) if itemStr == "" { break } array := strings.Split(itemStr, "\\,") result = append(result, &Config_Pay_Center{ Id: i, Name: array[0], Money: Atoi(array[1]), Diamond: Atoi(array[2]), Desc: array[3]}) } Lua.Close() return result }
func tempItemDiamond() [4]int { Lua, _ := lua.NewLua("conf/item.lua") Lua.L.GetGlobal("tempItemDiamond") Lua.L.DoString("d1,d2,d3,d4 = tempItemDiamond()") d1, d2, d3, d4 := Lua.GetInt("d1"), Lua.GetInt("d2"), Lua.GetInt("d3"), Lua.GetInt("d4") Lua.Close() return [4]int{d1, d2, d3, d4} }
func buyActionDiamond(n int) int { Lua, _ := lua.NewLua("conf/role.lua") Lua.L.GetGlobal("buyActionDiamond") Lua.L.DoString(fmt.Sprintf("diamond = buyActionDiamond(%d)", n)) diamond := Lua.GetInt("diamond") Lua.Close() return diamond }
func init() { go func() { Lua, _ := lua.NewLua("conf/app.lua") port := Lua.GetInt("httpPort") Lua.Close() http.HandleFunc("/confirm", httpConfirm) http.ListenAndServe(fmt.Sprintf(":%d", port), nil) }() }
func signReward(times int) (coin, diamond, action, generalId int) { Lua, _ := lua.NewLua("conf/sign_reward.lua") Lua.L.GetGlobal("signReward") Lua.L.DoString(fmt.Sprintf("coin, diamond, action, generalId = signReward(%d)", times)) coin = Lua.GetInt("coin") diamond = Lua.GetInt("diamond") action = Lua.GetInt("action") generalId = Lua.GetInt("generalId") Lua.Close() return }
func init() { setting, err := lua.NewLua("conf/app.lua") if err != nil { panic(err) } DB = Open(setting.GetString("dsn")) setting.Close() }
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 }
func (this *Connect) MailList() error { var result []*protodata.MailData for _, mail := range models.NewMailModel(this.Role.Uid).List() { result = append(result, mailProto(mail)) } Lua, _ := lua.NewLua("conf/notice.lua") content := Lua.GetString("content") datetime := Lua.GetString("datetime") Lua.Close() return this.Send(StatusOK, &protodata.MailResponse{ Mails: result, Cnnouncement: proto.String(content), Time: proto.String(datetime)}) }
func UnLimitDuplicate() *ConfigDuplicate { Lua, _ := lua.NewLua("conf/duplicate.lua") duplicateStr := Lua.GetString("duplicate_0") if duplicateStr == "" { return nil } array := strings.Split(duplicateStr, "\\,") result := &ConfigDuplicate{ ConfigId: 0, Chapter: Atoi(array[0]), Section: Atoi(array[1]), ChapterName: array[2], SectionName: array[3], Value: array[4], GenId: Atoi(array[5])} Lua.Close() return result }
func (this *Connect) SetRoleName() error { request := &protodata.SetUpNameRequest{} if err := Unmarshal(this.Request.GetSerializedString(), request); err != nil { return this.Send(lineNum(), err) } name := request.GetName() L, _ := lua.NewLua("conf/random_name.lua") sensitiveWord := L.GetString("sensitive_word") L.Close() wordArray := strings.Split(sensitiveWord, ",") // 过滤敏感字 for _, word := range wordArray { name = strings.Replace(name, word, "", len(name)) } if name == "" { return this.Send(lineNum(), fmt.Errorf("名字不能为空")) } rune := []rune(name) if len(rune) > 7 { rune = rune[:7] name = string(rune) } // 判断是否存在此用户名 if n, _ := models.Role.NumberByRoleName(name); n > 0 { return this.Send(lineNum(), fmt.Errorf("这个名字已被使用")) } if err := this.Role.SetName(name); err != nil { return this.Send(lineNum(), err) } return this.Send(StatusOK, &protodata.SetUpNameResponse{Role: roleProto(this.Role)}) }
func otherLogin(platId int, otherId, session, sign, otherData string) (string, bool) { if platId == 0 { return otherId, true } Lua, err := lua.NewLua(fmt.Sprintf("lua/plat_%d.lua", platId)) if err != nil { log.Error("LUA ERROR : login.go line - 60") return "0", false } Lua.L.GetGlobal("isLogin") Lua.L.DoString(fmt.Sprintf("uid, isLogin = isLogin('%s', '%s', '%s', '%s')", otherId, session, sign, otherData)) uid := Lua.GetString("uid") isLogin := Lua.GetBool("isLogin") Lua.Close() return uid, isLogin }
func SSDB() *Client { i++ if ssdb[maxClient-1] == nil { L, err := lua.NewLua("conf/app.lua") if err != nil { panic(err) } host := L.GetString("ssdbhost") port := L.GetInt("ssdbport") L.Close() for i := 0; i < maxClient; i++ { if ssdb[i], err = Connect(host, port); err != nil { panic(err) } } } return ssdb[i%maxClient] }
func BaseGeneralMap() map[int]*Base_General { result := make(map[int]*Base_General) Lua, _ := lua.NewLua("conf/general.lua") var coinList []int //升级需要的金币 levelUpCoin := Lua.GetString("level_up_coin") for _, val := range strings.Split(levelUpCoin, ",") { coinList = append(coinList, Atoi(val)) } indexStr := Lua.GetString("index") indexArr := strings.Split(indexStr, ",") for _, index := range indexArr { baseId := Atoi(index) result[baseId] = BaseGeneral(baseId, Lua) result[baseId].LevelUpCoin = coinList } Lua.Close() return result }
// 随机生成角色名字 func (this *Connect) RandomName() error { L, err := lua.NewLua("conf/random_name.lua") if err != nil { return this.Send(lineNum(), err) } firstNameStr := L.GetString("first_name") SecondNameStr := L.GetString("second_name") L.Close() firstNameArray := strings.Split(firstNameStr, ",") SecondNameArray := strings.Split(SecondNameStr, ",") firstName := firstNameArray[rand.Intn(len(firstNameArray))] secondName := SecondNameArray[rand.Intn(len(SecondNameArray))] response := &protodata.RandomNameResponse{ Name: proto.String(firstName + secondName), } return this.Send(StatusOK, response) }
func init() { L, err := lua.NewLua("conf/app.lua") if err != nil { panic(err) } levelMap := make(map[string]int) levelMap["Trace"] = logs.LevelTrace levelMap["Debug"] = logs.LevelDebug levelMap["Info"] = logs.LevelInfo levelMap["Warn"] = logs.LevelWarn levelMap["Error"] = logs.LevelError levelMap["Critical"] = logs.LevelCritical debugLevel, _ := levelMap[strings.Title(L.GetString("level"))] L.Close() // init focust core logger = logs.NewLogger(1000) logger.SetLogger("console", "") logger.SetLevel(debugLevel) }
func (this RoleModel) NewRole(uid int64) (*RoleData, error) { Lua, err := lua.NewLua("conf/role.lua") if err != nil { return nil, err } unixTime := time.Now().Unix() RoleData := new(RoleData) RoleData.Uid = uid RoleData.Coin = Lua.GetInt("new_coin") RoleData.Diamond = Lua.GetInt("new_diamond") RoleData.GeneralBaseId = Lua.GetInt("new_leader") RoleData.UnixTime = unixTime Lua.Close() Transaction, err := DB().Begin() if err != nil { return nil, err } defer func() { if err != nil { Transaction.Rollback() RoleData = nil } else { err = Transaction.Commit() } }() if err = Transaction.Insert(RoleData); err != nil { return nil, err } configs := BaseGeneralMap() baseIds := [3]int{105, 117, 123} var generals []interface{} for index := range baseIds { base := configs[baseIds[index]] general := new(GeneralData) general.Uid = uid general.BaseId = base.BaseId general.Name = base.Name general.Level = 0 general.Atk = base.Atk general.Def = base.Def general.Hp = base.Hp general.Speed = base.Speed general.Dex = base.Dex general.Range = base.Range general.UnixTime = unixTime generals = append(generals, general) } if err = Transaction.Insert(generals...); err != nil { return nil, err } return RoleData, err }