private void OnCreateCharacterClicked(object sender, RoutedEventArgs e) { var gameConn = m_OnlineClient.GetConnection(OnlineClient.ConnectionType.Game); if (gameConn == null) { return; } var gamePolicy = new SF.Net.SendMessageGame(gameConn); var charName = string.Format("testchar{0}{1}", txtLoginName.Text, m_Rand.Next() % 100); var visualConfig = new VariableTable(); visualConfig.Add(new StringCrc32("sex"), 1); visualConfig.Add(new StringCrc32("hat"), 10); visualConfig.Add(new StringCrc32("shoes"), 10); var attributes = new VariableTable(); attributes.Add(new StringCrc32("Gold"), 100); attributes.Add(new StringCrc32("Agile"), 10); attributes.Add(new StringCrc32("Strength"), 20); attributes.Add(new StringCrc32("Integer"), 30); gamePolicy.CreateCharacterCmd(0, charName, visualConfig, attributes); }
public override void Execute(VariableTable table) { base.Execute(table); if (Variable == null) { throw new VariableException("변수가 비어있습니다."); } if (table.Contains(Variable)) { throw new VariableException("이미 같은 이름의 변수가 정의되어 있습니다."); } table.Add(Variable); Next = _linked[0]; }
private void RunInstruction(T1Instruction instruction) { switch (instruction.Type) { // Variable table should contain scope pointer as well as variable id case T1InstructionType.Assignment: EvaluateExpression(((T1InstructionAssignment)instruction).Expression); if (((T1InstructionAssignment)instruction).Variable.VariableType != ExpressionType) { throw new Exception("Runtime error: Variable type mismatch in expression"); } ((T1InstructionAssignment)instruction).Variable.Scope.VariableTable[((T1InstructionAssignment)instruction).Variable.VariableId] = new T1Variable(((T1InstructionAssignment)instruction).Variable.VariableType, ExpressionResult); break; case T1InstructionType.ConditionalJump: EvaluateExpression(((T1InstructionConditionalJump)instruction).Expression); if ((int)ExpressionResult != 0) { instructionPointer = LabelTable[((T1InstructionConditionalJump)instruction).LabelId] + 1; } break; case T1InstructionType.ExpressionEvaluation: EvaluateExpression(((T1InstructionEvaluateExpression)instruction).Expression); break; case T1InstructionType.FunctionCall: T1Scope newScope = (T1Scope)SubScopes[((T1InstructionFunctionCall)instruction).FunctionId]; // .Clone(); newScope.ParentScope = this; // Variable assignments for arguments for (int i = 0; i < ((T1InstructionFunctionCall)instruction).Arguments.Count; i++) { newScope.VariableTable[i + 1] = new T1Variable(((T1InstructionFunctionCall)instruction).Arguments[i].VariableType, ((T1InstructionFunctionCall)instruction).Arguments[i].Operand); } newScope.Run(); break; case T1InstructionType.FunctionDeclaration: T1Scope subScope = ((T1InstructionFunctionDeclaration)instruction).FunctionScope; // Return value T1Variable returnValue = null; switch (((T1InstructionFunctionDeclaration)instruction).ReturnType) { case T1VariableType.Void: returnValue = new T1Variable(T1VariableType.Void); break; case T1VariableType.Byte: returnValue = new T1Variable(T1VariableType.Byte); break; case T1VariableType.Double: returnValue = new T1Variable(T1VariableType.Double); break; case T1VariableType.Int: returnValue = new T1Variable(T1VariableType.Int); break; case T1VariableType.String: returnValue = new T1Variable(T1VariableType.String); break; } subScope.VariableTable.Add(returnValue); // Arguments for (int i = 0; i < ((T1InstructionFunctionDeclaration)instruction).Arguments.Count; i++) { T1Variable newArgument = null; switch (((T1InstructionFunctionDeclaration)instruction).Arguments[i].VariableType) { case T1VariableType.Void: newArgument = new T1Variable(T1VariableType.Void); break; case T1VariableType.Byte: newArgument = new T1Variable(T1VariableType.Byte); break; case T1VariableType.Double: newArgument = new T1Variable(T1VariableType.Double); break; case T1VariableType.Int: newArgument = new T1Variable(T1VariableType.Int); break; case T1VariableType.String: newArgument = new T1Variable(T1VariableType.String); break; } subScope.VariableTable.Add(newArgument); } SubScopes.Add(subScope); break; case T1InstructionType.Import: break; case T1InstructionType.Jump: instructionPointer = LabelTable[((T1InstructionJump)instruction).LabelId] + 1; break; case T1InstructionType.LabelSet: LabelTable.Add(instructionPointer); break; case T1InstructionType.VariableDeclaration: T1Variable newVariable = null; switch (((T1InstructionVariableDeclaration)instruction).VariableType) { case T1VariableType.Void: newVariable = new T1Variable(T1VariableType.Void, VariableTable.Count); break; case T1VariableType.Byte: newVariable = new T1Variable(T1VariableType.Byte, VariableTable.Count); break; case T1VariableType.Double: newVariable = new T1Variable(T1VariableType.Double, VariableTable.Count); break; case T1VariableType.Int: newVariable = new T1Variable(T1VariableType.Int, VariableTable.Count); break; case T1VariableType.String: newVariable = new T1Variable(T1VariableType.String, VariableTable.Count); break; } VariableTable.Add(newVariable); break; case T1InstructionType.Return: instructionPointer = Instructions.Count; break; } }