英雄属性、战力计算,新玩家初始化

This commit is contained in:
sk 2025-06-09 18:33:52 +08:00
parent ea2fca4572
commit b1bd0139c8
24 changed files with 654 additions and 398 deletions

View File

@ -123,11 +123,14 @@ const (
// TipExistedRoleName 已存在的角色名称
TipExistedRoleName StringTipError = "ExistedRoleName"
// TipLineupHeroNotSet 需要上级天赋满级
// TipLineupNotFound 找不到阵容
TipLineupNotFound StringTipError = "LineupNotFound"
// TipLineupHeroNotSet 阵容英雄未设置
TipLineupHeroNotSet StringTipError = "BattleHeroNotSet"
// TipLineupNotFound 需要上级天赋满级
TipLineupNotFound StringTipError = "LineupNotFound"
// TipLineupHeroHasSet 阵容英雄已设置
TipLineupHeroHasSet StringTipError = "LineupHeroHasSet"
// TipLineupsAlreadyMax 需要上级天赋满级
TipLineupsAlreadyMax StringTipError = "LineupsAlreadyMax"
@ -189,6 +192,9 @@ const (
// TipHeroNotFound 找不到英雄
TipHeroNotFound StringTipError = "HeroNotFound"
// TipRoleHeroCanNotUpgrade 主角不能升级
TipRoleHeroCanNotUpgrade StringTipError = "RoleHeroCanNotUpgrade"
// TipHeroBreakLevelAlreadyMax 英雄名将册已激活
TipHeroBreakLevelAlreadyMax StringTipError = "HeroBreakLevelAlreadyMax"

View File

@ -45,21 +45,18 @@ enum RolePropertyType {
//
RoleTitle = 5;
//
RoleLevel = 6;
//
LoginDays = 7;
LoginDays = 6;
//
PowerNextTime = 8;
PowerNextTime = 7;
}
//
enum MoneyType {
MoneyTypeNone = 0;
//
// ,
Exp = 1;
//
@ -174,7 +171,7 @@ enum EquipType {
enum TreasureType {
WarBook = 0;
WarToken = 2;
WarToken = 1;
}
enum CopyType {

View File

@ -74,7 +74,14 @@ message EquipChangeListAck {
//
message EquipUpgradeReq {
uint64 EquipUid = 1;
uint32 Levels = 2; // 1/5
uint32 Times = 2; // 1/5
}
// ModEquipRefine: 6014
//
message EquipRefineReq {
uint64 EquipUid = 1;
// uint32 Times = 2; // 1/5
}
message Treasure {

View File

@ -10,6 +10,7 @@ import "enums.proto";
// MsgId.ModRoleProperty: 2001
//
//
message RolePropertyAck {
//unchangeable
uint64 UserId = 1;
@ -28,9 +29,8 @@ message RolePropertyAck {
uint32 NamePrefix = 12;
uint32 NameTitle = 13;
uint32 RoleTitle = 14;
uint32 RoleLevel = 15;
uint32 LoginDays = 16;
int64 PowerNextTime = 17;
uint32 LoginDays = 15;
int64 PowerNextTime = 16;
}
// MsgId.ModRoleProperty: 2001
@ -113,12 +113,17 @@ message LineupHeroChangeReq {
uint64 HeroUid = 3;
}
// ModRoleLineupHeroChange: 2007
//
message LineupHeroChangeAck {
repeated LineupHero HeroList = 1;
}
// ModRoleBattleHeroPosition = 2008;
//
message LineupHeroPositionReq {
uint64 LineupUid = 1;
repeated uint32 IndexList = 2; //
repeated uint32 PositionList = 3; //
repeated uint32 PositionList = 3; // 6
}
// ModRoleBattleHeroEquip = 2009;
@ -126,7 +131,7 @@ message LineupHeroPositionReq {
message LineupHeroEquipReq {
uint64 LineupUid = 1;
uint32 Index = 2;
EquipType EquipType = 3; // Uid为0时不知道是什么类型的装备
EquipType EquipType = 3; // EquipUid为0时不知道是什么类型的装备
uint64 EquipUid = 4; // 0
}
@ -135,7 +140,7 @@ message LineupHeroEquipReq {
message LineupHeroTreasureReq {
uint64 LineupUid = 1;
uint32 Index = 2;
TreasureType TreasureType = 3; // Uid为0时不知道是什么类型的宝物
TreasureType TreasureType = 3; // TreasureUid为0时不知道是什么类型的宝物
uint64 TreasureUid = 4; // 0
}

View File

@ -212,11 +212,14 @@ enum MsgId {
//
ModItemEquipUpgrade = 6013;
//
ModItemEquipRefine = 6014;
//
ModItemTreasureList = 6014;
ModItemTreasureList = 6021;
//
ModItemTreasureChange = 6015;
ModItemTreasureChange = 6022;
//ModCounter begin -----------------------------------------------------------------------------------------------------------
//

View File

@ -28,6 +28,8 @@ type Tables struct {
Scene SceneTable
ServerConfig ServerConfigTable
Treasure TreasureTable
TreasureLevel TreasureLevelTable
UpgradeMaster UpgradeMasterTable
}
func NewTables(dataDir string) (*Tables, error) {

View File

@ -0,0 +1,60 @@
package data
import (
json "github.com/json-iterator/go"
"github.com/oylshe1314/framework/util"
)
type TreasureLevel struct {
Id int `json:"id"`
TreasureId int `json:"treasure_id"`
Level int `json:"level"`
NeedExp int `json:"need_exp"`
AttrType int `json:"attr_type"`
AttrValue int `json:"attr_value"`
}
type TreasureLevelTable struct {
l []*TreasureLevel
m1 map[int]*TreasureLevel
m2 map[int][]*TreasureLevel
m3 map[uint64]*TreasureLevel
}
func (this *TreasureLevelTable) load(buf []byte) error {
var err = json.Unmarshal(buf, &this.l)
if err != nil {
return err
}
this.m1 = make(map[int]*TreasureLevel)
this.m2 = make(map[int][]*TreasureLevel)
this.m3 = make(map[uint64]*TreasureLevel)
for i := range this.l {
this.m1[this.l[i].Id] = this.l[i]
this.m2[this.l[i].TreasureId] = append(this.m2[this.l[i].TreasureId], this.l[i])
this.m3[util.Compose2uint32(uint32(this.l[i].TreasureId), uint32(this.l[i].Level))] = this.l[i]
}
return nil
}
func (this *TreasureLevelTable) List() []*TreasureLevel {
return this.l
}
func (this *TreasureLevelTable) Get(i int) *TreasureLevel {
return this.l[i]
}
func (this *TreasureLevelTable) Find1(id int) *TreasureLevel {
return this.m1[id]
}
func (this *TreasureLevelTable) Find2(treasureId int) []*TreasureLevel {
return this.m2[treasureId]
}
func (this *TreasureLevelTable) Find3(treasureId, level int) *TreasureLevel {
return this.m3[util.Compose2uint32(uint32(treasureId), uint32(level))]
}

View File

@ -0,0 +1,47 @@
package data
import (
json "github.com/json-iterator/go"
"github.com/oylshe1314/framework/util"
)
type UpgradeMaster struct {
Id int `json:"id"`
Type int `json:"type"`
Level int `json:"level"`
NeedLevel int `json:"need_level"`
AttrType1 int `json:"attr_type1"`
AttrValue1 int `json:"attr_value1"`
AttrType2 int `json:"attr_type2"`
AttrValue2 int `json:"attr_value2"`
AttrType3 int `json:"attr_type3"`
AttrValue3 int `json:"attr_value3"`
AttrType4 int `json:"attr_type4"`
AttrValue4 int `json:"attr_value4"`
AttrType5 int `json:"attr_type5"`
AttrValue5 int `json:"attr_value5"`
AttrType6 int `json:"attr_type6"`
AttrValue6 int `json:"attr_value6"`
}
type UpgradeMasterTable struct {
l []*UpgradeMaster
m1 map[int][]*UpgradeMaster
m2 map[uint64]*UpgradeMaster
}
func (this *UpgradeMasterTable) load(buf []byte) error {
var err = json.Unmarshal(buf, &this.l)
if err != nil {
return err
}
this.m1 = make(map[int][]*UpgradeMaster)
this.m2 = make(map[uint64]*UpgradeMaster)
for i := range this.l {
this.m1[this.l[i].Type] = append(this.m1[this.l[i].Type], this.l[i])
this.m2[util.Compose2uint32(uint32(this.l[i].Type), uint32(this.l[i].Level))] = this.l[i]
}
return nil
}

View File

@ -17,10 +17,17 @@ func (this *PlayerHandler) HeroUpgrade(player *logic.Player, msg *net.Message) {
}
if req.HeroUid == 0 {
this.logger.Error("Parameter error, req.HeroUid == 0")
_ = player.TipNotice(proto.TipParameterError)
return
}
if req.HeroUid == player.RoleHero.Uid {
this.logger.Error("Parameter error, Role hero can not upgrade here, req.HeroUid: ", req.HeroUid)
_ = player.TipNotice(proto.TipRoleHeroCanNotUpgrade)
return
}
if req.Levels != 1 && req.Levels != 5 {
_ = player.TipNotice(proto.TipParameterError)
return

View File

@ -38,11 +38,13 @@ func (this *PlayerHandler) EquipUpgrade(player *logic.Player, msg *net.Message)
}
if req.EquipUid == 0 {
this.logger.Error("Parameter error, req.EquipUid == 0")
_ = player.TipNotice(proto.TipParameterError)
return
}
if req.Levels != 1 && req.Levels != 5 {
if req.Times != 1 && req.Times != 5 {
this.logger.Error("Parameter error, req.Level: ", req.Times)
_ = player.TipNotice(proto.TipParameterError)
return
}
@ -68,7 +70,7 @@ func (this *PlayerHandler) EquipUpgrade(player *logic.Player, msg *net.Message)
var consumeItems = map[uint32]uint32{}
levelLoop:
for range req.Levels {
for range req.Times {
var equipLevelTable = this.tables.EquipLevel.Find3(int(equip.Id), int(equip.Level))
if equipLevelTable == nil {
_ = player.TipNotice(proto.TipDataTablesError)
@ -99,3 +101,20 @@ levelLoop:
})
return
}
func (this *PlayerHandler) EquipRefine(player *logic.Player, msg *net.Message) {
var req = new(pb.EquipUpgradeReq)
var err = msg.Read(req)
if err != nil {
this.logger.Error("Read message failed, ", err)
_ = player.TipNotice(proto.TipMessageError)
return
}
if req.EquipUid == 0 {
this.logger.Error("Parameter error, req.EquipUid == 0")
_ = player.TipNotice(proto.TipParameterError)
return
}
}

View File

@ -82,23 +82,16 @@ func (this *PlayerHandler) RolePropertyChange(player *logic.Player, msg *net.Mes
}
switch req.Property.Type {
case pb.RolePropertyType_AvatarFrame:
player.AvatarFrame = uint32(req.Property.Value)
case pb.RolePropertyType_ChatBubble:
player.ChatBubble = uint32(req.Property.Value)
case pb.RolePropertyType_NamePrefix:
player.NamePrefix = uint32(req.Property.Value)
case pb.RolePropertyType_NameTitle:
player.NameTitle = uint32(req.Property.Value)
case pb.RolePropertyType_RoleTitle:
player.RoleTitle = uint32(req.Property.Value)
case pb.RolePropertyType_AvatarFrame,
pb.RolePropertyType_ChatBubble,
pb.RolePropertyType_NamePrefix,
pb.RolePropertyType_NameTitle,
pb.RolePropertyType_RoleTitle:
player.ChangeProperty(util.NewPair(req.Property.Type, req.Property.Value))
default:
this.logger.Error("Parameter error, req.Property.Type: ", req.Property.Type)
_ = player.TipNotice(proto.TipParameterError)
}
_ = player.Send(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRolePropertyChange), &pb.RolePropertyChangeAck{
PropertyList: []*pb.RoleProperty{req.Property},
})
return
}
@ -111,6 +104,12 @@ func (this *PlayerHandler) LineupHeroChange(player *logic.Player, msg *net.Messa
return
}
if req.LineupUid == 0 {
this.logger.Error("Parameter error, req.LineupUid: ", req.LineupUid)
_ = player.TipNotice(proto.TipParameterError)
return
}
if req.Index >= 8 {
this.logger.Error("Parameter error, req.Index: ", req.Index)
_ = player.TipNotice(proto.TipParameterError)
@ -128,30 +127,60 @@ func (this *PlayerHandler) LineupHeroChange(player *logic.Player, msg *net.Messa
return
}
var lineup = player.Lineup[req.LineupUid]
if lineup == nil {
this.logger.Error("Parameter error, Lineup not found, req.LineupUid: ", req.LineupUid)
_ = player.TipNotice(proto.TipLineupNotFound)
return
}
var hero = player.Hero[req.HeroUid]
if hero == nil {
this.logger.Error("Parameter error, Lineup not found, req.LineupUid: ", req.LineupUid)
_ = player.TipNotice(proto.TipHeroNotFound)
return
}
var LineupHero = player.LineupHeroes[req.Index]
if LineupHero == nil {
LineupHero = &logic.PlayerLineupHero{
var setups [7]bool
for i := 0; i < 8; i++ {
if lineup.Heroes[i] != nil && hero.Uid == lineup.Heroes[i].HeroUid {
this.logger.Errorf("The hero has set into the lineup, hero.Uid: %d, index: %d", hero.Uid, i)
_ = player.TipNotice(proto.TipLineupHeroHasSet)
return
}
if i < 6 {
if lineup.Heroes[i].Position > 0 {
setups[lineup.Heroes[i].Position] = true
}
}
}
var lineupHero = lineup.Heroes[req.Index]
if lineupHero == nil {
lineupHero = &logic.PlayerLineupHero{
HeroUid: hero.Uid,
}
player.LineupHeroes[req.Index] = LineupHero
} else {
LineupHero.HeroUid = hero.Uid
for position := 1; position < 7; position++ {
if !setups[position] {
lineupHero.Position = uint32(position)
}
}
player.SaveArray("lineup_heroes", int(req.Index), LineupHero)
lineup.Heroes[req.Index] = lineupHero
} else {
lineupHero.HeroUid = hero.Uid
}
player.SaveArray("lineup.heroes", int(req.Index), lineupHero)
player.UpdateHeroAttrs(hero)
//TODO lineup hero capacity
//_ = player.Send(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleLineupHeroChange), &pb.LineupHeroListAck{
// HeroList: []*pb.LineupHero{LineupHero.BuildMsgLineupHero(req.Index)},
//})
_ = player.Send(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleLineupHeroChange), &pb.LineupHeroChangeAck{
HeroList: []*pb.LineupHero{lineupHero.BuildMsgLineupHero(req.Index)},
})
}
func (this *PlayerHandler) LineupHeroPosition(player *logic.Player, msg *net.Message) {
@ -163,39 +192,54 @@ func (this *PlayerHandler) LineupHeroPosition(player *logic.Player, msg *net.Mes
return
}
if len(req.IndexList) != len(req.PositionList) {
this.logger.Errorf("Read message failed, len(req.IndexList) = %d, len(req.PositionList) = %d", len(req.IndexList), len(req.PositionList))
_ = player.TipNotice(proto.TipMessageError)
return
}
for i := range req.IndexList {
if req.IndexList[i] >= 6 {
this.logger.Errorf("Parameter error, req.IndexList[%d]: %d", i, req.IndexList[i])
if len(req.PositionList) != 6 {
this.logger.Errorf("Parameter error, len(req.IndexList) != 6, len(req.IndexList) = %d", len(req.PositionList))
_ = player.TipNotice(proto.TipParameterError)
return
}
if req.PositionList[i] > 6 {
var lineup = player.Lineup[req.LineupUid]
if lineup == nil {
this.logger.Error("Parameter error, Lineup not found, req.LineupUid: ", req.LineupUid)
_ = player.TipNotice(proto.TipLineupNotFound)
return
}
var setups [7]bool
for i := range req.PositionList {
if req.PositionList[i] < 1 || req.PositionList[i] > 6 {
this.logger.Errorf("Parameter error, req.PositionList[%d]: %d", i, req.PositionList[i])
_ = player.TipNotice(proto.TipParameterError)
return
}
if setups[req.PositionList[i]] {
this.logger.Errorf("Parameter error, repeated hero battle position, position: %d, index: %d", req.PositionList[i], i)
_ = player.TipNotice(proto.TipParameterError)
return
}
setups[req.PositionList[i]] = true
}
var lineupHeroList []*pb.LineupHero
for i := range req.IndexList {
var lineupHero = player.LineupHeroes[req.IndexList[i]]
if lineupHero != nil {
if lineupHero.Position != req.PositionList[i] {
lineupHero.Position = req.PositionList[i]
player.SaveArray("lineup_heroes", int(req.IndexList[i]), lineupHero)
lineupHeroList = append(lineupHeroList, lineupHero.BuildMsgLineupHero(req.IndexList[i]))
}
}
for i, lineupHero := range lineup.Heroes {
if i > 5 {
break
}
if lineupHero == nil {
continue
}
lineupHero.Position = req.PositionList[i]
lineupHeroList = append(lineupHeroList, lineupHero.BuildMsgLineupHero(uint32(i)))
}
player.SaveField("lineup.heroes", lineup.Heroes)
if len(lineupHeroList) > 0 {
//_ = player.Send(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleLineupHeroChange), &pb.LineupHeroListAck{HeroList: lineupHeroList})
_ = player.Send(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleLineupHeroChange), &pb.LineupHeroChangeAck{HeroList: lineupHeroList})
}
}
@ -208,6 +252,12 @@ func (this *PlayerHandler) LineupHeroEquip(player *logic.Player, msg *net.Messag
return
}
if req.LineupUid == 0 {
this.logger.Error("Parameter error, req.LineupUid: ", req.LineupUid)
_ = player.TipNotice(proto.TipParameterError)
return
}
if req.Index >= 8 {
this.logger.Error("Parameter error, req.Index: ", req.Index)
_ = player.TipNotice(proto.TipParameterError)
@ -225,15 +275,16 @@ func (this *PlayerHandler) LineupHeroEquip(player *logic.Player, msg *net.Messag
return
}
var LineupHero = player.LineupHeroes[req.Index]
if LineupHero == nil {
_ = player.TipNotice(proto.TipLineupHeroNotSet)
var lineup = player.Lineup[req.LineupUid]
if lineup == nil {
this.logger.Error("Parameter error, Lineup not found, req.LineupUid: ", req.LineupUid)
_ = player.TipNotice(proto.TipLineupNotFound)
return
}
var hero = player.Hero[LineupHero.HeroUid]
if hero == nil {
_ = player.TipNotice(proto.TipHeroNotFound)
var lineupHero = lineup.Heroes[req.Index]
if lineupHero == nil {
_ = player.TipNotice(proto.TipLineupHeroNotSet)
return
}
@ -257,13 +308,11 @@ func (this *PlayerHandler) LineupHeroEquip(player *logic.Player, msg *net.Messag
}
}
var equipIndex = int(req.EquipType)
var LineupHeroList []*pb.LineupHero
var lineupHeroList []*pb.LineupHero
var equipChangeList []*pb.EquipChange
if LineupHero.Equip[equipIndex] != 0 {
var preEquip = player.Equip[LineupHero.Equip[equipIndex]]
if lineupHero.Equip[req.EquipType] != 0 {
var preEquip = player.Equip[lineupHero.Equip[req.EquipType]]
if preEquip != nil && preEquip.HeroUid != 0 {
preEquip.HeroUid = 0
player.SaveModel(preEquip)
@ -274,25 +323,25 @@ func (this *PlayerHandler) LineupHeroEquip(player *logic.Player, msg *net.Messag
}
}
LineupHero.Equip[equipIndex] = req.EquipUid
player.SaveArray("lineup_heroes", int(req.Index), LineupHero)
LineupHeroList = append(LineupHeroList, LineupHero.BuildMsgLineupHero(req.Index))
lineupHero.Equip[req.EquipType] = req.EquipUid
player.SaveArray("lineup.heroes", int(req.Index), lineupHero)
lineupHeroList = append(lineupHeroList, lineupHero.BuildMsgLineupHero(req.Index))
if equip != nil {
if equip.HeroUid != 0 {
for i := range player.LineupHeroes {
if player.LineupHeroes[i].HeroUid == equip.HeroUid {
var preLineupHero = player.LineupHeroes[i]
if preLineupHero.Equip[equipIndex] != 0 {
preLineupHero.Equip[equipIndex] = 0
player.SaveArray("lineup_heroes", i, preLineupHero)
LineupHeroList = append(LineupHeroList, preLineupHero.BuildMsgLineupHero(uint32(i)))
for i := range lineup.Heroes {
if lineup.Heroes[i].HeroUid == equip.HeroUid {
var preLineupHero = lineup.Heroes[i]
if preLineupHero.Equip[req.EquipType] != 0 {
preLineupHero.Equip[req.EquipType] = 0
player.SaveArray("lineup.heroes", i, preLineupHero)
lineupHeroList = append(lineupHeroList, preLineupHero.BuildMsgLineupHero(uint32(i)))
}
}
}
}
equip.HeroUid = LineupHero.HeroUid
equip.HeroUid = lineupHero.HeroUid
player.SaveModel(equip)
equipChangeList = append(equipChangeList, &pb.EquipChange{
ChangeType: pb.ChangeType_Changed,
@ -300,7 +349,7 @@ func (this *PlayerHandler) LineupHeroEquip(player *logic.Player, msg *net.Messag
})
}
//_ = player.Send(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleLineupHeroChange), &pb.LineupHeroListAck{HeroList: LineupHeroList})
_ = player.Send(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleLineupHeroChange), &pb.LineupHeroChangeAck{HeroList: lineupHeroList})
_ = player.Send(uint16(pb.ModId_ModuleItem), uint16(pb.MsgId_ModItemEquipChange), &pb.EquipChangeListAck{ChangeList: equipChangeList})
return
}
@ -314,6 +363,12 @@ func (this *PlayerHandler) LineupHeroTreasure(player *logic.Player, msg *net.Mes
return
}
if req.LineupUid == 0 {
this.logger.Error("Parameter error, req.LineupUid: ", req.LineupUid)
_ = player.TipNotice(proto.TipParameterError)
return
}
if req.Index >= 8 {
this.logger.Error("Parameter error, req.Index: ", req.Index)
_ = player.TipNotice(proto.TipParameterError)
@ -331,15 +386,16 @@ func (this *PlayerHandler) LineupHeroTreasure(player *logic.Player, msg *net.Mes
return
}
var LineupHero = player.LineupHeroes[req.Index]
if LineupHero == nil {
_ = player.TipNotice(proto.TipLineupHeroNotSet)
var lineup = player.Lineup[req.LineupUid]
if lineup == nil {
this.logger.Error("Parameter error, Lineup not found, req.LineupUid: ", req.LineupUid)
_ = player.TipNotice(proto.TipLineupNotFound)
return
}
var hero = player.Hero[LineupHero.HeroUid]
if hero == nil {
_ = player.TipNotice(proto.TipHeroNotFound)
var lineupHero = lineup.Heroes[req.Index]
if lineupHero == nil {
_ = player.TipNotice(proto.TipLineupHeroNotSet)
return
}
@ -351,63 +407,61 @@ func (this *PlayerHandler) LineupHeroTreasure(player *logic.Player, msg *net.Mes
return
}
var treasureTable = this.tables.Treasure.Find(int(treasure.Id))
if treasureTable == nil {
var equipTable = this.tables.Treasure.Find(int(treasure.Id))
if equipTable == nil {
_ = player.TipNotice(proto.TipDataTablesError)
return
}
if req.TreasureType != pb.TreasureType(treasureTable.Type) {
if req.TreasureType != pb.TreasureType(equipTable.Type) {
_ = player.TipNotice(proto.TipParameterError)
return
}
}
var treasureIndex = int(req.TreasureType)
var lineupHeroList []*pb.LineupHero
var equipChangeList []*pb.TreasureChange
var LineupHeroList []*pb.LineupHero
var treasureChangeList []*pb.TreasureChange
if LineupHero.Treasure[treasureIndex] != 0 {
var preTreasure = player.Treasure[LineupHero.Treasure[treasureIndex]]
if lineupHero.Treasure[req.TreasureType] != 0 {
var preTreasure = player.Treasure[lineupHero.Treasure[req.TreasureType]]
if preTreasure != nil && preTreasure.HeroUid != 0 {
preTreasure.HeroUid = 0
player.SaveModel(preTreasure)
treasureChangeList = append(treasureChangeList, &pb.TreasureChange{
equipChangeList = append(equipChangeList, &pb.TreasureChange{
ChangeType: pb.ChangeType_Changed,
Treasure: preTreasure.BuildMsgTreasure(),
})
}
}
LineupHero.Treasure[treasureIndex] = req.TreasureUid
player.SaveArray("lineup_heroes", int(req.Index), LineupHero)
LineupHeroList = append(LineupHeroList, LineupHero.BuildMsgLineupHero(req.Index))
lineupHero.Treasure[req.TreasureType] = req.TreasureUid
player.SaveArray("lineup.heroes", int(req.Index), lineupHero)
lineupHeroList = append(lineupHeroList, lineupHero.BuildMsgLineupHero(req.Index))
if treasure != nil {
if treasure.HeroUid != 0 {
for i := range player.LineupHeroes {
if player.LineupHeroes[i].HeroUid == treasure.HeroUid {
var preLineupHero = player.LineupHeroes[i]
if preLineupHero.Treasure[treasureIndex] != 0 {
preLineupHero.Treasure[treasureIndex] = 0
player.SaveArray("lineup_heroes", i, preLineupHero)
LineupHeroList = append(LineupHeroList, preLineupHero.BuildMsgLineupHero(uint32(i)))
for i := range lineup.Heroes {
if lineup.Heroes[i].HeroUid == treasure.HeroUid {
var preLineupHero = lineup.Heroes[i]
if preLineupHero.Treasure[req.TreasureType] != 0 {
preLineupHero.Treasure[req.TreasureType] = 0
player.SaveArray("lineup.heroes", i, preLineupHero)
lineupHeroList = append(lineupHeroList, preLineupHero.BuildMsgLineupHero(uint32(i)))
}
}
}
}
treasure.HeroUid = LineupHero.HeroUid
treasure.HeroUid = lineupHero.HeroUid
player.SaveModel(treasure)
treasureChangeList = append(treasureChangeList, &pb.TreasureChange{
equipChangeList = append(equipChangeList, &pb.TreasureChange{
ChangeType: pb.ChangeType_Changed,
Treasure: treasure.BuildMsgTreasure(),
})
}
//_ = player.Send(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleLineupHeroChange), &pb.LineupHeroListAck{HeroList: LineupHeroList})
_ = player.Send(uint16(pb.ModId_ModuleItem), uint16(pb.MsgId_ModItemTreasureChange), &pb.TreasureChangeListAck{ChangeList: treasureChangeList})
_ = player.Send(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleLineupHeroChange), &pb.LineupHeroChangeAck{HeroList: lineupHeroList})
_ = player.Send(uint16(pb.ModId_ModuleItem), uint16(pb.MsgId_ModItemTreasureChange), &pb.TreasureChangeListAck{ChangeList: equipChangeList})
return
}

View File

@ -36,6 +36,7 @@ type Player struct {
NamePrefix uint32 `bson:"name_prefix"`
NameTitle uint32 `bson:"name_title"`
RoleTitle uint32 `bson:"role_title"`
RoleExp uint64 `bson:"role_exp"`
RoleLevel uint32 `bson:"role_level"`
//Fields
@ -51,21 +52,19 @@ type Player struct {
//CopyMainSceneId uint32 `bson:"copy_main_scene_id"`
//BattlePassSeason uint32 `bson:"battle_pass_season"`
//Arrays
LineupHeroes [8]*PlayerLineupHero `bson:"lineup_heroes"`
//Fields
RoleHero *PlayerHero `bson:"role_hero"`
//LoginReward *PlayerLoginReward `bson:"login_reward"`
//IdleBattle *PlayerIdleBattle `bson:"idle_battle"`
//Arena *PlayerArena `bson:"arena"`
//
////Arrays
//BattlePassReward []*PlayerBattlePassRewrad `bson:"battle_pass_reward"`
//BattlePassReward []*PlayerBattlePassReward `bson:"battle_pass_reward"`
//
////Models
//Achievement map[uint64]*PlayerAchievement `bson:"achievement"`
//BattlePass map[uint32]*PlayerBattlePass `bson:"battle_pass"`
//Cdkey map[string]*PlayerCdkey `bson:"cdkey"`
//CdKey map[string]*PlayerCdKey `bson:"cd_key"`
CopyPassed map[uint32]*PlayerCopyPassed `bson:"copy_passed"`
//CopySpeed map[uint32]*PlayerCopySpeed `bson:"copy_speed"`
CopyStatus map[uint64]*PlayerCopyStatus `bson:"copy_status"`
@ -77,7 +76,7 @@ type Player struct {
Equip map[uint64]*PlayerEquip `bson:"rig_equip"`
//GiftPack map[uint32]*PlayerGiftPack `bson:"gift_pack"`
//Mail map[uint64]*PlayerMail `bson:"mail"`
Lineup map[uint64]*PlayerLineup `bson:"lineups"`
Lineup map[uint64]*PlayerLineup `bson:"lineup"`
Money map[uint32]*PlayerMoney `bson:"money"`
//MonthlyCard map[uint32]*PlayerMonthlyCard `bson:"monthly_card"`
//Planet map[uint32]*PlayerPlanet `bson:"planet"`
@ -152,11 +151,11 @@ func (this *Player) sync() {
//_ = this.Send(proto.ModIdLevel, proto.MsgIdPlanetList, this.BuildMsgPlanetListAck())
//_ = this.Send(proto.ModIdLevel, proto.MsgIdPlanetRawStoneStatus, this.BuildMsgPlanetRawStoneStatusListAck())
//_ = this.Send(proto.ModIdLevel, proto.MsgIdCopyArenaStatus, this.BuildMsgCopyArenaStatusAck())
//
////Battle module
//_ = this.Send(proto.ModIdBattle, proto.MsgIdIdleBattleStatus, this.BuildMsgIdleBattleStatusAck())
//
////Hero module
//Hero module
_ = this.Send(uint16(pb.ModId_ModuleHero), uint16(pb.MsgId_ModHeroList), this.BuildMsgHeroListAck())
_ = this.Send(uint16(pb.ModId_ModuleHero), uint16(pb.MsgId_ModHeroBookList), this.BuildMsgHeroBookListAck())
//_ = this.Send(proto.ModIdRig, proto.MsgIdRigComponentList, this.BuildMsgRigComponentListAck())
@ -169,30 +168,32 @@ func (this *Player) sync() {
//_ = this.Send(proto.ModIdRig, proto.MsgIdRigCoreList, this.BuildMsgRigCoreListAck())
//_ = this.Send(proto.ModIdRig, proto.MsgIdRigTrammelsList, this.BuildMsgRigTrammelsListAck())
//_ = this.Send(proto.ModIdRig, proto.MsgIdRigWarshipList, this.BuildMsgWarshipListAck())
//
//Item module
_ = this.Send(uint16(pb.ModId_ModuleItem), uint16(pb.MsgId_ModItemList), this.BuildMsgItemListAck())
_ = this.Send(uint16(pb.ModId_ModuleItem), uint16(pb.MsgId_ModItemEquipList), this.BuildMsgEquipListAck())
_ = this.Send(uint16(pb.ModId_ModuleItem), uint16(pb.MsgId_ModItemTreasureList), this.BuildMsgTreasureListAck())
//Counter module
_ = this.Send(uint16(pb.ModId_ModuleCounter), uint16(pb.MsgId_ModCounterList), this.BuildMsgCounterListAck())
////Mail module
//_ = this.Send(proto.ModIdMail, proto.MsgIdMailList, this.BuildMsgMailListAck())
//
////Counter module
//_ = this.Send(proto.ModIdCounter, proto.MsgIdCounterList, this.BuildMsgCounterListAck())
//
////Item module
//_ = this.Send(proto.ModIdItem, proto.MsgIdPackItemList, this.BuildMsgPackItemListAck())
//
////Achievement module
//_ = this.Send(proto.ModIdAchievement, proto.MsgIdAchievementList, this.BuildMsgAchievementListAck())
//
////Task module
//_ = this.Send(proto.ModIdTask, proto.MsgIdTaskList, this.BuildMsgTaskListAck())
//_ = this.Send(proto.ModIdTask, proto.MsgIdActiveInfo, this.BuildMsgActiveInfoAck())
//
////Store module
//_ = this.Send(proto.ModIdStore, proto.MsgIdStorePoolList, this.BuildMsgStorePoolListAck())
//_ = this.Send(proto.ModIdStore, proto.MsgIdMonthlyCardList, this.BuildMsgMonthlyCardListAck())
//_ = this.Send(proto.ModIdStore, proto.MsgIdBattlePassInfo, this.BuildMsgBattlePassInfoAck())
//_ = this.Send(proto.ModIdStore, proto.MsgIdBattlePassRewardStatusList, this.BuildMsgBattlePassRewardListAck())
//_ = this.Send(proto.ModIdStore, proto.MsgIdLimitGiftPackList, this.BuildMsgLimitGiftPackListAck())
//
////Activity module
//_ = this.Send(proto.ModIdActivity, proto.MsgIdLoginRewardInfo, this.BuildMsgLoginRewardInfoAck())
}

View File

@ -4,12 +4,12 @@ import (
"ecs/proto"
"ecs/proto/pb"
"ecs/servers/game/data"
"math/rand/v2"
"github.com/oylshe1314/framework/util"
)
func (this *Player) EnterBattle(sceneTable *data.Scene) {
this.Temp.Fighting = true
this.Temp.RandSeed = rand.Int64()
this.Temp.RandSeed = util.DefaultRandom.Uint64()
this.copyBattle(sceneTable)
this.enterScene(uint32(sceneTable.Id))

View File

@ -1,6 +1,6 @@
package logic
//type PlayerCdkey struct {
//type PlayerCdKey struct {
// Key string `bson:"key" key:"1"`
// ExchangeTime int64 `bson:"exchange_time"`
//}

View File

@ -2,6 +2,7 @@ package logic
import (
"ecs/proto/pb"
"github.com/oylshe1314/framework/util"
)
func (this *Player) checkCorrect(firstLogin bool, cur *GameTime) {
@ -165,19 +166,19 @@ func (this *Player) initRole(cur *GameTime) {
return
}
_ = this.addHero(heroTable)
var roleHero = this.newHero(heroTable)
if roleHero == nil {
return
}
this.RoleHero = roleHero
this.SaveField("role_hero", this.RoleHero)
}
func (this *Player) initHeroes(cur *GameTime) {
var initHeroIds = this.manager.tables.ServerConfig.GetInitHeroes()
for _, initHeroId := range initHeroIds {
var heroTable = this.manager.tables.Hero.Find(initHeroId)
if heroTable == nil {
this.manager.logger.Error("find hero table failed, initHeroId: ", initHeroId)
return
}
_ = this.addHero(heroTable)
this.AddHero(uint32(initHeroId))
}
}
@ -196,92 +197,45 @@ func (this *Player) initItems(cur *GameTime) {
}
}
//
// func (this *Player) initComponents(cur *GameTime) {
// var cfgTable = this.manager.tables.ServerCfg.Get("init_components")
// if cfgTable == nil {
// return
// }
//
// itemPairs, err := util.SplitItemPairs(cfgTable.Value1, cfgTable.Value2, 1)
// if err != nil {
// return
// }
//
// for _, itemPair := range itemPairs {
// var componentTable = this.manager.tables.RigComponentExtend.Get(int(itemPair[0]), 1)
// if componentTable == nil {
// continue
// }
//
// var componentStarTable = this.manager.tables.RigComponentStarExtend.Get(int(itemPair[0]), 0)
// if componentStarTable == nil {
// continue
// }
//
// var component = &PlayerRigComponent{
// ItemId: uint32(componentTable.ItemId),
// Id: uint32(componentTable.Id),
// StarId: uint32(componentStarTable.Id),
// Type: uint32(componentTable.Type),
// Setup: true,
// }
//
// this.RigComponent[component.ItemId] = component
//
// switch proto.EquipType(component.Type) {
// case proto.EquipTypeHead:
// this.Rig.Head = component.ItemId
// this.SaveField("rig.head", this.Rig.Head)
// case proto.EquipTypeBody:
// this.Rig.Body = component.ItemId
// this.SaveField("rig.body", this.Rig.Body)
// case proto.EquipTypeTail:
// this.Rig.Tail = component.ItemId
// this.SaveField("rig.tail", this.Rig.Tail)
// }
//
// this.SaveModel(component)
//
// this.CheckAchievement(proto.AchievementTypeComponents, 0, 1)
// }
// }
//
// func (this *Player) initCharacters(cur *GameTime) {
// var cfgTable = this.manager.tables.ServerCfg.Get("init_characters")
// if cfgTable == nil {
// return
// }
//
// itemPairs, err := util.SplitItemPairs(cfgTable.Value1, cfgTable.Value2, 1)
// if err != nil {
// return
// }
//
// var characterCount = 0
// var teams proto.Teams
// for _, itemPair := range itemPairs {
// var characterTable = this.manager.tables.RigCharacterExtend.Get(int(itemPair[0]), 1)
// if characterTable != nil {
// var characterStarTable = this.manager.tables.RigCharacterStarExtend.Get(int(itemPair[0]), 0)
// if characterStarTable != nil {
// var character = this.AddRigCharacter(characterTable, characterStarTable)
// if character != nil {
// if characterCount%proto.TeamNum == 0 {
// teams = append(teams, proto.Team{})
// }
// teams[len(teams)-1][characterCount%proto.TeamNum] = character.ItemId
// characterCount += 1
// }
// }
// }
// }
// if len(teams) > 0 {
// this.Rig.Teams = teams
// this.SaveField("rig.teams", this.Rig.Teams)
// }
// }
//
func (this *Player) initLineup(cur *GameTime) {
var roleHero = this.RoleHero
if roleHero == nil {
return
}
var lineup = &PlayerLineup{
Uid: util.RandomUid(),
Name: "阵容1",
Active: true,
}
var roleLineupHero = &PlayerLineupHero{
HeroUid: roleHero.Uid,
Position: 1,
}
this.updateHeroAttrs(roleHero, lineup, roleLineupHero)
this.UpdateBattleHeroCapacity(roleLineupHero)
lineup.Heroes[0] = roleLineupHero
var i = uint32(1)
for _, hero := range this.Hero {
var lineupHero = &PlayerLineupHero{
HeroUid: hero.Uid,
Position: i + 1,
}
this.updateHeroAttrs(hero, lineup, lineupHero)
this.UpdateBattleHeroCapacity(lineupHero)
lineup.Heroes[i] = lineupHero
}
this.Lineup[lineup.Uid] = lineup
this.SaveModel(lineup)
}
// func (this *Player) initMails(cur *GameTime) {
// var cfgTable = this.manager.tables.ServerCfg.Get("init_mails")
// if cfgTable == nil {
@ -326,8 +280,7 @@ func (this *Player) checkCorrectFirstLogin(cur *GameTime) {
this.initRole(cur)
this.initHeroes(cur)
//this.initItems(cur)
//this.initComponents(cur)
//this.initCharacters(cur)
this.initLineup(cur)
//this.initMails(cur)
//this.initTasks(cur)
this.initPower(cur)
@ -336,7 +289,7 @@ func (this *Player) checkCorrectFirstLogin(cur *GameTime) {
func (this *Player) checkCorrectMemoryData(cur *GameTime) {
this.initTemp()
for _, hero := range this.Hero {
this.updateHeroAttrs(hero)
this.UpdateHeroAttrs(hero)
}
}

View File

@ -142,7 +142,7 @@ func (this *Player) AddEquips(equipId, nums uint32, logType LogType) {
// this.UpdateRigAttrs()
//}
func (this *Player) BuildMsgRigEquipListAck() *pb.EquipListAck {
func (this *Player) BuildMsgEquipListAck() *pb.EquipListAck {
var list []*pb.Equip
for _, equip := range this.Equip {
list = append(list, equip.BuildMsgEquip())

View File

@ -4,6 +4,7 @@ import (
"ecs/proto/pb"
"ecs/servers/game/data"
"github.com/oylshe1314/framework/util"
"slices"
)
type Attrs [pb.AttrType_Nums]uint64
@ -39,7 +40,7 @@ func (this *PlayerHero) Attrs() Attrs {
return this.attrs
}
func (this *Player) addHero(heroTable *data.Hero) bool {
func (this *Player) newHero(heroTable *data.Hero) *PlayerHero {
var hero = &PlayerHero{
Uid: util.RandomUid(),
Id: uint32(heroTable.Id),
@ -50,7 +51,7 @@ func (this *Player) addHero(heroTable *data.Hero) bool {
heroLevelTable = this.manager.tables.HeroLevel.Find3(heroTable.Id, 1)
if heroLevelTable == nil {
this.manager.logger.Errorf("Find hero level table failed, heroId %d, level: %d", heroTable.Id, 1)
return false
return nil
}
hero.Level = uint32(heroLevelTable.Level)
}
@ -60,7 +61,7 @@ func (this *Player) addHero(heroTable *data.Hero) bool {
heroBreakTable = this.manager.tables.HeroBreak.Find3(heroTable.Id, 0)
if heroBreakTable == nil {
this.manager.logger.Errorf("Find hero break table failed, heroId %d, level: %d", heroTable.Id, 1)
return false
return nil
}
hero.BreakLevel = uint32(heroBreakTable.BreakLevel)
}
@ -69,11 +70,7 @@ func (this *Player) addHero(heroTable *data.Hero) bool {
//Awaken
this.Hero[hero.Uid] = hero
this.SaveModel(hero)
this.addHeroBook(hero.Id)
return true
return hero
}
func (this *Player) AddHero(heroId uint32) bool {
@ -83,7 +80,16 @@ func (this *Player) AddHero(heroId uint32) bool {
return false
}
return this.addHero(heroTable)
var hero = this.newHero(heroTable)
if hero == nil {
return false
}
this.Hero[hero.Uid] = hero
this.SaveModel(hero)
this.addHeroBook(hero.Id)
return true
}
func (this *Player) calcHeroLevelAttrs(hero *PlayerHero) (attrs Attrs) {
@ -120,84 +126,10 @@ func (this *Player) calcHeroBreakAttrs(hero *PlayerHero) (attrs Attrs) {
return
}
func (this *Player) calcHeroBondAttrs(hero *PlayerHero) (attrs Attrs) {
//var heroBondTables = this.manager.tables.HeroBond.Find(int(hero.Id))
//for i := range heroBondTables {
// var yes = false
// switch heroBondTables[i].BondType {
// case 1: //装备
// for _, equipUid := range hero.Equips {
// if equipUid == 0 {
// continue
// }
// if equip, ok := this.Equip[equipUid]; ok && slices.Contains(heroBondTables[i].BondId, int(equip.Id)) {
// yes = true
// break
// }
// }
// case 2: //宝物
// for _, treasureUid := range hero.Treasures {
// if treasureUid == 0 {
// continue
// }
// if treasure, ok := this.Treasure[treasureUid]; ok && slices.Contains(heroBondTables[i].BondId, int(treasure.Id)) {
// yes = true
// break
// }
// }
// case 3: //神兵
// for _, artifactUid := range hero.Artifact {
// if artifactUid == 0 {
// continue
// }
// if artifact, ok := this.Artifact[artifactUid]; ok && slices.Contains(heroBondTables[i].BondId, int(artifact.Id)) {
// yes = true
// break
// }
// }
// case 4: //英雄
//
// }
// if yes {
// attrs[heroBondTables[i].AttrType1] += uint64(heroBondTables[i].AttrValue1)
// attrs[heroBondTables[i].AttrType2] += uint64(heroBondTables[i].AttrValue2)
// attrs[heroBondTables[i].AttrType3] += uint64(heroBondTables[i].AttrValue3)
// }
//}
return
}
func (this *Player) calcHeroAwakenAttrs(hero *PlayerHero) (attrs Attrs) {
return
}
func (this *Player) calcHeroEquipsAttrs(hero *PlayerHero) (attrs Attrs) {
//for _, equipUid := range hero.Equips {
// if equipUid == 0 {
// continue
// }
//
// var equip = this.Equip[equipUid]
// var equipLevelTable = this.manager.tables.EquipLevel.Find3(int(equip.Id), int(equip.Level))
// if equipLevelTable != nil {
// attrs[equipLevelTable.AttrType] += uint64(equipLevelTable.AttrValue)
// }
//}
return
}
func (this *Player) calcHeroTreasuresAttrs(hero *PlayerHero) (attrs Attrs) {
return
}
func (this *Player) calcHeroMountsAttrs(hero *PlayerHero) (attrs Attrs) {
return
}
func (this *Player) calcHeroArtifactAttrs(hero *PlayerHero) (attrs Attrs) {
return
}
func (this *Player) calcHeroBookAttrs(hero *PlayerHero) (attrs Attrs) {
var heroBook = this.HeroBook[hero.Id]
if heroBook == nil {
@ -221,6 +153,122 @@ func (this *Player) calcHeroBookAttrs(hero *PlayerHero) (attrs Attrs) {
return
}
func (this *Player) calcHeroBondAttrs(hero *PlayerHero, lineup *PlayerLineup, lineupHero *PlayerLineupHero) (attrs Attrs) {
if lineup == nil || lineupHero == nil {
return
}
var heroBondTables = this.manager.tables.HeroBond.Find(int(hero.Id))
for i := range heroBondTables {
var yes = false
switch heroBondTables[i].BondType {
case 1: //装备
for _, equipUid := range lineupHero.Equip {
if equipUid == 0 {
continue
}
if equip, ok := this.Equip[equipUid]; ok && slices.Contains(heroBondTables[i].BondId, int(equip.Id)) {
yes = true
break
}
}
case 2: //宝物
for _, treasureUid := range lineupHero.Treasure {
if treasureUid == 0 {
continue
}
if treasure, ok := this.Treasure[treasureUid]; ok && slices.Contains(heroBondTables[i].BondId, int(treasure.Id)) {
yes = true
break
}
}
case 3: //神兵
for _, artifactUid := range lineupHero.Artifact {
if artifactUid == 0 {
continue
}
if artifact, ok := this.Artifact[artifactUid]; ok && slices.Contains(heroBondTables[i].BondId, int(artifact.Id)) {
yes = true
break
}
}
case 4: //英雄
var bondIdMap = map[int]struct{}{}
for _, bondId := range heroBondTables[i].BondId {
bondIdMap[bondId] = struct{}{}
}
for lhi := range lineup.Heroes {
if lineup.Heroes[i] == nil {
continue
}
if another, ok := this.Hero[lineup.Heroes[lhi].HeroUid]; ok {
delete(bondIdMap, int(another.Id))
}
}
//所有羁绊英雄要全部上阵
yes = len(bondIdMap) == 0
}
if yes {
attrs[heroBondTables[i].AttrType1] += uint64(heroBondTables[i].AttrValue1)
attrs[heroBondTables[i].AttrType2] += uint64(heroBondTables[i].AttrValue2)
attrs[heroBondTables[i].AttrType3] += uint64(heroBondTables[i].AttrValue3)
}
}
return
}
func (this *Player) calcHeroEquipsAttrs(hero *PlayerHero, lineup *PlayerLineup, lineupHero *PlayerLineupHero) (attrs Attrs) {
if lineup == nil || lineupHero == nil {
return
}
for _, equipUid := range lineupHero.Equip {
if equipUid == 0 {
continue
}
var equip = this.Equip[equipUid]
var equipLevelTable = this.manager.tables.EquipLevel.Find3(int(equip.Id), int(equip.Level))
if equipLevelTable != nil {
attrs[equipLevelTable.AttrType] += uint64(equipLevelTable.AttrValue)
}
}
return
}
func (this *Player) calcHeroTreasuresAttrs(hero *PlayerHero, lineup *PlayerLineup, lineupHero *PlayerLineupHero) (attrs Attrs) {
if lineup == nil || lineupHero == nil {
return
}
for _, treasureUid := range lineupHero.Treasure {
if treasureUid == 0 {
continue
}
var treasure = this.Treasure[treasureUid]
var equipLevelTable = this.manager.tables.TreasureLevel.Find3(int(treasure.Id), int(treasure.Level))
if equipLevelTable != nil {
attrs[equipLevelTable.AttrType] += uint64(equipLevelTable.AttrValue)
}
}
return
}
func (this *Player) calcHeroMountsAttrs(hero *PlayerHero, lineup *PlayerLineup, lineupHero *PlayerLineupHero) (attrs Attrs) {
if lineup == nil || lineupHero == nil {
return
}
return
}
func (this *Player) calcHeroArtifactAttrs(hero *PlayerHero, lineup *PlayerLineup, lineupHero *PlayerLineupHero) (attrs Attrs) {
if lineup == nil || lineupHero == nil {
return
}
return
}
func (this *Player) calcHeroAttrs(hero *PlayerHero, attrsList ...Attrs) bool {
var newAttrs Attrs
for _, attrs := range attrsList {
@ -239,26 +287,40 @@ func (this *Player) calcHeroAttrs(hero *PlayerHero, attrsList ...Attrs) bool {
return false
}
func (this *Player) updateHeroAttrs(hero *PlayerHero) bool {
func (this *Player) updateHeroAttrs(hero *PlayerHero, lineup *PlayerLineup, lineupHero *PlayerLineupHero) bool {
return this.calcHeroAttrs(hero,
this.calcHeroLevelAttrs(hero),
this.calcHeroBreakAttrs(hero),
this.calcHeroBondAttrs(hero),
this.calcHeroAwakenAttrs(hero),
this.calcHeroEquipsAttrs(hero),
this.calcHeroTreasuresAttrs(hero),
this.calcHeroMountsAttrs(hero),
this.calcHeroArtifactAttrs(hero),
this.calcHeroBookAttrs(hero),
this.calcHeroBondAttrs(hero, lineup, lineupHero),
this.calcHeroEquipsAttrs(hero, lineup, lineupHero),
this.calcHeroTreasuresAttrs(hero, lineup, lineupHero),
this.calcHeroMountsAttrs(hero, lineup, lineupHero),
this.calcHeroArtifactAttrs(hero, lineup, lineupHero),
)
}
func (this *Player) UpdateHeroAttrs(hero *PlayerHero) bool {
return this.updateHeroAttrs(hero)
if hero == nil {
return false
}
for _, lineup := range this.Lineup {
if lineup.Active {
for _, lineupHero := range lineup.Heroes {
if lineupHero.HeroUid == hero.Uid {
return this.updateHeroAttrs(hero, lineup, lineupHero)
}
}
}
}
return this.updateHeroAttrs(hero, nil, nil)
}
func (this *Player) BuildMsgHeroListAck() *pb.HeroListAck {
var list []*pb.Hero
var list = []*pb.Hero{this.RoleHero.BuildMsgHero()}
for _, hero := range this.Hero {
list = append(list, hero.BuildMsgHero())
}

View File

@ -35,7 +35,7 @@ func (this *Player) addItem(itemTable *data.Item, itemNum uint32, logType LogTyp
// this.manager.eventManager.PlayerItemObtain(this, logType, uint32(itemTable.Id), itemNum)
//}
return &pb.ItemChange{Item: item.BuildMsgItem(), ChangeType: changeType}
return &pb.ItemChange{ChangeType: changeType, Item: item.BuildMsgItem()}
}
func (this *Player) useItem(itemTable *data.Item, itemNum uint32, logType LogType) bool {

View File

@ -38,3 +38,34 @@ func (this *PlayerLineupHero) BuildMsgLineupHero(index uint32) *pb.LineupHero {
}
return msg
}
func (this *Player) UpdateBattleHeroCapacity(lineupHero *PlayerLineupHero) {
if lineupHero == nil {
return
}
var hero = this.Hero[lineupHero.HeroUid]
if hero == nil {
return
}
var attrs = hero.Attrs()
var capacity = (float64(attrs[pb.AttrType_Attack]) * 2) +
(float64(attrs[pb.AttrType_Hp]) * 0.2) +
(float64(attrs[pb.AttrType_AttrPhysicalDefense]) * 6) +
(float64(attrs[pb.AttrType_AttrMagicDefense]) * 6) +
(float64(attrs[pb.AttrType_AttrDamageRatio]) * 12) +
(float64(attrs[pb.AttrType_AttrDamageRelief]) * 12) +
(float64(attrs[pb.AttrType_AttrCriticalRatio]) * 12) +
(float64(attrs[pb.AttrType_AttrCriticalResistance]) * 12) +
(float64(attrs[pb.AttrType_AttrCriticalDamage]) * 12) +
(float64(attrs[pb.AttrType_AttrCriticalDamageRelief]) * 12) +
(float64(attrs[pb.AttrType_AttrHitRate]) * 12) +
(float64(attrs[pb.AttrType_AttrDodgeRate]) * 12) +
(float64(attrs[pb.AttrType_AttrTreatRatio]) * 12) +
(float64(attrs[pb.AttrType_AttrByTreatedRatio]) * 12) +
(float64(attrs[pb.AttrType_AttrFinalDamageRatio]) * 12)
lineupHero.Capacity = uint64(capacity)
}

View File

@ -27,7 +27,7 @@ func (this *Player) GetMoney(moneyType pb.MoneyType) *PlayerMoney {
func (this *Player) AddMoney(moneyType pb.MoneyType, value uint32, logType LogType) {
switch moneyType {
case pb.MoneyType_Exp:
//this.addExp(value, logType)
this.addExp(value, logType)
case pb.MoneyType_Power:
this.addPower(value, logType)
default:
@ -51,6 +51,8 @@ func (this *Player) CheckMoney(moneyType pb.MoneyType, value uint32) (bool, prot
func (this *Player) ReduceMoney(moneyType pb.MoneyType, value uint32, logType LogType) {
switch moneyType {
case pb.MoneyType_Exp:
return
case pb.MoneyType_Power:
this.reducePower(value, logType)
default:
@ -102,45 +104,49 @@ func (this *Player) reduceMoney(moneyType pb.MoneyType, value uint32, logType Lo
//}
}
//func (this *Player) addExp(value uint32, logType LogType) {
// if value == 0 {
// return
// }
//
// var money = this.GetMoney(proto.MoneyTypeExp)
// money.Value += value
//
// var curLevel = this.Role.Level
// //for {
// // var roleLevelTable = this.manager.tables.RoleLevelExtend.Get(int(this.Role.Career), int(this.Role.Level))
// // if roleLevelTable == nil {
// // return
// // }
// //
// // if money.Value < uint32(roleLevelTable.RequireExp) {
// // break
// // }
// //
// // curLevel += 1
// // money.Value -= uint32(roleLevelTable.RequireExp)
// //}
//
// this.SaveModel(money)
//
// _ = this.Send(proto.ModIdRole, proto.MsgIdRoleMoneyChange, &proto.MsgRoleMoneyListAck{List: []*proto.RoleMoney{money.BuildMsgMoney()}})
//
// if curLevel != this.Role.Level {
// var preLevel = this.Role.Level
// this.ChangeProperty(util.NewPair(proto.RolePropertyTypeLevel, uint64(curLevel)))
// if logType != LogTypeNone {
// this.manager.eventManager.PlayerLevelUpgrade(this, logType, preLevel, curLevel)
// }
// }
//
// if logType != LogTypeNone {
// this.manager.eventManager.PlayerMoneyObtain(this, logType, uint32(proto.MoneyTypeExp), value, money.Value)
// }
//}
func (this *Player) addExp(value uint32, logType LogType) {
if value == 0 {
return
}
var roleHero = this.RoleHero
if roleHero == nil {
return
}
var curExp = roleHero.Exp + uint64(value)
var curLevel = roleHero.Level
for {
var heroLevelTable = this.manager.tables.HeroLevel.Find3(int(roleHero.Id), int(curLevel))
if heroLevelTable == nil {
return
}
if curExp < uint64(heroLevelTable.NeedExp) {
break
}
curLevel += 1
curExp -= uint64(heroLevelTable.NeedExp)
}
roleHero.Exp = curExp
roleHero.Level = curLevel
this.SaveModel(roleHero)
this.RoleExp = roleHero.Exp
this.RoleLevel = roleHero.Level
this.SaveField("role_exp", this.RoleExp)
this.SaveField("role_level", this.RoleLevel)
_ = this.Send(uint16(pb.MsgId_ModHeroChange), uint16(pb.MsgId_ModHeroChange), &pb.HeroChangeListAck{
ChangeList: []*pb.HeroChange{{ChangeType: pb.ChangeType_Changed, Hero: roleHero.BuildMsgHero()}},
})
//if logType != LogTypeNone {
// this.manager.eventManager.PlayerMoneyObtain(this, logType, uint32(proto.MoneyTypeExp), value, money.Value)
//}
}
func (this *Player) addPower(value uint32, logType LogType) {
var money = this.GetMoney(pb.MoneyType_Power)

View File

@ -21,7 +21,6 @@ func (this *Player) BuildMsgRolePropertyAck() *pb.RolePropertyAck {
NamePrefix: this.NamePrefix,
NameTitle: this.NameTitle,
RoleTitle: this.RoleTitle,
RoleLevel: this.RoleLevel,
LoginDays: this.LoginDays,
PowerNextTime: this.PowerNextTime,
}
@ -50,9 +49,6 @@ func (this *Player) ChangeProperty(properties ...*util.Pair[pb.RolePropertyType,
case pb.RolePropertyType_RoleTitle:
this.RoleTitle = uint32(property.Value)
this.SaveField("role_title", this.RoleTitle)
case pb.RolePropertyType_RoleLevel:
this.RoleLevel = uint32(property.Value)
this.SaveField("role_level", this.RoleLevel)
case pb.RolePropertyType_LoginDays:
this.LoginDays = uint32(property.Value)
this.SaveField("login_days", this.LoginDays)
@ -82,8 +78,6 @@ func (this *Player) BuildMsgRolePropertyChangeAck(types ...pb.RolePropertyType)
property.Value = int64(this.NameTitle)
case pb.RolePropertyType_RoleTitle:
property.Value = int64(this.RoleTitle)
case pb.RolePropertyType_RoleLevel:
property.Value = int64(this.RoleLevel)
case pb.RolePropertyType_LoginDays:
property.Value = int64(this.LoginDays)
case pb.RolePropertyType_PowerNextTime:

View File

@ -18,7 +18,7 @@ type PlayerTemp struct {
SceneId uint32
Fighting bool
RandSeed int64
RandSeed uint64
//ArenaEnemy *RankingPlayer

View File

@ -5,6 +5,7 @@ import "ecs/proto/pb"
type PlayerTreasure struct {
Uid uint64 `bson:"uid" key:"1"`
Id uint32 `bson:"id"`
Level uint32 `bson:"level"`
HeroUid uint64 `bson:"hero_id"`
}
@ -16,7 +17,7 @@ func (this *PlayerTreasure) BuildMsgTreasure() *pb.Treasure {
}
}
func (this *Player) BuildMsgRigTreasureListAck() *pb.TreasureListAck {
func (this *Player) BuildMsgTreasureListAck() *pb.TreasureListAck {
var list []*pb.Treasure
for _, treasure := range this.Treasure {
list = append(list, treasure.BuildMsgTreasure())

View File

@ -205,8 +205,9 @@ func (this *gameServer) Init() (err error) {
this.playerManager.Handler(uint16(pb.ModId_ModuleHero), uint16(pb.MsgId_ModHeroQuality), this.playerHandler.HeroQuality)
this.playerManager.Handler(uint16(pb.ModId_ModuleHero), uint16(pb.MsgId_ModHeroBookActivate), this.playerHandler.HeroBookActivate)
//Register player mail module message handlers
//Register player item module message handlers
this.playerManager.Handler(uint16(pb.ModId_ModuleItem), uint16(pb.MsgId_ModItemEquipUpgrade), this.playerHandler.EquipUpgrade)
this.playerManager.Handler(uint16(pb.ModId_ModuleItem), uint16(pb.MsgId_ModItemEquipRefine), this.playerHandler.EquipRefine)
////Register player mail module message handlers
//this.playerManager.Handler(proto.ModIdMail, proto.MsgIdMailRead, this.playerHandler.MailRead)