543 lines
14 KiB
Go
543 lines
14 KiB
Go
package main
|
|
|
|
import (
|
|
"time"
|
|
|
|
"mongo.games.com/goserver/core/module"
|
|
|
|
"mongo.games.com/game/common"
|
|
"mongo.games.com/game/model"
|
|
hall_proto "mongo.games.com/game/protocol/gamehall"
|
|
"mongo.games.com/game/protocol/pets"
|
|
"mongo.games.com/game/srvdata"
|
|
)
|
|
|
|
const (
|
|
ItemObtain = iota //得到
|
|
ItemConsume //消耗
|
|
)
|
|
|
|
var PetMgrSington = &PetMgr{
|
|
//RPInfos: make(map[int32]*RoleAndPetInfo),
|
|
}
|
|
|
|
type PetMgr struct {
|
|
//RPInfos map[int32]*RoleAndPetInfo
|
|
}
|
|
type RoleAndPetInfo struct {
|
|
ModId int32 //模型id
|
|
Name string //名字
|
|
Story string //人物背景介绍
|
|
AwardTitle string //奖励标题
|
|
MaxLevel int32 //最大等级
|
|
}
|
|
|
|
func (this *PetMgr) ModuleName() string {
|
|
return "PetMgr"
|
|
}
|
|
|
|
// 人物
|
|
func (this *PetMgr) GetRoleInfos(p *Player) []*pets.RoleInfo {
|
|
rolesInfo := srvdata.RolePetMgrSington.Roles
|
|
if rolesInfo != nil {
|
|
var newRoles = make([]*pets.RoleInfo, 0)
|
|
for roleId, roles := range rolesInfo {
|
|
level := p.Roles.ModUnlock[roleId]
|
|
if len(roles) >= int(level) {
|
|
rol := roles[level]
|
|
role := &pets.RoleInfo{
|
|
Id: rol.Id,
|
|
RoleId: rol.RoleId,
|
|
Name: rol.Name,
|
|
Grade: rol.Grade,
|
|
Level: rol.Level,
|
|
Fragment: rol.Fragment,
|
|
Amount: rol.Amount,
|
|
AwardType: rol.AwardType,
|
|
Award: rol.Award,
|
|
AwardRate: rol.AwardRate,
|
|
}
|
|
if level > 0 {
|
|
role.IsUnlock = true
|
|
if p.Roles.ModId == roleId {
|
|
role.IsUsing = true
|
|
}
|
|
}
|
|
|
|
if level == 0 {
|
|
role.NextAward = roles[1].Award
|
|
} else {
|
|
if int32(len(roles)) > level+1 {
|
|
role.NextAward = roles[level+1].Award
|
|
}
|
|
}
|
|
|
|
roleOther := this.GetIntroductionByModId(role.RoleId)
|
|
role.MaxLevel = roleOther.MaxLevel
|
|
role.Name = roleOther.Name
|
|
role.Story = roleOther.Story
|
|
role.AwardTitle = roleOther.AwardTitle
|
|
///
|
|
item := BagMgrSingleton.GetItem(p.SnId, role.Fragment)
|
|
if item != nil {
|
|
role.HaveAmount = int32(item.ItemNum)
|
|
}
|
|
newRoles = append(newRoles, role)
|
|
}
|
|
}
|
|
return newRoles
|
|
}
|
|
return nil
|
|
}
|
|
func (this *PetMgr) GetRoleInfo(p *Player, modId int32) *pets.RoleInfo {
|
|
level := p.Roles.ModUnlock[modId]
|
|
roleInfo := srvdata.RolePetMgrSington.GetRoleByRoleIdAndLevel(modId, level)
|
|
if roleInfo != nil {
|
|
role := &pets.RoleInfo{
|
|
Id: roleInfo.Id,
|
|
RoleId: roleInfo.RoleId,
|
|
Name: roleInfo.Name,
|
|
Grade: roleInfo.Grade,
|
|
Level: roleInfo.Level,
|
|
Fragment: roleInfo.Fragment,
|
|
Amount: roleInfo.Amount,
|
|
AwardType: roleInfo.AwardType,
|
|
Award: roleInfo.Award,
|
|
AwardRate: roleInfo.AwardRate,
|
|
}
|
|
if level > 0 {
|
|
role.IsUnlock = true
|
|
if p.Roles.ModId == roleInfo.RoleId {
|
|
role.IsUsing = true
|
|
}
|
|
}
|
|
nextInfo := srvdata.RolePetMgrSington.GetRoleByRoleIdAndLevel(modId, level+1)
|
|
if nextInfo != nil {
|
|
role.NextAward = nextInfo.Award
|
|
}
|
|
roleOther := this.GetIntroductionByModId(modId)
|
|
role.MaxLevel = roleOther.MaxLevel
|
|
role.Name = roleOther.Name
|
|
role.Story = roleOther.Story
|
|
role.AwardTitle = roleOther.AwardTitle
|
|
//
|
|
item := BagMgrSingleton.GetItem(p.SnId, role.Fragment)
|
|
if item != nil {
|
|
role.HaveAmount = int32(item.ItemNum)
|
|
}
|
|
return role
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ////////////////////////////////////////////////////////////////////////
|
|
// 宠物
|
|
func (this *PetMgr) GetPetInfos(p *Player) []*pets.PetInfo {
|
|
petsInfo := srvdata.RolePetMgrSington.Pets
|
|
if petsInfo != nil {
|
|
var newPets = make([]*pets.PetInfo, 0)
|
|
for petId, petInfo := range petsInfo {
|
|
level := p.Pets.ModUnlock[petId]
|
|
if len(petInfo) >= int(level) {
|
|
pet := petInfo[level]
|
|
newPet := &pets.PetInfo{
|
|
Id: pet.Id,
|
|
PetId: pet.PetId,
|
|
Name: pet.Name,
|
|
Grade: pet.Grade,
|
|
Level: pet.Level,
|
|
Fragment: pet.Fragment,
|
|
Amount: pet.Amount,
|
|
AwardType: pet.AwardType,
|
|
Award: pet.Award,
|
|
AwardRate: pet.AwardRate,
|
|
}
|
|
if level > 0 {
|
|
newPet.IsUnlock = true
|
|
if p.Pets.ModId == petId {
|
|
newPet.IsUsing = true
|
|
}
|
|
}
|
|
|
|
if level == 0 {
|
|
newPet.NextAward = petInfo[1].Award
|
|
} else {
|
|
if int32(len(petInfo)) > level+1 {
|
|
newPet.NextAward = petInfo[level+1].Award
|
|
}
|
|
}
|
|
|
|
petOther := this.GetIntroductionByModId(newPet.PetId)
|
|
newPet.MaxLevel = petOther.MaxLevel
|
|
newPet.Name = petOther.Name
|
|
newPet.Story = petOther.Story
|
|
newPet.AwardTitle = petOther.AwardTitle
|
|
///
|
|
item := BagMgrSingleton.GetItem(p.SnId, newPet.Fragment)
|
|
if item != nil {
|
|
newPet.HaveAmount = int32(item.ItemNum)
|
|
}
|
|
//技能
|
|
if p.Pets.SkillInfo != nil && p.Pets.SkillInfo[petId] != nil {
|
|
skillInfo := p.Pets.SkillInfo[petId]
|
|
for skillId, skillLevel := range skillInfo {
|
|
info := &pets.PetSkillInfo{}
|
|
info.SkillId = skillId
|
|
info.SkillLevel = skillLevel
|
|
newPet.SkillInfo = append(newPet.SkillInfo, info)
|
|
}
|
|
|
|
}
|
|
newPets = append(newPets, newPet)
|
|
}
|
|
}
|
|
return newPets
|
|
}
|
|
return nil
|
|
}
|
|
func (this *PetMgr) GetPetInfo(p *Player, modId int32) *pets.PetInfo {
|
|
level := p.Pets.ModUnlock[modId]
|
|
petInfo := srvdata.RolePetMgrSington.GetPetByPetIdAndLevel(modId, level)
|
|
if petInfo != nil {
|
|
newPet := &pets.PetInfo{
|
|
Id: petInfo.Id,
|
|
PetId: petInfo.PetId,
|
|
Name: petInfo.Name,
|
|
Grade: petInfo.Grade,
|
|
Level: petInfo.Level,
|
|
Fragment: petInfo.Fragment,
|
|
Amount: petInfo.Amount,
|
|
AwardType: petInfo.AwardType,
|
|
Award: petInfo.Award,
|
|
AwardRate: petInfo.AwardRate,
|
|
}
|
|
if level > 0 {
|
|
newPet.IsUnlock = true
|
|
if p.Roles.ModId == petInfo.PetId {
|
|
newPet.IsUsing = true
|
|
}
|
|
}
|
|
nextInfo := srvdata.RolePetMgrSington.GetPetByPetIdAndLevel(modId, level+1)
|
|
if nextInfo != nil {
|
|
newPet.NextAward = nextInfo.Award
|
|
}
|
|
petOther := this.GetIntroductionByModId(modId)
|
|
newPet.MaxLevel = petOther.MaxLevel
|
|
newPet.Name = petOther.Name
|
|
newPet.Story = petOther.Story
|
|
newPet.AwardTitle = petOther.AwardTitle
|
|
//
|
|
item := BagMgrSingleton.GetItem(p.SnId, newPet.Fragment)
|
|
if item != nil {
|
|
newPet.HaveAmount = int32(item.ItemNum)
|
|
}
|
|
//技能
|
|
if p.Pets.SkillInfo != nil && p.Pets.SkillInfo[modId] != nil {
|
|
skillInfo := p.Pets.SkillInfo[modId]
|
|
for skillId, skillLevel := range skillInfo {
|
|
info := &pets.PetSkillInfo{}
|
|
info.SkillId = skillId
|
|
info.SkillLevel = skillLevel
|
|
newPet.SkillInfo = append(newPet.SkillInfo, info)
|
|
}
|
|
}
|
|
return newPet
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// 皮肤
|
|
func (this *PetMgr) GetSkinInfos(p *Player) []*pets.SkinInfo {
|
|
var ret []*pets.SkinInfo
|
|
for _, v := range PlatformMgrSingleton.GetConfig(p.Platform).SkinConfig.GetItems() {
|
|
ret = append(ret, this.GetSkinInfo(p, v.GetId()))
|
|
}
|
|
return ret
|
|
}
|
|
|
|
func (this *PetMgr) GetSkinInfo(p *Player, id int32) *pets.SkinInfo {
|
|
cfg := PlatformMgrSingleton.GetSkinInfo(p.Platform, id)
|
|
if cfg == nil {
|
|
return nil
|
|
}
|
|
|
|
bag := BagMgrSingleton.GetBagInfo(p.SnId)
|
|
level := p.Skin.ModUnlock[id]
|
|
var unLockCost, cost, have []*pets.Item
|
|
var needVip int32
|
|
for k, v := range cfg.GetUnlockParam() {
|
|
unLockCost = append(unLockCost, &pets.Item{
|
|
Id: k,
|
|
N: v,
|
|
})
|
|
needVip = k
|
|
}
|
|
if level == 0 {
|
|
cost = unLockCost
|
|
if cfg.GetUnlockType() == common.SkinGetVip {
|
|
cost = cost[:0]
|
|
}
|
|
} else {
|
|
for k, v := range PlatformMgrSingleton.GetSkinLevel(p.Platform, id, level+1).GetUpItem() {
|
|
cost = append(cost, &pets.Item{
|
|
Id: k,
|
|
N: v,
|
|
})
|
|
}
|
|
}
|
|
for _, v := range cost {
|
|
if bag != nil {
|
|
info := bag.BagItem[v.GetId()]
|
|
if info != nil {
|
|
have = append(have, &pets.Item{
|
|
Id: v.GetId(),
|
|
N: info.ItemNum,
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
unLock := level > 0
|
|
use := unLock && p.Skin.ModId == id
|
|
|
|
ret := &pets.SkinInfo{
|
|
Id: id,
|
|
Level: level,
|
|
MaxLevel: PlatformMgrSingleton.GetSkinMaxLevel(p.Platform, id),
|
|
Cost: cost,
|
|
Have: have,
|
|
IsUsing: use,
|
|
IsUnlock: unLock,
|
|
IsUpgrade: cfg.GetIsUpgrade() == 1,
|
|
SkillType: cfg.GetSkillType(),
|
|
UnLockType: cfg.GetUnlockType(),
|
|
}
|
|
if cfg.GetUnlockType() == common.SkinGetVip {
|
|
ret.NeedVip = needVip
|
|
}
|
|
curLevel := PlatformMgrSingleton.GetSkinLevel(p.Platform, id, level)
|
|
nextLevel := PlatformMgrSingleton.GetSkinLevel(p.Platform, id, level+1)
|
|
if curLevel != nil {
|
|
ret.SkillId = curLevel.GetSkillId()
|
|
}
|
|
if nextLevel != nil {
|
|
ret.SkillId = nextLevel.GetSkillId()
|
|
}
|
|
if curLevel != nil {
|
|
ret.SkillLevel = curLevel.GetSkillLevel()
|
|
ret.SkillValue = curLevel.GetSkillValue()
|
|
}
|
|
ret.SkillMaxLevel = PlatformMgrSingleton.GetSkinSkillMaxLevel(p.Platform, id)
|
|
if nextLevel != nil {
|
|
ret.SkillNextLevel = nextLevel.GetSkillLevel()
|
|
ret.SkillNextValue = nextLevel.GetSkillValue()
|
|
}
|
|
|
|
return ret
|
|
}
|
|
|
|
func (this *PetMgr) CheckSkinRed(p *Player) {
|
|
if p == nil || p.IsRob {
|
|
return
|
|
}
|
|
for _, v := range PlatformMgrSingleton.GetConfig(p.Platform).SkinConfig.GetItems() {
|
|
if v == nil {
|
|
continue
|
|
}
|
|
info := this.GetSkinInfo(p, v.Id)
|
|
// 解锁
|
|
if !info.GetIsUnlock() {
|
|
ok := true
|
|
for _, v := range info.GetCost() {
|
|
item := BagMgrSingleton.GetItem(p.SnId, v.GetId())
|
|
if item == nil || item.ItemNum < v.GetN() {
|
|
ok = false
|
|
break
|
|
}
|
|
}
|
|
if ok && len(info.GetCost()) > 0 {
|
|
p.SendShowRed(hall_proto.ShowRedCode_Skin, v.Id, 1)
|
|
continue
|
|
}
|
|
// vip等级解锁
|
|
if info.GetUnLockType() == common.SkinGetVip && p.VIP >= info.GetNeedVip() {
|
|
p.SendShowRed(hall_proto.ShowRedCode_Skin, v.Id, 1)
|
|
continue
|
|
}
|
|
}
|
|
// 升级
|
|
if info.GetIsUnlock() && info.GetLevel() < info.GetMaxLevel() && info.GetIsUpgrade() {
|
|
ok := true
|
|
for _, v := range info.GetCost() {
|
|
item := BagMgrSingleton.GetItem(p.SnId, v.GetId())
|
|
if item == nil || item.ItemNum < v.GetN() {
|
|
ok = false
|
|
break
|
|
}
|
|
}
|
|
if ok && len(info.GetCost()) > 0 {
|
|
p.SendShowRed(hall_proto.ShowRedCode_Skin, v.Id, 1)
|
|
continue
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 商品人物总加成 人物功能变动需要修改
|
|
func (this *PetMgr) GetShopAward(shopInfo *model.ShopInfo, p *Player) (award, roleId int32) {
|
|
if shopInfo.Ad > 0 && shopInfo.Type == ShopTypeCoin {
|
|
id, add := srvdata.RolePetMgrSington.GetRoleAdd(p.PlayerData, common.RoleAddADV)
|
|
award += add
|
|
roleId = id
|
|
}
|
|
|
|
if shopInfo.Ad == 0 && shopInfo.Type == ShopTypeCoin {
|
|
id, add := srvdata.RolePetMgrSington.GetRoleAdd(p.PlayerData, common.RoleAddCoin)
|
|
award += add
|
|
roleId = id
|
|
}
|
|
|
|
//VIP商城没有人物加成
|
|
if shopInfo.Page == ShopPageVip || shopInfo.Page == ShopPagePhoneScore || shopInfo.Page == ShopPagePhoneScoreGoogle {
|
|
award = 0
|
|
}
|
|
return award, roleId
|
|
}
|
|
|
|
// 宠物加成 宠物功能变动需要修改
|
|
func (this *PetMgr) GetAwardPetByWelf(p *Player) (award int64) {
|
|
petChick := this.GetPetInfo(p, 1000001)
|
|
if petChick != nil && petChick.Level > 0 {
|
|
award = int64(petChick.Award)
|
|
}
|
|
return
|
|
}
|
|
func (this *PetMgr) GetIntroductionByModId(modId int32) *RoleAndPetInfo {
|
|
mod := srvdata.PBDB_Game_IntroductionMgr.GetData(modId)
|
|
if mod == nil {
|
|
return &RoleAndPetInfo{}
|
|
}
|
|
return &RoleAndPetInfo{
|
|
ModId: mod.Id,
|
|
Name: mod.Name,
|
|
Story: mod.Story,
|
|
AwardTitle: mod.AwardTitle,
|
|
MaxLevel: mod.LevelMax,
|
|
}
|
|
}
|
|
func (this *PetMgr) CheckShowRed(p *Player) {
|
|
if p == nil || p.IsRob {
|
|
return
|
|
}
|
|
var roleRed, petRed bool
|
|
if p.Roles != nil {
|
|
needAmount := make(map[int32]int32)
|
|
for roleId, rol := range srvdata.RolePetMgrSington.Roles {
|
|
if level, ok := p.Roles.ModUnlock[roleId]; ok {
|
|
needAmount[rol[level].Fragment] = rol[level].Amount
|
|
} else {
|
|
needAmount[rol[level].Fragment] = rol[level].Amount
|
|
}
|
|
}
|
|
for fragment, amount := range needAmount {
|
|
item := BagMgrSingleton.GetItem(p.SnId, fragment)
|
|
if item != nil && item.ItemNum >= int64(amount) && amount != 0 {
|
|
roleRed = true
|
|
break
|
|
}
|
|
}
|
|
}
|
|
if p.Pets != nil {
|
|
needAmount := make(map[int32]int32)
|
|
for petId, pet := range srvdata.RolePetMgrSington.Pets {
|
|
if level, ok := p.Pets.ModUnlock[petId]; ok {
|
|
needAmount[pet[level].Fragment] = pet[level].Amount
|
|
} else {
|
|
needAmount[pet[level].Fragment] = pet[level].Amount
|
|
}
|
|
}
|
|
for fragment, amount := range needAmount {
|
|
item := BagMgrSingleton.GetItem(p.SnId, fragment)
|
|
if item != nil && item.ItemNum >= int64(amount) && amount != 0 {
|
|
petRed = true
|
|
break
|
|
}
|
|
}
|
|
//宠物技能红点
|
|
if !petRed {
|
|
for _, SkillInfo := range srvdata.PBDB_PetSkillMgr.Datas.GetArr() {
|
|
if p.Pets.SkillInfo[SkillInfo.PetId] != nil {
|
|
for skillId, skilllevel := range p.Pets.SkillInfo[SkillInfo.PetId] {
|
|
if SkillInfo.SkillId == skillId && SkillInfo.SkillLevel == skilllevel+1 {
|
|
//获取物品数量
|
|
status := true
|
|
for itemId, itemNum := range SkillInfo.ItemConsum {
|
|
item := BagMgrSingleton.GetItem(p.SnId, int32(itemId))
|
|
if item != nil {
|
|
if item.ItemNum < itemNum {
|
|
status = false
|
|
break
|
|
}
|
|
} else {
|
|
status = false
|
|
break
|
|
}
|
|
}
|
|
if status {
|
|
petRed = true
|
|
break
|
|
}
|
|
}
|
|
}
|
|
if petRed {
|
|
break
|
|
}
|
|
} else {
|
|
//获取物品数量
|
|
status := true
|
|
for itemId, itemNum := range SkillInfo.ItemConsum {
|
|
item := BagMgrSingleton.GetItem(p.SnId, int32(itemId))
|
|
if item != nil {
|
|
if item.ItemNum < itemNum {
|
|
status = false
|
|
break
|
|
}
|
|
} else {
|
|
status = false
|
|
break
|
|
}
|
|
}
|
|
if status {
|
|
petRed = true
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if roleRed {
|
|
p.SendShowRed(hall_proto.ShowRedCode_Role, 0, 1)
|
|
}
|
|
if petRed {
|
|
p.SendShowRed(hall_proto.ShowRedCode_Pet, 0, 1)
|
|
}
|
|
}
|
|
|
|
//////////////////////////////////
|
|
|
|
func (this *PetMgr) Init() {
|
|
|
|
}
|
|
func (this *PetMgr) Update() {
|
|
|
|
}
|
|
|
|
func (this *PetMgr) Shutdown() {
|
|
module.UnregisteModule(this)
|
|
}
|
|
|
|
func init() {
|
|
module.RegisteModule(PetMgrSington, time.Second, 0)
|
|
}
|