private void StopApplyingEffect(Effect effect, GodmaShipEffect godmaEffect, Client forClient = null) { // ensure the effect is being applied before doing anything if (godmaEffect.ShouldStart == false) { return; } Ship ship = this.ItemFactory.GetItem <Ship>(this.LocationID); Character character = this.ItemFactory.GetItem <Character>(this.OwnerID); // create the environment for this run Node.Dogma.Interpreter.Environment env = new Node.Dogma.Interpreter.Environment() { Character = character, Self = this, Ship = ship, Target = null, Client = forClient }; Opcode opcode = new Interpreter(env).Run(effect.PostExpression.VMCode); if (opcode is OpcodeRunnable runnable) { runnable.Execute(); } else if (opcode is OpcodeWithBooleanOutput booleanOutput) { booleanOutput.Execute(); } else if (opcode is OpcodeWithDoubleOutput doubleOutput) { doubleOutput.Execute(); } // ensure the module is saved this.Persist(); // update things like duration, start, etc godmaEffect.StartTime = 0; godmaEffect.ShouldStart = false; godmaEffect.Duration = 0; // notify the client about it forClient?.NotifyMultiEvent(new OnGodmaShipEffect(godmaEffect)); // online effect, this requires some special processing as all the passive effects should also be applied if (effect.EffectID == (int)EffectsEnum.Online) { this.StopApplyingOnlineEffects(forClient); } }
private void ApplyEffect(Effect effect, GodmaShipEffect godmaEffect, Client forClient = null) { if (godmaEffect.ShouldStart == true) { return; } Ship ship = this.ItemFactory.GetItem <Ship>(this.LocationID); Character character = this.ItemFactory.GetItem <Character>(this.OwnerID); try { // create the environment for this run Node.Dogma.Interpreter.Environment env = new Node.Dogma.Interpreter.Environment() { Character = character, Self = this, Ship = ship, Target = null, Client = forClient }; Opcode opcode = new Interpreter(env).Run(effect.PreExpression.VMCode); if (opcode is OpcodeRunnable runnable) { runnable.Execute(); } else if (opcode is OpcodeWithBooleanOutput booleanOutput) { booleanOutput.Execute(); } else if (opcode is OpcodeWithDoubleOutput doubleOutput) { doubleOutput.Execute(); } } catch (Exception) { // notify the client about it forClient?.NotifyMultiEvent(new OnGodmaShipEffect(godmaEffect)); throw; } // ensure the module is saved this.Persist(); PyDataType duration = 0; if (effect.DurationAttributeID is not null) { duration = this.Attributes[(int)effect.DurationAttributeID]; } // update things like duration, start, etc godmaEffect.StartTime = DateTime.UtcNow.ToFileTimeUtc(); godmaEffect.ShouldStart = true; godmaEffect.Duration = duration; // notify the client about it forClient?.NotifyMultiEvent(new OnGodmaShipEffect(godmaEffect)); if (effect.EffectID == (int)EffectsEnum.Online) { this.ApplyOnlineEffects(forClient); } }