protected virtual bool DoIload(string rawParameters, params CommandParameter[] parameters) { if (parameters.Length == 0 || !parameters[0].IsNumber) { Send("Syntax: iload <id>"); return(true); } ItemBlueprintBase itemBlueprint = DependencyContainer.Instance.GetInstance <IWorld>().GetItemBlueprint(parameters[0].AsNumber); if (itemBlueprint == null) { Send("No item with that id."); return(true); } IContainer container = itemBlueprint.WearLocation == WearLocations.None ? Impersonating.Room as IContainer : Impersonating as IContainer; IItem item = DependencyContainer.Instance.GetInstance <IWorld>().AddItem(Guid.NewGuid(), itemBlueprint, container); if (item == null) { Send("Item cannot be created."); DependencyContainer.Instance.GetInstance <IServer>().Wiznet($"DoIload: item with id {parameters[0].AsNumber} cannot be created", WiznetFlags.Bugs, AdminLevels.Implementor); return(true); } DependencyContainer.Instance.GetInstance <IServer>().Wiznet($"{DisplayName} loads {item.DebugName}.", WiznetFlags.Load); Impersonating.Act(ActOptions.ToAll, "{0:N} {0:h} created {1}!", Impersonating, item); Send("Ok."); return(true); }
protected virtual bool DoCload(string rawParameters, params CommandParameter[] parameters) { if (parameters.Length == 0 || !parameters[0].IsNumber) { Send("Syntax: cload <id>"); return(true); } CharacterBlueprint characterBlueprint = DependencyContainer.Instance.GetInstance <IWorld>().GetCharacterBlueprint(parameters[0].AsNumber); if (characterBlueprint == null) { Send("No character with that id."); return(true); } ICharacter character = DependencyContainer.Instance.GetInstance <IWorld>().AddCharacter(Guid.NewGuid(), characterBlueprint, Impersonating.Room); if (character == null) { Send("Character cannot be created."); DependencyContainer.Instance.GetInstance <IServer>().Wiznet($"DoCload: character with id {parameters[0].AsNumber} cannot be created", WiznetFlags.Bugs, AdminLevels.Implementor); return(true); } DependencyContainer.Instance.GetInstance <IServer>().Wiznet($"{DisplayName} loads {character.DebugName}.", WiznetFlags.Load); Impersonating.Act(ActOptions.ToAll, "{0:N} {0:h} created {1:n}!", Impersonating, character); Send("Ok."); return(true); }
protected virtual bool DoGoto(string rawParameters, params CommandParameter[] parameters) { if (parameters.Length == 0) { Send("Goto where?"); return(true); } // IRoom where = FindHelpers.FindLocation(Impersonating, parameters[0]); if (where == null) { Send("No such location."); return(true); } if (Impersonating.Fighting != null) { Impersonating.StopFighting(true); } Impersonating.Act(Impersonating.Room.People.Where(x => x != Impersonating && x.CanSee(Impersonating)), "{0} leaves in a swirling mist.", Impersonating); // Don't display 'Someone leaves ...' if Impersonating is not visible Impersonating.ChangeRoom(where); Impersonating.Act(Impersonating.Room.People.Where(x => x != Impersonating && x.CanSee(Impersonating)), "{0} appears in a swirling mist.", Impersonating); Impersonating.AutoLook(); return(true); }
protected virtual bool DoPurge(string rawParameters, params CommandParameter[] parameters) { if (parameters.Length == 0) { Send("Purge what?"); return(true); } IItem item = FindHelpers.FindItemHere(Impersonating, parameters[0]); if (item == null) { Send(StringHelpers.ItemNotFound); return(true); } DependencyContainer.Instance.GetInstance <IServer>().Wiznet($"{DisplayName} purges {item.DebugName}.", WiznetFlags.Punish); Impersonating.Act(ActOptions.ToAll, "{0:N} purge{0:v} {1}!", Impersonating, item); DependencyContainer.Instance.GetInstance <IWorld>().RemoveItem(item); return(true); }
protected virtual bool DoQuit(string rawParameters, params CommandParameter[] parameters) { if (Impersonating != null) { if (Impersonating.Fighting != null) { Send("No way! You are fighting."); return(true); } if (Impersonating.Position == Positions.Stunned) { Send("You can't leave while stunned."); return(true); } } Send("Alas, all good things must come to an end."); Impersonating?.Act(ActOptions.ToRoom, "{0:N} has left the game.", Impersonating); DependencyContainer.Instance.GetInstance <IServer>().Wiznet($"{DisplayName} rejoins the real world.", WiznetFlags.Logins); Save(); DependencyContainer.Instance.GetInstance <IServer>().Quit(this); return(true); }
public override bool ProcessCommand(string commandLine) // TODO: refactoring needed: almost same code in Player { // ! means repeat last command if (commandLine != null && commandLine.Length >= 1 && commandLine[0] == '!') { commandLine = LastCommand; LastCommandTimestamp = DateTime.Now; } else { LastCommand = commandLine; LastCommandTimestamp = DateTime.Now; } // If an input state machine is running, send commandLine to machine if (CurrentStateMachine != null && !CurrentStateMachine.IsFinalStateReached) { CurrentStateMachine.ProcessInput(this, commandLine); return(true); } else { CurrentStateMachine = null; // reset current state machine if not currently running one // Extract command and parameters bool extractedSuccessfully = CommandHelpers.ExtractCommandAndParameters(Aliases, commandLine, out var command, out var rawParameters, out var parameters, out var forceOutOfGame); if (!extractedSuccessfully) { Log.Default.WriteLine(LogLevels.Warning, "Command and parameters not extracted successfully"); Send("Invalid command or parameters"); return(false); } // Execute command bool executedSuccessfully; if (forceOutOfGame || (Impersonating == null && Incarnating == null)) // neither incarnating nor impersonating { Log.Default.WriteLine(LogLevels.Debug, "[{0}] executing [{1}]", DisplayName, commandLine); executedSuccessfully = ExecuteCommand(command, rawParameters, parameters); } else if (Incarnating != null) // incarnating { Log.Default.WriteLine(LogLevels.Debug, "[{0}]|[{1}] executing [{2}]", DisplayName, Incarnating.DebugName, commandLine); executedSuccessfully = Incarnating.ExecuteCommand(command, rawParameters, parameters); } else if (Impersonating != null) // impersonating { Log.Default.WriteLine(LogLevels.Debug, "[{0}]|[{1}] executing [{2}]", DisplayName, Impersonating.DebugName, commandLine); executedSuccessfully = Impersonating.ExecuteCommand(command, rawParameters, parameters); } else { Log.Default.WriteLine(LogLevels.Error, "[{0}] is neither out of game, nor impersonating, nor incarnating"); executedSuccessfully = false; } if (!executedSuccessfully) { Log.Default.WriteLine(LogLevels.Warning, "Error while executing command"); } return(executedSuccessfully); } }