xy 2 өдөр өмнө
parent
commit
04943d7060

+ 29 - 4
bin/client_msg/common.proto

@@ -89,6 +89,7 @@ message ColorData {
   string m_head = 7;
   int32 rank_num = 8;
   int32 m_coin = 9;
+  int32 m_reward_coin = 10;
 }
 
 message MoveStepData {
@@ -210,10 +211,7 @@ message ResMatchLudo {
   MsgError err_msg = 2;
   RoomInfo room = 3;
 }
-//被踢登陆
-message BeKickLogin {
-  MsgError err_msg = 1;
-}
+
 //error
 message MsgError {
   int32 error_code = 1;
@@ -221,6 +219,10 @@ message MsgError {
 }
 
 
+// 更新用户信息
+message UpdateUserInfo {
+  UserInfo info = 1;
+}
 message ResHeartBeat {
   string msg = 1;
 }
@@ -228,3 +230,26 @@ message ResHeartBeat {
 message ReqHeartBeat {
   string msg = 1;
 }
+
+message ShopItem{
+  string name = 1;
+  string id = 2;
+  int32 price = 3;
+}
+
+//被踢登陆
+message BeKickLogin {
+  MsgError err_msg = 1;
+}
+
+// 请求商城
+message ReqShop {
+  int32 shopType = 1;
+}
+
+// 响应商城
+message ResShop {
+  bool success = 1;
+  MsgError err_msg = 2;
+  repeated ShopItem list = 3;
+}

BIN
src/.DS_Store


+ 7 - 0
src/server/game/ludo/battle.go

@@ -6,6 +6,7 @@ import (
 	"server/game"
 	"server/msg"
 	"server/tools"
+	"server/user"
 	"time"
 )
 
@@ -118,6 +119,12 @@ func (room_info *RoomInfoWrapper) notify_settlement() {
 	if len(message.FinishColors) == 0 {
 		message.FinishColors = room_info.getNotKickColors()
 	}
+	matchConfig := gameRule.getMatchByLevle(room_info.RoomLevel)
+	for _, v := range message.FinishColors {
+		user_id := v.MId
+		v.MRewardCoin = matchConfig.rewardNum
+		user.AddUserCoin(v.MRewardCoin, user_id)
+	}
 	room_info.notify_to_all_player(message)
 }
 

+ 49 - 6
src/server/game/ludo/ludo.go

@@ -11,12 +11,19 @@ import (
 	"github.com/name5566/leaf/log"
 )
 
+type MatchModeItem struct {
+	enterNum  int32
+	rewardNum int32
+	level     int32
+}
+
 // GameRule 定义游戏规则
 type GameRule struct {
-	MAX_STEP     int32
-	OPT_TIME     int32
-	WU_DI_ROAD   []string
-	AN_QUAN_ROAD []string
+	MAX_STEP      int32
+	OPT_TIME      int32
+	WU_DI_ROAD    []string
+	AN_QUAN_ROAD  []string
+	PVP_MODE_LIST []*MatchModeItem
 }
 
 type Config struct {
@@ -28,8 +35,9 @@ type Config struct {
 var (
 	gameConfig *Config
 	gameRule   = GameRule{
-		OPT_TIME: 10,
-		MAX_STEP: 57,
+		PVP_MODE_LIST: makeMatchConfig(),
+		OPT_TIME:      10,
+		MAX_STEP:      57,
 		WU_DI_ROAD: []string{
 			"p_2", "p_15", "p_28", "p_41", "p_23", "p_10", "p_36", "p_49",
 			"red_1", "red_2", "red_3", "red_4", "red_5", "red_des",
@@ -83,6 +91,41 @@ var (
 	}
 )
 
+func (gameRule *GameRule) getMatchByLevle(level int32) *MatchModeItem {
+	for i := 0; i < len(gameRule.PVP_MODE_LIST); i++ {
+		item := gameRule.PVP_MODE_LIST[i]
+		if item.level == level {
+			return item
+		}
+	}
+	return nil
+}
+
+func makeMatchConfig() []*MatchModeItem {
+	list := make([]*MatchModeItem, 0)
+	list = append(list, &MatchModeItem{
+		enterNum:  500,
+		rewardNum: 950,
+		level:     1,
+	})
+	list = append(list, &MatchModeItem{
+		enterNum:  1000,
+		rewardNum: 1900,
+		level:     2,
+	})
+	list = append(list, &MatchModeItem{
+		enterNum:  1500,
+		rewardNum: 2850,
+		level:     3,
+	})
+	list = append(list, &MatchModeItem{
+		enterNum:  2000,
+		rewardNum: 3800,
+		level:     4,
+	})
+	return list
+}
+
 func InitGame() {
 	gameConfig = &Config{
 		RoomMap:    make(map[int32]*msg.RoomInfo),

+ 10 - 1
src/server/game/ludo/match.go

@@ -3,6 +3,7 @@ package ludo
 import (
 	"fmt"
 	"server/msg"
+	"server/user"
 
 	"github.com/name5566/leaf/gate"
 	"github.com/name5566/leaf/log"
@@ -15,7 +16,15 @@ func RecvMatchLudo(args []interface{}) {
 	ud := a.UserData()
 	user_id := ud.(*msg.UserInfo).UserId
 	log.Error("user_id:=%s , start match!", user_id)
-	go matchRoom(m, user_id, a)
+	//判断玩家是否有足够金币
+	coin := ud.(*msg.UserInfo).MCoin
+	matchConfig := gameRule.getMatchByLevle(m.RoomLevel)
+	if coin >= matchConfig.enterNum {
+		user.DecreaseUserCoin(matchConfig.enterNum, user_id)
+		go matchRoom(m, user_id, a)
+	} else {
+		sendMatchErrorMsg(a, 101, "Not enough gold coins")
+	}
 }
 
 //根据玩家要匹配的对局,给玩家寻找和的房间

+ 296 - 56
src/server/msg/common.pb.go

@@ -676,6 +676,7 @@ type ColorData struct {
 	MHead         string                 `protobuf:"bytes,7,opt,name=m_head,json=mHead,proto3" json:"m_head,omitempty"`
 	RankNum       int32                  `protobuf:"varint,8,opt,name=rank_num,json=rankNum,proto3" json:"rank_num,omitempty"`
 	MCoin         int32                  `protobuf:"varint,9,opt,name=m_coin,json=mCoin,proto3" json:"m_coin,omitempty"`
+	MRewardCoin   int32                  `protobuf:"varint,10,opt,name=m_reward_coin,json=mRewardCoin,proto3" json:"m_reward_coin,omitempty"`
 	unknownFields protoimpl.UnknownFields
 	sizeCache     protoimpl.SizeCache
 }
@@ -773,6 +774,13 @@ func (x *ColorData) GetMCoin() int32 {
 	return 0
 }
 
+func (x *ColorData) GetMRewardCoin() int32 {
+	if x != nil {
+		return x.MRewardCoin
+	}
+	return 0
+}
+
 type MoveStepData struct {
 	state         protoimpl.MessageState `protogen:"open.v1"`
 	MId           string                 `protobuf:"bytes,1,opt,name=m_id,json=mId,proto3" json:"m_id,omitempty"`
@@ -1875,28 +1883,29 @@ func (x *ResMatchLudo) GetRoom() *RoomInfo {
 	return nil
 }
 
-// 被踢登陆
-type BeKickLogin struct {
+// error
+type MsgError struct {
 	state         protoimpl.MessageState `protogen:"open.v1"`
-	ErrMsg        *MsgError              `protobuf:"bytes,1,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"`
+	ErrorCode     int32                  `protobuf:"varint,1,opt,name=error_code,json=errorCode,proto3" json:"error_code,omitempty"`
+	ErrorMsg      string                 `protobuf:"bytes,2,opt,name=error_msg,json=errorMsg,proto3" json:"error_msg,omitempty"`
 	unknownFields protoimpl.UnknownFields
 	sizeCache     protoimpl.SizeCache
 }
 
-func (x *BeKickLogin) Reset() {
-	*x = BeKickLogin{}
+func (x *MsgError) Reset() {
+	*x = MsgError{}
 	mi := &file_common_proto_msgTypes[23]
 	ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 	ms.StoreMessageInfo(mi)
 }
 
-func (x *BeKickLogin) String() string {
+func (x *MsgError) String() string {
 	return protoimpl.X.MessageStringOf(x)
 }
 
-func (*BeKickLogin) ProtoMessage() {}
+func (*MsgError) ProtoMessage() {}
 
-func (x *BeKickLogin) ProtoReflect() protoreflect.Message {
+func (x *MsgError) ProtoReflect() protoreflect.Message {
 	mi := &file_common_proto_msgTypes[23]
 	if x != nil {
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@@ -1908,41 +1917,47 @@ func (x *BeKickLogin) ProtoReflect() protoreflect.Message {
 	return mi.MessageOf(x)
 }
 
-// Deprecated: Use BeKickLogin.ProtoReflect.Descriptor instead.
-func (*BeKickLogin) Descriptor() ([]byte, []int) {
+// Deprecated: Use MsgError.ProtoReflect.Descriptor instead.
+func (*MsgError) Descriptor() ([]byte, []int) {
 	return file_common_proto_rawDescGZIP(), []int{23}
 }
 
-func (x *BeKickLogin) GetErrMsg() *MsgError {
+func (x *MsgError) GetErrorCode() int32 {
 	if x != nil {
-		return x.ErrMsg
+		return x.ErrorCode
 	}
-	return nil
+	return 0
 }
 
-// error
-type MsgError struct {
+func (x *MsgError) GetErrorMsg() string {
+	if x != nil {
+		return x.ErrorMsg
+	}
+	return ""
+}
+
+// 更新用户信息
+type UpdateUserInfo struct {
 	state         protoimpl.MessageState `protogen:"open.v1"`
-	ErrorCode     int32                  `protobuf:"varint,1,opt,name=error_code,json=errorCode,proto3" json:"error_code,omitempty"`
-	ErrorMsg      string                 `protobuf:"bytes,2,opt,name=error_msg,json=errorMsg,proto3" json:"error_msg,omitempty"`
+	Info          *UserInfo              `protobuf:"bytes,1,opt,name=info,proto3" json:"info,omitempty"`
 	unknownFields protoimpl.UnknownFields
 	sizeCache     protoimpl.SizeCache
 }
 
-func (x *MsgError) Reset() {
-	*x = MsgError{}
+func (x *UpdateUserInfo) Reset() {
+	*x = UpdateUserInfo{}
 	mi := &file_common_proto_msgTypes[24]
 	ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 	ms.StoreMessageInfo(mi)
 }
 
-func (x *MsgError) String() string {
+func (x *UpdateUserInfo) String() string {
 	return protoimpl.X.MessageStringOf(x)
 }
 
-func (*MsgError) ProtoMessage() {}
+func (*UpdateUserInfo) ProtoMessage() {}
 
-func (x *MsgError) ProtoReflect() protoreflect.Message {
+func (x *UpdateUserInfo) ProtoReflect() protoreflect.Message {
 	mi := &file_common_proto_msgTypes[24]
 	if x != nil {
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@@ -1954,23 +1969,16 @@ func (x *MsgError) ProtoReflect() protoreflect.Message {
 	return mi.MessageOf(x)
 }
 
-// Deprecated: Use MsgError.ProtoReflect.Descriptor instead.
-func (*MsgError) Descriptor() ([]byte, []int) {
+// Deprecated: Use UpdateUserInfo.ProtoReflect.Descriptor instead.
+func (*UpdateUserInfo) Descriptor() ([]byte, []int) {
 	return file_common_proto_rawDescGZIP(), []int{24}
 }
 
-func (x *MsgError) GetErrorCode() int32 {
-	if x != nil {
-		return x.ErrorCode
-	}
-	return 0
-}
-
-func (x *MsgError) GetErrorMsg() string {
+func (x *UpdateUserInfo) GetInfo() *UserInfo {
 	if x != nil {
-		return x.ErrorMsg
+		return x.Info
 	}
-	return ""
+	return nil
 }
 
 type ResHeartBeat struct {
@@ -2061,6 +2069,217 @@ func (x *ReqHeartBeat) GetMsg() string {
 	return ""
 }
 
+type ShopItem struct {
+	state         protoimpl.MessageState `protogen:"open.v1"`
+	Name          string                 `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
+	Id            string                 `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"`
+	Price         int32                  `protobuf:"varint,3,opt,name=price,proto3" json:"price,omitempty"`
+	unknownFields protoimpl.UnknownFields
+	sizeCache     protoimpl.SizeCache
+}
+
+func (x *ShopItem) Reset() {
+	*x = ShopItem{}
+	mi := &file_common_proto_msgTypes[27]
+	ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+	ms.StoreMessageInfo(mi)
+}
+
+func (x *ShopItem) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*ShopItem) ProtoMessage() {}
+
+func (x *ShopItem) ProtoReflect() protoreflect.Message {
+	mi := &file_common_proto_msgTypes[27]
+	if x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use ShopItem.ProtoReflect.Descriptor instead.
+func (*ShopItem) Descriptor() ([]byte, []int) {
+	return file_common_proto_rawDescGZIP(), []int{27}
+}
+
+func (x *ShopItem) GetName() string {
+	if x != nil {
+		return x.Name
+	}
+	return ""
+}
+
+func (x *ShopItem) GetId() string {
+	if x != nil {
+		return x.Id
+	}
+	return ""
+}
+
+func (x *ShopItem) GetPrice() int32 {
+	if x != nil {
+		return x.Price
+	}
+	return 0
+}
+
+// 被踢登陆
+type BeKickLogin struct {
+	state         protoimpl.MessageState `protogen:"open.v1"`
+	ErrMsg        *MsgError              `protobuf:"bytes,1,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"`
+	unknownFields protoimpl.UnknownFields
+	sizeCache     protoimpl.SizeCache
+}
+
+func (x *BeKickLogin) Reset() {
+	*x = BeKickLogin{}
+	mi := &file_common_proto_msgTypes[28]
+	ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+	ms.StoreMessageInfo(mi)
+}
+
+func (x *BeKickLogin) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*BeKickLogin) ProtoMessage() {}
+
+func (x *BeKickLogin) ProtoReflect() protoreflect.Message {
+	mi := &file_common_proto_msgTypes[28]
+	if x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use BeKickLogin.ProtoReflect.Descriptor instead.
+func (*BeKickLogin) Descriptor() ([]byte, []int) {
+	return file_common_proto_rawDescGZIP(), []int{28}
+}
+
+func (x *BeKickLogin) GetErrMsg() *MsgError {
+	if x != nil {
+		return x.ErrMsg
+	}
+	return nil
+}
+
+// 请求商城
+type ReqShop struct {
+	state         protoimpl.MessageState `protogen:"open.v1"`
+	ShopType      int32                  `protobuf:"varint,1,opt,name=shopType,proto3" json:"shopType,omitempty"`
+	unknownFields protoimpl.UnknownFields
+	sizeCache     protoimpl.SizeCache
+}
+
+func (x *ReqShop) Reset() {
+	*x = ReqShop{}
+	mi := &file_common_proto_msgTypes[29]
+	ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+	ms.StoreMessageInfo(mi)
+}
+
+func (x *ReqShop) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*ReqShop) ProtoMessage() {}
+
+func (x *ReqShop) ProtoReflect() protoreflect.Message {
+	mi := &file_common_proto_msgTypes[29]
+	if x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use ReqShop.ProtoReflect.Descriptor instead.
+func (*ReqShop) Descriptor() ([]byte, []int) {
+	return file_common_proto_rawDescGZIP(), []int{29}
+}
+
+func (x *ReqShop) GetShopType() int32 {
+	if x != nil {
+		return x.ShopType
+	}
+	return 0
+}
+
+// 响应商城
+type ResShop struct {
+	state         protoimpl.MessageState `protogen:"open.v1"`
+	Success       bool                   `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"`
+	ErrMsg        *MsgError              `protobuf:"bytes,2,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"`
+	List          []*ShopItem            `protobuf:"bytes,3,rep,name=list,proto3" json:"list,omitempty"`
+	unknownFields protoimpl.UnknownFields
+	sizeCache     protoimpl.SizeCache
+}
+
+func (x *ResShop) Reset() {
+	*x = ResShop{}
+	mi := &file_common_proto_msgTypes[30]
+	ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+	ms.StoreMessageInfo(mi)
+}
+
+func (x *ResShop) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*ResShop) ProtoMessage() {}
+
+func (x *ResShop) ProtoReflect() protoreflect.Message {
+	mi := &file_common_proto_msgTypes[30]
+	if x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use ResShop.ProtoReflect.Descriptor instead.
+func (*ResShop) Descriptor() ([]byte, []int) {
+	return file_common_proto_rawDescGZIP(), []int{30}
+}
+
+func (x *ResShop) GetSuccess() bool {
+	if x != nil {
+		return x.Success
+	}
+	return false
+}
+
+func (x *ResShop) GetErrMsg() *MsgError {
+	if x != nil {
+		return x.ErrMsg
+	}
+	return nil
+}
+
+func (x *ResShop) GetList() []*ShopItem {
+	if x != nil {
+		return x.List
+	}
+	return nil
+}
+
 var File_common_proto protoreflect.FileDescriptor
 
 const file_common_proto_rawDesc = "" +
@@ -2099,7 +2318,7 @@ const file_common_proto_rawDesc = "" +
 	"\n" +
 	"m_cur_road\x18\x04 \x01(\x0e2\t.roadTypeR\bmCurRoad\x12\x12\n" +
 	"\x04step\x18\x05 \x01(\x05R\x04step\x12\x19\n" +
-	"\bold_setp\x18\x06 \x01(\x05R\aoldSetp\"\xfa\x01\n" +
+	"\bold_setp\x18\x06 \x01(\x05R\aoldSetp\"\x9e\x02\n" +
 	"\tColorData\x12\x11\n" +
 	"\x04m_id\x18\x01 \x01(\tR\x03mId\x12\"\n" +
 	"\am_color\x18\x02 \x01(\x0e2\t.roleTypeR\x06mColor\x12\x17\n" +
@@ -2110,7 +2329,9 @@ const file_common_proto_rawDesc = "" +
 	"\x06m_name\x18\x06 \x01(\tR\x05mName\x12\x15\n" +
 	"\x06m_head\x18\a \x01(\tR\x05mHead\x12\x19\n" +
 	"\brank_num\x18\b \x01(\x05R\arankNum\x12\x15\n" +
-	"\x06m_coin\x18\t \x01(\x05R\x05mCoin\"P\n" +
+	"\x06m_coin\x18\t \x01(\x05R\x05mCoin\x12\"\n" +
+	"\rm_reward_coin\x18\n" +
+	" \x01(\x05R\vmRewardCoin\"P\n" +
 	"\fMoveStepData\x12\x11\n" +
 	"\x04m_id\x18\x01 \x01(\tR\x03mId\x12\x12\n" +
 	"\x04step\x18\x02 \x01(\x05R\x04step\x12\x19\n" +
@@ -2184,17 +2405,29 @@ const file_common_proto_rawDesc = "" +
 	"\fResMatchLudo\x12\x18\n" +
 	"\asuccess\x18\x01 \x01(\bR\asuccess\x12\"\n" +
 	"\aerr_msg\x18\x02 \x01(\v2\t.MsgErrorR\x06errMsg\x12\x1d\n" +
-	"\x04room\x18\x03 \x01(\v2\t.RoomInfoR\x04room\"1\n" +
-	"\vBeKickLogin\x12\"\n" +
-	"\aerr_msg\x18\x01 \x01(\v2\t.MsgErrorR\x06errMsg\"F\n" +
+	"\x04room\x18\x03 \x01(\v2\t.RoomInfoR\x04room\"F\n" +
 	"\bMsgError\x12\x1d\n" +
 	"\n" +
 	"error_code\x18\x01 \x01(\x05R\terrorCode\x12\x1b\n" +
-	"\terror_msg\x18\x02 \x01(\tR\berrorMsg\" \n" +
+	"\terror_msg\x18\x02 \x01(\tR\berrorMsg\"/\n" +
+	"\x0eUpdateUserInfo\x12\x1d\n" +
+	"\x04info\x18\x01 \x01(\v2\t.UserInfoR\x04info\" \n" +
 	"\fResHeartBeat\x12\x10\n" +
 	"\x03msg\x18\x01 \x01(\tR\x03msg\" \n" +
 	"\fReqHeartBeat\x12\x10\n" +
-	"\x03msg\x18\x01 \x01(\tR\x03msg*K\n" +
+	"\x03msg\x18\x01 \x01(\tR\x03msg\"D\n" +
+	"\bShopItem\x12\x12\n" +
+	"\x04name\x18\x01 \x01(\tR\x04name\x12\x0e\n" +
+	"\x02id\x18\x02 \x01(\tR\x02id\x12\x14\n" +
+	"\x05price\x18\x03 \x01(\x05R\x05price\"1\n" +
+	"\vBeKickLogin\x12\"\n" +
+	"\aerr_msg\x18\x01 \x01(\v2\t.MsgErrorR\x06errMsg\"%\n" +
+	"\aReqShop\x12\x1a\n" +
+	"\bshopType\x18\x01 \x01(\x05R\bshopType\"f\n" +
+	"\aResShop\x12\x18\n" +
+	"\asuccess\x18\x01 \x01(\bR\asuccess\x12\"\n" +
+	"\aerr_msg\x18\x02 \x01(\v2\t.MsgErrorR\x06errMsg\x12\x1d\n" +
+	"\x04list\x18\x03 \x03(\v2\t.ShopItemR\x04list*K\n" +
 	"\broleType\x12\x15\n" +
 	"\x11ROLE_TYPE_UNKNOWN\x10\x00\x12\a\n" +
 	"\x03RED\x10\x01\x12\b\n" +
@@ -2245,7 +2478,7 @@ func file_common_proto_rawDescGZIP() []byte {
 }
 
 var file_common_proto_enumTypes = make([]protoimpl.EnumInfo, 7)
-var file_common_proto_msgTypes = make([]protoimpl.MessageInfo, 27)
+var file_common_proto_msgTypes = make([]protoimpl.MessageInfo, 31)
 var file_common_proto_goTypes = []any{
 	(RoleType)(0),                // 0: roleType
 	(OptType)(0),                 // 1: OptType
@@ -2277,10 +2510,14 @@ var file_common_proto_goTypes = []any{
 	(*LeaveHall)(nil),            // 27: LeaveHall
 	(*MatchLudo)(nil),            // 28: MatchLudo
 	(*ResMatchLudo)(nil),         // 29: ResMatchLudo
-	(*BeKickLogin)(nil),          // 30: BeKickLogin
-	(*MsgError)(nil),             // 31: MsgError
+	(*MsgError)(nil),             // 30: MsgError
+	(*UpdateUserInfo)(nil),       // 31: UpdateUserInfo
 	(*ResHeartBeat)(nil),         // 32: ResHeartBeat
 	(*ReqHeartBeat)(nil),         // 33: ReqHeartBeat
+	(*ShopItem)(nil),             // 34: ShopItem
+	(*BeKickLogin)(nil),          // 35: BeKickLogin
+	(*ReqShop)(nil),              // 36: ReqShop
+	(*ResShop)(nil),              // 37: ResShop
 }
 var file_common_proto_depIdxs = []int32{
 	0,  // 0: round.m_color:type_name -> roleType
@@ -2301,7 +2538,7 @@ var file_common_proto_depIdxs = []int32{
 	0,  // 15: SendColorSz.color:type_name -> roleType
 	0,  // 16: SendRoleMove.color:type_name -> roleType
 	0,  // 17: NotifyPlayerSzNumber.color:type_name -> roleType
-	31, // 18: NotifyPlayerSzNumber.err_msg:type_name -> MsgError
+	30, // 18: NotifyPlayerSzNumber.err_msg:type_name -> MsgError
 	0,  // 19: NotifyPlayerMove.color:type_name -> roleType
 	11, // 20: NotifyPlayerMove.step:type_name -> MoveStepData
 	9,  // 21: NotifyPlayerMove.kick:type_name -> RoleData
@@ -2316,20 +2553,23 @@ var file_common_proto_depIdxs = []int32{
 	10, // 30: NotifySettlement.finish_colors:type_name -> ColorData
 	8,  // 31: NotifyUpdateRoomInfo.room_info:type_name -> RoomInfo
 	20, // 32: ResLogin.userInfo:type_name -> UserInfo
-	31, // 33: ResLogin.err_msg:type_name -> MsgError
-	31, // 34: ResRegister.err_msg:type_name -> MsgError
-	31, // 35: ResEnterHall.err_msg:type_name -> MsgError
+	30, // 33: ResLogin.err_msg:type_name -> MsgError
+	30, // 34: ResRegister.err_msg:type_name -> MsgError
+	30, // 35: ResEnterHall.err_msg:type_name -> MsgError
 	8,  // 36: ResEnterHall.reconnect_room_info:type_name -> RoomInfo
 	2,  // 37: MatchLudo.select_room_type:type_name -> roomType
 	0,  // 38: MatchLudo.select_color:type_name -> roleType
-	31, // 39: ResMatchLudo.err_msg:type_name -> MsgError
+	30, // 39: ResMatchLudo.err_msg:type_name -> MsgError
 	8,  // 40: ResMatchLudo.room:type_name -> RoomInfo
-	31, // 41: BeKickLogin.err_msg:type_name -> MsgError
-	42, // [42:42] is the sub-list for method output_type
-	42, // [42:42] is the sub-list for method input_type
-	42, // [42:42] is the sub-list for extension type_name
-	42, // [42:42] is the sub-list for extension extendee
-	0,  // [0:42] is the sub-list for field type_name
+	20, // 41: UpdateUserInfo.info:type_name -> UserInfo
+	30, // 42: BeKickLogin.err_msg:type_name -> MsgError
+	30, // 43: ResShop.err_msg:type_name -> MsgError
+	34, // 44: ResShop.list:type_name -> ShopItem
+	45, // [45:45] is the sub-list for method output_type
+	45, // [45:45] is the sub-list for method input_type
+	45, // [45:45] is the sub-list for extension type_name
+	45, // [45:45] is the sub-list for extension extendee
+	0,  // [0:45] is the sub-list for field type_name
 }
 
 func init() { file_common_proto_init() }
@@ -2343,7 +2583,7 @@ func file_common_proto_init() {
 			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
 			RawDescriptor: unsafe.Slice(unsafe.StringData(file_common_proto_rawDesc), len(file_common_proto_rawDesc)),
 			NumEnums:      7,
-			NumMessages:   27,
+			NumMessages:   31,
 			NumExtensions: 0,
 			NumServices:   0,
 		},

+ 1 - 0
src/server/msg/msg.go

@@ -41,6 +41,7 @@ func init() {
 	Processor.Register(&ResMatchLudo{})
 	Processor.Register(&NotifyUpdateRoomInfo{})
 	Processor.Register(&BeKickLogin{})
+	Processor.Register(&UpdateUserInfo{})
 	Processor.Range(func(id uint16, t reflect.Type) {
 		log.Debug("消息ID: %d, 消息类型: %s\n", id, t.Elem().Name())
 		msgList = append(msgList, MsgInfo{

+ 15 - 8
src/server/user/user.go

@@ -3,6 +3,7 @@ package user
 import (
 	mongodbmgr "server/db/mongodb"
 	redismgr "server/db/redis"
+	agentmanager "server/game/agentManager"
 	"server/msg"
 
 	"github.com/name5566/leaf/log"
@@ -55,27 +56,33 @@ func GetUserInfoById(userId string) *msg.UserInfo {
 	return userData
 }
 
-// 减少用户积分
-func DecreaseUserPoint(decrementAmount int32, userId string) {
+// 减少用户金币
+func DecreaseUserCoin(coin int32, userId string) {
 	userData := GetUserInfoById(userId)
 	// 获取存储在 agent 中的 UserData
 	// 减少用户积分
-	// userData.Points -= decrementAmount
+	userData.MCoin -= coin
 	SetUserInfo(userData)
 	// 打印更新日志
-	log.Debug("User %s's points decreased by %d. New balance: %d", userId, decrementAmount, userData)
+	log.Debug("User %s's coin decreased by %d. New balance: %d", userId, coin, userData)
 }
 func SetUserInfo(userData *msg.UserInfo) {
 	redismgr.SaveUserInfoToRedis(userData)
+	user_agent := agentmanager.GetAgentByUserID(userData.UserId)
+	if user_agent != nil {
+		user_agent.WriteMsg(&msg.UpdateUserInfo{
+			Info: userData,
+		})
+	}
 }
 
-// 更新用户积分
-func AddUserPoint(betAmount int32, userId string) {
+// 添加用户金币
+func AddUserCoin(coin int32, userId string) {
 	// 查找用户数据
 	userData := GetUserInfoById(userId)
 
-	// 更新用户的积分
-	// userData.Points += betAmount
+	// 更新用户的金币
+	userData.MCoin += coin
 	SetUserInfo(userData)
 	// 打印更新日志
 	log.Debug("User %s's points updated: %d", userId, userData)

+ 39 - 0
src/server/webserver/login.go

@@ -0,0 +1,39 @@
+package main
+
+import (
+	"net/http"
+	redismgr "server/db/redis"
+	"server/msg"
+	"server/user"
+
+	"github.com/gin-gonic/gin"
+)
+
+func ReqLogin(c *gin.Context) {
+	req := c.MustGet("protobuf_data").(*msg.ReqLogin)
+	UserId, err := redismgr.GetUserIDFromRedisByAP(req.Account, req.Password)
+	if err != nil {
+
+		c.ProtoBuf(http.StatusOK, &msg.ResLogin{
+			NikeName: "",
+			UserId:   "",
+			ErrMsg: &msg.MsgError{
+				ErrorCode: 101,
+				ErrorMsg:  "Password or Account is error!",
+			},
+		})
+		return
+	}
+	// 获取用户信息 ,如果新用户则创建一个
+	userData := user.GetUserInfoById(UserId)
+	c.ProtoBuf(http.StatusOK, &msg.ResLogin{
+		UserInfo: &msg.UserInfo{
+			UserId: userData.UserId,
+			MHead:  userData.MHead,
+			MCoin:  userData.MCoin,
+			Name:   userData.Name,
+			RoomId: userData.RoomId,
+		},
+		ErrMsg: nil,
+	})
+}

+ 1 - 74
src/server/webserver/main.go

@@ -2,14 +2,11 @@ package main
 
 import (
 	"net/http"
-	redismgr "server/db/redis"
 	"server/msg"
-	"server/user"
 
 	"github.com/gin-contrib/cors"
 	"github.com/gin-gonic/gin"
 	"github.com/gin-gonic/gin/binding"
-	"github.com/name5566/leaf/log"
 	"google.golang.org/protobuf/proto"
 )
 
@@ -72,76 +69,6 @@ func main() {
 
 	r.POST("/ReqLogin", ParseProtoBuf(&msg.ReqLogin{}), ReqLogin)
 	r.POST("/ReqRegister", ParseProtoBuf(&msg.ReqRegister{}), ReqRegister)
+	r.POST("/ReqShop", ParseProtoBuf(&msg.ReqShop{}), ReqShop)
 	r.Run(":8080") // 默认监听 :8080
 }
-
-func ReqRegister(c *gin.Context) {
-	req := c.MustGet("protobuf_data").(*msg.ReqRegister)
-
-	log.Debug(req.Account, req.Password)
-
-	userId, _ := redismgr.GetUserIDFromRedisByAP(req.Account, req.Password)
-
-	if userId != "" {
-		c.ProtoBuf(http.StatusOK, &msg.ResRegister{
-			Success: false,
-			ErrMsg: &msg.MsgError{
-				ErrorCode: 101,
-				ErrorMsg:  " Account is exist!",
-			},
-		})
-		return
-	}
-
-	userId, Success := redismgr.SetUserIDFromRedisByAP(req.Account, req.Password)
-	if !Success {
-		c.ProtoBuf(http.StatusOK, &msg.ResRegister{
-			Success: false,
-			ErrMsg: &msg.MsgError{
-				ErrorCode: 102,
-				ErrorMsg:  "server registerHandler error",
-			},
-		})
-		return
-	}
-
-	redismgr.SaveUserInfoToRedis(&msg.UserInfo{
-		UserId: userId,
-		MCoin:  0,
-		MHead:  req.MHead,
-		Name:   req.NikeName,
-	})
-	c.ProtoBuf(http.StatusOK, &msg.ResRegister{
-		Success: true,
-		ErrMsg:  nil,
-	})
-}
-
-func ReqLogin(c *gin.Context) {
-	req := c.MustGet("protobuf_data").(*msg.ReqLogin)
-	UserId, err := redismgr.GetUserIDFromRedisByAP(req.Account, req.Password)
-	if err != nil {
-
-		c.ProtoBuf(http.StatusOK, &msg.ResLogin{
-			NikeName: "",
-			UserId:   "",
-			ErrMsg: &msg.MsgError{
-				ErrorCode: 101,
-				ErrorMsg:  "Password or Account is error!",
-			},
-		})
-		return
-	}
-	// 获取用户信息 ,如果新用户则创建一个
-	userData := user.GetUserInfoById(UserId)
-	c.ProtoBuf(http.StatusOK, &msg.ResLogin{
-		UserInfo: &msg.UserInfo{
-			UserId: userData.UserId,
-			MHead:  userData.MHead,
-			MCoin:  userData.MCoin,
-			Name:   userData.Name,
-			RoomId: userData.RoomId,
-		},
-		ErrMsg: nil,
-	})
-}

+ 52 - 0
src/server/webserver/register.go

@@ -0,0 +1,52 @@
+package main
+
+import (
+	"net/http"
+	redismgr "server/db/redis"
+	"server/msg"
+
+	"github.com/gin-gonic/gin"
+	"github.com/name5566/leaf/log"
+)
+
+func ReqRegister(c *gin.Context) {
+	req := c.MustGet("protobuf_data").(*msg.ReqRegister)
+
+	log.Debug(req.Account, req.Password)
+
+	userId, _ := redismgr.GetUserIDFromRedisByAP(req.Account, req.Password)
+
+	if userId != "" {
+		c.ProtoBuf(http.StatusOK, &msg.ResRegister{
+			Success: false,
+			ErrMsg: &msg.MsgError{
+				ErrorCode: 101,
+				ErrorMsg:  " Account is exist!",
+			},
+		})
+		return
+	}
+
+	userId, Success := redismgr.SetUserIDFromRedisByAP(req.Account, req.Password)
+	if !Success {
+		c.ProtoBuf(http.StatusOK, &msg.ResRegister{
+			Success: false,
+			ErrMsg: &msg.MsgError{
+				ErrorCode: 102,
+				ErrorMsg:  "server registerHandler error",
+			},
+		})
+		return
+	}
+
+	redismgr.SaveUserInfoToRedis(&msg.UserInfo{
+		UserId: userId,
+		MCoin:  0,
+		MHead:  req.MHead,
+		Name:   req.NikeName,
+	})
+	c.ProtoBuf(http.StatusOK, &msg.ResRegister{
+		Success: true,
+		ErrMsg:  nil,
+	})
+}

+ 35 - 0
src/server/webserver/shop.go

@@ -0,0 +1,35 @@
+package main
+
+import (
+	"fmt"
+	"net/http"
+	"server/msg"
+
+	"github.com/gin-gonic/gin"
+)
+
+var list []*msg.ShopItem = make([]*msg.ShopItem, 0)
+
+func MakeShop() []*msg.ShopItem {
+	if len(list) == 10 {
+		return list
+	}
+	for i := range 10 {
+		list = append(list, &msg.ShopItem{
+			Id:    fmt.Sprint("%d", i+1),
+			Name:  fmt.Sprint("Item:%d", i+1),
+			Price: int32(i * 100),
+		})
+	}
+	return list
+}
+
+func ReqShop(c *gin.Context) {
+	req := c.MustGet("protobuf_data").(*msg.ReqShop)
+	if req.ShopType == 1 {
+		c.ProtoBuf(http.StatusOK, &msg.ResShop{
+			Success: true,
+			List:    MakeShop(),
+		})
+	}
+}