package guild

import (
	"fmt"
	"server/GoUtil"
	guildCfg "server/conf/guild"
	"server/game/mod/item"
	"server/msg"
)

type Guild struct {
	Guild  int
	Reward map[int]int
}

func (g *Guild) InitData() {
	g.Reward = make(map[int]int)
	if g.Reward == nil {
		g.Reward = make(map[int]int)
	}
}

func (g *Guild) GetReward(Id int) ([]*item.Item, error) {
	Items, Num := guildCfg.GetGuildReward(Id)
	n, ok := g.Reward[Id]
	if !ok {
		n = 0
	}
	if n >= Num {
		return nil, fmt.Errorf("Guild GetReward Id:%v has been received", Id)
	}
	g.Reward[Id]++
	return Items, nil
}

func (g *Guild) BackData() *msg.ResGuildInfo {
	return &msg.ResGuildInfo{
		Reward: GoUtil.MapIntToInt32(g.Reward),
	}
}
