1 Star 0 Fork 0

liuxuezhan / mylib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
LC_ActivityTask.go 13.60 KB
一键复制 编辑 原始数据 按行查看 历史
liuxuezhan 提交于 2020-12-19 16:15 . 'ok'
package logic
import (
"strings"
"sync/atomic"
"gitee.com/liuxuezhan/mylib/GameServer/CSV"
"gitee.com/liuxuezhan/mylib/GameServer/cache"
"gitee.com/liuxuezhan/mylib/GameServer/observer"
"gitee.com/liuxuezhan/mylib/GameServer/oss"
proto "gitee.com/liuxuezhan/mylib/Protocol"
"gitee.com/liuxuezhan/mylib/Utils/wlog"
"gitee.com/liuxuezhan/mylib/common"
"gitee.com/liuxuezhan/mylib/wtime"
)
func ProcessActivityTask(userData *cache.Info) {
if userData == nil {
return
}
today := wtime.GetTodayZeroClock()
if userData.GetActivityTaskRefreshTime() > today {
return
}
userData.WithActivityTaskAsset(false, func(asset *proto.ST_Asset_ActivityTask_PB) bool {
atomic.StoreUint64(asset.RefreshTime, today+86400)
asset.RewardedBoxIdxs = make([]uint32, 0)
asset.Tasks = make([]*proto.ST_ActivityTask_Item, 0)
asset.MainCityLevel = proto.SetUint32(userData.GetMainCityLevel())
asset.TotalScore = proto.SetUint32(0)
// 重新刷新任务
taskIds := CSV.GetActivityTasks()
for _, id := range taskIds {
conf := CSV.Mgr.CSV_ActivityTask.GetEntryPtr(id)
if nil != conf {
condition := common.ParseStringToVector3(conf.TaskCondition)
limt := strings.Split(conf.MainCityLevel, " ")
if len(condition) <= 0 || len(limt) != 2 {
continue
}
if asset.GetMainCityLevel() < common.StringToUint32(limt[0]) || asset.GetMainCityLevel() > common.StringToUint32(limt[1]) {
continue
}
asset.Tasks = append(asset.Tasks, &proto.ST_ActivityTask_Item{
Id: proto.SetUint32(uint32(conf.ID)),
Type: proto.SetUint32(uint32(condition[0].GetX())),
//CurrentTimes: proto.SetUint32(0),
TargetTimes: proto.SetUint32(uint32(condition[0].GetZ())),
Param: proto.SetUint32(uint32(condition[0].GetY())),
})
}
}
userData.DirtyAll()
return true
})
}
func registerActivityTaskEventHandler() {
observer.ObserverSingleton.Register(observer.ActivityTaskReceiveUnitEvent, handleReceiveUnitEvent)
observer.ObserverSingleton.Register(observer.ActivityTaskLeagueHelpEvent, handleLeagueHelpEvent)
observer.ObserverSingleton.Register(observer.ActivityTaskLeagueTechEvent, handleLeagueTechEvent)
observer.ObserverSingleton.Register(observer.ActivityTaskResearchEvent, handleResearchEvent)
observer.ObserverSingleton.Register(observer.ActivityTaskBuildingUpgradeEvent, handleBuildingUpgradeEvent)
observer.ObserverSingleton.Register(observer.ActivityTaskKillMonsterEvent, handleKillMonsterEvent)
observer.ObserverSingleton.Register(observer.UserCollectEvent, handleCollectEvent)
observer.ObserverSingleton.Register(observer.ActivityTaskBlackMarketEvent, handleBlackMarketEvent)
observer.ObserverSingleton.Register(observer.ActivityTaskSupplyEvent, handleSupplyEvent)
observer.ObserverSingleton.Register(observer.ActivityTaskMapListEvent, handleMapListEvent)
observer.ObserverSingleton.Register(observer.ActivityTaskLeagueTaskEvent, handleActivityTaskLeagueTaskEvent)
observer.ObserverSingleton.Register(observer.ActivityTaskDispatchTaskEvent, handleActivityTaskDispatchTaskEvent)
observer.ObserverSingleton.Register(observer.ActivityTaskHeroEvent, handleHeroEvent)
observer.ObserverSingleton.Register(observer.AttackMonsterEvent, handleAttackMonsterEvent)
observer.ObserverSingleton.Register(observer.TakeCardEvent, func(params []interface{}) { handleCommonActivityTaskEvent2(observer.TakeCardEvent, params) })
observer.ObserverSingleton.Register(observer.UseItemEvent, func(params []interface{}) { handleCommonActivityTaskEvent2(observer.UseItemEvent, params) })
observer.ObserverSingleton.Register(observer.Event_50021, func(params []interface{}) { handleCommonActivityTaskEvent2(observer.Event_50021, params) })
}
func handleReceiveUnitEvent(params []interface{}) {
if len(params) != 3 {
wlog.Error("handleReceiveUnitEventHandler params err")
return
}
userData, ok := params[0].(*cache.Info)
if !ok {
wlog.Error("handleReceiveUnitEventHandler params 0 err")
return
}
buildingConf, ok := params[1].(*CSV.CF_BuildingConfig_DataEntry)
if !ok {
wlog.Error("handleReceiveUnitEventHandler params 1 err")
return
}
count, ok := params[2].(uint32)
if !ok {
wlog.Error("handleReceiveUnitEventHandler parms 2 err")
return
}
times := uint32(0)
userData.WithActivityTaskAsset(false, func(asset *proto.ST_Asset_ActivityTask_PB) bool {
write := false
for _, task := range asset.Tasks {
if task.GetCurrentTimes() < task.GetTargetTimes() {
if (task.GetType() == uint32(proto.ActivityTaskType_ATT_ProductBuBing) && buildingConf.ID == 1020000) ||
(task.GetType() == uint32(proto.ActivityTaskType_ATT_ProductJijia) && buildingConf.ID == 1030000) ||
(task.GetType() == uint32(proto.ActivityTaskType_ATT_ProductFeiji) && buildingConf.ID == 1040000) ||
(task.GetType() == uint32(proto.ActivityTaskType_ATT_ProductTank) && buildingConf.ID == 1050000) ||
(task.GetType() == uint32(proto.ActivityTaskType_ATT_ProductPitfall) && buildingConf.ID == 1080000) ||
(task.GetType() == uint32(proto.ActivityTaskType_ATT_CureUnit) && buildingConf.ID == 1060000) {
task.AccNum = proto.SetUint32(task.GetAccNum() + count)
times = task.GetAccNum() / task.GetParam()
if times > 0 {
task.AccNum = proto.SetUint32(task.GetAccNum() % task.GetParam())
addTaskTimes(asset, task, times, userData)
}
}
write = true
}
}
return write
})
}
func handleLeagueHelpEvent(params []interface{}) {
handleCommonActivityTaskEvent(proto.ActivityTaskType_ATT_LeagueHelp, params)
}
func handleLeagueTechEvent(params []interface{}) {
handleCommonActivityTaskEvent(proto.ActivityTaskType_ATT_LeagueTech, params)
}
func handleResearchEvent(params []interface{}) {
handleCommonActivityTaskEvent(proto.ActivityTaskType_ATT_Research, params)
}
func handleBuildingUpgradeEvent(params []interface{}) {
handleCommonActivityTaskEvent(proto.ActivityTaskType_ATT_BuildingUpgrade, params)
}
func handleKillMonsterEvent(params []interface{}) {
handleCommonActivityTaskEvent(proto.ActivityTaskType_ATT_KillMonster, params)
}
func handleAttackMonsterEvent(params []interface{}) {
handleCommonActivityTaskEvent(proto.ActivityTaskType_ATT_AttackMonster, params)
}
func handleBlackMarketEvent(params []interface{}) {
handleCommonActivityTaskEvent(proto.ActivityTaskType_ATT_BlackMarket, params)
}
func handleSupplyEvent(params []interface{}) {
handleCommonActivityTaskEvent(proto.ActivityTaskType_ATT_Supply, params)
}
func handleMapListEvent(params []interface{}) {
handleCommonActivityTaskEvent(proto.ActivityTaskType_ATT_MapList, params)
}
func handleActivityTaskDispatchTaskEvent(params []interface{}) {
handleCommonActivityTaskEvent(proto.ActivityTaskType_ATT_DispatchTask, params)
}
func handleActivityTaskLeagueTaskEvent(params []interface{}) {
handleCommonActivityTaskEvent(proto.ActivityTaskType_ATT_LeagueTask, params)
}
func handleHeroEvent(params []interface{}) {
handleCommonActivityTaskEvent(proto.ActivityTaskType_ATT_UseHeroExpItem, params)
}
func handleCommonActivityTaskEvent(eventType proto.ActivityTaskType, params []interface{}) {
if len(params) < 2 {
wlog.Error(eventType, " params err")
return
}
userData, ok := params[0].(*cache.Info)
if !ok {
wlog.Error(eventType, " params 0 err")
return
}
count, ok := params[1].(uint32)
if !ok {
wlog.Error(eventType, " params 1 err")
return
}
if eventType == proto.ActivityTaskType_ATT_KillMonster {
count = 1
}
userData.WithActivityTaskAsset(false, func(asset *proto.ST_Asset_ActivityTask_PB) bool {
write := false
for _, task := range asset.GetTasks() {
if task.GetCurrentTimes() < task.GetTargetTimes() &&
task.GetType() == uint32(eventType) {
addTaskTimes(asset, task, count, userData)
write = true
}
}
return write
})
}
func handleCommonActivityTaskEvent2(eventType int32, params []interface{}) {
userData, ok := params[0].(*cache.Info)
if !ok {
wlog.Error(eventType, " params 0 err")
return
}
userData.WithActivityTaskAsset(false, func(asset *proto.ST_Asset_ActivityTask_PB) bool {
write := false
for _, task := range asset.GetTasks() {
taskConf := CSV.Mgr.CSV_ActivityTask.GetEntryPtr(int64(task.GetId()))
if taskConf != nil {
arg := common.ParseParameterStringToMap(taskConf.SubType)
if task.GetCurrentTimes() < task.GetTargetTimes() && eventType == common.StringToInt32(arg["type"]) {
if eventType == observer.TakeCardEvent && len(params) > 2 {
if cardPoolID, ok := params[2].(uint32); ok {
if arg["cardPoolID"] == "" {
addTaskTimes(asset, task, 1, userData)
write = true
} else if common.StringToUint32(arg["cardPoolID"]) == cardPoolID {
addTaskTimes(asset, task, 1, userData)
write = true
}
}
} else if eventType == observer.Event_50021 && len(params) > 2 {
if count, ok := params[2].(uint64); ok {
task.AccNum = proto.SetUint32(task.GetAccNum() + uint32(count))
times := task.GetAccNum() / task.GetParam()
if times > 0 {
task.AccNum = proto.SetUint32(task.GetAccNum() % task.GetParam())
addTaskTimes(asset, task, times, userData)
}
write = true
}
} else if eventType == observer.UseItemEvent && len(params) > 2 {
if itemTypeID, ok := params[1].(uint32); ok {
conf := CSV.Mgr.CSV_ItemList.GetEntryPtr(int64(itemTypeID))
if nil != conf && common.StringToInt64(arg["ItemMainType"]) == conf.ItemMainType {
if itemCount, ok := params[2].(uint32); ok {
if arg["ItemSubType"] == "" {
addTaskTimes(asset, task, uint32(itemCount), userData)
write = true
} else if common.StringToInt64(arg["ItemSubType"]) == conf.ItemSubType {
addTaskTimes(asset, task, uint32(itemCount), userData)
write = true
}
}
}
}
}
}
}
}
return write
})
}
func handleCollectEvent(params []interface{}) {
if len(params) < 4 {
wlog.Error("handleCollectEvent params err")
return
}
userData, ok := params[0].(*cache.Info)
if !ok {
wlog.Error("handleCollectEvent params 0 err")
return
}
cashType, ok := params[1].(uint32)
if !ok {
wlog.Error("handleCollectEvent params 1 err")
return
}
cashCount, ok := params[3].(uint32)
if !ok {
wlog.Error("handleCollectEvent params 2 err")
return
}
times := uint32(0)
userData.WithActivityTaskAsset(false, func(asset *proto.ST_Asset_ActivityTask_PB) bool {
write := false
for _, task := range asset.GetTasks() {
if task.GetCurrentTimes() < task.GetTargetTimes() {
if (task.GetType() == uint32(proto.ActivityTaskType_ATT_CollectMetal) && cashType == 1) ||
(task.GetType() == uint32(proto.ActivityTaskType_ATT_CollectCrystal) && cashType == 2) ||
(task.GetType() == uint32(proto.ActivityTaskType_ATT_CollectGas) && cashType == 3) ||
(task.GetType() == uint32(proto.ActivityTaskType_ATT_CollectDeuterium) && cashType == 4) ||
(task.GetType() == uint32(proto.ActivityTaskType_ATT_CollectCoke) && cashType == 5) {
task.AccNum = proto.SetUint32(task.GetAccNum() + cashCount)
times = task.GetAccNum() / task.GetParam()
if times > 0 {
task.AccNum = proto.SetUint32(task.GetAccNum() % task.GetParam())
addTaskTimes(asset, task, times, userData)
}
write = true
}
}
}
return write
})
}
func addTaskTimes(asset *proto.ST_Asset_ActivityTask_PB, task *proto.ST_ActivityTask_Item, count uint32, userData *cache.Info) {
if count+task.GetCurrentTimes() > task.GetTargetTimes() {
count = task.GetTargetTimes() - task.GetCurrentTimes()
}
if count == 0 {
return
}
task.CurrentTimes = proto.SetUint32(task.GetCurrentTimes() + count)
if task.GetCurrentTimes() >= task.GetTargetTimes() {
taskPower := uint32(0)
observer.ObserverSingleton.AsyncNotify(observer.ActivityTaskEvent, []interface{}{userData})
observer.ObserverSingleton.AsyncNotify(observer.UserTaskFinishEvent, []interface{}{userData, uint32(proto.GameTaskType_GTT_ActPoint), taskPower})
cache.NewOssTaskFinish(userData, uint32(proto.GameTaskType_GTT_ActPoint), task.GetId(), []*proto.ST_Vector4Int_PB{})
}
taskConf := CSV.Mgr.CSV_ActivityTask.GetEntryPtr(int64(task.GetId()))
if taskConf != nil {
asset.TotalScore = proto.SetUint32(asset.GetTotalScore() + uint32(taskConf.Integral)*count)
}
newOssActivityRecord(userData, task.GetId(), uint32(oss.UAOP_Task), asset.GetTotalScore(), uint32(taskConf.Integral)*count, task.GetTargetTimes(), task.GetCurrentTimes(), 0)
}
func GetActivityTaskBoxReward(uid uint64, boxIdx uint32) proto.RetActionType {
userData := cache.GetCharinfo(uid)
if nil == userData {
return proto.RetActionType_RAT_INPUT_ERROR
}
ret := proto.RetActionType_RAT_INPUT_ERROR
userData.WithActivityTaskAsset(false, func(asset *proto.ST_Asset_ActivityTask_PB) bool {
for _, v := range asset.GetRewardedBoxIdxs() {
if boxIdx == v {
return false
}
}
rewards := getActivityTaskCanRewardBoxIdxs(asset.GetTotalScore(), asset.GetMainCityLevel())
for k, dropId := range rewards {
if k == boxIdx {
items := CSV.GetDropItem(int32(dropId))
for _, item := range items {
userData.AddItem(item.GetItemId(), item.GetItemNum(), oss.AddCashSrcActivityTask)
}
asset.RewardedBoxIdxs = append(asset.RewardedBoxIdxs, k)
ret = proto.RetActionType_RAT_SUCCESS
userData.DirtyAll()
newOssActivityRecord(userData, 0, uint32(oss.UAOP_Box), 0, 0, 0, 0, boxIdx)
return true
}
}
return false
})
return ret
}
func getActivityTaskCanRewardBoxIdxs(score, mainCityLevel uint32) map[uint32]uint32 {
idxs := make(map[uint32]uint32, 0)
conf := CSV.GetActivityBoxRewardCfg(int64(mainCityLevel))
if nil == conf {
return idxs
}
rewards := common.ParseStringToVector2(conf.Rewards)
for k, v := range rewards {
if v.GetX() <= int32(score) {
idxs[uint32(k)] = uint32(v.GetY())
}
}
return idxs
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liuxuezhan/mylib.git
git@gitee.com:liuxuezhan/mylib.git
liuxuezhan
mylib
mylib
v1.1.1

搜索帮助

344bd9b3 5694891 D2dac590 5694891