本文整理汇总了C#中IHsGameState.SetCurrentEntity方法的典型用法代码示例。如果您正苦于以下问题:C# IHsGameState.SetCurrentEntity方法的具体用法?C# IHsGameState.SetCurrentEntity怎么用?C# IHsGameState.SetCurrentEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHsGameState
的用法示例。
在下文中一共展示了IHsGameState.SetCurrentEntity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Handle
public void Handle(string logLine, IHsGameState gameState, IGame game)
{
var creationTag = false;
if(GameEntityRegex.IsMatch(logLine))
{
var match = GameEntityRegex.Match(logLine);
var id = int.Parse(match.Groups["id"].Value);
if(!game.Entities.ContainsKey(id))
game.Entities.Add(id, new Entity(id) {Name = "GameEntity"});
gameState.SetCurrentEntity(id);
if(gameState.DeterminedPlayers)
_tagChangeHandler.InvokeQueuedActions(game);
return;
}
else if(PlayerEntityRegex.IsMatch(logLine))
{
var match = PlayerEntityRegex.Match(logLine);
var id = int.Parse(match.Groups["id"].Value);
if(!game.Entities.ContainsKey(id))
game.Entities.Add(id, new Entity(id));
if(gameState.WasInProgress)
game.Entities[id].Name = game.GetStoredPlayerName(id);
gameState.SetCurrentEntity(id);
if(gameState.DeterminedPlayers)
_tagChangeHandler.InvokeQueuedActions(game);
return;
}
else if(TagChangeRegex.IsMatch(logLine))
{
var match = TagChangeRegex.Match(logLine);
var rawEntity = match.Groups["entity"].Value.Replace("UNKNOWN ENTITY ", "");
int entityId;
if(rawEntity.StartsWith("[") && EntityRegex.IsMatch(rawEntity))
{
var entity = EntityRegex.Match(rawEntity);
var id = int.Parse(entity.Groups["id"].Value);
_tagChangeHandler.TagChange(gameState, match.Groups["tag"].Value, id, match.Groups["value"].Value, game);
}
else if(int.TryParse(rawEntity, out entityId))
_tagChangeHandler.TagChange(gameState, match.Groups["tag"].Value, entityId, match.Groups["value"].Value, game);
else
{
var entity = game.Entities.FirstOrDefault(x => x.Value.Name == rawEntity);
if(entity.Value == null)
{
var players = game.Entities.Where(x => x.Value.HasTag(GameTag.PLAYER_ID)).Take(2).ToList();
var unnamedPlayers = players.Where(x => string.IsNullOrEmpty(x.Value.Name)).ToList();
var unknownHumanPlayer = players.FirstOrDefault(x => x.Value.Name == "UNKNOWN HUMAN PLAYER");
if(unnamedPlayers.Count == 0 && unknownHumanPlayer.Value != null)
{
Log.Info("Updating UNKNOWN HUMAN PLAYER");
entity = unknownHumanPlayer;
}
//while the id is unknown, store in tmp entities
var tmpEntity = _tmpEntities.FirstOrDefault(x => x.Name == rawEntity);
if(tmpEntity == null)
{
tmpEntity = new Entity(_tmpEntities.Count + 1) {Name = rawEntity};
_tmpEntities.Add(tmpEntity);
}
GameTag tag;
Enum.TryParse(match.Groups["tag"].Value, out tag);
var value = LogReaderHelper.ParseTag(tag, match.Groups["value"].Value);
if(unnamedPlayers.Count == 1)
entity = unnamedPlayers.Single();
else if(unnamedPlayers.Count == 2 && tag == GameTag.CURRENT_PLAYER && value == 0)
entity = game.Entities.FirstOrDefault(x => x.Value?.HasTag(GameTag.CURRENT_PLAYER) ?? false);
if(entity.Value != null)
{
entity.Value.Name = tmpEntity.Name;
foreach(var t in tmpEntity.Tags)
_tagChangeHandler.TagChange(gameState, t.Key, entity.Key, t.Value, game);
_tmpEntities.Remove(tmpEntity);
_tagChangeHandler.TagChange(gameState, match.Groups["tag"].Value, entity.Key, match.Groups["value"].Value, game);
}
if(_tmpEntities.Contains(tmpEntity))
{
tmpEntity.SetTag(tag, value);
var player = game.Player.Name == tmpEntity.Name ? game.Player
: (game.Opponent.Name == tmpEntity.Name ? game.Opponent : null);
if(player != null)
{
var playerEntity = game.Entities.FirstOrDefault(x => x.Value.GetTag(GameTag.PLAYER_ID) == player.Id).Value;
if(playerEntity != null)
{
playerEntity.Name = tmpEntity.Name;
foreach(var t in tmpEntity.Tags)
_tagChangeHandler.TagChange(gameState, t.Key, playerEntity.Id, t.Value, game);
_tmpEntities.Remove(tmpEntity);
}
}
}
}
else
_tagChangeHandler.TagChange(gameState, match.Groups["tag"].Value, entity.Key, match.Groups["value"].Value, game);
}
}
else if(CreationRegex.IsMatch(logLine))
//.........这里部分代码省略.........