//////////////// /// @private public override void Action(CommandCaller caller, string input, string[] args) { if (Main.netMode == NetmodeID.MultiplayerClient) { LogHelpers.Warn("Not supposed to run on client."); return; } var cutMngr = CutsceneManager.Instance; var introId = new CutsceneID(CutsceneLibMod.Instance, typeof(IntroCutscene)); if (cutMngr.CanBeginCutscene(false, introId, caller.Player, out string result)) { if (cutMngr.TryBeginCutscene(false, introId, caller.Player, true, out result)) { caller.Reply(result, Color.Lime); } else { caller.Reply(result, Color.Yellow); } } else { caller.Reply(result, Color.Red); } }
//////////////// protected sealed override void Receive() { var mngr = CutsceneManager.Instance; var cutsceneId = new CutsceneID(this.CutsceneModName, this.CutsceneClassFullName); Player playsFor = Main.player[this.PlaysForWho]; if (playsFor?.active != true) { LogHelpers.Warn("Missing player #" + this.PlaysForWho); return; } var cutscene = mngr.GetCurrentCutscene_Player(playsFor); if (cutscene == null) { LogHelpers.Warn("No cutscene " + cutsceneId + " playing " + playsFor.name + " (" + this.PlaysForWho + ")"); return; } SceneID sceneId = new SceneID(this.SceneModName, this.SceneClassFullName); mngr.SetCutsceneSceneFromNetwork(cutsceneId, playsFor, sceneId, this, false); }
//// private void Receive() { var mngr = CutsceneManager.Instance; var cutsceneId = new CutsceneID(this.CutsceneModName, this.CutsceneClassFullName); if (mngr.EndCutscene(cutsceneId, this.PlaysForWho, false)) { LogHelpers.Warn("Cannot end cutscene " + cutsceneId + "."); } }
//////////////// protected sealed override void Receive() { /*LogHelpers.Log( "RECEIVE " +"PlaysForWho:"+this.PlaysForWho + ", CutsceneModName:" + this.CutsceneModName + ", CutsceneClassFullName:" + this.CutsceneClassFullName + ", SceneModName:" + this.SceneModName + ", SceneClassFullName:" + this.SceneClassFullName );*/ var mngr = CutsceneManager.Instance; var cutsceneId = new CutsceneID(this.CutsceneModName, this.CutsceneClassFullName); Player playsFor = Main.player[this.PlaysForWho]; if (playsFor?.active != true) { LogHelpers.Warn("Missing player #" + this.PlaysForWho); return; } if (!mngr.CanBeginCutscene(false, cutsceneId, playsFor, out string result)) { LogHelpers.Warn("Cannot play cutscene " + cutsceneId + ": " + result); return; } SceneID sceneId = new SceneID(this.SceneModName, this.SceneClassFullName); if (!this.PreReceive(cutsceneId, sceneId)) { return; } // void onSuccess(string myResult) { LogHelpers.Log("Beginning cutscene " + cutsceneId + " result for client: " + myResult); } void onFail(string myResult) { LogHelpers.Warn("Cannot play cutscene " + cutsceneId + ": " + myResult); //if( !mngr.SetCutsceneScene( cutsceneId, playsFor, sceneId, false ) ) { } } // mngr.TryBeginCutsceneFromNetwork(cutsceneId, sceneId, playsFor, this, onSuccess, onFail); this.PostReceive(); }
//// public void TryBeginCutsceneFromNetwork( CutsceneID cutsceneId, SceneID sceneId, Player playsFor, CutsceneStartProtocol data, Action <string> onSuccess, Action <string> onFail) { if (!this.CanBeginCutscene(false, cutsceneId, playsFor, out Cutscene cutscene, out string result)) { onFail("Cannot play cutscene " + cutsceneId + ": " + result); return; } if (this.CutsceneInWaitingPerClient.ContainsKey(playsFor.whoAmI)) { cutscene = this.CutsceneInWaitingPerClient[playsFor.whoAmI]; } this.CutsceneInWaitingPerClient[playsFor.whoAmI] = cutscene; // void onMySuccess(string myResult) { this._CutscenePerPlayer[playsFor.whoAmI] = cutscene; this.CutsceneInWaitingPerClient.Remove(playsFor.whoAmI); // just in case var myplayer = playsFor.GetModPlayer <CutsceneLibPlayer>(); myplayer.TriggeredCutsceneIDs_Player.Add(cutsceneId); var myworld = ModContent.GetInstance <CutsceneLibWorld>(); myworld.TriggeredCutsceneIDs_World.Add(cutsceneId); onSuccess(myResult); } void onMyFail(string myResult) { this.EndCutscene(cutscene, playsFor.whoAmI, false); onFail(myResult); } // cutscene.BeginCutsceneFromNetwork_Internal(sceneId, data, onMySuccess, onMyFail); }
internal void NetReceive_World(CutsceneLibWorld myworld, BinaryReader reader) { myworld.TriggeredCutsceneIDs_World.Clear(); int count = reader.ReadInt32(); for (int i = 0; i < count; i++) { string modName = reader.ReadString(); string className = reader.ReadString(); var uid = new CutsceneID(modName, className); myworld.TriggeredCutsceneIDs_World.Add(uid); } }
//////////////// public bool TryBeginCutscene( bool isAutoplay, CutsceneID cutsceneId, Player playsFor, bool sync, out string result) { if (!this.CanBeginCutscene(isAutoplay, cutsceneId, playsFor, out Cutscene cutscene, out result)) { result = "Cannot play cutscene " + cutsceneId + ": " + result; return(false); } return(this.TryBeginCutscene(cutscene, sync, out result)); }
//////////////// public bool EndCutscene(CutsceneID cutsceneId, int playsForWhom, bool sync) { Cutscene cutscene = this._CutscenePerPlayer.GetOrDefault(playsForWhom); if (cutscene == null) { return(false); } if (cutscene.UniqueId != cutsceneId) { return(false); } return(this.EndCutscene(cutscene, playsForWhom, sync)); }
//////////////// internal void Load_Player(CutsceneLibPlayer myplayer, TagCompound tag) { myplayer.TriggeredCutsceneIDs_Player.Clear(); if (!tag.ContainsKey("TriggeredCutscenesCount")) { return; } int count = tag.GetInt("TriggeredCutscenesCount"); for (int i = 0; i < count; i++) { string modName = tag.GetString("TriggeredCutsceneMod_" + i); string className = tag.GetString("TriggeredCutsceneName_" + i); var uid = new CutsceneID(modName, className); myplayer.TriggeredCutsceneIDs_Player.Add(uid); } }
internal void Load_World(CutsceneLibWorld myworld, TagCompound tag) { this.ResetCutscenes(); myworld.TriggeredCutsceneIDs_World.Clear(); if (!tag.ContainsKey("TriggeredCutscenesCount")) { return; } int count = tag.GetInt("TriggeredCutscenesCount"); for (int i = 0; i < count; i++) { string modName = tag.GetString("TriggeredCutsceneMod_" + i); string className = tag.GetString("TriggeredCutsceneName_" + i); var uid = new CutsceneID(modName, className); myworld.TriggeredCutsceneIDs_World.Add(uid); } }
//////////////// internal bool SetCutsceneSceneFromNetwork( CutsceneID cutsceneId, Player playsFor, SceneID sceneId, CutsceneUpdateProtocol netData, bool sync) { Cutscene cutscene = this._CutscenePerPlayer.GetOrDefault(playsFor.whoAmI); if (cutscene == null) { return(false); } if (cutscene.UniqueId != cutsceneId) { return(false); } cutscene.SetCurrentSceneFromNetwork_Internal(sceneId, netData, sync); return(true); }
//// private bool CanBeginCutscene( bool isAutoplay, CutsceneID cutsceneId, Player playsFor, out Cutscene cutscene, out string result) { if (this.GetCurrentCutscene_Player(playsFor) != null) { cutscene = null; result = "Player " + playsFor.name + " (" + playsFor.whoAmI + ") is already playing " + cutsceneId; return(false); } cutscene = cutsceneId.Create(playsFor); if (isAutoplay && !cutscene.CanAutoplay) { result = "Cutscene " + cutsceneId + " does not support autoplay."; return(false); } if (!cutscene.CanReplayPerWorld && this.HasCutscenePlayed_World(cutsceneId)) { cutscene = null; result = "World has already played " + playsFor.name + " (" + playsFor.whoAmI + ")'s cutscene " + cutsceneId; return(false); } if (!cutscene.CanReplayPerPlayer && this.HasCutscenePlayed_Player(cutsceneId, playsFor)) { cutscene = null; result = "Player has already played " + playsFor.name + " (" + playsFor.whoAmI + ")'s cutscene " + cutsceneId; return(false); } return(cutscene.CanBegin(out result)); }
//// protected virtual bool PreReceive(CutsceneID cutsceneId, SceneID sceneId) { return(true); }
public bool HasCutscenePlayed_Player(CutsceneID cutsceneId, Player player) { var myplayer = player.GetModPlayer <CutsceneLibPlayer>(); return(myplayer.TriggeredCutsceneIDs_Player.Contains(cutsceneId)); }
//////////////// public bool HasCutscenePlayed_World(CutsceneID cutsceneId) { var myworld = ModContent.GetInstance <CutsceneLibWorld>(); return(myworld.TriggeredCutsceneIDs_World.Contains(cutsceneId)); }
public bool CanBeginCutscene(bool isAutoplay, CutsceneID cutsceneId, Player playsFor, out string result) { return(this.CanBeginCutscene(isAutoplay, cutsceneId, playsFor, out Cutscene _, out result)); }