|
|
|
package serviceGame
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"github.com/gogf/gf/v2/encoding/gjson"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
|
|
"github.com/gogf/gf/v2/os/gtime"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
"tyj_admin/api/v1/game"
|
|
|
|
"tyj_admin/config"
|
|
|
|
"tyj_admin/internal/consts"
|
|
|
|
"tyj_admin/internal/serviceGame/internal"
|
|
|
|
"tyj_admin/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
type IGameManage interface {
|
|
|
|
ChangeGm(ctx context.Context, req *game.ChangeGmReq) (res *game.ChangeGmRes, err error)
|
|
|
|
ChangePwd(ctx context.Context, req *game.ResetPwdReq) (res *game.ResetPwdRes, err error)
|
|
|
|
SearchGm(ctx context.Context, req *game.SearchGmReq) (res *game.SearchGmRes, err error)
|
|
|
|
ListGm(ctx context.Context, req *game.ListGmReq) (res *game.ListGmRes, err error)
|
|
|
|
SetGmToClient(ctx context.Context, req *game.SetGmToClientReq) (res *game.SetGmToClientRes, err error)
|
|
|
|
CopyUnit(ctx context.Context, req *game.CopyUnitReq) (res *game.CopyUnitRes, err error)
|
|
|
|
//EditUnit(ctx context.Context, req *game.EditUnitReq) (res *game.EditUnitRes, err error)
|
|
|
|
UpdateUnit(ctx context.Context, req *game.UpdateUnitReq) (res *game.UpdateUnitRes, err error)
|
|
|
|
DelAccount(ctx context.Context, req *game.DelAccountReq) (res *game.DelAccountRes, err error)
|
|
|
|
SearchAccount(ctx context.Context, req *game.SearchAccountReq) (res *game.SearchAccountRes, err error)
|
|
|
|
GetKeepAlive(ctx context.Context, req *game.GetKeepAliveReq) (res *game.GetKeepAliveRes, err error)
|
|
|
|
GetLive(ctx context.Context, req *game.GetLiveReq) (res *game.GetLiveRes, err error)
|
|
|
|
RegisterCount(ctx context.Context, req *game.RegisterCountReq) (res *game.RegisterCountRes, err error)
|
|
|
|
GetShopItemLog(ctx context.Context, req *game.GetShopItemLogReq) (res *game.GetShopItemLogRes, err error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type gameManageImpl struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
var gameManageService = gameManageImpl{}
|
|
|
|
|
|
|
|
func GameManage() IGameManage {
|
|
|
|
return &gameManageService
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ga *gameManageImpl) ChangePwd(ctx context.Context, req *game.ResetPwdReq) (res *game.ResetPwdRes, err error) {
|
|
|
|
//pwd := gmd5.MustEncryptString(req.Pwd + "sdsd")
|
|
|
|
res, err = internal.ChangePwd(ctx, req.Account, req.Pwd, fmt.Sprint(req.ServerId))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ga *gameManageImpl) SearchGm(ctx context.Context, req *game.SearchGmReq) (res *game.SearchGmRes, err error) {
|
|
|
|
res = new(game.SearchGmRes)
|
|
|
|
res.Gm, err = internal.SearchGm(ctx, req)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ga *gameManageImpl) ListGm(ctx context.Context, req *game.ListGmReq) (res *game.ListGmRes, err error) {
|
|
|
|
res = new(game.ListGmRes)
|
|
|
|
res, err = internal.ListGm(ctx, req)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ga *gameManageImpl) SetGmToClient(ctx context.Context, req *game.SetGmToClientReq) (res *game.SetGmToClientRes, err error) {
|
|
|
|
res = new(game.SetGmToClientRes)
|
|
|
|
res, err = internal.SetGmToClient(ctx, req)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ga *gameManageImpl) ChangeGm(ctx context.Context, req *game.ChangeGmReq) (res *game.ChangeGmRes, err error) {
|
|
|
|
res = new(game.ChangeGmRes)
|
|
|
|
res, err = internal.ChangeGm(ctx, req)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ga *gameManageImpl) AddGameUnit(ctx context.Context, req *game.AddGameUnitReq) (res *game.AddGameUnitRes, err error) {
|
|
|
|
uid, err := internal.GetAccountUid(ctx, req.Account, fmt.Sprint(req.ServerId))
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("GetAccount err", err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
fmt.Println("GetRoleDelta", uid)
|
|
|
|
roleDelta, err2 := internal.GetRoleDetail(ctx, uid, fmt.Sprint(req.ServerId))
|
|
|
|
if err2 != nil {
|
|
|
|
fmt.Println("err2: ", err2)
|
|
|
|
return nil, err2
|
|
|
|
}
|
|
|
|
|
|
|
|
t := roleDelta["_t"]
|
|
|
|
c := roleDelta["C"].(primitive.A)
|
|
|
|
log.Println(" rrr >>> ", t)
|
|
|
|
GameUnitComponent := map[string]interface{}{}
|
|
|
|
for _, v := range c {
|
|
|
|
v1 := v.(map[string]interface{})
|
|
|
|
if v1["_t"] == consts.GameUnitComponent {
|
|
|
|
GameUnitComponent = v.(map[string]interface{})
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
children := GameUnitComponent["Children"].(primitive.A)
|
|
|
|
switch fmt.Sprint(req.GameUnitType) {
|
|
|
|
case consts.GameUnitType_Villager:
|
|
|
|
villagerConfig := config.InitialVillagerConfig[req.CfgId]
|
|
|
|
unit := map[string]interface{}{"_id": gtime.TimestampMilli(), "_t": consts.GameUnit, "UnitType": consts.GameUnitType_Villager,
|
|
|
|
"UnitCamp": consts.GameUnitCamp_Friend, "Position": map[string]interface{}{"x": req.X, "y": req.Y}, "C": []interface{}{}}
|
|
|
|
children = append(children, unit)
|
|
|
|
villagers := unit["C"].(primitive.A)
|
|
|
|
villagerRecordComponent := map[string]interface{}{"_id": unit["_id"], "_t": consts.VillagerRecordComponent, "DisplayState": villagerConfig.DisplayState}
|
|
|
|
gameNumericComponent := map[string]interface{}{"_id": unit["_id"], "_t": consts.GameNumericComponent, "NumericDic": []interface{}{}}
|
|
|
|
NumericDic := gameNumericComponent["NumericDic"].(primitive.A)
|
|
|
|
NumericDic = append(NumericDic, []interface{}{consts.NUMERICTYPE_PHYSIQUE, villagerConfig.Physique},
|
|
|
|
[]interface{}{consts.NUMERICTYPE_AGE, villagerConfig.Age}, []interface{}{consts.NUMERICTYPE_AGE, villagerConfig.Age})
|
|
|
|
if villagerConfig.LifeMax > 0 {
|
|
|
|
NumericDic = append(NumericDic, []interface{}{consts.NUMERICTYPE_LIFEMAX, villagerConfig.LifeMax})
|
|
|
|
}
|
|
|
|
gameNumericComponent["NumericDic"] = append(NumericDic, []interface{}{consts.NUMERICTYPE_HP, villagerConfig.StartHp},
|
|
|
|
[]interface{}{consts.NUMERICTYPE_ATKBASE, villagerConfig.StartATK}, []interface{}{consts.NUMERICTYPE_MAXHPBASE, villagerConfig.StartHp},
|
|
|
|
[]interface{}{consts.NUMERICTYPE_DEFBASE, villagerConfig.StartDEF}, []interface{}{consts.NUMERICTYPE_LABORBASE, villagerConfig.Labor},
|
|
|
|
[]interface{}{consts.NUMERICTYPE_WISDOMBASE, villagerConfig.Wisdom}, []interface{}{consts.NUMERICTYPE_MOVESPEEDBASE, villagerConfig.MoveSpeed},
|
|
|
|
[]interface{}{consts.NUMERICTYPE_ATTACKSPEEDBASE, 100}, []interface{}{consts.NUMERICTYPE_LABOREXP, 0},
|
|
|
|
[]interface{}{consts.NUMERICTYPE_LIFEEXP, 0}, []interface{}{consts.NUMERICTYPE_PHYSIQUE, villagerConfig.Physique},
|
|
|
|
[]interface{}{consts.NUMERICTYPE_PHYSIQUEEXP, 0}, []interface{}{consts.NUMERICTYPE_HITRATE, villagerConfig.HitRate},
|
|
|
|
[]interface{}{consts.NUMERICTYPE_HITBASE, villagerConfig.Hit})
|
|
|
|
|
|
|
|
personalityLabel := config.PersonalityLabelConfig[villagerConfig.Personality]
|
|
|
|
villagerRecordComponent["EndWordsCfgId"] = config.GetRandomConfigIdByGroup(personalityLabel.EndWords)
|
|
|
|
peopleComponent := map[string]interface{}{"_id": unit["_id"], "_t": consts.PeopleComponent, "Name": villagerConfig.Name, "FamilyName": villagerConfig.FirstName,
|
|
|
|
"PersonalityCfgId": villagerConfig.Personality, "Gender": villagerConfig.Gender}
|
|
|
|
|
|
|
|
if len(req.Name) > 0 {
|
|
|
|
peopleComponent["Name"] = req.Name
|
|
|
|
}
|
|
|
|
if len(req.FamilyName) > 0 {
|
|
|
|
peopleComponent["FamilyName"] = req.FamilyName
|
|
|
|
}
|
|
|
|
BehaveComponent := map[string]interface{}{"_id": unit["_id"], "_t": consts.BehaveComponent}
|
|
|
|
SlotComponent := map[string]interface{}{"_id": unit["_id"], "_t": consts.SlotComponent}
|
|
|
|
LabourComponent := map[string]interface{}{"_id": unit["_id"], "_t": consts.LabourComponent}
|
|
|
|
MarriageComponent := map[string]interface{}{"_id": unit["_id"], "_t": consts.MarriageComponent}
|
|
|
|
ResidentComponent := map[string]interface{}{"_id": unit["_id"], "_t": consts.ResidentComponent}
|
|
|
|
FightComponent := map[string]interface{}{"_id": unit["_id"], "_t": consts.FightComponent}
|
|
|
|
BuffComponent := map[string]interface{}{"_id": unit["_id"], "_t": consts.BuffComponent}
|
|
|
|
StudyComponent := map[string]interface{}{"_id": unit["_id"], "_t": consts.StudyComponent}
|
|
|
|
SkillComponent := map[string]interface{}{"_id": unit["_id"], "_t": consts.SkillComponent, "Children": []interface{}{}, "PassiveSkillCfgIds": []interface{}{}, "TalentSkillCfgId": 0}
|
|
|
|
SkillComponent["Children"] = append(SkillComponent["Children"].(primitive.A), map[string]interface{}{"_id": unit["_id"], "_t": consts.Skill, "ConfigId": config.WorldParametersConfig.VillagerSkillId, "CoolTime": 0})
|
|
|
|
VillagerSkillComponent := map[string]interface{}{"_id": unit["_id"], "_t": consts.VillagerSkillComponent, "Children": []interface{}{}}
|
|
|
|
|
|
|
|
for _, v := range villagerConfig.Skill {
|
|
|
|
villagerSkillC := config.VillagerSkillConfig[v]
|
|
|
|
if villagerSkillC == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
VillagerSkill := map[string]interface{}{"_id": unit["_id"], "_t": consts.VillagerSkill, "ConfigId": villagerSkillC.Id}
|
|
|
|
VillagerSkillComponent["Children"] = append(VillagerSkillComponent["Children"].(primitive.A), VillagerSkill)
|
|
|
|
State_Ref, ok := config.SkillBuffConfig[villagerSkillC.State]
|
|
|
|
if State_Ref != nil && ok {
|
|
|
|
buff := map[string]interface{}{"_id": unit["_id"], "_t": consts.Buff, "BuffLayer": 1,
|
|
|
|
"SkillCfgId": villagerSkillC.Id, "ConfigId": villagerSkillC.State, "AtkerId": 0, "Life": 0}
|
|
|
|
BuffComponent["Children"] = []map[string]interface{}{buff}
|
|
|
|
SpecialStatus_Ref, ok1 := config.SpecialStatusConfig[State_Ref.SpecialStatus]
|
|
|
|
if SpecialStatus_Ref != nil && ok1 {
|
|
|
|
buff["Children"] = []map[string]interface{}{{"_id": unit["_id"], "_t": consts.Status, "ConfigId": State_Ref.SpecialStatus}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
unit["C"] = append(villagers, villagerRecordComponent, gameNumericComponent, peopleComponent, BehaveComponent,
|
|
|
|
SlotComponent, LabourComponent, MarriageComponent, ResidentComponent, FightComponent, BuffComponent, StudyComponent,
|
|
|
|
SkillComponent, VillagerSkillComponent)
|
|
|
|
case consts.GameUnitType_Npc:
|
|
|
|
npcConfig := config.NpcConfig[req.CfgId]
|
|
|
|
if npcConfig == nil {
|
|
|
|
return nil, errors.New("err_NpcConfig")
|
|
|
|
}
|
|
|
|
pos := config.WorldParametersConfig.ValleyBusinessManSpawnPos
|
|
|
|
unit := map[string]interface{}{"_id": gtime.TimestampMilli(), "_t": consts.GameUnit, "UnitType": consts.GameUnitType_Npc,
|
|
|
|
"UnitCamp": consts.GameUnitCamp_Friend, "Position": map[string]interface{}{"x": pos.X, "y": pos.Y}, "C": []interface{}{}}
|
|
|
|
children = append(children, unit)
|
|
|
|
villagers := unit["C"].(primitive.A)
|
|
|
|
npcComponent := map[string]interface{}{"_id": unit["_id"], "_t": consts.NpcComponent}
|
|
|
|
villagers = append(villagers, npcComponent)
|
|
|
|
npcComponent["ConfigId"] = req.CfgId
|
|
|
|
behaveComponent := map[string]interface{}{"_id": unit["_id"], "_t": consts.BehaveComponent, "BehaveType": consts.BehaveType_BEHAVE_IDLE,
|
|
|
|
"DayBehaveType": consts.BehaveType_BEHAVE_IDLE, "DayTargetId": 0}
|
|
|
|
villagers = append(villagers, behaveComponent)
|
|
|
|
gameNumericComponent := map[string]interface{}{"_id": unit["_id"], "_t": consts.GameNumericComponent, "NumericDic": []interface{}{}}
|
|
|
|
NumericDic := gameNumericComponent["NumericDic"].(primitive.A)
|
|
|
|
NumericDic = append(NumericDic, []interface{}{consts.NUMERICTYPE_MOVESPEEDBASE, npcConfig.MoveSpeed})
|
|
|
|
villagers = append(villagers, gameNumericComponent)
|
|
|
|
dialogueComponent := map[string]interface{}{"_id": unit["_id"], "_t": consts.DialogueComponent, "State": 0, "IsInteractived": false, "InteractivedRewardOptions": []int32{}}
|
|
|
|
unit["C"] = append(villagers, dialogueComponent)
|
|
|
|
if npcConfig.Type == consts.NpcConfig_Type_BUSINESSMAN {
|
|
|
|
businessManComponent := map[string]interface{}{"_id": unit["_id"], "_t": consts.BusinessManComponent, "Sales": []interface{}{},
|
|
|
|
"Recycles": []interface{}{}, "SaleRefreshTimes": 0, "RecycleRefreshTimes": 0}
|
|
|
|
villagers = append(villagers, businessManComponent)
|
|
|
|
businessManComponent["ConfigId"] = npcConfig.RelatedId
|
|
|
|
businessManConfig := config.BusinessManConfig[npcConfig.RelatedId]
|
|
|
|
|
|
|
|
// Recycles
|
|
|
|
extralRecycleConfigs := config.GoodsForRecycleConfig[businessManConfig.RecycleItem]
|
|
|
|
var extralRecycleNum int32 = 0
|
|
|
|
extralRecycles := []*config.GoodsForRecycle{}
|
|
|
|
extralRecycleWeight := []int32{}
|
|
|
|
for _, v := range extralRecycleConfigs {
|
|
|
|
extralRecycles = append(extralRecycles, v)
|
|
|
|
extralRecycleWeight = append(extralRecycleWeight, v.Weight)
|
|
|
|
}
|
|
|
|
|
|
|
|
recycles := businessManComponent["Recycles"].(primitive.A)
|
|
|
|
for {
|
|
|
|
if extralRecycleNum >= businessManConfig.RecycleItemNum || len(extralRecycles) == 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
index := utils.RandomByWeight(extralRecycleWeight)
|
|
|
|
extralRecycleNum++
|
|
|
|
recycles = append(recycles, createRecycleGoods(extralRecycles[index]))
|
|
|
|
extralRecycleWeight = append(extralRecycleWeight[:index], extralRecycleWeight[index+1:]...)
|
|
|
|
extralRecycles = append(extralRecycles[:index], extralRecycles[index+1:]...)
|
|
|
|
}
|
|
|
|
commonRecycleItems := config.GoodsForRecycleConfig[businessManConfig.CommonRecycleItem]
|
|
|
|
for _, v := range commonRecycleItems {
|
|
|
|
recycles = append(recycles, createRecycleGoods(v))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sales
|
|
|
|
sales := businessManComponent["Sales"].(primitive.A)
|
|
|
|
saleConfigs := config.GoodsForRecycleConfig[businessManConfig.ItemGroup]
|
|
|
|
for _, saleConfig := range saleConfigs {
|
|
|
|
if saleConfig.SaleMax > 0 {
|
|
|
|
// todo 最大值判断
|
|
|
|
}
|
|
|
|
sales = append(sales, createRecycleGoods(saleConfig))
|
|
|
|
}
|
|
|
|
extralSaleConfigs := config.GoodsForRecycleConfig[businessManConfig.ExtraItemGroup]
|
|
|
|
var extralSaleNum int32 = 0
|
|
|
|
extralSales := []*config.GoodsForRecycle{}
|
|
|
|
extralSaleWeight := []int32{}
|
|
|
|
for _, v := range extralSaleConfigs {
|
|
|
|
extralSales = append(extralSales, v)
|
|
|
|
extralSaleWeight = append(extralSaleWeight, v.Weight)
|
|
|
|
}
|
|
|
|
for {
|
|
|
|
if extralSaleNum >= businessManConfig.ExtraItemNum || len(extralSales) == 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
index := utils.RandomByWeight(extralSaleWeight)
|
|
|
|
extralSaleNum++
|
|
|
|
recycles = append(recycles, createRecycleGoods(extralSales[index]))
|
|
|
|
extralSaleWeight = append(extralSaleWeight[:index], extralSaleWeight[index+1:]...)
|
|
|
|
extralSales = append(extralSales[:index], extralSales[index+1:]...)
|
|
|
|
}
|
|
|
|
|
|
|
|
businessManComponent["Recycles"] = recycles
|
|
|
|
}
|
|
|
|
case consts.GameUnitType_Warrior:
|
|
|
|
case consts.GameUnitType_RegionResPoint:
|
|
|
|
case consts.GameUnitType_Building:
|
|
|
|
case consts.GameUnitType_Monster:
|
|
|
|
default:
|
|
|
|
return nil, errors.New("ERR_OperateFail")
|
|
|
|
}
|
|
|
|
|
|
|
|
err3 := internal.UpdateUnitP(ctx, uid, c, fmt.Sprint(req.ServerId))
|
|
|
|
if err3 != nil {
|
|
|
|
log.Println("additem UpdateUnitP err", err3)
|
|
|
|
return nil, err3
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Println("additem UpdateUnitP 1", err3)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func createRecycleGoods(cfg *config.GoodsForRecycle) map[string]interface{} {
|
|
|
|
res := map[string]interface{}{}
|
|
|
|
randVal := utils.RandInt32(0, 101)
|
|
|
|
if randVal <= cfg.DiscountWeight {
|
|
|
|
res["Discount"] = cfg.Discount
|
|
|
|
} else {
|
|
|
|
res["Discount"] = 100
|
|
|
|
}
|
|
|
|
res["Amount"] = 0
|
|
|
|
res["ItemCfgId"] = cfg.ItemId
|
|
|
|
res["AmountMax"] = utils.RandInt32(cfg.SaleNum[0], cfg.SaleNum[1]+1)
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ga *gameManageImpl) AddVillagerSkill(ctx context.Context, req *game.AddVillagerSkillReq) (res *game.AddVillagerSkillRes, err error) {
|
|
|
|
uid, err := internal.GetAccountUid(ctx, req.Account, fmt.Sprint(req.ServerId))
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("GetAccount err", err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
fmt.Println("GetRoleDelta", uid)
|
|
|
|
roleDelta, err2 := internal.GetRoleDetail(ctx, uid, fmt.Sprint(req.ServerId))
|
|
|
|
if err2 != nil {
|
|
|
|
fmt.Println("err2: ", err2)
|
|
|
|
return nil, err2
|
|
|
|
}
|
|
|
|
|
|
|
|
t := roleDelta["_t"]
|
|
|
|
c := roleDelta["C"].(primitive.A)
|
|
|
|
log.Println(" rrr >>> ", t)
|
|
|
|
GameUnitComponent := map[string]interface{}{}
|
|
|
|
gameUnit := primitive.A{}
|
|
|
|
villagerSkillComponent := map[string]interface{}{}
|
|
|
|
buffComponent := map[string]interface{}{}
|
|
|
|
for _, v := range c {
|
|
|
|
v1 := v.(map[string]interface{})
|
|
|
|
if v1["_t"] == consts.GameUnitComponent {
|
|
|
|
GameUnitComponent = v.(map[string]interface{})
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
childs := GameUnitComponent["children"].(primitive.A)
|
|
|
|
for _, v := range childs {
|
|
|
|
v1 := v.(map[string]interface{})
|
|
|
|
if v1["_id"] == req.GameUnitId {
|
|
|
|
gameUnit = v1["C"].(primitive.A)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range gameUnit {
|
|
|
|
v1 := v.(map[string]interface{})
|
|
|
|
if v1["_t"] == consts.VillagerSkillComponent {
|
|
|
|
villagerSkillComponent = v1
|
|
|
|
break
|
|
|
|
} else if v1["_t"] == consts.BuffComponent {
|
|
|
|
buffComponent = v1
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vsconfig := config.VillagerSkillConfig[req.VillagerSkillId]
|
|
|
|
if vsconfig == nil {
|
|
|
|
return nil, errors.New("error_config")
|
|
|
|
}
|
|
|
|
Children := villagerSkillComponent["Children"].(primitive.A)
|
|
|
|
oldConfigId := getVillagerSkillCfgIdByGroupAndGrade(vsconfig.Group, vsconfig.Grade-1)
|
|
|
|
for k, v := range Children {
|
|
|
|
villagerSkill := v.(map[string]interface{})
|
|
|
|
if villagerSkill["ConfigId"] == oldConfigId {
|
|
|
|
Children = append(Children[:k], Children[k+1:]...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
VillagerSkill := map[string]interface{}{"_id": gtime.TimestampMilli(), "_t": consts.VillagerSkill}
|
|
|
|
VillagerSkill["Config"] = vsconfig.Id
|
|
|
|
villagerSkillComponent["Children"] = append(Children, VillagerSkill)
|
|
|
|
AddBuff(buffComponent, vsconfig.State, vsconfig.Id, 0)
|
|
|
|
err3 := internal.UpdateUnitP(ctx, uid, c, fmt.Sprint(req.ServerId))
|
|
|
|
if err3 != nil {
|
|
|
|
log.Println("additem UpdateUnitP err", err3)
|
|
|
|
return nil, err3
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Println("additem UpdateUnitP 1", err3)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
func getVillagerSkillCfgIdByGroupAndGrade(group int32, grade int32) int32 {
|
|
|
|
for _, v := range config.VillagerSkillConfig {
|
|
|
|
if v.Group == group && v.Grade == grade {
|
|
|
|
return v.Id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func AddBuff(buffComponent map[string]interface{}, buffCfgId int32, skillCfgId int32, atkerId int64) {
|
|
|
|
buffChildren := buffComponent["Children"].(primitive.A)
|
|
|
|
|
|
|
|
//vsconfig := config.VillagerSkillConfig[skillCfgId]
|
|
|
|
buffConfig := config.SkillBuffConfig[buffCfgId]
|
|
|
|
if buffConfig != nil {
|
|
|
|
//var removeId int64 = 0
|
|
|
|
var layer int32 = 1
|
|
|
|
for k, v := range buffChildren {
|
|
|
|
oldBuff := v.(map[string]interface{})
|
|
|
|
if oldBuff["ConfigId"] == buffCfgId {
|
|
|
|
if buffConfig.Overlay {
|
|
|
|
BuffLayer := oldBuff["BuffLayer"].(int32)
|
|
|
|
if BuffLayer < buffConfig.OverlayMax {
|
|
|
|
layer = BuffLayer + 1
|
|
|
|
} else {
|
|
|
|
layer = buffConfig.OverlayMax
|
|
|
|
}
|
|
|
|
buffChildren = append(buffChildren[:k], buffChildren[k+1:]...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if buffConfig.SequenceId != 0 && buffConfig.SequenceLv != 0 {
|
|
|
|
for k, v := range buffChildren {
|
|
|
|
oldBuff := v.(map[string]interface{})
|
|
|
|
vConfig := config.SkillBuffConfig[oldBuff["ConfigId"].(int32)]
|
|
|
|
if vConfig.SequenceId != 0 && vConfig.SequenceLv != 0 && vConfig.SequenceId == buffConfig.SequenceId {
|
|
|
|
if vConfig.SequenceLv <= buffConfig.SequenceLv {
|
|
|
|
buffChildren = append(buffChildren[:k], buffChildren[k+1:]...)
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buffChild := map[string]interface{}{"_id": gtime.TimestampMilli(), "_t": consts.Buff, "ConfigId": buffCfgId, "Duration": 0, "BuffLayer": layer,
|
|
|
|
"SkillCfgId": skillCfgId, "EffectValues": []interface{}{}, "Life": 0, "EffectCdTime": 0, "AtkerId": atkerId, "EffectTick": 0, "Children": primitive.A{}}
|
|
|
|
SpecialStatus_Ref := config.SpecialStatusConfig[buffConfig.SpecialStatus]
|
|
|
|
if SpecialStatus_Ref != nil {
|
|
|
|
buffChilds := buffChild["Children"].(primitive.A)
|
|
|
|
buffChild["Children"] = append(buffChilds, map[string]interface{}{"_id": gtime.TimestampMilli(), "_t": consts.Status, "ConfigId": buffConfig.SpecialStatus})
|
|
|
|
}
|
|
|
|
if buffConfig.TriggerTime == consts.SkillBuff_TriggerTime_RIGHTNOW {
|
|
|
|
for _, v := range buffConfig.LinkEffect {
|
|
|
|
SkillEffectConfig := config.SkillEffectConfig[v]
|
|
|
|
if SkillEffectConfig != nil {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if buffConfig.ContinuedType == consts.SkillBuff_ContinuedType_RIGHTNOW {
|
|
|
|
|
|
|
|
}
|
|
|
|
buffComponent["Children"] = append(buffChildren, buffChild)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ga *gameManageImpl) SetWeather(ctx context.Context, req *game.SetWeatherReq) (res *game.SetWeatherRes, err error) {
|
|
|
|
uid, err := internal.GetAccountUid(ctx, req.Account, fmt.Sprint(req.ServerId))
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("SetWeather err", err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
fmt.Println("SetWeather GetRoleDetail", uid)
|
|
|
|
roleDelta, err2 := internal.GetRoleDetail(ctx, uid, fmt.Sprint(req.ServerId))
|
|
|
|
if err2 != nil {
|
|
|
|
fmt.Println("err2: ", err2)
|
|
|
|
return nil, err2
|
|
|
|
}
|
|
|
|
|
|
|
|
t := roleDelta["_t"]
|
|
|
|
c := roleDelta["C"].(primitive.A)
|
|
|
|
log.Println("SetWeather rrr >>> ", t)
|
|
|
|
WeatherComponent := map[string]interface{}{}
|
|
|
|
ValleyComponent := map[string]interface{}{}
|
|
|
|
GameUnitComponent := map[string]interface{}{}
|
|
|
|
|
|
|
|
for _, v := range c {
|
|
|
|
v1 := v.(map[string]interface{})
|
|
|
|
if v1["_t"] == consts.WeatherComponent {
|
|
|
|
WeatherComponent = v1
|
|
|
|
} else if v1["_t"] == consts.ValleyComponent {
|
|
|
|
ValleyComponent = v1
|
|
|
|
} else if v1["_t"] == consts.GameUnitComponent {
|
|
|
|
GameUnitComponent = v1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if WeatherComponent == nil {
|
|
|
|
WeatherComponent = map[string]interface{}{"_id": uid, "_t": consts.WeatherComponent}
|
|
|
|
roleDelta["C"] = append(c, WeatherComponent)
|
|
|
|
}
|
|
|
|
WeatherComponent["ConfigId"] = req.WeatherConfigId
|
|
|
|
WeatherComponent["StartTime"] = 0
|
|
|
|
weatherConf := config.WeatherConfig[req.WeatherConfigId]
|
|
|
|
WeatherComponent["Duration"] = utils.RandInt32(weatherConf.Duration[0], weatherConf.Duration[1]+1)
|
|
|
|
WeatherComponent["IsWeatherStart"] = true
|
|
|
|
if weatherConf.SkillBUFF != 0 {
|
|
|
|
for _, v := range GameUnitComponent {
|
|
|
|
gameUnit := v.(map[string]interface{})
|
|
|
|
if gameUnit != nil && gameUnit["UnitType"] != consts.GameUnitType_Villager && gameUnit["UnitType"] != consts.GameUnitType_Warrior {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
Compoent := gameUnit["C"].(primitive.A)
|
|
|
|
buffComponent := map[string]interface{}{}
|
|
|
|
for _, v2 := range Compoent {
|
|
|
|
v3 := v2.(map[string]interface{})
|
|
|
|
if v3["_t"] == consts.BuffComponent {
|
|
|
|
buffComponent = v3
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AddBuff(buffComponent, weatherConf.SkillBUFF, 0, 0)
|
|
|
|
BuffCfgIds := ValleyComponent["BuffCfgIds"].(primitive.A)
|
|
|
|
//var a = weatherConf.SkillBUFF.(interface{})
|
|
|
|
if !utils.ContainsGeneric(BuffCfgIds, weatherConf.SkillBUFF) {
|
|
|
|
BuffCfgIds = append(BuffCfgIds, weatherConf.SkillBUFF)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err3 := internal.UpdateUnitP(ctx, uid, c, fmt.Sprint(req.ServerId))
|
|
|
|
if err3 != nil {
|
|
|
|
log.Println("SetWeather UpdateUnitP err", err3)
|
|
|
|
return nil, err3
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Println("SetWeather UpdateUnitP 1", err3)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ga *gameManageImpl) ClearResource(ctx context.Context, req *game.ClearResourceReq) (res *game.ClearResourceRes, err error) {
|
|
|
|
uid, err := internal.GetAccountUid(ctx, req.Account, fmt.Sprint(req.ServerId))
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("ClearResource GetAccount err", err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
fmt.Println("ClearResource GetRoleDelta", uid)
|
|
|
|
roleDelta, err2 := internal.GetRoleDetail(ctx, uid, fmt.Sprint(req.ServerId))
|
|
|
|
if err2 != nil {
|
|
|
|
fmt.Println("err2: ", err2)
|
|
|
|
return nil, err2
|
|
|
|
}
|
|
|
|
|
|
|
|
t := roleDelta["_t"]
|
|
|
|
c := roleDelta["C"].(primitive.A)
|
|
|
|
log.Println("ClearResource rrr >>> ", t)
|
|
|
|
GatherComponent := map[string]interface{}{}
|
|
|
|
GameUnitComponent := map[string]interface{}{}
|
|
|
|
ValleyComponent := map[string]interface{}{}
|
|
|
|
TroopComponent := map[string]interface{}{}
|
|
|
|
for _, v := range c {
|
|
|
|
v1 := v.(map[string]interface{})
|
|
|
|
if v1["_t"] == consts.GatherComponent {
|
|
|
|
GatherComponent = v1
|
|
|
|
} else if v1["_t"] == consts.GameUnitComponent {
|
|
|
|
GameUnitComponent = v1
|
|
|
|
} else if v1["_t"] == consts.ValleyComponent {
|
|
|
|
ValleyComponent = v1
|
|
|
|
} else if v1["_t"] == consts.TroopComponent {
|
|
|
|
TroopComponent = v1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ResIds := []int32{}
|
|
|
|
guC := GameUnitComponent["Children"].(primitive.A)
|
|
|
|
for _, v := range guC {
|
|
|
|
GameUnit := v.(map[string]interface{})
|
|
|
|
if GameUnit["UnitType"] == consts.GameUnitType_Building || GameUnit["UnitType"] == consts.GameUnitType_ResourcePoint {
|
|
|
|
gameUnitC := GameUnit["C"].(primitive.A)
|
|
|
|
for _, v1 := range gameUnitC {
|
|
|
|
component := v1.(map[string]interface{})
|
|
|
|
if component["_t"] == consts.ResidentComponent {
|
|
|
|
rpConfig := config.ResourcesPointConfig[component["ConfigId"].(int32)]
|
|
|
|
if rpConfig.Type == consts.ResourcesPoint_Type_POINTRESOURCES {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
gatherC := GatherComponent["Children"].(primitive.A)
|
|
|
|
for _, v2 := range gatherC {
|
|
|
|
gather := v2.(map[string]interface{})
|
|
|
|
if gather["_id"] == GameUnit["_id"] {
|
|
|
|
var idList = append(gather["PeopleIdList"].(primitive.A), gather["PreparePeopleIdList"].(primitive.A)...)
|
|
|
|
for _, vi := range idList {
|
|
|
|
for _, vg := range guC {
|
|
|
|
gameUnit1 := vg.(map[string]interface{})
|
|
|
|
if gameUnit1["_id"] == vi {
|
|
|
|
gu1C := gameUnit1["C"].(primitive.A)
|
|
|
|
for _, vg1 := range gu1C {
|
|
|
|
vg2 := vg1.(map[string]interface{})
|
|
|
|
if vg2["_t"] == consts.BehaveComponent {
|
|
|
|
processedNewBehave := consts.BehaveType_BEHAVE_IDLE
|
|
|
|
if ValleyComponent != nil && ValleyComponent["IsNight"].(bool) {
|
|
|
|
processedNewBehave = consts.BehaveType_BEHAVE_NIGHT_IDLE
|
|
|
|
}
|
|
|
|
PeopleList := TroopComponent["PeopleList"].(primitive.A)
|
|
|
|
if processedNewBehave == consts.BehaveType_BEHAVE_BATTLE && gameUnit1["UnitType"] == consts.GameUnitType_Warrior &&
|
|
|
|
PeopleList != nil && utils.ContainsGeneric(PeopleList, vg2["_id"]) {
|
|
|
|
processedNewBehave = consts.BehaveType_BEHAVE_TROOP_BATTLE
|
|
|
|
}
|
|
|
|
vg2["BehaveType"] = processedNewBehave
|
|
|
|
vg2["TargetId"] = 0
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ResIds = append(ResIds, component["_id"].(int32))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, v := range ResIds {
|
|
|
|
for k1, v1 := range guC {
|
|
|
|
GameUnit := v1.(map[string]interface{})
|
|
|
|
if GameUnit["_id"] == v {
|
|
|
|
v1 = append(guC[:k1], guC[k1+1:]...)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err3 := internal.UpdateUnitP(ctx, uid, c, fmt.Sprint(req.ServerId))
|
|
|
|
if err3 != nil {
|
|
|
|
log.Println("ClearResource UpdateUnitP err", err3)
|
|
|
|
return nil, err3
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Println("ClearResource UpdateUnitP 1", err3)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ga *gameManageImpl) CopyUnit(ctx context.Context, req *game.CopyUnitReq) (res *game.CopyUnitRes, err error) {
|
|
|
|
res = new(game.CopyUnitRes)
|
|
|
|
unit, err := internal.GetUnit(ctx, int64(req.SrcName))
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("GetAccount:", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
mongoConfig := internal.MongoConfigs[fmt.Sprint(unit.Server)]
|
|
|
|
if mongoConfig.Id == "" {
|
|
|
|
return res, errors.New("区服不存在!")
|
|
|
|
}
|
|
|
|
filename := "Unit" + fmt.Sprint(req.SrcName) + ".json"
|
|
|
|
storeFilename := "storeComponent" + fmt.Sprint(req.SrcName) + ".json"
|
|
|
|
userDir := "./download/" + filename
|
|
|
|
storeDir := "./download/" + storeFilename
|
|
|
|
cmdName := "getData" + fmt.Sprint(time.Now().Unix())
|
|
|
|
g.Try(ctx, func(ctx context.Context) {
|
|
|
|
if runtime.GOOS == "linux" {
|
|
|
|
// LINUX系统
|
|
|
|
wireteString := fmt.Sprintf("mongoexport --uri=\"%s\" --authenticationDatabase=%s --collection=Unit --out=\"%s\" --query=\"{\\\"UniqueId\\\":%d}\" --jsonArray --jsonFormat=canonical --type=json",
|
|
|
|
mongoConfig.Link1, mongoConfig.Auth, userDir, req.SrcName)
|
|
|
|
writeString := fmt.Sprintf("mongoexport --uri=\"%s\" --authenticationDatabase=%s --collection=StoreComponent --out=\"%s\" --query=\"{\\\"_id\\\":%d}\" --jsonArray --jsonFormat=canonical --type=json",
|
|
|
|
mongoConfig.Link1, mongoConfig.Auth, storeDir, unit.Uid)
|
|
|
|
log.Println(wireteString)
|
|
|
|
log.Println(writeString)
|
|
|
|
if err = os.WriteFile("./"+cmdName+".sh", []byte(wireteString+"\n"+writeString), 0666); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
cmd := exec.Command("sh", cmdName+".sh")
|
|
|
|
var stdout, stderr bytes.Buffer
|
|
|
|
cmd.Stdout = &stdout // 标准输出
|
|
|
|
cmd.Stderr = &stderr // 标准错误
|
|
|
|
err = cmd.Run()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("cmd.Run() failed with %s\n", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
outStr, errStr := string(stdout.Bytes()), string(stderr.Bytes())
|
|
|
|
fmt.Printf("out:\n%s\nerr:\n%s\n", outStr, errStr)
|
|
|
|
}
|
|
|
|
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
// windows系统
|
|
|
|
writeString := fmt.Sprintf("mongoexport --uri=\"%s\" --authenticationDatabase=%s --collection=Unit --out=\"%s\" --query=\"{\\\"UniqueId\\\":%d}\" --jsonArray --jsonFormat=canonical --type=json",
|
|
|
|
mongoConfig.Link1, mongoConfig.Auth, userDir, req.SrcName)
|
|
|
|
storeWriteString := fmt.Sprintf("mongoexport --uri=\"%s\" --authenticationDatabase=%s --collection=StoreComponent --out=\"%s\" --query=\"{\\\"_id\\\":%d}\" --jsonArray --jsonFormat=canonical --type=json",
|
|
|
|
mongoConfig.Link1, mongoConfig.Auth, storeDir, unit.Uid)
|
|
|
|
log.Println(writeString)
|
|
|
|
log.Println(storeWriteString)
|
|
|
|
if err = os.WriteFile("./"+cmdName+".bat", []byte(writeString+"\n"+storeWriteString), 0666); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
cmd := exec.Command("cmd", "/c", cmdName+".bat")
|
|
|
|
err = cmd.Start()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error:", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res.Filename = filename
|
|
|
|
res.StoreFilename = storeFilename
|
|
|
|
})
|
|
|
|
fmt.Println("CopyUnit GetRoleDelta", res.Filename)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ga *gameManageImpl) UpdateUnit(ctx context.Context, req *game.UpdateUnitReq) (res *game.UpdateUnitRes, err error) {
|
|
|
|
res = new(game.UpdateUnitRes)
|
|
|
|
unit, err := internal.GetUnit(ctx, int64(req.DestName))
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("GetAccount:", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
mongoConfig := internal.MongoConfigs[fmt.Sprint(unit.Server)]
|
|
|
|
if mongoConfig.Id == "" {
|
|
|
|
return res, errors.New("区服不存在!")
|
|
|
|
}
|
|
|
|
|
|
|
|
destId, err1 := internal.GetIdToUid(ctx, int64(req.DestName))
|
|
|
|
if err1 != nil {
|
|
|
|
return res, err1
|
|
|
|
}
|
|
|
|
userDir := "./download/Unit" + fmt.Sprint(req.DestName) + ".json"
|
|
|
|
srcUserDir := "./download/" + req.Filename
|
|
|
|
writeByte, err1 := os.ReadFile(srcUserDir)
|
|
|
|
if err1 != nil {
|
|
|
|
return res, err1
|
|
|
|
}
|
|
|
|
|
|
|
|
srcUid := ""
|
|
|
|
srcId := ""
|
|
|
|
var v1 map[string]interface{}
|
|
|
|
if strings.HasPrefix(string(writeByte), "[") {
|
|
|
|
user := []interface{}{}
|
|
|
|
json.Unmarshal(writeByte, &user)
|
|
|
|
v1 = user[0].(map[string]interface{})
|
|
|
|
} else {
|
|
|
|
json.Unmarshal(writeByte, &v1)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := v1["UniqueId"]; ok {
|
|
|
|
UniqueId := v1["UniqueId"].(map[string]interface{})
|
|
|
|
srcUid = fmt.Sprint(UniqueId["$numberInt"])
|
|
|
|
}
|
|
|
|
if _, ok := v1["_id"]; ok {
|
|
|
|
UniqueId := v1["_id"].(map[string]interface{})
|
|
|
|
srcId = fmt.Sprint(UniqueId["$numberLong"])
|
|
|
|
}
|
|
|
|
|
|
|
|
userStoreDir := "./download/storeComponent" + fmt.Sprint(req.DestName) + ".json"
|
|
|
|
srcStoreDir := "./download/" + req.StoreFilename
|
|
|
|
writeStoreByte, err1 := os.ReadFile(srcStoreDir)
|
|
|
|
if err1 != nil {
|
|
|
|
return res, err1
|
|
|
|
}
|
|
|
|
|
|
|
|
var v2 map[string]interface{}
|
|
|
|
if strings.HasPrefix(string(writeStoreByte), "[") {
|
|
|
|
user := []interface{}{}
|
|
|
|
json.Unmarshal(writeStoreByte, &user)
|
|
|
|
v2 = user[0].(map[string]interface{})
|
|
|
|
} else {
|
|
|
|
json.Unmarshal(writeStoreByte, &v2)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("copyUnit srcid: %s, uid: %s, destid: %d, uid: %d", srcId, srcUid, destId, req.DestName)
|
|
|
|
if srcId == "" || srcUid == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
writeUnitString := strings.ReplaceAll(gjson.MustEncodeString(v1), srcId, fmt.Sprint(destId))
|
|
|
|
writeStoreString := strings.ReplaceAll(gjson.MustEncodeString(v2), srcId, fmt.Sprint(destId))
|
|
|
|
writeUnitString = internal.ReplaceLastOccurrence(writeUnitString, srcUid, fmt.Sprint(req.DestName))
|
|
|
|
if err = os.WriteFile(userDir, []byte(writeUnitString), 0666); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err = os.WriteFile(userStoreDir, []byte(writeStoreString), 0666); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
writeUnitCmd := fmt.Sprintf("mongoimport --uri=\"%s\" --authenticationDatabase=%s --collection=Unit --file=\"%s\" --type=json --mode=upsert",
|
|
|
|
mongoConfig.Link1, mongoConfig.Auth, userDir)
|
|
|
|
writeStoreCmd := fmt.Sprintf("mongoimport --uri=\"%s\" --authenticationDatabase=%s --collection=StoreComponent --file=\"%s\" --type=json --mode=upsert",
|
|
|
|
mongoConfig.Link1, mongoConfig.Auth, userStoreDir)
|
|
|
|
log.Println("sh Unit: ", writeUnitCmd)
|
|
|
|
log.Println("sh StoreComponent: ", writeStoreCmd)
|
|
|
|
g.Try(ctx, func(ctx context.Context) {
|
|
|
|
cmdName := "getData" + fmt.Sprint(time.Now().Unix())
|
|
|
|
if runtime.GOOS == "linux" {
|
|
|
|
// LINUX系统
|
|
|
|
if err = os.WriteFile("./"+cmdName+".sh", []byte(writeUnitCmd+"\n"+writeStoreCmd), 0666); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
cmd := exec.Command("sh", cmdName+".sh")
|
|
|
|
var stdout, stderr bytes.Buffer
|
|
|
|
cmd.Stdout = &stdout // 标准输出
|
|
|
|
cmd.Stderr = &stderr // 标准错误
|
|
|
|
err = cmd.Run()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("cmd.Run() failed with %s\n", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
outStr, errStr := string(stdout.Bytes()), string(stderr.Bytes())
|
|
|
|
fmt.Printf("out:\n%s\nerr:\n%s\n", outStr, errStr)
|
|
|
|
}
|
|
|
|
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
// windows系统
|
|
|
|
if err = os.WriteFile("./"+cmdName+".bat", []byte(writeUnitCmd+"\n"+writeStoreCmd), 0666); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
cmd := exec.Command("cmd", "/c", cmdName+".bat")
|
|
|
|
err = cmd.Start()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error:", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
fmt.Println("UpdateUnit GetRoleDelta", req.DestName)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ga *gameManageImpl) DelAccount(ctx context.Context, req *game.DelAccountReq) (res *game.DelAccountRes, err error) {
|
|
|
|
uid, err := internal.GetAccountUid2(ctx, req.SrcName, fmt.Sprint(req.ServerId))
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("DelAccount GetAccount err", err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
fmt.Println("DelAccount DelRole", uid)
|
|
|
|
_, err2 := internal.DelRole(ctx, uid, fmt.Sprint(req.ServerId))
|
|
|
|
if err2 != nil {
|
|
|
|
fmt.Println("DelAccount err2: ", err2)
|
|
|
|
return nil, err2
|
|
|
|
}
|
|
|
|
_, err3 := internal.DelAccount(ctx, uid, fmt.Sprint(req.ServerId))
|
|
|
|
if err3 != nil {
|
|
|
|
fmt.Println("DelAccount err3: ", err3)
|
|
|
|
return nil, err3
|
|
|
|
}
|
|
|
|
_, err4 := internal.DelBaseInfo(ctx, uid, fmt.Sprint(req.ServerId))
|
|
|
|
fmt.Println("DelAccount err4: ", err4)
|
|
|
|
_, err6 := internal.DelBazaar(ctx, uid, fmt.Sprint(req.ServerId))
|
|
|
|
fmt.Println("DelAccount err6: ", err6)
|
|
|
|
_, err5 := internal.DelFriendUnit(ctx, uid, fmt.Sprint(req.ServerId))
|
|
|
|
fmt.Println("DelAccount err5: ", err5)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ga *gameManageImpl) SearchAccount(ctx context.Context, req *game.SearchAccountReq) (res *game.SearchAccountRes, err error) {
|
|
|
|
res, err = internal.SearchAccount(ctx, req)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("err3: ", err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
**留存
|
|
|
|
**/
|
|
|
|
func (ga *gameManageImpl) GetKeepAlive(ctx context.Context, req *game.GetKeepAliveReq) (res *game.GetKeepAliveRes, err error) {
|
|
|
|
res, err = internal.GetKeepAlive(ctx, req)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ga *gameManageImpl) GetLive(ctx context.Context, req *game.GetLiveReq) (res *game.GetLiveRes, err error) {
|
|
|
|
res, err = internal.GetLive(ctx, req)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ga *gameManageImpl) RegisterCount(ctx context.Context, req *game.RegisterCountReq) (res *game.RegisterCountRes, err error) {
|
|
|
|
res, err = internal.RegisterNum(ctx, req)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ga *gameManageImpl) GetShopItemLog(ctx context.Context, req *game.GetShopItemLogReq) (res *game.GetShopItemLogRes, err error) {
|
|
|
|
res, err = internal.GetShopItemLog(ctx, req)
|
|
|
|
return
|
|
|
|
}
|