public void StopStatement(ContextControllerStatementDesc statement) { var statementId = statement.Lightweight.StatementContext.StatementId; if (!Statements.ContainsKey(statementId)) { return; } RemoveStatement(statementId); ContextStateEventUtil.DispatchPartition( listenersLazy, () => new ContextStateEventContextStatementRemoved( StatementContextCreate.RuntimeURI, ContextRuntimeDescriptor.ContextDeploymentId, ContextRuntimeDescriptor.ContextName, statement.Lightweight.StatementContext.DeploymentId, statement.Lightweight.StatementContext.StatementName), ( listener, context) => listener.OnContextStatementRemoved(context)); if (Statements.IsEmpty()) { Realization.StopContext(); ContextPartitionIdService.Clear(); ContextStateEventUtil.DispatchPartition( listenersLazy, () => new ContextStateEventContextDeactivated( StatementContextCreate.RuntimeURI, ContextRuntimeDescriptor.ContextDeploymentId, ContextRuntimeDescriptor.ContextName), ( listener, context) => listener.OnContextDeactivated(context)); } }
public void SaveScript(string fileName) { var builder = new StringBuilder(); builder.Append("local keywordHandler = KeywordHandler:new()\n"); builder.Append("local npcHandler = NpcHandler:new(keywordHandler)\n"); builder.Append("NpcSystem.parseParameters(npcHandler)\n"); builder.Append("\n"); builder.Append("function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end\n"); builder.Append("function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end\n"); builder.Append("function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end\n"); builder.Append("function onThink() npcHandler:onThink() end\n"); builder.Append("\n"); if (Statements.ContainsKey("hi")) { builder.Append("npcHandler:setMessage(MESSAGE_GREET, '").Append(Statements["hi"]).Append("')\n"); } else if (Statements.ContainsKey("bye")) { builder.Append("npcHandler:setMessage(MESSAGE_FAREWELL, '").Append(Statements["bye"]).Append("')\n"); } else if (Statements.ContainsKey("trade")) { builder.Append("npcHandler:setMessage(MESSAGE_SENDTRADE, '").Append("')\n"); } builder.Append("\n"); foreach (var statement in Statements) { if (statement.Key.Equals("hi") || statement.Key.Equals("bye") || statement.Key.Equals("trade")) { continue; } builder.Append("keywordHandler:addKeyword({'").Append(statement.Key) .Append("'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = '") .Append(statement.Value).Append("'})\n"); } if (Shop != null) { builder.Append("\n"); builder.Append("local shopModule = ShopModule:new()\n"); builder.Append("npcHandler:addModule(shopModule)\n"); builder.Append("\n"); foreach (var item in Shop.Items.Where(x => x.IsBuyable)) { var otItem = items.GetItemBySpriteId(item.Id); if (otItem == null) { continue; } builder.Append("shopModule:addBuyableItem({'").Append(item.Name.ToLower()). Append("'}, ").Append(otItem.Id).Append(", ").Append(item.BuyPrice).Append(", "); if (otItem.Group == OtItemGroup.Splash || otItem.Group == OtItemGroup.FluidContainer) { builder.Append(OtConverter.TibiaFluidToOtFluid(item.SubType)).Append(", "); } builder.Append('\'').Append(item.Name.ToLower()).Append("')\n"); } builder.Append("\n"); foreach (var item in Shop.Items.Where(x => x.IsSellable)) { var otItem = items.GetItemBySpriteId(item.Id); if (otItem == null) { continue; } builder.Append("shopModule:addSellableItem({'").Append(item.Name.ToLower()). Append("'}, ").Append(otItem.Id).Append(", ").Append(item.SellPrice).Append(", "); if (otItem.Group == OtItemGroup.Splash || otItem.Group == OtItemGroup.FluidContainer) { builder.Append(OtConverter.TibiaFluidToOtFluid(item.SubType)).Append(", "); } builder.Append('\'').Append(item.Name.ToLower()).Append("')\n"); } } builder.Append("\n"); builder.Append("npcHandler:addModule(FocusModule:new())"); File.WriteAllText(fileName, builder.ToString()); }