public void Register(GameCommandType type, GameCommandHandler handler) { List <System.Action> callbacks = null; if (!handlers.TryGetValue(type, out callbacks)) { callbacks = handlers[type] = new List <System.Action>(); } callbacks.Add(handler.OnInteraction); }
public void Receive(GameCommandType type, object sender) { List <Action <object> > callbackList; if (handerDic.TryGetValue(type, out callbackList)) { foreach (var callback in callbackList) { callback(sender); } } }
public void Register(GameCommandType type, ICommandHandler handler) { List <Action <object> > callbackList; if (!handerDic.TryGetValue(type, out callbackList)) { handerDic[type] = new List <Action <object> >(); callbackList = handerDic[type]; } callbackList.Add(handler.OnReceve); }
public void Register(GameCommandType type, GameCommandHandler gch) { List <Action <object> > callbackList; if (!handerDic.TryGetValue(type, out callbackList)) { handerDic[type] = new List <Action <object> >(); callbackList = handerDic[type]; } callbackList.Add(gch.OnInteractor); }
public void Receive(GameCommandType e) { List <System.Action> callbacks = null; if (handlers.TryGetValue(e, out callbacks)) { foreach (var i in callbacks) { i(); } } }
public void HandlePacket() { while (_packet.Data.Length > 0) { GameCommandType gameCommandType = _packet.Pull <GameCommandType>(); ICommandHandler commandHandler; switch (gameCommandType) { case GameCommandType.SetControllablePlayer: commandHandler = new SetControllablePlayerCommandHandler(_packet, _modelManagerClient); break; default: throw new ArgumentOutOfRangeException(); } commandHandler.HandleCommand(); } }
public void HandleData() { while (_unprocessedReceivedPacket.Data.Length > 0) { IDataHandler dataHandler; GameCommandType commandType = _unprocessedReceivedPacket.Pull <GameCommandType>(); switch (commandType) { case GameCommandType.CharacterAttackEnemy: dataHandler = new CharacterAttackEnemyDataHandler(_unprocessedReceivedPacket, _modelManagerServer); break; case GameCommandType.HoldWeaponChanged: dataHandler = new HoldWeaponChangedDataHandler(_unprocessedReceivedPacket, _modelManagerServer); break; default: throw new ArgumentOutOfRangeException(); } dataHandler.HandleData(); } }
public override MouseHandlingResult HandleClick() { bool clearSelectionFirst = false; bool unselectingInstead = false; if (Engine_AIW2.Instance.PresentationLayer.GetAreInputFlagsActive(ArcenInputFlags.Additive)) { } else if (Engine_AIW2.Instance.PresentationLayer.GetAreInputFlagsActive(ArcenInputFlags.Subtractive)) { unselectingInstead = true; } else { clearSelectionFirst = true; } bool isAssigningToGroup = Engine_AIW2.Instance.PresentationLayer.GetAreInputFlagsActive(ArcenInputFlags.ModifyingControlGroup); if (this.ControlGroup == null) { return(MouseHandlingResult.PlayClickDeniedSound); } Planet planet = Engine_AIW2.Instance.NonSim_GetPlanetBeingCurrentlyViewed(); bool foundOne = false; if (isAssigningToGroup) { GameCommandType commandType = GameCommandType.SetControlGroupPopulation; if (unselectingInstead) { commandType = GameCommandType.RemoveFromControlGroupPopulation; } else if (!clearSelectionFirst) { commandType = GameCommandType.AddToControlGroupPopulation; } else { commandType = GameCommandType.SetControlGroupPopulation; } GameCommand command = GameCommand.Create(commandType); command.SentWithToggleSet_SetOrdersForProducedUnits = Engine_AIW2.Instance.SettingOrdersForProducedUnits; command.RelatedControlGroup = this.ControlGroup; Engine_AIW2.Instance.DoForSelected(SelectionCommandScope.CurrentPlanet_UnlessViewingGalaxy, delegate(GameEntity selected) { command.RelatedEntityIDs.Add(selected.PrimaryKeyID); return(DelReturn.Continue); }); World_AIW2.Instance.QueueGameCommand(command, true); } else { this.ControlGroup.DoForEntities(delegate(GameEntity entity) { if (entity.Combat.Planet != planet) { return(DelReturn.Continue); } if (!foundOne) { foundOne = true; if (clearSelectionFirst) { if (entity.GetIsSelected()) { Engine_AIW2.Instance.PresentationLayer.CenterPlanetViewOnEntity(entity, false); } Engine_AIW2.Instance.ClearSelection(SelectionCommandScope.CurrentPlanet_UnlessViewingGalaxy); } } if (unselectingInstead) { entity.Unselect(); } else { entity.Select(); } return(DelReturn.Continue); }); if (!foundOne && clearSelectionFirst) { Engine_AIW2.Instance.ClearSelection(SelectionCommandScope.CurrentPlanet_UnlessViewingGalaxy); this.ControlGroup.DoForEntities(delegate(GameEntity entity) { if (!foundOne) { foundOne = true; Engine_AIW2.Instance.PresentationLayer.ReactToLeavingPlanetView(planet); planet = entity.Combat.Planet; World_AIW2.Instance.SwitchViewToPlanet(planet); Engine_AIW2.Instance.PresentationLayer.CenterPlanetViewOnEntity(entity, true); Engine_AIW2.Instance.PresentationLayer.ReactToEnteringPlanetView(planet); } if (entity.Combat.Planet != planet) { return(DelReturn.Continue); } entity.Select(); return(DelReturn.Continue); }); } Window_InGameBottomMenu.Instance.CloseAllExpansions(); } return(MouseHandlingResult.None); }
public void Remove(GameCommandType type, ICommandHandler handler) { handerDic[type].Remove(handler.OnReceve); }
public void Remove(GameCommandType type, GameCommandHandler handler) { handerDic[type].Remove(handler.OnInteractor); }
public void Remove(GameCommandType type, GameCommandHandler handler) { handlers[type].Remove(handler.OnInteraction); }
//--- Methods --- public IEnumerable <AGameResponse> Do(GamePlayer player, GameCommandType command) { var result = new List <AGameResponse>(); // some commands are optional and don't require to be defined for a place var optional = false; switch (command) { case GameCommandType.Describe: case GameCommandType.Help: case GameCommandType.Hint: case GameCommandType.Restart: case GameCommandType.Quit: optional = true; break; } // check if the place has associated actions for the choice GamePlace place = Places[player.PlaceId]; if (place.Choices.TryGetValue(command, out IEnumerable <KeyValuePair <GameActionType, string> > choice)) { foreach (var action in choice) { switch (action.Key) { case GameActionType.Goto: if (!Places.TryGetValue(action.Value, out place)) { throw new GameException($"Cannot find place: '{action.Value}'"); } if (player.PlaceId != place.Id) { player.PlaceId = place.Id; DescribePlace(place); // check if the current place marks the end of the adventure if (place.Finished) { result.Add(new GameResponseFinished()); } } break; case GameActionType.Say: result.Add(new GameResponseSay(action.Value)); break; case GameActionType.Pause: if (!double.TryParse(action.Value, out double delayValue)) { throw new GameException($"Delay must be a number: '{action.Value}'"); } result.Add(new GameResponseDelay(TimeSpan.FromSeconds(delayValue))); break; case GameActionType.Play: result.Add(new GameResponsePlay(action.Value)); break; } } } else if (!optional) { result.Add(new GameResponseNotUnderstood()); } switch (command) { case GameCommandType.Describe: DescribePlace(place); break; case GameCommandType.Help: result.Add(new GameResponseSay(place.Instructions)); break; case GameCommandType.Hint: // hints are optional; nothing else to do by default break; case GameCommandType.Restart: if ((choice == null) || !choice.Any(c => c.Key == GameActionType.Goto)) { place = Places[Game.StartPlaceId]; player.PlaceId = place.Id; } DescribePlace(place); break; case GameCommandType.Quit: result.Add(new GameResponseBye()); break; } return(result); // helper functions void DescribePlace(GamePlace current) { if ((current.Description != null) && (current.Instructions != null)) { result.Add(new GameResponseSay(current.Description)); result.Add(new GameResponseSay(current.Instructions)); } else if (current.Description != null) { result.Add(new GameResponseSay(current.Description)); } else if (current.Instructions != null) { result.Add(new GameResponseSay(current.Instructions)); } } }
//--- Extension Methods --- public static IEnumerable <AGameResponse> TryDo(this Game game, GamePlayer player, GameCommandType command) { try { return(game.Do(player, command)); } catch (GameException e) { LambdaLogger.Log($"*** ERROR: a game exception occurred ({e.Message})\n"); return(new[] { new GameResponseSay("") }); } catch (Exception e) { LambdaLogger.Log($"*** ERROR: {e}\n"); return(new[] { new GameResponseSay("Oops, something went wrong. Please try again.") }); } }
public GameCommandSignal(Neuron neuron, GameCommandType type) { FromNeuron = neuron; CommandType = type; }