public TriggerSceneEffectEditor() { scenes = Controller.Instance.IdentifierSummary.getIds <IChapterTarget>(); this.effect = new TriggerSceneEffect(scenes[0], 400, 300) { DestinyScale = 1 }; SetDestinyScene(0); localSceneEditor = new SceneEditor(); playerDestination = new Trajectory.Node("", 0, 0, 1f); localSceneEditor.Elements = new List <DataControl>() { new NodeDataControl(null, playerDestination, new Trajectory()) }; transitionTypes = new string[] { TC.get("NextScene.NoTransition"), TC.get("NextScene.TopToBottom"), TC.get("NextScene.BottomToTop"), TC.get("NextScene.LeftToRight"), TC.get("NextScene.RightToLeft"), TC.get("NextScene.FadeIn") }; }
public TriggerSceneEffectEditor() { scenes = Controller.getInstance().getSelectedChapterDataControl() .getObjects() .FindAll(o => o is IChapterTarget) .ConvertAll(t => (t as IChapterTarget).getId()) .ToArray(); this.effect = new TriggerSceneEffect(scenes[0], x, y); }
private InteractuableResult FinishCutscene(Cutscene cutscene) { InteractuableResult res = InteractuableResult.DOES_SOMETHING; TriggerSceneEffect triggerScene = null; switch ((cutscene).getNext()) { default: // By default Cutscene.GOBACK var previousTarget = Game.Instance.GameState.PreviousChapterTarget; if (previousTarget == null) { var possibleTargets = Game.Instance.GameState.GetObjects <IChapterTarget>(); previousTarget = possibleTargets.FirstOrDefault(t => t.getId() != this.SceneData.getId()); } if (previousTarget != null) { triggerScene = new TriggerSceneEffect(previousTarget.getId(), int.MinValue, int.MinValue, float.MinValue, cutscene.getTransitionTime(), (int)cutscene.getTransitionType()); } break; case Cutscene.NEWSCENE: triggerScene = new TriggerSceneEffect(cutscene.getTargetId(), int.MinValue, int.MinValue, float.MinValue, cutscene.getTransitionTime(), (int)cutscene.getTransitionType()); break; case Cutscene.ENDCHAPTER: // TODO: When we add more chapters, we must trigger the next chapter instead of quiting que aplication GUIManager.Instance.ExitApplication(); break; } if (triggerScene != null) { var effects = new Effects { triggerScene }; var cutsceneEffects = cutscene.getEffects(); if (cutsceneEffects != null) { effects.AddRange(cutsceneEffects); } Game.Instance.Execute(new EffectHolder(effects)); } return(res); }
public bool execute() { var forceWait = false; if (effect != null && (!runsOnce || timesRun == 0 || waitForLoadPulse)) { if (!validated) { isValid = conditions == null || ConditionChecker.check(conditions); validated = true; } if (isValid) { switch (effect.getType()) { case EffectType.ACTIVATE: Game.Instance.GameState.SetFlag(((ActivateEffect)effect).getTargetId(), FlagCondition.FLAG_ACTIVE); break; case EffectType.DEACTIVATE: Game.Instance.GameState.SetFlag(((DeactivateEffect)effect).getTargetId(), FlagCondition.FLAG_INACTIVE); break; case EffectType.SHOW_TEXT: var showTextEffect = (ShowTextEffect)effect; Game.Instance.Talk(showTextEffect.getText(), showTextEffect.getX(), showTextEffect.getY(), showTextEffect.getRgbFrontColor(), showTextEffect.getRgbBorderColor()); forceWait = true; break; case EffectType.SPEAK_PLAYER: Game.Instance.Talk(((SpeakPlayerEffect)effect).getLine(), Player.IDENTIFIER); forceWait = true; break; case EffectType.SPEAK_CHAR: Game.Instance.Talk(((SpeakCharEffect)effect).getLine(), ((SpeakCharEffect)effect).getTargetId()); forceWait = true; break; case EffectType.TRIGGER_SCENE: if (!waitForLoadPulse) { runsOnce = false; TriggerSceneEffect tse = ((TriggerSceneEffect)effect); if (!Game.Instance.GameState.IsFirstPerson) { var playerContext = Game.Instance.GameState.PlayerContext; if (tse.getX() != int.MinValue || tse.getY() != int.MinValue) { playerContext.setPosition(tse.getX(), tse.getY()); if (tse.DestinyScale > 0) { playerContext.Scale = tse.DestinyScale; } } else { var targetScene = Game.Instance.GameState.GetChapterTarget(tse.getTargetId()) as Scene; if (targetScene != null) { if (targetScene.getTrajectory() != null) { var initial = targetScene.getTrajectory().getInitial(); playerContext.setPosition(initial.getX(), initial.getY()); playerContext.Scale = initial.getScale(); } else { playerContext.setPosition(targetScene.getPositionX(), targetScene.getPositionY()); playerContext.Scale = targetScene.getPlayerScale(); } } } } var trace = !(additionalInfo.ContainsKey("disable_trace") && (bool)additionalInfo["disable_trace"]); Game.Instance.RunTarget(tse.getTargetId(), tse.getTransitionTime(), tse.getTransitionType(), null, trace); waitForLoadPulse = true; forceWait = true; } else { waitForLoadPulse = false; } // DODO make something to wait until the target is ready to prevent undesired effect advance break; case EffectType.TRIGGER_CUTSCENE: runsOnce = false; TriggerCutsceneEffect tce = (TriggerCutsceneEffect)effect; if (timesRun > 1) // The first interaction is the run target callback { if (additionalInfo.ContainsKey("sub_effects_wait")) { forceWait = false; } else { InteractuableResult res = ((Interactuable)additionalInfo["scene"]).Interacted(); if (res == InteractuableResult.REQUIRES_MORE_INTERACTION) { forceWait = true; } else if (res == InteractuableResult.DOES_SOMETHING) { additionalInfo["sub_effects_wait"] = true; forceWait = true; } } } else if (timesRun == 1) { forceWait = true; } else if (timesRun == 0) { var trace = !(additionalInfo.ContainsKey("disable_trace") && (bool)additionalInfo["disable_trace"]); additionalInfo.Add("lastscene", Game.Instance.GameState.CurrentTarget); additionalInfo.Add("scene", Game.Instance.RunTarget(tce.getTargetId(), null, trace)); forceWait = true; } if (!forceWait && ((Cutscene)((IRunnerChapterTarget)additionalInfo["scene"]).Data).getNext() == Cutscene.GOBACK) { string last = (string)additionalInfo["lastscene"]; Game.Instance.RunTarget(last); } break; case EffectType.TRIGGER_LAST_SCENE: runsOnce = false; Game.Instance.SwitchToLastTarget(); break; case EffectType.TRIGGER_CONVERSATION: runsOnce = false; runsOnce = false; if (timesRun == 0) { var tcoe = (TriggerConversationEffect)effect; this.additionalInfo.Add("conversation", new GraphConversationHolder(Game.Instance.GameState.GetConversation(tcoe.getTargetId()))); } forceWait = ((GraphConversationHolder)this.additionalInfo["conversation"]).execute(); break; case EffectType.RANDOM_EFFECT: RandomEffect re = (RandomEffect)effect; if (timesRun == 0) { int pro = re.getProbability(), now = Random.Range(0, 100); if (pro <= now) { if (re.getPositiveEffect() != null) { additionalInfo.Add("current", new EffectHolderNode(re.getPositiveEffect())); runsOnce = false; } } else if (re.getNegativeEffect() != null) { additionalInfo.Add("current", new EffectHolderNode(re.getNegativeEffect())); runsOnce = false; } } if (additionalInfo.ContainsKey("current")) { var subEffectHolder = (EffectHolderNode)additionalInfo["current"]; forceWait = subEffectHolder.execute(); runsOnce = subEffectHolder.runsOnce; } break; case EffectType.SET_VALUE: SetValueEffect sve = (SetValueEffect)effect; Game.Instance.GameState.SetVariable(sve.getTargetId(), sve.getValue()); break; case EffectType.INCREMENT_VAR: IncrementVarEffect ive = (IncrementVarEffect)effect; Game.Instance.GameState.SetVariable(ive.getTargetId(), Game.Instance.GameState.GetVariable(ive.getTargetId()) + ive.getIncrement()); break; case EffectType.DECREMENT_VAR: DecrementVarEffect dve = (DecrementVarEffect)effect; Game.Instance.GameState.SetVariable(dve.getTargetId(), Game.Instance.GameState.GetVariable(dve.getTargetId()) - dve.getDecrement()); break; case EffectType.MACRO_REF: runsOnce = false; if (timesRun == 0) { MacroReferenceEffect mre = (MacroReferenceEffect)effect; this.additionalInfo.Add("macro", new EffectHolder(Game.Instance.GameState.GetMacro(mre.getTargetId()))); } forceWait = ((EffectHolder)this.additionalInfo["macro"]).execute(); break; case EffectType.MOVE_OBJECT: MoveObjectEffect moe = (MoveObjectEffect)effect; runsOnce = !moe.isAnimated(); if (timesRun == 0) { if (moe.isAnimated()) { Game.Instance.GameState.Move(moe.getTargetId(), new Vector2(moe.getX(), moe.getY()), moe.getTranslateSpeed(), this); } else { Game.Instance.GameState.Move(moe.getTargetId(), new Vector2(moe.getX(), moe.getY())); } } if (!runsOnce && !pulsed) { forceWait = true; } break; case EffectType.MOVE_NPC: MoveNPCEffect mne = (MoveNPCEffect)effect; runsOnce = true; if (timesRun == 0) { Game.Instance.GameState.Move(mne.getTargetId(), new Vector2(mne.getX(), mne.getY()), 1, this); } if (!runsOnce && !pulsed) { forceWait = true; } break; case EffectType.GENERATE_OBJECT: GenerateObjectEffect gen = (GenerateObjectEffect)effect; var toAdd = Game.Instance.GameState.FindElement <Item>(gen.getTargetId()); InventoryManager.Instance.AddElement(toAdd); break; case EffectType.CONSUME_OBJECT: ConsumeObjectEffect con = (ConsumeObjectEffect)effect; var toRemove = Game.Instance.GameState.FindElement <Item>(con.getTargetId()); InventoryManager.Instance.RemoveElement(toRemove); break; case EffectType.TRIGGER_BOOK: if (timesRun == 0) { if (InventoryManager.Instance.Opened) { InventoryManager.Instance.Close(); } TriggerBookEffect triggerBookEffect = (TriggerBookEffect)effect; Game.Instance.ShowBook(triggerBookEffect.getTargetId()); } runsOnce = false; forceWait = Game.Instance.ShowingBook; break; case EffectType.PLAY_SOUND: PlaySoundEffect pse = (PlaySoundEffect)effect; AudioClip audioClip = Game.Instance.ResourceManager.getAudio(pse.getPath()); PlayMusicOn(audioClip, Game.Instance); break; case EffectType.WAIT_TIME: WaitTimeEffect wte = (WaitTimeEffect)effect; runsOnce = false; if (timesRun == 0) { Game.Instance.PulseOnTime(this, wte.getTime()); } if (!pulsed) { forceWait = true; } break; case EffectType.CUSTOM_EFFECT: runsOnce = false; if (timesRun == 0) { this.additionalInfo["custom_effect_runner"] = CustomEffectRunnerFactory.Instance.CreateRunnerFor(effect); } forceWait = ((CustomEffectRunner)this.additionalInfo["custom_effect_runner"]).execute(); break; } } } if (!forceWait) { timesRun = 0; } else { timesRun++; } return(forceWait); }
public TriggerSceneEffectEditor() { scenes = Controller.getInstance().getSelectedChapterDataControl().getScenesList().getScenesIDs(); this.effect = new TriggerSceneEffect(scenes[0], x, y); }
public override bool doTool() { bool effectEdited = false; EffectType effectType = effect.getType(); // If a change has been made if (newProperties != null) { effectEdited = true; oldEffect = (AbstractEffect)effect; switch (effectType) { case EffectType.ACTIVATE: ActivateEffect activateEffect = (ActivateEffect)effect; activateEffect.setTargetId((string)newProperties[EffectsController.EFFECT_PROPERTY_TARGET]); Controller.getInstance().updateVarFlagSummary(); break; case EffectType.DEACTIVATE: DeactivateEffect deactivateEffect = (DeactivateEffect)effect; deactivateEffect.setTargetId((string)newProperties[EffectsController.EFFECT_PROPERTY_TARGET]); Controller.getInstance().updateVarFlagSummary(); break; case EffectType.SET_VALUE: SetValueEffect setValueEffect = (SetValueEffect)effect; setValueEffect.setTargetId((string)newProperties[EffectsController.EFFECT_PROPERTY_TARGET]); setValueEffect.setValue(int.Parse((string)newProperties[EffectsController.EFFECT_PROPERTY_VALUE])); Controller.getInstance().updateVarFlagSummary(); break; case EffectType.INCREMENT_VAR: IncrementVarEffect incrementVarEffect = (IncrementVarEffect)effect; incrementVarEffect.setTargetId((string)newProperties[EffectsController.EFFECT_PROPERTY_TARGET]); incrementVarEffect.setIncrement(int.Parse((string)newProperties[EffectsController.EFFECT_PROPERTY_VALUE])); Controller.getInstance().updateVarFlagSummary(); break; case EffectType.DECREMENT_VAR: DecrementVarEffect decrementVarEffect = (DecrementVarEffect)effect; decrementVarEffect.setTargetId((string)newProperties[EffectsController.EFFECT_PROPERTY_TARGET]); decrementVarEffect.setDecrement(int.Parse((string)newProperties[EffectsController.EFFECT_PROPERTY_VALUE])); Controller.getInstance().updateVarFlagSummary(); break; case EffectType.MACRO_REF: MacroReferenceEffect macroEffect = (MacroReferenceEffect)effect; macroEffect.setTargetId((string)newProperties[EffectsController.EFFECT_PROPERTY_TARGET]); break; case EffectType.CONSUME_OBJECT: ConsumeObjectEffect consumeObjectEffect = (ConsumeObjectEffect)effect; consumeObjectEffect.setTargetId((string)newProperties[EffectsController.EFFECT_PROPERTY_TARGET]); break; case EffectType.GENERATE_OBJECT: GenerateObjectEffect generateObjectEffect = (GenerateObjectEffect)effect; generateObjectEffect.setTargetId((string)newProperties[EffectsController.EFFECT_PROPERTY_TARGET]); break; case EffectType.SPEAK_PLAYER: SpeakPlayerEffect speakPlayerEffect = (SpeakPlayerEffect)effect; speakPlayerEffect.setLine((string)newProperties[EffectsController.EFFECT_PROPERTY_TEXT]); speakPlayerEffect.setAudioPath((string)newProperties[EffectsController.EFFECT_PROPERTY_PATH]); break; case EffectType.SPEAK_CHAR: SpeakCharEffect speakCharEffect = (SpeakCharEffect)effect; speakCharEffect.setTargetId((string)newProperties[EffectsController.EFFECT_PROPERTY_TARGET]); speakCharEffect.setLine((string)newProperties[EffectsController.EFFECT_PROPERTY_TEXT]); speakCharEffect.setAudioPath((string)newProperties[EffectsController.EFFECT_PROPERTY_PATH]); break; case EffectType.TRIGGER_BOOK: TriggerBookEffect triggerBookEffect = (TriggerBookEffect)effect; triggerBookEffect.setTargetId((string)newProperties[EffectsController.EFFECT_PROPERTY_TARGET]); break; case EffectType.PLAY_SOUND: PlaySoundEffect playSoundEffect = (PlaySoundEffect)effect; playSoundEffect.setPath((string)newProperties[EffectsController.EFFECT_PROPERTY_PATH]); playSoundEffect.setBackground(bool.Parse((string)newProperties[EffectsController.EFFECT_PROPERTY_BACKGROUND])); break; case EffectType.PLAY_ANIMATION: PlayAnimationEffect playAnimationEffect = (PlayAnimationEffect)effect; playAnimationEffect.setPath((string)newProperties[EffectsController.EFFECT_PROPERTY_PATH]); playAnimationEffect.setDestiny(int.Parse((string)newProperties[EffectsController.EFFECT_PROPERTY_X]), int.Parse((string)newProperties[EffectsController.EFFECT_PROPERTY_Y])); break; case EffectType.MOVE_PLAYER: MovePlayerEffect movePlayerEffect = (MovePlayerEffect)effect; movePlayerEffect.setDestiny(int.Parse((string)newProperties[EffectsController.EFFECT_PROPERTY_X]), int.Parse((string)newProperties[EffectsController.EFFECT_PROPERTY_Y])); break; case EffectType.MOVE_NPC: MoveNPCEffect moveNPCEffect = (MoveNPCEffect)effect; moveNPCEffect.setTargetId((string)newProperties[EffectsController.EFFECT_PROPERTY_TARGET]); moveNPCEffect.setDestiny(int.Parse((string)newProperties[EffectsController.EFFECT_PROPERTY_X]), int.Parse((string)newProperties[EffectsController.EFFECT_PROPERTY_Y])); break; case EffectType.TRIGGER_CONVERSATION: TriggerConversationEffect triggerConversationEffect = (TriggerConversationEffect)effect; triggerConversationEffect.setTargetId((string)newProperties[EffectsController.EFFECT_PROPERTY_TARGET]); break; case EffectType.TRIGGER_CUTSCENE: TriggerCutsceneEffect triggerCutsceneEffect = (TriggerCutsceneEffect)effect; triggerCutsceneEffect.setTargetId((string)newProperties[EffectsController.EFFECT_PROPERTY_TARGET]); break; case EffectType.TRIGGER_SCENE: TriggerSceneEffect triggerSceneEffect = (TriggerSceneEffect)effect; triggerSceneEffect.setTargetId((string)newProperties[EffectsController.EFFECT_PROPERTY_TARGET]); triggerSceneEffect.setPosition(int.Parse((string)newProperties[EffectsController.EFFECT_PROPERTY_X]), int.Parse((string)newProperties[EffectsController.EFFECT_PROPERTY_Y])); break; case EffectType.RANDOM_EFFECT: RandomEffect randomEffect = (RandomEffect)effect; randomEffect.setProbability(int.Parse((string)newProperties[EffectsController.EFFECT_PROPERTY_PROBABILITY])); randomEffect.setPositiveEffect(pos); randomEffect.setNegativeEffect(neg); break; case EffectType.WAIT_TIME: WaitTimeEffect waitTimeEffect = (WaitTimeEffect)effect; waitTimeEffect.setTime(int.Parse((string)newProperties[EffectsController.EFFECT_PROPERTY_TIME])); break; case EffectType.SHOW_TEXT: ShowTextEffect showTextEffect = (ShowTextEffect)effect; showTextEffect.setText((string)newProperties[EffectsController.EFFECT_PROPERTY_TEXT]); showTextEffect.setTextPosition(int.Parse((string)newProperties[EffectsController.EFFECT_PROPERTY_X]), int.Parse((string)newProperties[EffectsController.EFFECT_PROPERTY_Y])); showTextEffect.setRgbFrontColor((string)newProperties[EffectsController.EFFECT_PROPERTY_FRONT_COLOR]); showTextEffect.setRgbBorderColor((string)newProperties[EffectsController.EFFECT_PROPERTY_BORDER_COLOR]); showTextEffect.setAudioPath((string)newProperties[EffectsController.EFFECT_PROPERTY_PATH]); break; case EffectType.HIGHLIGHT_ITEM: HighlightItemEffect highlightItemEffect = (HighlightItemEffect)effect; highlightItemEffect.setTargetId((string)newProperties[EffectsController.EFFECT_PROPERTY_TARGET]); highlightItemEffect.setHighlightAnimated((bool)newProperties[EffectsController.EFFECT_PROPERTY_ANIMATED]); highlightItemEffect.setHighlightType((int)newProperties[EffectsController.EFFECT_PROPERTY_HIGHLIGHT_TYPE]); break; case EffectType.MOVE_OBJECT: MoveObjectEffect moveObjectEffect = (MoveObjectEffect)effect; moveObjectEffect.setTargetId((string)newProperties[EffectsController.EFFECT_PROPERTY_TARGET]); moveObjectEffect.setX(int.Parse((string)newProperties[EffectsController.EFFECT_PROPERTY_X])); moveObjectEffect.setY(int.Parse((string)newProperties[EffectsController.EFFECT_PROPERTY_Y])); moveObjectEffect.setScale((float)newProperties[EffectsController.EFFECT_PROPERTY_SCALE]); moveObjectEffect.setAnimated((bool)newProperties[EffectsController.EFFECT_PROPERTY_ANIMATED]); moveObjectEffect.setScaleSpeed((int)newProperties[EffectsController.EFFECT_PROPERTY_SCALE_SPEED]); moveObjectEffect.setTranslateSpeed((int)newProperties[EffectsController.EFFECT_PROPERTY_TRANSLATION_SPEED]); break; } effectEdited = true; Controller.getInstance().updatePanel(); } return(effectEdited); }
private static XmlElement buildEffectNode(AbstractEffect effect, XmlDocument doc) { XmlElement effectElement = null; switch (effect.getType()) { case EffectType.ACTIVATE: ActivateEffect activateEffect = (ActivateEffect)effect; effectElement = doc.CreateElement("activate"); effectElement.SetAttribute("flag", activateEffect.getTargetId()); break; case EffectType.DEACTIVATE: DeactivateEffect deactivateEffect = (DeactivateEffect)effect; effectElement = doc.CreateElement("deactivate"); effectElement.SetAttribute("flag", deactivateEffect.getTargetId()); break; case EffectType.SET_VALUE: SetValueEffect setValueEffect = (SetValueEffect)effect; effectElement = doc.CreateElement("set-value"); effectElement.SetAttribute("var", setValueEffect.getTargetId()); effectElement.SetAttribute("value", setValueEffect.getValue().ToString()); break; case EffectType.INCREMENT_VAR: IncrementVarEffect incrementVarEffect = (IncrementVarEffect)effect; effectElement = doc.CreateElement("increment"); effectElement.SetAttribute("var", incrementVarEffect.getTargetId()); effectElement.SetAttribute("value", incrementVarEffect.getIncrement().ToString()); break; case EffectType.DECREMENT_VAR: DecrementVarEffect decrementVarEffect = (DecrementVarEffect)effect; effectElement = doc.CreateElement("decrement"); effectElement.SetAttribute("var", decrementVarEffect.getTargetId()); effectElement.SetAttribute("value", decrementVarEffect.getDecrement().ToString()); break; case EffectType.MACRO_REF: MacroReferenceEffect macroRefEffect = (MacroReferenceEffect)effect; effectElement = doc.CreateElement("macro-ref"); effectElement.SetAttribute("id", macroRefEffect.getTargetId()); break; case EffectType.CONSUME_OBJECT: ConsumeObjectEffect consumeObjectEffect = (ConsumeObjectEffect)effect; effectElement = doc.CreateElement("consume-object"); effectElement.SetAttribute("idTarget", consumeObjectEffect.getTargetId()); break; case EffectType.GENERATE_OBJECT: GenerateObjectEffect generateObjectEffect = (GenerateObjectEffect)effect; effectElement = doc.CreateElement("generate-object"); effectElement.SetAttribute("idTarget", generateObjectEffect.getTargetId()); break; case EffectType.CANCEL_ACTION: effectElement = doc.CreateElement("cancel-action"); break; case EffectType.SPEAK_PLAYER: SpeakPlayerEffect speakPlayerEffect = (SpeakPlayerEffect)effect; effectElement = doc.CreateElement("speak-player"); if (speakPlayerEffect.getAudioPath() != null && !speakPlayerEffect.getAudioPath().Equals("")) { effectElement.SetAttribute("uri", speakPlayerEffect.getAudioPath()); } effectElement.AppendChild(doc.CreateTextNode(speakPlayerEffect.getLine())); break; case EffectType.SPEAK_CHAR: SpeakCharEffect speakCharEffect = (SpeakCharEffect)effect; effectElement = doc.CreateElement("speak-char"); effectElement.SetAttribute("idTarget", speakCharEffect.getTargetId()); if (speakCharEffect.getAudioPath() != null && !speakCharEffect.getAudioPath().Equals("")) { effectElement.SetAttribute("uri", speakCharEffect.getAudioPath()); } effectElement.AppendChild(doc.CreateTextNode(speakCharEffect.getLine())); break; case EffectType.TRIGGER_BOOK: TriggerBookEffect triggerBookEffect = (TriggerBookEffect)effect; effectElement = doc.CreateElement("trigger-book"); effectElement.SetAttribute("idTarget", triggerBookEffect.getTargetId()); break; case EffectType.PLAY_SOUND: PlaySoundEffect playSoundEffect = (PlaySoundEffect)effect; effectElement = doc.CreateElement("play-sound"); if (!playSoundEffect.isBackground()) { effectElement.SetAttribute("background", "no"); } effectElement.SetAttribute("uri", playSoundEffect.getPath()); break; case EffectType.PLAY_ANIMATION: PlayAnimationEffect playAnimationEffect = (PlayAnimationEffect)effect; effectElement = doc.CreateElement("play-animation"); effectElement.SetAttribute("uri", playAnimationEffect.getPath()); effectElement.SetAttribute("x", playAnimationEffect.getX().ToString()); effectElement.SetAttribute("y", playAnimationEffect.getY().ToString()); break; case EffectType.MOVE_PLAYER: MovePlayerEffect movePlayerEffect = (MovePlayerEffect)effect; effectElement = doc.CreateElement("move-player"); effectElement.SetAttribute("x", movePlayerEffect.getX().ToString()); effectElement.SetAttribute("y", movePlayerEffect.getY().ToString()); break; case EffectType.MOVE_NPC: MoveNPCEffect moveNPCEffect = (MoveNPCEffect)effect; effectElement = doc.CreateElement("move-npc"); effectElement.SetAttribute("idTarget", moveNPCEffect.getTargetId()); effectElement.SetAttribute("x", moveNPCEffect.getX().ToString()); effectElement.SetAttribute("y", moveNPCEffect.getY().ToString()); break; case EffectType.TRIGGER_CONVERSATION: TriggerConversationEffect triggerConversationEffect = (TriggerConversationEffect)effect; effectElement = doc.CreateElement("trigger-conversation"); effectElement.SetAttribute("idTarget", triggerConversationEffect.getTargetId()); break; case EffectType.TRIGGER_CUTSCENE: TriggerCutsceneEffect triggerCutsceneEffect = (TriggerCutsceneEffect)effect; effectElement = doc.CreateElement("trigger-cutscene"); effectElement.SetAttribute("idTarget", triggerCutsceneEffect.getTargetId()); break; case EffectType.TRIGGER_LAST_SCENE: effectElement = doc.CreateElement("trigger-last-scene"); break; case EffectType.TRIGGER_SCENE: TriggerSceneEffect triggerSceneEffect = (TriggerSceneEffect)effect; effectElement = doc.CreateElement("trigger-scene"); effectElement.SetAttribute("idTarget", triggerSceneEffect.getTargetId()); effectElement.SetAttribute("x", triggerSceneEffect.getX().ToString()); effectElement.SetAttribute("y", triggerSceneEffect.getY().ToString()); break; case EffectType.WAIT_TIME: WaitTimeEffect waitTimeEffect = (WaitTimeEffect)effect; effectElement = doc.CreateElement("wait-time"); effectElement.SetAttribute("time", waitTimeEffect.getTime().ToString()); break; case EffectType.SHOW_TEXT: ShowTextEffect showTextEffect = (ShowTextEffect)effect; effectElement = doc.CreateElement("show-text"); effectElement.SetAttribute("x", showTextEffect.getX().ToString()); effectElement.SetAttribute("y", showTextEffect.getY().ToString()); effectElement.SetAttribute("frontColor", showTextEffect.getRgbFrontColor().ToString()); effectElement.SetAttribute("borderColor", showTextEffect.getRgbBorderColor().ToString()); effectElement.SetAttribute("uri", showTextEffect.getAudioPath()); effectElement.AppendChild(doc.CreateTextNode(showTextEffect.getText())); break; case EffectType.MOVE_OBJECT: MoveObjectEffect moveObjectEffect = (MoveObjectEffect)effect; effectElement = doc.CreateElement("move-object"); effectElement.SetAttribute("idTarget", moveObjectEffect.getTargetId()); effectElement.SetAttribute("x", moveObjectEffect.getX().ToString()); effectElement.SetAttribute("y", moveObjectEffect.getY().ToString()); effectElement.SetAttribute("scale", moveObjectEffect.getScale().ToString()); effectElement.SetAttribute("animated", (moveObjectEffect.isAnimated() ? "yes" : "no")); effectElement.SetAttribute("translateSpeed", moveObjectEffect.getTranslateSpeed().ToString()); effectElement.SetAttribute("scaleSpeed", moveObjectEffect.getScaleSpeed().ToString()); break; case EffectType.HIGHLIGHT_ITEM: HighlightItemEffect highlightItemEffect = (HighlightItemEffect)effect; effectElement = doc.CreateElement("highlight-item"); effectElement.SetAttribute("idTarget", highlightItemEffect.getTargetId()); effectElement.SetAttribute("animated", (highlightItemEffect.isHighlightAnimated() ? "yes" : "no")); switch (highlightItemEffect.getHighlightType()) { case HighlightItemEffect.HIGHLIGHT_BLUE: effectElement.SetAttribute("type", "blue"); break; case HighlightItemEffect.HIGHLIGHT_BORDER: effectElement.SetAttribute("type", "border"); break; case HighlightItemEffect.HIGHLIGHT_RED: effectElement.SetAttribute("type", "red"); break; case HighlightItemEffect.HIGHLIGHT_GREEN: effectElement.SetAttribute("type", "green"); break; case HighlightItemEffect.NO_HIGHLIGHT: effectElement.SetAttribute("type", "none"); break; } break; } return(effectElement); }
public static void PlayConversation(string id) { if (xmld == null) { Init(); } string query = string.Format("//*[@id='{0}']", id); XmlElement conv = (XmlElement)xmld.SelectSingleNode(query); XmlNodeList nodes = conv.SelectNodes("*"); Conversation convModel = new Conversation(); convModel.nodes = new Node[nodes.Count]; for (int i = 0; i < nodes.Count; ++i) { XmlNode node = nodes[i]; string name = node.Name; Node nodeModel = null; if (name == "dialogue-node") { DialogNode dialogNodeModel = new DialogNode(); XmlNodeList dialogSpeaks = node.SelectNodes("*"); dialogNodeModel.speaks = new Speak[node.SelectNodes("speak-player").Count + node.SelectNodes("speak-char").Count]; int z = 0; for (int j = 0; j < dialogSpeaks.Count; ++j) { XmlNode speakNode = dialogSpeaks[j]; string speakName = speakNode.Name; if (speakName == "speak-player") { Speak speakModel = new Speak(); speakModel.text = speakNode.InnerText; dialogNodeModel.speaks[z] = speakModel; ++z; } else if (speakName == "speak-char") { Speak speakModel = new Speak(); speakModel.text = speakNode.InnerText; speakModel.isPhone = true; dialogNodeModel.speaks[z] = speakModel; ++z; } else if (speakName == "condition") { Condition conditionModel = new Condition(); XmlNodeList activesList = speakNode.SelectNodes("active"); conditionModel.actives = new string[activesList.Count]; for (int y = 0; y < activesList.Count; y++) { conditionModel.actives[y] = activesList[y].Attributes["flag"].Value; } XmlNodeList inactivesList = speakNode.SelectNodes("inactive"); conditionModel.inactives = new string[inactivesList.Count]; for (int y = 0; y < inactivesList.Count; y++) { conditionModel.inactives[y] = inactivesList[y].Attributes["flag"].Value; } dialogNodeModel.speaks[z - 1].condition = conditionModel; } else if (speakName == "child") { dialogNodeModel.nextIndex = Utils.IntParseFast(speakNode.Attributes["nodeindex"].Value); } else if (speakName == "end-conversation") { XmlNode effect = speakNode.SelectSingleNode("effect"); if (effect != null) { XmlNodeList effectsList = effect.SelectNodes("*"); dialogNodeModel.effects = new EndConvEffect[ effectsList.Count - effect.SelectNodes("condition").Count]; int m = 0; for (int x = 0; x < effectsList.Count; ++x) { XmlNode effectNode = effectsList[x]; string effectNodeName = effectNode.Name; if (effectNodeName == "activate") { ActivateFlagEffect activateFlageffect = new ActivateFlagEffect(); activateFlageffect.flag = effectNode.Attributes["flag"].Value; dialogNodeModel.effects[m] = activateFlageffect; ++m; } else if (effectNodeName == "deactivate") { DeactivateFlagEffect deactivateFlageffect = new DeactivateFlagEffect(); deactivateFlageffect.flag = effectNode.Attributes["flag"].Value; dialogNodeModel.effects[m] = deactivateFlageffect; ++m; } else if (effectNodeName == "increment") { IncrementFlagEffect eff = new IncrementFlagEffect(); eff.val = Utils.IntParseFast( effectNode.Attributes["value"].Value); eff.var = effectNode.Attributes["var"].Value; dialogNodeModel.effects[m] = eff; ++m; } else if (effectNodeName == "decrement") { DecrementFlagEffect eff = new DecrementFlagEffect(); eff.val = Utils.IntParseFast( effectNode.Attributes["value"].Value); eff.var = effectNode.Attributes["var"].Value; dialogNodeModel.effects[m] = eff; ++m; } else if (effectNodeName == "trigger-conversation") { TriggerConvEffect eff = new TriggerConvEffect(); eff.idTarget = effectNode.Attributes["idTarget"].Value; dialogNodeModel.effects[m] = eff; ++m; } else if (effectNodeName == "trigger-scene") { TriggerSceneEffect eff = new TriggerSceneEffect(); eff.idTarget = effectNode.Attributes["idTarget"].Value; dialogNodeModel.effects[m] = eff; ++m; } else if (effectNodeName == "trigger-cutscene") { TriggerCutSceneEffect eff = new TriggerCutSceneEffect(); eff.idTarget = effectNode.Attributes["idTarget"].Value; dialogNodeModel.effects[m] = eff; ++m; } else if (effectNodeName == "condition") { Condition conditionModel = new Condition(); XmlNodeList activesList = effectNode.SelectNodes("active"); conditionModel.actives = new string[activesList.Count]; for (int y = 0; y < activesList.Count; y++) { conditionModel.actives[y] = activesList[y].Attributes["flag"].Value; } XmlNodeList inactivesList = effectNode.SelectNodes("inactive"); conditionModel.inactives = new string[inactivesList.Count]; for (int y = 0; y < inactivesList.Count; y++) { conditionModel.inactives[y] = inactivesList[y].Attributes["flag"].Value; } dialogNodeModel.effects[m - 1].condition = conditionModel; } } } } else if (speakName == "effect") { XmlNodeList effectsList = speakNode.SelectNodes("*"); dialogNodeModel.effects = new EndConvEffect[ effectsList.Count - speakNode.SelectNodes("condition").Count]; int m = 0; for (int x = 0; x < effectsList.Count; ++x) { XmlNode effectNode = effectsList[x]; string effectNodeName = effectNode.Name; if (effectNodeName == "activate") { ActivateFlagEffect activateFlageffect = new ActivateFlagEffect(); activateFlageffect.flag = effectNode.Attributes["flag"].Value; dialogNodeModel.effects[m] = activateFlageffect; ++m; } else if (effectNodeName == "deactivate") { DeactivateFlagEffect deactivateFlageffect = new DeactivateFlagEffect(); deactivateFlageffect.flag = effectNode.Attributes["flag"].Value; dialogNodeModel.effects[m] = deactivateFlageffect; ++m; } else if (effectNodeName == "increment") { IncrementFlagEffect eff = new IncrementFlagEffect(); eff.val = Utils.IntParseFast( effectNode.Attributes["value"].Value); eff.var = effectNode.Attributes["var"].Value; dialogNodeModel.effects[m] = eff; ++m; } else if (effectNodeName == "decrement") { DecrementFlagEffect eff = new DecrementFlagEffect(); eff.val = Utils.IntParseFast( effectNode.Attributes["value"].Value); eff.var = effectNode.Attributes["var"].Value; dialogNodeModel.effects[m] = eff; ++m; } else if (effectNodeName == "trigger-conversation") { TriggerConvEffect eff = new TriggerConvEffect(); eff.idTarget = effectNode.Attributes["idTarget"].Value; dialogNodeModel.effects[m] = eff; ++m; } else if (effectNodeName == "trigger-scene") { TriggerSceneEffect eff = new TriggerSceneEffect(); eff.idTarget = effectNode.Attributes["idTarget"].Value; dialogNodeModel.effects[m] = eff; ++m; } else if (effectNodeName == "trigger-cutscene") { TriggerCutSceneEffect eff = new TriggerCutSceneEffect(); eff.idTarget = effectNode.Attributes["idTarget"].Value; dialogNodeModel.effects[m] = eff; ++m; } else if (effectNodeName == "condition") { Condition conditionModel = new Condition(); XmlNodeList activesList = effectNode.SelectNodes("active"); conditionModel.actives = new string[activesList.Count]; for (int y = 0; y < activesList.Count; y++) { conditionModel.actives[y] = activesList[y].Attributes["flag"].Value; } XmlNodeList inactivesList = effectNode.SelectNodes("inactive"); conditionModel.inactives = new string[inactivesList.Count]; for (int y = 0; y < inactivesList.Count; y++) { conditionModel.inactives[y] = inactivesList[y].Attributes["flag"].Value; } dialogNodeModel.effects[m - 1].condition = conditionModel; } } } } nodeModel = dialogNodeModel; } else if (name == "option-node") { OptionNode optionNodeModel = new OptionNode(); XmlAttribute randomAttr = node.Attributes["random"]; if (randomAttr != null && randomAttr.Value == "yes") { optionNodeModel.isRandom = true; } XmlNodeList optionSpeaks = node.SelectNodes("*"); optionNodeModel.options = new Option[node.SelectNodes("speak-player").Count]; int z = 0; for (int j = 0; j < optionSpeaks.Count; ++j) { XmlNode optionNode = optionSpeaks[j]; string optionName = optionNode.Name; if (optionName == "speak-player") { Option speakModel = new Option(); speakModel.text = optionNode.InnerText; optionNodeModel.options[z] = speakModel; ++z; } else if (optionName == "condition") { Condition conditionModel = new Condition(); XmlNodeList activesList = optionNode.SelectNodes("active"); conditionModel.actives = new string[activesList.Count]; for (int y = 0; y < activesList.Count; y++) { conditionModel.actives[y] = activesList[y].Attributes["flag"].Value; } XmlNodeList inactivesList = optionNode.SelectNodes("inactive"); conditionModel.inactives = new string[inactivesList.Count]; for (int y = 0; y < inactivesList.Count; y++) { conditionModel.inactives[y] = inactivesList[y].Attributes["flag"].Value; } optionNodeModel.options[z - 1].condition = conditionModel; } else if (optionName == "child") { optionNodeModel.options[z - 1].nextIndex = Utils.IntParseFast(optionNode.Attributes["nodeindex"].Value); } } nodeModel = optionNodeModel; } convModel.nodes[i] = nodeModel; } convModel.exec(); }
public bool execute() { bool forcewait = false; if (!(runs_once && times_runed > 0)) { if (effect == null || effect.getConditions() == null) { Debug.Log("Asd"); } else { if (!validated) { is_valid = ConditionChecker.check(effect.getConditions()); validated = true; } if (is_valid) { switch (effect.getType()) { case EffectType.ACTIVATE: Game.Instance.GameState.setFlag(((ActivateEffect)effect).getTargetId(), FlagCondition.FLAG_ACTIVE); break; case EffectType.DEACTIVATE: Game.Instance.GameState.setFlag(((DeactivateEffect)effect).getTargetId(), FlagCondition.FLAG_INACTIVE); break; case EffectType.SPEAK_PLAYER: Game.Instance.talk(((SpeakPlayerEffect)effect).getLine(), null); forcewait = true; break; case EffectType.SPEAK_CHAR: Game.Instance.talk(((SpeakCharEffect)effect).getLine(), ((SpeakCharEffect)effect).getTargetId()); forcewait = true; break; case EffectType.TRIGGER_SCENE: runs_once = false; TriggerSceneEffect tse = ((TriggerSceneEffect)effect); Game.Instance.RunTarget(tse.getTargetId(), tse.getTransitionTime(), tse.getTransitionType()); // DODO make something to wait until the target is ready to prevent undesired effect advance break; case EffectType.TRIGGER_CUTSCENE: runs_once = false; TriggerCutsceneEffect tce = (TriggerCutsceneEffect)effect; if (times_runed > 0) { if (!aditional_info.ContainsKey("cutscene_effect")) { InteractuableResult res = ((Interactuable)aditional_info["scene"]).Interacted(); if (res == InteractuableResult.REQUIRES_MORE_INTERACTION) { forcewait = true; } else if (res == InteractuableResult.DOES_SOMETHING) { forcewait = true; aditional_info.Add("cutscene_effect", Game.Instance.getNextInteraction()); } } else { forcewait = ((Interactuable)aditional_info["cutscene_effect"]).Interacted() == InteractuableResult.REQUIRES_MORE_INTERACTION; } } else { aditional_info = new Dictionary <string, object>(); aditional_info.Add("lastscene", Game.Instance.GameState.CurrentTarget); aditional_info.Add("scene", Game.Instance.RunTarget(tce.getTargetId())); forcewait = true; } if (!forcewait && ((Cutscene)((IRunnerChapterTarget)aditional_info["scene"]).Data).getNext() == Cutscene.GOBACK) { string last = (string)aditional_info["lastscene"]; Game.Instance.RunTarget(last); } break; case EffectType.TRIGGER_LAST_SCENE: runs_once = false; Game.Instance.SwitchToLastTarget(); break; case EffectType.TRIGGER_CONVERSATION: runs_once = false; runs_once = false; if (times_runed == 0) { TriggerConversationEffect tcoe = (TriggerConversationEffect)effect; this.aditional_info.Add("conversation", new GraphConversationHolder(Game.Instance.GameState.getConversation(tcoe.getTargetId()))); } forcewait = ((GraphConversationHolder)this.aditional_info["conversation"]).execute(); break; case EffectType.RANDOM_EFFECT: runs_once = false; RandomEffect re = (RandomEffect)effect; if (!aditional_info.ContainsKey("first")) { aditional_info.Add("first", new EffectHolderNode(re.getPositiveEffect())); aditional_info.Add("second", new EffectHolderNode(re.getNegativeEffect())); } if (times_runed == 0) { int pro = re.getProbability(), now = Random.Range(0, 100); if (aditional_info.ContainsKey("current")) { aditional_info.Remove("current"); } if (pro <= now) { aditional_info.Add("current", "first"); } else { aditional_info.Add("current", "second"); } forcewait = ((EffectHolderNode)aditional_info[((string)aditional_info["current"])]).execute(); } else { forcewait = ((EffectHolderNode)aditional_info[((string)aditional_info["current"])]).execute(); } break; case EffectType.SET_VALUE: SetValueEffect sve = (SetValueEffect)effect; Game.Instance.GameState.setVariable(sve.getTargetId(), sve.getValue()); break; case EffectType.INCREMENT_VAR: IncrementVarEffect ive = (IncrementVarEffect)effect; Game.Instance.GameState.setVariable(ive.getTargetId(), Game.Instance.GameState.getVariable(ive.getTargetId()) + ive.getIncrement()); break; case EffectType.DECREMENT_VAR: DecrementVarEffect dve = (DecrementVarEffect)effect; Game.Instance.GameState.setVariable(dve.getTargetId(), Game.Instance.GameState.getVariable(dve.getTargetId()) - dve.getDecrement()); break; case EffectType.MACRO_REF: runs_once = false; if (times_runed == 0) { MacroReferenceEffect mre = (MacroReferenceEffect)effect; this.aditional_info.Add("macro", new EffectHolder(Game.Instance.GameState.getMacro(mre.getTargetId()))); } forcewait = ((EffectHolder)this.aditional_info["macro"]).execute(); break; case EffectType.MOVE_OBJECT: MoveObjectEffect moe = (MoveObjectEffect)effect; Game.Instance.GameState.Move(moe.getTargetId(), new Vector2(moe.getX(), 600 - moe.getY()) / 10f); break; case EffectType.CUSTOM_EFFECT: runs_once = false; if (times_runed == 0) { this.aditional_info["custom_effect_runner"] = CustomEffectRunnerFactory.Instance.CreateRunnerFor(effect); } forcewait = ((CustomEffectRunner)this.aditional_info["custom_effect_runner"]).execute(); break; } } } } if (!forcewait) { times_runed = 0; } else { times_runed++; } return(forcewait); }