/// <summary> /// Performs common tool usage logic and also sends start / end action messages, and invokes a callback on success. /// </summary> /// <param name="handApply">interaction causing the tool use</param> /// <param name="seconds">seconds taken to perform the action, 0 if it should be instant</param> /// <param name="performerStartActionMessage">message to show performer when action begins.</param> /// <param name="othersStartActionMessage">message to show others when action begins.</param> /// <param name="performerFinishActionMessage">message to show performer when action completes successfully.</param> /// <param name="othersFinishActionMessage">message to show others when action completes successfully.</param> /// <param name="onSuccessfulCompletion">called when action is completed</param> public static void ServerUseToolWithActionMessages(PositionalHandApply handApply, float seconds, string performerStartActionMessage, string othersStartActionMessage, string performerFinishActionMessage, string othersFinishActionMessage, Action onSuccessfulCompletion) { ServerUseToolWithActionMessages(handApply.Performer, handApply.HandObject, ActionTarget.Tile(handApply.WorldPositionTarget), seconds, performerStartActionMessage, othersStartActionMessage, performerFinishActionMessage, othersFinishActionMessage, onSuccessfulCompletion); }
/// <summary> /// Performs common tool usage logic and also sends start / end action messages, and invokes a callback on success. /// </summary> /// <param name="handApply">interaction causing the tool use</param> /// <param name="seconds">seconds taken to perform the action, 0 if it should be instant</param> /// <param name="performerStartActionMessage">message to show performer when action begins.</param> /// <param name="othersStartActionMessage">message to show others when action begins.</param> /// <param name="performerFinishActionMessage">message to show performer when action completes successfully.</param> /// <param name="othersFinishActionMessage">message to show others when action completes successfully.</param> /// <param name="onSuccessfulCompletion">called when action is completed</param> /// <param name="performerFailMessage">message to show performer when action completes unsuccessfully.</param> /// <param name="othersFailMessage">message to show others when action completes unsuccessfully.</param> /// <param name="onFailComplete">called when action is completed unsuccessfully.</param> /// <param name="playSound">Whether to play default tool sound</param> public static void ServerUseToolWithActionMessages(PositionalHandApply handApply, float seconds, string performerStartActionMessage, string othersStartActionMessage, string performerFinishActionMessage, string othersFinishActionMessage, Action onSuccessfulCompletion, string performerFailMessage = "", string othersFailMessage = "", Action onFailComplete = null, bool playSound = true) { ServerUseToolWithActionMessages(handApply.Performer, handApply.HandObject, ActionTarget.Tile(handApply.WorldPositionTarget), seconds, performerStartActionMessage, othersStartActionMessage, performerFinishActionMessage, othersFinishActionMessage, onSuccessfulCompletion, performerFailMessage, othersFailMessage, onFailComplete, playSound); }
/// <summary> /// Performs common tool usage logic and also sends start / end action messages, and invokes a callback on success. /// </summary> /// <param name="tileApply">interaction causing the tool use</param> /// <param name="seconds">seconds taken to perform the action, 0 if it should be instant</param> /// <param name="performerStartActionMessage">message to show performer when action begins.</param> /// <param name="othersStartActionMessage">message to show others when action begins.</param> /// <param name="performerFinishActionMessage">message to show performer when action completes successfully.</param> /// <param name="othersFinishActionMessage">message to show others when action completes successfully.</param> /// <param name="onSuccessfulCompletion">called when action is completed</param> /// <param name="performerFailMessage">message to show performer when action completes unsuccessfully.</param> /// <param name="othersFailMessage">message to show others when action completes unsuccessfully.</param> /// <param name="onFailComplete">called when action is completed unsuccessfully.</param> public static void ServerUseToolWithActionMessages(TileApply tileApply, float seconds, string performerStartActionMessage, string othersStartActionMessage, string performerFinishActionMessage, string othersFinishActionMessage, Action onSuccessfulCompletion, string performerFailMessage = "", string othersFailMessage = "", Action onFailComplete = null) { ServerUseToolWithActionMessages(tileApply.Performer, tileApply.HandObject, ActionTarget.Tile(tileApply.WorldPositionTarget), seconds, performerStartActionMessage, othersStartActionMessage, performerFinishActionMessage, othersFinishActionMessage, onSuccessfulCompletion, performerFailMessage, othersFailMessage, onFailComplete); }
public override IEnumerator Process() { var clientStorage = SentByPlayer.Script.ItemStorage; var usedSlot = clientStorage.GetActiveHandSlot(); if (usedSlot == null || usedSlot.ItemObject == null) { yield break; } var hasConstructionMenu = usedSlot.ItemObject.GetComponent <BuildingMaterial>(); if (hasConstructionMenu == null) { yield break; } var entry = hasConstructionMenu.BuildList.Entries.ToArray()[EntryIndex]; if (!entry.CanBuildWith(hasConstructionMenu)) { yield break; } //check if the space to construct on is passable if (!MatrixManager.IsPassableAt((Vector3Int)SentByPlayer.GameObject.TileWorldPosition(), true, includingPlayers: false)) { Chat.AddExamineMsg(SentByPlayer.GameObject, "It won't fit here."); yield break; } //if we are building something impassable, check if there is anything on the space other than the performer. var atPosition = MatrixManager.GetAt <RegisterTile>((Vector3Int)SentByPlayer.GameObject.TileWorldPosition(), true); if (entry.Prefab == null) { //requires immediate attention, show it regardless of log filter: Logger.Log($"Construction entry is missing prefab for {entry.Name}"); yield break; } var registerTile = entry.Prefab.GetComponent <RegisterTile>(); if (registerTile == null) { Logger.LogWarningFormat("Buildable prefab {0} has no registerTile, no idea if it's passable", Category.Construction, entry.Prefab); } var builtObjectIsImpassable = registerTile == null || !registerTile.IsPassable(true); foreach (var thingAtPosition in atPosition) { if (entry.OnePerTile) { //can only build one of this on a given tile if (entry.Prefab.Equals(Spawn.DeterminePrefab(thingAtPosition.gameObject))) { Chat.AddExamineMsg(SentByPlayer.GameObject, $"There's already one here."); yield break; } } if (builtObjectIsImpassable) { //if the object we are building is itself impassable, we should check if anything blocks construciton. //otherwise it's fine to add it to the pile on the tile if (ServerValidations.IsConstructionBlocked(SentByPlayer.GameObject, null, SentByPlayer.GameObject.TileWorldPosition())) { yield break; } } } //build and consume void ProgressComplete() { if (entry.ServerBuild(SpawnDestination.At(SentByPlayer.Script.registerTile), hasConstructionMenu)) { Chat.AddActionMsgToChat(SentByPlayer.GameObject, $"You finish building the {entry.Name}.", $"{SentByPlayer.GameObject.ExpensiveName()} finishes building the {entry.Name}."); } } Chat.AddActionMsgToChat(SentByPlayer.GameObject, $"You begin building the {entry.Name}...", $"{SentByPlayer.GameObject.ExpensiveName()} begins building the {entry.Name}..."); ToolUtils.ServerUseTool(SentByPlayer.GameObject, usedSlot.ItemObject, ActionTarget.Tile(SentByPlayer.Script.registerTile.WorldPositionServer), entry.BuildTime, ProgressComplete); }
/// <summary> /// Performs common tool usage logic, such as playing the correct sound. /// If item is not a tool, simply performs the progress action normally. /// </summary> /// <param name="tileApply">tile apply causing the tool usage</param> /// <param name="seconds">seconds taken to perform the action, 0 for instant.</param> /// <param name="progressCompleteAction">completion callback</param> /// <param name="playSound">Whether to play default tool sound</param> /// <returns>progress bar spawned, null if progress did not start</returns> public static ProgressBar ServerUseTool(TileApply tileApply, float seconds = 0, Action progressCompleteAction = null, bool playSound = true) { return(ServerUseTool(tileApply.Performer, tileApply.HandObject, ActionTarget.Tile(tileApply.WorldPositionTarget), seconds, progressCompleteAction, playSound)); }
/// <summary> /// Performs common tool usage logic, such as playing the correct sound. /// If item is not a tool, simply performs the progress action normally. /// </summary> /// <param name="positionalHandApply">positional hand apply causing the tool usage</param> /// <param name="seconds">seconds taken to perform the action, 0 for instant.</param> /// <param name="progressCompleteAction">completion callback</param> /// <returns>progress bar spawned, null if progress did not start</returns> public static ProgressBar ServerUseTool(PositionalHandApply positionalHandApply, float seconds = 0, Action progressCompleteAction = null) { return(ServerUseTool(positionalHandApply.Performer, positionalHandApply.HandObject, ActionTarget.Tile(positionalHandApply.WorldPositionTarget), seconds, progressCompleteAction)); }
/// <summary> /// Start a progress action targeting a specific tile. /// Tries to create and begin animating a progress bar for a specific player. Returns null /// if progress did not begin for some reason. /// </summary> /// <param name="progressAction">progress action being performed</param> /// <param name="worldTilePos">tile position the action is being performed on</param> /// <param name="timeForCompletion">how long in seconds the action should take</param> /// <param name="player">player performing the action</param> /// <returns>progress bar associated with this action (can use this to interrupt progress). Null if /// progress was not started for some reason (such as already in progress for this action on the specified tile).</returns> public static ProgressBar ServerStartProgress(this IProgressAction progressAction, Vector3 worldTilePos, float timeForCompletion, GameObject player) { return(UIManager._ServerStartProgress(progressAction, ActionTarget.Tile(worldTilePos), timeForCompletion, player)); }