예제 #1
0
파일: sign.go 프로젝트: zhjh1209/a_game
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
}
예제 #2
0
파일: mail.go 프로젝트: zhjh1209/a_game
func (this *Connect) MailRewardRequest() error {

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

	mail := models.NewMailModel(this.Role.Uid).Mail(int(request.GetMailId()))
	if mail == nil {
		return this.Send(lineNum(), fmt.Errorf("没有这条邮件"))
	}

	models.DeleteMail(mail.Id)

	var rewardPoto protodata.RewardData

	if mail.ActionValue > 0 {
		if err := this.Role.SetActionValue(this.Role.ActionValue() + mail.ActionValue); err != nil {
			return this.Send(lineNum(), err)
		}
		rewardPoto.Stamina = proto.Int32(int32(mail.ActionValue))
	} else {
		if mail.Coin > 0 {
			this.Role.AddCoin(mail.Coin, models.FINANCE_MAIL_GET, fmt.Sprintf("mailId : %d", mail.Id))
			rewardPoto.RewardCoin = proto.Int32(int32(mail.Coin))
		}
		rewardPoto.RewardCoin = proto.Int32(int32(mail.Coin))
		if mail.Diamond > 0 {
			this.Role.AddDiamond(mail.Diamond, models.FINANCE_MAIL_GET, fmt.Sprintf("mailId : %d", mail.Id))
			rewardPoto.RewardDiamond = proto.Int32(int32(mail.Diamond))
		}
	}

	response := &protodata.MailRewardResponse{
		Role:   roleProto(this.Role),
		Reward: &rewardPoto}
	return this.Send(StatusOK, response)
}