Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dependency/proto/Services.proto
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
syntax = "proto3";
syntax = "proto3";
package protobuf;

import "Message2Clients.proto";
Expand All @@ -25,8 +25,8 @@ service AvailableService
rpc Trade(TradeMsg) returns (BoolRes); // 出售产品

// 游戏过程中核心角色(工厂)可以执行操作的服务
rpc CreatCharacter(CreateCharacterMsg) returns (BoolRes); // 创建角色
rpc CreatCharacterRID(CreateCharacterMsg) returns (CreatCharacterRes); // 获取角色编号
rpc CreateCharacter(CreateCharacterMsg) returns (BoolRes); // 创建角色
rpc CreateCharacterRID(CreateCharacterMsg) returns (CreatCharacterRes); // 获取角色编号
rpc Produce(ProduceGoodsMsg) returns (BoolRes); // 生产产品
//rpc Repair(RepairFactoryMsg) returns (BoolRes); // 修理工厂
rpc EndAllAction(IDMsg) returns (BoolRes); // 结束所有动作
Expand Down
4 changes: 2 additions & 2 deletions logic/ClientTest/program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Grpc.Core;
using Grpc.Core;
using Protobuf;

namespace ClientTest
Expand Down Expand Up @@ -44,7 +44,7 @@
PlayerId = 1,
};

var createRes = client.CreatCharacter(createMsg); // 当前可用接口
var createRes = client.CreateCharacter(createMsg); // 当前可用接口
if (!createRes.ActSuccess)
{
Console.WriteLine("CreateCharacter failed.");
Expand Down Expand Up @@ -74,6 +74,6 @@
if (tot % 10 == 0) moveMsg.Angle += 1;
}

return Task.CompletedTask;

Check warning on line 77 in logic/ClientTest/program.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-logic

Unreachable code detected
}
}
Expand Down
Empty file added logic/Server/114514
Empty file.
59 changes: 19 additions & 40 deletions logic/Server/RpcServices.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GameClass.GameObj;
using GameClass.GameObj;
using Gaming;
using Grpc.Core;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -412,7 +412,7 @@ public override Task<BoolRes> Trade(TradeMsg request, ServerCallContext context)

#region 核心角色操作

public override Task<BoolRes> CreatCharacter(CreateCharacterMsg request, ServerCallContext context)
public override Task<BoolRes> CreateCharacter(CreateCharacterMsg request, ServerCallContext context)
{
GameServerLogging.logger.LogDebug($"TRY CreatCharacter: CharacterType {request.CharacterType} from Team {request.TeamId}");
BoolRes boolRes = new()
Expand All @@ -424,41 +424,25 @@ public override Task<BoolRes> CreatCharacter(CreateCharacterMsg request, ServerC
Transformation.CharacterTypeFromProto(request.CharacterType))
};
// if (boolRes.ActSuccess) teamMoneyPool.SubMoney(activateCost);
GameServerLogging.logger.LogDebug($"END CreatCharacter:{boolRes.ActSuccess}");
GameServerLogging.logger.LogDebug($"END CreateCharacter:{boolRes.ActSuccess}");
return Task.FromResult(boolRes);
}

// 暂时废弃CreatCharacterRID,因为playerId由玩家自行指定
// public override Task<CreatCharacterRes> CreatCharacterRID(CreateCharacterMsg request, ServerCallContext context)
// {
// // GameServerLogging.logger.LogDebug($"TRY CreatCharacterRID: CharacterType {request.CharacterType} from Team {request.TeamId}");
// // // var activateCost = Transformation.CharacterTypeFromProto(request.CharacterType) switch
// // // {
// // // Utility.CharacterType.DRONE => GameData.DroneCost,
// // // Utility.CharacterType.ROBOT => GameData.RobotCost,
// // // Utility.CharacterType.AUTONOMOUS_CAR => GameData.AutonomouCarCost,

// // // _ => int.MaxValue
// // // };
// // // var teamMoneyPool = game.TeamList[(int)request.TeamId].MoneyPool;
// // // if (activateCost > teamMoneyPool.Money)
// // // {
// // // return Task.FromResult(new CreatCharacterRes { ActSuccess = false });
// // // }
// // var playerId = game.RecruitCharacterAtFactory(
// // request.TeamId,
// // request.PlayerId,
// // Transformation.CharacterTypeFromProto(request.CharacterType));

// // CreatCharacterRes creatCharacterRes = new()
// // {
// // ActSuccess = false,
// // PlayerId = playerId
// // };
// // if (creatCharacterRes.ActSuccess) teamMoneyPool.SubMoney(activateCost);
// // GameServerLogging.logger.LogDebug("END CreatCharacterRID");
// return Task.FromResult(creatCharacterRes);
// }
public override Task<BoolRes> Produce(ProduceGoodsMsg request, ServerCallContext context)
{
GameServerLogging.logger.LogDebug($"TRY Produce Goods: Team {request.TeamId} want to " +
$"produce Type {request.ProductType}, with produce {request.MaxProduceNum} at most");
BoolRes boolRes = new()
{
ActSuccess =
game.Produce(
request.TeamId,
Transformation.GoodsTypeFromProto(request.ProductType),
request.MaxProduceNum)
};
GameServerLogging.logger.LogDebug($"END Produce Goods: {boolRes.ActSuccess}");
return Task.FromResult(boolRes);
}

public override Task<BoolRes> EndAllAction(IDMsg request, ServerCallContext context)
{
Expand All @@ -472,19 +456,14 @@ public override Task<BoolRes> EndAllAction(IDMsg request, ServerCallContext cont

#endregion

#region AI 服务

public override Task<StrategicAIResponse> AskAI(StrategicAIRequest request, ServerCallContext context)
{
GameServerLogging.logger.LogDebug($"TRY AskAI: Team {request.TeamId}");
GameServerLogging.logger.LogDebug($"TRY AskAI: Team {request.TeamId} at {request.CurrentGameTime}");
StrategicAIResponse response = new();
// 待实现
Boolean boolRes = new();
// boolRes.ActSuccess = game.AskAI(request.TeamId, request.GameState, request.AIAction);
GameServerLogging.logger.LogDebug("END AskAI");
return Task.FromResult(response);
}

#endregion
}
}
Binary file not shown.
Loading