1 Star 0 Fork 0

liuxuezhan/mylib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
LC_RobotWorldBattleManager.go 6.37 KB
一键复制 编辑 原始数据 按行查看 历史
liuxuezhan 提交于 2020-12-19 16:15 . 'ok'
package logic
import (
"sync"
"gitee.com/liuxuezhan/mylib/GameServer/cache"
"gitee.com/liuxuezhan/mylib/Protocol"
"gitee.com/liuxuezhan/mylib/Utils/wlog"
"gitee.com/liuxuezhan/mylib/common"
"gitee.com/liuxuezhan/mylib/wtime"
"github.com/golang/protobuf/proto"
)
/*
仅仅用于机器人战斗时记录战斗场次信息
*/
var RobotWorldBattleManager *RobotWorldBattlePool
type RobotWorldBattlePool struct {
sync.RWMutex
RobotUIDList []uint64
PVPMatchesDataMap map[*cache.Info]*cache.Info //key:进攻方 UID 防守方
//PVPMatchesDataMap map[uint64]*RobotDefInfo //key:进攻方 UID 防守方
RecordInstanceMap map[uint64]*BattleRecordInstance
totalRobot uint64
}
type BattleRecordInstance struct {
startNum uint64 //已开启的战斗场次
succeedNum uint64 //成功打完的战斗
errorNum uint64 //战斗流程出错
}
/*
type RobotDefInfo struct{
UID uint64
tileID int32 //基地坐标
}
*/
const (
switchFlag = "off"
)
func (this *RobotWorldBattlePool) CreateInstance(UID uint64) bool {
if switchFlag == "off" {
return false
}
this.Lock()
defer this.Unlock()
_, ok := this.RecordInstanceMap[UID]
if ok {
this.RecordInstanceMap[UID].startNum += 1
} else {
recordInstance := &BattleRecordInstance{
startNum: 1,
succeedNum: 0,
errorNum: 0,
}
this.totalRobot += 1
this.RecordInstanceMap[UID] = recordInstance
}
return true
}
func (this *RobotWorldBattlePool) EndRobotBattle(UID uint64, isSucceed uint32) {
if switchFlag == "off" {
return
}
this.Lock()
defer this.Unlock()
_, ok := this.RecordInstanceMap[UID]
if ok {
if 0 != isSucceed {
this.RecordInstanceMap[UID].succeedNum += 1
} else {
this.RecordInstanceMap[UID].errorNum += 1
}
}
}
func initRobotWorldBattlePool() {
RobotWorldBattleManager = &RobotWorldBattlePool{
RobotUIDList: make([]uint64, 0),
PVPMatchesDataMap: make(map[*cache.Info]*cache.Info, 0), //key:进攻方UID 防守方信息
RecordInstanceMap: make(map[uint64]*BattleRecordInstance, 0),
totalRobot: 0,
}
}
func (this *RobotWorldBattlePool) ShowTotoalBattleNum() {
if switchFlag == "off" {
return
}
this.Lock()
defer this.Unlock()
if 0 == this.totalRobot {
wlog.Error("【robotBattle】error: no robot battle")
}
totalStartNum := uint64(0)
totalSucceedNum := uint64(0)
for _, v := range this.RecordInstanceMap {
totalStartNum += v.startNum
totalSucceedNum += v.succeedNum
}
wlog.Error("【robotBattle】totalStartNum...", totalStartNum)
wlog.Error("【robotBattle】totalSucceedNum...", totalSucceedNum)
wlog.Error("【robotBattle】totalRobotNum...", this.totalRobot)
}
func (this *RobotWorldBattlePool) ClearRobotReocrd() {
this.Lock()
defer this.Unlock()
RobotWorldBattleManager.RecordInstanceMap = make(map[uint64]*BattleRecordInstance, 0)
RobotWorldBattleManager.totalRobot = 0
}
//准备PVP数据
func (this *RobotWorldBattlePool) DeployRobotPVPBattle() {
if switchFlag == "off" {
return
}
cache.ForeachOnline(func(tmpInfo *cache.Info) bool {
if tmpInfo.GetUserName() == "You" {
return true
}
//准备英雄
heroIDList := []uint32{4500001, 4500014, 4500018} //苏莱曼,凯撒,瓦尔基里
for _, v := range heroIDList {
tmpInfo.InitHeroByParm(v, 1, 1)
}
//升级建筑
tmpInfo.UnlockAllLand() //>>>去掉所有锁定地块
SetBuildingLevel(tmpInfo, 25)
//准备城墙,并取消保护罩
processDefenseInit(tmpInfo)
tmpInfo.GetDenfenseAsset().Bootcap = proto.Bool(false)
tmpInfo.GetDenfenseAsset().Newbootcap = proto.Bool(false)
tmpInfo.GetDenfenseAsset().CapStartTime = proto.Uint64(0)
tmpInfo.GetDenfenseAsset().CapDuration = proto.Uint64(0)
updateUserWorldData(tmpInfo)
this.RobotUIDList = append(this.RobotUIDList, tmpInfo.GetUid())
return true
})
//两两配对
robotNum := len(this.RobotUIDList)
for index := 0; index < robotNum; {
atkUID := this.RobotUIDList[index]
atkUser := cache.GetCharinfo(atkUID)
index += 1
if robotNum <= index {
break
}
defUID := this.RobotUIDList[index]
defUser := cache.GetCharinfo(defUID)
this.PVPMatchesDataMap[atkUser] = defUser
index += 1
}
wlog.Error("PVP matches num...", len(this.PVPMatchesDataMap))
}
//开始机器人PVP战斗
func (this *RobotWorldBattlePool) StartRobotPVPBattle() {
if switchFlag == "off" {
return
}
startTime := wtime.GetNow() + 5
clearAsset := []string{"as_unit"}
for atkUser, defUser := range this.PVPMatchesDataMap {
atkUser.ResetSomeData(clearAsset)
defUser.ResetSomeData(clearAsset)
//设置兵力数据
for id := uint32(3101001); id <= 3101004; id++ {
atkUser.AddUnitAsset(id, 2000)
defUser.AddUnitAsset(id, 2000)
}
for id := uint32(3102001); id <= 3102004; id++ {
atkUser.AddUnitAsset(id, 2000)
defUser.AddUnitAsset(id, 2000)
}
for id := uint32(3103001); id <= 3103004; id++ {
atkUser.AddUnitAsset(id, 2000)
defUser.AddUnitAsset(id, 2000)
}
for id := uint32(3104001); id <= 3104004; id++ {
atkUser.AddUnitAsset(id, 2000)
defUser.AddUnitAsset(id, 2000)
}
heroIDList := []uint32{4500001, 4500014, 4500018} //苏莱曼,凯撒,瓦尔基里
//设置防守方城墙和驻守的英雄
for _, v := range heroIDList {
ProcessHeroDefense(defUser, v, 1, -1, true)
}
defUser.GetDenfenseAsset().Durable = proto.Uint32(10000)
//设置进攻英雄和进攻兵力
atkHeroIDList := &Protocol.ST_Int32List_PB{
List: []int32{4500001, 4500014, 4500018},
}
unitList := &Protocol.ST_UnitAsset_PB{
Units: make([]*Protocol.ST_Unit_PB, 0),
}
for _, v := range atkUser.GetUnitAsset().GetUnits() {
unitList.Units = append(unitList.Units, Protocol.Clone(v).(*Protocol.ST_Unit_PB))
}
atkHeroIDListString := common.Base64Encode(string(Protocol.Marshal(atkHeroIDList)))
unitListString := common.Base64Encode(string(Protocol.Marshal(unitList)))
//设置进攻方大地图信息
processWorldMapAction(atkUser.GetUid(),
atkUser.GetLocation(),
defUser.GetLocation(),
402,
unitListString,
atkHeroIDListString,
0,
0,
"",
0, 0,
nil)
}
//重新设定全局的攻击行的行军时间,使之同时开战
for atkUser := range this.PVPMatchesDataMap {
actionIDList := atkUser.GetGlobalActionIDs()
if 0 == len(actionIDList) {
continue
}
actionAsset := cache.Instance_GlobalAssetGlobalAction.GetGlobalActionAsset(actionIDList[0])
if nil == actionAsset {
continue
}
tmpRetTime := startTime - wtime.GetNow()
actionAsset.UpdateRemaintime(tmpRetTime)
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liuxuezhan/mylib.git
git@gitee.com:liuxuezhan/mylib.git
liuxuezhan
mylib
mylib
v1.1.1

搜索帮助