public void Command(ChatParser.Command command) { if (HitPoints.IsAlive == false) { return; } switch (command.commandType) { case ChatParser.ChatCommands.Gather: GatherResource(command.resourceType); break; case ChatParser.ChatCommands.Build: if (CurrentJob.canBuild == false) { return; } unitBehaviour.Build(command.buildingType, command.position, command.direction); break; case ChatParser.ChatCommands.Job: if (command.jobType == CurrentJob.jobType || TryGetJobFromType(command.jobType, out var job) == false || UnitTeam.CheckHasBuilding(job.buildingNeeded) == false) { return; } unitBehaviour.ChangeJob(job); break; case ChatParser.ChatCommands.Patrol: if (CurrentJob.canPatrol == false) { return; } unitBehaviour.Patrol(command.position, command.secondPosition); break; case ChatParser.ChatCommands.Move: unitBehaviour.Move(command.position); break; case ChatParser.ChatCommands.Kill: var enemyTeam = GameController.Instance.GetEnemyTeam(UnitTeam); Unit target = string.IsNullOrEmpty(command.targetName) == false?enemyTeam.GetUnit(command.targetIndex) : (command.teamTag != UnitTeam.teamTag ? enemyTeam.GetUnit(command.targetIndex) : null); if (target == null) { return; } unitBehaviour.AttackTarget(target.HitPoints); break; } }
private void ChatCommandHandler(ChatParser.Command command) { Unit unit = null; if (command.commandType != ChatParser.ChatCommands.Join) { if (command.isBotCommand) { var team = command.teamTag == TeamTag.green ? greenTeam : redTeam; if (team.Units.Count <= command.botIndex) { return; } unit = team.Units[command.botIndex]; if (unit.IsPlayer) { return; } } else if (playerUnits.ContainsKey(command.user)) { unit = playerUnits[command.user]; } else { return; } } switch (command.commandType) { case ChatParser.ChatCommands.Join: JoinUser(command.user, command.teamTag); break; case ChatParser.ChatCommands.Gather: case ChatParser.ChatCommands.Build: case ChatParser.ChatCommands.Job: case ChatParser.ChatCommands.Patrol: case ChatParser.ChatCommands.Move: case ChatParser.ChatCommands.Kill: unit.Command(command); break; default: throw new ArgumentOutOfRangeException(); } }