1 Star 0 Fork 0

liuxuezhan/mylib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
LC_FactoryPackage.go 8.60 KB
一键复制 编辑 原始数据 按行查看 历史
liuxuezhan 提交于 2020-12-19 16:15 . 'ok'
package logic
import (
"strings"
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"
)
/**
@brief 材料合成
*/
func MaterialCompose(userData *cache.Info, materialID uint32, isAll uint32) (proto.RetActionType, uint32, uint64) {
if nil == userData {
return proto.RetActionType_RAT_INPUT_ERROR, 0, 0
}
itemCSV := csv.Mgr.CSV_Equipment.GetEntryPtr(int64(materialID))
if nil == itemCSV || itemCSV.MainType != int64(proto.ItemMainType_IMT_COMMANDER_MATERIAL) {
return proto.RetActionType_RAT_INPUT_ERROR, 0, 0
}
//合成消耗
tmpString := strings.Split(itemCSV.ComposeParam, "Compose=")[1]
tmp := strings.Split(tmpString, ";")[0]
costList := common.ParseStringToVector4(tmp)
//检查材料并扣除
//"全部合成"不是一次性检查和扣除所有消耗,
//而是是一遍一遍的检查和扣除材料
count := uint32(0)
for {
if false == checkMakeMaterial(userData, costList) {
break
}
if false == reduceMaterial(userData, costList, oss.ReduceCashSrcTypeMaterialCompose) {
break
}
count += 1
if 0 == isAll {
break
}
}
if 0 < count {
userData.AddCommanderItem(materialID, uint64(count), oss.AddCashSrcMaterialCompose)
return proto.RetActionType_RAT_SUCCESS, materialID, uint64(count)
}
return proto.RetActionType_RAT_INPUT_ERROR, 0, 0
}
/**
@brief 材料分解
*/
func MaterialDecompose(userData *cache.Info, materialID int64, isAll uint32) (proto.RetActionType, uint32, uint64) {
if nil == userData {
return proto.RetActionType_RAT_INPUT_ERROR, 0, 0
}
itemCSV := csv.Mgr.CSV_Equipment.GetEntryPtr(int64(materialID))
if nil == itemCSV || (itemCSV.MainType != int64(proto.ItemMainType_IMT_COMMANDER_MATERIAL) &&
itemCSV.MainType != int64(proto.ItemMainType_IMT_COMMANDER_EQUIP)) {
return proto.RetActionType_RAT_INPUT_ERROR, 0, 0
}
//分解获得的材料目前只会有一种
tmpList := strings.Split(itemCSV.ComposeParam, "Decompose=")
if len(tmpList) < 2 {
return proto.RetActionType_RAT_INPUT_ERROR, 0, 0
}
tmpString := tmpList[1]
itemsList := common.ParseStringToVector4(tmpString)
totalCount := uint64(0)
if 1 >= len(itemsList) {
newMaterialID := uint32(itemsList[0].GetY())
count := uint64(itemsList[0].GetW())
for {
if false == userData.ReduceCommanderItemByCSVID(uint32(materialID), uint64(1)) {
break
}
totalCount += count
if 0 == isAll {
break
}
}
if 0 < totalCount {
userData.AddCommanderItem(newMaterialID, totalCount, oss.AddCashSrcMaterialDeComp)
cache.NewOssRemoveItem(userData, oss.ReduceCashScrTypeMaterialDecomp, uint32(materialID), uint64(userData.GetItemNumber(uint32(materialID))), uint64(totalCount))
return proto.RetActionType_RAT_SUCCESS, newMaterialID, totalCount
wlog.Error("【MaterialDecompose_you】 DeCompose SUCCESS >", newMaterialID, count)
}
}
return proto.RetActionType_RAT_INPUT_ERROR, 0, 0
}
/**
@brief 拆分装备合成所需消耗
*/
func splitCostItems(costList []*proto.ST_Vector4Int_PB) (bool, []*proto.ST_Vector4Int_PB, []*proto.ST_Vector4Int_PB) {
if 0 == len(costList) {
return false, nil, nil
}
materialList := make([]*proto.ST_Vector4Int_PB, 0) //材料消耗
cashList := make([]*proto.ST_Vector4Int_PB, 0) //资源消耗
for _, v := range costList {
tmp := &proto.ST_Vector4Int_PB{
X: proto.SetInt32(v.GetX()),
Y: proto.SetInt32(v.GetY()),
W: proto.SetInt32(v.GetW()),
Z: proto.SetInt32(v.GetZ()),
}
if int32(proto.CashType_CASH_TYPE_1) <= tmp.GetX() && int32(proto.CashType_CASH_TYPE_5) >= tmp.GetX() {
cashList = append(cashList, tmp)
} else {
materialList = append(materialList, tmp)
}
}
return true, materialList, cashList
}
/**
@brief 检查合成材料
*/
func checkMakeMaterial(userData *cache.Info, materialList []*proto.ST_Vector4Int_PB) bool {
if nil == userData || 0 == len(materialList) {
return false
}
for _, v := range materialList {
if false == userData.CheckCommanderItem(uint32(v.GetY()), uint64(v.GetZ())) {
return false
}
}
return true
}
/**
@brief 删除材料
*/
func reduceMaterial(userData *cache.Info, materialList []*proto.ST_Vector4Int_PB, ossType uint32) bool {
if nil == userData || 0 == len(materialList) {
return false
}
for _, v := range materialList {
if false == userData.ReduceCommanderItemByCSVID(uint32(v.GetY()), uint64(v.GetW())) {
return false
}
cache.NewOssRemoveItem(userData, ossType, uint32(v.GetY()), uint64(v.GetW()), uint64(userData.GetItemNumber(uint32(v.GetY()))))
}
return true
}
/**
@brief 开始装备合成
*/
func ProcessCommanderEquipMake(userData *cache.Info, buildingID, actionType, equipID uint32) proto.RetActionType {
buildingTypeID, buildingLevel := userData.GetBuildingInfoByBuildingId(buildingID)
buildingLevelUp := csv.GetDoubleKeyBuildingLevel(buildingTypeID, buildingLevel)
buildingConfig := csv.Mgr.CSV_BuildingConfig.GetEntryPtr(int64(buildingTypeID))
if nil == buildingLevelUp || buildingConfig == nil {
return proto.RetActionType_RAT_INTERNAL_ERROR
}
if buildingConfig.Type != int64(proto.BuildingType_BT_EQUIP_FACTORY) {
return proto.RetActionType_RAT_INTERNAL_ERROR
}
equipCSV := csv.Mgr.CSV_Equipment.GetEntryPtr(int64(equipID))
if nil == equipCSV {
return proto.RetActionType_RAT_INTERNAL_ERROR
}
//合成消耗
tmp := strings.Split(equipCSV.ComposeParam, ";")[0]
tmp = strings.Split(tmp, "Compose=")[1]
costList := common.ParseStringToVector4(tmp)
rlt, materialCostList, cashCostList := splitCostItems(costList)
if false == rlt {
return proto.RetActionType_RAT_INTERNAL_ERROR
}
//制造时间
makeTime := countDecreaseFloatWithBuilding(float64(equipCSV.Equipspeed), userData, []uint32{buildingID}, proto.AtttibuteType_EquipMakeSpeed)
//材料必备,无法用钻石替代
if false == checkMakeMaterial(userData, materialCostList) {
return proto.RetActionType_RAT_CON_BUILDING_ERROR
}
//钻石直接完成
if actionType == uint32(proto.ActionType_AT_MISC_FACTORY_MAKE_CASH) {
needCash, cost := getCostMoneyByVectorList(cashCostList, userData, proto.ActionType(actionType), []proto.AtttibuteType{proto.AtttibuteType_EquipMakeSpeed}...)
cost += calculateCostMoney(uint64(makeTime), 0, userData, proto.ActionType(actionType))
if !userData.CheckMoney(cost) || !userData.CheckCashAsset(needCash) {
return proto.RetActionType_RAT_CON_RESOURCE_ERROR
}
if false == reduceMaterial(userData, materialCostList, oss.ReduceCashSrcTypeMaterialCompose) {
return proto.RetActionType_RAT_CON_RESOURCE_ERROR
}
userData.ReduceMoney(cost, oss.ReduceCashScrTypeFactoryMake)
userData.ReduceCashAsset(needCash, oss.ReduceCashScrTypeFactoryMake)
FinishCommanderEquipMake(userData, buildingID, equipID)
} else { //用资源和时间完成
needCash, cost := getCostMoneyByVectorList(cashCostList, userData, proto.ActionType(actionType), []proto.AtttibuteType{proto.AtttibuteType_EquipMakeSpeed}...)
if !userData.CheckCashAsset(needCash) || !userData.CheckMoney(cost) {
return proto.RetActionType_RAT_CON_RESOURCE_ERROR
}
if false == reduceMaterial(userData, materialCostList, oss.ReduceCashSrcTypeMaterialCompose) {
return proto.RetActionType_RAT_CON_RESOURCE_ERROR
}
userData.ReduceCashAsset(needCash, oss.ReduceCashScrTypeFactoryMake)
if cost != 0 {
userData.ReduceMoney(cost, oss.ReduceCashScrTypeFactoryMake)
}
//添加进度列表
needCash.Cash100 = proto.SetUint64(cost)
appendData := encodeActionAppendData("", "usrCash", string(proto.Marshal(needCash)))
userData.SafeAddLocalAction(userData.GetNextLocalActionId(), actionType, buildingID, uint64(makeTime), appendData, 0, int32(equipID), int32(1))
}
return proto.RetActionType_RAT_SUCCESS
}
/**
@brief 装备合成结束
*/
func FinishCommanderEquipMake(userData *cache.Info, buildingID, equipID uint32) {
equipCSV := csv.Mgr.CSV_Equipment.GetEntryPtr(int64(equipID))
if nil != equipCSV && equipCSV.MainType == int64(proto.ItemMainType_IMT_COMMANDER_EQUIP) {
userData.AddEquipCSVIDToBuilding(buildingID, equipID)
observer.ObserverSingleton.AsyncNotify(observer.ProductEquipEvent, []interface{}{userData})
}
}
/**
@brief 工厂升级后的各种处理
*/
func processFactoryLevelUp(userData *cache.Info) {
if nil == userData {
return
}
//解锁对应等级的部位
bFunction := userData.GetBuildingFuctionByConfigType(int64(proto.BuildingType_BT_EQUIP_FACTORY))
if v, ok := bFunction["forgingunlock"]; ok {
userData.CleanUnlockPos()
for _, v := range strings.Split(v, " ") {
userData.UnlockEquipPos(common.StringToUint32(v))
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liuxuezhan/mylib.git
git@gitee.com:liuxuezhan/mylib.git
liuxuezhan
mylib
mylib
v1.1.0

搜索帮助