Browse Source

isnew

master
linquan 3 months ago
parent
commit
ff1bc1d142
  1. 1
      api/v1/game/ccd.go
  2. 1
      api/v1/game/pub.go
  3. 10
      internal/controller/baseinfo_role.go
  4. 5
      internal/controller/game_manage.go
  5. 2
      internal/dao/internal/game_login_url.go
  6. 1
      internal/model/do/game_login_url.go
  7. 1
      internal/model/entity/game_login_url.go
  8. 18
      internal/serviceGame/game_role.go
  9. 9
      internal/serviceGame/internal/basicinfo.go
  10. 32
      internal/serviceGame/internal/manage.go
  11. 6
      internal/serviceGame/loginUrl.go
  12. 610
      internal/serviceGame/manage.go

1
api/v1/game/ccd.go

@ -74,6 +74,7 @@ type AddLoginUrlReq struct {
Port int `p:"port"`
State int `p:"state"`
Recommend int `p:"recommend"`
IsNew int `p:"isNew"`
}
type AddLoginUrlRes struct {

1
api/v1/game/pub.go

@ -40,6 +40,7 @@ type LoginUrlData struct {
Scale int `json:"scale" description:"玩家规模等级"`
AccountName string `json:"accountName" description:"玩家名称"`
CreateTime int64 `json:"createTime" description:"创建时间"`
IsNew int `json:"isNew" description:"是否新服"`
}
type GetGameLoginUrlRes struct {

10
internal/controller/baseinfo_role.go

@ -18,11 +18,6 @@ func (c *gameRoleController) List(ctx context.Context, req *game.RoleSearchReq)
return
}
//func (c *gameRoleController) RoleDetail(ctx context.Context, req *game.RoleDetailReq) (res *game.RoleDetailRes, err error) {
// res, err = serviceGame.GameRole().GetRoleDetail(ctx, req)
// return res, err
//}
func (c *gameRoleController) OnlineList(ctx context.Context, req *game.RoleOnlineReq) (res *game.RoleOnlineRes, err error) {
res, err = serviceGame.GameRole().GetOnlineList(ctx, req)
return res, err
@ -32,11 +27,6 @@ func (c *gameRoleController) OnlineTopList(ctx context.Context, req *game.RoleOn
return res, err
}
//func (c *gameRoleController) AccountList(ctx context.Context, req *game.AccountListReq) (res *game.AccountListRes, err error) {
// //res, err = serviceGame.GameRole().GetAccountList(ctx, req)
// return res, err
//}
func (c *gameRoleController) Account(ctx context.Context, req *game.AccountReq) (res *game.AccountRes, err error) {
res, err = serviceGame.GameRole().GetAccount(ctx, req)
return res, err

5
internal/controller/game_manage.go

@ -42,11 +42,6 @@ func (c *manageController) CopyUnit(ctx context.Context, req *game.CopyUnitReq)
return
}
//func (c *manageController) EditUnit(ctx context.Context, req *game.EditUnitReq) (res *game.EditUnitRes, err error) {
// res, err = serviceGame.GameManage().EditUnit(ctx, req)
// return
//}
func (c *manageController) UpdateUnit(ctx context.Context, req *game.UpdateUnitReq) (res *game.UpdateUnitRes, err error) {
res, err = serviceGame.GameManage().UpdateUnit(ctx, req)
return

2
internal/dao/internal/game_login_url.go

@ -39,6 +39,7 @@ type GameLoginUrlColumns struct {
InnerIp string // 内外地址
CreateTime string // 开服时间-用于服务器时间
Remark string // 备注名称
IsNew string //
}
// gameLoginUrlColumns holds the columns for table game_login_url.
@ -62,6 +63,7 @@ var gameLoginUrlColumns = GameLoginUrlColumns{
InnerIp: "inner_ip",
CreateTime: "create_time",
Remark: "remark",
IsNew: "is_new",
}
// NewGameLoginUrlDao creates and returns a new DAO object for table data access.

1
internal/model/do/game_login_url.go

@ -31,4 +31,5 @@ type GameLoginUrl struct {
InnerIp interface{} // 内外地址
CreateTime *gtime.Time // 开服时间-用于服务器时间
Remark interface{} // 备注名称
IsNew interface{} //
}

1
internal/model/entity/game_login_url.go

@ -29,4 +29,5 @@ type GameLoginUrl struct {
InnerIp string `json:"innerIp" description:"内外地址"`
CreateTime *gtime.Time `json:"createTime" description:"开服时间-用于服务器时间"`
Remark string `json:"remark" description:"备注名称"`
IsNew int `json:"isNew" description:""`
}

18
internal/serviceGame/game_role.go

@ -14,10 +14,8 @@ import (
type IGameRole interface {
GetGameRoleListSearch(ctx context.Context, req *game.RoleSearchReq) (res *game.RoleSearchRes, err error)
//GetRoleDetail(ctx context.Context, req *game.RoleDetailReq) (res *game.RoleDetailRes, err error)
GetOnlineList(ctx context.Context, req *game.RoleOnlineReq) (res *game.RoleOnlineRes, err error)
GetOnlineTopList(ctx context.Context, req *game.RoleOnlineTopReq) (res *game.RoleOnlineTopRes, err error)
//GetAccountList(ctx context.Context, req *game.AccountListReq) (res *game.AccountListRes, err error)
GetAccount(ctx context.Context, req *game.AccountReq) (res *game.AccountRes, err error)
GameRegister(ctx context.Context, req *game.RegisterReq) (res *game.RegisterRes, err error)
GameUnitChangeName(ctx context.Context, req *game.UnitChangeNameReq) (res *game.UnitChangeNameRes, err error)
@ -47,16 +45,6 @@ func (s *gameRoleImpl) GetGameRoleListSearch(ctx context.Context, req *game.Role
return
}
// 获取角色详情
//func (s *gameRoleImpl) GetRoleDetail(ctx context.Context, req *game.RoleDetailReq) (res *game.RoleDetailRes, err error) {
// res = new(game.RoleDetailRes)
// g.Try(ctx, func(ctx context.Context) {
// unit, _ := internal.GetRoleDetail(ctx, req.Uid)
// res.RoleDetail.C = unit["C"].([]entity.Component)
// })
// return
//}
func (s *gameRoleImpl) GetOnlineList(ctx context.Context, req *game.RoleOnlineReq) (res *game.RoleOnlineRes, err error) {
res = new(game.RoleOnlineRes)
ip := internal.ServerConfig[fmt.Sprint(req.ServerId)]
@ -110,12 +98,6 @@ func (s *gameRoleImpl) GetOnlineTopList(ctx context.Context, req *game.RoleOnlin
return
}
//func (s *gameRoleImpl) GetAccountList(ctx context.Context, req *game.AccountListReq) (res *game.AccountListRes, err error) {
// res = new(game.AccountListRes)
// res.Accounts, err = internal.GetAccountList(ctx, req.Ident, req.Name)
// return
//}
func (s *gameRoleImpl) GetAccount(ctx context.Context, req *game.AccountReq) (res *game.AccountRes, err error) {
res, err = internal.GetAccount(ctx, req)
return

9
internal/serviceGame/internal/basicinfo.go

@ -167,11 +167,6 @@ func GetRoleList(ctx context.Context, req *game.RoleSearchReq) (res *game.RoleSe
return res, err
}
func GetRoleDetail(ctx context.Context, uid int, server string) (roleDetail map[string]interface{}, err error) {
err = MongoDatabaseList[server].Collection("Unit").Find(ctx, bson.M{"UniqueId": uid}).One(&roleDetail)
return roleDetail, err
}
func DelRole(ctx context.Context, uid int64, server string) (roleDetail map[string]interface{}, err error) {
err = MongoDatabaseList[server].Collection("Unit").RemoveId(ctx, uid)
return roleDetail, err
@ -934,12 +929,12 @@ func GetShopItemLog(ctx context.Context, req *game.GetShopItemLogReq) (res *game
shopLogSql := fmt.Sprintf(`select u.account,s.itemId,s.num,s.price from game_shop_log s inner join game_unit u on s.uid=u.uid where 1=1`)
rechargeSql := fmt.Sprintf(`select DISTINCT u.account from game_recharge r inner join game_unit u on r.unitId=u.uid inner join game_register rr on rr.account=u.account where r.status=2`)
if req.LowTime != 0 {
start := time.Unix(req.LowTime, 0).Format(TIME_LAYOUT)
start := time.Unix(req.LowTime, 0).Format(consts.TIME_FORMAT)
rechargeSql += fmt.Sprintf(` and rr.create_time>%s`, start)
shopLogSql += fmt.Sprintf(` and s.c_date>%s`, start)
}
if req.Uptime != 0 {
end := time.Unix(req.Uptime, 0).Format(TIME_LAYOUT)
end := time.Unix(req.Uptime, 0).Format(consts.TIME_FORMAT)
rechargeSql = fmt.Sprintf(`%s and rr.create_time<%s`, rechargeSql, end)
shopLogSql = fmt.Sprintf(`%s and s.c_date<%s`, shopLogSql, end)
}

32
internal/serviceGame/internal/manage.go

@ -9,10 +9,10 @@ import (
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"strings"
"time"
"tyj_admin/api/v1/game"
"tyj_admin/internal/consts"
"tyj_admin/internal/dao"
"tyj_admin/internal/model/entity"
)
@ -138,9 +138,7 @@ func SetGmToClient(ctx context.Context, req *game.SetGmToClientReq) (res *game.S
g.Log().Info(ctx, "SendToGame - errdata2: ", url, errdata)
}
return
//return errors.New(errdata)
}
func ChangeGm(ctx context.Context, req *game.ChangeGmReq) (res *game.ChangeGmRes, err error) {
@ -179,24 +177,6 @@ func ChangePwd(ctx context.Context, account string, pwd string, server string) (
return
}
//func GetRegisterNum(ctx context.Context, lowTime int64, upTime int64, server string) (num int64, err error) {
// num, err = MongoDatabaseList[server].Collection("Account").Find(ctx, bson.M{"CreateTime": bson.M{"$lte": time.UnixMilli(upTime), "$gte": time.UnixMilli(lowTime)}}).Count()
// return
//}
func UpdateUnitP(ctx context.Context, uid int, unit primitive.A, server string) (err error) {
for _, v := range unit {
v1 := v.(map[string]interface{})
set := bson.M{}
set["C.$"] = v
err = MongoDatabaseList[server].Collection("Unit").UpdateOne(ctx, bson.M{"UniqueId": uid, "C._t": v1["_t"]}, bson.M{"$set": set})
}
return
}
const TIME_LAYOUT = "2006-01-02 15:04:05"
const DATE_LAYOUT = "2006-01-02"
/*
* 留存
*/
@ -205,7 +185,7 @@ func GetKeepAlive(ctx context.Context, req *game.GetKeepAliveReq) (res *game.Get
if req.CreateTime == "" {
return nil, gerror.New("请填写注册时间")
}
t, _ := time.ParseInLocation(TIME_LAYOUT, req.CreateTime+" 00:00:00", time.Local)
t, _ := time.ParseInLocation(consts.TIME_FORMAT, req.CreateTime+" 00:00:00", time.Local)
registersql := fmt.Sprintf("select account, server from game_register" +
" where 1=1 ")
@ -215,7 +195,7 @@ func GetKeepAlive(ctx context.Context, req *game.GetKeepAliveReq) (res *game.Get
if req.Channel != "" {
registersql += fmt.Sprintf(` and channel="%s"`, req.Channel)
}
registersql += fmt.Sprintf(` and STR_TO_DATE(create_time, "%%Y-%%m-%%d")="%s"`, t.Format(DATE_LAYOUT))
registersql += fmt.Sprintf(` and STR_TO_DATE(create_time, "%%Y-%%m-%%d")="%s"`, t.Format(consts.DATE_FORMAT))
if req.Keep == 2 {
registersql = fmt.Sprintf("select MAX( b.recharge ) AS `recharge`, b.account, MAX( b.server ) AS `server` from game_register as a inner join game_unit as b on a.account=b.account" +
" where b.recharge>0 ")
@ -225,7 +205,7 @@ func GetKeepAlive(ctx context.Context, req *game.GetKeepAliveReq) (res *game.Get
if req.Channel != "" {
registersql += fmt.Sprintf(` and b.channel="%s"`, req.Channel)
}
registersql += fmt.Sprintf(` and STR_TO_DATE(a.create_time, "%%Y-%%m-%%d")="%s"`, t.Format(DATE_LAYOUT))
registersql += fmt.Sprintf(` and STR_TO_DATE(a.create_time, "%%Y-%%m-%%d")="%s"`, t.Format(consts.DATE_FORMAT))
registersql += fmt.Sprintf(` group by b.account`)
}
@ -263,7 +243,7 @@ func GetLive(ctx context.Context, req *game.GetLiveReq) (res *game.GetLiveRes, e
return nil, gerror.New("请填写起始时间")
}
t, _ := time.ParseInLocation(TIME_LAYOUT, req.CreateTime+" 00:00:00", time.Local)
t, _ := time.ParseInLocation(consts.TIME_FORMAT, req.CreateTime+" 00:00:00", time.Local)
sql := fmt.Sprintf(`SELECT cd,COUNT(1) as num from (SELECT b.account, FROM_UNIXTIME( a.c_date, "%%Y-%%m-%%d" ) AS cd FROM login_out_log a INNER JOIN game_unit b ON ( a.uid = b.uid ) WHERE ( a.e_date - a.c_date > 60 ) AND ( a.c_date >= %d ) AND ( a.c_date < %d )`,
t.Unix(), t.AddDate(0, 0, 30).Unix())
if req.Server != 0 {
@ -316,7 +296,7 @@ func HighLogs(ctx context.Context, req *game.GetLiveReq) (res *game.GetLiveRes,
return nil, gerror.New("请填写起始时间")
}
t, _ := time.ParseInLocation(TIME_LAYOUT, req.CreateTime+" 00:00:00", time.Local)
t, _ := time.ParseInLocation(consts.TIME_FORMAT, req.CreateTime+" 00:00:00", time.Local)
HighSql := fmt.Sprintf(`SELECT max(num) AS num, STR_TO_DATE(date, "%%Y-%%m-%%d") AS cd FROM game_online WHERE UNIX_TIMESTAMP(date) >= %d AND UNIX_TIMESTAMP(date) < %d `,
t.Unix(), t.AddDate(0, 0, 30).Unix())
if req.Server != 0 {

6
internal/serviceGame/loginUrl.go

@ -99,6 +99,7 @@ func (c *gameLoginUrlImpl) AddLoginUrl(ctx context.Context, req *game.AddLoginUr
dao.GameLoginUrl.Columns().Port: req.Port,
dao.GameLoginUrl.Columns().State: req.State,
dao.GameLoginUrl.Columns().Recommend: req.Recommend,
dao.GameLoginUrl.Columns().IsNew: req.IsNew,
})
}
})
@ -163,11 +164,14 @@ func (c *gameLoginUrlImpl) GetGameLoginUrl(ctx context.Context, req *game.GetGam
}
channel += ";"
for _, v := range LoginUrlList {
if v.IsShow != 1 {
continue
}
if !strings.Contains(v.Channel, channel) {
continue
}
var data = game.LoginUrlData{Id: v.Id, Host: v.Host, Port: v.Port, Difficulty: v.Difficulty,
var data = game.LoginUrlData{Id: v.Id, Host: v.Host, Port: v.Port, Difficulty: v.Difficulty, IsNew: v.IsNew,
Recommend: v.Recommend, Name: v.Name, State: v.State, Area: v.Area, CreateTime: v.CDate.Unix()}
if data.State == consts.Login_URL_STATE_WHITE {
if utils.ContainsWhiteList(list, ip) || utils.ContainsWhiteList(list, req.Channel) {

610
internal/serviceGame/manage.go

@ -7,15 +7,11 @@ import (
"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"
"strings"
"time"
"tyj_admin/api/v1/game"
"tyj_admin/config"
"tyj_admin/internal/consts"
"tyj_admin/internal/model/entity"
"tyj_admin/internal/serviceGame/internal"
"tyj_admin/utils"
@ -28,7 +24,6 @@ type IGameManage interface {
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)
@ -77,536 +72,6 @@ func (ga *gameManageImpl) ChangeGm(ctx context.Context, req *game.ChangeGmReq) (
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.GetUnitByUid(ctx, int64(req.SrcName), req.SrcServer)
@ -632,7 +97,6 @@ func (ga *gameManageImpl) CopyUnit(ctx context.Context, req *game.CopyUnitReq) (
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) {
name := "mongoexport"
@ -666,50 +130,14 @@ func (ga *gameManageImpl) CopyUnit(ctx context.Context, req *game.CopyUnitReq) (
log.Printf("cmd.Run() args1 failed with %s\n", err)
return
}
//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.Println(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.Printf("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}\" --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}\" --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.Println(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
})
@ -846,39 +274,7 @@ func (ga *gameManageImpl) UpdateUnit(ctx context.Context, req *game.UpdateUnitRe
log.Printf("os.Remove failed with %s\n", err)
return
}
//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.Println(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.Printf("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.Println(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

Loading…
Cancel
Save