代码拉取完成,页面将自动刷新
package logic
import (
"fmt"
"sync/atomic"
csv "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/httputils"
"gitee.com/liuxuezhan/mylib/wtime"
)
func ProcessActionCommand(actionParameter *ActionParameter, respon *httputils.Respon) {
var rettype proto.RetActionType
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
rettype = proto.RetActionType_RAT_INPUT_ERROR
respon.Add("status", rettype)
return
}
userData.Lock()
defer userData.Unlock()
switch actionParameter.ActionType {
case uint32(proto.ActionType_AT_MISC_SPEEDUP_CASH):
rettype = processSpeedUpActionCash(actionParameter)
case uint32(proto.ActionType_AT_MISC_SPEEDUP_ITEM):
rettype = processSpeedUpLocalOrGlobalActionItem(actionParameter)
case uint32(proto.ActionType_AT_MISC_BUILD_DESTROY):
rettype = destroyBuilding(actionParameter.Uid, actionParameter.BuildingID)
case uint32(proto.ActionType_AT_MISC_BUILD_CANCEL):
rettype = cancelAction(actionParameter.Uid, actionParameter.ActionID)
case uint32(proto.ActionType_AT_MISC_RECALL):
rettype = processRecallArmy(actionParameter.Uid, actionParameter.GActionID)
case uint32(proto.ActionType_AT_MISC_PRODUCTION_UNIT_CANCEL):
rettype = cancelAction(actionParameter.Uid, actionParameter.ActionID)
case uint32(proto.ActionType_AT_MISC_RESEARCH_RESET):
rettype = resetResearch(actionParameter.Uid)
case uint32(proto.ActionType_AT_MISC_BUILD_EMPTY_CASH):
rettype = processBuildEmptyCash(actionParameter)
case uint32(proto.ActionType_AT_MISC_BUILD_LEVELUP_CASH):
rettype = processBuildUpgradeCash(actionParameter)
case uint32(proto.ActionType_AT_MISC_PRODUCTION_UNIT_CASH):
rettype = processUnitCash(actionParameter)
case uint32(proto.ActionType_AT_MISC_REQUEST_HELP):
rettype = processRequestHelp(actionParameter)
case uint32(proto.ActionType_AT_MISC_HELPALL):
rettype = processHelpAll(actionParameter)
case uint32(proto.ActionType_AT_MISC_CANCEL_MASS):
rettype = processDissolveMass(actionParameter.Uid, actionParameter.GActionID)
case uint32(proto.ActionType_AT_MISC_USEITEMONHERO):
rettype = doItemFunc_AddHeroExp(actionParameter.Uid, actionParameter.ItemTypeID,
actionParameter.ItemCount, actionParameter.HeroIDList, actionParameter.SkillID)
case uint32(proto.ActionType_AT_MISC_SPEEDUP_FREE):
rettype = processSpeedUpActionFree(actionParameter)
case uint32(proto.ActionType_AT_MISC_IGNORERADAR):
rettype = processIgnoreRadar(actionParameter)
case uint32(proto.ActionType_AT_MISC_CLEARLEAGUEGIFT):
rettype = processClearLeagueGift(actionParameter)
case uint32(proto.ActionType_AT_MISC_CURE_CASH):
rettype = processCureCash(actionParameter)
case uint32(proto.ActionType_AT_MISC_RESEARCH_CASH):
rettype = processResearchCash(actionParameter)
case uint32(proto.ActionType_AT_MISC_MOVEBUILDING):
rettype = processMoveBuilding(actionParameter)
case uint32(proto.ActionType_AT_MISC_RECEIVEALLRESOURCE):
rettype = processReceiveResource(actionParameter)
case uint32(proto.ActionType_AT_MISC_TALENT_LEVELUP):
rettype = processTalentLevelUp(actionParameter)
case uint32(proto.ActionType_AT_MISC_TALENT_UNLOCK):
rettype = processTalentUnlock(actionParameter)
case uint32(proto.ActionType_AT_MISC_USE_SKILL):
rettype = processUseSkill(actionParameter)
case uint32(proto.ActionType_AT_MISC_RESET_TALENT):
rettype = processResetTalent(actionParameter)
case uint32(proto.ActionType_AT_MISC_TALENT_MAX):
rettype = processTalentMax(actionParameter)
case uint32(proto.ActionType_AT_MISC_RECEIVE_UNITS):
rettype = processreceiveunits(actionParameter, respon)
case uint32(proto.ActionType_AT_MISC_ABANDONING_TREATMENT):
rettype = processAbandoningTreatment(actionParameter)
case uint32(proto.ActionType_AT_MISC_READRADAR):
rettype = processReadRadar(actionParameter)
case uint32(proto.ActionType_AT_MISC_HELPSINGLE):
rettype = processSingleHelp(actionParameter)
case uint32(proto.ActionType_AT_MISC_UPGRADE_UNIT_CASH):
rettype = processUnitUpgradeCash(actionParameter)
case uint32(proto.ActionType_AT_MISC_TRAP_REMOVE):
rettype = processTrapRemove(actionParameter)
// case uint32(proto.ActionType_AT_MISC_STATUE_ENHANCE):
// rettype = processStatue(actionParameter)
case uint32(proto.ActionType_AT_MISC_FACTORY_COMPOSE):
rettype = processFactoryCompose(actionParameter, respon)
case uint32(proto.ActionType_AT_MISC_FACTORY_DECOMPOSE):
rettype = processFactoryDecompose(actionParameter, respon)
case uint32(proto.ActionType_AT_MISC_FACTORY_RECEIVE):
rettype = processReceiveCommanderEquip(actionParameter, respon)
case uint32(proto.ActionType_AT_MISC_FACTORY_MAKE_CASH):
rettype = processFactoryCashMake(actionParameter)
case uint32(proto.ActionType_AT_MISC_BUILD_RECYCLING):
rettype = recyclingBuilding(actionParameter.Uid, actionParameter.BuildingID, respon)
case uint32(proto.ActionType_AT_MISC_BUILD_RECYCLING_LIST):
rettype = recyclingBuildingList(actionParameter.Uid, actionParameter.BuildingIDList, respon)
case uint32(proto.ActionType_AT_MISC_HERO_DEFENSE):
processHeroDefenseOp(actionParameter.Uid, actionParameter.HeroIDList, actionParameter.DefenseOp, actionParameter.DefensePos)
case uint32(proto.ActionType_AT_MISC_MOVEBUILDING_LIST):
rettype = processMoveBuildingList(actionParameter)
case uint32(proto.ActionType_AT_MISC_MAIN_HP):
userData.WithDefenceAsset(false, func(defense *proto.ST_DefenseAsset_PB) bool {
if wtime.GetNow() < defense.GetHpTime() {
return false
}
add := uint64(csv.GetGameConfigValueUint32("WALL_HP_RECOVERY"))
max := GetMaxHp(userData)
if defense.GetHp()+add > max {
defense.Hp = proto.SetUint64(max)
} else {
defense.Hp = proto.SetUint64(defense.GetHp() + add)
}
defense.HpTime = proto.SetUint64(wtime.GetNow() + 30*60)
userData.DirtyAll()
return true
})
case uint32(proto.ActionType_AT_MISC_CAMP_LEADER):
rettype = processChangeCampLeader(actionParameter.Uid, actionParameter.TargetUid, uint64(actionParameter.ActionID))
default:
wlog.Error("Unknow action type ,", actionParameter.ActionType)
}
respon.Add("status", rettype)
}
func processreceiveunits(actionParameter *ActionParameter, respon *httputils.Respon) proto.RetActionType {
tmpInfo := cache.GetCharinfo(actionParameter.Uid)
if tmpInfo == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
buildingid := actionParameter.BuildingID
buildingAsset := tmpInfo.GetBuildingAssetByBuildingId(buildingid)
if buildingAsset == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
units := proto.Clone(buildingAsset.GetUnits()).(*proto.ST_UnitAsset_PB)
tmpInfo.AddUnitAssets(units)
if buildingAsset.GetBuildingtype() != 1060000 {
tmpInfo.AddUnitCountAssets(buildingAsset.GetUnits())
}
var power uint64
var count uint32
csvbuildingConfig := csv.Mgr.CSV_BuildingConfig.GetEntryPtr(int64(buildingAsset.GetBuildingtype()))
for _, v := range buildingAsset.GetUnits().GetUnits() {
// 数据上报
newOssUnitChange(tmpInfo, oss.UnitChangeTypeProduct, v.GetUnitid(), int32(v.GetUnitnum()), 0)
count += uint32(v.GetUnitnum())
conf := csv.Mgr.CSV_UnitConfig.GetEntryPtr(int64(v.GetUnitid()))
if nil != conf {
del_power := int64(0)
csvOld := csv.GetUnitUpgradeEntry(uint32(conf.Type), uint32(v.GetLv()))
if nil != csvOld {
del_power = csvOld.Power
}
power += uint64(conf.Power-del_power) * v.GetUnitnum()
}
if csvbuildingConfig != nil && csvbuildingConfig.Type != int64(proto.BuildingType_BT_HOSPITAL) {
observer.ObserverSingleton.AsyncNotify(observer.ReceiveUnitEvent, []interface{}{
tmpInfo, v.GetUnitid(), uint32(v.GetUnitnum()), uint32(conf.UnitLevel), uint32(power), uint32(conf.UnitPosType)})
}
}
observer.ObserverSingleton.AsyncNotify(observer.ActivityTaskReceiveUnitEvent, []interface{}{tmpInfo, csvbuildingConfig, count})
if power != 0 {
tmpInfo.AddTips(11000121, common.Uint64ToString(power))
}
tmpInfo.CalcPower()
if buildingAsset.GetUnits() != nil {
respon.Add("unit", units)
}
tmpInfo.DeleteUnitFromBuilding(buildingid, units)
return proto.RetActionType_RAT_SUCCESS
}
func processTalentMax(actionParameter *ActionParameter) proto.RetActionType {
tmpInfo := cache.GetCharinfo(actionParameter.Uid)
if tmpInfo == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
talentID := actionParameter.TalentID
researchConfig := csv.Mgr.CSV_Talent.GetEntryPtr(int64(talentID))
var userNowResearchConfig *csv.CF_TalentLevelUp_DataEntry
ori_talentId := tmpInfo.GetTalentIDByType(uint32(researchConfig.FuncType))
ori_researchConfig := csv.Mgr.CSV_Talent.GetEntryPtr(int64(ori_talentId))
var ori_power int64
if ori_researchConfig != nil {
ori_power = ori_researchConfig.TalentPower
}
var power int64
for {
researchConfig = csv.Mgr.CSV_Talent.GetEntryPtr(int64(talentID))
if nil == researchConfig {
break
}
//>>>下一个等级
nextLevelId := researchConfig.NextLevelID
//>>>检查已有的科研是否连续升级
if nextResearchConfig := csv.Mgr.CSV_Talent.GetEntryPtr(nextLevelId); nil != nextResearchConfig {
rType := uint32(nextResearchConfig.FuncType)
rLevel := uint32(nextResearchConfig.TalentLevel)
if rLevel > 2 {
hasRID := tmpInfo.GetTalentIDByType(rType)
tmpConfig := csv.Mgr.CSV_Talent.GetEntryPtr(int64(hasRID))
if tmpConfig == nil || tmpConfig.NextLevelID != int64(talentID) {
break
}
}
} else {
if nextLevelId != 0 {
break
}
}
researchCondition := common.ParseStringToVector4(researchConfig.LevelUpCondition)
if !checkVector4Conditions(tmpInfo, researchCondition) {
break
}
if !tmpInfo.CheckTalentPoint(uint32(researchConfig.RequestPoint)) {
break
}
tmpInfo.ReduceTalentPoint(uint32(researchConfig.RequestPoint))
tmpInfo.AddTalentAsset(uint32(researchConfig.FuncType), uint32(researchConfig.ID))
userNowResearchConfig = researchConfig
power = researchConfig.TalentPower
tmpInfo.CalcPower()
// 数据上报
observer.ObserverSingleton.AsyncNotify(observer.LordTalentEvent, []interface{}{tmpInfo})
tmpInfo.SetFirstLordPage(false)
if 0 == uint32(nextLevelId) {
break
}
talentID = uint32(nextLevelId)
}
if power > ori_power {
tmpInfo.AddTips(11000121, common.Int64ToString(power-ori_power))
}
if ori_researchConfig != nil {
if researchConfig.WhetherSkill == 0 {
if tmpInfo.GetCommanderStatus() == uint32(proto.HeroStatus_HS_NORMAL) {
cache.ReduceAttribute(tmpInfo, ori_researchConfig.Function, uint32(proto.AttributeSource_Talent)) //ok
}
} else {
tmpInfo.DeleteSkill(uint32(ori_researchConfig.ID))
}
}
if userNowResearchConfig != nil {
if userNowResearchConfig.WhetherSkill == 0 {
if tmpInfo.GetCommanderStatus() == uint32(proto.HeroStatus_HS_NORMAL) {
cache.SetAttribute(tmpInfo, userNowResearchConfig.Function, uint32(proto.AttributeSource_Talent)) //ok
}
} else {
tmpInfo.AddSkill(uint32(userNowResearchConfig.ID))
}
}
return proto.RetActionType_RAT_SUCCESS
}
func processResetTalent(actionParameter *ActionParameter) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
userData.ResetTalent()
// 数据上报
newOssTalentLevelUp(userData, 0, 0, userData.GetCanUseTalentPoint(), 0, 0)
userData.ResetSkill()
userData.CalcPower()
return proto.RetActionType_RAT_SUCCESS
}
func processUseSkill(actionParameter *ActionParameter) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
if userData.GetCommanderStatus() == uint32(proto.HeroStatus_HS_IMPRISONED) || userData.GetCommanderStatus() == uint32(proto.HeroStatus_HS_DEATH) {
return proto.RetActionType_RAT_INPUT_ERROR
}
if !useSkill(userData, actionParameter.SkillID) {
return proto.RetActionType_RAT_INPUT_ERROR
}
return proto.RetActionType_RAT_SUCCESS
}
func TestUnlockTalent(uid uint64) {
talentList := &proto.ST_Vector2IntList_PB{
List: make([]*proto.ST_Vector2Int_PB, 0),
}
talentList.List = append(talentList.List, &proto.ST_Vector2Int_PB{X: proto.SetInt32(3001), Y: proto.SetInt32(2300105)})
talentList.List = append(talentList.List, &proto.ST_Vector2Int_PB{X: proto.SetInt32(3002), Y: proto.SetInt32(2300203)})
talentList.List = append(talentList.List, &proto.ST_Vector2Int_PB{X: proto.SetInt32(3003), Y: proto.SetInt32(2300303)})
talentList.List = append(talentList.List, &proto.ST_Vector2Int_PB{X: proto.SetInt32(3004), Y: proto.SetInt32(2300402)})
strTest := common.Base64Encode(string(proto.Marshal(talentList)))
actionParameter := &ActionParameter{
Uid: uid,
UnlockTalent: strTest,
}
processTalentUnlock(actionParameter)
}
/**
@brief 天赋解锁
*/
func processTalentUnlock(actionParameter *ActionParameter) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
oldPower := userData.CalcTelentPower()
talentList := &proto.ST_Vector2IntList_PB{} //需要解锁的天赋类型和对应等级的ID
proto.Unmarshal([]byte(common.Base64Decode(actionParameter.UnlockTalent)), talentList)
for _, talent := range talentList.List {
targetTalentType := talent.GetX()
targetTalentID := talent.GetY()
talentID := int64(0)
/*
先检查当前类型的天赋是否已解锁
如果已解锁,再升级目标等级,用于达到解锁下一个天赋的条件
*/
hasTalentID := userData.GetTalentIDByType(uint32(targetTalentType))
hasTalentConfig := csv.Mgr.CSV_Talent.GetEntryPtr(int64(hasTalentID))
if hasTalentConfig != nil {
talentID = hasTalentConfig.NextLevelID
} else {
if v, ok := csv.Mgr.TalentConfigMap[int64(targetTalentType)]; ok {
talentID = v.TelentIDList[0]
}
}
for {
//循环添加天赋等级,直到等于targetTalentID
talentConfig := csv.Mgr.CSV_Talent.GetEntryPtr(talentID)
if nil == talentConfig {
break
}
talentPoint := uint32(talentConfig.RequestPoint)
researchCondition := common.ParseStringToVector4(talentConfig.LevelUpCondition)
if !checkVector4Conditions(userData, researchCondition) {
return proto.RetActionType_RAT_CON_BUILDING_ERROR
}
if !userData.CheckTalentPoint(talentPoint) {
return proto.RetActionType_RAT_CON_RESOURCE_ERROR
}
//如果已存在当前类型的天赋,则需要删除其属性加成或者技能
//后续添加最终属性或者技能
if hasTalentConfig != nil {
if hasTalentConfig.WhetherSkill == 0 {
if userData.GetCommanderStatus() == uint32(proto.HeroStatus_HS_NORMAL) {
cache.ReduceAttribute(userData, hasTalentConfig.Function, uint32(proto.AttributeSource_Talent)) //ok
}
} else {
userData.DeleteSkill(uint32(hasTalentConfig.ID))
}
}
userData.ReduceTalentPoint(talentPoint)
userData.AddTalentAsset(uint32(targetTalentType), uint32(talentID))
// 数据上报
observer.ObserverSingleton.AsyncNotify(observer.LordTalentEvent, []interface{}{userData})
userData.SetFirstLordPage(false)
//天赋升级到目标等级后,添加对应的技能或者天赋
if int64(targetTalentID) == talentConfig.ID {
if talentConfig.WhetherSkill == 0 {
if userData.GetCommanderStatus() == uint32(proto.HeroStatus_HS_NORMAL) {
cache.SetAttribute(userData, talentConfig.Function, uint32(proto.AttributeSource_Talent)) //ok
}
} else {
userData.AddSkill(uint32(talentConfig.ID))
}
break
} else {
talentID = talentConfig.NextLevelID
}
}
}
newPower := userData.CalcTelentPower()
if newPower > oldPower {
userData.AddTips(11000121, common.Uint64ToString(newPower-oldPower))
}
userData.CalcPower()
return proto.RetActionType_RAT_SUCCESS
}
func processTalentLevelUp(actionParameter *ActionParameter) proto.RetActionType {
tmpInfo := cache.GetCharinfo(actionParameter.Uid)
if tmpInfo == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
researchConfig := csv.Mgr.CSV_Talent.GetEntryPtr(int64(actionParameter.TalentID))
if nil == researchConfig {
return proto.RetActionType_RAT_INTERNAL_ERROR
}
ori_talentId := tmpInfo.GetTalentIDByType(uint32(researchConfig.FuncType))
ori_researchConfig := csv.Mgr.CSV_Talent.GetEntryPtr(int64(ori_talentId))
var ori_power int64
if ori_researchConfig != nil {
ori_power = ori_researchConfig.TalentPower
}
//>>>下一个等级
nextLevelId := researchConfig.NextLevelID
//>>>检查已有的科研是否连续升级
if nextResearchConfig := csv.Mgr.CSV_Talent.GetEntryPtr(nextLevelId); nil != nextResearchConfig {
rType := uint32(nextResearchConfig.FuncType)
rLevel := uint32(nextResearchConfig.TalentLevel)
if rLevel > 2 {
hasRID := tmpInfo.GetTalentIDByType(rType)
tmpConfig := csv.Mgr.CSV_Talent.GetEntryPtr(int64(hasRID))
if tmpConfig == nil || tmpConfig.NextLevelID != int64(actionParameter.TalentID) {
return proto.RetActionType_RAT_INPUT_ERROR
}
}
} else {
if nextLevelId != 0 {
return proto.RetActionType_RAT_INPUT_ERROR
}
}
researchCondition := common.ParseStringToVector4(researchConfig.LevelUpCondition)
if !checkVector4Conditions(tmpInfo, researchCondition) {
return proto.RetActionType_RAT_CON_BUILDING_ERROR
}
if !tmpInfo.CheckTalentPoint(uint32(researchConfig.RequestPoint)) {
return proto.RetActionType_RAT_CON_RESOURCE_ERROR
}
if ori_researchConfig != nil {
if ori_researchConfig.WhetherSkill == 0 {
if tmpInfo.GetCommanderStatus() == uint32(proto.HeroStatus_HS_NORMAL) {
cache.ReduceAttribute(tmpInfo, ori_researchConfig.Function, uint32(proto.AttributeSource_Talent)) //ok
}
} else {
tmpInfo.DeleteSkill(uint32(ori_researchConfig.ID))
}
}
if researchConfig.WhetherSkill == 0 {
if tmpInfo.GetCommanderStatus() == uint32(proto.HeroStatus_HS_NORMAL) {
cache.SetAttribute(tmpInfo, researchConfig.Function, uint32(proto.AttributeSource_Talent)) //ok
}
} else {
tmpInfo.AddSkill(uint32(researchConfig.ID))
}
tmpInfo.ReduceTalentPoint(uint32(researchConfig.RequestPoint))
tmpInfo.AddTalentAsset(uint32(researchConfig.FuncType), uint32(researchConfig.ID))
//tmpInfo.AddPower()
if researchConfig.TalentPower > ori_power {
tmpInfo.AddTips(11000121, common.Int64ToString(researchConfig.TalentPower-ori_power))
}
tmpInfo.CalcPower()
// 数据上报
observer.ObserverSingleton.AsyncNotify(observer.LordTalentEvent, []interface{}{tmpInfo})
tmpInfo.SetFirstLordPage(false)
return proto.RetActionType_RAT_SUCCESS
}
func processReceiveResource(actionParameter *ActionParameter) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
for _, v := range userData.GetNeedReceiveResource() {
userData.AddCashAsset(v.GetResource(), oss.AddCashSrcTypeReceiveAllResource)
}
userData.ReceiveResource()
return proto.RetActionType_RAT_SUCCESS
}
func processMoveBuildingList(actionParameter *ActionParameter) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
buildingidlist := common.Base64Decode(actionParameter.BuildingIDList)
idmsg := &proto.ST_Uint64List_PB{}
proto.Unmarshal([]byte(buildingidlist), idmsg)
tilelist := common.Base64Decode(actionParameter.TileIDList)
tilemsg := &proto.ST_Uint64List_PB{}
proto.Unmarshal([]byte(tilelist), tilemsg)
if len(idmsg.GetList()) != len(tilemsg.GetList()) {
return proto.RetActionType_RAT_INPUT_ERROR
}
for k, v := range idmsg.GetList() {
if tilemsg.GetList()[k] == 0 {
continue
}
buildingAsset := userData.GetBuildingAssetByBuildingId(uint32(v))
if buildingAsset == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
bConfig := csv.Mgr.CSV_BuildingConfig.GetEntryPtr(int64(buildingAsset.GetBuildingtype()))
if bConfig == nil {
return proto.RetActionType_RAT_INTERNAL_ERROR
}
tileid := uint32(tilemsg.GetList()[k])
x, y := common.ConvertMainCityIdToCoordinate(tileid)
width := uint32(bConfig.Width)
height := uint32(bConfig.Height)
if !cache.SafeCheckTileCanUse(userData, x, y, width, height) {
return proto.RetActionType_RAT_INPUT_ERROR
}
if !userData.CheckBuildingIndexWithID(tileid, width, height, actionParameter.BuildingID) {
return proto.RetActionType_RAT_INPUT_ERROR
}
userData.UpdateBuildingLocation(buildingAsset.GetBuildingID(), x, y)
// 数据上报
//ossBuildingMove(userData, o_tileid, tileid, buildingAsset.GetBuildinglevel(), buildingAsset.GetBuildingID(), uint64(buildingAsset.GetBuildingtype()))
//ossMainCityClick(userData, oss.CCT_MoveItem, fmt.Sprint(x), fmt.Sprint(y), 2, uint64(buildingAsset.GetBuildingtype()), nil)
}
return proto.RetActionType_RAT_SUCCESS
}
func processMoveBuilding(actionParameter *ActionParameter) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
buildingAsset := userData.GetBuildingAssetByBuildingId(actionParameter.BuildingID)
if buildingAsset == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
bConfig := csv.Mgr.CSV_BuildingConfig.GetEntryPtr(int64(buildingAsset.GetBuildingtype()))
if bConfig == nil {
return proto.RetActionType_RAT_INTERNAL_ERROR
}
tileid := uint32(actionParameter.TileID)
x, y := common.ConvertMainCityIdToCoordinate(tileid)
width := uint32(bConfig.Width)
height := uint32(bConfig.Height)
if !cache.SafeCheckTileCanUse(userData, x, y, width, height) {
return proto.RetActionType_RAT_INPUT_ERROR
}
if !userData.CheckBuildingIndexWithID(tileid, width, height, actionParameter.BuildingID) {
return proto.RetActionType_RAT_INPUT_ERROR
}
userData.UpdateBuildingLocation(buildingAsset.GetBuildingID(), x, y)
// 数据上报
newOssUserChangeInfo(userData, 7, "", common.ConvertToString(buildingAsset.GetBuildingID()))
return proto.RetActionType_RAT_SUCCESS
}
func processClearLeagueGift(actionParameter *ActionParameter) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
userData.ClearLeagueGift()
return proto.RetActionType_RAT_SUCCESS
}
func processIgnoreRadar(actionParameter *ActionParameter) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
userData.DeleteRadarAsset(actionParameter.GActionID)
return proto.RetActionType_RAT_SUCCESS
}
func processRecallArmy(uid, actionid uint64) proto.RetActionType {
actionData := cache.Instance_GlobalAssetGlobalAction.GetGlobalActionAsset(actionid)
if actionData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
if actionData.Actiondata.GetUid() != uid {
return proto.RetActionType_RAT_INPUT_ERROR
}
userData := cache.GetCharinfo(uid)
//检查道具
var (
itemID uint32 = 0
)
if actionData.Actiondata.GetActiontype() == uint32(proto.ActionType_AT_WORLDMAP_ATTCK) || actionData.Actiondata.GetActiontype() == uint32(proto.ActionType_AT_WORLDMAP_MASS) {
if actionData.Actiondata.GetStage() == uint32(proto.MapStageType_MST_WORKING) || actionData.Actiondata.GetStage() == uint32(proto.MapStageType_MST_WAITBATTLE) {
return proto.RetActionType_RAT_INPUT_ERROR
}
}
if actionData.Actiondata.GetActiontype() == uint32(proto.ActionType_AT_WORLDMAP_JOINMASS) {
itemID = 5120015
} else {
if actionData.Actiondata.GetStage() == uint32(proto.MapStageType_MST_MARCH) {
itemID = 5120016
}
}
if itemID != 0 {
entry := csv.Mgr.CSV_ItemList.GetEntryPtr(int64(itemID))
if nil == entry {
return proto.RetActionType_RAT_INPUT_ERROR
}
ret := proto.RetActionType_RAT_SUCCESS
useType := 1
//检查道具
if !userData.CheckItem(uint32(itemID), 1) {
ret = proto.RetActionType_RAT_CON_ITEM_ERROR
}
//检查钻石
if proto.RetActionType_RAT_CON_ITEM_ERROR == ret {
useType = 2
ret = proto.RetActionType_RAT_SUCCESS
price := common.ParseStringToVector4(entry.SellPrice)
if !userData.CheckVec4ResourceList(price, 1) {
ret = proto.RetActionType_RAT_CON_RESOURCE_ERROR
}
}
if proto.RetActionType_RAT_SUCCESS != ret {
return ret
}
if 1 == useType {
userData.ReduceItem(uint32(entry.ID), 1, oss.ReduceCashSrcTypeUseItem)
userData.AddTips(11000005, int32(entry.ID), common.Uint32ToString(1))
} else if 2 == useType {
price := common.ParseStringToVector4(entry.SellPrice)
userData.ReduceVec4ResourceList(price, 1, oss.ReduceCashSrcTypeUseItem)
}
}
wdata := cache.Instance_GlobalAssetWorldData.GetWorldDataByTileId(actionData.Actiondata.GetEndTileID())
if nil == wdata {
wlog.Error(fmt.Sprintf("processRecallArmy:deleteRadar error uid:%v name:%v actionType:%v", userData.GetUid(), userData.GetUserName(), actionData.Actiondata.GetActiontype()))
} else {
actionIds := wdata.CopyGActionList()
if len(actionIds) > 0 {
actionAsset := cache.Instance_GlobalAssetGlobalAction.GetGlobalActionAsset(actionIds[0])
if actionAsset != nil {
recvActionIds := actionAsset.Actiondata.GetRecvActionIDList()
//获取出针对次地块的攻击、侦察、集结、援助行为
//然后从撤军的玩家的预警雷达中删除
for _, recvActionId := range recvActionIds {
wlog.Error("recvActionId ", recvActionId)
otherActionAsset := cache.Instance_GlobalAssetGlobalAction.GetGlobalActionAsset(recvActionId)
if nil == otherActionAsset {
continue
}
actionType := otherActionAsset.Actiondata.GetActiontype()
if actionType == uint32(proto.ActionType_AT_WORLDMAP_ATTCK) ||
actionType == uint32(proto.ActionType_AT_WORLDMAP_SPYINTO) ||
actionType == uint32(proto.ActionType_AT_WORLDMAP_MASS) ||
actionType == uint32(proto.ActionType_AT_WORLDMAP_GARRISON) {
deleteRadar(otherActionAsset.Actiondata)
}
}
}
}
processMiracleWarBack(wdata, actionid)
}
b := DelWarCityData(actionData.Actiondata.GetEndTileID(), actionid)
recallArmy(actionid, false)
targetType := getBattleTargetType(actionData.Actiondata)
if b {
if targetType == targetWarCity {
d := cache.Instance_GlobalAssetWorldData.GetWorldDataByTileId(actionData.Actiondata.GetEndTileID())
if d != nil && len(d.GetWorldData().SimpleEntry.GetGActionList()) == 0 {
d.UpdateOwner(0, 0)
}
}
}
if actionData.Actiondata.GetActiontype() == uint32(proto.ActionType_AT_WORLDMAP_GARRISON) &&
actionData.Actiondata.GetStage() == uint32(proto.MapStageType_MST_BACK) &&
(targetType == targetRayolCity || targetType == targetWarCity) {
cityData := cache.Instance_GlobalAssetWorldData.GetWorldData(actionData.Actiondata.GetWorldDataID())
if cityData != nil {
calcBigMiracleGarrsonCapAfterBattle(cityData)
}
}
recallArmyRefund(userData, actionData.Actiondata.GetActiontype(), actionid)
return proto.RetActionType_RAT_SUCCESS
}
//攻击alpha军团、机械兽、机械中枢打空或取消机械中枢集结,返还扣除的体力
func recallArmyRefund(userData *cache.Info, actionType uint32, actionid uint64) {
if actionType != uint32(proto.ActionType_AT_WORLDMAP_ATTCK) &&
actionType != uint32(proto.ActionType_AT_WORLDMAP_MASS) &&
actionType != uint32(proto.ActionType_AT_WORLDMAP_JOINMASS) {
return
}
actionData := cache.Instance_GlobalAssetGlobalAction.GetGlobalActionAsset(actionid)
if userData == nil || actionData == nil {
wlog.Error("recallArmyRefund userData == nil || actionData == nil")
return
}
costSta := actionData.Actiondata.GetCostSta()
bFind := false
if actionType == uint32(proto.ActionType_AT_WORLDMAP_MASS) {
for _, v := range actionData.Actiondata.GetChildrenID() {
tmpactiondata := cache.Instance_GlobalAssetGlobalAction.GetGlobalActionAsset(v)
if tmpactiondata == nil {
continue
}
if userData.GetUid() == tmpactiondata.Actiondata.GetUid() {
costSta = tmpactiondata.Actiondata.GetCostSta()
bFind = true
break
}
}
}
if !bFind && actionData.Actiondata.GetUid() != userData.GetUid() {
return
}
if costSta <= 0 {
return
}
addVal := addUserSta(userData, uint32(costSta), oss.OSGT_Refond, oss.CancelAtkRefond)
sTitle := common.CreateTips(77461)
sContent := &proto.ST_Tips_PB{}
if actionType == uint32(proto.ActionType_AT_WORLDMAP_ATTCK) {
if addVal > 0 {
sContent = common.CreateTips(77462, common.ConvertToString(addVal))
} else {
sContent = common.CreateTips(77482)
}
} else {
if addVal > 0 {
sContent = common.CreateTips(77463, common.ConvertToString(addVal))
} else {
sContent = common.CreateTips(77482)
}
}
userData.AddRewardLanguageIDMailAsset(uint32(proto.MailType_MT_SYSTEM), 0, int32(userData.GetUid()), int32(proto.MailSourceType_MST_Other),
oss.MRS_CancelAtkRefond, sTitle, sContent, "", "", "")
}
//Important 调用该函数的匿名回调函数中必须使用没有联盟资产锁的函数,否则会造成死锁
func withLeagueAndLocalActionLock(userData *cache.Info, actionid uint32, callback func(entry *proto.ST_LocalActionEntry_PB)) {
leagueData := cache.Instance_GlobalAssetLeague.GetLeagueData(userData.GetLeagueID())
if leagueData != nil {
leagueData.Lock()
defer leagueData.Unlock()
}
userData.SafeGetLocalAction(actionid, callback)
}
//Important 调用该函数的匿名回调函数中必须使用没有联盟资产锁的函数,否则会造成死锁
func withLeagueAndLocalActionLockForeach(userData *cache.Info, istrue bool, callback func(entry *proto.ST_LocalActionEntry_PB) bool) {
leagueData := cache.Instance_GlobalAssetLeague.GetLeagueData(userData.GetLeagueID())
if leagueData != nil {
leagueData.Lock()
defer leagueData.Unlock()
}
userData.SafeForeachLocalAction(istrue, callback)
}
func processRequestHelp(actionParameter *ActionParameter) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
leagueID := userData.GetLeagueID()
if leagueID == 0 {
return proto.RetActionType_RAT_INPUT_ERROR
}
bid, _ := userData.GetMaxBuildingInfoByBuildingConfigType(int64(proto.BuildingType_BT_LEAGUECENTER))
if bid == 0 {
return proto.RetActionType_RAT_CON_BUILDING_ERROR
}
ret := proto.RetActionType_RAT_SUCCESS
withLeagueAndLocalActionLock(userData, actionParameter.ActionID, func(localAction *proto.ST_LocalActionEntry_PB) {
if localAction == nil || localAction.GetIsHelped() {
ret = proto.RetActionType_RAT_INPUT_ERROR
return
}
var maxAcceptCount uint32 //单次任务可接受最大被帮助次数
bFunction := userData.GetBuildingFuctionByConfigType(int64(proto.BuildingType_BT_LEAGUECENTER))
var buildingtype, level, techid uint32
switch localAction.GetActiontype() {
case uint32(proto.ActionType_AT_BUILD_EMPTY):
fallthrough
case uint32(proto.ActionType_AT_BUILD_LEVELUP):
details := localAction.GetDetails()
if len(details) < 2 {
ret = proto.RetActionType_RAT_INTERNAL_ERROR
return
}
buildingtype = uint32(details[0])
level = uint32(details[1])
maxAcceptCount = common.StringToUint32(bFunction["BuHelpNumber"])
case uint32(proto.ActionType_AT_RESEARCH_START):
details := localAction.GetDetails()
if len(details) < 1 {
ret = proto.RetActionType_RAT_INTERNAL_ERROR
return
}
techid = uint32(details[0])
maxAcceptCount = common.StringToUint32(bFunction["ReHelpNumber"])
case uint32(proto.ActionType_AT_PRODUCTION_CURE):
maxAcceptCount = common.StringToUint32(bFunction["CuHelpNumber"])
default:
ret = proto.RetActionType_RAT_INPUT_ERROR
return
}
//单次任务可接受最大被帮助次数Buff加成
maxAcceptCount += userData.GetAttributeByType(proto.AtttibuteType_UnionHelp) //ok
leagueHelp := &proto.ST_League_Help_Info_PB{
HelperID: make([]uint64, 0),
Simple: &proto.ST_League_Help_Simple_PB{
Basic: &proto.ST_LeagueHelpBaisc_PB{
Uid: proto.SetUint64(actionParameter.Uid),
ActionID: proto.SetUint32(localAction.GetActionid()),
},
ActionType: proto.SetUint32(localAction.GetActiontype()),
HelpCount: proto.SetUint32(0),
BuildingType: proto.SetUint32(buildingtype),
BuildingLevel: proto.SetUint32(level),
TechID: proto.SetUint32(techid),
Username: proto.SetString(userData.GetUserName()),
MaxCount: proto.SetUint32(maxAcceptCount),
},
}
cache.Instance_GlobalAssetLeague.UnsafeAddLeagueHelp(leagueID, leagueHelp)
notifyHelpToMembers(leagueID, actionParameter.Uid, localAction.GetActionid(), true)
userData.HelpedLocalAction(localAction.GetActionid())
})
return ret
}
func processSingleHelp(actionParameter *ActionParameter) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
leagueID := userData.GetLeagueID()
if leagueID == 0 {
return proto.RetActionType_RAT_INPUT_ERROR
}
leagueData := cache.Instance_GlobalAssetLeague.GetLeagueData(leagueID)
if leagueData == nil {
return proto.RetActionType_RAT_SUCCESS
}
ret := proto.RetActionType_RAT_INPUT_ERROR
leagueMemberLevel := cache.Instance_GlobalAssetLeague.GetMemberLevel(leagueID, userData.GetUid())
// ---注意, Foreach里请使用GlobalAsset_League 的unsafe函数,要不就死锁
leagueData.ForeachLeagueHelp(false, func(v *proto.ST_League_Help_Info_PB) bool {
// 找到对应的帮助项
if v.Simple.Basic.GetUid() == actionParameter.UnitNum &&
v.Simple.Basic.GetActionID() == actionParameter.ActionID {
// 自己不能帮助自己
if v.Simple.Basic.GetUid() == actionParameter.Uid {
return false
}
// 不能重复帮助
if common.Uint64SliceContant(v.GetHelperID(), actionParameter.Uid) {
return false
}
tmpUserData := cache.GetCharinfo(v.Simple.Basic.GetUid())
if tmpUserData == nil {
return false
}
tmpUserData.SafeGetLocalAction(v.Simple.Basic.GetActionID(), func(entry *proto.ST_LocalActionEntry_PB) {
if nil == entry {
return
}
if v.Simple.GetHelpCount() >= v.Simple.GetMaxCount() {
return
}
atomic.AddUint32(v.Simple.HelpCount, 1)
v.HelperID = append(v.HelperID, actionParameter.Uid)
remaintime := entry.GetRemaintime()
var rtime uint64 = 0
if remaintime > (wtime.GetNow() - entry.GetStarttime()) {
rtime = remaintime - (wtime.GetNow() - entry.GetStarttime())
}
var reduceTime = rtime * uint64(csv.GetGameConfigValueUint32("Help_Num_2")) / 10000
reduceTime += uint64(csv.GetGameConfigValueUint32("Help_Num_1"))
reduceTime += uint64(tmpUserData.GetAttributeByType(proto.AtttibuteType_Talent6)) //ok
reduceTime += uint64(tmpUserData.GetAttributeByType(proto.AtttibuteType_UnionHelpTime))
if remaintime <= reduceTime {
reduceTime = remaintime
remaintime = 0
} else {
remaintime = remaintime - reduceTime
}
tmpUserData.ChangeLocalActionRemainTime(v.Simple.Basic.GetActionID(), remaintime)
// 数据上报
rtime = 0
if remaintime > (wtime.GetNow() - entry.GetStarttime()) {
rtime = remaintime - (wtime.GetNow() - entry.GetStarttime())
}
ossProcessSpeedUpLocalAction(entry, tmpUserData, 0, reduceTime, rtime, 4, 0)
tmpUserData.AddleagueHelpCount()
tmpUserData.AddTips(11000004, userData.GetUserName())
var score uint32
helpCount := csv.GetGameConfigValueUint32("HELP_DAY_NUMBER")
if userData.GetHelpMemberCount() < helpCount {
score = csv.GetGameConfigValueUint32("HELP_INTEGRAL")
userData.AddLeagueDevote(score)
leagueData.UnsafeAddLeagueScore(uint64(score))
userData.SyncAchievementAdd(cache.LJLMGXDEvent, uint64(score))
leagueData.UnsafeUpdateDevoteRank(userData.GetUid(), uint64(score))
}
userData.AddHelpMemberCount()
//>>>联盟帮助成就,总计帮助盟友1000次[6508501]
userData.SyncAchievementAdd(cache.LJLMBZSLEvent, uint64(1))
userData.SyncAchievementAdd(cache.Src2008, &cache.UInt64Tuple{uint64(6), uint64(reduceTime)})
// 数据上报
newOssLeagueHelp(userData, tmpUserData.GetUid(), reduceTime, score, v.Simple.GetActionType(), leagueMemberLevel)
tmpUserData.DirtyLeagueHelp()
userData.DeleteLeagueHelp(actionParameter.UnitNum, actionParameter.ActionID)
observer.ObserverSingleton.AsyncNotify(observer.LeagueHelpEvent, []interface{}{userData, uint32(1)})
observer.ObserverSingleton.AsyncNotify(observer.ActivityTaskLeagueHelpEvent, []interface{}{userData, uint32(1)})
})
ret = proto.RetActionType_RAT_SUCCESS
return false
}
return true
})
cleanLeagueHelp(leagueID)
userData.GetStatisticsAsset().UpdateLeagueHelpTimes() //联盟帮助
return ret
}
func processHelpAll(actionParameter *ActionParameter) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
leagueID := userData.GetLeagueID()
if leagueID == 0 {
return proto.RetActionType_RAT_INPUT_ERROR
}
leagueData := cache.Instance_GlobalAssetLeague.GetLeagueData(leagueID)
if leagueData == nil {
return proto.RetActionType_RAT_SUCCESS
}
leagueMemberLevel := cache.Instance_GlobalAssetLeague.GetMemberLevel(leagueID, userData.GetUid())
count := uint32(0)
// ---注意, Foreach里请使用GlobalAsset_League 的unsafe函数,要不就死锁
leagueData.ForeachLeagueHelp(false, func(v *proto.ST_League_Help_Info_PB) bool {
if v.Simple.Basic.GetUid() == actionParameter.Uid {
return true
}
if common.Uint64SliceContant(v.GetHelperID(), actionParameter.Uid) {
return true
}
tmpUserData := cache.GetCharinfo(v.Simple.Basic.GetUid())
if tmpUserData == nil {
return true
}
tmpUserData.SafeGetLocalAction(v.Simple.Basic.GetActionID(), func(entry *proto.ST_LocalActionEntry_PB) {
if nil == entry {
return
}
if v.Simple.GetHelpCount() >= v.GetSimple().GetMaxCount() { //最大被帮助次数已超过上限
return
}
atomic.AddUint32(v.Simple.HelpCount, 1)
v.HelperID = append(v.HelperID, actionParameter.Uid)
remainTime := entry.GetRemaintime()
var finalRemainTime uint64 = 0
if remainTime > (wtime.GetNow() - entry.GetStarttime()) {
finalRemainTime = remainTime - (wtime.GetNow() - entry.GetStarttime())
}
var reduceTime = finalRemainTime * uint64(csv.GetGameConfigValueUint32("Help_Num_2")) / 10000
reduceTime += uint64(csv.GetGameConfigValueUint32("Help_Num_1"))
reduceTime += uint64(tmpUserData.GetAttributeByType(proto.AtttibuteType_Talent6)) //ok
reduceTime += uint64(tmpUserData.GetAttributeByType(proto.AtttibuteType_UnionHelpTime))
if remainTime <= reduceTime {
reduceTime = remainTime
remainTime = 0
} else {
remainTime = remainTime - reduceTime
}
tmpUserData.ChangeLocalActionRemainTime(v.Simple.Basic.GetActionID(), remainTime)
// 数据上报
finalRemainTime = 0
if remainTime > (wtime.GetNow() - entry.GetStarttime()) {
finalRemainTime = remainTime - (wtime.GetNow() - entry.GetStarttime())
}
ossProcessSpeedUpLocalAction(entry, tmpUserData, 0, reduceTime, finalRemainTime, 4, 0)
tmpUserData.AddleagueHelpCount()
tmpUserData.AddTips(11000004, userData.GetUserName())
//帮助获得积分
var score uint32
helpCount := csv.GetGameConfigValueUint32("HELP_DAY_NUMBER")
if userData.GetHelpMemberCount() < helpCount {
score = csv.GetGameConfigValueUint32("HELP_INTEGRAL")
userData.AddLeagueDevote(score)
leagueData.UnsafeAddLeagueScore(uint64(score))
userData.SyncAchievementAdd(cache.LJLMGXDEvent, uint64(score))
leagueData.UnsafeUpdateDevoteRank(userData.GetUid(), uint64(score))
}
userData.AddHelpMemberCount()
//联盟帮助成就,总计帮助盟友1000次[6508501]
userData.SyncAchievementAdd(cache.LJLMBZSLEvent, uint64(1))
userData.SyncAchievementAdd(cache.Src2008, &cache.UInt64Tuple{uint64(6), uint64(reduceTime)})
//数据上报
newOssLeagueHelp(userData, tmpUserData.GetUid(), reduceTime, score, v.Simple.GetActionType(), leagueMemberLevel)
count++
})
return true
})
if count > 0 {
observer.ObserverSingleton.AsyncNotify(observer.LeagueHelpEvent, []interface{}{userData, count})
observer.ObserverSingleton.AsyncNotify(observer.ActivityTaskLeagueHelpEvent, []interface{}{userData, count})
}
userData.ClearLeagueHelp()
cleanLeagueHelp(leagueID)
userData.GetStatisticsAsset().UpdateLeagueHelpTimes() //联盟帮助
return proto.RetActionType_RAT_SUCCESS
}
func processBuildEmptyCash(actionParameter *ActionParameter) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
wlog.Error("【build error】 userdata is nil...", actionParameter.Uid)
return proto.RetActionType_RAT_INPUT_ERROR
}
return buildEmpty(userData, actionParameter.BuildingID, actionParameter.BuildingType, proto.ActionType_AT_MISC_BUILD_EMPTY_CASH, 0)
}
func processCureCash(actionParameter *ActionParameter) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
return produce_Cure(userData, actionParameter.BuildingID, actionParameter.Asset, proto.ActionType_AT_MISC_CURE_CASH)
}
func processUnitCash(actionParameter *ActionParameter) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
return produceUnit(userData, actionParameter.BuildingID, actionParameter.ActionType, actionParameter.UnitType, actionParameter.UnitNum)
}
func processUnitUpgradeCash(actionParameter *ActionParameter) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
return product_Upgrade(userData, actionParameter.BuildingID, actionParameter.UnitType, actionParameter.UnitNum, proto.ActionType_AT_MISC_UPGRADE_UNIT_CASH)
}
func processTrapRemove(params *ActionParameter) proto.RetActionType {
userData := cache.GetCharinfo(params.Uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
ret := product_Remove(userData, params.BuildingID, params.UnitType, params.UnitNum)
if ret != proto.RetActionType_RAT_SUCCESS {
return ret
}
curNum := userData.CountUnitNum(params.UnitType)
newOssTrap(userData, 2, params.UnitType, params.UnitNum, curNum)
return ret
}
func processBuildUpgradeCash(actionParameter *ActionParameter) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
ret := proto.RetActionType_RAT_SUCCESS
buildingID := actionParameter.BuildingID
userData.SafeForeachLocalAction(true, func(entry *proto.ST_LocalActionEntry_PB) bool {
//同一建筑上有新建和升级行为,不允许秒建筑
if entry.GetBuildingID() == buildingID &&
(entry.GetActiontype() == uint32(proto.ActionType_AT_BUILD_EMPTY) ||
entry.GetActiontype() == uint32(proto.ActionType_AT_BUILD_LEVELUP)) {
wlog.Error("【build error】 has same action...",
buildingID, actionParameter.ActionType, userData.GetUid(), userData.GetUserName())
ret = proto.RetActionType_RAT_INPUT_ERROR
return false
}
return true
})
if proto.RetActionType_RAT_SUCCESS != ret {
return ret
}
return upgradeBuilding(userData, actionParameter.BuildingID, proto.ActionType_AT_MISC_BUILD_LEVELUP_CASH, 0)
}
func getCostMoneyByVectorList(list []*proto.ST_Vector4Int_PB, userData *cache.Info, actionType proto.ActionType, attributeType ...proto.AtttibuteType) (*proto.ST_CashAsset_PB, uint64) {
var (
gem, c1, c2, c3, c4, c5, cExpedition uint64 = 0, 0, 0, 0, 0, 0, 0
)
needCashAsset := genCashAssetFromV4List(list, userData, attributeType...)
alreadyHasCash := userData.GetCashAsset()
if alreadyHasCash.GetCash1() >= needCashAsset.GetCash1() {
c1 = needCashAsset.GetCash1()
} else {
c1 = alreadyHasCash.GetCash1()
gem += calculateCostMoney(needCashAsset.GetCash1()-alreadyHasCash.GetCash1(), int32(proto.CashType_CASH_TYPE_1), userData, actionType)
}
if alreadyHasCash.GetCash2() >= needCashAsset.GetCash2() {
c2 = needCashAsset.GetCash2()
} else {
c2 = alreadyHasCash.GetCash2()
gem += calculateCostMoney(needCashAsset.GetCash2()-alreadyHasCash.GetCash2(), int32(proto.CashType_CASH_TYPE_2), userData, actionType)
}
if alreadyHasCash.GetCash3() >= needCashAsset.GetCash3() {
c3 = needCashAsset.GetCash3()
} else {
c3 = alreadyHasCash.GetCash3()
gem += calculateCostMoney(needCashAsset.GetCash3()-alreadyHasCash.GetCash3(), int32(proto.CashType_CASH_TYPE_3), userData, actionType)
}
if alreadyHasCash.GetCash4() >= needCashAsset.GetCash4() {
c4 = needCashAsset.GetCash4()
} else {
c4 = alreadyHasCash.GetCash4()
gem += calculateCostMoney(needCashAsset.GetCash4()-alreadyHasCash.GetCash4(), int32(proto.CashType_CASH_TYPE_4), userData, actionType)
}
if alreadyHasCash.GetCash5() >= needCashAsset.GetCash5() {
c5 = needCashAsset.GetCash5()
} else {
c5 = alreadyHasCash.GetCash5()
gem += calculateCostMoney(needCashAsset.GetCash5()-alreadyHasCash.GetCash5(), int32(proto.CashType_CASH_TYPE_5), userData, actionType)
}
if alreadyHasCash.GetCashExpedition() >= needCashAsset.GetCashExpedition() {
cExpedition = needCashAsset.GetCashExpedition()
} else {
cExpedition = alreadyHasCash.GetCashExpedition()
gem += calculateCostMoney(needCashAsset.GetCashExpedition()-alreadyHasCash.GetCashExpedition(), int32(proto.CashType_CASH_TYPE_EXPEDITION), userData, actionType)
}
needReduce := &proto.ST_CashAsset_PB{
Cash1: proto.SetUint64(c1),
Cash2: proto.SetUint64(c2),
Cash3: proto.SetUint64(c3),
Cash4: proto.SetUint64(c4),
Cash5: proto.SetUint64(c5),
Cash100: proto.SetUint64(0),
CashExpedition: proto.SetUint64(cExpedition),
}
return needReduce, gem
}
func calculateCostMoney(resourceNum uint64, resourceType int32, userData *cache.Info, actionType proto.ActionType) uint64 {
var realNum uint64
if resourceType == 0 {
var tmpTime uint64
if actionType == proto.ActionType_AT_BUILD_EMPTY || actionType == proto.ActionType_AT_MISC_BUILD_EMPTY_CASH ||
actionType == proto.ActionType_AT_BUILD_LEVELUP || actionType == proto.ActionType_AT_MISC_BUILD_LEVELUP_CASH ||
actionType == proto.ActionType_AT_RESEARCH_START || actionType == proto.ActionType_AT_MISC_RESEARCH_CASH {
freeTime := getFreeTime(userData)
tmpTime = resourceNum - freeTime
} else {
tmpTime = resourceNum
}
remainTimeMinute := (tmpTime) / 60
if tmpTime%60 > 0 {
remainTimeMinute += 1
}
realNum = remainTimeMinute
} else {
realNum = resourceNum
}
idList := make([]int64, 0)
for _, v := range csv.Mgr.CSV_ResourceCount.GetIDList() {
tmpPtr := csv.Mgr.CSV_ResourceCount.GetEntryPtr(v)
if tmpPtr.ResType == int64(resourceType) {
idList = append(idList, tmpPtr.ID)
}
}
var cost float64 = 0
for _, v := range idList {
tmpPtr := csv.Mgr.CSV_ResourceCount.GetEntryPtr(v)
if int64(realNum) >= tmpPtr.Low && int64(realNum) <= tmpPtr.Up {
cost = tmpPtr.Base + (float64(realNum-uint64(tmpPtr.Low)) * tmpPtr.Parameter)
break
}
continue
}
return uint64(cost)
}
func processSpeedUpActionCash(actionParameter *ActionParameter) proto.RetActionType {
uid := actionParameter.Uid
actionId := actionParameter.ActionID
userData := cache.GetCharinfo(uid)
if userData == nil {
return proto.RetActionType_RAT_INTERNAL_ERROR
}
ret := proto.RetActionType_RAT_SUCCESS
withLeagueAndLocalActionLock(userData, actionId, func(entry *proto.ST_LocalActionEntry_PB) {
if nil == entry {
ret = proto.RetActionType_RAT_INTERNAL_ERROR
return
}
remainTime := entry.GetRemaintime() - (wtime.GetNow() - entry.GetStarttime())
needcost := calculateCostMoney(remainTime, 0, userData, proto.ActionType(entry.GetActiontype()))
if !userData.CheckMoney(needcost) {
ret = proto.RetActionType_RAT_CON_RESOURCE_ERROR
return
}
ossProcessSpeedUpLocalAction(entry, userData, needcost, remainTime, 0, 1, 0)
retVal, idList := finishLocalAction(entry, userData)
userData.DeleteLocalActionList(idList)
ossType := oss.ReduceCashSrcTypeSpeedUpCash
userData.GetStatueAsset().SafeGetStatueEntry(actionId, func(statueEntry *proto.ST_Statue_PB, statueConfigEntry *csv.CF_Statue_DataEntry) {
if nil == statueEntry && nil == statueConfigEntry {
ret = retVal
} else {
ret = StatueSpeedUpByCash(userData, statueEntry, uint32(needcost))
ossType = oss.ReduceCashSrcTypeStatueBuildSpeed
}
})
//如果是集结加速
if retVal == proto.RetActionType_RAT_SUCCESS {
userData.ReduceMoney(needcost, uint32(ossType))
}
retVal = MainCityEventSpeedUpByCash(userData, actionId)
if retVal != proto.RetActionType_RAT_SUCCESS {
retVal = LeagueBoxSpeedUpByCash(userData, actionId, needcost)
}
})
return ret
}
func processSpeedUpActionFree(actionParameter *ActionParameter) proto.RetActionType {
uid := actionParameter.Uid
actionId := actionParameter.ActionID
userData := cache.GetCharinfo(uid)
if userData == nil {
return proto.RetActionType_RAT_INTERNAL_ERROR
}
ret := proto.RetActionType_RAT_SUCCESS
withLeagueAndLocalActionLock(userData, actionId, func(entry *proto.ST_LocalActionEntry_PB) {
if nil == entry {
ret = proto.RetActionType_RAT_INTERNAL_ERROR
return
}
remainTime := entry.GetStarttime() + entry.GetRemaintime() - wtime.GetNow()
if getFreeTime(userData) < remainTime {
ret = proto.RetActionType_RAT_TIME_ERROR
return
}
ossProcessSpeedUpLocalAction(entry, userData, 0, remainTime, 0, 2, 0)
retVal, idList := finishLocalAction(entry, userData)
userData.DeleteLocalActionList(idList)
ret = retVal
})
return ret
}
func processSpeedUpLocalOrGlobalActionItem(actionParameter *ActionParameter) proto.RetActionType {
uid := actionParameter.Uid
localActionID := actionParameter.ActionID
globalActionID := actionParameter.GActionID
itemTypeIDs := actionParameter.ItemTypeIDs
itemCounts := actionParameter.ItemCounts
ossType := oss.ReduceCashSrcTypeSpeedUpItem
if len(itemTypeIDs.List) != len(itemCounts.List) {
wlog.Error("SpeedUp client param error:", len(itemTypeIDs.List), len(itemCounts.List))
return proto.RetActionType_RAT_INTERNAL_ERROR
}
if len(itemTypeIDs.List) == 0 && actionParameter.ItemTypeID > 0 {
itemTypeIDs.List = []uint64{uint64(actionParameter.ItemTypeID)}
itemCounts.List = []uint64{uint64(actionParameter.ItemCount)}
}
for idx, _ := range itemTypeIDs.List {
itemTypeID := uint32(itemTypeIDs.List[idx])
itemCount := uint32(itemCounts.List[idx])
if itemTypeID <= 0 || itemCount <= 0 {
wlog.Error("SpeedUp itemCount error :", itemTypeID, itemCount)
return proto.RetActionType_RAT_INTERNAL_ERROR
}
charInfo := cache.GetCharinfo(uid)
if charInfo == nil {
wlog.Error("SpeedUp GetCharinfo error:", uid)
return proto.RetActionType_RAT_INTERNAL_ERROR
}
itemConfig := csv.Mgr.CSV_ItemList.GetEntryPtr(int64(itemTypeID))
if nil == itemConfig {
wlog.Error("SpeedUp read config error:", itemTypeID)
return proto.RetActionType_RAT_INTERNAL_ERROR
}
haveEnoughItem := charInfo.CheckItem(itemTypeID, itemCount)
if !haveEnoughItem {
wlog.Error("SpeedUp do not haveEnoughItem:", itemTypeID, itemCount)
return proto.RetActionType_RAT_INTERNAL_ERROR
}
var result bool = false
if localActionID > 0 {
result = UseItemOnLocalAction(charInfo, localActionID, itemTypeID, itemCount)
if result {
charInfo.GetStatueAsset().SafeGetStatueEntry(localActionID, func(statueEntry *proto.ST_Statue_PB, statueConfigEntry *csv.CF_Statue_DataEntry) {
if nil != statueEntry && nil != statueConfigEntry {
result = StatueSpeedUpByItem(charInfo, statueEntry, itemTypeID, itemCount)
ossType = oss.ReduceCashSrcTypeStatueBuildSpeed
}
})
ret := MainCityEventSpeedUpByItem(charInfo, itemTypeID, itemCount, actionParameter.ActionID)
if !ret {
LeagueBoxSpeedUpByItem(charInfo, itemTypeID, itemCount, actionParameter.ActionID)
}
}
} else if globalActionID > 0 {
result, ossType = UseItemOnGlobalAction(charInfo, globalActionID, itemTypeID, itemCount, common.StringToUint32(itemConfig.ItemName))
}
if !result {
wlog.Error("SpeedUp result false:", localActionID, itemTypeID, itemCount)
return proto.RetActionType_RAT_INTERNAL_ERROR
}
if csvItem := csv.Mgr.CSV_ItemList.GetEntryPtr(int64(itemTypeID)); csvItem != nil {
funcs := common.ParseParameterStringToMap(csvItem.ItemFunction)
for key, val := range funcs {
if "reducetime" == key {
observer.ObserverSingleton.AsyncNotify(observer.SpeedItemUseEvent, []interface{}{charInfo, common.StringToUint64(val), itemCount, uint32(itemConfig.ItemSubType)})
break
}
}
}
charInfo.AddTips(11000005, int32(itemConfig.ID), common.Uint32ToString(itemCount))
charInfo.ReduceItem(itemTypeID, itemCount, uint32(ossType))
}
return proto.RetActionType_RAT_SUCCESS
}
func destroyBuilding(uid uint64, buildingID uint32) proto.RetActionType {
tmpinfo := cache.GetCharinfo(uid)
if tmpinfo == nil {
return proto.RetActionType_RAT_INTERNAL_ERROR
}
for _, v := range tmpinfo.GetBuildings() {
if v.GetBuildingID() == buildingID {
tmpinfo.DeleteBuildingAsset(buildingID)
actionlist := tmpinfo.SafeGetLocalActionIDsByBuildingId(buildingID)
if len(actionlist) > 0 {
for _, v1 := range actionlist {
tmpinfo.SafeDeleteLocalAction(v1)
}
}
break
}
}
return proto.RetActionType_RAT_SUCCESS
}
func recyclingBuildingList(uid uint64, buildingList string, respon *httputils.Respon) proto.RetActionType {
tmpinfo := cache.GetCharinfo(uid)
if tmpinfo == nil {
return proto.RetActionType_RAT_INTERNAL_ERROR
}
list := common.Base64Decode(buildingList)
msg := &proto.ST_Uint64List_PB{}
proto.Unmarshal([]byte(list), msg)
cash := common.NewCashAsset()
for _, v1 := range msg.GetList() {
var buildingType uint32 = 0
var buildingLevel uint32 = 0
for _, v := range tmpinfo.GetBuildings() {
if v.GetBuildingID() == uint32(v1) {
buildingType = v.GetBuildingtype()
buildingLevel = v.GetBuildinglevel()
conf := csv.Mgr.CSV_BuildingConfig.GetEntryPtr(int64(buildingType))
if conf.CanRecycle == 0 {
return proto.RetActionType_RAT_INTERNAL_ERROR
}
tmpinfo.DeleteBuildingAsset(uint32(v1))
actionlist := tmpinfo.SafeGetLocalActionIDsByBuildingId(uint32(v1))
if len(actionlist) > 0 {
for _, v1 := range actionlist {
tmpinfo.SafeDeleteLocalAction(v1)
}
}
break
}
}
csvConfig := csv.GetDoubleKeyBuildingLevel(buildingType, buildingLevel)
if nil == csvConfig {
continue
}
resourceCost := common.ParseStringToVector4(csvConfig.AssetsRequire)
for _, v := range resourceCost {
if v.GetX() != int32(proto.VectorType_VT_CASH) {
continue
}
resourceNum := uint64(v.GetW() / 10)
switch v.GetY() {
case int32(proto.CashType_CASH_TYPE_1):
cash.Cash1 = proto.SetUint64(cash.GetCash1() + resourceNum)
case int32(proto.CashType_CASH_TYPE_2):
cash.Cash2 = proto.SetUint64(cash.GetCash2() + resourceNum)
case int32(proto.CashType_CASH_TYPE_3):
cash.Cash3 = proto.SetUint64(cash.GetCash3() + resourceNum)
case int32(proto.CashType_CASH_TYPE_4):
cash.Cash4 = proto.SetUint64(cash.GetCash4() + resourceNum)
case int32(proto.CashType_CASH_TYPE_5):
cash.Cash5 = proto.SetUint64(cash.GetCash5() + resourceNum)
case int32(proto.CashType_CASH_TYPE_EXPEDITION):
cash.CashExpedition = proto.SetUint64(cash.GetCashExpedition() + resourceNum)
}
}
}
tmpinfo.AddCashAsset(cash, oss.AddCashSrcRecyclingBuilding)
respon.Add("reward", cash)
return proto.RetActionType_RAT_SUCCESS
}
func recyclingBuilding(uid uint64, buildingID uint32, respon *httputils.Respon) proto.RetActionType {
tmpinfo := cache.GetCharinfo(uid)
if tmpinfo == nil {
return proto.RetActionType_RAT_INTERNAL_ERROR
}
var buildingType uint32 = 0
var buildingLevel uint32 = 0
for _, v := range tmpinfo.GetBuildings() {
if v.GetBuildingID() == buildingID {
buildingType = v.GetBuildingtype()
buildingLevel = v.GetBuildinglevel()
conf := csv.Mgr.CSV_BuildingConfig.GetEntryPtr(int64(buildingType))
if conf.CanRecycle == 0 {
return proto.RetActionType_RAT_INTERNAL_ERROR
}
tmpinfo.DeleteBuildingAsset(buildingID)
actionlist := tmpinfo.SafeGetLocalActionIDsByBuildingId(buildingID)
if len(actionlist) > 0 {
for _, v1 := range actionlist {
tmpinfo.SafeDeleteLocalAction(v1)
}
}
break
}
}
csvConfig := csv.GetDoubleKeyBuildingLevel(buildingType, buildingLevel)
if nil == csvConfig {
return proto.RetActionType_RAT_INTERNAL_ERROR
}
resourceCost := common.ParseStringToVector4(csvConfig.AssetsRequire)
cash := common.NewCashAsset()
for _, v := range resourceCost {
if v.GetX() != int32(proto.VectorType_VT_CASH) {
continue
}
resourceNum := uint64(v.GetW() / 10)
switch v.GetY() {
case int32(proto.CashType_CASH_TYPE_1):
cash.Cash1 = proto.SetUint64(cash.GetCash1() + resourceNum)
case int32(proto.CashType_CASH_TYPE_2):
cash.Cash2 = proto.SetUint64(cash.GetCash2() + resourceNum)
case int32(proto.CashType_CASH_TYPE_3):
cash.Cash3 = proto.SetUint64(cash.GetCash3() + resourceNum)
case int32(proto.CashType_CASH_TYPE_4):
cash.Cash4 = proto.SetUint64(cash.GetCash4() + resourceNum)
case int32(proto.CashType_CASH_TYPE_5):
cash.Cash5 = proto.SetUint64(cash.GetCash5() + resourceNum)
case int32(proto.CashType_CASH_TYPE_EXPEDITION):
cash.CashExpedition = proto.SetUint64(cash.GetCashExpedition() + resourceNum)
}
}
tmpinfo.AddCashAsset(cash, oss.AddCashSrcRecyclingBuilding)
respon.Add("buildingtype", buildingType)
respon.Add("buildinglevel", buildingLevel)
return proto.RetActionType_RAT_SUCCESS
}
func cancelAction(uid uint64, actionId uint32) proto.RetActionType {
tmpInfo := cache.GetCharinfo(uid)
if tmpInfo == nil {
return proto.RetActionType_RAT_INTERNAL_ERROR
}
ret := proto.RetActionType_RAT_SUCCESS
withLeagueAndLocalActionLock(tmpInfo, actionId, func(entry *proto.ST_LocalActionEntry_PB) {
if nil == entry {
ret = proto.RetActionType_RAT_INTERNAL_ERROR
return
}
ossAddCashType := uint32(oss.AddCashSrcTypeCancelBuild)
if uint32(proto.ActionType_AT_PRODUCTION_STATUE) == entry.GetActiontype() {
StatueSafeCancelBuildStatue(tmpInfo, actionId)
} else {
if entry.GetActiontype() == uint32(proto.ActionType_AT_BUILD_EMPTY) {
tmpInfo.DeleteBuildingAsset(entry.GetBuildingID())
}
if entry.GetActiontype() == uint32(proto.ActionType_AT_PRODUCTION_UNIT) {
ossAddCashType = oss.AddCashSrcTypeCancelProductUnit
}
//返还资源
usrCashStr := decodeActionAppendData(entry.GetAppenddata(), "usrCash")
usrCash := &proto.ST_CashAsset_PB{}
proto.Unmarshal([]byte(usrCashStr), usrCash)
realUsrCash := getResourceWithPercent(usrCash, 5000)
tmpInfo.AddCashAsset(realUsrCash, ossAddCashType)
}
if entry.GetIsHelped() {
cache.Instance_GlobalAssetLeague.UnsafeDeleteLeagueHelp(tmpInfo.GetLeagueID(), uid, actionId)
notifyHelpToMembers(tmpInfo.GetLeagueID(), uid, actionId, false)
}
tmpInfo.DeleteLocalAction(actionId)
})
return ret
}
func resetResearch(uid uint64) proto.RetActionType {
tmpinfo := cache.GetCharinfo(uid)
if tmpinfo == nil {
return proto.RetActionType_RAT_INTERNAL_ERROR
}
tmpinfo.ResetResearch()
return proto.RetActionType_RAT_SUCCESS
}
func actionRecall(actiondata *proto.ST_GlobalActionEntry_PB) {
deleteRadar(actiondata)
worldAsset := cache.Instance_GlobalAssetWorldData.GetWorldData(actiondata.GetWorldDataID())
targetType := getWorldDataTargetType(worldAsset)
if worldAsset != nil {
worldAsset.UnBindGlobalActionId(actiondata.GetActionid())
}
if actiondata.GetActiontype() == uint32(proto.ActionType_AT_WORLDMAP_GARRISON) {
if worldAsset != nil {
if targetType == targetMainCity {
targetUser := cache.GetCharinfo(worldAsset.GetWorldDataOwner())
if targetUser != nil {
targetUser.DeleteGarrison(actiondata.GetActionid())
}
} else if targetType == targetWarCity {
targetUser := cache.GetCharinfo(worldAsset.GetWorldDataOwner())
if targetUser != nil {
targetUser.DeleteGarrison(actiondata.GetActionid())
}
} else if targetType == targetLeagueCenter {
targetUser := cache.GetCharinfo(worldAsset.GetWorldDataOwner())
if targetUser != nil {
targetUser.DeleteGarrison(actiondata.GetActionid())
}
}
}
}
if actiondata.GetActiontype() == uint32(proto.ActionType_AT_WORLDMAP_BESTATIONED) {
wdataid := actiondata.GetWorldDataID()
cache.Instance_GlobalAssetWorldData.DeleteDataEntry(wdataid, false)
}
if actiondata.GetActiontype() == uint32(proto.ActionType_AT_WORLDMAP_JOINMASS) {
parentAction := cache.Instance_GlobalAssetGlobalAction.GetGlobalActionAsset(actiondata.GetParentID())
if parentAction != nil {
/////
if parentAction.Actiondata.MassDetail.MassInitiator.GetUserId() == actiondata.GetUid() {
parentAction.Lock()
parentAction.Actiondata.MassDetail = &proto.ST_LeagueMassDetail{}
parentAction.Dirty()
parentAction.Unlock()
} else {
parentAction.Lock()
joins := make([]*proto.ST_LeagueMassJoins, 0)
for _, member := range parentAction.Actiondata.MassDetail.JoinMembers {
if member.GetUserId() != actiondata.GetUid() {
joins = append(joins, member)
}
}
if len(joins) != len(parentAction.Actiondata.MassDetail.JoinMembers) {
parentAction.Actiondata.MassDetail.JoinMembers = joins
parentAction.Dirty()
}
parentAction.Unlock()
}
/////
parentAction.DeleteChildren(actiondata.GetActionid(), countUnitNum(actiondata.GetUnits()))
//if actiondata.GetStage() == uint32(proto.MapStageType_MST_WORKING) ||
// actiondata.GetStage() == uint32(proto.MapStageType_MST_BACK) {
processParentActionTime(parentAction.Actiondata.GetActionid())
}
}
}
func processParentActionTime(actionid uint64) {
parentAction := cache.Instance_GlobalAssetGlobalAction.GetGlobalActionAsset(actionid)
if parentAction == nil {
return
}
if parentAction.Actiondata.GetStage() == uint32(proto.MapStageType_MST_WAITMARCH) {
tmpremaintime := genMaxRemainTime(parentAction.Actiondata)
if tmpremaintime > 0 {
parentAction.UpdateStage(wtime.GetNow(), tmpremaintime, uint32(proto.MapStageType_MST_WAITMARCH))
} else {
massStartMarch(parentAction)
}
}
}
func processRecallRemainTime(actionAsset *cache.GlobalActionEntry) {
actionData := actionAsset.Actiondata
if actionData.GetStage() == uint32(proto.MapStageType_MST_BACK) {
return
}
now := wtime.GetNow()
if endid := getActionNowTileID(actionData); endid != actionData.GetEndTileID() {
remaintime := countMarchTime(actionData.GetUid(), actionData.GetStartTileID(),
endid, actionData.GetWorldDataID(), actionData.GetActiontype(), actionData.GetHeroIDList(), actionData.GetUnits(), actionData.GetCrossSpecialTile())
actionAsset.Actiondata.EndTileID = proto.SetInt32(endid)
actionAsset.UpdateStage(now, remaintime, uint32(proto.MapStageType_MST_BACK))
} else {
var alreadyPassTime uint64
if actionData.GetRemaintime() == 0 {
alreadyPassTime = actionData.GetTotaltime()
} else {
if (actionData.GetActiontype() == uint32(proto.ActionType_AT_WORLDMAP_EXPLORE) ||
actionData.GetActiontype() == uint32(proto.ActionType_AT_WORLDMAP_MASS) ||
actionData.GetActiontype() == uint32(proto.ActionType_AT_WORLDMAP_GARRISON) ||
actionData.GetActiontype() == uint32(proto.ActionType_AT_WORLDMAP_IN) ||
actionData.GetActiontype() == uint32(proto.ActionType_AT_WORLDMAP_OUT) ||
actionData.GetActiontype() == uint32(proto.ActionType_AT_WORLDMAP_BESTATIONED)) &&
actionData.GetStage() == uint32(proto.MapStageType_MST_WORKING) {
alreadyPassTime = actionData.GetTotaltime()
} else {
alreadyPassTime = (now - actionData.GetStarttime()) * actionData.GetTotaltime() / actionData.GetRemaintime()
}
}
actionAsset.UpdateStage(now-(actionData.GetTotaltime()-alreadyPassTime), actionData.GetTotaltime(), uint32(proto.MapStageType_MST_BACK))
}
}
func getActionNowTileID(actionData *proto.ST_GlobalActionEntry_PB) int32 {
if actionData == nil {
return -1
}
var endid int32 = -1
if actionData.GetActiontype() == uint32(proto.ActionType_AT_WORLDMAP_JOINMASS) {
tmpAction := cache.Instance_GlobalAssetGlobalAction.GetGlobalActionAsset(actionData.GetParentID())
if tmpAction != nil {
tmpData := tmpAction.Actiondata
switch tmpData.GetStage() {
case uint32(proto.MapStageType_MST_MARCH):
endid = common.GetTileidByMarchTime(tmpData.GetStartTileID(), tmpData.GetEndTileID(),
wtime.GetNow()-tmpData.GetStarttime(), tmpData.GetRemaintime())
case uint32(proto.MapStageType_MST_WORKING):
fallthrough
case uint32(proto.MapStageType_MST_WAITBATTLE):
fallthrough
case uint32(proto.MapStageType_MST_BACK):
endid = tmpData.GetEndTileID()
default:
endid = actionData.GetEndTileID()
}
}
} else {
endid = actionData.GetEndTileID()
}
return endid
}
func transportBack(actiondata *proto.ST_GlobalActionEntry_PB) {
appendData := actiondata.GetAppenddata()
if 0 == len(appendData) {
return
}
taxResource := decodeActionAppendData(appendData, "resource")
originalResource := decodeActionAppendData(appendData, "originalResource")
tmpResource := &proto.ST_CashAsset_PB{}
proto.Unmarshal([]byte(originalResource), tmpResource)
fromUserId := common.StringToUint64(decodeActionAppendData(appendData, "fromUserId"))
toUserId := common.StringToUint64(decodeActionAppendData(appendData, "toUserId"))
if 0 == fromUserId || 0 == toUserId {
return
}
fromUser := cache.GetCharinfo(fromUserId)
toUser := cache.GetCharinfo(toUserId)
if nil == fromUser || nil == toUser {
return
}
fromUser.ReduceSendResource(getResourceCount(tmpResource))
toUser.ReduceReceiveResource(getResourceCount(tmpResource))
proto.Unmarshal([]byte(taxResource), tmpResource)
fromUser.AddCashAsset(tmpResource, oss.ReduceCashScrTypeLeagueTransport)
}
func recallArmy(gactionid uint64, isImmediately bool) proto.RetActionType {
//wlog.Warning("Army Recall..............................[actionID]", gactionid)
actionAsset := cache.Instance_GlobalAssetGlobalAction.GetGlobalActionAsset(gactionid)
if actionAsset == nil {
wlog.Warning("Army Recall..............................0")
return proto.RetActionType_RAT_INPUT_ERROR
}
/*
wdata := cache.Instance_GlobalAssetWorldData.GetWorldDataByTileId(actionAsset.Actiondata.GetEndTileID())
if nil == wdata {
wlog.Error(fmt.Sprintf("processRecallArmy:deleteRadar error actionType:%v", actionAsset.Actiondata.GetActiontype()))
} else {
actionIds := wdata.CopyGActionList()
if len(actionIds) > 0 {
actionAsset := cache.Instance_GlobalAssetGlobalAction.GetGlobalActionAsset(actionIds[0])
if actionAsset != nil {
recvActionIds := actionAsset.Actiondata.GetRecvActionIDList()
//获取出针对次地块的攻击、侦察、集结、援助行为
//然后从撤军的玩家的预警雷达中删除
for _, recvActionId := range recvActionIds {
wlog.Error("recvActionId ", recvActionId)
otherActionAsset := cache.Instance_GlobalAssetGlobalAction.GetGlobalActionAsset(recvActionId)
if nil == otherActionAsset {
continue
}
actionType := otherActionAsset.Actiondata.GetActiontype()
if actionType == uint32(proto.ActionType_AT_WORLDMAP_ATTCK) ||
actionType == uint32(proto.ActionType_AT_WORLDMAP_SPYINTO) ||
actionType == uint32(proto.ActionType_AT_WORLDMAP_MASS) ||
actionType == uint32(proto.ActionType_AT_WORLDMAP_GARRISON) {
deleteRadar(otherActionAsset.Actiondata)
}
}
}
}
processMiracleWarBack(wdata, gactionid)
}
b := DelWarCityData(actionAsset.Actiondata.GetEndTileID(), gactionid)
*/
worldAsset := cache.Instance_GlobalAssetWorldData.GetWorldData(actionAsset.Actiondata.GetWorldDataID())
CountLeagueCenter(worldAsset) //返回前结算
ret := recallArmyByAction(actionAsset, isImmediately)
TimeLeagueCenter(worldAsset)
targetType := getBattleTargetType(actionAsset.Actiondata)
if targetType == targetLeagueCenter {
d := cache.Instance_GlobalAssetWorldData.GetWorldDataByTileId(actionAsset.Actiondata.GetEndTileID())
if d != nil && len(d.GetWorldData().SimpleEntry.GetGActionList()) == 0 {
d.UpdateOwner(0, 0)
}
}
/*
if b {
if targetType == targetWarCity {
d := cache.Instance_GlobalAssetWorldData.GetWorldDataByTileId(actionAsset.Actiondata.GetEndTileID())
if d != nil && len(d.GetWorldData().SimpleEntry.GetGActionList()) == 0 {
d.UpdateOwner(0, 0)
}
}
}
if actionAsset.Actiondata.GetActiontype() == uint32(proto.ActionType_AT_WORLDMAP_GARRISON) &&
actionAsset.Actiondata.GetStage() == uint32(proto.MapStageType_MST_BACK) &&
(targetType == targetRayolCity || targetType == targetWarCity) {
cityData := cache.Instance_GlobalAssetWorldData.GetWorldData(actionAsset.Actiondata.GetWorldDataID())
if cityData != nil {
calcBigMiracleGarrsonCapAfterBattle(cityData)
}
}
*/
return ret
}
func recallArmyByAction(action *cache.GlobalActionEntry, isImmediately bool) proto.RetActionType {
actiondata := action.Actiondata
userData := cache.GetCharinfo(actiondata.GetUid())
if userData == nil {
wlog.Warning("Army Recall..............................1")
return proto.RetActionType_RAT_INPUT_ERROR
}
deleteLeagueBattleInfo(actiondata)
//wlog.Warning("Army Recall..............................[aID, aType, mType]", actiondata.GetUid(), actiondata.GetActiontype(), actiondata.GetStage())
switch actiondata.GetActiontype() {
case uint32(proto.ActionType_AT_WORLDMAP_TRANSPORT):
if actiondata.GetStage() == uint32(proto.MapStageType_MST_MARCH) {
transportBack(actiondata)
}
case uint32(proto.ActionType_AT_WORLDMAP_COLLECT):
if actiondata.GetStage() == uint32(proto.MapStageType_MST_WORKING) {
// 如果采集还没结束,那就结束采集,设置结束时间
var useTime uint64 = 0
if wtime.GetNow() > actiondata.GetStarttime() {
useTime = wtime.GetNow() - actiondata.GetStarttime() - 1 //采集比资源减量早结算,所以这里应该结算的是上一秒
}
wdata := cache.Instance_GlobalAssetWorldData.GetWorldData(actiondata.GetWorldDataID())
collectFinish(action, wdata, useTime, isImmediately)
} else if actiondata.GetStage() == uint32(proto.MapStageType_MST_BACK) {
// 如果是返回行军,就直接发送邮件
if isImmediately {
addCollectResourceAndSendMail(actiondata)
}
}
case uint32(proto.ActionType_AT_WORLDMAP_IN):
case uint32(proto.ActionType_AT_WORLDMAP_OUT):
case uint32(proto.ActionType_AT_WORLDMAP_MASS):
notifymassidtomember(actiondata.GetLeagueID(), actiondata.GetActionid(), false)
tmpList := make([]uint64, len(actiondata.GetChildrenID()))
copy(tmpList, actiondata.GetChildrenID())
for _, v := range tmpList {
actionAsset := cache.Instance_GlobalAssetGlobalAction.GetGlobalActionAsset(v)
if actionAsset != nil {
recallArmyByAction(actionAsset, isImmediately)
}
}
case uint32(proto.ActionType_AT_WORLDMAP_GARRISON):
if actiondata.GetStage() == uint32(proto.MapStageType_MST_WORKING) {
worldAsset := cache.Instance_GlobalAssetWorldData.GetWorldData(actiondata.GetWorldDataID())
if worldAsset != nil {
targetType := getWorldDataTargetType(worldAsset)
if targetType == targetRayolCity || targetType == targetWarCity || targetType == targetLeagueCenter {
tmpList := worldAsset.CopyGActionList()
if len(tmpList) == 1 && targetType == targetLeagueCenter { //联盟堡垒最后一个人离开清除队长信息
cache.Instance_GlobalAssetLeague.RemoveCampLeader(worldAsset.GetLeagueOwner(), worldAsset.GetWorldDataID())
}
if len(tmpList) > 0 && tmpList[0] == actiondata.GetActionid() {
if targetType == targetLeagueCenter && len(tmpList) > 1 { //自动把队长让给下个驻防成员
actionData := cache.Instance_GlobalAssetGlobalAction.GetGlobalActionAsset(tmpList[1])
cache.Instance_GlobalAssetLeague.ChangeCampLeader(worldAsset.GetLeagueOwner(), worldAsset.GetWorldDataID(), actionData.Actiondata.GetUid())
worldAsset.SwapGActionList(tmpList[1])
}
if targetType != targetLeagueCenter {
notifymassidtomember(actiondata.GetLeagueID(), actiondata.GetActionid(), false)
for k, v := range tmpList {
if k != 0 {
actionAsset := cache.Instance_GlobalAssetGlobalAction.GetGlobalActionAsset(v)
if actionAsset != nil {
recallArmyByAction(actionAsset, isImmediately)
}
}
}
}
}
}
}
}
}
RadarCheckOtherGAction(action, true)
switch actiondata.GetStage() {
case uint32(proto.MapStageType_MST_WAITMASS):
fallthrough
case uint32(proto.MapStageType_MST_WAITMARCH):
if !isImmediately {
processUnitBack(actiondata)
}
case uint32(proto.MapStageType_MST_BACK):
if !isImmediately {
return proto.RetActionType_RAT_INPUT_ERROR
}
}
processRecallRemainTime(action)
actionRecall(actiondata)
if actiondata.GetActiontype() == uint32(proto.ActionType_AT_WORLDMAP_MASS) && actiondata.GetStage() != uint32(proto.MapStageType_MST_BACK) {
userData.AddTips(11000436)
}
if isImmediately {
armyBackToMainCity(actiondata)
if actiondata.GetActiontype() == uint32(proto.ActionType_AT_WORLDMAP_EXPLORE) {
if actiondata.GetStage() == uint32(proto.MapStageType_MST_WORKING) {
addExploreMail(action)
}
}
}
// 数据上报
if actiondata.GetActiontype() != uint32(proto.ActionType_AT_WORLDMAP_MASS) {
newOssUserMarch(userData, actiondata, 4, 0, 0)
}
if countUnitNum(actiondata.GetUnits()) <= 0 {
if actiondata.GetActiontype() != uint32(proto.ActionType_AT_WORLDMAP_SPY) &&
actiondata.GetActiontype() != uint32(proto.ActionType_AT_WORLDMAP_TRANSPORT) &&
actiondata.GetActiontype() != uint32(proto.ActionType_AT_WORLDMAP_IN) &&
actiondata.GetActiontype() != uint32(proto.ActionType_AT_WORLDMAP_OUT) &&
actiondata.GetActiontype() != uint32(proto.ActionType_AT_WORLDMAP_SPYINTO) {
userData.RemoveGlobalActionID(actiondata.GetActionid())
cache.Instance_GlobalAssetGlobalAction.DeleteGlobalAction(actiondata.GetActionid())
}
}
return proto.RetActionType_RAT_SUCCESS
}
func processResearchCash(actionParameter *ActionParameter) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
return researchStart(userData, actionParameter.BuildingID, actionParameter.ResearchTypeID, proto.ActionType_AT_MISC_RESEARCH_CASH)
}
func processAbandoningTreatment(actionParameter *ActionParameter) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil || 0 == actionParameter.UnitType || 0 == actionParameter.UnitNum {
return proto.RetActionType_RAT_INPUT_ERROR
}
if !userData.DeleteHospitalAsset(actionParameter.UnitType, actionParameter.UnitNum) {
return proto.RetActionType_RAT_INPUT_ERROR
}
userData.CalcPower()
return proto.RetActionType_RAT_SUCCESS
}
func processReadRadar(actionParameter *ActionParameter) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
userData.ReadRadarAsset()
return proto.RetActionType_RAT_SUCCESS
}
func processStatue(actionParameter *ActionParameter) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
return StatueEnhance(userData, actionParameter.ActionID)
}
/**
@brief 装备车间合成材料
*/
func processFactoryCompose(actionParameter *ActionParameter, respon *httputils.Respon) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
rlt, itemID, count := MaterialCompose(userData, uint32(actionParameter.FactoryItemID), actionParameter.FactoryOpAll)
respon.Add("materialID", itemID)
respon.Add("materialNum", count)
return rlt
}
/**
@brief 装备车间分解材料
*/
func processFactoryDecompose(actionParameter *ActionParameter, respon *httputils.Respon) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
rlt, itemID, count := MaterialDecompose(userData, int64(actionParameter.FactoryItemID), actionParameter.FactoryOpAll)
respon.Add("materialID", itemID)
respon.Add("materialNum", count)
return rlt
}
/**
@brief 收取装备车间合成出来的装备
*/
func processReceiveCommanderEquip(actionParameter *ActionParameter, respon *httputils.Respon) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
buildingID := actionParameter.BuildingID
buildingAsset := userData.GetBuildingAssetByBuildingId(buildingID)
if buildingAsset == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
userData.AddCommanderItem(buildingAsset.GetEquipCSVID(), 1, oss.AddCashSrcEquipCraft)
//触发礼包
itemCSV := csv.Mgr.CSV_Equipment.GetEntryPtr(int64(buildingAsset.GetEquipCSVID()))
if itemCSV != nil {
CheckAllGiftSaleCondition(userData, proto.GiftConditionType_GCT_EQUIP_QUALITY, itemCSV.Quality)
}
userData.DeleteEquipFromBuilding(buildingID)
respon.Add("equipcsvid", buildingAsset.GetEquipCSVID())
return proto.RetActionType_RAT_SUCCESS
}
func processFactoryCashMake(actionParameter *ActionParameter) proto.RetActionType {
userData := cache.GetCharinfo(actionParameter.Uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
return ProcessCommanderEquipMake(userData, actionParameter.BuildingID, actionParameter.ActionType, uint32(actionParameter.FactoryItemID))
}
func processHeroDefenseOp(uid uint64, heroIDList string, onOrOff uint32, defpos int32) proto.RetActionType {
userData := cache.GetCharinfo(uid)
if userData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
//解析英雄ID
TmpHeroIDList := &proto.ST_Int32List_PB{}
proto.Unmarshal([]byte(common.Base64Decode(heroIDList)), TmpHeroIDList)
if 0 == len(TmpHeroIDList.List) {
return proto.RetActionType_RAT_INPUT_ERROR
}
ret := ProcessHeroDefense(userData, uint32(TmpHeroIDList.List[0]), onOrOff, defpos, false)
if ret {
return proto.RetActionType_RAT_SUCCESS
} else {
return proto.RetActionType_RAT_INPUT_ERROR
}
}
func processChangeCampLeader(uid, targetuid, actionid uint64) proto.RetActionType {
actionData := cache.Instance_GlobalAssetGlobalAction.GetGlobalActionAsset(actionid)
if actionData == nil {
return proto.RetActionType_RAT_INPUT_ERROR
}
worldAsset := cache.Instance_GlobalAssetWorldData.GetWorldData(actionData.Actiondata.GetWorldDataID())
actionlst := worldAsset.CopyGActionList()
selfActId := uint64(0)
for _, v := range actionlst {
dt := cache.Instance_GlobalAssetGlobalAction.GetGlobalActionAsset(v)
if dt.Actiondata.GetUid() == uid {
selfActId = v
break
}
}
if actionlst[0] != selfActId {
if ret, _, _ := CheckRight(uid, LEAGUERIGHT_DisbandGarrison); ret != proto.LeagueResult_LeagueSuccess {
return proto.RetActionType_RAT_LEAGUE_PERMISSION_DENIED
}
}
if actionid == 0 || !worldAsset.SwapGActionList(actionid) {
return proto.RetActionType_RAT_INPUT_ERROR
}
cache.Instance_GlobalAssetLeague.ChangeCampLeader(worldAsset.GetLeagueOwner(), worldAsset.GetWorldDataID(), targetuid)
return proto.RetActionType_RAT_SUCCESS
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。