mirror of
https://github.com/Walter-Sparrow/lunar-tear.git
synced 2026-07-02 05:43:41 +03:00
Add admin API for content reload
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
"log"
|
||||
|
||||
pb "lunar-tear/server/gen/proto"
|
||||
"lunar-tear/server/internal/masterdata"
|
||||
"lunar-tear/server/internal/runtime"
|
||||
"lunar-tear/server/internal/store"
|
||||
)
|
||||
|
||||
@@ -14,23 +14,25 @@ type ConsumableItemServiceServer struct {
|
||||
pb.UnimplementedConsumableItemServiceServer
|
||||
users store.UserRepository
|
||||
sessions store.SessionRepository
|
||||
catalog *masterdata.ConsumableItemCatalog
|
||||
config *masterdata.GameConfig
|
||||
holder *runtime.Holder
|
||||
}
|
||||
|
||||
func NewConsumableItemServiceServer(users store.UserRepository, sessions store.SessionRepository, catalog *masterdata.ConsumableItemCatalog, config *masterdata.GameConfig) *ConsumableItemServiceServer {
|
||||
return &ConsumableItemServiceServer{users: users, sessions: sessions, catalog: catalog, config: config}
|
||||
func NewConsumableItemServiceServer(users store.UserRepository, sessions store.SessionRepository, holder *runtime.Holder) *ConsumableItemServiceServer {
|
||||
return &ConsumableItemServiceServer{users: users, sessions: sessions, holder: holder}
|
||||
}
|
||||
|
||||
func (s *ConsumableItemServiceServer) Sell(ctx context.Context, req *pb.ConsumableItemSellRequest) (*pb.ConsumableItemSellResponse, error) {
|
||||
log.Printf("[ConsumableItemService] Sell: %d item(s)", len(req.ConsumableItemPossession))
|
||||
|
||||
cat := s.holder.Get()
|
||||
catalog := cat.ConsumableItem
|
||||
config := cat.GameConfig
|
||||
userId := CurrentUserId(ctx, s.users, s.sessions)
|
||||
|
||||
_, err := s.users.UpdateUser(userId, func(user *store.UserState) {
|
||||
totalGold := int32(0)
|
||||
for _, item := range req.ConsumableItemPossession {
|
||||
row, ok := s.catalog.All[item.ConsumableItemId]
|
||||
row, ok := catalog.All[item.ConsumableItemId]
|
||||
if !ok {
|
||||
log.Printf("[ConsumableItemService] Sell: unknown consumableItemId=%d, skipping", item.ConsumableItemId)
|
||||
continue
|
||||
@@ -53,7 +55,7 @@ func (s *ConsumableItemServiceServer) Sell(ctx context.Context, req *pb.Consumab
|
||||
}
|
||||
|
||||
if totalGold > 0 {
|
||||
user.ConsumableItems[s.config.ConsumableItemIdForGold] += totalGold
|
||||
user.ConsumableItems[config.ConsumableItemIdForGold] += totalGold
|
||||
log.Printf("[ConsumableItemService] Sell: total gold +%d", totalGold)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user