Пример #1
0
func (this *Connect) BuyCoinRequest() error {

	request := &protodata.BuyCoinRequest{}
	if err := Unmarshal(this.Request.GetSerializedString(), request); err != nil {
		return this.Send(lineNum(), err)
	}

	index := int(request.GetProductIndex())
	configList := models.ConfigCoinDiamondList()
	needDiamond := configList[index-1].Diamond
	addCoin := configList[index-1].Coin

	if needDiamond > this.Role.Diamond {
		return this.Send(lineNum(), fmt.Errorf("钻石不足"))
	}

	err := this.Role.DiamondIntoCoin(needDiamond, addCoin, fmt.Sprintf("index : %d", index))
	if err != nil {
		return this.Send(lineNum(), err)
	}

	response := &protodata.BuyCoinResponse{
		Role: roleProto(this.Role),
		Coin: proto.Int32(int32(addCoin)),
	}
	return this.Send(StatusOK, response)
}
Пример #2
0
func (this *Connect) UserDataRequest() error {

	var isReceive bool
	if this.Role.SignDate == time.Now().Format("20060102") {
		isReceive = true
	}
	if !isReceive {
		if err := this.Role.Sign(); err != nil {
			return this.Send(lineNum(), err)
		}
	}

	configs := models.BaseGeneralMap()

	//var rewardList []*protodata.RewardData
	//for i := this.Role.SignNum; i < this.Role.SignNum+7; i++ {

	//	c, d, s, g := signReward(i)

	//	temp := new(protodata.RewardData)
	//	temp.RewardCoin = proto.Int32(int32(c))
	//	temp.RewardDiamond = proto.Int32(int32(d))
	//	temp.Stamina = proto.Int32(int32(s))
	//	if g > 0 {
	//		temp.General = generalProto(new(models.GeneralData), configs[g])
	//	}

	//	rewardList = append(rewardList, temp)
	//}

	signDay := this.Role.SignNum % 7
	if signDay == 0 {
		signDay = 7
	}

	signProto := &protodata.SignRewardData{
		Reward:    signProto(this.Role.SignNum),
		IsReceive: proto.Bool(isReceive),
		SignDay:   proto.Int32(int32(signDay)),
	}

	var coinProductProtoList []*protodata.CoinProductData
	coinDiamond := models.ConfigCoinDiamondList()
	for _, val := range coinDiamond {
		coinProductProtoList = append(coinProductProtoList, &protodata.CoinProductData{
			ProductIndex: proto.Int32(int32(val.Index)),
			ProductName:  proto.String(val.Name),
			ProductDesc:  proto.String(val.Desc),
			ProductCoin:  proto.Int32(int32(val.Coin)),
			PriceDiamond: proto.Int32(int32(val.Diamond)),
		})
	}

	var productProtoList []*protodata.DiamondProductData
	productList := models.ConfigPayCenterList()
	for _, val := range productList {
		productProtoList = append(productProtoList, &protodata.DiamondProductData{
			ProductIndex:   proto.Int32(int32(val.Id)),
			ProductName:    proto.String(val.Name),
			ProductDesc:    proto.String(val.Desc),
			ProductDiamond: proto.Int32(int32(val.Diamond)),
			Price:          proto.Int32(int32(val.Money)),
		})
	}

	generalList := models.General.List(this.Uid)
	//if len(generalList) == 0 {
	//	Lua, _ := lua.NewLua("conf/general.lua")
	//	s := Lua.GetString("init_generals")
	//	Lua.Close()
	//	array := strings.Split(s, ",")
	//	generalList = append(generalList, models.General.Insert(this.Uid, configs[models.Atoi(array[0])]))
	//	generalList = append(generalList, models.General.Insert(this.Uid, configs[models.Atoi(array[1])]))
	//	generalList = append(generalList, models.General.Insert(this.Uid, configs[models.Atoi(array[2])]))
	//}

	if !isReceive {
		coin, diamond, action, generalId := signReward(this.Role.SignNum)
		if coin > 0 {
			this.Role.AddCoin(coin, models.FINANCE_SIGN_GET, fmt.Sprintf("signDay : %d", signDay))
		} else if diamond > 0 {
			this.Role.AddDiamond(diamond, models.FINANCE_SIGN_GET, fmt.Sprintf("signDay : %d", signDay))
		} else if action > 0 {
			this.Role.SetActionValue(this.Role.ActionValue() + action)
		} else if generalId > 0 {
			var find bool
			for _, val := range generalList {
				if generalId == val.BaseId {
					find = true
					break
				}
			}
			baseGeneral := configs[generalId]
			if find {
				this.Role.AddDiamond(baseGeneral.BuyDiamond, models.FINANCE_SIGN_GET, fmt.Sprintf("signDay : %d", signDay))
			} else {
				newGeneral, err := models.General.Insert(this.Uid, baseGeneral)
				if err != nil {
					return this.Send(lineNum(), err)
				}
				generalList = append(generalList, newGeneral)
			}
		}
	}

	tempItemDiamond := tempItemDiamond()

	return this.Send(StatusOK, &protodata.UserDataResponse{
		Role:             roleProto(this.Role),
		Items:            itemProtoList(models.Item.List(this.Uid)),
		Generals:         generalProtoList(generalList, configs),
		SignReward:       signProto,
		Chapters:         duplicateProtoList(models.NewDuplicateModel(this.Uid).List(), models.ConfigDuplicateList()),
		TempItemDiamonds: []int32{int32(tempItemDiamond[0]), int32(tempItemDiamond[1]), int32(tempItemDiamond[2]), int32(tempItemDiamond[3])},
		CoinProducts:     coinProductProtoList,
		DiamondProducts:  productProtoList,
		LeaderId:         proto.Int32(int32(this.Role.GeneralBaseId)),
		StaminaTimeMax:   proto.Int32(int32(models.Role.ActionWaitTime))})
}