【猫草大作战】-领奖逻辑优化
This commit is contained in:
parent
7dcd683997
commit
822ae4c6ef
@ -78,19 +78,22 @@ func GetTemplateId(Id int) int {
|
|||||||
return gamedata.GetIntValue(data, "Template")
|
return gamedata.GetIntValue(data, "Template")
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetProgressReward(Id int, Progress int) []*item.Item {
|
func GetProgressReward(Id int, Rewards []int, Progress int) ([]*item.Item, []int) {
|
||||||
TemplateId := GetTemplateId(Id)
|
TemplateId := GetTemplateId(Id)
|
||||||
data, err := gamedata.GetDataByIntKey(CATNIP_GAME_CFG_NAME, Id)
|
data, err := gamedata.GetDataByIntKey(CATNIP_GAME_CFG_NAME, Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
Items := []*item.Item{}
|
||||||
for _, v := range data {
|
Ids := []int{}
|
||||||
if gamedata.GetIntValue(v, "Need") == Progress && gamedata.GetIntValue(v, "Template") == TemplateId {
|
for k, v := range data {
|
||||||
return gamedata.GetItemList(v, "Items")
|
Id := GoUtil.Int(k)
|
||||||
|
if !GoUtil.InArray(Id, Rewards) && gamedata.GetIntValue(v, "Need") < Progress && gamedata.GetIntValue(v, "Template") == TemplateId {
|
||||||
|
Items = append(Items, gamedata.GetItemList(v, "Items")...)
|
||||||
|
Ids = append(Ids, GoUtil.Int(k))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return Items, Ids
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetItemCost(Id, Mul int) []*item.Item {
|
func GetItemCost(Id, Mul int) []*item.Item {
|
||||||
|
|||||||
@ -5551,7 +5551,7 @@ func ReqCatnipReward(player *Player, buf []byte) error {
|
|||||||
})
|
})
|
||||||
return fmt.Errorf("activity not active")
|
return fmt.Errorf("activity not active")
|
||||||
}
|
}
|
||||||
Items, GameInfo, err := CatnipMod.Reward(int(req.Id), int(req.Progress))
|
Items, GameInfo, err := CatnipMod.Reward(int(req.Id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
player.SendErrClienRes(&msg.ResCatnipReward{
|
player.SendErrClienRes(&msg.ResCatnipReward{
|
||||||
Code: msg.RES_CODE_FAIL,
|
Code: msg.RES_CODE_FAIL,
|
||||||
|
|||||||
@ -179,21 +179,15 @@ func (c *CatnipMod) Play(Id int) (int, int, int, []*item.Item, []*item.Item, int
|
|||||||
return Id, Growth, GameInfo.Partner, Items, ItemCost, FriendItems, nil
|
return Id, Growth, GameInfo.Partner, Items, ItemCost, FriendItems, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CatnipMod) Reward(Id, Progress int) ([]*item.Item, *CatnipGame, error) {
|
func (c *CatnipMod) Reward(Id int) ([]*item.Item, *CatnipGame, error) {
|
||||||
GameInfo, ok := c.Game[Id]
|
GameInfo, ok := c.Game[Id]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, nil, fmt.Errorf("game with Progress %d does not exist", Id)
|
return nil, nil, fmt.Errorf("game with Progress %d does not exist", Id)
|
||||||
}
|
}
|
||||||
if GameInfo.Progress < Progress {
|
Items, Ids := catnipCfg.GetProgressReward(c.Id, GameInfo.Reward, GameInfo.Progress)
|
||||||
return nil, nil, fmt.Errorf("game with ID %d has not reached the required progress %d", Id, Progress)
|
GameInfo.Reward = append(GameInfo.Reward, Ids...)
|
||||||
}
|
|
||||||
if GoUtil.InArray(Progress, GameInfo.Reward) {
|
|
||||||
return nil, nil, fmt.Errorf("reward for progress %d has already been claimed in game ID %d", Progress, Id)
|
|
||||||
}
|
|
||||||
GameInfo.Reward = append(GameInfo.Reward, Progress)
|
|
||||||
Items := catnipCfg.GetProgressReward(c.Id, Progress)
|
|
||||||
if Items == nil {
|
if Items == nil {
|
||||||
return nil, nil, fmt.Errorf("no reward found for progress %d in game ID %d", Progress, Id)
|
return nil, nil, fmt.Errorf("no reward found for progress %d in game ID %d", GameInfo.Progress, Id)
|
||||||
}
|
}
|
||||||
return Items, GameInfo, nil
|
return Items, GameInfo, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26732,8 +26732,7 @@ func (x *ResCatnipPlay) GetId() int32 {
|
|||||||
// 领取阶段奖励
|
// 领取阶段奖励
|
||||||
type ReqCatnipReward struct {
|
type ReqCatnipReward struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
Id int32 `protobuf:"varint,1,opt,name=Id,proto3" json:"Id,omitempty"` // 猫草id
|
Id int32 `protobuf:"varint,1,opt,name=Id,proto3" json:"Id,omitempty"` // 猫草id
|
||||||
Progress int32 `protobuf:"varint,2,opt,name=Progress,proto3" json:"Progress,omitempty"` // 进度
|
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
@ -26775,13 +26774,6 @@ func (x *ReqCatnipReward) GetId() int32 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ReqCatnipReward) GetProgress() int32 {
|
|
||||||
if x != nil {
|
|
||||||
return x.Progress
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
type ResCatnipReward struct {
|
type ResCatnipReward struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
Code RES_CODE `protobuf:"varint,1,opt,name=Code,proto3,enum=tutorial.RES_CODE" json:"Code,omitempty"`
|
Code RES_CODE `protobuf:"varint,1,opt,name=Code,proto3,enum=tutorial.RES_CODE" json:"Code,omitempty"`
|
||||||
@ -29440,10 +29432,9 @@ const file_proto_Gameapi_proto_rawDesc = "" +
|
|||||||
"\rResCatnipPlay\x12&\n" +
|
"\rResCatnipPlay\x12&\n" +
|
||||||
"\x04Code\x18\x01 \x01(\x0e2\x12.tutorial.RES_CODER\x04Code\x12\x10\n" +
|
"\x04Code\x18\x01 \x01(\x0e2\x12.tutorial.RES_CODER\x04Code\x12\x10\n" +
|
||||||
"\x03Msg\x18\x02 \x01(\tR\x03Msg\x12\x0e\n" +
|
"\x03Msg\x18\x02 \x01(\tR\x03Msg\x12\x0e\n" +
|
||||||
"\x02Id\x18\x03 \x01(\x05R\x02Id\"=\n" +
|
"\x02Id\x18\x03 \x01(\x05R\x02Id\"!\n" +
|
||||||
"\x0fReqCatnipReward\x12\x0e\n" +
|
"\x0fReqCatnipReward\x12\x0e\n" +
|
||||||
"\x02Id\x18\x01 \x01(\x05R\x02Id\x12\x1a\n" +
|
"\x02Id\x18\x01 \x01(\x05R\x02Id\"K\n" +
|
||||||
"\bProgress\x18\x02 \x01(\x05R\bProgress\"K\n" +
|
|
||||||
"\x0fResCatnipReward\x12&\n" +
|
"\x0fResCatnipReward\x12&\n" +
|
||||||
"\x04Code\x18\x01 \x01(\x0e2\x12.tutorial.RES_CODER\x04Code\x12\x10\n" +
|
"\x04Code\x18\x01 \x01(\x0e2\x12.tutorial.RES_CODER\x04Code\x12\x10\n" +
|
||||||
"\x03Msg\x18\x02 \x01(\tR\x03Msg\"\x16\n" +
|
"\x03Msg\x18\x02 \x01(\tR\x03Msg\"\x16\n" +
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user