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
79 changes: 79 additions & 0 deletions logic/Server/ArgumentOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using CommandLine;
using Preparation.Utility;

namespace Server
{
public class DefaultArgumentOptions
{
public const string FileName = "xxxxxxxxx";
public const string Token = "xxxxxxxxx";
public const string Url = "xxxxxxxxx";
public const string MapResource = "xxxxxxxxx";
}
public class ArgumentOptions
{
[Option("ip", Required = false, HelpText = "Server listening ip")]
public string IP { get; set; } = "0.0.0.0";

[Option('p', "port", Required = true, HelpText = "Server listening port")]
public ushort ServerPort { get; set; } = 8888;

[Option("teamCount", Required = false, HelpText = "The number of teams, 4 by defualt")]
public ushort TeamCount { get; set; } = 4;

[Option("CharacterNum", Required = false, HelpText = "The max number of Character, 6 by default")]
public ushort CharacterCount { get; set; } = 6;

[Option('g', "gameTimeInSecond", Required = false, HelpText = "The time of the game in second, 10 minutes by default")]
public uint GameTimeInSecond { get; set; } = GameData.GameDurationInSecond;

[Option("homeNum", Required = false, HelpText = "The number of Home , 1 by default")]
public ushort HomeCount { get; set; } = 1;

[Option('f', "fileName", Required = false, HelpText = "The file to store playback file or to read file.")]
public string FileName { get; set; } = "xxxxxxxxx";

[Option("notAllowSpectator", Required = false, HelpText = "Whether to allow a spectator to watch the game.")]
public bool NotAllowSpectator { get; set; } = false;

[Option('b', "playback", Required = false, HelpText = "Whether open the server in a playback mode.")]
public bool Playback { get; set; } = false;

[Option("playbackSpeed", Required = false, HelpText = "The speed of the playback, between 0.25 and 4.0")]
public double PlaybackSpeed { get; set; } = 1.0;

[Option("resultOnly", Required = false, HelpText = "In playback mode to get the result directly")]
public bool ResultOnly { get; set; } = false;

[Option('k', "token", Required = false, HelpText = "Web API Token")]
public string Token { get; set; } = "xxxxxxxxx";

[Option('u', "url", Required = false, HelpText = "Web Url")]
public string Url { get; set; } = "xxxxxxxxx";

[Option('m', "mapResource", Required = false, HelpText = "Map Resource Path")]
public string MapResource { get; set; } = DefaultArgumentOptions.MapResource;

[Option("requestOnly", Required = false, HelpText = "Only send web requests")]
public bool RequestOnly { get; set; } = false;

[Option("finalGame", Required = false, HelpText = "Whether it is the final game")]
public bool FinalGame { get; set; } = false;

[Option("cheatMode", Required = false, HelpText = "Whether to open the cheat code")]
public bool CheatMode { get; set; } = false;

[Option("resultFileName", Required = false, HelpText = "Result file name, saved as .json")]
public string ResultFileName { get; set; } = "xxxxxxxxx";

[Option("startLockFile", Required = false, HelpText = "Whether to create a file that identifies whether the game has started")]
public string StartLockFile { get; set; } = "114514";

[Option("mode", Required = false, HelpText = "Whether to run final competition. 0 本地玩,1 最终比赛,2 天梯")]
public int Mode { get; set; } = 0;

[Option("loglevel", Required = false, HelpText = "Set the log level: 1=Error, 2=Warning, 3=Info, 4=Debug, 5=Trace")]
public int LogLevel { get; set; } = 5; // 默认Trace级别

}
}
294 changes: 294 additions & 0 deletions logic/Server/CopyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
using GameClass.GameObj;
using GameClass.GameObj.Areas;
using Preparation.Utility;
using Protobuf;
using Utility = Preparation.Utility;

namespace Server
{
public static class CopyInfo
{
public static MessageOfObj? Auto(GameObj gameObj, long time)
{
if (gameObj.IsRemoved == true)
return null;
switch (gameObj.Type)
{
case GameObjType.CHARACTER:
return Character((Character)gameObj, time);
case GameObjType.ECONOMY_RESOURCE:
return EconomyResource((E_Resource)gameObj);
case GameObjType.ADDITIONAL_RESOURCE:
return AdditionResource((A_Resource)gameObj);
case GameObjType.CONSTRUCTION:
Construction construction = (Construction)gameObj;
if (construction.ConstructionType == Utility.ConstructionType.BARRACKS)
return Barracks(construction);
else if (construction.ConstructionType == Utility.ConstructionType.SPRING)
return Spring(construction);
else if (construction.ConstructionType == Utility.ConstructionType.FARM)
return Farm(construction);
return null;
case GameObjType.TRAP:
if (gameObj is HOLE hole)
return Traps(hole);
else if (gameObj is Cage cage)
return Traps(cage);
return null;
default: return null;
}
}

public static MessageOfObj? Auto(MessageOfNews news)
{
MessageOfObj objMsg = new()
{
NewsMessage = news
};
return objMsg;
}
private static MessageOfObj? Base(Base player, long time)
{
MessageOfObj msg = new()
{
TeamMessage = new()
{
TeamId = player.TeamID,
PlayerId = player.PlayerID,
Score = player.MoneyPool.Score,
Energy = player.MoneyPool.Money,
}
};
return msg;
}

public static MessageOfObj? Auto(Base @base, long time)
{
return Base(@base, time);
}
private static MessageOfObj? Character(Character player, long time)
{
MessageOfObj msg = new()
{
CharacterMessage = new()
{
Guid = player.ID,

TeamId = player.TeamID,
PlayerId = player.PlayerID,

CharacterType = Transformation.CharacterTypeToProto(player.CharacterType),

CharacterActiveState = Transformation.CharacterStateToProto(player.CharacterState1),

IsBlind = player.blind,
BlindTime = player.BlindTime,
IsStunned = player.stunned,
StunnedTime = player.StunnedTime,
IsInvisible = !player.visible,
InvisibleTime = player.InvisibleTime,
IsBurned = player.burned,
BurnedTime = player.BurnedTime,
HarmCut = player.HarmCut,
HarmCutTime = player.HarmCutTime,

CharacterPassiveState = Transformation.CharacterStateToProto(player.CharacterState2),

X = player.Position.x,
Y = player.Position.y,

FacingDirection = player.FacingDirection.Angle(),
Speed = player.MoveSpeed,
ViewRange = player.ViewRange,

CommonAttack = (int)player.AttackPower,
// 待修改,Character.cs中没有CommonAttackCD
CommonAttackCd = (int)(1 / player.ATKFrequency),
CommonAttackRange = (int)player.AttackSize,

SkillAttackCd = player.skillCD,

EconomyDepletion = player.EconomyDepletion,
KillScore = (int)player.GetCost(),

Hp = (int)player.HP,

// 待修改,Shield要分两类
ShieldEquipment = (int)player.Shield, // 护盾装备
ShoesEquipment = (int)player.Shoes, // 加成值
ShoesTime = player.ShoesTime, // 包含所有速度加成的时间
IsPurified = player.Purified,
PurifiedTime = player.PurifiedTime,
IsBerserk = player.IsBerserk,
BerserkTime = player.BerserkTime,

AttackBuffNum = (int)player.CrazyManNum,
AttackBuffTime = player.CrazyManTime,
SpeedBuffTime = player.QuickStepTime,
VisionBuffTime = player.WideViewTime,
}
};
return msg;
}

private static MessageOfObj EconomyResource(E_Resource economyresource)
{
MessageOfObj msg = new()
{
EconomyResourceMessage = new()
{
EconomyResourceState = Transformation.EconomyResourceStateToProto(economyresource.ERstate),
EconomyResourceType = Transformation.EconomyResourceTypeToProto(economyresource.EResourceType),

X = economyresource.Position.x,
Y = economyresource.Position.y,

Process = (10000 - (int)economyresource.HP) / 10000,
Id = 0,
}
};
return msg;
}

private static MessageOfObj AdditionResource(A_Resource additionResource)
{
MessageOfObj msg = new()
{
AdditionResourceMessage = new()
{
AdditionResourceType = Transformation.AResourceToProto(additionResource.AResourceType),
AdditionResourceState = Transformation.AResourceStateToProto(additionResource.ARstate),

X = additionResource.Position.x,
Y = additionResource.Position.y,

Hp = (int)additionResource.HP,
Id = 0,
}
};
// Debugger.Output(additionResource, additionResource.Place.ToString()+" "+additionResource.Position.ToString());
return msg;
}

private static MessageOfObj Barracks(Construction construction)
{
MessageOfObj msg = new()
{
BarracksMessage = new()
{
X = construction.Position.x,
Y = construction.Position.y,

Hp = (int)construction.HP,

TeamId = construction.TeamID,
Id = 0,
}
};
return msg;
}

private static MessageOfObj Spring(Construction construction)
{
MessageOfObj msg = new()
{
SpringMessage = new()
{
X = construction.Position.x,
Y = construction.Position.y,

Hp = (int)construction.HP,

TeamId = construction.TeamID,
Id = 0,
}
};
return msg;
}

private static MessageOfObj Farm(Construction construction)
{
MessageOfObj msg = new()
{
FarmMessage = new()
{
X = construction.Position.x,
Y = construction.Position.y,

Hp = (int)construction.HP,

TeamId = construction.TeamID,
Id = 0,
}
};
return msg;
}

// private static MessageOfObj Traps(GameObj trap)
// {
// MessageOfObj msg = new()
// {
// TrapMessage = new()
// {
// TrapType = trap switch
// {
// HOLE _ => Protobuf.TrapType.Hole,
// Cage _ => Protobuf.TrapType.Cage,
// },

// X = trap.Position.x,
// Y = trap.Position.y,

// TeamId = trap switch
// {
// HOLE t => t.TeamID.Get(),
// Cage c => c.TeamID.Get(),
// },
// Id = 0,

// TrapValid = !trap.IsActivated.Get(),
// }
// };
// return msg;
// }
private static MessageOfObj Traps(HOLE trap)
{
MessageOfObj msg = new()
{
TrapMessage = new()
{
TrapType = Protobuf.TrapType.Hole,

X = trap.Position.x,
Y = trap.Position.y,

TeamId = trap.TeamID.Get(),
Id = 0,

TrapValid = !trap.IsActivated.Get(),
}
};
return msg;
}

private static MessageOfObj Traps(Cage trap)
{
MessageOfObj msg = new()
{
TrapMessage = new()
{
TrapType = Protobuf.TrapType.Cage,

X = trap.Position.x,
Y = trap.Position.y,

TeamId = trap.TeamID.Get(),
Id = 0,

TrapValid = !trap.IsActivated.Get(),
}
};
return msg;
}
}
}
Loading
Loading